|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Notifications configuration page. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot, QPoint |
|
11 from PyQt4.QtGui import QApplication |
|
12 |
|
13 from .ConfigurationPageBase import ConfigurationPageBase |
|
14 from .Ui_NotificationsPage import Ui_NotificationsPage |
|
15 |
|
16 from UI.NotificationWidget import NotificationWidget |
|
17 |
|
18 import Preferences |
|
19 import UI.PixmapCache |
|
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 @param parent reference to the parent widget (QWidget) |
|
31 """ |
|
32 super().__init__() |
|
33 self.setupUi(self) |
|
34 self.setObjectName("NotificationsPage") |
|
35 |
|
36 geom = QApplication.desktop().availableGeometry() |
|
37 self.xSpinBox.setMaximum(geom.width()) |
|
38 self.ySpinBox.setMaximum(geom.height()) |
|
39 |
|
40 self.__notification = None |
|
41 |
|
42 # set initial values |
|
43 self.enableCheckBox.setChecked(Preferences.getUI("NotificationsEnabled")) |
|
44 self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout")) |
|
45 point = Preferences.getUI("NotificationPosition") |
|
46 self.xSpinBox.setValue(point.x()) |
|
47 self.ySpinBox.setValue(point.y()) |
|
48 |
|
49 def save(self): |
|
50 """ |
|
51 Public slot to save the Notifications configuration. |
|
52 """ |
|
53 Preferences.setUI("NotificationsEnabled", self.enableCheckBox.isChecked()) |
|
54 Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value()) |
|
55 Preferences.setUI("NotificationPosition", QPoint( |
|
56 self.xSpinBox.value(), self.ySpinBox.value())) |
|
57 |
|
58 @pyqtSlot(bool) |
|
59 def on_visualButton_clicked(self, checked): |
|
60 """ |
|
61 Private slot to select the position visually. |
|
62 |
|
63 @param checked state of the button (boolean) |
|
64 """ |
|
65 if checked: |
|
66 self.__notification = NotificationWidget(parent=self, setPosition=True) |
|
67 self.__notification.setPixmap(UI.PixmapCache.getPixmap("notification48.png")) |
|
68 self.__notification.setHeading(self.trUtf8("Visual Selection")) |
|
69 self.__notification.setText(self.trUtf8("Drag the notification window to" |
|
70 " the desired place and release the button.")) |
|
71 self.__notification.move(QPoint(self.xSpinBox.value(), self.ySpinBox.value())) |
|
72 self.__notification.show() |
|
73 else: |
|
74 # retrieve the position |
|
75 point = self.__notification.frameGeometry().topLeft() |
|
76 self.xSpinBox.setValue(point.x()) |
|
77 self.ySpinBox.setValue(point.y()) |
|
78 self.__notification.close() |
|
79 self.__notification = None |
|
80 |
|
81 |
|
82 def create(dlg): |
|
83 """ |
|
84 Module function to create the configuration page. |
|
85 |
|
86 @param dlg reference to the configuration dialog |
|
87 """ |
|
88 page = NotificationsPage() |
|
89 return page |