-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserInterface.py
235 lines (162 loc) · 6.61 KB
/
userInterface.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
from tkinter import *
from tkinter import filedialog
from tkinter import ttk
import os
from AllData import SimilarityMatrix as SMM
import Classification_with_weka as classification
def quit(event=None):
global root
root.destroy()
# defining options to open or save file
file_opt = options = {}
# default file extension
options['defaultextension'] = '.txt'
# default file types
options['filetypes'] = [('text files', '.txt')]
def open_train(event=None):
# display a dialog box for file choosing
txt_file = filedialog.askopenfilename(parent=root, initialdir=os.getcwd(), **file_opt)
# clear text area
if txt_file:
# before adding text, enable it
txt_train.config(state=NORMAL)
txt_train.delete(1.0, END)
# open file and write to our text are
train_set = SMM.openFile(SMM, txt_file, 'train')
line_num = 1
for x in train_set:
txt_train.insert(END, str(line_num)+ '.'+ x + '\n')
line_num += 1
# update text widget
root.update_idletasks()
# after editing, disable for safety
txt_train.config(state=DISABLED)
if txt_test.compare("end-1c", "!=", "1.0"):
# enabling train button
btn_train['state'] = 'normal'
print('train set is loaded')
else:
print("File is not exist")
def open_test(event=None):
# display a dialog box for file choosing
txt_file = filedialog.askopenfilename(parent=root, initialdir=os.getcwd(), **file_opt)
# clear text area
if txt_file:
# before adding text, enable it
txt_test.config(state=NORMAL)
txt_test.delete(1.0, END)
# open file and write to our text are
test_set = SMM.openFile(SMM, txt_file, 'test')
line_num = 1
for x in test_set:
txt_test.insert(END, str(line_num) + '.' + x + '\n')
line_num += 1
# update text widget
root.update_idletasks()
# after editing, disable for safety
txt_test.config(state=DISABLED)
if txt_train.compare("end-1c", "!=", "1.0"):
# enabling train button
btn_train['state'] = 'normal'
print('Test set is loaded')
else:
print("File is not exist")
def save_file(event=None):
pass
def start_traning():
print('Active')
classification.classify()
def start_summary():
pass
# ---------------- Graphic Interface ------------------------
root = Tk()
root.geometry('700x550')
notebook = ttk.Notebook(root)
btn_frame = Frame(root)
btn_frame.pack(fill='both', side=BOTTOM)
# summary button
btn_summary = Button(btn_frame, state=DISABLED, text="Özetle", width=5, height=2, command=start_summary,
background='cornsilk2', activebackground='light grey')
btn_summary.pack(side=RIGHT, fill=X, padx=5, pady=5)
# train button
btn_train = Button(btn_frame, state=DISABLED, text="Eğit", width=5, height=2, command=start_traning,
background='cornsilk2', activebackground='light grey')
btn_train.pack(side=RIGHT, padx=5, pady=5)
input_set_frame = Frame(notebook)
classification_frame = Frame(notebook)
summary_frame = Frame(notebook)
inner_notebook = ttk.Notebook(input_set_frame)
train_frame = Frame(inner_notebook)
test_frame = Frame(inner_notebook)
inner_notebook.add(train_frame, text='Eğitim Kümesi')
inner_notebook.add(test_frame, text='Test Kümesi')
inner_notebook.pack(fill='both', pady=10, padx=2)
notebook.add(input_set_frame, text='Veri seti')
notebook.add(classification_frame, text='Kümeleme')
notebook.add(summary_frame, text='Sınıflandırma')
notebook.pack(fill='both', padx=2)
# ----------- adding menu bar ------------
menu_bar = Menu(root)
# menu item 1
file_menu = Menu(menu_bar, tearoff=0)
# add sub menus to menu item 1
file_menu.add_command(label="Eğitim kümesini ekle...", accelerator='Ctrl+E', command=open_train)
file_menu.add_command(label="Test kümesini ekle...",accelerator='Ctrl+T', command=open_test)
file_menu.add_separator()
file_menu.add_command(label="Sonuçları kaydet...",accelerator='Ctrl+S', command=save_file)
file_menu.add_separator()
file_menu.add_command(label="Çık",accelerator='Ctrl+Q', command=quit)
menu_bar.add_cascade(label="File", menu=file_menu)
root.config(menu=menu_bar)
# ----------- text areas for train frame --------------
# creating a scroll bar
scrl_train = Scrollbar(train_frame, background='green')
# create text are and connect scroll bar to it
txt_train = Text(train_frame, state=DISABLED, width=600, height=550, yscrollcommand=scrl_train.set, padx=10, pady=10)
# if scroll bar moved, move text
scrl_train.config(command=txt_train.yview)
# put scroll bar on the right
scrl_train.pack(side='right', fill='y')
# add text area to the left
txt_train.pack(side="left", fill="both", expand=True)
# ----------- text areas for test frame --------------
# creating a scroll bar
scrl_test = Scrollbar(test_frame, background='green')
# create text are and connect scroll bar to it
txt_test = Text(test_frame, state=DISABLED, width=600, height=550, yscrollcommand=scrl_test.set, padx=10, pady=10)
# if scroll bar moved, move text
scrl_test.config(command=txt_test.yview)
# put scroll bar on the right
scrl_test.pack(side='right', fill='y')
# add text area to the left
txt_test.pack(side="left", fill="both", expand=True)
# ---------- text area for classification frame ---------------
# creating a scroll bar
scrl_classification = Scrollbar(classification_frame)
# create text are and connect scroll bar to it
txt_classification = Text(classification_frame, state=DISABLED, width=600, height=550,
yscrollcommand=scrl_classification.set, padx=10,
pady=10)
# if scroll bar moved, move text
scrl_classification.config(command=txt_classification.yview)
# put scroll bar on the right
scrl_classification.pack(side='right', fill='y')
# add text area to the left
txt_classification.pack(side="left", fill="both", expand=True)
# ---------- text area for summary frame ---------------
# creating a scroll bar
scrl_summary = Scrollbar(summary_frame)
# create text are and connect scroll bar to it
txt_summary = Text(summary_frame, state=DISABLED, width=600, height=550, yscrollcommand=scrl_summary.set, padx=10,
pady=10)
# if scroll bar moved, move text
scrl_summary.config(command=txt_summary.yview)
# put scroll bar on the right
scrl_summary.pack(side='right', fill='y')
# add text area to the left
txt_summary.pack(side="left", fill="both", expand=True)
root.bind('<Control-e>', open_train)
root.bind('<Control-t>', open_test)
root.bind('<Control-s>', save_file)
root.bind('<Control-q>', quit)
root.mainloop()