This commit is contained in:
恍兮惚兮 2024-07-22 00:25:17 +08:00
parent 7205bc8f87
commit 67072b4936
3 changed files with 22 additions and 33 deletions

View File

@ -1194,7 +1194,9 @@ class MAINUI:
self.parsedefaultfont() self.parsedefaultfont()
self.loadmetadatas() self.loadmetadatas()
self.translation_ui = QUnFrameWindow() self.translation_ui = QUnFrameWindow()
winsharedutils.showintab(int(self.translation_ui.winId()), globalconfig["showintab"]) winsharedutils.showintab(
int(self.translation_ui.winId()), globalconfig["showintab"]
)
self.translation_ui.show() self.translation_ui.show()
self.translation_ui.aftershowdosomething() self.translation_ui.aftershowdosomething()
self.mainuiloadafter() self.mainuiloadafter()
@ -1234,8 +1236,11 @@ class MAINUI:
def installeventfillter(self): def installeventfillter(self):
class WindowEventFilter(QObject): class WindowEventFilter(QObject):
def eventFilter(_, obj, event): def eventFilter(_, obj: QObject, event: QEvent):
if event.type() == QEvent.Type.WinIdChange: if event.type() == QEvent.Type.LanguageChange:
if "updatelangtext" in dir(obj):
obj.updatelangtext()
elif event.type() == QEvent.Type.WinIdChange:
hwnd = obj.winId() hwnd = obj.winId()
if hwnd: # window create/destroy,when destroy winId is None if hwnd: # window create/destroy,when destroy winId is None

View File

@ -2,17 +2,7 @@ from myutils.config import _TR, _TRL
from qtsymbols import * from qtsymbols import *
class LBase(QWidget): class LLabel(QLabel):
def changeEvent(self, e: QEvent):
if e.type() == QEvent.Type.LanguageChange:
self.updatelangtext()
super().changeEvent(e)
def updatelangtext(self): ...
class LLabel(QLabel, LBase):
def __init__(self, s=None): def __init__(self, s=None):
super().__init__(_TR(s) if s else None) super().__init__(_TR(s) if s else None)
self.__s = s self.__s = s
@ -26,7 +16,7 @@ class LLabel(QLabel, LBase):
super().setText(_TR(self.__s)) super().setText(_TR(self.__s))
class LMessageBox(QMessageBox, LBase): class LMessageBox(QMessageBox):
def __init__(self, *argc, **kwarg): def __init__(self, *argc, **kwarg):
super().__init__(*argc, **kwarg) super().__init__(*argc, **kwarg)
self._title = None self._title = None
@ -47,7 +37,7 @@ class LMessageBox(QMessageBox, LBase):
super().setText(_TR(self._text)) super().setText(_TR(self._text))
class LPushButton(QPushButton, LBase): class LPushButton(QPushButton):
def __init__(self, *argc): def __init__(self, *argc):
self._text = None self._text = None
self._ToolTip = None self._ToolTip = None
@ -90,14 +80,14 @@ class LAction(QAction):
super().__init__(*newarg, **kwargv) super().__init__(*newarg, **kwargv)
class LMenu(QMenu, LBase): class LMenu(QMenu):
def updatelangtext(self): def updatelangtext(self):
for action in self.actions(): for action in self.actions():
if isinstance(action, LAction): if isinstance(action, LAction):
action.updatelangtext() action.updatelangtext()
class LCheckBox(QCheckBox, LBase): class LCheckBox(QCheckBox):
def __init__(self, text): def __init__(self, text):
super().__init__(_TR(text)) super().__init__(_TR(text))
self._text = text self._text = text
@ -121,11 +111,6 @@ class LGroupBox(QGroupBox):
if self._text: if self._text:
super().setTitle(_TR(self._text)) super().setTitle(_TR(self._text))
def changeEvent(self, e: QEvent):
if e.type() == QEvent.Type.LanguageChange:
self.updatelangtext()
super().changeEvent(e)
class LListWidgetItem(QListWidgetItem): class LListWidgetItem(QListWidgetItem):
def __init__(self, text): def __init__(self, text):
@ -136,7 +121,7 @@ class LListWidgetItem(QListWidgetItem):
self.setText(_TR(self.__text)) self.setText(_TR(self.__text))
class LListWidget(QListWidget, LBase): class LListWidget(QListWidget):
def updatelangtext(self): def updatelangtext(self):
for i in range(self.count()): for i in range(self.count()):
item = self.item(i) item = self.item(i)
@ -154,7 +139,7 @@ class LFormLayout(QFormLayout):
super().addRow(*argc) super().addRow(*argc)
class LDialog(QDialog, LBase): class LDialog(QDialog):
def __init__(self, *argc, **kwarg): def __init__(self, *argc, **kwarg):
super().__init__(*argc, **kwarg) super().__init__(*argc, **kwarg)
@ -169,7 +154,7 @@ class LDialog(QDialog, LBase):
super().setWindowTitle(_TR(self._title)) super().setWindowTitle(_TR(self._title))
class LMainWindow(QMainWindow, LBase): class LMainWindow(QMainWindow):
def __init__(self, *argc, **kwarg): def __init__(self, *argc, **kwarg):
super().__init__(*argc, **kwarg) super().__init__(*argc, **kwarg)
@ -184,7 +169,7 @@ class LMainWindow(QMainWindow, LBase):
super().setWindowTitle(_TR(self._title)) super().setWindowTitle(_TR(self._title))
class LRadioButton(QRadioButton, LBase): class LRadioButton(QRadioButton):
def __init__(self, t): def __init__(self, t):
self.__t = t self.__t = t
super().__init__(_TR(t)) super().__init__(_TR(t))
@ -193,7 +178,7 @@ class LRadioButton(QRadioButton, LBase):
self.setText(_TR(self.__t)) self.setText(_TR(self.__t))
class LTabBar(QTabBar, LBase): class LTabBar(QTabBar):
def __init__(self, *argc, **kwarg): def __init__(self, *argc, **kwarg):
super().__init__(*argc, **kwarg) super().__init__(*argc, **kwarg)
self.__titles = [] self.__titles = []
@ -215,7 +200,7 @@ class LTabBar(QTabBar, LBase):
self.setTabText(i, _TR(self.__titles[i])) self.setTabText(i, _TR(self.__titles[i]))
class LTabWidget(QTabWidget, LBase): class LTabWidget(QTabWidget):
def __init__(self, *argc, **kwarg): def __init__(self, *argc, **kwarg):
super().__init__(*argc, **kwarg) super().__init__(*argc, **kwarg)
self.__titles = [] self.__titles = []
@ -229,7 +214,7 @@ class LTabWidget(QTabWidget, LBase):
self.setTabText(i, _TR(self.__titles[i])) self.setTabText(i, _TR(self.__titles[i]))
class LStandardItemModel(QStandardItemModel, LBase): class LStandardItemModel(QStandardItemModel):
def __init__(self, *argc, **kwarg): def __init__(self, *argc, **kwarg):
super().__init__(*argc, **kwarg) super().__init__(*argc, **kwarg)
self.__ls = [] self.__ls = []

View File

@ -17,7 +17,6 @@ from gui.dynalang import (
LPushButton, LPushButton,
LAction, LAction,
LGroupBox, LGroupBox,
LBase,
LFormLayout, LFormLayout,
LTabWidget, LTabWidget,
LStandardItemModel, LStandardItemModel,
@ -40,7 +39,7 @@ class FocusCombo(QComboBox):
return super().wheelEvent(e) return super().wheelEvent(e)
class LFocusCombo(FocusCombo, LBase): class LFocusCombo(FocusCombo):
def __init__(self, parent: QWidget = None) -> None: def __init__(self, parent: QWidget = None) -> None:
super().__init__(parent) super().__init__(parent)
self.__items = None self.__items = None
@ -91,7 +90,7 @@ class FocusDoubleSpin(QDoubleSpinBox):
return super().wheelEvent(e) return super().wheelEvent(e)
class TableViewW(QTableView, LBase): class TableViewW(QTableView):
def setIndexWidget(self, index: QModelIndex, w: QWidget): def setIndexWidget(self, index: QModelIndex, w: QWidget):
super().setIndexWidget(index, w) super().setIndexWidget(index, w)
if self.rowHeight(index.row()) < w.height(): if self.rowHeight(index.row()) < w.height():