From 731ab0a08f2eb6e731745ee98b80da6e729a5437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Thu, 30 May 2024 14:39:23 +0800 Subject: [PATCH] update --- .../LunaTranslator/gui/dialog_savedgame.py | 8 +++++- LunaTranslator/LunaTranslator/gui/edittext.py | 11 ++------ LunaTranslator/LunaTranslator/gui/showword.py | 10 ++----- .../LunaTranslator/gui/textbrowser.py | 2 +- .../LunaTranslator/gui/translatorUI.py | 28 +++++++++---------- .../LunaTranslator/gui/usefulwidget.py | 10 ++++--- .../LunaTranslator/myutils/utils.py | 9 ++++++ .../files/defaultconfig/config.json | 3 +- plugins/CMakeLists.txt | 2 +- 9 files changed, 45 insertions(+), 38 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index de9325d1..21fa037d 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -24,6 +24,7 @@ import winsharedutils from myutils.wrapper import Singleton_close, Singleton, threader, tryprint from myutils.utils import ( checkifnewgame, + str2rgba, vidchangedtask, titlechangedtask, imgchangedtask, @@ -57,7 +58,7 @@ class ItemWidget(QWidget): def mousePressEvent(self, ev) -> None: try: self.bottommask.setStyleSheet( - f'background-color: {globalconfig["dialog_savegame_layout"]["onselectcolor"]};' + f'background-color: {str2rgba(globalconfig["dialog_savegame_layout"]["onselectcolor"],globalconfig["dialog_savegame_layout"]["transparent"])};' ) if self != ItemWidget.globallashfocus: @@ -121,6 +122,7 @@ class ItemWidget(QWidget): c = globalconfig["dialog_savegame_layout"][ ("onfilenoexistscolor", "backcolor")[os.path.exists(exe)] ] + c = str2rgba(c, globalconfig["dialog_savegame_layout"]["transparent"]) self.maskshowfileexists.setStyleSheet(f"background-color:{c};") @@ -1221,6 +1223,10 @@ class dialog_syssetting(QDialog): parent=self, ), ) + formLayout.addRow( + (_TR("不透明度")), + getspinbox(0, 100, globalconfig["dialog_savegame_layout"], "transparent"), + ) formLayout.addRow( _TR("缩放"), getsimplecombobox( diff --git a/LunaTranslator/LunaTranslator/gui/edittext.py b/LunaTranslator/LunaTranslator/gui/edittext.py index 5497300d..ca716220 100644 --- a/LunaTranslator/LunaTranslator/gui/edittext.py +++ b/LunaTranslator/LunaTranslator/gui/edittext.py @@ -4,7 +4,7 @@ import threading, windows import gobject, time from myutils.config import globalconfig, _TR from gui.usefulwidget import closeashidewindow, saveposwindow -from myutils.config import globalconfig +from myutils.utils import str2rgba from myutils.wrapper import Singleton_close, threader @@ -97,13 +97,8 @@ class edittrans(QMainWindow): super().__init__(parent, Qt.WindowType.FramelessWindowHint) self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) self.setStyleSheet( - "background-color: rgba(%s, %s, %s, %s)" - % ( - int(globalconfig["backcolor"][1:3], 16), - int(globalconfig["backcolor"][3:5], 16), - int(globalconfig["backcolor"][5:7], 16), - globalconfig["transparent"], - ) + "background-color: %s" + % str2rgba(globalconfig["backcolor"], globalconfig["transparent"]) ) self.setupUi() diff --git a/LunaTranslator/LunaTranslator/gui/showword.py b/LunaTranslator/LunaTranslator/gui/showword.py index e30f3a8f..f3a8dbe3 100644 --- a/LunaTranslator/LunaTranslator/gui/showword.py +++ b/LunaTranslator/LunaTranslator/gui/showword.py @@ -19,6 +19,7 @@ from gui.usefulwidget import ( getsimpleswitch, getsimplekeyseq, getcolorbutton, + makesubtab_lazy, tabadd_lazy, ) from myutils.subproc import subproc_w @@ -142,7 +143,7 @@ class AnkiWindow(QWidget): self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) self.setWindowTitle("Anki Connect") self.currentword = "" - self.tabs = QTabWidget() + self.tabs = makesubtab_lazy(callback=self.ifshowrefresh) self.tabs.addTab(self.createaddtab(), _TR("添加")) tabadd_lazy(self.tabs, "设置", self.creatsetdtab) tabadd_lazy(self.tabs, "模板", self.creattemplatetab) @@ -156,13 +157,6 @@ class AnkiWindow(QWidget): self.tabs.currentChanged.connect(self.ifshowrefresh) def ifshowrefresh(self, idx): - try: - w = self.tabs.currentWidget() - if "lazyfunction" in dir(w): - w.lazyfunction() - delattr(w, "lazyfunction") - except: - print_exc() if idx == 2: self.refreshhtml.emit() diff --git a/LunaTranslator/LunaTranslator/gui/textbrowser.py b/LunaTranslator/LunaTranslator/gui/textbrowser.py index ab452f32..9c235f96 100644 --- a/LunaTranslator/LunaTranslator/gui/textbrowser.py +++ b/LunaTranslator/LunaTranslator/gui/textbrowser.py @@ -211,6 +211,7 @@ class Textbrowser(QLabel): def resizeEvent(self, event): self.atback2.resize(event.size()) self.toplabel2.resize(event.size()) + self.masklabel.resize(event.size()) def contentchangedfunction(self): sz = self.textbrowser.document().size().toSize() @@ -250,7 +251,6 @@ class Textbrowser(QLabel): Qt.ScrollBarPolicy.ScrollBarAlwaysOff ) self.masklabel = QLabel(self.textbrowser) - self.masklabel.setGeometry(0, 0, 9999, 9999) self.masklabel.setMouseTracking(True) self.savetaglabels = [] diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 8cfc80b8..652176fd 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -12,7 +12,7 @@ import winsharedutils from myutils.config import globalconfig, saveallconfig, _TR, static_data from myutils.subproc import endsubprocs from myutils.ocrutil import ocr_run, imageCut -from myutils.utils import loadpostsettingwindowmethod, getimageformat +from myutils.utils import loadpostsettingwindowmethod, getimageformat, str2rgba from myutils.hwnd import mouseselectwindow, grabwindow, getExeIcon from gui.dialog_savedgame import dialog_savedgame_new from gui.dialog_memory import dialog_memory @@ -699,23 +699,22 @@ class QUnFrameWindow(resizableframeless): ) self.translate_text.setStyleSheet( - "border-width: 0;%s;background-color: rgba(%s, %s, %s, %s)" + "border-width: 0;%s;background-color: %s" % ( topr, - int(globalconfig["backcolor"][1:3], 16), - int(globalconfig["backcolor"][3:5], 16), - int(globalconfig["backcolor"][5:7], 16), - globalconfig["transparent"] * (not self.backtransparent) / 100, + str2rgba( + globalconfig["backcolor"], + globalconfig["transparent"] * (not self.backtransparent), + ), ) ) self._TitleLabel.setStyleSheet( - "border-width: 0;%s;background-color: rgba(%s, %s, %s, %s)" + "border-width: 0;%s;background-color: %s" % ( bottomr, - int(globalconfig["backcolor_tool"][1:3], 16), - int(globalconfig["backcolor_tool"][3:5], 16), - int(globalconfig["backcolor_tool"][5:7], 16), - globalconfig["transparent_tool"] / 100, + str2rgba( + globalconfig["backcolor_tool"], globalconfig["transparent_tool"] + ), ) ) for _type in self.stylebuttons: @@ -951,14 +950,15 @@ class QUnFrameWindow(resizableframeless): self.dodelayhide(delay) - def resizeEvent(self, e): + def resizeEvent(self, e: QResizeEvent): super().resizeEvent(e) wh = globalconfig["buttonsize"] * 1.5 height = self.height() - wh self.translate_text.resize(self.width(), int(height)) - self.adjustbuttons() - self._TitleLabel.setFixedWidth(self.width()) + if e.oldSize().width() != e.size().width(): + self.adjustbuttons() + self._TitleLabel.setFixedWidth(self.width()) def adjustbuttons(self): left = [] diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index 17889d55..2850ee5c 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -117,10 +117,10 @@ class closeashidewindow(saveposwindow): def showfunction(self): if self.isMinimized(): self.showNormal() - elif self.isHidden(): - self.show() - else: + elif self.isVisible(): self.hide() + else: + self.show() def closeEvent(self, event: QCloseEvent): self.hide() @@ -812,7 +812,7 @@ def makegrid(grid, save=False, savelist=None, savelay=None): return gridlayoutwidget -def makesubtab_lazy(titles=None, functions=None, klass=None): +def makesubtab_lazy(titles=None, functions=None, klass=None, callback=None): if klass: tab = klass() else: @@ -826,6 +826,8 @@ def makesubtab_lazy(titles=None, functions=None, klass=None): delattr(w, "lazyfunction") except: print_exc() + if callback: + callback(i) tab.currentChanged.connect(functools.partial(__, tab)) if titles and functions: diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index 8e049d72..340dd953 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -623,3 +623,12 @@ def parsekeystringtomodvkcode(keystring, modes=False): if modes: mode = _modes return mode, vkcode + + +def str2rgba(string, alpha100): + return "rgba(%s, %s, %s, %s)" % ( + int(string[1:3], 16), + int(string[3:5], 16), + int(string[5:7], 16), + alpha100 / 100, + ) diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 2d32af34..cfbf121a 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -240,7 +240,8 @@ "textH": 50, "backcolor": "#c38282", "onselectcolor": "#007fff", - "onfilenoexistscolor": "#acacac" + "onfilenoexistscolor": "#acacac", + "transparent": 25 }, "profiles_index": 0, "ocrautobindwindow": true, diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 381ff61e..acd8be6b 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 3) set(VERSION_MINOR 0) -set(VERSION_PATCH 2) +set(VERSION_PATCH 3) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)