eric6/UI/NotificationWidget.py

Mon, 04 Jan 2021 16:52:56 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 04 Jan 2021 16:52:56 +0100
changeset 7956
7db67b70e6a8
parent 7952
1849f61cf2b6
child 7959
44e15eda6506
permissions
-rw-r--r--

Added some TODO comments to enhance the notification widget.

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
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
10 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
11 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
12
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 .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
14
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 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
16 import Preferences
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
7956
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
19 # TODO: add background colors to indicate notification severity
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
20 # - all messages with timeout of 0
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
21 # - standard: information messages
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
22 # - yellow: warning messages
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
23 # - red: critical messages
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
24
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
25 # TODO: add a notification log
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
26 # - date/time and message
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
27 # - display widget with capability to save the messages
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
28 # - optional: display widget with capability to load saved messages
7db67b70e6a8 Added some TODO comments to enhance the notification widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7952
diff changeset
29
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
30 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
31 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Class implementing a Notification widget.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
34 def __init__(self, icon, heading, text, parent=None):
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
35 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
36 Constructor
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
37
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
38 @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
39 @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
40 @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
41 @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
42 @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
43 @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
44 @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
45 @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
46 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
47 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
48 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
49
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
50 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
51 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
52
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
53 self.icon.setPixmap(icon)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
54 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
55 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
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.show()
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.adjustSize()
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
59
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
60
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
61 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
62 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
63 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
64 """
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 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
66 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 Constructor
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
69 @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
70 @type QWidget
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 @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
72 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
73 @type bool
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
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
75 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
76
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
77 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
78 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
79 self.setLayout(self.__layout)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.__timeout = 5000
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 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
83 self.__timers = {}
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.__settingPosition = setPosition
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
87 flags = (
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
88 Qt.Tool |
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
89 Qt.FramelessWindowHint |
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
90 Qt.WindowStaysOnTopHint |
3039
8dd0165d805d Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3012
diff changeset
91 Qt.X11BypassWindowManagerHint
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
92 )
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 if Globals.isWindowsPlatform():
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 flags |= Qt.ToolTip
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.setWindowFlags(flags)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 if self.__settingPosition:
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.setCursor(Qt.OpenHandCursor)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
100 def showNotification(self, icon, heading, text, timeout=0):
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
102 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
103
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
104 @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
105 @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
106 @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
107 @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
108 @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
109 @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
110 @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
111 to be removed (0 = do not remove until it is clicked on)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 """
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 notificationFrame = NotificationFrame(icon, heading, text, self)
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
114 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
115
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
116 self.show()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
118 self.__adjustSizeAndPosition()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
120 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
121 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
122 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
123 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
124 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
125 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
126 )
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
127 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
128 timer.start()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
130 def __adjustSizeAndPosition(self):
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 """
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
132 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
133 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
134 self.adjustSize()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 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
137 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
138 try:
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
139 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
140 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
141 # < 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
142 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
143 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
144 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
145
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
157 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
158
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
159 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
160 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
161 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
162
7952
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 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
164 @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
165 """
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
166 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
167
7952
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
168 # 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
169 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
170 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
171 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
172 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
173
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
174 # 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
175 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
176 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
177 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
178
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
179 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
180 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
181 else:
1849f61cf2b6 Changed the notification widget to be able to show multiple notification simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
182 self.close()
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 def mousePressEvent(self, evt):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 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
187
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 @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
189 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 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
191 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
192 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
193 self.__removeNotification(clickedNotification)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 return
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 if evt.button() == Qt.LeftButton:
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
197 self.__dragPosition = (
3012
d177226027e2 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
198 evt.globalPos() - self.frameGeometry().topLeft()
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
199 )
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 self.setCursor(Qt.ClosedHandCursor)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 evt.accept()
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 def mouseReleaseEvent(self, evt):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 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
206
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 @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
208 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 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
210 self.setCursor(Qt.OpenHandCursor)
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 def mouseMoveEvent(self, evt):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 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
215
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 @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
217 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 if evt.buttons() & Qt.LeftButton:
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 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
220 evt.accept()

eric ide

mercurial