示例#1
0
    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)
示例#2
0
    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)
示例#3
0
文件: app.py 项目: YaDev/BB10-Py-App
 def missing_handler(self, msg):
     tart.log('tart: ERROR, missing handler for', msg[0])
示例#4
0
文件: app.py 项目: YaDev/BB10-Py-App
 def __init__(self, debug=True):
     self.debug = debug
     if self.debug:
         tart.log('tart: app starting')
示例#5
0
 def missing_handler(self, msg):
     tart.log('tart: ERROR, missing handler for', msg[0])
示例#6
0
 def __init__(self, debug=False):
     self.debug = debug
     if self.debug:
         tart.log('tart: app starting')