Example #1
0
 def ap_to_p(self, ap):
     '''(From Leo plugin leoflexx.py) Convert an archived position to a true Leo position.'''
     childIndex = ap['childIndex']
     v = self.gnx_to_vnode[ap['gnx']]
     stack = [(self.gnx_to_vnode[d['gnx']], d['childIndex'])
              for d in ap['stack']]
     return leoNodes.position(v, childIndex, stack)
Example #2
0
    def readFile(self, fileName):

        if not fileName:
            return g.trace('no fileName')

        c = self.c.new()
        # Create the new commander *now*
        # so that created vnodes will have the proper context.

        # Pass one: create the intermediate nodes.
        dummyRoot = self.parse_opml_file(fileName)
        self.dumpTree(dummyRoot)

        # Pass two: create the outline from the sax nodes.
        children = self.createVnodes(c, dummyRoot)
        p = leoNodes.position(v=children[0], childIndex=0, stack=None)

        # Check the outline.
        c.dumpOutline()
        errors = c.checkOutline()
        if errors:
            return g.trace('%s errors!' % errors)

        # if self.opml_read_derived_files:
        # at = c.atFileCommands
        # c.fileCommands.tnodesDict = self.createTnodesDict()
        # self.resolveTnodeLists(c)
        # if self.opml_read_derived_files:
        # c.atFileCommands.readAll(c.rootPosition())

        c.selectPosition(p)
        c.redraw()
        return c  # for testing.
Example #3
0
    def readFile(self, fileName):

        if not fileName:
            return g.trace("no fileName")

        c = self.c.new()
        # Create the new commander *now*
        # so that created vnodes will have the proper context.

        # Pass one: create the intermediate nodes.
        dummyRoot = self.parse_opml_file(fileName)
        self.dumpTree(dummyRoot)

        # Pass two: create the outline from the sax nodes.
        children = self.createVnodes(c, dummyRoot)
        p = leoNodes.position(v=children[0], childIndex=0, stack=None)

        # Check the outline.
        c.dumpOutline()
        errors = c.checkOutline()
        if errors:
            return g.trace("%s errors!" % errors)

        # if self.opml_read_derived_files:
        # at = c.atFileCommands
        # c.fileCommands.tnodesDict = self.createTnodesDict()
        # self.resolveTnodeLists(c)
        # if self.opml_read_derived_files:
        # c.atFileCommands.readAll(c.rootPosition())

        c.selectPosition(p)
        c.redraw()
        return c  # for testing.
Example #4
0
 def createFirstTreeNode(self):
     c = self.c
     v = leoNodes.vnode(context=c)
     p = leoNodes.position(v)
     v.initHeadString("NewHeadline")
     # New in Leo 4.5: p.moveToRoot would be wrong:
     # the node hasn't been linked yet.
     p._linkAsRoot(oldRoot=None)
Example #5
0
 def createFirstTreeNode(self):
     c = self.c
     v = leoNodes.vnode(context=c)
     p = leoNodes.position(v)
     v.initHeadString("NewHeadline")
     # New in Leo 4.5: p.moveToRoot would be wrong:
     # the node hasn't been linked yet.
     p._linkAsRoot(oldRoot=None)
Example #6
0
  def createFirstTreeNode (self):

    f = self ; c = f.c

    v = leoNodes.vnode(context=c)
    p = leoNodes.position(v)
    v.initHeadString("NewHeadline")
    # New in Leo 4.5: p.moveToRoot would be wrong: the node hasn't been linked yet.
    p._linkAsRoot(oldRoot=None)
    # c.setRootPosition(p) # New in 4.4.2.
    c.editPosition(p)
Example #7
0
 def createFirstTreeNode(self):
     c = self.c
     #
     # #1631: Initialize here, not in p._linkAsRoot.
     c.hiddenRootNode.children = []
     #
     # #1817: Clear the gnxDict.
     c.fileCommands.gnxDict = {}
     #
     v = leoNodes.vnode(context=c)
     p = leoNodes.position(v)
     v.initHeadString("NewHeadline")
     # New in Leo 4.5: p.moveToRoot would be wrong:
     # the node hasn't been linked yet.
     p._linkAsRoot()
Example #8
0
def _descendHdl(cmdrUnl, unlList):
    """
    Descend the target outline matching the Headline outline path

    Arguments:
        cmdrUnl:  Commander for the target outline
        unlList:  Root to position list of headlines.
            None --> UNL specifies all root nodes.

    Returns:
        posList:   A list containing in tree order all
            the positions that satisfy the UNL.
            [] (empty list) --> No position satisfies the UNL

    """
    def appendList(lst, entry):
        lstNew = lst[:]
        lstNew.append(entry)
        return lstNew

    if unlList is None:
        return listRoots(cmdrUnl)
    soFarList = [[
        (childVnode, idx)
    ] for idx, childVnode in enumerate(cmdrUnl.hiddenRootNode.children)]
    lastUnlIdx = len(unlList) - 1
    for idx1, hdl in enumerate(unlList):
        if idx1 == lastUnlIdx:
            soFarList = [stk for stk in soFarList if stk[-1][0].h == hdl]
        else:
            soFarList = [
                appendList(stk, (childVnode, idx2)) for stk in soFarList
                for idx2, childVnode in enumerate(stk[-1][0].children)
                if stk[-1][0].h == hdl
            ]
        if not soFarList:
            return list()
    return [
        leoNodes.position(stk[-1][0], childIndex=stk[-1][1], stack=stk[:-1])
        for stk in soFarList
    ]
Example #9
0
def _descendHdl(cmdrUnl, unlList):
    """
    Descend the target outline matching the Headline outline path

    Arguments:
        cmdrUnl:  Commander for the target outline
        unlList:  Root to position list of headlines.
            None --> UNL specifies all root nodes.

    Returns:
        posList:   A list containing in tree order all
            the positions that satisfy the UNL.
            [] (empty list) --> No position satisfies the UNL

    """

    def appendList(lst, entry):
        lstNew = lst[:]
        lstNew.append(entry)
        return lstNew

    if unlList is None:
        return listRoots(cmdrUnl)
    soFarList = [[(childVnode, idx)] for idx, childVnode in
        enumerate(cmdrUnl.hiddenRootNode.children)]
    lastUnlIdx = len(unlList) - 1
    for idx1, hdl in enumerate(unlList):
        if idx1 == lastUnlIdx:
            soFarList = [stk for stk in soFarList if stk[-1][0].h == hdl]
        else:
            soFarList = [appendList(stk, (childVnode, idx2)) for stk
                in soFarList for idx2, childVnode
                in enumerate(stk[-1][0].children) if stk[-1][0].h == hdl]
        if not soFarList:
            return list()
    return [leoNodes.position(stk[-1][0], childIndex=stk[-1][1],
        stack=stk[:-1]) for stk in soFarList]