This commit is contained in:
恍兮惚兮 2024-05-04 17:15:37 +08:00
parent 1930b9895d
commit 7a775c2410
3 changed files with 12 additions and 27 deletions

View File

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

View File

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

View File

@ -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["利用上文信息翻译(通常会有一定的效果提升,但会导致变慢)"]