12 try: |
12 try: |
13 str = unicode # __IGNORE_EXCEPTION__ |
13 str = unicode # __IGNORE_EXCEPTION__ |
14 except NameError: |
14 except NameError: |
15 pass |
15 pass |
16 |
16 |
17 from PyQt5.QtCore import QUrl, QTimer, QEventLoop, QPoint |
17 from PyQt5.QtCore import pyqtSlot, QUrl, QTimer, QEventLoop, QPoint |
18 from PyQt5.QtGui import QDesktopServices |
18 from PyQt5.QtGui import QDesktopServices |
19 from PyQt5.QtWebEngineWidgets import QWebEnginePage |
19 from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineSettings |
20 from PyQt5.QtWebChannel import QWebChannel |
20 from PyQt5.QtWebChannel import QWebChannel |
21 |
21 |
22 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
22 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
23 |
23 |
24 from .JavaScript.ExternalJsObject import ExternalJsObject |
24 from .JavaScript.ExternalJsObject import ExternalJsObject |
51 |
51 |
52 self.proxyAuthenticationRequired.connect( |
52 self.proxyAuthenticationRequired.connect( |
53 WebBrowserWindow.networkManager().proxyAuthentication) |
53 WebBrowserWindow.networkManager().proxyAuthentication) |
54 |
54 |
55 self.fullScreenRequested.connect(self.__fullScreenRequested) |
55 self.fullScreenRequested.connect(self.__fullScreenRequested) |
|
56 |
|
57 self.urlChanged.connect(self.__urlChanged) |
56 |
58 |
57 def acceptNavigationRequest(self, url, type_, isMainFrame): |
59 def acceptNavigationRequest(self, url, type_, isMainFrame): |
58 """ |
60 """ |
59 Public method to determine, if a request may be accepted. |
61 Public method to determine, if a request may be accepted. |
60 |
62 |
79 return False |
81 return False |
80 |
82 |
81 return QWebEnginePage.acceptNavigationRequest(self, url, type_, |
83 return QWebEnginePage.acceptNavigationRequest(self, url, type_, |
82 isMainFrame) |
84 isMainFrame) |
83 |
85 |
|
86 @pyqtSlot(QUrl) |
|
87 def __urlChanged(self, url): |
|
88 """ |
|
89 Private slot to handle changes of the URL. |
|
90 |
|
91 @param url new URL |
|
92 @type QUrl |
|
93 """ |
|
94 if not url.isEmpty() and url.scheme() == "eric": |
|
95 self.setJavaScriptEnabled(True) |
|
96 |
84 @classmethod |
97 @classmethod |
85 def userAgent(cls, resolveEmpty=False): |
98 def userAgent(cls, resolveEmpty=False): |
86 """ |
99 """ |
87 Class method to get the global user agent setting. |
100 Class method to get the global user agent setting. |
88 |
101 |
154 self.runJavaScript(script, resultCallback) |
167 self.runJavaScript(script, resultCallback) |
155 |
168 |
156 loop.exec_() |
169 loop.exec_() |
157 return resultDict["res"] |
170 return resultDict["res"] |
158 |
171 |
|
172 def setJavaScriptEnabled(self, enable): |
|
173 """ |
|
174 Public method to enable JavaScript. |
|
175 |
|
176 @param enable flag indicating the enabled state to be set |
|
177 @type bool |
|
178 """ |
|
179 if not self.url().isEmpty() and self.url().scheme() == "eric": |
|
180 enable = True |
|
181 |
|
182 self.settings().setAttribute(QWebEngineSettings.JavascriptEnabled, |
|
183 enable); |
|
184 |
159 def scroll(self, x, y): |
185 def scroll(self, x, y): |
160 """ |
186 """ |
161 Public method to scroll by the given amount of pixels. |
187 Public method to scroll by the given amount of pixels. |
162 |
188 |
163 @param x horizontal scroll value |
189 @param x horizontal scroll value |