eric6/WebBrowser/WebBrowserView.py

branch
maintenance
changeset 8043
0acf98cd089a
parent 7939
0fc1df79965d
parent 7960
e8fc383322f7
child 8176
31965986ecd1
equal deleted inserted replaced
7991:866adc8c315b 8043:0acf98cd089a
36 from .Tools.WebBrowserTools import getHtmlPage, pixmapToDataUrl 36 from .Tools.WebBrowserTools import getHtmlPage, pixmapToDataUrl
37 37
38 import Preferences 38 import Preferences
39 import UI.PixmapCache 39 import UI.PixmapCache
40 import Utilities 40 import Utilities
41 from Globals import qVersionTuple
42 41
43 42
44 class WebBrowserView(QWebEngineView): 43 class WebBrowserView(QWebEngineView):
45 """ 44 """
46 Class implementing the web browser view widget. 45 Class implementing the web browser view widget.
135 134
136 self.__restoreData = None 135 self.__restoreData = None
137 136
138 if self.parentWidget() is not None: 137 if self.parentWidget() is not None:
139 self.parentWidget().installEventFilter(self) 138 self.parentWidget().installEventFilter(self)
140
141 if qVersionTuple() < (5, 11, 0):
142 lay = self.layout()
143 lay.currentChanged.connect(
144 lambda: QTimer.singleShot(0, self.__setRwhvqt))
145 self.__setRwhvqt()
146 139
147 self.grabGesture(Qt.PinchGesture) 140 self.grabGesture(Qt.PinchGesture)
148 141
149 def __createNewPage(self): 142 def __createNewPage(self):
150 """ 143 """
272 name = QUrl.fromLocalFile(name.toString()) 265 name = QUrl.fromLocalFile(name.toString())
273 266
274 if not QFileInfo(name.toLocalFile()).exists(): 267 if not QFileInfo(name.toLocalFile()).exists():
275 E5MessageBox.critical( 268 E5MessageBox.critical(
276 self, 269 self,
277 self.tr("eric6 Web Browser"), 270 self.tr("eric Web Browser"),
278 self.tr( 271 self.tr(
279 """<p>The file <b>{0}</b> does not exist.</p>""") 272 """<p>The file <b>{0}</b> does not exist.</p>""")
280 .format(name.toLocalFile())) 273 .format(name.toLocalFile()))
281 return 274 return
282 275
283 if name.toLocalFile().lower().endswith((".pdf", ".chm")): 276 if name.toLocalFile().lower().endswith((".pdf", ".chm")):
284 started = QDesktopServices.openUrl(name) 277 started = QDesktopServices.openUrl(name)
285 if not started: 278 if not started:
286 E5MessageBox.critical( 279 E5MessageBox.critical(
287 self, 280 self,
288 self.tr("eric6 Web Browser"), 281 self.tr("eric Web Browser"),
289 self.tr( 282 self.tr(
290 """<p>Could not start a viewer""" 283 """<p>Could not start a viewer"""
291 """ for file <b>{0}</b>.</p>""") 284 """ for file <b>{0}</b>.</p>""")
292 .format(name.path())) 285 .format(name.path()))
293 return 286 return
294 elif name.scheme() in ["mailto"]: 287 elif name.scheme() in ["mailto"]:
295 started = QDesktopServices.openUrl(name) 288 started = QDesktopServices.openUrl(name)
296 if not started: 289 if not started:
297 E5MessageBox.critical( 290 E5MessageBox.critical(
298 self, 291 self,
299 self.tr("eric6 Web Browser"), 292 self.tr("eric Web Browser"),
300 self.tr( 293 self.tr(
301 """<p>Could not start an application""" 294 """<p>Could not start an application"""
302 """ for URL <b>{0}</b>.</p>""") 295 """ for URL <b>{0}</b>.</p>""")
303 .format(name.toString())) 296 .format(name.toString()))
304 return 297 return
306 if name.toString().lower().endswith((".pdf", ".chm")): 299 if name.toString().lower().endswith((".pdf", ".chm")):
307 started = QDesktopServices.openUrl(name) 300 started = QDesktopServices.openUrl(name)
308 if not started: 301 if not started:
309 E5MessageBox.critical( 302 E5MessageBox.critical(
310 self, 303 self,
311 self.tr("eric6 Web Browser"), 304 self.tr("eric Web Browser"),
312 self.tr( 305 self.tr(
313 """<p>Could not start a viewer""" 306 """<p>Could not start a viewer"""
314 """ for file <b>{0}</b>.</p>""") 307 """ for file <b>{0}</b>.</p>""")
315 .format(name.path())) 308 .format(name.path()))
316 return 309 return
449 def setZoomValue(self, value, saveValue=True): 442 def setZoomValue(self, value, saveValue=True):
450 """ 443 """
451 Public method to set the zoom value. 444 Public method to set the zoom value.
452 445
453 @param value zoom value (integer) 446 @param value zoom value (integer)
454 @keyparam saveValue flag indicating to save the zoom value with the 447 @param saveValue flag indicating to save the zoom value with the
455 zoom manager 448 zoom manager
456 @type bool 449 @type bool
457 """ 450 """
458 if value != self.__currentZoom: 451 if value != self.__currentZoom:
459 self.setZoomFactor(value / 100.0) 452 self.setZoomFactor(value / 100.0)
581 574
582 if not hitTest.isContentEditable() and not hitTest.isContentSelected(): 575 if not hitTest.isContentEditable() and not hitTest.isContentSelected():
583 self.__menu.addSeparator() 576 self.__menu.addSeparator()
584 self.__menu.addAction(self.__mw.adBlockIcon().menuAction()) 577 self.__menu.addAction(self.__mw.adBlockIcon().menuAction())
585 578
586 if ( 579 self.__menu.addSeparator()
587 qVersionTuple() >= (5, 11, 0) or 580 self.__menu.addAction(
588 Preferences.getWebBrowser("WebInspectorEnabled") 581 UI.PixmapCache.getIcon("webInspector"),
589 ): 582 self.tr("Inspect Element..."), self.__webInspector)
590 self.__menu.addSeparator()
591 self.__menu.addAction(
592 UI.PixmapCache.getIcon("webInspector"),
593 self.tr("Inspect Element..."), self.__webInspector)
594 583
595 if not self.__menu.isEmpty(): 584 if not self.__menu.isEmpty():
596 pos = evt.globalPos() 585 pos = evt.globalPos()
597 self.__menu.popup(QPoint(pos.x(), pos.y() + 1)) 586 self.__menu.popup(QPoint(pos.x(), pos.y() + 1))
598 587
1569 ): 1558 ):
1570 self.parentWidget().installEventFilter(self) 1559 self.parentWidget().installEventFilter(self)
1571 1560
1572 # find the render widget receiving events for the web page 1561 # find the render widget receiving events for the web page
1573 if obj is self and evt.type() == QEvent.ChildAdded: 1562 if obj is self and evt.type() == QEvent.ChildAdded:
1574 if qVersionTuple() >= (5, 11, 0): 1563 QTimer.singleShot(0, self.__setRwhvqt)
1575 QTimer.singleShot(0, self.__setRwhvqt)
1576 1564
1577 # forward events to WebBrowserView 1565 # forward events to WebBrowserView
1578 if ( 1566 if (
1579 obj is self.__rwhvqt and 1567 obj is self.__rwhvqt and
1580 evt.type() in [QEvent.KeyPress, QEvent.KeyRelease, 1568 evt.type() in [QEvent.KeyPress, QEvent.KeyRelease,
2275 2263
2276 ########################################################################### 2264 ###########################################################################
2277 ## Methods below implement slots for Qt 5.11+ 2265 ## Methods below implement slots for Qt 5.11+
2278 ########################################################################### 2266 ###########################################################################
2279 2267
2280 if qVersionTuple() >= (5, 11, 0): 2268 @pyqtSlot("QWebEngineQuotaRequest")
2281 @pyqtSlot("QWebEngineQuotaRequest") 2269 def __quotaRequested(self, quotaRequest):
2282 def __quotaRequested(self, quotaRequest): 2270 """
2283 """ 2271 Private slot to handle quota requests of the web page.
2284 Private slot to handle quota requests of the web page. 2272
2273 @param quotaRequest reference to the quota request object
2274 @type QWebEngineQuotaRequest
2275 """
2276 acceptRequest = Preferences.getWebBrowser("AcceptQuotaRequest")
2277 # map yes/no/ask from (0, 1, 2)
2278 if acceptRequest == 0:
2279 # always yes
2280 ok = True
2281 elif acceptRequest == 1:
2282 # always no
2283 ok = False
2284 else:
2285 # ask user
2286 from .Download.DownloadUtilities import dataString
2287 sizeStr = dataString(quotaRequest.requestedSize())
2285 2288
2286 @param quotaRequest reference to the quota request object 2289 ok = E5MessageBox.yesNo(
2287 @type QWebEngineQuotaRequest 2290 self,
2288 """ 2291 self.tr("Quota Request"),
2289 acceptRequest = Preferences.getWebBrowser("AcceptQuotaRequest") 2292 self.tr("""<p> Allow the website at <b>{0}</b> to use"""
2290 # map yes/no/ask from (0, 1, 2) 2293 """ <b>{1}</b> of persistent storage?</p>""")
2291 if acceptRequest == 0: 2294 .format(quotaRequest.origin().host(), sizeStr)
2292 # always yes 2295 )
2293 ok = True 2296
2294 elif acceptRequest == 1: 2297 if ok:
2295 # always no 2298 quotaRequest.accept()
2296 ok = False 2299 else:
2297 else: 2300 quotaRequest.reject()
2298 # ask user
2299 from .Download.DownloadUtilities import dataString
2300 sizeStr = dataString(quotaRequest.requestedSize())
2301
2302 ok = E5MessageBox.yesNo(
2303 self,
2304 self.tr("Quota Request"),
2305 self.tr("""<p> Allow the website at <b>{0}</b> to use"""
2306 """ <b>{1}</b> of persistent storage?</p>""")
2307 .format(quotaRequest.origin().host(), sizeStr)
2308 )
2309
2310 if ok:
2311 quotaRequest.accept()
2312 else:
2313 quotaRequest.reject()
2314 2301
2315 ########################################################################### 2302 ###########################################################################
2316 ## Methods below implement slots for Qt 5.12+ 2303 ## Methods below implement slots for Qt 5.12+
2317 ########################################################################### 2304 ###########################################################################
2318 2305
2319 if qVersionTuple() >= (5, 12, 0): 2306 @pyqtSlot("QWebEngineClientCertificateSelection")
2320 @pyqtSlot("QWebEngineClientCertificateSelection") 2307 def __selectClientCertificate(self, clientCertificateSelection):
2321 def __selectClientCertificate(self, clientCertificateSelection): 2308 """
2322 """ 2309 Private slot to handle the client certificate selection request.
2323 Private slot to handle the client certificate selection request. 2310
2311 @param clientCertificateSelection list of client SSL certificates
2312 found in system's client certificate store
2313 @type QWebEngineClientCertificateSelection
2314 """
2315 certificates = clientCertificateSelection.certificates()
2316 if len(certificates) == 0:
2317 clientCertificateSelection.selectNone()
2318 elif len(certificates) == 1:
2319 clientCertificateSelection.select(certificates[0])
2320 else:
2321 certificate = None
2322 from E5Network.E5SslCertificateSelectionDialog import (
2323 E5SslCertificateSelectionDialog
2324 )
2325 dlg = E5SslCertificateSelectionDialog(certificates, self)
2326 if dlg.exec() == QDialog.Accepted:
2327 certificate = dlg.getSelectedCertificate()
2324 2328
2325 @param clientCertificateSelection list of client SSL certificates 2329 if certificate is None:
2326 found in system's client certificate store
2327 @type QWebEngineClientCertificateSelection
2328 """
2329 certificates = clientCertificateSelection.certificates()
2330 if len(certificates) == 0:
2331 clientCertificateSelection.selectNone() 2330 clientCertificateSelection.selectNone()
2332 elif len(certificates) == 1:
2333 clientCertificateSelection.select(certificates[0])
2334 else: 2331 else:
2335 certificate = None 2332 clientCertificateSelection.select(certificate)
2336 from E5Network.E5SslCertificateSelectionDialog import (
2337 E5SslCertificateSelectionDialog
2338 )
2339 dlg = E5SslCertificateSelectionDialog(certificates, self)
2340 if dlg.exec() == QDialog.Accepted:
2341 certificate = dlg.getSelectedCertificate()
2342
2343 if certificate is None:
2344 clientCertificateSelection.selectNone()
2345 else:
2346 clientCertificateSelection.select(certificate)

eric ide

mercurial