Ok, I haven't fixed the Qt version yet, but I have the tk version
working well. I thought I'd post it for others.

Place this code into a Leo node with "following sibling" nodes, and
execute it (Ctrl-B).
On the button bar that is created:
    Left click a button to hoist the node associated with that button.
    Right click on the buttons to remove them.


@
This script will create a hoist button bar with buttons for every
sibling node that follows this script node
@c

from mod_scripting import scriptingController

class myScriptingController(scriptingController):
    def deleteButton(self,button,**kw):

        """Delete the given button.
        This is called from callbacks, it is not a callback."""

        w = button

        if button and self.buttonsDict.get(w):
            del self.buttonsDict[w]
            self.iconBar.deleteButton(w)
            self.c.bodyWantsFocusNow()
        w.master.iconBarButtonCount -= 1
        if w.master.iconBarButtonCount == 0:
            w.master.destroy()

def makeiIconBarButton(node):
    text = node.headString()
    statusLine = "Hoist %s" % text
    def hoistButtonCallback (event=None,c=c,p=node.copy()):
        while (c.canDehoist()):
            c.dehoist()
        c.selectPosition(p)
        c.hoist()
    b = sc.createIconButton(text=text,
                            command=hoistButtonCallback,
                            shortcut=None,
                            statusLine=statusLine,
                            bg='yellow')
    g.app.iconWidgetCount -= 1
    return b

sc = myScriptingController(c)

originalFrame = sc.iconBar.iconFrame
sc.iconBar.addRow()
sc.iconBar.iconFrame.iconBarButtonCount = 0

for node in p.following_siblings_iter():
    b = makeiIconBarButton(node)
    sc.iconBar.iconFrame.iconBarButtonCount += 1

sc.iconBar.iconFrame = originalFrame
c.frame.iconFrame = originalFrame

-- 
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