Sun, 26 Dec 2021 17:40:29 +0100
Added some style sheet and color related TODO markers.
--- a/eric7/EricWidgets/EricTextEditSearchWidget.py Sun Dec 26 17:40:02 2021 +0100 +++ b/eric7/EricWidgets/EricTextEditSearchWidget.py Sun Dec 26 17:40:29 2021 +0100 @@ -58,6 +58,8 @@ self.__texteditType = EricTextEditType.UNKNOWN self.__findBackwards = False + # TODO: change to use style sheets + # get style sheet or create one from palette self.__defaultBaseColor = ( self.findtextCombo.lineEdit().palette().color( QPalette.ColorRole.Base) @@ -460,6 +462,7 @@ """ le = self.findtextCombo.lineEdit() p = le.palette() + # TODO: change to use style sheets if error: p.setBrush(QPalette.ColorRole.Base, QBrush(QColor("#FF6666"))) p.setBrush(QPalette.ColorRole.Text, QBrush(QColor("#000000")))
--- a/eric7/HexEdit/HexEditWidget.py Sun Dec 26 17:40:02 2021 +0100 +++ b/eric7/HexEdit/HexEditWidget.py Sun Dec 26 17:40:29 2021 +0100 @@ -133,6 +133,7 @@ else: self.setFont(QFont(["Monospace"], 10)) + # TODO: make some colors custimizable self.setAddressAreaColors( self.palette().color(QPalette.ColorRole.WindowText), self.palette().alternateBase().color())
--- a/eric7/IconEditor/IconEditorGrid.py Sun Dec 26 17:40:02 2021 +0100 +++ b/eric7/IconEditor/IconEditorGrid.py Sun Dec 26 17:40:29 2021 +0100 @@ -429,6 +429,7 @@ painter = QPainter(self) if self.__zoom >= 3 and self.__gridEnabled: + # TODO: adjust colors painter.setPen(self.palette().windowText().color()) i = 0 while i <= self.__image.width():
--- a/eric7/Preferences/ConfigurationPages/IconsPreviewDialog.py Sun Dec 26 17:40:02 2021 +0100 +++ b/eric7/Preferences/ConfigurationPages/IconsPreviewDialog.py Sun Dec 26 17:40:29 2021 +0100 @@ -68,6 +68,7 @@ """ self.__inverted = checked + # TODO: change to use style sheets palette = self.iconView.palette() if self.__inverted: palette.setBrush(QPalette.ColorRole.Base, self.__textBrush)
--- a/eric7/WebBrowser/SearchWidget.py Sun Dec 26 17:40:02 2021 +0100 +++ b/eric7/WebBrowser/SearchWidget.py Sun Dec 26 17:40:29 2021 +0100 @@ -36,6 +36,9 @@ self.findPrevButton.setIcon(UI.PixmapCache.getIcon("1leftarrow")) self.findNextButton.setIcon(UI.PixmapCache.getIcon("1rightarrow")) + # TODO: change to use style sheets + # get style sheet or create one from palette + # see EricTextEditSearchWidget self.__defaultBaseColor = ( self.findtextCombo.lineEdit().palette().color( QPalette.ColorRole.Base)
--- a/eric7/WebBrowser/UrlBar/UrlBar.py Sun Dec 26 17:40:02 2021 +0100 +++ b/eric7/WebBrowser/UrlBar/UrlBar.py Sun Dec 26 17:40:29 2021 +0100 @@ -7,8 +7,8 @@ Module implementing the URL bar widget. """ -from PyQt6.QtCore import pyqtSlot, Qt, QPointF, QUrl, QDateTime, QTimer, QPoint -from PyQt6.QtGui import QColor, QPalette, QLinearGradient, QIcon +from PyQt6.QtCore import pyqtSlot, Qt, QUrl, QDateTime, QTimer, QPoint +from PyQt6.QtGui import QColor, QPalette, QIcon from PyQt6.QtWidgets import QDialog, QApplication, QLineEdit from PyQt6.QtWebEngineCore import QWebEnginePage try: @@ -38,8 +38,10 @@ """ Constructor - @param mainWindow reference to the main window (WebBrowserWindow) - @param parent reference to the parent widget (WebBrowserView) + @param mainWindow reference to the main window + @type WebBrowserWindow + @param parent reference to the parent widget + @type WebBrowserView """ super().__init__(parent) self.setPlaceholderText(self.tr("Enter the URL here.")) @@ -91,13 +93,14 @@ """ Public method to set the browser connection. - @param browser reference to the browser widget (WebBrowserView) + @param browser reference to the browser widget + @type WebBrowserView """ self.__browser = browser self.__favicon.setBrowser(browser) self.__browser.urlChanged.connect(self.__browserUrlChanged) - self.__browser.loadProgress.connect(self.update) + self.__browser.loadProgress.connect(self.__loadProgress) self.__browser.loadFinished.connect(self.__loadFinished) self.__browser.loadStarted.connect(self.__loadStarted) @@ -112,15 +115,18 @@ """ Public method to get the associated browser. - @return reference to the associated browser (HelpBrowser) + @return reference to the associated browser + @rtype WebBrowserView """ return self.__browser + @pyqtSlot(QUrl) def __browserUrlChanged(self, url): """ Private slot to handle a URL change of the associated browser. - @param url new URL of the browser (QUrl) + @param url new URL of the browser + @type QUrl """ strUrl = url.toString() if strUrl in ["eric:speeddial", "eric:home", @@ -131,14 +137,7 @@ self.setText(strUrl) self.setCursorPosition(0) - def __loadStarted(self): - """ - Private slot to perform actions before the page is loaded. - """ - self.__bookmarkAction.setVisible(False) - self.__rssAction.setVisible(False) - self.__sslLabel.setVisible(False) - + @pyqtSlot() def __checkBookmark(self): """ Private slot to check the current URL for the bookmarked state. @@ -156,11 +155,85 @@ else: self.__bookmarkAction.setIcon(self.__bmInactiveIcon) + @pyqtSlot() + def __loadStarted(self): + """ + Private slot to perform actions before the page is loaded. + """ + self.__bookmarkAction.setVisible(False) + self.__rssAction.setVisible(False) + self.__sslLabel.setVisible(False) + + @pyqtSlot(int) + def __loadProgress(self, progress): + """ + Private slot to track the load progress. + + @param progress load progress in percent + @type int + """ + foregroundColor = QApplication.palette().color(QPalette.ColorRole.Text) + + backgroundColor = ( + Preferences.getWebBrowser("PrivateModeUrlColor") + if self.__privateMode else + QApplication.palette().color(QPalette.ColorRole.Base) + ) + + if not self.__browser.getSafeBrowsingStatus(): + # malicious web site + backgroundColor = Preferences.getWebBrowser( + "MaliciousUrlColor") + elif self.__browser.url().scheme() == "https": + if WebBrowserWindow.networkManager().isInsecureHost( + self.__browser.url().host() + ): + backgroundColor = Preferences.getWebBrowser( + "InsecureUrlColor") + else: + backgroundColor = Preferences.getWebBrowser( + "SecureUrlColor") + + if progress in (0, 100): + styleSheet = ( + f"color: {foregroundColor.name()}; " + f"background-color: {backgroundColor.name()};" + ) + else: + highlight = QApplication.palette().color( + QPalette.ColorRole.Highlight) + r = (highlight.red() + 2 * backgroundColor.red()) // 3 + g = (highlight.green() + 2 * backgroundColor.green()) // 3 + b = (highlight.blue() + 2 * backgroundColor.blue()) // 3 + + loadingColor = QColor(r, g, b) + if abs(loadingColor.lightness() - + backgroundColor.lightness()) < 20: + r = (2 * highlight.red() + backgroundColor.red()) // 3 + g = (2 * highlight.green() + backgroundColor.green()) // 3 + b = (2 * highlight.blue() + backgroundColor.blue()) // 3 + loadingColor = QColor(r, g, b) + + styleSheet = ( + f"color: {foregroundColor.name()}; " + f"background-color: qlineargradient(" + f"spread: pad, x1: 0, y1: 0, x2: 1, y2: 0, " + f"stop: 0 {loadingColor.name()}, " + f"stop: {progress / 100.0 - 0.001} {loadingColor.name()}, " + f"stop: {progress / 100.0 + 0.001} {backgroundColor.name()}, " + f"stop: 1 {backgroundColor.name()});" + ) + + self.setStyleSheet(styleSheet) + self.repaint() + + @pyqtSlot(bool) def __loadFinished(self, ok): """ Private slot to set some data after the page was loaded. - @param ok flag indicating a successful load (boolean) + @param ok flag indicating a successful load + @type bool """ if self.__browser.url().scheme() in ["eric", "about"]: self.__bookmarkAction.setVisible(False) @@ -175,6 +248,7 @@ if ok: QTimer.singleShot(0, self.__setRssButton) + @pyqtSlot() def preferencesChanged(self): """ Public slot to handle a change of preferences. @@ -215,73 +289,12 @@ """ self.__checkBookmark() - def paintEvent(self, evt): - """ - Protected method handling a paint event. - - @param evt reference to the paint event (QPaintEvent) - """ - foregroundColor = QApplication.palette().color(QPalette.ColorRole.Text) - - backgroundColor = ( - Preferences.getWebBrowser("PrivateModeUrlColor") - if self.__privateMode else - QApplication.palette().color(QPalette.ColorRole.Base) - ) - - if self.__browser is not None: - p = self.palette() - progress = self.__browser.progress() - - if not self.__browser.getSafeBrowsingStatus(): - # malicious web site - backgroundColor = Preferences.getWebBrowser( - "MaliciousUrlColor") - elif self.__browser.url().scheme() == "https": - if WebBrowserWindow.networkManager().isInsecureHost( - self.__browser.url().host() - ): - backgroundColor = Preferences.getWebBrowser( - "InsecureUrlColor") - else: - backgroundColor = Preferences.getWebBrowser( - "SecureUrlColor") - - if progress in (0, 100): - p.setBrush(QPalette.ColorRole.Base, backgroundColor) - p.setBrush(QPalette.ColorRole.Text, foregroundColor) - else: - highlight = QApplication.palette().color( - QPalette.ColorRole.Highlight) - r = (highlight.red() + 2 * backgroundColor.red()) // 3 - g = (highlight.green() + 2 * backgroundColor.green()) // 3 - b = (highlight.blue() + 2 * backgroundColor.blue()) // 3 - - loadingColor = QColor(r, g, b) - if abs(loadingColor.lightness() - - backgroundColor.lightness()) < 20: - # special handling for special color schemes (e.g Gaia) - r = (2 * highlight.red() + backgroundColor.red()) // 3 - g = (2 * highlight.green() + backgroundColor.green()) // 3 - b = (2 * highlight.blue() + backgroundColor.blue()) // 3 - loadingColor = QColor(r, g, b) - - gradient = QLinearGradient( - QPointF(0, 0), QPointF(self.width(), 0)) - gradient.setColorAt(0, loadingColor) - gradient.setColorAt(progress / 100.0 - 0.000001, loadingColor) - gradient.setColorAt(progress / 100.0, backgroundColor) - p.setBrush(QPalette.ColorRole.Base, gradient) - - self.setPalette(p) - - super().paintEvent(evt) - def focusOutEvent(self, evt): """ Protected method to handle focus out event. - @param evt reference to the focus event (QFocusEvent) + @param evt reference to the focus event + @type QFocusEvent """ if self.text() == "" and self.__browser is not None: self.__browserUrlChanged(self.__browser.url()) @@ -291,7 +304,8 @@ """ Protected method called by a mouse press event. - @param evt reference to the mouse event (QMouseEvent) + @param evt reference to the mouse event + @type QMouseEvent """ if evt.button() == Qt.MouseButton.XButton1: self.__mw.currentBrowser().triggerPageAction( @@ -306,7 +320,8 @@ """ Protected method to handle mouse double click events. - @param evt reference to the mouse event (QMouseEvent) + @param evt reference to the mouse event + @type QMouseEvent """ if evt.button() == Qt.MouseButton.LeftButton: self.selectAll() @@ -317,7 +332,8 @@ """ Protected method to handle key presses. - @param evt reference to the key press event (QKeyEvent) + @param evt reference to the key press event + @type QKeyEvent """ if evt.key() == Qt.Key.Key_Escape: if self.__browser is not None: @@ -361,7 +377,8 @@ """ Protected method to handle drag enter events. - @param evt reference to the drag enter event (QDragEnterEvent) + @param evt reference to the drag enter event + @type QDragEnterEvent """ mimeData = evt.mimeData() if mimeData.hasUrls() or mimeData.hasText(): @@ -373,7 +390,8 @@ """ Protected method to handle drop events. - @param evt reference to the drop event (QDropEvent) + @param evt reference to the drop event + @type QDropEvent """ mimeData = evt.mimeData() @@ -393,6 +411,7 @@ evt.acceptProposedAction() + @pyqtSlot() def __setRssButton(self): """ Private slot to show the RSS button.