StagedObject.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. pass
  17. def goOnStage(self, *args, **kw):
  18. """
  19. If a stage switch is needed, the correct "handle" function
  20. will be called. Otherwise, nothing happens.
  21. """
  22. # This is the high level function that clients of
  23. # your class should call to set the on/off stage state.
  24. if not self.isOnStage():
  25. self.handleOnStage(*args, **kw)
  26. pass
  27. pass
  28. def handleOnStage(self):
  29. """
  30. Override this function to provide your on/off stage funcitionality.
  31. Don't forget to call down to this one, though.
  32. """
  33. self.__state = StagedObject.ON
  34. pass
  35. def goOffStage(self, *args, **kw):
  36. """
  37. If a stage switch is needed, the correct "handle" function
  38. will be called. Otherwise, nothing happens.
  39. """
  40. # This is the high level function that clients of
  41. # your class should call to set the on/off stage state.
  42. if not self.isOffStage():
  43. self.handleOffStage(*args, **kw)
  44. pass
  45. pass
  46. def handleOffStage(self):
  47. """
  48. Override this function to provide your on/off stage funcitionality.
  49. Don't forget to call down to this one, though.
  50. """
  51. self.__state = StagedObject.OFF
  52. pass
  53. def isOnStage(self):
  54. return self.__state == StagedObject.ON
  55. def isOffStage(self):
  56. return self.__state == StagedObject.OFF