/GUI/Generic/GRadioButtons.py
Python | 52 lines | 45 code | 2 blank | 5 comment | 0 complexity | f817db242941b583dedb55b13d8c3085 MD5 | raw file
1#
2# Python GUI - Radio buttons - Generic
3#
4
5from Properties import overridable_property
6from Controls import Control
7
8class RadioButton(Control):
9 """RadioButtons are used in groups to represent a 1-of-N
10 choice. A group of RadioButtons is coordinated by a
11 RadioGroup object. The 'group' property indicates the
12 RadioGroup to which it belongs, and the 'value' property
13 is the value to which the RadioGroup's value is set
14 when this RadioButton is selected."""
15
16 group = overridable_property('group', """The RadioGroup to
17 which this radio button belongs.""")
18
19 value = overridable_property('value', """The value to which
20 the associated radio group's 'value' property should be
21 set when this radio button is selected.""")
22
23 _group = None
24 _value = None
25
26 #
27 # Properties
28 #
29
30 def get_group(self):
31 return self._group
32
33 def set_group(self, new_group):
34 old_group = self._group
35 if new_group is not old_group:
36 if old_group:
37 old_group._remove(self)
38 self._group = new_group
39 if new_group:
40 new_group._add(self)
41
42 def get_value(self):
43 return self._value
44
45 def set_value(self, new_value):
46 old_value = self._value
47 if new_value != old_value:
48 self._value = new_value
49 self._value_changed()
50
51 def _value_changed(self):
52 raise NotImplementedError