don't understand MRO

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Fri Jun 24 05:53:50 EDT 2005


Uwe Mayer wrote:
> Thursday 23 June 2005 19:22 pm Terry Reedy wrote:
> 
> [...]
> 
>>In the absence of other information, I would presume that none of the
>>other classes have a move() method.
> 
> 
> move() is implemented in the class qtcanvas.QCanvasItem
> I checked the pyqt sources and it is linked via sip to the C++ object file.
> In C++, QCanvasItem.move is delegated to QCanvasItem.moveBy. 
> 
> -- snip: C++ sources --
> void QCanvasItem::move( double x, double y ){
>     moveBy( x-myx, y-myy );
> }
> 
> void QCanvasItem::moveBy( double dx, double dy ){
>     if ( dx || dy ) {
>         removeFromChunks();
>         myx += dx;
>         myy += dy;
>         addToChunks();
>     }
> }

I wonder if it is to do with the signature of these methods.  they
accept two doubles and perhaps the python bindings do not automatically
convert from integers, therefore these methods are not called and the
rules of mro kick in (thus calling the python move method)





> -- snip --
> 
> 
>>Are you sure that QCanvasItem has a move method?  What results from
>>
>>>>>print qtcanvas.QCanvasItem.move # ?
>>
>>If so, I would need to see its code to try to answer.
> 
> 
>>>>import qtcanvas
>>>>qtcanvas.QCanvasItem.move
> 
> <built-in function move>
> 
> Here is a working portion which recreates the strange output:
> 
> -- snip --
> from qtcanvas import *
> 
> class Node(object):
>     def move(self, x,y):
>         print "Node: move(%d,%d)"%(x,y)
> 
> class Rhomb(QCanvasPolygon, Node):
>     def __init__(self, parent):
>         QCanvasPolygon.__init__(self, parent)
>         Node.__init__(self)
> 
> print Rhomb.mro()
> r = Rhomb(None)
> r.move(1,2)
> -- snip --
> 
> This prints:
> 
> [<class '__main__.Rhomb'>, <class 'qtcanvas.QCanvasPolygon'>, <class
> 'qtcanvas.QCanvasPolygonalItem'>, <class 'qtcanvas.QCanvasItem'>, <class
> 'qt.Qt'>, <type 'sip.wrapper'>, <class '__main__.Node'>, <type 'object'>]
> Node: move(1,2)
> 
> Ciao
> Uwe
> 




More information about the Python-list mailing list