5 |
5 |
6 """ |
6 """ |
7 Module implementing a Notification widget. |
7 Module implementing a Notification widget. |
8 """ |
8 """ |
9 |
9 |
10 from enum import Enum |
|
11 import contextlib |
10 import contextlib |
|
11 import enum |
12 |
12 |
13 from PyQt5.QtCore import Qt, QTimer, QPoint |
13 from PyQt5.QtCore import Qt, QTimer, QPoint |
14 from PyQt5.QtWidgets import QFrame, QWidget, QVBoxLayout |
14 from PyQt5.QtWidgets import QFrame, QWidget, QVBoxLayout |
15 |
15 |
16 from .Ui_NotificationFrame import Ui_NotificationFrame |
16 from .Ui_NotificationFrame import Ui_NotificationFrame |
18 import Globals |
18 import Globals |
19 import Preferences |
19 import Preferences |
20 import UI.PixmapCache |
20 import UI.PixmapCache |
21 |
21 |
22 |
22 |
23 class NotificationTypes(Enum): |
23 class NotificationTypes(enum.Enum): |
24 """ |
24 """ |
25 Class implementing the notification types. |
25 Class implementing the notification types. |
26 """ |
26 """ |
27 Information = 0 |
27 INFORMATION = 0 |
28 Warning = 1 # __IGNORE_WARNING_M131__ |
28 WARNING = 1 |
29 Critical = 2 |
29 CRITICAL = 2 |
30 Other = 99 |
30 OTHER = 99 |
31 |
31 |
32 |
32 |
33 class NotificationFrame(QFrame, Ui_NotificationFrame): |
33 class NotificationFrame(QFrame, Ui_NotificationFrame): |
34 """ |
34 """ |
35 Class implementing a Notification widget. |
35 Class implementing a Notification widget. |
36 """ |
36 """ |
37 NotificationStyleSheetTemplate = "color:{0};background-color:{1};" |
37 NotificationStyleSheetTemplate = "color:{0};background-color:{1};" |
38 |
38 |
39 def __init__(self, icon, heading, text, |
39 def __init__(self, icon, heading, text, |
40 kind=NotificationTypes.Information, parent=None): |
40 kind=NotificationTypes.INFORMATION, parent=None): |
41 """ |
41 """ |
42 Constructor |
42 Constructor |
43 |
43 |
44 @param icon icon to be used |
44 @param icon icon to be used |
45 @type QPixmap |
45 @type QPixmap |
80 @param kind notification kind |
80 @param kind notification kind |
81 @type NotificationTypes |
81 @type NotificationTypes |
82 @return icon for the notification kind |
82 @return icon for the notification kind |
83 @rtype QPixmap |
83 @rtype QPixmap |
84 """ |
84 """ |
85 if kind == NotificationTypes.Critical: |
85 if kind == NotificationTypes.CRITICAL: |
86 return UI.PixmapCache.getPixmap("notificationCritical48") |
86 return UI.PixmapCache.getPixmap("notificationCritical48") |
87 elif kind == NotificationTypes.Warning: |
87 elif kind == NotificationTypes.WARNING: # __NO-TASK__ |
88 return UI.PixmapCache.getPixmap("notificationWarning48") |
88 return UI.PixmapCache.getPixmap("notificationWarning48") |
89 elif kind == NotificationTypes.Information: |
89 elif kind == NotificationTypes.INFORMATION: |
90 return UI.PixmapCache.getPixmap("notificationInformation48") |
90 return UI.PixmapCache.getPixmap("notificationInformation48") |
91 else: |
91 else: |
92 return UI.PixmapCache.getPixmap("notification48") |
92 return UI.PixmapCache.getPixmap("notification48") |
93 |
93 |
94 @classmethod |
94 @classmethod |
99 @param kind notification kind |
99 @param kind notification kind |
100 @type NotificationTypes |
100 @type NotificationTypes |
101 @return string containing the style sheet for the notification kind |
101 @return string containing the style sheet for the notification kind |
102 @rtype str |
102 @rtype str |
103 """ |
103 """ |
104 if kind == NotificationTypes.Critical: |
104 if kind == NotificationTypes.CRITICAL: |
105 return NotificationFrame.NotificationStyleSheetTemplate.format( |
105 return NotificationFrame.NotificationStyleSheetTemplate.format( |
106 Preferences.getUI("NotificationCriticalForeground"), |
106 Preferences.getUI("NotificationCriticalForeground"), |
107 Preferences.getUI("NotificationCriticalBackground") |
107 Preferences.getUI("NotificationCriticalBackground") |
108 ) |
108 ) |
109 elif kind == NotificationTypes.Warning: |
109 elif kind == NotificationTypes.WARNING: # __NO-TASK__ |
110 return NotificationFrame.NotificationStyleSheetTemplate.format( |
110 return NotificationFrame.NotificationStyleSheetTemplate.format( |
111 Preferences.getUI("NotificationWarningForeground"), |
111 Preferences.getUI("NotificationWarningForeground"), |
112 Preferences.getUI("NotificationWarningBackground") |
112 Preferences.getUI("NotificationWarningBackground") |
113 ) |
113 ) |
114 else: |
114 else: |
154 |
154 |
155 if self.__settingPosition: |
155 if self.__settingPosition: |
156 self.setCursor(Qt.CursorShape.OpenHandCursor) |
156 self.setCursor(Qt.CursorShape.OpenHandCursor) |
157 |
157 |
158 def showNotification(self, icon, heading, text, |
158 def showNotification(self, icon, heading, text, |
159 kind=NotificationTypes.Information, timeout=0): |
159 kind=NotificationTypes.INFORMATION, timeout=0): |
160 """ |
160 """ |
161 Public method to show a notification. |
161 Public method to show a notification. |
162 |
162 |
163 @param icon icon to be used |
163 @param icon icon to be used |
164 @type QPixmap |
164 @type QPixmap |