Copy the following snippet, save it as leo outline, open the file with
leo

--- cut here ---
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet ekr_test?>
<leo_file>
<leo_header file_format="2" tnodes="0" max_tnode_index="0"
clone_windows="0"/>
<globals body_outline_ratio="0.5" body_secondary_ratio="0.5">
        <global_window_position top="50" left="50" height="500" width="700"/>
        <global_log_window_position top="0" left="0" height="0" width="0"/>
</globals>
<preferences/>
<find_panel_settings/>
<vnodes>
<v t="shadow.20100823070331.1280"><vh>test</vh>
<v t="shadow.20100823070331.1281"><vh>@button script</vh></v>
<v t="shadow.20100823070331.1282"><vh>sorted</vh>
<v t="shadow.20100823070331.1283"><vh>1</vh></v>
<v t="shadow.20100823070331.1284"><vh>3</vh></v>
<v t="shadow.20100823070331.1285"><vh>2</vh></v>
</v>
</v>
</vnodes>
<tnodes>
<t tx="shadow.20100823070331.1280"></t>
<t tx="shadow.20100823070331.1281">for p in c.all_positions():
    if p.headString() == 'sorted':
        children = list(p.children())
        headlines = [x.headString() for x in children]
        print headlines
        break

</t>
<t tx="shadow.20100823070331.1282"></t>
<t tx="shadow.20100823070331.1283"></t>
<t tx="shadow.20100823070331.1284"></t>
<t tx="shadow.20100823070331.1285"></t>
</tnodes>
</leo_file>
--- cut here ---

For redundancy I pasted the same xml snippet here:
http://pastebin.ca/1923111

This is the error I see in the log pane:
--- cut here ---
exception executing script
AttributeError: 'NoneType' object has no attribute 'headString'
--------------------
  line 450:
* line 451:         return self.v.headString()
  line 452:
  line 453:     def cleanHeadString (self):
--- cut here ---

I generally don't use leo to script leo itself, so I don't know a lot
of "script leo the right way" and "don't do it this way" tricks. I
occasionally write small scripts to spare myself from doing monotonous
manual management of nodes in an outline.

When this thread is exhausted, I expect to have not only the attached
script working, but also to learn about a new pitfall, to avoid it in
the future. That's because I assume it's me doing something wrong by
default, it's not leo's fault/eventual bug.

I'm using the current trunk of leo (r3275) with python 2.6.4. on linux.

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to