]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/ogl/oglhelpers.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: oglhelpers.cpp
3 // Purpose: Some Helper functions to help in data conversions in OGL
7 // Created: 3-Sept-1999
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
17 // This one will work for any class for the VERY generic cases, but beyond that
18 // the helper needs to know more about the type.
20 wxList
* wxPy_wxListHelper(PyObject
* pyList
, char* className
) {
21 bool doSave
= wxPyRestoreThread();
22 if (!PyList_Check(pyList
)) {
23 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
24 wxPySaveThread(doSave
);
27 int count
= PyList_Size(pyList
);
28 wxList
* list
= new wxList
;
30 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate wxList object");
31 wxPySaveThread(doSave
);
34 for (int x
=0; x
<count
; x
++) {
35 PyObject
* pyo
= PyList_GetItem(pyList
, x
);
38 if (SWIG_GetPtrObj(pyo
, (void **)&wxo
, className
)) {
40 sprintf(errmsg
, "Type error, expected list of %s objects", className
);
41 PyErr_SetString(PyExc_TypeError
, errmsg
);
42 wxPySaveThread(doSave
);
47 wxPySaveThread(doSave
);
51 //---------------------------------------------------------------------------
53 wxList
* wxPy_wxRealPoint_ListHelper(PyObject
* pyList
) {
54 bool doSave
= wxPyRestoreThread();
55 if (!PyList_Check(pyList
)) {
56 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
57 wxPySaveThread(doSave
);
60 int count
= PyList_Size(pyList
);
61 wxList
* list
= new wxList
;
63 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate wxList object");
64 wxPySaveThread(doSave
);
67 for (int x
=0; x
<count
; x
++) {
68 PyObject
* pyo
= PyList_GetItem(pyList
, x
);
70 if (PyTuple_Check(pyo
)) {
71 PyObject
* o1
= PyNumber_Float(PyTuple_GetItem(pyo
, 0));
72 PyObject
* o2
= PyNumber_Float(PyTuple_GetItem(pyo
, 1));
74 double val1
= (o1
? PyFloat_AsDouble(o1
) : 0.0);
75 double val2
= (o2
? PyFloat_AsDouble(o2
) : 0.0);
77 list
->Append((wxObject
*) new wxRealPoint(val1
, val2
));
80 wxRealPoint
* wxo
= NULL
;
81 if (SWIG_GetPtrObj(pyo
, (void **)&wxo
, "_wxRealPoint_p")) {
82 PyErr_SetString(PyExc_TypeError
, "Type error, expected list of wxRealPoint objects or 2-tuples");
83 wxPySaveThread(doSave
);
86 list
->Append((wxObject
*) new wxRealPoint(*wxo
));
89 wxPySaveThread(doSave
);
94 //---------------------------------------------------------------------------