-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGUI.py
543 lines (449 loc) · 22.7 KB
/
GUI.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# from tkinter import *
from tkinter import Frame, Text, Button, Menu, Label, W, E, END, Tk
from tkinter.filedialog import askopenfilename, askdirectory, Toplevel, CENTER, askopenfilenames
from tkinter.messagebox import *
from tkinter.scrolledtext import ScrolledText
from log_parser_Hoang import *
from qcat_exp import *
from UpLinkAnalysis import *
from variable import *
# from variable import log_file_PATH, config_file_PATH, csv_folder_PATH, raw_log_file_PATH
# IMPORTAN PATH
# config_file_PATH = r''
# log_file_PATH = r''
# csv_folder_PATH = r''
# csv_dict = {}
#
# log_type_list_brief = []
# log_type_list_full = []
class Window(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.master = master
self.master.title("LOG ANALYSIS TOOLS")
self.QCAT_func_button = Button(self.master, text='QCAT Automation', command=self.Call_Open_QCAT)
self.QCAT_func_button.config(width=25, heigh=2, padx=5, pady=5)
# self.QCAT_func_button.grid(row = 0, column = 0, columnspan=2)
self.QCAT_func_button.place(relx=0.5, rely=0.2, anchor=CENTER)
self.Table_func_button = Button(self.master, text='Convert Table Automation',
command=self.Call_Convert_Table_Auto)
self.Table_func_button.config(width=25, heigh=2, padx=5, pady=5)
self.Table_func_button.place(relx=0.5, rely=0.4, anchor=CENTER)
self.Table_func_button = Button(self.master, text='Uplink Table Merge',
command=self.Call_Uplink_Analysis)
self.Table_func_button.config(width=25, heigh=2, padx=5, pady=5)
self.Table_func_button.place(relx=0.5, rely=0.6, anchor=CENTER)
def Call_Open_QCAT(self):
self.newWindow = Toplevel(self.master)
self.app = QCAT_Auto(self.newWindow)
def Call_Convert_Table_Auto(self):
self.newWindow = Toplevel(self.master)
self.app = Convert_Table_Auto(self.newWindow)
def Call_Uplink_Analysis(self):
self.newWindow = Toplevel(self.master)
self.app = Uplink_Analysis(self.newWindow)
######################
class Convert_Table_Auto(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.master.title("Conver Table Automation")
######################################################################################################
self.config_file_PATH_label = Label(self.master, text="Config file path")
self.config_file_PATH_label.grid(row=0, column=0, sticky=W, pady=2)
self.config_file_PATH_txt = Text(self.master, heigh=1, width=35)
self.config_file_PATH_txt.grid(row=0, column=1, pady=2)
self.log_file_PATH_label = Label(self.master, text="Log files dir")
self.log_file_PATH_label.grid(row=1, column=0, sticky=W, pady=2)
self.log_file_PATH_txt = Text(self.master, heigh=1, width=35)
self.log_file_PATH_txt.grid(row=1, column=1, pady=2)
self.qcat_input_label = Label(self.master, text='')
self.log_type_label = Label(self.master, text="Information")
self.log_type_label.grid(row=2, column=0, sticky=W)
self.log_type_txt = ScrolledText(self.master, undo=True, width=55)
self.log_type_txt.grid(row=3, rowspan=4, column=0, columnspan=3, sticky=W)
self.csv_dir_label = Label(self.master, text="CSV directory")
self.csv_dir_label.grid(row=8, column=0, sticky=W)
self.csv_dir_txt = Text(self.master, heigh=1, width=35)
self.csv_dir_txt.grid(row=8, column=0, columnspan=3, padx=80, sticky=W)
######################################################################################################
self.convert_csv_button = Button(self.master, text='Convert to csv', command=self.call_convert_csv)
self.convert_csv_button.grid(row=8, column=1, columnspan=2, sticky=E, pady=2, padx=3)
self.convert_csv_button.config(width=11, heigh=2)
self.extract_config_button = Button(self.master, text="Extract", command=self.call_extract)
self.extract_config_button.grid(row=0, column=2, sticky=E, padx=4)
# self.view_log_button = Button(self.master, text = "View")
# self.view_log_button.grid(row=1, column=2, sticky=E, padx=4)
###############################################################################
# creating a menu instance
self.menu = Menu(self.master)
self.master.config(menu=self.menu)
# create the file object)
self.file = Menu(self.menu)
# adds a command to the menu option, calling it exit, and the
# command it runs on event is client_exit
# self.file.add_command(label="QCAT Automation", command = self.openQCAT)
self.file.add_command(label="Open Config", command=self.open_config)
self.file.add_command(label="Choose Log Files", command=self.open_log)
self.file.add_command(label="Set CSV Directory", command=self.set_csv_directory)
self.file.add_command(label="Exit", command=self.client_exit)
self.menu.add_cascade(label="File", menu=self.file)
# menu.add_cascade(label="Open config", menu=file)
self.edit = Menu(self.menu)
self.menu.add_cascade(label="Edit", menu=self.edit)
self.help = Menu(self.menu)
self.help.add_command(label="About", command=self.show_about)
self.help.add_command(label="Instruction", command=self.show_instruction)
self.menu.add_cascade(label="Help", menu=self.help)
####################################################################################
def client_exit(self):
exit()
def open_config(self):
###Test
# global config_file_PATH
# config_file_PATH = r'G:\PycharmProjects\Log_Extractor\parser.cfg'
filename = askopenfilename(initialdir='/', title="Select file",
filetypes=(("config file", "*.cfg"), ("all files", "*.*")))
if filename:
global config_file_PATH
config_file_PATH = filename
print(config_file_PATH)
# self.update_text()
self.config_file_PATH_txt.delete("1.0", "end")
self.config_file_PATH_txt.insert(END, config_file_PATH)
else:
showerror("Error", "No file selected")
def open_log(self):
# Test
# global log_file_PATH
# log_file_PATH = r'G:\PycharmProjects\Log_Extractor\Test\log_test.txt'
log_paths = askopenfilenames(initialdir='/', title="Select file",
filetypes=(("log file", "*.log"), ("text file", "*.txt"), ("all files", "*.*")))
# log_path = askdirectory()
if log_paths:
global log_file_PATH
for path in log_paths:
log_file_PATH.append(path)
# log_file_PATH = log_paths
print(log_paths)
self.log_file_PATH_txt.delete("1.0", "end")
self.log_file_PATH_txt.insert(END, log_file_PATH)
else:
showerror("Error", "No file selected")
def set_csv_directory(self):
csv_dir = askdirectory()
if csv_dir:
global csv_folder_PATH
csv_folder_PATH = csv_dir
self.csv_dir_txt.delete("1.0", "end")
self.csv_dir_txt.insert(END, csv_dir)
else:
showerror("Error", "No directory selected")
##Test'
# global csv_folder_PATH
# csv_folder_PATH = r'C:\Users\Admin\Desktop\test'
def call_extract(self):
global config_file_PATH
global log_type_list_brief, log_type_list_full
# if config_file_PATH == '':
# self.log_type_txt.insert("Error, No file selected")
# # showerror("Error", "No file selected")
# return
try:
self.log_type_txt.insert(END, "Extracting...\n")
lines = read_file(config_file_PATH)
log_type_list_brief, log_type_list_full = read_config_log_types(lines)
if len(log_type_list_brief) != 0:
# self.log_type_txt.delete("1.0", "end")
for log in log_type_list_brief:
self.log_type_txt.insert(END, log + '\n')
self.log_type_txt.insert(END, "Extract successfully\n")
# showinfo("Respond", "Extract successfully")
else:
showwarning("Config Empty", "No log type found in config file. Try again!")
except:
# self.log_type_txt.delete("1.0", "end")
self.log_type_txt.insert(END, "Error extracting\n")
def call_convert_csv(self):
global csv_dict, csv_folder_PATH, log_file_PATH, log_type_list_brief
print(log_type_list_brief)
if csv_folder_PATH == '':
self.log_type_txt.insert(END, "You need to select csv directory before convert\n")
return
try:
self.log_type_txt.insert(END, "Converting! Please wait...\n")
for t in log_type_list_brief: # init dict of log data list for csv
csv_dict[t] = [0, []]
parse_log(log_file_PATH, log_type_list_brief, csv_dict)
write_csv(csv_folder_PATH, csv_dict)
self.log_type_txt.insert(END, "Converting successful\n")
except:
self.log_type_txt.insert(END, "Fail converting!\n")
# showerror("Error", "Error Converting")
# def openQCAT(self):
# self.newWindow = Toplevel(self.master)
# self.app = QCAT_Auto(self.newWindow)
def show_instruction(self):
pass
def show_about(self):
pass
class QCAT_Auto(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.master.title("QCAT Automation")
######################################################################################################
self.config_file_PATH_label = Label(self.master, text="Config file path")
self.config_file_PATH_label.grid(row=0, column=0, sticky=W, pady=2)
self.config_file_PATH_txt = Text(self.master, heigh=1, width=35)
self.config_file_PATH_txt.grid(row=0, column=1, pady=2)
self.raw_log_file_PATH_label = Label(self.master, text="Raw Log file path")
self.raw_log_file_PATH_label.grid(row=1, column=0, sticky=W, pady=2)
self.raw_log_file_PATH_txt = Text(self.master, heigh=1, width=35)
self.raw_log_file_PATH_txt.grid(row=1, column=1, pady=2)
# self.qcat_input_label = Label(self.master, text = '')
self.log_type_label = Label(self.master, text="Information")
self.log_type_label.grid(row=2, column=0, sticky=W)
self.log_type_txt = ScrolledText(self.master, undo=True, width=55)
self.log_type_txt.grid(row=3, rowspan=4, column=0, columnspan=3, sticky=W)
self.QCAT_txt_dir_label = Label(self.master, text="QCAT Output\nDirectory")
self.QCAT_txt_dir_label.grid(row=8, column=0, sticky=W)
self.QCAT_txt_dir_txt = Text(self.master, heigh=1, width=35)
self.QCAT_txt_dir_txt.grid(row=8, rowspan=2, column=0, columnspan=3, padx=80, sticky=W)
######################################################################################################
self.Import_txt_button = Button(self.master, text='Import to txt', command=self.call_import_txt)
self.Import_txt_button.grid(row=8, column=1, columnspan=2, sticky=E, pady=2, padx=3)
self.Import_txt_button.config(width=11, heigh=2)
self.extract_config_button = Button(self.master, text="Extract", command=self.call_extract)
self.extract_config_button.grid(row=0, column=2, sticky=E, padx=4)
# self.view_log_button = Button(self.master, text = "View")
# self.view_log_button.grid(row=1, column=2, sticky=E, padx=4)
###############################################################################
# creating a menu instance
self.menu = Menu(self.master)
self.master.config(menu=self.menu)
# create the file object)
self.file = Menu(self.menu)
# adds a command to the menu option, calling it exit, and the
# command it runs on event is client_exit
# self.file.add_command(label="QCAT Automation", command = self.openQCAT)
self.file.add_command(label="Open Config", command=self.open_config)
self.file.add_command(label="Open Raw Log", command=self.open_raw_log)
self.file.add_command(label="Set Output Directory", command=self.set_output_directory)
self.file.add_command(label="Exit", command=self.client_exit)
self.menu.add_cascade(label="File", menu=self.file)
# menu.add_cascade(label="Open config", menu=file)
self.edit = Menu(self.menu)
self.menu.add_cascade(label="Edit", menu=self.edit)
self.help = Menu(self.menu)
self.help.add_command(label="About", command=self.show_about)
self.help.add_command(label="Instruction", command=self.show_instruction)
self.menu.add_cascade(label="Help", menu=self.help)
####################################################################################
def client_exit(self):
exit()
def open_config(self):
###Test
# global config_file_PATH
# config_file_PATH = r'G:\PycharmProjects\Log_Extractor\parser.cfg'
filename = askopenfilename(initialdir='/', title="Select file",
filetypes=(("config file", "*.cfg"), ("all files", "*.*")))
if filename:
global QCAT_config_file_PATH
QCAT_config_file_PATH = filename
print(config_file_PATH)
# self.update_text()
self.config_file_PATH_txt.delete("1.0", "end")
self.config_file_PATH_txt.insert(END, QCAT_config_file_PATH)
else:
showerror("Error", "No file selected")
def open_raw_log(self):
# Test
# global log_file_PATH
# log_file_PATH = r'G:\PycharmProjects\Log_Extractor\Test\log_test.txt'
log_path = askopenfilename(initialdir='/', title="Select file",
filetypes=(("raw log file", "*.qmdl *.dlf *.isf"), ("dlf file", "*.dlf"), ("all files", "*.*")))
if log_path:
global QCAT_raw_log_file_PATH
QCAT_raw_log_file_PATH = log_path
print(log_path)
self.raw_log_file_PATH_txt.delete("1.0", "end")
self.raw_log_file_PATH_txt.insert(END, QCAT_raw_log_file_PATH)
else:
showerror("Error", "No file selected")
def set_output_directory(self):
csv_dir = askdirectory()
if csv_dir:
global QCAT_output_directory
QCAT_output_directory = csv_dir
self.QCAT_txt_dir_txt.delete("1.0", "end")
self.QCAT_txt_dir_txt.insert(END, csv_dir)
else:
showerror("Error", "No directory selected")
##Test'
# global csv_folder_PATH
# csv_folder_PATH = r'C:\Users\Admin\Desktop\test'
def call_extract(self):
global QCAT_config_file_PATH
global QCAT_log_list_brief, QCAT_log_list_full
try:
self.log_type_txt.insert(END, "Extracting...\n")
lines = read_file(QCAT_config_file_PATH)
QCAT_log_list_brief, QCAT_log_list_full = read_config_log_types(lines)
if len(QCAT_log_list_brief) != 0:
# self.log_type_txt.delete("1.0", "end")
for log in QCAT_log_list_brief:
self.log_type_txt.insert(END, log + '\n')
self.log_type_txt.insert(END, "Extract successfully\n")
# showinfo("Respond", "Extract successfully")
else:
showwarning("Config Empty", "No log type found in config file. Try again!")
except:
# self.log_type_txt.delete("1.0", "end")
self.log_type_txt.insert(END, "Error extracting\n")
def call_import_txt(self):
global QCAT_raw_log_file_PATH, QCAT_output_directory, QCAT_log_list_brief
self.log_type_txt.insert(END, "Importing! Please wait...\n")
if QCAT_raw_log_file_PATH == '' or QCAT_output_directory == '' or len(QCAT_log_list_brief) == 0:
self.log_type_txt.insert(END, "Error, Please check raw log path, output directory and config file\n")
try:
QCAT_Execute(QCAT_raw_log_file_PATH, QCAT_log_list_brief, QCAT_output_directory)
self.log_type_txt.insert(END, "Import successful")
except:
self.log_type_txt.insert(END, "Error importing\n")
# def openQCAT(self):
# self.newWindow = Toplevel(self.master)
# self.app = QCAT_Auto(self.newWindow)
def show_instruction(self):
pass
def show_about(self):
pass
class Uplink_Analysis(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.master = master
self.master.geometry("420x200")
self.master.title("Uplink Analysis")
self.PwCtrl_file_PATH_label = Label(self.master, text="Power Control File Path")
self.PwCtrl_file_PATH_label.grid(row=0, column=0, sticky=W, pady=2)
self.PwCtrl_file_PATH_txt = Text(self.master, heigh=1, width=35)
self.PwCtrl_file_PATH_txt.grid(row=0, column=1, pady=2)
self.DCI_file_PATH_label = Label(self.master, text="DCI File Path")
self.DCI_file_PATH_label.grid(row=1, column=0, sticky=W, pady=2)
self.DCI_file_PATH_txt = Text(self.master, heigh=1, width=35)
self.DCI_file_PATH_txt.grid(row=1, column=1, pady=2)
self.TxReport_file_PATH_label = Label(self.master, text="Tx Report File Path")
self.TxReport_file_PATH_label.grid(row=2, column=0, sticky=W, pady=2)
self.TxReport_file_PATH_txt = Text(self.master, heigh=1, width=35)
self.TxReport_file_PATH_txt.grid(row=2, column=1, pady=2)
self.PHICH_file_PATH_label = Label(self.master, text="PHICH File Path")
self.PHICH_file_PATH_label.grid(row=3, column=0, sticky=W, pady=2)
self.PHICH_file_PATH_txt = Text(self.master, heigh=1, width=35)
self.PHICH_file_PATH_txt.grid(row=3, column=1, pady=2)
self.Output_dir_label = Label(self.master, text="Output directory")
self.Output_dir_label.grid(row=4, column=0, sticky=W, pady=2)
self.Output_dir_txt = Text(self.master, heigh=1, width=35)
self.Output_dir_txt.grid(row=4, column=1, pady=2)
# Button config
self.merge_button = Button(self.master, text = 'Merge Table', command = self.call_merge)
self.merge_button.config(width=10, heigh=4)
self.merge_button.grid(row = 5, column=0, columnspan = 2, sticky = E)
self.menu = Menu(self.master)
self.master.config(menu=self.menu)
# create the file object)
self.file = Menu(self.menu)
# adds a command to the menu option, calling it exit, and the
# command it runs on event is client_exit
self.file.add_command(label="Open Power Control file", command=self.open_PwCtrl)
self.file.add_command(label="Open DCI file", command=self.open_DCI)
self.file.add_command(label="Open Tx Report file", command=self.open_TxReport)
self.file.add_command(label="Open PHICH file", command=self.open_PHICH)
self.file.add_command(label="Set oput directory", command=self.set_dir)
self.file.add_command(label="Exit", command=self.client_exit)
self.menu.add_cascade(label="File", menu=self.file)
# menu.add_cascade(label="Open config", menu=file)
self.edit = Menu(self.menu)
self.menu.add_cascade(label="Edit", menu=self.edit)
self.help = Menu(self.menu)
self.help.add_command(label="About", command=self.show_about)
self.help.add_command(label="Instruction", command=self.show_instruction)
self.menu.add_cascade(label="Help", menu=self.help)
def open_PwCtrl(self):
filename = askopenfilename(initialdir='/', title="Select file",
filetypes=(("csv file", "*.csv"), ("all files", "*.*")))
if filename:
global pw_ctrl_path
pw_ctrl_path = filename
print(pw_ctrl_path)
# self.update_text()
self.PwCtrl_file_PATH_txt.delete("1.0", "end")
self.PwCtrl_file_PATH_txt.insert(END, pw_ctrl_path)
else:
showerror("Error", "No file selected")
def open_DCI(self):
filename = askopenfilename(initialdir='/', title="Select file",
filetypes=(("csv file", "*.csv"), ("all files", "*.*")))
if filename:
global dci_path
dci_path = filename
print(dci_path)
# self.update_text()
self.DCI_file_PATH_txt.delete("1.0", "end")
self.DCI_file_PATH_txt.insert(END, dci_path)
else:
showerror("Error", "No file selected")
def open_TxReport(self):
filename = askopenfilename(initialdir='/', title="Select file",
filetypes=(("csv file", "*.csv"), ("all files", "*.*")))
if filename:
global tx_report_path
tx_report_path = filename
print(tx_report_path)
# self.update_text()
self.TxReport_file_PATH_txt.delete("1.0", "end")
self.TxReport_file_PATH_txt.insert(END, tx_report_path)
else:
showerror("Error", "No file selected")
def open_PHICH(self):
filename = askopenfilename(initialdir='/', title="Select file",
filetypes=(("csv file", "*.csv"), ("all files", "*.*")))
if filename:
global phich_path
phich_path = filename
print(phich_path)
# self.update_text()
self.PHICH_file_PATH_txt.delete("1.0", "end")
self.PHICH_file_PATH_txt.insert(END, phich_path)
else:
showerror("Error", "No file selected")
def set_dir(self):
dir = askdirectory()
if dir:
global output_path
output_path = dir
print(output_path)
self.Output_dir_txt.delete("1.0", "end")
self.Output_dir_txt.insert(END, output_path)
else:
showerror("Error", "No directory selected")
def call_merge(self):
global pw_ctrl_path, dci_path, tx_report_path, phich_path, output_path
try:
Execute(pw_ctrl_path, dci_path, tx_report_path, phich_path, output_path)
except:
showerror("Error", "Check files or directory")
def client_exit(self):
exit()
def show_about(self):
pass
def show_instruction(self):
pass
# root window created. Here, that would be the only window, but
# you can later have windows within windows.
root = Tk()
root.geometry("300x300")
root.resizable(width=False, height=False)
# creation of an instance
app = Window(root)
# mainloop
root.mainloop()