Пример #1
0
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))
Пример #2
0
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))
Пример #3
0
 def on_timeout(self):
     print('Timeout...')
     self.sm.dispatch(Event('timeout', oven=self))
     self.timer = threading.Timer(Oven.TIMEOUT, self.on_timeout)
Пример #4
0
 def close_door(self):
     self.sm.dispatch(Event('close', oven=self))
Пример #5
0
 def open_door(self):
     self.sm.dispatch(Event('open', oven=self))
Пример #6
0
 def toast(self):
     self.sm.dispatch(Event('toast', oven=self))
Пример #7
0
 def bake(self):
     self.sm.dispatch(Event('bake', oven=self))