StagedObject.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. class StagedObject:
  2. """
  3. Use this class as a mixin to provide an interface for onStage/offStage objects.
  4. The idea here is that a DistributedObject could be present and active due to
  5. simple visibility, but we want to hide or otherwise disable it for some reason.
  6. """
  7. UNKNOWN = -1
  8. OFF = 0
  9. ON = 1
  10. def __init__(self, initState = UNKNOWN):
  11. """
  12. Only sets the initial state of this object. This will not
  13. call any "handle" functions.
  14. """
  15. self.__state = initState
  16. def goOnStage(self, *args, **kw):
  17. """
  18. If a stage switch is needed, the correct "handle" function
  19. will be called. Otherwise, nothing happens.
  20. """
  21. # This is the high level function that clients of
  22. # your class should call to set the on/off stage state.
  23. if not self.isOnStage():
  24. self.handleOnStage(*args, **kw)
  25. def handleOnStage(self):
  26. """
  27. Override this function to provide your on/off stage funcitionality.
  28. Don't forget to call down to this one, though.
  29. """
  30. self.__state = StagedObject.ON
  31. def goOffStage(self, *args, **kw):
  32. """
  33. If a stage switch is needed, the correct "handle" function
  34. will be called. Otherwise, nothing happens.
  35. """
  36. # This is the high level function that clients of
  37. # your class should call to set the on/off stage state.
  38. if not self.isOffStage():
  39. self.handleOffStage(*args, **kw)
  40. def handleOffStage(self):
  41. """
  42. Override this function to provide your on/off stage funcitionality.
  43. Don't forget to call down to this one, though.
  44. """
  45. self.__state = StagedObject.OFF
  46. def isOnStage(self):
  47. return self.__state == StagedObject.ON
  48. def isOffStage(self):
  49. return self.__state == StagedObject.OFF