~ubuntu-branches/ubuntu/trusty/python-enable/trusty

« back to all changes in this revision

Viewing changes to enthought/enable/radio_group.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-04-05 21:54:28 UTC
  • mfrom: (1.1.5 upstream)
  • mto: (8.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20110405215428-1x2wtubz3ok2kxaq
Tags: upstream-3.4.1
ImportĀ upstreamĀ versionĀ 3.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#-------------------------------------------------------------------------------
16
16
 
17
17
from enthought.traits.api import HasPrivateTraits, Trait
18
 
            
 
18
 
19
19
#-------------------------------------------------------------------------------
20
20
#  Trait definitions:
21
21
#-------------------------------------------------------------------------------
22
 
            
 
22
 
23
23
# ARadioGroup = Instance( 'RadioGroup' )
24
 
            
 
24
 
25
25
#-------------------------------------------------------------------------------
26
26
#  'RadioStyle' class:
27
27
#-------------------------------------------------------------------------------
28
28
 
29
29
class RadioStyle ( HasPrivateTraits ):
30
 
    
 
30
 
31
31
    #---------------------------------------------------------------------------
32
32
    #  Trait definitions:
33
33
    #---------------------------------------------------------------------------
34
34
 
35
 
#    radio_group = ARadioGroup    
36
 
    
37
 
    #---------------------------------------------------------------------------
38
 
    #  Handle the group the radio style component belongs to being changed: 
39
 
    #---------------------------------------------------------------------------
40
 
    
 
35
#    radio_group = ARadioGroup
 
36
 
 
37
    #---------------------------------------------------------------------------
 
38
    #  Handle the group the radio style component belongs to being changed:
 
39
    #---------------------------------------------------------------------------
 
40
 
41
41
    def _group_changed ( self, old, new ):
42
42
        if old is not None:
43
43
            old.remove( self )
49
49
#-------------------------------------------------------------------------------
50
50
 
51
51
class RadioGroup ( HasPrivateTraits ):
52
 
    
 
52
 
53
53
    #---------------------------------------------------------------------------
54
54
    #  Trait definitions:
55
55
    #---------------------------------------------------------------------------
56
56
 
57
57
    # selection = Instance( RadioStyle )
58
58
    selection = Trait(None, RadioStyle)
59
 
    
60
 
    #---------------------------------------------------------------------------
61
 
    #  Handle elements being added to the group: 
62
 
    #---------------------------------------------------------------------------
63
 
    
 
59
 
 
60
    #---------------------------------------------------------------------------
 
61
    #  Handle elements being added to the group:
 
62
    #---------------------------------------------------------------------------
 
63
 
64
64
    def add ( self, *components ):
65
65
        for component in components:
66
66
            component.radio_group = self
69
69
                    component.selected = False
70
70
                else:
71
71
                    self.selection = component
72
 
        
73
 
    #---------------------------------------------------------------------------
74
 
    #  Handle components being removed from the group: 
75
 
    #---------------------------------------------------------------------------
76
 
    
 
72
 
 
73
    #---------------------------------------------------------------------------
 
74
    #  Handle components being removed from the group:
 
75
    #---------------------------------------------------------------------------
 
76
 
77
77
    def remove ( self, *components ):
78
78
        for component in components:
79
79
            if component is self.selection:
80
80
                self.selection is None
81
81
                break
82
 
                
 
82
 
83
83
    #---------------------------------------------------------------------------
84
84
    #  Handle the selection being changed:
85
85
    #---------------------------------------------------------------------------
86
 
    
 
86
 
87
87
    def _selection_changed ( self, old, new ):
88
88
        if old is not None:
89
89
            old.selected = False