--- a/eric6/Preferences/ConfigurationPages/NotificationsPage.py Sun Jan 17 13:53:08 2021 +0100 +++ b/eric6/Preferences/ConfigurationPages/NotificationsPage.py Mon Feb 01 10:38:16 2021 +0100 @@ -8,15 +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 Globals import qVersionTuple +from UI.NotificationWidget import NotificationFrame, NotificationTypes class NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage): @@ -31,48 +31,62 @@ self.setupUi(self) self.setObjectName("NotificationsPage") - minX, maxX = self.xSpinBox.maximum(), self.xSpinBox.minimum() - minY, maxY = self.ySpinBox.maximum(), self.ySpinBox.minimum() - if qVersionTuple() >= (5, 10, 0): - for screen in QApplication.screens(): - geom = screen.availableGeometry() - minX = min(minX, geom.x()) - maxX = max(maxX, geom.x() + geom.width()) - minY = min(minY, geom.y()) - maxY = max(maxY, geom.y() + geom.height()) - else: - desk = QApplication.desktop() - for screen in range(desk.screenCount()): - geom = desk.availableGeometry(screen) - minX = min(minX, geom.x()) - maxX = max(maxX, geom.x() + geom.width()) - minY = min(minY, geom.y()) - maxY = max(maxY, geom.y() + geom.height()) - self.xSpinBox.setMinimum(minX) - self.xSpinBox.setMaximum(maxX) - self.ySpinBox.setMinimum(minY) - self.ySpinBox.setMaximum(maxY) + geom = QApplication.screens()[0].availableVirtualGeometry() + self.xSpinBox.setMinimum(geom.x()) + self.xSpinBox.setMaximum(geom.width()) + 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 # set initial values - self.enableCheckBox.setChecked( - Preferences.getUI("NotificationsEnabled")) self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout")) point = Preferences.getUI("NotificationPosition") self.xSpinBox.setValue(point.x()) self.ySpinBox.setValue(point.y()) + + 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): """ Public slot to save the Notifications configuration. """ - Preferences.setUI( - "NotificationsEnabled", self.enableCheckBox.isChecked()) 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): @@ -85,15 +99,15 @@ from UI.NotificationWidget import NotificationWidget self.__notification = NotificationWidget( parent=self, setPosition=True) - self.__notification.setPixmap( - UI.PixmapCache.getPixmap("notification48")) - self.__notification.setHeading(self.tr("Visual Selection")) - self.__notification.setText( + self.__notification.showNotification( + NotificationFrame.getIcon(NotificationTypes.Other), + self.tr("Visual Selection"), self.tr("Drag the notification window to" - " the desired place and release the button.")) + " the desired place and release the button."), + timeout=0 + ) self.__notification.move( QPoint(self.xSpinBox.value(), self.ySpinBox.value())) - self.__notification.show() if self.__firstTime: # adjust the maximum values to the width of the notification self.xSpinBox.setMaximum( @@ -101,6 +115,7 @@ self.ySpinBox.setMaximum( self.ySpinBox.maximum() - self.__notification.height()) self.__firstTime = False + self.__firstTime = False else: # retrieve the position point = self.__notification.frameGeometry().topLeft() @@ -109,6 +124,157 @@ self.__notification.close() self.__notification = None + @pyqtSlot() + def __moveNotification(self): + """ + Private slot to move the notification widget. + """ + if self.visualButton.isChecked(): + self.__notification.move( + 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): """