From 7657b13c5f623582b04257b91a52d3499c128eb0 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: Fri, 2 Aug 2024 22:47:31 +0800 Subject: [PATCH] use --- .../LunaTranslator/gui/setting_display_text.py | 13 ++++++++++++- LunaTranslator/LunaTranslator/rendertext/webview.py | 9 ++++++--- LunaTranslator/files/defaultconfig/config.json | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_text.py b/LunaTranslator/LunaTranslator/gui/setting_display_text.py index e37df856..c4748785 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_text.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_text.py @@ -13,9 +13,11 @@ from gui.usefulwidget import ( getQMessageBox, D_getspinbox, D_getIconButton, + getboxlayout, D_getcolorbutton, getcolorbutton, MySwitch, + getsimpleswitch, D_getsimpleswitch, selectcolor, listediter, @@ -246,8 +248,17 @@ def resetgroudswitchcallback(self, group): self.seletengeinecombo.lastindex = self.seletengeinecombo.currentIndex() if group == "webview" or group == "QWebEngine": _btn = LPushButton("额外的html") - self.goodfontsettingsformlayout.addRow(_btn) _btn.clicked.connect(lambda: extrahtml(self)) + switch = getsimpleswitch( + globalconfig, + "useextrahtml", + callback=lambda x: [ + gobject.baseobject.translation_ui.translate_text.textbrowser.loadextra(0), + _btn.setEnabled(x), + ], + ) + _btn.setEnabled(globalconfig["useextrahtml"]) + self.goodfontsettingsformlayout.addRow(getboxlayout([_btn, switch])) if group == "QWebEngine": group = "webview" __form = LFormLayout() diff --git a/LunaTranslator/LunaTranslator/rendertext/webview.py b/LunaTranslator/LunaTranslator/rendertext/webview.py index 183516fa..508dd02c 100644 --- a/LunaTranslator/LunaTranslator/rendertext/webview.py +++ b/LunaTranslator/LunaTranslator/rendertext/webview.py @@ -109,10 +109,10 @@ class TextBrowser(QWidget, dataget): if not isinstance(self.webivewwidget, WebivewWidget): return self.isfirst = False - self.__loadextra(0) - self.webivewwidget.on_load.connect(self.__loadextra) + self.loadextra(0) + self.webivewwidget.on_load.connect(self.loadextra) - def __loadextra(self, _): + def loadextra(self, _): for _ in [ "userconfig/extrahtml.html", r"LunaTranslator\rendertext\exampleextrahtml.html", @@ -136,6 +136,9 @@ class TextBrowser(QWidget, dataget): self.debugeval(f"clear_all()") def set_extra_html(self, html): + if not globalconfig["useextrahtml"]: + self.debugeval(f'set_extra_html("")') + return html = quote(html) self.debugeval(f'set_extra_html("{html}")') diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 2f402f0c..e6834382 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -17,6 +17,7 @@ "read_translator": 0, "disappear_delay": 5, "network": 1, + "useextrahtml": true, "network_websocket": 1, "webview_textbrowser": false, "imagewrapmode": 0,