eric6/UI/NotificationWidget.py

Fri, 22 Jan 2021 14:14:15 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 22 Jan 2021 14:14:15 +0100
changeset 7997
2ca23396c25c
parent 7996
ce1d288659ae
child 8143
2c730d5fd177
permissions
-rw-r--r--

Another modifications to prevent an exception in certain situations.

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(
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
58 self.verticalLayout, Qt.AlignLeft | Qt.AlignVCenter)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
59
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
60 self.setStyleSheet(NotificationFrame.getStyleSheet(kind))
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
61
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
62 if icon is None:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
63 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
64 self.icon.setPixmap(icon)
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
65
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.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
67 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
68
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.show()
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.adjustSize()
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
71
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
72 @classmethod
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
73 def getIcon(cls, kind):
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
74 """
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
75 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
76
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
77 @param kind notification kind
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
78 @type NotificationTypes
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
79 @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
80 @rtype QPixmap
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
81 """
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
82 if kind == NotificationTypes.Critical:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
83 return UI.PixmapCache.getPixmap("notificationCritical48")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
84 elif kind == NotificationTypes.Warning:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
85 return UI.PixmapCache.getPixmap("notificationWarning48")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
86 elif kind == NotificationTypes.Information:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
87 return UI.PixmapCache.getPixmap("notificationInformation48")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
88 else:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
89 return UI.PixmapCache.getPixmap("notification48")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
90
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
91 @classmethod
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
92 def getStyleSheet(cls, kind):
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
93 """
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
94 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
95
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
96 @param kind notification kind
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
97 @type NotificationTypes
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
98 @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
99 @rtype str
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
100 """
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
101 if kind == NotificationTypes.Critical:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
102 return NotificationFrame.NotificationStyleSheetTemplate.format(
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
103 Preferences.getUI("NotificationCriticalForeground"),
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
104 Preferences.getUI("NotificationCriticalBackground")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
105 )
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
106 elif kind == NotificationTypes.Warning:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
107 return NotificationFrame.NotificationStyleSheetTemplate.format(
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
108 Preferences.getUI("NotificationWarningForeground"),
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
109 Preferences.getUI("NotificationWarningBackground")
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
110 )
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
111 else:
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
112 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
113
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
114
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
115 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
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 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
118 """
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 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
120 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 Constructor
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
123 @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
124 @type QWidget
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 @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
126 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
127 @type bool
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 """
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
129 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
130
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
131 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
132 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
133 self.setLayout(self.__layout)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 self.__timeout = 5000
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 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
137 self.__timers = {}
7996
ce1d288659ae Slight modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7961
diff changeset
138 self.__notifications = []
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 self.__settingPosition = setPosition
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
142 flags = (
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
143 Qt.Tool |
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
144 Qt.FramelessWindowHint |
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
145 Qt.WindowStaysOnTopHint |
3039
8dd0165d805d Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3012
diff changeset
146 Qt.X11BypassWindowManagerHint
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
147 )
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 if Globals.isWindowsPlatform():
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 flags |= Qt.ToolTip
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 self.setWindowFlags(flags)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 if self.__settingPosition:
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 self.setCursor(Qt.OpenHandCursor)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
155 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
156 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
157 """
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
158 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
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 @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
161 @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
162 @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
163 @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
164 @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
165 @type str
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
166 @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
167 @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
168 @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
169 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
170 @type int
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
172 notificationFrame = NotificationFrame(
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
173 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
174 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
175 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
176
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
177 self.show()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
7952
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.__adjustSizeAndPosition()
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 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
182 timer = QTimer()
7996
ce1d288659ae Slight modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7961
diff changeset
183 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
184 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
185 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
186 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
187 )
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
188 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
189 timer.start()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
191 def __adjustSizeAndPosition(self):
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 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
194 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
195 self.adjustSize()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 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
198 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
199 try:
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
200 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
201 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
202 # < 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
203 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
204 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
205 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
206
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 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
215 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
216 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
217
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
218 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
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 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
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 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
223
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
224 @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
225 @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
226 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
227 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
228
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
229 # 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
230 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
231 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
232 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
233 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
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 # 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
236 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
237 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
238 try:
2ca23396c25c Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7996
diff changeset
239 self.__notifications.remove(notification)
2ca23396c25c Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7996
diff changeset
240 notification.deleteLater()
2ca23396c25c Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7996
diff changeset
241 except ValueError:
2ca23396c25c Another modifications to prevent an exception in certain situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7996
diff changeset
242 # 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
243 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
244
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
245 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
246 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
247 else:
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
248 self.hide()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 def mousePressEvent(self, evt):
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 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
253
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 @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
255 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 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
257 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
258 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
259 self.__removeNotification(clickedNotification)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 return
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 if evt.button() == Qt.LeftButton:
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
263 self.__dragPosition = (
3012
d177226027e2 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
264 evt.globalPos() - self.frameGeometry().topLeft()
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
265 )
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 self.setCursor(Qt.ClosedHandCursor)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 evt.accept()
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 def mouseReleaseEvent(self, evt):
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 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
272
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 @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
274 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 if self.__settingPosition and evt.button() == Qt.LeftButton:
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 self.setCursor(Qt.OpenHandCursor)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 def mouseMoveEvent(self, evt):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 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
281
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 @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
283 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 if evt.buttons() & Qt.LeftButton:
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 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
286 evt.accept()

eric ide

mercurial