--- a/src/eric7/WebBrowser/SiteInfo/SiteInfoWidget.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/WebBrowser/SiteInfo/SiteInfoWidget.py Wed Jul 13 14:55:47 2022 +0200 @@ -9,8 +9,14 @@ from PyQt6.QtCore import pyqtSlot, Qt, QPoint from PyQt6.QtWidgets import ( - QMenu, QGridLayout, QHBoxLayout, QLabel, QFrame, QSizePolicy, QPushButton, - QSpacerItem + QMenu, + QGridLayout, + QHBoxLayout, + QLabel, + QFrame, + QSizePolicy, + QPushButton, + QSpacerItem, ) import UI.PixmapCache @@ -22,85 +28,86 @@ """ Class implementing a widget to show site related infos. """ + def __init__(self, browser, parent=None): """ Constructor - + @param browser reference to the browser view @type WebBrowserView @param parent reference to the parent object @type QWidget """ super().__init__(parent) - + self.__browser = browser url = browser.url() - + self.setMinimumWidth(400) - + layout = QGridLayout(self) rows = 0 - + titleLabel = QLabel(self) titleLabel.setText(self.tr("<b>Site {0}</b>").format(url.host())) - layout.addWidget(titleLabel, rows, 0, 1, -1, - Qt.AlignmentFlag.AlignCenter) + layout.addWidget(titleLabel, rows, 0, 1, -1, Qt.AlignmentFlag.AlignCenter) rows += 1 - + line = QFrame(self) line.setLineWidth(1) line.setFrameStyle(QFrame.Shape.HLine | QFrame.Shadow.Sunken) layout.addWidget(line, rows, 0, 1, -1) rows += 1 - + secureIcon = QLabel() layout.addWidget(secureIcon, rows, 0, Qt.AlignmentFlag.AlignCenter) secureLabel = QLabel() - secureLabel.setSizePolicy(QSizePolicy.Policy.Expanding, - QSizePolicy.Policy.Preferred) + secureLabel.setSizePolicy( + QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred + ) layout.addWidget(secureLabel, rows, 1) if url.scheme() in ["https"]: if WebBrowserWindow.networkManager().isInsecureHost(url.host()): secureLabel.setText( - self.tr("Your connection to this site " - "<b>may not be secure</b>.")) - secureIcon.setPixmap( - UI.PixmapCache.getPixmap("securityMedium")) + self.tr("Your connection to this site " "<b>may not be secure</b>.") + ) + secureIcon.setPixmap(UI.PixmapCache.getPixmap("securityMedium")) else: secureLabel.setText( - self.tr("Your connection to this site is <b>secure</b>.")) - secureIcon.setPixmap( - UI.PixmapCache.getPixmap("securityHigh")) + self.tr("Your connection to this site is <b>secure</b>.") + ) + secureIcon.setPixmap(UI.PixmapCache.getPixmap("securityHigh")) else: secureLabel.setText( - self.tr("Your connection to this site is <b>not secure</b>.")) - secureIcon.setPixmap( - UI.PixmapCache.getPixmap("securityLow")) + self.tr("Your connection to this site is <b>not secure</b>.") + ) + secureIcon.setPixmap(UI.PixmapCache.getPixmap("securityLow")) rows += 1 - + visits = WebBrowserWindow.historyManager().siteVisitsCount( - url.scheme(), url.host()) + url.scheme(), url.host() + ) historyIcon = QLabel() layout.addWidget(historyIcon, rows, 0, Qt.AlignmentFlag.AlignCenter) historyLabel = QLabel() - historyLabel.setSizePolicy(QSizePolicy.Policy.Expanding, - QSizePolicy.Policy.Preferred) + historyLabel.setSizePolicy( + QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred + ) layout.addWidget(historyLabel, rows, 1) if visits > 3: historyLabel.setText( - self.tr("This is your <b>{0}.</b> visit of this site.") - .format(visits)) - historyIcon.setPixmap( - UI.PixmapCache.getPixmap("flagGreen")) + self.tr("This is your <b>{0}.</b> visit of this site.").format(visits) + ) + historyIcon.setPixmap(UI.PixmapCache.getPixmap("flagGreen")) elif visits == 0: historyLabel.setText( - self.tr("You have <b>never</b> visited this site before.") - .format(visits)) - historyIcon.setPixmap( - UI.PixmapCache.getPixmap("flagBlack")) + self.tr("You have <b>never</b> visited this site before.").format( + visits + ) + ) + historyIcon.setPixmap(UI.PixmapCache.getPixmap("flagBlack")) else: - historyIcon.setPixmap( - UI.PixmapCache.getPixmap("flagYellow")) + historyIcon.setPixmap(UI.PixmapCache.getPixmap("flagYellow")) if visits == 1: visitStr = self.tr("first") elif visits == 2: @@ -108,62 +115,59 @@ else: visitStr = self.tr("third") historyLabel.setText( - self.tr("This is your <b>{0}</b> visit of this site.") - .format(visitStr)) + self.tr("This is your <b>{0}</b> visit of this site.").format(visitStr) + ) rows += 1 - + line = QFrame(self) line.setLineWidth(1) line.setFrameStyle(QFrame.Shape.HLine | QFrame.Shadow.Sunken) layout.addWidget(line, rows, 0, 1, -1) rows += 1 - + page = self.__browser.page() scheme = page.registerProtocolHandlerRequestScheme() - registeredUrl = ( - WebBrowserWindow.protocolHandlerManager().protocolHandler(scheme) + registeredUrl = WebBrowserWindow.protocolHandlerManager().protocolHandler( + scheme ) - if ( - bool(scheme) and - registeredUrl != page.registerProtocolHandlerRequestUrl() - ): + if bool(scheme) and registeredUrl != page.registerProtocolHandlerRequestUrl(): horizontalLayout = QHBoxLayout() protocolHandlerLabel = QLabel( - self.tr("Register as <b>{0}</b> links handler.") - .format(scheme), self) - protocolHandlerLabel.setSizePolicy(QSizePolicy.Policy.Expanding, - QSizePolicy.Policy.Preferred) - + self.tr("Register as <b>{0}</b> links handler.").format(scheme), self + ) + protocolHandlerLabel.setSizePolicy( + QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred + ) + horizontalLayout.addWidget(protocolHandlerLabel) protocolHandlerButton = QPushButton(self.tr("Register"), self) horizontalLayout.addWidget(protocolHandlerButton) - protocolHandlerButton.clicked.connect( - self.__registerProtocolHandler) + protocolHandlerButton.clicked.connect(self.__registerProtocolHandler) layout.addLayout(horizontalLayout, rows, 0, 1, -1) rows += 1 - + protocolHandlerLine = QFrame(self) protocolHandlerLine.setLineWidth(1) - protocolHandlerLine.setFrameStyle( - QFrame.Shape.HLine | QFrame.Shadow.Sunken) + protocolHandlerLine.setFrameStyle(QFrame.Shape.HLine | QFrame.Shadow.Sunken) layout.addWidget(protocolHandlerLine, rows, 0, 1, -1) rows += 1 - + horizontalLayout = QHBoxLayout() spacerItem = QSpacerItem( - 40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum) + 40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum + ) horizontalLayout.addItem(spacerItem) moreButton = QPushButton(self.tr("More..."), self) horizontalLayout.addWidget(moreButton) moreButton.clicked.connect(self.__showSiteInfo) layout.addLayout(horizontalLayout, rows, 0, 1, -1) - + layout.activate() - + def showAt(self, pos): """ Public method to show the widget. - + @param pos position to show at @type QPoint """ @@ -174,23 +178,23 @@ p = QPoint(xpos, pos.y() + 10) self.move(p) self.show() - + def accept(self): """ Public method to accept the widget. """ self.close() - + @pyqtSlot() def __showSiteInfo(self): """ Private slot to show the site info dialog. """ from .SiteInfoDialog import SiteInfoDialog - siteinfoDialog = SiteInfoDialog( - self.__browser, self.__browser.mainWindow()) + + siteinfoDialog = SiteInfoDialog(self.__browser, self.__browser.mainWindow()) siteinfoDialog.show() - + @pyqtSlot() def __registerProtocolHandler(self): """ @@ -200,4 +204,5 @@ page = self.__browser.page() WebBrowserWindow.protocolHandlerManager().addProtocolHandler( page.registerProtocolHandlerRequestScheme(), - page.registerProtocolHandlerRequestUrl()) + page.registerProtocolHandlerRequestUrl(), + )