Skip to content

Create a global event #347

Closed Answered by fgmacedo
yoavweber asked this question in Q&A
Feb 16, 2023 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

Hi @yoavweber ,

One example of solution is to create internal transitions on each state:

class TrafficLightMachine(StateMachine):
    "A traffic light machine"
    green = State("Green", initial=True)
    yellow = State("Yellow")
    red = State("Red")

    honk = green.to.itself(internal=True) | yellow.to.itself(internal=True) | red.to.itself(internal=True)

    def on_honk(self):
            print("honk")
  1. The state will NOT be changed.
  2. The on_enter* or on_exit* hooks will NOT be called.
  3. The on_hook will be called.

If this not helps, can you elaborate more your expected behaviour?

  1. How could honk be triggered?
  2. What you expect to happen when honk is triggered?
  3. Is there any change in state?

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@yoavweber
Comment options

@yoavweber
Comment options

@fgmacedo
Comment options

@yoavweber
Comment options

@fgmacedo
Comment options

Answer selected by fgmacedo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants