6 """ |
6 """ |
7 Module implementing dialog-like popup that displays messages without |
7 Module implementing dialog-like popup that displays messages without |
8 interrupting the user. |
8 interrupting the user. |
9 """ |
9 """ |
10 |
10 |
|
11 import enum |
|
12 |
11 from PyQt5.QtCore import pyqtSignal, Qt, QTimer, QPoint, QRect |
13 from PyQt5.QtCore import pyqtSignal, Qt, QTimer, QPoint, QRect |
12 from PyQt5.QtWidgets import QFrame, QVBoxLayout, QApplication |
14 from PyQt5.QtWidgets import QFrame, QVBoxLayout, QApplication |
13 |
15 |
14 |
16 |
|
17 class E5PassivePopupStyle(enum.Enum): |
|
18 """ |
|
19 Class defining the popup styles. |
|
20 """ |
|
21 BOXED = 0 # box with no shadow |
|
22 STYLED = 1 # styled panel with no shadow |
|
23 CUSTOM = 128 # reserved for extensions |
|
24 |
|
25 |
15 class E5PassivePopup(QFrame): |
26 class E5PassivePopup(QFrame): |
16 """ |
27 """ |
17 Class implementing dialog-like popup that displays messages without |
28 Class implementing dialog-like popup that displays messages without |
18 interrupting the user. |
29 interrupting the user. |
19 |
30 |
20 @signal clicked emitted to indicate a mouse button click |
31 @signal clicked emitted to indicate a mouse button click |
21 """ |
32 """ |
22 # TODO: covert to Enum |
33 DefaultPopupTime = 6 * 1000 # time im milliseconds |
23 Boxed = 0 |
|
24 Custom = 128 |
|
25 |
34 |
26 clicked = pyqtSignal((), (QPoint, )) |
35 clicked = pyqtSignal((), (QPoint, )) |
27 |
36 |
28 def __init__(self, parent=None): |
37 def __init__(self, style=E5PassivePopupStyle.BOXED, parent=None): |
29 """ |
38 """ |
30 Constructor |
39 Constructor |
31 |
40 |
32 @param parent reference to the parent widget (QWidget) |
41 @param style style of the popup |
|
42 @type E5PassivePopupStyle |
|
43 @param parent reference to the parent widget |
|
44 @type QWidget |
33 """ |
45 """ |
34 super().__init__(None) |
46 super().__init__(None) |
35 |
47 |
36 self.__popupStyle = DEFAULT_POPUP_TYPE |
|
37 self.__msgView = None |
48 self.__msgView = None |
38 self.__topLayout = None |
49 self.__topLayout = None |
39 self.__hideDelay = DEFAULT_POPUP_TIME |
50 self.__hideDelay = E5PassivePopup.DefaultPopupTime |
40 self.__hideTimer = QTimer(self) |
51 self.__hideTimer = QTimer(self) |
41 self.__autoDelete = False |
52 self.__autoDelete = False |
42 self.__fixedPosition = QPoint() |
53 self.__fixedPosition = QPoint() |
43 |
54 |
44 self.setWindowFlags(POPUP_FLAGS) |
55 self.setWindowFlags(Qt.WindowFlags( |
45 self.setFrameStyle(QFrame.Shape.Box | QFrame.Shadow.Plain) |
56 Qt.WindowType.Tool | |
|
57 Qt.WindowType.X11BypassWindowManagerHint | |
|
58 Qt.WindowType.WindowStaysOnTopHint | |
|
59 Qt.WindowType.FramelessWindowHint |
|
60 )) |
|
61 if style == E5PassivePopupStyle.STYLED: |
|
62 self.setFrameStyle(QFrame.Shape.StyledPanel | QFrame.Shadow.Plain) |
|
63 else: |
|
64 # default style is Boxed - Plain |
|
65 self.setFrameStyle(QFrame.Shape.Box | QFrame.Shadow.Plain) |
46 self.setLineWidth(2) |
66 self.setLineWidth(2) |
47 self.__hideTimer.timeout.connect(self.hide) |
67 self.__hideTimer.timeout.connect(self.hide) |
48 self.clicked.connect(self.hide) |
68 self.clicked.connect(self.hide) |
49 |
69 |
50 self.__customData = {} # dictionary to store some custom data |
70 self.__customData = {} # dictionary to store some custom data |