eric6/UI/NotificationWidget.py

Wed, 06 Jan 2021 13:58:40 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 06 Jan 2021 13:58:40 +0100
changeset 7961
9a11cf4ca0d6
parent 7959
44e15eda6506
child 7996
ce1d288659ae
permissions
-rw-r--r--

NotificationWidget: removed the remaining TODO as it doesn't seem to be of real use.

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 = {}
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 self.__settingPosition = setPosition
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
141 flags = (
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
142 Qt.Tool |
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
143 Qt.FramelessWindowHint |
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
144 Qt.WindowStaysOnTopHint |
3039
8dd0165d805d Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3012
diff changeset
145 Qt.X11BypassWindowManagerHint
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
146 )
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 if Globals.isWindowsPlatform():
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 flags |= Qt.ToolTip
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self.setWindowFlags(flags)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 if self.__settingPosition:
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 self.setCursor(Qt.OpenHandCursor)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
154 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
155 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
156 """
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
157 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
158
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
159 @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
160 @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
161 @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
162 @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
163 @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
164 @type str
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
165 @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
166 @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
167 @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
168 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
169 @type int
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
171 notificationFrame = NotificationFrame(
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
172 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
173 self.__layout.addWidget(notificationFrame)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
174
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
175 self.show()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176
7952
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.__adjustSizeAndPosition()
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 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
180 timer = QTimer()
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.__timers[repr(notificationFrame)] = timer
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.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
183 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
184 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
185 )
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.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
187 timer.start()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
189 def __adjustSizeAndPosition(self):
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 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
192 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
193 self.adjustSize()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 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
196 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
197 try:
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
198 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
199 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
200 # < 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
201 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
202 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
203 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
204
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
205 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
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 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
215
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
216 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
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 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
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 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
221
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
222 @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
223 @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
224 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
225 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
226
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
227 # delete timer of an auto close notification
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
228 key = repr(notification)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
229 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
230 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
231 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
232
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
233 # 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
234 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
235 self.__layout.takeAt(index)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
236 notification.deleteLater()
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
237
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
238 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
239 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
240 else:
7959
44e15eda6506 Improved the Notification system by supporting colored notifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7956
diff changeset
241 self.hide()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 def mousePressEvent(self, evt):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 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
246
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 @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
248 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 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
250 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
251 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
252 self.__removeNotification(clickedNotification)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 return
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 if evt.button() == Qt.LeftButton:
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
256 self.__dragPosition = (
3012
d177226027e2 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
257 evt.globalPos() - self.frameGeometry().topLeft()
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
258 )
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 self.setCursor(Qt.ClosedHandCursor)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 evt.accept()
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 def mouseReleaseEvent(self, evt):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 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
265
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 @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
267 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 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
269 self.setCursor(Qt.OpenHandCursor)
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 mouseMoveEvent(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 dragging the window.
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 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 if evt.buttons() & Qt.LeftButton:
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 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
279 evt.accept()

eric ide

mercurial