NoteLynx Export:
    Project list -- Press & hold target project -- Export

The "Export" is export xml.  Other options are "Export as HTML" and
"Export as CSV".
All exported files are put in folder /sdcard/NoteLynX.

NoteLynx Import:
    Project list -- Menu - Import

This pops up a list of all the *.xml files in folder /sdcard/NoteLynX.

Leo-Editor to NoteLynx:
    leo2nlx

Problem:  Must Edit before a leo2nlx file can be opened

Suppose you use leo2nlx.py to produce file xyz.xml.  NoteLynX imports
xyz.xml producing NoteLyX "project" xyz.  Now if you tap on project xyz,
NoteLynX terminates without displaying any error.  I think is occurs
because leo2nlx does not generate any of the "overhead" nodes usually
present in a NoteLynX "project."  You can work around this problem by
first opening xyz for editing:  press xyz for several seconds till a
menu pops up, then select edit.  You can immediately hit either the
checkmark or the yellow plus sign to terminate the edit.  Now project
xyz can be opened, viewed, and modified normally.

You could obviously change leo2nlx to generate the overhead nodes:

Example of overhead nodes:
Caution:  Node ID 1 must be the unique root node.  All other node ID's
vary from project to project.

<!--NoteLynX Export - Modified _#_2015-01-31 19-34-17_#_-->

<node id="3" title="notelynx_bookmarks" body="" links=" 1 " linkTypes="1"/>

<node id="4" title="notelynx_style_main"
body="body&nbsp;{<br>font-family:&nbsp;"Arial";<br>font-size:&nbsp;100%;<br><br>margin-top:&nbsp;10px;<br>margin-left:&nbsp;10px;<br>margin-right:&nbsp;10px;<br>margin-bottom:&nbsp;10px;<br>}<br><br>h1,&nbsp;h2,&nbsp;h3,&nbsp;h4,&nbsp;h5,&nbsp;h6&nbsp;{<br>display:&nbsp;inline;<br>}<br><br>a:link&nbsp;{<br>color:&nbsp;#007FFF;<br>}<br><br>a:visited&nbsp;{<br>color:&nbsp;#007FFF;<br>}<br><br>.title&nbsp;{<br>font-size:120%;<br>font-weight:&nbsp;bold;<br>}<br><br>/*&nbsp;Alternate&nbsp;Fonts<br>Arial,&nbsp;Times,&nbsp;Courier,&nbsp;Monospace<br>*/"
links="" linkTypes=""/>

<node id="5" title="notelynx_style_day"
body="body<br>{<br>background-color:&nbsp;white;<br>color:&nbsp;black;<br>}<br><br>"
links="" linkTypes=""/>

<node id="6" title="notelynx_style_night"
body="body<br>{<br>background-color:&nbsp;black;<br>color:&nbsp;white;<br>}<br><br>"
links="" linkTypes=""/>

<node id="7" title="notelynx_sort" body="" links=" " linkTypes="
"/></network>

-- 
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 post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.
#!/usr/bin/python
# -*- coding: utf-8 -*-
#@+leo-ver=5-thin
#@+node:bob05.20150128152642.4: * @file py/leo2nlx.py
#@@first
#@@first
#@@language python
#@@tabwidth -4

#@+<< documentation >>
#@+node:bob05.20150128152642.5: ** << documentation >>
"""
Generate a NoteLynX XML project file that represents the specified
Leo-Editor File
"""
#@-<< documentation >>
#@+<< Copyright >>
#@+node:bob05.20150203124337.4: ** << Copyright >>
"""
leo2nlx.py - Leo-Editor file compare functions
Copyright (C) 2015 Robert F. Hossley.  All Rights Reserved.

leo2nlx.py is Open Software and is distributed under the terms of the
MIT License. The gist of the license is that leo2nlx.py is absolutely
free, even for commercial use (including resale). There is no GNU-like
"copyleft" restriction. The Open Source Initiative board has voted to certify
the MIT license as Open Source. This license is compatible with the GPL.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Robert F. Hossley
not be used in advertising or publicity pertaining to distribution of
the software without specific, written prior permission.

DISCLAIMER OF WARRANTIES

Robert F. Hossley SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESSED
OR IMPLIED, WITH RESPECT TO THIS COMPUTER SOFTWARE, INCLUDING BUT NOT
LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE. IN NO EVENT SHALL REAM BE LIABLE FOR ANY LOSS OF
PROFIT OR ANY COMMERCIAL DAMAGE, INCLUDING BUT NOT LIMITED TO SPECIAL,
INCIDENTAL, CONSEQUENTIAL OR OTHER DAMAGES.

"""

#@-<< Copyright >>
#@+<< imports >>
#@+node:bob05.20150128152642.6: ** << imports >>
import argparse
import os
import xml.etree.ElementTree as ET

import leo.core.leoBridge as leoBridge
#@-<< imports >>

#@+others
#@+node:bob05.20150128152642.7: ** cmdLineHandler()
def cmdLineHandler():
    """
    Command Line Handler

    @param return:  argparse.Namespace object containing all the parsed
        command line arguments.
    """

    parser = argparse.ArgumentParser(description='Leo-Editor to NoteLynX', usage='%(prog)s inFile outFile')
    parser.add_argument('inFile', help='Pathname of a .leo file.  .leo is added automatically if needed.')
    parser.add_argument('outFile', help='Pathname of an xml file to be created or overwritten. .xml is added automatically if needed.')
    args = parser.parse_args()
    
    if not args.inFile.endswith('.leo'):
        args.inFile = args.inFile + '.leo'
    if not args.outFile.endswith('.xml'):
        args.outFile = args.outFile + '.xml'

    return args
#@+node:bob05.20150128152642.8: ** main()
def main():
    args = cmdLineHandler()

    bridge = leoBridge.controller(gui='nullGui', silent=True,
        verbose=False, loadPlugins=False, readSettings=False)
    cmdrIn = bridge.openLeoFile(args.inFile)
    leo2nlx(cmdrIn, args.outFile)
    cmdrIn.close()
#@+node:bob05.20150130154417.2: ** class NodeObj
class NodeObj(object):
    #@+others
    #@+node:bob05.20150130154417.3: *3* __init__()
    def __init__(self, hdr, bdy):
        self.hdr = hdr
        self.bdy = bdy
        self.children = None
        self.parents = None
        self.visited = None
        self.nodeID = None
    #@+node:bob05.20150130154417.4: *3* __repr__()
    def __repr__(self):
        return 'Node ID: {ni} Headline: "{hdr}"'.format(
            ni=self.nodeID, hdr=self.hdr)
    #@-others
#@+node:bob05.20150128152642.9: ** leo2nlx()
def leo2nlx(cmdrIn, outPath):
    """ Traverse a Leo-Editor Outline producing a 
    NoteLynX XML project file
    
    Arguments:
        cmdrIn:  Leo-Editor commander for the target
            input file.
        outPath:  Pathname of XML file to be produced.

    Returns:
        None

    """
    def _allVnodes():
        yield hiddenVnode
        for vnode in cmdrIn.all_vnodes_iter():
            yield vnode

    vnode2nobj = dict()
    # Create all Node Objects
    hiddenNobj = None
    hiddenVnode = None
    for vnode in cmdrIn.all_vnodes_iter():
        nobj = NodeObj(vnode.h, vnode.b)
        vnode2nobj[vnode] = nobj
        pv = vnode.parents[0]
        if (pv.gnx == 'hidden-root-vnode-gnx' 
            and
            hiddenNobj is None):
            title = os.path.splitext(os.path.basename(outPath))[0]
            hiddenNobj = NodeObj(title, '')
            hiddenVnode = pv
            vnode2nobj[hiddenVnode] = hiddenNobj
    # Fill in the children list and parent list in each Node Object
    for vnode in  _allVnodes():
        nodeObjx = vnode2nobj[vnode]
        nodeObjx.children = [vnode2nobj[vnode] for vnode in vnode.children]
        nodeObjx.parents = [vnode2nobj[vnode] for vnode in vnode.parents]
    # Walk the NodeObj tree assigning node ID's
    nodeID = 1
    for nodex in bffvWalk(hiddenNobj):
        nodex.nodeID = nodeID
        nodeID += 1
    # Walk the NodeObj tree generating XML
    xmlRoot = ET.Element('network')
    for nodex in bffvWalk(hiddenNobj):
        links = [str(nodey.nodeID) for nodey in nodex.parents]
        linkTypes = ['1' for nodey in nodex.parents]
        links = links + [str(nodey.nodeID) for nodey in nodex.children]
        linkTypes = linkTypes + ['3' for nodey in nodex.children]
        _ = ET.SubElement(xmlRoot, 'node',
            {'id': str(nodex.nodeID),
            'title': nodex.hdr,
            'body': nodex.bdy,
            'links': ' '.join(links) ,
            'linkTypes': ' '.join(linkTypes) })
    
    ET.ElementTree(xmlRoot).write(outPath, encoding='utf-8')
        
#@+node:bob05.20150131111640.2: ** bffvWalk() - Breadth First node Walk
def bffvWalk(rootNodeObj):
    """ Breadth First node Walk
    Generator returning every Vnode in Breadth First Order.

    Arguments:
        rootNodeObj:  Root Node Object

    Returns:
        nodex:  Next node in the tree.

    Exceptions:
        StopIteration:  All nodes have been returned.

    """

    clearAllVisited(rootNodeObj)
    #fifo = [(nodeObjx, None) for nodeObjx in rootNodeObj.children]
    fifo = [(rootNodeObj, None)]
    while True:
        if fifo:
            parent, index = fifo[0]
            if index is None:
                if not parent.visited:
                    parent.visited = True
                    yield parent
                del fifo[0]
                fifo.append((parent, 0))
            else:
                if index < len(parent.children):
                    nxtVnode = parent.children[index]
                    if not nxtVnode.visited:
                        nxtVnode.visited = True
                        yield nxtVnode
                    fifo[0] = (parent, index + 1)
                    fifo.append((nxtVnode, 0))
                else:
                    del fifo[0]
        else:
            break
#@+node:bob05.20150131111640.3: ** clearAllVisited()
def clearAllVisited(rootNodeObj):
    """ Attach a "visited" attribute with value False
    to each NodeObj
    
    Arguments:
        rootNodeObj:  Root node object
    
    Returns:
        None
    
    This is easier than bffvWalk() because it doesn't matter
    if the attribute is attached several times to a node.
    This occurs when there are clones.
    """

    rootNodeObj.visited = False
    for nodex in rootNodeObj.children:
        clearAllVisited(nodex)
#@-others

if __name__ == '__main__':
    main()
#@-leo

Reply via email to