Using *@g.CommanderCommand* would probably be better, since once run it 
would be available to all outlines.

On Monday, October 31, 2022 at 1:05:53 PM UTC-4 Thomas Passin wrote:

> On Monday, October 31, 2022 at 11:12:14 AM UTC-4 jkn wrote:
>
>> Thanks, this looks very interesting...
>>
>> I have one question - something I have wondered about before. If I have 
>> your example code as a button command, say ... then where/how can I put the 
>>
>> def toggle_app_tab(log, tabname, top_widget):
>>     # ...
>>
>> code, in order for it to accessible by multiple such buttons/commands? 
>> I've never been sure about this.
>>
>> Thanks, J^n
>>
> [snip]
>
> For the function to be available to all outlines, I'm sure people have 
> various ideas.  One thing I've done in the past (with other functions) is 
> to assign it to some object.  I tend to use c, the outline's commander.  If 
> Edward ever changes it to use slots, I suppose this wouldn't work any 
> more.  Using this technique, your launch command would first look to see if 
> it has been assigned to c.  If not, it runs the def and assigns it.  Then 
> it would be invoked.  Something like this sketch -
>
> has_tabbed_app_toggle = hasattr(c, 'toggle_app_tab')
> if not has_tabbed_app_toggle:
>     def toggle_app_tab(log, tabname, top_widget):
>           # Body of function here
>     c.toggle_app_tab = toggle_app_tab
>
> # Invoke function here
>
> You can even make the function into a method of c.  Other people may do 
> that differently, but I think the easiest way is 
>
> c.has_tabbed_app_toggle = has_tabbed_app_toggle.__get__(c)
>
> If you did this, you would need to change the function to include *self*, 
> and you would need to use *self* instead of *c* in the code.
>
> There is also a Leo decorator, *g.CommanderCommand*, that you could use 
> (it would have to be run first before the function could be used, and your 
> function cannot use "g"):
>
> @g.CommanderCommand('z-f1')
> def z_f1(self, x, y):
>     print(x * y)
>
> Then:
> c.z_f1(2, 3)
> # prints 6
>
> (It seems to me that there was something recently about not using this 
> decorator, but I can't remember for sure).
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/799df4f2-a43f-442c-a1eb-267972c10b04n%40googlegroups.com.

Reply via email to