mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2025-01-01 18:14:13 +08:00
anki
This commit is contained in:
parent
afa4744b14
commit
fb6d115473
@ -761,7 +761,6 @@ 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],
|
||||||
@ -1116,23 +1115,6 @@ 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):
|
||||||
|
@ -6,7 +6,7 @@ import qtawesome, requests, gobject, windows
|
|||||||
import myutils.ankiconnect as anki
|
import myutils.ankiconnect as anki
|
||||||
from myutils.hwnd import grabwindow
|
from myutils.hwnd import grabwindow
|
||||||
from myutils.config import globalconfig, _TR, static_data, savehook_new_data
|
from myutils.config import globalconfig, _TR, static_data, savehook_new_data
|
||||||
from myutils.utils import loopbackrecorder
|
from myutils.utils import loopbackrecorder, parsekeystringtomodvkcode
|
||||||
from myutils.wrapper import threader, tryprint
|
from myutils.wrapper import threader, tryprint
|
||||||
from myutils.ocrutil import imageCut, ocr_run_2
|
from myutils.ocrutil import imageCut, ocr_run_2
|
||||||
from gui.rangeselect import rangeselct_function
|
from gui.rangeselect import rangeselct_function
|
||||||
@ -15,6 +15,7 @@ from gui.usefulwidget import (
|
|||||||
statusbutton,
|
statusbutton,
|
||||||
getQMessageBox,
|
getQMessageBox,
|
||||||
auto_select_webview,
|
auto_select_webview,
|
||||||
|
FocusCombo,
|
||||||
getboxlayout,
|
getboxlayout,
|
||||||
getspinbox,
|
getspinbox,
|
||||||
getsimplecombobox,
|
getsimplecombobox,
|
||||||
@ -290,7 +291,36 @@ class AnkiWindow(QWidget):
|
|||||||
layout.addRow(
|
layout.addRow(
|
||||||
"端口号", getspinbox(0, 65536, globalconfig["ankiconnect"], "port")
|
"端口号", getspinbox(0, 65536, globalconfig["ankiconnect"], "port")
|
||||||
)
|
)
|
||||||
layout.addRow("DeckName", getlineedit(globalconfig["ankiconnect"], "DeckName"))
|
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(
|
layout.addRow(
|
||||||
"ModelName", getlineedit(globalconfig["ankiconnect"], "ModelName5")
|
"ModelName", getlineedit(globalconfig["ankiconnect"], "ModelName5")
|
||||||
)
|
)
|
||||||
@ -345,9 +375,50 @@ class AnkiWindow(QWidget):
|
|||||||
namemapfunction=lambda k: globalconfig["cishu"][k]["name"],
|
namemapfunction=lambda k: globalconfig["cishu"][k]["name"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@threader
|
||||||
|
def simulate_key(self, i):
|
||||||
|
def __internal__keystring(i):
|
||||||
|
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
|
||||||
|
if not savehook_new_data[gameuid][f"anki_simulate_key_{i}_use"]:
|
||||||
|
return None
|
||||||
|
return savehook_new_data[gameuid][
|
||||||
|
f"anki_simulate_key_{i}_keystring"
|
||||||
|
]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return globalconfig["ankiconnect"]["simulate_key"][i]["keystring"]
|
||||||
|
|
||||||
|
keystring = __internal__keystring(i)
|
||||||
|
if not keystring:
|
||||||
|
return
|
||||||
|
windows.SetForegroundWindow(gobject.baseobject.textsource.hwnd)
|
||||||
|
time.sleep(0.1)
|
||||||
|
try:
|
||||||
|
modes, vkcode = parsekeystringtomodvkcode(keystring, modes=True)
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
for mode in modes:
|
||||||
|
windows.keybd_event(mode, 0, 0, 0)
|
||||||
|
windows.keybd_event(vkcode, 0, 0, 0)
|
||||||
|
time.sleep(0.1)
|
||||||
|
windows.keybd_event(vkcode, 0, windows.KEYEVENTF_KEYUP, 0)
|
||||||
|
for mode in modes:
|
||||||
|
windows.keybd_event(mode, 0, windows.KEYEVENTF_KEYUP, 0)
|
||||||
|
|
||||||
def startorendrecord(self, target: QLineEdit, idx):
|
def startorendrecord(self, target: QLineEdit, idx):
|
||||||
if idx == 1:
|
if idx == 1:
|
||||||
self.recorder = loopbackrecorder()
|
self.recorder = loopbackrecorder()
|
||||||
|
self.simulate_key(idx)
|
||||||
else:
|
else:
|
||||||
self.recorder.end(callback=target.setText)
|
self.recorder.end(callback=target.setText)
|
||||||
|
|
||||||
@ -553,29 +624,16 @@ 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"]
|
||||||
DeckName = __internal__DeckName()
|
try:
|
||||||
|
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)
|
||||||
|
@ -131,7 +131,6 @@ 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": [],
|
||||||
@ -468,6 +467,22 @@ 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"]:
|
||||||
|
|
||||||
|
@ -472,7 +472,10 @@
|
|||||||
"jiamingcolor": "black",
|
"jiamingcolor": "black",
|
||||||
"ankiconnect": {
|
"ankiconnect": {
|
||||||
"port": 8765,
|
"port": 8765,
|
||||||
"DeckName": "lunadeck",
|
"DeckName_i": 0,
|
||||||
|
"DeckNameS": [
|
||||||
|
"lunadeck"
|
||||||
|
],
|
||||||
"ModelName5": "lunamodel5",
|
"ModelName5": "lunamodel5",
|
||||||
"allowDuplicate": true,
|
"allowDuplicate": true,
|
||||||
"autoUpdateModel": true,
|
"autoUpdateModel": true,
|
||||||
|
@ -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 0)
|
set(VERSION_PATCH 1)
|
||||||
|
|
||||||
add_library(pch pch.cpp)
|
add_library(pch pch.cpp)
|
||||||
target_precompile_headers(pch PUBLIC pch.h)
|
target_precompile_headers(pch PUBLIC pch.h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user