Sat, 01 May 2021 20:28:00 +0200
Modernized some more code (Tasks).
--- a/eric6/E5XML/TasksReader.py Sat May 01 18:48:35 2021 +0200 +++ b/eric6/E5XML/TasksReader.py Sat May 01 20:28:00 2021 +0200 @@ -15,7 +15,7 @@ from .Config import tasksFileFormatVersion from .XMLStreamReaderBase import XMLStreamReaderBase -from Tasks.Task import Task +from Tasks.Task import TaskType import Utilities @@ -85,7 +85,7 @@ "created": 0, "filename": "", "linenumber": 0, - "type": Task.TypeTodo, + "type": TaskType.TODO, "description": "", "uid": "", } @@ -94,11 +94,11 @@ if self.version in ["4.2", "5.0"]: isBugfix = self.toBool(self.attribute("bugfix", "False")) if isBugfix: - task["type"] = Task.TypeFixme + task["type"] = TaskType.FIXME else: - # TODO: task type enum change - # TaskType(int(self.attribute("type", str(Task.TypeTodo.value)))) - task["type"] = int(self.attribute("type", str(Task.TypeTodo))) + task["type"] = TaskType( + int(self.attribute("type", str(TaskType.TODO.value))) + ) uid = self.attribute("uid", "") if uid: task["uid"] = uid
--- a/eric6/E5XML/TasksWriter.py Sat May 01 18:48:35 2021 +0200 +++ b/eric6/E5XML/TasksWriter.py Sat May 01 20:28:00 2021 +0200 @@ -76,8 +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("type", str(task.taskType.value)) self.writeAttribute("uid", task.uid) if task.parentUid: self.writeAttribute("parent_uid", task.parentUid)
--- 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(),
--- a/eric6/Tasks/TaskFilter.py Sat May 01 18:48:35 2021 +0200 +++ b/eric6/Tasks/TaskFilter.py Sat May 01 20:28:00 2021 +0200 @@ -10,7 +10,7 @@ import fnmatch import re -from .Task import Task +from .Task import TaskType class TaskFilter: @@ -25,7 +25,7 @@ self.summaryFilter = None self.filenameFilter = "" - self.typeFilter = Task.TypeNone + self.typeFilter = TaskType.NONE # task type self.scopeFilter = None @@ -70,8 +70,8 @@ """ Public method to set the type filter. - @param taskType type of the task (one of Task.TypeNone, Task.TypeFixme, - Task.TypeTodo, Task.TypeWarning, Task.TypeNote) + @param taskType type of the task + @type TaskType """ self.typeFilter = taskType @@ -108,7 +108,7 @@ return ( self.summaryFilter is not None or bool(self.filenameFilter) or - self.typeFilter != Task.TypeNone or + self.typeFilter != TaskType.NONE or self.scopeFilter is not None or self.statusFilter is not None or self.prioritiesFilter is not None @@ -137,7 +137,7 @@ return False if ( - self.typeFilter != Task.TypeNone and + self.typeFilter != TaskType.NONE and self.typeFilter != task.taskType ): return False
--- a/eric6/Tasks/TaskFilterConfigDialog.py Sat May 01 18:48:35 2021 +0200 +++ b/eric6/Tasks/TaskFilterConfigDialog.py Sat May 01 20:28:00 2021 +0200 @@ -9,7 +9,7 @@ from PyQt5.QtWidgets import QDialog -from .Task import Task +from .Task import TaskType from .Ui_TaskFilterConfigDialog import Ui_TaskFilterConfigDialog @@ -28,13 +28,13 @@ super().__init__(parent) self.setupUi(self) - self.typeCombo.addItem("", Task.TypeNone) - self.typeCombo.addItem(self.tr("Bugfix"), Task.TypeFixme) - self.typeCombo.addItem(self.tr("Warning"), Task.TypeWarning) - self.typeCombo.addItem(self.tr("ToDo"), Task.TypeTodo) - self.typeCombo.addItem(self.tr("Note"), Task.TypeNote) - self.typeCombo.addItem(self.tr("Test"), Task.TypeTest) - self.typeCombo.addItem(self.tr("Documentation"), Task.TypeDocu) + self.typeCombo.addItem("", TaskType.NONE) + self.typeCombo.addItem(self.tr("Bugfix"), TaskType.FIXME) + self.typeCombo.addItem(self.tr("Warning"), TaskType.WARNING) + self.typeCombo.addItem(self.tr("ToDo"), TaskType.TODO) + self.typeCombo.addItem(self.tr("Note"), TaskType.NOTE) + self.typeCombo.addItem(self.tr("Test"), TaskType.TEST) + self.typeCombo.addItem(self.tr("Documentation"), TaskType.DOCU) if ( taskFilter.summaryFilter is None or @@ -53,7 +53,7 @@ self.filenameGroup.setChecked(True) self.filenameEdit.setText(taskFilter.filenameFilter) - if taskFilter.typeFilter == Task.TypeNone: + if taskFilter.typeFilter == TaskType.NONE: self.typeGroup.setChecked(False) self.typeCombo.setCurrentIndex(0) else: @@ -116,9 +116,12 @@ if self.typeGroup.isChecked(): taskFilter.setTypeFilter( - self.typeCombo.itemData(self.typeCombo.currentIndex())) + TaskType( + self.typeCombo.itemData(self.typeCombo.currentIndex()) + ) + ) else: - taskFilter.setTypeFilter(Task.TypeNone) + taskFilter.setTypeFilter(TaskType.NONE) if self.scopeGroup.isChecked(): if self.projectRadioButton.isChecked():
--- a/eric6/Tasks/TaskViewer.py Sat May 01 18:48:35 2021 +0200 +++ b/eric6/Tasks/TaskViewer.py Sat May 01 20:28:00 2021 +0200 @@ -25,7 +25,7 @@ from E5Gui import E5MessageBox from E5Gui.E5ProgressDialog import E5ProgressDialog -from .Task import Task +from .Task import Task, TaskType import UI.PixmapCache @@ -320,26 +320,37 @@ def addTask(self, summary, priority=1, filename="", lineno=0, completed=False, _time=0, isProjectTask=False, - taskType=Task.TypeTodo, description="", uid="", + taskType=TaskType.TODO, description="", uid="", parentTask=None): """ Public slot to add a task. - @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 Task.TypeFixme, Task.TypeTodo, - Task.TypeWarning, Task.TypeNote) - @param description explanatory text of the task (string) - @param uid unique id of the task (string) - @param parentTask reference to the parent task item (Task) or the - UID of the parent task - @return reference to the task item (Task) + project + @type bool + @param taskType type of the task + @type TaskType + @param description explanatory text of the task + @type str + @param uid unique id of the task + @type str + @param parentTask reference to the parent task item or the UID of the + parent task + @type Task or str + @return reference to the task item + @rtype Task """ if isinstance(parentTask, str): # UID of parent task @@ -377,23 +388,27 @@ return task - def addFileTask(self, summary, filename, lineno, taskType=Task.TypeTodo, + def addFileTask(self, summary, filename, lineno, taskType=TaskType.TODO, description=""): """ Public slot to add a file related task. - @param summary summary text of the task (string) - @param filename filename containing the task (string) - @param lineno line number containing the task (integer) - @param taskType type of the task (one of Task.TypeFixme, Task.TypeTodo, - Task.TypeWarning, Task.TypeNote) - @param description explanatory text of the task (string) + @param summary summary text of the task + @type str + @param filename filename containing the task + @type str + @param lineno line number containing the task + @type int + @param taskType type of the task + @type TaskType + @param description explanatory text of the task + @type str """ self.addTask(summary, filename=filename, lineno=lineno, isProjectTask=( self.project and self.project.isProjectSource(filename)), - taskType=taskType, description=description) + taskType=TaskType(taskType), description=description) def getProjectTasks(self): """ @@ -816,11 +831,11 @@ """ Class implementing a thread to extract tasks related to a project. - @signal taskFound(str, str, int, int) emitted with the task description, - the file name, the line number and task type to signal the presence of - a task + @signal taskFound(str, str, int, TaskType) emitted with the task + description, the file name, the line number and task type to signal + the presence of a task """ - taskFound = pyqtSignal(str, str, int, int) + taskFound = pyqtSignal(str, str, int, TaskType) def __init__(self, parent=None): """
--- a/eric6/Tasks/TasksFile.py Sat May 01 18:48:35 2021 +0200 +++ b/eric6/Tasks/TasksFile.py Sat May 01 20:28:00 2021 +0200 @@ -18,6 +18,8 @@ import Preferences +from .Task import TaskType + class TasksFile(QObject): """ @@ -138,7 +140,8 @@ task["summary"], priority=task["priority"], filename=task["filename"], lineno=task["lineno"], completed=task["completed"], _time=task["created"], - isProjectTask=not self.__isGlobal, taskType=task["type"], + isProjectTask=not self.__isGlobal, + taskType=TaskType(task["type"]), description=task["description"], uid=task["uid"], parentTask=task["parent_uid"]) addedTasks.append((addedTask, task["expanded"]))