From 92af25483a7cf17f13a6f1df2539fd859a53d8df 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: Sun, 11 Aug 2024 02:59:54 +0800 Subject: [PATCH] Revert --- .../LunaTranslator/gui/dialog_savedgame.py | 18 ++++++ LunaTranslator/LunaTranslator/gui/showword.py | 57 +++++++------------ .../LunaTranslator/myutils/config.py | 17 +----- .../files/defaultconfig/config.json | 5 +- plugins/CMakeLists.txt | 2 +- 5 files changed, 41 insertions(+), 58 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index 22944533..8e64f9a6 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -761,6 +761,7 @@ class dialog_setting_game_internal(QWidget): ("翻译优化", functools.partial(self.___tabf, self.gettransoptimi)), ("语音", functools.partial(self.___tabf, self.getttssetting)), ("预翻译", functools.partial(self.___tabf, self.getpretranstab)), + ("Anki", functools.partial(self.___tabf, self.maketabforanki)), ] methodtab, do = makesubtab_lazy( [_[0] for _ in functs], @@ -1115,6 +1116,23 @@ class dialog_setting_game_internal(QWidget): ), ) + def maketabforanki(self, formLayout: LFormLayout, gameuid): + + savehook_new_data[gameuid]["anki_DeckName"] = savehook_new_data[gameuid].get( + "anki_DeckName", globalconfig["ankiconnect"]["DeckName"] + ) + + formLayout2 = self.createfollowdefault( + savehook_new_data[gameuid], "follow_default_ankisettings", formLayout + ) + formLayout2.addRow( + "DeckName", + getlineedit( + savehook_new_data[gameuid], + "anki_DeckName", + ), + ) + def getpretranstab(self, formLayout: LFormLayout, gameuid): def selectimg(gameuid, key, res): diff --git a/LunaTranslator/LunaTranslator/gui/showword.py b/LunaTranslator/LunaTranslator/gui/showword.py index adc3ce8d..f4f2e70a 100644 --- a/LunaTranslator/LunaTranslator/gui/showword.py +++ b/LunaTranslator/LunaTranslator/gui/showword.py @@ -15,7 +15,6 @@ from gui.usefulwidget import ( statusbutton, getQMessageBox, auto_select_webview, - FocusCombo, getboxlayout, getspinbox, getsimplecombobox, @@ -291,36 +290,7 @@ class AnkiWindow(QWidget): layout.addRow( "端口号", getspinbox(0, 65536, globalconfig["ankiconnect"], "port") ) - combox = getsimplecombobox( - globalconfig["ankiconnect"]["DeckNameS"], - globalconfig["ankiconnect"], - "DeckName_i", - ) - - def refreshcombo(combo: QComboBox): - combo.clear() - if len(globalconfig["ankiconnect"]["DeckNameS"]) == 0: - globalconfig["ankiconnect"]["DeckNameS"].append("lunadeck") - combo.addItems(globalconfig["ankiconnect"]["DeckNameS"]) - - layout.addRow( - "DeckName", - getboxlayout( - [ - getIconButton( - lambda: listediter( - self, - "DeckName", - "DeckName", - globalconfig["ankiconnect"]["DeckNameS"], - closecallback=functools.partial(refreshcombo, combox), - ), - icon="fa.gear", - ), - combox, - ] - ), - ) + layout.addRow("DeckName", getlineedit(globalconfig["ankiconnect"], "DeckName")) layout.addRow( "ModelName", getlineedit(globalconfig["ankiconnect"], "ModelName5") ) @@ -624,16 +594,29 @@ class AnkiWindow(QWidget): def addanki(self): + def __internal__DeckName(): + try: + for _ in (0,): + + if not gobject.baseobject.textsource: + break + + gameuid = gobject.baseobject.textsource.gameuid + if not gameuid: + break + if savehook_new_data[gameuid]["follow_default_ankisettings"]: + break + + return savehook_new_data[gameuid]["anki_DeckName"] + except: + pass + return globalconfig["ankiconnect"]["DeckName"] + autoUpdateModel = globalconfig["ankiconnect"]["autoUpdateModel"] allowDuplicate = globalconfig["ankiconnect"]["allowDuplicate"] anki.global_port = globalconfig["ankiconnect"]["port"] ModelName = globalconfig["ankiconnect"]["ModelName5"] - try: - DeckName = globalconfig["ankiconnect"]["DeckNameS"][ - globalconfig["ankiconnect"]["DeckName_i"] - ] - except: - DeckName = "lunadeck" + DeckName = __internal__DeckName() model_htmlfront, model_htmlback, model_css = self.tryloadankitemplates() tags = globalconfig["ankiconnect"]["tags"] anki.Deck.create(DeckName) diff --git a/LunaTranslator/LunaTranslator/myutils/config.py b/LunaTranslator/LunaTranslator/myutils/config.py index fc417197..55b8ee44 100644 --- a/LunaTranslator/LunaTranslator/myutils/config.py +++ b/LunaTranslator/LunaTranslator/myutils/config.py @@ -131,6 +131,7 @@ def getdefaultsavehook(title=None): # "private_srclang_2": 0,# 显示时再加载,缺省用global中的键 # "private_tgtlang_2": 0, "follow_default_ankisettings": True, + # "anki_DeckName":str # "localeswitcher": 0,废弃 "onloadautochangemode2": 0, "needinserthookcode": [], @@ -467,22 +468,6 @@ for key in globalconfig["toolbutton"]["rank2"]: for key in ___: globalconfig["toolbutton"]["rank2"].remove(key) -if "DeckName" in globalconfig["ankiconnect"]: - if ( - globalconfig["ankiconnect"]["DeckName"] - not in globalconfig["ankiconnect"]["DeckNameS"] - ): - globalconfig["ankiconnect"]["DeckNameS"].append( - globalconfig["ankiconnect"].pop("DeckName") - ) - - for data in savehook_new_data.values(): - deck = data.get("anki_DeckName", "") - if not deck: - continue - if deck in globalconfig["ankiconnect"]["DeckNameS"]: - continue - globalconfig["ankiconnect"]["DeckNameS"].append(deck) for group in ["webview", "textbrowser"]: diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 3637c404..8a9089f2 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -472,10 +472,7 @@ "jiamingcolor": "black", "ankiconnect": { "port": 8765, - "DeckName_i": 0, - "DeckNameS": [ - "lunadeck" - ], + "DeckName": "lunadeck", "ModelName5": "lunamodel5", "allowDuplicate": true, "autoUpdateModel": true, diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 44dd5105..3580ee38 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 5) set(VERSION_MINOR 25) -set(VERSION_PATCH 1) +set(VERSION_PATCH 0) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)