Modernized some more code and marked code to be modernized.

Thu, 29 Apr 2021 17:39:17 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 29 Apr 2021 17:39:17 +0200
changeset 8269
87f521f359d5
parent 8268
6b8128e0c9d1
child 8270
6ba3564b7161

Modernized some more code and marked code to be modernized.

eric6/E5Gui/E5PassivePopup.py file | annotate | diff | comparison | revisions
eric6/E5XML/TasksReader.py file | annotate | diff | comparison | revisions
eric6/E5XML/TasksWriter.py file | annotate | diff | comparison | revisions
eric6/Graphics/UMLDialog.py file | annotate | diff | comparison | revisions
eric6/IconEditor/IconEditorGrid.py file | annotate | diff | comparison | revisions
eric6/Tasks/Task.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/WebBrowserTabBar.py file | annotate | diff | comparison | revisions
--- 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)
--- a/eric6/E5XML/TasksReader.py	Wed Apr 28 19:42:28 2021 +0200
+++ b/eric6/E5XML/TasksReader.py	Thu Apr 29 17:39:17 2021 +0200
@@ -96,6 +96,8 @@
             if isBugfix:
                 task["type"] = Task.TypeFixme
         else:
+            # TODO: task type enum change
+            #  TaskType(int(self.attribute("type", str(Task.TypeTodo.value))))
             task["type"] = int(self.attribute("type", str(Task.TypeTodo)))
         uid = self.attribute("uid", "")
         if uid:
--- a/eric6/E5XML/TasksWriter.py	Wed Apr 28 19:42:28 2021 +0200
+++ b/eric6/E5XML/TasksWriter.py	Thu Apr 29 17:39:17 2021 +0200
@@ -76,6 +76,7 @@
             self.writeStartElement("Task")
             self.writeAttribute("priority", str(task.priority))
             self.writeAttribute("completed", str(task.completed))
+            # TODO: task type enum change; str(task.taskType.value)
             self.writeAttribute("type", str(task.taskType))
             self.writeAttribute("uid", task.uid)
             if task.parentUid:
--- a/eric6/Graphics/UMLDialog.py	Wed Apr 28 19:42:28 2021 +0200
+++ b/eric6/Graphics/UMLDialog.py	Thu Apr 29 17:39:17 2021 +0200
@@ -21,6 +21,7 @@
     """
     Class implementing a dialog showing UML like diagrams.
     """
+    # convert to Enum
     NoDiagram = 255
     ClassDiagram = 0
     PackageDiagram = 1
--- a/eric6/IconEditor/IconEditorGrid.py	Wed Apr 28 19:42:28 2021 +0200
+++ b/eric6/IconEditor/IconEditorGrid.py	Thu Apr 29 17:39:17 2021 +0200
@@ -91,6 +91,7 @@
     sizeChanged = pyqtSignal(int, int)
     zoomChanged = pyqtSignal(int)
     
+    # convert to Enum
     Pencil = 1
     Rubber = 2
     Line = 3
@@ -103,6 +104,7 @@
     Fill = 10
     ColorPicker = 11
     
+    # convert to Enum
     RectangleSelection = 20
     CircleSelection = 21
     
--- a/eric6/Tasks/Task.py	Wed Apr 28 19:42:28 2021 +0200
+++ b/eric6/Tasks/Task.py	Thu Apr 29 17:39:17 2021 +0200
@@ -18,10 +18,13 @@
 import Preferences
 
 
+# TODO: separate into Task and TaskItem(QTreeWidgetItem) (eric7)
 class Task(QTreeWidgetItem):
     """
     Class implementing the task data structure.
     """
+    # TODO: add Enum for priority
+    # TODO: convert to Enum
     TypeNone = -1
     TypeFixme = 0
     TypeTodo = 1
--- a/eric6/WebBrowser/WebBrowserTabBar.py	Wed Apr 28 19:42:28 2021 +0200
+++ b/eric6/WebBrowser/WebBrowserTabBar.py	Thu Apr 29 17:39:17 2021 +0200
@@ -8,10 +8,10 @@
 """
 
 from PyQt5.QtCore import Qt, QPoint, QTimer, QEvent
-from PyQt5.QtWidgets import QFrame, QLabel
+from PyQt5.QtWidgets import QLabel
 
 from E5Gui.E5TabWidget import E5WheelTabBar
-from E5Gui.E5PassivePopup import E5PassivePopup
+from E5Gui.E5PassivePopup import E5PassivePopup, E5PassivePopupStyle
 
 import Preferences
 
@@ -56,9 +56,8 @@
             w = self.tabSizeHint(index).width()
             h = int(w * currentBrowser.height() / currentBrowser.width())
             
-            self.__previewPopup = E5PassivePopup(self)
-            self.__previewPopup.setFrameShape(QFrame.Shape.StyledPanel)
-            self.__previewPopup.setFrameShadow(QFrame.Shadow.Plain)
+            self.__previewPopup = E5PassivePopup(
+                style=E5PassivePopupStyle.STYLED, parent=self)
             self.__previewPopup.setFixedSize(w, h)
             self.__previewPopup.setCustomData("index", index)
             
@@ -81,6 +80,7 @@
         """
         if self.__previewPopup is not None:
             self.__previewPopup.hide()
+            self.__previewPopup.deleteLater()
         self.__previewPopup = None
     
     def mouseMoveEvent(self, evt):

eric ide

mercurial