On Sun, 6 Jul 2014 14:16:18 -0700 (PDT)
Fidel N <fidelpe...@gmail.com> wrote:

> Thank you both. Already tried both ways; And failed but already very
> close.
> 
> Edward, how is Leo supposed to know that my "leopyref.leo" file now
> will be leopy.leo? Where do I have to tell Leo to search for leopy
> instead of leopyref?
> 
> 
> Terry, I like your solution very much, but my lack of python
> knowledge let me on the edge here.
> It was already "fun" enough to reach the class and the function
> itself:
> 
> c.frame.tree.treeWidget.urlDrop
> 
> But when I replace that function with my (actually working in Leo)
> one, it throws this error:
> http://i.imgur.com/5ZvRFJ5.png
> I know I reached the one I wanted because in other windows, where I
> didnt replace it, it works as usual.

I'm guessing you left out my lambda: part.  Maybe this is a better way
to do it:

    import types
    class LeoInternalClass:
        def seven(self, x):
            print(7,x)
    
    lic1 = LeoInternalClass()
    lic2 = LeoInternalClass()
    
    print("pre-patch")
    lic1.seven('1')
    lic2.seven('2')
    
    def new_seven(self,x):
        print("seven",x)
    
    # patch the class
    LeoInternalClass.seven = new_seven
    
    print("\nPatch class and lic2 instance")
    
    # and patch the object (normally do only one)
    
    # either lic2.seven = lambda x, self=lic2: new_seven(self, x)
    # or, without futzing with arguments
    lic2.seven = types.MethodType(new_seven, lic2)
    
    lic3 = LeoInternalClass()
    
    lic1.seven('1')
    lic2.seven('2')
    lic3.seven('3')
    
    def newer_seven(self,x):
        print("3+4",x)
    
    LeoInternalClass.seven = newer_seven
    
    lic4 = LeoInternalClass()
    
    print("\nPatch class again")
    lic1.seven('1')
    lic2.seven('2')
    lic3.seven('3')
    lic4.seven('4')

types.MethodType() is much cleaner than that lambda thing.

Cheers -Terry

> Thanks again!
> 

-- 
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/d/optout.

Reply via email to