I would like to set up an interface such that, upon listening to a trait, the interface will switch between different predefined View
objects. Here is an example:
class App(Handler):
info=Instance(UIInfo)
view_type=Enum('slider_view','spinner_view')
number=Range(1,10)
message=Str('sawmill')
spinner_view=View(Item('number',editor=RangeEditor(mode='spinner',high=10, low=1)),Item('message'),Item('view_type'))
slider_view=View(Item('number',editor=RangeEditor(mode='slider',high=10, low=1)),Item('message'),Item('view_type'))
@on_trait_change('view_type')
def chg_view_type(self):
self.reconstruct()
def init_info(self,info):
self.info=info
def reconstruct(self):
self.info.ui.dispose()
self.info.object.edit_traits(view=self.view_type)
This code works and does everything that it needs to do for the toy example presented. However, my application has complex editors (including but not necessarily limited to a SceneEditor
for a mayavi scene), that destroy their entire contents when disposed of. I am wondering if there is a simpler way of dynamically changing the view of a particular Item
or subpanel (altering the view of an Instance
that does not change would be just fine) while a window is active, whether by simplicity or trickery.