diff options
Diffstat (limited to 'src/gui/tasks/form')
-rw-r--r-- | src/gui/tasks/form/state.py | 52 | ||||
-rw-r--r-- | src/gui/tasks/form/widget.py | 52 |
2 files changed, 84 insertions, 20 deletions
diff --git a/src/gui/tasks/form/state.py b/src/gui/tasks/form/state.py index 46e2909..727bedd 100644 --- a/src/gui/tasks/form/state.py +++ b/src/gui/tasks/form/state.py @@ -3,6 +3,8 @@ from PyQt5 import QtCore from typing import NamedTuple, Optional from model.task import ValidTaskForm +from model.difficulty import Difficulty +from model.priority import Priority import gui.tasks.duration class TaskFormEdition: @@ -10,36 +12,48 @@ class TaskFormEdition: self, name, name_signal, - description, - description_signal, duration, duration_signal, tag, - tag_signal): + tag_signal, + difficulty, + difficulty_signal, + priority, + priority_signal, + description, + description_signal): self._name = name - self._description = description self._duration = duration self._tag = tag + self._difficulty = difficulty + self._priority = priority + self._description = description self._signal = ValidTaskFormSignal() - name_signal.connect(lambda name: self.on_name_signal(name)) - description_signal.connect(lambda description: self.on_description_signal(description)) - duration_signal.connect(lambda duration: self.on_duration_signal(duration)) - tag_signal.connect(lambda tag: self.on_tag_signal(tag)) + name_signal.connect(lambda n: self.on_name_signal(n)) + duration_signal.connect(lambda d: self.on_duration_signal(d)) + tag_signal.connect(lambda t: self.on_tag_signal(t)) + difficulty_signal.connect(lambda d: self.on_difficulty_signal(d)) + priority_signal.connect(lambda p: self.on_priority_signal(p)) + description_signal.connect(lambda d: self.on_description_signal(d)) def get(self) -> Optional[ValidTaskForm]: name = self._name.strip() - description = self._description.strip() duration = gui.tasks.duration.parse(self._duration) tag = self._tag.strip() + difficulty = self._difficulty + priority = self._priority + description = self._description.strip() if name and duration != None: return ValidTaskForm( name = name, - description = description, duration = duration, - tag = tag) + tag = tag, + difficulty = difficulty, + priority = priority, + description = description) else: return None @@ -47,10 +61,6 @@ class TaskFormEdition: self._name = name self.emit() - def on_description_signal(self, description: str): - self._description = description - self.emit() - def on_duration_signal(self, duration: str): self._duration = duration self.emit() @@ -59,6 +69,18 @@ class TaskFormEdition: self._tag = tag self.emit() + def on_difficulty_signal(self, index: int): + self._difficulty = Difficulty(index) + self.emit() + + def on_priority_signal(self, index: int): + self._priority = Priority(index) + self.emit() + + def on_description_signal(self, description: str): + self._description = description + self.emit() + def emit(self): validForm = self.get() if validForm: diff --git a/src/gui/tasks/form/widget.py b/src/gui/tasks/form/widget.py index 49bf5f7..846ce90 100644 --- a/src/gui/tasks/form/widget.py +++ b/src/gui/tasks/form/widget.py @@ -1,9 +1,9 @@ from PyQt5 import QtWidgets, QtCore -from typing import Optional, Tuple +from typing import Optional, Tuple, List, Any import db.tasks from model.task import Task, ValidTaskForm - +from model import difficulty, priority import gui.icons import gui.tasks.form.state import gui.tasks.duration @@ -45,6 +45,24 @@ def widget( init_tag = task.tag if task is not None else '' tag_input = line_edit(grid, grid_layout, 2, 'Tag', init_tag) + init_difficulty = task.difficulty if task is not None else difficulty.Difficulty.MEDIUM + difficulty_input = combo_box( + grid, + grid_layout, + 3, + 'Difficulty', + [difficulty.format(d) for d in difficulty.values], + int(init_difficulty)) + + init_priority = task.priority if task is not None else priority.Priority.MEDIUM + priority_input = combo_box( + grid, + grid_layout, + 4, + 'Priority', + [priority.format(d) for d in priority.values], + int(init_priority)) + init_description = task.description if task is not None else '' (description_input, description_signal) = text_edit(widget, 'Description', init_description) layout.addWidget(description_input) @@ -52,12 +70,16 @@ def widget( task_form_edition = gui.tasks.form.state.TaskFormEdition( init_name, name_input.textChanged, - init_description, - description_signal, init_duration, duration_input.textChanged, init_tag, - tag_input.textChanged) + tag_input.textChanged, + init_difficulty, + difficulty_input.currentIndexChanged, + init_priority, + priority_input.currentIndexChanged, + init_description, + description_signal) def on_validate(): form = task_form_edition.get() @@ -90,6 +112,26 @@ def line_edit( return edit +def combo_box( + parent, + layout: QtWidgets.QGridLayout, + n: int, + label: str, + values: List[str], + default_value: int) -> QtWidgets.QComboBox: + + label = QtWidgets.QLabel(label, parent) + layout.addWidget(label, n, 0) + + box = QtWidgets.QComboBox(parent) + for value in values: + box.addItem(value) + if default_value != None: + box.setCurrentIndex(default_value) + layout.addWidget(box, n, 1) + + return box + def text_edit( parent, label: str, |