eric6/WebBrowser/WebInspector.py

Mon, 12 Oct 2020 19:28:42 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 12 Oct 2020 19:28:42 +0200
changeset 7781
607a6098cb44
parent 7360
9190402e4505
child 7923
91e843545d9a
permissions
-rw-r--r--

Performed some more code cleanup.

4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7271
diff changeset
3 # Copyright (c) 2015 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
7 Module implementing a QWebEngineView to load the web inspector in.
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
10 import json
6126
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
11 import os
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
12
6126
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
13 from PyQt5.QtCore import pyqtSignal, QSize, QUrl
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
14 from PyQt5.QtNetwork import QNetworkRequest
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
15 from PyQt5.QtWebEngineWidgets import (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
16 QWebEngineView, QWebEnginePage, QWebEngineSettings
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
17 )
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
6402
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
19 from Globals import qVersionTuple
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
20
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 import Preferences
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
23 _VIEWS = []
4352
86f7a3344d38 Fixed some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4341
diff changeset
24
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
25
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
26 class WebInspector(QWebEngineView):
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
28 Class implementing a QWebEngineView to load the web inspector in.
6126
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
29
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
30 @signal inspectorClosed emitted to indicate the closing of the inspector
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
31 window
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
6126
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
33 inspectorClosed = pyqtSignal()
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
34
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 def __init__(self, parent=None):
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 Constructor
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @param parent reference to the parent widget
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @type QWidget
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
42 super(WebInspector, self).__init__(parent)
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
43
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
44 self.__view = None
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
45 self.__inspectElement = False
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
46
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.__reloadGeometry()
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
48
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
49 registerView(self)
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
50
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
51 self.page().windowCloseRequested.connect(self.close)
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
52 self.page().loadFinished.connect(self.__loadFinished)
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
53
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 def closeEvent(self, evt):
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Protected method to save the geometry when closed.
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @param evt event object
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 @type QCloseEvent
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
61 Preferences.setGeometry("WebInspectorGeometry", self.saveGeometry())
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
62 super(WebInspector, self).closeEvent(evt)
6126
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
63
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
64 if evt.isAccepted():
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
65 self.inspectorClosed.emit()
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 def __reloadGeometry(self):
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 """
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 Private method to restore the geometry.
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
71 geom = Preferences.getGeometry("WebInspectorGeometry")
4341
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 if geom.isEmpty():
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 s = QSize(600, 600)
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.resize(s)
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 else:
1ff0929aab09 Added our own web inspector window to overcome a Qt weekness.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.restoreGeometry(geom)
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
77
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
78 def setView(self, view, inspectElement=False):
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
79 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
80 Public method to connect a view to this inspector.
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
81
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
82 @param view reference to the view object
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
83 @type WebBrowserView
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
84 @param inspectElement flag indicating to start a web inspection
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
85 @type bool
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
86 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
87 self.__view = view
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
88 if not self.isEnabled():
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
89 return
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
90
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
91 self.__inspectElement = inspectElement
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
92
6402
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
93 try:
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
94 self.page().setInspectedPage(self.__view.page())
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
95 except AttributeError:
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
96 # pre Qt 5.11
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
97 port = Preferences.getWebBrowser("WebInspectorPort")
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
98 inspectorUrl = QUrl("http://localhost:{0}".format(port))
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
99
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
100 from WebBrowser.WebBrowserWindow import WebBrowserWindow
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
101 self.__reply = WebBrowserWindow.networkManager().get(
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
102 QNetworkRequest(inspectorUrl.resolved(QUrl("json/list"))))
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
103 self.__reply.finished.connect(self.__inspectorReplyFinished)
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
104
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
105 def __inspectorReplyFinished(self):
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
106 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
107 Private slot handling the reply.
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
108 """
6402
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
109 # used for pre Qt 5.11
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
110 result = str(self.__reply.readAll(), encoding="utf8")
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
111
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
112 self.__reply.deleteLater()
6280
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
113 self.__reply = None
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
114
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
115 pageUrl = QUrl()
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
116 try:
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
117 index = _VIEWS.index(self.__view)
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
118 except ValueError:
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
119 index = -1
6280
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
120 try:
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
121 clients = json.loads(result)
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
122 if len(clients) > index:
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
123 port = Preferences.getWebBrowser("WebInspectorPort")
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
124 inspectorUrl = QUrl("http://localhost:{0}".format(port))
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
125
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
126 client = clients[index]
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
127 pageUrl = inspectorUrl.resolved(
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
128 QUrl(client["devtoolsFrontendUrl"]))
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
129 self.load(pageUrl)
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
130 pushView(self)
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
131 self.show()
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
132 except json.JSONDecodeError:
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
133 # ignore silently
1d4d790414b2 WebInspector: fixed an issue caused by the inspector backend not returning anything
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
134 pass
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
135
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
136 def inspectElement(self):
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
137 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
138 Public method to inspect an element.
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
139 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
140 self.__inspectElement = True
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
141
6126
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
142 @classmethod
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
143 def isEnabled(cls):
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
144 """
6126
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
145 Class method to check, if the web inspector is enabled.
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
146
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
147 @return flag indicating the enabled state
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
148 @rtype bool
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
149 """
6402
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
150 if qVersionTuple() < (5, 11, 0):
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
151 if not os.getenv("QTWEBENGINE_REMOTE_DEBUGGING"):
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
152 return False
6126
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
153
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6126
diff changeset
154 from WebBrowser.WebBrowserWindow import WebBrowserWindow
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6126
diff changeset
155 if not WebBrowserWindow.webSettings().testAttribute(
6126
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
156 QWebEngineSettings.JavascriptEnabled):
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
157 return False
6c4509eceea2 Fixed an issue related to the display of the web inspector window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
158
6402
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
159 if qVersionTuple() < (5, 11, 0):
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
160 return Preferences.getWebBrowser("WebInspectorEnabled")
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
161 else:
bdc273bb66c5 WebInspector: adjusted the code to support the enhanced web inspector interface of Qt 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6398
diff changeset
162 return True
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
163
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
164 def __loadFinished(self):
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
165 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
166 Private slot handling the finished signal.
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
167 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
168 if self.__inspectElement:
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4782
diff changeset
169 self.__view.triggerPageAction(QWebEnginePage.InspectElement)
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
170 self.__inspectElement = False
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
171
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
172
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
173 def registerView(view):
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
174 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
175 Function to register a view.
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
176
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
177 @param view reference to the view
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
178 @type WebBrowserView
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
179 """
4782
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
180 if _VIEWS is None:
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
181 return
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
182
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
183 _VIEWS.insert(0, view)
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
184
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
185
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
186 def unregisterView(view):
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
187 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
188 Function to unregister a view.
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
189
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
190 @param view reference to the view
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
191 @type WebBrowserView
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
192 """
4782
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
193 if _VIEWS is None:
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
194 return
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
195
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
196 if view in _VIEWS:
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
197 _VIEWS.remove(view)
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
198
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
199
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
200 def pushView(view):
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
201 """
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
202 Function to push a view to the front of the list.
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
203
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
204 @param view reference to the view
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
205 @type WebBrowserView
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
206 """
4782
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
207 if _VIEWS is None:
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
208 return
4ad656e4ebec Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4781
diff changeset
209
4781
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
210 if view in _VIEWS:
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
211 _VIEWS.remove(view)
15d416f1eca5 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
212 _VIEWS.insert(0, view)

eric ide

mercurial