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) |