I don't have a large objection to creating a plugin. One thing you will
have to decide is where the plugin should live. You don't want it to be in
the Leo codebase since it's personal. Leo will load plugins from sys.path
if you list them in the @enabled-plugins setting if you give the module
name without the ".py" extension. So you have to get your plugin on
sys.path. Here is how I do it (using Windows paths). In *Lib.sitepackages
*I place a .pth file, *custom.pth*. This file walks up the the Python
directory in %APPDATA%\Python:
# Look in AppData\Roaming\Python for other files and packages.
..\..\
In this Python directory I created *pycustomize\leo.* Now I can import a
module from that directory:
from pycustomize.leo import my_plugin
I decided to set up the location of these files (I have some others in
*pycustomizeI*) like this so they wouldn't need to be copied to each new
Python install. I only need to remember to copy *custom.pth* to the new
install.
I recently wrote a tiny test plugin that can install scripts and functions
(see, I've just been teaching myself how to do the same things you are
asking about). In this case I was monkeypatching the g.openUNLFile() method
. Here's its contents:
"""A Leo plugin to run scripts at startup.
Methods changed by this plugin:
- g.openUNLFile()
"""
import leo.core.leoGlobals as g
def new_open_unl(c, s):
print('the new openUNLFile', s, c)
return g.old_openUNLFile(c, s)
def onCreate(tag, keywords):
pass
def init():
"""Return True if the plugin has loaded successfully."""
if g.unitTesting:
return False
print('hello from the monkey-patcher')
# Register the handlers...
# g.registerHandler('after-create-leo-frame', onCreate)
g.old_openUNLFile = g.openUNLFile
g.openUNLFile = new_open_unl
g.plugin_signon(__name__)
return True
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/51b678c8-da47-4568-85fe-78bedc103107n%40googlegroups.com.