On Sat, May 9, 2015 at 11:58 PM, <[email protected]> wrote:
> The main point is to tell a function from a method. If you don't want to
> use __qualname__ one might use the inspect module.
>
> But assuming the Python convention to name the first argument of method
> 'self', the foll
> o
> wing works for both Python 2 and 3:
>
Thanks for all your suggestions. They have been helpful.
The VimCommands class uses 'vc' instead of self. That isn't going to
change. Decorators must adapt to existing code, not vice versa.
The primary task is to associate a decorator with an *instance *of a class.
The code that I pushed yesterday does this by defining a cmd decorator for
each class that defines a Leo command.
When I awoke this morning I saw that a single dict, say g.instance_dict,
could eliminate the need for per-class decorators. A single *g.cmd*
decorator could recover desired instance using this dict. Keys would be
class names, values would be lists of attributes. For example,
*cmd_instance_dict* = {
'AutoCompleter': ['c','k','autoCompleter'],
'LeoApp': ['g','app'],
...
}
This dict encapsulates the "variable" parts of the present cmd decorators.
*Important*: the event sent to the *wrapper* contains the proper commander,
so the wrapper can get the desired instance using g.ivars2instance.
Two kinds of checks will be performed:
1. The g.cmd decorator itself will check that func.__class__.__name__ is in
g.cmd_instance_dict.keys(). This is an import-time check.
2. Code in c.finishCreate will check that all the attributes in each list
exist. g.ivars2instance already performs this check. This is a permanent
unit test that can't be run with per-class definitions of cmd.
*Note*: g.cmd_instance_dict and g.global_commands_dict must be in
leoGlobals.py. They can't be in the LeoApp class because this class is not
fully created when decorators execute.
A final task in the new_dispatch project has nothing to do with decorators.
A single kind of event must be sent to all commands. At present, some
events do not have 'stroke' attributes, etc. Unifying events is likely to
be tricky.
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 http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.