eric6/Preferences/ConfigurationPages/NotificationsPage.py

changeset 7959
44e15eda6506
parent 7955
567f2ec958c3
child 8043
0acf98cd089a
child 8205
4a0f1f896341
equal deleted inserted replaced
7958:a70ebfad3d0e 7959:44e15eda6506
6 """ 6 """
7 Module implementing the Notifications configuration page. 7 Module implementing the Notifications configuration page.
8 """ 8 """
9 9
10 from PyQt5.QtCore import pyqtSlot, QPoint 10 from PyQt5.QtCore import pyqtSlot, QPoint
11 from PyQt5.QtWidgets import QApplication 11 from PyQt5.QtGui import QColor
12 from PyQt5.QtWidgets import QApplication, QColorDialog
12 13
13 from .ConfigurationPageBase import ConfigurationPageBase 14 from .ConfigurationPageBase import ConfigurationPageBase
14 from .Ui_NotificationsPage import Ui_NotificationsPage 15 from .Ui_NotificationsPage import Ui_NotificationsPage
15 16
16 import Preferences 17 import Preferences
17 import UI.PixmapCache 18
19 from UI.NotificationWidget import NotificationFrame, NotificationTypes
18 20
19 21
20 class NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage): 22 class NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage):
21 """ 23 """
22 Class implementing the Notifications configuration page. 24 Class implementing the Notifications configuration page.
33 self.xSpinBox.setMinimum(geom.x()) 35 self.xSpinBox.setMinimum(geom.x())
34 self.xSpinBox.setMaximum(geom.width()) 36 self.xSpinBox.setMaximum(geom.width())
35 self.ySpinBox.setMinimum(geom.y()) 37 self.ySpinBox.setMinimum(geom.y())
36 self.ySpinBox.setMaximum(geom.height()) 38 self.ySpinBox.setMaximum(geom.height())
37 39
40 self.warningIcon.setPixmap(
41 NotificationFrame.getIcon(NotificationTypes.Warning))
42 self.criticalIcon.setPixmap(
43 NotificationFrame.getIcon(NotificationTypes.Critical))
44
38 self.__notification = None 45 self.__notification = None
39 self.__firstTime = True 46 self.__firstTime = True
40 47
41 # set initial values 48 # set initial values
42 self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout")) 49 self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout"))
44 self.xSpinBox.setValue(point.x()) 51 self.xSpinBox.setValue(point.x())
45 self.ySpinBox.setValue(point.y()) 52 self.ySpinBox.setValue(point.y())
46 53
47 self.xSpinBox.valueChanged.connect(self.__moveNotification) 54 self.xSpinBox.valueChanged.connect(self.__moveNotification)
48 self.ySpinBox.valueChanged.connect(self.__moveNotification) 55 self.ySpinBox.valueChanged.connect(self.__moveNotification)
56
57 self.__colors = {}
58 self.__colors["NotificationWarningForeground"] = Preferences.getUI(
59 "NotificationWarningForeground")
60 self.__colors["NotificationWarningBackground"] = Preferences.getUI(
61 "NotificationWarningBackground")
62 self.__colors["NotificationCriticalForeground"] = Preferences.getUI(
63 "NotificationCriticalForeground")
64 self.__colors["NotificationCriticalBackground"] = Preferences.getUI(
65 "NotificationCriticalBackground")
66
67 self.warningFrame.setStyleSheet(
68 NotificationFrame.NotificationStyleSheetTemplate.format(
69 self.__colors["NotificationWarningForeground"],
70 self.__colors["NotificationWarningBackground"]
71 )
72 )
73 self.criticalFrame.setStyleSheet(
74 NotificationFrame.NotificationStyleSheetTemplate.format(
75 self.__colors["NotificationCriticalForeground"],
76 self.__colors["NotificationCriticalBackground"]
77 )
78 )
49 79
50 def save(self): 80 def save(self):
51 """ 81 """
52 Public slot to save the Notifications configuration. 82 Public slot to save the Notifications configuration.
53 """ 83 """
54 Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value()) 84 Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value())
55 Preferences.setUI("NotificationPosition", QPoint( 85 Preferences.setUI("NotificationPosition", QPoint(
56 self.xSpinBox.value(), self.ySpinBox.value())) 86 self.xSpinBox.value(), self.ySpinBox.value()))
87
88 for key in self.__colors.keys():
89 Preferences.setUI(key, self.__colors[key])
57 90
58 @pyqtSlot(bool) 91 @pyqtSlot(bool)
59 def on_visualButton_clicked(self, checked): 92 def on_visualButton_clicked(self, checked):
60 """ 93 """
61 Private slot to select the position visually. 94 Private slot to select the position visually.
65 if checked: 98 if checked:
66 from UI.NotificationWidget import NotificationWidget 99 from UI.NotificationWidget import NotificationWidget
67 self.__notification = NotificationWidget( 100 self.__notification = NotificationWidget(
68 parent=self, setPosition=True) 101 parent=self, setPosition=True)
69 self.__notification.showNotification( 102 self.__notification.showNotification(
70 UI.PixmapCache.getPixmap("notification48"), 103 NotificationFrame.getIcon(NotificationTypes.Other),
71 self.tr("Visual Selection"), 104 self.tr("Visual Selection"),
72 self.tr("Drag the notification window to" 105 self.tr("Drag the notification window to"
73 " the desired place and release the button."), 106 " the desired place and release the button."),
74 timeout=0 107 timeout=0
75 ) 108 )
98 if self.visualButton.isChecked(): 131 if self.visualButton.isChecked():
99 self.__notification.move( 132 self.__notification.move(
100 self.xSpinBox.value(), 133 self.xSpinBox.value(),
101 self.ySpinBox.value() 134 self.ySpinBox.value()
102 ) 135 )
136
137 ##################################################################
138 ## colors for warning notifications
139 ##################################################################
140
141 @pyqtSlot()
142 def on_warningFgButton_clicked(self):
143 """
144 Private slot to set the foreground color of the warning notifications.
145 """
146 color = QColorDialog.getColor(
147 QColor(self.__colors["NotificationWarningForeground"]))
148 if color.isValid():
149 self.__colors["NotificationWarningForeground"] = color.name()
150 self.warningFrame.setStyleSheet(
151 NotificationFrame.NotificationStyleSheetTemplate.format(
152 self.__colors["NotificationWarningForeground"],
153 self.__colors["NotificationWarningBackground"]
154 )
155 )
156
157 @pyqtSlot()
158 def on_warningBgButton_clicked(self):
159 """
160 Private slot to set the background color of the warning notifications.
161 """
162 color = QColorDialog.getColor(
163 QColor(self.__colors["NotificationWarningBackground"]))
164 if color.isValid():
165 self.__colors["NotificationWarningBackground"] = color.name()
166 self.warningFrame.setStyleSheet(
167 NotificationFrame.NotificationStyleSheetTemplate.format(
168 self.__colors["NotificationWarningForeground"],
169 self.__colors["NotificationWarningBackground"]
170 )
171 )
172
173 @pyqtSlot()
174 def on_warningResetButton_clicked(self):
175 """
176 Private slot to reset the colors for warning notifications to their
177 current values.
178 """
179 self.__colors["NotificationWarningForeground"] = Preferences.getUI(
180 "NotificationWarningForeground")
181 self.__colors["NotificationWarningBackground"] = Preferences.getUI(
182 "NotificationWarningBackground")
183 self.warningFrame.setStyleSheet(
184 NotificationFrame.NotificationStyleSheetTemplate.format(
185 self.__colors["NotificationWarningForeground"],
186 self.__colors["NotificationWarningBackground"]
187 )
188 )
189
190 @pyqtSlot()
191 def on_warningDefaultButton_clicked(self):
192 """
193 Private slot to reset the colors for warning notifications to their
194 default values.
195 """
196 self.__colors["NotificationWarningForeground"] = (
197 Preferences.Prefs.uiDefaults["NotificationWarningForeground"])
198 self.__colors["NotificationWarningBackground"] = (
199 Preferences.Prefs.uiDefaults["NotificationWarningBackground"])
200 self.warningFrame.setStyleSheet(
201 NotificationFrame.NotificationStyleSheetTemplate.format(
202 self.__colors["NotificationWarningForeground"],
203 self.__colors["NotificationWarningBackground"]
204 )
205 )
206
207 ##################################################################
208 ## colors for critical notifications
209 ##################################################################
210
211 @pyqtSlot()
212 def on_criticalFgButton_clicked(self):
213 """
214 Private slot to set the foreground color of the critical notifications.
215 """
216 color = QColorDialog.getColor(
217 QColor(self.__colors["NotificationCriticalForeground"]))
218 if color.isValid():
219 self.__colors["NotificationCriticalForeground"] = color.name()
220 self.criticalFrame.setStyleSheet(
221 NotificationFrame.NotificationStyleSheetTemplate.format(
222 self.__colors["NotificationCriticalForeground"],
223 self.__colors["NotificationCriticalBackground"]
224 )
225 )
226
227 @pyqtSlot()
228 def on_criticalBgButton_clicked(self):
229 """
230 Private slot to set the background color of the critical notifications.
231 """
232 color = QColorDialog.getColor(
233 QColor(self.__colors["NotificationCriticalBackground"]))
234 if color.isValid():
235 self.__colors["NotificationCriticalBackground"] = color.name()
236 self.criticalFrame.setStyleSheet(
237 NotificationFrame.NotificationStyleSheetTemplate.format(
238 self.__colors["NotificationCriticalForeground"],
239 self.__colors["NotificationCriticalBackground"]
240 )
241 )
242
243 @pyqtSlot()
244 def on_criticalResetButton_clicked(self):
245 """
246 Private slot to reset the colors for critical notifications to their
247 current values.
248 """
249 self.__colors["NotificationCriticalForeground"] = Preferences.getUI(
250 "NotificationCriticalForeground")
251 self.__colors["NotificationCriticalBackground"] = Preferences.getUI(
252 "NotificationCriticalBackground")
253 self.criticalFrame.setStyleSheet(
254 NotificationFrame.NotificationStyleSheetTemplate.format(
255 self.__colors["NotificationCriticalForeground"],
256 self.__colors["NotificationCriticalBackground"]
257 )
258 )
259
260 @pyqtSlot()
261 def on_criticalDefaultButton_clicked(self):
262 """
263 Private slot to reset the colors for critical notifications to their
264 default values.
265 """
266 self.__colors["NotificationCriticalForeground"] = (
267 Preferences.Prefs.uiDefaults["NotificationCriticalForeground"])
268 self.__colors["NotificationCriticalBackground"] = (
269 Preferences.Prefs.uiDefaults["NotificationCriticalBackground"])
270 self.criticalFrame.setStyleSheet(
271 NotificationFrame.NotificationStyleSheetTemplate.format(
272 self.__colors["NotificationCriticalForeground"],
273 self.__colors["NotificationCriticalBackground"]
274 )
275 )
103 276
104 277
105 def create(dlg): 278 def create(dlg):
106 """ 279 """
107 Module function to create the configuration page. 280 Module function to create the configuration page.

eric ide

mercurial