don't understand MRO

U

Uwe Mayer

Hi,

I have a subclassed PyQt class:

class Node(object):
def move(self, x,y): pass

class CRhomb(QCanvasPolygon, Node): pass

$ python
v2.4.1[<class '__main__.CRhomb'>, <class 'qtcanvas.QCanvasPolygon'>, <class

This executes also Node.move(a, 1,2)
Why?

Because even QCanvasItem.move delegates the call to the derived object? But
qt.Qt does not have a move() method... how does it get passed on to Node?

Thanks in advance,
Ciao
Uwe
 
T

Terry Reedy

Uwe Mayer said:
I have a subclassed PyQt class:

class Node(object):
def move(self, x,y): pass

class CRhomb(QCanvasPolygon, Node): pass

$ python
v2.4.1[<class '__main__.CRhomb'>, <class 'qtcanvas.QCanvasPolygon'>, <class
'qtcanvas.QCanvasPolygonalItem'>, <class 'qtcanvas.QCanvasItem'>, <class
'qt.Qt'>, <type 'sip.wrapper'>, <class '__main__.Node'>, <type 'object'>]

For those who don't know, 'mro' stands for 'method resolution order'. The
method returns a list of classes (all except the first are base or super
classes of the first) in the order in which their dictionaries are searched
for method (or other attribute) names.
This executes also Node.move(a, 1,2)
Why?

In the absence of other information, I would presume that none of the other
classes have a move() method.
Because even QCanvasItem.move delegates the call to the derived object?
But
qt.Qt does not have a move() method... how does it get passed on to Node?

Are you sure that QCanvasItem has a move method? What results fromIf so, I would need to see its code to try to answer.

Terry J. Reedy
 
U

Uwe Mayer

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
If so, I would need to see its code to try to answer.
<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
 
M

Martin Franklin

Uwe said:
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


If so, I would need to see its code to try to answer.

<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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top