From 22604a0eb54fadecd9a477b49bf9755a4de2caae 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, 11 Jul 2024 14:53:06 +0800 Subject: [PATCH] fix --- .../LunaTranslator/gui/setting_display_ui.py | 8 +++- .../LunaTranslator/gui/textbrowser.py | 30 +------------- .../LunaTranslator/gui/translatorUI.py | 39 +++++++++++-------- .../LunaTranslator/rendertext/webview.py | 38 +++++++++++++++++- .../files/defaultconfig/config.json | 2 +- LunaTranslator/files/lang/ar.json | 3 +- LunaTranslator/files/lang/cht.json | 3 +- LunaTranslator/files/lang/en.json | 3 +- LunaTranslator/files/lang/es.json | 3 +- LunaTranslator/files/lang/fr.json | 3 +- LunaTranslator/files/lang/it.json | 3 +- LunaTranslator/files/lang/ja.json | 3 +- LunaTranslator/files/lang/ko.json | 3 +- LunaTranslator/files/lang/pl.json | 3 +- LunaTranslator/files/lang/ru.json | 3 +- LunaTranslator/files/lang/th.json | 3 +- LunaTranslator/files/lang/tr.json | 3 +- LunaTranslator/files/lang/uk.json | 3 +- LunaTranslator/files/lang/vi.json | 3 +- LunaTranslator/files/lang/zh.json | 3 +- 20 files changed, 98 insertions(+), 64 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_ui.py b/LunaTranslator/LunaTranslator/gui/setting_display_ui.py index 3ce11100..650c5225 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_ui.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_ui.py @@ -363,7 +363,7 @@ def uisetting(self): ), ], [ - ("锁定工具栏"), + "锁定工具栏", D_getsimpleswitch( globalconfig, "locktools", @@ -383,6 +383,12 @@ def uisetting(self): callback=lambda _: toolcolorchange(), ), "", + "延申", + D_getsimpleswitch( + globalconfig, + "extendtools", + callback=gobject.baseobject.translation_ui.changeextendstated_1 + ), ], ), ), diff --git a/LunaTranslator/LunaTranslator/gui/textbrowser.py b/LunaTranslator/LunaTranslator/gui/textbrowser.py index 4e18dedc..9305b38c 100644 --- a/LunaTranslator/LunaTranslator/gui/textbrowser.py +++ b/LunaTranslator/LunaTranslator/gui/textbrowser.py @@ -8,28 +8,11 @@ from gui.usefulwidget import getQMessageBox class Textbrowser(QLabel): contentsChanged = pyqtSignal(QSize) - _padding = 5 - - def __makeborder(self, size: QSize): - _padding = self._padding - self.masklabel_right.move(self.width() - _padding, 0) - self.masklabel_bottom.move(0, 0 + size.height() - _padding) - self.masklabel_left.resize(_padding, size.height()) - self.masklabel_right.resize(_padding, size.height()) - self.masklabel_bottom.resize(size.width(), _padding) - def resizeEvent(self, event: QResizeEvent): - _padding = self._padding - self.textbrowser.setGeometry( - _padding, - 0, - event.size().width() - 2 * _padding, - event.size().height() - _padding, - ) - self.__makeborder(event.size()) + self.textbrowser.resize(event.size()) def _contentsChanged(self, size: QSize): - self.contentsChanged.emit(QSize(size.width(), size.height())) + self.contentsChanged.emit(size) def loadinternal(self): __ = globalconfig["rendertext_using"] @@ -63,15 +46,6 @@ class Textbrowser(QLabel): self.setMouseTracking(True) self.cleared = True self.loadinternal() - self.masklabel_left = QLabel(self) - self.masklabel_left.setMouseTracking(True) - # self.masklabel_left.setStyleSheet('background-color:red') - self.masklabel_right = QLabel(self) - # self.masklabel_right.setStyleSheet('background-color:red') - self.masklabel_right.setMouseTracking(True) - self.masklabel_bottom = QLabel(self) - self.masklabel_bottom.setMouseTracking(True) - # self.masklabel_bottom.setStyleSheet('background-color:red') def iter_append(self, iter_context_class, origin, atcenter, text, color): cleared = self.cleared diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 62923b2b..185b98e6 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -270,12 +270,12 @@ class QUnFrameWindow(resizableframeless): self.buttons[name].setIconSize( QSize(globalconfig["buttonsize"], globalconfig["buttonsize"]) ) - self.translate_text.move(0, int(globalconfig["buttonsize"] * 1.5)) self.setMinimumHeight(int(globalconfig["buttonsize"] * 1.5 + 10)) - self.setMinimumWidth(globalconfig["buttonsize"] * 2) + self.setMinimumWidth(globalconfig["buttonsize"] * 10) self.set_color_transparency() self.seteffect() self.adjustbuttons() + self.changeextendstated() def ocr_once_function(self): @threader @@ -416,6 +416,14 @@ class QUnFrameWindow(resizableframeless): belong, ) + def changeextendstated(self): + + self.translate_text.move(0, self.dynamicextraheight()) + + def changeextendstated_1(self, extend): + self.changeextendstated() + self.resize(self.width(), self.height() + [-1, 1][extend]) + def hide_(self): if globalconfig["showintab"]: windows.ShowWindow(int(self.winId()), windows.SW_SHOWMINIMIZED) @@ -581,6 +589,7 @@ class QUnFrameWindow(resizableframeless): self.translate_text = Textbrowser(self) self.translate_text.contentsChanged.connect(self.textAreaChanged) self.translate_text.textbrowser.setselectable(globalconfig["selectable"]) + self._TitleLabel.raise_() t = QTimer(self) t.setInterval(100) self._isentered = False @@ -646,13 +655,11 @@ class QUnFrameWindow(resizableframeless): ) topr = self.createborderradiusstring( rate * use_r1, - globalconfig["yuanjiao_merge"] and self._TitleLabel.isVisible(), + globalconfig["extendtools"] and self._TitleLabel.isVisible(), False, ) bottomr3 = self.createborderradiusstring(use_r2, False) - bottomr = self.createborderradiusstring( - rate * use_r2, globalconfig["yuanjiao_merge"], True - ) + bottomr = self.createborderradiusstring(rate * use_r2, True, True) self.translate_text.setStyleSheet( "Textbrowser{border-width: 0;%s;background-color: %s}" @@ -834,6 +841,9 @@ class QUnFrameWindow(resizableframeless): globalconfig["locktools"] = not globalconfig["locktools"] self.refreshtoolicon() + def dynamicextraheight(self): + return int(globalconfig["extendtools"]) * int(globalconfig["buttonsize"] * 1.5) + def textAreaChanged(self, size: QSize): if self.translate_text.cleared: @@ -841,9 +851,7 @@ class QUnFrameWindow(resizableframeless): if not globalconfig["adaptive_height"]: return limit = min(size.height(), self.screen().geometry().height()) - newHeight = ( - limit + self.translate_text._padding + int(globalconfig["buttonsize"] * 1.5) - ) + newHeight = limit + self.dynamicextraheight() size = QSize(self.width(), newHeight) self.autoresizesig = uuid.uuid4() if newHeight > self.height(): @@ -854,7 +862,7 @@ class QUnFrameWindow(resizableframeless): @threader def delaymaybeshrink(self, size: QSize, sig): - time.sleep(0.1) + time.sleep(0.2) if sig != self.autoresizesig: return self.resizesignal.emit(size) @@ -884,8 +892,6 @@ class QUnFrameWindow(resizableframeless): def toolbarhidedelay(self): - for button in self.buttons.values(): - button.hide() self._TitleLabel.hide() self.set_color_transparency() @@ -929,8 +935,6 @@ class QUnFrameWindow(resizableframeless): self.toolbarhidedelaysignal.emit() def enterfunction(self, delay=None): - for button in self.showbuttons: - button.show() self._TitleLabel.show() self.set_color_transparency() @@ -938,7 +942,7 @@ class QUnFrameWindow(resizableframeless): def resizeEvent(self, e: QResizeEvent): super().resizeEvent(e) - wh = globalconfig["buttonsize"] * 1.5 + wh = self.dynamicextraheight() height = self.height() - wh self.translate_text.resize(self.width(), int(height)) @@ -999,7 +1003,7 @@ class QUnFrameWindow(resizableframeless): def takusanbuttons(self, _type, clickfunc, tips, name, belong=None): if clickfunc: - button = QPushButton(self) + button = QPushButton(self._TitleLabel) button.clicked.connect(functools.partial(self.callwrap, clickfunc)) else: @@ -1007,6 +1011,7 @@ class QUnFrameWindow(resizableframeless): def __init__(self, p): super().__init__(p) self._lb = QLabel(p) + self._lb.setStyleSheet("background-color: transparent;") self._lb.raise_() def hideEvent(self, _): @@ -1021,7 +1026,7 @@ class QUnFrameWindow(resizableframeless): def resizeEvent(self, event): self._lb.resize(event.size()) - button = __(self) + button = __(self._TitleLabel) if tips: button.setToolTip(_TR(tips)) diff --git a/LunaTranslator/LunaTranslator/rendertext/webview.py b/LunaTranslator/LunaTranslator/rendertext/webview.py index 31ae6919..498d8fd4 100644 --- a/LunaTranslator/LunaTranslator/rendertext/webview.py +++ b/LunaTranslator/LunaTranslator/rendertext/webview.py @@ -11,11 +11,30 @@ testsavejs = False class TextBrowser(QWidget, dataget): contentsChanged = pyqtSignal(QSize) + _padding = 5 + + def __makeborder(self, size: QSize): + _padding = self._padding + self.masklabel_top.setGeometry(0, 0, size.width(), _padding) + + self.masklabel_left.setGeometry(0, 0, _padding, size.height()) + self.masklabel_right.setGeometry( + self.width() - _padding, 0, _padding, size.height() + ) + self.masklabel_bottom.setGeometry( + 0, size.height() - _padding, size.width(), _padding + ) @tryprint def resizeEvent(self, event: QResizeEvent): - self.webivewwidget.resize(event.size()) + self.webivewwidget.setGeometry( + self._padding, + self._padding, + event.size().width() - 2 * self._padding, + event.size().height() - 2 * self._padding, + ) self.masklabel.resize(event.size()) + self.__makeborder(event.size()) def setselectable(self, b): self.masklabel.setHidden(b) @@ -29,6 +48,18 @@ class TextBrowser(QWidget, dataget): # webview2当会执行alert之类的弹窗js时,若qt窗口不可视,会卡住 self.webivewwidget = WebivewWidget(self) + self.masklabel_left = QLabel(self) + self.masklabel_left.setMouseTracking(True) + # self.masklabel_left.setStyleSheet('background-color:red') + self.masklabel_right = QLabel(self) + # self.masklabel_right.setStyleSheet('background-color:red') + self.masklabel_right.setMouseTracking(True) + self.masklabel_bottom = QLabel(self) + self.masklabel_bottom.setMouseTracking(True) + self.masklabel_top = QLabel(self) + self.masklabel_top.setMouseTracking(True) + # self.masklabel_bottom.setStyleSheet('background-color:red') + self.masklabel = QLabel(self.webivewwidget) self.masklabel.setMouseTracking(True) self.webivewwidget.navigate( @@ -126,7 +157,10 @@ class TextBrowser(QWidget, dataget): def calllunaheightchange(self, h): self.contentsChanged.emit( - QSize(self.width(), int(h * self.webivewwidget.get_zoom())) + QSize( + self.width(), + 1 + self._padding * 2 + int(h * self.webivewwidget.get_zoom()), + ) ) def calllunaclickedword(self, wordinfo): diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 0d45562c..565fa5eb 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -349,7 +349,6 @@ "maxBufferSize": 3000, "maxHistorySize": 1000000, "yuanjiao_r": 0, - "yuanjiao_merge": true, "qwebinspectgeo": [ 100, 100, @@ -459,6 +458,7 @@ "backcolor_tool": "#3f3f3f", "isshowhira": false, "locktools": true, + "extendtools": true, "showfanyisource": false, "use_yapi": false, "showfanyi": true, diff --git a/LunaTranslator/files/lang/ar.json b/LunaTranslator/files/lang/ar.json index e7750b96..13a8652a 100644 --- a/LunaTranslator/files/lang/ar.json +++ b/LunaTranslator/files/lang/ar.json @@ -815,5 +815,6 @@ "音量": "حجم", "固定翻译显示顺序": "ترجمة ثابتة عرض تسلسل", "显示顺序": "عرض تسلسل", - "安装": "تركيب ." + "安装": "تركيب .", + "延申": "تمديد" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/cht.json b/LunaTranslator/files/lang/cht.json index dbf316be..53df6a2e 100644 --- a/LunaTranslator/files/lang/cht.json +++ b/LunaTranslator/files/lang/cht.json @@ -815,5 +815,6 @@ "音量": "音量", "固定翻译显示顺序": "固定翻譯顯示順序", "显示顺序": "顯示順序", - "安装": "安裝" + "安装": "安裝", + "延申": "延申" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/en.json b/LunaTranslator/files/lang/en.json index d899520b..e74a8438 100644 --- a/LunaTranslator/files/lang/en.json +++ b/LunaTranslator/files/lang/en.json @@ -815,5 +815,6 @@ "音量": "Volume", "固定翻译显示顺序": "Fixed translation display order", "显示顺序": "Display order", - "安装": "install" + "安装": "install", + "延申": "Extension" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/es.json b/LunaTranslator/files/lang/es.json index 1c12ab7e..9f600647 100644 --- a/LunaTranslator/files/lang/es.json +++ b/LunaTranslator/files/lang/es.json @@ -815,5 +815,6 @@ "音量": "Volumen", "固定翻译显示顺序": "Orden fijo de visualización de la traducción", "显示顺序": "Orden de visualización", - "安装": "Instalación" + "安装": "Instalación", + "延申": "Extensión" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/fr.json b/LunaTranslator/files/lang/fr.json index b6aeb1a0..f780853e 100644 --- a/LunaTranslator/files/lang/fr.json +++ b/LunaTranslator/files/lang/fr.json @@ -815,5 +815,6 @@ "音量": "Volume", "固定翻译显示顺序": "Ordre fixe d'affichage de la traduction", "显示顺序": "Ordre d'affichage", - "安装": "Installation" + "安装": "Installation", + "延申": "Yanshin" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/it.json b/LunaTranslator/files/lang/it.json index 970417a0..6df4c5ec 100644 --- a/LunaTranslator/files/lang/it.json +++ b/LunaTranslator/files/lang/it.json @@ -815,5 +815,6 @@ "音量": "volume", "固定翻译显示顺序": "Ordine fisso di visualizzazione della traduzione", "显示顺序": "Ordine di visualizzazione", - "安装": "installa" + "安装": "installa", + "延申": "Estensione" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ja.json b/LunaTranslator/files/lang/ja.json index 3afc3f47..c393407e 100644 --- a/LunaTranslator/files/lang/ja.json +++ b/LunaTranslator/files/lang/ja.json @@ -815,5 +815,6 @@ "音量": "音量", "固定翻译显示顺序": "固定翻訳表示順序", "显示顺序": "表示順序", - "安装": "インストール" + "安装": "インストール", + "延申": "に言及" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ko.json b/LunaTranslator/files/lang/ko.json index 5d23834d..417082fb 100644 --- a/LunaTranslator/files/lang/ko.json +++ b/LunaTranslator/files/lang/ko.json @@ -815,5 +815,6 @@ "音量": "볼륨", "固定翻译显示顺序": "고정 번역 표시 순서", "显示顺序": "표시 순서", - "安装": "설치" + "安装": "설치", + "延申": "연장" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/pl.json b/LunaTranslator/files/lang/pl.json index d77f5d08..1e91b928 100644 --- a/LunaTranslator/files/lang/pl.json +++ b/LunaTranslator/files/lang/pl.json @@ -815,5 +815,6 @@ "音量": "objętość", "固定翻译显示顺序": "Stała kolejność wyświetlania tłumaczeń", "显示顺序": "Kolejność wyświetlania", - "安装": "instaluj" + "安装": "instaluj", + "延申": "Rozszerzenie" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ru.json b/LunaTranslator/files/lang/ru.json index 1418d6c6..f53cde4e 100644 --- a/LunaTranslator/files/lang/ru.json +++ b/LunaTranslator/files/lang/ru.json @@ -815,5 +815,6 @@ "音量": "Громкость", "固定翻译显示顺序": "Фиксированный перевод Показать порядок", "显示顺序": "Показать последовательность", - "安装": "Монтаж" + "安装": "Монтаж", + "延申": "Яньшэнь" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/th.json b/LunaTranslator/files/lang/th.json index dff444ca..ea018cb7 100644 --- a/LunaTranslator/files/lang/th.json +++ b/LunaTranslator/files/lang/th.json @@ -815,5 +815,6 @@ "音量": "ระดับเสียง", "固定翻译显示顺序": "ลำดับการแสดงผลการแปลคงที่", "显示顺序": "แสดงลำดับ", - "安装": "การติดตั้ง" + "安装": "การติดตั้ง", + "延申": "ยันชิน" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/tr.json b/LunaTranslator/files/lang/tr.json index f6a28c3b..2ffd7326 100644 --- a/LunaTranslator/files/lang/tr.json +++ b/LunaTranslator/files/lang/tr.json @@ -815,5 +815,6 @@ "音量": "volume", "固定翻译显示顺序": "Fikir çeviri gösterme düzeni", "显示顺序": "Gösterim düzeni", - "安装": "Kur" + "安装": "Kur", + "延申": "Uzantı" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/uk.json b/LunaTranslator/files/lang/uk.json index d8df8635..ae083ccf 100644 --- a/LunaTranslator/files/lang/uk.json +++ b/LunaTranslator/files/lang/uk.json @@ -815,5 +815,6 @@ "音量": "гучність", "固定翻译显示顺序": "Визначений порядок показу перекладу", "显示顺序": "Порядок показу", - "安装": "встановити" + "安装": "встановити", + "延申": "Розширення" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/vi.json b/LunaTranslator/files/lang/vi.json index 9c7b46f6..0a551ce7 100644 --- a/LunaTranslator/files/lang/vi.json +++ b/LunaTranslator/files/lang/vi.json @@ -815,5 +815,6 @@ "音量": "Âm lượng", "固定翻译显示顺序": "Trình tự hiển thị bản dịch cố định", "显示顺序": "Thứ tự hiển thị", - "安装": "Cài đặt" + "安装": "Cài đặt", + "延申": "Dương Thân" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index 54a27a52..47b6308a 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -815,5 +815,6 @@ "音量": "", "固定翻译显示顺序": "", "显示顺序": "", - "安装": "" + "安装": "", + "延申": "" } \ No newline at end of file