>
>
> Installation was non-trivial. You *must* install the "nightly" version of
> rust!
>
> It's not enough to do `rustup toolchain install nightly`. I had to do a
> complete reinstall of rust.
>
>
Actually you didn't need to reinstall rust. The rustup utility is capable
of keeping several different tool chains at once. You should have run:
rustup default nightly
This would set default tool chain to nightly version, and following cargo
commands would use nightly version of rust.
> After that, `cargo build --lib --release` appears to have worked.
>
> > This command will build in the `target/release/libmini_leo.so` on linux
> or `libmini_leo.dll` on Windows.
>
> Now I'm stuck. How do I run mini_leo?
>
>
mini_leo doesn't have any GUI yet, so it can't be run on its own. I haven't
decided which GUI to use yet.
At its current state mini_leo is just a python extension module. Copy
mini_leo.dll somewhere on PYTHONPATH and try importing "_minileo".
import _minileo
t1 = _minileo.load_leo('leo/core/LeoPyRef.leo')
print(f'total number of nodes {_minileo.tree_len(t1)}')
for level, v in _minileo.iternodes(t1):
print('-'*level, v.h)
t1 in the above example is just an int, a handle to loaded outline. Many
_minileo functions expect an outline handle as their first argument.
Function iternodes(outlinehandle) returns a generator which yields tuples
(level, vdata). VData instances have h, b, and gnx fields. To actually
change tree one must use _minileo functions. Yielded vdata instances are
just copies taken from the tree, so changing them won't change the
original.
Function outline_from_str(content) parses the content which should be in
leo-thin-5 format, and returns a handle to the loaded outline. The
outline_from_file is the same just reads content from the given file. The
outline_from_leo_str and outline_from_leo_file functions expect xml content
and return outline handle.
I don't have much time now to write or to work on Leo. I hope next week I
will continue to work on the #1598 and write more about it.
I've attached small python script that demonstrate using mini_leo extension
for loading Leo outline into Leo commander c.
HTH Vitalije
--
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/2d665600-284b-4c66-a34f-e8f751dfaf14o%40googlegroups.com.
import sys
import os
if __name__ == '__main__':
if len(sys.argv) < 2:
print('usage: python mini_leo_demo.py <path to Leo installation folder>')
sys.exit(1)
LEO_INSTALL = sys.argv[1]
sys.path.append(LEO_INSTALL)
import leo.core.leoBridge as leoBridge
import leo.core.leoNodes as leoNodes
import leo.core.leoGlobals as g
from collections import defaultdict
import _minileo
import timeit
def build_tree(c, it):
'''
This function builds a tree of vnodes from the
iterable generating tuples of the following form:
(parent_gnx, gnx, childIndex, h, b, ua)
The tuples must be in the outline order.
Returns vnode instance that is a root of this tree.
'''
gnxDict = c.fileCommands.gnxDict
# returns v node for the given gnx
# if necessary it will create a new node
def getv(gnx, h, b, ua):
v = gnxDict.get(gnx)
if v is None:
v = leoNodes.VNode(c, gnx)
v._headString = h
v._bodyString = b
if ua:
v.unknownAttributes = ua
gnxDict[gnx] = v
return v
# root is handled first, before the loop
parent_gnx, gnx, childIndex, h, b, ua = next(it)
vparent = gnxDict.get(parent_gnx)
root = getv(gnx, h, b, ua)
vparent.children.insert(childIndex, root)
root.parents.append(vparent)
# now rest of the tuples
for parent_gnx, gnx, childIndex, h, b, ua in it:
vparent = gnxDict.get(parent_gnx)
v = getv(gnx, h, b, ua)
vparent.children.insert(childIndex, v)
v.parents.append(vparent)
return root
def to_build_iterator(it):
root = next(it)[1]
stack = [root.gnx]
ccounter = defaultdict(int)
seen = set()
skip_level = 100000000
for lev, v in it:
gnx = v.gnx
if skip_level < lev: continue
skip_level = 100000000
if gnx in seen:
skip_level = lev
seen.add(gnx)
stack[lev:] = [gnx]
pgnx = stack[-2]
i = ccounter[pgnx]
ccounter[pgnx] = i + 1
yield pgnx, gnx, i, v.h, v.b, {}
def new_c():
c = g.app.newCommander('dummy.leo')
hroot = c.hiddenRootNode
c.fileCommands.gnxDict[hroot.gnx] = hroot
return c
def load_leo_file(fname):
c = new_c()
t1 = _minileo.load_leo(fname)
build_tree(c, to_build_iterator(_minileo.iternodes(t1)))
_minileo.drop_tree(t1)
return c
def main():
leoBridge.controller(loadPlugins=False)
LEOPYREF = os.path.join(LEO_INSTALL, 'leo', 'core', 'LeoPyRef.leo')
def f():
return load_leo_file(LEOPYREF)
t = timeit.timeit(f, number=20)/20*1000
print(f'average: {t:6.2f}ms')
c = f()
a1 = [(p.level(), p.h, p.b) for p in c.all_positions()]
t1 = _minileo.load_leo(LEOPYREF)
a2 = [(level-1, v.h, v.b) for level, v in _minileo.iternodes(t1) if level > 0]
for i, a, b in zip(range(1000000000), a1, a2):
assert a == b, f'a != b line {i}\n\n{a!r}\n{b!r}'
print('ok')
if __name__ == '__main__':
main()