Wed, 13 Jul 2022 14:55:47 +0200
Reformatted the source code using the 'Black' utility.
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 | |
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8319
diff
changeset
|
3 | # Copyright (c) 2012 - 2022 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 a Notification widget. |
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 | |
8243
cc717c2ae956
Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
10 | import contextlib |
8265
0090cfa83159
Converted enum names to use all uppercase letters (except for E5PathPickerModes to keep plug-ins using this compatible with previous eric releases).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
11 | import enum |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
12 | |
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
13 | from PyQt6.QtCore import Qt, QTimer, QPoint |
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
14 | from PyQt6.QtWidgets import QFrame, QWidget, QVBoxLayout |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
16 | from .Ui_NotificationFrame import Ui_NotificationFrame |
2190
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 Globals |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
19 | import Preferences |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
20 | import UI.PixmapCache |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | |
7956
7db67b70e6a8
Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7952
diff
changeset
|
22 | |
8265
0090cfa83159
Converted enum names to use all uppercase letters (except for E5PathPickerModes to keep plug-ins using this compatible with previous eric releases).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
23 | class NotificationTypes(enum.Enum): |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
24 | """ |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
25 | Class implementing the notification types. |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
26 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
27 | |
8265
0090cfa83159
Converted enum names to use all uppercase letters (except for E5PathPickerModes to keep plug-ins using this compatible with previous eric releases).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
28 | INFORMATION = 0 |
0090cfa83159
Converted enum names to use all uppercase letters (except for E5PathPickerModes to keep plug-ins using this compatible with previous eric releases).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
29 | WARNING = 1 |
0090cfa83159
Converted enum names to use all uppercase letters (except for E5PathPickerModes to keep plug-ins using this compatible with previous eric releases).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
30 | CRITICAL = 2 |
0090cfa83159
Converted enum names to use all uppercase letters (except for E5PathPickerModes to keep plug-ins using this compatible with previous eric releases).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
31 | OTHER = 99 |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
32 | |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
33 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
34 | class NotificationFrame(QFrame, Ui_NotificationFrame): |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | Class implementing a Notification widget. |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
38 | |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
39 | NotificationStyleSheetTemplate = "color:{0};background-color:{1};" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
40 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
41 | def __init__( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
42 | self, icon, heading, text, kind=NotificationTypes.INFORMATION, parent=None |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
43 | ): |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
44 | """ |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
45 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
46 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
47 | @param icon icon to be used |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
48 | @type QPixmap |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
49 | @param heading heading to be used |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
50 | @type str |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
51 | @param text text to be used |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
52 | @type str |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
53 | @param kind kind of notification to be shown |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
54 | @type NotificationTypes |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
55 | @param parent reference to the parent widget |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
56 | @type QWidget |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
57 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8154
diff
changeset
|
58 | super().__init__(parent) |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
59 | self.setupUi(self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
60 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
61 | self.layout().setAlignment( |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7997
diff
changeset
|
62 | self.verticalLayout, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
63 | Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter, |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7997
diff
changeset
|
64 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
65 | |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
66 | self.setStyleSheet(NotificationFrame.getStyleSheet(kind)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
67 | |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
68 | if icon is None: |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
69 | icon = NotificationFrame.getIcon(kind) |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
70 | self.icon.setPixmap(icon) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
71 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
72 | self.heading.setText(heading) |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
73 | self.text.setText(text) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
74 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
75 | self.show() |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
76 | self.adjustSize() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
77 | |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
78 | @classmethod |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
79 | def getIcon(cls, kind): |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
80 | """ |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
81 | Class method to get the icon for a specific notification kind. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
83 | @param kind notification kind |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
84 | @type NotificationTypes |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
85 | @return icon for the notification kind |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
86 | @rtype QPixmap |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
87 | """ |
8265
0090cfa83159
Converted enum names to use all uppercase letters (except for E5PathPickerModes to keep plug-ins using this compatible with previous eric releases).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
88 | if kind == NotificationTypes.CRITICAL: |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
89 | return UI.PixmapCache.getPixmap("notificationCritical48") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
90 | elif kind == NotificationTypes.WARNING: # __NO-TASK__ |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
91 | return UI.PixmapCache.getPixmap("notificationWarning48") |
8265
0090cfa83159
Converted enum names to use all uppercase letters (except for E5PathPickerModes to keep plug-ins using this compatible with previous eric releases).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
92 | elif kind == NotificationTypes.INFORMATION: |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
93 | return UI.PixmapCache.getPixmap("notificationInformation48") |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
94 | else: |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
95 | return UI.PixmapCache.getPixmap("notification48") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
96 | |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
97 | @classmethod |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
98 | def getStyleSheet(cls, kind): |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
99 | """ |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
100 | Class method to get a style sheet for specific notification kind. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
101 | |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
102 | @param kind notification kind |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
103 | @type NotificationTypes |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
104 | @return string containing the style sheet for the notification kind |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
105 | @rtype str |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
106 | """ |
8265
0090cfa83159
Converted enum names to use all uppercase letters (except for E5PathPickerModes to keep plug-ins using this compatible with previous eric releases).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8243
diff
changeset
|
107 | if kind == NotificationTypes.CRITICAL: |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
108 | return NotificationFrame.NotificationStyleSheetTemplate.format( |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
109 | Preferences.getUI("NotificationCriticalForeground"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
110 | Preferences.getUI("NotificationCriticalBackground"), |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
111 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
112 | elif kind == NotificationTypes.WARNING: # __NO-TASK__ |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
113 | return NotificationFrame.NotificationStyleSheetTemplate.format( |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
114 | Preferences.getUI("NotificationWarningForeground"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
115 | Preferences.getUI("NotificationWarningBackground"), |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
116 | ) |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
117 | else: |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
118 | return "" |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
119 | |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
120 | |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
121 | class NotificationWidget(QWidget): |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
122 | """ |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
123 | Class implementing a Notification list widget. |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
124 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
125 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | def __init__(self, parent=None, setPosition=False): |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
129 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
130 | @param parent reference to the parent widget |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
131 | @type QWidget |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | @param setPosition flag indicating to set the display |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
133 | position interactively |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
134 | @type bool |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8154
diff
changeset
|
136 | super().__init__(parent) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
137 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
138 | self.__layout = QVBoxLayout(self) |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
139 | self.__layout.setContentsMargins(0, 0, 0, 0) |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
140 | self.setLayout(self.__layout) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
141 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | self.__timeout = 5000 |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | self.__dragPosition = QPoint() |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
144 | self.__timers = {} |
7996
ce1d288659ae
Slight modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7961
diff
changeset
|
145 | self.__notifications = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
146 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | self.__settingPosition = setPosition |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
148 | |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
149 | flags = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
150 | Qt.WindowType.Tool |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
151 | | Qt.WindowType.FramelessWindowHint |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
152 | | Qt.WindowType.WindowStaysOnTopHint |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
153 | | Qt.WindowType.X11BypassWindowManagerHint |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
154 | ) |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | if Globals.isWindowsPlatform(): |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7997
diff
changeset
|
156 | flags |= Qt.WindowType.ToolTip |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | self.setWindowFlags(flags) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
158 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | if self.__settingPosition: |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7997
diff
changeset
|
160 | self.setCursor(Qt.CursorShape.OpenHandCursor) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
161 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
162 | def showNotification( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
163 | self, icon, heading, text, kind=NotificationTypes.INFORMATION, timeout=0 |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
164 | ): |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | """ |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
166 | Public method to show a notification. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
167 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
168 | @param icon icon to be used |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
169 | @type QPixmap |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
170 | @param heading heading to be used |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
171 | @type str |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
172 | @param text text to be used |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
173 | @type str |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
174 | @param kind kind of notification to be shown |
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
175 | @type NotificationTypes |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
176 | @param timeout timeout in seconds after which the notification is |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
177 | to be removed (0 = do not remove until it is clicked on) |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
178 | @type int |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | """ |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
180 | notificationFrame = NotificationFrame( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
181 | icon, heading, text, kind=kind, parent=self |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
182 | ) |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
183 | self.__layout.addWidget(notificationFrame) |
7996
ce1d288659ae
Slight modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7961
diff
changeset
|
184 | self.__notifications.append(notificationFrame) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
185 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
186 | self.show() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
187 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
188 | self.__adjustSizeAndPosition() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
189 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
190 | if timeout: |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
191 | timer = QTimer() |
7996
ce1d288659ae
Slight modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7961
diff
changeset
|
192 | self.__timers[id(notificationFrame)] = timer |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
193 | timer.setSingleShot(True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
194 | timer.timeout.connect(lambda: self.__removeNotification(notificationFrame)) |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
195 | timer.setInterval(timeout * 1000) |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
196 | timer.start() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
197 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
198 | def __adjustSizeAndPosition(self): |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | """ |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
200 | Private slot to adjust the notification list widget size and position. |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
201 | """ |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
202 | self.adjustSize() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
203 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | if not self.__settingPosition: |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
205 | pos = Preferences.getUI("NotificationPosition") |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
206 | try: |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
207 | screen = self.screen() |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
208 | except AttributeError: |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
209 | # < Qt 5.15 |
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
210 | from PyQt6.QtGui import QGuiApplication |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
211 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
212 | screen = QGuiApplication.screenAt(pos) |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
213 | screenGeom = screen.geometry() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
214 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
215 | newX = pos.x() |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
216 | newY = pos.y() |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
217 | if newX < screenGeom.x(): |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
218 | newX = screenGeom.x() |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
219 | if newY < screenGeom.y(): |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
220 | newY = screenGeom.y() |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
221 | if newX + self.width() > screenGeom.width(): |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
222 | newX = screenGeom.width() - self.width() |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
223 | if newY + self.height() > screenGeom.height(): |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
224 | newY = screenGeom.height() - self.height() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
225 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
226 | self.move(newX, newY) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
227 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
228 | def __removeNotification(self, notification): |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
229 | """ |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
230 | Private method to remove a notification from the list. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
231 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
232 | @param notification reference to the notification to be removed |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
233 | @type NotificationFrame |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
234 | """ |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
235 | notification.hide() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
236 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
237 | # delete timer of an auto close notification |
7996
ce1d288659ae
Slight modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7961
diff
changeset
|
238 | key = id(notification) |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
239 | if key in self.__timers: |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
240 | self.__timers[key].stop() |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
241 | del self.__timers[key] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
242 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
243 | # delete the notification |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
244 | index = self.__layout.indexOf(notification) |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
245 | self.__layout.takeAt(index) |
8243
cc717c2ae956
Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
246 | with contextlib.suppress(ValueError): |
7997
2ca23396c25c
Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7996
diff
changeset
|
247 | self.__notifications.remove(notification) |
2ca23396c25c
Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7996
diff
changeset
|
248 | notification.deleteLater() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
249 | |
7952
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
250 | if self.__layout.count(): |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
251 | self.__adjustSizeAndPosition() |
1849f61cf2b6
Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
252 | else: |
7959
44e15eda6506
Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7956
diff
changeset
|
253 | self.hide() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
254 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | def mousePressEvent(self, evt): |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
256 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | Protected method to handle presses of a mouse button. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
258 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | @param evt reference to the mouse event (QMouseEvent) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | if not self.__settingPosition: |
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
262 | clickedLabel = self.childAt(evt.position().toPoint()) |
8154
5f4b02eefc32
NotificationWidget: changed code to prevent a potential exception when the user clicks the widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
263 | if clickedLabel: |
5f4b02eefc32
NotificationWidget: changed code to prevent a potential exception when the user clicks the widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
264 | clickedNotification = clickedLabel.parent() |
5f4b02eefc32
NotificationWidget: changed code to prevent a potential exception when the user clicks the widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
265 | self.__removeNotification(clickedNotification) |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
267 | |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7997
diff
changeset
|
268 | if evt.button() == Qt.MouseButton.LeftButton: |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
269 | self.__dragPosition = ( |
8319
ea11a3948f40
Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
270 | evt.globalPosition().toPoint() - self.frameGeometry().topLeft() |
7264
bedbe458d792
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
271 | ) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7997
diff
changeset
|
272 | self.setCursor(Qt.CursorShape.ClosedHandCursor) |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | evt.accept() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
274 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | def mouseReleaseEvent(self, evt): |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | Protected method to handle releases of a mouse button. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
278 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
279 | @param evt reference to the mouse event (QMouseEvent) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
281 | if self.__settingPosition and evt.button() == Qt.MouseButton.LeftButton: |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7997
diff
changeset
|
282 | self.setCursor(Qt.CursorShape.OpenHandCursor) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
283 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | def mouseMoveEvent(self, evt): |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | """ |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | Protected method to handle dragging the window. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
287 | |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | @param evt reference to the mouse event (QMouseEvent) |
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | """ |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7997
diff
changeset
|
290 | if evt.buttons() & Qt.MouseButton.LeftButton: |
8319
ea11a3948f40
Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
291 | self.move(evt.globalPosition().toPoint() - self.__dragPosition) |
2190
abd65b78425e
Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | evt.accept() |