diff --git a/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py b/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py index a76d56b7..ae899f64 100644 --- a/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py +++ b/LunaTranslator/LunaTranslator/gui/attachprocessdialog.py @@ -41,7 +41,7 @@ class AttachProcessDialog(saveposwindow): super().closeEvent(e) def __init__(self, parent, callback, hookselectdialog=None): - super().__init__(parent, globalconfig, "attachprocessgeo") + super().__init__(parent, poslist=globalconfig["attachprocessgeo"]) self.setcurrentpidpnamesignal.connect(self.selectwindowcallback) self.iconcache = {} diff --git a/LunaTranslator/LunaTranslator/gui/dialog_memory.py b/LunaTranslator/LunaTranslator/gui/dialog_memory.py index b83f9f2e..062ee16e 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_memory.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_memory.py @@ -24,8 +24,7 @@ class dialog_memory(saveposwindow): parent, flags=Qt.WindowType.WindowCloseButtonHint | Qt.WindowType.WindowMinMaxButtonsHint, - dic=globalconfig, - key="memorydialoggeo", + poslist=globalconfig["memorydialoggeo"], ) self.setWindowTitle(_TR("备忘录")) self.gamemd5 = gamemd5 diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index 02d60189..7421f1fc 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -479,7 +479,7 @@ class browserdialog(saveposwindow): self.startupsettitle(exepath) def __init__(self, parent, exepath=None) -> None: - super().__init__(parent, globalconfig, "browserwidget") + super().__init__(parent, poslist=globalconfig["browserwidget"]) if exepath: self.setWindowIcon(getExeIcon(exepath, cache=True)) self.browser = auto_select_webview(self) @@ -1703,8 +1703,7 @@ class dialog_savedgame_integrated(saveposwindow): parent, flags=Qt.WindowType.WindowMinMaxButtonsHint | Qt.WindowType.WindowCloseButtonHint, - dic=globalconfig, - key="savegamedialoggeo", + poslist=globalconfig["savegamedialoggeo"] ) self.setWindowTitle(_TR("游戏管理")) diff --git a/LunaTranslator/LunaTranslator/gui/edittext.py b/LunaTranslator/LunaTranslator/gui/edittext.py index 8a8b6933..0bbc90c1 100644 --- a/LunaTranslator/LunaTranslator/gui/edittext.py +++ b/LunaTranslator/LunaTranslator/gui/edittext.py @@ -16,7 +16,7 @@ class edittext(saveposwindow): super().closeEvent(e) def __init__(self, parent, cached): - super().__init__(parent, globalconfig, "edit_geo") + super().__init__(parent, poslist=globalconfig["edit_geo"]) self.setupUi() # self.setWindowFlags(self.windowFlags()&~Qt.WindowMinimizeButtonHint) diff --git a/LunaTranslator/LunaTranslator/gui/selecthook.py b/LunaTranslator/LunaTranslator/gui/selecthook.py index 2fe6486b..899efcf7 100644 --- a/LunaTranslator/LunaTranslator/gui/selecthook.py +++ b/LunaTranslator/LunaTranslator/gui/selecthook.py @@ -373,7 +373,7 @@ class hookselect(closeashidewindow): update_item_new_line = pyqtSignal(tuple, str) def __init__(self, parent): - super(hookselect, self).__init__(parent, globalconfig, "selecthookgeo") + super(hookselect, self).__init__(parent, globalconfig["selecthookgeo"]) self.setupUi() self.changeprocessclearsignal.connect(self.changeprocessclear) self.removehooksignal.connect(self.removehook) diff --git a/LunaTranslator/LunaTranslator/gui/setting.py b/LunaTranslator/LunaTranslator/gui/setting.py index 937a5ad6..fd58a6d8 100644 --- a/LunaTranslator/LunaTranslator/gui/setting.py +++ b/LunaTranslator/LunaTranslator/gui/setting.py @@ -72,7 +72,7 @@ class Setting(closeashidewindow): showandsolvesig = pyqtSignal(str) def __init__(self, parent): - super(Setting, self).__init__(parent, globalconfig, "setting_geo_2") + super(Setting, self).__init__(parent, globalconfig["setting_geo_2"]) self.setWindowIcon(qtawesome.icon("fa.gear")) self.mp3player = wavmp3player() self.mp3playsignal.connect(self.mp3player.mp3playfunction) diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_text.py b/LunaTranslator/LunaTranslator/gui/setting_display_text.py index da281ef5..e79cff0f 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_text.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_text.py @@ -96,7 +96,7 @@ class extrahtml(saveposwindow): ff.write(self.vistext.toPlainText()) def __init__(self, parent) -> None: - super().__init__(parent, globalconfig, "geo_extrahtml") + super().__init__(parent, poslist=globalconfig["geo_extrahtml"]) self.setWindowTitle(_TR("额外的html")) self.btn_save = QPushButton(_TR("保存")) diff --git a/LunaTranslator/LunaTranslator/gui/showocrimage.py b/LunaTranslator/LunaTranslator/gui/showocrimage.py index 21e198db..91346ba1 100644 --- a/LunaTranslator/LunaTranslator/gui/showocrimage.py +++ b/LunaTranslator/LunaTranslator/gui/showocrimage.py @@ -50,7 +50,7 @@ class showocrimage(saveposwindow): def __init__(self, parent, cached): self.img1 = None self.originimage = None - super().__init__(parent, globalconfig, "showocrgeo") + super().__init__(parent, poslist=globalconfig["showocrgeo"]) self.setWindowIcon(qtawesome.icon("fa.picture-o")) self.setWindowTitle(_TR("查看处理效果")) self.originlabel = pixlabel() diff --git a/LunaTranslator/LunaTranslator/gui/showword.py b/LunaTranslator/LunaTranslator/gui/showword.py index 04b27e00..ccc6b17d 100644 --- a/LunaTranslator/LunaTranslator/gui/showword.py +++ b/LunaTranslator/LunaTranslator/gui/showword.py @@ -724,7 +724,7 @@ class searchwordW(closeashidewindow): showtabsignal = pyqtSignal(float, str, str) def __init__(self, parent): - super(searchwordW, self).__init__(parent, globalconfig, "sw_geo") + super(searchwordW, self).__init__(parent, globalconfig["sw_geo"]) # self.setWindowFlags(self.windowFlags()&~Qt.WindowMinimizeButtonHint) self.getnewsentencesignal.connect(self.getnewsentence) diff --git a/LunaTranslator/LunaTranslator/gui/transhist.py b/LunaTranslator/LunaTranslator/gui/transhist.py index 5a8d16a6..2430a882 100644 --- a/LunaTranslator/LunaTranslator/gui/transhist.py +++ b/LunaTranslator/LunaTranslator/gui/transhist.py @@ -12,7 +12,7 @@ class transhist(closeashidewindow): getnewtranssignal = pyqtSignal(str, str) def __init__(self, parent): - super(transhist, self).__init__(parent, globalconfig, "hist_geo") + super(transhist, self).__init__(parent, globalconfig["hist_geo"]) self.setupUi() # self.setWindowFlags(self.windowFlags()&~Qt.WindowMinimizeButtonHint) self.getnewsentencesignal.connect(self.getnewsentence) diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 126c8f98..afc126e3 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -579,8 +579,7 @@ class QUnFrameWindow(resizableframeless): None, flags=Qt.WindowType.FramelessWindowHint | Qt.WindowType.WindowMinimizeButtonHint, - dic=globalconfig, - key="transuigeo", + poslist=globalconfig["transuigeo"] ) # 设置为顶级窗口,无边框 icon = getExeIcon(sys.argv[0]) #'./LunaTranslator.exe')# QIcon() # icon.addPixmap(QPixmap('./files/luna.png'), QIcon.Normal, QIcon.On) diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index 434e2109..b4bf911b 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -115,27 +115,28 @@ def makerect(_): class saveposwindow(QMainWindow): - def __init__(self, parent, dic=None, key=None, flags=None) -> None: + def __init__(self, parent, poslist=None, flags=None) -> None: if flags: super().__init__(parent, flags=flags) else: super().__init__(parent) d = QApplication.primaryScreen() - self.dic, self.key = dic, key - if self.dic: - dic[key][2] = max(0, min(dic[key][2], d.size().width())) - dic[key][3] = max(0, min(dic[key][3], d.size().height())) - dic[key][0] = min(max(dic[key][0], 0), d.size().width() - dic[key][2]) - dic[key][1] = min(max(dic[key][1], 0), d.size().height() - dic[key][3]) - self.setGeometry(*dic[key]) + self.poslist = poslist + if self.poslist: + poslist[2] = max(0, min(poslist[2], d.size().width())) + poslist[3] = max(0, min(poslist[3], d.size().height())) + poslist[0] = min(max(poslist[0], 0), d.size().width() - poslist[2]) + poslist[1] = min(max(poslist[1], 0), d.size().height() - poslist[3]) + self.setGeometry(*poslist) def __checked_savepos(self): - if not self.dic: + if not self.poslist: return if windows.IsZoomed(int(self.winId())) != 0: return # self.isMaximized()会在event结束后才被设置,不符合预期。 - self.dic[self.key] = list(self.geometry().getRect()) + for i, _ in enumerate(self.geometry().getRect()): + self.poslist[i] = _ def resizeEvent(self, a0) -> None: self.__checked_savepos() @@ -151,8 +152,8 @@ class closeashidewindow(saveposwindow): showsignal = pyqtSignal() realshowhide = pyqtSignal(bool) - def __init__(self, parent, dic=None, key=None) -> None: - super().__init__(parent, dic, key) + def __init__(self, parent, poslist=None) -> None: + super().__init__(parent, poslist) self.showsignal.connect(self.showfunction) self.realshowhide.connect(self.realshowhidefunction) @@ -400,8 +401,8 @@ class MySwitch2(QPushButton): class resizableframeless(saveposwindow): - def __init__(self, parent, flags, dic, key) -> None: - super().__init__(parent, dic, key, flags) + def __init__(self, parent, flags, poslist) -> None: + super().__init__(parent, poslist, flags) self.setMouseTracking(True) self._padding = 5 @@ -1166,7 +1167,7 @@ class CustomKeySequenceEdit(QKeySequenceEdit): def getsimplekeyseq(dic, key, callback=None): - key1 = CustomKeySequenceEdit(QKeySequence(dic[key])) + key1 = CustomKeySequenceEdit(QKeySequence(poslist)) def __(_d, _k, cb, s): _d[_k] = s diff --git a/LunaTranslator/LunaTranslator/rendertext/webview.py b/LunaTranslator/LunaTranslator/rendertext/webview.py index 128b3640..6c5b7146 100644 --- a/LunaTranslator/LunaTranslator/rendertext/webview.py +++ b/LunaTranslator/LunaTranslator/rendertext/webview.py @@ -4,7 +4,7 @@ from rendertext.somefunctions import dataget import gobject, uuid, json, os from urllib.parse import quote from myutils.config import globalconfig -from gui.usefulwidget import WebivewWidget, QWebWrap +from gui.usefulwidget import WebivewWidget, QWebWrap, saveposwindow from myutils.utils import checkportavailable testsavejs = False @@ -33,6 +33,7 @@ class TextBrowser(QWidget, dataget): Qt.ContextMenuPolicy.CustomContextMenu ) self.webivewwidget.internal.customContextMenuRequested.connect(self._qwmenu) + else: # webview2当会执行alert之类的弹窗js时,若qt窗口不可视,会卡住 self.webivewwidget = WebivewWidget(self) @@ -47,27 +48,45 @@ class TextBrowser(QWidget, dataget): self.isfirst = True def _qwmenu(self, pos): - web_menu = QMenu() - inspect = QAction("inspect") - web_menu.addAction(inspect) - action = web_menu.exec_(self.webivewwidget.mapToGlobal(pos)) - if action == inspect: - from PyQt5.QtWebEngineWidgets import QWebEngineView + from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView - self.inspector = QWebEngineView() - - def __(_): - self.webivewwidget.internal.setContextMenuPolicy( - Qt.ContextMenuPolicy.CustomContextMenu - ) - - self.inspector.closeEvent = __ - self.inspector.load(QUrl(self.DEBUG_URL)) - self.webivewwidget.internal.page().setDevToolsPage(self.inspector.page()) - self.inspector.show() - self.webivewwidget.internal.setContextMenuPolicy( - Qt.ContextMenuPolicy.DefaultContextMenu + loadinspector = QAction("Inspect") + web_menu = self.webivewwidget.internal.page().createStandardContextMenu() + if ( + self.webivewwidget.internal.page().action( + QWebEnginePage.WebAction.InspectElement ) + not in web_menu.actions() + ): + web_menu.addAction(loadinspector) + action = web_menu.exec_(self.webivewwidget.mapToGlobal(pos)) + + if action == loadinspector: + + class QMW(saveposwindow): + def closeEvent(_self, e): + self.webivewwidget.internal.page().setDevToolsPage(None) + super(QMW, _self).closeEvent(e) + + def __init__(_self) -> None: + super().__init__( + gobject.baseobject.settin_ui, + poslist=globalconfig["qwebinspectgeo"] + ) + _self.setWindowTitle("Inspect") + _self.internal = QWebEngineView(_self) + _self.setCentralWidget(_self.internal) + _self.internal.load(QUrl(self.DEBUG_URL)) + self.webivewwidget.internal.page().setDevToolsPage( + _self.internal.page() + ) + self.webivewwidget.internal.page().triggerAction( + QWebEnginePage.WebAction.InspectElement + ) + + _self.show() + + QMW() def showEvent(self, e): if not self.isfirst: diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 785f3e53..698f845e 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -310,6 +310,12 @@ "maxHistorySize": 1000000, "yuanjiao_r": 0, "yuanjiao_merge": true, + "qwebinspectgeo": [ + 100, + 100, + 800, + 400 + ], "transuigeo": [ 500, 500,