-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQMPrimers.py
139 lines (105 loc) · 4 KB
/
QMPrimers.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 8 15:30:29 2018
@author: David Soldevila
"""
from tkinter import filedialog
from tkinter import *
from tkinter.font import Font
import tkinter.ttk as ttk
import os
import pandas as pd
from simulation_frontend import *
from matching_frontend import *
class TextRedirector(object):
def __init__(self, widget, tag="stdout"):
self.widget = widget
self.tag = tag
def write(self, str):
self.widget.configure(state="normal")
self.widget.insert("end", str, (self.tag,))
self.widget.yview(END)
class GUI(Frame):
def __init__(self, parent=Frame):
parent.protocol('WM_DELETE_WINDOW', (lambda: self.finnish(parent)))
self.main_frame = Frame.__init__(self, parent)
"""Other"""
self.current_directory = os.getcwd()
"""Menu Bar demo"""
"""
self.main_menu = Menu(parent)
parent.config(menu=self.main_menu)
file = Menu(self.main_menu, tearoff=False)
file.add_command(label="Option 1")
file.add_command(label="Option 2...")
self.main_menu.add_cascade(label="File", menu=file)
"""
"""Tabs"""
nb = ttk.Notebook(self.main_frame)
page2 = ttk.Frame(nb)
self.gui_simulate = GUI_simulate(page2)
page1 = ttk.Frame(nb)
self.gui_matching = GUI_matching(page1, self.gui_simulate)
self.gui_matching.pack()
nb.add(page1, text="Matching")
self.gui_simulate.pack()
nb.add(page2, text="Simulation")
nb.pack(fill=BOTH, expand=NO)
"""Terminal"""
self.terminal_frame = Frame(self.main_frame)
self.text = Text(self.terminal_frame, wrap="word")
self.text.pack(fill=BOTH, expand=YES)
self.text.tag_configure("stderr", foreground="#b22222")
"""STDOUT redirect"""
sys.stdout = TextRedirector(self.text, "stdout")
#sys.stderr = TextRedirector(self.text, "stderr")
"""Verbose"""
self.extra_frame = Frame(self.main_frame)
self.is_verbose = BooleanVar()
Checkbutton(self.extra_frame, variable=self.is_verbose, text="verbose", command=self.update_verbosity).pack(expand=NO)
self.is_verbose.set(False)
init_logger()
self.update_verbosity()
#Packing Terminal and Verbose
self.extra_frame.pack(side=BOTTOM, expand=NO, fill=X)
self.terminal_frame.pack(side=BOTTOM, expand=YES, fill=BOTH)
def update_verbosity(self):
set_verbosity(self.is_verbose.get())
def finnish(self, parent):
close_logger()
parent.destroy()
def get_help():
info = {"PARAMETERS" : "\t-------------",
"--help": "\tDisplay this message",
"--sim": "\tSimulation mode",
"--match": "\tMatching mode",
"GUI mode": "To open the graphical mode, do not pass any parameter"}
print("QMPRIMERS HELP PAGE");
for param in info:
print(param, ": ", info[param])
return
def main(argv):
if(len(argv)>0 ):
init_logger()
if(argv[0]=="--sim"):
sim_cl(argv[1:])
elif(argv[0]=="--match"):
matching_cl(argv[1:])
elif(argv[0]=="--help"):
get_help()
else:
print("Unknown command ",argv[0],". Use --help to display the manual.")
close_logger()
else:
saved_sys_stdout = sys.stdout
saved_sys_stderr = sys.stderr
root = Tk()
root.title("QMPrimers")
root.geometry('900x400')
main_window = GUI(root)
root.mainloop()
sys.stdout = saved_sys_stdout
sys.stderr = saved_sys_stderr
if (__name__=="__main__"):
main(sys.argv[1:])