diff options
Diffstat (limited to 'src/gui/tasks/form/widget.py')
-rw-r--r-- | src/gui/tasks/form/widget.py | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/src/gui/tasks/form/widget.py b/src/gui/tasks/form/widget.py index 61fa24d..8063d8d 100644 --- a/src/gui/tasks/form/widget.py +++ b/src/gui/tasks/form/widget.py @@ -1,7 +1,8 @@ from PyQt5 import QtWidgets +from typing import Optional import db.tasks -from model.task import Task, TaskForm +from model.task import Task, ValidTaskForm import gui.icons import gui.tasks.form.state @@ -21,6 +22,10 @@ def widget( (name_labelled_input, name_input) = labelled_input(widget, 'Name', init_name) layout.addWidget(name_labelled_input) + init_duration = str(task.duration) if task is not None else '' + (duration_labelled_input, duration_input) = labelled_input(widget, 'Duration', init_duration) + layout.addWidget(duration_labelled_input) + init_tag = task.tag if task is not None else '' (tag_labelled_input, tag_input) = labelled_input(widget, 'Tag', init_tag) layout.addWidget(tag_labelled_input) @@ -28,6 +33,8 @@ def widget( task_form_edition = gui.tasks.form.state.TaskFormEdition( init_name, name_input.textChanged, + init_duration, + duration_input.textChanged, init_tag, tag_input.textChanged) @@ -40,7 +47,6 @@ def widget( return widget -# Use grid ? def labelled_input(parent, label: str, default_value: str): widget = QtWidgets.QWidget(parent) @@ -67,8 +73,8 @@ def buttons(parent, action_title, task_form_signal, on_validate, on_cancel): validate.clicked.connect(on_validate); layout.addWidget(validate) - def on_task_form_signal(task_form): - if validate_form(task_form): + def on_task_form_signal(form: Optional[ValidTaskForm]): + if form: validate.setEnabled(True) else: validate.setDisabled(True) @@ -82,19 +88,6 @@ def buttons(parent, action_title, task_form_signal, on_validate, on_cancel): return widget -def validate(task_form: TaskForm, on_validated): - valid_form = validate_form(task_form) - if valid_form: - on_validated(valid_form) - -def clean_form(task_form: TaskForm): - return TaskForm( - name = task_form.name.strip(), - tag = task_form.tag.strip()) - -def validate_form(task_form: TaskForm): - task_form = clean_form(task_form) - if task_form.name: - return task_form - else: - return None +def validate(form: Optional[ValidTaskForm], on_validated): + if form: + on_validated(form) |