Creating a leo file usign a script

7 views
Skip to first unread message

mdb

unread,
Dec 30, 2011, 4:46:41 PM12/30/11
to leo-editor
I am trying to create a new .leo file that I will populate using a
script
However, these two methods (from Leo web page docs) do not work as I
expect.


Method 1:

import leo.core.leoGui as leoGui
nullGui = leoGui.nullGui("nullGui")
c2,frame = g.app.newLeoCommanderAndFrame(fileName=None,gui=nullGui)
c2.frame.createFirstTreeNode()

# Test that the script works.
for p in c2.all_positions():
g.es(p.h)

Method 2:

fileName='test.leo'
ok, frame = g.openWithFileName(fileName,c)
new_c = frame.c

Method 1 produces 'New Headline' in the Log pane but I do not see the
outline. I can rename the only headilne, add another headline (using
c2.insertHeadline()) and I tried redawing but I see nothing visually
to work with.

With Method 2 can not figure out what to do next, in terms of setting
the test.leo outline and adding nodes.

mdb

unread,
Jan 2, 2012, 11:49:49 AM1/2/12
to leo-editor
I think I figured out a solution combining both methods as so

import leo.core.leoGui as leoGui

fn2='test2.leo'

nullGui = leoGui.nullGui("nullGui")
c2,frame = g.app.newLeoCommanderAndFrame(fileName=None,gui=nullGui)
c2.frame.createFirstTreeNode()
c2.save()

ok, frame = g.openWithFileName(fn2,c)
c3 = frame.c
c3.redraw()

But the c2.save() step opens a dialogue where I need to type in fn2
I want to pass fn2 to this step, but saveAs and saveTo also open the
dialogue box.

Is there a save that sets the saved outline file name?

mdb

unread,
Jan 2, 2012, 12:11:51 PM1/2/12
to leo-editor
Nevermind. Setting the filename was right in front of my nose in
newLeoCommanderAndFrame(fileName=

So the working script is

import leo.core.leoGui as leoGui

## Create and save an empty leo outline
fn2='test2.leo'
nullGui = leoGui.nullGui("nullGui")
c2,frame = g.app.newLeoCommanderAndFrame(fileName=fn2,gui=nullGui)
c2.save()

## Open the new leo outline file to see it
ok, newframe = g.openWithFileName(fn2,c)

## Extra
c3 = newframe.c
p1=c3.rootPosition()
p1.h='Top Node ***'
c3.redraw()

But I imagine there is an easier way and it would be good to know if
there is a version of c.saveAs() that accepts a newfilename

Edward K. Ream

unread,
Jan 5, 2012, 7:31:05 AM1/5/12
to leo-e...@googlegroups.com
On Mon, Jan 2, 2012 at 11:11 AM, mdb <mdbo...@gmail.com> wrote:

> So the working script is

[snip]

> But I imagine there is an easier way and it would be good to know if

> there is a version of c.saveAs() that accepts a newfilename.

I doubt there is a substantially easier way: init code is inherently
tricky. You could take a look at the c.new code, but it's pretty
geeky too.

Adding a filename argument to c.saveAs and c.saveTo would be useful
additions for scripts.

Feel free to contribute such a patch. To be considered, the patch
should include a unit test demonstrating that the new argument works.

Edward

mdb

unread,
Jan 5, 2012, 8:57:30 AM1/5/12
to leo-editor
I think I found an easier way. Should have guessed nullGui had real
meaning. I just removed this and here is code that works for me

c2,frame = g.app.newLeoCommanderAndFrame(fileName='NewOutline')
c2.frame.createFirstTreeNode()

I will try to expand on c.saveAs()

mdb

unread,
Jan 5, 2012, 9:50:46 AM1/5/12
to leo-editor
Actually ... my suggestion to remove the gui argument:

> c2,frame = g.app.newLeoCommanderAndFrame(fileName='NewOutline')

does not look like a good idea. Editing the outline produces unusual
behavior and I see no menu items in the frame.
I guess gui needs to be set but I do not see how. I think these are
the minimum steps that are necessary:

fn2='NewOutline.leo'
nullGui = leoGui.nullGui("nullGui")
c2, frame2= g.app.newLeoCommanderAndFrame(fileName=fn2,gui=nullGui)
c2.save()
ok, frame2 = g.openWithFileName(fn2,c2)
c2 = frame2.c

and then c2 refers to the new outline.


Reply all
Reply to author
Forward
0 new messages