~ubuntu-branches/ubuntu/utopic/python-traitsui/utopic

« back to all changes in this revision

Viewing changes to examples/demo/Standard_Editors/Popup_versions/InstanceEditor_demo.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-09 13:57:39 UTC
  • Revision ID: james.westby@ubuntu.com-20110709135739-x5u20q86huissmn1
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Implementation of an InstanceEditor demo plugin for the Traits UI demo program.
 
3
 
 
4
This demo shows each of the four styles of the InstanceEditor.
 
5
 
 
6
Fixme: This version of the demo only shows the old-style InstanceEditor
 
7
capabilities.
 
8
"""
 
9
 
 
10
from traits.api import HasTraits, Str, Range, Bool, Trait
 
11
from traitsui.api import Item, Group, View
 
12
 
 
13
#-------------------------------------------------------------------------------
 
14
#  Classes:
 
15
#-------------------------------------------------------------------------------
 
16
 
 
17
class SampleClass ( HasTraits ):
 
18
    """ This Sample class is used to demonstrate the InstanceEditor demo.
 
19
    """
 
20
 
 
21
    #--------------------------------------------------------------------------
 
22
    # The actual attributes don't matter here; we just need an assortment
 
23
    # to demonstrate the InstanceEditor's capabilities.
 
24
    #--------------------------------------------------------------------------
 
25
 
 
26
    name             = Str
 
27
    occupation       = Str
 
28
    age              = Range( 21,65 )
 
29
    registered_voter = Bool
 
30
 
 
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
 
34
    # explicitly.
 
35
    #--------------------------------------------------------------------------
 
36
 
 
37
    view = View( 'name', 'occupation', 'age', 'registered_voter' )
 
38
 
 
39
 
 
40
class InstanceEditorDemo ( HasTraits ):
 
41
    """ This class specifies the details of the InstanceEditor demo.
 
42
    """
 
43
 
 
44
    # To demonstrate any given Trait editor, an appropriate Trait is required.
 
45
    sample_instance  = Trait( SampleClass() )
 
46
 
 
47
 
 
48
    # Items are used to define the demo display - one item per
 
49
    # editor style
 
50
    inst_group = Group( Item('sample_instance', style='simple', label='Simple'),
 
51
                        Item('_'),
 
52
                        Item('sample_instance', style='custom', label='Custom'),
 
53
                        Item('_'),
 
54
                        Item('sample_instance', style='text', label='Text'),
 
55
                        Item('_'),
 
56
                        Item('sample_instance',
 
57
                              style='readonly',
 
58
                              label='ReadOnly'))
 
59
 
 
60
    # Demo View
 
61
    view1 = View( inst_group,
 
62
                  title='InstanceEditor',
 
63
                  buttons=['OK'] )
 
64
 
 
65
 
 
66
# Create the demo:
 
67
popup = InstanceEditorDemo()
 
68
 
 
69
# Run the demo (if invoked from the command line):
 
70
if __name__ == '__main__':
 
71
    popup.configure_traits()
 
72