eric6/Tasks/Task.py

changeset 8278
e647b71b393f
parent 8269
87f521f359d5
child 8280
17d03699f151
--- a/eric6/Tasks/Task.py	Sat May 01 18:48:35 2021 +0200
+++ b/eric6/Tasks/Task.py	Sat May 01 20:28:00 2021 +0200
@@ -7,9 +7,10 @@
 Module implementing a class to store task data.
 """
 
+import contextlib
+import enum
 import os
 import time
-import contextlib
 
 from PyQt5.QtCore import Qt, QUuid
 from PyQt5.QtWidgets import QTreeWidgetItem
@@ -18,67 +19,83 @@
 import Preferences
 
 
+class TaskType(enum.IntEnum):
+    """
+    Class defining the task types.
+    """
+    NONE = 255
+    FIXME = 0
+    TODO = 1
+    WARNING = 2
+    NOTE = 3
+    TEST = 4
+    DOCU = 5
+
+
 # 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
-    TypeWarning = 2
-    TypeNote = 3
-    TypeTest = 4
-    TypeDocu = 5
+    # TODO: add IntEnum for priority
     
     TaskType2IconName = {
-        TypeFixme: "taskFixme",
-        TypeTodo: "taskTodo",
-        TypeWarning: "taskWarning",
-        TypeNote: "taskNote",
-        TypeTest: "taskTest",
-        TypeDocu: "taskDocu",
+        TaskType.FIXME: "taskFixme",                # __NO-TASK__
+        TaskType.TODO: "taskTodo",                  # __NO-TASK__
+        TaskType.WARNING: "taskWarning",            # __NO-TASK__
+        TaskType.NOTE: "taskNote",                  # __NO-TASK__
+        TaskType.TEST: "taskTest",                  # __NO-TASK__
+        TaskType.DOCU: "taskDocu",                  # __NO-TASK__
     }
     TaskType2ColorName = {
-        TypeFixme: "TasksFixmeColor",
-        TypeTodo: "TasksTodoColor",
-        TypeWarning: "TasksWarningColor",
-        TypeNote: "TasksNoteColor",
-        TypeTest: "TasksTestColor",
-        TypeDocu: "TasksDocuColor",
+        TaskType.FIXME: "TasksFixmeColor",          # __NO-TASK__
+        TaskType.TODO: "TasksTodoColor",            # __NO-TASK__
+        TaskType.WARNING: "TasksWarningColor",      # __NO-TASK__
+        TaskType.NOTE: "TasksNoteColor",            # __NO-TASK__
+        TaskType.TEST: "TasksTestColor",            # __NO-TASK__
+        TaskType.DOCU: "TasksDocuColor",            # __NO-TASK__
     }
     TaskType2MarkersName = {
-        TypeFixme: "TasksFixmeMarkers",
-        TypeTodo: "TasksTodoMarkers",
-        TypeWarning: "TasksWarningMarkers",
-        TypeNote: "TasksNoteMarkers",
-        TypeTest: "TasksTestMarkers",
-        TypeDocu: "TasksDocuMarkers",
+        TaskType.FIXME: "TasksFixmeMarkers",        # __NO-TASK__
+        TaskType.TODO: "TasksTodoMarkers",          # __NO-TASK__
+        TaskType.WARNING: "TasksWarningMarkers",    # __NO-TASK__
+        TaskType.NOTE: "TasksNoteMarkers",          # __NO-TASK__
+        TaskType.TEST: "TasksTestMarkers",          # __NO-TASK__
+        TaskType.DOCU: "TasksDocuMarkers",          # __NO-TASK__
     }
     
     def __init__(self, summary, priority=1, filename="", lineno=0,
                  completed=False, _time=0, isProjectTask=False,
-                 taskType=TypeTodo, project=None, description="",
+                 taskType=TaskType.TODO, project=None, description="",
                  uid="", parentUid=""):
         """
         Constructor
         
-        @param summary summary text of the task (string)
+        @param summary summary text of the task
+        @type str
         @param priority priority of the task (0=high, 1=normal, 2=low)
-        @param filename filename containing the task (string)
-        @param lineno line number containing the task (integer)
-        @param completed flag indicating completion status (boolean)
-        @param _time creation time of the task (float, if 0 use current time)
+        @type int
+        @param filename filename containing the task
+        @type str
+        @param lineno line number containing the task
+        @type int
+        @param completed flag indicating completion status
+        @type bool
+        @param _time creation time of the task (if 0 use current time)
+        @type float
         @param isProjectTask flag indicating a task related to the current
-            project (boolean)
-        @param taskType type of the task (one of TypeFixme, TypeTodo,
-            TypeWarning, TypeNote, TypeTest, TypeDocu)
-        @param project reference to the project object (Project)
-        @param description explanatory text of the task (string)
-        @param uid unique id of the task (string)
-        @param parentUid unique id of the parent task (string)
+            project
+        @type bool
+        @param taskType type of the task
+        @type TaskType
+        @param project reference to the project object
+        @type Project
+        @param description explanatory text of the task
+        @type str
+        @param uid unique id of the task
+        @type str
+        @param parentUid unique id of the parent task
+        @type str
         """
         super().__init__()
         
@@ -308,7 +325,7 @@
             "lineno": self.lineno,
             "completed": self.completed,
             "created": self.created,
-            "type": self.taskType,
+            "type": self.taskType.value,
             "uid": self.uid,
             "parent_uid": self.parentUid,
             "expanded": self.isExpanded(),

eric ide

mercurial