don't understand MRO

Uwe Mayer merkosh at hadiko.de
Thu Jun 23 14:28:05 EDT 2005


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();
    }
}
-- 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