How to add nodes to Leo via a Python script

76 views
Skip to first unread message

Rand

unread,
Aug 29, 2012, 5:11:01 PM8/29/12
to leo-e...@googlegroups.com
I want to add a tree of nodes to Leo via a python script.

Can someone give me an example ?

thanks
Rand

Brian Theado

unread,
Aug 29, 2012, 8:12:57 PM8/29/12
to leo-e...@googlegroups.com
On Wed, Aug 29, 2012 at 5:11 PM, Rand <ran...@gmail.com> wrote:
> I want to add a tree of nodes to Leo via a python script.
> Can someone give me an example ?

If you know the minibuffer commands (easily discoverable due to tab
completion), then you can use those. For example:

c.executeMinibufferCommand('insert-node')

or

c.executeMinibufferCommand('insert-child')

Here's an example of creating a new command from multiple minibuffer commands:

def executeMinibufferCommands (c, cmds):
for cmd in cmds.strip().splitlines():
c.executeMinibufferCommand(cmd.strip())

@g.command("splice-insert")
def spliceInsert (event):
'''Inserts a new headline as a parent of the current headline'''
c.inCommand = False
executeMinibufferCommands (event.get('c'), '''
contract-node
insert-node
goto-prev-sibling
move-outline-down
move-outline-right
goto-parent
edit-headline
''')

That doesn't add a tree of nodes, but maybe it will give you the idea.
Though at some point it probably makes more sense to dive into the
lower level python methods and call them directly.

Brian

Edward K. Ream

unread,
Aug 31, 2012, 2:39:25 PM8/31/12
to leo-e...@googlegroups.com
On Wed, Aug 29, 2012 at 4:11 PM, Rand <ran...@gmail.com> wrote:
> I want to add a tree of nodes to Leo via a python script.
>
> Can someone give me an example ?

leoPy.leo contains numerous examples.

You can also use Brian's suggestion to use
c.executeMinibufferCommand, but it also happens that using Leo's
built-in capabilities gives you more flexibility. Some places to look
at in leoPy.leo:

@file leoNodes.py-->class position-->
p.Moving, Inserting, Deleting, Cloning, Sorting

@file leoCommands.py-->class commands-->
Command handlers...-->Outline menu...--> Top Level... (Commands)-->
c.Cut & Paste Outlines

HTH. Let me know if you have other questions.

Edward
Reply all
Reply to author
Forward
0 new messages