On Mon, 27 May 2013 01:01:37 -0700 (PDT)
Fidel Pérez <[email protected]> wrote:

> The first problem im encountering is that the command wont erase the 
> button!! hehe... This is what I have tried so far:

Here's a working example just playing around - not sure exactly what
you're trying to do, but this creates a master button, which, when
clicked (and when first created) creates script-button buttons for all
its siblings.  It refreshes these, deletes and replaces any that already
existed, when clicked.

Cheers -Terry

--- cut here ---
from leo.plugins.mod_scripting import scriptingController
sc = scriptingController(c)
data = {'clicks':0, 'sc': sc, 'our_buttons': []}
def my_cmd(c=c, v=p.v, data=data):
    p = c.vnode2position(v)
    g.es("Created from "+p.h)
    data['clicks'] += 1
    toolbar = data['b'].parent()
    
    # get list of our buttons that are still on the toolbar, not removed by user
    culls = [i for i in toolbar.actions() if i in data['our_buttons']]

    for other in culls:
        toolbar.removeAction(other)

    data['our_buttons'] = []

    existing = list(toolbar.actions())

    current_pos = c.p.copy()

    for nd in p.self_and_siblings():
        if nd == p:
            continue
            
        c.selectPosition(nd)
        data['sc'].addScriptButtonCommand()
        
    c.selectPosition(current_pos)

    # record list of buttons we added
    data['our_buttons'] = [i for i in toolbar.actions() if i not in existing]
        
b = sc.createIconButton(
    'Master',
    command = my_cmd,
    statusLine = 'Make buttons',
    bg="light_blue"
)
data['b'] = b
my_cmd()  # to create master button
--- cut here ---

-- 
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?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to