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()
[<class '__main__.CRhomb'>, <class 'qtcanvas.QCanvasPolygon'>, <class
'qtcanvas.QCanvasPolygonalItem'>, <class 'qtcanvas.QCanvasItem'>, <class
'qt.Qt'>, <type 'sip.wrapper'>, <class '__main__.Node'>, <type 'object'>]
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 3 1492
"Uwe Mayer" <me*****@hadiko.de> wrote in message
news:d9**********@news2.rz.uni-karlsruhe.de... 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() [<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.
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mike420 |
last post by:
In the context of LATEX, some Pythonista asked what the big
successes of Lisp were. I think there were at least three *big*
successes.
a. orbitz.com web site uses Lisp for algorithms, etc.
b....
|
by: Bart |
last post by:
Hi all
I don't understand globals between multiple modules in a python program. I
really don't. I've narrowed it down to the following two very simple
programs a.py and b.py. When I run a.py I...
|
by: Robert Nicholson |
last post by:
So I've got one page where I have an image inside a DIV with
text-align: center and the
image is correctly centered in that block. Making me think that
text-align will center the contents of a...
|
by: Jace Benson |
last post by:
Ok I have read alot of things on zend.com, php.net and other sites went
to the wikibooks to try to understand how to use a class. I have this
project I want to do that I am sure would work great...
|
by: =?Utf-8?B?Y2F0aGFyaW51cyB2YW4gZGVyIHdlcmY=?= |
last post by:
Hello,
I have build a website with approximately 30 html-pages.
When I search this website in Google, I see the index.html or home.html on
this website, but also other html-pages on this...
|
by: Jo |
last post by:
class A {
public:
char text_a;
A() { *text_a=0; }
~A() {}
};
//-----------------------------------------------------------------------------
|
by: jehugaleahsa |
last post by:
Hello:
I had an hour-long discussion with my boss today. Last night, right
before I dozed off, I realized some of his code resulted in duplicate
processing. I tried to explain it to him and he...
|
by: Ben Thomas |
last post by:
Hello,
I have the following code which I don't understand why it works :
#include <iostream>
using namespace std;
void DontWork (unsigned int& i) {
cout << i << endl;
}
|
by: Stef Mientki |
last post by:
Terry Reedy wrote:
sorry, don't know how this happened, as I always copy/paste ?
AFAIK locals() == sys._getframe(0).f_locals
AFAIK, again one level up
weird, I use it in 2.5 and if I remember...
|
by: Thierry |
last post by:
Hello fellow pythonists,
I'm a relatively new python developer, and I try to adjust my
understanding about "how things works" to python, but I have hit a
block, that I cannot understand.
I...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |