]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/pyfragments.swg
Applied patch #1181805 TextEditMixin and EVT_LIST_END_LABEL_EDIT
[wxWidgets.git] / wxPython / src / pyfragments.swg
1
2
3 // There standard t_output_helper has been changed to return a list rather
4 // than a tuple, we'll replace it with the old implementation here.
5
6
7 %fragment("t_output_helper","header") %{
8 static PyObject* t_output_helper(PyObject* target, PyObject* o) {
9 PyObject* o2;
10 PyObject* o3;
11
12 if (!target) {
13 target = o;
14 } else if (target == Py_None) {
15 Py_DECREF(Py_None);
16 target = o;
17 } else {
18 if (!PyTuple_Check(target)) {
19 o2 = target;
20 target = PyTuple_New(1);
21 PyTuple_SetItem(target, 0, o2);
22 }
23 o3 = PyTuple_New(1);
24 PyTuple_SetItem(o3, 0, o);
25
26 o2 = target;
27 target = PySequence_Concat(o2, o3);
28 Py_DECREF(o2);
29 Py_DECREF(o3);
30 }
31 return target;
32 }
33 %}
34
35
36
37 // These fragments are inserted in modules that need to convert PyObjects to
38 // integer values, my versions allow any numeric type to be used, as long as
39 // it can be converted to a PyInt. (Specifically, I allow floats where the
40 // default SWIG_AsVal_long would just raise an exception.
41 //
42
43
44 %fragment(SWIG_AsVal_frag(long), "header") {
45 SWIGINTERN int
46 SWIG_AsVal(long)(PyObject* obj, long* val)
47 {
48 if (PyNumber_Check(obj)) {
49 if (val) *val = PyInt_AsLong(obj);
50 return 1;
51 }
52 else {
53 SWIG_type_error("number", obj);
54 }
55 return 0;
56 }
57 }
58
59
60 %fragment(SWIG_AsVal_frag(unsigned long), "header",
61 fragment=SWIG_AsVal_frag(long)) {
62 SWIGINTERN int
63 SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val)
64 {
65 long v = 0;
66 if (SWIG_AsVal_long(obj, &v) && v < 0) {
67 SWIG_type_error("unsigned number", obj);
68 }
69 else if (val)
70 *val = (unsigned long)v;
71 return 1;
72 }
73 }
74
75
76 %fragment(SWIG_AsVal_frag(double), "header") {
77 SWIGINTERN int
78 SWIG_AsVal(double)(PyObject *obj, double* val)
79 {
80 if (PyNumber_Check(obj)) {
81 if (val) *val = PyFloat_AsDouble(obj);
82 return 1;
83 }
84 else {
85 SWIG_type_error("number", obj);
86 }
87 return 0;
88 }
89 }