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'
{html}
' self.htmlbrowser.setHtml(html) - def creattemplatetab(self): + def creattemplatetab(self, baselay): layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) wid = QWidget() wid.setLayout(layout) - + baselay.addWidget(wid) edittemptab = QTabWidget() self.previewtab = QTabBar() revertbtn = QPushButton(_TR("恢复")) @@ -241,7 +241,6 @@ class AnkiWindow(QWidget): self.backtext.textChanged.connect(lambda: self.refreshhtml.emit()) self.csstext.textChanged.connect(lambda: self.refreshhtml.emit()) self.previewtab.currentChanged.connect(lambda: self.refreshhtml.emit()) - return wid def loadedits(self): for text, object in zip( @@ -335,10 +334,11 @@ class AnkiWindow(QWidget): with open("userconfig/anki/style.css", "w", encoding="utf8") as ff: ff.write(model_css) - def creatsetdtab(self): + def creatsetdtab(self, baselay): layout = QFormLayout() wid = QWidget() wid.setLayout(layout) + baselay.addWidget(wid) layout.addRow( _TR("端口号"), getspinbox(0, 65536, globalconfig["ankiconnect"], "port") ) @@ -409,7 +409,6 @@ class AnkiWindow(QWidget): makewidget=True, ), ) - return wid @threader def simulate_key(self, i): diff --git a/LunaTranslator/LunaTranslator/gui/textbrowser.py b/LunaTranslator/LunaTranslator/gui/textbrowser.py index 9c235f96..c94cfbcc 100644 --- a/LunaTranslator/LunaTranslator/gui/textbrowser.py +++ b/LunaTranslator/LunaTranslator/gui/textbrowser.py @@ -220,7 +220,6 @@ class Textbrowser(QLabel): def __init__(self, parent): super().__init__(parent) - self.setMouseTracking(True) self.atback2 = QLabel(parent) diff --git a/LunaTranslator/LunaTranslator/gui/transhist.py b/LunaTranslator/LunaTranslator/gui/transhist.py index 41cb830d..d6a5fab5 100644 --- a/LunaTranslator/LunaTranslator/gui/transhist.py +++ b/LunaTranslator/LunaTranslator/gui/transhist.py @@ -2,6 +2,7 @@ from qtsymbols import * import qtawesome, functools, winsharedutils from gui.usefulwidget import closeashidewindow from myutils.config import globalconfig, _TR +from myutils.utils import get_time_stamp class transhist(closeashidewindow): @@ -17,6 +18,7 @@ class transhist(closeashidewindow): self.getnewtranssignal.connect(self.getnewtrans) self.hiderawflag = False self.hideapiflag = False + self.hidetime = True self.setWindowTitle(_TR("历史翻译")) @@ -45,6 +47,7 @@ class transhist(closeashidewindow): copy = QAction(_TR("复制到剪贴板")) hideshowraw = QAction(_TR("显示原文" if self.hiderawflag else "不显示原文")) hideshowapi = QAction(_TR("显示api" if self.hideapiflag else "不显示api")) + hidetime = QAction(_TR("显示时间" if self.hidetime else "不显示时间")) menu.addAction(qingkong) menu.addAction(baocun) if len(self.textOutput.textCursor().selectedText()): @@ -52,6 +55,7 @@ class transhist(closeashidewindow): if flag == 1: menu.addAction(hideshowraw) menu.addAction(hideshowapi) + menu.addAction(hidetime) action = menu.exec(QCursor.pos()) if action == qingkong: @@ -67,20 +71,27 @@ class transhist(closeashidewindow): elif action == hideshowraw: self.hiderawflag = not self.hiderawflag + elif action == hidetime: + + self.hidetime = not self.hidetime elif action == hideshowapi: self.hideapiflag = not self.hideapiflag def getnewsentence(self, sentence): - sentence = "\n" + sentence if self.hiderawflag: sentence = "" + else: + if not self.hidetime: + sentence = get_time_stamp() + " " + sentence + sentence = "\n" + sentence self.textOutput.appendPlainText(sentence) def getnewtrans(self, api, sentence): - if self.hideapiflag: - res = sentence - else: - res = api + " " + sentence - self.textOutput.appendPlainText(res) + if not self.hideapiflag: + sentence = api + " " + sentence + if not self.hidetime: + sentence = get_time_stamp() + " " + sentence + + self.textOutput.appendPlainText(sentence) diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 01b00c40..5ba24406 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -130,7 +130,7 @@ class QUnFrameWindow(resizableframeless): else: self.showline(clear=clear) - gobject.baseobject.edittextui.getnewsentencesignal.emit(text) + gobject.baseobject.maybesetedittext(text) def showstatus(self, res, color, clear, origin): self.showline(clear=clear, text=res, color=color, origin=origin) @@ -234,6 +234,7 @@ class QUnFrameWindow(resizableframeless): ) if hira: + @threader def callback(word, append): if globalconfig["usewordorigin"] == False: @@ -265,6 +266,7 @@ class QUnFrameWindow(resizableframeless): self.lastrefreshtime = time.time() self.autohidestart = True + @threader def autohidedelaythread(self): while True: if globalconfig["autodisappear"] and self.autohidestart: @@ -295,7 +297,6 @@ class QUnFrameWindow(resizableframeless): self.showhideui() def refreshtoolicon(self): - iconstate = { "fullscreen": self.isletgamefullscreened, "muteprocess": self.processismuteed, @@ -383,7 +384,7 @@ class QUnFrameWindow(resizableframeless): "copy", lambda: winsharedutils.clipboard_set(gobject.baseobject.currenttext), ), - ("edit", lambda: gobject.baseobject.edittextui.showsignal.emit()), + ("edit", gobject.baseobject.createedittextui), ("edittrans", lambda: edittrans(gobject.baseobject.settin_ui)), ("showraw", self.changeshowhideraw), ("history", lambda: gobject.baseobject.transhis.showsignal.emit()), @@ -406,7 +407,7 @@ class QUnFrameWindow(resizableframeless): ("gamepad_new", lambda: dialog_savedgame_new(gobject.baseobject.settin_ui)), ( "selectgame", - lambda: gobject.baseobject.AttachProcessDialog.showsignal.emit(), + lambda: gobject.baseobject.createattachprocess(), ), ( "selecttext", @@ -492,19 +493,13 @@ class QUnFrameWindow(resizableframeless): self.show() windows.SetForegroundWindow(int(self.winId())) - def showEvent(self, a0) -> None: - if self.isfirstshow: - self.showline(clear=True, text=_TR("欢迎使用"), origin=False) + def aftershowdosomething(self): + self.showline(clear=True, text=_TR("欢迎使用"), origin=False) - self.tray.activated.connect(self.leftclicktray) - - self.tray.show() - windows.SetForegroundWindow(int(self.winId())) - self.isfirstshow = False - self.setontopthread() - self.refreshtoolicon() - - return super().showEvent(a0) + windows.SetForegroundWindow(int(self.winId())) + self.refreshtoolicon() + self.setontopthread() + self.autohidedelaythread() def canceltop(self): windows.SetWindowPos( @@ -554,26 +549,24 @@ class QUnFrameWindow(resizableframeless): windows.SWP_NOACTIVATE | windows.SWP_NOSIZE | windows.SWP_NOMOVE, ) + @threader def setontopthread(self): - def _(): - self.settop() - while globalconfig["keepontop"]: + self.settop() + while globalconfig["keepontop"]: - try: - hwnd = windows.GetForegroundWindow() - pid = windows.GetWindowThreadProcessId(hwnd) - if pid == os.getpid(): - pass - elif globalconfig["focusnotop"] and self.thistimenotsetop: - pass - else: - self.settop() - except: - print_exc() - time.sleep(0.5) - self.canceltop() - - threading.Thread(target=_).start() + try: + hwnd = windows.GetForegroundWindow() + pid = windows.GetWindowThreadProcessId(hwnd) + if pid == os.getpid(): + pass + elif globalconfig["focusnotop"] and self.thistimenotsetop: + pass + else: + self.settop() + except: + print_exc() + time.sleep(0.5) + self.canceltop() def seteffect(self): if globalconfig["WindowEffect"] == 0: @@ -583,33 +576,31 @@ class QUnFrameWindow(resizableframeless): elif globalconfig["WindowEffect"] == 2: winsharedutils.setAeroEffect(int(self.winId())) - def __init__(self): - - super(QUnFrameWindow, self).__init__( - None, - flags=Qt.WindowType.FramelessWindowHint - | Qt.WindowType.WindowMinimizeButtonHint, - dic=globalconfig, - key="transuigeo", - ) # 设置为顶级窗口,无边框 - icon = getExeIcon(sys.argv[0]) #'./LunaTranslator.exe')# QIcon() - # icon.addPixmap(QPixmap('./files/luna.png'), QIcon.Normal, QIcon.On) - self.setWindowIcon(icon) - self.tray = QSystemTrayIcon() - self.tray.setIcon(icon) - self.isfirstshow = True - self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) - self.setAttribute(Qt.WidgetAttribute.WA_ShowWithoutActivating, True) - self.setWindowTitle("LunaTranslator") - self.hidesignal.connect(self.hide_) + def initvalues(self): self.lastrefreshtime = time.time() self.autohidestart = False - threading.Thread(target=self.autohidedelaythread).start() - self.muteprocessignal.connect(self.muteprocessfuntion) - self.toolbarhidedelaysignal.connect(self.toolbarhidedelay) + self.enter_sig = 0 + self.fullscreenmanager_busy = False + self.isletgamefullscreened = False + self.fullscreenmanager = None + self.fullscreenmethod = None + self._isTracking = False + self.isontop = True + self.showhidestate = False + self.processismuteed = False + self.mousetransparent = False + self.thistimenotsetop = False + self.backtransparent = False + self.isbindedwindow = False + self.buttons = {} + self.showbuttons = [] + self.stylebuttons = {} + self.saveiterclasspointer = {} + + def initsignals(self): + self.hidesignal.connect(self.hide_) self.ocr_once_signal.connect(self.ocr_once_function) - self.enter_sig = 0 self.entersignal.connect(self.enterfunction) self.displaystatus.connect(self.showstatus) self.showhideuisignal.connect(self.showhideui) @@ -628,28 +619,32 @@ class QUnFrameWindow(resizableframeless): self.quitf_signal.connect(self.close) self.fullsgame_signal.connect(self._fullsgame) - self.fullscreenmanager_busy = False - self.isletgamefullscreened = False - self.fullscreenmanager = None - self.fullscreenmethod = None - self._isTracking = False - self.isontop = True + self.muteprocessignal.connect(self.muteprocessfuntion) + self.toolbarhidedelaysignal.connect(self.toolbarhidedelay) + + def __init__(self): + + super(QUnFrameWindow, self).__init__( + None, + flags=Qt.WindowType.FramelessWindowHint + | Qt.WindowType.WindowMinimizeButtonHint, + dic=globalconfig, + key="transuigeo", + ) # 设置为顶级窗口,无边框 + icon = getExeIcon(sys.argv[0]) #'./LunaTranslator.exe')# QIcon() + # icon.addPixmap(QPixmap('./files/luna.png'), QIcon.Normal, QIcon.On) + self.setWindowIcon(icon) + + self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) + self.setAttribute(Qt.WidgetAttribute.WA_ShowWithoutActivating, True) + self.setWindowTitle("LunaTranslator") + self.initvalues() + self.initsignals() self._TitleLabel = QLabel(self) - self._TitleLabel.move(0, 0) - self.showhidestate = False - self.processismuteed = False - self.mousetransparent = False - self.backtransparent = False - self.isbindedwindow = False - self.buttons = {} - self.showbuttons = [] - self.stylebuttons = {} - self.saveiterclasspointer = {} self.addbuttons() self.translate_text = Textbrowser(self) self.translate_text.contentsChanged.connect(self.textAreaChanged) - self.thistimenotsetop = False def createborderradiusstring(self, r, merge, top=False): if merge: @@ -868,7 +863,10 @@ class QUnFrameWindow(resizableframeless): self.refreshtoolicon() def changeshowhideraw(self): - gobject.baseobject.settin_ui.show_original_switch.click() + try: + gobject.baseobject.settin_ui.show_original_switch.click() + except: + pass def changeTranslateMode(self): globalconfig["autorun"] = not globalconfig["autorun"] @@ -1061,8 +1059,6 @@ class QUnFrameWindow(resizableframeless): if self.fullscreenmanager: self.fullscreenmanager.endX() gobject.baseobject.isrunning = False - self.tray.hide() - self.tray = None self.hide() if gobject.baseobject.textsource: @@ -1073,4 +1069,5 @@ class QUnFrameWindow(resizableframeless): endsubprocs() self.tryremoveuseless() + gobject.baseobject.destroytray() os._exit(0) diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index 4f0b4564..0761955e 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -399,6 +399,10 @@ def getsimplecombobox(lst, d, k, callback=None, fixedsize=False, internallist=No return s +def D_getsimplecombobox(lst, d, k, callback=None, fixedsize=False, internallist=None): + return lambda: getsimplecombobox(lst, d, k, callback, fixedsize, internallist) + + def getlineedit(d, key, callback=None, readonly=False): s = QLineEdit() s.setText(d[key]) @@ -422,6 +426,10 @@ def getspinbox(mini, maxi, d, key, double=False, step=1, callback=None, dec=1): return s +def D_getspinbox(mini, maxi, d, key, double=False, step=1, callback=None, dec=1): + return lambda: getspinbox(mini, maxi, d, key, double, step, callback, dec) + + def getcolorbutton( d, key, @@ -457,6 +465,34 @@ def getcolorbutton( return b +def D_getcolorbutton( + d, + key, + callback, + name=None, + parent=None, + icon="fa.paint-brush", + constcolor=None, + enable=True, + transparent=True, + qicon=None, + sizefixed=False, +): + return lambda: getcolorbutton( + d, + key, + callback, + name, + parent, + icon, + constcolor, + enable, + transparent, + qicon, + sizefixed, + ) + + def yuitsu_switch(parent, configdict, dictobjectn, key, callback, checked): dictobject = getattr(parent, dictobjectn) if checked: @@ -487,6 +523,14 @@ def getsimpleswitch( return b +def D_getsimpleswitch( + d, key, enable=True, callback=None, name=None, pair=None, parent=None, default=None +): + return lambda: getsimpleswitch( + d, key, enable, callback, name, pair, parent, default + ) + + def selectcolor( parent, configdict, configkey, button, item=None, name=None, callback=None ): @@ -506,24 +550,39 @@ def selectcolor( print_exc() -def getboxlayout(widgets, lc=QHBoxLayout, margin0=False, makewidget=False): +def getboxlayout( + widgets, lc=QHBoxLayout, margin0=False, makewidget=False, delay=False, both=False +): cp_layout = lc() - for w in widgets: - if isinstance(w, QWidget): - cp_layout.addWidget(w) - elif isinstance(w, QLayout): - cp_layout.addLayout(w) + + def __do(cp_layout, widgets): + for w in widgets: + if callable(w): + w = w() + if isinstance(w, QWidget): + cp_layout.addWidget(w) + elif isinstance(w, QLayout): + cp_layout.addLayout(w) + + _do = functools.partial(__do, cp_layout, widgets) if margin0: cp_layout.setContentsMargins(0, 0, 0, 0) + if not delay: + _do() if makewidget: w = QWidget() w.setLayout(cp_layout) + if delay: + return w, _do + if both: + return w, cp_layout + if makewidget: return w return cp_layout -def makevbox(wids): - return getboxlayout(wids, lc=QVBoxLayout, margin0=True, makewidget=True) +def getvboxwidget(): + return getboxlayout([], lc=QVBoxLayout, margin0=True, makewidget=True, both=True) def textbrowappendandmovetoend(textOutput, sentence, addspace=True): @@ -660,6 +719,10 @@ def getsimplekeyseq(dic, key, callback=None): return key1 +def D_getsimplekeyseq(dic, key, callback=None): + return lambda: getsimplekeyseq(dic, key, callback) + + class QWebWrap(QWidget): on_load = pyqtSignal(str) html_limit = 2 * 1024 * 1024 @@ -789,7 +852,7 @@ def tabadd_lazy(tab, title, getrealwidgetfunction): v = QVBoxLayout() q.setLayout(v) v.setContentsMargins(0, 0, 0, 0) - q.lazyfunction = lambda: v.addWidget(getrealwidgetfunction()) + q.lazyfunction = functools.partial(getrealwidgetfunction, v) tab.addTab(q, _TR(title)) @@ -835,9 +898,11 @@ def automakegrid(grid: QGridLayout, lis, save=False, savelist=None): if cols > 0: col = cols elif cols == 0: - col = maxl + col = maxl - nowc else: col = -maxl // cols + if callable(wid): + wid = wid() grid.addWidget(wid, nowr, nowc, 1, col) if save: ll.append(wid) @@ -847,7 +912,7 @@ def automakegrid(grid: QGridLayout, lis, save=False, savelist=None): grid.setRowMinimumHeight(nowr, 25) -def makegrid(grid, save=False, savelist=None, savelay=None): +def makegrid(grid=None, save=False, savelist=None, savelay=None, delay=False): class gridwidget(QWidget): pass @@ -858,13 +923,38 @@ def makegrid(grid, save=False, savelist=None, savelay=None): gridlayoutwidget.setLayout(gridlay) gridlayoutwidget.setStyleSheet("gridwidget{background-color:transparent;}") - automakegrid(gridlay, grid, save, savelist) - if save: - savelay.append(gridlay) - return gridlayoutwidget + def do(gridlay, grid, save, savelist, savelay): + automakegrid(gridlay, grid, save, savelist) + if save: + savelay.append(gridlay) + + __do = functools.partial(do, gridlay, grid, save, savelist, savelay) + if not delay: + __do() + return gridlayoutwidget + return gridlayoutwidget, __do -def makesubtab_lazy(titles=None, functions=None, klass=None, callback=None): +def makescroll(widget): + scroll = QScrollArea() + # scroll.setHorizontalScrollBarPolicy(1) + scroll.setStyleSheet("""QScrollArea{background-color:transparent;border:0px}""") + scroll.setWidgetResizable(True) + return scroll + + +def makescrollgrid(grid, lay, save=False, savelist=None, savelay=None): + wid, do = makegrid(grid, save, savelist, savelay, delay=True) + swid = makescroll(wid) + lay.addWidget(swid) + swid.setWidget(wid) + do() + return wid + + +def makesubtab_lazy( + titles=None, functions=None, klass=None, callback=None, delay=False +): if klass: tab = klass() else: @@ -882,16 +972,15 @@ def makesubtab_lazy(titles=None, functions=None, klass=None, callback=None): callback(i) tab.currentChanged.connect(functools.partial(__, tab)) - if titles and functions: - for i, func in enumerate(functions): - tabadd_lazy(tab, titles[i], func) - return tab + def __do(tab, titles, functions): + if titles and functions: + for i, func in enumerate(functions): + tabadd_lazy(tab, titles[i], func) -def makescroll(widget): - scroll = QScrollArea() - # scroll.setHorizontalScrollBarPolicy(1) - scroll.setStyleSheet("""QScrollArea{background-color:transparent;border:0px}""") - scroll.setWidgetResizable(True) - scroll.setWidget(widget) - return scroll + ___do = functools.partial(__do, tab, titles, functions) + if not delay: + ___do() + return tab + else: + return tab, ___do diff --git a/LunaTranslator/LunaTranslator/myutils/ocrutil.py b/LunaTranslator/LunaTranslator/myutils/ocrutil.py index 97c6f803..a2d582e4 100644 --- a/LunaTranslator/LunaTranslator/myutils/ocrutil.py +++ b/LunaTranslator/LunaTranslator/myutils/ocrutil.py @@ -76,7 +76,7 @@ def imageCut(hwnd, x1, y1, x2, y2, viscompare=True, rawimage=False) -> QImage: return image image2 = imagesolve(image) if viscompare: - gobject.baseobject.showocrimage.setimage.emit([image, image2]) + gobject.baseobject.maybesetimage([image, image2]) return image2 diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index 340dd953..2442aa7d 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -632,3 +632,11 @@ def str2rgba(string, alpha100): int(string[5:7], 16), alpha100 / 100, ) + +def get_time_stamp(): + 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 \ No newline at end of file diff --git a/LunaTranslator/LunaTranslator/qtsymbols.py b/LunaTranslator/LunaTranslator/qtsymbols.py index d9d6a322..c077d0d8 100644 --- a/LunaTranslator/LunaTranslator/qtsymbols.py +++ b/LunaTranslator/LunaTranslator/qtsymbols.py @@ -1,7 +1,7 @@ try: from PyQt5 import QtSvg from PyQt5.QtWidgets import QFrame,QListView,QCheckBox,QAbstractItemView,QTextEdit,QTableView,QHeaderView,QColorDialog,QSpinBox,QDoubleSpinBox,QComboBox,QDialogButtonBox,QMainWindow,QMessageBox,QDialog,QGridLayout,QTextBrowser,QGraphicsDropShadowEffect,QWidget,QSizePolicy,QScrollArea,QApplication,QPushButton,QSystemTrayIcon,QPlainTextEdit,QAction,QMenu,QFileDialog,QKeySequenceEdit,QLabel,QSpacerItem,QWidgetItem,QLayout,QTextBrowser,QLineEdit,QFormLayout,QSizePolicy,QTabWidget,QTabBar,QSplitter,QListWidget,QListWidgetItem,QHBoxLayout,QVBoxLayout,QSizeGrip,QFontComboBox,QProgressBar,QRadioButton,QButtonGroup,QSlider - from PyQt5.QtGui import QIconEngine,QIntValidator,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics + from PyQt5.QtGui import QIconEngine,QIntValidator,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent from PyQt5.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex isqt5 = True except: @@ -9,6 +9,6 @@ except: #print_exc() from PyQt6 import QtSvg from PyQt6.QtWidgets import QFrame,QListView,QCheckBox,QAbstractItemView,QTextEdit,QTableView,QHeaderView,QColorDialog,QSpinBox,QDoubleSpinBox,QComboBox,QDialogButtonBox,QMainWindow,QMessageBox,QDialog,QGridLayout,QTextBrowser,QGraphicsDropShadowEffect,QWidget,QSizePolicy,QScrollArea,QApplication,QPushButton,QSystemTrayIcon,QPlainTextEdit,QMenu,QFileDialog,QKeySequenceEdit,QLabel,QSpacerItem,QWidgetItem,QLayout,QTextBrowser,QLineEdit,QFormLayout,QSizePolicy,QTabWidget,QTabBar,QSplitter,QListWidget,QListWidgetItem,QHBoxLayout,QVBoxLayout,QSizeGrip,QFontComboBox,QProgressBar,QRadioButton,QButtonGroup,QSlider - from PyQt6.QtGui import QIconEngine,QIntValidator,QAction,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics + from PyQt6.QtGui import QIconEngine,QIntValidator,QAction,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics,QShowEvent from PyQt6.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex isqt5 = False \ No newline at end of file diff --git a/LunaTranslator/LunaTranslator/textsource/ocrtext.py b/LunaTranslator/LunaTranslator/textsource/ocrtext.py index c49e64e0..095660dd 100644 --- a/LunaTranslator/LunaTranslator/textsource/ocrtext.py +++ b/LunaTranslator/LunaTranslator/textsource/ocrtext.py @@ -105,9 +105,12 @@ class ocrtext(basetext): else: image_score = 0 if i == 0: - gobject.baseobject.settin_ui.threshold1label.setText( - str(image_score) - ) + try: + gobject.baseobject.settin_ui.threshold1label.setText( + str(image_score) + ) + except: + pass self.savelastimg[i] = imgr1 if image_score > globalconfig["ocr_stable_sim"]: @@ -118,9 +121,12 @@ class ocrtext(basetext): else: image_score2 = 0 if i == 0: - gobject.baseobject.settin_ui.threshold2label.setText( - str(image_score2) - ) + try: + gobject.baseobject.settin_ui.threshold2label.setText( + str(image_score2) + ) + except: + pass if image_score2 > globalconfig["ocr_diff_sim"]: ok = False else: diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 1d2a6522..32ab023e 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -562,21 +562,6 @@ "quick_setting": { "use": false, "all": { - "_A": { - "use": false, - "name": "选择翻译源_剪贴板", - "keystring": "" - }, - "_B": { - "use": false, - "name": "选择翻译源_OCR", - "keystring": "" - }, - "_C": { - "use": false, - "name": "选择翻译源_HOOK", - "keystring": "" - }, "_1": { "use": false, "name": "重新翻译", @@ -706,6 +691,11 @@ "use": false, "name": "模拟按键Enter", "keystring": "" + }, + "_28": { + "use": false, + "name": "复制到剪贴板_翻译", + "keystring": "" } } }, diff --git a/LunaTranslator/files/lang/ar.json b/LunaTranslator/files/lang/ar.json index a6fd819b..28dabdbd 100644 --- a/LunaTranslator/files/lang/ar.json +++ b/LunaTranslator/files/lang/ar.json @@ -620,7 +620,6 @@ "过长惩罚": "عقوبة طويلة", "重复惩罚": "تكرار العقوبة", "OCR语言包": "التعرف الضوئي على الحروف حزمة اللغة", - "选择翻译源": "اختيار مصدر الترجمة", "最长显示字数": "أقصى عرض الكلمات", "显示日语注音": "عرض صوتي ياباني", "注音颜色": "لون صوتي", @@ -804,5 +803,9 @@ "窗口特效": "نافذة المؤثرات الخاصة", "实时编辑": "في الوقت الحقيقي تحرير", "翻译记录": "سجل الترجمة", - "遍历目录中的全部词典文件": "اجتياز جميع ملفات القاموس في الدليل" + "遍历目录中的全部词典文件": "اجتياز جميع ملفات القاموس في الدليل", + "网络请求": "طلب شبكة", + "网页显示": "عرض الصفحة", + "显示时间": "عرض الوقت", + "不显示时间": "لا وقت العرض" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/cht.json b/LunaTranslator/files/lang/cht.json index 59982bdc..3ed9af91 100644 --- a/LunaTranslator/files/lang/cht.json +++ b/LunaTranslator/files/lang/cht.json @@ -620,7 +620,6 @@ "过长惩罚": "過長懲罰", "重复惩罚": "重複懲罰", "OCR语言包": "OCR語言包", - "选择翻译源": "選擇翻譯源", "最长显示字数": "最長顯示字數", "显示日语注音": "顯示日語注音", "注音颜色": "注音顏色", @@ -804,5 +803,9 @@ "窗口特效": "視窗特效", "实时编辑": "實时編輯", "翻译记录": "翻譯記錄", - "遍历目录中的全部词典文件": "遍歷目錄中的全部詞典檔案" + "遍历目录中的全部词典文件": "遍歷目錄中的全部詞典檔案", + "网络请求": "網絡請求", + "网页显示": "網頁顯示", + "显示时间": "顯示時間", + "不显示时间": "不顯示時間" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/en.json b/LunaTranslator/files/lang/en.json index beb4a9ae..35098b08 100644 --- a/LunaTranslator/files/lang/en.json +++ b/LunaTranslator/files/lang/en.json @@ -620,7 +620,6 @@ "过长惩罚": "Excessive punishment", "重复惩罚": "Repetitive punishment", "OCR语言包": "OCR Language Pack", - "选择翻译源": "Select Translation Source", "最长显示字数": "Maximum number of displayed words", "显示日语注音": "Display Japanese Pinyin", "注音颜色": "Pinyin color", @@ -804,5 +803,9 @@ "窗口特效": "Window effects", "实时编辑": "Real time editing", "翻译记录": "Translation records", - "遍历目录中的全部词典文件": "Traverse all dictionary files in the directory" + "遍历目录中的全部词典文件": "Traverse all dictionary files in the directory", + "网络请求": "Network request", + "网页显示": "Web page display", + "显示时间": "Display time", + "不显示时间": "Do not display time" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/es.json b/LunaTranslator/files/lang/es.json index a5ca797a..c46c4602 100644 --- a/LunaTranslator/files/lang/es.json +++ b/LunaTranslator/files/lang/es.json @@ -620,7 +620,6 @@ "过长惩罚": "Castigo excesivo", "重复惩罚": "Repetir el castigo", "OCR语言包": "Paquete lingüístico OCR", - "选择翻译源": "Selección de la fuente de traducción", "最长显示字数": "Número máximo de palabras mostradas", "显示日语注音": "Muestra la fonética japonesa", "注音颜色": "Color de la nota", @@ -804,5 +803,9 @@ "窗口特效": "Efectos especiales de la ventana", "实时编辑": "Edición en tiempo real", "翻译记录": "Registros de traducción", - "遍历目录中的全部词典文件": "Recorrer todos los archivos del diccionario en el catálogo" + "遍历目录中的全部词典文件": "Recorrer todos los archivos del diccionario en el catálogo", + "网络请求": "Solicitud de red", + "网页显示": "Pantalla de la página web", + "显示时间": "Tiempo de visualización", + "不显示时间": "No muestra el tiempo" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/fr.json b/LunaTranslator/files/lang/fr.json index f2c98563..7bf30533 100644 --- a/LunaTranslator/files/lang/fr.json +++ b/LunaTranslator/files/lang/fr.json @@ -620,7 +620,6 @@ "过长惩罚": "Pénalité trop longue", "重复惩罚": "Punition répétée", "OCR语言包": "Pack de langue ocr", - "选择翻译源": "Choisir une source de traduction", "最长显示字数": "Nombre maximal de mots affichés", "显示日语注音": "Afficher les notes en japonais", "注音颜色": "Couleur d'accent", @@ -804,5 +803,9 @@ "窗口特效": "Effets spéciaux de fenêtre", "实时编辑": "Edit en temps réel", "翻译记录": "Record de traduction", - "遍历目录中的全部词典文件": "Parcourir tous les fichiers de dictionnaire dans le Répertoire" + "遍历目录中的全部词典文件": "Parcourir tous les fichiers de dictionnaire dans le Répertoire", + "网络请求": "Demande de réseau", + "网页显示": "Affichage de la page Web", + "显示时间": "Afficher l'heure", + "不显示时间": "Ne pas afficher l'heure" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/it.json b/LunaTranslator/files/lang/it.json index 2f6b4e97..3c86bcc1 100644 --- a/LunaTranslator/files/lang/it.json +++ b/LunaTranslator/files/lang/it.json @@ -620,7 +620,6 @@ "过长惩罚": "Pena eccessiva", "重复惩罚": "Pena ripetitiva", "OCR语言包": "Pacchetto linguistico OCR", - "选择翻译源": "Seleziona sorgente di traduzione", "最长显示字数": "Numero massimo di parole visualizzate", "显示日语注音": "Mostra pinyin giapponese", "注音颜色": "Colore pinyin", @@ -804,5 +803,9 @@ "窗口特效": "Effetti finestra", "实时编辑": "Modifica in tempo reale", "翻译记录": "Record di traduzione", - "遍历目录中的全部词典文件": "Attraversa tutti i file del dizionario nella directory" + "遍历目录中的全部词典文件": "Attraversa tutti i file del dizionario nella directory", + "网络请求": "Richiesta di rete", + "网页显示": "Visualizzazione pagina web", + "显示时间": "Tempo di visualizzazione", + "不显示时间": "Non visualizzare l'ora" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ja.json b/LunaTranslator/files/lang/ja.json index ea63ba7c..bc070242 100644 --- a/LunaTranslator/files/lang/ja.json +++ b/LunaTranslator/files/lang/ja.json @@ -620,7 +620,6 @@ "过长惩罚": "長すぎる罰", "重复惩罚": "繰り返し罰する.", "OCR语言包": "OCR言語パック", - "选择翻译源": "翻訳ソースの選択", "最长显示字数": "最長表示文字数", "显示日语注音": "日本語のルビを表示", "注音颜色": "ルビの色", @@ -804,5 +803,9 @@ "窗口特效": "ウィンドウ効果", "实时编辑": "リアルタイム編集", "翻译记录": "翻訳レコード", - "遍历目录中的全部词典文件": "ディレクトリ内のすべての辞書ファイルを巡回" + "遍历目录中的全部词典文件": "ディレクトリ内のすべての辞書ファイルを巡回", + "网络请求": "ネットワーク要求", + "网页显示": "Webページ表示", + "显示时间": "表示時間", + "不显示时间": "時間を表示しない" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ko.json b/LunaTranslator/files/lang/ko.json index 4fffa2c8..3b37215b 100644 --- a/LunaTranslator/files/lang/ko.json +++ b/LunaTranslator/files/lang/ko.json @@ -620,7 +620,6 @@ "过长惩罚": "과도한 처벌", "重复惩罚": "반복 처벌", "OCR语言包": "OCR 언어 팩", - "选择翻译源": "번역 소스 선택", "最长显示字数": "최대 표시 단어 수", "显示日语注音": "일본어 메모 표시", "注音颜色": "주음 색상", @@ -804,5 +803,9 @@ "窗口特效": "창 효과", "实时编辑": "실시간 편집", "翻译记录": "번역 기록", - "遍历目录中的全部词典文件": "디렉토리의 모든 사전 파일 반복" + "遍历目录中的全部词典文件": "디렉토리의 모든 사전 파일 반복", + "网络请求": "네트워크 요청", + "网页显示": "웹 페이지 표시", + "显示时间": "표시 시간", + "不显示时间": "시간 표시 안 함" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/pl.json b/LunaTranslator/files/lang/pl.json index 366484ef..2c65e769 100644 --- a/LunaTranslator/files/lang/pl.json +++ b/LunaTranslator/files/lang/pl.json @@ -620,7 +620,6 @@ "过长惩罚": "Nadmierna kara", "重复惩罚": "Kary powtarzające się", "OCR语言包": "Pakiet językowy OCR", - "选择翻译源": "Wybierz źródło tłumaczenia", "最长显示字数": "Maksymalna liczba wyświetlanych słów", "显示日语注音": "Wyświetl japoński pinyin", "注音颜色": "Kolor pinyin", @@ -804,5 +803,9 @@ "窗口特效": "Efekty okien", "实时编辑": "Edycja w czasie rzeczywistym", "翻译记录": "Zapisy tłumaczeń", - "遍历目录中的全部词典文件": "Przejrzyj wszystkie pliki słownika w katalogu" + "遍历目录中的全部词典文件": "Przejrzyj wszystkie pliki słownika w katalogu", + "网络请求": "Żądanie sieci", + "网页显示": "Wyświetlanie strony internetowej", + "显示时间": "Czas wyświetlania", + "不显示时间": "Nie wyświetlaj czasu" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ru.json b/LunaTranslator/files/lang/ru.json index e1943cba..cba04542 100644 --- a/LunaTranslator/files/lang/ru.json +++ b/LunaTranslator/files/lang/ru.json @@ -620,7 +620,6 @@ "过长惩罚": "Слишком длительное наказание", "重复惩罚": "Повторное наказание", "OCR语言包": "Языковый пакет OCR", - "选择翻译源": "Выберите источник перевода", "最长显示字数": "Максимальное количество слов", "显示日语注音": "Показать японское произношение", "注音颜色": "Цвет звука", @@ -804,5 +803,9 @@ "窗口特效": "Специальные эффекты окон", "实时编辑": "Редактирование в реальном времени", "翻译记录": "Перевод записей", - "遍历目录中的全部词典文件": "Все словарные файлы в каталоге" + "遍历目录中的全部词典文件": "Все словарные файлы в каталоге", + "网络请求": "Сетевой запрос", + "网页显示": "Показать страницу", + "显示时间": "Показать время", + "不显示时间": "Не показывать время" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/th.json b/LunaTranslator/files/lang/th.json index 475e8737..8a486dd8 100644 --- a/LunaTranslator/files/lang/th.json +++ b/LunaTranslator/files/lang/th.json @@ -620,7 +620,6 @@ "过长惩罚": "การลงโทษที่ยาวนานเกินไป", "重复惩罚": "การลงโทษซ้ำ", "OCR语言包": "แพคภาษา OCR", - "选择翻译源": "เลือกแหล่งที่มาของการแปล", "最长显示字数": "แสดงจำนวนคำที่ยาวที่สุด", "显示日语注音": "แสดงหมายเหตุภาษาญี่ปุ่น", "注音颜色": "สี Injection", @@ -804,5 +803,9 @@ "窗口特效": "เทคนิคพิเศษของหน้าต่าง", "实时编辑": "แก้ไขแบบเรียลไทม์", "翻译记录": "บันทึกการแปล", - "遍历目录中的全部词典文件": "ผ่านไฟล์พจนานุกรมทั้งหมดในไดเรกทอรี" + "遍历目录中的全部词典文件": "ผ่านไฟล์พจนานุกรมทั้งหมดในไดเรกทอรี", + "网络请求": "คำขอเครือข่าย", + "网页显示": "แสดงหน้าเว็บ", + "显示时间": "แสดงเวลา", + "不显示时间": "ไม่แสดงเวลา" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/tr.json b/LunaTranslator/files/lang/tr.json index edc09691..b9d4797b 100644 --- a/LunaTranslator/files/lang/tr.json +++ b/LunaTranslator/files/lang/tr.json @@ -620,7 +620,6 @@ "过长惩罚": "Çok fazla ceza", "重复惩罚": "Tekrar cezalandırıcı", "OCR语言包": "OCR Language Pack", - "选择翻译源": "Çeviri Kaynağını Seç", "最长显示字数": "Gösterilen sözlerin en yüksek sayısı", "显示日语注音": "Display Japanese Pinyin", "注音颜色": "Pinyin rengi", @@ -804,5 +803,9 @@ "窗口特效": "Pencere etkileri", "实时编辑": "Gerçek zamanlı düzenleme", "翻译记录": "Çeviri kayıtları", - "遍历目录中的全部词典文件": "Dizindeki bütün sözlük dosyalarını yolla" + "遍历目录中的全部词典文件": "Dizindeki bütün sözlük dosyalarını yolla", + "网络请求": "Network request", + "网页显示": "Web sayfası gösterisi", + "显示时间": "Display time", + "不显示时间": "Zamanı gösterme" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/uk.json b/LunaTranslator/files/lang/uk.json index ed638c93..6ee58f56 100644 --- a/LunaTranslator/files/lang/uk.json +++ b/LunaTranslator/files/lang/uk.json @@ -620,7 +620,6 @@ "过长惩罚": "Великий покарання", "重复惩罚": "Повторює покарання", "OCR语言包": "Пакет мови OCR", - "选择翻译源": "Виберіть джерело перекладу", "最长显示字数": "Максимальна кількість показаних слів", "显示日语注音": "Показувати японський пінін", "注音颜色": "Колір пініна", @@ -804,5 +803,9 @@ "窗口特效": "Ефекти вікна", "实时编辑": "Редагування реального часу", "翻译记录": "Записи перекладів", - "遍历目录中的全部词典文件": "Пересунути всі файли словника у каталозі" + "遍历目录中的全部词典文件": "Пересунути всі файли словника у каталозі", + "网络请求": "Запит на мережу", + "网页显示": "Показ веб- сторінок", + "显示时间": "Час показу", + "不显示时间": "Не показувати час" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/vi.json b/LunaTranslator/files/lang/vi.json index bef03faf..9038c865 100644 --- a/LunaTranslator/files/lang/vi.json +++ b/LunaTranslator/files/lang/vi.json @@ -620,7 +620,6 @@ "过长惩罚": "Hình phạt quá dài", "重复惩罚": "Hình phạt lặp lại", "OCR语言包": "Gói ngôn ngữ OCR", - "选择翻译源": "Chọn nguồn dịch", "最长显示字数": "Hiển thị tối đa số từ", "显示日语注音": "Hiện chú thích tiếng Nhật", "注音颜色": "Màu chú thích", @@ -804,5 +803,9 @@ "窗口特效": "Hiệu ứng cửa sổ", "实时编辑": "Chỉnh sửa thời gian thực", "翻译记录": "Bản dịch", - "遍历目录中的全部词典文件": "Đi qua tất cả các tập tin từ điển trong thư mục" + "遍历目录中的全部词典文件": "Đi qua tất cả các tập tin từ điển trong thư mục", + "网络请求": "Yêu cầu mạng", + "网页显示": "Hiển thị trang web", + "显示时间": "Thời gian hiển thị", + "不显示时间": "Không hiển thị thời gian" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index 7ea64c9a..417f24ee 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -619,7 +619,6 @@ "过长惩罚": "", "重复惩罚": "", "OCR语言包": "", - "选择翻译源": "", "最长显示字数": "", "显示日语注音": "", "注音颜色": "", @@ -804,5 +803,9 @@ "窗口特效": "", "实时编辑": "", "翻译记录": "", - "遍历目录中的全部词典文件": "" + "遍历目录中的全部词典文件": "", + "网络请求": "", + "网页显示": "", + "显示时间": "", + "不显示时间": "" } \ No newline at end of file diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 97387b36..319d7917 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -28,8 +28,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version) include(generate_product_version) set(VERSION_MAJOR 3) -set(VERSION_MINOR 0) -set(VERSION_PATCH 6) +set(VERSION_MINOR 1) +set(VERSION_PATCH 0) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)