eric6/E5Gui/E5PassivePopup.py

changeset 8269
87f521f359d5
parent 8268
6b8128e0c9d1
diff -r 6b8128e0c9d1 -r 87f521f359d5 eric6/E5Gui/E5PassivePopup.py
--- a/eric6/E5Gui/E5PassivePopup.py	Wed Apr 28 19:42:28 2021 +0200
+++ b/eric6/E5Gui/E5PassivePopup.py	Thu Apr 29 17:39:17 2021 +0200
@@ -8,10 +8,21 @@
 interrupting the user.
 """
 
+import enum
+
 from PyQt5.QtCore import pyqtSignal, Qt, QTimer, QPoint, QRect
 from PyQt5.QtWidgets import QFrame, QVBoxLayout, QApplication
 
 
+class E5PassivePopupStyle(enum.Enum):
+    """
+    Class defining the popup styles.
+    """
+    BOXED = 0           # box with no shadow
+    STYLED = 1          # styled panel with no shadow
+    CUSTOM = 128        # reserved for extensions
+
+
 class E5PassivePopup(QFrame):
     """
     Class implementing dialog-like popup that displays messages without
@@ -19,30 +30,39 @@
     
     @signal clicked emitted to indicate a mouse button click
     """
-    # TODO: covert to Enum
-    Boxed = 0
-    Custom = 128
+    DefaultPopupTime = 6 * 1000     # time im milliseconds
     
     clicked = pyqtSignal((), (QPoint, ))
     
-    def __init__(self, parent=None):
+    def __init__(self, style=E5PassivePopupStyle.BOXED, parent=None):
         """
         Constructor
         
-        @param parent reference to the parent widget (QWidget)
+        @param style style of the popup
+        @type E5PassivePopupStyle
+        @param parent reference to the parent widget
+        @type QWidget
         """
         super().__init__(None)
         
-        self.__popupStyle = DEFAULT_POPUP_TYPE
         self.__msgView = None
         self.__topLayout = None
-        self.__hideDelay = DEFAULT_POPUP_TIME
+        self.__hideDelay = E5PassivePopup.DefaultPopupTime
         self.__hideTimer = QTimer(self)
         self.__autoDelete = False
         self.__fixedPosition = QPoint()
         
-        self.setWindowFlags(POPUP_FLAGS)
-        self.setFrameStyle(QFrame.Shape.Box | QFrame.Shadow.Plain)
+        self.setWindowFlags(Qt.WindowFlags(
+            Qt.WindowType.Tool |
+            Qt.WindowType.X11BypassWindowManagerHint |
+            Qt.WindowType.WindowStaysOnTopHint |
+            Qt.WindowType.FramelessWindowHint
+        ))
+        if style == E5PassivePopupStyle.STYLED:
+            self.setFrameStyle(QFrame.Shape.StyledPanel | QFrame.Shadow.Plain)
+        else:
+            # default style is Boxed - Plain
+            self.setFrameStyle(QFrame.Shape.Box | QFrame.Shadow.Plain)
         self.setLineWidth(2)
         self.__hideTimer.timeout.connect(self.hide)
         self.clicked.connect(self.hide)
@@ -90,7 +110,7 @@
         
         delay = self.__hideDelay
         if delay < 0:
-            delay = DEFAULT_POPUP_TIME
+            delay = E5PassivePopup.DefaultPopupTime
         if delay > 0:
             self.__hideTimer.start(delay)
     
@@ -118,7 +138,7 @@
         if self.__hideTimer.isActive():
             if delay:
                 if delay == -1:
-                    delay = DEFAULT_POPUP_TIME
+                    delay = E5PassivePopup.DefaultPopupTime
                 self.__hideTimer.start(delay)
             else:
                 self.__hideTimer.stop()
@@ -232,9 +252,3 @@
         @rtype any
         """
         return self.__customData[key]
-
-DEFAULT_POPUP_TYPE = E5PassivePopup.Boxed
-DEFAULT_POPUP_TIME = 6 * 1000
-POPUP_FLAGS = Qt.WindowFlags(
-    Qt.WindowType.Tool | Qt.WindowType.X11BypassWindowManagerHint |
-    Qt.WindowType.WindowStaysOnTopHint | Qt.WindowType.FramelessWindowHint)

eric ide

mercurial