From cb0720f13774c6043ac0fa24c59c74b632c98871 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: Tue, 6 Aug 2024 13:31:30 +0800 Subject: [PATCH] fix --- LunaTranslator/LunaTranslator/LunaTranslator.py | 7 ++++--- LunaTranslator/LunaTranslator/gui/setting_hotkey.py | 12 +++++++++--- LunaTranslator/LunaTranslator/gui/setting_tts.py | 6 ++++-- LunaTranslator/LunaTranslator/gui/translatorUI.py | 10 +++++----- LunaTranslator/LunaTranslator/gui/usefulwidget.py | 3 ++- LunaTranslator/files/defaultconfig/config.json | 5 +++++ 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index c6990898..3222b3a8 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -577,16 +577,17 @@ class MAINUI: reader = self.reader else: engine, voice, _ = target - reader = self.specialreaders.get((engine, voice), None) + key = str((engine, voice)) # voice可能是list,无法hash + reader = self.specialreaders.get(key, None) if reader == -1: reader = self.reader elif reader is None: try: reader = self.loadreader(engine, privateconfig={"voice": voice}) - self.specialreaders[(engine, voice)] = reader + self.specialreaders[key] = reader except: reader = self.reader - self.specialreaders[(engine, voice)] = -1 + self.specialreaders[key] = -1 if reader is None: return if text2 is None: diff --git a/LunaTranslator/LunaTranslator/gui/setting_hotkey.py b/LunaTranslator/LunaTranslator/gui/setting_hotkey.py index 81bd4068..05a4c056 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_hotkey.py +++ b/LunaTranslator/LunaTranslator/gui/setting_hotkey.py @@ -26,6 +26,13 @@ def maybesetreferlabels(self, name, text): self.referlabels_data[name] = text +def autoreadswitch(self): + try: + self.autoread.clicksignal.emit() + except: + globalconfig["autoread"] = not globalconfig["autoread"] + + def registrhotkeys(self): self.hotkeymanager = SystemHotkey() self.referlabels = {} @@ -65,6 +72,7 @@ def registrhotkeys(self): "_29": lambda: gobject.baseobject.searchwordW.ankiwindow.recordbtn1.click(), "_30": lambda: gobject.baseobject.searchwordW.ankiwindow.recordbtn2.click(), "_31": lambda: gobject.baseobject.hualang_recordbtn.click(), + "_32": functools.partial(autoreadswitch, self), } for name in globalconfig["quick_setting"]["all"]: if name not in self.bindfunctions: @@ -89,9 +97,7 @@ def setTab_quick_lazy(self): ), ] ] - for name in globalconfig["quick_setting"]["all"]: - if name not in self.bindfunctions: - continue + for name in self.bindfunctions: grids.append( [ diff --git a/LunaTranslator/LunaTranslator/gui/setting_tts.py b/LunaTranslator/LunaTranslator/gui/setting_tts.py index 5c67c209..5fcd3e11 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_tts.py +++ b/LunaTranslator/LunaTranslator/gui/setting_tts.py @@ -30,7 +30,7 @@ def showvoicelist(self, obj): vl = obj.voiceshowlist idx = obj.voicelist.index(obj.voice) try: - + self.voicecombo.clear() self.voicecombo.addItems(vl) self.voicecombo.setCurrentIndex(idx) @@ -186,7 +186,9 @@ def setTab5lz(self): grid=[ [ "自动朗读", - D_getsimpleswitch(globalconfig, "autoread"), + D_getsimpleswitch( + globalconfig, "autoread", name="autoread", parent=self + ), ], [ "不被打断", diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 3d8eb942..6c128a71 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -471,7 +471,7 @@ class QUnFrameWindow(resizableframeless): def btnsetontopfunction(self): try: - gobject.baseobject.settin_ui.keepontopbutton.click() + gobject.baseobject.settin_ui.keepontopbutton.clicksignal.emit() except: globalconfig["keepontop"] = not globalconfig["keepontop"] @@ -886,7 +886,7 @@ class QUnFrameWindow(resizableframeless): def setselectable(self): try: - gobject.baseobject.settin_ui.selectable_btn.click() + gobject.baseobject.settin_ui.selectable_btn.clicksignal.emit() except: globalconfig["selectable"] = not globalconfig["selectable"] self.translate_text.textbrowser.setselectable(globalconfig["selectable"]) @@ -1042,7 +1042,7 @@ class QUnFrameWindow(resizableframeless): if idx == 0: try: - gobject.baseobject.settin_ui.mousetransbutton.click() + gobject.baseobject.settin_ui.mousetransbutton.clicksignal.emit() except: globalconfig["mousetransparent"] = not globalconfig["mousetransparent"] self.mousetransparent_check() @@ -1072,7 +1072,7 @@ class QUnFrameWindow(resizableframeless): def changeshowhideraw(self): try: - gobject.baseobject.settin_ui.show_original_switch.click() + gobject.baseobject.settin_ui.show_original_switch.clicksignal.emit() except: globalconfig["isshowrawtext"] = not globalconfig["isshowrawtext"] self.refreshtoolicon() @@ -1083,7 +1083,7 @@ class QUnFrameWindow(resizableframeless): def changetoolslockstate(self): try: - gobject.baseobject.settin_ui.locktoolsbutton.click() + gobject.baseobject.settin_ui.locktoolsbutton.clicksignal.emit() except: globalconfig["locktools"] = not globalconfig["locktools"] self.refreshtoolicon() diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index 90275eb3..650abb8b 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -310,6 +310,7 @@ def disablecolor(__: QColor): class MySwitch(commonsolveevent): clicked = pyqtSignal(bool) + clicksignal = pyqtSignal() def click(self): self.setChecked(not self.checked) @@ -325,7 +326,7 @@ class MySwitch(commonsolveevent): self.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) self.checked = sign self.setCursor(Qt.CursorShape.PointingHandCursor) - + self.clicksignal.connect(self.click) self.__currv = 0 if sign: self.__currv = 20 diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 87977ee6..884c2be9 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -1033,6 +1033,11 @@ "use": false, "name": "画廊_录音", "keystring": "" + }, + "_32": { + "use": false, + "name": "自动朗读", + "keystring": "" } } },