diff options
Diffstat (limited to 'todo/gui/tasks/dialog.py')
-rw-r--r-- | todo/gui/tasks/dialog.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/todo/gui/tasks/dialog.py b/todo/gui/tasks/dialog.py new file mode 100644 index 0000000..c2bd164 --- /dev/null +++ b/todo/gui/tasks/dialog.py @@ -0,0 +1,76 @@ +from PyQt5 import QtCore, QtWidgets +from typing import List + +from todo.model.tag import Tag +from todo.model.task import Task, ValidTaskForm +from todo.model.status import Status +import todo.database +import todo.gui.tasks.form.widget +import todo.service.tasks + +def add(parent_widget, status: Status, add_task_signal): + + def on_add(task_form: ValidTaskForm): + task = todo.service.tasks.create(todo.database.cursor(), status, task_form) + add_task_signal.emit(task, task_form.tags) + + return widget(parent_widget, "Add a task", "add", None, [], on_add) + +def update(parent_widget, update_task_signal, row: int, task: Task, tags: List[int]): + + def on_update(task_form: ValidTaskForm): + updated_task = todo.service.tasks.update(todo.database.cursor(), task, task_form) + update_task_signal.emit(row, updated_task, task_form.tags) + + return widget(parent_widget, "Modify a task", "modify", task, tags, on_update) + +def confirm_delete(parent, rows: List[int], on_confirm): + confirm = QtWidgets.QMessageBox.question( + parent, + "Task deletion", + "Do you really want to delete the selected tasks ?", + QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Yes, + QtWidgets.QMessageBox.Yes) + + if confirm == QtWidgets.QMessageBox.Yes: + on_confirm() + +def confirm_move(parent, rows: List[int], move_to: Status, on_confirm): + confirm = QtWidgets.QMessageBox.question( + parent, + "Task move", + "Do you really want to move the selected tasks ?", + QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Yes, + QtWidgets.QMessageBox.Yes) + + if confirm == QtWidgets.QMessageBox.Yes: + on_confirm() + +def widget( + parent: QtWidgets.QWidget, + title: str, + action_title: str, + task: Task, + tags: List[int], + on_validated): + + dialog = QtWidgets.QDialog(parent) + dialog.setWindowTitle(title) + dialog.setMinimumSize(QtCore.QSize(320, 240)) + + layout = QtWidgets.QVBoxLayout(dialog) + dialog.setLayout(layout) + + def on_dialog_validated(form): + dialog.accept() + on_validated(form) + + layout.addWidget(todo.gui.tasks.form.widget.widget( + parent = dialog, + action_title = action_title, + task = task, + tags = tags, + on_validated = on_dialog_validated, + on_cancel = lambda: dialog.reject())) + + return dialog |