eric6/Preferences/ConfigurationPages/NotificationsPage.py

branch
maintenance
changeset 8043
0acf98cd089a
parent 7944
6359e8b55505
parent 7959
44e15eda6506
child 8177
5688d73cc3ae
equal deleted inserted replaced
7991:866adc8c315b 8043:0acf98cd089a
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
18 19 from UI.NotificationWidget import NotificationFrame, NotificationTypes
19 from Globals import qVersionTuple
20 20
21 21
22 class NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage): 22 class NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage):
23 """ 23 """
24 Class implementing the Notifications configuration page. 24 Class implementing the Notifications configuration page.
29 """ 29 """
30 super(NotificationsPage, self).__init__() 30 super(NotificationsPage, self).__init__()
31 self.setupUi(self) 31 self.setupUi(self)
32 self.setObjectName("NotificationsPage") 32 self.setObjectName("NotificationsPage")
33 33
34 minX, maxX = self.xSpinBox.maximum(), self.xSpinBox.minimum() 34 geom = QApplication.screens()[0].availableVirtualGeometry()
35 minY, maxY = self.ySpinBox.maximum(), self.ySpinBox.minimum() 35 self.xSpinBox.setMinimum(geom.x())
36 if qVersionTuple() >= (5, 10, 0): 36 self.xSpinBox.setMaximum(geom.width())
37 for screen in QApplication.screens(): 37 self.ySpinBox.setMinimum(geom.y())
38 geom = screen.availableGeometry() 38 self.ySpinBox.setMaximum(geom.height())
39 minX = min(minX, geom.x()) 39
40 maxX = max(maxX, geom.x() + geom.width()) 40 self.warningIcon.setPixmap(
41 minY = min(minY, geom.y()) 41 NotificationFrame.getIcon(NotificationTypes.Warning))
42 maxY = max(maxY, geom.y() + geom.height()) 42 self.criticalIcon.setPixmap(
43 else: 43 NotificationFrame.getIcon(NotificationTypes.Critical))
44 desk = QApplication.desktop()
45 for screen in range(desk.screenCount()):
46 geom = desk.availableGeometry(screen)
47 minX = min(minX, geom.x())
48 maxX = max(maxX, geom.x() + geom.width())
49 minY = min(minY, geom.y())
50 maxY = max(maxY, geom.y() + geom.height())
51 self.xSpinBox.setMinimum(minX)
52 self.xSpinBox.setMaximum(maxX)
53 self.ySpinBox.setMinimum(minY)
54 self.ySpinBox.setMaximum(maxY)
55 44
56 self.__notification = None 45 self.__notification = None
57 self.__firstTime = True 46 self.__firstTime = True
58 47
59 # set initial values 48 # set initial values
60 self.enableCheckBox.setChecked(
61 Preferences.getUI("NotificationsEnabled"))
62 self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout")) 49 self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout"))
63 point = Preferences.getUI("NotificationPosition") 50 point = Preferences.getUI("NotificationPosition")
64 self.xSpinBox.setValue(point.x()) 51 self.xSpinBox.setValue(point.x())
65 self.ySpinBox.setValue(point.y()) 52 self.ySpinBox.setValue(point.y())
53
54 self.xSpinBox.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 )
66 79
67 def save(self): 80 def save(self):
68 """ 81 """
69 Public slot to save the Notifications configuration. 82 Public slot to save the Notifications configuration.
70 """ 83 """
71 Preferences.setUI(
72 "NotificationsEnabled", self.enableCheckBox.isChecked())
73 Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value()) 84 Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value())
74 Preferences.setUI("NotificationPosition", QPoint( 85 Preferences.setUI("NotificationPosition", QPoint(
75 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])
76 90
77 @pyqtSlot(bool) 91 @pyqtSlot(bool)
78 def on_visualButton_clicked(self, checked): 92 def on_visualButton_clicked(self, checked):
79 """ 93 """
80 Private slot to select the position visually. 94 Private slot to select the position visually.
83 """ 97 """
84 if checked: 98 if checked:
85 from UI.NotificationWidget import NotificationWidget 99 from UI.NotificationWidget import NotificationWidget
86 self.__notification = NotificationWidget( 100 self.__notification = NotificationWidget(
87 parent=self, setPosition=True) 101 parent=self, setPosition=True)
88 self.__notification.setPixmap( 102 self.__notification.showNotification(
89 UI.PixmapCache.getPixmap("notification48")) 103 NotificationFrame.getIcon(NotificationTypes.Other),
90 self.__notification.setHeading(self.tr("Visual Selection")) 104 self.tr("Visual Selection"),
91 self.__notification.setText(
92 self.tr("Drag the notification window to" 105 self.tr("Drag the notification window to"
93 " the desired place and release the button.")) 106 " the desired place and release the button."),
107 timeout=0
108 )
94 self.__notification.move( 109 self.__notification.move(
95 QPoint(self.xSpinBox.value(), self.ySpinBox.value())) 110 QPoint(self.xSpinBox.value(), self.ySpinBox.value()))
96 self.__notification.show()
97 if self.__firstTime: 111 if self.__firstTime:
98 # adjust the maximum values to the width of the notification 112 # adjust the maximum values to the width of the notification
99 self.xSpinBox.setMaximum( 113 self.xSpinBox.setMaximum(
100 self.xSpinBox.maximum() - self.__notification.width()) 114 self.xSpinBox.maximum() - self.__notification.width())
101 self.ySpinBox.setMaximum( 115 self.ySpinBox.setMaximum(
102 self.ySpinBox.maximum() - self.__notification.height()) 116 self.ySpinBox.maximum() - self.__notification.height())
117 self.__firstTime = False
103 self.__firstTime = False 118 self.__firstTime = False
104 else: 119 else:
105 # retrieve the position 120 # retrieve the position
106 point = self.__notification.frameGeometry().topLeft() 121 point = self.__notification.frameGeometry().topLeft()
107 self.xSpinBox.setValue(point.x()) 122 self.xSpinBox.setValue(point.x())
108 self.ySpinBox.setValue(point.y()) 123 self.ySpinBox.setValue(point.y())
109 self.__notification.close() 124 self.__notification.close()
110 self.__notification = None 125 self.__notification = None
111 126
127 @pyqtSlot()
128 def __moveNotification(self):
129 """
130 Private slot to move the notification widget.
131 """
132 if self.visualButton.isChecked():
133 self.__notification.move(
134 self.xSpinBox.value(),
135 self.ySpinBox.value()
136 )
137
138 ##################################################################
139 ## colors for warning notifications
140 ##################################################################
141
142 @pyqtSlot()
143 def on_warningFgButton_clicked(self):
144 """
145 Private slot to set the foreground color of the warning notifications.
146 """
147 color = QColorDialog.getColor(
148 QColor(self.__colors["NotificationWarningForeground"]))
149 if color.isValid():
150 self.__colors["NotificationWarningForeground"] = color.name()
151 self.warningFrame.setStyleSheet(
152 NotificationFrame.NotificationStyleSheetTemplate.format(
153 self.__colors["NotificationWarningForeground"],
154 self.__colors["NotificationWarningBackground"]
155 )
156 )
157
158 @pyqtSlot()
159 def on_warningBgButton_clicked(self):
160 """
161 Private slot to set the background color of the warning notifications.
162 """
163 color = QColorDialog.getColor(
164 QColor(self.__colors["NotificationWarningBackground"]))
165 if color.isValid():
166 self.__colors["NotificationWarningBackground"] = color.name()
167 self.warningFrame.setStyleSheet(
168 NotificationFrame.NotificationStyleSheetTemplate.format(
169 self.__colors["NotificationWarningForeground"],
170 self.__colors["NotificationWarningBackground"]
171 )
172 )
173
174 @pyqtSlot()
175 def on_warningResetButton_clicked(self):
176 """
177 Private slot to reset the colors for warning notifications to their
178 current values.
179 """
180 self.__colors["NotificationWarningForeground"] = Preferences.getUI(
181 "NotificationWarningForeground")
182 self.__colors["NotificationWarningBackground"] = Preferences.getUI(
183 "NotificationWarningBackground")
184 self.warningFrame.setStyleSheet(
185 NotificationFrame.NotificationStyleSheetTemplate.format(
186 self.__colors["NotificationWarningForeground"],
187 self.__colors["NotificationWarningBackground"]
188 )
189 )
190
191 @pyqtSlot()
192 def on_warningDefaultButton_clicked(self):
193 """
194 Private slot to reset the colors for warning notifications to their
195 default values.
196 """
197 self.__colors["NotificationWarningForeground"] = (
198 Preferences.Prefs.uiDefaults["NotificationWarningForeground"])
199 self.__colors["NotificationWarningBackground"] = (
200 Preferences.Prefs.uiDefaults["NotificationWarningBackground"])
201 self.warningFrame.setStyleSheet(
202 NotificationFrame.NotificationStyleSheetTemplate.format(
203 self.__colors["NotificationWarningForeground"],
204 self.__colors["NotificationWarningBackground"]
205 )
206 )
207
208 ##################################################################
209 ## colors for critical notifications
210 ##################################################################
211
212 @pyqtSlot()
213 def on_criticalFgButton_clicked(self):
214 """
215 Private slot to set the foreground color of the critical notifications.
216 """
217 color = QColorDialog.getColor(
218 QColor(self.__colors["NotificationCriticalForeground"]))
219 if color.isValid():
220 self.__colors["NotificationCriticalForeground"] = color.name()
221 self.criticalFrame.setStyleSheet(
222 NotificationFrame.NotificationStyleSheetTemplate.format(
223 self.__colors["NotificationCriticalForeground"],
224 self.__colors["NotificationCriticalBackground"]
225 )
226 )
227
228 @pyqtSlot()
229 def on_criticalBgButton_clicked(self):
230 """
231 Private slot to set the background color of the critical notifications.
232 """
233 color = QColorDialog.getColor(
234 QColor(self.__colors["NotificationCriticalBackground"]))
235 if color.isValid():
236 self.__colors["NotificationCriticalBackground"] = color.name()
237 self.criticalFrame.setStyleSheet(
238 NotificationFrame.NotificationStyleSheetTemplate.format(
239 self.__colors["NotificationCriticalForeground"],
240 self.__colors["NotificationCriticalBackground"]
241 )
242 )
243
244 @pyqtSlot()
245 def on_criticalResetButton_clicked(self):
246 """
247 Private slot to reset the colors for critical notifications to their
248 current values.
249 """
250 self.__colors["NotificationCriticalForeground"] = Preferences.getUI(
251 "NotificationCriticalForeground")
252 self.__colors["NotificationCriticalBackground"] = Preferences.getUI(
253 "NotificationCriticalBackground")
254 self.criticalFrame.setStyleSheet(
255 NotificationFrame.NotificationStyleSheetTemplate.format(
256 self.__colors["NotificationCriticalForeground"],
257 self.__colors["NotificationCriticalBackground"]
258 )
259 )
260
261 @pyqtSlot()
262 def on_criticalDefaultButton_clicked(self):
263 """
264 Private slot to reset the colors for critical notifications to their
265 default values.
266 """
267 self.__colors["NotificationCriticalForeground"] = (
268 Preferences.Prefs.uiDefaults["NotificationCriticalForeground"])
269 self.__colors["NotificationCriticalBackground"] = (
270 Preferences.Prefs.uiDefaults["NotificationCriticalBackground"])
271 self.criticalFrame.setStyleSheet(
272 NotificationFrame.NotificationStyleSheetTemplate.format(
273 self.__colors["NotificationCriticalForeground"],
274 self.__colors["NotificationCriticalBackground"]
275 )
276 )
277
112 278
113 def create(dlg): 279 def create(dlg):
114 """ 280 """
115 Module function to create the configuration page. 281 Module function to create the configuration page.
116 282

eric ide

mercurial