-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTable.py
78 lines (52 loc) · 2.36 KB
/
Table.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import tkinter as tk
import tkmacosx as tkmac
from abc import ABC, abstractmethod
import SceneElement
import FileService
from Row import ProductRow
import GUI
class AbstractSortingTable(SceneElement.AbstractSceneElement):
def __init__(self, scene, data, columnNames, sortByColumnID = 0, descending = False):
super().__init__(scene)
self.scene = scene
self.data = data
self.width = len(columnNames) + 1
self.columnNames = columnNames
self.sortByColumnID = sortByColumnID
self.descending = descending
for i, _ in enumerate(self.columnNames):
self.scene.root.columnconfigure(i + 1, weight=1)
def create(self):
self.reloadData()
self.buildTable()
def changeSorting(self, newSorting):
self.sortByColumnID = newSorting//2
self.descending = (newSorting)%2
self.scene.rebuild()
def sort(self):
self.data.sort(key=lambda x: x[self.sortByColumnID], reverse=self.descending)
def buildTable(self):
idLabel = tk.Label(self.scene.root, text="ID")
idLabel.grid(row=0, column=0, pady=10, padx=5)
for i, name in enumerate(self.columnNames):
columnNameLabel = tk.Label(self.scene.root, text=name)
columnNameLabel.grid(row=0, column=i + 1, pady=10, padx=5)
upArrowButton = tkmac.Button(self.scene.root, width=20, height=20, text=u"\u2191",
command=lambda x=i: self.changeSorting(2*x))
upArrowButton.grid(row=0, column= i + 1, pady=10, padx=5, sticky='e')
downArrowButton = tkmac.Button(self.scene.root, width=20, height=20, text=u"\u2193",
command=lambda x=i: self.changeSorting(2*x + 1) )
downArrowButton.grid(row=0, column=i + 1, pady=10, padx=25, sticky='e')
@abstractmethod
def reloadData(self):
pass
class SortingTable(AbstractSortingTable):
def buildTable(self):
super().buildTable()
for i, record in enumerate(self.data):
productIdLabel = tk.Label(self.scene.root, text=str(i + 1))
productIdLabel.grid(row=i + self.scene.freeRowsOnTop, column=0)
ProductRow(self, record).create(i)
def reloadData(self):
self.data = FileService.fileService.getAllProductsAsLists()
self.sort()