gui/resource.py
def connect(component, controller=None):
    "Associate event handlers "
    
    # get the controller functions and names (module or class)
    if not controller or isinstance(controller, dict):
        if not controller:
            controller = util.get_caller_module_dict()
        controller_name = controller['__name__']
        controller_dict = controller
    else:
        controller_name = controller.__class__.__name__
        controller_dict = dict([(k, getattr(controller, k)) for k 
                                in dir(controller) if k.startswith("on_")])

    for fn in [n for n in controller_dict if n.startswith("on_")]:
        # on_mypanel_mybutton_click -> ['mypanel']['mybutton'].onclick 
        names = fn.split("_")
        event_name = names.pop(0) + names.pop(-1)
        # find the control
        obj = component
        for name in names:
            try:
                obj = obj[name]
            except KeyError:
                obj = None
                break
        if not obj:
            from .component import COMPONENTS
            for key, obj in COMPONENTS.items():
                if obj.name == name:
                    print "WARNING: %s should be %s" % (name, key.replace(".", "_"))
                    break
            else:
                raise NameError("'%s' component not found (%s.%s)" % 
                                    (name, controller_name, fn))
        # check if the control supports the event:
        if event_name in PYTHONCARD_EVENT_MAP:
            new_name = PYTHONCARD_EVENT_MAP[event_name]
            print "WARNING: %s should be %s (%s)" % (event_name, new_name, fn)
            event_name = new_name
        if not hasattr(obj, event_name):
            raise NameError("'%s' event not valid (%s.%s)" % 
                                (event_name, controller_name, fn))
        # bind the event (assign the method to the on... spec)
        setattr(obj, event_name, controller_dict[fn])
def connect(component, controller=None):
    "Associate event handlers "
    
    # get the controller functions and names (module or class)
    if not controller or isinstance(controller, dict):
        if not controller:
            controller = util.get_caller_module_dict()
        controller_name = controller['__name__']
        controller_dict = controller
    else:
        controller_name = controller.__class__.__name__
        controller_dict = dict([(k, getattr(controller, k)) for k 
                                in dir(controller) if k.startswith("on_")])

    for fn in [n for n in controller_dict if n.startswith("on_")]:
        # on_mypanel_mybutton_click -> ['mypanel']['mybutton'].onclick 
        names = fn.split("_")
        event_name = names.pop(0) + names.pop(-1)
        # find the control
        obj = component
        for name in names:
            try:
                obj = obj[name]
            except KeyError:
                obj = None
                break
        if not obj:
            from .component import COMPONENTS
            for key, obj in COMPONENTS.items():
                if obj.name == name:
                    print "WARNING: %s should be %s" % (name, key.replace(".", "_"))
                    break
            else:
                raise NameError("'%s' component not found (%s.%s)" % 
                                    (name, controller_name, fn))
        # check if the control supports the event:
        if event_name in PYTHONCARD_EVENT_MAP:
            new_name = PYTHONCARD_EVENT_MAP[event_name]
            print "WARNING: %s should be %s (%s)" % (event_name, new_name, fn)
            event_name = new_name
        if not hasattr(obj, event_name):
            raise NameError("'%s' event not valid (%s.%s)" % 
                                (event_name, controller_name, fn))
        # bind the event (assign the method to the on... spec)
        setattr(obj, event_name, controller_dict[fn])
Associate event handlers