WebBrowser/WebBrowserView.py

changeset 5736
000ea446ff4b
parent 5721
b4d0cddecd64
child 5740
292538236234
equal deleted inserted replaced
5735:f606dbe20be6 5736:000ea446ff4b
15 pass 15 pass
16 16
17 import os 17 import os
18 18
19 from PyQt5.QtCore import pyqtSignal, QUrl, QFileInfo, Qt, QTimer, QEvent, \ 19 from PyQt5.QtCore import pyqtSignal, QUrl, QFileInfo, Qt, QTimer, QEvent, \
20 QPoint, QDateTime, qVersion, QStandardPaths 20 QPoint, QDateTime, QStandardPaths
21 from PyQt5.QtGui import QDesktopServices, QClipboard, QIcon, \ 21 from PyQt5.QtGui import QDesktopServices, QClipboard, QIcon, \
22 QContextMenuEvent, QPixmap 22 QContextMenuEvent, QPixmap
23 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication 23 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication
24 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, \ 24 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, \
25 QWebEngineDownloadItem 25 QWebEngineDownloadItem
36 from .Tools.WebBrowserTools import readAllFileContents, pixmapToDataUrl 36 from .Tools.WebBrowserTools import readAllFileContents, 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
41 42
42 43
43 class WebBrowserView(QWebEngineView): 44 class WebBrowserView(QWebEngineView):
44 """ 45 """
45 Class implementing the web browser view widget. 46 Class implementing the web browser view widget.
120 self.__mw.personalInformationManager().connectPage(self.page()) 121 self.__mw.personalInformationManager().connectPage(self.page())
121 122
122 self.__inspector = None 123 self.__inspector = None
123 WebInspector.registerView(self) 124 WebInspector.registerView(self)
124 125
125 if qVersion() >= "5.8.0": 126 if qVersionTuple() >= (5, 8, 0):
126 if self.parentWidget() is not None: 127 if self.parentWidget() is not None:
127 self.parentWidget().installEventFilter(self) 128 self.parentWidget().installEventFilter(self)
128 129
129 lay = self.layout() 130 lay = self.layout()
130 lay.currentChanged.connect( 131 lay.currentChanged.connect(
340 341
341 def unselect(self): 342 def unselect(self):
342 """ 343 """
343 Public slot to clear the current selection. 344 Public slot to clear the current selection.
344 """ 345 """
345 if qVersion() >= "5.7.0": 346 if qVersionTuple() >= (5, 7, 0):
346 self.triggerPageAction(QWebEnginePage.Unselect) 347 self.triggerPageAction(QWebEnginePage.Unselect)
347 else: 348 else:
348 self.page().runJavaScript( 349 self.page().runJavaScript(
349 "window.getSelection().empty()", 350 "window.getSelection().empty()",
350 WebBrowserPage.SafeJsWorld) 351 WebBrowserPage.SafeJsWorld)
523 @type QMenu 524 @type QMenu
524 @param hitTest reference to the hit test object 525 @param hitTest reference to the hit test object
525 @type WebHitTestResult 526 @type WebHitTestResult
526 """ 527 """
527 spellCheckActionCount = 0 528 spellCheckActionCount = 0
528 if qVersion() >= "5.7.0": 529 if qVersionTuple() >= (5, 7, 0):
529 contextMenuData = self.page().contextMenuData() 530 contextMenuData = self.page().contextMenuData()
530 hitTest.updateWithContextMenuData(contextMenuData) 531 hitTest.updateWithContextMenuData(contextMenuData)
531 532
532 if qVersion() >= "5.8.0" and \ 533 if qVersionTuple() >= (5, 8, 0) and \
533 bool(contextMenuData.misspelledWord()): 534 bool(contextMenuData.misspelledWord()):
534 boldFont = menu.font() 535 boldFont = menu.font()
535 boldFont.setBold(True) 536 boldFont.setBold(True)
536 537
537 for suggestion in contextMenuData.spellCheckerSuggestions(): 538 for suggestion in contextMenuData.spellCheckerSuggestions():
1389 @type QEvent 1390 @type QEvent
1390 @return flag indicating that the event should be filtered out 1391 @return flag indicating that the event should be filtered out
1391 @rtype bool 1392 @rtype bool
1392 """ 1393 """
1393 # find the render widget receiving events for the web page 1394 # find the render widget receiving events for the web page
1394 if qVersion() < "5.8.0": 1395 if qVersionTuple() < (5, 8, 0):
1395 if obj is self and evt.type() == QEvent.ChildAdded: 1396 if obj is self and evt.type() == QEvent.ChildAdded:
1396 child = evt.child() 1397 child = evt.child()
1397 if child and child.inherits( 1398 if child and child.inherits(
1398 "QtWebEngineCore::" 1399 "QtWebEngineCore::"
1399 "RenderWidgetHostViewQtDelegateWidget"): 1400 "RenderWidgetHostViewQtDelegateWidget"):
1702 """ 1703 """
1703 url = self.url() 1704 url = self.url()
1704 if url.isEmpty(): 1705 if url.isEmpty():
1705 return 1706 return
1706 1707
1707 if qVersion() >= "5.8.0": 1708 if qVersionTuple() >= (5, 8, 0):
1708 # since Qt 5.8.0 1709 # since Qt 5.8.0
1709 fileName, savePageFormat = self.__getSavePageFileNameAndFormat() 1710 fileName, savePageFormat = self.__getSavePageFileNameAndFormat()
1710 if fileName: 1711 if fileName:
1711 self.page().save(fileName, savePageFormat) 1712 self.page().save(fileName, savePageFormat)
1712 else: 1713 else:

eric ide

mercurial