/GUI/Generic/GRadioButtons.py

https://bitbucket.org/alsh/pygui-mirror · Python · 52 lines · 45 code · 2 blank · 5 comment · 0 complexity · f817db242941b583dedb55b13d8c3085 MD5 · raw file

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