From 0b475800888e5b98b1499e016067e2bc8343a79c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Sun, 3 Nov 2024 22:53:48 +0800 Subject: [PATCH] tts --- src/LunaTranslator/gui/showword.py | 22 +++++++++++++++++++--- src/files/defaultconfig/config.json | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/LunaTranslator/gui/showword.py b/src/LunaTranslator/gui/showword.py index 814f300d..1a300703 100644 --- a/src/LunaTranslator/gui/showword.py +++ b/src/LunaTranslator/gui/showword.py @@ -497,6 +497,7 @@ class AnkiWindow(QWidget): ) folder_open3 = QPushButton(qtawesome.icon("fa.folder-open"), "") folder_open3.clicked.connect(functools.partial(self.selecfile2, self.editpath)) + def createadd(): btn = LRButton("添加") btn.clicked.connect(functools.partial(self.errorwrap, False)) @@ -600,7 +601,7 @@ class AnkiWindow(QWidget): ] ), self.viewimagelabel, - createadd + createadd, ], QVBoxLayout, ), @@ -1040,6 +1041,17 @@ class searchwordW(closeashidewindow): _.searchtext.setText(word) _.__search_by_click_search_btn() + def showmenu_auto_sound(self, _): + + menu = QMenu(self) + auto = LAction("自动") + auto.setCheckable(True) + auto.setChecked(globalconfig["is_search_word_auto_tts"]) + menu.addAction(auto) + action = menu.exec(QCursor.pos()) + if action == auto: + globalconfig["is_search_word_auto_tts"] = auto.isChecked() + def setupUi(self): self.setWindowTitle("查词") self.ankiwindow = AnkiWindow(self) @@ -1083,7 +1095,9 @@ class searchwordW(closeashidewindow): self.searchlayout.addWidget(searchbutton) soundbutton = QPushButton(qtawesome.icon("fa.music"), "") - soundbutton.clicked.connect(self.langdu) + soundbutton.clicked.connect(self.tts_for_searched_word) + soundbutton.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) + soundbutton.customContextMenuRequested.connect(self.showmenu_auto_sound) self.soundbutton = soundbutton self.searchlayout.addWidget(soundbutton) @@ -1150,7 +1164,7 @@ class searchwordW(closeashidewindow): self.ankiwindow.hide() self.isfirstshowanki = False - def langdu(self): + def tts_for_searched_word(self): if gobject.baseobject.reader: gobject.baseobject.audioplayer.timestamp = uuid.uuid4() gobject.baseobject.reader.read( @@ -1231,6 +1245,8 @@ class searchwordW(closeashidewindow): word = word.strip() if word == "": return + if globalconfig["is_search_word_auto_tts"]: + self.tts_for_searched_word() self.ankiwindow.reset(word) for i in range(self.tab.count()): self.tab.removeTab(0) diff --git a/src/files/defaultconfig/config.json b/src/files/defaultconfig/config.json index 0f4ff784..69e9aa65 100644 --- a/src/files/defaultconfig/config.json +++ b/src/files/defaultconfig/config.json @@ -18,6 +18,7 @@ "network": 1, "useextrahtml": true, "ocrselectalpha": 0.3, + "is_search_word_auto_tts": false, "network_websocket": 1, "webview_textbrowser": false, "imagewrapmode": 0,