WebBrowser/WebBrowserPage.py

changeset 4964
a894e8c92369
parent 4925
6534062014dc
child 4965
a9a4b632fe48
--- a/WebBrowser/WebBrowserPage.py	Mon May 02 20:14:37 2016 +0200
+++ b/WebBrowser/WebBrowserPage.py	Tue May 03 19:42:26 2016 +0200
@@ -14,9 +14,9 @@
 except NameError:
     pass
 
-from PyQt5.QtCore import QUrl, QTimer, QEventLoop, QPoint
+from PyQt5.QtCore import pyqtSlot, QUrl, QTimer, QEventLoop, QPoint
 from PyQt5.QtGui import QDesktopServices
-from PyQt5.QtWebEngineWidgets import QWebEnginePage
+from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineSettings
 from PyQt5.QtWebChannel import QWebChannel
 
 from WebBrowser.WebBrowserWindow import WebBrowserWindow
@@ -53,6 +53,8 @@
             WebBrowserWindow.networkManager().proxyAuthentication)
         
         self.fullScreenRequested.connect(self.__fullScreenRequested)
+        
+        self.urlChanged.connect(self.__urlChanged)
     
     def acceptNavigationRequest(self, url, type_, isMainFrame):
         """
@@ -81,6 +83,17 @@
         return QWebEnginePage.acceptNavigationRequest(self, url, type_,
                                                       isMainFrame)
     
+    @pyqtSlot(QUrl)
+    def __urlChanged(self, url):
+        """
+        Private slot to handle changes of the URL.
+        
+        @param url new URL
+        @type QUrl
+        """
+        if not url.isEmpty() and url.scheme() == "eric":
+            self.setJavaScriptEnabled(True)
+    
     @classmethod
     def userAgent(cls, resolveEmpty=False):
         """
@@ -156,6 +169,19 @@
         loop.exec_()
         return resultDict["res"]
     
+    def setJavaScriptEnabled(self, enable):
+        """
+        Public method to enable JavaScript.
+        
+        @param enable flag indicating the enabled state to be set
+        @type bool
+        """
+        if not self.url().isEmpty() and self.url().scheme() == "eric":
+            enable = True
+        
+        self.settings().setAttribute(QWebEngineSettings.JavascriptEnabled,
+                                     enable);
+    
     def scroll(self, x, y):
         """
         Public method to scroll by the given amount of pixels.

eric ide

mercurial