1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
import re
from PyQt5 import QtCore
from typing import NamedTuple, Optional
from model.task import ValidTaskForm
import gui.tasks.duration
class TaskFormEdition:
def __init__(
self,
name,
name_signal,
description,
description_signal,
duration,
duration_signal,
tag,
tag_signal):
self._name = name
self._description = description
self._duration = duration
self._tag = tag
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))
def get(self) -> Optional[ValidTaskForm]:
name = self._name.strip()
description = self._description.strip()
duration = gui.tasks.duration.parse(self._duration)
tag = self._tag.strip()
if name and duration != None:
return ValidTaskForm(
name = name,
description = description,
duration = duration,
tag = tag)
else:
return None
def on_name_signal(self, name: str):
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()
def on_tag_signal(self, tag: str):
self._tag = tag
self.emit()
def emit(self):
validForm = self.get()
if validForm:
self._signal.emit(validForm)
def signal(self):
return self._signal
class ValidTaskFormSignal(QtCore.QObject):
_signal = QtCore.pyqtSignal(ValidTaskForm, name = 'validTaskForm')
def __init__(self):
QtCore.QObject.__init__(self)
def emit(self, form: Optional[ValidTaskForm]):
self._signal.emit(form)
def connect(self, f):
self._signal.connect(f)
|