I'm trying to replicate the code from this talk:
class Video:
## Define the states
PLAYING = "playing"
PAUSED = "paused"
STOPPED = "stopped"
def __init__(self,source):
self.source = source
transitions = [
{"trigger":"play","source":self.PAUSED, "dest":self.PLAYING},
{"trigger":"play","source":self.STOPPED, "dest":self.PLAYING},
##
{"trigger":"pause","source":self.PAUSED, "dest":self.PAUSED},
##
{"trigger":"stop","source":self.PAUSED, "dest":self.STOPPED},
{"trigger":"stop","source":self.PLAYING, "dest":self.STOPPED}
]
self.machine = Machine(
model = self,
transitions = transitions,
initial = self.STOPPED)
def pause(self):
print ("pause")
def play(self):
print ("play")
def stop(self):
print ("stop")
But one I call it, it does not work:
test = Video("some text")
that returns a warning:
2020-09-27 17:25:50,255 [11472] WARNING transitions.core:828: [JupyterRequire] Model already contains an attribute 'play'. Skip binding.
2020-09-27 17:25:50,259 [11472] WARNING transitions.core:828: [JupyterRequire] Model already contains an attribute 'pause'. Skip binding.
2020-09-27 17:25:50,260 [11472] WARNING transitions.core:828: [JupyterRequire] Model already contains an attribute 'stop'. Skip binding.
But the main issue is that the state does not change:
This is the code from the original talk:
from state do not change in a FSM in python using transitions library
No comments:
Post a Comment