eric6/UI/NotificationWidget.py

Tue, 02 Mar 2021 17:17:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 02 Mar 2021 17:17:09 +0100
changeset 8143
2c730d5fd177
parent 7997
2ca23396c25c
child 8154
5f4b02eefc32
permissions
-rw-r--r--

Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.

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
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2012 - 2021 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
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
10 from enum import Enum
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
11
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
12 from PyQt5.QtCore import Qt, QTimer, 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
13 from PyQt5.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
14
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
15 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
16
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 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
18 import Preferences
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
19 import UI.PixmapCache
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
7956
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
21
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
22 class NotificationTypes(Enum):
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
23 """
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
24 Class implementing the notification types.
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
25 """
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
26 Information = 0
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
27 Warning = 1 # __IGNORE_WARNING_M131__
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
28 Critical = 2
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
29 Other = 99
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
30
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
31
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
32 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
33 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 Class implementing a Notification widget.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
36 NotificationStyleSheetTemplate = "color:{0};background-color:{1};"
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
37
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
38 def __init__(self, icon, heading, text,
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
39 kind=NotificationTypes.Information, parent=None):
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
40 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
41 Constructor
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
42
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
43 @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
44 @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
45 @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
46 @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
47 @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
48 @type str
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
49 @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
50 @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
51 @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
52 @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
53 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
54 super(NotificationFrame, self).__init__(parent)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
55 self.setupUi(self)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
56
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
57 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
58 self.verticalLayout,
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
59 Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter
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
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
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
62 self.setStyleSheet(NotificationFrame.getStyleSheet(kind))
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
63
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
64 if icon is None:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
65 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
66 self.icon.setPixmap(icon)
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
67
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
68 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
69 self.text.setText(text)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
70
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
71 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
72 self.adjustSize()
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
73
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
74 @classmethod
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
75 def getIcon(cls, kind):
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
76 """
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
77 Class method to get the icon for a specific notification kind.
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
78
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
79 @param kind notification kind
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
80 @type NotificationTypes
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
81 @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
82 @rtype QPixmap
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
83 """
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
84 if kind == NotificationTypes.Critical:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
85 return UI.PixmapCache.getPixmap("notificationCritical48")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
86 elif kind == NotificationTypes.Warning:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
87 return UI.PixmapCache.getPixmap("notificationWarning48")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
88 elif kind == NotificationTypes.Information:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
89 return UI.PixmapCache.getPixmap("notificationInformation48")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
90 else:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
91 return UI.PixmapCache.getPixmap("notification48")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
92
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
93 @classmethod
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
94 def getStyleSheet(cls, kind):
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
95 """
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
96 Class method to get a style sheet for specific notification kind.
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
97
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
98 @param kind notification kind
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
99 @type NotificationTypes
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
100 @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
101 @rtype str
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
102 """
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
103 if kind == NotificationTypes.Critical:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
104 return NotificationFrame.NotificationStyleSheetTemplate.format(
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
105 Preferences.getUI("NotificationCriticalForeground"),
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
106 Preferences.getUI("NotificationCriticalBackground")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
107 )
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
108 elif kind == NotificationTypes.Warning:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
109 return NotificationFrame.NotificationStyleSheetTemplate.format(
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
110 Preferences.getUI("NotificationWarningForeground"),
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
111 Preferences.getUI("NotificationWarningBackground")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
112 )
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
113 else:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
114 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
115
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
116
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
117 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
118 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
119 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
120 """
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 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
122 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 Constructor
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
125 @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
126 @type QWidget
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 @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
128 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
129 @type bool
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
131 super(NotificationWidget, self).__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
132
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
133 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
134 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
135 self.setLayout(self.__layout)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 self.__timeout = 5000
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 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
139 self.__timers = {}
7996
ce1d288659ae Slight modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7961
diff changeset
140 self.__notifications = []
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 self.__settingPosition = setPosition
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
144 flags = (
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
145 Qt.WindowType.Tool |
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
146 Qt.WindowType.FramelessWindowHint |
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
147 Qt.WindowType.WindowStaysOnTopHint |
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
148 Qt.WindowType.X11BypassWindowManagerHint
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
149 )
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 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
151 flags |= Qt.WindowType.ToolTip
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 self.setWindowFlags(flags)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 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
155 self.setCursor(Qt.CursorShape.OpenHandCursor)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
157 def showNotification(self, icon, heading, text,
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
158 kind=NotificationTypes.Information, timeout=0):
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
160 Public method to show a notification.
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
162 @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
163 @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
164 @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
165 @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
166 @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
167 @type str
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
168 @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
169 @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
170 @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
171 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
172 @type int
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 """
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
174 notificationFrame = NotificationFrame(
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
175 icon, heading, text, kind=kind, parent=self)
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 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
177 self.__notifications.append(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
178
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
179 self.show()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
181 self.__adjustSizeAndPosition()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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 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
184 timer = QTimer()
7996
ce1d288659ae Slight modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7961
diff changeset
185 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
186 timer.setSingleShot(True)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
187 timer.timeout.connect(
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
188 lambda: self.__removeNotification(notificationFrame)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
189 )
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
190 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
191 timer.start()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192
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 def __adjustSizeAndPosition(self):
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 """
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 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
196 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
197 self.adjustSize()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 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
200 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
201 try:
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
202 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
203 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
204 # < Qt 5.15
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
205 from PyQt5.QtGui import QGuiApplication
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
206 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
207 screenGeom = screen.geometry()
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
208
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
209 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
210 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
211 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
212 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
213 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
214 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
215 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
216 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
217 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
218 newY = screenGeom.height() - self.height()
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
219
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
220 self.move(newX, newY)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
221
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
222 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
223 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
224 Private method to remove a notification from the list.
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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 @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
227 @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
228 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
229 notification.hide()
3366
6084bb3c3911 Made some changes to have a bunch of dialogs with correct sizes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
230
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
231 # 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
232 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
233 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
234 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
235 del self.__timers[key]
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
236
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 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
238 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
239 self.__layout.takeAt(index)
7997
2ca23396c25c Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7996
diff changeset
240 try:
2ca23396c25c Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7996
diff changeset
241 self.__notifications.remove(notification)
2ca23396c25c Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7996
diff changeset
242 notification.deleteLater()
2ca23396c25c Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7996
diff changeset
243 except ValueError:
2ca23396c25c Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7996
diff changeset
244 # it was already delete by other method; ignore
2ca23396c25c Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7996
diff changeset
245 pass
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
246
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
247 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
248 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
249 else:
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
250 self.hide()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 def mousePressEvent(self, evt):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 Protected method to handle presses of a mouse button.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 @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
257 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 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
259 clickedLabel = self.childAt(evt.pos())
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
260 clickedNotification = clickedLabel.parent()
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
261 self.__removeNotification(clickedNotification)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 return
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263
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
264 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
265 self.__dragPosition = (
3012
d177226027e2 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
266 evt.globalPos() - self.frameGeometry().topLeft()
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
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 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
269 evt.accept()
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 def mouseReleaseEvent(self, evt):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 Protected method to handle releases of a mouse button.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 @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
276 """
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
277 if (
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
278 self.__settingPosition and
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
279 evt.button() == Qt.MouseButton.LeftButton
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
280 ):
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
281 self.setCursor(Qt.CursorShape.OpenHandCursor)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 def mouseMoveEvent(self, evt):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 Protected method to handle dragging the window.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 @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
288 """
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
289 if evt.buttons() & Qt.MouseButton.LeftButton:
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 self.move(evt.globalPos() - self.__dragPosition)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 evt.accept()

eric ide

mercurial