From 07d1255b281aa331d9a1f7a1d8bffa342333e220 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: Thu, 15 Aug 2024 23:21:04 +0800 Subject: [PATCH] autoloadocrrange --- .../LunaTranslator/LunaTranslator.py | 8 +++----- .../gui/setting_textinput_ocr.py | 4 ---- .../LunaTranslator/gui/translatorUI.py | 18 +++++++----------- .../LunaTranslator/textsource/copyboard.py | 1 - .../LunaTranslator/textsource/ocrtext.py | 12 ++++++------ .../LunaTranslator/textsource/texthook.py | 3 +-- .../textsource/textsourcebase.py | 7 +++++-- .../translator/basetranslator.py | 9 +++------ LunaTranslator/files/defaultconfig/config.json | 1 - LunaTranslator/files/lang/ar.json | 1 - LunaTranslator/files/lang/cht.json | 1 - LunaTranslator/files/lang/cs.json | 1 - LunaTranslator/files/lang/de.json | 1 - LunaTranslator/files/lang/en.json | 1 - LunaTranslator/files/lang/es.json | 1 - LunaTranslator/files/lang/fr.json | 1 - LunaTranslator/files/lang/it.json | 1 - LunaTranslator/files/lang/ja.json | 1 - LunaTranslator/files/lang/ko.json | 1 - LunaTranslator/files/lang/nl.json | 1 - LunaTranslator/files/lang/pl.json | 1 - LunaTranslator/files/lang/pt.json | 1 - LunaTranslator/files/lang/ru.json | 1 - LunaTranslator/files/lang/sv.json | 1 - LunaTranslator/files/lang/th.json | 1 - LunaTranslator/files/lang/tr.json | 1 - LunaTranslator/files/lang/uk.json | 1 - LunaTranslator/files/lang/vi.json | 1 - LunaTranslator/files/lang/zh.json | 1 - docs/zh/alltoolbuttons.md | 3 ++- 30 files changed, 27 insertions(+), 59 deletions(-) diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index 6603b716..50cb0cd7 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -147,7 +147,7 @@ class MAINUI: def textsource(self, _): if _ is None and self.textsource_p: try: - self.textsource_p.end() + self.textsource_p.endX() except: print_exc() self.hwnd = None @@ -240,7 +240,6 @@ class MAINUI: safe_embedcallback = embedcallback if embedcallback else lambda _: 1 safe_embedcallback_none = functools.partial(safe_embedcallback, "") - if text.startswith(""): self.translation_ui.displayres.emit( dict( @@ -418,8 +417,8 @@ class MAINUI: color=globalconfig["fanyi"][engine]["color"], res="", onlytrans=onlytrans, + iter_context=(1, engine), ) - displayreskwargs.update(iter_context=(1, engine)) self.translation_ui.displayres.emit(displayreskwargs) def create_translate_task( @@ -520,9 +519,8 @@ class MAINUI: color=globalconfig["fanyi"][classname]["color"], res=res, onlytrans=onlytrans, + iter_context=(iter_res_status, classname), ) - if iter_res_status: - displayreskwargs.update(iter_context=(iter_res_status, classname)) self.translation_ui.displayres.emit(displayreskwargs) if iter_res_status in (0, 2): # 0为普通,1为iter,2为iter终止 diff --git a/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py b/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py index 433b9348..f37291bb 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py +++ b/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py @@ -267,10 +267,6 @@ def getocrgrid(self): "多重区域模式", D_getsimpleswitch(globalconfig, "multiregion"), ], - [ - "记忆选定区域", - D_getsimpleswitch(globalconfig, "rememberocrregions"), - ], [ "范围框颜色", D_getcolorbutton( diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index adf71af9..9be0048e 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -2,7 +2,7 @@ from qtsymbols import * import time, functools, threading, os, importlib, shutil, uuid from traceback import print_exc import windows, qtawesome, gobject, winsharedutils -from myutils.wrapper import threader, trypass +from myutils.wrapper import threader, trypass, tryprint from myutils.config import ( globalconfig, saveallconfig, @@ -308,16 +308,13 @@ class TranslatorWindow(resizableframeless): color = kwargs.get("color") res = kwargs.get("res") onlytrans = kwargs.get("onlytrans") # 仅翻译,不显示 - iter_context = kwargs.get("iter_context", None) + iter_context = kwargs.get("iter_context", (0, None)) clear = kwargs.get("clear", False) - if iter_context: - iter_res_status, iter_context_class = iter_context - if iter_res_status == 2: # iter结束 - gobject.baseobject.transhis.getnewtranssignal.emit(name, res) - return - else: + iter_res_status, iter_context_class = iter_context + if iter_res_status == 2: # iter结束 gobject.baseobject.transhis.getnewtranssignal.emit(name, res) + return if onlytrans: return @@ -1246,6 +1243,7 @@ class TranslatorWindow(resizableframeless): rangeselct_function(self.afterrange, auto, auto) + @tryprint def afterrange(self, rect): gobject.baseobject.textsource.newrangeadjustor() gobject.baseobject.textsource.setrect(rect) @@ -1360,9 +1358,7 @@ class TranslatorWindow(resizableframeless): gobject.baseobject.isrunning = False self.hide() - if gobject.baseobject.textsource: - - gobject.baseobject.textsource = None + gobject.baseobject.textsource = None endsubprocs() gobject.baseobject.destroytray() handle = windows.CreateMutex(False, "LUNASAVECONFIGUPDATE") diff --git a/LunaTranslator/LunaTranslator/textsource/copyboard.py b/LunaTranslator/LunaTranslator/textsource/copyboard.py index 10f1946a..e9251a25 100644 --- a/LunaTranslator/LunaTranslator/textsource/copyboard.py +++ b/LunaTranslator/LunaTranslator/textsource/copyboard.py @@ -7,7 +7,6 @@ class copyboard(basetext): def end(self): winsharedutils.clipboard_callback_stop(self.__hwnd) - super().end() def __callback(self, string, ismy): if globalconfig["excule_from_self"] and ismy: diff --git a/LunaTranslator/LunaTranslator/textsource/ocrtext.py b/LunaTranslator/LunaTranslator/textsource/ocrtext.py index 1a8ba6c6..abe59d50 100644 --- a/LunaTranslator/LunaTranslator/textsource/ocrtext.py +++ b/LunaTranslator/LunaTranslator/textsource/ocrtext.py @@ -37,11 +37,6 @@ class ocrtext(basetext): self.range_ui = [] self.timestamp = time.time() super(ocrtext, self).__init__("0", "ocr") - if globalconfig["rememberocrregions"]: - for region in globalconfig["ocrregions"]: - if region: - self.newrangeadjustor() - self.setrect(region) def newrangeadjustor(self): if len(self.range_ui) == 0 or globalconfig["multiregion"]: @@ -85,6 +80,12 @@ class ocrtext(basetext): [_.setstyle() for _ in self.range_ui] def showhiderangeui(self, b): + if b and len(self.range_ui) == 0: + for region in globalconfig["ocrregions"]: + if region: + self.newrangeadjustor() + self.setrect(region) + return for _ in self.range_ui: if b: _r = _.getrect() @@ -195,4 +196,3 @@ class ocrtext(basetext): def end(self): globalconfig["ocrregions"] = [_.getrect() for _ in self.range_ui] [_.closesignal.emit() for _ in self.range_ui] - super().end() diff --git a/LunaTranslator/LunaTranslator/textsource/texthook.py b/LunaTranslator/LunaTranslator/textsource/texthook.py index 90d53c8c..fe0b501e 100644 --- a/LunaTranslator/LunaTranslator/textsource/texthook.py +++ b/LunaTranslator/LunaTranslator/textsource/texthook.py @@ -229,7 +229,7 @@ class texthook(basetext): def procdisc(self, pid): self.connectedpids.remove(pid) - if len(self.connectedpids) == 0: + if len(self.connectedpids) == 0 and not self.ending: gobject.baseobject.textsource = None def prepares(self): @@ -564,4 +564,3 @@ class texthook(basetext): for pid in self.connectedpids: self.Luna_Detach(pid) time.sleep(0.1) - super().end() diff --git a/LunaTranslator/LunaTranslator/textsource/textsourcebase.py b/LunaTranslator/LunaTranslator/textsource/textsourcebase.py index 96762abf..8aa2f325 100644 --- a/LunaTranslator/LunaTranslator/textsource/textsourcebase.py +++ b/LunaTranslator/LunaTranslator/textsource/textsourcebase.py @@ -54,10 +54,13 @@ class basetext: def gettextonce(self): return None - def end(self): - self.ending = True + def end(self): ... ################## + def endX(self): + self.ending = True + self.end() + def sqlqueueput(self, xx): try: self.sqlqueue.put(xx) diff --git a/LunaTranslator/LunaTranslator/translator/basetranslator.py b/LunaTranslator/LunaTranslator/translator/basetranslator.py index 51d50317..4087d8b9 100644 --- a/LunaTranslator/LunaTranslator/translator/basetranslator.py +++ b/LunaTranslator/LunaTranslator/translator/basetranslator.py @@ -302,14 +302,14 @@ class basetrans(commonbase): else: collectiterres += _res callback(collectiterres, 1) - callback("", 2) + callback(collectiterres, 2) res = collectiterres else: if globalconfig["fix_translate_rank"]: # 这个性能会稍微差一点,不然其实可以全都这样的。 callback(res, 1) - callback("", 2) + callback(res, 2) else: callback(res, 0) @@ -391,7 +391,4 @@ class basetrans(commonbase): msg = stringfyerror(e) self.needreinit = True msg = "" + msg - if embedcallback: - callback(contentraw, 0) - else: - callback(msg, 0) + callback(msg, 0) diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 244a53be..de0850e6 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -433,7 +433,6 @@ "removeuseless": false, "currvislistuid": null, "multiregion": false, - "rememberocrregions": false, "ocrregions": [], "ocr_stable_sim": 0, "ocr_diff_sim": 0.95, diff --git a/LunaTranslator/files/lang/ar.json b/LunaTranslator/files/lang/ar.json index a7c9096b..8b4ae8e9 100644 --- a/LunaTranslator/files/lang/ar.json +++ b/LunaTranslator/files/lang/ar.json @@ -547,7 +547,6 @@ "外部缩放软件": "برامج التكبير الخارجي", "保持非重复字符": "الحفاظ على الطابع غير المتكرر", "多重区域模式": "وضع منطقة متعددة", - "记忆选定区域": "اختيار الذاكرة", "关闭": "غلق", "命令行启动": "بدء تشغيل سطر الأوامر", "文本相似度阈值": "نص التشابه العتبة", diff --git a/LunaTranslator/files/lang/cht.json b/LunaTranslator/files/lang/cht.json index 11c8dd06..610dea2d 100644 --- a/LunaTranslator/files/lang/cht.json +++ b/LunaTranslator/files/lang/cht.json @@ -547,7 +547,6 @@ "外部缩放软件": "外部縮放軟體", "保持非重复字符": "保持非重複字元", "多重区域模式": "多重區域模式", - "记忆选定区域": "記憶選定區域", "关闭": "關閉", "命令行启动": "命令列啟動", "文本相似度阈值": "文字相似度閾值", diff --git a/LunaTranslator/files/lang/cs.json b/LunaTranslator/files/lang/cs.json index 10b9c7b6..c4501043 100644 --- a/LunaTranslator/files/lang/cs.json +++ b/LunaTranslator/files/lang/cs.json @@ -554,7 +554,6 @@ "外部缩放软件": "Externí software pro škálování", "保持非重复字符": "Zachovat neopakující se znaky", "多重区域模式": "Víceregionální režim", - "记忆选定区域": "Oblast výběru paměti", "关闭": "zavřít", "命令行启动": "Spuštění příkazového řádku", "文本相似度阈值": "Práh podobnosti textu", diff --git a/LunaTranslator/files/lang/de.json b/LunaTranslator/files/lang/de.json index 9100871b..01e527b0 100644 --- a/LunaTranslator/files/lang/de.json +++ b/LunaTranslator/files/lang/de.json @@ -554,7 +554,6 @@ "外部缩放软件": "Externe Skalierungssoftware", "保持非重复字符": "Nicht wiederkehrende Zeichen beibehalten", "多重区域模式": "Multiregionaler Modus", - "记忆选定区域": "Speicherauswahlbereich", "关闭": "schließen", "命令行启动": "Start der Befehlszeile", "文本相似度阈值": "Schwellenwert für Textähnlichkeit", diff --git a/LunaTranslator/files/lang/en.json b/LunaTranslator/files/lang/en.json index 7d6c2921..1373b5a0 100644 --- a/LunaTranslator/files/lang/en.json +++ b/LunaTranslator/files/lang/en.json @@ -546,7 +546,6 @@ "外部缩放软件": "External Scaling Software", "保持非重复字符": "Keep Unduplicated Characters", "多重区域模式": "Multi-Region Mode", - "记忆选定区域": "Remember Selected Region", "关闭": "Close", "命令行启动": "Command Line Startup", "文本相似度阈值": "Text Similarity Threshold", diff --git a/LunaTranslator/files/lang/es.json b/LunaTranslator/files/lang/es.json index 98011078..ad2d9ec3 100644 --- a/LunaTranslator/files/lang/es.json +++ b/LunaTranslator/files/lang/es.json @@ -547,7 +547,6 @@ "外部缩放软件": "Software de zoom externo", "保持非重复字符": "Mantener caracteres no repetitivos", "多重区域模式": "Modelo multiregional", - "记忆选定区域": "Área seleccionada de memoria", "关闭": "Cierre", "命令行启动": "Se inicia la línea de órdenes", "文本相似度阈值": "Umbral de similitud de texto", diff --git a/LunaTranslator/files/lang/fr.json b/LunaTranslator/files/lang/fr.json index de443dc0..7d083398 100644 --- a/LunaTranslator/files/lang/fr.json +++ b/LunaTranslator/files/lang/fr.json @@ -547,7 +547,6 @@ "外部缩放软件": "Logiciel de zoom externe", "保持非重复字符": "Garder les caractères non répétitifs", "多重区域模式": "Mode Multi - zones", - "记忆选定区域": "Mémoriser la zone sélectionnée", "关闭": "Fermé", "命令行启动": "Démarrage de la ligne de commande", "文本相似度阈值": "Seuil de similarité du texte", diff --git a/LunaTranslator/files/lang/it.json b/LunaTranslator/files/lang/it.json index 354e8e41..088192d2 100644 --- a/LunaTranslator/files/lang/it.json +++ b/LunaTranslator/files/lang/it.json @@ -547,7 +547,6 @@ "外部缩放软件": "Software di ridimensionamento esterno", "保持非重复字符": "Mantieni caratteri non ripetuti", "多重区域模式": "Modalità multi regione", - "记忆选定区域": "Area di selezione della memoria", "关闭": "chiudi", "命令行启动": "Avvio della riga di comando", "文本相似度阈值": "Soglia di somiglianza del testo", diff --git a/LunaTranslator/files/lang/ja.json b/LunaTranslator/files/lang/ja.json index 8ce0d738..bfb680f5 100644 --- a/LunaTranslator/files/lang/ja.json +++ b/LunaTranslator/files/lang/ja.json @@ -547,7 +547,6 @@ "外部缩放软件": "外部ズームソフトウェア", "保持非重复字符": "非反復文字の維持", "多重区域模式": "複数領域モード", - "记忆选定区域": "メモリ選択領域", "关闭": "閉じる", "命令行启动": "コマンドライン起動", "文本相似度阈值": "テキスト類似度しきい値", diff --git a/LunaTranslator/files/lang/ko.json b/LunaTranslator/files/lang/ko.json index daef2660..15ca9a6e 100644 --- a/LunaTranslator/files/lang/ko.json +++ b/LunaTranslator/files/lang/ko.json @@ -547,7 +547,6 @@ "外部缩放软件": "외부 확대 / 축소 소프트웨어", "保持非重复字符": "비반복 문자 유지", "多重区域模式": "다중 영역 모드", - "记忆选定区域": "선택한 영역 기억하기", "关闭": "닫기", "命令行启动": "명령줄 시작", "文本相似度阈值": "텍스트 유사도 임계값", diff --git a/LunaTranslator/files/lang/nl.json b/LunaTranslator/files/lang/nl.json index 2e975c4d..2b9e138b 100644 --- a/LunaTranslator/files/lang/nl.json +++ b/LunaTranslator/files/lang/nl.json @@ -554,7 +554,6 @@ "外部缩放软件": "Externe schaalsoftware", "保持非重复字符": "Niet-herhalende tekens behouden", "多重区域模式": "Multiregionale modus", - "记忆选定区域": "Geheugen selectiegebied", "关闭": "sluiten", "命令行启动": "Opstarten van de opdrachtregel", "文本相似度阈值": "Drempel voor tekstgelijkenis", diff --git a/LunaTranslator/files/lang/pl.json b/LunaTranslator/files/lang/pl.json index 2baba3a0..50fcb977 100644 --- a/LunaTranslator/files/lang/pl.json +++ b/LunaTranslator/files/lang/pl.json @@ -547,7 +547,6 @@ "外部缩放软件": "Oprogramowanie do skalowania zewnętrznego", "保持非重复字符": "Zachowaj niepowtarzające się znaki", "多重区域模式": "Tryb wielu regionów", - "记忆选定区域": "Obszar wyboru pamięci", "关闭": "zamknij", "命令行启动": "Uruchamianie wiersza poleceń", "文本相似度阈值": "Próg podobieństwa tekstu", diff --git a/LunaTranslator/files/lang/pt.json b/LunaTranslator/files/lang/pt.json index bd4d957c..197accd6 100644 --- a/LunaTranslator/files/lang/pt.json +++ b/LunaTranslator/files/lang/pt.json @@ -554,7 +554,6 @@ "外部缩放软件": "Software de dimensionamento externo", "保持非重复字符": "Manter caracteres não repetitivos", "多重区域模式": "Modo multiregional", - "记忆选定区域": "Área de selecção da memória", "关闭": "fechar", "命令行启动": "Arranque da linha de comandos", "文本相似度阈值": "Limiar de similaridade do texto", diff --git a/LunaTranslator/files/lang/ru.json b/LunaTranslator/files/lang/ru.json index 2131f5da..f4b2a8bc 100644 --- a/LunaTranslator/files/lang/ru.json +++ b/LunaTranslator/files/lang/ru.json @@ -547,7 +547,6 @@ "外部缩放软件": "Программное обеспечение для внешнего масштабирования", "保持非重复字符": "Сохранить символ без повторения", "多重区域模式": "Многорегиональная модель", - "记忆选定区域": "Запоминание выбранной области", "关闭": "Закрыть", "命令行启动": "Запуск командной строки", "文本相似度阈值": "Порог сходства текста", diff --git a/LunaTranslator/files/lang/sv.json b/LunaTranslator/files/lang/sv.json index c49f9e68..cd9e5aa7 100644 --- a/LunaTranslator/files/lang/sv.json +++ b/LunaTranslator/files/lang/sv.json @@ -554,7 +554,6 @@ "外部缩放软件": "Extern skalningsprogram", "保持非重复字符": "Behåll tecken som inte upprepas", "多重区域模式": "Flerregionalt sätt", - "记忆选定区域": "Minnesvalsområde", "关闭": "stäng", "命令行启动": "Kommandoradsstart", "文本相似度阈值": "Tröskelvärde för textlikhet", diff --git a/LunaTranslator/files/lang/th.json b/LunaTranslator/files/lang/th.json index 0f8ead33..84e0e6a1 100644 --- a/LunaTranslator/files/lang/th.json +++ b/LunaTranslator/files/lang/th.json @@ -547,7 +547,6 @@ "外部缩放软件": "ซอฟต์แวร์ซูมภายนอก", "保持非重复字符": "เก็บอักขระที่ไม่ซ้ำกัน", "多重区域模式": "โหมดหลายโซน", - "记忆选定区域": "หน่วยความจำพื้นที่ที่เลือก", "关闭": "ปิด", "命令行启动": "เริ่มบรรทัดคำสั่ง", "文本相似度阈值": "เกณฑ์ความคล้ายคลึงกันของข้อความ", diff --git a/LunaTranslator/files/lang/tr.json b/LunaTranslator/files/lang/tr.json index aef7b2a1..147ea62c 100644 --- a/LunaTranslator/files/lang/tr.json +++ b/LunaTranslator/files/lang/tr.json @@ -547,7 +547,6 @@ "外部缩放软件": "Dışarı skalama yazılımı", "保持非重复字符": "Tekrarlamayan karakterleri tut", "多重区域模式": "Çok bölge modu", - "记忆选定区域": "Hafıza seçim alanı", "关闭": "kapat", "命令行启动": "Komut satırı başlatma", "文本相似度阈值": "Metin benzerliği eşiği", diff --git a/LunaTranslator/files/lang/uk.json b/LunaTranslator/files/lang/uk.json index 778893c4..c65a8cf5 100644 --- a/LunaTranslator/files/lang/uk.json +++ b/LunaTranslator/files/lang/uk.json @@ -547,7 +547,6 @@ "外部缩放软件": "Зовнішнє програмне забезпечення масштабу", "保持非重复字符": "Зберегти символи, які не повторюються", "多重区域模式": "Режим декількох регіонів", - "记忆选定区域": "Область вибору пам' яті", "关闭": "закрити", "命令行启动": "Запуск командного рядка", "文本相似度阈值": "Праг подібності до тексту", diff --git a/LunaTranslator/files/lang/vi.json b/LunaTranslator/files/lang/vi.json index 0b0cdbeb..156772c6 100644 --- a/LunaTranslator/files/lang/vi.json +++ b/LunaTranslator/files/lang/vi.json @@ -547,7 +547,6 @@ "外部缩放软件": "Phần mềm Zoom ngoài", "保持非重复字符": "Giữ các ký tự không trùng lặp", "多重区域模式": "Chế độ đa vùng", - "记忆选定区域": "Ghi nhớ vùng chọn", "关闭": "Đóng cửa", "命令行启动": "Chạy dòng lệnh", "文本相似度阈值": "Ngưỡng tương tự văn bản", diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index e2028083..45e285c8 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -555,7 +555,6 @@ "外部缩放软件": "", "保持非重复字符": "", "多重区域模式": "", - "记忆选定区域": "", "关闭": "", "命令行启动": "", "文本相似度阈值": "", diff --git a/docs/zh/alltoolbuttons.md b/docs/zh/alltoolbuttons.md index a9c5d065..5f3a9d6a 100644 --- a/docs/zh/alltoolbuttons.md +++ b/docs/zh/alltoolbuttons.md @@ -66,7 +66,8 @@ 该按钮每次都需要进行翻译选择,不会进行记忆。 1. #### 显示/隐藏范围框 **该按钮仅在OCR模式下可用**
- 略 + 当未选择任何OCR范围时,使用该按钮显示OCR范围,会自动设置OCR范围为上一次选择的OCR。 + 1. #### 专有名词翻译_直接替换 1. #### 专有名词翻译_sakura_gpt_词典 1. #### 专有名词翻译_占位符_全局