def _handle_event(self, event=''): '''called from event loop to handle''' if self.debug: tart.log('tart: event', event) try: msg = json.loads(event) except ValueError: msg = [] # extract message type and build handler name based on convention # shared with and adopted from QML try: msg_type = msg[0] # apply Qt-style case normalization name = 'on' + msg_type[0].upper() + msg_type[1:] except IndexError: tart.log('tart: ERROR, no type found in message') return else: # find a matching handler routine, if there is one try: handler = getattr(self, name) except AttributeError: if msg_type.startswith('on'): tart.log( 'tart: WARNING, message starts with "on", maybe remove?' ) self.missing_handler(msg) return # tart.log('calling', handler) try: kwargs = msg[1] or {} except KeyError: kwargs = {} # Actually process the message in the handler: note that # results are ignored for now, and any exceptions will # result in a traceback from the calling code (in tart.cpp) result = handler(**kwargs)
def _handle_event(self, event=''): '''called from event loop to handle''' if self.debug: tart.log('tart: event', event) try: msg = json.loads(event) except ValueError: msg = [] # extract message type and build handler name based on convention # shared with and adopted from QML try: msg_type = msg[0] # apply Qt-style case normalization name = 'on' + msg_type[0].upper() + msg_type[1:] except IndexError: tart.log('tart: ERROR, no type found in message') return else: # find a matching handler routine, if there is one try: handler = getattr(self, name) except AttributeError: if msg_type.startswith('on'): tart.log('tart: WARNING, message starts with "on", maybe remove?') self.missing_handler(msg) return # tart.log('calling', handler) try: kwargs = msg[1] or {} except KeyError: kwargs = {} # Actually process the message in the handler: note that # results are ignored for now, and any exceptions will # result in a traceback from the calling code (in tart.cpp) result = handler(**kwargs)
def missing_handler(self, msg): tart.log('tart: ERROR, missing handler for', msg[0])
def __init__(self, debug=True): self.debug = debug if self.debug: tart.log('tart: app starting')
def __init__(self, debug=False): self.debug = debug if self.debug: tart.log('tart: app starting')