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

« back to all changes in this revision

Viewing changes to examples/tutorials/traitsui_4.0/buttons.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
#--(View Default Button Changes)------------------------------------------------
 
5
"""
 
6
View Default Button Changes
 
7
===========================
 
8
 
 
9
For the last year or so, use of the following **View** traits for managing the
 
10
default buttons displayed at the bottom of a view has been deprecated:
 
11
 
 
12
- apply
 
13
- revert
 
14
- undo
 
15
- ok
 
16
- cancel
 
17
 
 
18
Use of these traits has been supplanted by use of the *buttons* trait instead.
 
19
 
 
20
As part of the ongoing phasing out of these traits, the following changes have
 
21
been implemented in Traits 3.0:
 
22
 
 
23
- All use of the *apply*, *revert*, *undo*, *ok* and *cancel* traits have been
 
24
  removed from views contained within the traits package itself, and have been
 
25
  replaced with the *buttons* trait.
 
26
 
 
27
- The default value for each of the deprecated traits has been changed from
 
28
  **True** to **False**.
 
29
 
 
30
While use of the deprecated **View** traits is still allowed at the moment, the
 
31
affect of these changes could cause changes in behavior within existing code
 
32
that has not yet removed references to the deprecated traits.
 
33
 
 
34
In particular, the most likely side effect is for some or all of the default
 
35
**View** buttons to disappear from views which are implicitly relying on the
 
36
default values for each of the deprecated traits. Views which explicitly set
 
37
the deprecated **View** traits or use the newer *buttons* trait should not be
 
38
affected.
 
39
 
 
40
The correct fix for any **View** which has buttons disappear after installing
 
41
Traits 3.0 is to add a *buttons* trait with the correct value set to the
 
42
**View**.
 
43
 
 
44
Note that in a future release, the deprecated view traits will actually be
 
45
removed from the **View** class.
 
46
"""
 
47
 
 
48
#--<Imports>--------------------------------------------------------------------
 
49
 
 
50
from traits.api import *
 
51
from traitsui.api import *
 
52
 
 
53
#--[Adder Class]----------------------------------------------------------------
 
54
 
 
55
# Click the run button to view the pop-up dialog...
 
56
 
 
57
class Adder ( HasTraits ):
 
58
 
 
59
    value_1 = Float
 
60
    value_2 = Float
 
61
    sum     = Property( depends_on = [ 'value_1', 'value_2' ] )
 
62
 
 
63
    view = View(
 
64
        Item( 'value_1' ),
 
65
        Item( 'value_2' ),
 
66
        '_',
 
67
        Item( 'sum', style = 'readonly' ),
 
68
        title   = 'Adding Machine',
 
69
        buttons = [ 'OK' ]
 
70
    )
 
71
 
 
72
    def _get_sum ( self ):
 
73
        return (self.value_1 + self.value_2)
 
74
 
 
75
#--<Example>--------------------------------------------------------------------
 
76
 
 
77
popup = Adder()
 
78