]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/my_fragments.i
Use dummy class on Mac until wxEventLoop is implemented there
[wxWidgets.git] / wxPython / src / my_fragments.i
1 // There is a bug in the standard t_output_helper, this one will replace it
2 // until it is fixed.
3
4
5 %fragment("t_output_helper","header") %{
6 static PyObject* t_output_helper(PyObject* target, PyObject* o) {
7 PyObject* o2;
8 PyObject* o3;
9
10 if (!target) {
11 target = o;
12 } else if (target == Py_None) {
13 Py_DECREF(Py_None);
14 target = o;
15 } else {
16 if (!PyTuple_Check(target)) {
17 o2 = target;
18 target = PyTuple_New(1);
19 PyTuple_SetItem(target, 0, o2);
20 }
21 o3 = PyTuple_New(1);
22 PyTuple_SetItem(o3, 0, o);
23
24 o2 = target;
25 target = PySequence_Concat(o2, o3);
26 Py_DECREF(o2);
27 Py_DECREF(o3);
28 }
29 return target;
30 }
31 %}
32
33
34
35 // These fragments are inserted in modules that need to convert PyObjects to
36 // integer values, my versions allow any numeric type to be used, as long as
37 // it can be converted to a PyInt. (Specifically, I allow floats where the
38 // default SWIG_AsVal_long would just raise an exception.
39 //
40 // NOTE: This file has to be %included very early in the SWIGging process as
41 // it no longer allows existing fragments to be replaced with one of the same
42 // name. So to make this work I had to bring a copy of python.swg into this
43 // project and do the %include there before most other of the standard swiglib
44 // files are %included. This may change in 1.3.23, so adjust accordingly then.
45
46
47
48 %fragment(SWIG_AsVal_frag(long), "header") {
49 // See my_fragments.i
50 SWIGSTATICINLINE(int)
51 SWIG_AsVal(long)(PyObject* obj, long* val)
52 {
53 if (PyNumber_Check(obj)) {
54 if (val) *val = PyInt_AsLong(obj);
55 return 1;
56 }
57 else {
58 PyObject* errmsg = PyString_FromFormat("Expected number, got %s",
59 obj->ob_type->tp_name);
60 PyErr_SetObject(PyExc_TypeError, errmsg);
61 Py_DECREF(errmsg);
62 }
63 return 0;
64 }
65 }
66
67
68 %fragment(SWIG_AsVal_frag(unsigned long), "header",
69 fragment=SWIG_AsVal_frag(long)) {
70 // See my_fragments.i
71 SWIGSTATICINLINE(int)
72 SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val)
73 {
74 long v = 0;
75 if (SWIG_AsVal_long(obj, &v) && v < 0) {
76 PyErr_SetString(PyExc_TypeError, "negative value received for unsigned type");
77 return 0;
78 }
79 else if (val)
80 *val = (unsigned long)v;
81 return 1;
82 }
83 }
84
85
86 %fragment(SWIG_AsVal_frag(double), "header") {
87 // See my_fragments.i
88 SWIGSTATICINLINE(int)
89 SWIG_AsVal(double)(PyObject *obj, double* val)
90 {
91 if (PyNumber_Check(obj)) {
92 if (val) *val = PyFloat_AsDouble(obj);
93 return 1;
94 }
95 else {
96 PyObject* errmsg = PyString_FromFormat("Expected number, got %s",
97 obj->ob_type->tp_name);
98 PyErr_SetObject(PyExc_TypeError, errmsg);
99 Py_DECREF(errmsg);
100 }
101 return 0;
102 }
103 }