aboutsummaryrefslogtreecommitdiff
path: root/src/gui/tasks
diff options
context:
space:
mode:
authorJoris2020-05-10 11:07:12 +0200
committerJoris2020-05-10 11:07:12 +0200
commita134f20eb62e6d174e7da81fd4adb7ff9e8b3b71 (patch)
treefe4b98d4a4636f20f28a5a7e5011a73171a2d182 /src/gui/tasks
parente33a5e7aff3143c50813fee7c12f10f98d132240 (diff)
Add task description field
Diffstat (limited to 'src/gui/tasks')
-rw-r--r--src/gui/tasks/form/state.py21
-rw-r--r--src/gui/tasks/form/widget.py71
2 files changed, 76 insertions, 16 deletions
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)