On Sat, 25 May 2013 05:00:46 -0700 (PDT)
Fidel Pérez <[email protected]> wrote:

> Hi:
> Im trying to make a button loop through all its siblings and make buttons 
> of them when their bodies have certain conditions. This way, when I 
> increase the tree, the button will auto-update with the new branches.
> 
> For that, I need to refer the actual button's sibilings, instead of the 
> "node which is selected" when i press the button. I need "p" of the node 
> when my position is in another node (to which I will have to refer too) so 
> I actually get an interaction among the sibilings tree and the position Im 
> currently in.

This question may have come up recently, here it is
https://groups.google.com/forum/?fromgroups#!topic/leo-editor/K90m_aIiz9k
last message in that thread.

Another way would be, if you were creating the button from a script, to
include a reference to the position in the command.

from leo.plugins.mod_scripting import scriptingController
sc = scriptingController(c)

def my_cmd(c=c, v=p.v):
    p = c.vnode2position(v)
    g.es("Created from "+p.h)

b = sc.createIconButton(
    'but',
    command = my_cmd,
    statusLine = 'Make buttons',
    bg="light_blue"
)

 - stores v, not p, p will break
 - create button by clicking run-script, or by making this a @script
   node
 - change its headline, click button again, new headline reported

And here's the really hacky version which knows not only the node it
came from but the button it's fired from:

from leo.plugins.mod_scripting import scriptingController
sc = scriptingController(c)
data = {'clicks':0}
def my_cmd(c=c, v=p.v, data=data):
    p = c.vnode2position(v)
    g.es("Created from "+p.h)
    data['clicks'] += 1
    data['b'].button.setText(str(data['clicks']))

b = sc.createIconButton(
    'zero',
    command = my_cmd,
    statusLine = 'Make buttons',
    bg="light_blue"
)
data['b'] = b

 - sc.createIconButton() returns a QWidgetAction, not a QPushButton,
   hence the '.button' part.
 - I guess this is a closure, with the surrounding @script node acting
   as the scope for the closure's data ('data').

Cheers -Terry

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