Skip to content

Commit 39bbf22

Browse files
committed
pylint fixes and workaround for mac users
1 parent dcd91af commit 39bbf22

File tree

3 files changed

+70
-74
lines changed

3 files changed

+70
-74
lines changed

pygem/gui.py

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44
.. todo::
55
Switch to Ttk instead of Tk for a better look of the GUI
66
"""
7-
87
import Tkinter
98
from tkFileDialog import askopenfilename
10-
import pygem as pg
11-
import sys
129
import os
1310
import webbrowser
14-
1511
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
16-
from matplotlib.figure import Figure
1712

1813

1914
class Gui(object):
@@ -22,8 +17,8 @@ class Gui(object):
2217
2318
:cvar string filename_geometry: input geometry to be morphed.
2419
:cvar string filename_parameters: input parameters file for FFD.
25-
:cvar int check_var_1: dump or not the original FFD lattice.
26-
:cvar int check_var_2: dump or not the morphed FFD lattice.
20+
:cvar int check_var_dump_orig: dump or not the original FFD lattice.
21+
:cvar int check_var_dump_morphed: dump or not the morphed FFD lattice.
2722
:cvar string outfilename: name of the output file geometry.
2823
The extension of the file is set automatically equal to the on of input file 'filename_geometry'.
2924
:cvar string outfilename_lattice_orig: name of the dumped file for the original lattice.
@@ -32,29 +27,26 @@ class Gui(object):
3227
The extension of the file is set automatically equal to '.vtk'.
3328
:cvar Tkinter.Tk root: main window object of the GUI.
3429
:cvar string print_geometry_path: geometry path to be printed close to the 'pick geometry' button.
35-
:cvar string print_parameter_path: parameters file path to be printed close to the 'pick parameters' button.
30+
:cvar string print_parameter_path: parameters file path to be printed close to the
31+
'pick parameters' button.
3632
:cvar Tkinter.Label label_geo: label related to 'print_geometry_path'.
3733
:cvar Tkinter.Label label_params: label related to 'print_parameters_path'.
3834
:cvar string url: url of the github page of PyGeM.
3935
:cvar Tkinter.Canvas logo_panel: canvas for PyGeM logo.
4036
:cvar Tkinter.PhotoImage img: PyGeM logo.
4137
:cvar Tkinter.Frame orig_geo_frame: frame for plotting of the original geometry.
4238
:cvar Tkinter.Frame mod_geo_frame: frame for plotting of the final geometry.
43-
4439
"""
45-
4640
def __init__(self):
47-
4841
self.root = Tkinter.Tk()
4942
self.root.resizable(width=False, height=False)
5043
self.root.minsize(width=1400, height=400)
5144
self.root.maxsize(width=1400, height=400)
5245
self.root.title('PyGeM')
53-
5446
self.filename_geometry = Tkinter.StringVar()
5547
self.filename_parameters = Tkinter.StringVar()
56-
self.check_var_1 = Tkinter.IntVar()
57-
self.check_var_2 = Tkinter.IntVar()
48+
self.check_var_dump_orig = Tkinter.IntVar()
49+
self.check_var_dump_morphed = Tkinter.IntVar()
5850
self.outfilename = Tkinter.StringVar()
5951
self.outfilename_lattice_orig = Tkinter.StringVar()
6052
self.outfilename_lattice_mod = Tkinter.StringVar()
@@ -74,8 +66,9 @@ def _chose_geometry(self):
7466
The private method explores the file system and allows to select the wanted geometry.
7567
Up to now, you can select only IGES, OpenFOAM, STL, UNV or VTK geometry file.
7668
"""
77-
self.filename_geometry = askopenfilename(filetypes=[("IGES File",('*.iges', '*.igs')), \
78-
("OpenFOAM File",'*'),('STL File','*.stl'),('UNV File','*.unv'),('VTK File','*.vtk'),('All','*')])
69+
self.filename_geometry = askopenfilename(filetypes=[("IGES File", ('*.iges', '*.igs')), \
70+
("OpenFOAM File", '*'), ('STL File', '*.stl'), ('UNV File', '*.unv'), \
71+
('VTK File', '*.vtk'), ('All', '*')])
7972
self.print_geometry_path.set(self.filename_geometry)
8073
self.label_geo.configure(fg='green')
8174

@@ -85,7 +78,7 @@ def _chose_parameters(self):
8578
The private method explores the file system and allows to select the wanted parameters file.
8679
It visualizes only .prm files.
8780
"""
88-
self.filename_parameters = askopenfilename(filetypes=[("Params File","*.prm")])
81+
self.filename_parameters = askopenfilename(filetypes=[("Params File", "*.prm")])
8982
self.print_parameter_path.set(self.filename_parameters)
9083
self.label_params.configure(fg='green')
9184

@@ -94,45 +87,44 @@ def _run_simulation(self):
9487
"""
9588
The private method runs the geometrical morphing.
9689
"""
90+
import pygem as pg
9791
params = pg.params.FFDParameters()
9892
params.read_parameters(filename=self.filename_parameters)
9993

100-
(__,file_extension_in) = os.path.splitext(self.filename_geometry)
101-
102-
if file_extension_in == '.stl':
103-
geo_handler = pg.stlhandler.StlHandler()
104-
elif file_extension_in in ['.iges', '.igs']:
105-
geo_handler = pg.igeshandler.IgesHandler()
106-
elif file_extension_in == '.unv':
107-
geo_handler = pg.unvhandler.UnvHandler()
108-
elif file_extension_in == '':
109-
geo_handler = pg.openfhandler.OpenFoamHandler()
110-
elif file_extension_in == '.vtk':
111-
geo_handler = pg.vtkhandler.VtkHandler()
94+
file_extension_in = os.path.splitext(self.filename_geometry)[-1]
95+
ext_handlers = {'.stl': pg.stlhandler.StlHandler(), \
96+
'.iges': pg.igeshandler.IgesHandler(), \
97+
'.igs': pg.igeshandler.IgesHandler(), \
98+
'.unv': pg.unvhandler.UnvHandler(), \
99+
'': pg.openfhandler.OpenFoamHandler(), \
100+
'.vtk': pg.vtkhandler.VtkHandler()}
101+
102+
if file_extension_in in ext_handlers:
103+
geo_handler = ext_handlers[file_extension_in]
112104
else:
113-
raise NotImplementedError("Format not implemented yet")
114-
115-
mesh_points = geo_handler.parse(self.filename_geometry)
105+
raise NotImplementedError("Format not implemented yet.")
116106

107+
mesh_points = geo_handler.parse(self.filename_geometry)
117108
free_form = pg.freeform.FFD(params, mesh_points)
118109
free_form.perform()
119110
new_mesh_points = free_form.modified_mesh_points
120111

121112
geo_handler.write(new_mesh_points, self.outfilename.get() + file_extension_in)
122113

123-
if self.check_var_1.get() == 1:
114+
if self.check_var_dump_orig.get() == 1:
124115
pg.utils.write_bounding_box(params, self.outfilename_lattice_orig.get() + '.vtk', False)
125-
if self.check_var_2.get() == 1:
116+
if self.check_var_dump_morphed.get() == 1:
126117
pg.utils.write_bounding_box(params, self.outfilename_lattice_mod.get() + '.vtk', True)
127118

128119
if file_extension_in in ['.vtk', '.stl', '.iges', '.igs']:
129120
figure_in = geo_handler.plot()
130121
figure_in.set_size_inches(4, 3)
131-
FigureCanvasTkAgg(figure_in, master=self.orig_geo_frame).get_tk_widget().grid(row=1, column=0, padx=5, pady=5)
132-
122+
FigureCanvasTkAgg(figure_in, master=self.orig_geo_frame).get_tk_widget().grid(row=1, column=0, \
123+
padx=5, pady=5)
133124
figure_out = geo_handler.plot(self.outfilename.get() + file_extension_in)
134125
figure_out.set_size_inches(4, 3)
135-
FigureCanvasTkAgg(figure_out, master=self.mod_geo_frame).get_tk_widget().grid(row=1, column=0, padx=5, pady=5)
126+
FigureCanvasTkAgg(figure_out, master=self.mod_geo_frame).get_tk_widget().grid(row=1, column=0, \
127+
padx=5, pady=5)
136128

137129

138130
def _goto_website(self):
@@ -143,64 +135,67 @@ def _goto_website(self):
143135
webbrowser.open(self.url)
144136

145137

146-
def main(self):
138+
def _main(self):
147139
"""
148-
The method inizializes and visualizes the window.
140+
The private method inizializes and visualizes the window.
149141
"""
150-
151-
self.logo_panel = Tkinter.Canvas(self.root, height=60 , width=60)
152-
self.logo_panel.pack(side="bottom", padx=5, pady=5,anchor=Tkinter.SE)
142+
self.logo_panel = Tkinter.Canvas(self.root, height=60, width=60)
143+
self.logo_panel.pack(side="bottom", padx=5, pady=5, anchor=Tkinter.SE)
153144
self.img = Tkinter.PhotoImage(master=self.logo_panel, file='readme/logo_PyGeM_gui.gif')
154-
self.logo_panel.create_image(35,35, image=self.img)
145+
self.logo_panel.create_image(35, 35, image=self.img)
155146

156147
self.orig_geo_frame = Tkinter.Frame(self.root, height=450, width=360, bg='#c1d0f0')
157148
self.orig_geo_frame.pack(side="left", padx=5, pady=5)
158149
self.orig_geo_frame.pack_propagate(0)
159-
Tkinter.Label(self.orig_geo_frame, text="INPUT GEOMETRY", bg='#c1d0f0', font=("Arial", 20)).grid(row=0, column=0, padx=3, pady=3)
160-
150+
Tkinter.Label(self.orig_geo_frame, text="INPUT GEOMETRY", bg='#c1d0f0', \
151+
font=("Arial", 20)).grid(row=0, column=0, padx=3, pady=3)
152+
161153
self.mod_geo_frame = Tkinter.Frame(self.root, height=450, width=360, bg='#80ff80', padx=5, pady=5)
162154
self.mod_geo_frame.pack(side="right", padx=5, pady=5)
163155
self.mod_geo_frame.pack_propagate(0)
164-
Tkinter.Label(self.mod_geo_frame, text="OUTPUT GEOMETRY", bg='#80ff80', font=("Arial", 20)).grid(row=0, column=0, padx=3, pady=3)
165-
156+
Tkinter.Label(self.mod_geo_frame, text="OUTPUT GEOMETRY", bg='#80ff80', \
157+
font=("Arial", 20)).grid(row=0, column=0, padx=3, pady=3)
158+
166159
code_frame = Tkinter.Frame(self.root, height=490, width=360, relief=Tkinter.GROOVE, borderwidth=1)
167160
code_frame.pack(padx=5, pady=5)
168161
code_frame.pack_propagate(0)
169162

170163
# Buttons 1
171-
Tkinter.Button(code_frame, text ="Pick the geometry", command = self._chose_geometry).grid(row=0, column=0, padx=3, pady=3)
172-
self.label_geo=Tkinter.Label(code_frame, textvariable=self.print_geometry_path, fg='red')
164+
Tkinter.Button(code_frame, text="Pick the geometry", \
165+
command=self._chose_geometry).grid(row=0, column=0, padx=3, pady=3)
166+
self.label_geo = Tkinter.Label(code_frame, textvariable=self.print_geometry_path, fg='red')
173167
self.print_geometry_path.set("No geometry chosen!")
174168
self.label_geo.grid(row=0, column=1, padx=3, pady=3)
175169

176170
# Button 2
177-
Tkinter.Button(code_frame, text ="Pick the parameters", command = self._chose_parameters).grid(row=1, column=0, padx=3, pady=3)
171+
Tkinter.Button(code_frame, text="Pick the parameters", \
172+
command=self._chose_parameters).grid(row=1, column=0, padx=3, pady=3)
178173
self.label_params = Tkinter.Label(code_frame, textvariable=self.print_parameter_path, fg='red')
179174
self.print_parameter_path.set("No parameters file chosen!")
180175
self.label_params.grid(row=1, column=1, padx=3, pady=3)
181176

182177
# Entry
183178
Tkinter.Label(code_frame, text="Output geometry file").grid(row=2, column=0, padx=3, pady=3)
184-
Tkinter.Entry(code_frame, bd =5, textvariable=self.outfilename).grid(row=2, column=1, padx=3, pady=3)
179+
Tkinter.Entry(code_frame, bd=5, textvariable=self.outfilename).grid(row=2, column=1, \
180+
padx=3, pady=3)
185181

186182
# Checkboxes
187-
Tkinter.Checkbutton(code_frame, text = "Dump Original FFD lattice", variable = self.check_var_1, \
188-
onvalue = 1, offvalue = 0, height=3, \
189-
width = 20).grid(row=3, column=0)
190-
Tkinter.Entry(code_frame, bd =5, textvariable=self.outfilename_lattice_orig).grid(row=3, column=1)
183+
Tkinter.Checkbutton(code_frame, text="Dump Original FFD lattice", \
184+
variable=self.check_var_dump_orig, onvalue=1, offvalue=0, height=3, width=20).grid(row=3, \
185+
column=0)
186+
Tkinter.Entry(code_frame, bd=5, textvariable=self.outfilename_lattice_orig).grid(row=3, column=1)
191187

192-
Tkinter.Checkbutton(code_frame, text = "Dump Morphed FFD lattice", variable = self.check_var_2, \
193-
onvalue = 1, offvalue = 0, height=3, \
194-
width = 20).grid(row=4, column=0)
195-
Tkinter.Entry(code_frame, bd =5, textvariable=self.outfilename_lattice_mod).grid(row=4, column=1)
196-
188+
Tkinter.Checkbutton(code_frame, text="Dump Morphed FFD lattice", \
189+
variable=self.check_var_dump_morphed, onvalue=1, offvalue=0, height=3, width=20).grid(row=4, \
190+
column=0)
191+
Tkinter.Entry(code_frame, bd=5, textvariable=self.outfilename_lattice_mod).grid(row=4, column=1)
192+
197193
# Run button
198-
Tkinter.Button(code_frame, text ="Run PyGeM", command = self._run_simulation, bg='#065893', fg='#f19625', \
199-
font='bold').grid(row=5, column=0, columnspan=2, padx=3, pady=3)
194+
Tkinter.Button(code_frame, text="Run PyGeM", command=self._run_simulation, bg='#065893', \
195+
fg='#f19625', font='bold').grid(row=5, column=0, columnspan=2, padx=3, pady=3)
200196

201197
# Menu
202198
menubar = Tkinter.Menu(self.root)
203-
204199
helpmenu = Tkinter.Menu(menubar, tearoff=0)
205200
helpmenu.add_command(label="About...", command=self._goto_website)
206201
menubar.add_cascade(label="Help", menu=helpmenu)
@@ -209,6 +204,14 @@ def main(self):
209204

210205

211206
def start(self):
212-
207+
"""
208+
This method inizializes and starts the GUI.
209+
"""
210+
self._main()
213211
self.root.mainloop()
214212

213+
214+
215+
if __name__ == "__main__":
216+
app = Gui()
217+
app.start()

start_gui.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import pygem as pg
22

33
interface = pg.gui.Gui()
4-
5-
interface.main()
6-
74
interface.start()

tests/test_gui.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ def test_gui_init_string_9(self):
5353

5454
def test_gui_init_int_1(self):
5555
gui_handler = gui.Gui()
56-
assert gui_handler.check_var_1.get() == 0
56+
assert gui_handler.check_var_dump_orig.get() == 0
5757

5858

5959
def test_gui_init_int_2(self):
6060
gui_handler = gui.Gui()
61-
assert gui_handler.check_var_2.get() == 0
61+
assert gui_handler.check_var_dump_morphed.get() == 0
6262

6363

6464
def test_gui_init_none_1(self):
@@ -90,13 +90,9 @@ def test_gui_init_none_6(self):
9090
gui_handler = gui.Gui()
9191
assert gui_handler.mod_geo_frame == None
9292

93-
94-
def test_gui_init_all(self):
95-
gui.Gui()
96-
9793

9894
def test_gui_main(self):
9995
interface = gui.Gui()
100-
interface.main()
96+
interface._main()
10197

10298

0 commit comments

Comments
 (0)