diff options
author | Joris | 2020-05-08 14:33:15 +0200 |
---|---|---|
committer | Joris | 2020-05-08 14:33:15 +0200 |
commit | bff2dfd96169f595510b16980a4cb2f3d4548029 (patch) | |
tree | 716d09dc4b2b20be565188539883853601fa32ca /src/gui/tasks/widget.py | |
parent | df828c4b141f84f731afffbe17c80618cacf9480 (diff) |
Extract task form code from the dialog file
Diffstat (limited to 'src/gui/tasks/widget.py')
-rw-r--r-- | src/gui/tasks/widget.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/gui/tasks/widget.py b/src/gui/tasks/widget.py new file mode 100644 index 0000000..bca6585 --- /dev/null +++ b/src/gui/tasks/widget.py @@ -0,0 +1,39 @@ +from PyQt5 import QtWidgets, QtCore + +import db.tasks +import gui.tasks.signal +import gui.tasks.table.widget +import gui.icons +from model.task import TaskForm + +def widget(database, parent): + widget = QtWidgets.QWidget(parent) + + layout = QtWidgets.QVBoxLayout(widget) + widget.setLayout(layout) + + add_task_signal = gui.tasks.signal.AddTask() + + add_task_button = QtWidgets.QPushButton('Add a task', widget) + add_task_button.setIcon(gui.icons.new_folder(widget.style())) + add_task_button.clicked.connect(lambda: show_add_dialog(database, widget, add_task_signal)) + layout.addWidget(add_task_button) + + table = gui.tasks.table.widget.widget(database, widget, add_task_signal) + layout.addWidget(table) + + return widget + +def show_add_dialog(database, parent_widget, add_task_signal): + dialog = gui.tasks.modal.dialog( + parent_widget, + 'Add a task', + 'add', + None, + lambda taskForm: on_add(database, taskForm, add_task_signal)) + dialog.exec_() + +def on_add(database, taskForm: TaskForm, add_task_signal): + task = db.tasks.insert(database.cursor(), taskForm) + database.commit() + add_task_signal.emit(task) |