aboutsummaryrefslogtreecommitdiff
path: root/todo/gui/tasks/table/menu.py
blob: 78c85acbbcd95c4ae0e6b2b7c298fbf6e96e2f63 (plain)
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
from PyQt5 import QtWidgets, QtCore
from typing import List

import todo.gui.tasks.dialog
from todo.model.status import Status
from todo.model.task import Task, ValidTaskForm
from todo.model.tag import Tag

def open(table: QtWidgets.QTableWidget, status: Status, 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(todo.gui.icon.dialog_open(menu.style()), "modify")
    else:
        modify_action = QtWidgets.QAction(menu)

    delete_action = menu.addAction(todo.gui.icon.trash(menu.style()), "delete")

    if status != Status.READY:
        move_to_ready = menu.addAction(todo.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(todo.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(todo.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)
        todo.gui.tasks.dialog.update(table, update_task_signal, row, task, tags).exec_()
    elif action == delete_action:
        todo.gui.tasks.dialog.confirm_delete(table, rows, lambda: table.delete_rows(rows))
    elif action == move_to_ready:
        table.update_status(rows, Status.READY)
    elif action == move_to_waiting:
        table.update_status(rows, Status.WAITING)
    elif action == move_to_maybe:
        table.update_status(rows, Status.MAYBE)