Thu, 03 Apr 2014 23:05:31 +0200
Merge with default branch.
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 | |
3160
209a07d7e401
Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3010
diff
changeset
|
3 | # Copyright (c) 2012 - 2014 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 | |
3145
a9de05d4a22f
# __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3057
diff
changeset
|
10 | from __future__ import unicode_literals |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2408
diff
changeset
|
11 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | 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
|
13 | from PyQt4.QtGui import QApplication |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | from .ConfigurationPageBase import ConfigurationPageBase |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | 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
|
17 | |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | import Preferences |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | import UI.PixmapCache |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | |
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 NotificationsPage(ConfigurationPageBase, Ui_NotificationsPage): |
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 | 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
|
25 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | def __init__(self): |
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 | Constructor |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | """ |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2408
diff
changeset
|
30 | super(NotificationsPage, self).__init__() |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | self.setupUi(self) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | self.setObjectName("NotificationsPage") |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | |
2224
c681f765d64d
Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2190
diff
changeset
|
34 | 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
|
35 | 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
|
36 | 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
|
37 | 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
|
38 | 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
|
39 | 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
|
40 | 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
|
41 | 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
|
42 | 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
|
43 | 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
|
44 | 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
|
45 | 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
|
46 | self.ySpinBox.setMaximum(maxY) |
2190
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 | self.__notification = None |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | # set initial values |
3010
befeff46ec0f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2964
diff
changeset
|
51 | self.enableCheckBox.setChecked( |
befeff46ec0f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2964
diff
changeset
|
52 | Preferences.getUI("NotificationsEnabled")) |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | 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
|
54 | point = Preferences.getUI("NotificationPosition") |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | self.xSpinBox.setValue(point.x()) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | self.ySpinBox.setValue(point.y()) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | def save(self): |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | 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
|
61 | """ |
3010
befeff46ec0f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2964
diff
changeset
|
62 | Preferences.setUI( |
befeff46ec0f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2964
diff
changeset
|
63 | "NotificationsEnabled", self.enableCheckBox.isChecked()) |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | 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
|
65 | Preferences.setUI("NotificationPosition", QPoint( |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | 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
|
67 | |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | @pyqtSlot(bool) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | 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
|
70 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | 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
|
72 | |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | @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
|
74 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | if checked: |
2408
dc3a7c9d8f6e
Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
76 | from UI.NotificationWidget import NotificationWidget |
3010
befeff46ec0f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2964
diff
changeset
|
77 | self.__notification = NotificationWidget( |
befeff46ec0f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2964
diff
changeset
|
78 | parent=self, setPosition=True) |
befeff46ec0f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2964
diff
changeset
|
79 | self.__notification.setPixmap( |
befeff46ec0f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2964
diff
changeset
|
80 | UI.PixmapCache.getPixmap("notification48.png")) |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
81 | self.__notification.setHeading(self.tr("Visual Selection")) |
3010
befeff46ec0f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2964
diff
changeset
|
82 | self.__notification.setText( |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
83 | self.tr("Drag the notification window to" |
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
84 | " the desired place and release the button.")) |
3010
befeff46ec0f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2964
diff
changeset
|
85 | self.__notification.move( |
befeff46ec0f
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2964
diff
changeset
|
86 | QPoint(self.xSpinBox.value(), self.ySpinBox.value())) |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | self.__notification.show() |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | else: |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | # retrieve the position |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | point = self.__notification.frameGeometry().topLeft() |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | self.xSpinBox.setValue(point.x()) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | self.ySpinBox.setValue(point.y()) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | self.__notification.close() |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | self.__notification = None |
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 | |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | def create(dlg): |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | 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
|
100 | |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | @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
|
102 | @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
|
103 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | page = NotificationsPage() |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | return page |