LUIRadioboxGroup.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from LUIObject import LUIObject
  2. class LUIRadioboxGroup(LUIObject):
  3. """ Simple helper to group a bunch of LUIRadiobox and ensure only one is
  4. checked at one timem """
  5. def __init__(self):
  6. """ Constructs a new group without any radioboxes inside """
  7. self._boxes = []
  8. self._selected_box = None
  9. def register_box(self, box):
  10. """ Registers a box to the collection """
  11. if box not in self._boxes:
  12. self._boxes.append(box)
  13. def set_active_box(self, active_box):
  14. """ Internal function to set the active box """
  15. for box in self._boxes:
  16. if box is not active_box:
  17. box._update_state(False)
  18. else:
  19. box._update_state(True)
  20. self._selected_box = active_box
  21. def get_active_box(self):
  22. """ Returns the current selected box """
  23. return self._selected_box
  24. active_box = property(get_active_box, set_active_box)
  25. def get_active_value(self):
  26. """ Returns the value of the current selected box (or None if none is
  27. selected) """
  28. if self._selected_box is None:
  29. return None
  30. return self._selected_box.get_value()
  31. active_value = property(get_active_value)