Skip to content

Commit

Permalink
Clean up the view somewhat.
Browse files Browse the repository at this point in the history
  • Loading branch information
corranwebster committed Oct 26, 2016
1 parent 0d632cf commit e7c1ebf
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions examples/kiva_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@


class ScriptedComponent(Component):
""" An Enable component that draws its mainlayer from a script """

#: kiva drawing code for mainlayer
draw_script = Code(default_script)
Expand All @@ -53,6 +54,7 @@ class ScriptedComponent(Component):
_draw_code = Any

def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
""" Try running the compiled code with the graphics context as `gc` """
with gc:
try:
self.error = ''
Expand All @@ -61,6 +63,7 @@ def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
self.error = str(exc)

def _compile_script(self):
""" Try compiling the script to bytecode """
try:
self.error = ''
return compile(self.draw_script, "<script>", "exec")
Expand All @@ -82,19 +85,20 @@ def __draw_code_default(self):


class ScriptedComponentView(ModelView):
""" ModelView of a ScriptedComponent displaying the script and image """

#: the component we are editing
model = Instance(ScriptedComponent, ())

script = DelegatesTo('model', 'draw_script')

error = DelegatesTo('model')

view = View(
HSplit(
VGroup(
UItem('script'),
UItem('error', visible_when="error != ''", style='readonly',
height=100)
UItem('model.draw_script'),
UItem(
'model.error',
visible_when="model.error != ''",
style='readonly',
height=100)
),
UItem('model', editor=ComponentEditor()),
),
Expand Down

0 comments on commit e7c1ebf

Please sign in to comment.