[PyQt] Passing image using SIP

2011-06-20 Thread Jarosław Białas

Hello,

I wanted to create code fragment that will pass an object containg image 
or pointer to this object from Python to C++ function.

I tried to create function:
void loadImage(QImage* image);
Then I created sip file, and after compiling and linking everything 
looks fine until I tried to import shared library in python:

ImportError: ./test.so: undefined symbol: _ZTI6QImage

I am open to any suggestion how to solve that problem.

Jaroslaw


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] PyQt Custom user types with QVariants and QMetaTypes

2011-06-20 Thread Justin Rosen
Hey all,

I've been struggling the past few days with trying to wrap my mind around
how PyQt has implemented QVariants and QMetaTypes.  In short I'm trying to
register/declare a custom user type that will be picked up by
QItemEditorFactory.

I've found a few postings related to the topic, but have been unable to get
a working example.  I'm using Qt 4.6.1 and PyQt 4.7.2 on Linux Red Hat
Enterprise 5.5

The FAQ clearly states that this is doable: "Can I store a python object
reference in a 
QVariant?"
And the original thread covering the issue in the FAQ: Construct QVariant
from object of user
type
.

I'm able to store a python object on a QVariant and get the object back, For
example the following class Triplet:
>>> class Triplet:
...def __init__(self):
...self.first, self.second, self.third = (-1, -1, -1)

>>> t = Triplet()
>>> tv = QtCore.QVariant(t)
>>> assert tv.toPyObject() is t
True

But I can't seem to derive the type/userType as being a Triplet.  Comes back
as PyQt_PyObject and UserType:
>>> tv.type()
127
>>> tv.typeName()
'PyQt_PyObject'
>>> tv.typeToName(tv.type())
'UserType'
>>> tv.userType()
260
>>> tv.typeToName(tv.userType())
'PyQt_PyObject'

What am I doing wrong?  The FAQ says that new python types are automatically
registered, but I keep getting the same PyObject type.
"The QVariant() ctor will now register new Python types automatically. I've
also wrapped QMetaType.type() and overloaded it so that you can pass a
Python type. I think this is enough for what you need."

In a previous post Matt Newell posted some code that achieves this, but I'm
assuming this has been superseded by integration with sip?:
>>> class A: pass
>>> metaTypeId = registerPythonQMetaType(A)
>>> print metaTypeId
424
>>> qv = qvariantFromPyObject(A())
>>> qv

>>> qv.userType()
424
>>> print qv.typeName()
A
>>> pyObjectFromQVariant(qv)
<__main__.A instance at 0xb65391ec>

Thanks, any help would be greatly appreciated!
Justin
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] sipConvertFromSliceObject() macro incompatible with Python 3.2

2011-06-20 Thread Arfrever Frehtes Taifersar Arahesis
2011-06-20 18:45:25 Arfrever Frehtes Taifersar Arahesis napisał(a):
> sipConvertFromSliceObject() macro is incompatible with Python 3.2.
> Please see comment #0 in:
> https://bugs.gentoo.org/show_bug.cgi?id=365549
> 
> The patch for SIP:
> https://365549.bugs.gentoo.org/attachment.cgi?id=271739

It might be appropriate to also update some code in siplib/voidptr.c.
I'm attaching updated patch.

-- 
Arfrever Frehtes Taifersar Arahesis
--- siplib/sip.h.in
+++ siplib/sip.h.in
@@ -1553,9 +1553,15 @@
 
 #define sipIsExactWrappedType(wt)   (sipTypeAsPyTypeObject((wt)->type) == (PyTypeObject *)(wt))
 
+#if PY_VERSION_HEX >= 0x0302
+#define sipConvertFromSliceObject(o,len,start,stop,step,slen) \
+PySlice_GetIndicesEx((o), (len), (start), (stop), \
+(step), (slen))
+#else
 #define sipConvertFromSliceObject(o,len,start,stop,step,slen) \
 PySlice_GetIndicesEx((PySliceObject *)(o), (len), (start), (stop), \
 (step), (slen))
+#endif
 
 
 /*
--- siplib/voidptr.c
+++ siplib/voidptr.c
@@ -429,7 +429,11 @@
 {
 Py_ssize_t start, stop, step, slicelength;
 
+#if PY_VERSION_HEX >= 0x0302
+if (PySlice_GetIndicesEx(key, v->size, &start, &stop, &step, &slicelength) < 0)
+#else
 if (PySlice_GetIndicesEx((PySliceObject *)key, v->size, &start, &stop, &step, &slicelength) < 0)
+#endif
 return NULL;
 
 if (step != 1)
@@ -486,7 +490,11 @@
 {
 Py_ssize_t stop, step;
 
+#if PY_VERSION_HEX >= 0x0302
+if (PySlice_GetIndicesEx(key, v->size, &start, &stop, &step, &size) < 0)
+#else
 if (PySlice_GetIndicesEx((PySliceObject *)key, v->size, &start, &stop, &step, &size) < 0)
+#endif
 return -1;
 
 if (step != 1)


signature.asc
Description: This is a digitally signed message part.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] sipConvertFromSliceObject() macro incompatible with Python 3.2

2011-06-20 Thread Arfrever Frehtes Taifersar Arahesis
sipConvertFromSliceObject() macro is incompatible with Python 3.2.
Please see comment #0 in:
https://bugs.gentoo.org/show_bug.cgi?id=365549

The patch for SIP:
https://365549.bugs.gentoo.org/attachment.cgi?id=271739

-- 
Arfrever Frehtes Taifersar Arahesis


signature.asc
Description: This is a digitally signed message part.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] Suggestion for wrapping std::tr1::shared_ptr<>

2011-06-20 Thread Shen, Guobao

Hi, Phil and everyone,
It is great to find this mailing list.
I am recently starting to use SIP to expose a C++ app, which makes heavy 
use of std::tr1::shared_ptr.

I hit some problems to wrap them in SIP. Here is my example:

class FooA;
typedef std::tr1::shared_ptr a_ptr;

class FooA : public std::tr1::enable_shared_from_this {
public:
typedef std::tr1::shared_ptr shared_pointer;
  ...
}

class FooB: {
public:
a_ptr method1(std::string name, a_ptr pointer) const;
...
}

How should I wrap them in SIP? Is there some code in PyQt that I can 
look at?


Thanks,

Guobao

--
Guobao Shen
Bldg. 902-B, 17 Cornell Avenue
National Synchrotron Light Source II
Brookhaven National Laboratory
Upton, New York 11973
Tel.: +1 (631) 344 7540
Fax.: +1 (631) 344 8085
http://www.bnl.gov/nsls2


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt