From 78398bc624c6b9e46c9cf599e30705e98ceaec0f 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: Sun, 14 Jul 2024 01:46:07 +0800 Subject: [PATCH] split --- .../LunaTranslator/gui/setting_proxy.py | 9 ++-- .../gui/setting_textinput_ocr.py | 52 +++++++++++++++---- .../LunaTranslator/gui/setting_translate.py | 5 +- .../LunaTranslator/myutils/utils.py | 17 +++++- 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 +- 19 files changed, 91 insertions(+), 37 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/setting_proxy.py b/LunaTranslator/LunaTranslator/gui/setting_proxy.py index cb3726c7..f10c63bc 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_proxy.py +++ b/LunaTranslator/LunaTranslator/gui/setting_proxy.py @@ -16,10 +16,7 @@ def getall(l, item="fanyi", name=None): grids = [] i = 0 line = [] - for fanyi in globalconfig[item]: - - if fanyi not in l: - continue + for fanyi in l: if name: _f = name % fanyi if not os.path.exists(_f): @@ -103,7 +100,7 @@ def makeproxytab(self, basel): name="./Lunatranslator/ocrengines/%s.py", ) meta = getall( - l=list(globalconfig["metadata"].keys()), + l=globalconfig["metadata"], item="metadata", name="./LunaTranslator/metadata/%s.py", ) @@ -123,7 +120,7 @@ def makeproxytab(self, basel): name="./LunaTranslator/hiraparse/%s.py", ) github = getall( - l=list(globalconfig["github"].keys()), + l=globalconfig["github"], item="github", ) diff --git a/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py b/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py index b02c5a32..4d75906c 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py +++ b/LunaTranslator/LunaTranslator/gui/setting_textinput_ocr.py @@ -2,6 +2,7 @@ from qtsymbols import * import functools, os import gobject from myutils.config import globalconfig, ocrsetting, _TRL, ocrerrorfix, _TR +from myutils.utils import splitocrtypes from gui.inputdialog import autoinitdialog, postconfigdialog, autoinitdialog_items from gui.usefulwidget import ( D_getsimplecombobox, @@ -24,16 +25,11 @@ def __label2(self): return self.threshold2label -def getocrgrid(self): - - grids = [] - grids_source = [] - i = 0 - - self.ocrswitchs = {} +def initgridsources(self, names): line = [] - for name in globalconfig["ocr"]: - + i = 0 + grids_source = [] + for name in names: _f = "./Lunatranslator/ocrengines/{}.py".format(name) if os.path.exists(_f) == False: continue @@ -75,6 +71,15 @@ def getocrgrid(self): i += 1 if len(line): grids_source.append(line) + return grids_source + + +def getocrgrid(self): + + grids = [] + + offline, online = splitocrtypes() + self.ocrswitchs = {} def vissolvebtn(text): _ = QPushButton() @@ -85,7 +90,34 @@ def getocrgrid(self): grids += [ [ ( - dict(title="引擎", type="grid", grid=grids_source), + dict( + title="引擎", + type="grid", + grid=[ + [ + ( + dict( + title="离线", + type="grid", + grid=initgridsources(self, offline), + ), + 0, + "group", + ) + ], + [ + ( + dict( + title="在线", + type="grid", + grid=initgridsources(self, online), + ), + 0, + "group", + ) + ], + ], + ), 0, "group", ) diff --git a/LunaTranslator/LunaTranslator/gui/setting_translate.py b/LunaTranslator/LunaTranslator/gui/setting_translate.py index a645ff03..1a19177c 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_translate.py +++ b/LunaTranslator/LunaTranslator/gui/setting_translate.py @@ -32,10 +32,7 @@ def initsome11(self, l, label=None): grids.append([(label, 8)]) i = 0 line = [] - for fanyi in globalconfig["fanyi"]: - - if fanyi not in l: - continue + for fanyi in l: _f = "./Lunatranslator/translator/{}.py".format(fanyi) if not os.path.exists(_f): diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index d0d4daad..875b5135 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -281,18 +281,31 @@ def checkportavailable(port): def splittranslatortypes(): - pre, offline, free, dev, api = set(), set(), set(), set(), set() + pre, offline, free, dev, api = [], [], [], [], [] for k in globalconfig["fanyi"]: try: {"pre": pre, "offline": offline, "free": free, "dev": dev, "api": api}[ globalconfig["fanyi"][k].get("type", "free") - ].add(k) + ].append(k) except: pass return offline, pre, free, dev, api +def splitocrtypes(): + offline, online = [], [] + for k in globalconfig["ocr"]: + try: + {"online": online, "offline": offline}[ + globalconfig["ocr"][k].get("type", "online") + ].append(k) + except: + pass + + return offline, online + + def argsort(l): ll = list(range(len(l))) ll.sort(key=lambda x: l[x]) diff --git a/LunaTranslator/files/lang/ar.json b/LunaTranslator/files/lang/ar.json index 53980b36..a4213485 100644 --- a/LunaTranslator/files/lang/ar.json +++ b/LunaTranslator/files/lang/ar.json @@ -818,5 +818,6 @@ "游戏数据": "بيانات اللعبة", "当前支持的语言": "اللغات المدعومة حاليا", "添加语言包": "إضافة حزمة اللغة", - "未添加": "لا إضافة" + "未添加": "لا إضافة", + "在线": "آنلاین" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/cht.json b/LunaTranslator/files/lang/cht.json index 7fcddd31..2def75b2 100644 --- a/LunaTranslator/files/lang/cht.json +++ b/LunaTranslator/files/lang/cht.json @@ -818,5 +818,6 @@ "游戏数据": "遊戲數據", "当前支持的语言": "當前支持的語言", "添加语言包": "添加語言包", - "未添加": "未添加" + "未添加": "未添加", + "在线": "線上" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/en.json b/LunaTranslator/files/lang/en.json index ab1d6298..2cca0b5a 100644 --- a/LunaTranslator/files/lang/en.json +++ b/LunaTranslator/files/lang/en.json @@ -818,5 +818,6 @@ "游戏数据": "Game data", "当前支持的语言": "Currently supported languages", "添加语言包": "Add language pack", - "未添加": "Not added" + "未添加": "Not added", + "在线": "on-line" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/es.json b/LunaTranslator/files/lang/es.json index 9928ec8a..a5a2f5fa 100644 --- a/LunaTranslator/files/lang/es.json +++ b/LunaTranslator/files/lang/es.json @@ -818,5 +818,6 @@ "游戏数据": "Datos del juego", "当前支持的语言": "Idiomas apoyados actualmente", "添加语言包": "Añadir paquetes de idiomas", - "未添加": "Sin agregar" + "未添加": "Sin agregar", + "在线": "En línea" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/fr.json b/LunaTranslator/files/lang/fr.json index 44d32a45..b8ab5961 100644 --- a/LunaTranslator/files/lang/fr.json +++ b/LunaTranslator/files/lang/fr.json @@ -818,5 +818,6 @@ "游戏数据": "Données du jeu", "当前支持的语言": "Langues actuellement supportées", "添加语言包": "Ajouter un pack de langue", - "未添加": "Non ajouté" + "未添加": "Non ajouté", + "在线": "En ligne" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/it.json b/LunaTranslator/files/lang/it.json index d3f5ff83..579d0be4 100644 --- a/LunaTranslator/files/lang/it.json +++ b/LunaTranslator/files/lang/it.json @@ -818,5 +818,6 @@ "游戏数据": "Dati di gioco", "当前支持的语言": "Lingue attualmente supportate", "添加语言包": "Aggiungi pacchetto linguistico", - "未添加": "Non aggiunto" + "未添加": "Non aggiunto", + "在线": "on-line" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ja.json b/LunaTranslator/files/lang/ja.json index 562ccdba..81b7be61 100644 --- a/LunaTranslator/files/lang/ja.json +++ b/LunaTranslator/files/lang/ja.json @@ -818,5 +818,6 @@ "游戏数据": "ゲームデータ", "当前支持的语言": "現在サポートされている言語", "添加语言包": "言語パックの追加", - "未添加": "追加されていません" + "未添加": "追加されていません", + "在线": "オンライン" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ko.json b/LunaTranslator/files/lang/ko.json index ece92d74..ae0b72de 100644 --- a/LunaTranslator/files/lang/ko.json +++ b/LunaTranslator/files/lang/ko.json @@ -818,5 +818,6 @@ "游戏数据": "게임 데이터", "当前支持的语言": "현재 지원되는 언어", "添加语言包": "언어 팩 추가", - "未添加": "추가되지 않음" + "未添加": "추가되지 않음", + "在线": "온라인" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/pl.json b/LunaTranslator/files/lang/pl.json index b3056f32..59495392 100644 --- a/LunaTranslator/files/lang/pl.json +++ b/LunaTranslator/files/lang/pl.json @@ -818,5 +818,6 @@ "游戏数据": "Dane gry", "当前支持的语言": "Obecnie obsługiwane języki", "添加语言包": "Dodaj pakiet językowy", - "未添加": "Nie dodano" + "未添加": "Nie dodano", + "在线": "on-line" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ru.json b/LunaTranslator/files/lang/ru.json index e2bd1eca..819903e4 100644 --- a/LunaTranslator/files/lang/ru.json +++ b/LunaTranslator/files/lang/ru.json @@ -818,5 +818,6 @@ "游戏数据": "Игровые данные", "当前支持的语言": "Поддерживаемые языки", "添加语言包": "Добавить языковой пакет", - "未添加": "Не добавлено" + "未添加": "Не добавлено", + "在线": "Онлайн" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/th.json b/LunaTranslator/files/lang/th.json index 9aacea91..12d28b44 100644 --- a/LunaTranslator/files/lang/th.json +++ b/LunaTranslator/files/lang/th.json @@ -818,5 +818,6 @@ "游戏数据": "ข้อมูลเกม", "当前支持的语言": "ภาษาที่รองรับในปัจจุบัน", "添加语言包": "เพิ่มแพคภาษา", - "未添加": "ไม่ได้เพิ่ม" + "未添加": "ไม่ได้เพิ่ม", + "在线": "ออนไลน์" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/tr.json b/LunaTranslator/files/lang/tr.json index a73d46b3..19e053bb 100644 --- a/LunaTranslator/files/lang/tr.json +++ b/LunaTranslator/files/lang/tr.json @@ -818,5 +818,6 @@ "游戏数据": "Oyun verileri", "当前支持的语言": "Şu anda desteklenmiş diller", "添加语言包": "Dil paketi ekle", - "未添加": "Eklenmedi" + "未添加": "Eklenmedi", + "在线": "on line" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/uk.json b/LunaTranslator/files/lang/uk.json index 2552f591..93fe6ee8 100644 --- a/LunaTranslator/files/lang/uk.json +++ b/LunaTranslator/files/lang/uk.json @@ -818,5 +818,6 @@ "游戏数据": "Дані гри", "当前支持的语言": "Поточно підтримувані мови", "添加语言包": "Додати пакунок мови", - "未添加": "Не додано" + "未添加": "Не додано", + "在线": "онлайн" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/vi.json b/LunaTranslator/files/lang/vi.json index 4be4c027..a9c3bf9f 100644 --- a/LunaTranslator/files/lang/vi.json +++ b/LunaTranslator/files/lang/vi.json @@ -818,5 +818,6 @@ "游戏数据": "Dữ liệu trò chơi", "当前支持的语言": "Ngôn ngữ được hỗ trợ hiện tại", "添加语言包": "Thêm gói ngôn ngữ", - "未添加": "Chưa thêm" + "未添加": "Chưa thêm", + "在线": "Trực tuyến" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index 0200e57b..eedc2fa2 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -818,5 +818,6 @@ "游戏数据": "", "当前支持的语言": "", "添加语言包": "", - "未添加": "" + "未添加": "", + "在线": "" } \ No newline at end of file