From 4b37f8194fcb8bea8c3a4f741025427756de0ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sat, 1 Jun 2024 08:56:56 +0800 Subject: [PATCH] many --- .../LunaTranslator/LunaTranslator.py | 180 ++-- .../LunaTranslator/LunaTranslator_main.py | 10 +- .../LunaTranslator/gui/attachprocessdialog.py | 16 +- .../LunaTranslator/gui/dialog_savedgame.py | 3 +- LunaTranslator/LunaTranslator/gui/edittext.py | 36 +- .../LunaTranslator/gui/gui_xianshi_buttons.py | 171 ++++ .../LunaTranslator/gui/gui_xianshi_scale.py | 327 ++++++ .../LunaTranslator/gui/gui_xianshi_text.py | 231 +++++ .../LunaTranslator/gui/gui_xianshi_ui.py | 271 +++++ .../LunaTranslator/gui/selecthook.py | 34 +- LunaTranslator/LunaTranslator/gui/settin.py | 124 +-- .../LunaTranslator/gui/setting_lang.py | 31 +- .../LunaTranslator/gui/setting_proxy.py | 75 +- .../LunaTranslator/gui/settingpage1.py | 190 ++-- .../LunaTranslator/gui/settingpage2.py | 171 ++-- .../LunaTranslator/gui/settingpage7.py | 77 +- .../LunaTranslator/gui/settingpage_about.py | 127 ++- .../LunaTranslator/gui/settingpage_cishu.py | 42 +- .../LunaTranslator/gui/settingpage_ocr.py | 65 +- .../LunaTranslator/gui/settingpage_quick.py | 63 +- .../LunaTranslator/gui/settingpage_tts.py | 91 +- .../gui/settingpage_xianshishezhi.py | 951 +----------------- .../LunaTranslator/gui/showocrimage.py | 19 +- LunaTranslator/LunaTranslator/gui/showword.py | 9 +- .../LunaTranslator/gui/textbrowser.py | 1 - .../LunaTranslator/gui/transhist.py | 23 +- .../LunaTranslator/gui/translatorUI.py | 151 ++- .../LunaTranslator/gui/usefulwidget.py | 143 ++- .../LunaTranslator/myutils/ocrutil.py | 2 +- .../LunaTranslator/myutils/utils.py | 8 + LunaTranslator/LunaTranslator/qtsymbols.py | 4 +- .../LunaTranslator/textsource/ocrtext.py | 18 +- .../files/defaultconfig/config.json | 20 +- LunaTranslator/files/lang/ar.json | 7 +- LunaTranslator/files/lang/cht.json | 7 +- LunaTranslator/files/lang/en.json | 7 +- LunaTranslator/files/lang/es.json | 7 +- LunaTranslator/files/lang/fr.json | 7 +- LunaTranslator/files/lang/it.json | 7 +- LunaTranslator/files/lang/ja.json | 7 +- LunaTranslator/files/lang/ko.json | 7 +- LunaTranslator/files/lang/pl.json | 7 +- LunaTranslator/files/lang/ru.json | 7 +- LunaTranslator/files/lang/th.json | 7 +- LunaTranslator/files/lang/tr.json | 7 +- LunaTranslator/files/lang/uk.json | 7 +- LunaTranslator/files/lang/vi.json | 7 +- LunaTranslator/files/lang/zh.json | 7 +- plugins/CMakeLists.txt | 4 +- 49 files changed, 2112 insertions(+), 1681 deletions(-) create mode 100644 LunaTranslator/LunaTranslator/gui/gui_xianshi_buttons.py create mode 100644 LunaTranslator/LunaTranslator/gui/gui_xianshi_scale.py create mode 100644 LunaTranslator/LunaTranslator/gui/gui_xianshi_text.py create mode 100644 LunaTranslator/LunaTranslator/gui/gui_xianshi_ui.py diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index 3de85644..6e1f8ddf 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -1,5 +1,5 @@ import time -import os, threading +import os, threading, sys from qtsymbols import * from traceback import print_exc from myutils.config import ( @@ -22,16 +22,16 @@ from myutils.utils import ( ) from myutils.wrapper import threader from gui.showword import searchwordW -from myutils.hwnd import getpidexe, ListProcess +from myutils.hwnd import getpidexe, ListProcess, getExeIcon from textsource.copyboard import copyboard from textsource.texthook import texthook from textsource.ocrtext import ocrtext -import gui.selecthook -import gui.translatorUI +from gui.selecthook import hookselect +from gui.translatorUI import QUnFrameWindow from gui.languageset import languageset import zhconv, functools -import gui.transhist -import gui.edittext +from gui.transhist import transhist +from gui.edittext import edittext import importlib, qtawesome from functools import partial from gui.settin import Settin @@ -44,6 +44,14 @@ from winsharedutils import pid_running, isDark from myutils.post import POSTSOLVE +class commonstylebase(QWidget): + setstylesheetsignal = pyqtSignal() + + def __init__(self, parent) -> None: + super().__init__(parent) + self.setstylesheetsignal.connect(gobject.baseobject.setcommonstylesheet) + + class MAINUI: def __init__(self) -> None: super().__init__() @@ -54,6 +62,7 @@ class MAINUI: self.textsource_p = None self.currentmd5 = "0" self.currenttext = "" + self.currenttranslate = "" self.currentread = "" self.refresh_on_get_trans_signature = 0 self.currentsignature = None @@ -62,6 +71,12 @@ class MAINUI: self.outputers = {} self.processmethods = [] self.zhanweifu = 0 + self.showocrimage = None + self.showocrimage_cached = None + self.AttachProcessDialog = None + self.edittextui = None + self.edittextui_cached = None + self.edittextui_sync=True @property def textsource(self): @@ -366,7 +381,7 @@ class MAINUI: self.textsource.sqlqueueput((contentraw, classname, res)) except: pass - + self.currenttranslate = res if ( globalconfig["embedded"]["as_fast_as_posible"] or classname == globalconfig["embedded"]["translator_2"] @@ -456,12 +471,15 @@ class MAINUI: def starttextsource(self, use=None, checked=True): self.translation_ui.showhidestate = False self.translation_ui.refreshtooliconsignal.emit() - self.settin_ui.selectbutton.setEnabled( - globalconfig["sourcestatus2"]["texthook"]["use"] - ) - self.settin_ui.selecthookbutton.setEnabled( - globalconfig["sourcestatus2"]["texthook"]["use"] - ) + try: + self.settin_ui.selectbutton.setEnabled( + globalconfig["sourcestatus2"]["texthook"]["use"] + ) + self.settin_ui.selecthookbutton.setEnabled( + globalconfig["sourcestatus2"]["texthook"]["use"] + ) + except: + pass self.textsource = None if checked: classes = {"ocr": ocrtext, "copy": copyboard, "texthook": None} @@ -589,11 +607,39 @@ class MAINUI: return aclass(type_) + def maybesetimage(self, pair): + + if self.showocrimage: + self.showocrimage.setimage.emit(pair) + self.showocrimage_cached = pair + + def createshowocrimage(self): + self.showocrimage = showocrimage(self.settin_ui, self.showocrimage_cached) + if self.showocrimage: + self.showocrimage.show() + + def maybesetedittext(self, text): + if self.edittextui: + self.edittextui.getnewsentencesignal.emit(text) + self.edittextui_cached = text + + def createedittextui(self): + self.edittextui = edittext(self.settin_ui, self.edittextui_cached) + if self.edittextui: + self.edittextui.show() + + def createattachprocess(self): + self.AttachProcessDialog = AttachProcessDialog( + self.settin_ui, self.selectprocess, self.hookselectdialog + ) + if self.AttachProcessDialog: + self.AttachProcessDialog.show() + def onwindowloadautohook(self): textsourceusing = globalconfig["sourcestatus2"]["texthook"]["use"] if not (globalconfig["autostarthook"] and textsourceusing): return - elif self.AttachProcessDialog.isVisible(): + elif self.AttachProcessDialog and self.AttachProcessDialog.isVisible(): return else: try: @@ -631,9 +677,14 @@ class MAINUI: "onloadautoswitchsrclang" ] if onloadautoswitchsrclang > 0: - self.settin_ui.srclangswitcher.setCurrentIndex( - onloadautoswitchsrclang - 1 - ) + try: + self.settin_ui.srclangswitcher.setCurrentIndex( + onloadautoswitchsrclang - 1 + ) + except: + globalconfig["srclang3"] = ( + onloadautoswitchsrclang - 1 + ) break else: @@ -727,32 +778,6 @@ class MAINUI: int(widget.winId()), dark, globalconfig["WindowBackdrop"] ) - def aa(self): - class WindowEventFilter(QObject): - def eventFilter(_, obj, event): - if event.type() == QEvent.Type.WinIdChange: - - hwnd = obj.winId() - if hwnd: # window create/destroy,when destroy winId is None - if self.currentisdark is not None: - self.setdarktheme(obj, self.currentisdark) - windows.SetProp( - int(obj.winId()), - "Magpie.WindowType.ToolWindow", - windows.HANDLE(1), - ) - self.setshowintab_checked(obj) - return False - - self.currentisdark = None - self.__filter = WindowEventFilter() # keep ref - QApplication.instance().installEventFilter(self.__filter) - - self.translation_ui = gui.translatorUI.QUnFrameWindow() - - self.translation_ui.show() - self.mainuiloadafter() - def checkgameplayingthread(self): self.tracestarted = False while True: @@ -839,7 +864,18 @@ class MAINUI: trayMenu.addAction(settingAction) trayMenu.addSeparator() trayMenu.addAction(quitAction) - self.translation_ui.tray.setContextMenu(trayMenu) + self.tray = QSystemTrayIcon() + + icon = getExeIcon(sys.argv[0]) #'./LunaTranslator.exe')# QIcon() + self.tray.setIcon(icon) + + self.tray.activated.connect(self.translation_ui.leftclicktray) + self.tray.show() + self.tray.setContextMenu(trayMenu) + + def destroytray(self): + self.tray.hide() + self.tray = None def setshowintab(self): for widget in QApplication.topLevelWidgets(): @@ -885,28 +921,28 @@ class MAINUI: + (globalconfig["settingfonttype"]) + "' ; }" ) - self.settin_ui.setStyleSheet(style) + self.__commonstylebase.setStyleSheet(style) + + def loadui(self): + self.installeventfillter() + self.translation_ui = QUnFrameWindow() + self.translation_ui.show() + self.translation_ui.aftershowdosomething() + self.mainuiloadafter() def mainuiloadafter(self): - self.setshowintab() self.safeloadprocessmodels() self.prepare() self.startxiaoxueguan() self.starthira() self.startoutputer() - self.settin_ui = Settin(self.translation_ui) - self.inittray() + self.__commonstylebase = commonstylebase(self.translation_ui) self.setcommonstylesheet() - self.transhis = gui.transhist.transhist(self.settin_ui) + self.settin_ui = Settin(self.__commonstylebase) + self.transhis = transhist(self.settin_ui) self.startreader() - - self.edittextui = gui.edittext.edittext(self.settin_ui) self.searchwordW = searchwordW(self.settin_ui) - self.hookselectdialog = gui.selecthook.hookselect(self.settin_ui) - self.showocrimage = showocrimage(self.settin_ui) - self.AttachProcessDialog = AttachProcessDialog( - self.settin_ui, self.selectprocess, self.hookselectdialog - ) + self.hookselectdialog = hookselect(self.settin_ui) self.starttextsource() threading.Thread(target=self.autocheckhwndexists).start() threading.Thread(target=self.autohookmonitorthread).start() @@ -914,6 +950,38 @@ class MAINUI: target=minmaxmoveobservefunc, args=(self.translation_ui,) ).start() threading.Thread(target=self.checkgameplayingthread).start() + threading.Thread(target=self.darklistener).start() + self.inittray() + + def darklistener(self): + sema = winsharedutils.startdarklistener() + while True: + # 会触发两次 + windows.WaitForSingleObject(sema, windows.INFINITE) + if globalconfig["darklight"] == 2: + self.__commonstylebase.setstylesheetsignal.emit() + windows.WaitForSingleObject(sema, windows.INFINITE) + + def installeventfillter(self): + class WindowEventFilter(QObject): + def eventFilter(_, obj, event): + if event.type() == QEvent.Type.WinIdChange: + + hwnd = obj.winId() + if hwnd: # window create/destroy,when destroy winId is None + if self.currentisdark is not None: + self.setdarktheme(obj, self.currentisdark) + windows.SetProp( + int(obj.winId()), + "Magpie.WindowType.ToolWindow", + windows.HANDLE(1), + ) + self.setshowintab_checked(obj) + return False + + self.currentisdark = None + self.__filter = WindowEventFilter() # keep ref + QApplication.instance().installEventFilter(self.__filter) def checklang(self): if globalconfig["language_setted_2.4.5"] == False: diff --git a/LunaTranslator/LunaTranslator/LunaTranslator_main.py b/LunaTranslator/LunaTranslator/LunaTranslator_main.py index c4027c84..7d9e1aed 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator_main.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator_main.py @@ -1,5 +1,5 @@ import sys, windows -import platform, os +import platform, os, time if __name__ == "__main__": _lock = windows.AutoHandle(windows.CreateMutex(False, "LUNA_UPDATER_BLOCK")) @@ -18,8 +18,6 @@ if __name__ == "__main__": 0, "./LunaTranslator/network/" + ["winhttp", "libcurl"][globalconfig["network"]] ) - from gui.usefulwidget import getQMessageBox - from LunaTranslator import MAINUI import gobject gobject.overridepathexists() @@ -60,6 +58,8 @@ if __name__ == "__main__": if os.path.exists(f) == False: collect.append(f) if len(collect): + from gui.usefulwidget import getQMessageBox + getQMessageBox( None, _TR("错误"), @@ -72,7 +72,9 @@ if __name__ == "__main__": ) os._exit(0) + from LunaTranslator import MAINUI + gobject.baseobject = MAINUI() gobject.baseobject.checklang() - gobject.baseobject.aa() + gobject.baseobject.loadui() app.exit(app.exec()) diff --git a/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py b/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py index 5aabbb73..b6abfa40 100644 --- a/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py +++ b/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py @@ -3,7 +3,8 @@ from winsharedutils import getpidhwndfirst import functools from myutils.config import globalconfig, _TR import windows -import os +import os, gobject +from myutils.wrapper import Singleton_close from myutils.hwnd import ( getpidexe, ListProcess, @@ -12,10 +13,11 @@ from myutils.hwnd import ( ) import qtawesome -from gui.usefulwidget import closeashidewindow, getQMessageBox +from gui.usefulwidget import saveposwindow, getQMessageBox -class AttachProcessDialog(closeashidewindow): +@Singleton_close +class AttachProcessDialog(saveposwindow): setcurrentpidpnamesignal = pyqtSignal(int, int) @@ -37,10 +39,12 @@ class AttachProcessDialog(closeashidewindow): self.windowtext.setText(windows.GetWindowText(hwnd)) self.selectedp = (_pids, name, hwnd) + def closeEvent(self, e): + gobject.baseobject.AttachProcessDialog = None + super().closeEvent(e) + def __init__(self, parent, callback, hookselectdialog=None): - super(AttachProcessDialog, self).__init__( - parent, globalconfig, "attachprocessgeo" - ) + super().__init__(parent, globalconfig, "attachprocessgeo") self.setcurrentpidpnamesignal.connect(self.selectwindowcallback) self.iconcache = {} diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index 3348336b..06b9ba06 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -473,7 +473,8 @@ class browserdialog(saveposwindow): def __init__(self, parent, exepath=None) -> None: super().__init__(parent, globalconfig, "browserwidget") - + if exepath: + self.setWindowIcon(getExeIcon(exepath, cache=True)) self.browser = auto_select_webview(self) self.tagswidget = TagWidget(self) diff --git a/LunaTranslator/LunaTranslator/gui/edittext.py b/LunaTranslator/LunaTranslator/gui/edittext.py index 816e3046..f1f97188 100644 --- a/LunaTranslator/LunaTranslator/gui/edittext.py +++ b/LunaTranslator/LunaTranslator/gui/edittext.py @@ -3,22 +3,28 @@ import qtawesome import threading, windows import gobject, time from myutils.config import globalconfig, _TR, _TRL -from gui.usefulwidget import closeashidewindow, getsimplecombobox +from gui.usefulwidget import saveposwindow, getsimplecombobox from myutils.utils import str2rgba from myutils.wrapper import Singleton_close, threader -class edittext(closeashidewindow): +@Singleton_close +class edittext(saveposwindow): getnewsentencesignal = pyqtSignal(str) - def __init__(self, parent): - super(edittext, self).__init__(parent, globalconfig, "edit_geo") - self.sync = True + def closeEvent(self, e): + gobject.baseobject.edittextui = None + super().closeEvent(e) + + def __init__(self, parent, cached): + super().__init__(parent, globalconfig, "edit_geo") self.setupUi() # self.setWindowFlags(self.windowFlags()&~Qt.WindowMinimizeButtonHint) self.getnewsentencesignal.connect(self.getnewsentence) self.setWindowTitle(_TR("编辑")) + if cached: + self.getnewsentence(cached) def setupUi(self): self.setWindowIcon(qtawesome.icon("fa.edit")) @@ -43,8 +49,12 @@ class edittext(closeashidewindow): ) bt2 = QPushButton( icon=qtawesome.icon( - "fa.forward" if self.sync else "fa.play", - color="#FF69B4" if self.sync else globalconfig["buttoncolor"], + "fa.forward" if gobject.baseobject.edittextui_sync else "fa.play", + color=( + "#FF69B4" + if gobject.baseobject.edittextui_sync + else globalconfig["buttoncolor"] + ), ) ) @@ -66,11 +76,15 @@ class edittext(closeashidewindow): ).start() def changestate(self): - self.sync = not self.sync + gobject.baseobject.edittextui_sync = not gobject.baseobject.edittextui_sync self.bt2.setIcon( qtawesome.icon( - "fa.forward" if self.sync else "fa.play", - color="#FF69B4" if self.sync else globalconfig["buttoncolor"], + "fa.forward" if gobject.baseobject.edittextui_sync else "fa.play", + color=( + "#FF69B4" + if gobject.baseobject.edittextui_sync + else globalconfig["buttoncolor"] + ), ) ) @@ -83,7 +97,7 @@ class edittext(closeashidewindow): self.textOutput.clear() def getnewsentence(self, sentence): - if self.sync: + if gobject.baseobject.edittextui_sync: self.textOutput.setPlainText(sentence) diff --git a/LunaTranslator/LunaTranslator/gui/gui_xianshi_buttons.py b/LunaTranslator/LunaTranslator/gui/gui_xianshi_buttons.py new file mode 100644 index 00000000..5e1f7481 --- /dev/null +++ b/LunaTranslator/LunaTranslator/gui/gui_xianshi_buttons.py @@ -0,0 +1,171 @@ +import functools +from qtsymbols import * +from myutils.config import globalconfig, _TR, _TRL +from myutils.wrapper import Singleton +import qtawesome, gobject, json +from gui.usefulwidget import ( + D_getsimplecombobox, + D_getcolorbutton, + getcolorbutton, + makescrollgrid, + D_getsimpleswitch, +) + + +@Singleton +class dialog_selecticon(QDialog): + def __init__(self, parent, dict, key, _nouse_for_click_arg) -> None: + + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) + self.dict = dict + self.key = key + self.setWindowTitle(_TR("选择图标")) + with open( + "./files/fonts/fontawesome4.7-webfont-charmap.json", "r", encoding="utf8" + ) as ff: + js = json.load(ff) + + layout = QGridLayout() + self.setLayout(layout) + for i, name in enumerate(js): + layout.addWidget( + getcolorbutton( + "", + "", + functools.partial(self.selectcallback, "fa." + name), + qicon=qtawesome.icon( + "fa." + name, color=globalconfig["buttoncolor"] + ), + ), + i // 30, + i % 30, + ) + self.show() + + def selectcallback(self, _): + print(_) + self.dict[self.key] = _ + self.close() + + +def doadjust(): + gobject.baseobject.translation_ui.enterfunction(delay=3) + gobject.baseobject.translation_ui.adjustbuttons() + + +def changerank(item, up, sortlist, savelist, savelay): + + idx = sortlist.index(item) + idx2 = idx + (-1 if up else 1) + if idx2 < 0 or idx2 >= len(sortlist): + return + headoffset = 1 + idx2 = idx + (-1 if up else 1) + sortlist[idx], sortlist[idx2] = sortlist[idx2], sortlist[idx] + for i, ww in enumerate(savelist[idx + headoffset]): + + w1 = savelay[0].indexOf(ww) + w2 = savelay[0].indexOf(savelist[idx2 + headoffset][i]) + p1 = savelay[0].getItemPosition(w1) + p2 = savelay[0].getItemPosition(w2) + savelay[0].removeWidget(ww) + savelay[0].removeWidget(savelist[idx2 + headoffset][i]) + + savelay[0].addWidget(savelist[idx2 + headoffset][i], *p1) + savelay[0].addWidget(ww, *p2) + savelist[idx + headoffset], savelist[idx2 + headoffset] = ( + savelist[idx2 + headoffset], + savelist[idx + headoffset], + ) + doadjust() + + +def createbuttonwidget(self, lay): + # return table + grids = [["显示", "", "", "对齐", "图标", "图标2", "说明"]] + sortlist = globalconfig["toolbutton"]["rank2"] + savelist = [] + savelay = [] + + for i, k in enumerate(sortlist): + + button_up = D_getcolorbutton( + globalconfig, + "", + callback=functools.partial( + changerank, k, True, sortlist, savelist, savelay + ), + icon="fa.arrow-up", + constcolor="#FF69B4", + ) + button_down = D_getcolorbutton( + globalconfig, + "", + callback=functools.partial( + changerank, k, False, sortlist, savelist, savelay + ), + icon="fa.arrow-down", + constcolor="#FF69B4", + ) + + l = [ + D_getsimpleswitch( + globalconfig["toolbutton"]["buttons"][k], + "use", + callback=lambda _: doadjust(), + ), + button_up, + button_down, + D_getsimplecombobox( + _TRL(["居左", "居右", "居中"]), + globalconfig["toolbutton"]["buttons"][k], + "align", + callback=lambda _: doadjust(), + fixedsize=True, + ), + D_getcolorbutton( + "", + "", + functools.partial( + dialog_selecticon, + self, + globalconfig["toolbutton"]["buttons"][k], + "icon", + ), + qicon=qtawesome.icon( + globalconfig["toolbutton"]["buttons"][k]["icon"], + color=globalconfig["buttoncolor"], + ), + ), + ] + if "icon2" in globalconfig["toolbutton"]["buttons"][k]: + l.append( + D_getcolorbutton( + "", + "", + functools.partial( + dialog_selecticon, + self, + globalconfig["toolbutton"]["buttons"][k], + "icon2", + ), + qicon=qtawesome.icon( + globalconfig["toolbutton"]["buttons"][k]["icon2"], + color=globalconfig["buttoncolor"], + ), + ), + ) + else: + l.append("") + if "belong" in globalconfig["toolbutton"]["buttons"][k]: + belong = ( + "_" + + "仅" + + "_" + + " ".join(globalconfig["toolbutton"]["buttons"][k]["belong"]) + ) + else: + belong = "" + l.append(globalconfig["toolbutton"]["buttons"][k]["tip"] + belong) + grids.append(l) + makescrollgrid(grids, lay, True, savelist, savelay) diff --git a/LunaTranslator/LunaTranslator/gui/gui_xianshi_scale.py b/LunaTranslator/LunaTranslator/gui/gui_xianshi_scale.py new file mode 100644 index 00000000..ee6f5935 --- /dev/null +++ b/LunaTranslator/LunaTranslator/gui/gui_xianshi_scale.py @@ -0,0 +1,327 @@ +import functools +from qtsymbols import * +from myutils.config import globalconfig, magpie_config, static_data +from gui.inputdialog import getsomepath1 +from gui.usefulwidget import ( + D_getsimplecombobox, + makegrid, + D_getspinbox, + getvboxwidget, + D_getcolorbutton, + makesubtab_lazy, + makescrollgrid, + D_getsimpleswitch, +) + + +def makescalew(self, lay): + + commonfsgrid = [ + [ + ("缩放方式", 4), + ( + D_getsimplecombobox( + static_data["scalemethods_vis"], + globalconfig, + "fullscreenmethod_4", + ), + 6, + ), + ] + ] + + losslessgrid = [ + [ + ("Magpie_路径", 4), + ( + D_getcolorbutton( + globalconfig, + "", + callback=lambda x: getsomepath1( + self, + "Magpie_路径", + globalconfig, + "magpiepath", + "Magpie_路径", + isdir=True, + ), + icon="fa.gear", + constcolor="#FF69B4", + ), + 1, + ), + ], + [ + ("Hook Magpie进程使其不会退出缩放", 4), + D_getsimpleswitch(globalconfig, "hookmagpie"), + ], + ] + + innermagpie = [ + [("常规", -1)], + [ + ("", 1), + ("缩放模式", 4), + ( + D_getsimplecombobox( + [_["name"] for _ in magpie_config["scalingModes"]], + magpie_config["profiles"][globalconfig["profiles_index"]], + "scalingMode", + ), + 6, + ), + "", + ], + [ + ("", 1), + ("捕获模式", 4), + ( + D_getsimplecombobox( + [ + "Graphics Capture", + "Desktop Duplication", + "GDI", + "DwmSharedSurface", + ], + magpie_config["profiles"][globalconfig["profiles_index"]], + "captureMethod", + ), + 6, + ), + ], + [ + ("", 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", + ), + 2, + ), + ], + [("源窗口", -1)], + [ + ("", 1), + ("缩放时禁用窗口大小调整", 4), + ( + D_getsimpleswitch( + magpie_config["profiles"][globalconfig["profiles_index"]], + "disableWindowResizing", + ) + ), + ], + [ + ("", 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", + ), + 6, + ), + ], + [ + ("", 1), + ("绘制光标_插值算法", 4), + ( + D_getsimplecombobox( + ["最邻近", "双线性"], + magpie_config["profiles"][globalconfig["profiles_index"]], + "cursorInterpolationMode", + ), + 6, + ), + ], + [ + ("", 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", + ), + 6, + ), + ], + [ + ("", 1), + ("启用动态检测统计", 4), + ( + D_getsimpleswitch( + magpie_config, + "enableStatisticsForDynamicDetection", + ) + ), + ], + ] + + vw, vl = getvboxwidget() + lay.addWidget(vw) + gw, gd = makegrid(commonfsgrid, delay=True) + vl.addWidget(gw) + tw, td = makesubtab_lazy( + ["Magpie", "外部缩放软件"], + [ + functools.partial(makescrollgrid, innermagpie), + functools.partial(makescrollgrid, losslessgrid), + ], + delay=True, + ) + vl.addWidget(tw) + gd() + td() diff --git a/LunaTranslator/LunaTranslator/gui/gui_xianshi_text.py b/LunaTranslator/LunaTranslator/gui/gui_xianshi_text.py new file mode 100644 index 00000000..09d53748 --- /dev/null +++ b/LunaTranslator/LunaTranslator/gui/gui_xianshi_text.py @@ -0,0 +1,231 @@ +import functools +from qtsymbols import * +from gui.inputdialog import multicolorset +from myutils.config import globalconfig, _TRL +import gobject +from gui.usefulwidget import ( + D_getsimplecombobox, + getsimpleswitch, + D_getspinbox, + getspinbox, + D_getcolorbutton, + D_getsimpleswitch, + selectcolor, +) + + +def maybehavefontsizespin(self, t): + if "fontSize_spinBox" in dir(self): + self.fontSize_spinBox.setValue(self.fontSize_spinBox.value() + 0.5 * t) + else: + globalconfig["fontsize"] += 0.5 * t + + +def createfontsizespin(self): + self.fontSize_spinBox = getspinbox( + 1, 100, globalconfig, "fontsize", double=True, step=0.1 + ) + return self.fontSize_spinBox + + +def __changeuibuttonstate(self, x): + gobject.baseobject.translation_ui.refreshtoolicon() + try: + self.show_hira_switch.setEnabled(x) + self.show_fenciswitch.setEnabled(x) + except: + pass + + +def createtextfontcom(key): + font_comboBox = QFontComboBox() + font_comboBox.currentTextChanged.connect(lambda x: globalconfig.__setitem__(key, x)) + font_comboBox.setCurrentFont(QFont(globalconfig[key])) + return font_comboBox + + +def createshoworiginswitch(self): + self.show_original_switch = getsimpleswitch( + globalconfig, "isshowrawtext", callback=lambda x: __changeuibuttonstate(self, x) + ) + return self.show_original_switch + + +def createhiraswitch(self): + + self.show_hira_switch = getsimpleswitch( + globalconfig, "isshowhira", enable=globalconfig["isshowrawtext"] + ) + return self.show_hira_switch + + +def createfenciwitch(self): + self.show_fenciswitch = getsimpleswitch( + globalconfig, "show_fenci", enable=globalconfig["isshowrawtext"] + ) + return self.show_fenciswitch + + +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( + _TRL( + [ + "普通字体", + "空心字体", + "描边字体", + "描边字体_2", + "描边字体_2_投影", + "发光字体", + ] + ), + globalconfig, + "zitiyangshi2", + ), + 6, + ), + ], + [ + ("特殊字体样式填充颜色", 5), + D_getcolorbutton( + globalconfig, + "miaobiancolor", + transparent=False, + callback=lambda: selectcolor( + self, globalconfig, "miaobiancolor", self.miaobian_color_button + ), + name="miaobian_color_button", + parent=self, + ), + ], + [ + ("空心线宽", 3), + ( + D_getspinbox( + 0.1, 100, globalconfig, "miaobianwidth", double=True, step=0.1 + ), + 3, + ), + "", + ("描边宽度", 3), + ( + D_getspinbox( + 0.1, 100, globalconfig, "miaobianwidth2", double=True, step=0.1 + ), + 3, + ), + ], + [ + ("发光亮度", 3), + (D_getspinbox(1, 100, globalconfig, "shadowforce"), 3), + "", + ("投影距离", 3), + ( + D_getspinbox( + 0.1, 100, globalconfig, "traceoffset", double=True, step=0.1 + ), + 3, + ), + ], + [], + [ + ("显示原文", 5), + functools.partial(createshoworiginswitch, self), + "", + ("显示翻译", 5), + (D_getsimpleswitch(globalconfig, "showfanyi"), 1), + ], + [ + ("原文颜色", 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 + ), + 3, + ), + ], + [ + ("语法加亮", 5), + functools.partial(createfenciwitch, self), + "", + ("词性颜色(需要Mecab)", 5), + D_getcolorbutton( + globalconfig, + "", + callback=lambda: multicolorset(self), + icon="fa.gear", + constcolor="#FF69B4", + ), + ], + [], + [ + ("收到翻译结果时才刷新", 5), + D_getsimpleswitch(globalconfig, "refresh_on_get_trans"), + ], + ] + return textgrid diff --git a/LunaTranslator/LunaTranslator/gui/gui_xianshi_ui.py b/LunaTranslator/LunaTranslator/gui/gui_xianshi_ui.py new file mode 100644 index 00000000..384fd615 --- /dev/null +++ b/LunaTranslator/LunaTranslator/gui/gui_xianshi_ui.py @@ -0,0 +1,271 @@ +import functools +from qtsymbols import * +from myutils.config import globalconfig, _TRL, static_data +import gobject +from gui.usefulwidget import ( + D_getsimplecombobox, + D_getspinbox, + D_getcolorbutton, + D_getsimpleswitch, + selectcolor, +) + + +def changeHorizontal(self): + + globalconfig["transparent"] = self.horizontal_slider.value() + try: + self.horizontal_slider_label.setText("{}%".format(globalconfig["transparent"])) + except: + pass + # + gobject.baseobject.translation_ui.set_color_transparency() + + +def createhorizontal_slider(self): + + self.horizontal_slider = QSlider() + self.horizontal_slider.setMaximum(100) + self.horizontal_slider.setMinimum(1) + self.horizontal_slider.setOrientation(Qt.Orientation.Horizontal) + self.horizontal_slider.setValue(0) + self.horizontal_slider.setValue(globalconfig["transparent"]) + self.horizontal_slider.valueChanged.connect( + functools.partial(changeHorizontal, self) + ) + return self.horizontal_slider + + +def createhorizontal_slider_label(self): + self.horizontal_slider_label = QLabel() + self.horizontal_slider_label.setText("{}%".format(globalconfig["transparent"])) + return self.horizontal_slider_label + + +def changeHorizontal_tool(self): + + globalconfig["transparent_tool"] = self.horizontal_slider_tool.value() + try: + self.horizontal_slider_tool_label.setText( + "{}%".format(globalconfig["transparent_tool"]) + ) + except: + pass + # + gobject.baseobject.translation_ui.set_color_transparency() + + +def createhorizontal_slider_tool(self): + + self.horizontal_slider_tool = QSlider() + self.horizontal_slider_tool.setMaximum(100) + self.horizontal_slider_tool.setMinimum(1) + self.horizontal_slider_tool.setOrientation(Qt.Orientation.Horizontal) + self.horizontal_slider_tool.setValue(0) + self.horizontal_slider_tool.setValue(globalconfig["transparent_tool"]) + self.horizontal_slider_tool.valueChanged.connect( + functools.partial(changeHorizontal_tool, self) + ) + return self.horizontal_slider_tool + + +def createhorizontal_slider_tool_label(self): + + self.horizontal_slider_tool_label = QLabel() + self.horizontal_slider_tool_label.setText( + "{}%".format(globalconfig["transparent_tool"]) + ) + return self.horizontal_slider_tool_label + + +def createfontcombo(): + + sfont_comboBox = QFontComboBox() + + def callback(x): + globalconfig.__setitem__("settingfonttype", x) + gobject.baseobject.setcommonstylesheet() + + sfont_comboBox.setCurrentFont(QFont(globalconfig["settingfonttype"])) + sfont_comboBox.currentTextChanged.connect(callback) + return sfont_comboBox + + +def uisetting(self): + + def themelist(t): + return [_["name"] for _ in static_data["themes"][t]] + + uigrid = [ + [("设置界面字体", 4), (createfontcombo, 5)], + [ + ("字体大小", 4), + ( + D_getspinbox( + 1, + 100, + globalconfig, + "settingfontsize", + callback=lambda _: gobject.baseobject.setcommonstylesheet(), + ), + 2, + ), + ], + [ + ("不透明度_翻译窗口", 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(), + ), + 2, + ), + ], + [ + ("圆角_半径", 4), + ( + D_getspinbox( + 0, + 100, + globalconfig, + "yuanjiao_r", + callback=lambda _: gobject.baseobject.translation_ui.set_color_transparency(), + ), + 2, + ), + "", + ("圆角_合并", 4), + D_getsimpleswitch( + globalconfig, + "yuanjiao_merge", + callback=lambda _: gobject.baseobject.translation_ui.set_color_transparency(), + ), + ], + [], + [ + ("明暗", 4), + ( + D_getsimplecombobox( + _TRL(["明亮", "黑暗", "跟随系统"]), + globalconfig, + "darklight", + callback=lambda _: gobject.baseobject.setcommonstylesheet(), + ), + 5, + ), + ], + [ + ("明亮主题", 4), + ( + D_getsimplecombobox( + _TRL(["默认"]) + themelist("light"), + globalconfig, + "lighttheme", + callback=lambda _: gobject.baseobject.setcommonstylesheet(), + ), + 5, + ), + ], + [ + ("黑暗主题", 4), + ( + D_getsimplecombobox( + themelist("dark"), + globalconfig, + "darktheme", + callback=lambda _: gobject.baseobject.setcommonstylesheet(), + ), + 5, + ), + ], + [], + [ + ("窗口特效_翻译窗口", 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, + ), + ], + ] + return uigrid diff --git a/LunaTranslator/LunaTranslator/gui/selecthook.py b/LunaTranslator/LunaTranslator/gui/selecthook.py index c7a5e1eb..351efedb 100644 --- a/LunaTranslator/LunaTranslator/gui/selecthook.py +++ b/LunaTranslator/LunaTranslator/gui/selecthook.py @@ -18,7 +18,7 @@ from gui.usefulwidget import ( getsimpleswitch, textbrowappendandmovetoend, ) -from myutils.utils import checkchaos +from myutils.utils import checkchaos, get_time_stamp from gui.dialog_savedgame import dialog_setting_game @@ -379,7 +379,6 @@ class hookselect(closeashidewindow): def __init__(self, parent): super(hookselect, self).__init__(parent, globalconfig, "selecthookgeo") self.setupUi() - self.changeprocessclearsignal.connect(self.changeprocessclear) self.removehooksignal.connect(self.removehook) self.addnewhooksignal.connect(self.addnewhook) @@ -576,12 +575,14 @@ class hookselect(closeashidewindow): ) def setupUi(self): - self.widget = QWidget() + + self.setCentralWidget(self.widget) self.setWindowIcon(qtawesome.icon("fa.gear")) self.hboxlayout = QHBoxLayout() self.widget.setLayout(self.hboxlayout) self.vboxlayout = QVBoxLayout() + self.hboxlayout.addLayout(self.vboxlayout) self.ttCombomodelmodel = QStandardItemModel() self.tttable = QTableView() @@ -643,11 +644,9 @@ class hookselect(closeashidewindow): self.searchtextbutton.clicked.connect(self.searchtextfunc) self.searchtextlayout.addWidget(self.searchtextbutton) ################### - self.ttCombomodelmodel2 = QStandardItemModel(self) - # self.ttCombomodelmodel.setColumnCount(2) - self.ttCombomodelmodel2.setHorizontalHeaderLabels(_TRL(["HOOK", "文本"])) - - self.tttable2 = QTableView(self) + self.ttCombomodelmodel2 = QStandardItemModel() + self.tttable2 = QTableView() + self.vboxlayout.addWidget(self.tttable2) self.tttable2.setModel(self.ttCombomodelmodel2) # self.tttable2 .horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents) self.tttable2.horizontalHeader().setStretchLastSection(True) @@ -658,7 +657,6 @@ class hookselect(closeashidewindow): self.tttable2.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) self.tttable2.clicked.connect(self.ViewThread2) - self.vboxlayout.addWidget(self.tttable2) self.searchtextlayout2 = QHBoxLayout() self.vboxlayout.addLayout(self.searchtextlayout2) self.searchtext2 = QLineEdit() @@ -685,16 +683,12 @@ class hookselect(closeashidewindow): self.sysOutput.setReadOnly(True) self.tabwidget = QTabWidget() + self.vboxlayout.addWidget(self.tabwidget) self.tabwidget.setTabPosition(QTabWidget.TabPosition.East) self.tabwidget.addTab(self.textOutput, _TR("文本")) self.tabwidget.addTab(self.sysOutput, _TR("系统")) - self.vboxlayout.addWidget(self.tabwidget) - self.hboxlayout.addLayout(self.vboxlayout) - self.setCentralWidget(self.widget) - self.changeprocessclear() - def showmenu(self, p: QPoint): r = self.tttable.currentIndex().row() if r < 0: @@ -895,7 +889,8 @@ class hookselect(closeashidewindow): print_exc() def showEvent(self, e): - gobject.baseobject.AttachProcessDialog.realshowhide.emit(False) + if gobject.baseobject.AttachProcessDialog: + gobject.baseobject.AttachProcessDialog.close() try: for i in range(len(self.save)): if self.save[i] in gobject.baseobject.textsource.selectedhook: @@ -904,18 +899,11 @@ class hookselect(closeashidewindow): except: print_exc() - def get_time_stamp(self): - ct = time.time() - local_time = time.localtime(ct) - data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time) - data_secs = (ct - int(ct)) * 1000 - time_stamp = "%s.%03d" % (data_head, data_secs) - return time_stamp def sysmessage(self, sentence): textbrowappendandmovetoend( - self.sysOutput, self.get_time_stamp() + " " + sentence + self.sysOutput, get_time_stamp() + " " + sentence ) def getnewsentence(self, sentence): diff --git a/LunaTranslator/LunaTranslator/gui/settin.py b/LunaTranslator/LunaTranslator/gui/settin.py index 20848c26..820e15ed 100644 --- a/LunaTranslator/LunaTranslator/gui/settin.py +++ b/LunaTranslator/LunaTranslator/gui/settin.py @@ -1,18 +1,24 @@ from qtsymbols import * -import qtawesome, gobject -import threading, windows, winsharedutils +import qtawesome +import functools from myutils.config import globalconfig, _TR from myutils.utils import wavmp3player -from gui.settingpage1 import setTabOne, setTabOne_direct -from gui.settingpage2 import setTabTwo, settab2d -from gui.settingpage_xianshishezhi import setTabThree, setTabThree_direct -from gui.settingpage_tts import setTab5, setTab5_direct +from gui.settingpage1 import setTabOne_lazy +from gui.settingpage2 import setTabTwo_lazy, checkconnected +from gui.settingpage_xianshishezhi import setTabThree_lazy +from gui.gui_xianshi_text import maybehavefontsizespin +from gui.settingpage_tts import setTab5, showvoicelist from gui.settingpage_cishu import setTabcishu -from gui.settingpage_quick import setTab_quick, setTab_quick_direct -from gui.setting_lang import setTablang, setTablangd +from gui.settingpage_quick import setTab_quick, registrhotkeys +from gui.setting_lang import setTablang from gui.setting_proxy import setTab_proxy -from gui.settingpage7 import setTab7, settab7direct -from gui.settingpage_about import setTab_about, setTab_about_dicrect +from gui.settingpage7 import setTab7_lazy, delaysetcomparetext +from gui.settingpage_about import ( + setTab_aboutlazy, + versionlabelmaybesettext, + updateprogress, + getversion, +) from gui.usefulwidget import closeashidewindow, makesubtab_lazy @@ -62,63 +68,73 @@ class Settin(closeashidewindow): versiontextsignal = pyqtSignal(str) progresssignal = pyqtSignal(str, int) fontbigsmallsignal = pyqtSignal(int) - clicksourcesignal = pyqtSignal(str) opensolvetextsig = pyqtSignal() showandsolvesig = pyqtSignal(str) - setstylesheetsignal = pyqtSignal() def __init__(self, parent): super(Settin, self).__init__(parent, globalconfig, "setting_geo_2") + self.setWindowIcon(qtawesome.icon("fa.gear")) self.mp3player = wavmp3player() self.mp3playsignal.connect(self.mp3player.mp3playfunction) self.opensolvetextsig.connect(self.opensolvetextfun) + self.showandsolvesig.connect(functools.partial(delaysetcomparetext, self)) + self.fontbigsmallsignal.connect(functools.partial(maybehavefontsizespin, self)) + self.voicelistsignal.connect(functools.partial(showvoicelist, self)) + self.versiontextsignal.connect( + functools.partial(versionlabelmaybesettext, self) + ) + self.progresssignal.connect(lambda text, val: updateprogress(self, text, val)) + self.isfirst = True + getversion(self) + checkconnected(self) + registrhotkeys(self) + + def showEvent(self, e: QShowEvent): + if self.isfirst: + self.isfirst = False + self.firstshow() + super().showEvent(e) + + def firstshow(self): self.setMinimumSize(100, 100) - self.list_width = 100 - self.window_height = 500 - self.savelastrect = None - - self.hooks = [] - - self.usevoice = 0 - setTabOne_direct(self) - settab2d(self) - settab7direct(self) - setTabThree_direct(self) - setTab5_direct(self) - setTab_quick_direct(self) - setTablangd(self) - setTab_about_dicrect(self) - - self.setstylesheetsignal.connect(gobject.baseobject.setcommonstylesheet) - threading.Thread(target=self.darklistener).start() - self.setWindowTitle(_TR("设置")) - self.setWindowIcon(qtawesome.icon("fa.gear")) - self.tab_widget = makesubtab_lazy(klass=TabWidget) + self.tab_widget, do = makesubtab_lazy( + [ + "文本输入", + "翻译设置", + "显示设置", + "文本处理", + "辞书设置", + "语音合成", + "快捷按键", + "语言设置", + "代理设置", + "其他设置", + ], + [ + functools.partial(setTabOne_lazy, self), + functools.partial(setTabTwo_lazy, self), + functools.partial(setTabThree_lazy, self), + functools.partial(setTab7_lazy, self), + functools.partial(setTabcishu, self), + functools.partial(setTab5, self), + functools.partial(setTab_quick, self), + functools.partial(setTablang, self), + functools.partial(setTab_proxy, self), + functools.partial(setTab_aboutlazy, self), + ], + klass=TabWidget, + delay=True, + ) self.setCentralWidget(self.tab_widget) - + do() self.tab_widget.setStyleSheet( """QListWidget { font:16pt ; } """ ) - # self.tab_widget.setTabPosition(QTabWidget.West) - setTabOne(self) - setTabTwo(self) - - setTabThree(self) - setTab7(self) - setTabcishu(self) - setTab5(self) - - setTab_quick(self) - - setTablang(self) - setTab_proxy(self) - setTab_about(self) - width = 0 fn = QFont() fn.setPixelSize(16) @@ -128,17 +144,7 @@ class Settin(closeashidewindow): width = max(fm.size(0, title).width(), width) width += 100 self.tab_widget.list_widget.setFixedWidth(width) - self.list_width = width def opensolvetextfun(self): self.show() self.tab_widget.setCurrentIndex(3) - - def darklistener(self): - sema = winsharedutils.startdarklistener() - while True: - # 会触发两次 - windows.WaitForSingleObject(sema, windows.INFINITE) - if globalconfig["darklight"] == 2: - self.setstylesheetsignal.emit() - windows.WaitForSingleObject(sema, windows.INFINITE) diff --git a/LunaTranslator/LunaTranslator/gui/setting_lang.py b/LunaTranslator/LunaTranslator/gui/setting_lang.py index e8ef04ef..3bc22a05 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_lang.py +++ b/LunaTranslator/LunaTranslator/gui/setting_lang.py @@ -1,35 +1,31 @@ -import os +import os, functools from myutils.config import globalconfig, _TRL, static_data, getlanguse from gui.usefulwidget import ( + D_getsimplecombobox, getsimplecombobox, - getcolorbutton, - makegrid, - tabadd_lazy, - makescroll, + D_getcolorbutton, + makescrollgrid, ) -def setTablang(self): - tabadd_lazy(self.tab_widget, ("语言设置"), lambda: setTablanglz(self)) - - -def setTablangd(self): +def createlangs(self): self.srclangswitcher = getsimplecombobox( _TRL(static_data["language_list_translator"]), globalconfig, "srclang3" ) + return self.srclangswitcher def setTablanglz(self): - grids = [ + return [ [("翻译及OCR语言", 15)], [ ("源语言", 5), - (self.srclangswitcher, 5), + (functools.partial(createlangs, self), 5), ], [ ("目标语言", 5), ( - getsimplecombobox( + D_getsimplecombobox( _TRL(static_data["language_list_translator"]), globalconfig, "tgtlang3", @@ -41,13 +37,13 @@ def setTablanglz(self): [ ("本软件显示语言(重启生效)", 5), ( - getsimplecombobox( + D_getsimplecombobox( (static_data["language_list_show"]), globalconfig, "languageuse" ), 5, ), ( - getcolorbutton( + D_getcolorbutton( globalconfig, "", callback=lambda: os.startfile( @@ -62,7 +58,6 @@ def setTablanglz(self): [], ] - gridlayoutwidget = makegrid(grids) - gridlayoutwidget = makescroll(gridlayoutwidget) - return gridlayoutwidget +def setTablang(self, l): + makescrollgrid(setTablanglz(self), l) diff --git a/LunaTranslator/LunaTranslator/gui/setting_proxy.py b/LunaTranslator/LunaTranslator/gui/setting_proxy.py index 6761adb3..cdd41704 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_proxy.py +++ b/LunaTranslator/LunaTranslator/gui/setting_proxy.py @@ -3,14 +3,13 @@ from myutils.config import _TR from myutils.config import globalconfig from myutils.utils import splittranslatortypes from gui.usefulwidget import ( - getsimpleswitch, + D_getsimpleswitch, makegrid, makesubtab_lazy, - tabadd_lazy, - makevbox, - makescroll, + getvboxwidget, + makescrollgrid, ) -import os +import os, functools def getall(l, item="fanyi", name=""): @@ -28,7 +27,7 @@ def getall(l, item="fanyi", name=""): line += [ (globalconfig[item][fanyi]["name"], 6), - getsimpleswitch(globalconfig[item][fanyi], "useproxy", default=True), + D_getsimpleswitch(globalconfig[item][fanyi], "useproxy", default=True), "", ] if i % 3 == 0: @@ -41,35 +40,50 @@ def getall(l, item="fanyi", name=""): return grids -def setTab_proxy_lazy(self): +def createcheckbtn(self): - proxy = QLineEdit(globalconfig["proxy"]) btn = QPushButton(_TR("确定")) - btn.clicked.connect(lambda x: globalconfig.__setitem__("proxy", proxy.text())) + btn.clicked.connect( + lambda x: globalconfig.__setitem__("proxy", self.__proxyedit.text()) + ) + self.__checkproxybtn = btn + _ifusesysproxy(self, globalconfig["usesysproxy"]) + return btn - def _ifusesysproxy(x): - proxy.setEnabled(not x) - btn.setEnabled(not x) - _ifusesysproxy(globalconfig["usesysproxy"]) +def createproxyedit(self): + proxy = QLineEdit(globalconfig["proxy"]) + self.__proxyedit = proxy + return proxy + + +def _ifusesysproxy(self, x): + self.__proxyedit.setEnabled(not x) + self.__checkproxybtn.setEnabled(not x) + + +def setTab_proxy_lazy(self, basel): + grid1 = [ - [("使用代理", 5), (getsimpleswitch(globalconfig, "useproxy"), 1), ("", 10)], + [("使用代理", 5), (D_getsimpleswitch(globalconfig, "useproxy"), 1), ("", 10)], [ ("自动获取系统代理", 5), ( - getsimpleswitch( - globalconfig, "usesysproxy", callback=lambda x: _ifusesysproxy(x) + D_getsimpleswitch( + globalconfig, + "usesysproxy", + callback=lambda x: _ifusesysproxy(self, x), ) ), ], [ ("手动设置代理(ip:port)", 5), - (proxy, 5), - (btn, 2), + (functools.partial(createproxyedit, self), 5), + (functools.partial(createcheckbtn, self), 2), ], [], - [("使用代理的项目", 5)], + [("使用代理的项目", -1)], ] lixians, pre, mianfei, develop, shoufei = splittranslatortypes() @@ -80,18 +94,23 @@ def setTab_proxy_lazy(self): item="ocr", name="./Lunatranslator/ocrengines/%s.py", ) - tab = makesubtab_lazy( + vw, vl = getvboxwidget() + basel.addWidget(vw) + gridlayoutwidget, do = makegrid(grid1, delay=True) + vl.addWidget(gridlayoutwidget) + tab, dotab = makesubtab_lazy( ["在线翻译", "注册在线翻译", "在线OCR"], [ - lambda: makescroll(makegrid(mianfei)), - lambda: makescroll(makegrid(shoufei)), - lambda: makescroll(makegrid(ocrs)), + functools.partial(makescrollgrid, mianfei), + functools.partial(makescrollgrid, shoufei), + functools.partial(makescrollgrid, ocrs), ], + delay=True, ) - - gridlayoutwidget = makegrid(grid1) - return makevbox([gridlayoutwidget, tab]) + vl.addWidget(tab) + do() + dotab() -def setTab_proxy(self): - tabadd_lazy(self.tab_widget, ("代理设置"), lambda: setTab_proxy_lazy(self)) +def setTab_proxy(self, l): + setTab_proxy_lazy(self, l) diff --git a/LunaTranslator/LunaTranslator/gui/settingpage1.py b/LunaTranslator/LunaTranslator/gui/settingpage1.py index e6feb6b9..6e6be8f4 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage1.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage1.py @@ -7,16 +7,16 @@ from gui.dialog_savedgame import dialog_savedgame_new import gobject from gui.inputdialog import regexedit from gui.usefulwidget import ( - getsimplecombobox, - getspinbox, - makescroll, - getcolorbutton, + D_getsimplecombobox, + D_getspinbox, + D_getcolorbutton, makegrid, tabadd_lazy, yuitsu_switch, - makevbox, - getsimpleswitch, + getvboxwidget, + D_getsimpleswitch, makesubtab_lazy, + makescrollgrid, ) from gui.codeacceptdialog import codeacceptdialog from myutils.utils import makehtml, getfilemd5 @@ -30,17 +30,40 @@ def gethookgrid(self): (makehtml("https://github.com/HIllya51/LunaHook"), 8, "link"), ], [], - [("选择游戏", 5), self.selectbutton, ("", 5)], - [("选择文本", 5), self.selecthookbutton], + [ + ("选择游戏", 5), + D_getcolorbutton( + globalconfig, + "", + gobject.baseobject.createattachprocess, + name="selectbutton", + parent=self, + icon="fa.gear", + constcolor="#FF69B4", + ), + ("", 5), + ], + [ + ("选择文本", 5), + D_getcolorbutton( + globalconfig, + "", + lambda: gobject.baseobject.hookselectdialog.showsignal.emit(), + name="selecthookbutton", + parent=self, + icon="fa.gear", + constcolor="#FF69B4", + ), + ], [], [ ("检测到游戏时自动开始", 5), - (getsimpleswitch(globalconfig, "autostarthook"), 1), + (D_getsimpleswitch(globalconfig, "autostarthook"), 1), ], [ ("已保存游戏", 5), ( - getcolorbutton( + D_getcolorbutton( globalconfig, "", icon="fa.gamepad", @@ -53,12 +76,12 @@ def gethookgrid(self): [], [ ("过滤反复刷新的句子", 5), - (getsimpleswitch(globalconfig, "direct_filterrepeat"), 1), + (D_getsimpleswitch(globalconfig, "direct_filterrepeat"), 1), ], [ ("刷新延迟(ms)", 5), ( - getspinbox( + D_getspinbox( 0, 10000, globalconfig, @@ -71,7 +94,7 @@ def gethookgrid(self): [ ("最大缓冲区长度", 5), ( - getspinbox( + D_getspinbox( 0, 1000000, globalconfig, @@ -84,7 +107,7 @@ def gethookgrid(self): [ ("最大缓存文本长度", 5), ( - getspinbox( + D_getspinbox( 0, 1000000000, globalconfig, @@ -97,9 +120,9 @@ def gethookgrid(self): [], [ ("过滤包含乱码的文本行", 5), - (getsimpleswitch(globalconfig, "filter_chaos_code"), 1), + (D_getsimpleswitch(globalconfig, "filter_chaos_code"), 1), ( - getcolorbutton( + D_getcolorbutton( globalconfig, "", icon="fa.gear", @@ -110,8 +133,8 @@ def gethookgrid(self): ), ], [], - [("区分人名和文本", 5), getsimpleswitch(globalconfig, "allow_set_text_name")], - [("使用YAPI注入", 5), getsimpleswitch(globalconfig, "use_yapi")], + [("区分人名和文本", 5), D_getsimpleswitch(globalconfig, "allow_set_text_name")], + [("使用YAPI注入", 5), D_getsimpleswitch(globalconfig, "use_yapi")], ] return grids @@ -223,8 +246,9 @@ def exportchspatch(self): ff.write("{}") -def gethookembedgrid(self): - self.gamefont_comboBox = QFontComboBox() +def creategamefont_comboBox(): + + gamefont_comboBox = QFontComboBox() def callback(x): globalconfig["embedded"].__setitem__("changefont_font", x) @@ -233,14 +257,16 @@ def gethookembedgrid(self): except: pass - self.gamefont_comboBox.currentTextChanged.connect(callback) - self.gamefont_comboBox.setCurrentFont( - QFont(globalconfig["embedded"]["changefont_font"]) - ) + gamefont_comboBox.currentTextChanged.connect(callback) + gamefont_comboBox.setCurrentFont(QFont(globalconfig["embedded"]["changefont_font"])) + return gamefont_comboBox + + +def gethookembedgrid(self): grids = [ [ ("导出翻译补丁", 5), - getcolorbutton( + D_getcolorbutton( globalconfig, "", callback=lambda x: exportchspatch(self), @@ -252,7 +278,7 @@ def gethookembedgrid(self): [ ("保留原文", 5), ( - getsimpleswitch( + D_getsimpleswitch( globalconfig["embedded"], "keeprawtext", callback=lambda _: gobject.baseobject.textsource.flashembedsettings(), @@ -264,7 +290,7 @@ def gethookembedgrid(self): ("翻译等待时间(s)", 5), "", ( - getspinbox( + D_getspinbox( 0, 30, globalconfig["embedded"], @@ -278,13 +304,13 @@ def gethookembedgrid(self): ], [ ("使用最快翻译而非指定翻译器", 5), - (getsimpleswitch(globalconfig["embedded"], "as_fast_as_posible"), 1), + (D_getsimpleswitch(globalconfig["embedded"], "as_fast_as_posible"), 1), ], [ ("内嵌的翻译器", 5), "", ( - getsimplecombobox( + D_getsimplecombobox( _TRL( [ globalconfig["fanyi"][x]["name"] @@ -300,13 +326,13 @@ def gethookembedgrid(self): ], [ ("将汉字转换成繁体/日式汉字", 5), - (getsimpleswitch(globalconfig["embedded"], "trans_kanji"), 1), + (D_getsimpleswitch(globalconfig["embedded"], "trans_kanji"), 1), ], [ ("在重叠显示的字间插入空格", 5), "", ( - getsimplecombobox( + D_getsimplecombobox( _TRL(["不插入空格", "每个字后插入空格", "仅在无法编码的字后插入"]), globalconfig["embedded"], "insertspace_policy", @@ -318,20 +344,20 @@ def gethookembedgrid(self): [ ("修改游戏字体", 5), ( - getsimpleswitch( + D_getsimpleswitch( globalconfig["embedded"], "changefont", callback=lambda _: gobject.baseobject.textsource.flashembedsettings(), ), 1, ), - (self.gamefont_comboBox, 5), + (creategamefont_comboBox, 5), ], [], [ ("内嵌安全性检查", 5), - getsimpleswitch(globalconfig["embedded"], "safecheck_use"), - getcolorbutton( + D_getsimpleswitch(globalconfig["embedded"], "safecheck_use"), + D_getcolorbutton( globalconfig, "", callback=lambda x: regexedit( @@ -341,7 +367,6 @@ def gethookembedgrid(self): constcolor="#FF69B4", ), ], - # [('修改字体字符集',5),(getsimpleswitch( globalconfig['embedded'] ,'changecharset',callback=lambda _:gobject.baseobject.textsource.flashembedsettings()),1) ,(getsimplecombobox(_TRL(static_data["charsetmapshow"]),globalconfig['embedded'],'changecharset_charset',callback=lambda _:gobject.baseobject.textsource.flashembedsettings()),5)], ] return grids @@ -352,7 +377,7 @@ def getTabclip(self): grids = [ [ ("排除复制自翻译器的文本", 3), - getsimpleswitch(globalconfig, "excule_from_self"), + D_getsimpleswitch(globalconfig, "excule_from_self"), ("", 3), ] ] @@ -362,20 +387,20 @@ def getTabclip(self): def outputgrid(self): grids = [ - [("自动输出提取的文本", 10)], + [("自动输出提取的文本", 15)], [], - [("剪贴板", 10)], + [("剪贴板", 0)], [ "", ("输出到剪贴板", 5), - (getsimpleswitch(globalconfig["textoutputer"]["clipboard"], "use"), 1), + (D_getsimpleswitch(globalconfig["textoutputer"]["clipboard"], "use"), 1), ], - [("WebSocket", 10)], + [("WebSocket", -1)], [ "", ("输出到WebSocket", 5), ( - getsimpleswitch( + D_getsimpleswitch( globalconfig["textoutputer"]["websocket"], "use", callback=lambda _: gobject.baseobject.startoutputer_re("websocket"), @@ -387,7 +412,7 @@ def outputgrid(self): "", ("端口号", 5), ( - getspinbox( + D_getspinbox( 0, 65535, globalconfig["textoutputer"]["websocket"], @@ -401,14 +426,17 @@ def outputgrid(self): return grids -def setTabOne_direct(self): +def setTabOne(self): + tabadd_lazy(self.tab_widget, ("文本输入"), lambda l: setTabOne_lazy(self, l)) - self.tab1grids = [ - [("选择文本输入源", 8)], + +def setTabOne_lazy(self, basel): + tab1grids = [ + [("选择文本输入源", -1)], [ ("HOOK", 3), ( - getsimpleswitch( + D_getsimpleswitch( globalconfig["sourcestatus2"]["texthook"], "use", name="texthook", @@ -428,7 +456,7 @@ def setTabOne_direct(self): "", ("OCR", 3), ( - getsimpleswitch( + D_getsimpleswitch( globalconfig["sourcestatus2"]["ocr"], "use", name="ocr", @@ -448,7 +476,7 @@ def setTabOne_direct(self): "", ("剪贴板", 3), ( - getsimpleswitch( + D_getsimpleswitch( globalconfig["sourcestatus2"]["copy"], "use", name="copy", @@ -469,57 +497,21 @@ def setTabOne_direct(self): ], ] - getcolorbutton( - globalconfig, - "", - name="selectbutton", - parent=self, - icon="fa.gear", - constcolor="#FF69B4", - callback=lambda: gobject.baseobject.AttachProcessDialog.showsignal.emit(), - ) - getcolorbutton( - globalconfig, - "", - name="selectbuttonembed", - parent=self, - icon="fa.gear", - constcolor="#FF69B4", - callback=lambda: gobject.baseobject.AttachProcessDialog.showsignal.emit(), - ) - getcolorbutton( - globalconfig, - "", - name="selecthookbutton", - parent=self, - icon="fa.gear", - constcolor="#FF69B4", - callback=lambda: gobject.baseobject.hookselectdialog.showsignal.emit(), - ) - self.clicksourcesignal.connect(lambda k: getattr(self, "sourceswitchs")[k].click()) - - self.threshold1label = QLabel() - self.threshold2label = QLabel() - - self.Scriptscombo = QComboBox() - - -def setTabOne(self): - tabadd_lazy(self.tab_widget, ("文本输入"), lambda: setTabOne_lazy(self)) - - -def setTabOne_lazy(self): - - tab = makesubtab_lazy( + vw, vl = getvboxwidget() + basel.addWidget(vw) + gridlayoutwidget, do = makegrid(tab1grids, delay=True) + vl.addWidget(gridlayoutwidget) + tab, dotab = makesubtab_lazy( ["HOOK设置", "OCR设置", "剪贴板", "内嵌翻译", "文本输出"], [ - lambda: makescroll(makegrid(gethookgrid(self))), - lambda: makescroll(makegrid(getocrgrid(self))), - lambda: makescroll(makegrid(getTabclip(self))), - lambda: makescroll(makegrid(gethookembedgrid(self))), - lambda: makescroll(makegrid(outputgrid(self))), + lambda l: makescrollgrid(gethookgrid(self), l), + lambda l: makescrollgrid(getocrgrid(self), l), + lambda l: makescrollgrid(getTabclip(self), l), + lambda l: makescrollgrid(gethookembedgrid(self), l), + lambda l: makescrollgrid(outputgrid(self), l), ], + delay=True, ) - - gridlayoutwidget = makegrid(self.tab1grids) - return makevbox([gridlayoutwidget, tab]) + vl.addWidget(tab) + do() + dotab() diff --git a/LunaTranslator/LunaTranslator/gui/settingpage2.py b/LunaTranslator/LunaTranslator/gui/settingpage2.py index afe803de..eb5dabcc 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage2.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage2.py @@ -6,19 +6,20 @@ from myutils.subproc import subproc_w from gui.pretransfile import sqlite2json from myutils.config import globalconfig, _TR from myutils.utils import selectdebugfile, splittranslatortypes, checkportavailable -import os, time, requests, threading +import os, time, requests from gui.inputdialog import autoinitdialog, autoinitdialog_items from gui.usefulwidget import ( + D_getspinbox, getspinbox, - getcolorbutton, - getsimpleswitch, + D_getcolorbutton, + D_getsimpleswitch, selectcolor, makegrid, makesubtab_lazy, - makescroll, - makevbox, - tabadd_lazy, + makescrollgrid, + getvboxwidget, ) +from myutils.wrapper import threader import time, hashlib @@ -45,7 +46,7 @@ def initsome11(self, l, label=None): if fanyi in translatorsetting: items = autoinitdialog_items(translatorsetting[fanyi]) - last = getcolorbutton( + last = D_getcolorbutton( globalconfig, "", callback=functools.partial( @@ -59,7 +60,7 @@ def initsome11(self, l, label=None): constcolor="#FF69B4", ) elif fanyi == "selfbuild": - last = getcolorbutton( + last = D_getcolorbutton( globalconfig, "", callback=lambda: selectdebugfile("./userconfig/selfbuild.py"), @@ -70,12 +71,12 @@ def initsome11(self, l, label=None): last = "" line += [ (globalconfig["fanyi"][fanyi]["name"], 6), - getsimpleswitch( + D_getsimpleswitch( globalconfig["fanyi"][fanyi], "use", callback=functools.partial(gobject.baseobject.prepare, fanyi), ), - getcolorbutton( + D_getcolorbutton( globalconfig["fanyi"][fanyi], "color", parent=self, @@ -103,83 +104,98 @@ def initsome11(self, l, label=None): return grids -def setTabTwo(self): - tabadd_lazy(self.tab_widget, ("翻译设置"), lambda: setTabTwo_lazy(self)) +def statuslabelsettext(self, text): + try: + self.statuslabel.setText(text) + except: + pass -def settab2d(self): +def createstatuslabel(self): + self.statuslabel = QLabel() + return self.statuslabel - def checkconnected(): - lixians, pre, mianfei, develop, shoufei = splittranslatortypes() - while True: - port = globalconfig["debugport"] - _path = None - for syspath in [ - globalconfig["chromepath"], - r"C:\Program Files\Google\Chrome\Application\chrome.exe", - r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", - ]: - if os.path.exists(syspath) and os.path.isfile(syspath): - _path = syspath - break - needstart = ( - any([globalconfig["fanyi"][dev]["use"] for dev in develop]) and _path - ) - try: +@threader +def checkconnected(self): + lixians, pre, mianfei, develop, shoufei = splittranslatortypes() + while True: + port = globalconfig["debugport"] + _path = None + for syspath in [ + globalconfig["chromepath"], + r"C:\Program Files\Google\Chrome\Application\chrome.exe", + r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", + ]: + if os.path.exists(syspath) and os.path.isfile(syspath): + _path = syspath + break + needstart = ( + any([globalconfig["fanyi"][dev]["use"] for dev in develop]) and _path + ) + try: + + if needstart: + requests.get("http://127.0.0.1:{}/json/list".format(port)).json() + statuslabelsettext(self, _TR("连接成功")) + except: + if checkportavailable(port): + statuslabelsettext(self, _TR("连接失败")) if needstart: - requests.get("http://127.0.0.1:{}/json/list".format(port)).json() - self.statuslabel.setText(_TR("连接成功")) - except: - if checkportavailable(port): - self.statuslabel.setText(_TR("连接失败")) - if needstart: - call = ( - '"%s" --disable-extensions --remote-allow-origins=* --disable-gpu --no-first-run --remote-debugging-port=%d --user-data-dir="%s"' - % ( - _path, - port, - os.path.abspath("./chrome_cache/" + hashtext(_path)), - ) + call = ( + '"%s" --disable-extensions --remote-allow-origins=* --disable-gpu --no-first-run --remote-debugging-port=%d --user-data-dir="%s"' + % ( + _path, + port, + os.path.abspath("./chrome_cache/" + hashtext(_path)), ) - print(call) - self.engine = subproc_w(call) - else: - self.statuslabel.setText(_TR("端口冲突")) - time.sleep(1) - - threading.Thread(target=checkconnected).start() + ) + print(call) + self.engine = subproc_w(call) + else: + statuslabelsettext(self, _TR("端口冲突")) + time.sleep(1) -def setTabTwo_lazy(self): +def createbtnexport(self): bt = QPushButton(_TR("导出翻译记录为json文件")) bt.clicked.connect(lambda x: sqlite2json(self)) + return bt + + +def createfuzspin(self): _fuzainum = getspinbox(1, 99999, globalconfig, "loadbalance_oncenum", step=1) _fuzainum.setEnabled(globalconfig["loadbalance"]) + self._fuzainum = _fuzainum + return _fuzainum + + +def setTabTwo_lazy(self, basel): + grids = [ [ ("最短翻译字数", 7), - (getspinbox(0, 9999, globalconfig, "minlength"), 3), + (D_getspinbox(0, 9999, globalconfig, "minlength"), 3), "", ("最长翻译字数", 7), - (getspinbox(0, 9999, globalconfig, "maxlength"), 3), + (D_getspinbox(0, 9999, globalconfig, "maxlength"), 3), "", ], [ ("使用翻译缓存", 8), - (getsimpleswitch(globalconfig, "uselongtermcache")), + (D_getsimpleswitch(globalconfig, "uselongtermcache")), "", "", ("显示错误信息", 8), - (getsimpleswitch(globalconfig, "showtranexception"), 1), + (D_getsimpleswitch(globalconfig, "showtranexception"), 1), "", "", ("翻译请求间隔(s)", 7), ( - getspinbox( + D_getspinbox( 0, 9999, globalconfig, "requestinterval", step=0.1, double=True ), 3, @@ -188,29 +204,29 @@ def setTabTwo_lazy(self): [ ("均衡负载", 8), ( - getsimpleswitch( + D_getsimpleswitch( globalconfig, "loadbalance", - callback=lambda x: _fuzainum.setEnabled(x), + callback=lambda x: self._fuzainum.setEnabled(x), ) ), "", "", ("单次负载个数", 7), - (_fuzainum, 3), + (functools.partial(createfuzspin, self), 3), ], ] - online_reg_grid = [[("若有多个api key,用|将每个key连接后填入,即可轮流使用", 24)]] + online_reg_grid = [[("若有多个api key,用|将每个key连接后填入,即可轮流使用", -1)]] pretransgrid = [ [ ("预翻译采用模糊匹配", 8), - (getsimpleswitch(globalconfig, "premtsimiuse"), 1), + (D_getsimpleswitch(globalconfig, "premtsimiuse"), 1), "", ("模糊匹配_相似度_%", 8), - (getspinbox(0, 100, globalconfig, "premtsimi2"), 3), + (D_getspinbox(0, 100, globalconfig, "premtsimi2"), 3), ], [ - (bt, 12), + (functools.partial(createbtnexport, self), 12), ], [], ] @@ -230,7 +246,7 @@ def setTabTwo_lazy(self): [ ("Chromium_路径", 8), ( - getcolorbutton( + D_getcolorbutton( globalconfig, "", callback=functools.partial( @@ -243,9 +259,9 @@ def setTabTwo_lazy(self): ], [ ("端口号", 8), - (getspinbox(0, 65535, globalconfig, "debugport"), 4), + (D_getspinbox(0, 65535, globalconfig, "debugport"), 4), ], - [(self.statuslabel, 16)], + [(functools.partial(createstatuslabel, self), 16)], [], ] lixians, pre, mianfei, develop, shoufei = splittranslatortypes() @@ -255,16 +271,23 @@ def setTabTwo_lazy(self): developgrid += initsome11(self, develop) online_reg_grid += initsome11(self, shoufei) pretransgrid += initsome11(self, pre) - tab = makesubtab_lazy( + vw, vl = getvboxwidget() + basel.addWidget(vw) + + gridlayoutwidget, do = makegrid(grids, delay=True) + vl.addWidget(gridlayoutwidget) + tab, dotab = makesubtab_lazy( ["在线翻译", "develop", "注册在线翻译", "离线翻译", "预翻译"], [ - lambda: makescroll(makegrid(onlinegrid)), - lambda: makescroll(makegrid(developgrid)), - lambda: makescroll(makegrid(online_reg_grid)), - lambda: makescroll(makegrid(offlinegrid)), - lambda: makescroll(makegrid(pretransgrid)), + functools.partial(makescrollgrid, onlinegrid), + functools.partial(makescrollgrid, developgrid), + functools.partial(makescrollgrid, online_reg_grid), + functools.partial(makescrollgrid, offlinegrid), + functools.partial(makescrollgrid, pretransgrid), ], + delay=True, ) + vl.addWidget(tab) - gridlayoutwidget = makegrid(grids) - return makevbox([gridlayoutwidget, tab]) + do() + dotab() diff --git a/LunaTranslator/LunaTranslator/gui/settingpage7.py b/LunaTranslator/LunaTranslator/gui/settingpage7.py index a76f6b74..422df750 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage7.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage7.py @@ -1,21 +1,20 @@ -import functools +import functools, copy, os, gobject from qtsymbols import * from traceback import print_exc from myutils.config import ( globalconfig, postprocessconfig, static_data, + savehook_new_data, _TR, ) -import functools, gobject from gui.usefulwidget import ( getcolorbutton, - getsimpleswitch, - makevbox, - makescroll, - makegrid, + D_getcolorbutton, + D_getsimpleswitch, + makescrollgrid, + getvboxwidget, makesubtab_lazy, - tabadd_lazy, ) from gui.codeacceptdialog import codeacceptdialog from gui.inputdialog import ( @@ -28,8 +27,6 @@ from myutils.utils import ( checkpostlangmatch, loadpostsettingwindowmethod, ) -from myutils.config import savehook_new_data -import copy, os from myutils.post import POSTSOLVE @@ -67,12 +64,13 @@ def savegameprocesstext(): print_exc() -def settab7direct(self): - self.comparelayout = getcomparelayout(self) - - -def setTab7(self): - tabadd_lazy(self.tab_widget, ("文本处理"), lambda: setTab7_lazy(self)) +def delaysetcomparetext(self, s): + try: + self.__fromtext.setPlainText(s) + self.__totext.setPlainText(POSTSOLVE(s)) + except: + self.__fromtext_cache = s + self.__totext_cache = POSTSOLVE(s) def getcomparelayout(self): @@ -93,16 +91,17 @@ def getcomparelayout(self): layout.addWidget(totext) w = QWidget() w.setLayout(layout) - - def _(s): - fromtext.setPlainText(s) - totext.setPlainText(POSTSOLVE(fromtext.toPlainText())) - - self.showandsolvesig.connect(_) + self.__fromtext = fromtext + self.__totext = totext + try: + fromtext.setPlainText(self.__fromtext_cache) + totext.setPlainText(self.__totext_cache) + except: + pass return w -def setTab7_lazy(self): +def setTab7_lazy(self, basel): grids = [[("预处理方法", 6), "", "", ("调整执行顺序", 6)]] if set(postprocessconfig.keys()) != set(globalconfig["postprocess_rank"]): globalconfig["postprocess_rank"] = list(postprocessconfig.keys()) @@ -137,7 +136,7 @@ def setTab7_lazy(self): for i, post in enumerate(sortlist): if post == "_11": - config = getcolorbutton( + config = D_getcolorbutton( globalconfig, "", callback=lambda: selectdebugfile("./userconfig/mypost.py"), @@ -148,7 +147,7 @@ def setTab7_lazy(self): if post not in postprocessconfig: continue if post == "_remove_chaos": - config = getcolorbutton( + config = D_getcolorbutton( globalconfig, "", icon="fa.gear", @@ -172,7 +171,7 @@ def setTab7_lazy(self): 600, items, ) - config = getcolorbutton( + config = D_getcolorbutton( globalconfig, "", callback=callback, @@ -182,14 +181,14 @@ def setTab7_lazy(self): else: config = "" - button_up = getcolorbutton( + button_up = D_getcolorbutton( globalconfig, "", callback=functools.partial(changerank, post, True), icon="fa.arrow-up", constcolor="#FF69B4", ) - button_down = getcolorbutton( + button_down = D_getcolorbutton( globalconfig, "", callback=functools.partial(changerank, post, False), @@ -199,7 +198,7 @@ def setTab7_lazy(self): l = [ ((postprocessconfig[post]["name"]), 6), - getsimpleswitch(postprocessconfig[post], "use"), + D_getsimpleswitch(postprocessconfig[post], "use"), config, button_up, button_down, @@ -211,7 +210,7 @@ def setTab7_lazy(self): visname = item["visname"] if checkpostlangmatch(name): grids2.append( - [((visname), 6), getsimpleswitch(globalconfig["transoptimi"], name)] + [((visname), 6), D_getsimpleswitch(globalconfig["transoptimi"], name)] ) setting = loadpostsettingwindowmethod(name) @@ -220,7 +219,7 @@ def setTab7_lazy(self): if setting: grids2[-1].append( - getcolorbutton( + D_getcolorbutton( globalconfig, "", callback=functools.partial(__, setting, self), @@ -230,8 +229,10 @@ def setTab7_lazy(self): ) grids2 += [[("", 12)]] - def __(): - _w = makescroll(makegrid(grids, True, savelist, savelay)) + def ___(lay): + vboxw, vbox = getvboxwidget() + lay.addWidget(vboxw) + _w = makescrollgrid(grids, vbox, True, savelist, savelay) _w.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) def showmenu(p: QPoint): @@ -249,11 +250,13 @@ def setTab7_lazy(self): pass _w.customContextMenuRequested.connect(showmenu) - return _w - tab = makesubtab_lazy( + vbox.addWidget(getcomparelayout(self)) + + tab, dotab = makesubtab_lazy( ["文本预处理", "翻译优化"], - [lambda: __(), lambda: makescroll(makegrid(grids2))], + [___, functools.partial(makescrollgrid, grids2)], + delay=True, ) - - return makevbox([tab, self.comparelayout]) + basel.addWidget(tab) + dotab() diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_about.py b/LunaTranslator/LunaTranslator/gui/settingpage_about.py index 7c4f658d..5fea81b9 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_about.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_about.py @@ -1,17 +1,15 @@ from qtsymbols import * from gui.usefulwidget import ( - getsimpleswitch, - getsimplecombobox, - makegrid, - makescroll, + D_getsimpleswitch, + D_getsimplecombobox, + makescrollgrid, makesubtab_lazy, - tabadd_lazy, ) from myutils.config import globalconfig, _TR, static_data from myutils.wrapper import threader import platform, winsharedutils, sys, os from myutils.utils import makehtml, getimageformatlist -from functools import partial +import functools from myutils.githubupdate import updatemethod, getvesionmethod @@ -19,6 +17,7 @@ from myutils.githubupdate import updatemethod, getvesionmethod def getversion(self): version = winsharedutils.queryversion(sys.argv[0]) if version is None: + self.versiontextsignal.emit("unknown") return versionstring = f"v{version[0]}.{version[1]}.{version[2]}" self.versiontextsignal.emit( @@ -49,18 +48,15 @@ def getversion(self): def updateprogress(self, text, val): - self.downloadprogress.setValue(val) - self.downloadprogress.setFormat(text) + try: + self.downloadprogress.setValue(val) + self.downloadprogress.setFormat(text) + except: + self.downloadprogress_cache = val, text -def setTab_about_dicrect(self): +def createdownloadprogress(self): - self.versionlabel = QLabel() - self.versionlabel.setOpenExternalLinks(True) - self.versionlabel.setTextInteractionFlags( - Qt.TextInteractionFlag.LinksAccessibleByMouse - ) - self.versiontextsignal.connect(lambda x: self.versionlabel.setText(x)) self.downloadprogress = QProgressBar() self.downloadprogress.setRange(0, 10000) @@ -68,19 +64,37 @@ def setTab_about_dicrect(self): self.downloadprogress.setAlignment( Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter ) - self.progresssignal.connect(lambda text, val: updateprogress(self, text, val)) - getversion(self) + try: + val, text = self.downloadprogress_cache + self.downloadprogress.setValue(val) + self.downloadprogress.setFormat(text) + except: + pass + return self.downloadprogress -def setTab_about(self): - tabadd_lazy(self.tab_widget, ("其他设置"), lambda: setTab_aboutlazy(self)) +def createversionlabel(self): + + self.versionlabel = QLabel() + self.versionlabel.setOpenExternalLinks(True) + self.versionlabel.setTextInteractionFlags( + Qt.TextInteractionFlag.LinksAccessibleByMouse + ) + try: + self.versionlabel.setText(self.versionlabel_cache) + except: + pass + return self.versionlabel -def double_(self, grid): - return makescroll(makegrid(grid)) +def versionlabelmaybesettext(self, x): + try: + self.versionlabel.setText(x) + except: + self.versionlabel_cache = x -def resourcegrid(self): +def resourcegrid(self, l): titles = [] makewidgetsfunctions = [] for sourcetype in static_data["aboutsource"]: @@ -106,11 +120,27 @@ def resourcegrid(self): else: __ = True grid.append([(_TR(name), 1, ""), (makehtml(link, __), 2, "link")]) - makewidgetsfunctions.append(partial(double_, self, grid)) - return makesubtab_lazy(titles, makewidgetsfunctions) + makewidgetsfunctions.append(functools.partial(makescrollgrid, grid)) + tab, dotab = makesubtab_lazy(titles, makewidgetsfunctions, delay=True) + l.addWidget(tab) + dotab() -def setTab_aboutlazy(self): +def createimageview(self): + lb = QLabel() + img = QPixmap.fromImage(QImage("./files/zan.jpg")) + img.setDevicePixelRatio(self.devicePixelRatioF()) + img = img.scaled( + 600, + 600, + Qt.AspectRatioMode.KeepAspectRatio, + Qt.TransformationMode.SmoothTransformation, + ) + lb.setPixmap(img) + return lb + + +def setTab_aboutlazy(self, basel): webviews = ["IEFrame", "WebView2"] if os.path.exists("./LunaTranslator/runtime/PyQt5/Qt5/bin/Qt5WebEngineCore.dll"): webviews.append("QWebEngine") @@ -118,22 +148,22 @@ def setTab_aboutlazy(self): [ ("自动下载更新(需要连接github)", 5), ( - getsimpleswitch( + D_getsimpleswitch( globalconfig, "autoupdate", callback=lambda x: getversion(self) ), 1, ), ("", 10), ], - [(self.versionlabel, 10)], - [(self.downloadprogress, 10)], + [(functools.partial(createversionlabel, self), 10)], + [(functools.partial(createdownloadprogress, self), 10)], [], - [("Internet", 5)], - [(getsimplecombobox(["winhttp", "libcurl"], globalconfig, "network"), 5)], - [("WebView", 5)], + [("网络请求", -1)], + [(D_getsimplecombobox(["winhttp", "libcurl"], globalconfig, "network"), 5)], + [("网页显示", -1)], [ ( - getsimplecombobox( + D_getsimplecombobox( webviews, globalconfig, "usewebview", @@ -141,8 +171,8 @@ def setTab_aboutlazy(self): 5, ) ], - [("截图保存格式", 5)], - [(getsimplecombobox(getimageformatlist(), globalconfig, "imageformat"), 5)], + [("截图保存格式", -1)], + [(D_getsimplecombobox(getimageformatlist(), globalconfig, "imageformat"), 5)], ] shuominggrid = [ @@ -170,19 +200,10 @@ def setTab_aboutlazy(self): (makehtml("https://qm.qq.com/q/qE32v9NYBO", show=912525396), 3, "link"), ], [], - [("如果你感觉该软件对你有帮助,欢迎微信扫码赞助,谢谢~", 0)], + [("如果你感觉该软件对你有帮助,欢迎微信扫码赞助,谢谢~", -1)], ] - lb = QLabel(self) - img = QPixmap.fromImage(QImage("./files/zan.jpg")) - img.setDevicePixelRatio(self.devicePixelRatioF()) - img = img.scaled( - 600, - 600, - Qt.AspectRatioMode.KeepAspectRatio, - Qt.TransformationMode.SmoothTransformation, - ) - lb.setPixmap(img) - shuominggrid += [[(lb, 0)]] + + shuominggrid += [[(functools.partial(createimageview, self), -1)]] else: shuominggrid += [ [], @@ -202,14 +223,14 @@ def setTab_aboutlazy(self): ], ] - tab = makesubtab_lazy( + tab, dotab = makesubtab_lazy( ["相关说明", "其他设置", "资源下载"], [ - lambda: makescroll( - makegrid(shuominggrid), - ), - lambda: makescroll(makegrid(grid2)), - lambda: resourcegrid(self), + functools.partial(makescrollgrid, shuominggrid), + functools.partial(makescrollgrid, grid2), + functools.partial(resourcegrid, self), ], + delay=True, ) - return tab + basel.addWidget(tab) + dotab() diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_cishu.py b/LunaTranslator/LunaTranslator/gui/settingpage_cishu.py index f7484ee0..f6cb2c44 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_cishu.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_cishu.py @@ -2,19 +2,17 @@ import functools, os from myutils.config import globalconfig, _TRL from gui.inputdialog import autoinitdialog, autoinitdialog_items from gui.usefulwidget import ( - getcolorbutton, + D_getcolorbutton, yuitsu_switch, - makescroll, - makegrid, - tabadd_lazy, - getsimpleswitch, - getsimplecombobox, + makescrollgrid, + D_getsimpleswitch, + D_getsimplecombobox, ) import gobject -def setTabcishu(self): - tabadd_lazy(self.tab_widget, ("辞书设置"), lambda: setTabcishu_l(self)) +def setTabcishu(self, basel): + makescrollgrid(setTabcishu_l(self), basel) def gethiragrid(self): @@ -31,7 +29,7 @@ def gethiragrid(self): if "args" in globalconfig["hirasetting"][name]: items = autoinitdialog_items(globalconfig["hirasetting"][name]) items[-1]["callback"] = gobject.baseobject.starthira - _3 = getcolorbutton( + _3 = D_getcolorbutton( globalconfig, "", callback=functools.partial( @@ -51,7 +49,7 @@ def gethiragrid(self): line += [ ((globalconfig["hirasetting"][name]["name"]), 6), ( - getsimpleswitch( + D_getsimpleswitch( globalconfig["hirasetting"][name], "use", name=name, @@ -85,11 +83,11 @@ def setTabcishu_l(self): grids = ( [ - [("分词&假名分析器", 10)], + [("分词&假名分析器", -1)], [ ("日语注音方案", 6), ( - getsimplecombobox( + D_getsimplecombobox( _TRL(["平假名", "片假名", "罗马音"]), globalconfig, "hira_vis_type", @@ -104,8 +102,8 @@ def setTabcishu_l(self): [], [ ("点击单词查词", 6), - (getsimpleswitch(globalconfig, "usesearchword"), 1), - getcolorbutton( + (D_getsimpleswitch(globalconfig, "usesearchword"), 1), + D_getcolorbutton( globalconfig, "", callback=lambda: gobject.baseobject.searchwordW.showsignal.emit(), @@ -114,14 +112,14 @@ def setTabcishu_l(self): ), "", ("点击单词复制", 6), - (getsimpleswitch(globalconfig, "usecopyword"), 1), + (D_getsimpleswitch(globalconfig, "usecopyword"), 1), ], [ ("使用原型查询", 6), - (getsimpleswitch(globalconfig, "usewordorigin"), 1), + (D_getsimpleswitch(globalconfig, "usewordorigin"), 1), ], [], - [("辞书", 10)], + [("辞书", -1)], ] ) @@ -138,12 +136,12 @@ def setTabcishu_l(self): ) line += [ (globalconfig["cishu"][cishu]["name"], 6), - getsimpleswitch( + D_getsimpleswitch( globalconfig["cishu"][cishu], "use", callback=functools.partial(gobject.baseobject.startxiaoxueguan, cishu), ), - getcolorbutton( + D_getcolorbutton( globalconfig, "", callback=functools.partial( @@ -166,8 +164,4 @@ def setTabcishu_l(self): i += 1 if len(line): grids.append(line) - - gridlayoutwidget = makegrid(grids) - gridlayoutwidget = makescroll(gridlayoutwidget) - - return gridlayoutwidget + return grids diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_ocr.py b/LunaTranslator/LunaTranslator/gui/settingpage_ocr.py index c0cc5b3f..37f49732 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_ocr.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_ocr.py @@ -1,17 +1,28 @@ import functools, os from myutils.config import globalconfig, ocrsetting, _TRL, ocrerrorfix from gui.usefulwidget import ( - getsimplecombobox, - getspinbox, - getcolorbutton, + D_getsimplecombobox, + D_getspinbox, + D_getcolorbutton, yuitsu_switch, - getsimpleswitch, + D_getsimpleswitch, selectcolor, ) +from qtsymbols import * from gui.inputdialog import autoinitdialog, postconfigdialog, autoinitdialog_items import gobject +def __label1(self): + self.threshold1label = QLabel() + return self.threshold1label + + +def __label2(self): + self.threshold2label = QLabel() + return self.threshold2label + + def getocrgrid(self): grids = [] @@ -26,7 +37,7 @@ def getocrgrid(self): continue if name in ocrsetting: items = autoinitdialog_items(ocrsetting[name]) - _3 = getcolorbutton( + _3 = D_getcolorbutton( globalconfig, "", callback=functools.partial( @@ -42,7 +53,7 @@ def getocrgrid(self): line += [ ((globalconfig["ocr"][name]["name"]), 6), ( - getsimpleswitch( + D_getsimpleswitch( globalconfig["ocr"][name], "use", name=name, @@ -72,13 +83,13 @@ def getocrgrid(self): grids += [ [], - [(("竖向OCR识别"), 12), getsimpleswitch(globalconfig, "verticalocr")], - [(("合并多行识别结果"), 12), getsimpleswitch(globalconfig, "ocrmergelines")], + [(("竖向OCR识别"), 12), D_getsimpleswitch(globalconfig, "verticalocr")], + [(("合并多行识别结果"), 12), D_getsimpleswitch(globalconfig, "ocrmergelines")], [], [ ("OCR预处理方法", 8), ( - getsimplecombobox( + D_getsimplecombobox( _TRL(["不处理", "灰度化", "阈值二值化", "OTSU二值化"]), globalconfig, "ocr_presolve_method", @@ -89,22 +100,22 @@ def getocrgrid(self): ], [ ("查看处理效果", 6), - getcolorbutton( + D_getcolorbutton( globalconfig, "", + gobject.baseobject.createshowocrimage, icon="fa.picture-o", constcolor="#FF69B4", - callback=gobject.baseobject.showocrimage.showsignal.emit, ), "", (("二值化阈值"), 8), - (getspinbox(0, 255, globalconfig, "binary_thresh"), 4), + (D_getspinbox(0, 255, globalconfig, "binary_thresh"), 4), ], [], [ ("OCR自动化方法", 8), ( - getsimplecombobox( + D_getsimplecombobox( _TRL(["分析图像更新", "周期执行", "分析图像更新+周期执行"]), globalconfig, "ocr_auto_method", @@ -115,7 +126,7 @@ def getocrgrid(self): [ (("执行周期(s)"), 8), ( - getspinbox( + D_getspinbox( 0.1, 100, globalconfig, "ocr_interval", double=True, step=0.1 ), 4, @@ -124,35 +135,35 @@ def getocrgrid(self): [ (("图像稳定性阈值"), 8), ( - getspinbox( + D_getspinbox( 0, 1, globalconfig, "ocr_stable_sim", double=True, step=0.01, dec=3 ), 4, ), - (self.threshold1label, 4), + (functools.partial(__label1, self), 0), ], [ (("图像一致性阈值"), 8), ( - getspinbox( + D_getspinbox( 0, 1, globalconfig, "ocr_diff_sim", double=True, step=0.01, dec=3 ), 4, ), - (self.threshold2label, 4), + (functools.partial(__label2, self), 0), ], [ (("文本相似度阈值"), 8), - (getspinbox(0, 100000, globalconfig, "ocr_text_diff"), 4), + (D_getspinbox(0, 100000, globalconfig, "ocr_text_diff"), 4), ], [], - [(("多重区域模式"), 12), getsimpleswitch(globalconfig, "multiregion")], - [(("记忆选定区域"), 12), getsimpleswitch(globalconfig, "rememberocrregions")], + [(("多重区域模式"), 12), D_getsimpleswitch(globalconfig, "multiregion")], + [(("记忆选定区域"), 12), D_getsimpleswitch(globalconfig, "rememberocrregions")], [], [ (("OCR范围框颜色"), 12), ( - getcolorbutton( + D_getcolorbutton( globalconfig, "ocrrangecolor", callback=lambda: selectcolor( @@ -171,7 +182,7 @@ def getocrgrid(self): [ (("OCR范围框宽度"), 12), ( - getspinbox( + D_getspinbox( 1, 100, globalconfig, @@ -183,16 +194,16 @@ def getocrgrid(self): ], [ (("选取OCR范围后立即进行一次识别"), 12), - getsimpleswitch(globalconfig, "ocrafterrangeselect"), + D_getsimpleswitch(globalconfig, "ocrafterrangeselect"), ], [ (("选取OCR范围后显示范围框"), 12), - getsimpleswitch(globalconfig, "showrangeafterrangeselect"), + D_getsimpleswitch(globalconfig, "showrangeafterrangeselect"), ], [ (("OCR识别易错内容修正"), 12), - getsimpleswitch(ocrerrorfix, "use"), - getcolorbutton( + D_getsimpleswitch(ocrerrorfix, "use"), + D_getcolorbutton( globalconfig, "", callback=functools.partial( diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_quick.py b/LunaTranslator/LunaTranslator/gui/settingpage_quick.py index bcebbedc..1e4a07d5 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_quick.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_quick.py @@ -2,27 +2,40 @@ import functools from myutils.config import globalconfig, _TR from myutils.winsyshotkey import SystemHotkey, registerException import winsharedutils -import gobject, windows +import gobject, windows, functools from qtsymbols import * from gui.usefulwidget import ( - getsimpleswitch, - getsimplekeyseq, - makegrid, - tabadd_lazy, - makescroll, + D_getsimpleswitch, + D_getsimplekeyseq, + makescrollgrid, ) from myutils.hwnd import grabwindow from myutils.utils import getimageformat, parsekeystringtomodvkcode, unsupportkey -def setTab_quick_direct(self): +def delaycreatereferlabels(self, name): + referlabel = QLabel() + self.referlabels[name] = referlabel + try: + referlabel.setText(self.referlabels_data[name]) + except: + pass + return referlabel + + +def maybesetreferlabels(self, name, text): + try: + self.referlabels[name].setText(text) + except: + self.referlabels_data[name] = text + + +def registrhotkeys(self): self.hotkeymanager = SystemHotkey() self.referlabels = {} + self.referlabels_data = {} self.registok = {} self.bindfunctions = { - "_A": lambda: gobject.baseobject.settin_ui.clicksourcesignal.emit("copy"), - "_B": lambda: gobject.baseobject.settin_ui.clicksourcesignal.emit("ocr"), - "_C": lambda: gobject.baseobject.settin_ui.clicksourcesignal.emit("texthook"), "_1": gobject.baseobject.translation_ui.startTranslater, "_2": gobject.baseobject.translation_ui.changeTranslateMode, "_3": self.showsignal.emit, @@ -33,7 +46,7 @@ def setTab_quick_direct(self): "_8": lambda: gobject.baseobject.translation_ui.changemousetransparentstate(0), "_9": gobject.baseobject.translation_ui.changetoolslockstate, "_10": lambda: gobject.baseobject.translation_ui.showsavegame_signal.emit(), - "_11": lambda: gobject.baseobject.AttachProcessDialog.showsignal.emit(), + "_11": gobject.baseobject.createattachprocess, "_12": lambda: gobject.baseobject.hookselectdialog.showsignal.emit(), "_13": lambda: gobject.baseobject.translation_ui.clickRange_signal.emit(False), "_14": gobject.baseobject.translation_ui.showhide_signal.emit, @@ -52,18 +65,19 @@ def setTab_quick_direct(self): ), "_26": gobject.baseobject.translation_ui.ocr_once_signal.emit, "_27": gobject.baseobject.translation_ui.simulate_key_enter, + "_28": lambda: winsharedutils.clipboard_set( + gobject.baseobject.currenttranslate + ), } for name in globalconfig["quick_setting"]["all"]: if name not in self.bindfunctions: continue - referlabel = QLabel() - self.referlabels[name] = referlabel regist_or_not_key(self, name) -def setTab_quick(self): +def setTab_quick(self, l): - tabadd_lazy(self.tab_widget, ("快捷按键"), lambda: setTab_quick_lazy(self)) + makescrollgrid(setTab_quick_lazy(self), l) def setTab_quick_lazy(self): @@ -71,7 +85,7 @@ def setTab_quick_lazy(self): grids = [ [ (("是否使用快捷键"), 4), - getsimpleswitch( + D_getsimpleswitch( globalconfig["quick_setting"], "use", callback=functools.partial(__enable, self), @@ -86,26 +100,23 @@ def setTab_quick_lazy(self): grids.append( [ ((globalconfig["quick_setting"]["all"][name]["name"]), 4), - getsimpleswitch( + D_getsimpleswitch( globalconfig["quick_setting"]["all"][name], "use", callback=functools.partial(fanyiselect, self, name), ), ( - getsimplekeyseq( + D_getsimplekeyseq( globalconfig["quick_setting"]["all"][name], "keystring", functools.partial(regist_or_not_key, self, name), ), 2, ), - (self.referlabels[name], 4), + (functools.partial(delaycreatereferlabels, self, name), 4), ] ) - gridlayoutwidget = makegrid(grids) - gridlayoutwidget = makescroll(gridlayoutwidget) - return gridlayoutwidget - # self.yitiaolong("快捷按键",grids) + return grids def __enable(self, x): @@ -120,7 +131,7 @@ def fanyiselect(self, who, checked): def regist_or_not_key(self, name): - self.referlabels[name].setText("") + maybesetreferlabels(self, name, "") if name in self.registok: self.hotkeymanager.unregister(self.registok[name]) @@ -137,11 +148,11 @@ def regist_or_not_key(self, name): try: mode, vkcode = parsekeystringtomodvkcode(keystring) except unsupportkey as e: - self.referlabels[name].setText(_TR("不支持的键位") + ",".join(e.args[0])) + maybesetreferlabels(self, name, _TR("不支持的键位") + ",".join(e.args[0])) return try: self.hotkeymanager.register((mode, vkcode), callback=self.bindfunctions[name]) self.registok[name] = (mode, vkcode) except registerException: - self.referlabels[name].setText(_TR("快捷键冲突")) + maybesetreferlabels(self, name, _TR("快捷键冲突")) diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_tts.py b/LunaTranslator/LunaTranslator/gui/settingpage_tts.py index e5909950..495025bc 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_tts.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_tts.py @@ -5,25 +5,50 @@ from myutils.config import globalconfig, _TRL import os, functools import gobject from gui.usefulwidget import ( - getsimplecombobox, - getspinbox, - makegrid, - makescroll, - getcolorbutton, - tabadd_lazy, + D_getsimplecombobox, + D_getspinbox, + makescrollgrid, + D_getcolorbutton, yuitsu_switch, - getsimpleswitch, + D_getsimpleswitch, ) -def setTab5_direct(self): +def showvoicelist(self, vl, idx): + try: + self.voicecombo.blockSignals(True) + self.voicecombo.clear() + self.voicecombo.addItems(vl) + if idx >= 0: + self.voicecombo.setCurrentIndex(idx) + self.voicecombo.blockSignals(False) + except: + self.voicecombo_cache = vl, idx + + +def changevoice(self, text): + + globalconfig["reader"][gobject.baseobject.reader_usevoice]["voice"] = ( + gobject.baseobject.reader.voicelist[self.voicecombo.currentIndex()] + ) + + +def createvoicecombo(self): + self.voicecombo = QComboBox() - self.voicelistsignal.connect(functools.partial(showvoicelist, self)) self.voicecombo.currentTextChanged.connect(lambda x: changevoice(self, x)) + try: + vl, idx = self.voicecombo_cache + self.voicecombo.addItems(vl) + if idx >= 0: + self.voicecombo.setCurrentIndex(idx) + except: + pass + return self.voicecombo -def setTab5(self): - tabadd_lazy(self.tab_widget, ("语音合成"), lambda: setTab5lz(self)) +def setTab5(self, l): + makescrollgrid(setTab5lz(self), l) def getttsgrid(self): @@ -40,7 +65,7 @@ def getttsgrid(self): if "args" in globalconfig["reader"][name]: items = autoinitdialog_items(globalconfig["reader"][name]) items[-1]["callback"] = gobject.baseobject.startreader - _3 = getcolorbutton( + _3 = D_getcolorbutton( globalconfig, "", callback=functools.partial( @@ -60,7 +85,7 @@ def getttsgrid(self): line += [ ((globalconfig["reader"][name]["name"]), 6), ( - getsimpleswitch( + D_getsimpleswitch( globalconfig["reader"][name], "use", name=name, @@ -95,29 +120,29 @@ def setTab5lz(self): grids = getttsgrid(self) grids += [ [], - [("选择声音", 6), (self.voicecombo, 15)], + [("选择声音", 6), (functools.partial(createvoicecombo, self), 15)], [ ("语速:(-10~10)", 6), - (getspinbox(-10, 10, globalconfig["ttscommon"], "rate"), 3), + (D_getspinbox(-10, 10, globalconfig["ttscommon"], "rate"), 3), ], [ ("音量:(0~100)", 6), - (getspinbox(0, 100, globalconfig["ttscommon"], "volume"), 3), + (D_getspinbox(0, 100, globalconfig["ttscommon"], "volume"), 3), ], - [("自动朗读", 6), (getsimpleswitch(globalconfig, "autoread"), 1)], - [("不被打断", 6), (getsimpleswitch(globalconfig, "ttsnointerrupt"), 1)], + [("自动朗读", 6), (D_getsimpleswitch(globalconfig, "autoread"), 1)], + [("不被打断", 6), (D_getsimpleswitch(globalconfig, "ttsnointerrupt"), 1)], [ ("朗读原文", 6), - (getsimpleswitch(globalconfig, "read_raw"), 1), + (D_getsimpleswitch(globalconfig, "read_raw"), 1), "", "", ("朗读翻译", 6), - (getsimpleswitch(globalconfig, "read_trans"), 1), + (D_getsimpleswitch(globalconfig, "read_trans"), 1), ], [ ("朗读的翻译", 6), ( - getsimplecombobox( + D_getsimplecombobox( _TRL( [ globalconfig["fanyi"][x]["name"] @@ -133,8 +158,8 @@ def setTab5lz(self): [], [ ("语音修正", 6), - getsimpleswitch(globalconfig["ttscommon"], "tts_repair"), - getcolorbutton( + D_getsimpleswitch(globalconfig["ttscommon"], "tts_repair"), + D_getcolorbutton( globalconfig, "", callback=lambda x: noundictconfigdialog1( @@ -149,22 +174,4 @@ def setTab5lz(self): ), ], ] - gridlayoutwidget = makegrid(grids) - gridlayoutwidget = makescroll(gridlayoutwidget) - return gridlayoutwidget - - -def changevoice(self, text): - - globalconfig["reader"][gobject.baseobject.reader_usevoice]["voice"] = ( - gobject.baseobject.reader.voicelist[self.voicecombo.currentIndex()] - ) - - -def showvoicelist(self, vl, idx): - self.voicecombo.blockSignals(True) - self.voicecombo.clear() - self.voicecombo.addItems(vl) - if idx >= 0: - self.voicecombo.setCurrentIndex(idx) - self.voicecombo.blockSignals(False) + return grids diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_xianshishezhi.py b/LunaTranslator/LunaTranslator/gui/settingpage_xianshishezhi.py index b7099840..cd1a9282 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_xianshishezhi.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_xianshishezhi.py @@ -1,444 +1,52 @@ import functools from qtsymbols import * -from gui.inputdialog import multicolorset -from myutils.config import globalconfig, _TR, _TRL, magpie_config, static_data -from myutils.wrapper import Singleton -import qtawesome, gobject, json -from gui.inputdialog import getsomepath1 +from myutils.config import globalconfig +import gobject +from gui.gui_xianshi_buttons import createbuttonwidget +from gui.gui_xianshi_text import xianshigrid +from gui.gui_xianshi_ui import uisetting +from gui.gui_xianshi_scale import makescalew from gui.usefulwidget import ( - getsimplecombobox, - makegrid, - getspinbox, - tabadd_lazy, - makescroll, - makevbox, - getcolorbutton, + D_getspinbox, makesubtab_lazy, - getsimpleswitch, - selectcolor, + makescrollgrid, + D_getsimpleswitch, ) -def __changeuibuttonstate(self, x): - gobject.baseobject.translation_ui.refreshtoolicon() - self.show_hira_switch.setEnabled(x) - self.show_fenciswitch.setEnabled(x) - - -def setTabThree_direct(self): - self.fontSize_spinBox = getspinbox( - 1, 100, globalconfig, "fontsize", double=True, step=0.1 - ) - self.fontbigsmallsignal.connect( - lambda t: self.fontSize_spinBox.setValue( - self.fontSize_spinBox.value() + 0.5 * t - ) - ) - self.show_original_switch = getsimpleswitch( - globalconfig, "isshowrawtext", callback=lambda x: __changeuibuttonstate(self, x) - ) - self.show_hira_switch = getsimpleswitch( - globalconfig, "isshowhira", enable=globalconfig["isshowrawtext"] - ) - self.show_fenciswitch = getsimpleswitch( - globalconfig, "show_fenci", enable=globalconfig["isshowrawtext"] - ) - - -def setTabThree(self): - - tabadd_lazy(self.tab_widget, ("显示设置"), lambda: setTabThree_lazy(self)) - - -def createbuttonwidget(self): - # return table - grids = [["显示", "", "", "对齐", "图标", "图标2", "说明"]] - sortlist = globalconfig["toolbutton"]["rank2"] - savelist = [] - savelay = [] - - def doadjust(): - gobject.baseobject.translation_ui.enterfunction(delay=3) - gobject.baseobject.translation_ui.adjustbuttons() - - def changerank(item, up): - - idx = sortlist.index(item) - idx2 = idx + (-1 if up else 1) - if idx2 < 0 or idx2 >= len(sortlist): - return - headoffset = 1 - idx2 = idx + (-1 if up else 1) - sortlist[idx], sortlist[idx2] = sortlist[idx2], sortlist[idx] - for i, ww in enumerate(savelist[idx + headoffset]): - - w1 = savelay[0].indexOf(ww) - w2 = savelay[0].indexOf(savelist[idx2 + headoffset][i]) - p1 = savelay[0].getItemPosition(w1) - p2 = savelay[0].getItemPosition(w2) - savelay[0].removeWidget(ww) - savelay[0].removeWidget(savelist[idx2 + headoffset][i]) - - savelay[0].addWidget(savelist[idx2 + headoffset][i], *p1) - savelay[0].addWidget(ww, *p2) - savelist[idx + headoffset], savelist[idx2 + headoffset] = ( - savelist[idx2 + headoffset], - savelist[idx + headoffset], - ) - doadjust() - - for i, k in enumerate(sortlist): - - button_up = getcolorbutton( - globalconfig, - "", - callback=functools.partial(changerank, k, True), - icon="fa.arrow-up", - constcolor="#FF69B4", - ) - button_down = getcolorbutton( - globalconfig, - "", - callback=functools.partial(changerank, k, False), - icon="fa.arrow-down", - constcolor="#FF69B4", - ) - - l = [ - getsimpleswitch( - globalconfig["toolbutton"]["buttons"][k], - "use", - callback=lambda _: doadjust(), - ), - button_up, - button_down, - getsimplecombobox( - _TRL(["居左", "居右", "居中"]), - globalconfig["toolbutton"]["buttons"][k], - "align", - callback=lambda _: doadjust(), - fixedsize=True, - ), - getcolorbutton( - "", - "", - functools.partial( - dialog_selecticon, - self, - globalconfig["toolbutton"]["buttons"][k], - "icon", - ), - qicon=qtawesome.icon( - globalconfig["toolbutton"]["buttons"][k]["icon"], - color=globalconfig["buttoncolor"], - ), - ), - ] - if "icon2" in globalconfig["toolbutton"]["buttons"][k]: - l.append( - getcolorbutton( - "", - "", - functools.partial( - dialog_selecticon, - self, - globalconfig["toolbutton"]["buttons"][k], - "icon2", - ), - qicon=qtawesome.icon( - globalconfig["toolbutton"]["buttons"][k]["icon2"], - color=globalconfig["buttoncolor"], - ), - ), - ) - else: - l.append("") - if "belong" in globalconfig["toolbutton"]["buttons"][k]: - belong = ( - "_" - + "仅" - + "_" - + " ".join(globalconfig["toolbutton"]["buttons"][k]["belong"]) - ) - else: - belong = "" - l.append(globalconfig["toolbutton"]["buttons"][k]["tip"] + belong) - grids.append(l) - return makescroll(makegrid(grids, True, savelist, savelay)) - - -@Singleton -class dialog_selecticon(QDialog): - def __init__(self, parent, dict, key, _nouse_for_click_arg) -> None: - - super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) - self.dict = dict - self.key = key - self.setWindowTitle(_TR("选择图标")) - with open( - "./files/fonts/fontawesome4.7-webfont-charmap.json", "r", encoding="utf8" - ) as ff: - js = json.load(ff) - - layout = QGridLayout() - self.setLayout(layout) - for i, name in enumerate(js): - layout.addWidget( - getcolorbutton( - "", - "", - functools.partial(self.selectcallback, "fa." + name), - qicon=qtawesome.icon( - "fa." + name, color=globalconfig["buttoncolor"] - ), - ), - i // 30, - i % 30, - ) - self.show() - - def selectcallback(self, _): - print(_) - self.dict[self.key] = _ - self.close() - - -def setTabThree_lazy(self): - - self.horizontal_slider = QSlider() - self.horizontal_slider.setMaximum(100) - self.horizontal_slider.setMinimum(1) - self.horizontal_slider.setOrientation(Qt.Orientation.Horizontal) - self.horizontal_slider.setValue(0) - self.horizontal_slider.setValue(globalconfig["transparent"]) - self.horizontal_slider.valueChanged.connect( - functools.partial(changeHorizontal, self) - ) - self.horizontal_slider_label = QLabel() - self.horizontal_slider_label.setText("{}%".format(globalconfig["transparent"])) - - self.horizontal_slider_tool = QSlider() - self.horizontal_slider_tool.setMaximum(100) - self.horizontal_slider_tool.setMinimum(1) - self.horizontal_slider_tool.setOrientation(Qt.Orientation.Horizontal) - self.horizontal_slider_tool.setValue(0) - self.horizontal_slider_tool.setValue(globalconfig["transparent_tool"]) - self.horizontal_slider_tool.valueChanged.connect( - functools.partial(changeHorizontal_tool, self) - ) - self.horizontal_slider_tool_label = QLabel() - self.horizontal_slider_tool_label.setText( - "{}%".format(globalconfig["transparent_tool"]) - ) - - self.font_comboBox = QFontComboBox() - self.font_comboBox.currentTextChanged.connect( - lambda x: globalconfig.__setitem__("fonttype", x) - ) - self.font_comboBox.setCurrentFont(QFont(globalconfig["fonttype"])) - self.font_comboBox2 = QFontComboBox() - self.font_comboBox2.currentTextChanged.connect( - lambda x: globalconfig.__setitem__("fonttype2", x) - ) - self.font_comboBox2.setCurrentFont(QFont(globalconfig["fonttype2"])) - - self.sfont_comboBox = QFontComboBox() - - def callback(x): - globalconfig.__setitem__("settingfonttype", x) - gobject.baseobject.setcommonstylesheet() - - self.sfont_comboBox.currentTextChanged.connect(callback) - self.sfont_comboBox.setCurrentFont(QFont(globalconfig["settingfonttype"])) - - textgrid = [ - [("原文字体", 3), (self.font_comboBox, 6), ("", 5)], - [ - ("译文字体", 3), - (self.font_comboBox2, 6), - ], - [ - ("字体大小", 3), - (self.fontSize_spinBox, 3), - "", - ("额外的行间距", 3), - (getspinbox(-100, 100, globalconfig, "extra_space"), 3), - ], - [ - ("居中显示", 5), - getsimpleswitch(globalconfig, "showatcenter"), - "", - ("加粗字体", 5), - getsimpleswitch(globalconfig, "showbold"), - ], - [ - "", - ], - [ - ("字体样式", 3), - ( - getsimplecombobox( - _TRL( - [ - "普通字体", - "空心字体", - "描边字体", - "描边字体_2", - "描边字体_2_投影", - "发光字体", - ] - ), - globalconfig, - "zitiyangshi2", - ), - 6, - ), - ], - [ - ("特殊字体样式填充颜色", 5), - getcolorbutton( - globalconfig, - "miaobiancolor", - transparent=False, - callback=lambda: selectcolor( - self, globalconfig, "miaobiancolor", self.miaobian_color_button - ), - name="miaobian_color_button", - parent=self, - ), - ], - [ - ("空心线宽", 3), - ( - getspinbox( - 0.1, 100, globalconfig, "miaobianwidth", double=True, step=0.1 - ), - 3, - ), - "", - ("描边宽度", 3), - ( - getspinbox( - 0.1, 100, globalconfig, "miaobianwidth2", double=True, step=0.1 - ), - 3, - ), - ], - [ - ("发光亮度", 3), - (getspinbox(1, 100, globalconfig, "shadowforce"), 3), - "", - ("投影距离", 3), - ( - getspinbox( - 0.1, 100, globalconfig, "traceoffset", double=True, step=0.1 - ), - 3, - ), - ], - [], - [ - ("显示原文", 5), - self.show_original_switch, - "", - ("显示翻译", 5), - (getsimpleswitch(globalconfig, "showfanyi"), 1), - ], - [ - ("原文颜色", 5), - getcolorbutton( - globalconfig, - "rawtextcolor", - callback=lambda: selectcolor( - self, globalconfig, "rawtextcolor", self.original_color_button - ), - name="original_color_button", - parent=self, - ), - "", - ("显示翻译器名称", 5), - (getsimpleswitch(globalconfig, "showfanyisource"), 1), - ], - [ - ("最长显示字数", 3), - (getspinbox(0, 1000000, globalconfig, "maxoriginlength"), 3), - ], - [], - [ - ("显示日语注音", 5), - self.show_hira_switch, - ], - [ - ("注音颜色", 5), - getcolorbutton( - globalconfig, - "jiamingcolor", - callback=lambda: selectcolor( - self, globalconfig, "jiamingcolor", self.jiamingcolor_b - ), - name="jiamingcolor_b", - parent=self, - ), - "", - ("注音字体缩放", 3), - ( - getspinbox( - 0.05, 1, globalconfig, "kanarate", double=True, step=0.05, dec=2 - ), - 3, - ), - ], - [ - ("语法加亮", 5), - self.show_fenciswitch, - "", - ("词性颜色(需要Mecab)", 5), - getcolorbutton( - globalconfig, - "", - callback=lambda: multicolorset(self), - icon="fa.gear", - constcolor="#FF69B4", - ), - ], - [], - [ - ("收到翻译结果时才刷新", 5), - getsimpleswitch(globalconfig, "refresh_on_get_trans"), - ], - ] - - def themelist(t): - return [_["name"] for _ in static_data["themes"][t]] +def _xingw(): xingweigrid = [ - [("游戏最小化时窗口隐藏", 6), (getsimpleswitch(globalconfig, "minifollow"), 1)], + [ + ("游戏最小化时窗口隐藏", 6), + (D_getsimpleswitch(globalconfig, "minifollow"), 1), + ], [ ("游戏失去焦点时窗口隐藏", 6), - (getsimpleswitch(globalconfig, "focusfollow"), 1), + (D_getsimpleswitch(globalconfig, "focusfollow"), 1), ], [ ("游戏失去焦点时取消置顶", 6), - (getsimpleswitch(globalconfig, "focusnotop"), 1), + (D_getsimpleswitch(globalconfig, "focusnotop"), 1), ], [ ("游戏窗口移动时同步移动", 6), - (getsimpleswitch(globalconfig, "movefollow"), 1), + (D_getsimpleswitch(globalconfig, "movefollow"), 1), ], [ ("固定窗口尺寸", 6), - getsimpleswitch(globalconfig, "fixedheight"), + D_getsimpleswitch(globalconfig, "fixedheight"), ], [ ("自动隐藏窗口", 6), - (getsimpleswitch(globalconfig, "autodisappear"), 1), + (D_getsimpleswitch(globalconfig, "autodisappear"), 1), "", ("隐藏延迟(s)", 3), - (getspinbox(1, 100, globalconfig, "disappear_delay"), 2), + (D_getspinbox(1, 100, globalconfig, "disappear_delay"), 2), ], [ ("任务栏中显示_翻译窗口", 6), - getsimpleswitch( + D_getsimpleswitch( globalconfig, "showintab", callback=lambda _: gobject.baseobject.setshowintab(), @@ -446,7 +54,7 @@ def setTabThree_lazy(self): ], [ ("任务栏中显示_其他", 6), - getsimpleswitch( + D_getsimpleswitch( globalconfig, "showintab_sub", callback=lambda _: gobject.baseobject.setshowintab(), @@ -454,7 +62,7 @@ def setTabThree_lazy(self): ], [ ("选择文本窗口中文本框只读", 6), - getsimpleswitch( + D_getsimpleswitch( globalconfig, "textboxreadonly", callback=lambda x: gobject.baseobject.hookselectdialog.textOutput.setReadOnly( @@ -464,516 +72,29 @@ def setTabThree_lazy(self): ], [ ("可选取模式", 6), - getsimpleswitch( + D_getsimpleswitch( globalconfig, "selectable", callback=lambda x: gobject.baseobject.translation_ui.translate_text.setselectable(), ), ], ] - uigrid = [ - [("设置界面字体", 4), (self.sfont_comboBox, 5)], - [ - ("字体大小", 4), - ( - getspinbox( - 1, - 100, - globalconfig, - "settingfontsize", - callback=lambda _: gobject.baseobject.setcommonstylesheet(), - ), - 2, - ), - ], - [ - ("不透明度_翻译窗口", 4), - (self.horizontal_slider, 8), - (self.horizontal_slider_label, 2), - ], - [ - ("不透明度_工具栏", 4), - (self.horizontal_slider_tool, 8), - (self.horizontal_slider_tool_label, 2), - ], - [ - ("背景颜色_翻译窗口", 4), - 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), - 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), - getcolorbutton( - globalconfig, - "buttoncolor", - callback=lambda: selectcolor( - self, - globalconfig, - "buttoncolor", - self.buttoncolorbutton, - callback=lambda: gobject.baseobject.translation_ui.refreshtooliconsignal.emit(), - ), - name="buttoncolorbutton", - parent=self, - ), - "", - "", - ("工具按钮大小", 4), - ( - getspinbox( - 5, - 100, - globalconfig, - "buttonsize", - callback=lambda _: gobject.baseobject.translation_ui.refreshtooliconsignal.emit(), - ), - 2, - ), - ], - [ - ("圆角_半径", 4), - ( - getspinbox( - 0, - 100, - globalconfig, - "yuanjiao_r", - callback=lambda _: gobject.baseobject.translation_ui.set_color_transparency(), - ), - 2, - ), - "", - ("圆角_合并", 4), - getsimpleswitch( - globalconfig, - "yuanjiao_merge", - callback=lambda _: gobject.baseobject.translation_ui.set_color_transparency(), - ), - ], - [], - [ - ("明暗", 4), - ( - getsimplecombobox( - _TRL(["明亮", "黑暗", "跟随系统"]), - globalconfig, - "darklight", - callback=lambda _: gobject.baseobject.setcommonstylesheet(), - ), - 5, - ), - ], - [ - ("明亮主题", 4), - ( - getsimplecombobox( - _TRL(["默认"]) + themelist("light"), - globalconfig, - "lighttheme", - callback=lambda _: gobject.baseobject.setcommonstylesheet(), - ), - 5, - ), - ], - [ - ("黑暗主题", 4), - ( - getsimplecombobox( - themelist("dark"), - globalconfig, - "darktheme", - callback=lambda _: gobject.baseobject.setcommonstylesheet(), - ), - 5, - ), - ], - [], - [ - ("窗口特效_翻译窗口", 4), - ( - getsimplecombobox( - ["Disable", "Acrylic", "Aero"], - globalconfig, - "WindowEffect", - callback=lambda _: [ - gobject.baseobject.translation_ui.set_color_transparency(), - gobject.baseobject.translation_ui.seteffect(), - ], - ), - 5, - ), - ], - [ - ("窗口特效_其他", 4), - ( - getsimplecombobox( - ["Solid", "Acrylic", "Mica", "MicaAlt"], - globalconfig, - "WindowBackdrop", - callback=lambda _: gobject.baseobject.setcommonstylesheet(), - ), - 5, - ), - ], - ] + return xingweigrid - innermagpie = [ - [("常规", 4)], - [ - ("", 1), - ("缩放模式", 4), - ( - getsimplecombobox( - [_["name"] for _ in magpie_config["scalingModes"]], - magpie_config["profiles"][globalconfig["profiles_index"]], - "scalingMode", - ), - 6, - ), - "", - ], - [ - ("", 1), - ("捕获模式", 4), - ( - getsimplecombobox( - [ - "Graphics Capture", - "Desktop Duplication", - "GDI", - "DwmSharedSurface", - ], - magpie_config["profiles"][globalconfig["profiles_index"]], - "captureMethod", - ), - 6, - ), - ], - [ - ("", 1), - ("3D游戏模式", 4), - ( - getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "3DGameMode", - ) - ), - ], - [("性能", 4)], - [ - ("", 1), - ("显示帧率", 4), - ( - getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "showFPS", - ) - ), - ], - [ - ("", 1), - ("限制帧率", 4), - ( - getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "frameRateLimiterEnabled", - ) - ), - ], - [ - ("", 1), - ("最大帧率", 4), - ( - getspinbox( - 0, - 9999, - magpie_config["profiles"][globalconfig["profiles_index"]], - "maxFrameRate", - ), - 2, - ), - ], - [("源窗口", 4)], - [ - ("", 1), - ("缩放时禁用窗口大小调整", 4), - ( - getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "disableWindowResizing", - ) - ), - ], - [ - ("", 1), - ("捕获标题栏", 4), - ( - getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "captureTitleBar", - ) - ), - ], - [ - ("", 1), - ("自定义剪裁", 4), - ( - getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "croppingEnabled", - ) - ), - ], - [("光标", 4)], - [ - ("", 1), - ("绘制光标", 4), - ( - getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "drawCursor", - ) - ), - ], - [ - ("", 1), - ("绘制光标_缩放系数", 4), - ( - getsimplecombobox( - ["0.5x", "0.75x", "无缩放", "1.25x", "1.5x", "2x", "和源窗口相同"], - magpie_config["profiles"][globalconfig["profiles_index"]], - "cursorScaling", - ), - 6, - ), - ], - [ - ("", 1), - ("绘制光标_插值算法", 4), - ( - getsimplecombobox( - ["最邻近", "双线性"], - magpie_config["profiles"][globalconfig["profiles_index"]], - "cursorInterpolationMode", - ), - 6, - ), - ], - [ - ("", 1), - ("缩放时调整光标速度", 4), - ( - getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "adjustCursorSpeed", - ) - ), - ], - [("高级", 4)], - [ - ("", 1), - ("禁用DirectFlip", 4), - ( - getsimpleswitch( - magpie_config["profiles"][globalconfig["profiles_index"]], - "disableDirectFlip", - ) - ), - ], - [ - ("", 1), - ("允许缩放最大化或全屏的窗口", 4), - (getsimpleswitch(magpie_config, "allowScalingMaximized")), - ], - [ - ("", 1), - ("缩放时模拟独占全屏", 4), - (getsimpleswitch(magpie_config, "simulateExclusiveFullscreen")), - ], - [ - ("", 1), - ("内联效果参数", 4), - (getsimpleswitch(magpie_config, "inlineParams")), - ], - [("开发者选项", 4)], - [ - ("", 1), - ("调试模式", 4), - ( - getsimpleswitch( - magpie_config, - "debugMode", - ) - ), - ], - [ - ("", 1), - ("禁用效果缓存", 4), - ( - getsimpleswitch( - magpie_config, - "disableEffectCache", - ) - ), - ], - [ - ("", 1), - ("禁用字体缓存", 4), - ( - getsimpleswitch( - magpie_config, - "disableFontCache", - ) - ), - ], - [ - ("", 1), - ("解析效果时保存源代码", 4), - ( - getsimpleswitch( - magpie_config, - "saveEffectSources", - ) - ), - ], - [ - ("", 1), - ("编译效果时将警告视为错误", 4), - ( - getsimpleswitch( - magpie_config, - "warningsAreErrors", - ) - ), - ], - [ - ("", 1), - ("检测重复帧", 4), - ( - getsimplecombobox( - ["总是检测", "动态检测", "从不检测"], - magpie_config, - "duplicateFrameDetectionMode", - ), - 6, - ), - ], - [ - ("", 1), - ("启用动态检测统计", 4), - ( - getsimpleswitch( - magpie_config, - "enableStatisticsForDynamicDetection", - ) - ), - ], - ] - commonfsgrid = [ - [ - ("缩放方式", 4), - ( - getsimplecombobox( - static_data["scalemethods_vis"], - globalconfig, - "fullscreenmethod_4", - ), - 6, - ), - ] - ] - losslessgrid = [ - [ - ("Magpie_路径", 4), - ( - getcolorbutton( - globalconfig, - "", - callback=lambda x: getsomepath1( - self, - "Magpie_路径", - globalconfig, - "magpiepath", - "Magpie_路径", - isdir=True, - ), - icon="fa.gear", - constcolor="#FF69B4", - ), - 1, - ), - ], - [ - ("Hook Magpie进程使其不会退出缩放", 4), - getsimpleswitch(globalconfig, "hookmagpie"), - ], - ] - tab = makesubtab_lazy( +def setTabThree_lazy(self, basel): + + tab, do = makesubtab_lazy( ["文本设置", "界面主题", "窗口行为", "工具按钮", "窗口缩放"], [ - lambda: makescroll(makegrid(textgrid)), - lambda: makescroll(makegrid(uigrid)), - lambda: makescroll(makegrid(xingweigrid)), - lambda: createbuttonwidget(self), - lambda: makevbox( - [ - makegrid(commonfsgrid), - makesubtab_lazy( - ["Magpie", "外部缩放软件"], - [ - lambda: makescroll(makegrid(innermagpie)), - lambda: makescroll(makegrid(losslessgrid)), - ], - ), - ] - ), + lambda l: makescrollgrid(xianshigrid(self), l), + lambda l: makescrollgrid(uisetting(self), l), + lambda l: makescrollgrid(_xingw(), l), + functools.partial(createbuttonwidget, self), + functools.partial(makescalew, self), ], + delay=True, ) - return tab - - -def changeHorizontal(self): - - globalconfig["transparent"] = self.horizontal_slider.value() - self.horizontal_slider_label.setText("{}%".format(globalconfig["transparent"])) - # - gobject.baseobject.translation_ui.set_color_transparency() - - -def changeHorizontal_tool(self): - - globalconfig["transparent_tool"] = self.horizontal_slider_tool.value() - self.horizontal_slider_tool_label.setText( - "{}%".format(globalconfig["transparent_tool"]) - ) - # - gobject.baseobject.translation_ui.set_color_transparency() + basel.addWidget(tab) + do() diff --git a/LunaTranslator/LunaTranslator/gui/showocrimage.py b/LunaTranslator/LunaTranslator/gui/showocrimage.py index 59535878..7d13384e 100644 --- a/LunaTranslator/LunaTranslator/gui/showocrimage.py +++ b/LunaTranslator/LunaTranslator/gui/showocrimage.py @@ -1,18 +1,23 @@ from qtsymbols import * -import qtawesome +import qtawesome, gobject from myutils.ocrutil import imagesolve -from gui.usefulwidget import closeashidewindow +from gui.usefulwidget import saveposwindow from myutils.config import globalconfig, _TR -from myutils.config import globalconfig +from myutils.wrapper import Singleton_close -class showocrimage(closeashidewindow): +@Singleton_close +class showocrimage(saveposwindow): setimage = pyqtSignal(list) - def __init__(self, parent): + def closeEvent(self, e): + gobject.baseobject.showocrimage = None + super().closeEvent(e) + + def __init__(self, parent, cached): self.img1 = None self.originimage = None - super(showocrimage, self).__init__(parent, globalconfig, "showocrgeo") + super().__init__(parent, globalconfig, "showocrgeo") self.setWindowIcon(qtawesome.icon("fa.picture-o")) self.setWindowTitle(_TR("查看处理效果")) self.originlabel = QLabel(self) @@ -32,6 +37,8 @@ class showocrimage(closeashidewindow): self.layout1.addWidget(button) self.layout1.addWidget(self.solvedlabel) self.setimage.connect(self.setimagefunction) + if cached: + self.setimagefunction(cached) def retest(self): if self.originimage is None: diff --git a/LunaTranslator/LunaTranslator/gui/showword.py b/LunaTranslator/LunaTranslator/gui/showword.py index 7cea4a3d..5cadc6aa 100644 --- a/LunaTranslator/LunaTranslator/gui/showword.py +++ b/LunaTranslator/LunaTranslator/gui/showword.py @@ -192,14 +192,14 @@ class AnkiWindow(QWidget): html = f'