-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
176 lines (147 loc) · 6.73 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
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog
from tkinter import messagebox
import run_compare
import os
from collections import OrderedDict
# TODO make an option to select in which order the files will be compared
# TODO check if the numbering is working
class Gui(ttk.Frame):
def __init__(self, root, ):
super().__init__(master=root, padding="3 3 12 12")
self.root = root
self.file_dict = {} # store file-name: file-path pairs
self.file_name_labels = [] # store label objects that are associated with secondary file names
self.file_combos = {} # store combobox objects for secondary files
self.folder_path = ""
self.primary_combo = ""
self.primary_file = ""
# self.label_frame = ""
self.number_of_files = 0
self.loading_progress = None
self.pack()
self.create_widgets()
self.new_frame = ""
self.padd()
def padd(self):
for child in self.winfo_children(): child.grid_configure(padx=5, pady=5)
def check_combo_input(self):
for file_name in self.file_combos:
# print(self.file_combos[file_name].get())
if self.file_combos[file_name][1].current() == -1:
messagebox.showinfo("Error", "Please select match/not match for all files")
return False
elif self.file_combos[file_name][0].current() == -1:
messagebox.showinfo("Error", "Please select a number for all files")
return False
return True
def run_script(self):
# os.chdir(self.folder_path)
if self.check_combo_input():
secondary_files = OrderedDict()
for i in range(1, self.number_of_files):
for file_name in self.file_combos:
if self.file_combos[file_name][0].get() == str(i):
secondary_files[file_name] = "m" if self.file_combos[file_name][1].get() == "match" else "nm"
print(secondary_files)
run_compare.start(self.primary_file, secondary_files, self.folder_path)
# def run_compare(self):
# compare.start("compare_output1.xml", "leptolyngbya.fasta")
def check_subfolders(self, new_folder_path):
for file in os.scandir(new_folder_path):
if file.name == "compare1":
messagebox.showinfo("Error",
"The folder contains subfolders/files named compare_, please remove them before running the script")
return False
return True
def select_folder(self):
new_folder_path = filedialog.askdirectory()
print(new_folder_path)
if new_folder_path:
self.folder_path = new_folder_path
self.file_dict.clear()
if self.check_subfolders(new_folder_path):
for file in os.scandir(new_folder_path):
if file.name.endswith('.fasta'):
self.file_dict[file.name] = file.path
if len(self.file_dict.keys()) < 2:
messagebox.showinfo("Error", "Please select a folder with at least two .fasta files")
else:
print(self.file_dict)
self.number_of_files = len(self.file_dict.keys())
ttk.Label(self, text="The current folder is {}".format(self.folder_path)).grid(column=3, row=2)
self.choose_primary()
# self.create_file_labels()
def primary_selected(self, event):
self.primary_file = self.primary_combo.get()
print(self.primary_file)
# ttk.Separator(self, orient=tk.HORIZONTAL)
self.create_file_labels()
def choose_primary(self):
self.destroy_things()
list = []
for file_name in self.file_dict:
list.append(file_name)
ttk.Label(self, text="Select a Primary file").grid(column=1, row=5)
self.primary_combo = ttk.Combobox(self, values=list, state='readonly')
self.primary_combo.bind('<<ComboboxSelected>>', self.primary_selected)
self.primary_combo.grid(column=2, row=5)
self.padd()
def combo_number_change(self, event):
print(event.widget)
#
# chosen_number = event.widget.get()
# num_list = []
#
# for file_name in self.file_combos:
# number_combo = self.file_combos[file_name][0]
# if number_combo != event.widget:
# number_combo['values'] =
def destroy_things(self):
if self.new_frame != "":
self.new_frame.destroy()
for file_name in self.file_combos:
self.file_combos[file_name][0].destroy()
self.file_combos[file_name][1].destroy()
self.file_combos.clear()
for label in self.file_name_labels:
label.destroy()
self.file_name_labels.clear()
def create_file_labels(self):
row = 7
column = 1
self.destroy_things()
self.new_frame = ttk.Labelframe(self, text="Fasta files")
self.new_frame.grid(column=1, row=6, columnspan=3)
# self.label_frame = ttk.Labelframe(self, text="FASTA files")
# self.label_frame.grid(column=1, row=6)
for file_name in self.file_dict:
label = ttk.Label(self.new_frame, text=file_name)
label.grid(column=column, row=row)
if file_name == self.primary_file:
ttk.Label(self.new_frame, text="Primary").grid(column=column + 1, row=row)
else:
combo = ttk.Combobox(self.new_frame, values=["match", "not match"], state='readonly')
combo.grid(column=column + 1, row=row)
number_list = list(range(1, self.number_of_files))
number_combo = ttk.Combobox(self.new_frame, values=number_list, state='readonly')
number_combo.bind('<<ComboboxSelected>>', self.combo_number_change)
number_combo.grid(column=column + 2, row=row)
self.file_combos[file_name] = [number_combo, combo]
row += 1
self.file_name_labels.append(label)
button = ttk.Button(self.new_frame, text='Go', command=self.run_script)
button.grid(column=column, row=row)
for child in self.new_frame.winfo_children(): child.grid_configure(padx=5, pady=5)
self.padd()
def create_widgets(self):
label = ttk.Label(self, text='Select a folder:').grid(column=1, row=2)
button_folder = ttk.Button(self, text='Browse...', command=self.select_folder).grid(column=2, row=2)
ttk.Separator(self, orient=tk.HORIZONTAL)
if __name__ == '__main__':
root = tk.Tk()
root.title("SeqCompare")
root.minsize(800, 480)
app = Gui(root)
app.mainloop()