Skip to content

Commit 9c7ce99

Browse files
author
fsalmoir
authored
Merge pull request #82 from fsalmoir/plot_geo_gui
now we can plot iges, vtk and stl on the gui during the execution
2 parents 84dc625 + 391e05c commit 9c7ce99

File tree

6 files changed

+76
-8
lines changed

6 files changed

+76
-8
lines changed

pygem/gui.py

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import os
1313
import webbrowser
1414

15+
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
16+
from matplotlib.figure import Figure
17+
18+
1519
class Gui(object):
1620
"""
1721
The class for the Graphic Unit Interface.
@@ -32,12 +36,19 @@ class Gui(object):
3236
:cvar Tkinter.Label label_geo: label related to 'print_geometry_path'.
3337
:cvar Tkinter.Label label_params: label related to 'print_parameters_path'.
3438
:cvar string url: url of the github page of PyGeM.
39+
:cvar Tkinter.Canvas logo_panel: canvas for PyGeM logo.
40+
:cvar Tkinter.PhotoImage img: PyGeM logo.
41+
:cvar Tkinter.Frame orig_geo_frame: frame for plotting of the original geometry.
42+
:cvar Tkinter.Frame mod_geo_frame: frame for plotting of the final geometry.
3543
3644
"""
3745

3846
def __init__(self):
3947

4048
self.root = Tkinter.Tk()
49+
self.root.resizable(width=False, height=False)
50+
self.root.minsize(width=1400, height=400)
51+
self.root.maxsize(width=1400, height=400)
4152
self.root.title('PyGeM')
4253

4354
self.filename_geometry = Tkinter.StringVar()
@@ -52,10 +63,10 @@ def __init__(self):
5263
self.label_geo = None
5364
self.label_params = None
5465
self.url = 'https://github.com/mathLab/PyGeM'
55-
56-
self.canvas = None
66+
self.logo_panel = None
5767
self.img = None
58-
68+
self.orig_geo_frame = None
69+
self.mod_geo_frame = None
5970

6071

6172
def _chose_geometry(self):
@@ -107,7 +118,16 @@ def _run_simulation(self):
107118
free_form.perform()
108119
new_mesh_points = free_form.modified_mesh_points
109120

110-
geo_handler.write(new_mesh_points, self.outfilename.get() + file_extension_in)
121+
geo_handler.write(new_mesh_points, self.outfilename.get() + file_extension_in)
122+
123+
if file_extension_in in ['.vtk', '.stl', '.iges', '.igs']:
124+
figure_in = geo_handler.plot()
125+
figure_in.set_size_inches(4, 3)
126+
FigureCanvasTkAgg(figure_in, master=self.orig_geo_frame).get_tk_widget().grid(row=1, column=0, padx=5, pady=5)
127+
128+
figure_out = geo_handler.plot(self.outfilename.get() + file_extension_in)
129+
figure_out.set_size_inches(4, 3)
130+
FigureCanvasTkAgg(figure_out, master=self.mod_geo_frame).get_tk_widget().grid(row=1, column=0, padx=5, pady=5)
111131

112132
if self.check_var_1.get() == 1:
113133
pg.utils.write_bounding_box(params, self.outfilename_lattice_orig.get() + '.vtk', False)
@@ -129,12 +149,23 @@ def main(self):
129149
"""
130150

131151
self.logo_panel = Tkinter.Canvas(self.root, height=60 , width=60)
132-
self.logo_panel.pack(side = "bottom", padx = 5, pady = 5,anchor=Tkinter.SE)
152+
self.logo_panel.pack(side="bottom", padx=5, pady=5,anchor=Tkinter.SE)
133153
self.img = Tkinter.PhotoImage(master=self.logo_panel, file='readme/logo_PyGeM_gui.gif')
134154
self.logo_panel.create_image(35,35, image=self.img)
135155

136-
code_frame = Tkinter.Frame(self.root)
137-
code_frame.pack()
156+
self.orig_geo_frame = Tkinter.Frame(self.root, height=450, width=360, bg='#c1d0f0')
157+
self.orig_geo_frame.pack(side="left", padx=5, pady=5)
158+
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+
161+
self.mod_geo_frame = Tkinter.Frame(self.root, height=450, width=360, bg='#80ff80', padx=5, pady=5)
162+
self.mod_geo_frame.pack(side="right", padx=5, pady=5)
163+
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+
166+
code_frame = Tkinter.Frame(self.root, height=490, width=360, relief=Tkinter.GROOVE, borderwidth=1)
167+
code_frame.pack(padx=5, pady=5)
168+
code_frame.pack_propagate(0)
138169

139170
# Buttons 1
140171
Tkinter.Button(code_frame, text ="Pick the geometry", command = self._chose_geometry).grid(row=0, column=0, padx=3, pady=3)
@@ -164,7 +195,8 @@ def main(self):
164195
Tkinter.Entry(code_frame, bd =5, textvariable=self.outfilename_lattice_mod).grid(row=4, column=1)
165196

166197
# Run button
167-
Tkinter.Button(code_frame, text ="Run PyGeM", command = self._run_simulation, bg='#065893', fg='#f19625', font='bold').grid(row=5, column=0, padx=3, pady=3)
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)
168200

169201
# Menu
170202
menubar = Tkinter.Menu(self.root)

pygem/igeshandler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ def plot(self, plot_file=None, save_fig=False):
219219
:param string plot_file: the iges filename you want to plot.
220220
:param bool save_fig: a flag to save the figure in png or not. If True the
221221
plot is not shown.
222+
223+
:return: figure: matlplotlib structure for the figure of the chosen geometry
224+
:rtype: matplotlib.pyplot.figure
222225
"""
223226
if plot_file is None:
224227
plot_file = self.infile
@@ -254,6 +257,8 @@ def plot(self, plot_file=None, save_fig=False):
254257
pyplot.show()
255258
else:
256259
figure.savefig(plot_file.split('.')[0] + '.png')
260+
261+
return figure
257262

258263

259264
def show(self, show_file=None):

pygem/stlhandler.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def plot(self, plot_file=None, save_fig=False):
8787
:param string plot_file: the stl filename you want to plot.
8888
:param bool save_fig: a flag to save the figure in png or not. If True the
8989
plot is not shown.
90+
91+
:return: figure: matlplotlib structure for the figure of the chosen geometry
92+
:rtype: matplotlib.pyplot.figure
9093
"""
9194
if plot_file is None:
9295
plot_file = self.infile
@@ -110,3 +113,6 @@ def plot(self, plot_file=None, save_fig=False):
110113
pyplot.show()
111114
else:
112115
figure.savefig(plot_file.split('.')[0] + '.png')
116+
117+
return figure
118+

pygem/vtkhandler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ def plot(self, plot_file=None, save_fig=False):
106106
:param string plot_file: the vtk filename you want to plot.
107107
:param bool save_fig: a flag to save the figure in png or not. If True the
108108
plot is not shown.
109+
110+
:return: figure: matlplotlib structure for the figure of the chosen geometry
111+
:rtype: matplotlib.pyplot.figure
109112
"""
110113
if plot_file is None:
111114
plot_file = self.infile
@@ -147,6 +150,8 @@ def plot(self, plot_file=None, save_fig=False):
147150
plt.show()
148151
else:
149152
figure.savefig(plot_file.split('.')[0] + '.png')
153+
154+
return figure
150155

151156

152157
def show(self, show_file=None):

readme/gui_PyGeM.png

62.5 KB
Loading

tests/test_gui.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ def test_gui_init_none_2(self):
7070
gui_handler = gui.Gui()
7171
assert gui_handler.label_params == None
7272

73+
74+
def test_gui_init_none_3(self):
75+
gui_handler = gui.Gui()
76+
assert gui_handler.logo_panel == None
77+
78+
79+
def test_gui_init_none_4(self):
80+
gui_handler = gui.Gui()
81+
assert gui_handler.img == None
82+
83+
84+
def test_gui_init_none_5(self):
85+
gui_handler = gui.Gui()
86+
assert gui_handler.orig_geo_frame == None
87+
88+
89+
def test_gui_init_none_6(self):
90+
gui_handler = gui.Gui()
91+
assert gui_handler.mod_geo_frame == None
92+
7393

7494
def test_gui_init_all(self):
7595
gui.Gui()

0 commit comments

Comments
 (0)