WebBrowser/WebBrowserView.py

branch
maintenance
changeset 5948
6f958d5765f4
parent 5885
5228afbb870f
child 5949
22657f04f332
equal deleted inserted replaced
5937:cc296ba99a3f 5948:6f958d5765f4
14 except NameError: 14 except NameError:
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, PYQT_VERSION, Qt, QUrl, QFileInfo, \
20 QPoint, QPointF, QDateTime, QStandardPaths, QByteArray, QIODevice, \ 20 QTimer, QEvent, QPoint, QPointF, QDateTime, QStandardPaths, QByteArray, \
21 QDataStream 21 QIODevice, QDataStream
22 from PyQt5.QtGui import QDesktopServices, QClipboard, QIcon, \ 22 from PyQt5.QtGui import QDesktopServices, QClipboard, QIcon, \
23 QContextMenuEvent, QPixmap 23 QContextMenuEvent, QPixmap
24 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication 24 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication
25 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, \ 25 from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, \
26 QWebEngineDownloadItem 26 QWebEngineDownloadItem
360 360
361 def unselect(self): 361 def unselect(self):
362 """ 362 """
363 Public slot to clear the current selection. 363 Public slot to clear the current selection.
364 """ 364 """
365 if qVersionTuple() >= (5, 7, 0): 365 try:
366 self.triggerPageAction(QWebEnginePage.Unselect) 366 self.triggerPageAction(QWebEnginePage.Unselect)
367 else: 367 except AttributeError:
368 # prior to 5.7.0
368 self.page().runJavaScript( 369 self.page().runJavaScript(
369 "window.getSelection().empty()", 370 "window.getSelection().empty()",
370 WebBrowserPage.SafeJsWorld) 371 WebBrowserPage.SafeJsWorld)
371 372
372 def isForwardAvailable(self): 373 def isForwardAvailable(self):
543 @type QMenu 544 @type QMenu
544 @param hitTest reference to the hit test object 545 @param hitTest reference to the hit test object
545 @type WebHitTestResult 546 @type WebHitTestResult
546 """ 547 """
547 spellCheckActionCount = 0 548 spellCheckActionCount = 0
548 if qVersionTuple() >= (5, 7, 0): 549 if qVersionTuple() >= (5, 7, 0) and PYQT_VERSION >= 0x50700:
549 contextMenuData = self.page().contextMenuData() 550 contextMenuData = self.page().contextMenuData()
550 hitTest.updateWithContextMenuData(contextMenuData) 551 hitTest.updateWithContextMenuData(contextMenuData)
551 552
552 if qVersionTuple() >= (5, 8, 0) and \ 553 if qVersionTuple() >= (5, 8, 0) and PYQT_VERSION >= 0x50800 and \
553 bool(contextMenuData.misspelledWord()): 554 bool(contextMenuData.misspelledWord()):
554 boldFont = menu.font() 555 boldFont = menu.font()
555 boldFont.setBold(True) 556 boldFont.setBold(True)
556 557
557 for suggestion in contextMenuData.spellCheckerSuggestions(): 558 for suggestion in contextMenuData.spellCheckerSuggestions():
799 WebBrowserLanguagesDialog.defaultAcceptLanguages())) 800 WebBrowserLanguagesDialog.defaultAcceptLanguages()))
800 if languages: 801 if languages:
801 language = languages[0] 802 language = languages[0]
802 langCode = language.split("[")[1][:2] 803 langCode = language.split("[")[1][:2]
803 googleTranslatorUrl = QUrl( 804 googleTranslatorUrl = QUrl(
804 "http://translate.google.com/#auto|{0}|{1}".format( 805 "http://translate.google.com/#auto/{0}/{1}".format(
805 langCode, self.selectedText())) 806 langCode, self.selectedText()))
806 menu.addAction( 807 menu.addAction(
807 UI.PixmapCache.getIcon("translate.png"), 808 UI.PixmapCache.getIcon("translate.png"),
808 self.tr("Google Translate"), self.__openLinkInNewTab)\ 809 self.tr("Google Translate"), self.__openLinkInNewTab)\
809 .setData(googleTranslatorUrl) 810 .setData(googleTranslatorUrl)
1721 """ 1722 """
1722 url = self.url() 1723 url = self.url()
1723 if url.isEmpty(): 1724 if url.isEmpty():
1724 return 1725 return
1725 1726
1726 if qVersionTuple() >= (5, 8, 0): 1727 if qVersionTuple() >= (5, 8, 0) and PYQT_VERSION >= 0x50800:
1727 # since Qt 5.8.0 1728 # since Qt 5.8.0
1728 fileName, savePageFormat = self.__getSavePageFileNameAndFormat() 1729 fileName, savePageFormat = self.__getSavePageFileNameAndFormat()
1729 if fileName: 1730 if fileName:
1730 self.page().save(fileName, savePageFormat) 1731 self.page().save(fileName, savePageFormat)
1731 else: 1732 else:

eric ide

mercurial