From b244640288648f27ce1fc7be3f175703e0a3412b Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 6 Jun 2020 09:07:42 +0200 Subject: Add menu options to update tasks status --- src/db/tasks.py | 8 +++++++- src/gui/icon.py | 13 ++++++++++++- src/gui/tags/panel/form/widget.py | 2 +- src/gui/tasks/dialog.py | 15 +++++++++++++-- src/gui/tasks/form/widget.py | 2 +- src/gui/tasks/table/menu.py | 23 ++++++++++++++++++++++- src/gui/tasks/table/widget.py | 12 ++++++++++-- src/gui/window.py | 6 +++--- src/service/tasks.py | 4 ++++ 9 files changed, 73 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/db/tasks.py b/src/db/tasks.py index dca7710..efb88d6 100644 --- a/src/db/tasks.py +++ b/src/db/tasks.py @@ -90,8 +90,14 @@ def update(cursor: Cursor, task: Task, form: ValidTaskForm): description = form.description ) -def delete(cursor: Cursor, ids): +def delete(cursor: Cursor, ids: List[int]): if len(ids) >= 1: cursor.execute( "DELETE FROM tasks WHERE id IN (%s)" % ",".join("?"*len(ids)), ids) + +def update_status(cursor: Cursor, ids: List[int], s: Status): + if len(ids) >= 1: + cursor.execute( + "UPDATE tasks SET status = ? WHERE id IN (%s)" % ",".join("?"*len(ids)), + [status.format(s)] + ids) diff --git a/src/gui/icon.py b/src/gui/icon.py index c6584cb..7e2156d 100644 --- a/src/gui/icon.py +++ b/src/gui/icon.py @@ -1,12 +1,23 @@ from PyQt5 import QtWidgets +# List of icons: https://joekuan.wordpress.com/2015/09/23/list-of-qt-icons/ + +def task_ready(style): + return style.standardIcon(QtWidgets.QStyle.SP_DialogApplyButton) + +def task_waiting(style): + return style.standardIcon(QtWidgets.QStyle.SP_BrowserReload) + +def task_maybe(style): + return style.standardIcon(QtWidgets.QStyle.SP_TitleBarContextHelpButton) + def new_folder(style): return style.standardIcon(QtWidgets.QStyle.SP_FileDialogNewFolder) def dialog_open(style): return style.standardIcon(QtWidgets.QStyle.SP_DialogOpenButton) -def dialog_apply(style): +def dialog_ok(style): return style.standardIcon(QtWidgets.QStyle.SP_DialogOkButton) def dialog_cancel(style): diff --git a/src/gui/tags/panel/form/widget.py b/src/gui/tags/panel/form/widget.py index eb9cec8..7079e57 100644 --- a/src/gui/tags/panel/form/widget.py +++ b/src/gui/tags/panel/form/widget.py @@ -117,7 +117,7 @@ def buttons(parent, action_title, tag_form_signal, on_validate, on_cancel): validate = QtWidgets.QPushButton(action_title, widget) validate.setDisabled(True) - validate.setIcon(gui.icon.dialog_apply(validate.style())) + validate.setIcon(gui.icon.dialog_ok(validate.style())) validate.clicked.connect(on_validate); layout.addWidget(validate) diff --git a/src/gui/tasks/dialog.py b/src/gui/tasks/dialog.py index 3233dd6..2bf3b6b 100644 --- a/src/gui/tasks/dialog.py +++ b/src/gui/tasks/dialog.py @@ -26,7 +26,7 @@ def update(parent_widget, update_task_signal, row: int, task: Task, tags: List[i return widget(parent_widget, "Modify a task", "modify", task, tags, on_update) -def show_delete(parent, rows: List[int], on_delete): +def confirm_delete(parent, rows: List[int], on_confirm): confirm = QtWidgets.QMessageBox.question( parent, "Task deletion", @@ -35,7 +35,18 @@ def show_delete(parent, rows: List[int], on_delete): QtWidgets.QMessageBox.Yes) if confirm == QtWidgets.QMessageBox.Yes: - on_delete() + 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, diff --git a/src/gui/tasks/form/widget.py b/src/gui/tasks/form/widget.py index 9be2589..70d506d 100644 --- a/src/gui/tasks/form/widget.py +++ b/src/gui/tasks/form/widget.py @@ -164,7 +164,7 @@ def buttons(parent, action_title, task_form_signal, on_validate, on_cancel): validate = QtWidgets.QPushButton(action_title, widget) validate.setDisabled(True) - validate.setIcon(gui.icon.dialog_apply(validate.style())) + validate.setIcon(gui.icon.dialog_ok(validate.style())) validate.clicked.connect(on_validate); layout.addWidget(validate) diff --git a/src/gui/tasks/table/menu.py b/src/gui/tasks/table/menu.py index 0ad9857..5356be2 100644 --- a/src/gui/tasks/table/menu.py +++ b/src/gui/tasks/table/menu.py @@ -19,10 +19,31 @@ def open(table: QtWidgets.QTableWidget, status: Status, update_task_signal, posi delete_action = menu.addAction(gui.icon.trash(menu.style()), "delete") + if status != Status.READY: + move_to_ready = menu.addAction(gui.icon.task_ready(menu.style()), "move to ready") + else: + move_to_ready = QtWidgets.QAction(menu) + + if status != Status.WAITING: + move_to_waiting = menu.addAction(gui.icon.task_waiting(menu.style()), "move to waiting") + else: + move_to_waiting = QtWidgets.QAction(menu) + + if status != Status.MAYBE: + move_to_maybe = menu.addAction(gui.icon.task_maybe(menu.style()), "move to maybe") + else: + move_to_maybe = QtWidgets.QAction(menu) + action = menu.exec_(table.mapToGlobal(position + QtCore.QPoint(15, 20))) if action == modify_action and len(rows) == 1: row = list(rows)[0] (task, tags) = table.get_at(row) gui.tasks.dialog.update(table, update_task_signal, row, task, tags).exec_() elif action == delete_action: - gui.tasks.dialog.show_delete(table, rows, lambda: table.delete_rows(rows)) + gui.tasks.dialog.confirm_delete(table, rows, lambda: table.delete_rows(rows)) + elif action == move_to_ready: + gui.tasks.dialog.confirm_move(table, rows, Status.READY, lambda: table.update_status(rows, Status.READY)) + elif action == move_to_waiting: + gui.tasks.dialog.confirm_move(table, rows, Status.WAITING, lambda: table.update_status(rows, Status.WAITING)) + elif action == move_to_maybe: + gui.tasks.dialog.confirm_move(table, rows, Status.MAYBE, lambda: table.update_status(rows, Status.MAYBE)) diff --git a/src/gui/tasks/table/widget.py b/src/gui/tasks/table/widget.py index 14806fa..aacae2f 100644 --- a/src/gui/tasks/table/widget.py +++ b/src/gui/tasks/table/widget.py @@ -192,10 +192,18 @@ class Widget(QtWidgets.QTableWidget): def delete_rows(self, rows: List[int]): task_ids = [task.id for i, task in enumerate(self._tasks) if i in rows] service.tasks.delete(database.cursor(), task_ids) - self._tasks = [t for t in self._tasks if t.id not in task_ids] - self._task_tags = [tt for tt in self._task_tags if tt.task_id in [t.id for t in self._tasks]] + self.remove_rows_from_table(rows, task_ids) + + def update_status(self, rows: List[int], status: Status): + task_ids = [task.id for i, task in enumerate(self._tasks) if i in rows] + service.tasks.update_status(database.cursor(), task_ids, status) + self.remove_rows_from_table(rows, task_ids) + + def remove_rows_from_table(self, rows: List[int], task_ids: List[int]): for row in sorted(rows, reverse=True): self.removeRow(row) + self._tasks = [t for t in self._tasks if t.id not in task_ids] + self._task_tags = [tt for tt in self._task_tags if tt.task_id in [t.id for t in self._tasks]] self.setRowCount(len(self._tasks)) def get_selected_rows(self): diff --git a/src/gui/window.py b/src/gui/window.py index 35670c7..584fda6 100644 --- a/src/gui/window.py +++ b/src/gui/window.py @@ -14,13 +14,13 @@ def get(): tabs = QtWidgets.QTabWidget(window) window.setCentralWidget(tabs) - show_todo = gui.signal.Reload() + show_ready = gui.signal.Reload() show_waiting = gui.signal.Reload() show_maybe = gui.signal.Reload() def on_current_tab_changed(index: int): if index == 0: - show_todo.emit() + show_ready.emit() elif index == 1: show_waiting.emit() elif index == 2: @@ -28,7 +28,7 @@ def get(): tabs.currentChanged.connect(on_current_tab_changed) - tabs.addTab(gui.tasks.widget.widget(tabs, show_todo, Status.READY), "Todo") + tabs.addTab(gui.tasks.widget.widget(tabs, show_ready, Status.READY), "Ready") tabs.addTab(gui.tasks.widget.widget(tabs, show_waiting, Status.WAITING), "Waiting") tabs.addTab(gui.tasks.widget.widget(tabs, show_maybe, Status.MAYBE), "Maybe") tabs.addTab(gui.tags.panel.widget.widget(tabs), "Tags") diff --git a/src/service/tasks.py b/src/service/tasks.py index 0dfe94f..87194c4 100644 --- a/src/service/tasks.py +++ b/src/service/tasks.py @@ -26,3 +26,7 @@ def delete(cursor, task_ids: List[int]): db.task_tags.delete(cursor, task_ids) db.tasks.delete(cursor, task_ids) database.commit() + +def update_status(cursor, task_ids: List[int], status: Status) -> List[Task]: + db.tasks.update_status(cursor, task_ids, status) + database.commit() -- cgit v1.2.3