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

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']))
>     data['b'].parent().remove(data['b'])
>     data['b'].button.parent().remove(data['b'])
>     data['b'].button.parent().button.remove()
>     data['b'].parent().remove(data['b'])
>     data['b'].remove()
> b = sc.createIconButton( 
>     'zero', 
>     command = my_cmd, 
>     statusLine = 'Make buttons', 
>     bg="ligt_blue" 
> ) 
> data['b'] = b 


And none of them will erase the button.

On your answer I understand that:

> data['other_buttons'] will be a global variable (will be accessed from 
> other buttons scripts).

To add the newly created buttons to that, would this be the code?

> b=sc.createiconbutton(...)
> data['other buttons']=data['other buttons'].append(b)


Last but least important, the value

> bg="ligt_blue"

 Will not change the button color. Since im building this for an 
interactive Leo tutorial, I would say colors are important since they will 
make more visual (and easier to learn, since I will use same colors for 
same command types) for the new user.

Again very thankful, Im really eager to finish this and get to know your 
oppinions on this tutorial =)



On Sunday, May 26, 2013 3:53:35 PM UTC+2, Fidel Pérez wrote:
>
> Thank you very much Terry, it was very useful information, will be working 
> on it the next weeks and like always keep my conclusions on the Leo 
> interactive tutorial I am preparing.
>
> On Sunday, May 26, 2013 4:51:13 AM UTC+2, Terry wrote:
>>
>> 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