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
|
from PyQt5 import QtCore, QtWidgets
from typing import List
from model.tag import Tag
from model.task import Task, ValidTaskForm
from model.status import Status
import database
import db.task_tags
import db.tasks
import gui.tasks.form.widget
import service.tasks
def add(parent_widget, status: Status, add_task_signal):
def on_add(task_form: ValidTaskForm):
task = service.tasks.create(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 = service.tasks.update(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(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
|