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

« back to all changes in this revision

Viewing changes to examples/demo/Standard_Editors/TextEditor_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
#  Copyright (c) 2007, Enthought, Inc.
 
2
#  License: BSD Style.
 
3
 
 
4
"""
 
5
Implementation of a TextEditor demo plugin for the Traits UI demo program.
 
6
 
 
7
For each of three data types for which TextEditor is used, this demo shows
 
8
each of the four styles of the TextEditor.
 
9
"""
 
10
 
 
11
# Imports:
 
12
from traits.api \
 
13
    import HasTraits, Str, Int, Password
 
14
 
 
15
from traitsui.api \
 
16
    import Item, Group, View
 
17
 
 
18
# The main demo class:
 
19
class TextEditorDemo ( HasTraits ):
 
20
    """ Defines the TextEditor demo class.
 
21
    """
 
22
 
 
23
    # Define a trait for each of three TextEditor variants:
 
24
    string_trait = Str( "sample string" )
 
25
    int_trait    = Int( 1 )
 
26
    password     = Password
 
27
 
 
28
    # TextEditor display without multi-line capability (for various traits):
 
29
    text_int_group = Group(
 
30
        Item( 'int_trait', style = 'simple',   label = 'Simple' ),
 
31
        Item( '_' ),
 
32
        Item( 'int_trait', style = 'custom',   label = 'Custom' ),
 
33
        Item( '_' ),
 
34
        Item( 'int_trait', style = 'text',     label = 'Text' ),
 
35
        Item( '_' ),
 
36
        Item( 'int_trait', style = 'readonly', label = 'ReadOnly' ),
 
37
        label = 'Integer'
 
38
    )
 
39
 
 
40
    # TextEditor display with multi-line capability (for various traits):
 
41
    text_str_group = Group(
 
42
        Item( 'string_trait', style = 'simple',  label = 'Simple' ),
 
43
        Item( '_' ),
 
44
        Item( 'string_trait', style = 'custom',  label = 'Custom' ),
 
45
        Item( '_' ),
 
46
        Item( 'string_trait', style = 'text',     label = 'Text' ),
 
47
        Item( '_' ),
 
48
        Item( 'string_trait', style = 'readonly', label = 'ReadOnly' ),
 
49
        label = 'String'
 
50
    )
 
51
 
 
52
    # TextEditor display with secret typing capability (for Password traits):
 
53
    text_pass_group = Group(
 
54
        Item( 'password', style = 'simple',   label = 'Simple' ),
 
55
        Item( '_' ),
 
56
        Item( 'password', style = 'custom',   label = 'Custom' ),
 
57
        Item( '_' ),
 
58
        Item( 'password', style = 'text',     label = 'Text' ),
 
59
        Item( '_' ),
 
60
        Item( 'password', style = 'readonly', label = 'ReadOnly' ),
 
61
        label = 'Password'
 
62
    )
 
63
 
 
64
    # The view includes one group per data type. These will be displayed
 
65
    # on separate tabbed panels:
 
66
    view = View(
 
67
        text_int_group,
 
68
        text_str_group,
 
69
        text_pass_group,
 
70
        title   = 'TextEditor',
 
71
        buttons = [ 'OK' ]
 
72
    )
 
73
 
 
74
# Create the demo:
 
75
demo =  TextEditorDemo()
 
76
 
 
77
# Run the demo (if invoked from the command line):
 
78
if __name__ == "__main__":
 
79
    demo.configure_traits()