From b1385a9e74c6462af5f39901ad929818bac99fd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Wed, 25 Dec 2024 16:05:42 +0800 Subject: [PATCH] . --- cpp/LunaHook/LunaHook/engine64/vita3k.cpp | 14 ++ cpp/version.cmake | 2 +- docs/zh/hooksettings.md | 4 +- py/LunaTranslator/LunaTranslator.py | 1 + py/LunaTranslator/cishu/mdict.py | 21 ++- py/LunaTranslator/gui/dialog_savedgame.py | 48 ++++--- .../gui/dialog_savedgame_common.py | 1 + .../gui/dialog_savedgame_setting.py | 41 ++++-- py/LunaTranslator/gui/dialog_savedgame_v3.py | 107 ++++++-------- py/LunaTranslator/gui/dynalang.py | 15 ++ py/LunaTranslator/gui/inputdialog.py | 28 ++-- py/LunaTranslator/gui/setting_about.py | 21 +-- py/LunaTranslator/gui/setting_cishu.py | 3 +- py/LunaTranslator/gui/setting_display_text.py | 36 ----- .../gui/setting_textinput_ocr.py | 4 +- py/LunaTranslator/gui/setting_translate.py | 66 +++++---- py/LunaTranslator/gui/showword.py | 6 +- py/LunaTranslator/gui/transhist.py | 6 +- py/LunaTranslator/gui/usefulwidget.py | 130 ++++++------------ py/LunaTranslator/metadata/bangumi.py | 53 +++---- py/LunaTranslator/metadata/steam.py | 29 ++-- py/LunaTranslator/metadata/vndb.py | 51 +++---- py/files/defaultconfig/config.json | 2 +- py/files/yearsummary/yearsummary.html | 2 +- 24 files changed, 309 insertions(+), 382 deletions(-) diff --git a/cpp/LunaHook/LunaHook/engine64/vita3k.cpp b/cpp/LunaHook/LunaHook/engine64/vita3k.cpp index 08ae77d7..54df502c 100644 --- a/cpp/LunaHook/LunaHook/engine64/vita3k.cpp +++ b/cpp/LunaHook/LunaHook/engine64/vita3k.cpp @@ -522,6 +522,16 @@ namespace last = s; buffer->from(s); } + void PCSG01036(TextBuffer *buffer, HookParam *hp) + { + auto s = buffer->strA(); + static std::string last; + if (last == s) + return buffer->clear(); + last = s; + strReplace(s, "#n", ""); + buffer->from(s); + } void FPCSG00815(TextBuffer *buffer, HookParam *hp) { auto s = buffer->strA(); @@ -795,6 +805,10 @@ namespace {0x8005426C, {CODEC_UTF8, 0, 0, 0, PCSG01068, "PCSG01068"}}, // スカーレッドライダーゼクス Rev. {0x800BEE38, {CODEC_UTF8, 0, 0, 0, PCSG00787, "PCSG00745"}}, + // 緋色の欠片 ~おもいいろの記憶~ + {0x8007838c, {CODEC_UTF8, 5, 0, 0, PCSG01036, "PCSG01036"}}, + {0x8001154c, {CODEC_UTF8, 8, 0, 0, PCSG01036, "PCSG01036"}}, + {0x800879ee, {CODEC_UTF8, 2, 0, 0, PCSG01036, "PCSG01036"}}, }; return 1; }(); diff --git a/cpp/version.cmake b/cpp/version.cmake index 5d9b6093..4e86c32e 100644 --- a/cpp/version.cmake +++ b/cpp/version.cmake @@ -1,7 +1,7 @@ set(VERSION_MAJOR 6) set(VERSION_MINOR 15) -set(VERSION_PATCH 2) +set(VERSION_PATCH 3) set(VERSION_REVISION 0) set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) diff --git a/docs/zh/hooksettings.md b/docs/zh/hooksettings.md index 5ae726b1..e9a96716 100644 --- a/docs/zh/hooksettings.md +++ b/docs/zh/hooksettings.md @@ -96,8 +96,8 @@ N:无视上下文 寄存器的data_offset: - * 32位 -4 for EAX, -8 for ECX, -C for EDX, -10 for EBX, -14 for ESP, -18 for EBP, -1C for ESI, -20 for EDI - * 64位 -C for RAX, -14 for RBX, -1C for RCX, -24 for RDX, and so on for RSP, RBP, RSI, RDI, R8-R15 + * 32位 EAX -4, ECX -8, EDX -C, EBX -10, ESP -14, EBP -18, ESI -1C, EDI -20 + * 64位 RAX -C, RBX -14, RCX -1C, RDX -24, RSP -2C, RBP -34, RSI -3C, RDI -44, R8 -4C, R9 -54, R10 -5C, R11 -64, R12 -6C, R13 -74, R14 -7C, R15 -84 1. #### JIT HOOK diff --git a/py/LunaTranslator/LunaTranslator.py b/py/LunaTranslator/LunaTranslator.py index 4501cd75..c8364be1 100644 --- a/py/LunaTranslator/LunaTranslator.py +++ b/py/LunaTranslator/LunaTranslator.py @@ -1089,6 +1089,7 @@ class MAINUI: fontsize=globalconfig["settingfontsize"] + 4, fonttype=globalconfig["settingfonttype"], ) + style+="QGroupBox#notitle{ margin-top:0px;} QGroupBox#notitle:title {margin-top: 0px;}" self.commonstylebase.setStyleSheet(style) font = QFont() font.setFamily(globalconfig["settingfonttype"]) diff --git a/py/LunaTranslator/cishu/mdict.py b/py/LunaTranslator/cishu/mdict.py index 0d500778..ffe9c353 100644 --- a/py/LunaTranslator/cishu/mdict.py +++ b/py/LunaTranslator/cishu/mdict.py @@ -2378,12 +2378,11 @@ class mdict(cishubase): csscollect: dict, ): base = os.path.dirname(fn) - src_pattern = r'src="([^"]+)"' - href_pattern = r'href="([^"]+)"' - - src_matches = re.findall(src_pattern, html_content) - href_matches = re.findall(href_pattern, html_content) - for url in src_matches + href_matches: + matches = re.findall('src="([^"]+)"', html_content) + matches += re.findall('href="([^"]+)"', html_content) + matches += re.findall("""href='([^']+)'""", html_content) + matches += re.findall("""src='([^']+)'""", html_content) + for url in matches: if url.startswith("#"): # a href # 页内跳转 continue try: @@ -2468,11 +2467,11 @@ class mdict(cishubase): contents = [] idx = 0 for _, foldflow, title, res in allres: - klass2='tab-pane_mdict_internal' - klass1='tab-button_mdict_internal' - if idx==0: - klass2+=' active' - klass1+=' active' + klass2 = "tab-pane_mdict_internal" + klass1 = "tab-button_mdict_internal" + if idx == 0: + klass2 += " active" + klass1 += " active" btns.append( """""".format( idx=idx, title=title, klass=klass1 diff --git a/py/LunaTranslator/gui/dialog_savedgame.py b/py/LunaTranslator/gui/dialog_savedgame.py index 7bd21374..ebab7ba8 100644 --- a/py/LunaTranslator/gui/dialog_savedgame.py +++ b/py/LunaTranslator/gui/dialog_savedgame.py @@ -4,6 +4,7 @@ from qtsymbols import * import os, functools, uuid from traceback import print_exc import gobject, qtawesome +from gui.inputdialog import autoinitdialog from gui.dynalang import LAction from gui.dialog_savedgame_v3 import dialog_savedgame_v3 from gui.dialog_savedgame_legacy import dialog_savedgame_legacy @@ -22,7 +23,6 @@ from gui.usefulwidget import ( saveposwindow, getboxlayout, MySwitch, - Prompt_dialog, IconButton, getsimplecombobox, FQLineEdit, @@ -414,25 +414,16 @@ class dialog_savedgame_new(QWidget): self.clicked3_batch() elif action == editname or action == addlist: - _dia = Prompt_dialog( - self, - "修改列表名称" if action == editname else "创建列表", - "", - [ - [ - "名称", - ( - savegametaged[calculatetagidx(self.reftagid)]["title"] - if action == editname - else "" - ), - ], - ], - ) + __d = { + "k": ( + savegametaged[calculatetagidx(self.reftagid)]["title"] + if action == editname + else "" + ) + } - if _dia.exec(): - - title = _dia.text[0].text() + def cb(__d): + title = __d["k"] if title != "": i = calculatetagidx(self.reftagid) if action == addlist: @@ -448,6 +439,25 @@ class dialog_savedgame_new(QWidget): savegametaged[i]["title"] = title self.loadcombo(False) + + autoinitdialog( + self, + __d, + "修改列表名称" if action == editname else "创建列表", + 600, + [ + { + "type": "lineedit", + "name": "名称", + "k": "k", + }, + { + "type": "okcancel", + "callback": functools.partial(cb, __d), + }, + ], + exec_=True, + ) elif action == dellist: i = calculatetagidx(self.reftagid) savegametaged.pop(i) diff --git a/py/LunaTranslator/gui/dialog_savedgame_common.py b/py/LunaTranslator/gui/dialog_savedgame_common.py index 1a5b6c81..a88ea2b1 100644 --- a/py/LunaTranslator/gui/dialog_savedgame_common.py +++ b/py/LunaTranslator/gui/dialog_savedgame_common.py @@ -487,6 +487,7 @@ def getalistname(parent, callback, skipid=False, skipidid=None, title="添加到 "callback": functools.partial(__wrap, callback, __d, __uid), }, ], + exec_=True ) elif len(__uid): diff --git a/py/LunaTranslator/gui/dialog_savedgame_setting.py b/py/LunaTranslator/gui/dialog_savedgame_setting.py index e4ff754c..7d31c15f 100644 --- a/py/LunaTranslator/gui/dialog_savedgame_setting.py +++ b/py/LunaTranslator/gui/dialog_savedgame_setting.py @@ -49,10 +49,12 @@ from gui.usefulwidget import ( getsimpleswitch, threebuttons, getspinbox, + CollapsibleBox, getsmalllabel, listediterline, editswitchTextBrowser, FocusCombo, + VisLFormLayout, ) from gui.dynalang import ( LFormLayout, @@ -345,14 +347,15 @@ class dialog_setting_game_internal(QWidget): print_exc() def metadataorigin(self, formLayout: LFormLayout, gameuid): + vislf = VisLFormLayout() + formLayout.addRow(vislf) combo = getsimplecombobox( ["无"] + list(targetmod.keys()), globalconfig, "primitivtemetaorigin", internal=[None] + list(targetmod.keys()), ) - formLayout.addRow("首选的", combo) - formLayout.addRow(None, QLabel()) + vislf.addRow("首选的", combo) def valid(idx, x): if x: @@ -363,6 +366,8 @@ class dialog_setting_game_internal(QWidget): combo.setCurrentIndex(0) combo.setRowVisible(idx + 1, x) + linei = 1 + notvislineis = [] for i, key in enumerate(targetmod): try: idname = targetmod[key].idname @@ -402,18 +407,37 @@ class dialog_setting_game_internal(QWidget): continue try: __settting = targetmod[key].querysettingwindow + coll = CollapsibleBox( + functools.partial(__settting, gameuid), self, margin0=False + ) + + def _revert(c, li): + vis = c.isVisible() + vislf.setRowVisible(li, not vis) + c.toggle(not vis) + _vbox_internal.insert( 2, getIconButton( - functools.partial(__settting, self, gameuid), icon="fa.gear" + functools.partial(_revert, coll, linei + 1), + icon="fa.gear", ), ) + vislf.addRow( + key, + getboxlayout(_vbox_internal), + ) + vislf.addRow(coll) + notvislineis.append(linei + 1) + linei += 2 except: - pass - formLayout.addRow( - key, - getboxlayout(_vbox_internal), - ) + vislf.addRow( + key, + getboxlayout(_vbox_internal), + ) + linei += 1 + for _ in notvislineis: + vislf.setRowVisible(_, False) def doaddtab(self, wfunct, exe, layout): w, do = wfunct(exe) @@ -1032,6 +1056,7 @@ class dialog_setting_game_internal(QWidget): "callback": functools.partial(__callback, _internal, __d), }, ], + exec_=True, ) def getlangtab(self, formLayout: LFormLayout, gameuid): diff --git a/py/LunaTranslator/gui/dialog_savedgame_v3.py b/py/LunaTranslator/gui/dialog_savedgame_v3.py index f8d56a75..2e9e5b29 100644 --- a/py/LunaTranslator/gui/dialog_savedgame_v3.py +++ b/py/LunaTranslator/gui/dialog_savedgame_v3.py @@ -1,7 +1,7 @@ from qtsymbols import * import os, functools, uuid, threading, shutil, time from traceback import print_exc -import gobject, base64 +import gobject from myutils.config import ( savehook_new_list, savehook_new_data, @@ -18,7 +18,6 @@ from gui.specialwidget import stackedlist, shrinkableitem, shownumQPushButton from gui.usefulwidget import ( pixmapviewer, statusbutton, - Prompt_dialog, makesubtab_lazy, tabadd_lazy, listediter, @@ -744,32 +743,8 @@ class dialog_savedgame_v3(QWidget): if action == startgame: startgamecheck(self, getreflist(self.reftagid), self.currentfocusuid) elif addlist == action: - _dia = Prompt_dialog( - self, - "创建列表", - "", - [ - ["名称", ""], - ], - ) - if _dia.exec(): - - title = _dia.text[0].text() - if title != "": - i = calculatetagidx(None) - if action == addlist: - tag = { - "title": title, - "games": [], - "uid": str(uuid.uuid4()), - "opened": True, - } - savegametaged.insert(i, tag) - group0, btn = self.createtaglist( - self.stack, title, tag["uid"], True - ) - self.stack.insertw(i, group0) + self.createlist(True, None) elif action == delgame: self.shanchuyouxi() @@ -1002,42 +977,7 @@ class dialog_savedgame_v3(QWidget): elif action == Downaction: self.taglistrerank(tagid, 1) elif action == editname or action == addlist: - _dia = Prompt_dialog( - self, - "修改列表名称" if action == editname else "创建列表", - "", - [ - [ - "名称", - ( - savegametaged[calculatetagidx(tagid)]["title"] - if action == editname - else "" - ), - ], - ], - ) - - if _dia.exec(): - - title = _dia.text[0].text() - if title != "": - i = calculatetagidx(tagid) - if action == addlist: - tag = { - "title": title, - "games": [], - "uid": str(uuid.uuid4()), - "opened": True, - } - savegametaged.insert(i, tag) - group0, btn = self.createtaglist( - self.stack, title, tag["uid"], True - ) - self.stack.insertw(i, group0) - elif action == editname: - self.stack.w(i).settitle(title) - savegametaged[i]["title"] = title + self.createlist(action == addlist, tagid) elif action == dellist: i = calculatetagidx(tagid) @@ -1045,6 +985,47 @@ class dialog_savedgame_v3(QWidget): self.stack.popw(i) self.reallist.pop(tagid) + def createlist(self, create, tagid): + __d = {"k": ("" if create else savegametaged[calculatetagidx(tagid)]["title"])} + + def cb(__d): + title = __d["k"] + if not title: + return + i = calculatetagidx(tagid) + if create: + tag = { + "title": title, + "games": [], + "uid": str(uuid.uuid4()), + "opened": True, + } + savegametaged.insert(i, tag) + group0, btn = self.createtaglist(self.stack, title, tag["uid"], True) + self.stack.insertw(i, group0) + else: + self.stack.w(i).settitle(title) + savegametaged[i]["title"] = title + + autoinitdialog( + self, + __d, + "创建列表" if create else "修改列表名称", + 600, + [ + { + "type": "lineedit", + "name": "名称", + "k": "k", + }, + { + "type": "okcancel", + "callback": functools.partial(cb, __d), + }, + ], + exec_=True, + ) + def createtaglist(self, p, title, tagid, opened): self.reallist[tagid] = [] diff --git a/py/LunaTranslator/gui/dynalang.py b/py/LunaTranslator/gui/dynalang.py index e331ba8c..a0710b5b 100644 --- a/py/LunaTranslator/gui/dynalang.py +++ b/py/LunaTranslator/gui/dynalang.py @@ -265,3 +265,18 @@ class LStandardItemModel(QStandardItemModel): def removeColumn(self, col): self.__ls.pop(col) super().removeColumn(col) + + +class LToolButton(QToolButton): + def __init__(self, *argc, **kwarg): + super().__init__(*argc, **kwarg) + self._text = self.text() + super().setText(_TR(self._text)) + + def setText(self, t): + self._text = t + super().setText(_TR(t)) + + def updatelangtext(self): + if self._text: + super().setText(_TR(self._text)) diff --git a/py/LunaTranslator/gui/inputdialog.py b/py/LunaTranslator/gui/inputdialog.py index 9002c8cc..e98f85de 100644 --- a/py/LunaTranslator/gui/inputdialog.py +++ b/py/LunaTranslator/gui/inputdialog.py @@ -445,9 +445,17 @@ def autoinitdialog_items(dic): @Singleton_close -class autoinitdialog__(LDialog): +class autoinitdialog(LDialog): def __init__( - self, parent, dd, title, width, lines, modelfile=None, maybehasextrainfo=None + self, + parent, + dd, + title, + width, + lines, + modelfile=None, + maybehasextrainfo=None, + exec_=False, ) -> None: super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) self.setWindowTitle(title) @@ -695,18 +703,10 @@ class autoinitdialog__(LDialog): cachecombo[comboname].currentIndexChanged.emit( cachecombo[comboname].currentIndex() ) - - self.show() - - -def autoinitdialogx( - parent, dd, title, width, lines, modelfile, maybehasextrainfo, _=None -): - autoinitdialog__(parent, dd, title, width, lines, modelfile, maybehasextrainfo) - - -def autoinitdialog(parent, dd, title, width, lines, _=None): - autoinitdialog__(parent, dd, title, width, lines) + if exec_: + self.exec_() + else: + self.show() def getsomepath1( diff --git a/py/LunaTranslator/gui/setting_about.py b/py/LunaTranslator/gui/setting_about.py index 61df1f1e..180cd14e 100644 --- a/py/LunaTranslator/gui/setting_about.py +++ b/py/LunaTranslator/gui/setting_about.py @@ -13,7 +13,7 @@ import subprocess from gui.usefulwidget import ( D_getsimpleswitch, makescrollgrid, - CollapsibleBox, + CollapsibleBoxWithButton, makesubtab_lazy, D_getsimplecombobox, makegrid, @@ -276,7 +276,7 @@ def changelog(self, basel: QHBoxLayout): basel.addWidget(_) -def delayloadlinks(key, box): +def delayloadlinks(key, lay): sources = static_data["aboutsource"][key] grid = [] for source in sources: @@ -303,24 +303,13 @@ def delayloadlinks(key, box): ) ] ) - grid = [ - [ - ( - dict(type="grid", grid=grid), - 0, - "group", - ) - ] - ] - w, do = makegrid(grid, delay=True, w=False) - w.setContentsMargins(0, 0, 0, 0) - box.content_area.setLayout(w) + w, do = makegrid(grid, delay=True) + lay.addWidget(w) do() def offlinelinks(key): - box = CollapsibleBox("下载") - box.setdelayload(functools.partial(delayloadlinks, key)) + box = CollapsibleBoxWithButton(functools.partial(delayloadlinks, key), "下载") return box diff --git a/py/LunaTranslator/gui/setting_cishu.py b/py/LunaTranslator/gui/setting_cishu.py index 14ba365e..9f03ebe3 100644 --- a/py/LunaTranslator/gui/setting_cishu.py +++ b/py/LunaTranslator/gui/setting_cishu.py @@ -4,7 +4,6 @@ from myutils.utils import splitocrtypes from myutils.config import globalconfig, _TR, get_platform from gui.inputdialog import ( multicolorset, - autoinitdialogx, autoinitdialog_items, autoinitdialog, ) @@ -147,7 +146,7 @@ def initinternal(self, names): line += [ D_getIconButton( callback=functools.partial( - autoinitdialogx, + autoinitdialog, self, globalconfig["cishu"][cishu]["args"], globalconfig["cishu"][cishu]["name"], diff --git a/py/LunaTranslator/gui/setting_display_text.py b/py/LunaTranslator/gui/setting_display_text.py index 61560f0e..25479396 100644 --- a/py/LunaTranslator/gui/setting_display_text.py +++ b/py/LunaTranslator/gui/setting_display_text.py @@ -172,42 +172,6 @@ def createinternalfontsettings(self, forml: LFormLayout, group, _type): ) -def doinstallqweb(self, dd, base): - if not dd["k"].endswith(base): - getQMessageBox(self, "错误", "请选择_" + base) - return - with zipfile.ZipFile(dd["k"]) as zipf: - target = gobject.gettempdir("QWebEngine/") - zipf.extractall(target) - bit = ["x86", "x64"][platform.architecture()[0] == "64bit"] - copytree("{}/{}/PyQt5".format(target, bit), "files/runtime/PyQt5") - getQMessageBox(self, "成功", "安装成功") - - -def installqwebdialog(self, link): - dd = {"k": ""} - base = link.split("/")[-1] - autoinitdialog( - self, - dd, - "安装_QWebEngine", - 800, - [ - { - "type": "file", - "name": "路径", - "k": "k", - "dir": False, - "filter": base, - }, - { - "type": "okcancel", - "callback": functools.partial(doinstallqweb, self, dd, base), - }, - ], - ) - - def resetgroudswitchcallback(self, group): if group == "QWebEngine": group = "webview" diff --git a/py/LunaTranslator/gui/setting_textinput_ocr.py b/py/LunaTranslator/gui/setting_textinput_ocr.py index ff5a97c7..01cfbbc0 100644 --- a/py/LunaTranslator/gui/setting_textinput_ocr.py +++ b/py/LunaTranslator/gui/setting_textinput_ocr.py @@ -2,7 +2,7 @@ from qtsymbols import * import functools, os from myutils.config import globalconfig, ocrsetting, ocrerrorfix, static_data from myutils.utils import splitocrtypes, dynamiclink, getimagefilefilter -from gui.inputdialog import autoinitdialogx, postconfigdialog, autoinitdialog_items +from gui.inputdialog import postconfigdialog, autoinitdialog_items, autoinitdialog from gui.usefulwidget import ( D_getsimplecombobox, D_getspinbox, @@ -142,7 +142,7 @@ def initgridsources(self, names): items = autoinitdialog_items(ocrsetting[name]) _3 = D_getIconButton( callback=functools.partial( - autoinitdialogx, + autoinitdialog, self, ocrsetting[name]["args"], globalconfig["ocr"][name]["name"], diff --git a/py/LunaTranslator/gui/setting_translate.py b/py/LunaTranslator/gui/setting_translate.py index d5d5d356..15b3b891 100644 --- a/py/LunaTranslator/gui/setting_translate.py +++ b/py/LunaTranslator/gui/setting_translate.py @@ -1,7 +1,7 @@ from qtsymbols import * import functools, os import gobject, qtawesome, uuid, shutil -from myutils.config import globalconfig, translatorsetting, static_data +from myutils.config import globalconfig, translatorsetting from myutils.utils import ( selectdebugfile, splittranslatortypes, @@ -10,12 +10,11 @@ from myutils.utils import ( dynamicapiname, ) from gui.pretransfile import sqlite2json -from gui.inputdialog import autoinitdialog, autoinitdialog_items, autoinitdialogx +from gui.inputdialog import autoinitdialog, autoinitdialog_items from gui.usefulwidget import ( D_getspinbox, getIconButton, D_getcolorbutton, - Prompt_dialog, getcolorbutton, getsimpleswitch, D_getIconButton, @@ -114,44 +113,57 @@ def getalistname(parent, copy, btnplus, callback): } ) autoinitdialog( - parent, - __d, - ("删除" if copy else "复制") + "接口", - 600, - __, + parent, __d, ("删除" if copy else "复制") + "接口", 600, __, exec_=True ) -def renameapi(qlabel: QLabel, apiuid, _): +def renameapi(qlabel: QLabel, apiuid, self, countnum, btnplus, _): menu = QMenu(qlabel) editname = LAction("重命名") + delete = LAction("删除") menu.addAction(editname) + which = translate_exits(apiuid, which=True) + if which == 1: + menu.addAction(delete) action = menu.exec(qlabel.mapToGlobal(_)) + if action == delete: + selectllmcallback_2(self, countnum, btnplus, apiuid, None) if action == editname: before = dynamicapiname(apiuid) - _dia = Prompt_dialog( - qlabel, - "重命名", - "", - [ - [ - "名称", - before, - ], - ], - ) + __d = {"k": before} - if _dia.exec(): - title = _dia.text[0].text() + def cb(__d): + title = __d["k"] if title not in ("", before): globalconfig["fanyi"][apiuid]["name_self_set"] = title qlabel.setText(title) + autoinitdialog( + self, + __d, + "重命名", + 600, + [ + { + "type": "lineedit", + "name": "名称", + "k": "k", + }, + { + "type": "okcancel", + "callback": functools.partial(cb, __d), + }, + ], + exec_=True, + ) -def getrenameablellabel(uid): + +def getrenameablellabel(uid, self, countnum, btnplus): name = LLabel(dynamicapiname(uid)) name.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) - name.customContextMenuRequested.connect(functools.partial(renameapi, name, uid)) + name.customContextMenuRequested.connect( + functools.partial(renameapi, name, uid, self, countnum, btnplus) + ) return name @@ -164,7 +176,7 @@ def loadbutton(self, fanyi): aclass = "userconfig.copyed." + fanyi else: return - return autoinitdialogx( + return autoinitdialog( self, translatorsetting[fanyi]["args"], dynamicapiname(fanyi), @@ -203,7 +215,7 @@ def selectllmcallback(self, countnum, btnplus, fanyi, name): icon="fa.gear", ) - name = getrenameablellabel(uid) + name = getrenameablellabel(uid, self, countnum, btnplus) swc = getsimpleswitch( globalconfig["fanyi"][uid], "use", @@ -364,7 +376,7 @@ def initsome11(self, l, label=None, btnplus=False): else: last = "" line += [ - functools.partial(getrenameablellabel, fanyi), + functools.partial(getrenameablellabel, fanyi, self, countnum, btnplus), D_getsimpleswitch( globalconfig["fanyi"][fanyi], "use", diff --git a/py/LunaTranslator/gui/showword.py b/py/LunaTranslator/gui/showword.py index 0498384a..581ea233 100644 --- a/py/LunaTranslator/gui/showword.py +++ b/py/LunaTranslator/gui/showword.py @@ -34,7 +34,6 @@ from gui.usefulwidget import ( getIconButton, saveposwindow, tabadd_lazy, - LRButton, ) from gui.dynalang import ( LPushButton, @@ -516,9 +515,10 @@ class AnkiWindow(QWidget): folder_open3.clicked.connect(functools.partial(self.selecfile2, self.editpath)) def createadd(): - btn = LRButton("添加") + btn = QPushButton("添加") btn.clicked.connect(functools.partial(self.errorwrap, False)) - btn.rightclick.connect(functools.partial(self.errorwrap, True)) + btn.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) + btn.customContextMenuRequested.connect(functools.partial(self.errorwrap, True)) return btn layout.addLayout( diff --git a/py/LunaTranslator/gui/transhist.py b/py/LunaTranslator/gui/transhist.py index 61cbe6ff..9834bb0d 100644 --- a/py/LunaTranslator/gui/transhist.py +++ b/py/LunaTranslator/gui/transhist.py @@ -93,9 +93,9 @@ class transhist(closeashidewindow): def refresh(self): with self.lock: - self.textOutput.clear() - for line in self.trace: - self.textOutput.appendPlainText(self.visline(line)) + self.textOutput.setPlainText( + "\n".join(self.visline(line) for line in self.trace) + ) def visline(self, line): ii, line = line diff --git a/py/LunaTranslator/gui/usefulwidget.py b/py/LunaTranslator/gui/usefulwidget.py index 20673387..8b3f8cb3 100644 --- a/py/LunaTranslator/gui/usefulwidget.py +++ b/py/LunaTranslator/gui/usefulwidget.py @@ -17,6 +17,7 @@ from gui.dynalang import ( LStandardItemModel, LDialog, LMainWindow, + LToolButton, ) @@ -855,42 +856,6 @@ class resizableframeless(saveposwindow): return x, y, width, height -class Prompt_dialog(LDialog): - def __init__(self, parent, title, info, items) -> None: - super().__init__(parent) - self.setWindowFlags( - self.windowFlags() - & ~Qt.WindowType.WindowContextHelpButtonHint - & ~Qt.WindowType.WindowCloseButtonHint - | Qt.WindowType.WindowStaysOnTopHint - ) - self.setWindowTitle(title) - self.setWindowIcon(qtawesome.icon("fa-question")) - - _layout = QVBoxLayout() - - _layout.addWidget(LLabel(info)) - - self.text = [] - for _ in items: - - le = QLineEdit() - le.setText(_[1]) - self.text.append((le)) - hl = QHBoxLayout() - hl.addWidget(LLabel(_[0])) - hl.addWidget(le) - _layout.addLayout(hl) - button = QDialogButtonBox( - QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel - ) - button.accepted.connect(self.accept) - button.rejected.connect(self.reject) - _layout.addWidget(button) - self.setLayout(_layout) - self.resize(400, 1) - - def callbackwrap(d, k, call, _): d[k] = _ @@ -1783,15 +1748,7 @@ def makegroupingrid(args): if title: group.setTitle(title) else: - _id = "luna" + str(uuid.uuid4()) - group.setObjectName(_id) - group.setStyleSheet( - "QGroupBox#" - + _id - + "{ margin-top:0px;} QGroupBox#" - + _id - + ":title {margin-top: 0px;}" - ) + group.setObjectName('notitle') if _type == "grid": grid = QGridLayout() @@ -1875,18 +1832,18 @@ def automakegrid(grid: QGridLayout, lis, save=False, savelist=None): grid.setRowMinimumHeight(nowr, 25) -def makegrid(grid=None, save=False, savelist=None, savelay=None, delay=False, w=True): +def makegrid( + grid=None, save=False, savelist=None, savelay=None, delay=False +): class gridwidget(QWidget): pass - if w: - gridlayoutwidget = gridwidget() + gridlayoutwidget = gridwidget() gridlay = QGridLayout() gridlay.setAlignment(Qt.AlignmentFlag.AlignTop) - if w: - gridlayoutwidget.setLayout(gridlay) - gridlayoutwidget.setStyleSheet("gridwidget{background-color:transparent;}") + gridlayoutwidget.setLayout(gridlay) + gridlayoutwidget.setStyleSheet("gridwidget{background-color:transparent;}") def do(gridlay, grid, save, savelist, savelay): automakegrid(gridlay, grid, save, savelist) @@ -1894,8 +1851,7 @@ def makegrid(grid=None, save=False, savelist=None, savelay=None, delay=False, w= savelay.append(gridlay) __do = functools.partial(do, gridlay, grid, save, savelist, savelay) - if not w: - gridlayoutwidget = gridlay + if not delay: __do() return gridlayoutwidget @@ -2536,16 +2492,6 @@ class FQLineEdit(QLineEdit): return super().mousePressEvent(a0) -class LRButton(LPushButton): - rightclick = pyqtSignal() - - def mouseReleaseEvent(self, ev: QMouseEvent) -> None: - if self.rect().contains(ev.pos()): - if ev.button() == Qt.MouseButton.RightButton: - self.rightclick.emit() - return super().mouseReleaseEvent(ev) - - class VisLFormLayout(LFormLayout): # 简易实现 def __init__(self, *args, **kwargs): @@ -2593,45 +2539,47 @@ class VisLFormLayout(LFormLayout): self._row_vis[row_index] = visible -class CollapsibleBox(QWidget): - def setdelayload(self, func): - self.func = func - - def __init__(self, title="", parent=None): +class CollapsibleBox(QGroupBox): + def __init__(self, delayloadfunction=None, parent=None, margin0=True): super(CollapsibleBox, self).__init__(parent) + self.setObjectName('notitle') + lay = QVBoxLayout(self) + if margin0: + lay.setContentsMargins(0, 0, 0, 0) + self.setLayout(lay) + self.func = delayloadfunction + self.toggle(False) - self.toggle_button = QToolButton(text=title, checkable=True, checked=False) + def toggle(self, checked): + if checked and self.func: + self.func(self.layout()) + self.func = None + self.setVisible(checked) + + +class CollapsibleBoxWithButton(QWidget): + + def __init__(self, delayloadfunction=None, title="", parent=None): + super(CollapsibleBoxWithButton, self).__init__(parent) + self.toggle_button = LToolButton(text=title, checkable=True, checked=False) self.toggle_button.setToolButtonStyle( Qt.ToolButtonStyle.ToolButtonTextBesideIcon ) - self.toggle_button.toggled.connect(self.on_toggled) - self.content_area = QWidget() + self.toggle_button.toggled.connect(self.toggled) + self.content_area = CollapsibleBox(delayloadfunction, self) lay = QVBoxLayout(self) lay.setSpacing(0) lay.setContentsMargins(0, 0, 0, 0) lay.addWidget(self.toggle_button) lay.addWidget(self.content_area) - self.func = None - self.collapse() + self.toggled(False) - def on_toggled(self, checked): - if checked: - if self.func: - self.func(self) - self.func = None - self.toggle_button.setIcon(qtawesome.icon("fa.chevron-down")) - self.content_area.setVisible(True) - else: - self.toggle_button.setIcon(qtawesome.icon("fa.chevron-right")) - self.content_area.setVisible(False) - - def expand(self): - self.toggle_button.setChecked(True) - self.on_toggled(True) - - def collapse(self): - self.toggle_button.setChecked(False) - self.on_toggled(False) + def toggled(self, checked): + self.toggle_button.setChecked(checked) + self.content_area.toggle(checked) + self.toggle_button.setIcon( + qtawesome.icon("fa.chevron-down" if checked else "fa.chevron-right") + ) class editswitchTextBrowser(QWidget): diff --git a/py/LunaTranslator/metadata/bangumi.py b/py/LunaTranslator/metadata/bangumi.py index 56f5acc3..3b537070 100644 --- a/py/LunaTranslator/metadata/bangumi.py +++ b/py/LunaTranslator/metadata/bangumi.py @@ -5,12 +5,11 @@ import functools, time, json, gobject from qtsymbols import * from metadata.abstract import common from gui.dialog_savedgame import getreflist, getalistname -from myutils.wrapper import Singleton_close, threader -from gui.dynalang import LPushButton +from myutils.wrapper import threader +from gui.usefulwidget import threebuttons -@Singleton_close -class bgmsettings(QDialog): +class bgmsettings(QFormLayout): @property def headers(self): @@ -118,10 +117,6 @@ class bgmsettings(QDialog): except: pass - def __getalistname(self, title, callback, _): - getalistname(self, callback, title=title) - - infosig = pyqtSignal(str) showhide = pyqtSignal(bool) @threader @@ -229,18 +224,17 @@ class bgmsettings(QDialog): print(self._ref.config) break - def __init__(self, parent, _ref: common, gameuid: str) -> None: - super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) + def __init__(self, layout: QVBoxLayout, _ref: common, gameuid: str) -> None: + super().__init__(None) + layout.addLayout(self) self.tm = None self._ref = _ref - self.resize(QSize(800, 10)) - self.setWindowTitle(self._ref.config_all["name"]) - fl = QFormLayout(self) vbox = QVBoxLayout() hbox = QHBoxLayout() s = QLineEdit() self.lbinfo = QLabel() s.textChanged.connect(self.checkvalid) + s.setText(_ref.config["access-token"]) fl2 = QFormLayout() fl2.setContentsMargins(0, 0, 0, 0) ww = QWidget() @@ -255,29 +249,24 @@ class bgmsettings(QDialog): hbox.addWidget(oauth) oauth.clicked.connect(self.__oauth) vbox.addWidget(self.lbinfo) - fl.addRow("access-token", vbox) - btn = LPushButton("上传游戏") - btn.clicked.connect( + self.addRow("access-token", vbox) + + btn = threebuttons(["上传游戏", "上传游戏列表", "获取游戏列表"]) + btn.btn1clicked.connect( functools.partial(self.singleupload_existsoverride, gameuid) ) - fl2.addRow(btn) - btn = LPushButton("上传游戏列表") - btn.clicked.connect( + btn.btn2clicked.connect( functools.partial( - self.__getalistname, "上传游戏列表", self.getalistname_upload + getalistname, btn, self.getalistname_upload, "上传游戏列表" + ) + ) + btn.btn3clicked.connect( + functools.partial( + getalistname, btn, self.getalistname_download, "添加到列表" ) ) fl2.addRow(btn) - btn = LPushButton("获取游戏列表") - btn.clicked.connect( - functools.partial( - self.__getalistname, "添加到列表", self.getalistname_download - ) - ) - fl2.addRow(btn) - fl.addRow(ww) - s.setText(_ref.config["access-token"]) - self.show() + self.addRow(ww) class searcher(common): @@ -305,8 +294,8 @@ class searcher(common): print(resp) self.config["refresh_token"] = "" - def querysettingwindow(self, parent, gameuid): - bgmsettings(parent, self, gameuid) + def querysettingwindow(self, gameuid, layout): + bgmsettings(layout, self, gameuid) def getidbytitle(self, title): diff --git a/py/LunaTranslator/metadata/steam.py b/py/LunaTranslator/metadata/steam.py index b9ed5f02..6e962f6c 100644 --- a/py/LunaTranslator/metadata/steam.py +++ b/py/LunaTranslator/metadata/steam.py @@ -1,7 +1,6 @@ import requests, re from myutils.utils import ( simplehtmlparser, - simplehtmlparser_all, initanewitem, gamdidchangedtask, ) @@ -11,11 +10,9 @@ import functools from qtsymbols import * from gui.usefulwidget import getlineedit from gui.dialog_savedgame import getreflist, getalistname -from myutils.wrapper import Singleton_close -@Singleton_close -class steamsettings(QDialog): +class steamsettings(QFormLayout): def querylist(self): @@ -76,32 +73,26 @@ class steamsettings(QDialog): gamdidchangedtask(self._ref.typename, self._ref.idname, gameuid) reflist.insert(0, gameuid) - def __getalistname(self, callback, _): - getalistname(self, callback) - - def __init__(self, parent, _ref: common, gameuid: str) -> None: - super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) + def __init__(self, layout:QVBoxLayout, _ref: common, gameuid: str) -> None: + super().__init__(None) + layout.addLayout(self) self._ref = _ref - self.resize(QSize(800, 10)) - self.setWindowTitle(self._ref.config_all["name"]) - fl = QFormLayout(self) - fl.addRow("userid", getlineedit(_ref.config, "userid")) - fl.addRow( + self.addRow("userid", getlineedit(_ref.config, "userid")) + self.addRow( "cookie:steamLoginSecure", getlineedit(_ref.config, "steamLoginSecure") ) btn = QPushButton("wishlist") btn.clicked.connect( - functools.partial(self.__getalistname, self.getalistname_download) + functools.partial(getalistname, btn, self.getalistname_download) ) - fl.addRow(btn) - self.show() + self.addRow(btn) class searcher(common): - def querysettingwindow(self, parent, gameuid): - steamsettings(parent, self, gameuid) + def querysettingwindow(self, gameuid, layout): + steamsettings(layout, self, gameuid) def getidbytitle(self, title): response = requests.get( diff --git a/py/LunaTranslator/metadata/vndb.py b/py/LunaTranslator/metadata/vndb.py index 1c91ee7c..d64b8904 100644 --- a/py/LunaTranslator/metadata/vndb.py +++ b/py/LunaTranslator/metadata/vndb.py @@ -6,8 +6,8 @@ import time from qtsymbols import * from metadata.abstract import common from gui.dialog_savedgame import getreflist, getalistname -from myutils.wrapper import Singleton_close, threader -from gui.dynalang import LPushButton +from myutils.wrapper import threader +from gui.usefulwidget import threebuttons def saferequestvndb(proxy, method, url, json=None, headers=None, failnone=True): @@ -156,8 +156,7 @@ def getinfosbyvid(proxy, vid): ) -@Singleton_close -class vndbsettings(QDialog): +class vndbsettings(QFormLayout): @property def headers(self): @@ -259,9 +258,6 @@ class vndbsettings(QDialog): headers=self.headers, ) - def __getalistname(self, title, callback, _): - getalistname(self, callback, title=title) - showhide = pyqtSignal(bool) @threader @@ -286,17 +282,16 @@ class vndbsettings(QDialog): self.showhide.emit(False) self.lbinfo.setText(info) - def __init__(self, parent, _ref: common, gameuid: str) -> None: - super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) + def __init__(self, layout: QVBoxLayout, _ref: common, gameuid: str) -> None: + super().__init__(None) + layout.addLayout(self) self.tm = None self._ref = _ref - self.resize(QSize(800, 10)) - self.setWindowTitle(self._ref.config_all["name"]) - fl = QFormLayout(self) vbox = QVBoxLayout() s = QLineEdit() self.lbinfo = QLabel() s.textChanged.connect(self.checkvalid) + s.setText(_ref.config["Token"]) fl2 = QFormLayout() fl2.setContentsMargins(0, 0, 0, 0) ww = QWidget() @@ -307,35 +302,29 @@ class vndbsettings(QDialog): self._token = s vbox.addWidget(s) vbox.addWidget(self.lbinfo) - fl.addRow("Token", vbox) - btn = LPushButton("上传游戏") - btn.clicked.connect( + self.addRow("Token", vbox) + btn = threebuttons(["上传游戏", "上传游戏列表", "获取游戏列表"]) + btn.btn1clicked.connect( functools.partial(self.singleupload_existsoverride, gameuid) ) - fl2.addRow(btn) - btn = LPushButton("上传游戏列表") - btn.clicked.connect( + btn.btn2clicked.connect( functools.partial( - self.__getalistname, "上传游戏列表", self.getalistname_upload + getalistname, btn, self.getalistname_upload, "上传游戏列表" + ) + ) + btn.btn3clicked.connect( + functools.partial( + getalistname, btn, self.getalistname_download, "添加到列表" ) ) fl2.addRow(btn) - btn = LPushButton("获取游戏列表") - btn.clicked.connect( - functools.partial( - self.__getalistname, "添加到列表", self.getalistname_download - ) - ) - fl2.addRow(btn) - fl.addRow(ww) - s.setText(_ref.config["Token"]) - self.show() + self.addRow(ww) class searcher(common): - def querysettingwindow(self, parent, gameuid): - vndbsettings(parent, self, gameuid) + def querysettingwindow(self, gameuid, layout): + vndbsettings(layout, self, gameuid) def refmainpage(self, _id): return "https://vndb.org/v{}".format(_id) diff --git a/py/files/defaultconfig/config.json b/py/files/defaultconfig/config.json index 1057815b..a41527fd 100644 --- a/py/files/defaultconfig/config.json +++ b/py/files/defaultconfig/config.json @@ -1438,7 +1438,7 @@ "max_num": { "type": "intspin", "name": "最大结果条数", - "min": 0, + "min": 1, "max": 9999, "step": 1 }, diff --git a/py/files/yearsummary/yearsummary.html b/py/files/yearsummary/yearsummary.html index 904432f0..54ae18ad 100644 --- a/py/files/yearsummary/yearsummary.html +++ b/py/files/yearsummary/yearsummary.html @@ -2,7 +2,7 @@
-