On Sat, 25 May 2013 08:56:03 -0700 (PDT)
Fidel Pérez <[email protected]> wrote:

> Im really sorry to need so much help, but could you please show me the code 
> to remove a created button from another button?
> How to access the "button list" to be able to remove it from an "external" 
> script? Where did you get the .button.settext command? There is no such 
> definition in LeoPlugins...
> Thanks Terry

No problem - what you're trying to do isn't supported by the API as
designed, so you have to use the versatility of Python to sneak around
behind its back.

class leoIconBarButton is defined in
.../leo/core/LeoPyRef.leo#Code-->Qt
gui-->@file ../plugins/qtGui.py-->Frame and component classes...-->class 
leoQtFrame-->class qtIconBarClass-->add (qtIconBarClass)

and descends from QtGui.QWidgetAction.  Code following the class
definition assigns the button ivar, it's a QPushButton, hence
the .setText().

So in the second version, the one using the data dict, you have the
leoIconBarButton injected into the scope of the button command, data['b'].  
data['b'].parent() is the QToolBar containing all buttons, so you could
iterate the buttons that way, but I'm guessing your purpose could use a
"master" button which create and destroys the other.  Removing can be
as data['b'].parent().remove(data['b']), removes itself, or perhaps

for i in data['other_buttons']:
    data['b'].parent().remove(i)
data['other_buttons'] = []

The commands bound to the secondary buttons could have the same data
dict in their closure the same way, so all the buttons could know of
each other.

Let me know if you need something more specific.

Cheers -Terry

> On Saturday, May 25, 2013 4:58:11 PM UTC+2, Fidel Pérez wrote:
> >
> > Very much appreciated, got more homework to study :)
> >
> > On Saturday, May 25, 2013 4:53:34 PM UTC+2, Terry wrote:
> >>
> >> 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