This commit is contained in:
恍兮惚兮 2024-05-22 21:31:33 +08:00
parent 7df03810a1
commit 95877df877
24 changed files with 309 additions and 209 deletions

View File

@ -79,7 +79,7 @@ def setTab7(self):
def getcomparelayout(self): def getcomparelayout(self):
layout = QHBoxLayout() layout = QHBoxLayout()
fromtext =QPlainTextEdit() fromtext = QPlainTextEdit()
totext = QPlainTextEdit() totext = QPlainTextEdit()
solvebutton = getcolorbutton( solvebutton = getcolorbutton(
globalconfig, globalconfig,
@ -113,28 +113,27 @@ def setTab7_lazy(self):
def changerank(item, up): def changerank(item, up):
ii = sortlist.index(item) idx = sortlist.index(item)
if up and ii == 0: idx2 = idx + (-1 if up else 1)
return if idx2 < 0 or idx2 >= len(sortlist):
if up == False and ii == len(sortlist) - 1:
return return
headoffset = 1 headoffset = 1
toexchangei = ii + (-1 if up else 1) idx2 = idx + (-1 if up else 1)
sortlist[ii], sortlist[toexchangei] = sortlist[toexchangei], sortlist[ii] sortlist[idx], sortlist[idx2] = sortlist[idx2], sortlist[idx]
for i, ww in enumerate(savelist[ii + headoffset]): for i, ww in enumerate(savelist[idx + headoffset]):
w1 = savelay[0].indexOf(ww) w1 = savelay[0].indexOf(ww)
w2 = savelay[0].indexOf(savelist[toexchangei + headoffset][i]) w2 = savelay[0].indexOf(savelist[idx2 + headoffset][i])
p1 = savelay[0].getItemPosition(w1) p1 = savelay[0].getItemPosition(w1)
p2 = savelay[0].getItemPosition(w2) p2 = savelay[0].getItemPosition(w2)
savelay[0].removeWidget(ww) savelay[0].removeWidget(ww)
savelay[0].removeWidget(savelist[toexchangei + headoffset][i]) savelay[0].removeWidget(savelist[idx2 + headoffset][i])
savelay[0].addWidget(savelist[toexchangei + headoffset][i], *p1) savelay[0].addWidget(savelist[idx2 + headoffset][i], *p1)
savelay[0].addWidget(ww, *p2) savelay[0].addWidget(ww, *p2)
savelist[ii + headoffset], savelist[toexchangei + headoffset] = ( savelist[idx + headoffset], savelist[idx2 + headoffset] = (
savelist[toexchangei + headoffset], savelist[idx2 + headoffset],
savelist[ii + headoffset], savelist[idx + headoffset],
) )
for i, post in enumerate(sortlist): for i, post in enumerate(sortlist):

View File

@ -60,14 +60,14 @@ class dialog_toolbutton(QDialog):
super().__init__(parent, Qt.WindowCloseButtonHint) super().__init__(parent, Qt.WindowCloseButtonHint)
self.setWindowTitle(_TR("窗口按钮设置")) self.setWindowTitle(_TR("窗口按钮设置"))
model = QStandardItemModel() model = QStandardItemModel()
model.setHorizontalHeaderLabels(_TRL(["显示", "图标", "图标2", "说明"])) model.setHorizontalHeaderLabels(
_TRL(["显示", "", "", "对齐", "图标", "图标2", "说明"])
)
layout = QVBoxLayout(self) # layout = QVBoxLayout(self) #
self.model = model self.model = model
table = QTableView() table = QTableView()
table.setDragEnabled(True)
table.setAcceptDrops(True)
table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
table.horizontalHeader().setStretchLastSection(True) table.horizontalHeader().setStretchLastSection(True)
@ -77,13 +77,31 @@ class dialog_toolbutton(QDialog):
table.setWordWrap(False) table.setWordWrap(False)
table.setModel(model) table.setModel(model)
self.table = table self.table = table
for row, k in enumerate(globalconfig["toolbutton"]["rank"]): for row, k in enumerate(globalconfig["toolbutton"]["rank2"]):
self.newline(row, k) self.newline(row, k)
layout.addWidget(table) layout.addWidget(table)
self.resize(QSize(800, 400)) self.resize(QSize(800, 400))
self.show() self.show()
def changerank2(self, key, up):
idx = globalconfig["toolbutton"]["rank2"].index(key)
idx2 = idx + (-1 if up else 1)
if idx2 < 0 or idx2 >= len(globalconfig["toolbutton"]["rank2"]):
return
idx2 = idx + (-1 if up else 1)
(
globalconfig["toolbutton"]["rank2"][idx],
globalconfig["toolbutton"]["rank2"][idx2],
) = (
globalconfig["toolbutton"]["rank2"][idx2],
globalconfig["toolbutton"]["rank2"][idx],
)
self.model.removeRow(idx2)
self.newline(idx, globalconfig["toolbutton"]["rank2"][idx]),
gobject.baseobject.translation_ui.adjustbuttons()
def newline(self, row, k): def newline(self, row, k):
if "belong" in globalconfig["toolbutton"]["buttons"][k]: if "belong" in globalconfig["toolbutton"]["buttons"][k]:
belong = ( belong = (
@ -97,6 +115,9 @@ class dialog_toolbutton(QDialog):
self.model.insertRow( self.model.insertRow(
row, row,
[ [
QStandardItem(),
QStandardItem(),
QStandardItem(),
QStandardItem(), QStandardItem(),
QStandardItem(), QStandardItem(),
QStandardItem(), QStandardItem(),
@ -110,12 +131,43 @@ class dialog_toolbutton(QDialog):
getsimpleswitch( getsimpleswitch(
globalconfig["toolbutton"]["buttons"][k], globalconfig["toolbutton"]["buttons"][k],
"use", "use",
callback=lambda _: gobject.baseobject.translation_ui.showhidetoolbuttons(), callback=lambda _: gobject.baseobject.translation_ui.adjustbuttons(),
), ),
) )
button_up = getcolorbutton(
globalconfig,
"",
callback=functools.partial(self.changerank2, k, True),
icon="fa.arrow-up",
constcolor="#FF69B4",
)
button_down = getcolorbutton(
globalconfig,
"",
callback=functools.partial(self.changerank2, k, False),
icon="fa.arrow-down",
constcolor="#FF69B4",
)
self.table.setIndexWidget(
self.model.index(row, 1),
button_up,
)
self.table.setIndexWidget(
self.model.index(row, 2),
button_down,
)
self.table.setIndexWidget( self.table.setIndexWidget(
self.model.index(row, 1), self.model.index(row, 3),
getsimplecombobox(
["居左", "居右", "居中"],
globalconfig["toolbutton"]["buttons"][k],
"align",
callback=lambda _: gobject.baseobject.translation_ui.adjustbuttons(),
),
)
self.table.setIndexWidget(
self.model.index(row, 4),
getcolorbutton( getcolorbutton(
"", "",
"", "",
@ -130,7 +182,7 @@ class dialog_toolbutton(QDialog):
) )
if "icon2" in globalconfig["toolbutton"]["buttons"][k]: if "icon2" in globalconfig["toolbutton"]["buttons"][k]:
self.table.setIndexWidget( self.table.setIndexWidget(
self.model.index(row, 2), self.model.index(row, 5),
getcolorbutton( getcolorbutton(
"", "",
"", "",

View File

@ -11,6 +11,7 @@ from PyQt5.QtWidgets import (
QTabWidget, QTabWidget,
QFileDialog, QFileDialog,
QTabBar, QTabBar,
QSplitter,
QLabel, QLabel,
) )
from myutils.hwnd import grabwindow from myutils.hwnd import grabwindow
@ -172,6 +173,7 @@ class AnkiWindow(QWidget):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.setWindowTitle("Anki Connect") self.setWindowTitle("Anki Connect")
self.currentword = "" self.currentword = ""
self.tabs = QTabWidget() self.tabs = QTabWidget()
@ -798,18 +800,25 @@ class searchwordW(closeashidewindow):
self.cache_results = {} self.cache_results = {}
self.hiding = True self.hiding = True
self.spliter = QSplitter()
tablayout = QVBoxLayout() tablayout = QVBoxLayout()
tablayout.addWidget(self.tab)
tablayout.addWidget(self.textOutput)
tablayout.setContentsMargins(0, 0, 0, 0) tablayout.setContentsMargins(0, 0, 0, 0)
tablayout.setSpacing(0) tablayout.setSpacing(0)
self.vboxlayout.addLayout(tablayout) tablayout.addWidget(self.tab)
tablayout.addWidget(self.textOutput)
w = QWidget()
w.setLayout(tablayout)
self.vboxlayout.addWidget(self.spliter)
self.isfirstshowanki = True self.isfirstshowanki = True
self.spliter.setOrientation(Qt.Vertical)
self.spliter.addWidget(w)
def onceaddankiwindow(self, idx): def onceaddankiwindow(self, idx):
if idx == 1: if idx == 1:
if self.isfirstshowanki: if self.isfirstshowanki:
self.vboxlayout.addWidget(self.ankiwindow) self.spliter.addWidget(self.ankiwindow)
else: else:
self.ankiwindow.show() self.ankiwindow.show()
else: else:

View File

@ -1,4 +1,4 @@
from PyQt5.QtCore import Qt, QPoint, QPointF from PyQt5.QtCore import Qt, QPoint, QPointF, pyqtSignal
from PyQt5.QtGui import ( from PyQt5.QtGui import (
QTextCharFormat, QTextCharFormat,
QTextBlockFormat, QTextBlockFormat,
@ -178,41 +178,36 @@ class BorderedLabel(ShadowLabel):
painter.drawPixmap(0, 0, self._pix) painter.drawPixmap(0, 0, self._pix)
class Textbrowser: class Textbrowser(QLabel):
def movep(self, x, y): contentsChanged = pyqtSignal(int, int)
self.savey = y
self.atback.move(0, int(y))
if globalconfig["isshowhira"] and globalconfig["isshowrawtext"]:
if self.jiaming_y_delta > 0:
y = y + self.jiaming_y_delta
self.textbrowser.move(int(x), int(y))
self.atback2.move(0, int(y)) def move(self, x, y):
self.toplabel2.move(0, int(y)) super().move(x, y)
self.textbrowser.move(x, y)
self.atback2.move(x, y)
self.toplabel2.move(x, y)
def resizeEvent(self, event):
self.atback2.resize(event.size())
self.toplabel2.resize(event.size())
def contentchangedfunction(self):
sz = self.textbrowser.document().size().toSize()
self.textbrowser.resize(self.width(), sz.height())
self.contentsChanged.emit(sz.width(), sz.height())
def __init__(self, parent): def __init__(self, parent):
self.parent = parent super().__init__(parent)
self.savey = 0
# self.shadowlabel=QLabel(parent)
# self.shadowlabel.savetext=''
self.align = False
self.atback = QLabel(parent) self.setMouseTracking(True)
self.atback.setMouseTracking(True)
self.atback2 = QLabel(parent) self.atback2 = QLabel(parent)
self.toplabel2 = QLabel(parent) self.toplabel2 = QLabel(parent)
self.atback2.setMouseTracking(True) self.atback2.setMouseTracking(True)
self.textbrowser = QTextBrowser(parent) self.textbrowser = QTextBrowser(parent)
self.textbrowser.document().contentsChanged.connect(self.contentchangedfunction)
def __resizeevent(event: QResizeEvent):
self.atback.resize(event.size())
self.atback2.resize(event.size())
self.toplabel2.resize(event.size())
self.textbrowser.resizeEvent = __resizeevent
self.tranparentcolor = QColor() self.tranparentcolor = QColor()
self.tranparentcolor.setAlpha(0) self.tranparentcolor.setAlpha(0)
self.textbrowser.setTextColor(self.tranparentcolor) self.textbrowser.setTextColor(self.tranparentcolor)
@ -244,7 +239,6 @@ class Textbrowser:
self.yinyingpos = 0 self.yinyingpos = 0
self.yinyingposline = 0 self.yinyingposline = 0
self.lastcolor = None self.lastcolor = None
self.jiaming_y_delta = 0
self.setselectable() self.setselectable()
self.blockcount = 0 self.blockcount = 0
self.iteryinyinglabelsave = {} self.iteryinyinglabelsave = {}
@ -252,15 +246,6 @@ class Textbrowser:
def setselectable(self): def setselectable(self):
self.masklabel.setHidden(globalconfig["selectable"]) self.masklabel.setHidden(globalconfig["selectable"])
def setStyleSheet(self, x):
self.atback.setStyleSheet(x)
def document(self):
return self.textbrowser.document()
def resize(self, _1, _2):
self.textbrowser.resize(int(_1), int(_2))
def setnextfont(self, origin): def setnextfont(self, origin):
if origin: if origin:
self.font.setFamily(globalconfig["fonttype"]) self.font.setFamily(globalconfig["fonttype"])
@ -277,19 +262,8 @@ class Textbrowser:
c.setCharFormat(f) c.setCharFormat(f)
self.textbrowser.setTextCursor(c) self.textbrowser.setTextCursor(c)
def setGeometry(self, _1, _2, _3, _4):
self.textbrowser.setGeometry(_1, _2, _3, _4)
self.savey = _2
# self.shadowlabel.setGeometry(_1,_2,_3,_4)
# self.shadowlabel.resize(_3,_4)
def setAlignment(self, x): def setAlignment(self, x):
self.textbrowser.setAlignment(x) self.textbrowser.setAlignment(x)
if Qt.AlignCenter == x:
self.align = True
else:
self.align = False
def append(self, x, tag, color): def append(self, x, tag, color):
if self.cleared: if self.cleared:
@ -317,8 +291,6 @@ class Textbrowser:
if len(tag) > 0: if len(tag) > 0:
self.addtag(tag) self.addtag(tag)
self.movep(0, self.savey)
self.showyinyingtext(b1, b2, color) self.showyinyingtext(b1, b2, color)
def getcurrpointer(self): def getcurrpointer(self):
@ -429,7 +401,8 @@ class Textbrowser:
idx = 0 idx = 0
guesswidth = [] guesswidth = []
guesslinehead = None guesslinehead = None
wwww = self.parent.width() wwww = self.width()
heigth, __, _ = self.getfh(False)
for word in x: for word in x:
idx += 1 idx += 1
l = len(word["orig"]) l = len(word["orig"])
@ -473,14 +446,14 @@ class Textbrowser:
guesswidth1 = gw * len(word["orig"]) guesswidth1 = gw * len(word["orig"])
tailx = wwww - guesslinehead tailx = wwww - guesslinehead
pos1 = ( pos1 = (
tl1.x() + 2, tl1.x(),
tl1.y(), tl1.y(),
tailx - tl1.x() - 4, tailx - tl1.x(),
tl4.y() - tl1.y(), heigth,
) )
xx = int(guesswidth1 - (tailx - tl1.x())) xx = int(guesswidth1 - (tailx - tl1.x()))
guesslinehead = None guesslinehead = None
pos2 = tl3.x() - xx + 2, tl3.y(), xx - 4, tl4.y() - tl1.y() pos2 = tl3.x() - xx, tl3.y(), xx, heigth
if ( if (
globalconfig["usesearchword"] globalconfig["usesearchword"]
or globalconfig["usecopyword"] or globalconfig["usecopyword"]
@ -526,10 +499,10 @@ class Textbrowser:
len(word["orig"]) len(word["orig"])
) )
pos1 = ( pos1 = (
tl1.x() + 2, tl1.x(),
tl1.y(), tl1.y(),
tl2.x() - tl1.x() - 4, tl2.x() - tl1.x(),
tl2.y() - tl1.y(), heigth,
) )
if ( if (
globalconfig["usesearchword"] globalconfig["usesearchword"]
@ -585,30 +558,21 @@ class Textbrowser:
font.setPointSizeF((globalconfig["fontsize"])) font.setPointSizeF((globalconfig["fontsize"]))
fm = QFontMetricsF(font) fm = QFontMetricsF(font)
fhall = fm.height() return fm.height(), fm.ascent(), font
return fhall, font
def addtag(self, x): def addtag(self, x):
pos = 0 pos = 0
fhall, fontorig = self.getfh(False) fasall, _, fontorig = self.getfh(False)
fhhalf, fonthira = self.getfh(True) fha, fascent, fonthira = self.getfh(True)
for i in range(0, self.textbrowser.document().blockCount()): for i in range(0, self.textbrowser.document().blockCount()):
b = self.textbrowser.document().findBlockByNumber(i) b = self.textbrowser.document().findBlockByNumber(i)
tf = b.blockFormat() tf = b.blockFormat()
tf.setLineHeight(fhall + fhhalf, QTextBlockFormat.FixedHeight) tf.setLineHeight(fasall + fha, QTextBlockFormat.FixedHeight)
self.textcursor.setPosition(b.position()) self.textcursor.setPosition(b.position())
self.textcursor.setBlockFormat(tf) self.textcursor.setBlockFormat(tf)
self.textbrowser.setTextCursor(self.textcursor) self.textbrowser.setTextCursor(self.textcursor)
if i == 0:
tl1 = self.textbrowser.cursorRect(self.textcursor).topLeft().y()
if self.jiaming_y_delta + tl1 - fhhalf != 0:
self.jiaming_y_delta = fhhalf - tl1
self.movep(0, self.savey)
x = self.nearmerge(x, pos, fonthira, fontorig) x = self.nearmerge(x, pos, fonthira, fontorig)
self.settextposcursor(pos) self.settextposcursor(pos)
for word in x: for word in x:
@ -626,7 +590,7 @@ class Textbrowser:
if word["orig"] == " ": if word["orig"] == " ":
continue continue
self.savetaglabels.append( self.savetaglabels.append(
self.solvejiaminglabel(word, fonthira, tl1, tl2, fhhalf) self.solvejiaminglabel(word, fonthira, tl1, tl2, fascent)
) )
def settextposcursor(self, pos): def settextposcursor(self, pos):
@ -730,9 +694,8 @@ class Textbrowser:
def solvejiaminglabel(self, word, font, tl1, tl2, fh): def solvejiaminglabel(self, word, font, tl1, tl2, fh):
_ = self.guesscreatelabel( _ = self.guesscreatelabel(
self.parent, globalconfig["jiamingcolor"], rate=globalconfig["kanarate"] self.atback2, globalconfig["jiamingcolor"], rate=globalconfig["kanarate"]
) )
_.setText(word["hira"]) _.setText(word["hira"])
_.setFont(font) _.setFont(font)
_.adjustSize() _.adjustSize()
@ -750,8 +713,6 @@ class Textbrowser:
else: else:
x = tl1.x() / 2 + tl2.x() / 2 - w / 2 x = tl1.x() / 2 + tl2.x() / 2 - w / 2
y = tl2.y() - fh y = tl2.y() - fh
y += globalconfig["buttonsize"] * 1.5
y += self.jiaming_y_delta
_.move(QPoint(int(x), int(y))) _.move(QPoint(int(x), int(y)))

View File

@ -318,8 +318,7 @@ class QUnFrameWindow(resizableframeless):
onstatecolor = "#FF69B4" onstatecolor = "#FF69B4"
self._TitleLabel.setFixedHeight(int(globalconfig["buttonsize"] * 1.5)) self._TitleLabel.setFixedHeight(int(globalconfig["buttonsize"] * 1.5))
for i in range(len(self.buttons)): for name in self.buttons:
name = self.buttons[i].name
if name in colorstate: if name in colorstate:
color = ( color = (
onstatecolor if colorstate[name] else globalconfig["buttoncolor"] onstatecolor if colorstate[name] else globalconfig["buttoncolor"]
@ -334,23 +333,20 @@ class QUnFrameWindow(resizableframeless):
) )
else: else:
icon = globalconfig["toolbutton"]["buttons"][name]["icon"] icon = globalconfig["toolbutton"]["buttons"][name]["icon"]
self.buttons[i].setIcon(qtawesome.icon(icon, color=color)) # (icon[i]) self.buttons[name].setIcon(qtawesome.icon(icon, color=color)) # (icon[i])
self.buttons[i].resize( self.buttons[name].resize(
int(globalconfig["buttonsize"] * 2), int(globalconfig["buttonsize"] * 2),
int(globalconfig["buttonsize"] * 1.5), int(globalconfig["buttonsize"] * 1.5),
) )
if self.buttons[i].adjast: self.buttons[name].setIconSize(
self.buttons[i].adjast()
self.buttons[i].setIconSize(
QSize(globalconfig["buttonsize"], globalconfig["buttonsize"]) QSize(globalconfig["buttonsize"], globalconfig["buttonsize"])
) )
self.showhidetoolbuttons() self.translate_text.move(0, int(globalconfig["buttonsize"] * 1.5))
self.translate_text.movep(0, globalconfig["buttonsize"] * 1.5)
self.textAreaChanged()
self.setMinimumHeight(int(globalconfig["buttonsize"] * 1.5 + 10)) self.setMinimumHeight(int(globalconfig["buttonsize"] * 1.5 + 10))
self.setMinimumWidth(globalconfig["buttonsize"] * 2) self.setMinimumWidth(globalconfig["buttonsize"] * 2)
self.set_color_transparency() self.set_color_transparency()
self.adjustbuttons()
def ocr_once_function(self): def ocr_once_function(self):
@threader @threader
@ -474,7 +470,6 @@ class QUnFrameWindow(resizableframeless):
("minmize", self.hide_), ("minmize", self.hide_),
("quit", self.close), ("quit", self.close),
) )
adjast = {"minmize": -2, "quit": -1}
_type = {"quit": 2} _type = {"quit": 2}
for btn, func in functions: for btn, func in functions:
@ -483,12 +478,10 @@ class QUnFrameWindow(resizableframeless):
if "belong" in globalconfig["toolbutton"]["buttons"][btn] if "belong" in globalconfig["toolbutton"]["buttons"][btn]
else None else None
) )
_adjast = adjast[btn] if btn in adjast else 0
tp = _type[btn] if btn in _type else 1 tp = _type[btn] if btn in _type else 1
self.takusanbuttons( self.takusanbuttons(
tp, tp,
func, func,
_adjast,
globalconfig["toolbutton"]["buttons"][btn]["tip"], globalconfig["toolbutton"]["buttons"][btn]["tip"],
btn, btn,
belong, belong,
@ -648,17 +641,14 @@ class QUnFrameWindow(resizableframeless):
self.mousetransparent = False self.mousetransparent = False
self.backtransparent = False self.backtransparent = False
self.isbindedwindow = False self.isbindedwindow = False
self.buttons = [] self.buttons = {}
self.stylebuttons = {}
self.showbuttons = [] self.showbuttons = []
self.stylebuttons = {}
self.saveiterclasspointer = {} self.saveiterclasspointer = {}
self.addbuttons() self.addbuttons()
self.translate_text = Textbrowser(self) self.translate_text = Textbrowser(self)
# 翻译框根据内容自适应大小 self.translate_text.contentsChanged.connect(self.textAreaChanged)
self.document = self.translate_text.document()
self.document.contentsChanged.connect(self.textAreaChanged)
self.thistimenotsetop = False self.thistimenotsetop = False
def createborderradiusstring(self, r, merge, top=False): def createborderradiusstring(self, r, merge, top=False):
@ -889,12 +879,13 @@ class QUnFrameWindow(resizableframeless):
globalconfig["locktools"] = not globalconfig["locktools"] globalconfig["locktools"] = not globalconfig["locktools"]
self.refreshtoolicon() self.refreshtoolicon()
def textAreaChanged(self): def textAreaChanged(self, w, h):
if globalconfig["fixedheight"]: if globalconfig["fixedheight"]:
return return
if self.translate_text.cleared: if self.translate_text.cleared:
return return
newHeight = self.document.size().height() newHeight = h
width = self.width() width = self.width()
self.resize( self.resize(
width, width,
@ -930,7 +921,7 @@ class QUnFrameWindow(resizableframeless):
def toolbarhidedelay(self): def toolbarhidedelay(self):
for button in self.buttons: for button in self.buttons.values():
button.hide() button.hide()
self._TitleLabel.hide() self._TitleLabel.hide()
self.set_color_transparency() self.set_color_transparency()
@ -940,7 +931,7 @@ class QUnFrameWindow(resizableframeless):
def enterfunction(self): def enterfunction(self):
for button in self.buttons[-2:] + self.showbuttons: for button in self.showbuttons:
button.show() button.show()
self._TitleLabel.show() self._TitleLabel.show()
@ -964,16 +955,17 @@ class QUnFrameWindow(resizableframeless):
height = self.height() - wh height = self.height() - wh
self.translate_text.resize(self.width(), height) self.translate_text.resize(self.width(), height)
for button in self.buttons[-2:]: self.adjustbuttons()
button.adjast()
# 自定义窗口调整大小事件
self._TitleLabel.setFixedWidth(self.width()) self._TitleLabel.setFixedWidth(self.width())
def showhidetoolbuttons(self): def adjustbuttons(self):
showed = 0 left = []
self.showbuttons = [] right = []
center = []
for i, button in enumerate(self.buttons[:-2]): self.showbuttons.clear()
__ = [left, right, center]
for name in globalconfig["toolbutton"]["rank2"]:
button = self.buttons[name]
if button.belong: if button.belong:
hide = True hide = True
for k in button.belong: for k in button.belong:
@ -987,17 +979,29 @@ class QUnFrameWindow(resizableframeless):
button.hide() button.hide()
continue continue
if ( if (
button.name in globalconfig["toolbutton"]["buttons"] name in globalconfig["toolbutton"]["buttons"]
and globalconfig["toolbutton"]["buttons"][button.name]["use"] == False and globalconfig["toolbutton"]["buttons"][name]["use"] == False
): ):
button.hide() button.hide()
continue continue
__[globalconfig["toolbutton"]["buttons"][name]["align"]].append(button)
button.move(showed * button.width(), 0)
self.showbuttons.append(button) self.showbuttons.append(button)
# button.show()
showed += 1 leftmax = 0
self.enterEvent(None) rightmax = self.width()
for button in left:
button.move(leftmax, 0)
leftmax += button.width()
for button in reversed(right):
rightmax -= button.width()
button.move(rightmax, 0)
sumwidth = 0
for button in center:
sumwidth += button.width()
leftstart = leftmax + (rightmax - leftmax - sumwidth) / 2
for button in center:
button.move(leftstart, 0)
leftstart += button.width()
def callwrap(self, call, _): def callwrap(self, call, _):
try: try:
@ -1005,9 +1009,7 @@ class QUnFrameWindow(resizableframeless):
except: except:
print_exc() print_exc()
def takusanbuttons( def takusanbuttons(self, _type, clickfunc, tips, name, belong=None):
self, _type, clickfunc, adjast=None, tips=None, save=None, belong=None
):
button = QPushButton(self) button = QPushButton(self)
if tips: if tips:
@ -1020,15 +1022,8 @@ class QUnFrameWindow(resizableframeless):
else: else:
button.lower() button.lower()
button.name = save
button.belong = belong button.belong = belong
if adjast < 0: self.buttons[name] = button
button.adjast = lambda: button.move(
self.width() + adjast * button.width(), 0
)
else:
button.adjast = None
self.buttons.append(button)
def closeEvent(self, a0) -> None: def closeEvent(self, a0) -> None:
if self.fullscreenmanager: if self.fullscreenmanager:

View File

@ -645,6 +645,9 @@ class auto_select_webview(QWidget):
print("file://" + self.lastcachehtml.replace("\\", "/")) print("file://" + self.lastcachehtml.replace("\\", "/"))
self.internal.navigate("file://" + self.lastcachehtml.replace("\\", "/")) self.internal.navigate("file://" + self.lastcachehtml.replace("\\", "/"))
def sizeHint(self):
return QSize(256, 192)
def clearcache(self): def clearcache(self):
if self.lastcachehtml and os.path.exists(self.lastcachehtml): if self.lastcachehtml and os.path.exists(self.lastcachehtml):
lastcachehtml = self.lastcachehtml lastcachehtml = self.lastcachehtml

View File

@ -181,13 +181,15 @@ if ocrerrorfix == {}:
ocrerrorfix = ocrerrorfixdefault ocrerrorfix = ocrerrorfixdefault
syncconfig(postprocessconfig, defaultpost, True, 3) syncconfig(postprocessconfig, defaultpost, True, 3)
if len(globalconfig["toolbutton"]["rank"]) != len( for key in defaultglobalconfig["toolbutton"]["buttons"]:
globalconfig["toolbutton"]["buttons"].keys() if key not in globalconfig["toolbutton"]["rank2"]:
): globalconfig["toolbutton"]["rank2"].append(key)
globalconfig["toolbutton"]["rank"] += list( ___ = []
set(globalconfig["toolbutton"]["buttons"].keys()) for key in globalconfig["toolbutton"]["rank2"]:
- set(globalconfig["toolbutton"]["rank"]) if key not in defaultglobalconfig["toolbutton"]["buttons"]:
) ___.append(key)
for key in ___:
globalconfig["toolbutton"]["rank2"].remove(key)
def getlanguse(): def getlanguse():

View File

@ -240,59 +240,98 @@
"profiles_index": 0, "profiles_index": 0,
"ocrautobindwindow": true, "ocrautobindwindow": true,
"toolbutton": { "toolbutton": {
"rank": [ "rank2": [
"move", "move",
"retrans", "retrans",
"automodebutton",
"setting", "setting",
"automodebutton" "copy",
"edit",
"showraw",
"history",
"noundict",
"fix",
"langdu",
"mousetransbutton",
"backtransbutton",
"locktoolsbutton",
"gamepad_new",
"selectgame",
"selecttext",
"selectocrrange",
"hideocrrange",
"bindwindow",
"resize",
"fullscreen",
"grabwindow",
"muteprocess",
"memory",
"keepontop",
"simulate_key_ctrl",
"simulate_key_enter",
"copy_once",
"open_relative_link",
"open_game_setting",
"ocr_once",
"minmize",
"quit"
], ],
"buttons": { "buttons": {
"retrans": { "retrans": {
"use": true, "use": true,
"tip": "重新翻译", "tip": "重新翻译",
"icon": "fa.rotate-right" "icon": "fa.rotate-right",
"align": 0
}, },
"automodebutton": { "automodebutton": {
"use": true, "use": true,
"tip": "自动翻译", "tip": "自动翻译",
"icon": "fa.forward", "icon": "fa.forward",
"icon2": "fa.play" "icon2": "fa.play",
"align": 0
}, },
"setting": { "setting": {
"use": true, "use": true,
"tip": "打开设置", "tip": "打开设置",
"icon": "fa.gear" "icon": "fa.gear",
"align": 0
}, },
"copy_once": { "copy_once": {
"use": false, "use": false,
"tip": "读取剪贴板", "tip": "读取剪贴板",
"icon": "fa.file-o" "icon": "fa.file-o",
"align": 0
}, },
"open_relative_link": { "open_relative_link": {
"use": false, "use": false,
"tip": "打开关联页面", "tip": "打开关联页面",
"icon": "fa.sitemap" "icon": "fa.sitemap",
"align": 0
}, },
"open_game_setting": { "open_game_setting": {
"use": false, "use": false,
"tip": "游戏设置", "tip": "游戏设置",
"icon": "fa.futbol-o" "icon": "fa.futbol-o",
"align": 0
}, },
"mousetransbutton": { "mousetransbutton": {
"use": true, "use": true,
"tip": "鼠标穿透窗口", "tip": "鼠标穿透窗口",
"icon": "fa.mouse-pointer" "icon": "fa.mouse-pointer",
"align": 0
}, },
"backtransbutton": { "backtransbutton": {
"use": true, "use": true,
"tip": "背景窗口透明", "tip": "背景窗口透明",
"icon": "fa.lightbulb-o" "icon": "fa.lightbulb-o",
"align": 0
}, },
"locktoolsbutton": { "locktoolsbutton": {
"use": true, "use": true,
"tip": "锁定工具栏", "tip": "锁定工具栏",
"icon": "fa.lock", "icon": "fa.lock",
"icon2": "fa.unlock" "icon2": "fa.unlock",
"align": 0
}, },
"selectgame": { "selectgame": {
"use": true, "use": true,
@ -300,7 +339,8 @@
"belong": [ "belong": [
"texthook" "texthook"
], ],
"icon": "fa.link" "icon": "fa.link",
"align": 0
}, },
"selecttext": { "selecttext": {
"use": true, "use": true,
@ -308,7 +348,8 @@
"belong": [ "belong": [
"texthook" "texthook"
], ],
"icon": "fa.tasks" "icon": "fa.tasks",
"align": 0
}, },
"selectocrrange": { "selectocrrange": {
"use": true, "use": true,
@ -316,12 +357,14 @@
"belong": [ "belong": [
"ocr" "ocr"
], ],
"icon": "fa.crop" "icon": "fa.crop",
"align": 0
}, },
"ocr_once": { "ocr_once": {
"use": false, "use": false,
"tip": "进行一次OCR", "tip": "进行一次OCR",
"icon": "fa.crop" "icon": "fa.crop",
"align": 0
}, },
"hideocrrange": { "hideocrrange": {
"use": true, "use": true,
@ -329,110 +372,131 @@
"belong": [ "belong": [
"ocr" "ocr"
], ],
"icon": "fa.square" "icon": "fa.square",
"align": 0
}, },
"fix": { "fix": {
"use": false, "use": false,
"tip": "翻译结果修正", "tip": "翻译结果修正",
"icon": "fa.won" "icon": "fa.won",
"align": 0
}, },
"noundict": { "noundict": {
"use": false, "use": false,
"tip": "专有名词翻译设置", "tip": "专有名词翻译设置",
"icon": "fa.book" "icon": "fa.book",
"align": 0
}, },
"minmize": { "minmize": {
"use": true, "use": true,
"tip": "最小化到托盘", "tip": "最小化到托盘",
"icon": "fa.minus" "icon": "fa.minus",
"align": 1
}, },
"quit": { "quit": {
"use": true, "use": true,
"tip": "退出", "tip": "退出",
"icon": "fa.times" "icon": "fa.times",
"align": 1
}, },
"move": { "move": {
"use": false, "use": false,
"tip": "移动", "tip": "移动",
"icon": "fa.hand-paper-o" "icon": "fa.hand-paper-o",
"align": 0
}, },
"fullscreen": { "fullscreen": {
"use": true, "use": true,
"tip": "缩放/恢复游戏窗口", "tip": "缩放/恢复游戏窗口",
"icon": "fa.compress", "icon": "fa.compress",
"icon2": "fa.expand" "icon2": "fa.expand",
"align": 0
}, },
"grabwindow": { "grabwindow": {
"use": false, "use": false,
"tip": "窗口截图", "tip": "窗口截图",
"icon": "fa.camera" "icon": "fa.camera",
"align": 0
}, },
"resize": { "resize": {
"use": false, "use": false,
"tip": "调整游戏窗口", "tip": "调整游戏窗口",
"icon": "fa.arrows" "icon": "fa.arrows",
"align": 0
}, },
"muteprocess": { "muteprocess": {
"use": false, "use": false,
"tip": "游戏静音", "tip": "游戏静音",
"icon": "fa.volume-off", "icon": "fa.volume-off",
"icon2": "fa.volume-up" "icon2": "fa.volume-up",
"align": 0
}, },
"showraw": { "showraw": {
"use": true, "use": true,
"tip": "显示/隐藏原文", "tip": "显示/隐藏原文",
"icon": "fa.eye", "icon": "fa.eye",
"icon2": "fa.eye-slash" "icon2": "fa.eye-slash",
"align": 0
}, },
"langdu": { "langdu": {
"use": true, "use": true,
"tip": "朗读", "tip": "朗读",
"icon": "fa.music" "icon": "fa.music",
"align": 0
}, },
"copy": { "copy": {
"use": true, "use": true,
"tip": "复制到剪贴板", "tip": "复制到剪贴板",
"icon": "fa.copy" "icon": "fa.copy",
"align": 0
}, },
"history": { "history": {
"use": true, "use": true,
"tip": "显示/隐藏历史翻译", "tip": "显示/隐藏历史翻译",
"icon": "fa.rotate-left" "icon": "fa.rotate-left",
"align": 0
}, },
"gamepad_new": { "gamepad_new": {
"use": true, "use": true,
"tip": "游戏管理", "tip": "游戏管理",
"icon": "fa.gamepad" "icon": "fa.gamepad",
"align": 0
}, },
"edit": { "edit": {
"use": false, "use": false,
"tip": "编辑", "tip": "编辑",
"icon": "fa.edit" "icon": "fa.edit",
"align": 0
}, },
"simulate_key_ctrl": { "simulate_key_ctrl": {
"use": false, "use": false,
"tip": "模拟按键Ctrl", "tip": "模拟按键Ctrl",
"icon": "fa.download" "icon": "fa.download",
"align": 0
}, },
"simulate_key_enter": { "simulate_key_enter": {
"use": false, "use": false,
"tip": "模拟按键Enter", "tip": "模拟按键Enter",
"icon": "fa.download" "icon": "fa.download",
"align": 0
}, },
"memory": { "memory": {
"use": false, "use": false,
"tip": "备忘录", "tip": "备忘录",
"icon": "fa.list-ul" "icon": "fa.list-ul",
"align": 0
}, },
"bindwindow": { "bindwindow": {
"use": true, "use": true,
"tip": "绑定窗口(部分软件不支持)(点击自己取消)", "tip": "绑定窗口(部分软件不支持)(点击自己取消)",
"icon": "fa.windows" "icon": "fa.windows",
"align": 0
}, },
"keepontop": { "keepontop": {
"use": true, "use": true,
"tip": "窗口置顶", "tip": "窗口置顶",
"icon": "fa.neuter" "icon": "fa.neuter",
"align": 0
} }
} }
}, },

View File

@ -794,5 +794,6 @@
"自动截图": "لقطة التلقائي", "自动截图": "لقطة التلقائي",
"模糊匹配": "غامض مطابقة", "模糊匹配": "غامض مطابقة",
"相似度": "درجة التشابه", "相似度": "درجة التشابه",
"编辑距离": "تحرير بالجو" "编辑距离": "تحرير بالجو",
"对齐": "محاذاة"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "自動截圖", "自动截图": "自動截圖",
"模糊匹配": "模糊匹配", "模糊匹配": "模糊匹配",
"相似度": "相似度", "相似度": "相似度",
"编辑距离": "編輯距離" "编辑距离": "編輯距離",
"对齐": "對齊"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "Automatic screenshot", "自动截图": "Automatic screenshot",
"模糊匹配": "Fuzzy matching", "模糊匹配": "Fuzzy matching",
"相似度": "Similarity", "相似度": "Similarity",
"编辑距离": "Edit distance" "编辑距离": "Edit distance",
"对齐": "alignment"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "Captura de pantalla automática", "自动截图": "Captura de pantalla automática",
"模糊匹配": "Coincidencia inútil", "模糊匹配": "Coincidencia inútil",
"相似度": "Similitud", "相似度": "Similitud",
"编辑距离": "Distancia de edición" "编辑距离": "Distancia de edición",
"对齐": "Alinear"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "Capture d'écran automatique", "自动截图": "Capture d'écran automatique",
"模糊匹配": "Correspondance floue", "模糊匹配": "Correspondance floue",
"相似度": "Similarité", "相似度": "Similarité",
"编辑距离": "Modifier la distance" "编辑距离": "Modifier la distance",
"对齐": "Alignement"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "Schermata automatica", "自动截图": "Schermata automatica",
"模糊匹配": "Corrispondenza sfocata", "模糊匹配": "Corrispondenza sfocata",
"相似度": "Similitudine", "相似度": "Similitudine",
"编辑距离": "Modifica distanza" "编辑距离": "Modifica distanza",
"对齐": "allineamento"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "自動スクリーンショット", "自动截图": "自動スクリーンショット",
"模糊匹配": "ファジィマッチング", "模糊匹配": "ファジィマッチング",
"相似度": "そうじど", "相似度": "そうじど",
"编辑距离": "距離の編集" "编辑距离": "距離の編集",
"对齐": "配置"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "자동 캡처", "自动截图": "자동 캡처",
"模糊匹配": "흐림 일치", "模糊匹配": "흐림 일치",
"相似度": "유사도", "相似度": "유사도",
"编辑距离": "거리 편집" "编辑距离": "거리 편집",
"对齐": "정렬"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "Automatyczny zrzut ekranu", "自动截图": "Automatyczny zrzut ekranu",
"模糊匹配": "Dopasowanie rozmyte", "模糊匹配": "Dopasowanie rozmyte",
"相似度": "Podobieństwo", "相似度": "Podobieństwo",
"编辑距离": "Edytuj odległość" "编辑距离": "Edytuj odległość",
"对齐": "wyrównanie"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "Автоматический снимок экрана", "自动截图": "Автоматический снимок экрана",
"模糊匹配": "Нечеткое согласование", "模糊匹配": "Нечеткое согласование",
"相似度": "Сходство", "相似度": "Сходство",
"编辑距离": "Изменить расстояние" "编辑距离": "Изменить расстояние",
"对齐": "Выровнять"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "ภาพหน้าจออัตโนมัติ", "自动截图": "ภาพหน้าจออัตโนมัติ",
"模糊匹配": "จับคู่เบลอ", "模糊匹配": "จับคู่เบลอ",
"相似度": "ความคล้ายคลึงกัน", "相似度": "ความคล้ายคลึงกัน",
"编辑距离": "แก้ไขระยะทาง" "编辑距离": "แก้ไขระยะทาง",
"对齐": "จัดตำแหน่ง"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "Otomatik ekran fotoğrafı", "自动截图": "Otomatik ekran fotoğrafı",
"模糊匹配": ılgın eşleşme", "模糊匹配": ılgın eşleşme",
"相似度": "Görünüşe benziyor", "相似度": "Görünüşe benziyor",
"编辑距离": "Edit distance" "编辑距离": "Edit distance",
"对齐": "yönlendirme"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "Автоматичний знімок екрана", "自动截图": "Автоматичний знімок екрана",
"模糊匹配": "Незрозуміле збігання", "模糊匹配": "Незрозуміле збігання",
"相似度": "Схожість", "相似度": "Схожість",
"编辑距离": "Змінити відстань" "编辑距离": "Змінити відстань",
"对齐": "вирівнювання"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "Ảnh chụp màn hình tự động", "自动截图": "Ảnh chụp màn hình tự động",
"模糊匹配": "Phù hợp mờ", "模糊匹配": "Phù hợp mờ",
"相似度": "Tương tự", "相似度": "Tương tự",
"编辑距离": "Chỉnh sửa khoảng cách" "编辑距离": "Chỉnh sửa khoảng cách",
"对齐": "Canh lề"
} }

View File

@ -794,5 +794,6 @@
"自动截图": "", "自动截图": "",
"模糊匹配": "", "模糊匹配": "",
"相似度": "", "相似度": "",
"编辑距离": "" "编辑距离": "",
"对齐": ""
} }

View File

@ -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 4) set(VERSION_PATCH 5)
add_library(pch pch.cpp) add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h) target_precompile_headers(pch PUBLIC pch.h)