On Sat, 30 Jan 2010 19:21:06 +0200
"Ville M. Vainio" <[email protected]> wrote:

> For the magic, check out:
> 
> Plugins-->Commands & directives-->@thin quickMove.py-->class quickMove

+        # func = types.MethodType(func, None, quickMove)
+        func = types.MethodType(func, quickMove)

Seems Edward didn't believe in my magic :-) - trouble with magic is it doesn't 
work when you don't believe.  Anyway, I put the None back in and it works again 
now.

This is nuts, I just spent 10 minutes looking for docs. on the parameters of 
types.MethodType, and can't find them.  Anyway, they're the same as 
instancemethod(function, instance, class) in the depreciated 'new' module.

I should have commented the magic part better, my bad.

For anyone wondering, quickMove.py supports 11 similar ways of creating buttons 
to move nodes to other nodes, and rather than have 11 stub methods of the form:

def moveToFirstChild(...):  doSomething(self.target, type_='move', first=True)
def moveToLastChild(...):   doSomething(self.target, type_='move', first=False)
def copyToFirstChild(...):  doSomething(self.target, type_='copy', first=True)
def copyToLastChild(...):   doSomething(self.target, type_='copy', first=False)
def cloneToFirstChild(...): doSomething(self.target, type_='clone', first=True)
def cloneToLastChild(...):  doSomething(self.target, type_='clone', first=False)

I went with a short loop on a table to add the methods to the class 
dynamically.  Bottom line, the repetition is probably the better approach, but 
the dynamic method creation was partly to test my knowledge as much as solve 
the problem.  And it works fine, apart from being obscure and therefore running 
the risk of being accidentally broken, as happened.

Cheers -Terry

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to