Skip to content

Commit 770d9dd

Browse files
fsalmoirmtezzele
authored andcommitted
Gui improvements and tests (#80)
* # This is a combination of 4 commits. # The first commit's message is: tests added for gui init # The 2nd commit message will be skipped: # tests added for gui init # The 3rd commit message will be skipped: # test for the main part of gui code # The 4th commit message will be skipped: # test for the main part of gui code * trying to solve conflicts * removed pillow from packages * removed pillow from travis installation
1 parent 637016b commit 770d9dd

File tree

7 files changed

+136
-56
lines changed

7 files changed

+136
-56
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ install:
5050
- pip install numpy-stl
5151
- pip install coveralls
5252
- pip install coverage
53-
- pip install Pillow
5453
- python setup.py install
5554

5655
script: coverage run test.py

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ To uninstall the package you have to rerun the installation and record the insta
6565
The generated html can be found in `docs/build/html`. Open up the `index.html` you find there to browse.
6666

6767

68+
## Gui
69+
**PyGeM** comes with a very basic Graphic Unit Interface.
70+
71+
Pick the geometry, the parameters file, set the name of the output and decide whether dump the FFD lattice or not.
72+
Now just click on the `Run PyGeM` button and that is it.
73+
74+
<p align="center">
75+
<img src="readme/gui_PyGeM.png" alt>
76+
</p>
77+
<p align="center">
78+
<em>PyGeM GUI: how it appears when it pops up.</em>
79+
</p>
80+
6881
## Testing
6982
We are using Travis CI for continuous intergration testing. You can check out the current status [here](https://travis-ci.org/mathLab/PyGeM).
7083

pygem/gui.py

Lines changed: 33 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import Tkinter
99
from tkFileDialog import askopenfilename
10-
from PIL import ImageTk, Image
1110
import pygem as pg
1211
import sys
1312
import os
@@ -54,6 +53,9 @@ def __init__(self):
5453
self.label_params = None
5554
self.url = 'https://github.com/mathLab/PyGeM'
5655

56+
self.canvas = None
57+
self.img = None
58+
5759

5860

5961
def _chose_geometry(self):
@@ -121,83 +123,60 @@ def _goto_website(self):
121123
webbrowser.open(self.url)
122124

123125

124-
def start(self):
126+
def main(self):
125127
"""
126128
The method inizializes and visualizes the window.
127129
"""
128-
129-
image = Image.open('readme/logo_PyGeM_small.png')
130-
image = image.resize((50, 50), Image.ANTIALIAS)
131-
img = ImageTk.PhotoImage(image)
132-
panel = Label(self.root, image = img)
133-
panel.pack(side = "bottom", padx = 5, pady = 5,anchor=SE)
134-
135-
geo_frame = Frame(self.root)
136-
geo_frame.pack(anchor=W)
130+
131+
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)
133+
self.img = Tkinter.PhotoImage(master=self.logo_panel, file='readme/logo_PyGeM_gui.gif')
134+
self.logo_panel.create_image(35,35, image=self.img)
135+
136+
code_frame = Tkinter.Frame(self.root)
137+
code_frame.pack()
137138

138139
# Buttons 1
139-
button_1 = Tkinter.Button(geo_frame, text ="Pick the geometry", command = self._chose_geometry)
140-
button_1.pack(side=LEFT, padx = 5, pady = 5)
141-
self.label_geo=Label(geo_frame, textvariable=self.print_geometry_path, fg='red')
140+
Tkinter.Button(code_frame, text ="Pick the geometry", command = self._chose_geometry).grid(row=0, column=0, padx=3, pady=3)
141+
self.label_geo=Tkinter.Label(code_frame, textvariable=self.print_geometry_path, fg='red')
142142
self.print_geometry_path.set("No geometry chosen!")
143-
self.label_geo.pack(side=LEFT, padx = 5, pady = 5)
143+
self.label_geo.grid(row=0, column=1, padx=3, pady=3)
144144

145-
# Button 2
146-
params_frame = Frame(self.root)
147-
params_frame.pack(anchor=W)
148-
149-
button_2 = Tkinter.Button(params_frame, text ="Pick the parameters", command = self._chose_parameters)
150-
button_2.pack(side=LEFT, padx = 5, pady = 5)
151-
self.label_params = Label( params_frame, textvariable=self.print_parameter_path, fg='red')
145+
# Button 2
146+
Tkinter.Button(code_frame, text ="Pick the parameters", command = self._chose_parameters).grid(row=1, column=0, padx=3, pady=3)
147+
self.label_params = Tkinter.Label(code_frame, textvariable=self.print_parameter_path, fg='red')
152148
self.print_parameter_path.set("No parameters file chosen!")
153-
self.label_params.pack(side=LEFT, padx = 5, pady = 5)
149+
self.label_params.grid(row=1, column=1, padx=3, pady=3)
154150

155151
# Entry
156-
entryframe = Frame(self.root)
157-
entryframe.pack(padx = 5, pady = 5, anchor=W)
158-
159-
label_geo_out = Label(entryframe, text="Output geometry file")
160-
label_geo_out.pack( side = LEFT)
161-
entry_geo_out = Entry(entryframe, bd =5, textvariable=self.outfilename)
162-
entry_geo_out.pack(side = LEFT)
152+
Tkinter.Label(code_frame, text="Output geometry file").grid(row=2, column=0, padx=3, pady=3)
153+
Tkinter.Entry(code_frame, bd =5, textvariable=self.outfilename).grid(row=2, column=1, padx=3, pady=3)
163154

164155
# Checkboxes
165-
checkframe_orig = Frame(self.root)
166-
checkframe_orig.pack(anchor=W)
167-
168-
check_lattice_orig = Checkbutton(checkframe_orig, text = "Dump Original FFD lattice", variable = self.check_var_1, \
156+
Tkinter.Checkbutton(code_frame, text = "Dump Original FFD lattice", variable = self.check_var_1, \
169157
onvalue = 1, offvalue = 0, height=3, \
170-
width = 20)
158+
width = 20).grid(row=3, column=0)
159+
Tkinter.Entry(code_frame, bd =5, textvariable=self.outfilename_lattice_orig).grid(row=3, column=1)
171160

172-
check_lattice_orig.pack(side=LEFT)
173-
174-
entry_lattice_orig = Entry(checkframe_orig, bd =5, textvariable=self.outfilename_lattice_orig)
175-
entry_lattice_orig.pack(side = LEFT)
176-
177-
checkframe_mod = Frame(self.root)
178-
checkframe_mod.pack(anchor=W)
179-
180-
check_lattice_mod = Checkbutton(checkframe_mod, text = "Dump Morphed FFD lattice", variable = self.check_var_2, \
161+
Tkinter.Checkbutton(code_frame, text = "Dump Morphed FFD lattice", variable = self.check_var_2, \
181162
onvalue = 1, offvalue = 0, height=3, \
182-
width = 20)
183-
184-
check_lattice_mod.pack(side=LEFT)
185-
186-
entry_lattice_mod = Entry(checkframe_mod, bd =5, textvariable=self.outfilename_lattice_mod)
187-
entry_lattice_mod.pack(side = LEFT)
163+
width = 20).grid(row=4, column=0)
164+
Tkinter.Entry(code_frame, bd =5, textvariable=self.outfilename_lattice_mod).grid(row=4, column=1)
188165

189166
# Run button
190-
button_run = Tkinter.Button(self.root, text ="Run PyGeM", command = self._run_simulation, bg='#065893', fg='#f19625', font='bold')
191-
button_run.pack()
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)
192168

193169
# Menu
194-
menubar = Menu(self.root)
170+
menubar = Tkinter.Menu(self.root)
195171

196-
helpmenu = Menu(menubar, tearoff=0)
172+
helpmenu = Tkinter.Menu(menubar, tearoff=0)
197173
helpmenu.add_command(label="About...", command=self._goto_website)
198174
menubar.add_cascade(label="Help", menu=helpmenu)
199175

200176
self.root.config(menu=menubar)
201177

178+
179+
def start(self):
180+
202181
self.root.mainloop()
203182

readme/logo_PyGeM_gui.gif

1.63 KB
Loading

start_gui.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pygem as pg
2+
3+
interface = pg.gui.Gui()
4+
5+
interface.main()
6+
7+
interface.start()

tests/test_gui.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
from unittest import TestCase
3+
import unittest
4+
import pygem.gui as gui
5+
6+
7+
class TestGui(TestCase):
8+
9+
def test_gui_init_string_1(self):
10+
gui_handler = gui.Gui()
11+
assert gui_handler.root.title() == 'PyGeM'
12+
13+
14+
def test_gui_init_string_2(self):
15+
gui_handler = gui.Gui()
16+
assert gui_handler.filename_geometry.get() == ''
17+
18+
19+
def test_gui_init_string_3(self):
20+
gui_handler = gui.Gui()
21+
assert gui_handler.filename_parameters.get() == ''
22+
23+
24+
def test_gui_init_string_4(self):
25+
gui_handler = gui.Gui()
26+
assert gui_handler.outfilename.get() == ''
27+
28+
29+
def test_gui_init_string_5(self):
30+
gui_handler = gui.Gui()
31+
assert gui_handler.outfilename_lattice_orig.get() == ''
32+
33+
34+
def test_gui_init_string_6(self):
35+
gui_handler = gui.Gui()
36+
assert gui_handler.outfilename_lattice_mod.get() == ''
37+
38+
39+
def test_gui_init_string_7(self):
40+
gui_handler = gui.Gui()
41+
assert gui_handler.print_geometry_path.get() == ''
42+
43+
44+
def test_gui_init_string_8(self):
45+
gui_handler = gui.Gui()
46+
assert gui_handler.print_parameter_path.get() == ''
47+
48+
49+
def test_gui_init_string_9(self):
50+
gui_handler = gui.Gui()
51+
assert gui_handler.url == 'https://github.com/mathLab/PyGeM'
52+
53+
54+
def test_gui_init_int_1(self):
55+
gui_handler = gui.Gui()
56+
assert gui_handler.check_var_1.get() == 0
57+
58+
59+
def test_gui_init_int_2(self):
60+
gui_handler = gui.Gui()
61+
assert gui_handler.check_var_2.get() == 0
62+
63+
64+
def test_gui_init_none_1(self):
65+
gui_handler = gui.Gui()
66+
assert gui_handler.label_geo == None
67+
68+
69+
def test_gui_init_none_2(self):
70+
gui_handler = gui.Gui()
71+
assert gui_handler.label_params == None
72+
73+
74+
def test_gui_init_all(self):
75+
gui.Gui()
76+
77+
78+
def test_gui_main(self):
79+
interface = gui.Gui()
80+
interface.main()
81+
82+

tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import vtk
1010

1111

12-
class TestVtkHandler(TestCase):
12+
class TestUtils(TestCase):
1313

1414

1515
def test_utils_write_original_box(self):

0 commit comments

Comments
 (0)