Skip to content

Commit

Permalink
1、增加自动导入动作功能,当发现ps内没有插件需要的动作时会自动进行导入
Browse files Browse the repository at this point in the history
2、修复快捷键失效问题
3、添加了高频层、低频层、饱和度观察层、影调观察层的快速创建插件
  • Loading branch information
xi-yue-233 committed Oct 25, 2023
1 parent dad2e17 commit ad4f11b
Show file tree
Hide file tree
Showing 18 changed files with 602 additions and 38 deletions.
Binary file added PSDLink动作.atn
Binary file not shown.
29 changes: 24 additions & 5 deletions button_mehod.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ class All_running_StopException(Exception):
pass


def create_tasks():
pythoncom.CoInitialize() # 初始化com环境
try:
app=start_ps()
documents = app.documents
document_name = app.activeDocument.name
execute_action("sd修图", "sd")
for document in documents:
if document_name == document.name:
break
execute_action("返回上一个图层", "sd")
print("创建新图层任务")
finally:
pythoncom.CoInitialize() # 初始化com环境


def import_to_sd(application_list):
pythoncom.CoInitialize() # 初始化com环境
try:
Expand Down Expand Up @@ -82,9 +98,9 @@ def import_to_sd(application_list):
if application_list[i].is_use_translate.isChecked():
time.sleep(continue2)
print(f"{application_list[i].tab_name.text()} 执行翻译")
if add_positive!="":
if add_positive != "":
add_positive = translate(driver, add_positive)
if add_negative!="":
if add_negative != "":
add_negative = translate(driver, add_negative)
else:
raise StopException
Expand Down Expand Up @@ -1418,7 +1434,8 @@ def lama_upload(application_list, current_tab):

time.sleep(continue2)
if running_variable.running:
upload_img_to_lama(ps, driver, application_list[current_tab].lama_url.text(),application_list[current_tab].layer_name.text())
upload_img_to_lama(ps, driver, application_list[current_tab].lama_url.text(),
application_list[current_tab].layer_name.text())
print(f"{application_list[current_tab].tab_name.text()} 上传Lama图片成功")
else:
raise StopException
Expand All @@ -1439,6 +1456,7 @@ def lama_upload(application_list, current_tab):
finally:
pythoncom.CoUninitialize() # 清理com环境


def lama_download(application_list, current_tab):
try:
pythoncom.CoInitialize() # 初始化com环境
Expand Down Expand Up @@ -1481,7 +1499,8 @@ def lama_download(application_list, current_tab):

time.sleep(continue2)
if running_variable.running:
download_img_from_lama(ps, driver, application_list[current_tab].lama_url.text(),application_list[current_tab].layer_name.text())
download_img_from_lama(ps, driver, application_list[current_tab].lama_url.text(),
application_list[current_tab].layer_name.text())
print(f"{application_list[current_tab].tab_name.text()} 传回Lama图片成功")
else:
raise StopException
Expand All @@ -1500,4 +1519,4 @@ def lama_download(application_list, current_tab):
playsound()
traceback.print_exc()
finally:
pythoncom.CoUninitialize() # 清理com环境
pythoncom.CoUninitialize() # 清理com环境
8 changes: 7 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,11 @@
"isopacity": false,
"lama_url": "1",
"save_x": 1532,
"save_y": 192
"save_y": 192,
"gaopin_key": "shift+f4",
"dipin_key": "shift+f3",
"lama_export": "ctrl+shift+f3",
"lama_import": "ctrl+shift+f4",
"yingdiao": "ctrl+shift+d",
"baohe": "ctrl+shift+f"
}
128 changes: 105 additions & 23 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ps_tools import auto_doc_name
from save_import_project import save_project, import_project, save_project_self
from set_cn_preset import set_cn_win
from set_key_window import open_key_preset
from setting_preset import open_set_preset
from tool_bar_method import *

Expand All @@ -30,8 +31,10 @@
application_list = []
application_small_list = []
index = 0
is_block=False
ispswindow=False
is_block = False
ispswindow = False
is_exit = False


# PS插件窗口
class small_windows(QMainWindow):
Expand Down Expand Up @@ -72,7 +75,7 @@ def __init__(self, parent):
BASE_PATH = os.path.dirname(os.path.realpath(sys.argv[0]))
with open(os.path.join(BASE_PATH, "config.json"), "r") as f:
data = json.load(f)
self.move(data["save_x"],data["save_y"])
self.move(data["save_x"], data["save_y"])

def change_to_Main_w(self, parent):
repair_pswindow(False)
Expand Down Expand Up @@ -313,8 +316,8 @@ def small_tool_bar(self, parent):
self.ui.action_optop.triggered.connect(lambda: [toggle_topmost(self), toggle_topmost(parent), parent.hide()])
self.ui.action_to_night_2.triggered.connect(lambda: repair_is_night(True))
self.ui.action_to_early.triggered.connect(lambda: repair_is_night(False))
self.ui.actionopcacity_true.triggered.connect(lambda: repair_is_opacity(True,self))
self.ui.actionopcacity_false.triggered.connect(lambda: repair_is_opacity(False,self))
self.ui.actionopcacity_true.triggered.connect(lambda: repair_is_opacity(True, self))
self.ui.actionopcacity_false.triggered.connect(lambda: repair_is_opacity(False, self))

# 绑定副窗口工作栏功能
# self.ui_small.action_to_main_win.triggered.connect(lambda: self.change_main_window())
Expand All @@ -327,6 +330,9 @@ def small_tool_bar(self, parent):
self.ui.actionyinpin_start.triggered.connect(lambda: repair_is_sound(True))
self.ui.actionyinpin_stop.triggered.connect(lambda: repair_is_sound(False))

# 快捷键设置
self.ui.actionset_key.triggered.connect(lambda: open_key_preset(parent))

# 存档
self.ui.actionsave.triggered.connect(lambda: save_project(parent, application_list))
self.ui.actionimport.triggered.connect(
Expand All @@ -344,10 +350,14 @@ def small_tool_bar(self, parent):
def check_block():
global is_block
is_block = self.ui.is_block_short_key.isChecked()
self.ui.is_block_short_key.stateChanged.connect(lambda: [check_block(),parent.block_all_short_key()])
parent.block_all_short_key()

self.ui.is_block_short_key.stateChanged.connect(lambda: check_block())

def closeEvent(self, event):
try:
global is_exit
is_exit = True
BASE_PATH = os.path.dirname(os.path.realpath(sys.argv[0]))
with open(os.path.join(BASE_PATH, "config.json"), "r") as f:
data = json.load(f)
Expand All @@ -368,6 +378,7 @@ def closeEvent(self, event):
except:
event.accept()


class EmittingStr(QtCore.QObject):
textWritten = QtCore.pyqtSignal(str) # 定义一个发送str的信号

Expand Down Expand Up @@ -403,7 +414,6 @@ def __init__(self):

self.block_all_short_key()


def first_boot(self):
global ispswindow
if ispswindow:
Expand Down Expand Up @@ -454,7 +464,7 @@ def add_tab(self, tab=None, tab_w=None):
index = index + 1
# 注册工程窗口
if tab != None:
self.ui.tabWidget.insertTab(self.ui.tabWidget.count() -1, tab_w, tab.tab_name.text())
self.ui.tabWidget.insertTab(self.ui.tabWidget.count() - 1, tab_w, tab.tab_name.text())
self.ui.tabWidget.setTabsClosable(True)
# 把视图指向最新一个tab
self.ui.tabWidget.setCurrentIndex(self.ui.tabWidget.count() - 2)
Expand All @@ -465,7 +475,7 @@ def add_tab(self, tab=None, tab_w=None):
self.ui_tab_w.setupUi(self.tab_w)
# 连接tab上的元素
self.tabs_bind()
self.ui.tabWidget.insertTab(self.ui.tabWidget.count() -1, self.tab_w, "任务" + str(index))
self.ui.tabWidget.insertTab(self.ui.tabWidget.count() - 1, self.tab_w, "任务" + str(index))
self.ui.tabWidget.setTabsClosable(True)
self.ui_tab_w.tab_name.setText("任务" + str(index))

Expand Down Expand Up @@ -600,6 +610,10 @@ def Lama_export(self):
else:
print("当前已经有任务在运行了")

# 批量创建多任务层
def create_tasks_method(self):
threading.Thread(target=create_tasks).start()

# 中止当前任务
def stop(self):
running_variable.running = False
Expand All @@ -613,8 +627,8 @@ def main_tool_bar(self):
self.ui.action_to_night_2.triggered.connect(lambda: repair_is_night(True))
self.ui.action_to_early.triggered.connect(lambda: repair_is_night(False))
self.ui.action_to_by_win.triggered.connect(lambda: self.init_sub_win())
self.ui.actionopcacity_true.triggered.connect(lambda: repair_is_opacity(True,self))
self.ui.actionopcacity_false.triggered.connect(lambda: repair_is_opacity(False,self))
self.ui.actionopcacity_true.triggered.connect(lambda: repair_is_opacity(True, self))
self.ui.actionopcacity_false.triggered.connect(lambda: repair_is_opacity(False, self))

# 绑定副窗口工作栏功能
# self.ui_small.action_to_main_win.triggered.connect(lambda: self.change_main_window())
Expand All @@ -627,6 +641,9 @@ def main_tool_bar(self):
self.ui.actionyinpin_start.triggered.connect(lambda: repair_is_sound(True))
self.ui.actionyinpin_stop.triggered.connect(lambda: repair_is_sound(False))

# 快捷键设置
self.ui.actionset_key.triggered.connect(lambda: open_key_preset(self))

# 存档
self.ui.actionsave.triggered.connect(lambda: save_project(self, application_list))
self.ui.actionimport.triggered.connect(lambda: import_project(self, application_list))
Expand All @@ -642,31 +659,67 @@ def main_tool_bar(self):
def check_block():
global is_block
is_block = self.ui.is_block_short_key.isChecked()
self.ui.is_block_short_key.stateChanged.connect(lambda: [check_block(),self.block_all_short_key()])
self.block_all_short_key()

self.ui.is_block_short_key.stateChanged.connect(lambda: check_block())

def block_all_short_key(self):
global is_block
# 开启状态屏蔽掉所有快捷键
BASE_PATH = os.path.dirname(os.path.realpath(sys.argv[0]))
with open(os.path.join(BASE_PATH, "config.json"), "r") as f:
data = json.load(f)
if "gaopin_key" not in data:
data["gaopin_key"] = "shift+f4"
if "dipin_key" not in data:
data["dipin_key"] = "shift+f3"
if "lama_export" not in data:
data["lama_export"] = "ctrl+shift+f3"
if "lama_import" not in data:
data["lama_import"] = "ctrl+shift+f4"
if "yingdiao" not in data:
data["yingdiao"] = "ctrl+shift+d"
if "baohe" not in data:
data["baohe"] = "ctrl+shift+f"
setting = data["settings"][application_list[self.ui.tabWidget.currentIndex()].preset_combo.currentIndex()]
with open(os.path.join(BASE_PATH, "config.json"), "w") as f:
# 将 python 字典转换为 json 字符串,并指定缩进为 4 个空格
formatted_data = json.dumps(data, indent=4)
# 将格式化后的 json 字符串写入新的文件
f.write(formatted_data)
if is_block:
try:
keyboard.unhook_all_hotkeys()
keyboard.add_hotkey(setting["hotkey1"],
lambda: self.create_tasks_method())
print(f"切换至屏蔽快捷键模式,此模式下框选住想要执行的区域,使用{setting['hotkey1']}快捷键可以快速创建多任务文档")
except:
pass
# 取消屏蔽状态后更新当前页面的快捷键
else:
BASE_PATH = os.path.dirname(os.path.realpath(sys.argv[0]))
with open(os.path.join(BASE_PATH, "config.json"), "r") as f:
data = json.load(f)
setting = data["settings"][application_list[self.ui.tabWidget.currentIndex()].preset_combo.currentIndex()]
try:
keyboard.unhook_all_hotkeys()
except:
pass
keyboard.add_hotkey(setting["hotkey1"], lambda: self.short_key_import_sd())
keyboard.add_hotkey(setting["hotkey1"], lambda: [execute_action("sd修图", "sd"), self.short_key_import_sd()])
keyboard.add_hotkey(setting["hotkey2"], lambda: self.import_back_ps())
keyboard.add_hotkey(setting["hotkey3"], lambda: self.start_caculate())
keyboard.add_hotkey("ctrl+shift+f3", lambda: self.Lama_import())
keyboard.add_hotkey("ctrl+shift+f4", lambda: self.Lama_export())
keyboard.add_hotkey(data["gaopin_key"], lambda: [execute_action("高频层", "sd"),print("创建高频层")])
keyboard.add_hotkey(data["dipin_key"], lambda: [execute_action("低频层", "sd"),print("创建低频层")])
keyboard.add_hotkey(data["lama_export"], lambda: [execute_action("lama导入", "sd"), self.Lama_import()])
keyboard.add_hotkey(data["lama_import"], lambda: self.Lama_export())
keyboard.add_hotkey(data["yingdiao"], lambda: [execute_action("影调观察层", "sd"),print("创建影调观察层")])
keyboard.add_hotkey(data["baohe"], lambda: [execute_action("饱和度观察层", "sd"),print("创建饱和度观察层")])
print("快捷鍵开启,请检查ps内动作快捷键是否有冲突!!!")
print(f"执行全流程快捷键{setting['hotkey1']}")
print(f"传回ps快捷键{setting['hotkey2']}")
print(f"开始运算快捷键{setting['hotkey3']}")
print(f"快速创建高频层快捷键{data['gaopin_key']}")
print(f"快速创建低频层快捷键{data['dipin_key']}")
print(f"lama导入快捷键{data['lama_export']}")
print(f"lama导回快捷键{data['lama_import']}")
print(f"影调观察层快捷键{data['yingdiao']}")
print(f"饱和度观察层快捷键{data['baohe']}")

def init_sub_win(self):
repair_pswindow(True)
Expand Down Expand Up @@ -726,7 +779,8 @@ def tabs_bind(self):
self.ui_tab_w.cn3_preset.setCurrentIndex(0)

# 设置lama url
self.ui_tab_w.lama_url.setText(data["lama_url"])
if "lama_url" in data:
self.ui_tab_w.lama_url.setText(data["lama_url"])

# 连接tab上的预设设置按钮
self.ui_tab_w.set_preset.clicked.connect(
Expand Down Expand Up @@ -786,6 +840,8 @@ def tabs_bind(self):

def closeEvent(self, event):
try:
global is_exit
is_exit = True
BASE_PATH = os.path.dirname(os.path.realpath(sys.argv[0]))
with open(os.path.join(BASE_PATH, "config.json"), "r") as f:
data = json.load(f)
Expand Down Expand Up @@ -816,29 +872,55 @@ def check_pswindow():
BASE_PATH = os.path.dirname(os.path.realpath(sys.argv[0]))
with open(os.path.join(BASE_PATH, "config.json"), "r") as f:
data = json.load(f)
ispswindow=data["ispswindow"]
if "ispswindow" not in data:
data["ispswindow"]=False
with open(os.path.join(BASE_PATH, "config.json"), "w") as f:
# 将 python 字典转换为 json 字符串,并指定缩进为 4 个空格
formatted_data = json.dumps(data, indent=4)
# 将格式化后的 json 字符串写入新的文件
f.write(formatted_data)
ispswindow = data["ispswindow"]


def repair_pswindow(is_ps):
global ispswindow
ispswindow=is_ps
ispswindow = is_ps
if is_ps:
print("更改为ps插件窗口")
else:
print("更改为主窗口")
BASE_PATH = os.path.dirname(os.path.realpath(sys.argv[0]))
with open(os.path.join(BASE_PATH, "config.json"), "r") as f:
data = json.load(f)
data["ispswindow"]=is_ps
data["ispswindow"] = is_ps
with open(os.path.join(BASE_PATH, "config.json"), "w") as f:
# 将 python 字典转换为 json 字符串,并指定缩进为 4 个空格
formatted_data = json.dumps(data, indent=4)
# 将格式化后的 json 字符串写入新的文件
f.write(formatted_data)


def clear_keys():
while True:
# Hotkeys stop working after windows locks & unlocks
# https://github.com/boppreh/keyboard/issues/223
deleted = []
with keyboard._pressed_events_lock:
for k in list(keyboard._pressed_events.keys()):
item = keyboard._pressed_events[k]
if time.time() - item.time > 2:
deleted.append(item.name)
del keyboard._pressed_events[k]
if is_exit:
return 0
time.sleep(1)


if __name__ == '__main__':
QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
sys.excepthook = exceptOutConfig
app = QApplication(sys.argv)
threading.Thread(target=clear_keys).start()
check_is_sound()
check_pswindow()
# 查看是否透明
Expand Down
4 changes: 4 additions & 0 deletions main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def setupUi(self, MainWindow):
self.actionopcacity_true.setObjectName("actionopcacity_true")
self.actionopcacity_false = QtWidgets.QAction(MainWindow)
self.actionopcacity_false.setObjectName("actionopcacity_false")
self.actionset_key = QtWidgets.QAction(MainWindow)
self.actionset_key.setObjectName("actionset_key")
self.menu.addAction(self.actionsave)
self.menu.addAction(self.actionimport)
self.menu.addAction(self.actionexit)
Expand All @@ -112,6 +114,7 @@ def setupUi(self, MainWindow):
self.menu_7.addAction(self.actionopcacity_false)
self.menu_6.addAction(self.menuyinpin.menuAction())
self.menu_6.addAction(self.menu_7.menuAction())
self.menu_6.addAction(self.actionset_key)
self.menubar.addAction(self.menu.menuAction())
self.menubar.addAction(self.menu_2.menuAction())
self.menubar.addAction(self.menu_3.menuAction())
Expand Down Expand Up @@ -169,3 +172,4 @@ def retranslateUi(self, MainWindow):
self.actionsetting.setText(_translate("MainWindow", "Autodl账号密码配置"))
self.actionopcacity_true.setText(_translate("MainWindow", "不透明"))
self.actionopcacity_false.setText(_translate("MainWindow", "半透明"))
self.actionset_key.setText(_translate("MainWindow", "设置快捷键"))
Loading

0 comments on commit ad4f11b

Please sign in to comment.