aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtGui/glue/wid_conversions.h
blob: 183e682fe63a60072f12c61030fc9d70e3173c1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef Q_WS_WIN

namespace Shiboken {
template <>
struct Converter<WId>
{
    static bool checkType(PyObject* pyObj)
    {
        return false;
    }

    static bool isConvertible(PyObject* pyobj)
    {
        if (pyobj == Py_None)
            return true;

#ifdef IS_PY3K
        return PyCapsule_CheckExact(pyobj);
#else
        return PyCObject_Check(pyobj);
#endif
    }

    static inline PyObject* toPython(void* cppobj)
    {
        // not supported
        Q_ASSERT(true);
        return 0;
    }

    static PyObject* toPython(WId cppobj)
    {
        if (!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)
    {
        if (pyobj == Py_None)
            return 0;

#ifdef IS_PY3K
        return (WId)PyCapsule_GetPointer(pyobj, 0);
#else
        return (WId)PyCObject_AsVoidPtr(pyobj);
#endif
    }
};

}

#endif