-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmain_gui.py
More file actions
210 lines (162 loc) · 7.01 KB
/
main_gui.py
File metadata and controls
210 lines (162 loc) · 7.01 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
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
#!/usr/bin/python
# By Hernan Chavez Thielemann
__author__ = 'Hernan Chavez Thielemann <hchavezthiele at gmail dot com>'
# checked ok 30/04/2018
#------------------------------------------------------
#/// Packages and globals definitions are here ///
#------------------------------------------------------
from os.path import dirname, realpath
from sys import exit
from lib.gui.tk_lib import Tk, Frame, Label, TclError, PhotoImage, createmenubar
from lib.gui.conversion_gui import Conversion
from lib.gui.script_gui import Script_GUI
from lib.gui.run_gui import Run_GUI
from lib.gui.popup import AboutPopUp
from lib.misc.display import show
from lib.misc.warn import wrg_3
from lib.misc.file import run_command
from lib.misc.version import __version__
#------------------------------------------------------
'''/////////////// Class /////////////'''
#------------------------------------------------------
class Gro2Lam_GUI(Frame):
''' Graphic User Interface '''
def __init__(self, master=None, test = False):
Frame.__init__(self, master)
_ver= __version__.split()
self.master.title(" "*5+"{} {}".format(_ver[0],_ver[2]))#.master
self.pack() # ... why I'm packing here?? coords?
self.test = test
# images storaging
dir_path = dirname( realpath( __file__))
self.img = dict()
self.img['logo'] = PhotoImage( file = dir_path + "/img/logo.ppm")
self.img['help'] = PhotoImage( file = dir_path + "/img/help.ppm")
self.img['file'] = PhotoImage( file = dir_path + "/img/file.ppm")
self.img['gear'] = PhotoImage( file = dir_path + "/img/gear.ppm")
# body init
self.prevailing_body = 0
self.body = None
self.MAINVERTEX = [ 0, 0, 0, 0, 0, 0]
# Conversion gathered data container
self._convert_ = {'setup' : [], 'solvation': []}
self._convertdata_= None
# Script part
self._script_ = {'mainpage' : [], 'advanced': [], 'restrain': []}
self.createmainPennon()
def createmainPennon(self):
'''Self explanatory neated with subroutines to make it more readable'''
row = Frame(self,bg = "white")
Label( row, bg = "white",
image = self.img['logo']).pack( side= 'left', padx=25)
row.pack(side="top", fill='x', padx=1)
self.swapbody(1)
def swapbody(self, _pbody_):# checked ok 16/09 -----------WF
''' Deletes and clean the last generated body
maybe lacks a real body destroyer?? but works fine with
this, because it is just a "small" overlapping I gess
'''
if self.prevailing_body != _pbody_:
if self.body == None:
self.body = self.create_conversion_gui()
else:
self.body.destroy()
if _pbody_==1:
show( 'Swapping to gro2lam converter GUI')
self.body = self.create_conversion_gui()
elif _pbody_==2:
show( 'Swapping to input script generator GUI')
self.body = self.create_script_gui()
elif _pbody_==3:
show( 'Swapping to run script GUI')
self.body = self.create_run_gui()
else:
exit('Wuut...')
self.prevailing_body = _pbody_
self.body.createWidgets()
self.body.b1.focus()
self.master.bind('<Return>', self.b1_hook )
self.master.bind('<Escape>', self.quit_hook )
self.body.pack(side='top', fill='x')
def b1_hook(self, event=None):
self.body.b1.invoke()
def quit_hook(self, event=None):
self.body.quit()
def swap_hook(self):
_l_ = [1,2,3]
b = _l_[_l_.index(self.prevailing_body)-2]
self.swapbody(b)
def create_conversion_gui(self):
'Hook to create conversion gui'
return Conversion(self)# Hook
def create_script_gui(self):
'Hook to create script gui'
return Script_GUI(self)# Hook
def create_run_gui(self):
'Hook to create run gui'
return Run_GUI(self)# Hook
#------------------------------------------------------
'''/////////////// Sub routines /////////////'''
#------------------------------------------------------
def launch_gui( started = False):
''' launcher
Main GUI constructor
'''
show( wrg_3('Before you start, make sure there are no comments',
'(;) in the middle of a line of the input GROMACS files.',
'Data after this symbol are not taken into account.') )
MasterWin = Tk()
prompt = Gro2Lam_GUI( master= MasterWin, test = started)# xl_App
# Top main pennon menu bar definition
entry_list_of_dicts = [{ 'title' : 'File',
'cascade' : (('Quit' ,MasterWin.quit), ) },
{ 'title' : 'Data File Creation',
'title_com' : (prompt.swapbody , 1)},
{ 'title' : 'Input File Creation',
'title_com' : (prompt.swapbody , 2)},
{ 'title' : 'Run',
'title_com' : (prompt.swapbody , 3)},
{ 'titlei' : prompt.img['help'],
'cascade' : (('User manual' , showuserman),
('About' , launch_about, prompt),)}
]
createmenubar(MasterWin, entry_list_of_dicts)
w = 460
h = 570
# get screen width and height
ws = MasterWin.winfo_screenwidth() # width of the screen
hs = MasterWin.winfo_screenheight() # height of the screen
# calculate x and y coordinates for the Tk root window
x = int( (ws/6.0) - (w/2.0))
if x < 100:
x = 100
y = int( (hs/3.0) - (h/2.0))
if y < 40:
y = 40
#show([ws, hs, w, h, x, y] )
prompt.MAINVERTEX = [ws, hs, w, h, x, y]
show( prompt.MAINVERTEX, v = 4)
# set the dimensions of the screen
# and where it is placed
MasterWin.geometry('{:d}x{:d}+{:d}+{:d}'.format( *prompt.MAINVERTEX[2:]))
prompt.mainloop()
try:
MasterWin.destroy()
except TclError:
pass
def showlicence():
show( 'Opening licence file')
command = 'gedit ./lib/docs/LICENSE'#
run_command( command)
def launch_about( _master_window_):
show( 'Launching about')
title_txt = ' '*10+'ABOUT GROTOLAM'
pop = AboutPopUp(master = _master_window_,
title = title_txt,
licence = showlicence
)
def showuserman():
show( 'Opening readme file')
command = 'gedit ./lib/docs/README.md'#
run_command(command)
# vim:tw=80