Preferences/ConfigurationPages/NotificationsPage.py

Sun, 29 Sep 2013 15:54:10 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 29 Sep 2013 15:54:10 +0200
changeset 2964
84b65fb9e780
parent 2408
dc3a7c9d8f6e
child 3010
befeff46ec0f
permissions
-rw-r--r--

Continued correcting doc strings by using the new doc string checker.

2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
2302
f29e9405c851 Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2280
diff changeset
3 # Copyright (c) 2012 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the Notifications configuration page.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt4.QtCore import pyqtSlot, QPoint
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt4.QtGui import QApplication
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from .ConfigurationPageBase import ConfigurationPageBase
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from .Ui_NotificationsPage import Ui_NotificationsPage
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import Preferences
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import UI.PixmapCache
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class implementing the Notifications configuration page.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 def __init__(self):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 super().__init__()
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 self.setupUi(self)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.setObjectName("NotificationsPage")
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
2224
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
32 minX, maxX = self.xSpinBox.maximum(), self.xSpinBox.minimum()
2280
8e85ca3fabe7 Fixed a few PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2224
diff changeset
33 minY, maxY = self.ySpinBox.maximum(), self.ySpinBox.minimum()
2224
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
34 desk = QApplication.desktop()
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
35 for screen in range(desk.screenCount()):
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
36 geom = desk.availableGeometry(screen)
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
37 minX = min(minX, geom.x())
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
38 maxX = max(maxX, geom.x() + geom.width())
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
39 minY = min(minY, geom.y())
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
40 maxY = max(maxY, geom.y() + geom.height())
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
41 self.xSpinBox.setMinimum(minX)
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
42 self.xSpinBox.setMaximum(maxX)
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
43 self.ySpinBox.setMinimum(minY)
c681f765d64d Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2190
diff changeset
44 self.ySpinBox.setMaximum(maxY)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.__notification = None
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 # set initial values
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.enableCheckBox.setChecked(Preferences.getUI("NotificationsEnabled"))
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.timeoutSpinBox.setValue(Preferences.getUI("NotificationTimeout"))
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 point = Preferences.getUI("NotificationPosition")
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.xSpinBox.setValue(point.x())
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.ySpinBox.setValue(point.y())
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 def save(self):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 Public slot to save the Notifications configuration.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 Preferences.setUI("NotificationsEnabled", self.enableCheckBox.isChecked())
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 Preferences.setUI("NotificationTimeout", self.timeoutSpinBox.value())
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 Preferences.setUI("NotificationPosition", QPoint(
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.xSpinBox.value(), self.ySpinBox.value()))
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 @pyqtSlot(bool)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 def on_visualButton_clicked(self, checked):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 Private slot to select the position visually.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @param checked state of the button (boolean)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 if checked:
2408
dc3a7c9d8f6e Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
72 from UI.NotificationWidget import NotificationWidget
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__notification = NotificationWidget(parent=self, setPosition=True)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.__notification.setPixmap(UI.PixmapCache.getPixmap("notification48.png"))
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__notification.setHeading(self.trUtf8("Visual Selection"))
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.__notification.setText(self.trUtf8("Drag the notification window to"
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 " the desired place and release the button."))
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.__notification.move(QPoint(self.xSpinBox.value(), self.ySpinBox.value()))
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.__notification.show()
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 else:
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 # retrieve the position
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 point = self.__notification.frameGeometry().topLeft()
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.xSpinBox.setValue(point.x())
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.ySpinBox.setValue(point.y())
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.__notification.close()
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.__notification = None
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 def create(dlg):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 Module function to create the configuration page.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 @param dlg reference to the configuration dialog
2964
84b65fb9e780 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2408
diff changeset
94 @return reference to the instantiated page (ConfigurationPageBase)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 page = NotificationsPage()
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 return page

eric ide

mercurial