Skip to content

Commit c2246c2

Browse files
committed
Add buttons and guard for no figure
1 parent 6f1f95f commit c2246c2

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

ets_tutorial/util/mpl_figure_editor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def update_editor(self):
3030
def _do_layout(self):
3131
"""Creates sub-widgets and does layout.
3232
"""
33+
if not self.value:
34+
return
3335
canvas = FigureCanvasQTAgg(figure=self.value)
3436
# Allow the figure canvas to expand and shrink with the main widget.
3537
canvas.setSizePolicy(

stage3.1_first_views/traited_face_detect.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
List,
1919
observe,
2020
)
21-
from traitsui.api import ModelView, UItem, View
21+
from traitsui.api import ModelView, OKButton, UItem, View
2222

2323
# Local imports
2424
from ets_tutorial.util.mpl_figure_editor import MplFigureEditor
@@ -87,12 +87,15 @@ class ImageFileView(ModelView):
8787
view = View(
8888
UItem("model.filepath"),
8989
UItem("figure", editor=MplFigureEditor()),
90+
buttons=[OKButton],
9091
resizable=True,
9192
title="Pycasa"
9293
)
9394

9495
@observe("model.filepath")
9596
def build_mpl_figure(self, event):
97+
if not self.model.filepath:
98+
return
9699
figure = Figure()
97100
axes = figure.add_subplot(111)
98101
axes.imshow(self.model.to_array())
@@ -111,8 +114,6 @@ def build_mpl_figure(self, event):
111114

112115

113116
if __name__ == '__main__':
114-
img = ImageFile(
115-
filepath=join("..", "sample_images", "IMG-0311_xmas_2020.JPG")
116-
)
117+
img = ImageFile()
117118
view = ImageFileView(model=img)
118119
view.configure_traits()

0 commit comments

Comments
 (0)