]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/ogl/oglhelpers.cpp
added font encoding support
[wxWidgets.git] / utils / wxPython / modules / ogl / oglhelpers.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: oglhelpers.cpp
3 // Purpose: Some Helper functions to help in data conversions in OGL
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 3-Sept-1999
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 #include <Python.h>
14 #include "helpers.h"
15
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.
19
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);
25 return NULL;
26 }
27 int count = PyList_Size(pyList);
28 wxList* list = new wxList;
29 if (! list) {
30 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
31 wxPySaveThread(doSave);
32 return NULL;
33 }
34 for (int x=0; x<count; x++) {
35 PyObject* pyo = PyList_GetItem(pyList, x);
36 wxObject* wxo = NULL;
37
38 if (SWIG_GetPtrObj(pyo, (void **)&wxo, className)) {
39 char errmsg[1024];
40 sprintf(errmsg, "Type error, expected list of %s objects", className);
41 PyErr_SetString(PyExc_TypeError, errmsg);
42 wxPySaveThread(doSave);
43 return NULL;
44 }
45 list->Append(wxo);
46 }
47 wxPySaveThread(doSave);
48 return list;
49 }
50
51 //---------------------------------------------------------------------------
52
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);
58 return NULL;
59 }
60 int count = PyList_Size(pyList);
61 wxList* list = new wxList;
62 if (! list) {
63 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
64 wxPySaveThread(doSave);
65 return NULL;
66 }
67 for (int x=0; x<count; x++) {
68 PyObject* pyo = PyList_GetItem(pyList, x);
69
70 if (PyTuple_Check(pyo)) {
71 PyObject* o1 = PyNumber_Float(PyTuple_GetItem(pyo, 0));
72 PyObject* o2 = PyNumber_Float(PyTuple_GetItem(pyo, 1));
73
74 double val1 = (o1 ? PyFloat_AsDouble(o1) : 0.0);
75 double val2 = (o2 ? PyFloat_AsDouble(o2) : 0.0);
76
77 list->Append((wxObject*) new wxRealPoint(val1, val2));
78
79 } else {
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);
84 return NULL;
85 }
86 list->Append((wxObject*) new wxRealPoint(*wxo));
87 }
88 }
89 wxPySaveThread(doSave);
90 return list;
91 }
92
93
94 //---------------------------------------------------------------------------
95
96
97
98
99
100
101
102
103