diff options
-rw-r--r-- | src/db/init.py | 1 | ||||
-rw-r--r-- | src/db/tasks.py | 16 | ||||
-rw-r--r-- | src/gui/tasks/form/state.py | 21 | ||||
-rw-r--r-- | src/gui/tasks/form/widget.py | 71 | ||||
-rw-r--r-- | src/model/task.py | 2 |
5 files changed, 90 insertions, 21 deletions
diff --git a/src/db/init.py b/src/db/init.py index c1835eb..cb8a4a8 100644 --- a/src/db/init.py +++ b/src/db/init.py @@ -12,6 +12,7 @@ def init(path): " created_at INTEGER NOT NULL," " modified_at INTEGER NOT NULL," " name TEXT NOT NULL," + " description TEXT," " duration INTEGER," " tag TEXT" " )") diff --git a/src/db/tasks.py b/src/db/tasks.py index d03877b..e22a315 100644 --- a/src/db/tasks.py +++ b/src/db/tasks.py @@ -10,6 +10,7 @@ def get(cursor: Cursor) -> Task: " created_at," " modified_at," " name," + " description," " duration," " tag" " FROM tasks") @@ -22,8 +23,9 @@ def get(cursor: Cursor) -> Task: created_at = task[1], modified_at = task[2], name = task[3], - duration = task[4], - tag = task[5] + description = task[4], + duration = task[5], + tag = task[6] )) return res @@ -35,16 +37,18 @@ def insert(cursor: Cursor, form: ValidTaskForm): " created_at," " modified_at," " name," + " description," " duration," " tag" - " ) VALUES (?, ?, ?, ?, ?)", - (now, now, form.name, form.duration, form.tag)) + " ) VALUES (?, ?, ?, ?, ?, ?)", + (now, now, form.name, form.description, form.duration, form.tag)) return Task( id = cursor.lastrowid, created_at = now, modified_at = now, name = form.name, + description = form.description, duration = form.duration, tag = form.tag ) @@ -57,16 +61,18 @@ def update(cursor: Cursor, task: Task, form: ValidTaskForm): " SET" " modified_at = ?," " name = ?," + " description = ?," " duration = ?," " tag = ?" " WHERE id = ?", - (now, form.name, form.duration, form.tag, task.id)) + (now, form.name, form.description, form.duration, form.tag, task.id)) return Task( id = task.id, created_at = task.created_at, modified_at = now, name = form.name, + description = form.description, duration = form.duration, tag = form.tag ) diff --git a/src/gui/tasks/form/state.py b/src/gui/tasks/form/state.py index 12ffe36..46e2909 100644 --- a/src/gui/tasks/form/state.py +++ b/src/gui/tasks/form/state.py @@ -6,23 +6,38 @@ from model.task import ValidTaskForm import gui.tasks.duration class TaskFormEdition: - def __init__(self, name, name_signal, duration, duration_signal, tag, tag_signal): + 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: @@ -32,6 +47,10 @@ 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() diff --git a/src/gui/tasks/form/widget.py b/src/gui/tasks/form/widget.py index 64f785a..49bf5f7 100644 --- a/src/gui/tasks/form/widget.py +++ b/src/gui/tasks/form/widget.py @@ -1,5 +1,5 @@ -from PyQt5 import QtWidgets -from typing import Optional +from PyQt5 import QtWidgets, QtCore +from typing import Optional, Tuple import db.tasks from model.task import Task, ValidTaskForm @@ -8,6 +8,18 @@ import gui.icons import gui.tasks.form.state import gui.tasks.duration +class TextEditSignal(QtCore.QObject): + _signal = QtCore.pyqtSignal(str, name = 'textEdit') + + def __init__(self): + QtCore.QObject.__init__(self) + + def emit(self, text: str): + self._signal.emit(text) + + def connect(self, f): + self._signal.connect(f) + def widget( parent: QtWidgets.QWidget, action_title: str, @@ -25,32 +37,43 @@ def widget( grid.setLayout(grid_layout) init_name = task.name if task is not None else '' - name_input = add_input(grid, grid_layout, 0, 'Name', init_name) + name_input = line_edit(grid, grid_layout, 0, 'Name', init_name) init_duration = gui.tasks.duration.format(task.duration) if task is not None else '' - duration_input = add_input(grid, grid_layout, 1, 'Duration', init_duration) + duration_input = line_edit(grid, grid_layout, 1, 'Duration', init_duration) init_tag = task.tag if task is not None else '' - tag_input = add_input(grid, grid_layout, 2, 'Tag', init_tag) + tag_input = line_edit(grid, grid_layout, 2, 'Tag', init_tag) + + init_description = task.description if task is not None else '' + (description_input, description_signal) = text_edit(widget, 'Description', init_description) + layout.addWidget(description_input) 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) + def on_validate(): + form = task_form_edition.get() + if form: + on_validated(form) + layout.addWidget(buttons( parent = widget, action_title = action_title, task_form_signal = task_form_edition.signal(), - on_validate = lambda: validate(task_form_edition.get(), on_validated), + on_validate = on_validate, on_cancel = on_cancel)) return widget -def add_input( +def line_edit( parent, layout: QtWidgets.QGridLayout, n: int, @@ -60,12 +83,34 @@ def add_input( label = QtWidgets.QLabel(label, parent) layout.addWidget(label, n, 0) - line_edit = QtWidgets.QLineEdit(parent) + edit = QtWidgets.QLineEdit(parent) if default_value != None: - line_edit.setText(default_value) - layout.addWidget(line_edit, n, 1) + edit.setText(default_value) + layout.addWidget(edit, n, 1) - return line_edit + return edit + +def text_edit( + parent, + label: str, + default_value: str) -> Tuple[QtWidgets.QWidget, TextEditSignal]: + + widget = QtWidgets.QWidget(parent) + layout = QtWidgets.QVBoxLayout(widget) + + signal = TextEditSignal() + + label = QtWidgets.QLabel(label, parent) + layout.addWidget(label) + + edit = QtWidgets.QTextEdit(parent) + if default_value != None: + edit.insertPlainText(default_value) + layout.addWidget(edit) + + edit.textChanged.connect(lambda: signal.emit(edit.toPlainText())) + + return (widget, signal) def buttons(parent, action_title, task_form_signal, on_validate, on_cancel): widget = QtWidgets.QWidget(parent) @@ -91,7 +136,3 @@ def buttons(parent, action_title, task_form_signal, on_validate, on_cancel): layout.addWidget(cancel) return widget - -def validate(form: Optional[ValidTaskForm], on_validated): - if form: - on_validated(form) diff --git a/src/model/task.py b/src/model/task.py index afbb2ca..cc7758d 100644 --- a/src/model/task.py +++ b/src/model/task.py @@ -6,10 +6,12 @@ class Task(NamedTuple): created_at: int modified_at: int name: str + description: str duration: int tag: str class ValidTaskForm(NamedTuple): name: str + description: str duration: int tag: str |