src/eric7/Preferences/ConfigurationPages/NotificationsPage.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
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.
25 """ 25 """
26
26 def __init__(self): 27 def __init__(self):
27 """ 28 """
28 Constructor 29 Constructor
29 """ 30 """
30 super().__init__() 31 super().__init__()
31 self.setupUi(self) 32 self.setupUi(self)
32 self.setObjectName("NotificationsPage") 33 self.setObjectName("NotificationsPage")
33 34
34 geom = QApplication.screens()[0].availableVirtualGeometry() 35 geom = QApplication.screens()[0].availableVirtualGeometry()
35 self.xSpinBox.setMinimum(geom.x()) 36 self.xSpinBox.setMinimum(geom.x())
36 self.xSpinBox.setMaximum(geom.width()) 37 self.xSpinBox.setMaximum(geom.width())
37 self.ySpinBox.setMinimum(geom.y()) 38 self.ySpinBox.setMinimum(geom.y())
38 self.ySpinBox.setMaximum(geom.height()) 39 self.ySpinBox.setMaximum(geom.height())
39 40
40 self.warningIcon.setPixmap( 41 self.warningIcon.setPixmap(NotificationFrame.getIcon(NotificationTypes.WARNING))
41 NotificationFrame.getIcon(NotificationTypes.WARNING))
42 self.criticalIcon.setPixmap( 42 self.criticalIcon.setPixmap(
43 NotificationFrame.getIcon(NotificationTypes.CRITICAL)) 43 NotificationFrame.getIcon(NotificationTypes.CRITICAL)
44 44 )
45
45 self.__notification = None 46 self.__notification = None
46 self.__firstTime = True 47 self.__firstTime = True
47 48
48 # set initial values 49 # set initial values
49 self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout")) 50 self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout"))
50 point = Preferences.getUI("NotificationPosition") 51 point = Preferences.getUI("NotificationPosition")
51 self.xSpinBox.setValue(point.x()) 52 self.xSpinBox.setValue(point.x())
52 self.ySpinBox.setValue(point.y()) 53 self.ySpinBox.setValue(point.y())
53 54
54 self.xSpinBox.valueChanged.connect(self.__moveNotification) 55 self.xSpinBox.valueChanged.connect(self.__moveNotification)
55 self.ySpinBox.valueChanged.connect(self.__moveNotification) 56 self.ySpinBox.valueChanged.connect(self.__moveNotification)
56 57
57 self.__colors = {} 58 self.__colors = {}
58 self.__colors["NotificationWarningForeground"] = Preferences.getUI( 59 self.__colors["NotificationWarningForeground"] = Preferences.getUI(
59 "NotificationWarningForeground") 60 "NotificationWarningForeground"
61 )
60 self.__colors["NotificationWarningBackground"] = Preferences.getUI( 62 self.__colors["NotificationWarningBackground"] = Preferences.getUI(
61 "NotificationWarningBackground") 63 "NotificationWarningBackground"
64 )
62 self.__colors["NotificationCriticalForeground"] = Preferences.getUI( 65 self.__colors["NotificationCriticalForeground"] = Preferences.getUI(
63 "NotificationCriticalForeground") 66 "NotificationCriticalForeground"
67 )
64 self.__colors["NotificationCriticalBackground"] = Preferences.getUI( 68 self.__colors["NotificationCriticalBackground"] = Preferences.getUI(
65 "NotificationCriticalBackground") 69 "NotificationCriticalBackground"
66 70 )
71
67 self.warningFrame.setStyleSheet( 72 self.warningFrame.setStyleSheet(
68 NotificationFrame.NotificationStyleSheetTemplate.format( 73 NotificationFrame.NotificationStyleSheetTemplate.format(
69 self.__colors["NotificationWarningForeground"], 74 self.__colors["NotificationWarningForeground"],
70 self.__colors["NotificationWarningBackground"] 75 self.__colors["NotificationWarningBackground"],
71 ) 76 )
72 ) 77 )
73 self.criticalFrame.setStyleSheet( 78 self.criticalFrame.setStyleSheet(
74 NotificationFrame.NotificationStyleSheetTemplate.format( 79 NotificationFrame.NotificationStyleSheetTemplate.format(
75 self.__colors["NotificationCriticalForeground"], 80 self.__colors["NotificationCriticalForeground"],
76 self.__colors["NotificationCriticalBackground"] 81 self.__colors["NotificationCriticalBackground"],
77 ) 82 )
78 ) 83 )
79 84
80 def save(self): 85 def save(self):
81 """ 86 """
82 Public slot to save the Notifications configuration. 87 Public slot to save the Notifications configuration.
83 """ 88 """
84 Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value()) 89 Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value())
85 Preferences.setUI("NotificationPosition", QPoint( 90 Preferences.setUI(
86 self.xSpinBox.value(), self.ySpinBox.value())) 91 "NotificationPosition", QPoint(self.xSpinBox.value(), self.ySpinBox.value())
87 92 )
93
88 for key in self.__colors: 94 for key in self.__colors:
89 Preferences.setUI(key, self.__colors[key]) 95 Preferences.setUI(key, self.__colors[key])
90 96
91 @pyqtSlot(bool) 97 @pyqtSlot(bool)
92 def on_visualButton_clicked(self, checked): 98 def on_visualButton_clicked(self, checked):
93 """ 99 """
94 Private slot to select the position visually. 100 Private slot to select the position visually.
95 101
96 @param checked state of the button (boolean) 102 @param checked state of the button (boolean)
97 """ 103 """
98 if checked: 104 if checked:
99 from UI.NotificationWidget import NotificationWidget 105 from UI.NotificationWidget import NotificationWidget
100 self.__notification = NotificationWidget( 106
101 parent=self, setPosition=True) 107 self.__notification = NotificationWidget(parent=self, setPosition=True)
102 self.__notification.showNotification( 108 self.__notification.showNotification(
103 NotificationFrame.getIcon(NotificationTypes.OTHER), 109 NotificationFrame.getIcon(NotificationTypes.OTHER),
104 self.tr("Visual Selection"), 110 self.tr("Visual Selection"),
105 self.tr("Drag the notification window to" 111 self.tr(
106 " the desired place and release the button."), 112 "Drag the notification window to"
107 timeout=0 113 " the desired place and release the button."
114 ),
115 timeout=0,
108 ) 116 )
109 self.__notification.move( 117 self.__notification.move(
110 QPoint(self.xSpinBox.value(), self.ySpinBox.value())) 118 QPoint(self.xSpinBox.value(), self.ySpinBox.value())
119 )
111 if self.__firstTime: 120 if self.__firstTime:
112 # adjust the maximum values to the width of the notification 121 # adjust the maximum values to the width of the notification
113 self.xSpinBox.setMaximum( 122 self.xSpinBox.setMaximum(
114 self.xSpinBox.maximum() - self.__notification.width()) 123 self.xSpinBox.maximum() - self.__notification.width()
124 )
115 self.ySpinBox.setMaximum( 125 self.ySpinBox.setMaximum(
116 self.ySpinBox.maximum() - self.__notification.height()) 126 self.ySpinBox.maximum() - self.__notification.height()
127 )
117 self.__firstTime = False 128 self.__firstTime = False
118 else: 129 else:
119 # retrieve the position 130 # retrieve the position
120 point = self.__notification.frameGeometry().topLeft() 131 point = self.__notification.frameGeometry().topLeft()
121 self.xSpinBox.setValue(point.x()) 132 self.xSpinBox.setValue(point.x())
122 self.ySpinBox.setValue(point.y()) 133 self.ySpinBox.setValue(point.y())
123 self.__notification.close() 134 self.__notification.close()
124 self.__notification = None 135 self.__notification = None
125 136
126 @pyqtSlot() 137 @pyqtSlot()
127 def __moveNotification(self): 138 def __moveNotification(self):
128 """ 139 """
129 Private slot to move the notification widget. 140 Private slot to move the notification widget.
130 """ 141 """
131 if self.visualButton.isChecked(): 142 if self.visualButton.isChecked():
132 self.__notification.move( 143 self.__notification.move(self.xSpinBox.value(), self.ySpinBox.value())
133 self.xSpinBox.value(), 144
134 self.ySpinBox.value()
135 )
136
137 ################################################################## 145 ##################################################################
138 ## colors for warning notifications 146 ## colors for warning notifications
139 ################################################################## 147 ##################################################################
140 148
141 @pyqtSlot() 149 @pyqtSlot()
142 def on_warningFgButton_clicked(self): 150 def on_warningFgButton_clicked(self):
143 """ 151 """
144 Private slot to set the foreground color of the warning notifications. 152 Private slot to set the foreground color of the warning notifications.
145 """ 153 """
146 color = QColorDialog.getColor( 154 color = QColorDialog.getColor(
147 QColor(self.__colors["NotificationWarningForeground"])) 155 QColor(self.__colors["NotificationWarningForeground"])
156 )
148 if color.isValid(): 157 if color.isValid():
149 self.__colors["NotificationWarningForeground"] = color.name() 158 self.__colors["NotificationWarningForeground"] = color.name()
150 self.warningFrame.setStyleSheet( 159 self.warningFrame.setStyleSheet(
151 NotificationFrame.NotificationStyleSheetTemplate.format( 160 NotificationFrame.NotificationStyleSheetTemplate.format(
152 self.__colors["NotificationWarningForeground"], 161 self.__colors["NotificationWarningForeground"],
153 self.__colors["NotificationWarningBackground"] 162 self.__colors["NotificationWarningBackground"],
154 ) 163 )
155 ) 164 )
156 165
157 @pyqtSlot() 166 @pyqtSlot()
158 def on_warningBgButton_clicked(self): 167 def on_warningBgButton_clicked(self):
159 """ 168 """
160 Private slot to set the background color of the warning notifications. 169 Private slot to set the background color of the warning notifications.
161 """ 170 """
162 color = QColorDialog.getColor( 171 color = QColorDialog.getColor(
163 QColor(self.__colors["NotificationWarningBackground"])) 172 QColor(self.__colors["NotificationWarningBackground"])
173 )
164 if color.isValid(): 174 if color.isValid():
165 self.__colors["NotificationWarningBackground"] = color.name() 175 self.__colors["NotificationWarningBackground"] = color.name()
166 self.warningFrame.setStyleSheet( 176 self.warningFrame.setStyleSheet(
167 NotificationFrame.NotificationStyleSheetTemplate.format( 177 NotificationFrame.NotificationStyleSheetTemplate.format(
168 self.__colors["NotificationWarningForeground"], 178 self.__colors["NotificationWarningForeground"],
169 self.__colors["NotificationWarningBackground"] 179 self.__colors["NotificationWarningBackground"],
170 ) 180 )
171 ) 181 )
172 182
173 @pyqtSlot() 183 @pyqtSlot()
174 def on_warningResetButton_clicked(self): 184 def on_warningResetButton_clicked(self):
175 """ 185 """
176 Private slot to reset the colors for warning notifications to their 186 Private slot to reset the colors for warning notifications to their
177 current values. 187 current values.
178 """ 188 """
179 self.__colors["NotificationWarningForeground"] = Preferences.getUI( 189 self.__colors["NotificationWarningForeground"] = Preferences.getUI(
180 "NotificationWarningForeground") 190 "NotificationWarningForeground"
191 )
181 self.__colors["NotificationWarningBackground"] = Preferences.getUI( 192 self.__colors["NotificationWarningBackground"] = Preferences.getUI(
182 "NotificationWarningBackground") 193 "NotificationWarningBackground"
194 )
183 self.warningFrame.setStyleSheet( 195 self.warningFrame.setStyleSheet(
184 NotificationFrame.NotificationStyleSheetTemplate.format( 196 NotificationFrame.NotificationStyleSheetTemplate.format(
185 self.__colors["NotificationWarningForeground"], 197 self.__colors["NotificationWarningForeground"],
186 self.__colors["NotificationWarningBackground"] 198 self.__colors["NotificationWarningBackground"],
187 ) 199 )
188 ) 200 )
189 201
190 @pyqtSlot() 202 @pyqtSlot()
191 def on_warningDefaultButton_clicked(self): 203 def on_warningDefaultButton_clicked(self):
192 """ 204 """
193 Private slot to reset the colors for warning notifications to their 205 Private slot to reset the colors for warning notifications to their
194 default values. 206 default values.
195 """ 207 """
196 self.__colors["NotificationWarningForeground"] = ( 208 self.__colors["NotificationWarningForeground"] = Preferences.Prefs.uiDefaults[
197 Preferences.Prefs.uiDefaults["NotificationWarningForeground"]) 209 "NotificationWarningForeground"
198 self.__colors["NotificationWarningBackground"] = ( 210 ]
199 Preferences.Prefs.uiDefaults["NotificationWarningBackground"]) 211 self.__colors["NotificationWarningBackground"] = Preferences.Prefs.uiDefaults[
212 "NotificationWarningBackground"
213 ]
200 self.warningFrame.setStyleSheet( 214 self.warningFrame.setStyleSheet(
201 NotificationFrame.NotificationStyleSheetTemplate.format( 215 NotificationFrame.NotificationStyleSheetTemplate.format(
202 self.__colors["NotificationWarningForeground"], 216 self.__colors["NotificationWarningForeground"],
203 self.__colors["NotificationWarningBackground"] 217 self.__colors["NotificationWarningBackground"],
204 ) 218 )
205 ) 219 )
206 220
207 ################################################################## 221 ##################################################################
208 ## colors for critical notifications 222 ## colors for critical notifications
209 ################################################################## 223 ##################################################################
210 224
211 @pyqtSlot() 225 @pyqtSlot()
212 def on_criticalFgButton_clicked(self): 226 def on_criticalFgButton_clicked(self):
213 """ 227 """
214 Private slot to set the foreground color of the critical notifications. 228 Private slot to set the foreground color of the critical notifications.
215 """ 229 """
216 color = QColorDialog.getColor( 230 color = QColorDialog.getColor(
217 QColor(self.__colors["NotificationCriticalForeground"])) 231 QColor(self.__colors["NotificationCriticalForeground"])
232 )
218 if color.isValid(): 233 if color.isValid():
219 self.__colors["NotificationCriticalForeground"] = color.name() 234 self.__colors["NotificationCriticalForeground"] = color.name()
220 self.criticalFrame.setStyleSheet( 235 self.criticalFrame.setStyleSheet(
221 NotificationFrame.NotificationStyleSheetTemplate.format( 236 NotificationFrame.NotificationStyleSheetTemplate.format(
222 self.__colors["NotificationCriticalForeground"], 237 self.__colors["NotificationCriticalForeground"],
223 self.__colors["NotificationCriticalBackground"] 238 self.__colors["NotificationCriticalBackground"],
224 ) 239 )
225 ) 240 )
226 241
227 @pyqtSlot() 242 @pyqtSlot()
228 def on_criticalBgButton_clicked(self): 243 def on_criticalBgButton_clicked(self):
229 """ 244 """
230 Private slot to set the background color of the critical notifications. 245 Private slot to set the background color of the critical notifications.
231 """ 246 """
232 color = QColorDialog.getColor( 247 color = QColorDialog.getColor(
233 QColor(self.__colors["NotificationCriticalBackground"])) 248 QColor(self.__colors["NotificationCriticalBackground"])
249 )
234 if color.isValid(): 250 if color.isValid():
235 self.__colors["NotificationCriticalBackground"] = color.name() 251 self.__colors["NotificationCriticalBackground"] = color.name()
236 self.criticalFrame.setStyleSheet( 252 self.criticalFrame.setStyleSheet(
237 NotificationFrame.NotificationStyleSheetTemplate.format( 253 NotificationFrame.NotificationStyleSheetTemplate.format(
238 self.__colors["NotificationCriticalForeground"], 254 self.__colors["NotificationCriticalForeground"],
239 self.__colors["NotificationCriticalBackground"] 255 self.__colors["NotificationCriticalBackground"],
240 ) 256 )
241 ) 257 )
242 258
243 @pyqtSlot() 259 @pyqtSlot()
244 def on_criticalResetButton_clicked(self): 260 def on_criticalResetButton_clicked(self):
245 """ 261 """
246 Private slot to reset the colors for critical notifications to their 262 Private slot to reset the colors for critical notifications to their
247 current values. 263 current values.
248 """ 264 """
249 self.__colors["NotificationCriticalForeground"] = Preferences.getUI( 265 self.__colors["NotificationCriticalForeground"] = Preferences.getUI(
250 "NotificationCriticalForeground") 266 "NotificationCriticalForeground"
267 )
251 self.__colors["NotificationCriticalBackground"] = Preferences.getUI( 268 self.__colors["NotificationCriticalBackground"] = Preferences.getUI(
252 "NotificationCriticalBackground") 269 "NotificationCriticalBackground"
270 )
253 self.criticalFrame.setStyleSheet( 271 self.criticalFrame.setStyleSheet(
254 NotificationFrame.NotificationStyleSheetTemplate.format( 272 NotificationFrame.NotificationStyleSheetTemplate.format(
255 self.__colors["NotificationCriticalForeground"], 273 self.__colors["NotificationCriticalForeground"],
256 self.__colors["NotificationCriticalBackground"] 274 self.__colors["NotificationCriticalBackground"],
257 ) 275 )
258 ) 276 )
259 277
260 @pyqtSlot() 278 @pyqtSlot()
261 def on_criticalDefaultButton_clicked(self): 279 def on_criticalDefaultButton_clicked(self):
262 """ 280 """
263 Private slot to reset the colors for critical notifications to their 281 Private slot to reset the colors for critical notifications to their
264 default values. 282 default values.
265 """ 283 """
266 self.__colors["NotificationCriticalForeground"] = ( 284 self.__colors["NotificationCriticalForeground"] = Preferences.Prefs.uiDefaults[
267 Preferences.Prefs.uiDefaults["NotificationCriticalForeground"]) 285 "NotificationCriticalForeground"
268 self.__colors["NotificationCriticalBackground"] = ( 286 ]
269 Preferences.Prefs.uiDefaults["NotificationCriticalBackground"]) 287 self.__colors["NotificationCriticalBackground"] = Preferences.Prefs.uiDefaults[
288 "NotificationCriticalBackground"
289 ]
270 self.criticalFrame.setStyleSheet( 290 self.criticalFrame.setStyleSheet(
271 NotificationFrame.NotificationStyleSheetTemplate.format( 291 NotificationFrame.NotificationStyleSheetTemplate.format(
272 self.__colors["NotificationCriticalForeground"], 292 self.__colors["NotificationCriticalForeground"],
273 self.__colors["NotificationCriticalBackground"] 293 self.__colors["NotificationCriticalBackground"],
274 ) 294 )
275 ) 295 )
276 296
277 297
278 def create(dlg): 298 def create(dlg):
279 """ 299 """
280 Module function to create the configuration page. 300 Module function to create the configuration page.
281 301
282 @param dlg reference to the configuration dialog 302 @param dlg reference to the configuration dialog
283 @return reference to the instantiated page (ConfigurationPageBase) 303 @return reference to the instantiated page (ConfigurationPageBase)
284 """ 304 """
285 page = NotificationsPage() 305 page = NotificationsPage()
286 return page 306 return page

eric ide

mercurial