def _xcf_subscribe(state, memory, xpath, handler, actions=xcf.INSERT | xcf.REPLACE): # once, define _xcf_events and register enter/exit handlers to actually subscribe/unsubscribe events if not hasattr(state, '_xcf_events'): # define _xcf_events attribute state._xcf_events = [] # on enter, subscribe to topics state.add_handler('enter', lambda event: _subscribe_xcf_events(state, event)) # on exit, unsubscribe state.add_handler('exit', lambda event: _unsubscribe_xcf_events(state, event)) # a string "handler" is interpreted as an event to be triggered if isinstance(handler, string_types): name = handler # need to use another name! handler = lambda data: state.root.dispatch(Event(name, msg=data)) # actually register the event state._xcf_events.append(_XCFEvent(memory, xpath, actions, handler))
def _ros_subscribe(state, topic, msg_type, handler): # once, define _ros_events and register enter/exit handlers to actually subscribe/unsubscribe events if not hasattr(state, '_ros_events'): # define _ros_events attribute state._ros_events = [] # on enter, subscribe to topics state.add_handler('enter', lambda event: _subscribe_ros_events(state, event)) # on exit, unsubscribe state.add_handler('exit', lambda event: _unsubscribe_ros_events(state, event)) # a string "handler" is interpreted as an event to be triggered if isinstance(handler, string_types): name = handler # need to use another name! handler = lambda data: state.root.dispatch(Event(name, msg=data)) # actually register the event state._ros_events.append(_ROSEvent(topic, msg_type, handler))
def on_timeout(self): print('Timeout...') self.sm.dispatch(Event('timeout', oven=self)) self.timer = threading.Timer(Oven.TIMEOUT, self.on_timeout)
def close_door(self): self.sm.dispatch(Event('close', oven=self))
def open_door(self): self.sm.dispatch(Event('open', oven=self))
def toast(self): self.sm.dispatch(Event('toast', oven=self))
def bake(self): self.sm.dispatch(Event('bake', oven=self))