I am attempting to build a series of menus into my traitsui visualization program application. My GUI is comprised of a sequence of panels which all use different model objects, which are all displayed in the main GUI using InstanceEditors. This has numerous benefits including that the panels can just be garbage collected and rebuilt at any time (which is important for mayavi visualizations since mayavi is buggy, often it is better to just throw away the scene and start over after the user makes lots of changes).
I am having the problem that Menus do not show up in any of the subpanels in my GUI.
Here is a minimal working example.
from traits.api import HasTraits, Str, Instance
from traitsui.api import Menu, View, MenuBar, Action, Item, InstanceEditor
class Panel(HasTraits):
field = Str('placeholder_variable')
stuff_action = Action(name='Do stuff', action='do_stuff')
view = View(
Item('field'),
menubar = MenuBar( Menu( stuff_action, name='Menu')),
)
def do_stuff(self):
print '400'
class Application(HasTraits):
panel = Instance(Panel, ())
view = View(
Item('panel', editor=InstanceEditor(), style='custom'))
Application().configure_traits()
The expected behavior is that the calls Panel().configure_traits()
and Application().configure_traits()
result in the same GUI, with both a functional menu (with one item called "Do stuff" that prints 400 when clicked) and a string that can be edited.
The actual behavior I am seeing is that the panel GUI has both the string and the menu, while the application GUI has the string but the menu does not appear.
Is there a way to make the menu appear as a GUI widget from inside an InstanceEditor
?