-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimilarityTable.py
More file actions
35 lines (26 loc) · 1.22 KB
/
SimilarityTable.py
File metadata and controls
35 lines (26 loc) · 1.22 KB
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
from tkinter import W, Button
from tkinter.ttk import Treeview
from tkinter import Toplevel
class SimilarityTable:
def createAndShow(self, arr, filenames, window):
table_window = Toplevel(window)
columns = ('File #1', 'File #2', 'Similarity')
tree = Treeview(table_window, columns=columns, show='headings')
tree.column('File #1', width=260)
tree.column('File #2', width=260)
tree.column('Similarity', width=60)
tree.grid(row=0, column=0)
for (i, row) in enumerate(range(1, len(arr))):
for col in range(0, i + 1):
similarity = round(arr[row][col], 2)
tree.insert('', 'end', values=(filenames[row], filenames[col], similarity))
for col in columns:
tree.heading(col, text=col, command=lambda: self.sort_by_column(tree, col, True))
def sort_by_column(self, tv, col, reverse):
l = [(tv.set(k, col), k) for k in tv.get_children('')]
l.sort(reverse=reverse)
# rearrange items in sorted positions
for index, (val, k) in enumerate(l):
tv.move(k, '', index)
# reverse sort next time
tv.heading(col, command=lambda: self.sort_by_column(tv, col, not reverse))