On Saturday, November 25, 2017 at 10:03:49 AM UTC-6, Edward K. Ream wrote:

*c.executeAnyCommand*...uses Python's inspect module to determine how to 
> call each command.
>

Rev 442545b collapses the complexity of dispatch code. A new wrapper in the 
g.commander_command decorator makes this possible.  Here is the updated 
__call__ method:

def __call__(self, func):
    '''Register command for all future commanders.'''
    
    def commander_command_wrapper(event):
        c = event.get('c')
        method = getattr(c, func.__name__, None)
        method(event=event)
        
    # Inject ivars for plugins_menu.py.
    commander_command_wrapper.__name__ = 'commander_command_wrapper: %s' % 
self.name
    commander_command_wrapper.__doc__ = func.__doc__
    global_commands_dict[self.name] = commander_command_wrapper
    if app:
        import leo.core.leoCommands as leoCommands
        funcToMethod(func, leoCommands.Commands)
        for c in app.commanders():
            c.k.registerCommand(self.name, func)
    # Inject ivars for plugins_menu.py.
    func.is_command = True
    func.command_name = self.name
    return func

As a result, c.executeAnyCommand is equivalent to the legacy dispatch code:

def executeAnyCommand(self, command, event):
    try:
        return command(event)
    except Exception:
        g.es_exception()
        return None

I expect this to be the last major work on the project.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to