eric7/Preferences/ConfigurationPages/NotificationsPage.py

branch
eric7
changeset 8312
800c432b34c8
parent 8265
0090cfa83159
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Notifications configuration page.
8 """
9
10 from PyQt5.QtCore import pyqtSlot, QPoint
11 from PyQt5.QtGui import QColor
12 from PyQt5.QtWidgets import QApplication, QColorDialog
13
14 from .ConfigurationPageBase import ConfigurationPageBase
15 from .Ui_NotificationsPage import Ui_NotificationsPage
16
17 import Preferences
18
19 from UI.NotificationWidget import NotificationFrame, NotificationTypes
20
21
22 class NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage):
23 """
24 Class implementing the Notifications configuration page.
25 """
26 def __init__(self):
27 """
28 Constructor
29 """
30 super().__init__()
31 self.setupUi(self)
32 self.setObjectName("NotificationsPage")
33
34 geom = QApplication.screens()[0].availableVirtualGeometry()
35 self.xSpinBox.setMinimum(geom.x())
36 self.xSpinBox.setMaximum(geom.width())
37 self.ySpinBox.setMinimum(geom.y())
38 self.ySpinBox.setMaximum(geom.height())
39
40 self.warningIcon.setPixmap(
41 NotificationFrame.getIcon(NotificationTypes.WARNING))
42 self.criticalIcon.setPixmap(
43 NotificationFrame.getIcon(NotificationTypes.CRITICAL))
44
45 self.__notification = None
46 self.__firstTime = True
47
48 # set initial values
49 self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout"))
50 point = Preferences.getUI("NotificationPosition")
51 self.xSpinBox.setValue(point.x())
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 )
79
80 def save(self):
81 """
82 Public slot to save the Notifications configuration.
83 """
84 Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value())
85 Preferences.setUI("NotificationPosition", QPoint(
86 self.xSpinBox.value(), self.ySpinBox.value()))
87
88 for key in self.__colors:
89 Preferences.setUI(key, self.__colors[key])
90
91 @pyqtSlot(bool)
92 def on_visualButton_clicked(self, checked):
93 """
94 Private slot to select the position visually.
95
96 @param checked state of the button (boolean)
97 """
98 if checked:
99 from UI.NotificationWidget import NotificationWidget
100 self.__notification = NotificationWidget(
101 parent=self, setPosition=True)
102 self.__notification.showNotification(
103 NotificationFrame.getIcon(NotificationTypes.OTHER),
104 self.tr("Visual Selection"),
105 self.tr("Drag the notification window to"
106 " the desired place and release the button."),
107 timeout=0
108 )
109 self.__notification.move(
110 QPoint(self.xSpinBox.value(), self.ySpinBox.value()))
111 if self.__firstTime:
112 # adjust the maximum values to the width of the notification
113 self.xSpinBox.setMaximum(
114 self.xSpinBox.maximum() - self.__notification.width())
115 self.ySpinBox.setMaximum(
116 self.ySpinBox.maximum() - self.__notification.height())
117 self.__firstTime = False
118 else:
119 # retrieve the position
120 point = self.__notification.frameGeometry().topLeft()
121 self.xSpinBox.setValue(point.x())
122 self.ySpinBox.setValue(point.y())
123 self.__notification.close()
124 self.__notification = None
125
126 @pyqtSlot()
127 def __moveNotification(self):
128 """
129 Private slot to move the notification widget.
130 """
131 if self.visualButton.isChecked():
132 self.__notification.move(
133 self.xSpinBox.value(),
134 self.ySpinBox.value()
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 )
276
277
278 def create(dlg):
279 """
280 Module function to create the configuration page.
281
282 @param dlg reference to the configuration dialog
283 @return reference to the instantiated page (ConfigurationPageBase)
284 """
285 page = NotificationsPage()
286 return page

eric ide

mercurial