Re: don't understand MRO

2005-06-24 Thread Martin Franklin
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
> 
> 
> 
> 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:
> 
> [, ,  'qtcanvas.QCanvasPolygonalItem'>, ,  'qt.Qt'>, , , ]
> Node: move(1,2)
> 
> Ciao
> Uwe
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: don't understand MRO

2005-06-23 Thread 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
 print qtcanvas.QCanvasItem.move # ?
> If so, I would need to see its code to try to answer.

>>> import qtcanvas
>>> qtcanvas.QCanvasItem.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:

[, , , , , , , ]
Node: move(1,2)

Ciao
Uwe

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: don't understand MRO

2005-06-23 Thread Terry Reedy

"Uwe Mayer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> I have a subclassed PyQt class:
>
> class Node(object):
>def move(self, x,y): pass
>
> class CRhomb(QCanvasPolygon, Node): pass
>
> $ python
> v2.4.1
 CRhomb.mro()
> [, ,  'qtcanvas.QCanvasPolygonalItem'>, ,  'qt.Qt'>, , , ]

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.

>
 a = CRhomb()
 a.move(1,2)
>
> 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 from
>>> print qtcanvas.QCanvasItem.move # ?
If so, I would need to see its code to try to answer.

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


don't understand MRO

2005-06-23 Thread 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
>>> CRhomb.mro()
[, , , , , , , ]

>>> a = CRhomb()
>>> a.move(1,2)

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 
-- 
http://mail.python.org/mailman/listinfo/python-list