src/eric7/Tasks/Task.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
21 21
22 class TaskType(enum.IntEnum): 22 class TaskType(enum.IntEnum):
23 """ 23 """
24 Class defining the task types. 24 Class defining the task types.
25 """ 25 """
26
26 NONE = 255 27 NONE = 255
27 FIXME = 0 28 FIXME = 0
28 TODO = 1 29 TODO = 1
29 WARNING = 2 30 WARNING = 2
30 NOTE = 3 31 NOTE = 3
34 35
35 class TaskPriority(enum.IntEnum): 36 class TaskPriority(enum.IntEnum):
36 """ 37 """
37 Class defining the task priorities. 38 Class defining the task priorities.
38 """ 39 """
40
39 HIGH = 0 41 HIGH = 0
40 NORMAL = 1 42 NORMAL = 1
41 LOW = 2 43 LOW = 2
42 44
43 45
44 class Task(QTreeWidgetItem): 46 class Task(QTreeWidgetItem):
45 """ 47 """
46 Class implementing the task data structure. 48 Class implementing the task data structure.
47 """ 49 """
50
48 TaskType2IconName = { 51 TaskType2IconName = {
49 TaskType.FIXME: "taskFixme", # __NO-TASK__ 52 TaskType.FIXME: "taskFixme", # __NO-TASK__
50 TaskType.TODO: "taskTodo", # __NO-TASK__ 53 TaskType.TODO: "taskTodo", # __NO-TASK__
51 TaskType.WARNING: "taskWarning", # __NO-TASK__ 54 TaskType.WARNING: "taskWarning", # __NO-TASK__
52 TaskType.NOTE: "taskNote", # __NO-TASK__ 55 TaskType.NOTE: "taskNote", # __NO-TASK__
53 TaskType.TEST: "taskTest", # __NO-TASK__ 56 TaskType.TEST: "taskTest", # __NO-TASK__
54 TaskType.DOCU: "taskDocu", # __NO-TASK__ 57 TaskType.DOCU: "taskDocu", # __NO-TASK__
55 } 58 }
56 TaskType2ColorName = { 59 TaskType2ColorName = {
57 TaskType.FIXME: "TasksFixmeColor", # __NO-TASK__ 60 TaskType.FIXME: "TasksFixmeColor", # __NO-TASK__
58 TaskType.TODO: "TasksTodoColor", # __NO-TASK__ 61 TaskType.TODO: "TasksTodoColor", # __NO-TASK__
59 TaskType.WARNING: "TasksWarningColor", # __NO-TASK__ 62 TaskType.WARNING: "TasksWarningColor", # __NO-TASK__
60 TaskType.NOTE: "TasksNoteColor", # __NO-TASK__ 63 TaskType.NOTE: "TasksNoteColor", # __NO-TASK__
61 TaskType.TEST: "TasksTestColor", # __NO-TASK__ 64 TaskType.TEST: "TasksTestColor", # __NO-TASK__
62 TaskType.DOCU: "TasksDocuColor", # __NO-TASK__ 65 TaskType.DOCU: "TasksDocuColor", # __NO-TASK__
63 } 66 }
64 TaskType2MarkersName = { 67 TaskType2MarkersName = {
65 TaskType.FIXME: "TasksFixmeMarkers", # __NO-TASK__ 68 TaskType.FIXME: "TasksFixmeMarkers", # __NO-TASK__
66 TaskType.TODO: "TasksTodoMarkers", # __NO-TASK__ 69 TaskType.TODO: "TasksTodoMarkers", # __NO-TASK__
67 TaskType.WARNING: "TasksWarningMarkers", # __NO-TASK__ 70 TaskType.WARNING: "TasksWarningMarkers", # __NO-TASK__
68 TaskType.NOTE: "TasksNoteMarkers", # __NO-TASK__ 71 TaskType.NOTE: "TasksNoteMarkers", # __NO-TASK__
69 TaskType.TEST: "TasksTestMarkers", # __NO-TASK__ 72 TaskType.TEST: "TasksTestMarkers", # __NO-TASK__
70 TaskType.DOCU: "TasksDocuMarkers", # __NO-TASK__ 73 TaskType.DOCU: "TasksDocuMarkers", # __NO-TASK__
71 } 74 }
72 75
73 def __init__(self, summary, priority=TaskPriority.NORMAL, filename="", 76 def __init__(
74 lineno=0, completed=False, _time=0, isProjectTask=False, 77 self,
75 taskType=TaskType.TODO, project=None, description="", 78 summary,
76 uid="", parentUid=""): 79 priority=TaskPriority.NORMAL,
80 filename="",
81 lineno=0,
82 completed=False,
83 _time=0,
84 isProjectTask=False,
85 taskType=TaskType.TODO,
86 project=None,
87 description="",
88 uid="",
89 parentUid="",
90 ):
77 """ 91 """
78 Constructor 92 Constructor
79 93
80 @param summary summary text of the task 94 @param summary summary text of the task
81 @type str 95 @type str
82 @param priority priority of the task 96 @param priority priority of the task
83 @type TaskPriority 97 @type TaskPriority
84 @param filename filename containing the task 98 @param filename filename containing the task
102 @type str 116 @type str
103 @param parentUid unique id of the parent task 117 @param parentUid unique id of the parent task
104 @type str 118 @type str
105 """ 119 """
106 super().__init__() 120 super().__init__()
107 121
108 self.summary = summary 122 self.summary = summary
109 self.description = description 123 self.description = description
110 self.filename = filename 124 self.filename = filename
111 self.lineno = lineno 125 self.lineno = lineno
112 self.completed = completed 126 self.completed = completed
116 if uid: 130 if uid:
117 self.uid = uid 131 self.uid = uid
118 else: 132 else:
119 self.uid = QUuid.createUuid().toString() 133 self.uid = QUuid.createUuid().toString()
120 self.parentUid = parentUid 134 self.parentUid = parentUid
121 135
122 if isProjectTask: 136 if isProjectTask:
123 self.filename = self.project.getRelativePath(self.filename) 137 self.filename = self.project.getRelativePath(self.filename)
124 138
125 self.setData(0, Qt.ItemDataRole.DisplayRole, "") 139 self.setData(0, Qt.ItemDataRole.DisplayRole, "")
126 self.setData(1, Qt.ItemDataRole.DisplayRole, "") 140 self.setData(1, Qt.ItemDataRole.DisplayRole, "")
127 self.setData(2, Qt.ItemDataRole.DisplayRole, self.summary) 141 self.setData(2, Qt.ItemDataRole.DisplayRole, self.summary)
128 self.setData(3, Qt.ItemDataRole.DisplayRole, self.filename) 142 self.setData(3, Qt.ItemDataRole.DisplayRole, self.filename)
129 self.setData(4, Qt.ItemDataRole.DisplayRole, self.lineno or "") 143 self.setData(4, Qt.ItemDataRole.DisplayRole, self.lineno or "")
130 144
131 if self.completed: 145 if self.completed:
132 self.setIcon(0, UI.PixmapCache.getIcon("taskCompleted")) 146 self.setIcon(0, UI.PixmapCache.getIcon("taskCompleted"))
133 strikeOut = True 147 strikeOut = True
134 else: 148 else:
135 self.setIcon(0, UI.PixmapCache.getIcon("empty")) 149 self.setIcon(0, UI.PixmapCache.getIcon("empty"))
136 strikeOut = False 150 strikeOut = False
137 for column in range(2, 5): 151 for column in range(2, 5):
138 f = self.font(column) 152 f = self.font(column)
139 f.setStrikeOut(strikeOut) 153 f.setStrikeOut(strikeOut)
140 self.setFont(column, f) 154 self.setFont(column, f)
141 155
142 self.setPriority(priority) 156 self.setPriority(priority)
143 157
144 self.setTaskType(taskType) 158 self.setTaskType(taskType)
145 self.setTextAlignment(4, Qt.AlignmentFlag.AlignRight) 159 self.setTextAlignment(4, Qt.AlignmentFlag.AlignRight)
146 160
147 def colorizeTask(self): 161 def colorizeTask(self):
148 """ 162 """
149 Public slot to set the colors of the task item. 163 Public slot to set the colors of the task item.
150 """ 164 """
151 boldFont = self.font(0) 165 boldFont = self.font(0)
153 nonBoldFont = self.font(0) 167 nonBoldFont = self.font(0)
154 nonBoldFont.setBold(False) 168 nonBoldFont.setBold(False)
155 for col in range(5): 169 for col in range(5):
156 with contextlib.suppress(KeyError): 170 with contextlib.suppress(KeyError):
157 self.setBackground( 171 self.setBackground(
158 col, Preferences.getTasks( 172 col, Preferences.getTasks(Task.TaskType2ColorName[self.taskType])
159 Task.TaskType2ColorName[self.taskType])) 173 )
160 174
161 if self._isProjectTask: 175 if self._isProjectTask:
162 self.setFont(col, boldFont) 176 self.setFont(col, boldFont)
163 else: 177 else:
164 self.setFont(col, nonBoldFont) 178 self.setFont(col, nonBoldFont)
165 179
166 def setSummary(self, summary): 180 def setSummary(self, summary):
167 """ 181 """
168 Public slot to update the description. 182 Public slot to update the description.
169 183
170 @param summary summary text of the task (string) 184 @param summary summary text of the task (string)
171 """ 185 """
172 self.summary = summary 186 self.summary = summary
173 self.setText(2, self.summary) 187 self.setText(2, self.summary)
174 188
175 def setDescription(self, description): 189 def setDescription(self, description):
176 """ 190 """
177 Public slot to update the description field. 191 Public slot to update the description field.
178 192
179 @param description descriptive text of the task 193 @param description descriptive text of the task
180 @type str 194 @type str
181 """ 195 """
182 self.description = description 196 self.description = description
183 197
184 def setPriority(self, priority): 198 def setPriority(self, priority):
185 """ 199 """
186 Public slot to update the priority. 200 Public slot to update the priority.
187 201
188 @param priority priority of the task 202 @param priority priority of the task
189 @type TaskPriority 203 @type TaskPriority
190 """ 204 """
191 self.priority = priority 205 self.priority = priority
192 206
193 if self.priority == TaskPriority.NORMAL: 207 if self.priority == TaskPriority.NORMAL:
194 self.setIcon(1, UI.PixmapCache.getIcon("empty")) 208 self.setIcon(1, UI.PixmapCache.getIcon("empty"))
195 elif self.priority == TaskPriority.HIGH: 209 elif self.priority == TaskPriority.HIGH:
196 self.setIcon(1, UI.PixmapCache.getIcon("taskPrioHigh")) 210 self.setIcon(1, UI.PixmapCache.getIcon("taskPrioHigh"))
197 elif self.priority == TaskPriority.LOW: 211 elif self.priority == TaskPriority.LOW:
198 self.setIcon(1, UI.PixmapCache.getIcon("taskPrioLow")) 212 self.setIcon(1, UI.PixmapCache.getIcon("taskPrioLow"))
199 else: 213 else:
200 self.setIcon(1, UI.PixmapCache.getIcon("empty")) 214 self.setIcon(1, UI.PixmapCache.getIcon("empty"))
201 215
202 def setTaskType(self, taskType): 216 def setTaskType(self, taskType):
203 """ 217 """
204 Public method to update the task type. 218 Public method to update the task type.
205 219
206 @param taskType type of the task 220 @param taskType type of the task
207 @type TaskType 221 @type TaskType
208 """ 222 """
209 self.taskType = taskType 223 self.taskType = taskType
210 224
211 try: 225 try:
212 self.setIcon(2, UI.PixmapCache.getIcon( 226 self.setIcon(
213 Task.TaskType2IconName[self.taskType])) 227 2, UI.PixmapCache.getIcon(Task.TaskType2IconName[self.taskType])
228 )
214 except KeyError: 229 except KeyError:
215 self.setIcon(2, UI.PixmapCache.getIcon("empty")) 230 self.setIcon(2, UI.PixmapCache.getIcon("empty"))
216 231
217 self.colorizeTask() 232 self.colorizeTask()
218 233
219 def setCompleted(self, completed): 234 def setCompleted(self, completed):
220 """ 235 """
221 Public slot to update the completed flag. 236 Public slot to update the completed flag.
222 237
223 @param completed flag indicating completion status (boolean) 238 @param completed flag indicating completion status (boolean)
224 """ 239 """
225 self.completed = completed 240 self.completed = completed
226 if self.completed: 241 if self.completed:
227 self.setIcon(0, UI.PixmapCache.getIcon("taskCompleted")) 242 self.setIcon(0, UI.PixmapCache.getIcon("taskCompleted"))
231 strikeOut = False 246 strikeOut = False
232 for column in range(2, 5): 247 for column in range(2, 5):
233 f = self.font(column) 248 f = self.font(column)
234 f.setStrikeOut(strikeOut) 249 f.setStrikeOut(strikeOut)
235 self.setFont(column, f) 250 self.setFont(column, f)
236 251
237 # set the completion status for all children 252 # set the completion status for all children
238 for index in range(self.childCount()): 253 for index in range(self.childCount()):
239 self.child(index).setCompleted(completed) 254 self.child(index).setCompleted(completed)
240 255
241 def isCompleted(self): 256 def isCompleted(self):
242 """ 257 """
243 Public slot to return the completion status. 258 Public slot to return the completion status.
244 259
245 @return flag indicating the completion status (boolean) 260 @return flag indicating the completion status (boolean)
246 """ 261 """
247 return self.completed 262 return self.completed
248 263
249 def getFilename(self): 264 def getFilename(self):
250 """ 265 """
251 Public method to retrieve the task's filename. 266 Public method to retrieve the task's filename.
252 267
253 @return filename (string) 268 @return filename (string)
254 """ 269 """
255 if self._isProjectTask and self.filename: 270 if self._isProjectTask and self.filename:
256 return os.path.join(self.project.getProjectPath(), self.filename) 271 return os.path.join(self.project.getProjectPath(), self.filename)
257 else: 272 else:
258 return self.filename 273 return self.filename
259 274
260 def isFileTask(self): 275 def isFileTask(self):
261 """ 276 """
262 Public slot to get an indication, if this task is related to a file. 277 Public slot to get an indication, if this task is related to a file.
263 278
264 @return flag indicating a file task (boolean) 279 @return flag indicating a file task (boolean)
265 """ 280 """
266 return self.filename != "" 281 return self.filename != ""
267 282
268 def getLineno(self): 283 def getLineno(self):
269 """ 284 """
270 Public method to retrieve the task's linenumber. 285 Public method to retrieve the task's linenumber.
271 286
272 @return linenumber (integer) 287 @return linenumber (integer)
273 """ 288 """
274 return self.lineno 289 return self.lineno
275 290
276 def getUuid(self): 291 def getUuid(self):
277 """ 292 """
278 Public method to get the task's uid. 293 Public method to get the task's uid.
279 294
280 @return uid (string) 295 @return uid (string)
281 """ 296 """
282 return self.uid 297 return self.uid
283 298
284 def getParentUuid(self): 299 def getParentUuid(self):
285 """ 300 """
286 Public method to get the parent task's uid. 301 Public method to get the parent task's uid.
287 302
288 @return parent uid (string) 303 @return parent uid (string)
289 """ 304 """
290 return self.parentUid 305 return self.parentUid
291 306
292 def setProjectTask(self, pt): 307 def setProjectTask(self, pt):
293 """ 308 """
294 Public method to set the project relation flag. 309 Public method to set the project relation flag.
295 310
296 @param pt flag indicating a project task (boolean) 311 @param pt flag indicating a project task (boolean)
297 """ 312 """
298 self._isProjectTask = pt 313 self._isProjectTask = pt
299 self.colorizeTask() 314 self.colorizeTask()
300 315
301 def isProjectTask(self): 316 def isProjectTask(self):
302 """ 317 """
303 Public slot to return the project relation status. 318 Public slot to return the project relation status.
304 319
305 @return flag indicating the project relation status (boolean) 320 @return flag indicating the project relation status (boolean)
306 """ 321 """
307 return self._isProjectTask 322 return self._isProjectTask
308 323
309 def isProjectFileTask(self): 324 def isProjectFileTask(self):
310 """ 325 """
311 Public slot to get an indication, if this task is related to a 326 Public slot to get an indication, if this task is related to a
312 project file. 327 project file.
313 328
314 @return flag indicating a project file task (boolean) 329 @return flag indicating a project file task (boolean)
315 """ 330 """
316 return self._isProjectTask and self.filename != "" 331 return self._isProjectTask and self.filename != ""
317 332
318 def toDict(self): 333 def toDict(self):
319 """ 334 """
320 Public method to convert the task data to a dictionary. 335 Public method to convert the task data to a dictionary.
321 336
322 @return dictionary containing the task data 337 @return dictionary containing the task data
323 @rtype dict 338 @rtype dict
324 """ 339 """
325 return { 340 return {
326 "summary": self.summary.strip(), 341 "summary": self.summary.strip(),

eric ide

mercurial