-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui_analysis.py
More file actions
138 lines (106 loc) · 5.33 KB
/
gui_analysis.py
File metadata and controls
138 lines (106 loc) · 5.33 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import tkinter as tk
import customtkinter as ct
from tkinter import ttk
from logic_controller import model
class AnalysisTab(ct.CTkFrame):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.word_table = WordTable(self)
self.word_table.grid(row=0, column=0, sticky='news', rowspan=2)
self.definition = Definition(self)
self.definition.grid(row=0, column=1, sticky='news')
self.export = Export(self)
self.export.grid(row=1, column=1, sticky='news', padx=30, pady=30)
self.rowconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=1)
# self.configure(fg_color='powder blue')
# This is the table on the left side
class WordTable(ct.CTkFrame):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
style = ttk.Style()
style.configure('Treeview', rowheight=40)
style.configure('Treeview.Heading', foreground='dark orchid',
font=('Helvetica', 20, 'bold'))
self.table = ttk.Treeview(self, columns=('Word', 'Frequency'), displaycolumns='#all',
selectmode='browse', show='headings')
self.table.tag_configure('ttk', font=('Helvetica', 20, 'bold'))
# makes the headings appear
self.table.heading(0, text='Word')
self.table.heading(1, text='Frequency')
# centers the treeview items
self.table.column(0, anchor='center')
self.table.column(1, anchor='center')
# scrollbars
self.scroll_x = ct.CTkScrollbar(self, orientation="horizontal", command=self.table.xview)
self.scroll_y = ct.CTkScrollbar(self, orientation="vertical", command=self.table.yview)
self.table.configure(xscrollcommand=self.scroll_x.set, yscrollcommand=self.scroll_y.set)
self.scroll_x.grid(row=1, column=0, sticky="ew")
self.scroll_y.grid(row=0, column=1, sticky="ns")
self.table.grid(row=0, column=0, sticky='news')
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
# self.configure(fg_color='powder blue')
self.load_words()
def load_words(self):
# sorts it by value
temp = []
for key, value in model.word_freq.items():
temp.append((key, value))
temp.sort(reverse=True, key=lambda x: x[1])
self.table.delete(*self.table.get_children())
for key, value in temp:
self.table.insert('', 'end', values=(key, value), tags='ttk')
class Definition(ct.CTkFrame):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.definition = ct.CTkTextbox(self, wrap='word', cursor='', state="disabled")
ct.CTkLabel(self, text='Definition', font=('Arial', 24)).grid(row=0, column=0)
self.definition.grid(row=1, column=0, sticky='news', padx=10)
self.rowconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
self.columnconfigure(0, weight=1)
# self.configure(fg_color='powder blue')
# This is the stuff on the right side
class Export(ct.CTkFrame):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.configure(fg_color='gray')
self.min_freq = ct.CTkEntry(self, placeholder_text='0', width=5)
self.max_freq = ct.CTkEntry(self, placeholder_text='10', width=5)
self.export_button = ct.CTkButton(self, text='Export', fg_color='medium orchid', border_color='purple1',
hover_color='dark orchid', text_color='white', command=self.export, font=('Arial', 24))
ct.CTkLabel(self, text='Export words with a frequency between', font=('Arial', 24)).grid(row=0, column=0, columnspan=3, padx=20,
pady=(20, 10))
self.min_freq.grid(row=1, column=0, sticky='ew', padx=(30, 10))
ct.CTkLabel(self, text='and', font=('Arial', 24)).grid(row=1, column=1)
self.max_freq.grid(row=1, column=2, sticky='ew', padx=(10, 30))
self.export_button.grid(row=10, column=0, columnspan=3, pady=(30, 10))
# haha i love coding ( :
self.rowconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
self.rowconfigure(10, weight=1)
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=1)
self.columnconfigure(2, weight=1)
# self.configure(fg_color='powder blue')
self.add_vars()
def add_vars(self):
self.min_freq.var = tk.StringVar(value=0)
self.min_freq.configure(textvariable=self.min_freq.var)
self.max_freq.var = tk.StringVar(value=5)
self.max_freq.configure(textvariable=self.max_freq.var)
def export(self):
min_value = int(self.min_freq.var.get())
max_value = int(self.max_freq.var.get())
model.get_freq_range(min_value, max_value)
# label that says export created
tk.messagebox.showinfo(message='Export successfully created! Please open the export.txt file to access it.', title='Export created')
if __name__ == '__main__':
window = ct.CTk()
AnalysisTab(window).grid(row=0, column=0, sticky='news')
window.rowconfigure(0, weight=1)
window.columnconfigure(0, weight=1)
window.mainloop()