On Thursday, November 23, 2017 at 1:57:15 AM UTC-6, Edward K. Ream wrote:
> @c.command will likely morph into @g.commander_command.
Here is a slight variant of g.command that looks like it will suffice to
define commands as "bare" functions using g.@commander_command:
class CommanderCommand(object):
'''
A global decorator for creating commander commands, that is, commands
that were formerly methods of the Commands class in leoCommands.py.
Usage:
@g.command('command-name')
def command_name(self, *args, **kwargs):
...
The decorator injects command_name into the Commander class and calls
funcToMethod so the ivar will be injected in all future commanders.
g can *not* be used anywhere in this class!
'''
def __init__(self, name, **kwargs):
'''Ctor for command decorator class.'''
self.name = name
def __call__(self, func):
'''Register command for all future commanders.'''
global_commands_dict[self.name] = func
if app:
# funcToMethod ensures the command will be
# injected into all future commanders.
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
commander_command = CommanderCommand
To use this, we would just copy code from leoCommands.py to the new file,
changing @g.command to g.commander_command. Like this:
@g.commander_command('save')
def save(self, event=None, fileName=None):
# Exactly the same code as before.
I'll play with this in a new cmds branch. I have high hopes that everything
will "just work", with just a few tweaks to support code like
k.simulateCommand. I'll abandon this project if it can't be completed in a
day or three.
Edward
P.S. I don't think pyflakes has a right to complain about functions having
"self" as the first argument, but I'll check first.
EKR
> 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.