diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index 6ce6029b..721daf1d 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -1,5 +1,6 @@ import time import os, threading +from qtsymbols import * from traceback import print_exc from myutils.config import ( globalconfig, @@ -19,8 +20,6 @@ from myutils.utils import ( getpostfile, stringfyerror, ) -from PyQt5.QtWidgets import QApplication, QMenu, QAction, QFrame -from PyQt5.QtCore import Qt, QObject, QEvent from myutils.wrapper import threader from gui.showword import searchwordW from myutils.hwnd import getpidexe, ListProcess @@ -723,7 +722,7 @@ class MAINUI: time.sleep(0.5) def setdarktheme(self, widget, dark): - if widget.testAttribute(Qt.WA_TranslucentBackground): + if widget.testAttribute(Qt.WidgetAttribute.WA_TranslucentBackground): return winsharedutils.SetTheme( int(widget.winId()), dark, globalconfig["WindowBackdrop"] @@ -739,7 +738,9 @@ class MAINUI: if self.currentisdark is not None: self.setdarktheme(obj, self.currentisdark) windows.SetProp( - int(obj.winId()), "Magpie.ToolWindow", windows.HANDLE(1) + int(obj.winId()), + "Magpie.WindowType.ToolWindow", + windows.HANDLE(1), ) self.setshowintab_checked(obj) return False @@ -797,12 +798,22 @@ class MAINUI: winsharedutils.showintab(int(widget.winId()), globalconfig["showintab"]) return window_flags = widget.windowFlags() - if Qt.FramelessWindowHint & window_flags == Qt.FramelessWindowHint: + if ( + Qt.WindowType.FramelessWindowHint & window_flags + == Qt.WindowType.FramelessWindowHint + ): return if isinstance(widget, QMenu): return if isinstance(widget, QFrame): return + if ( + isinstance(widget, QWidget) + and widget.parent() is None + and len(widget.children()) == 0 + ): + # combobox的下拉框,然后这个widget会迅速销毁,会导致任务栏闪一下。没别的办法了姑且这样过滤一下 + return winsharedutils.showintab(int(widget.winId()), globalconfig["showintab_sub"]) def inittray(self): diff --git a/LunaTranslator/LunaTranslator/LunaTranslator_main.py b/LunaTranslator/LunaTranslator/LunaTranslator_main.py index ecd3ed70..36a5ab8d 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator_main.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator_main.py @@ -11,7 +11,7 @@ if __name__ == "__main__": ) # win7 no vcredist2015 from myutils.config import _TR, static_data, globalconfig - + sys.path.append("./") sys.path.append("./userconfig") sys.path.insert( @@ -23,16 +23,14 @@ if __name__ == "__main__": import gobject gobject.overridepathexists() + from qtsymbols import * - from PyQt5.QtCore import Qt - from PyQt5.QtWidgets import QApplication - from PyQt5.QtGui import QFont - - QApplication.addLibraryPath( - "./LunaTranslator/runtime/PyQt5/Qt5/plugins" - ) # 中文字符下不能自动加载 - QApplication.setAttribute(Qt.ApplicationAttribute.AA_EnableHighDpiScaling) - QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps) + if isqt5: + QApplication.addLibraryPath( + "./LunaTranslator/runtime/PyQt5/Qt5/plugins" + ) # 中文字符下不能自动加载 + QApplication.setAttribute(Qt.ApplicationAttribute.AA_EnableHighDpiScaling) + QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps) QApplication.setHighDpiScaleFactorRoundingPolicy( Qt.HighDpiScaleFactorRoundingPolicy.PassThrough ) @@ -70,4 +68,4 @@ if __name__ == "__main__": gobject.baseobject = MAINUI() gobject.baseobject.checklang() gobject.baseobject.aa() - app.exit(app.exec_()) + app.exit(app.exec()) diff --git a/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py b/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py index 093e882e..5aabbb73 100644 --- a/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py +++ b/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py @@ -1,20 +1,7 @@ -from PyQt5.QtCore import pyqtSignal -from PyQt5.QtWidgets import ( - QWidget, - QVBoxLayout, - QHBoxLayout, - QLabel, - QLineEdit, - QListView, - QDialogButtonBox, - QApplication, - QPushButton, -) +from qtsymbols import * from winsharedutils import getpidhwndfirst -from PyQt5.QtGui import QStandardItemModel, QStandardItem import functools from myutils.config import globalconfig, _TR -import sys import windows import os from myutils.hwnd import ( @@ -98,7 +85,9 @@ class AttachProcessDialog(closeashidewindow): self.layout2.addWidget(self.windowtextlayoutwidgets[1]) self.processList = QListView() self.buttonBox = QDialogButtonBox() - self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + self.buttonBox.setStandardButtons( + QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel + ) self.layout1.addLayout(self.layout2) self.layout1.addLayout(self.layout3) self.layout1.addWidget(self.processList) @@ -192,11 +181,3 @@ class AttachProcessDialog(closeashidewindow): # return self.close() self.callback(self.selectedp) - - -if __name__ == "__main__": - app = QApplication(sys.argv) - a = AttachProcessDialog() - a.show() - - app.exit(app.exec_()) diff --git a/LunaTranslator/LunaTranslator/gui/codeacceptdialog.py b/LunaTranslator/LunaTranslator/gui/codeacceptdialog.py index cc3e0f5f..186d6af7 100644 --- a/LunaTranslator/LunaTranslator/gui/codeacceptdialog.py +++ b/LunaTranslator/LunaTranslator/gui/codeacceptdialog.py @@ -1,17 +1,5 @@ import functools -from PyQt5.QtWidgets import ( - QCheckBox, - QLabel, - QLineEdit, - QPushButton, - QDialog, - QVBoxLayout, - QHeaderView, -) -from PyQt5.QtWidgets import QHBoxLayout, QTableView -from PyQt5.QtGui import QStandardItem, QStandardItemModel -from PyQt5.QtWidgets import QComboBox -from PyQt5.QtCore import Qt, QSize +from qtsymbols import * from gui.usefulwidget import getspinbox, threebuttons, getlineedit from myutils.utils import checkencoding from myutils.config import globalconfig, _TR, _TRL @@ -49,7 +37,7 @@ class codeacceptdialog(QDialog): itemsaver_.setText(code) def __init__(self, parent) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) title = "接受的编码" self.setWindowTitle(_TR(title)) # self.setWindowModality(Qt.ApplicationModal) @@ -61,7 +49,9 @@ class codeacceptdialog(QDialog): self.model.setHorizontalHeaderLabels(_TRL(["接受的编码"])) self.table = QTableView(self) self.table.setModel(self.model) - self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) + self.table.horizontalHeader().setSectionResizeMode( + QHeaderView.ResizeMode.Stretch + ) row = 0 for code in globalconfig["accept_encoding"]: # 2 diff --git a/LunaTranslator/LunaTranslator/gui/dialog_memory.py b/LunaTranslator/LunaTranslator/gui/dialog_memory.py index 1094520c..e0361deb 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_memory.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_memory.py @@ -1,8 +1,4 @@ -from PyQt5.QtWidgets import QPushButton, QFileDialog -from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QTextEdit, QWidget - -from PyQt5.QtGui import QTextCursor -from PyQt5.QtCore import Qt +from qtsymbols import * from myutils.config import _TR, globalconfig from gui.usefulwidget import saveposwindow from myutils.wrapper import Singleton_close @@ -26,7 +22,8 @@ class dialog_memory(saveposwindow): super().__init__( parent, - flags=Qt.WindowCloseButtonHint | Qt.WindowMinMaxButtonsHint, + flags=Qt.WindowType.WindowCloseButtonHint + | Qt.WindowType.WindowMinMaxButtonsHint, dic=globalconfig, key="memorydialoggeo", ) @@ -42,7 +39,7 @@ class dialog_memory(saveposwindow): except: text = "" self.showtext.insertHtml(text) - self.showtext.moveCursor(QTextCursor.Start) + self.showtext.moveCursor(QTextCursor.MoveOperation.Start) formLayout.addWidget(self.showtext) x = QHBoxLayout() diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index ba779f08..d885342e 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -1,42 +1,12 @@ import time from datetime import datetime, timedelta from gui.specialwidget import ScrollFlow, chartwidget, lazyscrollflow -from PyQt5.QtWidgets import ( - QPushButton, - QDialog, - QVBoxLayout, - QHeaderView, - QFileDialog, - QLineEdit, - QComboBox, - QFormLayout, - QHBoxLayout, - QTableView, - QAbstractItemView, - QLabel, - QTabWidget, - QApplication, - QSizePolicy, - QWidget, - QMenu, - QAction, - QTabBar, -) +from qtsymbols import * import functools, threading from traceback import print_exc import windows -from PyQt5.QtCore import QRect, QSize, Qt, pyqtSignal, QObject import os -from PyQt5.QtGui import ( - QCloseEvent, - QIntValidator, - QResizeEvent, - QPixmap, - QPainter, - QPen, - QStandardItem, - QStandardItemModel, -) + from gui.usefulwidget import ( getsimplecombobox, getspinbox, @@ -144,7 +114,7 @@ class ItemWidget(QWidget): self._lb.setText(file) self._lb.setWordWrap(True) self._lb.setStyleSheet("background-color: rgba(255,255,255, 0);") - self._lb.setAlignment(Qt.AlignCenter) + self._lb.setAlignment(Qt.AlignmentFlag.AlignCenter) layout.addWidget(self._lb) self.setLayout(layout) self.exe = exe @@ -192,10 +162,10 @@ class IMGWidget(QLabel): rate = self.devicePixelRatioF() newpixmap = QPixmap(self.size() * rate) newpixmap.setDevicePixelRatio(rate) - newpixmap.fill(Qt.transparent) + newpixmap.fill(Qt.GlobalColor.transparent) painter = QPainter(newpixmap) - painter.setRenderHint(QPainter.SmoothPixmapTransform) - painter.setRenderHint(QPainter.Antialiasing) + painter.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform) + painter.setRenderHint(QPainter.RenderHint.Antialiasing) painter.drawPixmap(self.getrect(pixmap.size()), pixmap) painter.end() @@ -231,7 +201,7 @@ class CustomTabBar(QTabBar): def mousePressEvent(self, event): index = self.tabAt(event.pos()) - if index == self.count() - 1 and event.button() == Qt.LeftButton: + if index == self.count() - 1 and event.button() == Qt.MouseButton.LeftButton: self.lastclick.emit() else: super().mousePressEvent(event) @@ -246,7 +216,7 @@ class ClickableLabel(QLabel): self._clickable = clickable def mousePressEvent(self, event): - if self._clickable and event.button() == Qt.LeftButton: + if self._clickable and event.button() == Qt.MouseButton.LeftButton: self.clicked.emit() clicked = pyqtSignal() @@ -277,17 +247,17 @@ class tagitem(QWidget): def paintEvent(self, event): painter = QPainter(self) - painter.setRenderHint(QPainter.Antialiasing) + painter.setRenderHint(QPainter.RenderHint.Antialiasing) if self._type == tagitem.TYPE_RAND: - border_color = Qt.black + border_color = Qt.GlobalColor.black elif self._type == tagitem.TYPE_DEVELOPER: - border_color = Qt.red + border_color = Qt.GlobalColor.red elif self._type == tagitem.TYPE_TAG: - border_color = Qt.green + border_color = Qt.GlobalColor.green elif self._type == tagitem.TYPE_USERTAG: - border_color = Qt.blue + border_color = Qt.GlobalColor.blue elif self._type == tagitem.TYPE_EXISTS: - border_color = Qt.yellow + border_color = Qt.GlobalColor.yellow border_width = 1 pen = QPen(border_color) pen.setWidth(border_width) @@ -338,10 +308,12 @@ class TagWidget(QWidget): lambda: self.linepressedenter.emit(self.lineEdit.currentText()) ) - self.lineEdit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) + self.lineEdit.setSizePolicy( + QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Maximum + ) layout.addWidget(self.lineEdit) - self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) + self.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Fixed) self.tag2widget = {} @@ -539,7 +511,7 @@ class browserdialog(saveposwindow): ) ) _topw = QWidget() - _topw.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) + _topw.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed) _topw.setLayout(hlay) layout = QVBoxLayout() layout.setContentsMargins(*(0 for i in range(4))) @@ -620,7 +592,7 @@ class dialog_setting_game(QDialog): return super().closeEvent(a0) def __init__(self, parent, exepath) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) global _global_dialog_setting_game _global_dialog_setting_game = self self.isopened = True @@ -676,7 +648,7 @@ class dialog_setting_game(QDialog): vndbid = QLineEdit(str(savehook_new_data[exepath]["vid"])) vndbid.setValidator(QIntValidator()) - vndbid.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) + vndbid.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed) vndbid.textEdited.connect(functools.partial(vidchangedtask, exepath)) @@ -755,7 +727,7 @@ class dialog_setting_game(QDialog): def selectbackupdir(self, edit): res = QFileDialog.getExistingDirectory( directory=edit.text(), - options=QFileDialog.DontResolveSymlinks, + options=QFileDialog.Option.DontResolveSymlinks, ) if not res: return @@ -885,8 +857,12 @@ class dialog_setting_game(QDialog): self.chart = chart self._timelabel = QLabel() self._wordlabel = QLabel() - self._wordlabel.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) - self._timelabel.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) + self._wordlabel.setSizePolicy( + QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed + ) + self._timelabel.setSizePolicy( + QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed + ) formLayout.addLayout(getboxlayout([QLabel(_TR("文字计数")), self._wordlabel])) formLayout.addLayout(getboxlayout([QLabel(_TR("游戏时间")), self._timelabel])) @@ -1034,7 +1010,7 @@ class dialog_setting_game(QDialog): def getttssetting(self, exepath): _w = QWidget() formLayout = QVBoxLayout() - formLayout.setAlignment(Qt.AlignTop) + formLayout.setAlignment(Qt.AlignmentFlag.AlignTop) _w.setLayout(formLayout) formLayout.addLayout( @@ -1154,11 +1130,13 @@ class dialog_setting_game(QDialog): self.hcmodel = model table = QTableView() - table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) + table.horizontalHeader().setSectionResizeMode( + QHeaderView.ResizeMode.ResizeToContents + ) table.horizontalHeader().setStretchLastSection(True) - # table.setEditTriggers(QAbstractItemView.NoEditTriggers); - table.setSelectionBehavior(QAbstractItemView.SelectRows) - table.setSelectionMode((QAbstractItemView.SingleSelection)) + # table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers); + table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + table.setSelectionMode((QAbstractItemView.SelectionMode.SingleSelection)) table.setWordWrap(False) table.setModel(model) self.hctable = table @@ -1207,7 +1185,7 @@ class dialog_setting_game(QDialog): class dialog_syssetting(QDialog): def __init__(self, parent) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) self.setWindowTitle(_TR("其他设置")) formLayout = QFormLayout(self) formLayout.addRow( @@ -1365,11 +1343,13 @@ class listediter(QDialog): self.hcmodel = model table = QTableView() - table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) + table.horizontalHeader().setSectionResizeMode( + QHeaderView.ResizeMode.ResizeToContents + ) table.horizontalHeader().setStretchLastSection(True) - # table.setEditTriggers(QAbstractItemView.NoEditTriggers); - table.setSelectionBehavior(QAbstractItemView.SelectRows) - table.setSelectionMode((QAbstractItemView.SingleSelection)) + # table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers); + table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + table.setSelectionMode((QAbstractItemView.SelectionMode.SingleSelection)) table.setWordWrap(False) table.setModel(model) self.hctable = table @@ -1447,7 +1427,9 @@ class dialog_savedgame_new(saveposwindow): opendir(self.currentfocuspath) def clicked3_batch(self): - res = QFileDialog.getExistingDirectory(options=QFileDialog.DontResolveSymlinks) + res = QFileDialog.getExistingDirectory( + options=QFileDialog.Option.DontResolveSymlinks + ) if res != "": for _dir, _, _fs in os.walk(res): for _f in _fs: @@ -1460,7 +1442,7 @@ class dialog_savedgame_new(saveposwindow): def clicked3(self): - f = QFileDialog.getOpenFileName(options=QFileDialog.DontResolveSymlinks) + f = QFileDialog.getOpenFileName(options=QFileDialog.Option.DontResolveSymlinks) res = f[0] if res != "": @@ -1556,7 +1538,8 @@ class dialog_savedgame_new(saveposwindow): def __init__(self, parent) -> None: super().__init__( parent, - flags=Qt.WindowMinMaxButtonsHint | Qt.WindowCloseButtonHint, + flags=Qt.WindowType.WindowMinMaxButtonsHint + | Qt.WindowType.WindowCloseButtonHint, dic=globalconfig, key="savegamedialoggeo", ) @@ -1614,7 +1597,7 @@ class dialog_savedgame_new(saveposwindow): layout.addWidget(self.tagswidget) formLayout.addLayout(layout) self.flow = lazyscrollflow() - self.setContextMenuPolicy(Qt.CustomContextMenu) + self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.customContextMenuRequested.connect(self.showmenu) formLayout.addWidget(self.flow) self.formLayout = formLayout @@ -1687,7 +1670,7 @@ class dialog_savedgame_new(saveposwindow): if save: self.savebutton.append((button5, exists)) button5.clicked.connect(callback) - button5.setFocusPolicy(Qt.NoFocus) + button5.setFocusPolicy(Qt.FocusPolicy.NoFocus) self.buttonlayout.addWidget(button5) return button5 diff --git a/LunaTranslator/LunaTranslator/gui/edittext.py b/LunaTranslator/LunaTranslator/gui/edittext.py index ad57ac2b..c9b763f6 100644 --- a/LunaTranslator/LunaTranslator/gui/edittext.py +++ b/LunaTranslator/LunaTranslator/gui/edittext.py @@ -1,16 +1,4 @@ -from PyQt5.QtGui import QCursor -from PyQt5.QtWidgets import ( - QPlainTextEdit, - QAction, - QMenu, - QHBoxLayout, - QMainWindow, - QLineEdit, - QWidget, - QPushButton, - QVBoxLayout, -) -from PyQt5.QtCore import Qt, pyqtSignal, QPoint, QSize +from qtsymbols import * import qtawesome import threading, windows import gobject, time @@ -37,7 +25,7 @@ class edittext(closeashidewindow): self.textOutput = QPlainTextEdit(self) - self.textOutput.setContextMenuPolicy(Qt.CustomContextMenu) + self.textOutput.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.textOutput.customContextMenuRequested.connect(self.showmenu) # self.setCentralWidget(self.textOutput) @@ -106,8 +94,8 @@ class edittrans(QMainWindow): swsignal = pyqtSignal() def __init__(self, parent): - super().__init__(parent, Qt.FramelessWindowHint) - self.setAttribute(Qt.WA_TranslucentBackground) + super().__init__(parent, Qt.WindowType.FramelessWindowHint) + self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) self.setStyleSheet( "background-color: rgba(%s, %s, %s, %s)" % ( diff --git a/LunaTranslator/LunaTranslator/gui/inputdialog.py b/LunaTranslator/LunaTranslator/gui/inputdialog.py index 96ee6c3c..6f934379 100644 --- a/LunaTranslator/LunaTranslator/gui/inputdialog.py +++ b/LunaTranslator/LunaTranslator/gui/inputdialog.py @@ -1,23 +1,5 @@ import functools -from PyQt5.QtWidgets import ( - QDialogButtonBox, - QDialog, - QHeaderView, - QComboBox, - QFormLayout, - QDoubleSpinBox, - QSpinBox, - QHBoxLayout, - QLineEdit, - QFileDialog, - QPushButton, - QLabel, - QTableView, - QVBoxLayout, -) -from PyQt5.QtCore import Qt, QSize -from PyQt5.QtGui import QCloseEvent, QStandardItem, QStandardItemModel - +from qtsymbols import * import qtawesome, importlib from myutils.config import globalconfig, _TR, _TRL from gui.usefulwidget import MySwitch, selectcolor, getsimpleswitch, threebuttons @@ -37,7 +19,7 @@ class noundictconfigdialog1(QDialog): ) def __init__(self, parent, configdict, configkey, title, label) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) self.setWindowTitle(_TR(title)) # self.setWindowModality(Qt.ApplicationModal) @@ -49,9 +31,11 @@ class noundictconfigdialog1(QDialog): table = QTableView(self) table.setModel(self.model) - table.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch) - table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch) - table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents) + table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.Stretch) + table.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch) + table.horizontalHeader().setSectionResizeMode( + 0, QHeaderView.ResizeMode.ResizeToContents + ) self.table = table for row, item in enumerate(configdict[configkey]): @@ -127,7 +111,7 @@ class noundictconfigdialog1(QDialog): @Singleton class regexedit(QDialog): def __init__(self, parent, regexlist) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) self.regexlist = regexlist self.setWindowTitle(_TR("正则匹配")) @@ -138,7 +122,7 @@ class regexedit(QDialog): table = QTableView(self) table.setModel(self.model) - table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) + table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) self.table = table for row, regex in enumerate(regexlist): @@ -197,7 +181,7 @@ def autoinitdialog_items(dic): @Singleton class autoinitdialog(QDialog): def __init__(self, parent, title, width, lines, _=None) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) self.setWindowTitle(_TR(title)) self.resize(QSize(width, 10)) @@ -262,7 +246,10 @@ class autoinitdialog(QDialog): functools.partial(dd.__setitem__, key) ) elif line["type"] == "okcancel": - lineW = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + lineW = QDialogButtonBox( + QDialogButtonBox.StandardButton.Ok + | QDialogButtonBox.StandardButton.Cancel + ) lineW.rejected.connect(self.close) lineW.accepted.connect( functools.partial( @@ -270,8 +257,10 @@ class autoinitdialog(QDialog): ) ) - lineW.button(QDialogButtonBox.Ok).setText(_TR("确定")) - lineW.button(QDialogButtonBox.Cancel).setText(_TR("取消")) + lineW.button(QDialogButtonBox.StandardButton.Ok).setText(_TR("确定")) + lineW.button(QDialogButtonBox.StandardButton.Cancel).setText( + _TR("取消") + ) elif line["type"] == "lineedit": try: lineW = QLineEdit(dd[key]) @@ -344,7 +333,7 @@ def getsomepath1( @Singleton class multicolorset(QDialog): def __init__(self, parent) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) self.setWindowTitle(_TR("颜色设置")) self.resize(QSize(300, 10)) formLayout = QFormLayout(self) # 配置layout @@ -411,7 +400,7 @@ class postconfigdialog_(QDialog): self.configdict[self.key] = newdict def __init__(self, parent, configdict, title) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) print(title) self.setWindowTitle(_TR(title)) # self.setWindowModality(Qt.ApplicationModal) @@ -438,8 +427,8 @@ class postconfigdialog_(QDialog): table = QTableView(self) table.setModel(model) table.setWordWrap(False) - table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) - # table.setEditTriggers(QAbstractItemView.NoEditTriggers) + table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) + # table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) # table.clicked.connect(self.show_info) button = threebuttons() diff --git a/LunaTranslator/LunaTranslator/gui/languageset.py b/LunaTranslator/LunaTranslator/gui/languageset.py index 5ed24625..ee5aa3fc 100644 --- a/LunaTranslator/LunaTranslator/gui/languageset.py +++ b/LunaTranslator/LunaTranslator/gui/languageset.py @@ -1,7 +1,4 @@ -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QVBoxLayout, QComboBox, QPushButton, QDialog -from PyQt5.QtGui import QFont -from PyQt5.QtCore import Qt, pyqtSignal +from qtsymbols import * import qtawesome @@ -13,7 +10,7 @@ class languageset(QDialog): def __init__(self, language_list): super(languageset, self).__init__( - None, Qt.WindowStaysOnTopHint + None, Qt.WindowType.WindowStaysOnTopHint ) # 设置为顶级窗口,无边框 self.setWindowIcon(qtawesome.icon("fa.language")) self.setMinimumSize(400, 100) diff --git a/LunaTranslator/LunaTranslator/gui/pretransfile.py b/LunaTranslator/LunaTranslator/gui/pretransfile.py index 76b1f34b..1ee3476f 100644 --- a/LunaTranslator/LunaTranslator/gui/pretransfile.py +++ b/LunaTranslator/LunaTranslator/gui/pretransfile.py @@ -1,15 +1,4 @@ -from PyQt5.QtWidgets import ( - QComboBox, - QPushButton, - QFormLayout, - QHBoxLayout, - QDialogButtonBox, - QDialog, - QLineEdit, - QFileDialog, -) - -from PyQt5.QtCore import Qt, QSize +from qtsymbols import * import sqlite3, os import json from traceback import print_exc @@ -54,7 +43,7 @@ def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): _collect.append(_) collect = _collect - dialog = QDialog(self, Qt.WindowCloseButtonHint) # 自定义一个dialog + dialog = QDialog(self, Qt.WindowType.WindowCloseButtonHint) # 自定义一个dialog dialog.setWindowTitle(_TR("导出翻译记录为json文件")) dialog.resize(QSize(800, 10)) formLayout = QFormLayout(dialog) # 配置layout @@ -85,7 +74,9 @@ def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): if targetjson is None: formLayout.addRow(_TR("保存路径"), hori) - button = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + button = QDialogButtonBox( + QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel + ) formLayout.addRow(button) button.rejected.connect(dialog.close) @@ -114,8 +105,8 @@ def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): dialog.close() button.accepted.connect(functools.partial(__savefunction, targetjson, existsmerge)) - button.button(QDialogButtonBox.Ok).setText(_TR("确定")) - button.button(QDialogButtonBox.Cancel).setText(_TR("取消")) + button.button(QDialogButtonBox.StandardButton.Ok).setText(_TR("确定")) + button.button(QDialogButtonBox.StandardButton.Cancel).setText(_TR("取消")) dialog.show() diff --git a/LunaTranslator/LunaTranslator/gui/rangeselect.py b/LunaTranslator/LunaTranslator/gui/rangeselect.py index 80331b2c..df3433f0 100644 --- a/LunaTranslator/LunaTranslator/gui/rangeselect.py +++ b/LunaTranslator/LunaTranslator/gui/rangeselect.py @@ -1,11 +1,4 @@ -from PyQt5.QtWidgets import ( - QMenu, - QMainWindow, - QLabel, - QAction, -) -from PyQt5.QtGui import QPainter, QPen, QColor, QCursor -from PyQt5.QtCore import Qt, QPoint, QRect +from qtsymbols import * from myutils.config import _TR from myutils.config import globalconfig from gui.resizeablemainwindow import Mainw @@ -23,9 +16,13 @@ class rangeadjust(Mainw): self.drag_label.setGeometry(0, 0, 4000, 2000) self._isTracking = False self._rect = None - self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint | Qt.Tool) - self.setAttribute(Qt.WA_TranslucentBackground) - self.setContextMenuPolicy(Qt.CustomContextMenu) + self.setWindowFlags( + Qt.WindowType.WindowStaysOnTopHint + | Qt.WindowType.FramelessWindowHint + | Qt.WindowType.Tool + ) + self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) + self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.customContextMenuRequested.connect(self.showmenu) for s in self.cornerGrips: s.raise_() @@ -51,12 +48,12 @@ class rangeadjust(Mainw): self.move(self.pos() + self._endPos) def mousePressEvent(self, e): - if e.button() == Qt.LeftButton: + if e.button() == Qt.MouseButton.LeftButton: self._isTracking = True self._startPos = QPoint(e.x(), e.y()) def mouseReleaseEvent(self, e): - if e.button() == Qt.LeftButton: + if e.button() == Qt.MouseButton.LeftButton: self._isTracking = False self._startPos = None self._endPos = None @@ -122,13 +119,13 @@ class rangeselct(QMainWindow): super(rangeselct, self).__init__(parent) self.setWindowFlags( - Qt.FramelessWindowHint | Qt.Tool + Qt.WindowType.FramelessWindowHint | Qt.WindowType.Tool ) # |Qt.WindowStaysOnTopHint ) self.rectlabel = QLabel(self) - # self.setAttribute(Qt.WA_TranslucentBackground) + # self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) self.setWindowOpacity(0.5) self.setMouseTracking(True) - self.setCursor(Qt.CrossCursor) + self.setCursor(Qt.CursorShape.CrossCursor) self.reset() def reset(self): @@ -180,7 +177,7 @@ class rangeselct(QMainWindow): self.rectlabel.setGeometry(QRect(_sp, _ep)) def mousePressEvent(self, event): - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: if self.clickrelease: self.clickrelease = False self.mouseReleaseEvent(event) @@ -216,7 +213,7 @@ class rangeselct(QMainWindow): return ((x1, y1), (x2, y2)) def mouseReleaseEvent(self, event): - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self.end_point = event.pos() self.__end = windows.GetCursorPos() diff --git a/LunaTranslator/LunaTranslator/gui/resizeablemainwindow.py b/LunaTranslator/LunaTranslator/gui/resizeablemainwindow.py index 205f19b8..279fe808 100644 --- a/LunaTranslator/LunaTranslator/gui/resizeablemainwindow.py +++ b/LunaTranslator/LunaTranslator/gui/resizeablemainwindow.py @@ -1,20 +1,20 @@ -from PyQt5 import QtCore, QtWidgets +from qtsymbols import * -class SideGrip(QtWidgets.QWidget): +class SideGrip(QWidget): def __init__(self, parent, edge): - QtWidgets.QWidget.__init__(self, parent) - if edge == QtCore.Qt.LeftEdge: - self.setCursor(QtCore.Qt.SizeHorCursor) + QWidget.__init__(self, parent) + if edge == Qt.Edge.LeftEdge: + self.setCursor(Qt.CursorShape.SizeHorCursor) self.resizeFunc = self.resizeLeft - elif edge == QtCore.Qt.TopEdge: - self.setCursor(QtCore.Qt.SizeVerCursor) + elif edge == Qt.Edge.TopEdge: + self.setCursor(Qt.CursorShape.SizeVerCursor) self.resizeFunc = self.resizeTop - elif edge == QtCore.Qt.RightEdge: - self.setCursor(QtCore.Qt.SizeHorCursor) + elif edge == Qt.Edge.RightEdge: + self.setCursor(Qt.CursorShape.SizeHorCursor) self.resizeFunc = self.resizeRight else: - self.setCursor(QtCore.Qt.SizeVerCursor) + self.setCursor(Qt.CursorShape.SizeVerCursor) self.resizeFunc = self.resizeBottom self.mousePos = None @@ -43,7 +43,7 @@ class SideGrip(QtWidgets.QWidget): window.resize(window.width(), height) def mousePressEvent(self, event): - if event.button() == QtCore.Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self.mousePos = event.pos() def mouseMoveEvent(self, event): @@ -55,24 +55,24 @@ class SideGrip(QtWidgets.QWidget): self.mousePos = None -class Mainw(QtWidgets.QMainWindow): +class Mainw(QMainWindow): _gripSize = 8 def __init__(self, x): - QtWidgets.QMainWindow.__init__(self, x) + QMainWindow.__init__(self, x) - self.setWindowFlags(QtCore.Qt.FramelessWindowHint) + self.setWindowFlags(Qt.WindowType.FramelessWindowHint) self.sideGrips = [ - SideGrip(self, QtCore.Qt.LeftEdge), - SideGrip(self, QtCore.Qt.TopEdge), - SideGrip(self, QtCore.Qt.RightEdge), - SideGrip(self, QtCore.Qt.BottomEdge), + SideGrip(self, Qt.Edge.LeftEdge), + SideGrip(self, Qt.Edge.TopEdge), + SideGrip(self, Qt.Edge.RightEdge), + SideGrip(self, Qt.Edge.BottomEdge), ] # corner grips should be "on top" of everything, otherwise the side grips # will take precedence on mouse events, so we are adding them *after*; # alternatively, widget.raise_() can be used - self.cornerGrips = [QtWidgets.QSizeGrip(self) for i in range(4)] + self.cornerGrips = [QSizeGrip(self) for i in range(4)] for s in self.cornerGrips: s.setStyleSheet(""" background-color: transparent; """) @@ -96,20 +96,18 @@ class Mainw(QtWidgets.QMainWindow): ) # top left - self.cornerGrips[0].setGeometry( - QtCore.QRect(outRect.topLeft(), inRect.topLeft()) - ) + self.cornerGrips[0].setGeometry(QRect(outRect.topLeft(), inRect.topLeft())) # top right self.cornerGrips[1].setGeometry( - QtCore.QRect(outRect.topRight(), inRect.topRight()).normalized() + QRect(outRect.topRight(), inRect.topRight()).normalized() ) # bottom right self.cornerGrips[2].setGeometry( - QtCore.QRect(inRect.bottomRight(), outRect.bottomRight()) + QRect(inRect.bottomRight(), outRect.bottomRight()) ) # bottom left self.cornerGrips[3].setGeometry( - QtCore.QRect(outRect.bottomLeft(), inRect.bottomLeft()).normalized() + QRect(outRect.bottomLeft(), inRect.bottomLeft()).normalized() ) # left edge @@ -126,11 +124,11 @@ class Mainw(QtWidgets.QMainWindow): ) def resizeEvent(self, event): - QtWidgets.QMainWindow.resizeEvent(self, event) + QMainWindow.resizeEvent(self, event) self.updateGrips() -# app = QtWidgets.QApplication([]) +# app = QApplication([]) # m = Mainw() # m.show() # m.resize(240, 160) diff --git a/LunaTranslator/LunaTranslator/gui/selecthook.py b/LunaTranslator/LunaTranslator/gui/selecthook.py index f030e3d8..c7a5e1eb 100644 --- a/LunaTranslator/LunaTranslator/gui/selecthook.py +++ b/LunaTranslator/LunaTranslator/gui/selecthook.py @@ -1,33 +1,7 @@ import functools, json, windows from traceback import print_exc -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import ( - QSizePolicy, - QWidget, - QHBoxLayout, - QDialog, - QAction, - QVBoxLayout, - QMenu, - QPlainTextEdit, - QTabWidget, - QComboBox, - QLineEdit, - QPushButton, - QTableView, - QAbstractItemView, - QRadioButton, - QButtonGroup, - QHeaderView, - QCheckBox, - QSpinBox, - QFormLayout, - QLabel, -) +from qtsymbols import * from myutils.config import savehook_new_data, static_data -from PyQt5.QtGui import QStandardItem, QStandardItemModel -from PyQt5.QtGui import QTextCursor -from PyQt5.QtCore import Qt, pyqtSignal, QModelIndex, QPoint import qtawesome import subprocess import winsharedutils @@ -221,7 +195,7 @@ class searchhookparam(QDialog): return space_hex_str def __init__(self, parent) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) windows.SetWindowPos( int(int(self.winId())), windows.HWND_TOPMOST, @@ -450,17 +424,17 @@ class hookselect(closeashidewindow): ) self.tttable.horizontalHeader().setSectionResizeMode( - 2, QHeaderView.Interactive + 2, QHeaderView.ResizeMode.Interactive ) self.tttable.horizontalHeader().setSectionResizeMode( - 3, QHeaderView.Interactive + 3, QHeaderView.ResizeMode.Interactive ) self.tttable.horizontalHeader().setSectionResizeMode( - 0, QHeaderView.ResizeToContents + 0, QHeaderView.ResizeMode.ResizeToContents ) self.tttable.horizontalHeader().setSectionResizeMode( - 1, QHeaderView.ResizeToContents + 1, QHeaderView.ResizeMode.ResizeToContents ) else: self.ttCombomodelmodel.setHorizontalHeaderLabels( @@ -468,14 +442,14 @@ class hookselect(closeashidewindow): ) self.tttable.horizontalHeader().setSectionResizeMode( - 1, QHeaderView.Interactive + 1, QHeaderView.ResizeMode.Interactive ) self.tttable.horizontalHeader().setSectionResizeMode( - 2, QHeaderView.Interactive + 2, QHeaderView.ResizeMode.Interactive ) self.tttable.horizontalHeader().setSectionResizeMode( - 0, QHeaderView.ResizeToContents + 0, QHeaderView.ResizeMode.ResizeToContents ) if hc[0] == "E": @@ -544,7 +518,9 @@ class hookselect(closeashidewindow): hlay.addWidget(label) label.setStyleSheet("background-color: rgba(255, 255, 255, 0)") checkbtn = QPushButton() - checkbtn.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) + checkbtn.setSizePolicy( + QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Preferred + ) def _t(tp): _isusing = gobject.baseobject.textsource.checkisusingembed( @@ -610,20 +586,22 @@ class hookselect(closeashidewindow): self.tttable = QTableView() self.tttable.setModel(self.ttCombomodelmodel) - # self.tttable .horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) + # self.tttable .horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) self.tttable.horizontalHeader().setStretchLastSection(True) - self.tttable.setSelectionBehavior(QAbstractItemView.SelectRows) - self.tttable.setSelectionMode(QAbstractItemView.SingleSelection) - self.tttable.setEditTriggers(QAbstractItemView.NoEditTriggers) + self.tttable.setSelectionBehavior( + QAbstractItemView.SelectionBehavior.SelectRows + ) + self.tttable.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) + self.tttable.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) self.tttable.doubleClicked.connect(self.table1doubleclicked) self.tttable.clicked.connect(self.ViewThread) # self.tttable.setFont(font) self.vboxlayout.addWidget(self.tttable) - # table.setEditTriggers(QAbstractItemView.NoEditTriggers) + # table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) # table.clicked.connect(self.show_info) - self.tttable.setContextMenuPolicy(Qt.CustomContextMenu) + self.tttable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.tttable.customContextMenuRequested.connect(self.showmenu) # self.ttCombo.setMaxVisibleItems(50) @@ -671,11 +649,13 @@ class hookselect(closeashidewindow): self.tttable2 = QTableView(self) self.tttable2.setModel(self.ttCombomodelmodel2) - # self.tttable2 .horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) + # self.tttable2 .horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents) self.tttable2.horizontalHeader().setStretchLastSection(True) - self.tttable2.setSelectionBehavior(QAbstractItemView.SelectRows) - self.tttable2.setSelectionMode(QAbstractItemView.SingleSelection) - self.tttable2.setEditTriggers(QAbstractItemView.NoEditTriggers) + self.tttable2.setSelectionBehavior( + QAbstractItemView.SelectionBehavior.SelectRows + ) + self.tttable2.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) + self.tttable2.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) self.tttable2.clicked.connect(self.ViewThread2) self.vboxlayout.addWidget(self.tttable2) @@ -705,7 +685,7 @@ class hookselect(closeashidewindow): self.sysOutput.setReadOnly(True) self.tabwidget = QTabWidget() - self.tabwidget.setTabPosition(QTabWidget.East) + self.tabwidget.setTabPosition(QTabWidget.TabPosition.East) self.tabwidget.addTab(self.textOutput, _TR("文本")) self.tabwidget.addTab(self.sysOutput, _TR("系统")) @@ -962,7 +942,7 @@ class hookselect(closeashidewindow): self.textOutput.setPlainText( gobject.baseobject.textsource.QueryThreadHistory(tp) ) - self.textOutput.moveCursor(QTextCursor.End) + self.textOutput.moveCursor(QTextCursor.MoveOperation.End) except: print_exc() diff --git a/LunaTranslator/LunaTranslator/gui/settin.py b/LunaTranslator/LunaTranslator/gui/settin.py index 36af9eb0..20848c26 100644 --- a/LunaTranslator/LunaTranslator/gui/settin.py +++ b/LunaTranslator/LunaTranslator/gui/settin.py @@ -1,14 +1,4 @@ -from PyQt5.QtCore import pyqtSignal, Qt, QSize -from PyQt5.QtWidgets import ( - QWidget, - QListWidget, - QHBoxLayout, - QListWidgetItem, - QMenu, - QAction, -) -from PyQt5.QtGui import QFont, QFontMetrics -from PyQt5.QtWidgets import QTabWidget +from qtsymbols import * import qtawesome, gobject import threading, windows, winsharedutils from myutils.config import globalconfig, _TR @@ -55,7 +45,7 @@ class TabWidget(QWidget): self.titles.append(title) self.tab_widget.addTab(widget, title) item = QListWidgetItem(title) - item.setTextAlignment(Qt.AlignCenter) + item.setTextAlignment(Qt.AlignmentFlag.AlignCenter) item.setSizeHint(QSize(self.tab_widget.width(), 50)) self.list_widget.addItem(item) if self.idx == 0: @@ -135,7 +125,7 @@ class Settin(closeashidewindow): fn.setFamily(globalconfig["settingfonttype"]) fm = QFontMetrics(fn) for title in self.tab_widget.titles: - width = max(fm.width(title), width) + width = max(fm.size(0, title).width(), width) width += 100 self.tab_widget.list_widget.setFixedWidth(width) self.list_width = width diff --git a/LunaTranslator/LunaTranslator/gui/setting_proxy.py b/LunaTranslator/LunaTranslator/gui/setting_proxy.py index d7e9c1e7..6761adb3 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_proxy.py +++ b/LunaTranslator/LunaTranslator/gui/setting_proxy.py @@ -1,4 +1,4 @@ -from PyQt5.QtWidgets import QLineEdit, QPushButton +from qtsymbols import * from myutils.config import _TR from myutils.config import globalconfig from myutils.utils import splittranslatortypes @@ -13,7 +13,7 @@ from gui.usefulwidget import ( import os -def getall(self, l, item="fanyi", name=""): +def getall(l, item="fanyi", name=""): grids = [] i = 0 line = [] @@ -29,6 +29,7 @@ def getall(self, l, item="fanyi", name=""): line += [ (globalconfig[item][fanyi]["name"], 6), getsimpleswitch(globalconfig[item][fanyi], "useproxy", default=True), + "", ] if i % 3 == 0: grids.append(line) @@ -72,14 +73,9 @@ def setTab_proxy_lazy(self): ] lixians, pre, mianfei, develop, shoufei = splittranslatortypes() - mianfei = getall( - self, l=mianfei, item="fanyi", name="./Lunatranslator/translator/%s.py" - ) - shoufei = getall( - self, l=shoufei, item="fanyi", name="./Lunatranslator/translator/%s.py" - ) + mianfei = getall(l=mianfei, item="fanyi", name="./Lunatranslator/translator/%s.py") + shoufei = getall(l=shoufei, item="fanyi", name="./Lunatranslator/translator/%s.py") ocrs = getall( - self, l=set(globalconfig["ocr"].keys()) - set(["local", "windowsocr"]), item="ocr", name="./Lunatranslator/ocrengines/%s.py", diff --git a/LunaTranslator/LunaTranslator/gui/settingpage1.py b/LunaTranslator/LunaTranslator/gui/settingpage1.py index 77b6231f..2e26d4d5 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage1.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage1.py @@ -1,15 +1,5 @@ import functools, os, windows, json -from PyQt5.QtGui import QFont -from PyQt5.QtCore import Qt, QSize -from PyQt5.QtWidgets import ( - QFontComboBox, - QDialog, - QLabel, - QComboBox, - QFileDialog, - QFormLayout, - QDialogButtonBox, -) +from qtsymbols import * from gui.pretransfile import sqlite2json2 from gui.settingpage_ocr import getocrgrid from myutils.config import globalconfig, _TR, _TRL, savehook_new_data, savehook_new_list @@ -172,7 +162,7 @@ def doexportchspatch(exe, realgame): def getunknowgameexe(self): - dialog = QDialog(self, Qt.WindowCloseButtonHint) # 自定义一个dialog + dialog = QDialog(self, Qt.WindowType.WindowCloseButtonHint) # 自定义一个dialog dialog.setWindowTitle(_TR("选择游戏")) dialog.resize(QSize(800, 10)) formLayout = QFormLayout(dialog) @@ -183,12 +173,14 @@ def getunknowgameexe(self): formLayout.addRow(_TR("选择游戏"), combo) - button = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + button = QDialogButtonBox( + QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel + ) formLayout.addRow(button) button.rejected.connect(dialog.close) button.accepted.connect(dialog.accept) - button.button(QDialogButtonBox.Ok).setText(_TR("确定")) - button.button(QDialogButtonBox.Cancel).setText(_TR("取消")) + button.button(QDialogButtonBox.StandardButton.Ok).setText(_TR("确定")) + button.button(QDialogButtonBox.StandardButton.Cancel).setText(_TR("取消")) if dialog.exec(): return savehook_new_list[combo.currentIndex()] @@ -241,7 +233,7 @@ def gethookembedgrid(self): except: pass - self.gamefont_comboBox.activated[str].connect(callback) + self.gamefont_comboBox.currentTextChanged.connect(callback) self.gamefont_comboBox.setCurrentFont( QFont(globalconfig["embedded"]["changefont_font"]) ) diff --git a/LunaTranslator/LunaTranslator/gui/settingpage2.py b/LunaTranslator/LunaTranslator/gui/settingpage2.py index 73eac3c3..afe803de 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage2.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage2.py @@ -1,4 +1,4 @@ -from PyQt5.QtWidgets import QPushButton, QLabel +from qtsymbols import * import functools, gobject from myutils.config import globalconfig, translatorsetting @@ -243,7 +243,7 @@ def setTabTwo_lazy(self): ], [ ("端口号", 8), - (getspinbox(0, 65535, globalconfig, "debugport"), 3), + (getspinbox(0, 65535, globalconfig, "debugport"), 4), ], [(self.statuslabel, 16)], [], diff --git a/LunaTranslator/LunaTranslator/gui/settingpage7.py b/LunaTranslator/LunaTranslator/gui/settingpage7.py index 2a7d8fd4..a76f6b74 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage7.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage7.py @@ -1,14 +1,5 @@ import functools - -from PyQt5.QtWidgets import ( - QHBoxLayout, - QPlainTextEdit, - QHBoxLayout, - QWidget, - QMenu, - QAction, -) -from PyQt5.QtCore import Qt, QPoint +from qtsymbols import * from traceback import print_exc from myutils.config import ( globalconfig, @@ -241,7 +232,7 @@ def setTab7_lazy(self): def __(): _w = makescroll(makegrid(grids, True, savelist, savelay)) - _w.setContextMenuPolicy(Qt.CustomContextMenu) + _w.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) def showmenu(p: QPoint): diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_about.py b/LunaTranslator/LunaTranslator/gui/settingpage_about.py index eb68cc08..b39e02a9 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_about.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_about.py @@ -1,6 +1,4 @@ -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QPixmap, QImage -from PyQt5.QtWidgets import QLabel, QProgressBar +from qtsymbols import * from gui.usefulwidget import ( getsimpleswitch, getsimplecombobox, @@ -59,13 +57,17 @@ def setTab_about_dicrect(self): self.versionlabel = QLabel() self.versionlabel.setOpenExternalLinks(True) - self.versionlabel.setTextInteractionFlags(Qt.LinksAccessibleByMouse) + self.versionlabel.setTextInteractionFlags( + Qt.TextInteractionFlag.LinksAccessibleByMouse + ) self.versiontextsignal.connect(lambda x: self.versionlabel.setText(x)) self.downloadprogress = QProgressBar() self.downloadprogress.setRange(0, 10000) - self.downloadprogress.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) + self.downloadprogress.setAlignment( + Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter + ) self.progresssignal.connect(lambda text, val: updateprogress(self, text, val)) getversion(self) @@ -164,8 +166,8 @@ def setTab_aboutlazy(self): img = img.scaled( 600, 600, - Qt.KeepAspectRatio, - Qt.SmoothTransformation, + Qt.AspectRatioMode.KeepAspectRatio, + Qt.TransformationMode.SmoothTransformation, ) lb.setPixmap(img) shuominggrid += [[(lb, 0)]] diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_quick.py b/LunaTranslator/LunaTranslator/gui/settingpage_quick.py index e14f5949..bcebbedc 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_quick.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_quick.py @@ -3,7 +3,7 @@ from myutils.config import globalconfig, _TR from myutils.winsyshotkey import SystemHotkey, registerException import winsharedutils import gobject, windows -from PyQt5.QtWidgets import QLabel +from qtsymbols import * from gui.usefulwidget import ( getsimpleswitch, getsimplekeyseq, diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_tts.py b/LunaTranslator/LunaTranslator/gui/settingpage_tts.py index 86e8ace2..e5909950 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_tts.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_tts.py @@ -1,6 +1,5 @@ import functools - -from PyQt5.QtWidgets import QComboBox +from qtsymbols import * from gui.inputdialog import autoinitdialog_items, noundictconfigdialog1, autoinitdialog from myutils.config import globalconfig, _TRL import os, functools diff --git a/LunaTranslator/LunaTranslator/gui/settingpage_xianshishezhi.py b/LunaTranslator/LunaTranslator/gui/settingpage_xianshishezhi.py index 16f74a59..b7099840 100644 --- a/LunaTranslator/LunaTranslator/gui/settingpage_xianshishezhi.py +++ b/LunaTranslator/LunaTranslator/gui/settingpage_xianshishezhi.py @@ -1,17 +1,9 @@ import functools -from PyQt5.QtGui import QFont - -from PyQt5.QtWidgets import QTableView, QAbstractItemView -from PyQt5.QtWidgets import QHeaderView -from PyQt5.QtCore import Qt - -from PyQt5.QtGui import QStandardItem, QStandardItemModel -from PyQt5.QtWidgets import QLabel, QSlider, QFontComboBox, QDialog, QGridLayout +from qtsymbols import * from gui.inputdialog import multicolorset from myutils.config import globalconfig, _TR, _TRL, magpie_config, static_data from myutils.wrapper import Singleton import qtawesome, gobject, json -from winsharedutils import showintab from gui.inputdialog import getsomepath1 from gui.usefulwidget import ( getsimplecombobox, @@ -179,7 +171,7 @@ def createbuttonwidget(self): class dialog_selecticon(QDialog): def __init__(self, parent, dict, key, _nouse_for_click_arg) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) self.dict = dict self.key = key self.setWindowTitle(_TR("选择图标")) @@ -216,7 +208,7 @@ def setTabThree_lazy(self): self.horizontal_slider = QSlider() self.horizontal_slider.setMaximum(100) self.horizontal_slider.setMinimum(1) - self.horizontal_slider.setOrientation(Qt.Horizontal) + self.horizontal_slider.setOrientation(Qt.Orientation.Horizontal) self.horizontal_slider.setValue(0) self.horizontal_slider.setValue(globalconfig["transparent"]) self.horizontal_slider.valueChanged.connect( @@ -228,7 +220,7 @@ def setTabThree_lazy(self): self.horizontal_slider_tool = QSlider() self.horizontal_slider_tool.setMaximum(100) self.horizontal_slider_tool.setMinimum(1) - self.horizontal_slider_tool.setOrientation(Qt.Horizontal) + self.horizontal_slider_tool.setOrientation(Qt.Orientation.Horizontal) self.horizontal_slider_tool.setValue(0) self.horizontal_slider_tool.setValue(globalconfig["transparent_tool"]) self.horizontal_slider_tool.valueChanged.connect( @@ -240,12 +232,12 @@ def setTabThree_lazy(self): ) self.font_comboBox = QFontComboBox() - self.font_comboBox.activated[str].connect( + self.font_comboBox.currentTextChanged.connect( lambda x: globalconfig.__setitem__("fonttype", x) ) self.font_comboBox.setCurrentFont(QFont(globalconfig["fonttype"])) self.font_comboBox2 = QFontComboBox() - self.font_comboBox2.activated[str].connect( + self.font_comboBox2.currentTextChanged.connect( lambda x: globalconfig.__setitem__("fonttype2", x) ) self.font_comboBox2.setCurrentFont(QFont(globalconfig["fonttype2"])) @@ -256,29 +248,27 @@ def setTabThree_lazy(self): globalconfig.__setitem__("settingfonttype", x) gobject.baseobject.setcommonstylesheet() - self.sfont_comboBox.activated[str].connect(callback) + self.sfont_comboBox.currentTextChanged.connect(callback) self.sfont_comboBox.setCurrentFont(QFont(globalconfig["settingfonttype"])) textgrid = [ + [("原文字体", 3), (self.font_comboBox, 6), ("", 5)], [ - ("原文字体", 3), - (self.font_comboBox, 5), - "", ("译文字体", 3), - (self.font_comboBox2, 5), + (self.font_comboBox2, 6), ], [ ("字体大小", 3), - (self.fontSize_spinBox, 2), + (self.fontSize_spinBox, 3), "", ("额外的行间距", 3), - (getspinbox(-100, 100, globalconfig, "extra_space"), 2), + (getspinbox(-100, 100, globalconfig, "extra_space"), 3), ], [ - ("居中显示", 4), + ("居中显示", 5), getsimpleswitch(globalconfig, "showatcenter"), "", - ("加粗字体", 4), + ("加粗字体", 5), getsimpleswitch(globalconfig, "showbold"), ], [ @@ -301,11 +291,11 @@ def setTabThree_lazy(self): globalconfig, "zitiyangshi2", ), - 5, + 6, ), ], [ - ("特殊字体样式填充颜色", 4), + ("特殊字体样式填充颜色", 5), getcolorbutton( globalconfig, "miaobiancolor", @@ -323,7 +313,7 @@ def setTabThree_lazy(self): getspinbox( 0.1, 100, globalconfig, "miaobianwidth", double=True, step=0.1 ), - 2, + 3, ), "", ("描边宽度", 3), @@ -331,27 +321,31 @@ def setTabThree_lazy(self): getspinbox( 0.1, 100, globalconfig, "miaobianwidth2", double=True, step=0.1 ), - 2, + 3, ), ], [ ("发光亮度", 3), - (getspinbox(1, 100, globalconfig, "shadowforce"), 2), + (getspinbox(1, 100, globalconfig, "shadowforce"), 3), "", ("投影距离", 3), ( getspinbox( 0.1, 100, globalconfig, "traceoffset", double=True, step=0.1 ), - 2, + 3, ), ], [], [ - ("显示原文", 4), + ("显示原文", 5), self.show_original_switch, "", - ("原文颜色", 4), + ("显示翻译", 5), + (getsimpleswitch(globalconfig, "showfanyi"), 1), + ], + [ + ("原文颜色", 5), getcolorbutton( globalconfig, "rawtextcolor", @@ -361,12 +355,21 @@ def setTabThree_lazy(self): name="original_color_button", parent=self, ), + "", + ("显示翻译器名称", 5), + (getsimpleswitch(globalconfig, "showfanyisource"), 1), ], [ - ("显示日语注音", 4), + ("最长显示字数", 3), + (getspinbox(0, 1000000, globalconfig, "maxoriginlength"), 3), + ], + [], + [ + ("显示日语注音", 5), self.show_hira_switch, - "", - ("注音颜色", 4), + ], + [ + ("注音颜色", 5), getcolorbutton( globalconfig, "jiamingcolor", @@ -382,14 +385,14 @@ def setTabThree_lazy(self): getspinbox( 0.05, 1, globalconfig, "kanarate", double=True, step=0.05, dec=2 ), - 2, + 3, ), ], [ - ("语法加亮", 4), + ("语法加亮", 5), self.show_fenciswitch, "", - ("词性颜色(需要Mecab)", 4), + ("词性颜色(需要Mecab)", 5), getcolorbutton( globalconfig, "", @@ -398,28 +401,10 @@ def setTabThree_lazy(self): constcolor="#FF69B4", ), ], - [ - ("显示翻译器名称", 4), - (getsimpleswitch(globalconfig, "showfanyisource"), 1), - "", - ("显示翻译", 4), - (getsimpleswitch(globalconfig, "showfanyi"), 1), - ], - [ - ("最长显示字数", 4), - (getspinbox(0, 1000000, globalconfig, "maxoriginlength"), 2), - ], [], [ - ("收到翻译结果时才刷新", 4), + ("收到翻译结果时才刷新", 5), getsimpleswitch(globalconfig, "refresh_on_get_trans"), - "", - ("可选取模式", 4), - getsimpleswitch( - globalconfig, - "selectable", - callback=lambda x: gobject.baseobject.translation_ui.translate_text.setselectable(), - ), ], ] @@ -477,6 +462,14 @@ def setTabThree_lazy(self): ), ), ], + [ + ("可选取模式", 6), + getsimpleswitch( + globalconfig, + "selectable", + callback=lambda x: gobject.baseobject.translation_ui.translate_text.setselectable(), + ), + ], ] uigrid = [ [("设置界面字体", 4), (self.sfont_comboBox, 5)], @@ -586,7 +579,7 @@ def setTabThree_lazy(self): ], [], [ - ("明暗", 6), + ("明暗", 4), ( getsimplecombobox( _TRL(["明亮", "黑暗", "跟随系统"]), @@ -598,7 +591,7 @@ def setTabThree_lazy(self): ), ], [ - ("明亮主题", 6), + ("明亮主题", 4), ( getsimplecombobox( _TRL(["默认"]) + themelist("light"), @@ -610,7 +603,7 @@ def setTabThree_lazy(self): ), ], [ - ("黑暗主题", 6), + ("黑暗主题", 4), ( getsimplecombobox( themelist("dark"), @@ -623,7 +616,7 @@ def setTabThree_lazy(self): ], [], [ - ("窗口特效_翻译窗口", 6), + ("窗口特效_翻译窗口", 4), ( getsimplecombobox( ["Disable", "Acrylic", "Aero"], @@ -638,7 +631,7 @@ def setTabThree_lazy(self): ), ], [ - ("窗口特效_其他", 6), + ("窗口特效_其他", 4), ( getsimplecombobox( ["Solid", "Acrylic", "Mica", "MicaAlt"], diff --git a/LunaTranslator/LunaTranslator/gui/showocrimage.py b/LunaTranslator/LunaTranslator/gui/showocrimage.py index 8cbec6e0..59535878 100644 --- a/LunaTranslator/LunaTranslator/gui/showocrimage.py +++ b/LunaTranslator/LunaTranslator/gui/showocrimage.py @@ -1,7 +1,4 @@ -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QWidget, QPushButton, QHBoxLayout, QVBoxLayout, QLabel -from PyQt5.QtGui import QPixmap -from PyQt5.QtCore import Qt, pyqtSignal +from qtsymbols import * import qtawesome from myutils.ocrutil import imagesolve from gui.usefulwidget import closeashidewindow @@ -46,12 +43,16 @@ class showocrimage(closeashidewindow): self.originlabel.setPixmap( self.img1.scaled( - self.originlabel.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation + self.originlabel.size(), + Qt.AspectRatioMode.KeepAspectRatio, + Qt.TransformationMode.SmoothTransformation, ) ) self.solvedlabel.setPixmap( self.img2.scaled( - self.solvedlabel.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation + self.solvedlabel.size(), + Qt.AspectRatioMode.KeepAspectRatio, + Qt.TransformationMode.SmoothTransformation, ) ) diff --git a/LunaTranslator/LunaTranslator/gui/showword.py b/LunaTranslator/LunaTranslator/gui/showword.py index e4b38079..e30f3a8f 100644 --- a/LunaTranslator/LunaTranslator/gui/showword.py +++ b/LunaTranslator/LunaTranslator/gui/showword.py @@ -1,26 +1,9 @@ -from PyQt5.QtWidgets import ( - QWidget, - QHBoxLayout, - QVBoxLayout, - QTextBrowser, - QLineEdit, - QPlainTextEdit, - QFormLayout, - QSizePolicy, - QPushButton, - QTabWidget, - QFileDialog, - QTabBar, - QSplitter, - QLabel, -) +from qtsymbols import * from myutils.hwnd import grabwindow from urllib.parse import quote -from PyQt5.QtGui import QPixmap, QImage from traceback import print_exc import requests, json, time -from PyQt5.QtCore import pyqtSignal, Qt import qtawesome, functools, os, base64 import gobject, uuid, windows from myutils.utils import getimageformat, parsekeystringtomodvkcode, unsupportkey @@ -156,7 +139,7 @@ class AnkiWindow(QWidget): def __init__(self) -> None: super().__init__() - self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) self.setWindowTitle("Anki Connect") self.currentword = "" self.tabs = QTabWidget() @@ -241,7 +224,9 @@ class AnkiWindow(QWidget): ) self.htmlbrowser = auto_select_webview(self) - self.htmlbrowser.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + self.htmlbrowser.setSizePolicy( + QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding + ) layout.addLayout( getboxlayout( [self.previewtab, self.htmlbrowser], @@ -596,7 +581,9 @@ class AnkiWindow(QWidget): pix.width() > self.viewimagelabel.width() or pix.height() > self.viewimagelabel.height() ): - pix = pix.scaled(self.viewimagelabel.size() * rate, Qt.KeepAspectRatio) + pix = pix.scaled( + self.viewimagelabel.size() * rate, Qt.AspectRatioMode.KeepAspectRatio + ) self.viewimagelabel.setPixmap(pix) def selecfile(self, item): @@ -837,7 +824,7 @@ class searchwordW(closeashidewindow): w.setLayout(tablayout) self.vboxlayout.addWidget(self.spliter) self.isfirstshowanki = True - self.spliter.setOrientation(Qt.Vertical) + self.spliter.setOrientation(Qt.Orientation.Vertical) self.spliter.addWidget(w) diff --git a/LunaTranslator/LunaTranslator/gui/specialwidget.py b/LunaTranslator/LunaTranslator/gui/specialwidget.py index 1c740265..6fb9fe17 100644 --- a/LunaTranslator/LunaTranslator/gui/specialwidget.py +++ b/LunaTranslator/LunaTranslator/gui/specialwidget.py @@ -1,20 +1,4 @@ -from PyQt5.QtWidgets import QWidget, QSizePolicy, QLabel, QScrollArea, QApplication -from PyQt5.QtGui import ( - QMouseEvent, - QPainter, - QPen, - QFont, - QFontMetrics, - QRegion, - QResizeEvent, -) -from PyQt5.QtCore import Qt, QEvent -from PyQt5.QtWidgets import ( - QSpacerItem, - QWidgetItem, -) -from PyQt5.QtCore import QPoint, QRect, QSize, Qt, pyqtSignal -from PyQt5.QtWidgets import QLayout +from qtsymbols import * from traceback import print_exc from myutils.wrapper import trypass import threading @@ -48,9 +32,9 @@ class chartwidget(QWidget): if len(self.data) == 1: self.data.insert(0, (0, 0)) painter = QPainter(self) - painter.setRenderHint(QPainter.Antialiasing) + painter.setRenderHint(QPainter.RenderHint.Antialiasing) - pen = QPen(Qt.blue) + pen = QPen(Qt.GlobalColor.blue) pen.setWidth(2) painter.setPen(pen) @@ -65,7 +49,7 @@ class chartwidget(QWidget): x_labels = [self.xtext(x) for x, _ in self.data] for l in y_labels: - xmargin = max(xmargin, self.fmetrics.width(l)) + xmargin = max(xmargin, self.fmetrics.size(0, l).width()) xmargin = xmargin + self.scalelinelen @@ -73,8 +57,8 @@ class chartwidget(QWidget): self.width() - xmargin - max( - self.fmetrics.width(x_labels[-1]) // 2, - self.fmetrics.width(self.ytext(self.data[-1][1])) // 2, + self.fmetrics.size(0, x_labels[-1]).width() // 2, + self.fmetrics.size(0, self.ytext(self.data[-1][1])).width() // 2, ) ) @@ -85,7 +69,7 @@ class chartwidget(QWidget): y = int(ymargin + height - i * (height / 5)) painter.drawLine(xmargin - self.scalelinelen, y, xmargin, y) painter.drawText( - xmargin - self.scalelinelen - self.fmetrics.width(label), + xmargin - self.scalelinelen - self.fmetrics.size(0, label).width(), y + 5, label, ) @@ -115,7 +99,7 @@ class chartwidget(QWidget): if self.data[i + 1][1]: #!=0 text = self.ytext(self.data[i + 1][1]) - W = self.fmetrics.width(text) + W = self.fmetrics.size(0, text).width() newrect = QRect(x2 - W // 2, y2 - 10, W, texth) if any(_.intersected(newrect) for _ in rects): continue @@ -126,7 +110,7 @@ class chartwidget(QWidget): for i, (x, y) in enumerate(points): painter.drawLine(x, ymargin + height, x, ymargin + height + 5) # 刻度线 - thisw = self.fmetrics.width(x_labels[i]) + thisw = self.fmetrics.size(0, x_labels[i]).width() thisx = x - thisw // 2 if thisx > lastx2: @@ -242,7 +226,9 @@ class FlowLayout(QLayout): self._item_list.append(item) def addSpacing(self, size): # pylint: disable=invalid-name - self.addItem(QSpacerItem(size, 0, QSizePolicy.Fixed, QSizePolicy.Minimum)) + self.addItem( + QSpacerItem(size, 0, QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Minimum) + ) def count(self): return len(self._item_list) @@ -257,9 +243,6 @@ class FlowLayout(QLayout): return self._item_list.pop(index) return None - def expandingDirections(self): # pylint: disable=invalid-name,no-self-use - return Qt.Orientations(Qt.Orientation(0)) - def setGeometry(self, rect): # pylint: disable=invalid-name super().setGeometry(rect) self._do_layout(rect, False) @@ -292,10 +275,14 @@ class FlowLayout(QLayout): space_y = self.spacing() if wid is not None: space_x += wid.style().layoutSpacing( - QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Horizontal + QSizePolicy.ControlType.PushButton, + QSizePolicy.ControlType.PushButton, + Qt.Orientation.Horizontal, ) space_y += wid.style().layoutSpacing( - QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Vertical + QSizePolicy.ControlType.PushButton, + QSizePolicy.ControlType.PushButton, + Qt.Orientation.Vertical, ) next_x = x + item.sizeHint().width() + space_x diff --git a/LunaTranslator/LunaTranslator/gui/textbrowser.py b/LunaTranslator/LunaTranslator/gui/textbrowser.py index c7fb090a..ab452f32 100644 --- a/LunaTranslator/LunaTranslator/gui/textbrowser.py +++ b/LunaTranslator/LunaTranslator/gui/textbrowser.py @@ -1,30 +1,7 @@ -from PyQt5.QtCore import Qt, QPoint, QPointF, pyqtSignal -from PyQt5.QtGui import ( - QTextCharFormat, - QTextBlockFormat, - QResizeEvent, - QTextCursor, - QPixmap, - QFontMetricsF, - QMouseEvent, -) -from PyQt5.QtWidgets import ( - QTextBrowser, - QLabel, - QGraphicsDropShadowEffect, -) +from qtsymbols import * import functools from myutils.config import globalconfig from traceback import print_exc -from PyQt5.QtGui import ( - QPainter, - QColor, - QFont, - QPen, - QPainterPath, - QBrush, - QFontMetrics, -) class Qlabel_c(QLabel): @@ -42,7 +19,7 @@ class Qlabel_c(QLabel): if self.underMouse(): try: if self.pr: - if event.button() == Qt.RightButton: + if event.button() == Qt.MouseButton.RightButton: self.callback(True) else: self.callback(False) @@ -141,13 +118,17 @@ class BorderedLabel(QLabel): text = self.text() font_m = QFontMetrics(font) self.resize( - int(font_m.width(text) + 2 * self.m_fontOutLineWidth), + int(font_m.size(0, text).width() + 2 * self.m_fontOutLineWidth), int(font_m.height() + 2 * self.m_fontOutLineWidth), ) def labelresetcolor(self, color, rate=1): c1 = color c2 = globalconfig["miaobiancolor"] + if c1 is None: + c1 = "" + if c2 is None: + c2 = "" if globalconfig["zitiyangshi2"] == 2: self.setColorWidth(c1, c2, rate * globalconfig["miaobianwidth2"]) self.clearShadow() @@ -161,10 +142,10 @@ class BorderedLabel(QLabel): 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.setColorWidth("", c1, 0, 2) self.clearShadow() elif globalconfig["zitiyangshi2"] == 5: - self.setColorWidth(None, c2, 0, 2) + self.setColorWidth("", c2, 0, 2) self.setShadow( c1, rate * globalconfig["fontsize"], globalconfig["shadowforce"] ) @@ -174,13 +155,13 @@ class BorderedLabel(QLabel): rate = self.devicePixelRatioF() self._pix = QPixmap(self.size() * rate) self._pix.setDevicePixelRatio(rate) - self._pix.fill(Qt.transparent) + self._pix.fill(Qt.GlobalColor.transparent) text = self.text() font = self.font() font_m = QFontMetrics(font) painter = QPainter(self._pix) - painter.setRenderHint(QPainter.Antialiasing) + painter.setRenderHint(QPainter.RenderHint.Antialiasing) path = QPainterPath() if self._type == 2: @@ -202,9 +183,9 @@ class BorderedLabel(QLabel): pen = QPen( self.m_outLineColor, self.m_fontOutLineWidth, - Qt.SolidLine, - Qt.RoundCap, - Qt.RoundJoin, + Qt.PenStyle.SolidLine, + Qt.PenCapStyle.RoundCap, + Qt.PenJoinStyle.RoundJoin, ) if self._type == 0: @@ -262,8 +243,12 @@ class Textbrowser(QLabel): ) self.textcursor = self.textbrowser.textCursor() - self.textbrowser.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - self.textbrowser.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + self.textbrowser.setVerticalScrollBarPolicy( + Qt.ScrollBarPolicy.ScrollBarAlwaysOff + ) + self.textbrowser.setHorizontalScrollBarPolicy( + Qt.ScrollBarPolicy.ScrollBarAlwaysOff + ) self.masklabel = QLabel(self.textbrowser) self.masklabel.setGeometry(0, 0, 9999, 9999) self.masklabel.setMouseTracking(True) @@ -294,7 +279,7 @@ class Textbrowser(QLabel): self.font.setPointSizeF(globalconfig["fontsize"]) self.font.setBold(globalconfig["showbold"]) - self.textbrowser.moveCursor(QTextCursor.End) + self.textbrowser.moveCursor(QTextCursor.MoveOperation.End) f = QTextCharFormat() f.setFont(self.font) f.setForeground(self.tranparentcolor) @@ -322,7 +307,11 @@ class Textbrowser(QLabel): for i in range(self.blockcount, self.textbrowser.document().blockCount()): b = self.textbrowser.document().findBlockByNumber(i) tf = b.blockFormat() - tf.setLineHeight(fh, QTextBlockFormat.LineDistanceHeight) + if isqt5: + lht = QTextBlockFormat.LineHeightTypes.LineDistanceHeight + else: + lht = 4 + tf.setLineHeight(fh, lht) self.textcursor.setPosition(b.position()) self.textcursor.setBlockFormat(tf) self.textbrowser.setTextCursor(self.textcursor) @@ -342,8 +331,8 @@ class Textbrowser(QLabel): self.textbrowser.insertPlainText(text) def deletebetween(self, p1, p2): - self.textcursor.setPosition(p1, QTextCursor.MoveAnchor) - self.textcursor.setPosition(p2, QTextCursor.KeepAnchor) + self.textcursor.setPosition(p1, QTextCursor.MoveMode.MoveAnchor) + self.textcursor.setPosition(p2, QTextCursor.MoveMode.KeepAnchor) self.textcursor.removeSelectedText() def showyinyingtext2(self, color, iter_context_class, pos, text): @@ -626,7 +615,11 @@ class Textbrowser(QLabel): b = self.textbrowser.document().findBlockByNumber(i) tf = b.blockFormat() - tf.setLineHeight(fasall + fha, QTextBlockFormat.FixedHeight) + if isqt5: + lht = QTextBlockFormat.LineHeightTypes.FixedHeight + else: + lht = 2 + tf.setLineHeight(fasall + fha, lht) self.textcursor.setPosition(b.position()) self.textcursor.setBlockFormat(tf) self.textbrowser.setTextCursor(self.textcursor) @@ -666,8 +659,8 @@ class Textbrowser(QLabel): _metrichira = QFontMetricsF(fonthira) _metricorig = QFontMetricsF(fontorig) for i, word in enumerate(x): - word["orig_w"] = _metricorig.width(word["orig"]) - word["hira_w"] = _metrichira.width(word["hira"]) + word["orig_w"] = _metricorig.size(0, word["orig"]).width() + word["hira_w"] = _metrichira.size(0, word["hira"]).width() # print(word['hira'],word['hira_w']) newline.append(word) diff --git a/LunaTranslator/LunaTranslator/gui/transhist.py b/LunaTranslator/LunaTranslator/gui/transhist.py index c2244c5e..41cb830d 100644 --- a/LunaTranslator/LunaTranslator/gui/transhist.py +++ b/LunaTranslator/LunaTranslator/gui/transhist.py @@ -1,6 +1,4 @@ -from PyQt5.QtWidgets import QPlainTextEdit, QAction, QMenu, QFileDialog -from PyQt5.QtCore import Qt, pyqtSignal -from PyQt5.QtGui import QCursor +from qtsymbols import * import qtawesome, functools, winsharedutils from gui.usefulwidget import closeashidewindow from myutils.config import globalconfig, _TR @@ -27,7 +25,7 @@ class transhist(closeashidewindow): def gettb(_type): textOutput = QPlainTextEdit() - textOutput.setContextMenuPolicy(Qt.CustomContextMenu) + textOutput.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) textOutput.customContextMenuRequested.connect( functools.partial(self.showmenu, textOutput, _type) ) diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 5743e60f..19b49c5f 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -4,11 +4,8 @@ import threading import os, sys import windows, importlib from traceback import print_exc -from PyQt5.QtCore import Qt, pyqtSignal import qtawesome -from PyQt5.QtCore import pyqtSignal, Qt, QSize -from PyQt5.QtGui import QCursor -from PyQt5.QtWidgets import QLabel, QPushButton, QSystemTrayIcon +from qtsymbols import * import gobject from myutils.wrapper import threader, trypass import winsharedutils @@ -183,9 +180,9 @@ class QUnFrameWindow(resizableframeless): self.translate_text.setnextfont(origin) if globalconfig["showatcenter"]: - self.translate_text.setAlignment(Qt.AlignCenter) + self.translate_text.setAlignment(Qt.AlignmentFlag.AlignCenter) else: - self.translate_text.setAlignment(Qt.AlignLeft) + self.translate_text.setAlignment(Qt.AlignmentFlag.AlignLeft) if iter_context: iter_res_status, iter_context_class = iter_context @@ -590,7 +587,7 @@ class QUnFrameWindow(resizableframeless): super(QUnFrameWindow, self).__init__( None, - flags=Qt.FramelessWindowHint | Qt.Tool, + flags=Qt.WindowType.FramelessWindowHint | Qt.WindowType.Tool, dic=globalconfig, key="transuigeo", ) # 设置为顶级窗口,无边框 @@ -600,8 +597,8 @@ class QUnFrameWindow(resizableframeless): self.tray = QSystemTrayIcon() self.tray.setIcon(icon) self.isfirstshow = True - self.setAttribute(Qt.WA_TranslucentBackground) - self.setAttribute(Qt.WA_ShowWithoutActivating, True) + self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) + self.setAttribute(Qt.WidgetAttribute.WA_ShowWithoutActivating, True) self.setWindowTitle("LunaTranslator") self.hidesignal.connect(self.hide_) self.lastrefreshtime = time.time() diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index 94f6b32e..17889d55 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -1,44 +1,11 @@ -from PyQt5.QtWidgets import ( - QLineEdit, - QMainWindow, - QApplication, - QPushButton, - QMessageBox, - QTabWidget, - QScrollArea, - QDialog, - QLabel, - QGridLayout, - QSizePolicy, - QHBoxLayout, - QWidget, - QLayout, -) -from PyQt5.QtCore import pyqtSignal -from PyQt5.QtWidgets import QKeySequenceEdit, QLabel -from PyQt5.QtGui import QFontDatabase -from PyQt5.QtGui import QKeySequence - +from qtsymbols import * from webviewpy import ( webview_native_handle_kind_t, Webview, declare_library_path, ) -from PyQt5.QtGui import QCloseEvent, QColor, QTextCursor, QResizeEvent -from PyQt5.QtCore import Qt, pyqtSignal, QSize from myutils.config import _TR, globalconfig -from PyQt5.QtWidgets import ( - QColorDialog, - QSpinBox, - QDoubleSpinBox, - QPushButton, - QComboBox, - QLabel, - QDialogButtonBox, - QLineEdit, - QApplication, - QVBoxLayout, -) + from traceback import print_exc import qtawesome, functools, threading, time from myutils.wrapper import Singleton @@ -50,7 +17,7 @@ import windows, os, platform class dialog_showinfo(QDialog): def __init__(self, parent, title, info) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) self.setWindowTitle(title) l = QLabel(info) layout = QHBoxLayout() @@ -251,94 +218,100 @@ class resizableframeless(saveposwindow): self.height() + 1, ] - def mousePressEvent(self, event): + def mousePressEvent(self, event: QMouseEvent): # 重写鼠标点击的事件 - - if (event.button() == Qt.LeftButton) and ( + if isqt5: + gpos = event.globalPos() + else: + gpos = event.globalPosition().toPoint() + if (event.button() == Qt.MouseButton.LeftButton) and ( isinrect(event.pos(), self._corner_rect) ): # 鼠标左键点击右下角边界区域 self._corner_drag = True - elif (event.button() == Qt.LeftButton) and ( + elif (event.button() == Qt.MouseButton.LeftButton) and ( isinrect(event.pos(), self._right_rect) ): # 鼠标左键点击右侧边界区域 self._right_drag = True - elif (event.button() == Qt.LeftButton) and ( + elif (event.button() == Qt.MouseButton.LeftButton) and ( isinrect(event.pos(), self._left_rect) ): # 鼠标左键点击右侧边界区域 self._left_drag = True - self.startxp = event.globalPos() - self.pos() - self.startx = event.globalPos().x() + self.startxp = gpos - self.pos() + self.startx = gpos.x() self.startw = self.width() - elif (event.button() == Qt.LeftButton) and ( + elif (event.button() == Qt.MouseButton.LeftButton) and ( isinrect(event.pos(), self._bottom_rect) ): # 鼠标左键点击下侧边界区域 self._bottom_drag = True - elif (event.button() == Qt.LeftButton) and ( + elif (event.button() == Qt.MouseButton.LeftButton) and ( isinrect(event.pos(), self._lcorner_rect) ): # 鼠标左键点击下侧边界区域 self._lcorner_drag = True - self.startxp = event.globalPos() - self.pos() - self.startx = event.globalPos().x() + self.startxp = gpos - self.pos() + self.startx = gpos.x() self.startw = self.width() # and (event.y() < self._TitleLabel.height()): - elif event.button() == Qt.LeftButton: + elif event.button() == Qt.MouseButton.LeftButton: # 鼠标左键点击标题栏区域 self._move_drag = True - self.move_DragPosition = event.globalPos() - self.pos() + self.move_DragPosition = gpos - self.pos() - def mouseMoveEvent(self, QMouseEvent): + def mouseMoveEvent(self, event): # 判断鼠标位置切换鼠标手势 - pos = QMouseEvent.pos() - + pos = event.pos() + if isqt5: + gpos = event.globalPos() + else: + gpos = event.globalPosition().toPoint() if self._move_drag == False: if isinrect(pos, self._corner_rect): - self.setCursor(Qt.SizeFDiagCursor) + self.setCursor(Qt.CursorShape.SizeFDiagCursor) elif isinrect(pos, self._lcorner_rect): - self.setCursor(Qt.SizeBDiagCursor) + self.setCursor(Qt.CursorShape.SizeBDiagCursor) elif isinrect(pos, self._bottom_rect): - self.setCursor(Qt.SizeVerCursor) + self.setCursor(Qt.CursorShape.SizeVerCursor) elif isinrect(pos, self._right_rect): - self.setCursor(Qt.SizeHorCursor) + self.setCursor(Qt.CursorShape.SizeHorCursor) elif isinrect(pos, self._left_rect): - self.setCursor(Qt.SizeHorCursor) + self.setCursor(Qt.CursorShape.SizeHorCursor) else: - self.setCursor(Qt.ArrowCursor) - if Qt.LeftButton and self._right_drag: + self.setCursor(Qt.CursorShape.ArrowCursor) + if Qt.MouseButton.LeftButton and self._right_drag: # 右侧调整窗口宽度 self.resize(pos.x(), self.height()) - elif Qt.LeftButton and self._left_drag: + elif Qt.MouseButton.LeftButton and self._left_drag: # 右侧调整窗口宽度 self.setGeometry( - (QMouseEvent.globalPos() - self.startxp).x(), + (gpos - self.startxp).x(), self.y(), - self.startw - (QMouseEvent.globalPos().x() - self.startx), + self.startw - (gpos.x() - self.startx), self.height(), ) # self.resize(pos.x(), self.height()) - elif Qt.LeftButton and self._bottom_drag: + elif Qt.MouseButton.LeftButton and self._bottom_drag: # 下侧调整窗口高度 - self.resize(self.width(), QMouseEvent.pos().y()) - elif Qt.LeftButton and self._lcorner_drag: + self.resize(self.width(), event.pos().y()) + elif Qt.MouseButton.LeftButton and self._lcorner_drag: # 下侧调整窗口高度 self.setGeometry( - (QMouseEvent.globalPos() - self.startxp).x(), + (gpos - self.startxp).x(), self.y(), - self.startw - (QMouseEvent.globalPos().x() - self.startx), - QMouseEvent.pos().y(), + self.startw - (gpos.x() - self.startx), + event.pos().y(), ) - elif Qt.LeftButton and self._corner_drag: + elif Qt.MouseButton.LeftButton and self._corner_drag: # 右下角同时调整高度和宽度 self.resize(pos.x(), pos.y()) - elif Qt.LeftButton and self._move_drag: + elif Qt.MouseButton.LeftButton and self._move_drag: # 标题栏拖放窗口位置 - self.move(QMouseEvent.globalPos() - self.move_DragPosition) + self.move(gpos - self.move_DragPosition) def mouseReleaseEvent(self, QMouseEvent): # 鼠标释放后,各扳机复位 @@ -356,7 +329,7 @@ class Prompt_dialog(QDialog): self.setWindowFlags( self.windowFlags() & ~Qt.WindowContextHelpButtonHint - & ~Qt.WindowCloseButtonHint + & ~Qt.WindowType.WindowCloseButtonHint | Qt.WindowStaysOnTopHint ) self.setWindowTitle(title) @@ -376,7 +349,9 @@ class Prompt_dialog(QDialog): hl.addWidget(QLabel(_[0])) hl.addWidget(le) _layout.addLayout(hl) - button = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + button = QDialogButtonBox( + QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel + ) button.accepted.connect(self.accept) button.rejected.connect(self.reject) _layout.addWidget(button) @@ -401,7 +376,7 @@ def getsimplecombobox(lst, d, k, callback=None, fixedsize=False): s.setCurrentIndex(d[k]) s.currentIndexChanged.connect(functools.partial(callbackwrap, d, k, callback)) if fixedsize: - s.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + s.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) return s @@ -457,7 +432,7 @@ def getcolorbutton( font: 100 10pt;""" ) b.clicked.connect(callback) - b.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + b.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) if name: setattr(parent, name, b) return b @@ -483,7 +458,7 @@ def getsimpleswitch( b = MySwitch(sign=d[key], enable=enable) b.clicked.connect(functools.partial(callbackwrap, d, key, callback)) - b.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + b.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) if pair: if pair not in dir(parent): setattr(parent, pair, {}) @@ -539,7 +514,7 @@ def textbrowappendandmovetoend(textOutput, sentence, addspace=True): or scrollbar.value() / scrollbar.maximum() > 0.975 ) cursor = QTextCursor(textOutput.document()) - cursor.movePosition(QTextCursor.End) + cursor.movePosition(QTextCursor.MoveOperation.End) cursor.insertText( (("" if textOutput.document().isEmpty() else "\n") if addspace else "") + sentence @@ -700,7 +675,7 @@ class auto_select_webview(QWidget): def __init__(self, parent) -> None: super().__init__(parent) - self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) self.cantusewebview2 = False self.internal = None self.contex = -1 @@ -817,7 +792,7 @@ def automakegrid(grid: QGridLayout, lis, save=False, savelist=None): nowc += cols if save: savelist.append(ll) - grid.setRowMinimumHeight(nowr, 30) + grid.setRowMinimumHeight(nowr, 25) def makegrid(grid, save=False, savelist=None, savelay=None): @@ -827,7 +802,7 @@ def makegrid(grid, save=False, savelist=None, savelay=None): gridlayoutwidget = gridwidget() gridlay = QGridLayout() - gridlay.setAlignment(Qt.AlignTop) + gridlay.setAlignment(Qt.AlignmentFlag.AlignTop) gridlayoutwidget.setLayout(gridlay) gridlayoutwidget.setStyleSheet("gridwidget{background-color:transparent;}") diff --git a/LunaTranslator/LunaTranslator/keeprefs.py b/LunaTranslator/LunaTranslator/keeprefs.py index bffaf6e8..6f40d2b1 100644 --- a/LunaTranslator/LunaTranslator/keeprefs.py +++ b/LunaTranslator/LunaTranslator/keeprefs.py @@ -9,5 +9,4 @@ from html.parser import HTMLParser from importlib import resources from distutils.version import StrictVersion from dataclasses import dataclass -import colorsys -from PyQt5 import QtSvg \ No newline at end of file +import colorsys \ No newline at end of file diff --git a/LunaTranslator/LunaTranslator/myutils/hwnd.py b/LunaTranslator/LunaTranslator/myutils/hwnd.py index c0c6804f..09c3db31 100644 --- a/LunaTranslator/LunaTranslator/myutils/hwnd.py +++ b/LunaTranslator/LunaTranslator/myutils/hwnd.py @@ -1,7 +1,6 @@ import windows import threading -from PyQt5.QtGui import QPixmap, QColor, QIcon -from PyQt5.QtWidgets import QApplication +from qtsymbols import * import gobject import os, subprocess import time, winrtutils, winsharedutils, hashlib diff --git a/LunaTranslator/LunaTranslator/myutils/ocrutil.py b/LunaTranslator/LunaTranslator/myutils/ocrutil.py index b4623238..97c6f803 100644 --- a/LunaTranslator/LunaTranslator/myutils/ocrutil.py +++ b/LunaTranslator/LunaTranslator/myutils/ocrutil.py @@ -1,8 +1,7 @@ import windows import os, importlib from myutils.config import globalconfig, _TR -from PyQt5.QtGui import QImage -from PyQt5.QtCore import QByteArray, QBuffer +from qtsymbols import * from myutils.commonbase import ArgsEmptyExc from myutils.hwnd import screenshot from myutils.utils import stringfyerror diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index 5cadbe97..8e049d72 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -8,10 +8,7 @@ import ctypes, importlib import time import ctypes.wintypes import time -from PyQt5.QtWidgets import ( - QApplication, -) -from PyQt5.QtGui import QImageWriter +from qtsymbols import * from traceback import print_exc from myutils.config import ( globalconfig, diff --git a/LunaTranslator/LunaTranslator/qtawesome.py b/LunaTranslator/LunaTranslator/qtawesome.py index ec150e36..857316ff 100644 --- a/LunaTranslator/LunaTranslator/qtawesome.py +++ b/LunaTranslator/LunaTranslator/qtawesome.py @@ -1,15 +1,6 @@ import json import os -from PyQt5.QtCore import QByteArray, QObject, QPoint, QRect, Qt -from PyQt5.QtGui import ( - QColor, - QFont, - QFontDatabase, - QIcon, - QIconEngine, - QPainter, - QPixmap, -) +from qtsymbols import * class CharIconPainter: @@ -20,7 +11,11 @@ class CharIconPainter: painter.setPen(qcolor) draw_size = round(0.875 * rect.height()) painter.setFont(iconic.font(draw_size)) - painter.drawText(rect, int(Qt.AlignCenter | Qt.AlignVCenter), char) + painter.drawText( + rect, + int(Qt.AlignmentFlag.AlignCenter | Qt.AlignmentFlag.AlignVCenter), + char, + ) painter.restore() @@ -38,7 +33,7 @@ class CharIconEngine(QIconEngine): def pixmap(self, size, mode, state): pm = QPixmap(size) - pm.fill(Qt.transparent) + pm.fill(Qt.GlobalColor.transparent) self.paint(QPainter(pm), QRect(QPoint(0, 0), size)) return pm diff --git a/LunaTranslator/LunaTranslator/qtsymbols.py b/LunaTranslator/LunaTranslator/qtsymbols.py new file mode 100644 index 00000000..d9d6a322 --- /dev/null +++ b/LunaTranslator/LunaTranslator/qtsymbols.py @@ -0,0 +1,14 @@ +try: + from PyQt5 import QtSvg + from PyQt5.QtWidgets import QFrame,QListView,QCheckBox,QAbstractItemView,QTextEdit,QTableView,QHeaderView,QColorDialog,QSpinBox,QDoubleSpinBox,QComboBox,QDialogButtonBox,QMainWindow,QMessageBox,QDialog,QGridLayout,QTextBrowser,QGraphicsDropShadowEffect,QWidget,QSizePolicy,QScrollArea,QApplication,QPushButton,QSystemTrayIcon,QPlainTextEdit,QAction,QMenu,QFileDialog,QKeySequenceEdit,QLabel,QSpacerItem,QWidgetItem,QLayout,QTextBrowser,QLineEdit,QFormLayout,QSizePolicy,QTabWidget,QTabBar,QSplitter,QListWidget,QListWidgetItem,QHBoxLayout,QVBoxLayout,QSizeGrip,QFontComboBox,QProgressBar,QRadioButton,QButtonGroup,QSlider + from PyQt5.QtGui import QIconEngine,QIntValidator,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics + from PyQt5.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex + isqt5 = True +except: + #from traceback import print_exc + #print_exc() + from PyQt6 import QtSvg + from PyQt6.QtWidgets import QFrame,QListView,QCheckBox,QAbstractItemView,QTextEdit,QTableView,QHeaderView,QColorDialog,QSpinBox,QDoubleSpinBox,QComboBox,QDialogButtonBox,QMainWindow,QMessageBox,QDialog,QGridLayout,QTextBrowser,QGraphicsDropShadowEffect,QWidget,QSizePolicy,QScrollArea,QApplication,QPushButton,QSystemTrayIcon,QPlainTextEdit,QMenu,QFileDialog,QKeySequenceEdit,QLabel,QSpacerItem,QWidgetItem,QLayout,QTextBrowser,QLineEdit,QFormLayout,QSizePolicy,QTabWidget,QTabBar,QSplitter,QListWidget,QListWidgetItem,QHBoxLayout,QVBoxLayout,QSizeGrip,QFontComboBox,QProgressBar,QRadioButton,QButtonGroup,QSlider + from PyQt6.QtGui import QIconEngine,QIntValidator,QAction,QStandardItem,QStandardItemModel,QImageWriter,QIcon,QTextCharFormat,QTextBlockFormat,QResizeEvent,QTextCursor,QFontMetricsF,QMouseEvent,QImage,QPainter,QRegion,QCloseEvent,QFontDatabase,QKeySequence,QPixmap,QCursor,QColor,QFont,QPen,QPainterPath,QBrush,QFontMetrics + from PyQt6.QtCore import QObject,pyqtSignal,Qt,QSize,QByteArray,QBuffer,QPointF,QPoint,QRect,QEvent,QModelIndex + isqt5 = False \ No newline at end of file diff --git a/LunaTranslator/LunaTranslator/textsource/ocrtext.py b/LunaTranslator/LunaTranslator/textsource/ocrtext.py index 7c51cd3b..c49e64e0 100644 --- a/LunaTranslator/LunaTranslator/textsource/ocrtext.py +++ b/LunaTranslator/LunaTranslator/textsource/ocrtext.py @@ -2,10 +2,9 @@ import time from myutils.config import globalconfig import winsharedutils from gui.rangeselect import rangeadjust -from myutils.ocrutil import imageCut, ocr_run, ocr_end, qimage2binary -import time, gobject, os -from PyQt5.QtWidgets import QApplication -from PyQt5.QtGui import QImage +from myutils.ocrutil import imageCut, ocr_run, ocr_end +import time, gobject +from qtsymbols import * from textsource.textsourcebase import basetext diff --git a/LunaTranslator/LunaTranslator/transoptimi/noundict.py b/LunaTranslator/LunaTranslator/transoptimi/noundict.py index 1f6667aa..b45ad093 100644 --- a/LunaTranslator/LunaTranslator/transoptimi/noundict.py +++ b/LunaTranslator/LunaTranslator/transoptimi/noundict.py @@ -1,19 +1,6 @@ from myutils.config import noundictconfig import gobject, re - -from PyQt5.QtWidgets import ( - QDialog, - QLabel, - QLineEdit, - QPushButton, - QTableView, - QVBoxLayout, - QHBoxLayout, - QHeaderView, - QHBoxLayout, -) -from PyQt5.QtCore import QSize, Qt -from PyQt5.QtGui import QCloseEvent, QStandardItem, QStandardItemModel +from qtsymbols import * from traceback import print_exc from myutils.config import ( noundictconfig, @@ -52,7 +39,7 @@ class noundictconfigdialog(QDialog): def __init__( self, parent, configdict, title, label=["游戏ID MD5", "原文", "翻译"], _=None ) -> None: - super().__init__(parent, Qt.WindowCloseButtonHint) + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) self.setWindowTitle(_TR(title)) # self.setWindowModality(Qt.ApplicationModal) @@ -76,8 +63,8 @@ class noundictconfigdialog(QDialog): model.setHorizontalHeaderLabels(_TRL(label)) table = QTableView(self) table.setModel(model) - table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) - # table.setEditTriggers(QAbstractItemView.NoEditTriggers) + table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) + # table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) # table.clicked.connect(self.show_info) button = threebuttons() diff --git a/LunaTranslator/python3.7.9.txt b/LunaTranslator/python3.7.9.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/LunaTranslator/requirements.txt b/LunaTranslator/requirements.txt index 90fe72e0..a97c26b7 100644 --- a/LunaTranslator/requirements.txt +++ b/LunaTranslator/requirements.txt @@ -1,4 +1,5 @@ PyQt5==5.15.10 PyQt5-Qt5==5.15.2 webviewpy==1.2.0 -pefile \ No newline at end of file +pefile +#python3.7.9 \ No newline at end of file diff --git a/LunaTranslator/requirements_qt6.txt b/LunaTranslator/requirements_qt6.txt new file mode 100644 index 00000000..7814fb4c --- /dev/null +++ b/LunaTranslator/requirements_qt6.txt @@ -0,0 +1,5 @@ +PyQt6==6.7.0 +PyQt6-Qt6==6.7.0 +webviewpy==1.2.0 +pefile +#python3.11.8 \ No newline at end of file diff --git a/LunaTranslator/run.bat b/LunaTranslator/run.bat new file mode 100644 index 00000000..c3432af3 --- /dev/null +++ b/LunaTranslator/run.bat @@ -0,0 +1,2 @@ +python.exe -B LunaTranslator\LunaTranslator_main.py +pause \ No newline at end of file