diff -r 41d09cf20415 -r 2cac5b7abcce eric6/WebBrowser/WebBrowserView.py --- a/eric6/WebBrowser/WebBrowserView.py Wed Sep 25 19:00:09 2019 +0200 +++ b/eric6/WebBrowser/WebBrowserView.py Wed Sep 25 19:11:13 2019 +0200 @@ -11,14 +11,17 @@ import os -from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QFileInfo, QTimer, \ - QEvent, QPoint, QPointF, QDateTime, QStandardPaths, QByteArray, \ - QIODevice, QDataStream -from PyQt5.QtGui import QDesktopServices, QClipboard, QIcon, \ - QContextMenuEvent, QPixmap, QCursor +from PyQt5.QtCore import ( + pyqtSignal, pyqtSlot, Qt, QUrl, QFileInfo, QTimer, QEvent, QPoint, + QPointF, QDateTime, QStandardPaths, QByteArray, QIODevice, QDataStream +) +from PyQt5.QtGui import ( + QDesktopServices, QClipboard, QIcon, QContextMenuEvent, QPixmap, QCursor +) from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication, QDialog -from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, \ - QWebEngineDownloadItem +from PyQt5.QtWebEngineWidgets import ( + QWebEngineView, QWebEnginePage, QWebEngineDownloadItem +) from E5Gui import E5MessageBox, E5FileDialog @@ -208,9 +211,11 @@ @param url URL to be loaded @type QUrl """ - if self.__page is not None and \ + if ( + self.__page is not None and not self.__page.acceptNavigationRequest( - url, QWebEnginePage.NavigationTypeTyped, True): + url, QWebEnginePage.NavigationTypeTyped, True) + ): return super(WebBrowserView, self).load(url) @@ -244,8 +249,10 @@ else: name.setUrl("file://" + name.toString()) - if len(name.scheme()) == 1 or \ - name.scheme() == "file": + if ( + len(name.scheme()) == 1 or + name.scheme() == "file" + ): # name is a local file if name.scheme() and len(name.scheme()) == 1: # it is a local path on win os @@ -551,8 +558,10 @@ self.__menu.addSeparator() self.__menu.addAction(self.__mw.adBlockIcon().menuAction()) - if qVersionTuple() >= (5, 11, 0) or \ - Preferences.getWebBrowser("WebInspectorEnabled"): + if ( + qVersionTuple() >= (5, 11, 0) or + Preferences.getWebBrowser("WebInspectorEnabled") + ): self.__menu.addSeparator() self.__menu.addAction( UI.PixmapCache.getIcon("webInspector.png"), @@ -591,8 +600,10 @@ menu.addSeparator() spellCheckActionCount = len(menu.actions()) - if not hitTest.linkUrl().isEmpty() and \ - hitTest.linkUrl().scheme() != "javascript": + if ( + not hitTest.linkUrl().isEmpty() and + hitTest.linkUrl().scheme() != "javascript" + ): self.__createLinkContextMenu(menu, hitTest) if not hitTest.imageUrl().isEmpty(): @@ -679,8 +690,10 @@ act.setData(hitTest.linkUrl()) act.triggered.connect( lambda: self.__sendLink(act)) - if Preferences.getWebBrowser("VirusTotalEnabled") and \ - Preferences.getWebBrowser("VirusTotalServiceKey") != "": + if ( + Preferences.getWebBrowser("VirusTotalEnabled") and + Preferences.getWebBrowser("VirusTotalServiceKey") != "" + ): act = menu.addAction( UI.PixmapCache.getIcon("virustotal.png"), self.tr("Scan Link with VirusTotal")) @@ -755,8 +768,10 @@ act.setData(hitTest.imageUrl().toString()) act.triggered.connect( lambda: self.__blockImage(act)) - if Preferences.getWebBrowser("VirusTotalEnabled") and \ - Preferences.getWebBrowser("VirusTotalServiceKey") != "": + if ( + Preferences.getWebBrowser("VirusTotalEnabled") and + Preferences.getWebBrowser("VirusTotalServiceKey") != "" + ): act = menu.addAction( UI.PixmapCache.getIcon("virustotal.png"), self.tr("Scan Image with VirusTotal")) @@ -835,8 +850,9 @@ menu.addAction(self.tr("Search with '{0}'").format(engineName), self.__searchDefaultRequested) - from .OpenSearch.OpenSearchEngineAction import \ + from .OpenSearch.OpenSearchEngineAction import ( OpenSearchEngineAction + ) self.__searchMenu = menu.addMenu(self.tr("Search with...")) engineNames = self.__mw.openSearchManager().allEnginesNames() @@ -1037,10 +1053,12 @@ @param url URL to be checked (QUrl) @return flag indicating a valid URL (boolean) """ - return url.isValid() and \ - bool(url.host()) and \ - bool(url.scheme()) and \ + return ( + url.isValid() and + bool(url.host()) and + bool(url.scheme()) and "." in url.host() + ) def __replaceMisspelledWord(self, act): """ @@ -1339,9 +1357,11 @@ @param evt reference to the drop event (QDropEvent) """ super(WebBrowserView, self).dropEvent(evt) - if not evt.isAccepted() and \ - evt.source() != self and \ - evt.possibleActions() & Qt.CopyAction: + if ( + not evt.isAccepted() and + evt.source() != self and + evt.possibleActions() & Qt.CopyAction + ): url = QUrl() if len(evt.mimeData().urls()) > 0: url = evt.mimeData().urls()[0] @@ -1383,12 +1403,16 @@ accepted = evt.isAccepted() self.__page.event(evt) - if not evt.isAccepted() and \ - self.__mw.eventMouseButtons() & Qt.MidButton: + if ( + not evt.isAccepted() and + self.__mw.eventMouseButtons() & Qt.MidButton + ): url = QUrl(QApplication.clipboard().text(QClipboard.Selection)) - if not url.isEmpty() and \ - url.isValid() and \ - url.scheme() != "": + if ( + not url.isEmpty() and + url.isValid() and + url.scheme() != "" + ): self.__mw.setEventMouseButtons(Qt.NoButton) self.__mw.setEventKeyboardModifiers(Qt.NoModifier) self.setSource(url) @@ -1513,8 +1537,11 @@ @return flag indicating that the event should be filtered out @rtype bool """ - if obj is self and evt.type() == QEvent.ParentChange and \ - self.parentWidget() is not None: + if ( + obj is self and + evt.type() == QEvent.ParentChange and + self.parentWidget() is not None + ): self.parentWidget().installEventFilter(self) # find the render widget receiving events for the web page @@ -1523,10 +1550,12 @@ QTimer.singleShot(0, self.__setRwhvqt) # forward events to WebBrowserView - if obj is self.__rwhvqt and \ - evt.type() in [QEvent.KeyPress, QEvent.KeyRelease, - QEvent.MouseButtonPress, QEvent.MouseButtonRelease, - QEvent.MouseMove, QEvent.Wheel, QEvent.Gesture]: + if ( + obj is self.__rwhvqt and + evt.type() in [QEvent.KeyPress, QEvent.KeyRelease, + QEvent.MouseButtonPress, QEvent.MouseButtonRelease, + QEvent.MouseMove, QEvent.Wheel, QEvent.Gesture] + ): wasAccepted = evt.isAccepted() evt.setAccepted(False) if evt.type() == QEvent.KeyPress: @@ -1547,8 +1576,10 @@ evt.setAccepted(wasAccepted) return ret - if obj is self.parentWidget() and \ - evt.type() in [QEvent.KeyPress, QEvent.KeyRelease]: + if ( + obj is self.parentWidget() and + evt.type() in [QEvent.KeyPress, QEvent.KeyRelease] + ): wasAccepted = evt.isAccepted() evt.setAccepted(False) if evt.type() == QEvent.KeyPress: @@ -2269,8 +2300,9 @@ clientCertificateSelection.select(certificates[0]) else: certificate = None - from E5Network.E5SslCertificateSelectionDialog import \ + from E5Network.E5SslCertificateSelectionDialog import ( E5SslCertificateSelectionDialog + ) dlg = E5SslCertificateSelectionDialog(certificates, self) if dlg.exec_() == QDialog.Accepted: certificate = dlg.getSelectedCertificate()