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
|
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt
import db.tasks
import gui.tasks.signal
import gui.tasks.table.menu
import gui.tasks.table.model
def widget(database, parent, add_task_signal):
table = QtWidgets.QTableView(parent)
tasks = db.tasks.get(database.cursor())
table_model = gui.tasks.table.model.TableModel(tasks)
table.setModel(table_model)
table.sortByColumn(
gui.tasks.table.model.default_sort[0],
gui.tasks.table.model.default_sort[1])
table.setSortingEnabled(True)
table.setSelectionBehavior(QtWidgets.QTableView.SelectRows)
table.horizontalHeader().setStretchLastSection(True)
resizeColumns(table)
update_task_signal = gui.tasks.signal.UpdateTask()
# Menu
table.setContextMenuPolicy(Qt.CustomContextMenu)
table.customContextMenuRequested.connect(lambda position: gui.tasks.table.menu.open(database, table, update_task_signal, position))
add_task_signal.get().connect(lambda task: insert(table, task))
update_task_signal.get().connect(lambda row, task: update(table, row, task))
return table
def insert(table, task):
table.model().insert_task(table.horizontalHeader(), task)
resizeColumns(table)
def update(table, row, task):
row = table.model().update_task(table.horizontalHeader(), row, task)
table.selectRow(row)
resizeColumns(table)
def resizeColumns(table):
for column in range(gui.tasks.table.model.columns):
table.resizeColumnToContents(column)
|