]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/pyfragments.swg
log wxChoice events in the same format as wxComboBox ones to make it simpler to compa...
[wxWidgets.git] / wxPython / src / pyfragments.swg
CommitLineData
1b8c7ba6
RD
1
2
214c4fbe
RD
3//----------------------------------------------------------------------
4
5// The standard t_output_helper has been changed to return a list rather than
6// a tuple, we'll replace it with the old implementation here. In SWIG 1.3.27
7// and earlier it is implemented as a $fragment, so it is only inserted in to
8// the modules that need it. For SWIG 1.3.28 we just need to add a -D on the
9// compile command line to turn on this version of the AppendOuput function.
10#if SWIG_VERSION < 0x010328
11%fragment("t_output_helper","header")
12%{
13 static PyObject* t_output_helper(PyObject* result, PyObject* obj)
14 {
15 PyObject* o2;
16 PyObject* o3;
17 if (!result) {
18 result = obj;
19 } else if (result == Py_None) {
20 Py_DECREF(result);
21 result = obj;
22 } else {
23 if (!PyTuple_Check(result)) {
24 o2 = result;
25 result = PyTuple_New(1);
26 PyTuple_SET_ITEM(result, 0, o2);
27 }
28 o3 = PyTuple_New(1);
29 PyTuple_SetItem(o3, 0, obj);
30 o2 = result;
31 result = PySequence_Concat(o2, o3);
32 Py_DECREF(o2);
33 Py_DECREF(o3);
34 }
35 return result;
80739955 36 }
80739955
RD
37%}
38
214c4fbe
RD
39#endif
40
41
80739955
RD
42
43
214c4fbe 44//----------------------------------------------------------------------
0190c472
RD
45// These fragments are inserted in modules that need to convert PyObjects to
46// integer values, my versions allow any numeric type to be used, as long as
47// it can be converted to a PyInt. (Specifically, I allow floats where the
48// default SWIG_AsVal_long would just raise an exception.
49//
0190c472 50
214c4fbe 51#if SWIG_VERSION < 0x010328
0190c472
RD
52
53%fragment(SWIG_AsVal_frag(long), "header") {
1b8c7ba6 54SWIGINTERN int
0190c472
RD
55SWIG_AsVal(long)(PyObject* obj, long* val)
56{
57 if (PyNumber_Check(obj)) {
58 if (val) *val = PyInt_AsLong(obj);
59 return 1;
60 }
61 else {
214c4fbe 62 SWIG_Python_TypeError("number", obj);
0190c472
RD
63 }
64 return 0;
65}
66}
67
68
69%fragment(SWIG_AsVal_frag(unsigned long), "header",
70 fragment=SWIG_AsVal_frag(long)) {
1b8c7ba6 71SWIGINTERN int
0190c472
RD
72SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val)
73{
74 long v = 0;
75 if (SWIG_AsVal_long(obj, &v) && v < 0) {
214c4fbe 76 SWIG_Python_TypeError("unsigned number", obj);
0190c472
RD
77 }
78 else if (val)
79 *val = (unsigned long)v;
80 return 1;
81}
82}
83
84
85%fragment(SWIG_AsVal_frag(double), "header") {
1b8c7ba6 86SWIGINTERN int
0190c472
RD
87SWIG_AsVal(double)(PyObject *obj, double* val)
88{
89 if (PyNumber_Check(obj)) {
90 if (val) *val = PyFloat_AsDouble(obj);
91 return 1;
92 }
93 else {
214c4fbe 94 SWIG_Python_TypeError("number", obj);
0190c472
RD
95 }
96 return 0;
97}
98}
214c4fbe
RD
99
100
101#else // SWIG_VERSION >= 1.3.28
102
103%fragment(SWIG_AsVal_frag(long), "header") {
104SWIGINTERN int
105SWIG_AsVal(long)(PyObject* obj, long* val)
106{
107 if (PyNumber_Check(obj)) {
108 if (val) *val = PyInt_AsLong(obj);
109 return SWIG_OK;
110 }
111 return SWIG_TypeError;
112}
113}
114
115
116%fragment(SWIG_AsVal_frag(unsigned long), "header",
117 fragment=SWIG_AsVal_frag(long)) {
118SWIGINTERN int
119SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val)
120{
121 long v = 0;
122 if (SWIG_AsVal_long(obj, &v) && v < 0) {
123 return SWIG_TypeError;
124 }
125 else if (val)
126 *val = (unsigned long)v;
127 return SWIG_OK;
128}
129}
130
131
132%fragment(SWIG_AsVal_frag(double), "header") {
133SWIGINTERN int
134SWIG_AsVal(double)(PyObject *obj, double* val)
135{
136 if (PyNumber_Check(obj)) {
137 if (val) *val = PyFloat_AsDouble(obj);
138 return SWIG_OK;
139 }
140 return SWIG_TypeError;
141}
142}
143
144
145#endif // SWIG_VERSION