diff options
Diffstat (limited to 'src/gui/tasks/table/menu.py')
-rw-r--r-- | src/gui/tasks/table/menu.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/gui/tasks/table/menu.py b/src/gui/tasks/table/menu.py new file mode 100644 index 0000000..4366c25 --- /dev/null +++ b/src/gui/tasks/table/menu.py @@ -0,0 +1,43 @@ +from PyQt5 import QtWidgets + +import db.tasks +import gui.tasks.modal +from model.task import Task, TaskForm + +def open(database, table, update_task_signal, position): + rows = set([index.row() for index in table.selectedIndexes()]) + + menu = QtWidgets.QMenu(table) + + if len(rows) == 1: + modify_action = menu.addAction(gui.icons.dialog_open(menu.style()), 'modify') + else: + modify_action = QtWidgets.QAction(menu) + + delete_action = menu.addAction(gui.icons.trash(menu.style()), 'Delete') + + action = menu.exec_(table.mapToGlobal(position)) + if action == modify_action and len(rows) == 1: + row = list(rows)[0] + task = table.model().get_at(row) + show_update_dialog(database, table, update_task_signal, row, task) + elif action == delete_action: + confirm = QtWidgets.QMessageBox.question(table, '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: + db.tasks.delete(database.cursor(), table.model().row_ids(rows)) + database.commit() + table.model().delete_tasks(rows) + +def show_update_dialog(database, parent_widget, update_task_signal, row, task): + dialog = gui.tasks.modal.dialog( + parent_widget, + 'Modify a task', + 'modify', + task, + lambda taskForm: on_update(database, update_task_signal, row, task, taskForm)) + dialog.exec_() + +def on_update(database, update_task_signal, row, task: Task, taskForm: TaskForm): + task = db.tasks.update(database.cursor(), task, taskForm) + update_task_signal.emit(row, task) + database.commit() |