mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2025-01-01 10:04:12 +08:00
inspect
This commit is contained in:
parent
8a68205f98
commit
ba0bcd6cc9
@ -1,7 +1,7 @@
|
|||||||
from qtsymbols import *
|
from qtsymbols import *
|
||||||
import os, platform, functools, threading, time
|
import os, platform, functools, threading, time
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
import windows, qtawesome, winsharedutils
|
import windows, qtawesome, winsharedutils, gobject
|
||||||
from webviewpy import (
|
from webviewpy import (
|
||||||
webview_native_handle_kind_t,
|
webview_native_handle_kind_t,
|
||||||
Webview,
|
Webview,
|
||||||
@ -10,7 +10,7 @@ from webviewpy import (
|
|||||||
from winsharedutils import HTMLBrowser
|
from winsharedutils import HTMLBrowser
|
||||||
from myutils.config import _TR, globalconfig
|
from myutils.config import _TR, globalconfig
|
||||||
from myutils.wrapper import Singleton, Singleton_close
|
from myutils.wrapper import Singleton, Singleton_close
|
||||||
from myutils.utils import nowisdark
|
from myutils.utils import nowisdark, checkportavailable
|
||||||
|
|
||||||
|
|
||||||
class FocusCombo(QComboBox):
|
class FocusCombo(QComboBox):
|
||||||
@ -1070,10 +1070,17 @@ class QWebWrap(abstractwebview):
|
|||||||
from PyQt5.QtWebEngineWidgets import QWebEngineView
|
from PyQt5.QtWebEngineWidgets import QWebEngineView
|
||||||
else:
|
else:
|
||||||
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
||||||
|
if 'QTWEBENGINE_REMOTE_DEBUGGING' not in os.environ:
|
||||||
|
DEBUG_PORT = 5588
|
||||||
|
for i in range(100):
|
||||||
|
if checkportavailable(DEBUG_PORT):
|
||||||
|
break
|
||||||
|
DEBUG_PORT += 1
|
||||||
|
os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = str(DEBUG_PORT)
|
||||||
|
self.DEBUG_URL = "http://127.0.0.1:%s" % os.environ["QTWEBENGINE_REMOTE_DEBUGGING"]
|
||||||
self.internal = QWebEngineView(self)
|
self.internal = QWebEngineView(self)
|
||||||
# self.internal.page().urlChanged.connect(
|
self.internal.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||||
# lambda qurl: self.on_load.emit(qurl.url())
|
self.internal.customContextMenuRequested.connect(self._qwmenu)
|
||||||
# )
|
|
||||||
self.internal.loadFinished.connect(self._loadFinish)
|
self.internal.loadFinished.connect(self._loadFinish)
|
||||||
self.internal_zoom = 1
|
self.internal_zoom = 1
|
||||||
t = QTimer(self)
|
t = QTimer(self)
|
||||||
@ -1082,6 +1089,50 @@ class QWebWrap(abstractwebview):
|
|||||||
t.timeout.emit()
|
t.timeout.emit()
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
def _qwmenu(self, pos):
|
||||||
|
|
||||||
|
if isqt5:
|
||||||
|
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
|
||||||
|
|
||||||
|
web_menu = self.internal.page().createStandardContextMenu()
|
||||||
|
else:
|
||||||
|
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
||||||
|
from PyQt6.QtWebEngineCore import QWebEnginePage
|
||||||
|
|
||||||
|
web_menu = self.internal.createStandardContextMenu()
|
||||||
|
loadinspector = QAction("Inspect")
|
||||||
|
if (
|
||||||
|
self.internal.page().action(QWebEnginePage.WebAction.InspectElement)
|
||||||
|
not in web_menu.actions()
|
||||||
|
):
|
||||||
|
web_menu.addAction(loadinspector)
|
||||||
|
action = web_menu.exec(self.internal.mapToGlobal(pos))
|
||||||
|
|
||||||
|
if action == loadinspector:
|
||||||
|
|
||||||
|
class QMW(saveposwindow):
|
||||||
|
def closeEvent(_self, e):
|
||||||
|
self.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.internal.page().setDevToolsPage(_self.internal.page())
|
||||||
|
self.internal.page().triggerAction(
|
||||||
|
QWebEnginePage.WebAction.InspectElement
|
||||||
|
)
|
||||||
|
|
||||||
|
_self.show()
|
||||||
|
|
||||||
|
QMW()
|
||||||
|
|
||||||
def _loadFinish(self):
|
def _loadFinish(self):
|
||||||
self.on_load.emit(self.internal.url().url())
|
self.on_load.emit(self.internal.url().url())
|
||||||
|
|
||||||
|
@ -18,20 +18,8 @@ class TextBrowser(QWidget, dataget):
|
|||||||
def __init__(self, parent) -> None:
|
def __init__(self, parent) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
if globalconfig["rendertext_using"] == "QWebEngine":
|
if globalconfig["rendertext_using"] == "QWebEngine":
|
||||||
DEBUG_PORT = 5588
|
|
||||||
for i in range(100):
|
|
||||||
if checkportavailable(DEBUG_PORT):
|
|
||||||
break
|
|
||||||
DEBUG_PORT += 1
|
|
||||||
self.DEBUG_URL = "http://127.0.0.1:%s" % DEBUG_PORT
|
|
||||||
os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = str(DEBUG_PORT)
|
|
||||||
self.webivewwidget = QWebWrap(self)
|
self.webivewwidget = QWebWrap(self)
|
||||||
self.webivewwidget.on_load.connect(self.__loadextra)
|
self.webivewwidget.on_load.connect(self.__loadextra)
|
||||||
self.webivewwidget.internal.setContextMenuPolicy(
|
|
||||||
Qt.ContextMenuPolicy.CustomContextMenu
|
|
||||||
)
|
|
||||||
self.webivewwidget.internal.customContextMenuRequested.connect(self._qwmenu)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# webview2当会执行alert之类的弹窗js时,若qt窗口不可视,会卡住
|
# webview2当会执行alert之类的弹窗js时,若qt窗口不可视,会卡住
|
||||||
self.webivewwidget = WebivewWidget(self)
|
self.webivewwidget = WebivewWidget(self)
|
||||||
@ -46,54 +34,6 @@ class TextBrowser(QWidget, dataget):
|
|||||||
self.isfirst = True
|
self.isfirst = True
|
||||||
self._qweb_query_word()
|
self._qweb_query_word()
|
||||||
|
|
||||||
def _qwmenu(self, pos):
|
|
||||||
|
|
||||||
if isqt5:
|
|
||||||
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
|
|
||||||
|
|
||||||
web_menu = self.webivewwidget.internal.page().createStandardContextMenu()
|
|
||||||
else:
|
|
||||||
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
|
||||||
from PyQt6.QtWebEngineCore import QWebEnginePage
|
|
||||||
|
|
||||||
web_menu = self.webivewwidget.internal.createStandardContextMenu()
|
|
||||||
loadinspector = QAction("Inspect")
|
|
||||||
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):
|
def showEvent(self, e):
|
||||||
if not self.isfirst:
|
if not self.isfirst:
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user