From 7a775c24105a802954274b8b57b35ed658f7ab25 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: Sat, 4 May 2024 17:15:37 +0800 Subject: [PATCH] fix --- .../LunaTranslator/gui/textbrowser.py | 29 +++++++------------ .../LunaTranslator/gui/translatorUI.py | 6 +--- .../LunaTranslator/translator/sakura.py | 4 +-- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/textbrowser.py b/LunaTranslator/LunaTranslator/gui/textbrowser.py index e083003a..452f1dc7 100644 --- a/LunaTranslator/LunaTranslator/gui/textbrowser.py +++ b/LunaTranslator/LunaTranslator/gui/textbrowser.py @@ -199,10 +199,6 @@ class Textbrowser: self.textbrowser.resize(int(_1), int(_2)) self.textbrowserback.resize(int(_1), int(_2)) - def clear(self): - self.clear() - self.blockcount = 0 - def setnextfont(self, origin): self.textbrowser.moveCursor(QTextCursor.End) self.textbrowserback.moveCursor(QTextCursor.End) @@ -230,25 +226,21 @@ class Textbrowser: else: self.align = False - def showhide(self): - self.textbrowserback.setVisible(globalconfig["zitiyangshi"] != 3) - self.textbrowser.setVisible(globalconfig["zitiyangshi"] != 3) - QApplication.processEvents() + def append(self, x, tag, color): - def append(self, x, tag, origin): if self.cleared: _space = "" self.blockcount = 0 - self.b1 = 0 + b1 = 0 else: _space = "\n" - self.b1 = self.textbrowser.document().blockCount() + b1 = self.textbrowser.document().blockCount() self.cleared = False if self.needdouble: self.textbrowserback.insertPlainText(_space + x) self.textbrowser.insertPlainText(_space + x) - self.b2 = self.textbrowser.document().blockCount() + b2 = self.textbrowser.document().blockCount() if True: # self.addtaged: if self.addtaged: @@ -273,6 +265,9 @@ class Textbrowser: self.movep(0, self.savey) + if globalconfig["zitiyangshi"] == 3: + self.showyinyingtext(color, b1, b2) + def getcurrpointer(self): return self.textcursor.position() @@ -366,17 +361,13 @@ class Textbrowser: if label.pos().y() > maxh: label.move(label.pos().x(), label.pos().y() + maxnewh - maxh) - def showyinyingtext(self, color): - + def showyinyingtext(self, color, b1, b2): linei = self.yinyingposline doc = self.textbrowser.document() block = doc.findBlockByNumber(0) - start = self.b1 - end = self.b2 - - for blocki in range(start, end): + for blocki in range(b1, b2): block = doc.findBlockByNumber(blocki) layout = block.layout() blockstart = block.position() @@ -390,7 +381,7 @@ class Textbrowser: self.textcursor.setPosition(blockstart + s) self.textbrowser.setTextCursor(self.textcursor) tl1 = self.textbrowser.cursorRect(self.textcursor).topLeft() - # print(tl1) + print(tl1) if (lc + linei) > len(self.yinyinglabels): _newlabels = [ QLabel(self.toplabel2) diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index d58816b6..92f8dfc2 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -258,7 +258,6 @@ class QUnFrameWindow(resizableframeless): self.saveiterclasspointer[klass]["curr"] += currchange self.saveiterclasspointer[klass]["start"] += currchange - self.translate_text.showhide() if globalconfig["zitiyangshi"] == 3: self.translate_text.showyinyingtext2( color, @@ -269,11 +268,8 @@ class QUnFrameWindow(resizableframeless): else: self.translate_text.append( - text, hira if globalconfig["isshowhira"] else [], origin + text, hira if globalconfig["isshowhira"] else [], color ) - self.translate_text.showhide() - if globalconfig["zitiyangshi"] == 3: - self.translate_text.showyinyingtext(color) if hira: diff --git a/LunaTranslator/LunaTranslator/translator/sakura.py b/LunaTranslator/LunaTranslator/translator/sakura.py index 6f020f39..bdcaa95e 100644 --- a/LunaTranslator/LunaTranslator/translator/sakura.py +++ b/LunaTranslator/LunaTranslator/translator/sakura.py @@ -13,7 +13,6 @@ class TS(basetrans): def __init__(self, typename): super().__init__(typename) self.timeout = 30 - self.api_url = "" self.history = {"ja": [], "zh": []} self.session = requests.Session() @@ -161,8 +160,7 @@ class TS(basetrans): def translate(self, query): self.checkempty(["API接口地址"]) self.timeout = self.config["API超时(秒)"] - if self.api_url == "": - self.get_client(self.config["API接口地址"]) + self.get_client(self.config["API接口地址"]) frequency_penalty = float(self.config["frequency_penalty"]) if not bool( self.config["利用上文信息翻译(通常会有一定的效果提升,但会导致变慢)"]