mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
perf
This commit is contained in:
parent
6e431ec5a3
commit
ee473c30a0
@ -821,7 +821,6 @@ class hookselect(closeashidewindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if gobject.baseobject.textsource:
|
if gobject.baseobject.textsource:
|
||||||
print(hookcode)
|
|
||||||
gobject.baseobject.textsource.inserthook(hookcode)
|
gobject.baseobject.textsource.inserthook(hookcode)
|
||||||
self.tabwidget.setCurrentIndex(1)
|
self.tabwidget.setCurrentIndex(1)
|
||||||
else:
|
else:
|
||||||
@ -897,7 +896,6 @@ class hookselect(closeashidewindow):
|
|||||||
if select:
|
if select:
|
||||||
gobject.baseobject.textsource.selectedhook.append(key)
|
gobject.baseobject.textsource.selectedhook.append(key)
|
||||||
|
|
||||||
print(key)
|
|
||||||
if key[-2][:8] == "UserHook":
|
if key[-2][:8] == "UserHook":
|
||||||
needinserthookcode = savehook_new_data[
|
needinserthookcode = savehook_new_data[
|
||||||
gobject.baseobject.textsource.pname
|
gobject.baseobject.textsource.pname
|
||||||
|
@ -76,21 +76,22 @@ class QGraphicsDropShadowEffect_multi(QGraphicsDropShadowEffect):
|
|||||||
super().draw(painter)
|
super().draw(painter)
|
||||||
|
|
||||||
|
|
||||||
class PlainLabel(QLabel):
|
class BorderedLabel(QLabel):
|
||||||
def __init__(self, parent=None):
|
|
||||||
super().__init__(parent)
|
|
||||||
self.setTextFormat(Qt.PlainText)
|
|
||||||
|
|
||||||
def move(self, point: QPoint):
|
def move(self, point: QPoint):
|
||||||
text = self.text()
|
text = self.text()
|
||||||
isarabic = any((ord(char) >= 0x0600 and ord(char) <= 0x06E0) for char in text)
|
isarabic = any((ord(char) >= 0x0600 and ord(char) <= 0x06E0) for char in text)
|
||||||
if isarabic:
|
if isarabic:
|
||||||
point.setX(point.x() - self.width())
|
point.setX(point.x() - self.width())
|
||||||
|
|
||||||
|
point.setX(int(point.x() - self.m_fontOutLineWidth))
|
||||||
|
point.setY(int(point.y() - self.m_fontOutLineWidth))
|
||||||
super().move(point)
|
super().move(point)
|
||||||
|
|
||||||
|
def clearShadow(self):
|
||||||
|
self.setGraphicsEffect(None)
|
||||||
|
|
||||||
|
def setShadow(self, colorshadow, width=1, deepth=1, trace=False):
|
||||||
|
|
||||||
class ShadowLabel(PlainLabel):
|
|
||||||
def setShadow(self, colorshadow, width, deepth, trace=False):
|
|
||||||
shadow2 = QGraphicsDropShadowEffect_multi(deepth)
|
shadow2 = QGraphicsDropShadowEffect_multi(deepth)
|
||||||
if trace:
|
if trace:
|
||||||
shadow2.setBlurRadius(width)
|
shadow2.setBlurRadius(width)
|
||||||
@ -101,9 +102,6 @@ class ShadowLabel(PlainLabel):
|
|||||||
shadow2.setColor(QColor(colorshadow))
|
shadow2.setColor(QColor(colorshadow))
|
||||||
self.setGraphicsEffect(shadow2)
|
self.setGraphicsEffect(shadow2)
|
||||||
|
|
||||||
|
|
||||||
class BorderedLabel(ShadowLabel):
|
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.m_outLineColor = QColor()
|
self.m_outLineColor = QColor()
|
||||||
@ -120,17 +118,14 @@ class BorderedLabel(ShadowLabel):
|
|||||||
self._m_text = text
|
self._m_text = text
|
||||||
|
|
||||||
def setColorWidth(self, outLineColor, contentColor, width, _type=0):
|
def setColorWidth(self, outLineColor, contentColor, width, _type=0):
|
||||||
|
|
||||||
self.m_outLineColor = QColor(outLineColor)
|
self.m_outLineColor = QColor(outLineColor)
|
||||||
self.m_contentColor = QColor(contentColor)
|
self.m_contentColor = QColor(contentColor)
|
||||||
self.m_fontOutLineWidth = width
|
self.m_fontOutLineWidth = width
|
||||||
self._type = _type
|
self._type = _type
|
||||||
|
|
||||||
def move(self, point: QPoint):
|
|
||||||
point.setX(int(point.x() - self.m_fontOutLineWidth))
|
|
||||||
point.setY(int(point.y() - self.m_fontOutLineWidth))
|
|
||||||
super().move(point)
|
|
||||||
|
|
||||||
def adjustSize(self):
|
def adjustSize(self):
|
||||||
|
self._pix = None
|
||||||
font = self.font()
|
font = self.font()
|
||||||
text = self.text()
|
text = self.text()
|
||||||
font_m = QFontMetrics(font)
|
font_m = QFontMetrics(font)
|
||||||
@ -139,6 +134,30 @@ class BorderedLabel(ShadowLabel):
|
|||||||
int(font_m.height() + 2 * self.m_fontOutLineWidth),
|
int(font_m.height() + 2 * self.m_fontOutLineWidth),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def labelresetcolor(self, color, rate=1):
|
||||||
|
c1 = color
|
||||||
|
c2 = globalconfig["miaobiancolor"]
|
||||||
|
if globalconfig["zitiyangshi2"] == 2:
|
||||||
|
self.setColorWidth(c1, c2, rate * globalconfig["miaobianwidth2"])
|
||||||
|
self.clearShadow()
|
||||||
|
elif globalconfig["zitiyangshi2"] == 3:
|
||||||
|
self.setColorWidth(c2, c1, rate * globalconfig["miaobianwidth2"])
|
||||||
|
self.clearShadow()
|
||||||
|
elif globalconfig["zitiyangshi2"] == 1:
|
||||||
|
self.setColorWidth(c1, c2, rate * globalconfig["miaobianwidth"], 1)
|
||||||
|
self.clearShadow()
|
||||||
|
elif globalconfig["zitiyangshi2"] == 4:
|
||||||
|
self.setColorWidth(c2, c1, rate * globalconfig["miaobianwidth2"])
|
||||||
|
self.setShadow(c2, rate * globalconfig["traceoffset"], 1, True)
|
||||||
|
elif globalconfig["zitiyangshi2"] == 0:
|
||||||
|
self.setColorWidth(None, c1, 0, 2)
|
||||||
|
self.clearShadow()
|
||||||
|
elif globalconfig["zitiyangshi2"] == 5:
|
||||||
|
self.setColorWidth(None, c2, 0, 2)
|
||||||
|
self.setShadow(
|
||||||
|
c1, rate * globalconfig["fontsize"], globalconfig["shadowforce"]
|
||||||
|
)
|
||||||
|
|
||||||
def paintEvent(self, event):
|
def paintEvent(self, event):
|
||||||
if not self._pix:
|
if not self._pix:
|
||||||
rate = self.devicePixelRatioF()
|
rate = self.devicePixelRatioF()
|
||||||
@ -150,7 +169,18 @@ class BorderedLabel(ShadowLabel):
|
|||||||
font_m = QFontMetrics(font)
|
font_m = QFontMetrics(font)
|
||||||
painter = QPainter(self._pix)
|
painter = QPainter(self._pix)
|
||||||
|
|
||||||
|
painter.setRenderHint(QPainter.Antialiasing)
|
||||||
path = QPainterPath()
|
path = QPainterPath()
|
||||||
|
if self._type == 2:
|
||||||
|
|
||||||
|
path.addText(
|
||||||
|
0,
|
||||||
|
font_m.ascent(),
|
||||||
|
font,
|
||||||
|
text,
|
||||||
|
)
|
||||||
|
painter.fillPath(path, QBrush(self.m_contentColor))
|
||||||
|
else:
|
||||||
path.addText(
|
path.addText(
|
||||||
self.m_fontOutLineWidth,
|
self.m_fontOutLineWidth,
|
||||||
self.m_fontOutLineWidth + font_m.ascent(),
|
self.m_fontOutLineWidth + font_m.ascent(),
|
||||||
@ -166,14 +196,12 @@ class BorderedLabel(ShadowLabel):
|
|||||||
Qt.RoundJoin,
|
Qt.RoundJoin,
|
||||||
)
|
)
|
||||||
|
|
||||||
painter.setRenderHint(QPainter.Antialiasing)
|
|
||||||
if self._type == 0:
|
if self._type == 0:
|
||||||
painter.strokePath(path, pen)
|
painter.strokePath(path, pen)
|
||||||
painter.fillPath(path, QBrush(self.m_contentColor))
|
painter.fillPath(path, QBrush(self.m_contentColor))
|
||||||
elif self._type == 1:
|
elif self._type == 1:
|
||||||
painter.fillPath(path, QBrush(self.m_contentColor))
|
painter.fillPath(path, QBrush(self.m_contentColor))
|
||||||
painter.strokePath(path, pen)
|
painter.strokePath(path, pen)
|
||||||
|
|
||||||
painter = QPainter(self)
|
painter = QPainter(self)
|
||||||
painter.drawPixmap(0, 0, self._pix)
|
painter.drawPixmap(0, 0, self._pix)
|
||||||
|
|
||||||
@ -235,6 +263,7 @@ class Textbrowser(QLabel):
|
|||||||
self.backcolorlabels = []
|
self.backcolorlabels = []
|
||||||
|
|
||||||
self.yinyinglabels = []
|
self.yinyinglabels = []
|
||||||
|
self.yinyinglabels_idx = 0
|
||||||
|
|
||||||
self.yinyingpos = 0
|
self.yinyingpos = 0
|
||||||
self.yinyingposline = 0
|
self.yinyingposline = 0
|
||||||
@ -308,10 +337,10 @@ class Textbrowser(QLabel):
|
|||||||
|
|
||||||
def showyinyingtext2(self, color, iter_context_class, pos, text):
|
def showyinyingtext2(self, color, iter_context_class, pos, text):
|
||||||
if iter_context_class not in self.iteryinyinglabelsave:
|
if iter_context_class not in self.iteryinyinglabelsave:
|
||||||
self.iteryinyinglabelsave[iter_context_class] = []
|
self.iteryinyinglabelsave[iter_context_class] = [[], 0]
|
||||||
maxh = 0
|
maxh = 0
|
||||||
maxh2 = 9999999
|
maxh2 = 9999999
|
||||||
for label in self.iteryinyinglabelsave[iter_context_class]:
|
for label in self.iteryinyinglabelsave[iter_context_class][0]:
|
||||||
maxh2 = min(label.pos().y(), maxh2)
|
maxh2 = min(label.pos().y(), maxh2)
|
||||||
if label.isVisible() == False:
|
if label.isVisible() == False:
|
||||||
continue
|
continue
|
||||||
@ -334,14 +363,23 @@ class Textbrowser(QLabel):
|
|||||||
|
|
||||||
maxnewh = 0
|
maxnewh = 0
|
||||||
for i in range(len(subtext)):
|
for i in range(len(subtext)):
|
||||||
|
if self.iteryinyinglabelsave[iter_context_class][1] >= len(
|
||||||
|
self.iteryinyinglabelsave[iter_context_class][0]
|
||||||
|
):
|
||||||
|
self.iteryinyinglabelsave[iter_context_class][0].append(
|
||||||
|
BorderedLabel(self.toplabel2)
|
||||||
|
)
|
||||||
maxnewh = max(maxnewh, subpos[i].y())
|
maxnewh = max(maxnewh, subpos[i].y())
|
||||||
_ = self.guesscreatelabel(self.toplabel2, color)
|
_ = self.iteryinyinglabelsave[iter_context_class][0][
|
||||||
|
self.iteryinyinglabelsave[iter_context_class][1]
|
||||||
|
]
|
||||||
|
_.labelresetcolor(color)
|
||||||
_.setText(subtext[i])
|
_.setText(subtext[i])
|
||||||
_.setFont(self.font)
|
_.setFont(self.font)
|
||||||
_.adjustSize()
|
_.adjustSize()
|
||||||
_.move(subpos[i])
|
_.move(subpos[i])
|
||||||
_.show()
|
_.show()
|
||||||
self.iteryinyinglabelsave[iter_context_class].append(_)
|
self.iteryinyinglabelsave[iter_context_class][1] += 1
|
||||||
if maxh:
|
if maxh:
|
||||||
if maxnewh == 0:
|
if maxnewh == 0:
|
||||||
maxnewh = maxh2
|
maxnewh = maxh2
|
||||||
@ -353,7 +391,7 @@ class Textbrowser(QLabel):
|
|||||||
for klass in self.iteryinyinglabelsave:
|
for klass in self.iteryinyinglabelsave:
|
||||||
if klass == iter_context_class:
|
if klass == iter_context_class:
|
||||||
continue
|
continue
|
||||||
for label in self.iteryinyinglabelsave[klass]:
|
for label in self.iteryinyinglabelsave[klass][0]:
|
||||||
if label.isVisible() == False:
|
if label.isVisible() == False:
|
||||||
continue
|
continue
|
||||||
if label.pos().y() > maxh:
|
if label.pos().y() > maxh:
|
||||||
@ -379,13 +417,16 @@ class Textbrowser(QLabel):
|
|||||||
self.textbrowser.setTextCursor(self.textcursor)
|
self.textbrowser.setTextCursor(self.textcursor)
|
||||||
tl1 = self.textbrowser.cursorRect(self.textcursor).topLeft()
|
tl1 = self.textbrowser.cursorRect(self.textcursor).topLeft()
|
||||||
|
|
||||||
_ = self.guesscreatelabel(self.toplabel2, color)
|
if self.yinyinglabels_idx >= len(self.yinyinglabels):
|
||||||
|
self.yinyinglabels.append(BorderedLabel(self.toplabel2))
|
||||||
|
_ = self.yinyinglabels[self.yinyinglabels_idx]
|
||||||
|
self.yinyinglabels_idx += 1
|
||||||
|
_.labelresetcolor(color)
|
||||||
_.setText(block.text()[s : s + l])
|
_.setText(block.text()[s : s + l])
|
||||||
_.setFont(self.font)
|
_.setFont(self.font)
|
||||||
_.adjustSize()
|
_.adjustSize()
|
||||||
_.move(tl1)
|
_.move(tl1)
|
||||||
_.show()
|
_.show()
|
||||||
self.yinyinglabels.append(_)
|
|
||||||
linei += 1
|
linei += 1
|
||||||
self.yinyingposline = linei
|
self.yinyingposline = linei
|
||||||
|
|
||||||
@ -575,6 +616,7 @@ class Textbrowser(QLabel):
|
|||||||
self.textbrowser.setTextCursor(self.textcursor)
|
self.textbrowser.setTextCursor(self.textcursor)
|
||||||
x = self.nearmerge(x, pos, fonthira, fontorig)
|
x = self.nearmerge(x, pos, fonthira, fontorig)
|
||||||
self.settextposcursor(pos)
|
self.settextposcursor(pos)
|
||||||
|
savetaglabels_idx = 0
|
||||||
for word in x:
|
for word in x:
|
||||||
l = len(word["orig"])
|
l = len(word["orig"])
|
||||||
|
|
||||||
@ -589,9 +631,12 @@ class Textbrowser(QLabel):
|
|||||||
# print(tl1,tl2,word['hira'],self.textbrowser.textCursor().position())
|
# print(tl1,tl2,word['hira'],self.textbrowser.textCursor().position())
|
||||||
if word["orig"] == " ":
|
if word["orig"] == " ":
|
||||||
continue
|
continue
|
||||||
self.savetaglabels.append(
|
if savetaglabels_idx >= len(self.savetaglabels):
|
||||||
self.solvejiaminglabel(word, fonthira, tl1, tl2, fascent)
|
self.savetaglabels.append(BorderedLabel(self.atback2))
|
||||||
|
self.solvejiaminglabel(
|
||||||
|
self.savetaglabels[savetaglabels_idx], word, fonthira, tl1, tl2, fascent
|
||||||
)
|
)
|
||||||
|
savetaglabels_idx += 1
|
||||||
|
|
||||||
def settextposcursor(self, pos):
|
def settextposcursor(self, pos):
|
||||||
self.textcursor.setPosition(pos)
|
self.textcursor.setPosition(pos)
|
||||||
@ -663,39 +708,8 @@ class Textbrowser(QLabel):
|
|||||||
self.settextposcursor(startpos)
|
self.settextposcursor(startpos)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def guesscreatelabel(self, p, color, rate=1):
|
def solvejiaminglabel(self, _: BorderedLabel, word, font, tl1, tl2, fh):
|
||||||
c1 = color
|
_.labelresetcolor(globalconfig["jiamingcolor"], rate=globalconfig["kanarate"])
|
||||||
c2 = globalconfig["miaobiancolor"]
|
|
||||||
if globalconfig["zitiyangshi2"] == 2:
|
|
||||||
label = BorderedLabel(p)
|
|
||||||
label.setColorWidth(c1, c2, rate * globalconfig["miaobianwidth2"])
|
|
||||||
|
|
||||||
elif globalconfig["zitiyangshi2"] == 3:
|
|
||||||
label = BorderedLabel(p)
|
|
||||||
label.setColorWidth(c2, c1, rate * globalconfig["miaobianwidth2"])
|
|
||||||
elif globalconfig["zitiyangshi2"] == 1:
|
|
||||||
|
|
||||||
label = BorderedLabel(p)
|
|
||||||
label.setColorWidth(c1, c2, rate * globalconfig["miaobianwidth"], 1)
|
|
||||||
elif globalconfig["zitiyangshi2"] == 4:
|
|
||||||
label = BorderedLabel(p)
|
|
||||||
label.setColorWidth(c2, c1, rate * globalconfig["miaobianwidth2"])
|
|
||||||
label.setShadow(c2, rate * globalconfig["traceoffset"], 1, True)
|
|
||||||
elif globalconfig["zitiyangshi2"] == 0:
|
|
||||||
label = PlainLabel(p)
|
|
||||||
label.setStyleSheet("color:{}; background-color:(0,0,0,0)".format(c1))
|
|
||||||
elif globalconfig["zitiyangshi2"] == 5:
|
|
||||||
label = ShadowLabel(p)
|
|
||||||
label.setStyleSheet("color:{}; background-color:(0,0,0,0)".format(c2))
|
|
||||||
label.setShadow(
|
|
||||||
c1, rate * globalconfig["fontsize"], globalconfig["shadowforce"]
|
|
||||||
)
|
|
||||||
return label
|
|
||||||
|
|
||||||
def solvejiaminglabel(self, word, font, tl1, tl2, fh):
|
|
||||||
_ = self.guesscreatelabel(
|
|
||||||
self.atback2, globalconfig["jiamingcolor"], rate=globalconfig["kanarate"]
|
|
||||||
)
|
|
||||||
_.setText(word["hira"])
|
_.setText(word["hira"])
|
||||||
_.setFont(font)
|
_.setFont(font)
|
||||||
_.adjustSize()
|
_.adjustSize()
|
||||||
@ -725,22 +739,16 @@ class Textbrowser(QLabel):
|
|||||||
for label in self.searchmasklabels_clicked:
|
for label in self.searchmasklabels_clicked:
|
||||||
label.hide()
|
label.hide()
|
||||||
for label in self.savetaglabels:
|
for label in self.savetaglabels:
|
||||||
label.deleteLater()
|
label.hide()
|
||||||
del label
|
|
||||||
self.savetaglabels.clear()
|
self.yinyinglabels_idx = 0
|
||||||
for label in self.yinyinglabels:
|
for label in self.yinyinglabels:
|
||||||
label.deleteLater()
|
label.hide()
|
||||||
del label
|
|
||||||
self.yinyinglabels.clear()
|
|
||||||
for klass, labels in self.iteryinyinglabelsave.items():
|
for klass, labels in self.iteryinyinglabelsave.items():
|
||||||
for label in labels:
|
for label in labels[0]:
|
||||||
label.deleteLater()
|
label.hide()
|
||||||
del label
|
labels[1] = 0
|
||||||
self.iteryinyinglabelsave.clear()
|
|
||||||
self.yinyingpos = 0
|
self.yinyingpos = 0
|
||||||
self.yinyingposline = 0
|
self.yinyingposline = 0
|
||||||
self.cleared = True
|
self.cleared = True
|
||||||
self.textbrowser.setText("")
|
self.textbrowser.clear()
|
||||||
|
|
||||||
# self.shadowlabel.setText('')
|
|
||||||
# self.shadowlabel.savetext=''
|
|
||||||
|
@ -5,19 +5,12 @@ from network.requests_common import *
|
|||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
|
|
||||||
|
|
||||||
class autostatus:
|
|
||||||
def __init__(self, ref) -> None:
|
|
||||||
self.ref = ref
|
|
||||||
ref._status = 1
|
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
self.ref._status = 0
|
|
||||||
|
|
||||||
|
|
||||||
class Response(ResponseBase):
|
class Response(ResponseBase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.last_error = 0
|
self.last_error = 0
|
||||||
|
self.keeprefs = []
|
||||||
|
self.queue = queue.Queue()
|
||||||
|
|
||||||
def iter_content_impl(self, chunk_size=1):
|
def iter_content_impl(self, chunk_size=1):
|
||||||
|
|
||||||
@ -62,15 +55,6 @@ def ExceptionFilter(func):
|
|||||||
|
|
||||||
class Session(Sessionbase):
|
class Session(Sessionbase):
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
super().__init__()
|
|
||||||
self._status = 0
|
|
||||||
self.curl = AutoCURLHandle(curl_easy_init())
|
|
||||||
curl_easy_setopt(self.curl, CURLoption.CURLOPT_COOKIEJAR, "")
|
|
||||||
curl_easy_setopt(
|
|
||||||
self.curl, CURLoption.CURLOPT_USERAGENT, self.UA.encode("utf8")
|
|
||||||
)
|
|
||||||
|
|
||||||
def raise_for_status(self):
|
def raise_for_status(self):
|
||||||
if self.last_error:
|
if self.last_error:
|
||||||
raise CURLException(self.last_error)
|
raise CURLException(self.last_error)
|
||||||
@ -120,18 +104,14 @@ class Session(Sessionbase):
|
|||||||
verify,
|
verify,
|
||||||
timeout,
|
timeout,
|
||||||
):
|
):
|
||||||
|
curl = AutoCURLHandle(curl_easy_init())
|
||||||
if self._status == 0:
|
curl_easy_setopt(curl, CURLoption.CURLOPT_COOKIEJAR, "")
|
||||||
curl = self.curl
|
curl_easy_setopt(curl, CURLoption.CURLOPT_USERAGENT, self.UA.encode("utf8"))
|
||||||
__ = autostatus(self)
|
|
||||||
else:
|
|
||||||
# 不能多线程同时复用同一个curl对象
|
|
||||||
curl = AutoCURLHandle(curl_easy_duphandle(self.curl))
|
|
||||||
if cookies:
|
if cookies:
|
||||||
cookies.update(self.cookies)
|
cookies.update(self.cookies)
|
||||||
else:
|
else:
|
||||||
cookies = self.cookies
|
cookies = self.cookies
|
||||||
curl_easy_reset(curl)
|
|
||||||
if cookies:
|
if cookies:
|
||||||
cookie = self._parsecookie(cookies)
|
cookie = self._parsecookie(cookies)
|
||||||
curl_easy_setopt(curl, CURLoption.CURLOPT_COOKIE, cookie.encode("utf8"))
|
curl_easy_setopt(curl, CURLoption.CURLOPT_COOKIE, cookie.encode("utf8"))
|
||||||
@ -171,7 +151,7 @@ class Session(Sessionbase):
|
|||||||
curl_easy_setopt(curl, CURLoption.CURLOPT_POSTFIELDSIZE, datalen)
|
curl_easy_setopt(curl, CURLoption.CURLOPT_POSTFIELDSIZE, datalen)
|
||||||
|
|
||||||
resp = Response()
|
resp = Response()
|
||||||
|
resp.keeprefs.append(curl)
|
||||||
if stream:
|
if stream:
|
||||||
|
|
||||||
def WriteMemoryCallback(queue, contents, size, nmemb, userp):
|
def WriteMemoryCallback(queue, contents, size, nmemb, userp):
|
||||||
@ -181,25 +161,23 @@ class Session(Sessionbase):
|
|||||||
|
|
||||||
_content = []
|
_content = []
|
||||||
_headers = []
|
_headers = []
|
||||||
resp.queue = queue.Queue()
|
|
||||||
headerqueue = queue.Queue()
|
headerqueue = queue.Queue()
|
||||||
resp.keepref1 = WRITEFUNCTION(
|
keepref1 = WRITEFUNCTION(functools.partial(WriteMemoryCallback, resp.queue))
|
||||||
functools.partial(WriteMemoryCallback, resp.queue)
|
keepref2 = WRITEFUNCTION(
|
||||||
)
|
|
||||||
resp.keepref2 = WRITEFUNCTION(
|
|
||||||
functools.partial(WriteMemoryCallback, headerqueue)
|
functools.partial(WriteMemoryCallback, headerqueue)
|
||||||
)
|
)
|
||||||
curl_easy_setopt(
|
curl_easy_setopt(
|
||||||
curl,
|
curl,
|
||||||
CURLoption.CURLOPT_WRITEFUNCTION,
|
CURLoption.CURLOPT_WRITEFUNCTION,
|
||||||
cast(resp.keepref1, c_void_p).value,
|
cast(keepref1, c_void_p).value,
|
||||||
)
|
)
|
||||||
|
|
||||||
curl_easy_setopt(
|
curl_easy_setopt(
|
||||||
curl,
|
curl,
|
||||||
CURLoption.CURLOPT_HEADERFUNCTION,
|
CURLoption.CURLOPT_HEADERFUNCTION,
|
||||||
cast(resp.keepref2, c_void_p).value,
|
cast(keepref2, c_void_p).value,
|
||||||
)
|
)
|
||||||
|
resp.keeprefs += [keepref1, keepref2]
|
||||||
|
|
||||||
def ___perform():
|
def ___perform():
|
||||||
error = False
|
error = False
|
||||||
@ -250,24 +228,20 @@ class Session(Sessionbase):
|
|||||||
|
|
||||||
_content = []
|
_content = []
|
||||||
_headers = []
|
_headers = []
|
||||||
resp.keepref1 = WRITEFUNCTION(
|
keepref1 = WRITEFUNCTION(functools.partial(WriteMemoryCallback, _content))
|
||||||
functools.partial(WriteMemoryCallback, _content)
|
keepref2 = WRITEFUNCTION(functools.partial(WriteMemoryCallback, _headers))
|
||||||
)
|
|
||||||
resp.keepref2 = WRITEFUNCTION(
|
|
||||||
functools.partial(WriteMemoryCallback, _headers)
|
|
||||||
)
|
|
||||||
|
|
||||||
curl_easy_setopt(
|
curl_easy_setopt(
|
||||||
curl,
|
curl,
|
||||||
CURLoption.CURLOPT_WRITEFUNCTION,
|
CURLoption.CURLOPT_WRITEFUNCTION,
|
||||||
cast(resp.keepref1, c_void_p).value,
|
cast(keepref1, c_void_p).value,
|
||||||
)
|
)
|
||||||
curl_easy_setopt(
|
curl_easy_setopt(
|
||||||
curl,
|
curl,
|
||||||
CURLoption.CURLOPT_HEADERFUNCTION,
|
CURLoption.CURLOPT_HEADERFUNCTION,
|
||||||
cast(resp.keepref2, c_void_p).value,
|
cast(keepref2, c_void_p).value,
|
||||||
)
|
)
|
||||||
|
resp.keeprefs += [keepref1, keepref2]
|
||||||
self._perform(curl)
|
self._perform(curl)
|
||||||
resp.content = b"".join(_content)
|
resp.content = b"".join(_content)
|
||||||
resp.headers = self._update_header_cookie(b"".join(_headers).decode("utf8"))
|
resp.headers = self._update_header_cookie(b"".join(_headers).decode("utf8"))
|
||||||
|
@ -234,8 +234,6 @@ class texthook(basetext):
|
|||||||
dll = os.path.abspath(
|
dll = os.path.abspath(
|
||||||
"./files/plugins/LunaHook/LunaHook{}.dll".format(arch)
|
"./files/plugins/LunaHook/LunaHook{}.dll".format(arch)
|
||||||
)
|
)
|
||||||
print(injecter, os.path.exists(injecter))
|
|
||||||
print(dll, os.path.exists(dll))
|
|
||||||
# subprocess.Popen('"{}" dllinject {} "{}"'.format(injecter,pid,dll))
|
# subprocess.Popen('"{}" dllinject {} "{}"'.format(injecter,pid,dll))
|
||||||
injectdll(injectpids, injecter, dll)
|
injectdll(injectpids, injecter, dll)
|
||||||
|
|
||||||
|
@ -12,5 +12,5 @@ class TS(basetransdev):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
return self.wait_for_result(
|
return self.wait_for_result(
|
||||||
r"""document.evaluate('//*[@id="headlessui-tabs-panel-7"]/div/div[1]/section/div/div[2]/div[3]/section/div[1]/d-textarea/div',document).iterateNext().textContent"""
|
r"""document.querySelector("#textareasContainer > div.rounded-ee-inherit.relative.min-h-\\[240px\\].min-w-0.md\\:min-h-\\[clamp\\(250px\\,50vh\\,557px\\)\\].mobile\\:min-h-0.mobile\\:flex-1.max-\\[768px\\]\\:min-h-\\[375px\\] > section > div.rounded-inherit.mobile\\:min-h-0.relative.flex.flex-1.flex-col > d-textarea").textContent"""
|
||||||
)
|
)
|
||||||
|
@ -5,9 +5,11 @@ class TS(basetransdev):
|
|||||||
target_url = "https://fanyi.youdao.com/"
|
target_url = "https://fanyi.youdao.com/"
|
||||||
|
|
||||||
def translate(self, content):
|
def translate(self, content):
|
||||||
|
|
||||||
self.Runtime_evaluate(
|
self.Runtime_evaluate(
|
||||||
'(a=document.querySelector("#TextTranslate > div.source > a"))?a.click():"";i=document.querySelector("#js_fanyi_input");i.innerText=`{}`;event = new Event("input", {{bubbles: true, cancelable: true }});i.dispatchEvent(event);'.format(
|
'document.querySelector("#TextTranslate > div.source > div.text-translate-top-right > a").click()'
|
||||||
|
)
|
||||||
|
self.Runtime_evaluate(
|
||||||
|
'i=document.querySelector("#js_fanyi_input");i.innerText=`{}`;event = new Event("input", {{bubbles: true, cancelable: true }});i.dispatchEvent(event);'.format(
|
||||||
content
|
content
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -21,11 +21,7 @@ class TS(basetrans):
|
|||||||
# self.url=self.config['host']+'_next/data/{}/%s/%s/%s.json'.format(_id)
|
# self.url=self.config['host']+'_next/data/{}/%s/%s/%s.json'.format(_id)
|
||||||
def translate(self, content):
|
def translate(self, content):
|
||||||
# print(self.url%(self.srclang,self.tgtlang,urllib.parse.quote(content)))
|
# print(self.url%(self.srclang,self.tgtlang,urllib.parse.quote(content)))
|
||||||
print(
|
|
||||||
"https://"
|
|
||||||
+ self.config["host"]
|
|
||||||
+ "/api/v1/%s/%s/%s" % (self.srclang, self.tgtlang, quote_plus(content))
|
|
||||||
)
|
|
||||||
x = self.session.get(
|
x = self.session.get(
|
||||||
"https://"
|
"https://"
|
||||||
+ self.config["host"]
|
+ self.config["host"]
|
||||||
|
@ -29,8 +29,10 @@ class TS(basetransdev):
|
|||||||
else:
|
else:
|
||||||
tgtidx = 1
|
tgtidx = 1
|
||||||
self.Runtime_evaluate(
|
self.Runtime_evaluate(
|
||||||
"""document.querySelector('div.textpanel-tool.tool-close').click();
|
'document.querySelector("div.textpanel-tool.tool-close").click()'
|
||||||
document.querySelector("#language-button-group-source > div.language-button-dropdown.language-source > ul > li:nth-child(1) > span").click();
|
)
|
||||||
|
self.Runtime_evaluate(
|
||||||
|
"""document.querySelector("#language-button-group-source > div.language-button-dropdown.language-source > ul > li:nth-child(1) > span").click();
|
||||||
document.querySelector("#language-button-group-target > div.language-button-dropdown.language-target > ul > li:nth-child({}) > span");
|
document.querySelector("#language-button-group-target > div.language-button-dropdown.language-target > ul > li:nth-child({}) > span");
|
||||||
document.getElementsByClassName('textinput')[0].value=`{}`;
|
document.getElementsByClassName('textinput')[0].value=`{}`;
|
||||||
document.getElementsByClassName('language-translate-button')[0].click();
|
document.getElementsByClassName('language-translate-button')[0].click();
|
||||||
|
@ -29,7 +29,7 @@ include(generate_product_version)
|
|||||||
|
|
||||||
set(VERSION_MAJOR 2)
|
set(VERSION_MAJOR 2)
|
||||||
set(VERSION_MINOR 52)
|
set(VERSION_MINOR 52)
|
||||||
set(VERSION_PATCH 5)
|
set(VERSION_PATCH 6)
|
||||||
|
|
||||||
add_library(pch pch.cpp)
|
add_library(pch pch.cpp)
|
||||||
target_precompile_headers(pch PUBLIC pch.h)
|
target_precompile_headers(pch PUBLIC pch.h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user