10 |
10 |
11 from PyQt4.QtCore import * |
11 from PyQt4.QtCore import * |
12 from PyQt4.QtGui import * |
12 from PyQt4.QtGui import * |
13 from PyQt4.QtWebKit import QWebView, QWebPage, QWebSettings |
13 from PyQt4.QtWebKit import QWebView, QWebPage, QWebSettings |
14 from PyQt4.QtNetwork import QNetworkReply, QNetworkRequest |
14 from PyQt4.QtNetwork import QNetworkReply, QNetworkRequest |
|
15 import sip |
15 |
16 |
16 import Preferences |
17 import Preferences |
17 |
18 |
18 from .DownloadDialog import DownloadDialog |
19 from .DownloadDialog import DownloadDialog |
19 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog |
20 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog |
179 Public method to get the attribute id of the page attribute. |
180 Public method to get the attribute id of the page attribute. |
180 |
181 |
181 @return attribute id of the page attribute (integer) |
182 @return attribute id of the page attribute (integer) |
182 """ |
183 """ |
183 return QNetworkRequest.User + 100 |
184 return QNetworkRequest.User + 100 |
|
185 |
|
186 def supportsExtension(self, extension): |
|
187 """ |
|
188 Public method to check the support for an extension. |
|
189 |
|
190 @param extension extension to test for (QWebPage.Extension) |
|
191 @return flag indicating the support of extension (boolean) |
|
192 """ |
|
193 try: |
|
194 if extension == QWebPage.ErrorPageExtension: |
|
195 return True |
|
196 except AttributeError: |
|
197 pass |
|
198 |
|
199 return QWebPage.supportsExtension(self, extension) |
|
200 |
|
201 def extension(self, extension, option, output): |
|
202 """ |
|
203 Public method to implement a specific extension. |
|
204 |
|
205 @param extension extension to be executed (QWebPage.Extension) |
|
206 @param option provides input to the extension (QWebPage.ExtensionOption) |
|
207 @param output stores the output results (QWebPage.ExtensionReturn) |
|
208 @return flag indicating a successful call of the extension (boolean) |
|
209 """ |
|
210 try: |
|
211 if extension == QWebPage.ErrorPageExtension: |
|
212 info = sip.cast(option, QWebPage.ErrorPageExtensionOption) |
|
213 errorPage = sip.cast(output, QWebPage.ErrorPageExtensionReturn) |
|
214 urlString = bytes(info.url.toEncoded()).decode() |
|
215 html = notFoundPage_html |
|
216 title = self.trUtf8("Error loading page: {0}").format(urlString) |
|
217 pixmap = qApp.style()\ |
|
218 .standardIcon(QStyle.SP_MessageBoxWarning, None, self.parent())\ |
|
219 .pixmap(32, 32) |
|
220 imageBuffer = QBuffer() |
|
221 imageBuffer.open(QIODevice.ReadWrite) |
|
222 if pixmap.save(imageBuffer, "PNG"): |
|
223 html = html.replace("IMAGE_BINARY_DATA_HERE", |
|
224 bytes(imageBuffer.buffer().toBase64()).decode()) |
|
225 errorPage.content = QByteArray(html.format( |
|
226 title, |
|
227 info.errorString, |
|
228 self.trUtf8("When connecting to: {0}.").format(urlString), |
|
229 self.trUtf8("Check the address for errors such as " |
|
230 "<b>ww</b>.example.org instead of " |
|
231 "<b>www</b>.example.org"), |
|
232 self.trUtf8("If the address is correct, try checking the network " |
|
233 "connection."), |
|
234 self.trUtf8("If your computer or network is protected by a firewall " |
|
235 "or proxy, make sure that the browser is permitted to " |
|
236 "access the network.") |
|
237 ).encode("utf8")) |
|
238 return True |
|
239 except AttributeError: |
|
240 pass |
|
241 |
|
242 return QWebPage.extension(self, extension, option, output) |
184 |
243 |
185 ########################################################################################## |
244 ########################################################################################## |
186 |
245 |
187 class HelpBrowser(QWebView): |
246 class HelpBrowser(QWebView): |
188 """ |
247 """ |