Example #1
0
        pass

    def pourcup(self, sugar=0):
        """
		"""
        pass


# -----------------------------------------------------------------------
# transitions...
# NOTE: if we use the non-strict transition mode then all manual
#       transitions can be omitted...
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# startup...
# manual (external actor)...
fsm.transition(CoffeeMachineOff, CoffeeMachineReady, condition=lambda o: o.haspower(), mode=fsm.MANUAL)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# ready to err...
# automatic...
fsm.transition(CoffeeMachineReady, CoffeeMachineNoCoffee, condition=lambda o: not o.hascoffee())
fsm.transition(CoffeeMachineReady, CoffeeMachineNoWater, condition=lambda o: not o.haswater())
fsm.transition(CoffeeMachineReady, CoffeeMachineNoSugar, condition=lambda o: not o.hassugar())

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# make and serve...
# manual (external actor)...
fsm.transition(CoffeeMachineReady, CoffeeMachineMixing, mode=fsm.MANUAL)
fsm.transition(CoffeeMachineNoSugar, CoffeeMachineMixing, mode=fsm.MANUAL)
fsm.transition(CoffeeMachineReady, CoffeeMachinePouring, mode=fsm.MANUAL)
fsm.transition(CoffeeMachineNoCoffee, CoffeeMachinePouring, mode=fsm.MANUAL)
Example #2
0
	if len(s) > sl:
		s += [0]
		return True
	return False
def pred_B2B(o):
	global s
	if len(s) <= sl:
		s += [0]
		return True
	return False


print 'defining transitions...'
##fsm.transition(A, B)
##fsm.transition(A, C)
fsm.transition(A, B, mode=fsm.MANUAL)
fsm.transition(A, C, mode=fsm.MANUAL)
fsm.transition(B, C, condition=pred_B2C)
fsm.transition(B, B, condition=pred_B2B)


print 'creating an fsm instance...'
mfsm = FSM()

print

print 'preparing events:'
print 'defining handler...'
def f(evt):
	print '   ****', evt.__class__.__name__, ':', evt.state_name
print 'binding events...'