Mon, 25 Mar 2013 03:11:06 +0100
Script changes: Future import added, super calls modified and unicode behavior for str.
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 | |
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
|
10 | from __future__ import unicode_literals # __IGNORE_WARNING__ |
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 | |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | @param parent reference to the parent widget (QWidget) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | """ |
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
|
32 | super(NotificationsPage, self).__init__() |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | self.setupUi(self) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | self.setObjectName("NotificationsPage") |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | |
2224
c681f765d64d
Fixed an issue configuring the notification position on multi screen computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2190
diff
changeset
|
36 | 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
|
37 | 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
|
38 | 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
|
39 | 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
|
40 | 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
|
41 | 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
|
42 | 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
|
43 | 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
|
44 | 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
|
45 | 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
|
46 | 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
|
47 | 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
|
48 | self.ySpinBox.setMaximum(maxY) |
2190
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 | self.__notification = None |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | # set initial values |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | 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
|
54 | 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
|
55 | point = Preferences.getUI("NotificationPosition") |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | self.xSpinBox.setValue(point.x()) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | self.ySpinBox.setValue(point.y()) |
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 | def save(self): |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | 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
|
62 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | 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
|
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 |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | 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
|
78 | 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
|
79 | 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
|
80 | 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
|
81 | " 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
|
82 | 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
|
83 | self.__notification.show() |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | else: |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | # retrieve the position |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | point = self.__notification.frameGeometry().topLeft() |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | self.xSpinBox.setValue(point.x()) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | self.ySpinBox.setValue(point.y()) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | self.__notification.close() |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | self.__notification = None |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | |
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 | def create(dlg): |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | 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
|
96 | |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | @param dlg reference to the configuration dialog |
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 | page = NotificationsPage() |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | return page |