I have a small plotting program implemented in python using TraitsUI as graphical interface (and matplotlib for plotting, but this is not important here). So I have a class Plotter(HasTraits), which is finally shown using the configure_traits() method. The view looks like this, with the actual maplotlib figure editor and some control elements:

view = View(Item('figure', editor=MPLFigureEditor(), show_label=False),
    Item('param', show_label=False),
    Group(Item('previous', show_label=False),
      Item('next', show_label=False),
      Item('xminbox', label="xrange"),
      Item('xmaxbox', show_label=False),
      Item('persistbox', label='persistent'),
      orientation = 'horizontal'),
    width=800,
    height=600,
    resizable=True,
    title="TraitsVisualizer",)

Now I would like to add an additional "array" of checkboxes to the controls, with the actual number of checkboxes determined dynamically by the number of plots in the figure. So in my thoughts, I would need some way to add and remove "Items" from the view dynamically, but I cannot figure out how to achieve this.

Thanks!

有帮助吗?

解决方案

If you have a limited number of items, the easiest way to do this is to specify all the items you might want in the GUI with visible_when (or enabled_when) options.

view=View(Item(name='muffin_type'),
          Item(name='type_of_blueberry',editor=BlueberryEditor(),
               visible_when='muffin_type==\'blueberry\'')))

(The string in visible_when is exec'd by the view)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top