diff --git a/py/LunaTranslator/gui/pretransfile.py b/py/LunaTranslator/gui/pretransfile.py index 91c3b481..c1fcfe79 100644 --- a/py/LunaTranslator/gui/pretransfile.py +++ b/py/LunaTranslator/gui/pretransfile.py @@ -2,7 +2,7 @@ from qtsymbols import * import sqlite3, os, json, functools from traceback import print_exc from myutils.config import globalconfig, _TR -from myutils.utils import autosql, dynamicapiname +from myutils.utils import autosql, getannotatedapiname from gui.usefulwidget import getQMessageBox, SuperCombo from gui.dynalang import LFormLayout, LPushButton, LDialog from textsource.texthook import splitembedlines @@ -50,7 +50,7 @@ def sqlite2json2( dialog.setLayout(formLayout) combo = SuperCombo() - combo.addItems([dynamicapiname(_) for _ in _collect], _collect) + combo.addItems([getannotatedapiname(_) for _ in _collect], _collect) formLayout.addRow("首选翻译", combo) e = QLineEdit(sqlitefile[: -(len(".sqlite"))]) diff --git a/py/LunaTranslator/gui/setting_cishu.py b/py/LunaTranslator/gui/setting_cishu.py index 04c04686..b4774847 100644 --- a/py/LunaTranslator/gui/setting_cishu.py +++ b/py/LunaTranslator/gui/setting_cishu.py @@ -1,7 +1,7 @@ import functools, os import gobject from myutils.utils import splitocrtypes -from myutils.config import globalconfig +from myutils.config import globalconfig, _TR from gui.inputdialog import autoinitdialog, autoinitdialog_items from gui.usefulwidget import ( yuitsu_switch, @@ -109,7 +109,7 @@ def vistranslate_rank(self): "显示顺序", globalconfig["cishuvisrank"], isrankeditor=True, - namemapfunction=lambda k: globalconfig["cishu"][k]["name"], + namemapfunction=lambda k: _TR(globalconfig["cishu"][k]["name"]), ) diff --git a/py/LunaTranslator/gui/setting_display_text.py b/py/LunaTranslator/gui/setting_display_text.py index 156b1bcd..97f10752 100644 --- a/py/LunaTranslator/gui/setting_display_text.py +++ b/py/LunaTranslator/gui/setting_display_text.py @@ -1,10 +1,10 @@ from qtsymbols import * import functools, platform import gobject, os, zipfile -from myutils.config import globalconfig, static_data +from myutils.config import globalconfig, static_data, _TR from gui.inputdialog import multicolorset, autoinitdialog from myutils.wrapper import tryprint -from myutils.utils import dynamiclink, translate_exits, copytree, dynamicapiname +from myutils.utils import dynamiclink, translate_exits, copytree, getannotatedapiname from gui.usefulwidget import ( D_getsimplecombobox, getsimplecombobox, @@ -332,7 +332,7 @@ def vistranslate_rank(self): ("显示顺序"), globalconfig["fix_translate_rank_rank"], isrankeditor=True, - namemapfunction=lambda k: dynamicapiname(k), + namemapfunction=lambda k: _TR(getannotatedapiname(k)) ) diff --git a/py/LunaTranslator/gui/setting_textinput.py b/py/LunaTranslator/gui/setting_textinput.py index ea87a7e0..5190393f 100644 --- a/py/LunaTranslator/gui/setting_textinput.py +++ b/py/LunaTranslator/gui/setting_textinput.py @@ -1,7 +1,7 @@ from qtsymbols import * import functools, os, json import windows, gobject -from myutils.utils import translate_exits, dynamicapiname +from myutils.utils import translate_exits, getannotatedapiname, sortAwithB from myutils.config import ( globalconfig, _TR, @@ -274,22 +274,10 @@ def loadvalidtss(): continue if not translate_exits(x): continue - tp = globalconfig["fanyi"][x].get("type", "free") - alltransvis.append( - dynamicapiname(x) - + "_(" - + { - "free": "在线翻译", - "api": "注册在线翻译", - "dev": "调试浏览器", - "pre": "预翻译", - "offline": "离线翻译", - }.get(tp, "unknown type") - + ")" - ) + alltransvis.append(getannotatedapiname(x)) alltrans.append(x) - sorted_pairs = sorted(zip(alltransvis, alltrans)) - return [x[1] for x in sorted_pairs], [x[0] for x in sorted_pairs] + sortAwithB(alltransvis, alltrans) + return alltrans, alltransvis def gethookembedgrid(self): diff --git a/py/LunaTranslator/gui/setting_textinput_ocr.py b/py/LunaTranslator/gui/setting_textinput_ocr.py index 6c88cea0..fb1ef3fb 100644 --- a/py/LunaTranslator/gui/setting_textinput_ocr.py +++ b/py/LunaTranslator/gui/setting_textinput_ocr.py @@ -61,7 +61,10 @@ class triggereditor(LDialog): self.hctable.removeselectedrows() def moverank(self, dy): - src, tgt = self.hctable.moverank(dy) + _pair = self.hctable.moverank(dy) + if not _pair: + return + src, tgt = _pair self.internalrealname.insert(tgt, self.internalrealname.pop(src)) def __init__(self, parent) -> None: diff --git a/py/LunaTranslator/gui/usefulwidget.py b/py/LunaTranslator/gui/usefulwidget.py index ca0e852f..c053a8dd 100644 --- a/py/LunaTranslator/gui/usefulwidget.py +++ b/py/LunaTranslator/gui/usefulwidget.py @@ -34,6 +34,7 @@ class FocusCombo(QComboBox): else: return super().wheelEvent(e) + class SuperCombo(FocusCombo): Visoriginrole = Qt.ItemDataRole.UserRole + 1 Internalrole = Visoriginrole + 1 @@ -1877,7 +1878,10 @@ class listediter(LDialog): self.moverank(1) def moverank(self, dy): - src, tgt = self.hctable.moverank(dy) + _pair = self.hctable.moverank(dy) + if not _pair: + return + src, tgt = _pair self.internalrealname.insert(tgt, self.internalrealname.pop(src)) def __init__( diff --git a/py/LunaTranslator/myutils/utils.py b/py/LunaTranslator/myutils/utils.py index 905dd098..b0f506da 100644 --- a/py/LunaTranslator/myutils/utils.py +++ b/py/LunaTranslator/myutils/utils.py @@ -836,7 +836,9 @@ class audiocapture: self.data = None self.cb1 = CFUNCTYPE(None, c_void_p, c_size_t)(self.__datacollect) self.cb2 = CFUNCTYPE(None, c_void_p)(self.__mutexcb) - threading.Thread(target=winsharedutils.StartCaptureAsync, args=(self.cb1, self.cb2)).start() + threading.Thread( + target=winsharedutils.StartCaptureAsync, args=(self.cb1, self.cb2) + ).start() class loopbackrecorder: @@ -1034,6 +1036,27 @@ def dynamicapiname(apiuid): ) +def getannotatedapiname(x): + tp = globalconfig["fanyi"][x].get("type", "free") + return ( + dynamicapiname(x) + + "_(" + + { + "free": "在线翻译", + "api": "注册在线翻译", + "dev": "调试浏览器", + "pre": "预翻译", + "offline": "离线翻译", + }.get(tp, "unknown type") + + ")" + ) + + +def sortAwithB(l1, l2): + sorted_pairs = sorted(zip(l1, l2)) + return [x[0] for x in sorted_pairs], [x[1] for x in sorted_pairs] + + def inrange(n, s, e): return n >= s and n <= e