eric6/WebBrowser/WebInspector.py

Wed, 25 Sep 2019 19:11:13 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 25 Sep 2019 19:11:13 +0200
changeset 7271
2cac5b7abcce
parent 7229
53054eb5b15a
child 7360
9190402e4505
permissions
-rw-r--r--

Continued to resolve code style issue M841.

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

eric ide

mercurial