Fix bug 1083 - "winId returns a PyCObject making it impossible to compare two winIds"

This commit is contained in:
Hugo Parente Lima 2011-12-09 11:21:38 -02:00
commit 93bb5d777e
2 changed files with 4 additions and 23 deletions

View file

@ -11,14 +11,7 @@ struct Converter<WId>
static bool isConvertible(PyObject* pyobj) static bool isConvertible(PyObject* pyobj)
{ {
if (pyobj == Py_None) return pyobj == Py_None || PyNumber_Check(pyobj);
return true;
#ifdef IS_PY3K
return PyCapsule_CheckExact(pyobj);
#else
return PyCObject_Check(pyobj);
#endif
} }
static inline PyObject* toPython(void* cppobj) static inline PyObject* toPython(void* cppobj)
@ -30,26 +23,14 @@ struct Converter<WId>
static PyObject* toPython(WId cppobj) static PyObject* toPython(WId cppobj)
{ {
if (!cppobj) return PyLong_FromVoidPtr((void*)cppobj);
Py_RETURN_NONE;
#ifdef IS_PY3K
return PyCapsule_New(cppobj, 0, 0);
#else
return PyCObject_FromVoidPtr(cppobj, 0);
#endif
} }
static WId toCpp(PyObject* pyobj) static WId toCpp(PyObject* pyobj)
{ {
if (pyobj == Py_None) if (pyobj == Py_None)
return 0; return 0;
return (WId)PyLong_AsVoidPtr(pyobj);
#ifdef IS_PY3K
return (WId)PyCapsule_GetPointer(pyobj, 0);
#else
return (WId)PyCObject_AsVoidPtr(pyobj);
#endif
} }
}; };

View file

@ -4245,7 +4245,7 @@
If a widget is non-native (alien) and winId() is invoked on it, that widget will be provided a native handle. If a widget is non-native (alien) and winId() is invoked on it, that widget will be provided a native handle.
On X11 the type returned is long, on other platforms it's a PyCObject. On X11 the type returned is long, on other platforms it's void pointer casted to a Python long long.
This value may change at run-time. An event with type PySide.QtCore.QEvent.WinIdChange will be sent to the widget following a change in window system identifier. This value may change at run-time. An event with type PySide.QtCore.QEvent.WinIdChange will be sent to the widget following a change in window system identifier.
</inject-documentation> </inject-documentation>