This commit is contained in:
恍兮惚兮 2024-08-11 02:59:54 +08:00
parent fb6d115473
commit 92af25483a
5 changed files with 41 additions and 58 deletions

View File

@ -761,6 +761,7 @@ class dialog_setting_game_internal(QWidget):
("翻译优化", functools.partial(self.___tabf, self.gettransoptimi)), ("翻译优化", functools.partial(self.___tabf, self.gettransoptimi)),
("语音", functools.partial(self.___tabf, self.getttssetting)), ("语音", functools.partial(self.___tabf, self.getttssetting)),
("预翻译", functools.partial(self.___tabf, self.getpretranstab)), ("预翻译", functools.partial(self.___tabf, self.getpretranstab)),
("Anki", functools.partial(self.___tabf, self.maketabforanki)),
] ]
methodtab, do = makesubtab_lazy( methodtab, do = makesubtab_lazy(
[_[0] for _ in functs], [_[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 getpretranstab(self, formLayout: LFormLayout, gameuid):
def selectimg(gameuid, key, res): def selectimg(gameuid, key, res):

View File

@ -15,7 +15,6 @@ from gui.usefulwidget import (
statusbutton, statusbutton,
getQMessageBox, getQMessageBox,
auto_select_webview, auto_select_webview,
FocusCombo,
getboxlayout, getboxlayout,
getspinbox, getspinbox,
getsimplecombobox, getsimplecombobox,
@ -291,36 +290,7 @@ class AnkiWindow(QWidget):
layout.addRow( layout.addRow(
"端口号", getspinbox(0, 65536, globalconfig["ankiconnect"], "port") "端口号", getspinbox(0, 65536, globalconfig["ankiconnect"], "port")
) )
combox = getsimplecombobox( layout.addRow("DeckName", getlineedit(globalconfig["ankiconnect"], "DeckName"))
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( layout.addRow(
"ModelName", getlineedit(globalconfig["ankiconnect"], "ModelName5") "ModelName", getlineedit(globalconfig["ankiconnect"], "ModelName5")
) )
@ -624,16 +594,29 @@ class AnkiWindow(QWidget):
def addanki(self): 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"] autoUpdateModel = globalconfig["ankiconnect"]["autoUpdateModel"]
allowDuplicate = globalconfig["ankiconnect"]["allowDuplicate"] allowDuplicate = globalconfig["ankiconnect"]["allowDuplicate"]
anki.global_port = globalconfig["ankiconnect"]["port"] anki.global_port = globalconfig["ankiconnect"]["port"]
ModelName = globalconfig["ankiconnect"]["ModelName5"] ModelName = globalconfig["ankiconnect"]["ModelName5"]
try: DeckName = __internal__DeckName()
DeckName = globalconfig["ankiconnect"]["DeckNameS"][
globalconfig["ankiconnect"]["DeckName_i"]
]
except:
DeckName = "lunadeck"
model_htmlfront, model_htmlback, model_css = self.tryloadankitemplates() model_htmlfront, model_htmlback, model_css = self.tryloadankitemplates()
tags = globalconfig["ankiconnect"]["tags"] tags = globalconfig["ankiconnect"]["tags"]
anki.Deck.create(DeckName) anki.Deck.create(DeckName)

View File

@ -131,6 +131,7 @@ def getdefaultsavehook(title=None):
# "private_srclang_2": 0,# 显示时再加载缺省用global中的键 # "private_srclang_2": 0,# 显示时再加载缺省用global中的键
# "private_tgtlang_2": 0, # "private_tgtlang_2": 0,
"follow_default_ankisettings": True, "follow_default_ankisettings": True,
# "anki_DeckName":str
# "localeswitcher": 0,废弃 # "localeswitcher": 0,废弃
"onloadautochangemode2": 0, "onloadautochangemode2": 0,
"needinserthookcode": [], "needinserthookcode": [],
@ -467,22 +468,6 @@ for key in globalconfig["toolbutton"]["rank2"]:
for key in ___: for key in ___:
globalconfig["toolbutton"]["rank2"].remove(key) 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"]: for group in ["webview", "textbrowser"]:

View File

@ -472,10 +472,7 @@
"jiamingcolor": "black", "jiamingcolor": "black",
"ankiconnect": { "ankiconnect": {
"port": 8765, "port": 8765,
"DeckName_i": 0, "DeckName": "lunadeck",
"DeckNameS": [
"lunadeck"
],
"ModelName5": "lunamodel5", "ModelName5": "lunamodel5",
"allowDuplicate": true, "allowDuplicate": true,
"autoUpdateModel": true, "autoUpdateModel": true,

View File

@ -29,7 +29,7 @@ include(generate_product_version)
set(VERSION_MAJOR 5) set(VERSION_MAJOR 5)
set(VERSION_MINOR 25) set(VERSION_MINOR 25)
set(VERSION_PATCH 1) set(VERSION_PATCH 0)
add_library(pch pch.cpp) add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h) target_precompile_headers(pch PUBLIC pch.h)