diff -r 7015247cbb05 -r 17d03699f151 eric6/Tasks/Task.py --- a/eric6/Tasks/Task.py Sun May 02 10:59:00 2021 +0200 +++ b/eric6/Tasks/Task.py Sun May 02 15:09:14 2021 +0200 @@ -32,13 +32,20 @@ DOCU = 5 -# TODO: separate into Task and TaskItem(QTreeWidgetItem) (eric7) +class TaskPriority(enum.IntEnum): + """ + Class defining the task priorities. + """ + HIGH = 0 + NORMAL = 1 + LOW = 2 + + +# TODO: eric7: separate into Task and TaskItem(QTreeWidgetItem) class Task(QTreeWidgetItem): """ Class implementing the task data structure. """ - # TODO: add IntEnum for priority - TaskType2IconName = { TaskType.FIXME: "taskFixme", # __NO-TASK__ TaskType.TODO: "taskTodo", # __NO-TASK__ @@ -64,8 +71,8 @@ TaskType.DOCU: "TasksDocuMarkers", # __NO-TASK__ } - def __init__(self, summary, priority=1, filename="", lineno=0, - completed=False, _time=0, isProjectTask=False, + def __init__(self, summary, priority=TaskPriority.NORMAL, filename="", + lineno=0, completed=False, _time=0, isProjectTask=False, taskType=TaskType.TODO, project=None, description="", uid="", parentUid=""): """ @@ -73,8 +80,8 @@ @param summary summary text of the task @type str - @param priority priority of the task (0=high, 1=normal, 2=low) - @type int + @param priority priority of the task + @type TaskPriority @param filename filename containing the task @type str @param lineno line number containing the task @@ -101,16 +108,11 @@ self.summary = summary self.description = description - if priority in [0, 1, 2]: - self.priority = priority - else: - self.priority = 1 self.filename = filename self.lineno = lineno self.completed = completed self.created = _time and _time or time.time() self._isProjectTask = isProjectTask - self.taskType = taskType self.project = project if uid: self.uid = uid @@ -138,22 +140,9 @@ f.setStrikeOut(strikeOut) self.setFont(column, f) - if self.priority == 1: - self.setIcon(1, UI.PixmapCache.getIcon("empty")) - elif self.priority == 0: - self.setIcon(1, UI.PixmapCache.getIcon("taskPrioHigh")) - elif self.priority == 2: - self.setIcon(1, UI.PixmapCache.getIcon("taskPrioLow")) - else: - self.setIcon(1, UI.PixmapCache.getIcon("empty")) + self.setPriority(priority) - try: - self.setIcon(2, UI.PixmapCache.getIcon( - Task.TaskType2IconName[self.taskType])) - except KeyError: - self.setIcon(2, UI.PixmapCache.getIcon("empty")) - - self.colorizeTask() + self.setTaskType(taskType) self.setTextAlignment(4, Qt.AlignmentFlag.AlignRight) def colorizeTask(self): @@ -188,7 +177,8 @@ """ Public slot to update the description field. - @param description descriptive text of the task (string) + @param description descriptive text of the task + @type str """ self.description = description @@ -196,22 +186,37 @@ """ Public slot to update the priority. - @param priority priority of the task (0=high, 1=normal, 2=low) + @param priority priority of the task + @type TaskPriority """ - if priority in [0, 1, 2]: - self.priority = priority - else: - self.priority = 1 + self.priority = priority - if self.priority == 1: + if self.priority == TaskPriority.NORMAL: self.setIcon(1, UI.PixmapCache.getIcon("empty")) - elif self.priority == 0: + elif self.priority == TaskPriority.HIGH: self.setIcon(1, UI.PixmapCache.getIcon("taskPrioHigh")) - elif self.priority == 2: + elif self.priority == TaskPriority.LOW: self.setIcon(1, UI.PixmapCache.getIcon("taskPrioLow")) else: self.setIcon(1, UI.PixmapCache.getIcon("empty")) + def setTaskType(self, taskType): + """ + Public method to update the task type. + + @param taskType type of the task + @type TaskType + """ + self.taskType = taskType + + try: + self.setIcon(2, UI.PixmapCache.getIcon( + Task.TaskType2IconName[self.taskType])) + except KeyError: + self.setIcon(2, UI.PixmapCache.getIcon("empty")) + + self.colorizeTask() + def setCompleted(self, completed): """ Public slot to update the completed flag. @@ -321,7 +326,7 @@ return { "summary": self.summary.strip(), "description": self.description.strip(), - "priority": self.priority, + "priority": self.priority.value, "lineno": self.lineno, "completed": self.completed, "created": self.created,