--- a/eric6/Preferences/ConfigurationPages/NotificationsPage.py Tue Jan 05 15:14:40 2021 +0100 +++ b/eric6/Preferences/ConfigurationPages/NotificationsPage.py Tue Jan 05 18:28:31 2021 +0100 @@ -8,13 +8,15 @@ """ from PyQt5.QtCore import pyqtSlot, QPoint -from PyQt5.QtWidgets import QApplication +from PyQt5.QtGui import QColor +from PyQt5.QtWidgets import QApplication, QColorDialog from .ConfigurationPageBase import ConfigurationPageBase from .Ui_NotificationsPage import Ui_NotificationsPage import Preferences -import UI.PixmapCache + +from UI.NotificationWidget import NotificationFrame, NotificationTypes class NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage): @@ -35,6 +37,11 @@ self.ySpinBox.setMinimum(geom.y()) self.ySpinBox.setMaximum(geom.height()) + self.warningIcon.setPixmap( + NotificationFrame.getIcon(NotificationTypes.Warning)) + self.criticalIcon.setPixmap( + NotificationFrame.getIcon(NotificationTypes.Critical)) + self.__notification = None self.__firstTime = True @@ -46,6 +53,29 @@ self.xSpinBox.valueChanged.connect(self.__moveNotification) self.ySpinBox.valueChanged.connect(self.__moveNotification) + + self.__colors = {} + self.__colors["NotificationWarningForeground"] = Preferences.getUI( + "NotificationWarningForeground") + self.__colors["NotificationWarningBackground"] = Preferences.getUI( + "NotificationWarningBackground") + self.__colors["NotificationCriticalForeground"] = Preferences.getUI( + "NotificationCriticalForeground") + self.__colors["NotificationCriticalBackground"] = Preferences.getUI( + "NotificationCriticalBackground") + + self.warningFrame.setStyleSheet( + NotificationFrame.NotificationStyleSheetTemplate.format( + self.__colors["NotificationWarningForeground"], + self.__colors["NotificationWarningBackground"] + ) + ) + self.criticalFrame.setStyleSheet( + NotificationFrame.NotificationStyleSheetTemplate.format( + self.__colors["NotificationCriticalForeground"], + self.__colors["NotificationCriticalBackground"] + ) + ) def save(self): """ @@ -54,6 +84,9 @@ Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value()) Preferences.setUI("NotificationPosition", QPoint( self.xSpinBox.value(), self.ySpinBox.value())) + + for key in self.__colors.keys(): + Preferences.setUI(key, self.__colors[key]) @pyqtSlot(bool) def on_visualButton_clicked(self, checked): @@ -67,7 +100,7 @@ self.__notification = NotificationWidget( parent=self, setPosition=True) self.__notification.showNotification( - UI.PixmapCache.getPixmap("notification48"), + NotificationFrame.getIcon(NotificationTypes.Other), self.tr("Visual Selection"), self.tr("Drag the notification window to" " the desired place and release the button."), @@ -100,6 +133,146 @@ self.xSpinBox.value(), self.ySpinBox.value() ) + + ################################################################## + ## colors for warning notifications + ################################################################## + + @pyqtSlot() + def on_warningFgButton_clicked(self): + """ + Private slot to set the foreground color of the warning notifications. + """ + color = QColorDialog.getColor( + QColor(self.__colors["NotificationWarningForeground"])) + if color.isValid(): + self.__colors["NotificationWarningForeground"] = color.name() + self.warningFrame.setStyleSheet( + NotificationFrame.NotificationStyleSheetTemplate.format( + self.__colors["NotificationWarningForeground"], + self.__colors["NotificationWarningBackground"] + ) + ) + + @pyqtSlot() + def on_warningBgButton_clicked(self): + """ + Private slot to set the background color of the warning notifications. + """ + color = QColorDialog.getColor( + QColor(self.__colors["NotificationWarningBackground"])) + if color.isValid(): + self.__colors["NotificationWarningBackground"] = color.name() + self.warningFrame.setStyleSheet( + NotificationFrame.NotificationStyleSheetTemplate.format( + self.__colors["NotificationWarningForeground"], + self.__colors["NotificationWarningBackground"] + ) + ) + + @pyqtSlot() + def on_warningResetButton_clicked(self): + """ + Private slot to reset the colors for warning notifications to their + current values. + """ + self.__colors["NotificationWarningForeground"] = Preferences.getUI( + "NotificationWarningForeground") + self.__colors["NotificationWarningBackground"] = Preferences.getUI( + "NotificationWarningBackground") + self.warningFrame.setStyleSheet( + NotificationFrame.NotificationStyleSheetTemplate.format( + self.__colors["NotificationWarningForeground"], + self.__colors["NotificationWarningBackground"] + ) + ) + + @pyqtSlot() + def on_warningDefaultButton_clicked(self): + """ + Private slot to reset the colors for warning notifications to their + default values. + """ + self.__colors["NotificationWarningForeground"] = ( + Preferences.Prefs.uiDefaults["NotificationWarningForeground"]) + self.__colors["NotificationWarningBackground"] = ( + Preferences.Prefs.uiDefaults["NotificationWarningBackground"]) + self.warningFrame.setStyleSheet( + NotificationFrame.NotificationStyleSheetTemplate.format( + self.__colors["NotificationWarningForeground"], + self.__colors["NotificationWarningBackground"] + ) + ) + + ################################################################## + ## colors for critical notifications + ################################################################## + + @pyqtSlot() + def on_criticalFgButton_clicked(self): + """ + Private slot to set the foreground color of the critical notifications. + """ + color = QColorDialog.getColor( + QColor(self.__colors["NotificationCriticalForeground"])) + if color.isValid(): + self.__colors["NotificationCriticalForeground"] = color.name() + self.criticalFrame.setStyleSheet( + NotificationFrame.NotificationStyleSheetTemplate.format( + self.__colors["NotificationCriticalForeground"], + self.__colors["NotificationCriticalBackground"] + ) + ) + + @pyqtSlot() + def on_criticalBgButton_clicked(self): + """ + Private slot to set the background color of the critical notifications. + """ + color = QColorDialog.getColor( + QColor(self.__colors["NotificationCriticalBackground"])) + if color.isValid(): + self.__colors["NotificationCriticalBackground"] = color.name() + self.criticalFrame.setStyleSheet( + NotificationFrame.NotificationStyleSheetTemplate.format( + self.__colors["NotificationCriticalForeground"], + self.__colors["NotificationCriticalBackground"] + ) + ) + + @pyqtSlot() + def on_criticalResetButton_clicked(self): + """ + Private slot to reset the colors for critical notifications to their + current values. + """ + self.__colors["NotificationCriticalForeground"] = Preferences.getUI( + "NotificationCriticalForeground") + self.__colors["NotificationCriticalBackground"] = Preferences.getUI( + "NotificationCriticalBackground") + self.criticalFrame.setStyleSheet( + NotificationFrame.NotificationStyleSheetTemplate.format( + self.__colors["NotificationCriticalForeground"], + self.__colors["NotificationCriticalBackground"] + ) + ) + + @pyqtSlot() + def on_criticalDefaultButton_clicked(self): + """ + Private slot to reset the colors for critical notifications to their + default values. + """ + self.__colors["NotificationCriticalForeground"] = ( + Preferences.Prefs.uiDefaults["NotificationCriticalForeground"]) + self.__colors["NotificationCriticalBackground"] = ( + Preferences.Prefs.uiDefaults["NotificationCriticalBackground"]) + self.criticalFrame.setStyleSheet( + NotificationFrame.NotificationStyleSheetTemplate.format( + self.__colors["NotificationCriticalForeground"], + self.__colors["NotificationCriticalBackground"] + ) + ) def create(dlg):