On Fri, Sep 20, 2013 at 2:42 AM, Fidel N <fidelpe...@gmail.com> wrote:
> > >> def MyFunction(string): >> g.es(string) >> c.MyFunction=MyFunction #We store the function in c >> c.MyFunction("this works") > > Good trick. However, it pollutes the namespace of class Commands. Take a look at the tree:: @file leoCommands.py-->class Commands--> c.Birth & death-->c.__init__ & helpers You will see that there is a significant chance of a collision with essential ivars of the Commands class. Your scripts can avoid this pollution as follows (Tested code):: def MyFunction(s): g.es(s) d = g.app.permanentScriptDict key = 'temp functions' d2 = d.get(key,{}) d2['myFunction'] = MyFunction # Later... f = d2.get('myFunction') f('This works') Not as clean as your solution, but *much* safer. If you do use the unsafe way, I suggest starting all "injected" functions with a common prefix, like perez. I always append 'leo_' to any ivars injected into Qt classes. Or just use c.k.registerCommand ;-) Edward -- 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 leo-editor+unsubscr...@googlegroups.com. To post to this group, send email to leo-editor@googlegroups.com. Visit this group at http://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/groups/opt_out.