2
Implementation of an InstanceEditor demo plugin for the Traits UI demo program.
4
This demo shows each of the four styles of the InstanceEditor.
6
Fixme: This version of the demo only shows the old-style InstanceEditor
10
from traits.api import HasTraits, Str, Range, Bool, Trait
11
from traitsui.api import Item, Group, View
13
#-------------------------------------------------------------------------------
15
#-------------------------------------------------------------------------------
17
class SampleClass ( HasTraits ):
18
""" This Sample class is used to demonstrate the InstanceEditor demo.
21
#--------------------------------------------------------------------------
22
# The actual attributes don't matter here; we just need an assortment
23
# to demonstrate the InstanceEditor's capabilities.
24
#--------------------------------------------------------------------------
29
registered_voter = Bool
31
#--------------------------------------------------------------------------
32
# The InstanceEditor uses whatever view is defined for the class. The
33
# default view lists the fields alphabetically, so it's best to define one
35
#--------------------------------------------------------------------------
37
view = View( 'name', 'occupation', 'age', 'registered_voter' )
40
class InstanceEditorDemo ( HasTraits ):
41
""" This class specifies the details of the InstanceEditor demo.
44
# To demonstrate any given Trait editor, an appropriate Trait is required.
45
sample_instance = Trait( SampleClass() )
48
# Items are used to define the demo display - one item per
50
inst_group = Group( Item('sample_instance', style='simple', label='Simple'),
52
Item('sample_instance', style='custom', label='Custom'),
54
Item('sample_instance', style='text', label='Text'),
56
Item('sample_instance',
61
view1 = View( inst_group,
62
title='InstanceEditor',
67
popup = InstanceEditorDemo()
69
# Run the demo (if invoked from the command line):
70
if __name__ == '__main__':
71
popup.configure_traits()