eric6/WebBrowser/WebBrowserPage.py

changeset 8143
2c730d5fd177
parent 7923
91e843545d9a
child 8218
7c09585bd960
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
55 @signal navigationRequestAccepted(url, navigation type, main frame) emitted 55 @signal navigationRequestAccepted(url, navigation type, main frame) emitted
56 to signal an accepted navigation request 56 to signal an accepted navigation request
57 @signal sslConfigurationChanged() emitted to indicate a change of the 57 @signal sslConfigurationChanged() emitted to indicate a change of the
58 stored SSL configuration data 58 stored SSL configuration data
59 """ 59 """
60 SafeJsWorld = QWebEngineScript.ApplicationWorld 60 SafeJsWorld = QWebEngineScript.ScriptWorldId.ApplicationWorld
61 UnsafeJsWorld = QWebEngineScript.MainWorld 61 UnsafeJsWorld = QWebEngineScript.ScriptWorldId.MainWorld
62 62
63 safeBrowsingAbort = pyqtSignal() 63 safeBrowsingAbort = pyqtSignal()
64 safeBrowsingBad = pyqtSignal(str, str) 64 safeBrowsingBad = pyqtSignal(str, str)
65 65
66 printPageRequested = pyqtSignal() 66 printPageRequested = pyqtSignal()
144 144
145 # GreaseMonkey 145 # GreaseMonkey
146 try: 146 try:
147 # PyQtWebEngine >= 5.14.0 147 # PyQtWebEngine >= 5.14.0
148 navigationType = type_ in [ 148 navigationType = type_ in [
149 QWebEnginePage.NavigationTypeLinkClicked, 149 QWebEnginePage.NavigationType.NavigationTypeLinkClicked,
150 QWebEnginePage.NavigationTypeRedirect 150 QWebEnginePage.NavigationType.NavigationTypeRedirect
151 ] 151 ]
152 except AttributeError: 152 except AttributeError:
153 navigationType = type_ == QWebEnginePage.NavigationTypeLinkClicked 153 navigationType = (
154 type_ ==
155 QWebEnginePage.NavigationType.NavigationTypeLinkClicked
156 )
154 if navigationType and url.toString().endswith(".user.js"): 157 if navigationType and url.toString().endswith(".user.js"):
155 WebBrowserWindow.greaseMonkeyManager().downloadScript(url) 158 WebBrowserWindow.greaseMonkeyManager().downloadScript(url)
156 return False 159 return False
157 160
158 if url.scheme() == "eric": 161 if url.scheme() == "eric":
209 if result: 212 if result:
210 if isMainFrame: 213 if isMainFrame:
211 isWeb = url.scheme() in ("http", "https", "ftp", "ftps", 214 isWeb = url.scheme() in ("http", "https", "ftp", "ftps",
212 "file") 215 "file")
213 globalJsEnabled = WebBrowserWindow.webSettings().testAttribute( 216 globalJsEnabled = WebBrowserWindow.webSettings().testAttribute(
214 QWebEngineSettings.JavascriptEnabled) 217 QWebEngineSettings.WebAttribute.JavascriptEnabled)
215 if isWeb: 218 if isWeb:
216 enable = globalJsEnabled 219 enable = globalJsEnabled
217 else: 220 else:
218 enable = True 221 enable = True
219 self.settings().setAttribute( 222 self.settings().setAttribute(
220 QWebEngineSettings.JavascriptEnabled, enable) 223 QWebEngineSettings.WebAttribute.JavascriptEnabled, enable)
221 224
222 self.__channelUrl = url 225 self.__channelUrl = url
223 self.__setupChannelTimer.start() 226 self.__setupChannelTimer.start()
224 self.navigationRequestAccepted.emit(url, type_, isMainFrame) 227 self.navigationRequestAccepted.emit(url, type_, isMainFrame)
225 228
236 if ( 239 if (
237 not url.isEmpty() and 240 not url.isEmpty() and
238 url.scheme() == "eric" and 241 url.scheme() == "eric" and
239 not self.isJavaScriptEnabled() 242 not self.isJavaScriptEnabled()
240 ): 243 ):
241 self.settings().setAttribute(QWebEngineSettings.JavascriptEnabled, 244 self.settings().setAttribute(
242 True) 245 QWebEngineSettings.WebAttribute.JavascriptEnabled, True)
243 self.triggerAction(QWebEnginePage.Reload) 246 self.triggerAction(QWebEnginePage.WebAction.Reload)
244 247
245 @classmethod 248 @classmethod
246 def userAgent(cls, resolveEmpty=False): 249 def userAgent(cls, resolveEmpty=False):
247 """ 250 """
248 Class method to get the global user agent setting. 251 Class method to get the global user agent setting.
292 @type QWebEnginePage.Feature 295 @type QWebEnginePage.Feature
293 """ 296 """
294 manager = WebBrowserWindow.featurePermissionManager() 297 manager = WebBrowserWindow.featurePermissionManager()
295 manager.requestFeaturePermission(self, url, feature) 298 manager.requestFeaturePermission(self, url, feature)
296 299
297 def execJavaScript(self, script, worldId=QWebEngineScript.MainWorld, 300 def execJavaScript(self, script,
301 worldId=QWebEngineScript.ScriptWorldId.MainWorld,
298 timeout=500): 302 timeout=500):
299 """ 303 """
300 Public method to execute a JavaScript function synchroneously. 304 Public method to execute a JavaScript function synchroneously.
301 305
302 @param script JavaScript script source to be executed 306 @param script JavaScript script source to be executed
303 @type str 307 @type str
304 @param worldId ID to run the script under 308 @param worldId ID to run the script under
305 @type int 309 @type QWebEngineScript.ScriptWorldId
306 @param timeout max. time the script is given to execute 310 @param timeout max. time the script is given to execute
307 @type int 311 @type int
308 @return result of the script 312 @return result of the script
309 @rtype depending upon script result 313 @rtype depending upon script result
310 """ 314 """
351 355
352 @return flag indicating the state of the JavaScript support 356 @return flag indicating the state of the JavaScript support
353 @rtype bool 357 @rtype bool
354 """ 358 """
355 return self.settings().testAttribute( 359 return self.settings().testAttribute(
356 QWebEngineSettings.JavascriptEnabled) 360 QWebEngineSettings.WebAttribute.JavascriptEnabled)
357 361
358 def scroll(self, x, y): 362 def scroll(self, x, y):
359 """ 363 """
360 Public method to scroll by the given amount of pixels. 364 Public method to scroll by the given amount of pixels.
361 365

eric ide

mercurial