From c25443a0a5ca1cd0a7ecf9d6ccdd9b8706211aa9 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: Wed, 5 Jun 2024 13:19:03 +0800 Subject: [PATCH] ed --- .../LunaTranslator/LunaTranslator.py | 2 +- LunaTranslator/LunaTranslator/gui/edittext.py | 5 ++ .../LunaTranslator/gui/translatorUI.py | 58 +++++++++---------- .../translator/basetranslator.py | 4 +- .../translator/realtime_edit.py | 3 +- 5 files changed, 38 insertions(+), 34 deletions(-) diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index cedf2ef0..9a55a17d 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -376,7 +376,7 @@ class MAINUI: 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终止,3为起始 + if iter_res_status in (0, 2): # 0为普通,1为iter,2为iter终止 try: self.textsource.sqlqueueput((contentraw, classname, res)) except: diff --git a/LunaTranslator/LunaTranslator/gui/edittext.py b/LunaTranslator/LunaTranslator/gui/edittext.py index 4a20ee6d..381f8852 100644 --- a/LunaTranslator/LunaTranslator/gui/edittext.py +++ b/LunaTranslator/LunaTranslator/gui/edittext.py @@ -173,8 +173,13 @@ class edittrans(QMainWindow): color=globalconfig["fanyi"]["realtime_edit"]["color"], res=text, onlytrans=False, + iter_context=(1, "realtime_edit_directvis_fakeclass"), ) gobject.baseobject.translation_ui.displayres.emit(displayreskwargs) + displayreskwargs.update( + dict(iter_context=(2, "realtime_edit_directvis_fakeclass")) + ) # 显示到历史翻译 + gobject.baseobject.translation_ui.displayres.emit(displayreskwargs) self.textOutput.clear() except: pass diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 12b6bdb6..2cb9b4fd 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -162,6 +162,7 @@ class QUnFrameWindow(resizableframeless): if clear: self.translate_text.clear() + self.saveiterclasspointer.clear() if text is None: return text = self.cleartext(text) @@ -177,41 +178,40 @@ class QUnFrameWindow(resizableframeless): self.translate_text.setAlignment(Qt.AlignmentFlag.AlignLeft) if iter_context: - iter_res_status, iter_context_class = iter_context - if iter_res_status == 3: + _, iter_context_class = iter_context + + if iter_context_class not in self.saveiterclasspointer: self.translate_text.append(" ", hira, origin) self.saveiterclasspointer[iter_context_class] = { "currtext": "", "curr": self.translate_text.getcurrpointer(), "start": self.translate_text.getcurrpointer(), } - else: - currbefore = self.saveiterclasspointer[iter_context_class]["curr"] - currlen = len(self.saveiterclasspointer[iter_context_class]["currtext"]) - if len(text) < currlen: - self.translate_text.deletebetween( - self.saveiterclasspointer[iter_context_class]["start"] - + len(text), - self.saveiterclasspointer[iter_context_class]["curr"], - ) - else: - newtext = text[currlen:] - self.translate_text.insertatpointer( - self.saveiterclasspointer[iter_context_class]["start"] - + currlen, - newtext, - ) - self.saveiterclasspointer[iter_context_class]["currtext"] = text - currcurrent = self.translate_text.getcurrpointer() - self.saveiterclasspointer[iter_context_class]["curr"] = currcurrent - currchange = currcurrent - currbefore - for klass in self.saveiterclasspointer: - if klass == iter_context_class: - continue - if self.saveiterclasspointer[klass]["curr"] > currbefore: - self.saveiterclasspointer[klass]["curr"] += currchange - self.saveiterclasspointer[klass]["start"] += currchange + currbefore = self.saveiterclasspointer[iter_context_class]["curr"] + currlen = len(self.saveiterclasspointer[iter_context_class]["currtext"]) + if len(text) < currlen: + self.translate_text.deletebetween( + self.saveiterclasspointer[iter_context_class]["start"] + len(text), + self.saveiterclasspointer[iter_context_class]["curr"], + ) + else: + newtext = text[currlen:] + self.translate_text.insertatpointer( + self.saveiterclasspointer[iter_context_class]["start"] + currlen, + newtext, + ) + + self.saveiterclasspointer[iter_context_class]["currtext"] = text + currcurrent = self.translate_text.getcurrpointer() + self.saveiterclasspointer[iter_context_class]["curr"] = currcurrent + currchange = currcurrent - currbefore + for klass in self.saveiterclasspointer: + if klass == iter_context_class: + continue + if self.saveiterclasspointer[klass]["curr"] > currbefore: + self.saveiterclasspointer[klass]["curr"] += currchange + self.saveiterclasspointer[klass]["start"] += currchange self.translate_text.showyinyingtext2( color, @@ -604,7 +604,7 @@ class QUnFrameWindow(resizableframeless): self.displayraw1.connect(self.showraw) self.refreshtooliconsignal.connect(self.refreshtoolicon) self.showsavegame_signal.connect( - lambda: dialog_savedgame_new(gobject.baseobject.settin_ui) + lambda: dialog_savedgame_integrated(gobject.baseobject.settin_ui) ) self.clickRange_signal.connect(self.clickRange) self.showhide_signal.connect(self.showhideocrrange) diff --git a/LunaTranslator/LunaTranslator/translator/basetranslator.py b/LunaTranslator/LunaTranslator/translator/basetranslator.py index f7f6fede..9fa300e4 100644 --- a/LunaTranslator/LunaTranslator/translator/basetranslator.py +++ b/LunaTranslator/LunaTranslator/translator/basetranslator.py @@ -274,9 +274,7 @@ class basetrans(commonbase): def _iterget(self, __callback, rid, __res): succ = True - for i, _res in enumerate(__res): - if i == 0: - __callback("", 3) + for _res in __res: if self.requestid != rid: succ = False break diff --git a/LunaTranslator/LunaTranslator/translator/realtime_edit.py b/LunaTranslator/LunaTranslator/translator/realtime_edit.py index fba19b7c..ad309ff7 100644 --- a/LunaTranslator/LunaTranslator/translator/realtime_edit.py +++ b/LunaTranslator/LunaTranslator/translator/realtime_edit.py @@ -10,10 +10,11 @@ class TS(basetrans): except: return None - (ret,) = sql.execute( + ret = sql.execute( "SELECT machineTrans FROM artificialtrans WHERE source = ?", (content,) ).fetchone() if ret is None: return None + (ret,) = ret ret = json.loads(ret) return ret.get("realtime_edit", None)