From 714c31846ef9e8d622cf35f61e5b7391b793f2e3 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: Tue, 13 Aug 2024 11:22:20 +0800 Subject: [PATCH] ui --- .../LunaTranslator/gui/setting_cishu.py | 59 ++++-- .../gui/setting_display_text.py | 144 ++++++++------ .../LunaTranslator/gui/setting_display_ui.py | 17 +- .../gui/setting_textinput_ocr.py | 2 +- .../LunaTranslator/gui/setting_tts.py | 176 ++++++++++++------ .../LunaTranslator/myutils/utils.py | 10 +- .../files/defaultconfig/config.json | 2 +- plugins/CMakeLists.txt | 2 +- 8 files changed, 276 insertions(+), 136 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/setting_cishu.py b/LunaTranslator/LunaTranslator/gui/setting_cishu.py index 9621153c..b9599ce2 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_cishu.py +++ b/LunaTranslator/LunaTranslator/gui/setting_cishu.py @@ -1,5 +1,6 @@ import functools, os import gobject +from myutils.utils import splitocrtypes from myutils.config import globalconfig from gui.inputdialog import autoinitdialog, autoinitdialog_items from gui.usefulwidget import ( @@ -108,21 +109,11 @@ def vistranslate_rank(self): ) -def setTabcishu_l(self): - - grids = [ - [ - ( - dict(title="分词器", type="grid", grid=gethiragrid(self)), - 0, - "group", - ) - ], - ] +def initinternal(self, names): cishugrid = [] line = [] i = 0 - for cishu in globalconfig["cishu"]: + for cishu in names: _f = "./LunaTranslator/cishu/{}.py".format(cishu) if os.path.exists(_f) == False: continue @@ -163,10 +154,52 @@ def setTabcishu_l(self): i += 1 if len(line): cishugrid.append(line) + return cishugrid + + +def setTabcishu_l(self): + + grids = [ + [ + ( + dict(title="分词器", type="grid", grid=gethiragrid(self)), + 0, + "group", + ) + ], + ] + offline, online = splitocrtypes(globalconfig["cishu"]) grids += [ [ ( - dict(title="辞书", type="grid", grid=cishugrid), + dict( + title="辞书", + type="grid", + grid=[ + [ + ( + dict( + title="离线", + type="grid", + grid=initinternal(self, offline), + ), + 0, + "group", + ) + ], + [ + ( + dict( + title="在线", + type="grid", + grid=initinternal(self, online), + ), + 0, + "group", + ) + ], + ], + ), 0, "group", ) diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_text.py b/LunaTranslator/LunaTranslator/gui/setting_display_text.py index 36e0370f..0eccd51c 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_text.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_text.py @@ -339,11 +339,6 @@ def _createseletengeinecombo(self): return self.seletengeinecombo -def __changeselectablestate(self, x): - gobject.baseobject.translation_ui.refreshtoolicon() - gobject.baseobject.translation_ui.translate_text.textbrowser.setselectable(x) - - def vistranslate_rank(self): _not = [] for i, k in enumerate(globalconfig["fix_translate_rank_rank"]): @@ -370,63 +365,94 @@ def xianshigrid_text(self): type="grid", grid=( [ - "可选取的", - D_getsimpleswitch( - globalconfig, - "selectable", - callback=functools.partial( - __changeselectablestate, self + ( + dict( + title="原文", + type="grid", + grid=( + [ + "显示原文", + D_getsimpleswitch( + globalconfig, + "isshowrawtext", + callback=lambda x: __changeuibuttonstate( + self, x + ), + name="show_original_switch", + parent=self, + ), + "", + "居中显示", + D_getsimpleswitch( + globalconfig, "showatcenter" + ), + "", + "最长显示字数", + D_getspinbox( + 0, + 1000000, + globalconfig, + "maxoriginlength", + ), + ], + ), ), - parent=self, - name="selectable_btn", - ), + 0, + "group", + ) ], [ - "显示原文", - D_getsimpleswitch( - globalconfig, - "isshowrawtext", - callback=lambda x: __changeuibuttonstate(self, x), - name="show_original_switch", - parent=self, - ), - "", - "最长显示字数", - D_getspinbox(0, 1000000, globalconfig, "maxoriginlength"), - "", - ], - [ - "显示翻译", - D_getsimpleswitch( - globalconfig, - "showfanyi", - callback=lambda x: __changeuibuttonstate2(self, x), - name="show_fany_switch", - parent=self, - ), - "", - ("显示翻译器名称"), - D_getsimpleswitch(globalconfig, "showfanyisource"), - "", - ], - [ - "收到翻译时才刷新", - D_getsimpleswitch(globalconfig, "refresh_on_get_trans"), - "", - "显示错误信息", - D_getsimpleswitch(globalconfig, "showtranexception"), - "", - ], - [ - "固定翻译显示顺序", - D_getsimpleswitch(globalconfig, "fix_translate_rank"), - D_getIconButton( - functools.partial(vistranslate_rank, self), "fa.gear" - ), - ], - [ - "居中显示", - D_getsimpleswitch(globalconfig, "showatcenter"), + ( + dict( + title="翻译", + type="grid", + grid=( + [ + "显示翻译", + D_getsimpleswitch( + globalconfig, + "showfanyi", + callback=lambda x: __changeuibuttonstate2( + self, x + ), + name="show_fany_switch", + parent=self, + ), + "", + "固定翻译显示顺序", + D_getsimpleswitch( + globalconfig, "fix_translate_rank" + ), + D_getIconButton( + functools.partial( + vistranslate_rank, self + ), + "fa.gear", + ), + ], + [ + "显示翻译器名称", + D_getsimpleswitch( + globalconfig, "showfanyisource" + ), + "", + "显示错误信息", + D_getsimpleswitch( + globalconfig, "showtranexception" + ), + "", + "", + "收到翻译时才刷新", + D_getsimpleswitch( + globalconfig, "refresh_on_get_trans" + ), + "", + ], + ), + ), + 0, + "group", + ) ], ), ), diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_ui.py b/LunaTranslator/LunaTranslator/gui/setting_display_ui.py index 16d7c451..ebfd5bdc 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_ui.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_ui.py @@ -251,6 +251,11 @@ def uisetting(self, l): do() +def __changeselectablestate(self, x): + gobject.baseobject.translation_ui.refreshtoolicon() + gobject.baseobject.translation_ui.translate_text.textbrowser.setselectable(x) + + def mainuisetting(self): return ( @@ -293,8 +298,16 @@ def mainuisetting(self): callback=lambda _: gobject.baseobject.translation_ui.set_color_transparency(), ), "", - "", - "", + "可选取的", + D_getsimpleswitch( + globalconfig, + "selectable", + callback=functools.partial( + __changeselectablestate, self + ), + parent=self, + name="selectable_btn", + ), ], ), ), diff --git a/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py b/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py index 0da636fe..5d3746d3 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py +++ b/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py @@ -132,7 +132,7 @@ def getocrgrid(self): grids = [] - offline, online = splitocrtypes() + offline, online = splitocrtypes(globalconfig["ocr"]) self.ocrswitchs = {} def vissolvebtn(): diff --git a/LunaTranslator/LunaTranslator/gui/setting_tts.py b/LunaTranslator/LunaTranslator/gui/setting_tts.py index 39b94c12..9b1765e5 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_tts.py +++ b/LunaTranslator/LunaTranslator/gui/setting_tts.py @@ -1,6 +1,7 @@ from qtsymbols import * import os, functools import gobject +from myutils.utils import splitocrtypes, translate_exits from myutils.config import globalconfig, static_data from gui.inputdialog import ( autoinitdialog_items, @@ -64,13 +65,13 @@ def setTab5(self, l): makescrollgrid(setTab5lz(self), l) -def getttsgrid(self): +def getttsgrid(self, names): grids = [] i = 0 self.ttswitchs = {} line = [] - for name in globalconfig["reader"]: + for name in names: _f = "./LunaTranslator/tts/{}.py".format(name) if os.path.exists(_f) == False: @@ -126,10 +127,45 @@ def getttsgrid(self): def setTab5lz(self): grids = [] + offline, online = splitocrtypes(globalconfig["reader"]) + alltransvis = [] + alltrans = [] + for x in globalconfig["fanyi"]: + if not translate_exits(x): + continue + alltransvis.append(globalconfig["fanyi"][x]["name"]) + alltrans.append(x) grids += [ [ ( - dict(title="引擎", type="grid", grid=getttsgrid(self)), + dict( + title="引擎", + type="grid", + grid=[ + [ + ( + dict( + title="离线", + type="grid", + grid=getttsgrid(self, offline), + ), + 0, + "group", + ) + ], + [ + ( + dict( + title="在线", + type="grid", + grid=getttsgrid(self, online), + ), + 0, + "group", + ) + ], + ], + ), 0, "group", ) @@ -164,64 +200,96 @@ def setTab5lz(self): type="grid", grid=[ [ - "自动朗读", - D_getsimpleswitch( - globalconfig, "autoread", name="autoread", parent=self - ), - ], - [ - "不被打断", - D_getsimpleswitch(globalconfig, "ttsnointerrupt"), - ], - [ - "朗读原文", - D_getsimpleswitch(globalconfig, "read_raw"), - ], - [ - "朗读翻译", - D_getsimpleswitch(globalconfig, "read_trans"), - ], - [ - "朗读的翻译", ( - D_getsimplecombobox( - [ - globalconfig["fanyi"][x]["name"] - for x in globalconfig["fanyi"] + dict( + type="grid", + grid=[ + [ + "自动朗读", + D_getsimpleswitch( + globalconfig, + "autoread", + name="autoread", + parent=self, + ), + "", + "不被打断", + D_getsimpleswitch( + globalconfig, "ttsnointerrupt" + ), + ], + [ + "朗读原文", + D_getsimpleswitch(globalconfig, "read_raw"), + "", + "朗读翻译", + D_getsimpleswitch( + globalconfig, "read_trans" + ), + D_getsimplecombobox( + alltransvis, + globalconfig, + "read_translator", + internal=alltrans, + ), + "", + ], ], - globalconfig, - "read_translator", ), 0, - ), + "group", + ) ], [ - "语音指定", - D_getsimpleswitch(globalconfig["ttscommon"], "tts_skip"), - D_getIconButton( - callback=lambda: yuyinzhidingsetting( - self, globalconfig["ttscommon"]["tts_skip_regex"] + ( + dict( + type="grid", + grid=[ + [ + "语音指定", + D_getsimpleswitch( + globalconfig["ttscommon"], "tts_skip" + ), + D_getIconButton( + callback=lambda: yuyinzhidingsetting( + self, + globalconfig["ttscommon"][ + "tts_skip_regex" + ], + ), + icon="fa.gear", + ), + ], + [ + "语音修正", + D_getsimpleswitch( + globalconfig["ttscommon"], "tts_repair" + ), + D_getIconButton( + callback=lambda: noundictconfigdialog1( + self, + globalconfig["ttscommon"][ + "tts_repair_regex" + ], + "语音修正", + ["正则", "转义", "原文", "替换"], + ), + icon="fa.gear", + ), + "", + D_getsimpleswitch( + globalconfig["ttscommon"], + "tts_repair_use_at_translate", + ), + "作用于翻译", + "", + "", + ], + ], ), - icon="fa.gear", - ), - ], - [ - "语音修正", - D_getsimpleswitch(globalconfig["ttscommon"], "tts_repair"), - D_getIconButton( - callback=lambda: noundictconfigdialog1( - self, - globalconfig["ttscommon"]["tts_repair_regex"], - "语音修正", - ["正则", "转义", "原文", "替换"], - ), - icon="fa.gear", - ), - "", - D_getsimpleswitch( - globalconfig["ttscommon"], "tts_repair_use_at_translate" - ), - "作用于翻译", + 0, + "group", + ) ], ], ), diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index 4e11abd4..05bedbba 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -317,13 +317,13 @@ def splittranslatortypes(): return offline, pre, free, dev, api -def splitocrtypes(): +def splitocrtypes(dic): offline, online = [], [] - for k in globalconfig["ocr"]: + for k in dic: try: - {"online": online, "offline": offline}[ - globalconfig["ocr"][k].get("type", "online") - ].append(k) + {"online": online, "offline": offline}[dic[k].get("type", "online")].append( + k + ) except: pass diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index da7f7c12..d66f1339 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -1055,7 +1055,7 @@ }, "reader": { "windowstts": { - "use": false, + "use": true, "voice": "", "name": "WindowsTTS", "type": "offline" diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 41532bde..7d958b74 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 5) set(VERSION_MINOR 26) -set(VERSION_PATCH 2) +set(VERSION_PATCH 3) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)