src/eric7/WebBrowser/WebInspector.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
17 17
18 18
19 class WebInspector(QWebEngineView): 19 class WebInspector(QWebEngineView):
20 """ 20 """
21 Class implementing a QWebEngineView to load the web inspector in. 21 Class implementing a QWebEngineView to load the web inspector in.
22 22
23 @signal inspectorClosed emitted to indicate the closing of the inspector 23 @signal inspectorClosed emitted to indicate the closing of the inspector
24 window 24 window
25 """ 25 """
26
26 inspectorClosed = pyqtSignal() 27 inspectorClosed = pyqtSignal()
27 28
28 def __init__(self, parent=None): 29 def __init__(self, parent=None):
29 """ 30 """
30 Constructor 31 Constructor
31 32
32 @param parent reference to the parent widget 33 @param parent reference to the parent widget
33 @type QWidget 34 @type QWidget
34 """ 35 """
35 super().__init__(parent) 36 super().__init__(parent)
36 37
37 self.__view = None 38 self.__view = None
38 self.__inspectElement = False 39 self.__inspectElement = False
39 40
40 self.__reloadGeometry() 41 self.__reloadGeometry()
41 42
42 registerView(self) 43 registerView(self)
43 44
44 self.page().windowCloseRequested.connect(self.close) 45 self.page().windowCloseRequested.connect(self.close)
45 self.page().loadFinished.connect(self.__loadFinished) 46 self.page().loadFinished.connect(self.__loadFinished)
46 47
47 def closeEvent(self, evt): 48 def closeEvent(self, evt):
48 """ 49 """
49 Protected method to save the geometry when closed. 50 Protected method to save the geometry when closed.
50 51
51 @param evt event object 52 @param evt event object
52 @type QCloseEvent 53 @type QCloseEvent
53 """ 54 """
54 Preferences.setGeometry("WebInspectorGeometry", self.saveGeometry()) 55 Preferences.setGeometry("WebInspectorGeometry", self.saveGeometry())
55 super().closeEvent(evt) 56 super().closeEvent(evt)
56 57
57 if evt.isAccepted(): 58 if evt.isAccepted():
58 self.inspectorClosed.emit() 59 self.inspectorClosed.emit()
59 60
60 def __reloadGeometry(self): 61 def __reloadGeometry(self):
61 """ 62 """
65 if geom.isEmpty(): 66 if geom.isEmpty():
66 s = QSize(600, 600) 67 s = QSize(600, 600)
67 self.resize(s) 68 self.resize(s)
68 else: 69 else:
69 self.restoreGeometry(geom) 70 self.restoreGeometry(geom)
70 71
71 def setView(self, view, inspectElement=False): 72 def setView(self, view, inspectElement=False):
72 """ 73 """
73 Public method to connect a view to this inspector. 74 Public method to connect a view to this inspector.
74 75
75 @param view reference to the view object 76 @param view reference to the view object
76 @type WebBrowserView 77 @type WebBrowserView
77 @param inspectElement flag indicating to start a web inspection 78 @param inspectElement flag indicating to start a web inspection
78 @type bool 79 @type bool
79 """ 80 """
80 self.__view = view 81 self.__view = view
81 if not self.isEnabled(): 82 if not self.isEnabled():
82 return 83 return
83 84
84 self.__inspectElement = inspectElement 85 self.__inspectElement = inspectElement
85 86
86 self.page().setInspectedPage(self.__view.page()) 87 self.page().setInspectedPage(self.__view.page())
87 88
88 def inspectElement(self): 89 def inspectElement(self):
89 """ 90 """
90 Public method to inspect an element. 91 Public method to inspect an element.
91 """ 92 """
92 self.__inspectElement = True 93 self.__inspectElement = True
93 94
94 @classmethod 95 @classmethod
95 def isEnabled(cls): 96 def isEnabled(cls):
96 """ 97 """
97 Class method to check, if the web inspector is enabled. 98 Class method to check, if the web inspector is enabled.
98 99
99 @return flag indicating the enabled state 100 @return flag indicating the enabled state
100 @rtype bool 101 @rtype bool
101 """ 102 """
102 from WebBrowser.WebBrowserWindow import WebBrowserWindow 103 from WebBrowser.WebBrowserWindow import WebBrowserWindow
104
103 if not WebBrowserWindow.webSettings().testAttribute( 105 if not WebBrowserWindow.webSettings().testAttribute(
104 QWebEngineSettings.WebAttribute.JavascriptEnabled): 106 QWebEngineSettings.WebAttribute.JavascriptEnabled
107 ):
105 return False 108 return False
106 109
107 return True 110 return True
108 111
109 def __loadFinished(self): 112 def __loadFinished(self):
110 """ 113 """
111 Private slot handling the finished signal. 114 Private slot handling the finished signal.
112 """ 115 """
113 if self.__inspectElement: 116 if self.__inspectElement:
114 self.__view.triggerPageAction( 117 self.__view.triggerPageAction(QWebEnginePage.WebAction.InspectElement)
115 QWebEnginePage.WebAction.InspectElement)
116 self.__inspectElement = False 118 self.__inspectElement = False
117 119
118 120
119 def registerView(view): 121 def registerView(view):
120 """ 122 """
121 Function to register a view. 123 Function to register a view.
122 124
123 @param view reference to the view 125 @param view reference to the view
124 @type WebBrowserView 126 @type WebBrowserView
125 """ 127 """
126 if _VIEWS is None: 128 if _VIEWS is None:
127 return 129 return
128 130
129 _VIEWS.insert(0, view) 131 _VIEWS.insert(0, view)
130 132
131 133
132 def unregisterView(view): 134 def unregisterView(view):
133 """ 135 """
134 Function to unregister a view. 136 Function to unregister a view.
135 137
136 @param view reference to the view 138 @param view reference to the view
137 @type WebBrowserView 139 @type WebBrowserView
138 """ 140 """
139 if _VIEWS is None: 141 if _VIEWS is None:
140 return 142 return
141 143
142 if view in _VIEWS: 144 if view in _VIEWS:
143 _VIEWS.remove(view) 145 _VIEWS.remove(view)
144 146
145 147
146 def pushView(view): 148 def pushView(view):
147 """ 149 """
148 Function to push a view to the front of the list. 150 Function to push a view to the front of the list.
149 151
150 @param view reference to the view 152 @param view reference to the view
151 @type WebBrowserView 153 @type WebBrowserView
152 """ 154 """
153 if _VIEWS is None: 155 if _VIEWS is None:
154 return 156 return
155 157
156 if view in _VIEWS: 158 if view in _VIEWS:
157 _VIEWS.remove(view) 159 _VIEWS.remove(view)
158 _VIEWS.insert(0, view) 160 _VIEWS.insert(0, view)

eric ide

mercurial