aboutsummaryrefslogtreecommitdiff
path: root/todo/gui/tasks/table/widget.py
diff options
context:
space:
mode:
Diffstat (limited to 'todo/gui/tasks/table/widget.py')
-rw-r--r--todo/gui/tasks/table/widget.py55
1 files changed, 21 insertions, 34 deletions
diff --git a/todo/gui/tasks/table/widget.py b/todo/gui/tasks/table/widget.py
index b379abc..e374c90 100644
--- a/todo/gui/tasks/table/widget.py
+++ b/todo/gui/tasks/table/widget.py
@@ -1,12 +1,10 @@
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtCore import Qt
from typing import List, Tuple
+from datetime import date, timedelta
import time
import math
-from todo.model import difficulty, priority
-from todo.model.difficulty import Difficulty
-from todo.model.priority import Priority
from todo.model.tag import Tag
from todo.model.task import Task
from todo.model.task_tag import TaskTag
@@ -17,7 +15,6 @@ import todo.db.task_tags
import todo.gui.color
import todo.gui.signal
import todo.gui.tasks.dialog
-import todo.gui.tasks.duration
import todo.gui.tasks.signal
import todo.gui.tasks.signal
import todo.gui.tasks.table.menu
@@ -128,12 +125,10 @@ class Widget(QtWidgets.QTableWidget):
else:
name = task.name
self.setItem(row, 1, item(name))
- self.setCellWidget(row, 2, colored_label(self, todo.gui.tasks.duration.format(task.duration), todo.gui.tasks.duration.color(task.duration)))
- self.setCellWidget(row, 3, colored_label(self, difficulty.format(task.difficulty), difficulty_color(task.difficulty)))
- self.setCellWidget(row, 4, colored_label(self, priority.format(task.priority), priority_color(task.priority)))
+ self.setCellWidget(row, 2, colored_label(self, task.due_date.strftime("%d/%m/%Y") if task.due_date else "", due_date_color(task.due_date)))
tag_ids = [tt.tag_id for tt in self._task_tags if tt.task_id == task.id]
res_tags = sorted([tag for tag in self._tags if tag.id in tag_ids], key=lambda t: t.name)
- self.setCellWidget(row, 5, render_tags(self, res_tags))
+ self.setCellWidget(row, 3, render_tags(self, res_tags))
self.setRowHeight(row, 50)
def insert(self, task: Task, tags: List[int]) -> int:
@@ -163,14 +158,10 @@ class Widget(QtWidgets.QTableWidget):
return task.name.lower()
elif row == 2:
if is_reversed:
- return task.duration
+ return task.due_date.isoformat() if task.due_date else ""
else:
- return (task.duration == 0, task.duration)
+ return (task.due_date == None, task.due_date.isoformat() if task.due_date else "")
elif row == 3:
- return task.difficulty
- elif row == 4:
- return task.priority
- elif row == 5:
tag_ids = [tt.tag_id for tt in self._task_tags if tt.task_id == task.id]
tags = sorted([tag.name.lower() for tag in self._tags if tag.id in tag_ids])
key = "".join(tags)
@@ -181,13 +172,13 @@ class Widget(QtWidgets.QTableWidget):
def keyPressEvent(self, event):
super().keyPressEvent(event)
+ rows = self.get_selected_rows()
if event.key() in (Qt.Key_Return, Qt.Key_Enter):
- rows = self.get_selected_rows()
if len(rows) == 1:
row = rows[0]
(task, tags) = self.get_at(row)
todo.gui.tasks.dialog.update(self, self._update_task_signal, row, task, tags).exec_()
- elif event.key() == Qt.Key_Delete:
+ elif event.key() == Qt.Key_Delete and len(rows) > 0:
rows = self.get_selected_rows()
todo.gui.tasks.dialog.confirm_delete(self, rows, lambda: self.delete_rows(rows))
@@ -221,7 +212,7 @@ class Widget(QtWidgets.QTableWidget):
return (task, tags)
def header_labels(self):
- labels = ["Age", "Name", "Duration", "Difficulty", "Priority", "Tag"]
+ labels = ["Âge", "Nom", "Échéance", "Étiquettes"]
if self._sort_is_ascending:
sign = "▼"
else:
@@ -237,7 +228,7 @@ def item(text: str):
def age_since(timestamp):
diff = int(time.time()) - timestamp
if diff >= 60 * 60 * 24:
- return "" + str(math.floor(diff / 60 / 60 / 24)) + "d"
+ return "" + str(math.floor(diff / 60 / 60 / 24)) + "j"
elif diff >= 60 * 60:
return "" + str(math.floor(diff / 60 / 60)) + "h"
elif diff >= 60:
@@ -245,6 +236,18 @@ def age_since(timestamp):
else:
return "1m"
+def due_date_color(d: date) -> QtGui.QColor:
+ if d != None:
+ today = date.today()
+ if d < today:
+ return todo.gui.color.red
+ elif d < today + timedelta(days = 7):
+ return todo.gui.color.orange
+ else:
+ return todo.gui.color.black
+ else:
+ return todo.gui.color.black
+
def colored_label(parent, text: str, color: QtGui.QColor):
label = QtWidgets.QLabel(text)
palette = QtGui.QPalette()
@@ -268,19 +271,3 @@ def render_tags(parent, tags: List[Tag]):
layout.addWidget(label)
return widget
-
-def difficulty_color(d: Difficulty) -> QtGui.QColor:
- if d == Difficulty.EASY:
- return todo.gui.color.easy_difficulty
- elif d == Difficulty.NORMAL:
- return todo.gui.color.normal_difficulty
- elif d == Difficulty.HARD:
- return todo.gui.color.hard_difficulty
-
-def priority_color(p: Priority) -> QtGui.QColor:
- if p == Priority.LOW:
- return todo.gui.color.low_priority
- elif p == Priority.MIDDLE:
- return todo.gui.color.middle_priority
- elif p == Priority.HIGH:
- return todo.gui.color.high_priority