diff --git a/.gitignore b/.gitignore index 3552a738..5e12838d 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,5 @@ LunaTranslator/files/data LunaTranslator/chrome_cache plugins/.vscode/settings.json -LunaTranslator/files/themes \ No newline at end of file +LunaTranslator/files/themes +LunaTranslator/LunaTranslator/rendertext/luna.png diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index 32cd51d8..17c181a5 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -348,7 +348,8 @@ class MAINUI: return res = self.solveaftertrans(res, optimization_params) - + if len(res) == 0: + return if onlytrans == False: if globalconfig["read_trans"] and ( list(globalconfig["fanyi"].keys())[globalconfig["read_translator"]] @@ -697,7 +698,6 @@ class MAINUI: needinserthookcode=needinserthookcode, ) - else: pids = self.textsource.pids if sum([int(pid_running(pid)) for pid in pids]) == 0: @@ -908,8 +908,9 @@ class MAINUI: self.__currentexe = None except: print_exc() + @threader - def clickwordcallback(self,word, append): + def clickwordcallback(self, word, append): if globalconfig["usewordorigin"] == False: word = word["orig"] else: @@ -917,15 +918,12 @@ class MAINUI: if globalconfig["usecopyword"]: if append: - winsharedutils.clipboard_set( - winsharedutils.clipboard_get() + word - ) + winsharedutils.clipboard_set(winsharedutils.clipboard_get() + word) else: winsharedutils.clipboard_set(word) if globalconfig["usesearchword"]: - self.searchwordW.getnewsentencesignal.emit( - word, append - ) + self.searchwordW.getnewsentencesignal.emit(word, append) + def setshowintab_checked(self, widget): try: self.translation_ui diff --git a/LunaTranslator/LunaTranslator/cishu/cishubase.py b/LunaTranslator/LunaTranslator/cishu/cishubase.py index 345b2fab..ece23ebe 100644 --- a/LunaTranslator/LunaTranslator/cishu/cishubase.py +++ b/LunaTranslator/LunaTranslator/cishu/cishubase.py @@ -41,6 +41,8 @@ class cishubase: if res and len(res): callback(res) + else: + callback(None) except: pass diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index 2dc5529f..02d60189 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -44,14 +44,15 @@ from gui.usefulwidget import ( getsimplepatheditor, getboxlayout, getlineedit, - MySwitch, + MySwitch2, auto_select_webview, Prompt_dialog, getsimplecombobox, D_getsimpleswitch, getspinbox, + getIconButton, + D_getIconButton, getcolorbutton, - D_getcolorbutton, makesubtab_lazy, tabadd_lazy, getsimpleswitch, @@ -301,13 +302,8 @@ class tagitem(QWidget): lb.clicked.connect(functools.partial(self.labelclicked.emit, key)) tagLayout.addWidget(lb) if removeable: - button = getcolorbutton( - None, - None, - functools.partial(self.removesignal.emit, key), # self.removeTag(tag), - icon="fa.times", - constcolor="#FF69B4", - sizefixed=True, + button = getIconButton( + functools.partial(self.removesignal.emit, key), icon="fa.times" ) tagLayout.addWidget(button) @@ -498,24 +494,10 @@ class browserdialog(saveposwindow): hlay = QHBoxLayout() hlay.addWidget(self.tagswidget) + hlay.addWidget(getIconButton(self.likelink, icon="fa.heart")) hlay.addWidget( - getcolorbutton( - "", - "", - self.likelink, - icon="fa.heart", - constcolor="#FF69B4", - sizefixed=True, - ) - ) - hlay.addWidget( - getcolorbutton( - "", - "", - lambda: self.urlclicked((None, None, self.current)), - icon="fa.repeat", - constcolor="#FF69B4", - sizefixed=True, + getIconButton( + lambda: self.urlclicked((None, None, self.current)), icon="fa.repeat" ) ) _topw = QWidget() @@ -573,27 +555,20 @@ def maybehavebutton(self, game, post): savehook_new_data[game]["save_text_process_info"]["mypost"] = str( uuid.uuid4() ).replace("-", "_") - return getcolorbutton( - globalconfig, - "", + return getIconButton( callback=functools.partial( selectdebugfile, savehook_new_data[game]["save_text_process_info"]["mypost"], ismypost=True, ), icon="fa.gear", - constcolor="#FF69B4", ) else: if post not in postprocessconfig: return if post == "_remove_chaos": - return getcolorbutton( - globalconfig, - "", - icon="fa.gear", - constcolor="#FF69B4", - callback=lambda: codeacceptdialog(self), + return getIconButton( + icon="fa.gear", callback=lambda: codeacceptdialog(self) ) elif "args" in postprocessconfig[post]: if isinstance(list(postprocessconfig[post]["args"].values())[0], dict): @@ -618,13 +593,7 @@ def maybehavebutton(self, game, post): 600, items, ) - return getcolorbutton( - globalconfig, - "", - callback=callback, - icon="fa.gear", - constcolor="#FF69B4", - ) + return getIconButton(callback=callback, icon="fa.gear") else: return None @@ -663,19 +632,10 @@ class dialog_setting_game_internal(QWidget): getboxlayout( [ self.editpath, - getcolorbutton( - "", - "", - functools.partial(self.selectexe), - icon="fa.gear", - constcolor="#FF69B4", - ), - getcolorbutton( - "", - "", + getIconButton(functools.partial(self.selectexe), icon="fa.gear"), + getIconButton( lambda: browserdialog(gobject.baseobject.settin_ui, exepath), icon="fa.book", - constcolor="#FF69B4", ), ] ), @@ -697,13 +657,7 @@ class dialog_setting_game_internal(QWidget): getboxlayout( [ titleedit, - getcolorbutton( - "", - "", - _titlechange, - icon="fa.search", - constcolor="#FF69B4", - ), + getIconButton(_titlechange, icon="fa.search"), ] ), ) @@ -772,19 +726,13 @@ class dialog_setting_game_internal(QWidget): ) _vbox_internal = [ vndbid, - getcolorbutton( - "", - "", + getIconButton( functools.partial(self.openrefmainpage, key, idname, exepath), icon="fa.chrome", - constcolor="#FF69B4", ), - getcolorbutton( - "", - "", + getIconButton( functools.partial(gamdidchangedtask, key, idname, exepath), icon="fa.search", - constcolor="#FF69B4", ), ] @@ -792,13 +740,7 @@ class dialog_setting_game_internal(QWidget): __settting = targetmod[key].querysettingwindow _vbox_internal.insert( 1, - getcolorbutton( - "", - "", - functools.partial(__settting, self), - icon="fa.gear", - constcolor="#FF69B4", - ), + getIconButton(functools.partial(__settting, self), icon="fa.gear"), ) except: pass @@ -1047,9 +989,7 @@ class dialog_setting_game_internal(QWidget): [ QLabel(_TR("语音修正")), getsimpleswitch(savehook_new_data[exepath], "tts_repair"), - getcolorbutton( - globalconfig, - "", + getIconButton( callback=lambda x: noundictconfigdialog1( self, savehook_new_data[exepath]["tts_repair_regex"], @@ -1057,7 +997,6 @@ class dialog_setting_game_internal(QWidget): ["正则", "原文", "替换"], ), icon="fa.gear", - constcolor="#FF69B4", ), ] ) @@ -1775,16 +1714,9 @@ class dialog_savedgame_integrated(saveposwindow): self.internallayout.addWidget(QWidget()) self.setCentralWidget(w) - colors = ["#7f7f7f", "#7f7f7f", "#FF69B4", "#FF69B4"] - self.layout1btn = MySwitch( - self, icons=["fa.th", "fa.th"], size=20, colors=colors - ) - self.layout2btn = MySwitch( - self, icons=["fa.th-list", "fa.th-list"], size=20, colors=colors - ) - self.layout3btn = MySwitch( - self, icons=["fa.list", "fa.list"], size=20, colors=colors - ) + self.layout1btn = MySwitch2(self, icons=["fa.th", "fa.th"], size=20) + self.layout2btn = MySwitch2(self, icons=["fa.th-list", "fa.th-list"], size=20) + self.layout3btn = MySwitch2(self, icons=["fa.list", "fa.list"], size=20) self.layout1btn.clicked.connect(functools.partial(self.selectlayout, 0)) self.layout2btn.clicked.connect(functools.partial(self.selectlayout, 1)) self.layout3btn.clicked.connect(functools.partial(self.selectlayout, 2)) @@ -1974,9 +1906,7 @@ class dialog_savedgame_new(QWidget): self.tagswidget.lineEdit.setCurrentText(_) layout.addWidget( - getcolorbutton( - "", - "", + getIconButton( lambda _: listediter( parent, _TR("标签集"), @@ -1985,7 +1915,6 @@ class dialog_savedgame_new(QWidget): closecallback=refreshcombo, ), icon="fa.gear", - constcolor="#FF69B4", ), ) @@ -2259,12 +2188,8 @@ class dialog_savedgame_lagacy(QWidget): self.table.setIndexWidget( self.model.index(row, 2), - D_getcolorbutton( - "", - "", - functools.partial(self.showsettingdialog, k), - icon="fa.gear", - constcolor="#FF69B4", + D_getIconButton( + functools.partial(self.showsettingdialog, k), icon="fa.gear" ), ) diff --git a/LunaTranslator/LunaTranslator/gui/inputdialog.py b/LunaTranslator/LunaTranslator/gui/inputdialog.py index d5b46f1c..4a6348c0 100644 --- a/LunaTranslator/LunaTranslator/gui/inputdialog.py +++ b/LunaTranslator/LunaTranslator/gui/inputdialog.py @@ -277,6 +277,11 @@ class autoinitdialog(QDialog): elif line["type"] == "switch": lineW = MySwitch(sign=dd[key]) regist.append([dd, key, lineW.isChecked]) + _ = QHBoxLayout() + _.addStretch() + _.addWidget(lineW) + _.addStretch() + lineW = _ elif line["type"] == "spin": lineW = FocusDoubleSpin() lineW.setMinimum(line.get("min", 0)) diff --git a/LunaTranslator/LunaTranslator/gui/setting_about.py b/LunaTranslator/LunaTranslator/gui/setting_about.py index f17cc511..e013472a 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_about.py +++ b/LunaTranslator/LunaTranslator/gui/setting_about.py @@ -157,7 +157,7 @@ def setTab_aboutlazy(self, basel): [(functools.partial(createversionlabel, self), 10)], [(functools.partial(createdownloadprogress, self), 10)], [], - [("网络请求", -1)], + [("网络请求_重启生效", -1)], [(D_getsimplecombobox(["winhttp", "libcurl"], globalconfig, "network"), 5)], [("网页显示", -1)], [ diff --git a/LunaTranslator/LunaTranslator/gui/setting_cishu.py b/LunaTranslator/LunaTranslator/gui/setting_cishu.py index 58cf8ed9..bbe70cfe 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_cishu.py +++ b/LunaTranslator/LunaTranslator/gui/setting_cishu.py @@ -3,11 +3,10 @@ import gobject from myutils.config import globalconfig, _TRL from gui.inputdialog import autoinitdialog, autoinitdialog_items from gui.usefulwidget import ( - D_getcolorbutton, yuitsu_switch, makescrollgrid, D_getsimpleswitch, - D_getsimplecombobox, + D_getIconButton, ) @@ -29,9 +28,7 @@ def gethiragrid(self): if "args" in globalconfig["hirasetting"][name]: items = autoinitdialog_items(globalconfig["hirasetting"][name]) items[-1]["callback"] = gobject.baseobject.starthira - _3 = D_getcolorbutton( - globalconfig, - "", + _3 = D_getIconButton( callback=functools.partial( autoinitdialog, self, @@ -40,7 +37,6 @@ def gethiragrid(self): items, ), icon="fa.gear", - constcolor="#FF69B4", ) else: @@ -81,48 +77,16 @@ def gethiragrid(self): def setTabcishu_l(self): - grids = ( + grids = [ [ - [("分词&假名分析器", -1)], - [ - ("日语注音方案", 6), - ( - D_getsimplecombobox( - _TRL(["平假名", "片假名", "罗马音"]), - globalconfig, - "hira_vis_type", - ), - 5, - ), - ], - ] - + gethiragrid(self) - + [ - [], - [], - [ - ("点击单词查词", 6), - (D_getsimpleswitch(globalconfig, "usesearchword"), 1), - D_getcolorbutton( - globalconfig, - "", - callback=lambda: gobject.baseobject.searchwordW.showsignal.emit(), - icon="fa.search", - constcolor="#FF69B4", - ), - "", - ("点击单词复制", 6), - (D_getsimpleswitch(globalconfig, "usecopyword"), 1), - ], - [ - ("使用原型查询", 6), - (D_getsimpleswitch(globalconfig, "usewordorigin"), 1), - ], - [], - [("辞书", -1)], - ] - ) - + ( + dict(title="分词器", type="grid", grid=gethiragrid(self)), + 0, + "group", + ) + ], + ] + cishugrid = [] line = [] i = 0 for cishu in globalconfig["cishu"]: @@ -141,9 +105,7 @@ def setTabcishu_l(self): "use", callback=functools.partial(gobject.baseobject.startxiaoxueguan, cishu), ), - D_getcolorbutton( - globalconfig, - "", + D_getIconButton( callback=functools.partial( autoinitdialog, self, @@ -152,16 +114,34 @@ def setTabcishu_l(self): items, ), icon="fa.gear", - constcolor="#FF69B4", ), ] if i % 3 == 2: - grids.append(line) + cishugrid.append(line) line = [] else: line += [""] i += 1 if len(line): - grids.append(line) + cishugrid.append(line) + grids += [ + [], + [ + "查词", + D_getIconButton( + callback=lambda: gobject.baseobject.searchwordW.showsignal.emit(), + icon="fa.search", + ), + ("",4) + ], + [], + [ + ( + dict(title="辞书", type="grid", grid=cishugrid), + 0, + "group", + ) + ], + ] return grids diff --git a/LunaTranslator/LunaTranslator/gui/setting_display.py b/LunaTranslator/LunaTranslator/gui/setting_display.py index b6349bbc..9084aba2 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display.py @@ -2,7 +2,7 @@ from qtsymbols import * import functools import gobject from myutils.config import globalconfig, _TRL -from gui.setting_display_buttons import createbuttonwidget +from gui.setting_display_buttons import createbuttonwidget from gui.setting_display_text import xianshigrid from gui.setting_display_ui import uisetting from gui.setting_display_scale import makescalew @@ -18,51 +18,89 @@ def _xingw(): xingweigrid = [ [ - ("游戏最小化时窗口隐藏", 6), - (D_getsimpleswitch(globalconfig, "minifollow"), 1), + ( + dict( + title="伴随游戏窗口", + grid=( + [ + "游戏最小化时窗口隐藏", + D_getsimpleswitch(globalconfig, "minifollow"), + ], + [ + "游戏失去焦点时取消置顶", + D_getsimpleswitch(globalconfig, "focusnotop"), + ], + [ + "游戏窗口移动时同步移动", + D_getsimpleswitch(globalconfig, "movefollow"), + ], + ), + ), + 0, + "group", + ) ], [ - ("游戏失去焦点时取消置顶", 6), - (D_getsimpleswitch(globalconfig, "focusnotop"), 1), + ( + dict( + title="窗口尺寸", + grid=( + [ + "自动延展", + D_getsimpleswitch(globalconfig, "auto_expand"), + ], + [ + "自动收缩", + D_getsimpleswitch(globalconfig, "auto_shrink"), + ], + ), + ), + 0, + "group", + ) ], [ - ("游戏窗口移动时同步移动", 6), - (D_getsimpleswitch(globalconfig, "movefollow"), 1), - ], - [ - ("固定窗口尺寸", 6), - D_getsimpleswitch(globalconfig, "fixedheight"), - ], - [ - ("自动隐藏窗口", 6), - (D_getsimpleswitch(globalconfig, "autodisappear"), 1), - "", - ("隐藏延迟(s)", 3), - (D_getspinbox(1, 100, globalconfig, "disappear_delay"), 2), - ], - [ - ("任务栏中显示_翻译窗口", 6), - D_getsimpleswitch( - globalconfig, - "showintab", - callback=lambda _: gobject.baseobject.setshowintab(), - ), - ], - [ - ("任务栏中显示_其他", 6), - D_getsimpleswitch( - globalconfig, - "showintab_sub", - callback=lambda _: gobject.baseobject.setshowintab(), - ), - ], - [ - ("可选取模式", 6), - D_getsimpleswitch( - globalconfig, - "selectable", - callback=lambda x: gobject.baseobject.translation_ui.translate_text.setselectable(), - ), + ( + dict( + title="其他", + grid=( + [ + "自动隐藏窗口", + D_getsimpleswitch(globalconfig, "autodisappear"), + ], + [ + "隐藏延迟(s)", + D_getspinbox(1, 100, globalconfig, "disappear_delay"), + ], + [ + "任务栏中显示_翻译窗口", + D_getsimpleswitch( + globalconfig, + "showintab", + callback=lambda _: gobject.baseobject.setshowintab(), + ), + ], + [ + "任务栏中显示_其他", + D_getsimpleswitch( + globalconfig, + "showintab_sub", + callback=lambda _: gobject.baseobject.setshowintab(), + ), + ], + [ + "可选取模式", + D_getsimpleswitch( + globalconfig, + "selectable", + callback=lambda x: gobject.baseobject.translation_ui.translate_text.setselectable(), + ), + ], + ), + ), + 0, + "group", + ) ], ] return xingweigrid diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_buttons.py b/LunaTranslator/LunaTranslator/gui/setting_display_buttons.py index c3a0cc34..e38415f6 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_buttons.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_buttons.py @@ -5,8 +5,8 @@ from myutils.config import globalconfig, _TR, _TRL from myutils.wrapper import Singleton from gui.usefulwidget import ( D_getsimplecombobox, - D_getcolorbutton, - getcolorbutton, + D_getIconButton, + getIconButton, makescrollgrid, D_getsimpleswitch, ) @@ -29,9 +29,7 @@ class dialog_selecticon(QDialog): self.setLayout(layout) for i, name in enumerate(js): layout.addWidget( - getcolorbutton( - "", - "", + getIconButton( functools.partial(self.selectcallback, "fa." + name), qicon=qtawesome.icon( "fa." + name, color=globalconfig["buttoncolor"] @@ -89,23 +87,17 @@ def createbuttonwidget(self, lay): for i, k in enumerate(sortlist): - button_up = D_getcolorbutton( - globalconfig, - "", + button_up = D_getIconButton( callback=functools.partial( changerank, k, True, sortlist, savelist, savelay ), icon="fa.arrow-up", - constcolor="#FF69B4", ) - button_down = D_getcolorbutton( - globalconfig, - "", + button_down = D_getIconButton( callback=functools.partial( changerank, k, False, sortlist, savelist, savelay ), icon="fa.arrow-down", - constcolor="#FF69B4", ) l = [ @@ -123,9 +115,7 @@ def createbuttonwidget(self, lay): callback=doadjust, fixedsize=True, ), - D_getcolorbutton( - "", - "", + D_getIconButton( functools.partial( dialog_selecticon, self, @@ -140,9 +130,7 @@ def createbuttonwidget(self, lay): ] if "icon2" in globalconfig["toolbutton"]["buttons"][k]: l.append( - D_getcolorbutton( - "", - "", + D_getIconButton( functools.partial( dialog_selecticon, self, diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_scale.py b/LunaTranslator/LunaTranslator/gui/setting_display_scale.py index 2ac11e76..55281792 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_scale.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_scale.py @@ -7,7 +7,7 @@ from gui.usefulwidget import ( makegrid, D_getspinbox, getvboxwidget, - D_getcolorbutton, + D_getIconButton, makesubtab_lazy, makescrollgrid, D_getsimpleswitch, @@ -34,9 +34,7 @@ def makescalew(self, lay): [ ("Magpie_路径", 4), ( - D_getcolorbutton( - globalconfig, - "", + D_getIconButton( callback=lambda x: getsomepath1( self, "Magpie_路径", @@ -46,7 +44,6 @@ def makescalew(self, lay): isdir=True, ), icon="fa.gear", - constcolor="#FF69B4", ), 1, ), @@ -55,255 +52,299 @@ def makescalew(self, lay): ] innermagpie = [ - [("常规", -1)], [ - ("", 1), - ("缩放模式", 4), ( - D_getsimplecombobox( - [_["name"] for _ in magpie_config["scalingModes"]], - magpie_config["profiles"][globalconfig["profiles_index"]], - "scalingMode", + dict( + title="常规", + grid=( + [ + [ + "缩放模式", + D_getsimplecombobox( + [_["name"] for _ in magpie_config["scalingModes"]], + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "scalingMode", + ), + ], + [ + "捕获模式", + D_getsimplecombobox( + [ + "Graphics Capture", + "Desktop Duplication", + "GDI", + "DwmSharedSurface", + ], + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "captureMethod", + ), + ], + [ + "3D游戏模式", + D_getsimpleswitch( + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "3DGameMode", + ), + ], + ] + ), ), - 6, - ), - "", + 0, + "group", + ) ], [ - ("", 1), - ("捕获模式", 4), ( - D_getsimplecombobox( - [ - "Graphics Capture", - "Desktop Duplication", - "GDI", - "DwmSharedSurface", - ], - magpie_config["profiles"][globalconfig["profiles_index"]], - "captureMethod", + dict( + title="性能", + grid=( + [ + [ + "显示帧率", + D_getsimpleswitch( + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "showFPS", + ), + ], + [ + "限制帧率", + D_getsimpleswitch( + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "frameRateLimiterEnabled", + ), + ], + [ + "最大帧率", + D_getspinbox( + 0, + 9999, + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "maxFrameRate", + ), + ], + ] + ), ), - 6, - ), + 0, + "group", + ) ], [ - ("", 1), - ("3D游戏模式", 4), ( - D_getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "3DGameMode", - ) - ), - ], - [("性能", -1)], - [ - ("", 1), - ("显示帧率", 4), - ( - D_getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "showFPS", - ) - ), - ], - [ - ("", 1), - ("限制帧率", 4), - ( - D_getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "frameRateLimiterEnabled", - ) - ), - ], - [ - ("", 1), - ("最大帧率", 4), - ( - D_getspinbox( - 0, - 9999, - magpie_config["profiles"][globalconfig["profiles_index"]], - "maxFrameRate", + dict( + title="源窗口", + grid=( + [ + [ + "缩放时禁用窗口大小调整", + D_getsimpleswitch( + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "disableWindowResizing", + ), + ], + [ + "捕获标题栏", + D_getsimpleswitch( + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "captureTitleBar", + ), + ], + [ + "自定义剪裁", + D_getsimpleswitch( + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "croppingEnabled", + ), + ], + ] + ), ), - 2, - ), - ], - [("源窗口", -1)], - [ - ("", 1), - ("缩放时禁用窗口大小调整", 4), - ( - D_getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "disableWindowResizing", - ) - ), + 0, + "group", + ) ], [ - ("", 1), - ("捕获标题栏", 4), ( - D_getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "captureTitleBar", - ) - ), - ], - [ - ("", 1), - ("自定义剪裁", 4), - ( - D_getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "croppingEnabled", - ) - ), - ], - [("光标", -1)], - [ - ("", 1), - ("绘制光标", 4), - ( - D_getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "drawCursor", - ) - ), - ], - [ - ("", 1), - ("绘制光标_缩放系数", 4), - ( - D_getsimplecombobox( - ["0.5x", "0.75x", "无缩放", "1.25x", "1.5x", "2x", "和源窗口相同"], - magpie_config["profiles"][globalconfig["profiles_index"]], - "cursorScaling", + dict( + title="光标", + grid=( + [ + [ + "绘制光标", + D_getsimpleswitch( + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "drawCursor", + ), + ], + [ + "绘制光标_缩放系数", + D_getsimplecombobox( + [ + "0.5x", + "0.75x", + "无缩放", + "1.25x", + "1.5x", + "2x", + "和源窗口相同", + ], + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "cursorScaling", + ), + ], + [ + "绘制光标_插值算法", + D_getsimplecombobox( + ["最邻近", "双线性"], + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "cursorInterpolationMode", + ), + ], + [ + "缩放时调整光标速度", + D_getsimpleswitch( + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "adjustCursorSpeed", + ), + ], + ] + ), ), - 6, - ), + 0, + "group", + ) ], [ - ("", 1), - ("绘制光标_插值算法", 4), ( - D_getsimplecombobox( - ["最邻近", "双线性"], - magpie_config["profiles"][globalconfig["profiles_index"]], - "cursorInterpolationMode", + dict( + title="高级", + grid=( + [ + [ + "禁用DirectFlip", + D_getsimpleswitch( + magpie_config["profiles"][ + globalconfig["profiles_index"] + ], + "disableDirectFlip", + ), + ], + [ + "允许缩放最大化或全屏的窗口", + D_getsimpleswitch( + magpie_config, + "allowScalingMaximized", + ), + ], + [ + "缩放时模拟独占全屏", + D_getsimpleswitch( + magpie_config, + "simulateExclusiveFullscreen", + ), + ], + [ + "内联效果参数", + D_getsimpleswitch( + magpie_config, + "inlineParams", + ), + ], + ] + ), ), - 6, - ), + 0, + "group", + ) ], [ - ("", 1), - ("缩放时调整光标速度", 4), ( - D_getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "adjustCursorSpeed", - ) - ), - ], - [("高级", -1)], - [ - ("", 1), - ("禁用DirectFlip", 4), - ( - D_getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "disableDirectFlip", - ) - ), - ], - [ - ("", 1), - ("允许缩放最大化或全屏的窗口", 4), - (D_getsimpleswitch(magpie_config, "allowScalingMaximized")), - ], - [ - ("", 1), - ("缩放时模拟独占全屏", 4), - (D_getsimpleswitch(magpie_config, "simulateExclusiveFullscreen")), - ], - [ - ("", 1), - ("内联效果参数", 4), - (D_getsimpleswitch(magpie_config, "inlineParams")), - ], - [("开发者选项", -1)], - [ - ("", 1), - ("调试模式", 4), - ( - D_getsimpleswitch( - magpie_config, - "debugMode", - ) - ), - ], - [ - ("", 1), - ("禁用效果缓存", 4), - ( - D_getsimpleswitch( - magpie_config, - "disableEffectCache", - ) - ), - ], - [ - ("", 1), - ("禁用字体缓存", 4), - ( - D_getsimpleswitch( - magpie_config, - "disableFontCache", - ) - ), - ], - [ - ("", 1), - ("解析效果时保存源代码", 4), - ( - D_getsimpleswitch( - magpie_config, - "saveEffectSources", - ) - ), - ], - [ - ("", 1), - ("编译效果时将警告视为错误", 4), - ( - D_getsimpleswitch( - magpie_config, - "warningsAreErrors", - ) - ), - ], - [ - ("", 1), - ("检测重复帧", 4), - ( - D_getsimplecombobox( - ["总是检测", "动态检测", "从不检测"], - magpie_config, - "duplicateFrameDetectionMode", + dict( + title="开发者选项", + grid=( + [ + [ + "调试模式", + D_getsimpleswitch( + magpie_config, + "debugMode", + ), + ], + [ + "禁用效果缓存", + D_getsimpleswitch( + magpie_config, + "disableEffectCache", + ), + ], + [ + "禁用字体缓存", + D_getsimpleswitch( + magpie_config, + "disableFontCache", + ), + ], + [ + "解析效果时保存源代码", + D_getsimpleswitch( + magpie_config, + "saveEffectSources", + ), + ], + [ + "编译效果时将警告视为错误", + D_getsimpleswitch( + magpie_config, + "warningsAreErrors", + ), + ], + [ + "检测重复帧", + D_getsimplecombobox( + ["总是检测", "动态检测", "从不检测"], + magpie_config, + "duplicateFrameDetectionMode", + ), + ], + [ + "启用动态检测统计", + D_getsimpleswitch( + magpie_config, + "enableStatisticsForDynamicDetection", + ), + ], + ] + ), ), - 6, - ), - ], - [ - ("", 1), - ("启用动态检测统计", 4), - ( - D_getsimpleswitch( - magpie_config, - "enableStatisticsForDynamicDetection", - ) - ), + 0, + "group", + ) ], ] diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_text.py b/LunaTranslator/LunaTranslator/gui/setting_display_text.py index 0ff226bd..6bdf28c4 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_text.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_text.py @@ -1,14 +1,17 @@ from qtsymbols import * import functools import gobject, os -from myutils.config import globalconfig, _TRL, _TR +from myutils.config import globalconfig, _TRL, _TR, static_data from gui.inputdialog import multicolorset +from myutils.wrapper import tryprint from gui.usefulwidget import ( D_getsimplecombobox, - getsimplecombobox, + Singleton_close, + saveposwindow, getsimpleswitch, D_getspinbox, getspinbox, + D_getIconButton, D_getcolorbutton, getcolorbutton, D_getsimpleswitch, @@ -72,7 +75,50 @@ def createfenciwitch(self): return self.show_fenciswitch +@Singleton_close +class extrahtml(saveposwindow): + def tryload(self): + + use = "userconfig/extrahtml.html" + if os.path.exists(use) == False: + use = r"LunaTranslator\rendertext\exampleextrahtml.html" + with open(use, "r", encoding="utf8") as ff: + self.vistext.setPlainText(ff.read()) + + @tryprint + def applyhtml(self, _): + + gobject.refwebview.set_extra_html(self.vistext.toPlainText()) + + def savehtml(self): + os.makedirs("userconfig", exist_ok=True) + with open("userconfig/extrahtml.html", "w", encoding="utf8") as ff: + ff.write(self.vistext.toPlainText()) + + def __init__(self, parent) -> None: + super().__init__(parent, globalconfig, "geo_extrahtml") + self.setWindowTitle(_TR("额外的html")) + + self.btn_save = QPushButton(_TR("保存")) + self.btn_save.clicked.connect(self.savehtml) + self.btn_apply = QPushButton(_TR("测试")) + self.btn_apply.clicked.connect(self.applyhtml) + self.vistext = QPlainTextEdit() + lay = QVBoxLayout() + hl = QHBoxLayout() + hl.addWidget(self.btn_save) + hl.addWidget(self.btn_apply) + lay.addWidget(self.vistext) + lay.addLayout(hl) + w = QWidget() + w.setLayout(lay) + self.setCentralWidget(w) + self.tryload() + self.show() + + def createinternalfontsettings(self, group, _type): + globalconfig["rendertext_using_internal"][group] = _type __internal = globalconfig["rendertext"][group][_type] dd = __internal.get("args", {}) @@ -84,6 +130,7 @@ def createinternalfontsettings(self, group, _type): w = item.widget() lay.removeWidget(w) w.deleteLater() + for key in dd: line = __internal["argstype"][key] name = line["name"] @@ -122,6 +169,10 @@ def createinternalfontsettings(self, group, _type): name, lineW, ) + if group == "webview": + _btn = QPushButton(_TR("额外的html")) + lay.addWidget(_btn) + _btn.clicked.connect(lambda: extrahtml(self)) def resetgroudswitchcallback(self, group): @@ -130,37 +181,24 @@ def resetgroudswitchcallback(self, group): self.goodfontgroupswitch.currentIndexChanged.disconnect() except: pass - _ = [] - for k in globalconfig["rendertext"][group]: - if not os.path.exists(f"LunaTranslator/rendertext/internal/{group}/{k}.py"): - _.append(k) - for k in _: - globalconfig["rendertext"][group].pop(k) - if ( - globalconfig["rendertext_using_internal"][group] - not in globalconfig["rendertext"][group] - ): - globalconfig["rendertext_using_internal"][group] = list( - globalconfig["rendertext"][group].keys() - )[0] self.goodfontgroupswitch.clear() self.goodfontgroupswitch.addItems( _TRL( [ globalconfig["rendertext"][group][x]["name"] - for x in globalconfig["rendertext"][group] + for x in static_data["textrender"][group] ] ) ) self.goodfontgroupswitch.setCurrentIndex(-1) self.goodfontgroupswitch.currentIndexChanged.connect( lambda idx: createinternalfontsettings( - self, group, list(globalconfig["rendertext"][group].keys())[idx] + self, group, static_data["textrender"][group][idx] ) ) self.goodfontgroupswitch.setCurrentIndex( - list(globalconfig["rendertext"][group].keys()).index( + static_data["textrender"][group].index( globalconfig["rendertext_using_internal"][group] ) ) @@ -185,112 +223,196 @@ def xianshigrid(self): textgrid = [ [ - ("原文字体", 3), - (functools.partial(createtextfontcom, "fonttype"), 6), - ("", 5), - ], - [ - ("译文字体", 3), - (functools.partial(createtextfontcom, "fonttype2"), 6), - ], - [ - ("字体大小", 3), - (functools.partial(createfontsizespin, self), 3), - "", - ("额外的行间距", 3), - (D_getspinbox(-100, 100, globalconfig, "extra_space"), 3), - ], - [ - ("居中显示", 5), - D_getsimpleswitch(globalconfig, "showatcenter"), - "", - ("加粗字体", 5), - D_getsimpleswitch(globalconfig, "showbold"), - ], - [], - [ - ("显示引擎", 3), ( - D_getsimplecombobox( - ["Webview2", "Qt"], - globalconfig, - "rendertext_using", - internallist=["webview", "textbrowser"], - callback=functools.partial(resetgroudswitchcallback, self), + dict( + title="样式", + type="grid", + grid=( + [ + ("原文字体", 3), + (functools.partial(createtextfontcom, "fonttype"), 6), + ], + [ + ("译文字体", 3), + (functools.partial(createtextfontcom, "fonttype2"), 6), + ], + [ + ("原文颜色", 3), + D_getcolorbutton( + globalconfig, + "rawtextcolor", + callback=lambda: selectcolor( + self, + globalconfig, + "rawtextcolor", + self.original_color_button, + ), + name="original_color_button", + parent=self, + ), + ], + [ + ("字体大小", 3), + (functools.partial(createfontsizespin, self), 3), + "", + ("额外的行间距", 3), + (D_getspinbox(-100, 100, globalconfig, "extra_space"), 3), + ], + [ + ("居中显示", 3), + D_getsimpleswitch(globalconfig, "showatcenter"), + ("", 3), + ("加粗字体", 3), + D_getsimpleswitch(globalconfig, "showbold"), + ], + ), ), - 6, - ), - ], - [(functools.partial(creategoodfontwid, self), 0)], - [], - [ - ("显示原文", 5), - functools.partial(createshoworiginswitch, self), - "", - ("显示翻译", 5), - (D_getsimpleswitch(globalconfig, "showfanyi"), 1), + 0, + "group", + ) ], [ - ("原文颜色", 5), - D_getcolorbutton( - globalconfig, - "rawtextcolor", - callback=lambda: selectcolor( - self, globalconfig, "rawtextcolor", self.original_color_button - ), - name="original_color_button", - parent=self, - ), - "", - ("显示翻译器名称", 5), - (D_getsimpleswitch(globalconfig, "showfanyisource"), 1), - ], - [ - ("最长显示字数", 3), - (D_getspinbox(0, 1000000, globalconfig, "maxoriginlength"), 3), - ], - [], - [ - ("显示日语注音", 5), - functools.partial(createhiraswitch, self), - ], - [ - ("注音颜色", 5), - D_getcolorbutton( - globalconfig, - "jiamingcolor", - callback=lambda: selectcolor( - self, globalconfig, "jiamingcolor", self.jiamingcolor_b - ), - name="jiamingcolor_b", - parent=self, - ), - "", - ("注音字体缩放", 3), ( - D_getspinbox( - 0.05, 1, globalconfig, "kanarate", double=True, step=0.05, dec=2 + dict( + type="grid", + grid=( + [ + ("显示引擎_重启生效", 3), + ( + D_getsimplecombobox( + ["Webview2", "Qt"], + globalconfig, + "rendertext_using", + internallist=["webview", "textbrowser"], + callback=functools.partial( + resetgroudswitchcallback, self + ), + ), + 6, + ), + ], + [(functools.partial(creategoodfontwid, self), 0)], + ), ), - 3, - ), + 0, + "group", + ) ], [ - ("语法加亮", 5), - functools.partial(createfenciwitch, self), - "", - ("词性颜色(需要Mecab)", 5), - D_getcolorbutton( - globalconfig, - "", - callback=lambda: multicolorset(self), - icon="fa.gear", - constcolor="#FF69B4", - ), + ( + dict( + title="注音", + type="grid", + grid=( + [ + ("显示", 5), + functools.partial(createhiraswitch, self), + "", + ("颜色", 5), + D_getcolorbutton( + globalconfig, + "jiamingcolor", + callback=lambda: selectcolor( + self, + globalconfig, + "jiamingcolor", + self.jiamingcolor_b, + ), + name="jiamingcolor_b", + parent=self, + ), + ], + [ + ("字体缩放", 5), + D_getspinbox( + 0.05, + 1, + globalconfig, + "kanarate", + double=True, + step=0.05, + dec=2, + ), + "", + ("日语注音方案", 5), + D_getsimplecombobox( + _TRL(["平假名", "片假名", "罗马音"]), + globalconfig, + "hira_vis_type", + ), + ], + ), + ), + 0, + "group", + ) ], - [], [ - ("收到翻译结果时才刷新", 5), - D_getsimpleswitch(globalconfig, "refresh_on_get_trans"), + ( + dict( + title="分词", + type="grid", + grid=( + [ + ("语法加亮", 5), + functools.partial(createfenciwitch, self), + "", + ("词性颜色(需要Mecab)", 5), + D_getIconButton( + callback=lambda: multicolorset(self), icon="fa.gear" + ), + ], + [ + ("点击单词查词", 5), + (D_getsimpleswitch(globalconfig, "usesearchword"), 1), + "", + ("点击单词复制", 5), + (D_getsimpleswitch(globalconfig, "usecopyword"), 1), + ], + [ + ("使用原型查询", 5), + (D_getsimpleswitch(globalconfig, "usewordorigin"), 1), + ], + ), + ), + 0, + "group", + ) + ], + [ + ( + dict( + title="显示行为", + type="grid", + grid=( + [ + ("显示原文", 5), + functools.partial(createshoworiginswitch, self), + "", + ("显示翻译", 5), + (D_getsimpleswitch(globalconfig, "showfanyi"), 1), + ], + [ + ("显示翻译器名称", 5), + (D_getsimpleswitch(globalconfig, "showfanyisource"), 1), + "", + ("最长显示字数", 5), + ( + D_getspinbox( + 0, 1000000, globalconfig, "maxoriginlength" + ), + 3, + ), + ], + [ + ("收到翻译结果时才刷新", 5), + D_getsimpleswitch(globalconfig, "refresh_on_get_trans"), + ], + ), + ), + 0, + "group", + ) ], ] return textgrid diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_ui.py b/LunaTranslator/LunaTranslator/gui/setting_display_ui.py index 7ded57a9..ecee9ba1 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_ui.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_ui.py @@ -8,9 +8,9 @@ from gui.usefulwidget import ( D_getsimplecombobox, D_getspinbox, D_getcolorbutton, - getcolorbutton, + getIconButton, selectcolor, - FocusFontCombo + FocusFontCombo, ) @@ -163,13 +163,7 @@ def checkthemesettingvisandapply_1(self, _dark): def createbtnthemelight(self): lightsetting = checkthemeissetable(self, False) self.lightsetting = lightsetting - self.btnthemelight = getcolorbutton( - globalconfig, - "", - callback=lambda: 1, - icon="fa.gear", - constcolor="#FF69B4", - ) + self.btnthemelight = getIconButton(icon="fa.gear") try: if not self.lightsetting: self.btnthemelight.hide() @@ -184,12 +178,8 @@ def createbtnthemelight(self): def createbtnthemedark(self): darksetting = checkthemeissetable(self, True) self.darksetting = darksetting - self.btnthemedark = getcolorbutton( - globalconfig, - "", - callback=lambda: 1, + self.btnthemedark = getIconButton( icon="fa.gear", - constcolor="#FF69B4", ) try: if not self.darksetting: @@ -213,170 +203,281 @@ def uisetting(self): return [_["name"] for _ in static_data["themes"][t]] uigrid = [ - [("设置界面字体", 4), (createfontcombo, 5)], [ - ("字体大小", 4), ( - D_getspinbox( - 1, - 100, - globalconfig, - "settingfontsize", - callback=lambda _: gobject.baseobject.setcommonstylesheet(), + dict( + title="主界面", + type="grid", + grid=( + [ + ( + dict( + title="翻译窗口", + type="grid", + grid=( + [ + ("不透明度", 4), + ( + functools.partial( + createhorizontal_slider, self + ), + 8, + ), + ( + functools.partial( + createhorizontal_slider_label, self + ), + 2, + ), + ], + [ + ("背景颜色", 4), + D_getcolorbutton( + globalconfig, + "backcolor", + callback=lambda: selectcolor( + self, + globalconfig, + "backcolor", + self.back_color_button, + callback=gobject.baseobject.translation_ui.set_color_transparency, + ), + name="back_color_button", + parent=self, + ), + "", + "", + ("圆角_半径", 4), + ( + D_getspinbox( + 0, + 100, + globalconfig, + "yuanjiao_r", + callback=lambda _: gobject.baseobject.translation_ui.set_color_transparency(), + ), + 2, + ), + ], + ), + ), + 0, + "group", + ) + ], + [ + ( + dict( + title="工具栏", + type="grid", + grid=( + [ + ("不透明度", 4), + ( + functools.partial( + createhorizontal_slider_tool, self + ), + 8, + ), + ( + functools.partial( + createhorizontal_slider_tool_label, + self, + ), + 2, + ), + ], + [ + ("背景颜色", 4), + D_getcolorbutton( + globalconfig, + "backcolor_tool", + callback=lambda: selectcolor( + self, + globalconfig, + "backcolor_tool", + self.back_color_button_tool, + callback=gobject.baseobject.translation_ui.set_color_transparency, + ), + name="back_color_button_tool", + parent=self, + ), + ], + [ + ("工具按钮颜色", 4), + D_getcolorbutton( + globalconfig, + "buttoncolor", + callback=lambda: selectcolor( + self, + globalconfig, + "buttoncolor", + self.buttoncolorbutton, + callback=lambda: gobject.baseobject.translation_ui.refreshtooliconsignal.emit(), + ), + name="buttoncolorbutton", + parent=self, + ), + "", + "", + ("工具按钮大小", 4), + ( + D_getspinbox( + 5, + 100, + globalconfig, + "buttonsize", + callback=lambda _: gobject.baseobject.translation_ui.refreshtooliconsignal.emit(), + ), + 2, + ), + ], + ), + ), + 0, + "group", + ) + ], + ), ), - 2, - ), + 0, + "group", + ) ], [ - ("不透明度_翻译窗口", 4), - (functools.partial(createhorizontal_slider, self), 8), - (functools.partial(createhorizontal_slider_label, self), 2), - ], - [ - ("不透明度_工具栏", 4), - (functools.partial(createhorizontal_slider_tool, self), 8), - (functools.partial(createhorizontal_slider_tool_label, self), 2), - ], - [ - ("背景颜色_翻译窗口", 4), - D_getcolorbutton( - globalconfig, - "backcolor", - callback=lambda: selectcolor( - self, - globalconfig, - "backcolor", - self.back_color_button, - callback=gobject.baseobject.translation_ui.set_color_transparency, - ), - name="back_color_button", - parent=self, - ), - "", - "", - ("背景颜色_工具栏", 4), - D_getcolorbutton( - globalconfig, - "backcolor_tool", - callback=lambda: selectcolor( - self, - globalconfig, - "backcolor_tool", - self.back_color_button_tool, - callback=gobject.baseobject.translation_ui.set_color_transparency, - ), - name="back_color_button_tool", - parent=self, - ), - ], - [ - ("工具按钮颜色", 4), - D_getcolorbutton( - globalconfig, - "buttoncolor", - callback=lambda: selectcolor( - self, - globalconfig, - "buttoncolor", - self.buttoncolorbutton, - callback=lambda: gobject.baseobject.translation_ui.refreshtooliconsignal.emit(), - ), - name="buttoncolorbutton", - parent=self, - ), - "", - "", - ("工具按钮大小", 4), ( - D_getspinbox( - 5, - 100, - globalconfig, - "buttonsize", - callback=lambda _: gobject.baseobject.translation_ui.refreshtooliconsignal.emit(), + dict( + title="设置界面", + grid=( + ["字体", createfontcombo], + [ + "字体大小", + D_getspinbox( + 1, + 100, + globalconfig, + "settingfontsize", + callback=lambda _: gobject.baseobject.setcommonstylesheet(), + ), + ], + [ + "按钮颜色", + ( + D_getcolorbutton( + globalconfig, + "buttoncolor2", + callback=lambda: selectcolor( + self, + globalconfig, + "buttoncolor2", + self.buttoncolorbutton2, + ), + name="buttoncolorbutton2", + parent=self, + ), + D_getcolorbutton( + globalconfig, + "buttoncolor3", + callback=lambda: selectcolor( + self, + globalconfig, + "buttoncolor3", + self.buttoncolorbutton3, + ), + name="buttoncolorbutton3", + parent=self, + ), + ), + ], + [ + "按钮大小", + D_getspinbox(5, 100, globalconfig, "buttonsize2"), + ], + ), ), - 2, - ), + 0, + "group", + ) ], [ - ("圆角_半径", 4), ( - D_getspinbox( - 0, - 100, - globalconfig, - "yuanjiao_r", - callback=lambda _: gobject.baseobject.translation_ui.set_color_transparency(), + dict( + title="主题", + grid=( + [ + "明暗", + D_getsimplecombobox( + _TRL(["跟随系统", "明亮", "黑暗"]), + globalconfig, + "darklight2", + lambda _: gobject.baseobject.setcommonstylesheet(), + ), + ], + [ + "明亮主题", + ( + D_getsimplecombobox( + _TRL(["默认"]) + themelist("light"), + globalconfig, + "lighttheme", + functools.partial( + checkthemesettingvisandapply, self, False + ), + ), + functools.partial(createbtnthemelight, self), + ), + ], + [ + "黑暗主题", + ( + D_getsimplecombobox( + themelist("dark"), + globalconfig, + "darktheme", + functools.partial( + checkthemesettingvisandapply, self, True + ), + ), + functools.partial(createbtnthemedark, self), + ), + ], + ), ), - 2, - ), - ], - [], - [ - ("明暗", 4), - ( - D_getsimplecombobox( - _TRL(["跟随系统", "明亮", "黑暗"]), - globalconfig, - "darklight2", - lambda _: gobject.baseobject.setcommonstylesheet(), - ), - 5, - ), + 0, + "group", + ) ], [ - ("明亮主题", 4), ( - D_getsimplecombobox( - _TRL(["默认"]) + themelist("light"), - globalconfig, - "lighttheme", - functools.partial(checkthemesettingvisandapply, self, False), + dict( + title="窗口特效", + grid=( + [ + "翻译窗口", + D_getsimplecombobox( + ["Disable", "Acrylic", "Aero"], + globalconfig, + "WindowEffect", + callback=lambda _: [ + gobject.baseobject.translation_ui.set_color_transparency(), + gobject.baseobject.translation_ui.seteffect(), + ], + ), + ], + [ + "其他", + D_getsimplecombobox( + ["Solid", "Acrylic", "Mica", "MicaAlt"], + globalconfig, + "WindowBackdrop", + callback=lambda _: gobject.baseobject.setcommonstylesheet(), + ), + ], + ), ), - 5, - ), - (functools.partial(createbtnthemelight, self), 0), - ], - [ - ("黑暗主题", 4), - ( - D_getsimplecombobox( - themelist("dark"), - globalconfig, - "darktheme", - functools.partial(checkthemesettingvisandapply, self, True), - ), - 5, - ), - (functools.partial(createbtnthemedark, self), 0), - ], - [], - [ - ("窗口特效_翻译窗口", 4), - ( - D_getsimplecombobox( - ["Disable", "Acrylic", "Aero"], - globalconfig, - "WindowEffect", - callback=lambda _: [ - gobject.baseobject.translation_ui.set_color_transparency(), - gobject.baseobject.translation_ui.seteffect(), - ], - ), - 5, - ), - ], - [ - ("窗口特效_其他", 4), - ( - D_getsimplecombobox( - ["Solid", "Acrylic", "Mica", "MicaAlt"], - globalconfig, - "WindowBackdrop", - callback=lambda _: gobject.baseobject.setcommonstylesheet(), - ), - 5, - ), + 0, + "group", + ) ], ] return uigrid diff --git a/LunaTranslator/LunaTranslator/gui/setting_lang.py b/LunaTranslator/LunaTranslator/gui/setting_lang.py index 3bc22a05..af89c83f 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_lang.py +++ b/LunaTranslator/LunaTranslator/gui/setting_lang.py @@ -3,7 +3,7 @@ from myutils.config import globalconfig, _TRL, static_data, getlanguse from gui.usefulwidget import ( D_getsimplecombobox, getsimplecombobox, - D_getcolorbutton, + D_getIconButton, makescrollgrid, ) @@ -35,7 +35,7 @@ def setTablanglz(self): ], [], [ - ("本软件显示语言(重启生效)", 5), + ("软件显示语言_重启生效", 5), ( D_getsimplecombobox( (static_data["language_list_show"]), globalconfig, "languageuse" @@ -43,14 +43,11 @@ def setTablanglz(self): 5, ), ( - D_getcolorbutton( - globalconfig, - "", + D_getIconButton( callback=lambda: os.startfile( os.path.abspath("./files/lang/{}.json".format(getlanguse())) ), icon="fa.gear", - constcolor="#FF69B4", ), 1, ), diff --git a/LunaTranslator/LunaTranslator/gui/setting_textinput.py b/LunaTranslator/LunaTranslator/gui/setting_textinput.py index c4547a21..7d5e2aa6 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_textinput.py +++ b/LunaTranslator/LunaTranslator/gui/setting_textinput.py @@ -18,7 +18,8 @@ from gui.inputdialog import regexedit from gui.usefulwidget import ( D_getsimplecombobox, D_getspinbox, - D_getcolorbutton, + D_getIconButton, + getIconButton, makegrid, yuitsu_switch, getvboxwidget, @@ -26,10 +27,24 @@ from gui.usefulwidget import ( makesubtab_lazy, makescrollgrid, FocusCombo, - FocusFontCombo + FocusFontCombo, ) +def __create(self): + self.selectbutton = getIconButton( + gobject.baseobject.createattachprocess, icon="fa.gear" + ) + return self.selectbutton + + +def __create2(self): + self.selecthookbutton = getIconButton( + lambda: gobject.baseobject.hookselectdialog.showsignal.emit(), icon="fa.gear" + ) + return self.selecthookbutton + + def gethookgrid(self): grids = [ @@ -40,28 +55,12 @@ def gethookgrid(self): [], [ ("选择游戏", 5), - D_getcolorbutton( - globalconfig, - "", - gobject.baseobject.createattachprocess, - name="selectbutton", - parent=self, - icon="fa.gear", - constcolor="#FF69B4", - ), + functools.partial(__create, self), ("", 5), ], [ ("选择文本", 5), - D_getcolorbutton( - globalconfig, - "", - lambda: gobject.baseobject.hookselectdialog.showsignal.emit(), - name="selecthookbutton", - parent=self, - icon="fa.gear", - constcolor="#FF69B4", - ), + functools.partial(__create2, self), ], [], [ @@ -71,92 +70,101 @@ def gethookgrid(self): [ ("已保存游戏", 5), ( - D_getcolorbutton( - globalconfig, - "", + D_getIconButton( lambda: dialog_savedgame_integrated(self), icon="fa.gamepad", - constcolor="#FF69B4", ), 1, ), ], [], [ - ("代码页", 5), ( - D_getsimplecombobox( - _TRL(static_data["codepage_display"]), - globalconfig, - "codepage_index", - lambda x: gobject.baseobject.textsource.setsettings(), + dict( + title="默认设置", + type="grid", + grid=( + [ + "代码页", + ( + D_getsimplecombobox( + _TRL(static_data["codepage_display"]), + globalconfig, + "codepage_index", + lambda x: gobject.baseobject.textsource.setsettings(), + ), + 4, + ), + ], + [ + "移除非选定hook", + D_getsimpleswitch(globalconfig, "removeuseless"), + ], + [ + "过滤反复刷新的句子", + D_getsimpleswitch(globalconfig, "direct_filterrepeat"), + ], + [ + "刷新延迟(ms)", + ( + D_getspinbox( + 0, + 10000, + globalconfig, + "textthreaddelay", + callback=lambda x: gobject.baseobject.textsource.setsettings(), + ), + 2, + ), + ], + [ + "最大缓冲区长度", + ( + D_getspinbox( + 0, + 1000000, + globalconfig, + "maxBufferSize", + callback=lambda x: gobject.baseobject.textsource.setsettings(), + ), + 2, + ), + ], + [ + "最大缓存文本长度", + ( + D_getspinbox( + 0, + 1000000000, + globalconfig, + "maxHistorySize", + callback=lambda x: gobject.baseobject.textsource.setsettings(), + ), + 2, + ), + ], + [ + "过滤包含乱码的文本行", + D_getsimpleswitch(globalconfig, "filter_chaos_code"), + D_getIconButton( + icon="fa.gear", + callback=lambda: codeacceptdialog(self), + ), + ], + [ + "区分人名和文本", + D_getsimpleswitch(globalconfig, "allow_set_text_name"), + ], + [ + "使用YAPI注入", + D_getsimpleswitch(globalconfig, "use_yapi"), + ], + ), ), - 8, - ), + 0, + "group", + ) ], - [ - ("移除非选定hook", 5), - (D_getsimpleswitch(globalconfig, "removeuseless"), 1), - ], - [ - ("过滤反复刷新的句子", 5), - (D_getsimpleswitch(globalconfig, "direct_filterrepeat"), 1), - ], - [ - ("刷新延迟(ms)", 5), - ( - D_getspinbox( - 0, - 10000, - globalconfig, - "textthreaddelay", - callback=lambda x: gobject.baseobject.textsource.setsettings(), - ), - 3, - ), - ], - [ - ("最大缓冲区长度", 5), - ( - D_getspinbox( - 0, - 1000000, - globalconfig, - "maxBufferSize", - callback=lambda x: gobject.baseobject.textsource.setsettings(), - ), - 3, - ), - ], - [ - ("最大缓存文本长度", 5), - ( - D_getspinbox( - 0, - 1000000000, - globalconfig, - "maxHistorySize", - callback=lambda x: gobject.baseobject.textsource.setsettings(), - ), - 3, - ), - ], - [ - ("过滤包含乱码的文本行", 5), - (D_getsimpleswitch(globalconfig, "filter_chaos_code"), 1), - ( - D_getcolorbutton( - globalconfig, - "", - icon="fa.gear", - constcolor="#FF69B4", - callback=lambda: codeacceptdialog(self), - ), - 1, - ), - ], - [("区分人名和文本", 5), D_getsimpleswitch(globalconfig, "allow_set_text_name")], - [("使用YAPI注入", 5), D_getsimpleswitch(globalconfig, "use_yapi")], ] return grids @@ -288,12 +296,9 @@ def gethookembedgrid(self): grids = [ [ ("导出翻译补丁", 5), - D_getcolorbutton( - globalconfig, - "", + D_getIconButton( callback=lambda x: exportchspatch(self), icon="fa.gear", - constcolor="#FF69B4", ), ], [], @@ -379,14 +384,11 @@ def gethookembedgrid(self): [ ("内嵌安全性检查", 5), D_getsimpleswitch(globalconfig["embedded"], "safecheck_use"), - D_getcolorbutton( - globalconfig, - "", + D_getIconButton( callback=lambda x: regexedit( self, globalconfig["embedded"]["safecheckregexs"] ), icon="fa.gear", - constcolor="#FF69B4", ), ], ] @@ -409,40 +411,58 @@ def getTabclip(self): def outputgrid(self): grids = [ - [("自动输出提取的文本", 15)], + ["自动输出提取的文本"], [], - [("剪贴板", 0)], [ - "", - ("输出到剪贴板", 5), - (D_getsimpleswitch(globalconfig["textoutputer"]["clipboard"], "use"), 1), - ], - [("WebSocket", -1)], - [ - "", - ("输出到WebSocket", 5), ( - D_getsimpleswitch( - globalconfig["textoutputer"]["websocket"], - "use", - callback=lambda _: gobject.baseobject.startoutputer_re("websocket"), + dict( + title="剪贴板", + grid=( + [ + "自动输出", + D_getsimpleswitch( + globalconfig["textoutputer"]["clipboard"], "use" + ), + ], + ), ), - 1, - ), + 0, + "group", + ) ], + [], [ - "", - ("端口号", 5), ( - D_getspinbox( - 0, - 65535, - globalconfig["textoutputer"]["websocket"], - "port", - callback=lambda _: gobject.baseobject.startoutputer_re("websocket"), + dict( + title="WebSocket", + grid=( + [ + "自动输出", + D_getsimpleswitch( + globalconfig["textoutputer"]["websocket"], + "use", + callback=lambda _: gobject.baseobject.startoutputer_re( + "websocket" + ), + ), + ], + [ + "端口号", + D_getspinbox( + 0, + 65535, + globalconfig["textoutputer"]["websocket"], + "port", + callback=lambda _: gobject.baseobject.startoutputer_re( + "websocket" + ), + ), + ], + ), ), - 3, - ), + 0, + "group", + ) ], ] return grids diff --git a/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py b/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py index 84fa57fa..b1b518de 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py +++ b/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py @@ -1,13 +1,14 @@ from qtsymbols import * import functools, os import gobject -from myutils.config import globalconfig, ocrsetting, _TRL, ocrerrorfix +from myutils.config import globalconfig, ocrsetting, _TRL, ocrerrorfix, _TR from gui.inputdialog import autoinitdialog, postconfigdialog, autoinitdialog_items from gui.usefulwidget import ( D_getsimplecombobox, D_getspinbox, - D_getcolorbutton, + D_getIconButton, yuitsu_switch, + D_getcolorbutton, D_getsimpleswitch, selectcolor, ) @@ -26,6 +27,7 @@ def __label2(self): def getocrgrid(self): grids = [] + grids_source = [] i = 0 self.ocrswitchs = {} @@ -37,14 +39,11 @@ def getocrgrid(self): continue if name in ocrsetting: items = autoinitdialog_items(ocrsetting[name]) - _3 = D_getcolorbutton( - globalconfig, - "", + _3 = D_getIconButton( callback=functools.partial( autoinitdialog, self, globalconfig["ocr"][name]["name"], 800, items ), icon="fa.gear", - constcolor="#FF69B4", ) else: @@ -73,145 +72,223 @@ def getocrgrid(self): _3, ] if i % 3 == 2: - grids.append(line) + grids_source.append(line) line = [] else: line += [""] i += 1 if len(line): - grids.append(line) + grids_source.append(line) + + def vissolvebtn(text): + _ = QPushButton() + _.setText(text) + _.clicked.connect(gobject.baseobject.createshowocrimage) + return _ grids += [ - [], - [(("竖向OCR识别"), 12), D_getsimpleswitch(globalconfig, "verticalocr")], - [(("合并多行识别结果"), 12), D_getsimpleswitch(globalconfig, "ocrmergelines")], - [], [ - ("OCR预处理方法", 8), ( - D_getsimplecombobox( - _TRL(["不处理", "灰度化", "阈值二值化", "OTSU二值化"]), - globalconfig, - "ocr_presolve_method", - ), - 12, - ), - "", - ], - [ - ("查看处理效果", 6), - D_getcolorbutton( - globalconfig, - "", - gobject.baseobject.createshowocrimage, - icon="fa.picture-o", - constcolor="#FF69B4", - ), - "", - (("二值化阈值"), 8), - (D_getspinbox(0, 255, globalconfig, "binary_thresh"), 4), + dict(title="引擎", type="grid", grid=grids_source), + 0, + "group", + ) ], [], - [ - ("OCR自动化方法", 8), - ( - D_getsimplecombobox( - _TRL(["分析图像更新", "周期执行", "分析图像更新+周期执行"]), - globalconfig, - "ocr_auto_method", - ), - 12, - ), - ], - [ - (("执行周期(s)"), 8), - ( - D_getspinbox( - 0.1, 100, globalconfig, "ocr_interval", double=True, step=0.1 - ), - 4, - ), - ], - [ - (("图像稳定性阈值"), 8), - ( - D_getspinbox( - 0, 1, globalconfig, "ocr_stable_sim", double=True, step=0.01, dec=3 - ), - 4, - ), - (functools.partial(__label1, self), 0), - ], - [ - (("图像一致性阈值"), 8), - ( - D_getspinbox( - 0, 1, globalconfig, "ocr_diff_sim", double=True, step=0.01, dec=3 - ), - 4, - ), - (functools.partial(__label2, self), 0), - ], - [ - (("文本相似度阈值"), 8), - (D_getspinbox(0, 100000, globalconfig, "ocr_text_diff"), 4), - ], - [], - [(("多重区域模式"), 12), D_getsimpleswitch(globalconfig, "multiregion")], - [(("记忆选定区域"), 12), D_getsimpleswitch(globalconfig, "rememberocrregions")], + [("竖向识别"), D_getsimpleswitch(globalconfig, "verticalocr"), ("", 4)], [], [ - (("OCR范围框颜色"), 12), ( - D_getcolorbutton( - globalconfig, - "ocrrangecolor", - callback=lambda: selectcolor( - self, - globalconfig, - "ocrrangecolor", - self.ocrrangecolor_button, - callback=lambda: gobject.baseobject.textsource.setstyle(), - ), - name="ocrrangecolor_button", - parent=self, + dict( + title="预处理", + type="grid", + grid=[ + [ + "预处理方法", + D_getsimplecombobox( + _TRL(["不处理", "灰度化", "阈值二值化", "OTSU二值化"]), + globalconfig, + "ocr_presolve_method", + ), + functools.partial(vissolvebtn, _TR("查看处理效果")), + ], + [ + "二值化阈值", + D_getspinbox(0, 255, globalconfig, "binary_thresh"), + ], + ], ), - 1, - ), + 0, + "group", + ) ], [ - (("OCR范围框宽度"), 12), ( - D_getspinbox( - 1, - 100, - globalconfig, - "ocrrangewidth", - callback=lambda x: gobject.baseobject.textsource.setstyle(), + dict( + title="后处理", + type="grid", + grid=[ + [ + (("合并多行识别结果"), 12), + D_getsimpleswitch(globalconfig, "ocrmergelines"), + ("", 12), + ], + [ + (("易错内容修正"), 12), + D_getsimpleswitch(ocrerrorfix, "use"), + D_getIconButton( + callback=functools.partial( + postconfigdialog, + self, + ocrerrorfix["args"], + "易错内容修正", + ), + icon="fa.gear", + ), + ], + ], ), - 4, - ), + 0, + "group", + ) ], [ - (("选取OCR范围后立即进行一次识别"), 12), - D_getsimpleswitch(globalconfig, "ocrafterrangeselect"), - ], - [ - (("选取OCR范围后显示范围框"), 12), - D_getsimpleswitch(globalconfig, "showrangeafterrangeselect"), - ], - [ - (("OCR识别易错内容修正"), 12), - D_getsimpleswitch(ocrerrorfix, "use"), - D_getcolorbutton( - globalconfig, - "", - callback=functools.partial( - postconfigdialog, self, ocrerrorfix["args"], "OCR识别易错内容修正" + ( + dict( + title="自动化执行", + type="grid", + grid=[ + [ + ("自动化执行方法", 8), + ( + D_getsimplecombobox( + _TRL( + [ + "分析图像更新", + "周期执行", + "分析图像更新+周期执行", + ] + ), + globalconfig, + "ocr_auto_method", + ), + 12, + ), + ], + [ + (("执行周期(s)"), 8), + ( + D_getspinbox( + 0.1, + 100, + globalconfig, + "ocr_interval", + double=True, + step=0.1, + ), + 4, + ), + ], + [ + (("图像稳定性阈值"), 8), + ( + D_getspinbox( + 0, + 1, + globalconfig, + "ocr_stable_sim", + double=True, + step=0.01, + dec=3, + ), + 4, + ), + (functools.partial(__label1, self), 0), + ], + [ + (("图像一致性阈值"), 8), + ( + D_getspinbox( + 0, + 1, + globalconfig, + "ocr_diff_sim", + double=True, + step=0.01, + dec=3, + ), + 4, + ), + (functools.partial(__label2, self), 0), + ], + [ + (("文本相似度阈值"), 8), + (D_getspinbox(0, 100000, globalconfig, "ocr_text_diff"), 4), + ], + ], ), - icon="fa.gear", - constcolor="#FF69B4", - ), + 0, + "group", + ) + ], + [ + ( + dict( + title="其他", + type="grid", + grid=[ + [ + "多重区域模式", + D_getsimpleswitch(globalconfig, "multiregion"), + ], + [ + "记忆选定区域", + D_getsimpleswitch(globalconfig, "rememberocrregions"), + ], + [ + "范围框颜色", + D_getcolorbutton( + globalconfig, + "ocrrangecolor", + callback=lambda: selectcolor( + self, + globalconfig, + "ocrrangecolor", + self.ocrrangecolor_button, + callback=lambda: gobject.baseobject.textsource.setstyle(), + ), + name="ocrrangecolor_button", + parent=self, + ), + ], + [ + "范围框宽度", + ( + D_getspinbox( + 1, + 100, + globalconfig, + "ocrrangewidth", + callback=lambda x: gobject.baseobject.textsource.setstyle(), + ), + 2, + ), + ], + [ + "选取OCR范围后立即进行一次识别", + D_getsimpleswitch(globalconfig, "ocrafterrangeselect"), + ], + [ + "选取OCR范围后显示范围框", + D_getsimpleswitch( + globalconfig, "showrangeafterrangeselect" + ), + ], + ], + ), + 0, + "group", + ) ], ] return grids diff --git a/LunaTranslator/LunaTranslator/gui/setting_translate.py b/LunaTranslator/LunaTranslator/gui/setting_translate.py index 012edb4d..ac1d54d9 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_translate.py +++ b/LunaTranslator/LunaTranslator/gui/setting_translate.py @@ -11,7 +11,7 @@ from gui.inputdialog import autoinitdialog, autoinitdialog_items from gui.usefulwidget import ( D_getspinbox, getspinbox, - D_getcolorbutton, + D_getcolorbutton,D_getIconButton, D_getsimpleswitch, selectcolor, makegrid, @@ -44,9 +44,7 @@ def initsome11(self, l, label=None): if fanyi in translatorsetting: items = autoinitdialog_items(translatorsetting[fanyi]) - last = D_getcolorbutton( - globalconfig, - "", + last = D_getIconButton( callback=functools.partial( autoinitdialog, self, @@ -54,16 +52,12 @@ def initsome11(self, l, label=None): 800, items, ), - icon="fa.gear", - constcolor="#FF69B4", + icon="fa.gear", ) elif fanyi == "selfbuild": - last = D_getcolorbutton( - globalconfig, - "", + last = D_getIconButton( callback=lambda: selectdebugfile("./userconfig/selfbuild.py"), - icon="fa.gear", - constcolor="#FF69B4", + icon="fa.gear", ) else: last = "" @@ -255,14 +249,11 @@ def setTabTwo_lazy(self, basel): [ ("Chromium_路径", 8), ( - D_getcolorbutton( - globalconfig, - "", + D_getIconButton( callback=functools.partial( autoinitdialog, self, "Chromium_路径", 800, _items ), - icon="fa.gear", - constcolor="#FF69B4", + icon="fa.gear", ) ), ], diff --git a/LunaTranslator/LunaTranslator/gui/setting_transopti.py b/LunaTranslator/LunaTranslator/gui/setting_transopti.py index b805306a..ad966bcc 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_transopti.py +++ b/LunaTranslator/LunaTranslator/gui/setting_transopti.py @@ -13,9 +13,9 @@ from myutils.config import ( _TRL, ) from gui.codeacceptdialog import codeacceptdialog -from gui.usefulwidget import ( - getcolorbutton, - D_getcolorbutton, +from gui.usefulwidget import ( + D_getIconButton, + getIconButton, D_getsimpleswitch, makescrollgrid, getvboxwidget, @@ -42,12 +42,9 @@ def getcomparelayout(self): layout = QHBoxLayout() fromtext = QPlainTextEdit() totext = QPlainTextEdit() - solvebutton = getcolorbutton( - globalconfig, - "", + solvebutton = getIconButton( callback=lambda: totext.setPlainText(POSTSOLVE(fromtext.toPlainText())), - icon="fa.chevron-right", - constcolor="#FF69B4", + icon="fa.chevron-right", ) layout.addWidget(fromtext) @@ -100,22 +97,16 @@ def setTab7_lazy(self, basel): for i, post in enumerate(sortlist): if post == "_11": - config = D_getcolorbutton( - globalconfig, - "", + config = D_getIconButton( callback=lambda: selectdebugfile("./userconfig/mypost.py"), - icon="fa.gear", - constcolor="#FF69B4", + icon="fa.gear", ) else: if post not in postprocessconfig: continue if post == "_remove_chaos": - config = D_getcolorbutton( - globalconfig, - "", - icon="fa.gear", - constcolor="#FF69B4", + config = D_getIconButton( + icon="fa.gear", callback=lambda: codeacceptdialog(self), ) elif "args" in postprocessconfig[post]: @@ -135,29 +126,20 @@ def setTab7_lazy(self, basel): 600, items, ) - config = D_getcolorbutton( - globalconfig, - "", + config = D_getIconButton( callback=callback, - icon="fa.gear", - constcolor="#FF69B4", + icon="fa.gear", ) else: config = "" - button_up = D_getcolorbutton( - globalconfig, - "", + button_up = D_getIconButton( callback=functools.partial(changerank, post, True), - icon="fa.arrow-up", - constcolor="#FF69B4", + icon="fa.arrow-up", ) - button_down = D_getcolorbutton( - globalconfig, - "", + button_down = D_getIconButton( callback=functools.partial(changerank, post, False), - icon="fa.arrow-down", - constcolor="#FF69B4", + icon="fa.arrow-down", ) l = [ @@ -178,17 +160,14 @@ def setTab7_lazy(self, basel): ) setting = loadpostsettingwindowmethod(name) - def __(_f, _1, _2): + def __(_f, _1): return _f(_1) if setting: grids2[-1].append( - D_getcolorbutton( - globalconfig, - "", + D_getIconButton( callback=functools.partial(__, setting, self), - icon="fa.gear", - constcolor="#FF69B4", + icon="fa.gear", ) ) grids2 += [[("", 12)]] diff --git a/LunaTranslator/LunaTranslator/gui/setting_tts.py b/LunaTranslator/LunaTranslator/gui/setting_tts.py index f9c068e0..1b2a1c61 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_tts.py +++ b/LunaTranslator/LunaTranslator/gui/setting_tts.py @@ -7,7 +7,7 @@ from gui.usefulwidget import ( D_getsimplecombobox, D_getspinbox, makescrollgrid, - D_getcolorbutton, + D_getIconButton, yuitsu_switch, FocusCombo, D_getsimpleswitch, @@ -65,9 +65,7 @@ def getttsgrid(self): if "args" in globalconfig["reader"][name]: items = autoinitdialog_items(globalconfig["reader"][name]) items[-1]["callback"] = gobject.baseobject.startreader - _3 = D_getcolorbutton( - globalconfig, - "", + _3 = D_getIconButton( callback=functools.partial( autoinitdialog, self, @@ -75,8 +73,7 @@ def getttsgrid(self): 800, items, ), - icon="fa.gear", - constcolor="#FF69B4", + icon="fa.gear", ) else: @@ -116,61 +113,95 @@ def getttsgrid(self): def setTab5lz(self): - - grids = getttsgrid(self) + grids = [] grids += [ - [], - [("选择声音", 6), (functools.partial(createvoicecombo, self), 15)], [ - ("语速:(-10~10)", 6), - (D_getspinbox(-10, 10, globalconfig["ttscommon"], "rate"), 3), - ], - [ - ("音量:(0~100)", 6), - (D_getspinbox(0, 100, globalconfig["ttscommon"], "volume"), 3), - ], - [("自动朗读", 6), (D_getsimpleswitch(globalconfig, "autoread"), 1)], - [("不被打断", 6), (D_getsimpleswitch(globalconfig, "ttsnointerrupt"), 1)], - [ - ("朗读原文", 6), - (D_getsimpleswitch(globalconfig, "read_raw"), 1), - "", - "", - ("朗读翻译", 6), - (D_getsimpleswitch(globalconfig, "read_trans"), 1), - ], - [ - ("朗读的翻译", 6), ( - D_getsimplecombobox( - _TRL( - [ - globalconfig["fanyi"][x]["name"] - for x in globalconfig["fanyi"] - ] - ), - globalconfig, - "read_translator", - ), - 15, - ), + dict(title="引擎", type="grid", grid=getttsgrid(self)), + 0, + "group", + ) ], - [], [ - ("语音修正", 6), - D_getsimpleswitch(globalconfig["ttscommon"], "tts_repair"), - D_getcolorbutton( - globalconfig, - "", - callback=lambda x: noundictconfigdialog1( - self, - globalconfig["ttscommon"]["tts_repair_regex"], - "语音修正", - ["正则", "原文", "替换"], + ( + dict( + title="声音", + type="grid", + grid=[ + [ + "选择声音", + (functools.partial(createvoicecombo, self), 4), + ], + [ + "语速:(-10~10)", + D_getspinbox(-10, 10, globalconfig["ttscommon"], "rate"), + ], + [ + "音量:(0~100)", + D_getspinbox(0, 100, globalconfig["ttscommon"], "volume"), + ], + ], ), - icon="fa.gear", - constcolor="#FF69B4", - ), + 0, + "group", + ) + ], + [ + ( + dict( + title="行为", + type="grid", + grid=[ + [ + "自动朗读", + D_getsimpleswitch(globalconfig, "autoread"), + ], + [ + "不被打断", + D_getsimpleswitch(globalconfig, "ttsnointerrupt"), + ], + [ + "朗读原文", + D_getsimpleswitch(globalconfig, "read_raw"), + ], + [ + "朗读翻译", + D_getsimpleswitch(globalconfig, "read_trans"), + ], + [ + "朗读的翻译", + ( + D_getsimplecombobox( + _TRL( + [ + globalconfig["fanyi"][x]["name"] + for x in globalconfig["fanyi"] + ] + ), + globalconfig, + "read_translator", + ), + 4, + ), + ], + [ + "语音修正", + D_getsimpleswitch(globalconfig["ttscommon"], "tts_repair"), + D_getIconButton( + callback=lambda x: noundictconfigdialog1( + self, + globalconfig["ttscommon"]["tts_repair_regex"], + "语音修正", + ["正则", "原文", "替换"], + ), + icon="fa.gear", + ), + ], + ], + ), + 0, + "group", + ) ], ] return grids diff --git a/LunaTranslator/LunaTranslator/gui/showword.py b/LunaTranslator/LunaTranslator/gui/showword.py index c29f705f..c65bc6eb 100644 --- a/LunaTranslator/LunaTranslator/gui/showword.py +++ b/LunaTranslator/LunaTranslator/gui/showword.py @@ -21,8 +21,8 @@ from gui.usefulwidget import ( listediterline, getsimpleswitch, getsimplekeyseq, - getcolorbutton, makesubtab_lazy, + getIconButton, tabadd_lazy, ) @@ -502,14 +502,11 @@ class AnkiWindow(QWidget): self.audiopath, recordbtn1, soundbutton, - getcolorbutton( - "", - "", + getIconButton( functools.partial( self.selecfile, self.audiopath ), icon="fa.gear", - constcolor="#FF69B4", ), ] ), @@ -519,14 +516,11 @@ class AnkiWindow(QWidget): self.audiopath_sentence, recordbtn2, soundbutton2, - getcolorbutton( - "", - "", + getIconButton( functools.partial( self.selecfile, self.audiopath_sentence ), icon="fa.gear", - constcolor="#FF69B4", ), ] ), @@ -535,14 +529,11 @@ class AnkiWindow(QWidget): QLabel(_TR("截图")), self.editpath, cropbutton, - getcolorbutton( - "", - "", + getIconButton( functools.partial( self.selecfile, self.editpath ), icon="fa.gear", - constcolor="#FF69B4", ), ] ), @@ -737,7 +728,8 @@ class searchwordW(closeashidewindow): def showresfun(self, timestamp, k, res): if self.current != timestamp: return - self.cache_results[k] = res + if res is None: + self.cache_results[k] = res thisp = globalconfig["cishu"][k]["args"]["priority"] idx = 0 @@ -783,7 +775,9 @@ class searchwordW(closeashidewindow): soundbutton.clicked.connect(self.langdu) self.searchlayout.addWidget(soundbutton) - ankiconnect = statusbutton(icons=["fa.adn"], colors=["", "#FF69B4"]) + ankiconnect = statusbutton( + icons=["fa.adn"], colors=["", globalconfig["buttoncolor2"]] + ) ankiconnect.statuschanged2.connect(self.onceaddankiwindow) self.searchlayout.addWidget(ankiconnect) diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index c7f3d406..126c8f98 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -16,6 +16,14 @@ from gui.edittext import edittrans from gui.dialog_savedgame import browserdialog, dialog_savedgame_integrated +def contrastcolor(color): + color = QColor(globalconfig["buttoncolor"]) + r, g, b, a = color.getRgb() + + r, g, b = [hex((_ + 128) % 256)[2:] for _ in (r, g, b)] + return f"#{r}{g}{b}" + + class QUnFrameWindow(resizableframeless): displayglobaltooltip = pyqtSignal(str) displayres = pyqtSignal(dict) @@ -248,13 +256,14 @@ class QUnFrameWindow(resizableframeless): "bindwindow": self.isbindedwindow, "keepontop": globalconfig["keepontop"], } - onstatecolor = "#FF69B4" self._TitleLabel.setFixedHeight(int(globalconfig["buttonsize"] * 1.5)) for name in self.buttons: if name in colorstate: color = ( - onstatecolor if colorstate[name] else globalconfig["buttoncolor"] + contrastcolor(globalconfig["buttoncolor"]) + if colorstate[name] + else globalconfig["buttoncolor"] ) else: color = globalconfig["buttoncolor"] @@ -431,7 +440,6 @@ class QUnFrameWindow(resizableframeless): windows.SetForegroundWindow(int(self.winId())) def aftershowdosomething(self): - self.showline(clear=True, text=_TR("欢迎使用"), origin=False) windows.SetForegroundWindow(int(self.winId())) self.refreshtoolicon() @@ -584,6 +592,7 @@ class QUnFrameWindow(resizableframeless): self.initvalues() self.initsignals() self._TitleLabel = QLabel(self) + self._TitleLabel.setMouseTracking(True) self.addbuttons() self.translate_text = Textbrowser(self) self.translate_text.contentsChanged.connect(self.textAreaChanged) @@ -827,16 +836,19 @@ class QUnFrameWindow(resizableframeless): def textAreaChanged(self, size: QSize): - if globalconfig["fixedheight"]: - return if self.translate_text.cleared: return - newHeight = size.height() + self.translate_text._padding - width = self.width() - self.resize( - width, - int(newHeight + globalconfig["buttonsize"] * 1.5), + if not (globalconfig["auto_expand"] or globalconfig["auto_shrink"]): + return + newHeight = ( + size.height() + + self.translate_text._padding + + int(globalconfig["buttonsize"] * 1.5) ) + if (newHeight > self.height() and globalconfig["auto_expand"]) or ( + newHeight < self.height() and globalconfig["auto_shrink"] + ): + self.resize(self.width(), newHeight) def clickRange(self, auto): if globalconfig["sourcestatus2"]["ocr"]["use"] == False: diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index e388c7fc..de942a55 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -176,20 +176,174 @@ class closeashidewindow(saveposwindow): super().closeEvent(event) -class MySwitch(QPushButton): - def __init__( - self, parent=None, sign=True, enable=True, icons=None, size=25, colors=None - ): +class MySwitch(QWidget): + clicked = pyqtSignal(bool) + + def sizeHint(self): + return QSize( + int(1.62 * globalconfig["buttonsize2"]), globalconfig["buttonsize2"] + ) + + def __init__(self, parent=None, sign=True, enable=True): + super().__init__(parent) + self.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) + self.checked = sign + self.setCursor(Qt.CursorShape.PointingHandCursor) + self.animation = QVariantAnimation() + self.animation.setDuration(80) + self.animation.setStartValue(0) + self.animation.setEndValue(20) + self.__currv = 0 + if sign: + self.__currv = 20 + self.animation.valueChanged.connect(self.update11) + self.animation.finished.connect(self.onAnimationFinished) + self.enable = enable + + def setEnabled(self, enable): + self.enable = enable + self.update() + + def isEnabled(self): + return self.enable + + def isChecked(self): + return self.checked + + def setChecked(self, check): + if check == self.checked: + return + self.checked = check + self.animation.setDirection( + QVariantAnimation.Direction.Forward + if self.checked + else QVariantAnimation.Direction.Backward + ) + self.animation.start() + + def update11(self): + self.__currv = self.animation.currentValue() + self.update() + + def paintEvent(self, event): + painter = QPainter(self) + painter.setRenderHint(QPainter.RenderHint.Antialiasing) + painter.setPen(Qt.PenStyle.NoPen) + + __ = QColor( + [globalconfig["buttoncolor3"], globalconfig["buttoncolor2"]][self.checked] + ) + if not self.enable: + __ = QColor( + max(0, (__.red() - 64)), + max( + 0, + (__.green() - 64), + ), + max(0, (__.blue() - 64)), + ) + painter.setBrush(__) + bigw = self.size().width() - self.sizeHint().width() + bigh = self.size().height() - self.sizeHint().height() + x = bigw // 2 + y = bigh // 2 + painter.drawRoundedRect( + QRect(x, y, self.sizeHint().width(), self.sizeHint().height()), + self.sizeHint().height() // 2, + self.sizeHint().height() // 2, + ) + + offset = int( + self.__currv * (self.sizeHint().width() - self.sizeHint().height()) / 20 + ) + painter.setBrush(QColor(255, 255, 255)) + painter.drawEllipse( + QPoint( + x + self.sizeHint().height() // 2 + offset, + y + self.sizeHint().height() // 2, + ), + self.sizeHint().height() * 0.35, + self.sizeHint().height() * 0.35, + ) + + def mouseReleaseEvent(self, event) -> None: + if not self.enable: + return + if event.button() == Qt.MouseButton.LeftButton: + self.checked = not self.checked + self.clicked.emit(self.checked) + self.animation.setDirection( + QVariantAnimation.Direction.Forward + if self.checked + else QVariantAnimation.Direction.Backward + ) + self.animation.start() + + def onAnimationFinished(self): + pass + + +class IconButton(QWidget): + clicked = pyqtSignal() + + def sizeHint(self): + return QSize( + int(1.42 * globalconfig["buttonsize2"]), + int(1.42 * globalconfig["buttonsize2"]), + ) + + def __init__(self, icon, enable=True, qicon=None, parent=None): + super().__init__(parent) + self.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) + self.enable = enable + self._icon = icon + self._qicon = qicon + + def setEnabled(self, enable): + self.enable = enable + self.update() + + def isEnabled(self): + return self.enable + + def paintEvent(self, event): + painter = QPainter(self) + painter.setRenderHint(QPainter.RenderHint.Antialiasing) + painter.setPen(Qt.PenStyle.NoPen) + if self._qicon: + icon = self._qicon + + else: + + __ = QColor(globalconfig["buttoncolor2"]) + if not self.enable: + __ = QColor( + max(0, (__.red() - 64)), + max( + 0, + (__.green() - 64), + ), + max(0, (__.blue() - 64)), + ) + icon: QIcon = qtawesome.icon(self._icon, color=__) + bigw = self.size().width() - self.sizeHint().width() + bigh = self.size().height() - self.sizeHint().height() + x = bigw // 2 + y = bigh // 2 + painter.drawPixmap(x, y, icon.pixmap(self.sizeHint())) + + def mouseReleaseEvent(self, event) -> None: + if not self.enable: + return + if event.button() == Qt.MouseButton.LeftButton: + self.clicked.emit() + + +class MySwitch2(QPushButton): + def __init__(self, parent=None, sign=True, enable=True, icons=None, size=25): self.status1 = 0 self.status2 = 0 - if colors is None: - colors = [ - "#7f7f7f", - "#afafaf", - "#FFa9d4", - "#FF69B4", - ] - self.colors = colors + if icons is None: icons = ["fa.times", "fa.check"] self.icons = icons @@ -209,25 +363,37 @@ class MySwitch(QPushButton): self.setCheckable(True) self.setChecked(sign) - def setChecked(self, a0): - super().setChecked(a0) - self.status1 = a0 + def __seticon(self): + + __ = QColor( + [globalconfig["buttoncolor3"], globalconfig["buttoncolor2"]][self.status1] + ) + if not self.status2: + __ = QColor( + max(0, (__.red() - 64)), + max( + 0, + (__.green() - 64), + ), + max(0, (__.blue() - 64)), + ) + color = __ self.setIcon( qtawesome.icon( self.icons[self.status1], - color=self.colors[self.status1 * 2 + self.status2], + color=color, ) ) + def setChecked(self, a0): + super().setChecked(a0) + self.status1 = a0 + self.__seticon() + def setEnabled(self, a0): super().setEnabled(a0) self.status2 = a0 - self.setIcon( - qtawesome.icon( - self.icons[self.status1], - color=self.colors[self.status1 * 2 + self.status2], - ) - ) + self.__seticon() class resizableframeless(saveposwindow): @@ -236,84 +402,103 @@ class resizableframeless(saveposwindow): self.setMouseTracking(True) self._padding = 5 - # 设置鼠标跟踪判断扳机默认值 + self.resetflags() + + def resetflags(self): self._move_drag = False - self._corner_drag = False + self._corner_drag_youxia = False self._bottom_drag = False - self._lcorner_drag = False + self._top_drag = False + self._corner_drag_zuoxia = False self._right_drag = False self._left_drag = False + self._corner_drag_zuoshang = False + self._corner_drag_youshang = False def resizeEvent(self, e): if self._move_drag == False: self._right_rect = [ self.width() - self._padding, - self.width() + 1, - 0, + self.width() + self._padding, + self._padding, + self.height() - self._padding, + ] + self._left_rect = [ + -self._padding, + self._padding, + self._padding, self.height() - self._padding, ] - self._left_rect = [-1, self._padding, 0, self.height() - self._padding] self._bottom_rect = [ self._padding, self.width() - self._padding, self.height() - self._padding, - self.height() + 1, + self.height() + self._padding, ] - self._corner_rect = [ + self._top_rect = [ + self._padding, self.width() - self._padding, - self.width() + 1, - self.height() - self._padding, - self.height() + 1, + -self._padding, + self._padding, ] - self._lcorner_rect = [ - -1, + self._corner_youxia = [ + self.width() - self._padding, + self.width() + self._padding, + self.height() - self._padding, + self.height() + self._padding, + ] + self._corner_zuoxia = [ + -self._padding, self._padding, self.height() - self._padding, - self.height() + 1, + self.height() + self._padding, + ] + + self._corner_youshang = [ + self.width() - self._padding, + self.width() + self._padding, + -self._padding, + self._padding, + ] + + self._corner_zuoshang = [ + -self._padding, + self._padding, + -self._padding, + self._padding, ] super().resizeEvent(e) def mousePressEvent(self, event: QMouseEvent): - # 重写鼠标点击的事件 if isqt5: gpos = event.globalPos() else: gpos = event.globalPosition().toPoint() - if (event.button() == Qt.MouseButton.LeftButton) and ( - isinrect(event.pos(), self._corner_rect) - ): - # 鼠标左键点击右下角边界区域 - self._corner_drag = True - elif (event.button() == Qt.MouseButton.LeftButton) and ( - isinrect(event.pos(), self._right_rect) - ): - # 鼠标左键点击右侧边界区域 + if event.button() != Qt.MouseButton.LeftButton: + return + self.startxp = gpos - self.pos() + self.starty = gpos.y() + self.startx = gpos.x() + self.starth = self.height() + self.startw = self.width() + if isinrect(event.pos(), self._corner_youxia): + self._corner_drag_youxia = True + elif isinrect(event.pos(), self._right_rect): self._right_drag = True - elif (event.button() == Qt.MouseButton.LeftButton) and ( - isinrect(event.pos(), self._left_rect) - ): - # 鼠标左键点击右侧边界区域 + elif isinrect(event.pos(), self._left_rect): self._left_drag = True - self.startxp = gpos - self.pos() - self.startx = gpos.x() - self.startw = self.width() - elif (event.button() == Qt.MouseButton.LeftButton) and ( - isinrect(event.pos(), self._bottom_rect) - ): - # 鼠标左键点击下侧边界区域 + elif isinrect(event.pos(), self._top_rect): + self._top_drag = True + elif isinrect(event.pos(), self._bottom_rect): self._bottom_drag = True - elif (event.button() == Qt.MouseButton.LeftButton) and ( - isinrect(event.pos(), self._lcorner_rect) - ): - # 鼠标左键点击下侧边界区域 - self._lcorner_drag = True - self.startxp = gpos - self.pos() - self.startx = gpos.x() - self.startw = self.width() - # and (event.y() < self._TitleLabel.height()): - elif event.button() == Qt.MouseButton.LeftButton: - # 鼠标左键点击标题栏区域 + elif isinrect(event.pos(), self._corner_zuoxia): + self._corner_drag_zuoxia = True + elif isinrect(event.pos(), self._corner_youshang): + self._corner_drag_youshang = True + elif isinrect(event.pos(), self._corner_zuoshang): + self._corner_drag_zuoshang = True + else: self._move_drag = True self.move_DragPosition = gpos - self.pos() @@ -322,65 +507,78 @@ class resizableframeless(saveposwindow): return super().leaveEvent(a0) def mouseMoveEvent(self, event): - # 判断鼠标位置切换鼠标手势 pos = event.pos() if isqt5: gpos = event.globalPos() else: gpos = event.globalPosition().toPoint() - if self._move_drag == False: - if isinrect(pos, self._corner_rect): - self.setCursor(Qt.CursorShape.SizeFDiagCursor) - elif isinrect(pos, self._lcorner_rect): - self.setCursor(Qt.CursorShape.SizeBDiagCursor) - elif isinrect(pos, self._bottom_rect): - self.setCursor(Qt.CursorShape.SizeVerCursor) - elif isinrect(pos, self._right_rect): - self.setCursor(Qt.CursorShape.SizeHorCursor) - elif isinrect(pos, self._left_rect): - self.setCursor(Qt.CursorShape.SizeHorCursor) - else: - self.setCursor(Qt.CursorShape.ArrowCursor) - if Qt.MouseButton.LeftButton and self._right_drag: - # 右侧调整窗口宽度 + if isinrect(pos, self._corner_youxia): + self.setCursor(Qt.CursorShape.SizeFDiagCursor) + elif isinrect(pos, self._corner_zuoshang): + self.setCursor(Qt.CursorShape.SizeFDiagCursor) + elif isinrect(pos, self._corner_zuoxia): + self.setCursor(Qt.CursorShape.SizeBDiagCursor) + elif isinrect(pos, self._corner_youshang): + self.setCursor(Qt.CursorShape.SizeBDiagCursor) + elif isinrect(pos, self._bottom_rect): + self.setCursor(Qt.CursorShape.SizeVerCursor) + elif isinrect(pos, self._top_rect): + self.setCursor(Qt.CursorShape.SizeVerCursor) + elif isinrect(pos, self._right_rect): + self.setCursor(Qt.CursorShape.SizeHorCursor) + elif isinrect(pos, self._left_rect): + self.setCursor(Qt.CursorShape.SizeHorCursor) + else: + self.setCursor(Qt.CursorShape.ArrowCursor) + if self._right_drag: self.resize(pos.x(), self.height()) - elif Qt.MouseButton.LeftButton and self._left_drag: - # 右侧调整窗口宽度 + elif self._corner_drag_youshang: + self.setGeometry( + self.x(), + (gpos - self.startxp).y(), + pos.x(), + self.starth - (gpos.y() - self.starty), + ) + elif self._corner_drag_zuoshang: + self.setGeometry( + (gpos - self.startxp).x(), + (gpos - self.startxp).y(), + self.startw - (gpos.x() - self.startx), + self.starth - (gpos.y() - self.starty), + ) + + elif self._left_drag: self.setGeometry( (gpos - self.startxp).x(), self.y(), self.startw - (gpos.x() - self.startx), self.height(), ) - # self.resize(pos.x(), self.height()) - elif Qt.MouseButton.LeftButton and self._bottom_drag: - # 下侧调整窗口高度 + elif self._bottom_drag: self.resize(self.width(), event.pos().y()) - elif Qt.MouseButton.LeftButton and self._lcorner_drag: - # 下侧调整窗口高度 + elif self._top_drag: + self.setGeometry( + self.x(), + (gpos - self.startxp).y(), + self.width(), + self.starth - (gpos.y() - self.starty), + ) + elif self._corner_drag_zuoxia: self.setGeometry( (gpos - self.startxp).x(), self.y(), self.startw - (gpos.x() - self.startx), event.pos().y(), ) - elif Qt.MouseButton.LeftButton and self._corner_drag: - # 右下角同时调整高度和宽度 + elif self._corner_drag_youxia: self.resize(pos.x(), pos.y()) - elif Qt.MouseButton.LeftButton and self._move_drag: - # 标题栏拖放窗口位置 + elif self._move_drag: self.move(gpos - self.move_DragPosition) def mouseReleaseEvent(self, QMouseEvent): - # 鼠标释放后,各扳机复位 - self._move_drag = False - self._corner_drag = False - self._bottom_drag = False - self._lcorner_drag = False - self._right_drag = False - self._left_drag = False + self.resetflags() class Prompt_dialog(QDialog): @@ -491,6 +689,20 @@ def D_getspinbox(mini, maxi, d, key, double=False, step=1, callback=None, dec=1) return lambda: getspinbox(mini, maxi, d, key, double, step, callback, dec) +def getIconButton(callback=None, icon="fa.paint-brush", enable=True, qicon=None): + + b = IconButton(icon, enable, qicon) + + if callback: + b.clicked.connect(callback) + + return b + + +def D_getIconButton(callback=None, icon="fa.paint-brush", enable=True, qicon=None): + return lambda: getIconButton(callback, icon, enable, qicon) + + def getcolorbutton( d, key, @@ -509,9 +721,10 @@ def getcolorbutton( b = QPushButton() b.setIcon(qicon) b.setEnabled(enable) - b.setIconSize(QSize(20, 20)) + sz = int(1.42 * globalconfig["buttonsize2"]) + b.setIconSize(QSize(sz, sz)) if sizefixed: - b.setFixedSize(QSize(20, 20)) + b.setFixedSize(QSize(sz, sz)) if transparent: b.setStyleSheet( """background-color: rgba(255, 255, 255, 0); @@ -1058,6 +1271,50 @@ def tabadd_lazy(tab, title, getrealwidgetfunction): tab.addTab(q, title) +def makegroupingrid(args): + lis = args.get("grid") + title = args.get("title", None) + _type = args.get("type", "form") + group = QGroupBox() + if title: + group.setTitle(_TR(title)) + if _type == "grid": + grid = QGridLayout() + group.setLayout(grid) + automakegrid(grid, lis) + elif _type == "form": + lay = QFormLayout() + group.setLayout(lay) + for line in lis: + name, wid = line + if isinstance(wid, tuple) or isinstance(wid, list): + hb = QHBoxLayout() + hb.setContentsMargins(0, 0, 0, 0) + needstretch = False + for w in wid: + if callable(w): + w = w() + if w.sizePolicy().horizontalPolicy() == QSizePolicy.Policy.Fixed: + needstretch = True + hb.addWidget(w) + if needstretch: + hb.insertStretch(0) + hb.addStretch() + wid = hb + else: + if callable(wid): + wid = wid() + if wid.sizePolicy().horizontalPolicy() == QSizePolicy.Policy.Fixed: + hb = QHBoxLayout() + hb.setContentsMargins(0, 0, 0, 0) + hb.addStretch(1) + hb.addWidget(wid) + hb.addStretch(1) + wid = hb + lay.addRow(_TR(name), wid) + return group + + def automakegrid(grid: QGridLayout, lis, save=False, savelist=None): maxl = 0 @@ -1097,6 +1354,8 @@ def automakegrid(grid: QGridLayout, lis, save=False, savelist=None): wid = QLabel((wid)) if arg == "link": wid.setOpenExternalLinks(True) + elif arg == "group": + wid = makegroupingrid(wid) if cols > 0: col = cols elif cols == 0: @@ -1389,7 +1648,7 @@ def getsimplepatheditor( e = QLineEdit(text) e.setReadOnly(True) if useiconbutton: - bu = getcolorbutton("", "", None, icon="fa.gear", constcolor="#FF69B4") + bu = getIconButton(icon="fa.gear") else: bu = QPushButton(_TR("选择" + ("文件夹" if isdir else "文件"))) bu.clicked.connect( diff --git a/LunaTranslator/LunaTranslator/myutils/config.py b/LunaTranslator/LunaTranslator/myutils/config.py index 9846d3bc..99b15bb3 100644 --- a/LunaTranslator/LunaTranslator/myutils/config.py +++ b/LunaTranslator/LunaTranslator/myutils/config.py @@ -69,9 +69,8 @@ def getdefaultsavehook(gamepath, title=None): # "mypost":# 设置时再加载 }, "lang_follow_default": True, - #"private_srclang": 0,# 显示时再加载,缺省用global中的键 - #"private_tgtlang": 0, - + # "private_srclang": 0,# 显示时再加载,缺省用global中的键 + # "private_tgtlang": 0, "localeswitcher": 0, "onloadautochangemode2": 0, "needinserthookcode": [], @@ -92,7 +91,7 @@ def getdefaultsavehook(gamepath, title=None): "hooktypeasname": {}, "use_saved_text_process": False, # "searchnoresulttime": 0, - "gamejsonfile": [],#之前是"",后面改成[] + "gamejsonfile": [], # 之前是"",后面改成[] "gamesqlitefile": "", "relationlinks": [], # "vndbtags": [],#->webtags @@ -112,7 +111,6 @@ def getdefaultsavehook(gamepath, title=None): "bgmsid": 0, "dlsiteid": "RJ/VJXXXX", "fanzaid": "", - "title": "", # "imagepath": None, # 封面->imagepath_all[0] # "imagepath_much2": [], # 截图->imagepath_all[1:] @@ -221,6 +219,17 @@ for key in ___: globalconfig["toolbutton"]["rank2"].remove(key) +for group in ["webview", "textbrowser"]: + + if ( + globalconfig["rendertext_using_internal"][group] + not in static_data["textrender"][group] + ): + globalconfig["rendertext_using_internal"][group] = static_data["textrender"][ + group + ][0] + + def getlanguse(): global language, languageshow return static_data["language_list_translator_inner"][language] diff --git a/LunaTranslator/LunaTranslator/qtsymbols.py b/LunaTranslator/LunaTranslator/qtsymbols.py index 866a8896..b90670ab 100644 --- a/LunaTranslator/LunaTranslator/qtsymbols.py +++ b/LunaTranslator/LunaTranslator/qtsymbols.py @@ -1,14 +1,14 @@ try: from PyQt5 import QtSvg from PyQt5.QtWidgets import QFrame,QListView,QCheckBox,QAbstractItemView,QTextEdit,QTableView,QHeaderView,QColorDialog,QSpinBox,QDoubleSpinBox,QComboBox,QDialogButtonBox,QMainWindow,QMessageBox,QDialog,QGridLayout,QTextBrowser,QGraphicsDropShadowEffect,QWidget,QSizePolicy,QScrollArea,QApplication,QPushButton,QSystemTrayIcon,QPlainTextEdit,QAction,QMenu,QFileDialog,QKeySequenceEdit,QLabel,QSpacerItem,QWidgetItem,QLayout,QTextBrowser,QLineEdit,QFormLayout,QSizePolicy,QTabWidget,QTabBar,QSplitter,QListWidget,QListWidgetItem,QHBoxLayout,QVBoxLayout,QSizeGrip,QFontComboBox,QProgressBar,QRadioButton,QButtonGroup,QSlider,QToolTip,QGroupBox - from PyQt5.QtGui import QIconEngine,QIntValidator,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent - from PyQt5.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer + from PyQt5.QtGui import QIconEngine,QIntValidator,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent,QPaintEvent + from PyQt5.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer,QRectF,QVariantAnimation isqt5 = True except: #from traceback import print_exc #print_exc() from PyQt6 import QtSvg from PyQt6.QtWidgets import QFrame,QListView,QCheckBox,QAbstractItemView,QTextEdit,QTableView,QHeaderView,QColorDialog,QSpinBox,QDoubleSpinBox,QComboBox,QDialogButtonBox,QMainWindow,QMessageBox,QDialog,QGridLayout,QTextBrowser,QGraphicsDropShadowEffect,QWidget,QSizePolicy,QScrollArea,QApplication,QPushButton,QSystemTrayIcon,QPlainTextEdit,QMenu,QFileDialog,QKeySequenceEdit,QLabel,QSpacerItem,QWidgetItem,QLayout,QTextBrowser,QLineEdit,QFormLayout,QSizePolicy,QTabWidget,QTabBar,QSplitter,QListWidget,QListWidgetItem,QHBoxLayout,QVBoxLayout,QSizeGrip,QFontComboBox,QProgressBar,QRadioButton,QButtonGroup,QSlider,QToolTip,QGroupBox - from PyQt6.QtGui import QIconEngine,QIntValidator,QAction,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent - from PyQt6.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer + from PyQt6.QtGui import QIconEngine,QIntValidator,QAction,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent,QWheelEvent,QPaintEvent + from PyQt6.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex,QTimer,QRectF,QVariantAnimation isqt5 = False \ No newline at end of file diff --git a/LunaTranslator/LunaTranslator/rendertext/exampleextrahtml.html b/LunaTranslator/LunaTranslator/rendertext/exampleextrahtml.html new file mode 100644 index 00000000..64e80c2f --- /dev/null +++ b/LunaTranslator/LunaTranslator/rendertext/exampleextrahtml.html @@ -0,0 +1,27 @@ + + + \ No newline at end of file diff --git a/LunaTranslator/LunaTranslator/rendertext/internal/textbrowser/yinying.py b/LunaTranslator/LunaTranslator/rendertext/internal/textbrowser/yinying.py deleted file mode 100644 index 59fb6908..00000000 --- a/LunaTranslator/LunaTranslator/rendertext/internal/textbrowser/yinying.py +++ /dev/null @@ -1,15 +0,0 @@ -from qtsymbols import * -from rendertext.internal.textbrowser.normal import TextLine as TextLabel_0 - - -class TextLine(TextLabel_0): - def usingcolor(self): - return QColor(self.config["fillcolor"]) - - def setShadow(self): - font = self.font() - self.setShadow_internal( - self.basecolor, - font.pointSizeF() * self.config["shadowR"], - self.config["shadowforce"], - ) diff --git a/LunaTranslator/LunaTranslator/rendertext/internal/webview/base.py b/LunaTranslator/LunaTranslator/rendertext/internal/webview/base.py deleted file mode 100644 index 62331529..00000000 --- a/LunaTranslator/LunaTranslator/rendertext/internal/webview/base.py +++ /dev/null @@ -1,75 +0,0 @@ -from qtsymbols import * -from myutils.config import globalconfig -from dataclasses import dataclass -import uuid - - -@dataclass -class datas: - font_family: str - font_size: float - bold: bool - atcenter: bool - color: str - extra_space: float - - -class base: - - @property - def config(self): - return globalconfig["rendertext"]["webview"][self.typename].get("args", {}) - - def __init__(self, typename, webview, parent) -> None: - self.typename = typename - self.parent = parent - self.webview = webview - - def gen_html__( - self, text, font_family, font_size, bold, atcenter, color, extra_space - ): - self.data_ = datas(font_family, font_size, bold, atcenter, color, extra_space) - return self.gen_html(text, self.data_) - - def gen_html(self, text, data: datas): - raise - - def eval(self, js): - self.parent.testeval(js) - - def bind(self, name, func): - self.webview.bind(name, func) - - def measureH(self, font_family, font_size): - font = QFont() - font.setFamily(font_family) - font.setPointSizeF(font_size) - fmetrics = QFontMetrics(font) - - return fmetrics.height() - - @property - def line_height(self): - if self.data_.extra_space == 0: - return "" - else: - return f"line-height: {self.measureH(self.data_.font_family,self.data_.font_size)+self.data_.extra_space}px;" - - @property - def align(self): - align = "text-align: center;" if self.data_.atcenter else "" - return align - - @property - def fontinfo(self): - bold = "font-weight: bold;" if self.data_.bold else "" - fms = f"font-family: {self.data_.font_family};font-size: {self.data_.font_size}pt;" - return fms + bold - - def getuid(self): - _id = f"luna_{uuid.uuid4()}" - return _id - - def makedivstyle(self, _id, inner, style): - - return f'