diff options
Diffstat (limited to 'src/gui/tasks/form/state.py')
-rw-r--r-- | src/gui/tasks/form/state.py | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/src/gui/tasks/form/state.py b/src/gui/tasks/form/state.py index 6aedb95..a47aec7 100644 --- a/src/gui/tasks/form/state.py +++ b/src/gui/tasks/form/state.py @@ -1,39 +1,59 @@ from PyQt5 import QtCore +from typing import NamedTuple, Optional -from model.task import TaskForm +from model.task import ValidTaskForm class TaskFormEdition: - def __init__(self, name, name_signal, tag, tag_signal): + def __init__(self, name, name_signal, duration, duration_signal, tag, tag_signal): self._name = name + self._duration = duration self._tag = tag - self._signal = TaskFormSignal() + self._signal = ValidTaskFormSignal() name_signal.connect(lambda name: self.on_name_signal(name)) + duration_signal.connect(lambda duration: self.on_duration_signal(duration)) tag_signal.connect(lambda tag: self.on_tag_signal(tag)) - def get(self): - return TaskForm( - name = self._name, - tag = self._tag) + def get(self) -> Optional[ValidTaskForm]: + name = self._name.strip() + duration = self._duration.strip() + tag = self._tag.strip() + + if name and (duration == '' or duration.isdigit()): + return ValidTaskForm( + name = name, + duration = 0 if duration == '' else int(duration), + tag = tag) + else: + return None def on_name_signal(self, name: str): self._name = name - self._signal.emit(self.get()) + self.emit() + + def on_duration_signal(self, duration: str): + self._duration = duration + self.emit() def on_tag_signal(self, tag: str): self._tag = tag - self._signal.emit(self.get()) + self.emit() + + def emit(self): + validForm = self.get() + if validForm: + self._signal.emit(validForm) def signal(self): return self._signal -class TaskFormSignal(QtCore.QObject): - _signal = QtCore.pyqtSignal(TaskForm, name = 'taskForm') +class ValidTaskFormSignal(QtCore.QObject): + _signal = QtCore.pyqtSignal(ValidTaskForm, name = 'validTaskForm') def __init__(self): QtCore.QObject.__init__(self) - def emit(self, taskForm): - self._signal.emit(taskForm) + def emit(self, form: Optional[ValidTaskForm]): + self._signal.emit(form) def connect(self, f): self._signal.connect(f) |