eric6/E5Gui/E5PassivePopup.py

changeset 8269
87f521f359d5
parent 8268
6b8128e0c9d1
equal deleted inserted replaced
8268:6b8128e0c9d1 8269:87f521f359d5
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
88 self.move(self.__fixedPosition) 108 self.move(self.__fixedPosition)
89 super().setVisible(True) 109 super().setVisible(True)
90 110
91 delay = self.__hideDelay 111 delay = self.__hideDelay
92 if delay < 0: 112 if delay < 0:
93 delay = DEFAULT_POPUP_TIME 113 delay = E5PassivePopup.DefaultPopupTime
94 if delay > 0: 114 if delay > 0:
95 self.__hideTimer.start(delay) 115 self.__hideTimer.start(delay)
96 116
97 def show(self, p=None): 117 def show(self, p=None):
98 """ 118 """
116 """ 136 """
117 self.__hideDelay = delay 137 self.__hideDelay = delay
118 if self.__hideTimer.isActive(): 138 if self.__hideTimer.isActive():
119 if delay: 139 if delay:
120 if delay == -1: 140 if delay == -1:
121 delay = DEFAULT_POPUP_TIME 141 delay = E5PassivePopup.DefaultPopupTime
122 self.__hideTimer.start(delay) 142 self.__hideTimer.start(delay)
123 else: 143 else:
124 self.__hideTimer.stop() 144 self.__hideTimer.stop()
125 145
126 def timeout(self): 146 def timeout(self):
230 @type str 250 @type str
231 @return stored data 251 @return stored data
232 @rtype any 252 @rtype any
233 """ 253 """
234 return self.__customData[key] 254 return self.__customData[key]
235
236 DEFAULT_POPUP_TYPE = E5PassivePopup.Boxed
237 DEFAULT_POPUP_TIME = 6 * 1000
238 POPUP_FLAGS = Qt.WindowFlags(
239 Qt.WindowType.Tool | Qt.WindowType.X11BypassWindowManagerHint |
240 Qt.WindowType.WindowStaysOnTopHint | Qt.WindowType.FramelessWindowHint)

eric ide

mercurial