File: buttons.py

package info (click to toggle)
python-traitsui 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 13,292 kB
  • sloc: python: 39,867; makefile: 120; sh: 5
file content (78 lines) | stat: -rw-r--r-- 2,472 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#  Copyright (c) 2007, Enthought, Inc.
#  License: BSD Style.

#--(View Default Button Changes)------------------------------------------------
"""
View Default Button Changes
===========================

For the last year or so, use of the following **View** traits for managing the
default buttons displayed at the bottom of a view has been deprecated:

- apply
- revert
- undo
- ok
- cancel

Use of these traits has been supplanted by use of the *buttons* trait instead.

As part of the ongoing phasing out of these traits, the following changes have
been implemented in Traits 3.0:

- All use of the *apply*, *revert*, *undo*, *ok* and *cancel* traits have been
  removed from views contained within the traits package itself, and have been
  replaced with the *buttons* trait.

- The default value for each of the deprecated traits has been changed from
  **True** to **False**.

While use of the deprecated **View** traits is still allowed at the moment, the
affect of these changes could cause changes in behavior within existing code
that has not yet removed references to the deprecated traits.

In particular, the most likely side effect is for some or all of the default
**View** buttons to disappear from views which are implicitly relying on the
default values for each of the deprecated traits. Views which explicitly set
the deprecated **View** traits or use the newer *buttons* trait should not be
affected.

The correct fix for any **View** which has buttons disappear after installing
Traits 3.0 is to add a *buttons* trait with the correct value set to the
**View**.

Note that in a future release, the deprecated view traits will actually be
removed from the **View** class.
"""

#--<Imports>--------------------------------------------------------------------

from traits.api import *
from traitsui.api import *

#--[Adder Class]----------------------------------------------------------------

# Click the run button to view the pop-up dialog...

class Adder ( HasTraits ):

    value_1 = Float
    value_2 = Float
    sum     = Property( depends_on = [ 'value_1', 'value_2' ] )

    view = View(
        Item( 'value_1' ),
        Item( 'value_2' ),
        '_',
        Item( 'sum', style = 'readonly' ),
        title   = 'Adding Machine',
        buttons = [ 'OK' ]
    )

    def _get_sum ( self ):
        return (self.value_1 + self.value_2)

#--<Example>--------------------------------------------------------------------

popup = Adder()