This commit is contained in:
恍兮惚兮 2024-06-05 13:19:03 +08:00
parent 790408d1c4
commit c25443a0a5
5 changed files with 38 additions and 34 deletions

View File

@ -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为iter2为iter终止3为起始
if iter_res_status in (0, 2): # 0为普通1为iter2为iter终止
try:
self.textsource.sqlqueueput((contentraw, classname, res))
except:

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)