]>
Commit | Line | Data |
---|---|---|
d638bf45 | 1 | |
2 | #include "config.h" | |
3 | ||
4 | #ifdef HAVE_ALLOCA_H | |
5 | #include <alloca.h> | |
6 | #endif | |
7 | ||
80d03bd8 | 8 | #include <errno.h> |
9 | #include <fcntl.h> | |
10 | #include <sys/stat.h> | |
11 | #include <sys/time.h> | |
12 | #include <unistd.h> | |
13 | ||
14 | #include "Python.h" | |
feef2cb5 | 15 | #include "nls.h" |
80d03bd8 | 16 | #include "newt.h" |
ce11acc8 | 17 | #include "newt_pr.h" |
80d03bd8 | 18 | |
19 | typedef struct snackWidget_s snackWidget; | |
20 | typedef struct snackGrid_s snackGrid; | |
21 | typedef struct snackForm_s snackForm; | |
22 | ||
5d678658 | 23 | struct callbackStruct { |
06cf519e | 24 | PyObject * cb, * data; |
25 | }; | |
26 | ||
d7e202d6 | 27 | /* Integer to pointer, 64-bit-sane */ |
28 | #define I2P(x) ((void *)(long)(x)) | |
29 | ||
1dfa0cfa | 30 | static struct callbackStruct suspend; |
72b71fa6 | 31 | static struct callbackStruct helpCallback; |
1dfa0cfa | 32 | |
80d03bd8 | 33 | static void emptyDestructor(PyObject * s); |
34 | ||
35 | static snackWidget * buttonWidget(PyObject * s, PyObject * args); | |
f954a19b | 36 | static snackWidget * compactbuttonWidget(PyObject * s, PyObject * args); |
80d03bd8 | 37 | static PyObject * centeredWindow(PyObject * s, PyObject * args); |
38 | static snackWidget * checkboxWidget(PyObject * s, PyObject * args); | |
39 | static PyObject * choiceWindow(PyObject * s, PyObject * args); | |
40 | static snackWidget * entryWidget(PyObject * s, PyObject * args); | |
75fb0452 | 41 | static PyObject * drawRootText(PyObject * s, PyObject * args); |
f1aef30b | 42 | static PyObject * doResume(PyObject * s, PyObject * args); |
43 | static PyObject * doSuspend(PyObject * s, PyObject * args); | |
44 | static PyObject * doSuspend(PyObject * s, PyObject * args); | |
80d03bd8 | 45 | static snackForm * formCreate(PyObject * s, PyObject * args); |
46 | static snackGrid * gridCreate(PyObject * s, PyObject * args); | |
47 | static PyObject * gridWrappedWindow(PyObject * s, PyObject * args); | |
48 | static PyObject * finishScreen(PyObject * s, PyObject * args); | |
49 | static PyObject * initScreen(PyObject * s, PyObject * args); | |
50 | static snackWidget * labelWidget(PyObject * s, PyObject * args); | |
6e25d997 | 51 | static snackWidget * listboxWidget(PyObject * s, PyObject * args); |
80d03bd8 | 52 | static PyObject * messageWindow(PyObject * s, PyObject * args); |
53 | static PyObject * openWindow(PyObject * s, PyObject * args); | |
75fb0452 | 54 | static PyObject * popHelpLine(PyObject * s, PyObject * args); |
80d03bd8 | 55 | static PyObject * popWindow(PyObject * s, PyObject * args); |
e5df813b | 56 | static PyObject * popWindowNoRefresh(PyObject * s, PyObject * args); |
75fb0452 | 57 | static PyObject * pushHelpLine(PyObject * s, PyObject * args); |
80d03bd8 | 58 | static snackWidget * radioButtonWidget(PyObject * s, PyObject * args); |
59 | static PyObject * refreshScreen(PyObject * s, PyObject * args); | |
06cf519e | 60 | static PyObject * scaleWidget(PyObject * s, PyObject * args); |
61 | static PyObject * scaleSet(snackWidget * s, PyObject * args); | |
9f0ab2ac | 62 | static PyObject * screenSize(PyObject * s, PyObject * args); |
06cf519e | 63 | static PyObject * setSuspendCallback(PyObject * s, PyObject * args); |
72b71fa6 | 64 | static PyObject * setHelpCallback(PyObject * s, PyObject * args); |
6e25d997 | 65 | static PyObject * reflowText(PyObject * s, PyObject * args); |
66 | static snackWidget * textWidget(PyObject * s, PyObject * args); | |
80d03bd8 | 67 | static PyObject * ternaryWindow(PyObject * s, PyObject * args); |
615bc463 | 68 | static snackWidget * checkboxTreeWidget(PyObject * s, PyObject * args, PyObject * kwargs); |
ce11acc8 | 69 | static PyObject * pywstrlen(PyObject * s, PyObject * args); |
80d03bd8 | 70 | |
71 | static PyMethodDef snackModuleMethods[] = { | |
72 | { "button", (PyCFunction) buttonWidget, METH_VARARGS, NULL }, | |
f954a19b | 73 | { "compactbutton", (PyCFunction) compactbuttonWidget, METH_VARARGS, NULL }, |
80d03bd8 | 74 | { "checkbox", (PyCFunction) checkboxWidget, METH_VARARGS, NULL }, |
75 | { "choice", choiceWindow, METH_VARARGS, NULL }, | |
76 | { "centeredwindow", centeredWindow, METH_VARARGS, NULL }, | |
75fb0452 | 77 | { "drawroottext", drawRootText, METH_VARARGS, NULL }, |
80d03bd8 | 78 | { "entry", (PyCFunction) entryWidget, METH_VARARGS, NULL }, |
79 | { "finish", finishScreen, METH_VARARGS, NULL }, | |
80 | { "form", (PyCFunction) formCreate, METH_VARARGS, NULL }, | |
81 | { "grid", (PyCFunction) gridCreate, METH_VARARGS, NULL }, | |
82 | { "gridwrappedwindow", gridWrappedWindow, METH_VARARGS, NULL }, | |
72b71fa6 | 83 | { "helpcallback", setHelpCallback, METH_VARARGS, NULL }, |
80d03bd8 | 84 | { "init", initScreen, METH_VARARGS, NULL }, |
85 | { "label", (PyCFunction) labelWidget, METH_VARARGS, NULL }, | |
6e25d997 | 86 | { "listbox", (PyCFunction) listboxWidget, METH_VARARGS, NULL }, |
80d03bd8 | 87 | { "message", messageWindow, METH_VARARGS, NULL }, |
88 | { "openwindow", openWindow, METH_VARARGS, NULL }, | |
75fb0452 | 89 | { "pophelpline", popHelpLine, METH_VARARGS, NULL }, |
80d03bd8 | 90 | { "popwindow", popWindow, METH_VARARGS, NULL }, |
e5df813b | 91 | { "popwindownorefresh", popWindowNoRefresh, METH_VARARGS, NULL }, |
75fb0452 | 92 | { "pushhelpline", pushHelpLine, METH_VARARGS, NULL }, |
80d03bd8 | 93 | { "radiobutton", (PyCFunction) radioButtonWidget, METH_VARARGS, NULL }, |
6e25d997 | 94 | { "reflow", (PyCFunction) reflowText, METH_VARARGS, NULL }, |
80d03bd8 | 95 | { "refresh", refreshScreen, METH_VARARGS, NULL }, |
f1aef30b | 96 | { "resume", doResume, METH_VARARGS, NULL }, |
06cf519e | 97 | { "scale", scaleWidget, METH_VARARGS, NULL }, |
9f0ab2ac | 98 | { "size", screenSize, METH_VARARGS, NULL }, |
f1aef30b | 99 | { "suspend", doSuspend, METH_VARARGS, NULL }, |
06cf519e | 100 | { "suspendcallback", setSuspendCallback, METH_VARARGS, NULL }, |
80d03bd8 | 101 | { "ternary", ternaryWindow, METH_VARARGS, NULL }, |
6e25d997 | 102 | { "textbox", (PyCFunction) textWidget, METH_VARARGS, NULL }, |
615bc463 | 103 | { "checkboxtree", (PyCFunction) checkboxTreeWidget, METH_VARARGS | METH_KEYWORDS, NULL }, |
ce11acc8 | 104 | { "wstrlen", (PyCFunction) pywstrlen, METH_VARARGS | METH_KEYWORDS, NULL }, |
80d03bd8 | 105 | { NULL } |
106 | } ; | |
107 | ||
108 | struct snackGrid_s { | |
cf4cf78f | 109 | PyObject_HEAD |
80d03bd8 | 110 | newtGrid grid; |
111 | } ; | |
112 | ||
113 | static PyObject * gridGetAttr(PyObject * s, char * name); | |
114 | static PyObject * gridPlace(snackGrid * s, PyObject * args); | |
115 | static PyObject * gridSetField(snackGrid * s, PyObject * args); | |
116 | ||
117 | static PyMethodDef gridMethods[] = { | |
118 | { "place", (PyCFunction) gridPlace, METH_VARARGS, NULL }, | |
119 | { "setfield", (PyCFunction) gridSetField, METH_VARARGS, NULL }, | |
120 | { NULL } | |
121 | }; | |
122 | ||
123 | static PyTypeObject snackGridType = { | |
124 | PyObject_HEAD_INIT(&PyType_Type) | |
125 | 0, /* ob_size */ | |
126 | "snackgrid", /* tp_name */ | |
127 | sizeof(snackGrid), /* tp_size */ | |
128 | 0, /* tp_itemsize */ | |
6f481af2 | 129 | emptyDestructor, /* tp_dealloc */ |
80d03bd8 | 130 | 0, /* tp_print */ |
6f481af2 | 131 | gridGetAttr, /* tp_getattr */ |
80d03bd8 | 132 | 0, /* tp_setattr */ |
133 | 0, /* tp_compare */ | |
134 | 0, /* tp_repr */ | |
135 | 0, /* tp_as_number */ | |
136 | 0, /* tp_as_sequence */ | |
6f481af2 | 137 | 0, /* tp_as_mapping */ |
80d03bd8 | 138 | }; |
139 | ||
140 | struct snackForm_s { | |
cf4cf78f | 141 | PyObject_HEAD |
80d03bd8 | 142 | newtComponent fo; |
143 | } ; | |
144 | ||
145 | static PyObject * formGetAttr(PyObject * s, char * name); | |
146 | static PyObject * formAdd(snackForm * s, PyObject * args); | |
bd38d47e | 147 | static PyObject * formDraw(snackForm * s, PyObject * args); |
80d03bd8 | 148 | static PyObject * formRun(snackForm * s, PyObject * args); |
ea59ae12 | 149 | static PyObject * formHotKey(snackForm * s, PyObject * args); |
5d678658 | 150 | static PyObject * formSetCurrent(snackForm * form, PyObject * args); |
73390860 | 151 | static PyObject * formSetTimer(snackForm * form, PyObject * args); |
d7e202d6 | 152 | static PyObject * formWatchFD(snackForm * form, PyObject * args); |
80d03bd8 | 153 | |
154 | static PyMethodDef formMethods[] = { | |
155 | { "add", (PyCFunction) formAdd, METH_VARARGS, NULL }, | |
bd38d47e | 156 | { "draw", (PyCFunction) formDraw, METH_VARARGS, NULL }, |
80d03bd8 | 157 | { "run", (PyCFunction) formRun, METH_VARARGS, NULL }, |
ea59ae12 | 158 | { "addhotkey", (PyCFunction) formHotKey, METH_VARARGS, NULL }, |
5d678658 | 159 | { "setcurrent", (PyCFunction) formSetCurrent, METH_VARARGS, NULL }, |
73390860 | 160 | { "settimer", (PyCFunction) formSetTimer, METH_VARARGS, NULL }, |
d7e202d6 | 161 | { "watchfd", (PyCFunction) formWatchFD, METH_VARARGS, NULL }, |
80d03bd8 | 162 | { NULL } |
163 | }; | |
164 | ||
165 | static PyTypeObject snackFormType = { | |
166 | PyObject_HEAD_INIT(&PyType_Type) | |
167 | 0, /* ob_size */ | |
168 | "snackform", /* tp_name */ | |
169 | sizeof(snackForm), /* tp_size */ | |
170 | 0, /* tp_itemsize */ | |
6f481af2 | 171 | emptyDestructor, /* tp_dealloc */ |
80d03bd8 | 172 | 0, /* tp_print */ |
6f481af2 | 173 | formGetAttr, /* tp_getattr */ |
80d03bd8 | 174 | 0, /* tp_setattr */ |
175 | 0, /* tp_compare */ | |
176 | 0, /* tp_repr */ | |
177 | 0, /* tp_as_number */ | |
178 | 0, /* tp_as_sequence */ | |
6f481af2 | 179 | 0, /* tp_as_mapping */ |
80d03bd8 | 180 | }; |
181 | ||
182 | struct snackWidget_s { | |
cf4cf78f | 183 | PyObject_HEAD |
80d03bd8 | 184 | newtComponent co; |
185 | char achar; | |
186 | void * apointer; | |
6e25d997 | 187 | int anint; |
5d678658 | 188 | struct callbackStruct scs; |
80d03bd8 | 189 | } ; |
190 | ||
6a703ca8 | 191 | static PyObject * widgetAddCallback(snackWidget * s, PyObject * args); |
80d03bd8 | 192 | static PyObject * widgetGetAttr(PyObject * s, char * name); |
1dfa0cfa | 193 | static void widgetDestructor(PyObject * s); |
80d03bd8 | 194 | static PyObject * widgetEntrySetValue(snackWidget * s, PyObject * args); |
522d3500 | 195 | static PyObject * widgetLabelText(snackWidget * s, PyObject * args); |
6e25d997 | 196 | static PyObject * widgetListboxSetW(snackWidget * s, PyObject * args); |
197 | static PyObject * widgetListboxAdd(snackWidget * s, PyObject * args); | |
a507b3ec | 198 | static PyObject * widgetListboxIns(snackWidget * s, PyObject * args); |
199 | static PyObject * widgetListboxDel(snackWidget * s, PyObject * args); | |
6e25d997 | 200 | static PyObject * widgetListboxGet(snackWidget * s, PyObject * args); |
99438c19 | 201 | static PyObject * widgetListboxSet(snackWidget * s, PyObject * args); |
50c9056c | 202 | static PyObject * widgetListboxClear(snackWidget * s, PyObject * args); |
36f926a6 | 203 | static PyObject * widgetTextboxText(snackWidget * s, PyObject * args); |
75d40644 | 204 | static PyObject * widgetCheckboxTreeAddItem(snackWidget * s, PyObject * args); |
5d678658 | 205 | static PyObject * widgetCheckboxTreeGetSel(snackWidget * s, PyObject * args); |
2b6641b1 | 206 | static PyObject * widgetCheckboxTreeGetCur(snackWidget * s, PyObject * args); |
c895490d | 207 | static PyObject * widgetCheckboxTreeSetEntry(snackWidget * s, PyObject * args); |
d8c97d41 | 208 | static PyObject * widgetCheckboxTreeSetWidth(snackWidget * s, PyObject * args); |
5160fc22 | 209 | static PyObject * widgetCheckboxTreeSetCurrent(snackWidget * s, PyObject * args); |
c895490d | 210 | static PyObject * widgetCheckboxTreeSetEntryValue(snackWidget * s, PyObject * args); |
211 | static PyObject * widgetCheckboxTreeGetEntryValue(snackWidget * s, PyObject * args); | |
5d678658 | 212 | static PyObject * widgetEntrySetFlags(snackWidget * s, PyObject * args); |
c573c71b | 213 | static PyObject * widgetCheckboxSetFlags(snackWidget * s, PyObject * args); |
870ff9eb | 214 | static PyObject * widgetCheckboxSetValue(snackWidget * s, PyObject * args); |
80d03bd8 | 215 | |
216 | static PyMethodDef widgetMethods[] = { | |
6a703ca8 | 217 | { "setCallback", (PyCFunction) widgetAddCallback, METH_VARARGS, NULL }, |
522d3500 | 218 | { "labelText", (PyCFunction) widgetLabelText, METH_VARARGS, NULL }, |
36f926a6 | 219 | { "textboxText", (PyCFunction) widgetTextboxText, METH_VARARGS, NULL }, |
80d03bd8 | 220 | { "entrySetValue", (PyCFunction) widgetEntrySetValue, METH_VARARGS, NULL }, |
6e25d997 | 221 | { "listboxAddItem", (PyCFunction) widgetListboxAdd, METH_VARARGS, NULL }, |
a507b3ec | 222 | { "listboxInsertItem", (PyCFunction) widgetListboxIns, METH_VARARGS, NULL }, |
6e25d997 | 223 | { "listboxGetCurrent", (PyCFunction) widgetListboxGet, METH_VARARGS, NULL }, |
99438c19 | 224 | { "listboxSetCurrent", (PyCFunction) widgetListboxSet, METH_VARARGS, NULL }, |
6e25d997 | 225 | { "listboxSetWidth", (PyCFunction) widgetListboxSetW, METH_VARARGS, NULL }, |
a507b3ec | 226 | { "listboxDeleteItem", (PyCFunction) widgetListboxDel, METH_VARARGS, NULL }, |
50c9056c | 227 | { "listboxClear", (PyCFunction) widgetListboxClear, METH_VARARGS, NULL }, |
06cf519e | 228 | { "scaleSet", (PyCFunction) scaleSet, METH_VARARGS, NULL }, |
75d40644 | 229 | { "checkboxtreeAddItem", (PyCFunction) widgetCheckboxTreeAddItem, |
f06c5a99 | 230 | METH_VARARGS, NULL }, |
2b6641b1 | 231 | { "checkboxtreeGetCurrent", (PyCFunction) widgetCheckboxTreeGetCur, |
232 | METH_VARARGS, NULL }, | |
c895490d | 233 | { "checkboxtreeGetEntryValue", (PyCFunction) widgetCheckboxTreeGetEntryValue, |
234 | METH_VARARGS, NULL }, | |
235 | { "checkboxtreeSetEntry", (PyCFunction) widgetCheckboxTreeSetEntry, | |
236 | METH_VARARGS, NULL }, | |
d8c97d41 | 237 | { "checkboxtreeSetWidth", (PyCFunction) widgetCheckboxTreeSetWidth, METH_VARARGS, NULL }, |
5160fc22 | 238 | { "checkboxtreeSetCurrent", (PyCFunction) widgetCheckboxTreeSetCurrent, |
239 | METH_VARARGS, NULL }, | |
c895490d | 240 | { "checkboxtreeSetEntryValue", (PyCFunction) widgetCheckboxTreeSetEntryValue, |
241 | METH_VARARGS, NULL }, | |
f06c5a99 | 242 | { "checkboxtreeGetSelection", (PyCFunction) widgetCheckboxTreeGetSel, |
615bc463 | 243 | METH_VARARGS, NULL }, |
5d678658 | 244 | { "entrySetFlags", (PyCFunction) widgetEntrySetFlags, METH_VARARGS, NULL }, |
c573c71b | 245 | { "checkboxSetFlags", (PyCFunction) widgetCheckboxSetFlags, METH_VARARGS, NULL }, |
870ff9eb | 246 | { "checkboxSetValue", (PyCFunction) widgetCheckboxSetValue, METH_VARARGS, NULL }, |
80d03bd8 | 247 | { NULL } |
248 | }; | |
249 | ||
250 | static PyTypeObject snackWidgetType = { | |
251 | PyObject_HEAD_INIT(&PyType_Type) | |
252 | 0, /* ob_size */ | |
253 | "snackwidget", /* tp_name */ | |
254 | sizeof(snackWidget), /* tp_size */ | |
255 | 0, /* tp_itemsize */ | |
6f481af2 | 256 | widgetDestructor, /* tp_dealloc */ |
80d03bd8 | 257 | 0, /* tp_print */ |
6f481af2 | 258 | widgetGetAttr, /* tp_getattr */ |
80d03bd8 | 259 | 0, /* tp_setattr */ |
260 | 0, /* tp_compare */ | |
261 | 0, /* tp_repr */ | |
262 | 0, /* tp_as_number */ | |
263 | 0, /* tp_as_sequence */ | |
6f481af2 | 264 | 0, /* tp_as_mapping */ |
80d03bd8 | 265 | }; |
266 | ||
1dfa0cfa | 267 | static snackWidget * snackWidgetNew (void) { |
268 | snackWidget * widget; | |
269 | ||
270 | widget = PyObject_NEW(snackWidget, &snackWidgetType); | |
271 | ||
272 | widget->scs.cb = NULL; | |
273 | widget->scs.data = NULL; | |
274 | ||
275 | return widget; | |
276 | } | |
277 | ||
80d03bd8 | 278 | static PyObject * initScreen(PyObject * s, PyObject * args) { |
1dfa0cfa | 279 | suspend.cb = NULL; |
280 | suspend.data = NULL; | |
281 | ||
80d03bd8 | 282 | newtInit(); |
283 | newtCls(); | |
284 | ||
285 | Py_INCREF(Py_None); | |
286 | return Py_None; | |
287 | } | |
288 | ||
289 | static PyObject * finishScreen(PyObject * s, PyObject * args) { | |
dd66cfb7 | 290 | Py_XDECREF (suspend.cb); |
291 | Py_XDECREF (suspend.data); | |
292 | ||
80d03bd8 | 293 | newtFinished(); |
294 | Py_INCREF(Py_None); | |
295 | return Py_None; | |
296 | } | |
297 | ||
298 | static PyObject * refreshScreen(PyObject * s, PyObject * args) { | |
299 | newtRefresh(); | |
300 | Py_INCREF(Py_None); | |
301 | return Py_None; | |
302 | } | |
303 | ||
06cf519e | 304 | static PyObject * scaleWidget(PyObject * s, PyObject * args) { |
305 | snackWidget * widget; | |
306 | int width, fullAmount; | |
307 | ||
308 | if (!PyArg_ParseTuple(args, "ii", &width, &fullAmount)) return NULL; | |
309 | ||
1dfa0cfa | 310 | widget = snackWidgetNew (); |
06cf519e | 311 | widget->co = newtScale(-1, -1, width, fullAmount); |
312 | ||
313 | return (PyObject *) widget; | |
314 | } | |
315 | ||
316 | static PyObject * scaleSet(snackWidget * s, PyObject * args) { | |
317 | int amount; | |
318 | ||
319 | if (!PyArg_ParseTuple(args, "i", &amount)) return NULL; | |
320 | ||
321 | newtScaleSet(s->co, amount); | |
322 | ||
323 | Py_INCREF(Py_None); | |
324 | return Py_None; | |
325 | } | |
326 | ||
9f0ab2ac | 327 | static PyObject * screenSize(PyObject * s, PyObject * args) { |
328 | int width, height; | |
329 | ||
330 | if (!PyArg_ParseTuple(args, "")) | |
6f481af2 | 331 | return NULL; |
9f0ab2ac | 332 | |
333 | newtGetScreenSize(&width, &height); | |
334 | ||
335 | return Py_BuildValue("(ii)", width, height); | |
336 | } | |
337 | ||
72b71fa6 | 338 | static void helpCallbackMarshall(newtComponent co, void * data) { |
339 | PyObject * args, * result; | |
340 | ||
341 | args = Py_BuildValue("(O)", data); | |
342 | result = PyEval_CallObject(helpCallback.cb, args); | |
343 | Py_DECREF (args); | |
344 | Py_XDECREF(result); | |
345 | ||
346 | return; | |
347 | } | |
348 | ||
5d678658 | 349 | static void suspendCallbackMarshall(void * data) { |
350 | struct callbackStruct * scs = data; | |
351 | PyObject * args, * result; | |
352 | ||
1dfa0cfa | 353 | if (scs->data) { |
6f481af2 | 354 | args = Py_BuildValue("(O)", scs->data); |
355 | result = PyEval_CallObject(scs->cb, args); | |
356 | Py_DECREF (args); | |
1dfa0cfa | 357 | } else |
6f481af2 | 358 | result = PyEval_CallObject(scs->cb, NULL); |
1dfa0cfa | 359 | |
360 | if (!result) { | |
6f481af2 | 361 | PyErr_Print(); |
362 | PyErr_Clear(); | |
1dfa0cfa | 363 | } |
5d678658 | 364 | |
5d678658 | 365 | Py_XDECREF(result); |
366 | ||
367 | return; | |
368 | } | |
369 | ||
370 | static void callbackMarshall(newtComponent co, void * data) { | |
371 | struct callbackStruct * scs = data; | |
06cf519e | 372 | PyObject * args, * result; |
373 | ||
1dfa0cfa | 374 | if (scs->data) { |
6f481af2 | 375 | args = Py_BuildValue("(O)", scs->data); |
376 | result = PyEval_CallObject(scs->cb, args); | |
377 | Py_DECREF (args); | |
1dfa0cfa | 378 | } else |
6f481af2 | 379 | result = PyEval_CallObject(scs->cb, NULL); |
1ea8f607 | 380 | |
5d678658 | 381 | if (!result) { |
6f481af2 | 382 | PyErr_Print(); |
383 | PyErr_Clear(); | |
5d678658 | 384 | } |
385 | ||
1ea8f607 | 386 | Py_XDECREF(result); |
06cf519e | 387 | |
1ea8f607 | 388 | return; |
06cf519e | 389 | } |
390 | ||
391 | static PyObject * setSuspendCallback(PyObject * s, PyObject * args) { | |
1dfa0cfa | 392 | if (!PyArg_ParseTuple(args, "O|O", &suspend.cb, &suspend.data)) |
6f481af2 | 393 | return NULL; |
06cf519e | 394 | |
1dfa0cfa | 395 | Py_INCREF (suspend.cb); |
396 | Py_XINCREF (suspend.data); | |
397 | ||
398 | newtSetSuspendCallback(suspendCallbackMarshall, &suspend); | |
06cf519e | 399 | |
400 | Py_INCREF(Py_None); | |
401 | return Py_None; | |
402 | } | |
403 | ||
72b71fa6 | 404 | static PyObject * setHelpCallback(PyObject * s, PyObject * args) { |
405 | if (!PyArg_ParseTuple(args, "O", &helpCallback.cb)) | |
6f481af2 | 406 | return NULL; |
72b71fa6 | 407 | |
408 | /*if (helpCallback.cb) { | |
6f481af2 | 409 | Py_DECREF (helpCallback.cb); |
72b71fa6 | 410 | }*/ |
411 | ||
412 | Py_INCREF (helpCallback.cb); | |
413 | ||
414 | newtSetHelpCallback(helpCallbackMarshall); | |
415 | ||
416 | Py_INCREF(Py_None); | |
417 | return Py_None; | |
418 | } | |
419 | ||
75fb0452 | 420 | static PyObject * drawRootText(PyObject * s, PyObject * args) { |
421 | int left, top; | |
422 | char * text; | |
423 | ||
424 | if (!PyArg_ParseTuple(args, "iis", &left, &top, &text)) | |
6f481af2 | 425 | return NULL; |
75fb0452 | 426 | |
ec65dcfe | 427 | newtDrawRootText(left, top, text); |
75fb0452 | 428 | |
429 | Py_INCREF(Py_None); | |
430 | return Py_None; | |
431 | } | |
432 | ||
f1aef30b | 433 | static PyObject * doSuspend(PyObject * s, PyObject * args) { |
434 | newtSuspend(); | |
435 | ||
436 | Py_INCREF(Py_None); | |
437 | return Py_None; | |
438 | } | |
439 | ||
440 | static PyObject * doResume(PyObject * s, PyObject * args) { | |
441 | newtResume(); | |
442 | ||
443 | Py_INCREF(Py_None); | |
444 | return Py_None; | |
445 | } | |
446 | ||
75fb0452 | 447 | static PyObject * popHelpLine(PyObject * s, PyObject * args) { |
448 | newtPopHelpLine(); | |
449 | Py_INCREF(Py_None); | |
450 | return Py_None; | |
451 | } | |
452 | ||
453 | static PyObject * pushHelpLine(PyObject * s, PyObject * args) { | |
454 | char * text; | |
455 | ||
456 | if (!PyArg_ParseTuple(args, "s", &text)) | |
6f481af2 | 457 | return NULL; |
75fb0452 | 458 | |
459 | if (!strcmp(text, "*default*")) | |
6f481af2 | 460 | newtPushHelpLine(NULL); |
75fb0452 | 461 | else |
6f481af2 | 462 | newtPushHelpLine(text); |
75fb0452 | 463 | |
464 | Py_INCREF(Py_None); | |
465 | return Py_None; | |
466 | } | |
467 | ||
6e25d997 | 468 | static PyObject * reflowText(PyObject * s, PyObject * args) { |
469 | char * text, * new; | |
470 | int width, minus = 5, plus = 5; | |
471 | int realWidth, realHeight; | |
472 | PyObject * tuple; | |
473 | ||
474 | if (!PyArg_ParseTuple(args, "si|ii", &text, &width, &minus, &plus)) | |
6f481af2 | 475 | return NULL; |
6e25d997 | 476 | |
477 | new = newtReflowText(text, width, minus, plus, &realWidth, &realHeight); | |
478 | ||
479 | tuple = Py_BuildValue("(sii)", new, realWidth, realHeight); | |
480 | free(new); | |
481 | ||
482 | return tuple; | |
483 | } | |
484 | ||
80d03bd8 | 485 | static PyObject * centeredWindow(PyObject * s, PyObject * args) { |
486 | int width, height; | |
487 | char * title; | |
488 | ||
489 | if (!PyArg_ParseTuple(args, "iis", &width, &height, &title)) | |
6f481af2 | 490 | return NULL; |
80d03bd8 | 491 | |
492 | newtCenteredWindow(width, height, title); | |
493 | ||
494 | Py_INCREF(Py_None); | |
495 | return Py_None; | |
496 | } | |
497 | ||
498 | static PyObject * gridWrappedWindow(PyObject * s, PyObject * args) { | |
499 | snackGrid * grid; | |
500 | char * title; | |
2b6641b1 | 501 | int x = -1, y = -1; |
80d03bd8 | 502 | |
2b6641b1 | 503 | if (!PyArg_ParseTuple(args, "O!s|ii", &snackGridType, &grid, &title, |
6f481af2 | 504 | &x, &y)) |
505 | return NULL; | |
80d03bd8 | 506 | |
2b6641b1 | 507 | if (y == -1) |
6f481af2 | 508 | newtGridWrappedWindow(grid->grid, title); |
2b6641b1 | 509 | else |
6f481af2 | 510 | newtGridWrappedWindowAt(grid->grid, title, x, y); |
80d03bd8 | 511 | |
512 | Py_INCREF(Py_None); | |
513 | return Py_None; | |
514 | } | |
515 | ||
516 | static PyObject * openWindow(PyObject * s, PyObject * args) { | |
517 | int left, top, width, height; | |
518 | char * title; | |
519 | ||
520 | if (!PyArg_ParseTuple(args, "iiiis", &left, &top, &width, &height, &title)) | |
6f481af2 | 521 | return NULL; |
80d03bd8 | 522 | |
523 | newtOpenWindow(left, top, width, height, title); | |
524 | ||
525 | Py_INCREF(Py_None); | |
526 | return Py_None; | |
527 | } | |
528 | ||
529 | static PyObject * popWindow(PyObject * s, PyObject * args) { | |
530 | newtPopWindow(); | |
531 | Py_INCREF(Py_None); | |
532 | return Py_None; | |
533 | } | |
534 | ||
e5df813b | 535 | static PyObject * popWindowNoRefresh(PyObject * s, PyObject * args) { |
536 | newtPopWindowNoRefresh(); | |
537 | Py_INCREF(Py_None); | |
538 | return Py_None; | |
539 | } | |
540 | ||
80d03bd8 | 541 | static PyObject * messageWindow(PyObject * s, PyObject * args) { |
542 | char * title, * text; | |
543 | char * okbutton = "Ok"; | |
544 | ||
545 | if (!PyArg_ParseTuple(args, "ss|s", &title, &text, &okbutton)) | |
6f481af2 | 546 | return NULL; |
80d03bd8 | 547 | |
548 | newtWinMessage(title, okbutton, text); | |
549 | ||
550 | Py_INCREF(Py_None); | |
551 | return Py_None; | |
552 | } | |
553 | ||
554 | static PyObject * choiceWindow(PyObject * s, PyObject * args) { | |
555 | char * title, * text; | |
556 | char * okbutton = "Ok"; | |
557 | char * cancelbutton = "Cancel"; | |
558 | int rc; | |
559 | ||
560 | if (!PyArg_ParseTuple(args, "ss|ss", &title, &text, &okbutton, | |
6f481af2 | 561 | &cancelbutton)) |
562 | return NULL; | |
80d03bd8 | 563 | |
564 | rc = newtWinChoice(title, okbutton, cancelbutton, text); | |
565 | ||
93a3a267 | 566 | return Py_BuildValue("i", rc); |
80d03bd8 | 567 | } |
568 | ||
569 | static PyObject * ternaryWindow(PyObject * s, PyObject * args) { | |
570 | char * title, * text, * button1, * button2, * button3; | |
571 | int rc; | |
572 | ||
573 | if (!PyArg_ParseTuple(args, "sssss", &title, &text, &button1, &button2, | |
6f481af2 | 574 | &button3)) |
575 | return NULL; | |
80d03bd8 | 576 | |
577 | rc = newtWinTernary(title, button1, button2, button3, text); | |
578 | ||
579 | return Py_BuildValue("i", rc); | |
580 | } | |
581 | ||
582 | static snackWidget * buttonWidget(PyObject * s, PyObject * args) { | |
583 | snackWidget * widget; | |
584 | char * label; | |
585 | ||
586 | if (!PyArg_ParseTuple(args, "s", &label)) return NULL; | |
587 | ||
1dfa0cfa | 588 | widget = snackWidgetNew (); |
80d03bd8 | 589 | widget->co = newtButton(-1, -1, label); |
590 | ||
591 | return widget; | |
592 | } | |
593 | ||
f954a19b | 594 | static snackWidget * compactbuttonWidget(PyObject * s, PyObject * args) { |
595 | snackWidget * widget; | |
596 | char * label; | |
597 | ||
598 | if (!PyArg_ParseTuple(args, "s", &label)) return NULL; | |
599 | ||
600 | widget = snackWidgetNew (); | |
601 | widget->co = newtCompactButton(-1, -1, label); | |
602 | ||
603 | return widget; | |
604 | } | |
605 | ||
80d03bd8 | 606 | static snackWidget * labelWidget(PyObject * s, PyObject * args) { |
607 | char * label; | |
608 | snackWidget * widget; | |
609 | ||
610 | if (!PyArg_ParseTuple(args, "s", &label)) return NULL; | |
611 | ||
1dfa0cfa | 612 | widget = snackWidgetNew (); |
80d03bd8 | 613 | widget->co = newtLabel(-1, -1, label); |
614 | ||
615 | return widget; | |
616 | } | |
617 | ||
522d3500 | 618 | static PyObject * widgetLabelText(snackWidget * s, PyObject * args) { |
619 | char * label; | |
620 | ||
621 | if (!PyArg_ParseTuple(args, "s", &label)) return NULL; | |
622 | ||
623 | newtLabelSetText(s->co, label); | |
624 | ||
625 | Py_INCREF(Py_None); | |
626 | return Py_None; | |
627 | } | |
628 | ||
36f926a6 | 629 | static PyObject * widgetTextboxText(snackWidget * s, PyObject * args) { |
630 | char * text; | |
631 | ||
632 | if (!PyArg_ParseTuple(args, "s", &text)) return NULL; | |
633 | ||
634 | newtTextboxSetText(s->co, text); | |
635 | ||
636 | Py_INCREF(Py_None); | |
637 | return Py_None; | |
638 | } | |
639 | ||
6e25d997 | 640 | static snackWidget * listboxWidget(PyObject * s, PyObject * args) { |
641 | snackWidget * widget; | |
642 | int height; | |
b5c4016a | 643 | int doScroll = 0, returnExit = 0, showCursor = 0 ; |
6e25d997 | 644 | |
b5c4016a | 645 | if (!PyArg_ParseTuple(args, "i|iii", &height, &doScroll, &returnExit, &showCursor)) |
6f481af2 | 646 | return NULL; |
6e25d997 | 647 | |
1dfa0cfa | 648 | widget = snackWidgetNew (); |
6e25d997 | 649 | widget->co = newtListbox(-1, -1, height, |
6f481af2 | 650 | (doScroll ? NEWT_FLAG_SCROLL : 0) | |
651 | (returnExit ? NEWT_FLAG_RETURNEXIT : 0) | | |
652 | (showCursor ? NEWT_FLAG_SHOWCURSOR : 0) | |
653 | ); | |
a507b3ec | 654 | widget->anint = 1; |
6e25d997 | 655 | |
656 | return widget; | |
657 | } | |
658 | ||
659 | static snackWidget * textWidget(PyObject * s, PyObject * args) { | |
660 | char * text; | |
661 | int width, height; | |
662 | int scrollBar = 0; | |
36f926a6 | 663 | int wrap = 0; |
6e25d997 | 664 | snackWidget * widget; |
665 | ||
36f926a6 | 666 | if (!PyArg_ParseTuple(args, "iis|ii", &width, &height, &text, &scrollBar, &wrap)) |
6f481af2 | 667 | return NULL; |
6e25d997 | 668 | |
1dfa0cfa | 669 | widget = snackWidgetNew (); |
6e25d997 | 670 | widget->co = newtTextbox(-1, -1, width, height, |
6f481af2 | 671 | (scrollBar ? NEWT_FLAG_SCROLL : 0) | |
672 | (wrap ? NEWT_FLAG_WRAP : 0)); | |
6e25d997 | 673 | newtTextboxSetText(widget->co, text); |
674 | ||
675 | return widget; | |
676 | } | |
677 | ||
80d03bd8 | 678 | static snackWidget * radioButtonWidget(PyObject * s, PyObject * args) { |
679 | snackWidget * widget, * group; | |
680 | char * text; | |
681 | int isOn; | |
682 | ||
683 | if (!PyArg_ParseTuple(args, "sOi", &text, &group, &isOn)) | |
6f481af2 | 684 | return NULL; |
80d03bd8 | 685 | |
1dfa0cfa | 686 | widget = snackWidgetNew (); |
80d03bd8 | 687 | |
688 | if ((PyObject *) group == Py_None) | |
6f481af2 | 689 | widget->co = newtRadiobutton(-1, -1, text, isOn, NULL); |
80d03bd8 | 690 | else |
6f481af2 | 691 | widget->co = newtRadiobutton(-1, -1, text, isOn, group->co); |
80d03bd8 | 692 | |
693 | return widget; | |
694 | } | |
695 | ||
696 | static snackWidget * checkboxWidget(PyObject * s, PyObject * args) { | |
697 | snackWidget * widget; | |
698 | char * text; | |
699 | int isOn; | |
700 | ||
701 | if (!PyArg_ParseTuple(args, "si", &text, &isOn)) return NULL; | |
702 | ||
1dfa0cfa | 703 | widget = snackWidgetNew (); |
80d03bd8 | 704 | widget->co = newtCheckbox(-1, -1, text, isOn ? '*' : ' ', NULL, |
6f481af2 | 705 | &widget->achar); |
80d03bd8 | 706 | |
707 | return widget; | |
708 | } | |
709 | ||
c573c71b | 710 | static PyObject * widgetCheckboxSetFlags(snackWidget * s, PyObject * args) { |
711 | int flag, sense; | |
712 | ||
713 | if (!PyArg_ParseTuple(args, "ii", &flag, &sense)) return NULL; | |
714 | ||
715 | newtCheckboxSetFlags(s->co, flag, sense); | |
716 | ||
717 | Py_INCREF(Py_None); | |
718 | return Py_None; | |
719 | } | |
720 | ||
870ff9eb | 721 | static PyObject * widgetCheckboxSetValue(snackWidget * s, PyObject * args) { |
722 | char *value; | |
723 | ||
724 | if (!PyArg_ParseTuple(args, "s", &value)) return NULL; | |
725 | ||
726 | newtCheckboxSetValue(s->co, *value); | |
727 | ||
728 | Py_INCREF(Py_None); | |
729 | return Py_None; | |
730 | } | |
c573c71b | 731 | |
80d03bd8 | 732 | static snackWidget * entryWidget(PyObject * s, PyObject * args) { |
733 | snackWidget * widget; | |
734 | int width; | |
735 | char * initial; | |
20fb366a | 736 | int isHidden, isScrolled, returnExit, isPassword; |
80d03bd8 | 737 | |
20fb366a | 738 | if (!PyArg_ParseTuple(args, "isiiii", &width, &initial, |
6f481af2 | 739 | &isHidden, &isPassword, &isScrolled, &returnExit)) return NULL; |
80d03bd8 | 740 | |
1dfa0cfa | 741 | widget = snackWidgetNew (); |
d78245ab | 742 | widget->co = newtEntry(-1, -1, initial, width, |
743 | (const char **) &widget->apointer, | |
6f481af2 | 744 | (isHidden ? NEWT_FLAG_HIDDEN : 0) | |
745 | (isPassword ? NEWT_FLAG_PASSWORD : 0) | | |
746 | (returnExit ? NEWT_FLAG_RETURNEXIT : 0) | | |
747 | (isScrolled ? NEWT_FLAG_SCROLL : 0)); | |
80d03bd8 | 748 | |
749 | return widget; | |
750 | } | |
751 | ||
752 | static snackForm * formCreate(PyObject * s, PyObject * args) { | |
753 | snackForm * form; | |
72b71fa6 | 754 | PyObject * help = Py_None; |
755 | ||
756 | if (!PyArg_ParseTuple(args, "|O", &help)) return NULL; | |
757 | ||
758 | if (help == Py_None) | |
6f481af2 | 759 | help = NULL; |
80d03bd8 | 760 | |
761 | form = PyObject_NEW(snackForm, &snackFormType); | |
72b71fa6 | 762 | form->fo = newtForm(NULL, help, 0); |
80d03bd8 | 763 | |
764 | return form; | |
765 | } | |
766 | ||
767 | static snackGrid * gridCreate(PyObject * s, PyObject * args) { | |
768 | int rows, cols; | |
769 | snackGrid * grid; | |
770 | ||
771 | if (!PyArg_ParseTuple(args, "ii", &cols, &rows)) return NULL; | |
772 | ||
773 | grid = PyObject_NEW(snackGrid, &snackGridType); | |
774 | grid->grid = newtCreateGrid(cols, rows); | |
775 | ||
776 | return grid; | |
777 | } | |
778 | ||
779 | static PyObject * gridGetAttr(PyObject * s, char * name) { | |
780 | return Py_FindMethod(gridMethods, s, name); | |
781 | } | |
782 | ||
783 | static PyObject * gridPlace(snackGrid * grid, PyObject * args) { | |
784 | int x, y; | |
785 | ||
786 | if (!PyArg_ParseTuple(args, "ii", &x, &y)) return NULL; | |
787 | ||
788 | newtGridPlace(grid->grid, x, y); | |
789 | ||
790 | Py_INCREF(Py_None); | |
791 | return Py_None; | |
792 | } | |
793 | ||
794 | static PyObject * gridSetField(snackGrid * grid, PyObject * args) { | |
795 | snackWidget * w; | |
6e25d997 | 796 | snackGrid * g; |
80d03bd8 | 797 | int x, y; |
798 | int pLeft = 0, pTop = 0, pRight = 0, pBottom = 0; | |
6e25d997 | 799 | int anchorFlags = 0, growFlags = 0; |
80d03bd8 | 800 | |
6e25d997 | 801 | if (!PyArg_ParseTuple(args, "iiO|(iiii)ii", &x, &y, |
6f481af2 | 802 | &w, &pLeft, &pTop, &pRight, &pBottom, |
803 | &anchorFlags, &growFlags)) | |
804 | return NULL; | |
80d03bd8 | 805 | |
6e25d997 | 806 | if (w->ob_type == &snackWidgetType) { |
6f481af2 | 807 | newtGridSetField(grid->grid, x, y, NEWT_GRID_COMPONENT, |
808 | w->co, pLeft, pTop, pRight, pBottom, anchorFlags, | |
809 | growFlags); | |
6e25d997 | 810 | } else { |
6f481af2 | 811 | g = (snackGrid *) w; |
812 | newtGridSetField(grid->grid, x, y, NEWT_GRID_SUBGRID, | |
813 | g->grid, pLeft, pTop, pRight, pBottom, anchorFlags, | |
814 | growFlags); | |
6e25d997 | 815 | } |
80d03bd8 | 816 | |
817 | Py_INCREF(Py_None); | |
818 | return Py_None; | |
819 | } | |
820 | ||
821 | static PyObject * formGetAttr(PyObject * s, char * name) { | |
822 | return Py_FindMethod(formMethods, s, name); | |
823 | } | |
824 | ||
bd38d47e | 825 | static PyObject * formDraw(snackForm * s, PyObject * args) { |
826 | newtDrawForm(s->fo); | |
827 | ||
828 | Py_INCREF(Py_None); | |
829 | return Py_None; | |
830 | } | |
831 | ||
80d03bd8 | 832 | static PyObject * formAdd(snackForm * s, PyObject * args) { |
833 | snackWidget * w; | |
834 | int size = PyTuple_Size(args), i; | |
835 | ||
836 | if (!size) { | |
6f481af2 | 837 | /* this is a hack, I should give an error directly */ |
838 | if (!PyArg_ParseTuple(args, "O!", &snackWidgetType, &w)) | |
839 | return NULL; | |
80d03bd8 | 840 | } |
841 | ||
842 | for (i = 0; i < size; i++) { | |
6f481af2 | 843 | w = (snackWidget *) PyTuple_GET_ITEM(args, i); |
844 | newtFormAddComponent(s->fo, w->co); | |
80d03bd8 | 845 | } |
846 | ||
847 | Py_INCREF(Py_None); | |
848 | return Py_None; | |
849 | } | |
850 | ||
851 | static PyObject * formRun(snackForm * s, PyObject * args) { | |
ea59ae12 | 852 | struct newtExitStruct result; |
853 | ||
854 | newtFormRun(s->fo, &result); | |
855 | ||
856 | if (result.reason == NEWT_EXIT_HOTKEY) | |
6f481af2 | 857 | return Py_BuildValue("(si)", "hotkey", result.u.key); |
73390860 | 858 | else if (result.reason == NEWT_EXIT_TIMER) |
6f481af2 | 859 | return Py_BuildValue("(si)", "timer", 0); |
d7e202d6 | 860 | else if (result.reason == NEWT_EXIT_FDREADY) |
6f481af2 | 861 | return Py_BuildValue("(si)", "fdready", result.u.watch); |
ea59ae12 | 862 | else |
6f481af2 | 863 | return Py_BuildValue("(si)", "widget", result.u.co); |
ea59ae12 | 864 | } |
865 | ||
866 | static PyObject * formHotKey(snackForm * s, PyObject * args) { | |
867 | int key; | |
868 | ||
869 | if (!PyArg_ParseTuple(args, "i", &key)) | |
6f481af2 | 870 | return NULL; |
ea59ae12 | 871 | |
872 | newtFormAddHotKey(s->fo, key); | |
80d03bd8 | 873 | |
874 | Py_INCREF(Py_None); | |
875 | return Py_None; | |
876 | } | |
877 | ||
73390860 | 878 | static PyObject * formSetTimer(snackForm * form, PyObject * args) { |
879 | int millisecs; | |
880 | ||
881 | if (!PyArg_ParseTuple(args, "i", &millisecs)) | |
6f481af2 | 882 | return NULL; |
73390860 | 883 | |
884 | newtFormSetTimer(form->fo, millisecs); | |
885 | ||
886 | Py_INCREF(Py_None); | |
887 | return Py_None; | |
888 | } | |
889 | ||
d7e202d6 | 890 | static PyObject * formWatchFD(snackForm * form, PyObject * args) { |
891 | int fd, fdflags; | |
892 | ||
893 | if (!PyArg_ParseTuple(args, "ii", &fd, &fdflags)) | |
6f481af2 | 894 | return NULL; |
d7e202d6 | 895 | |
896 | newtFormWatchFd(form->fo, fd, fdflags); | |
897 | ||
898 | Py_INCREF(Py_None); | |
899 | return Py_None; | |
900 | } | |
901 | ||
5d678658 | 902 | static PyObject * formSetCurrent(snackForm * form, PyObject * args) { |
903 | snackWidget * w; | |
904 | ||
905 | if (!PyArg_ParseTuple(args, "O", &w)) | |
6f481af2 | 906 | return NULL; |
5d678658 | 907 | |
908 | newtFormSetCurrent(form->fo, w->co); | |
909 | ||
910 | Py_INCREF(Py_None); | |
911 | return Py_None; | |
912 | } | |
913 | ||
80d03bd8 | 914 | static PyObject * widgetGetAttr(PyObject * s, char * name) { |
915 | snackWidget * w = (snackWidget *) s; | |
916 | ||
ea59ae12 | 917 | if (!strcmp(name, "key")) { |
6f481af2 | 918 | return Py_BuildValue("i", w->co); |
80d03bd8 | 919 | } else if (!strcmp(name, "entryValue")) { |
6f481af2 | 920 | return Py_BuildValue("s", w->apointer); |
80d03bd8 | 921 | } else if (!strcmp(name, "checkboxValue")) { |
6f481af2 | 922 | return Py_BuildValue("i", w->achar == ' ' ? 0 : 1); |
80d03bd8 | 923 | } else if (!strcmp(name, "radioValue")) { |
6f481af2 | 924 | return Py_BuildValue("i", newtRadioGetCurrent(w->co)); |
80d03bd8 | 925 | } |
926 | ||
927 | return Py_FindMethod(widgetMethods, s, name); | |
928 | } | |
929 | ||
1dfa0cfa | 930 | static void widgetDestructor(PyObject * o) { |
931 | snackWidget * s = (snackWidget *) o; | |
932 | ||
933 | Py_XDECREF (s->scs.cb); | |
934 | Py_XDECREF (s->scs.data); | |
bd0f4c32 | 935 | |
936 | PyObject_Free(o); | |
1dfa0cfa | 937 | } |
938 | ||
6a703ca8 | 939 | static PyObject * widgetAddCallback(snackWidget * s, PyObject * args) { |
1dfa0cfa | 940 | s->scs.cb = NULL; |
941 | s->scs.data = NULL; | |
942 | ||
5d678658 | 943 | if (!PyArg_ParseTuple(args, "O|O", &s->scs.cb, &s->scs.data)) |
6f481af2 | 944 | return NULL; |
6a703ca8 | 945 | |
1dfa0cfa | 946 | Py_INCREF (s->scs.cb); |
947 | Py_XINCREF (s->scs.data); | |
948 | ||
5d678658 | 949 | newtComponentAddCallback(s->co, callbackMarshall, &s->scs); |
6a703ca8 | 950 | |
951 | Py_INCREF(Py_None); | |
952 | return Py_None; | |
953 | } | |
954 | ||
80d03bd8 | 955 | static PyObject * widgetEntrySetValue(snackWidget * s, PyObject * args) { |
956 | char * val; | |
957 | ||
958 | if (!PyArg_ParseTuple(args, "s", &val)) | |
6f481af2 | 959 | return NULL; |
80d03bd8 | 960 | |
961 | newtEntrySet(s->co, val, 1); | |
962 | ||
963 | Py_INCREF(Py_None); | |
964 | return Py_None; | |
965 | } | |
966 | ||
5d678658 | 967 | static PyObject * widgetEntrySetFlags(snackWidget * s, PyObject * args) { |
968 | int flag, sense; | |
969 | ||
970 | if (!PyArg_ParseTuple(args, "ii", &flag, &sense)) return NULL; | |
971 | ||
972 | newtEntrySetFlags(s->co, flag, sense); | |
973 | ||
974 | Py_INCREF(Py_None); | |
975 | return Py_None; | |
976 | } | |
977 | ||
978 | ||
6e25d997 | 979 | static PyObject * widgetListboxAdd(snackWidget * s, PyObject * args) { |
980 | char * text; | |
981 | ||
982 | if (!PyArg_ParseTuple(args, "s", &text)) | |
6f481af2 | 983 | return NULL; |
6e25d997 | 984 | |
d7e202d6 | 985 | newtListboxAddEntry(s->co, text, I2P(s->anint)); |
6e25d997 | 986 | |
987 | return PyInt_FromLong(s->anint++); | |
988 | } | |
989 | ||
a507b3ec | 990 | static PyObject * widgetListboxIns(snackWidget * s, PyObject * args) { |
991 | char * text; | |
992 | int key; | |
993 | ||
994 | if (!PyArg_ParseTuple(args, "si", &text, &key)) | |
6f481af2 | 995 | return NULL; |
a507b3ec | 996 | |
d7e202d6 | 997 | newtListboxInsertEntry(s->co, text, I2P(s->anint), I2P(key)); |
a507b3ec | 998 | |
999 | return PyInt_FromLong(s->anint++); | |
1000 | } | |
1001 | ||
1002 | static PyObject * widgetListboxDel(snackWidget * s, PyObject * args) { | |
1003 | int key; | |
1004 | ||
1005 | if (!PyArg_ParseTuple(args, "i", &key)) | |
6f481af2 | 1006 | return NULL; |
a507b3ec | 1007 | |
d7e202d6 | 1008 | newtListboxDeleteEntry(s->co, I2P(key)); |
a507b3ec | 1009 | |
1010 | Py_INCREF(Py_None); | |
1011 | return Py_None; | |
1012 | } | |
1013 | ||
6e25d997 | 1014 | static PyObject * widgetListboxGet(snackWidget * s, PyObject * args) { |
1015 | if (!PyArg_ParseTuple(args, "")) | |
6f481af2 | 1016 | return NULL; |
6e25d997 | 1017 | |
1018 | return PyInt_FromLong((long) newtListboxGetCurrent(s->co)); | |
1019 | } | |
1020 | ||
99438c19 | 1021 | static PyObject * widgetListboxSet(snackWidget * s, PyObject * args) { |
1022 | int index; | |
1023 | ||
1024 | if (!PyArg_ParseTuple(args, "i", &index)) | |
6f481af2 | 1025 | return NULL; |
99438c19 | 1026 | |
d7e202d6 | 1027 | newtListboxSetCurrentByKey(s->co, I2P(index)); |
99438c19 | 1028 | |
1029 | Py_INCREF(Py_None); | |
1030 | return Py_None; | |
1031 | } | |
1032 | ||
6e25d997 | 1033 | static PyObject * widgetListboxSetW(snackWidget * s, PyObject * args) { |
1034 | int width; | |
1035 | ||
1036 | if (!PyArg_ParseTuple(args, "i", &width)) | |
6f481af2 | 1037 | return NULL; |
6e25d997 | 1038 | |
1039 | newtListboxSetWidth(s->co, width); | |
1040 | ||
1041 | Py_INCREF(Py_None); | |
1042 | return Py_None; | |
1043 | } | |
1044 | ||
50c9056c | 1045 | static PyObject * widgetListboxClear(snackWidget * s, PyObject * args) { |
1046 | if (!PyArg_ParseTuple(args, "")) | |
1047 | return NULL; | |
1048 | ||
1049 | newtListboxClear(s->co); | |
1050 | ||
1051 | Py_INCREF(Py_None); | |
1052 | return Py_None; | |
1053 | } | |
1054 | ||
80d03bd8 | 1055 | static void emptyDestructor(PyObject * s) { |
1056 | } | |
1057 | ||
615bc463 | 1058 | static snackWidget * checkboxTreeWidget(PyObject * s, PyObject * args, PyObject * kwargs) { |
f06c5a99 | 1059 | int height; |
1060 | int scrollBar = 0; | |
615bc463 | 1061 | int hide_checkbox = 0; |
1062 | int unselectable = 0; | |
1063 | int flags; | |
f06c5a99 | 1064 | snackWidget * widget; |
615bc463 | 1065 | const char *kw[] = {"height", "scrollbar", "hide_checkbox", "unselectable", NULL}; |
f06c5a99 | 1066 | |
615bc463 | 1067 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|iii", (char **) kw, |
6f481af2 | 1068 | &height, &scrollBar, &hide_checkbox, &unselectable)) |
1069 | return NULL; | |
f06c5a99 | 1070 | |
615bc463 | 1071 | flags = (scrollBar ? NEWT_FLAG_SCROLL : 0) | |
6f481af2 | 1072 | (hide_checkbox ? NEWT_CHECKBOXTREE_HIDE_BOX : 0) | |
1073 | (unselectable ? NEWT_CHECKBOXTREE_UNSELECTABLE : 0); | |
615bc463 | 1074 | |
1dfa0cfa | 1075 | widget = snackWidgetNew (); |
615bc463 | 1076 | widget->co = newtCheckboxTree(-1, -1, height, flags); |
f06c5a99 | 1077 | |
1078 | widget->anint = 1; | |
1079 | ||
1080 | return widget; | |
1081 | } | |
1082 | ||
75d40644 | 1083 | static PyObject * widgetCheckboxTreeAddItem(snackWidget * s, PyObject * args) { |
f06c5a99 | 1084 | char * text; |
f06c5a99 | 1085 | int selected = 0; |
75d40644 | 1086 | PyObject * pathList, * o; |
1087 | int len; | |
1088 | int * path; | |
1089 | int i; | |
1090 | ||
1091 | if (!PyArg_ParseTuple(args, "sOi", &text, &pathList, &selected)) | |
6f481af2 | 1092 | return NULL; |
f06c5a99 | 1093 | |
75d40644 | 1094 | len = PyTuple_Size(pathList); |
1095 | path = alloca(sizeof(*path) * (len + 1)); | |
1096 | for (i = 0; i < len; i++) { | |
1097 | o = PyTuple_GetItem(pathList, i); | |
6f481af2 | 1098 | path[i] = PyInt_AsLong(o); |
75d40644 | 1099 | } |
1100 | path[len] = NEWT_ARG_LAST; | |
1101 | ||
d7e202d6 | 1102 | newtCheckboxTreeAddArray(s->co, text, I2P(s->anint), |
6f481af2 | 1103 | selected ? NEWT_FLAG_SELECTED : 0, path); |
f06c5a99 | 1104 | |
1105 | return PyInt_FromLong(s->anint++); | |
1106 | } | |
1107 | ||
2b6641b1 | 1108 | static PyObject * widgetCheckboxTreeGetCur(snackWidget * s, PyObject * args) { |
1109 | if (!PyArg_ParseTuple(args, "")) | |
6f481af2 | 1110 | return NULL; |
2b6641b1 | 1111 | |
d7e202d6 | 1112 | return PyInt_FromLong((long)newtCheckboxTreeGetCurrent(s->co)); |
2b6641b1 | 1113 | } |
1114 | ||
c895490d | 1115 | static PyObject * widgetCheckboxTreeSetEntry(snackWidget * s, PyObject * args) { |
1116 | int data; | |
1117 | char *text; | |
1118 | ||
1119 | if (!PyArg_ParseTuple(args, "is", &data, &text)) return NULL; | |
1120 | ||
d7e202d6 | 1121 | newtCheckboxTreeSetEntry(s->co, I2P(data), text); |
c895490d | 1122 | |
1123 | Py_INCREF(Py_None); | |
d8c97d41 | 1124 | return Py_None; |
1125 | } | |
1126 | ||
1127 | static PyObject * widgetCheckboxTreeSetWidth(snackWidget * s, PyObject * args) { | |
1128 | int width; | |
1129 | ||
1130 | if (!PyArg_ParseTuple(args, "i", &width)) | |
6f481af2 | 1131 | return NULL; |
d8c97d41 | 1132 | |
1133 | newtCheckboxTreeSetWidth(s->co, width); | |
1134 | ||
1135 | Py_INCREF(Py_None); | |
c895490d | 1136 | return Py_None; |
1137 | } | |
1138 | ||
5160fc22 | 1139 | static PyObject * widgetCheckboxTreeSetCurrent(snackWidget * s, PyObject * args) { |
1140 | int data; | |
1141 | ||
1142 | if (!PyArg_ParseTuple(args, "i", &data)) return NULL; | |
1143 | ||
d7e202d6 | 1144 | newtCheckboxTreeSetCurrent(s->co, I2P(data)); |
5160fc22 | 1145 | |
1146 | Py_INCREF(Py_None); | |
1147 | return Py_None; | |
1148 | } | |
1149 | ||
c895490d | 1150 | static PyObject * widgetCheckboxTreeSetEntryValue(snackWidget * s, PyObject * args) { |
1151 | int data; | |
1152 | int isOn = 1; | |
1153 | ||
1154 | if (!PyArg_ParseTuple(args, "i|i", &data, &isOn)) return NULL; | |
1155 | ||
d7e202d6 | 1156 | newtCheckboxTreeSetEntryValue(s->co, I2P(data), |
6f481af2 | 1157 | isOn ? NEWT_CHECKBOXTREE_SELECTED : |
1158 | NEWT_CHECKBOXTREE_UNSELECTED); | |
c895490d | 1159 | |
1160 | Py_INCREF(Py_None); | |
1161 | return Py_None; | |
1162 | } | |
1163 | ||
1164 | static PyObject * widgetCheckboxTreeGetEntryValue(snackWidget * s, PyObject * args) { | |
1165 | int data; | |
1166 | int isOn = 0; | |
1167 | int isBranch = 0; | |
1168 | char selection; | |
1169 | ||
1170 | if (!PyArg_ParseTuple(args, "i", &data)) return NULL; | |
1171 | ||
d7e202d6 | 1172 | selection = newtCheckboxTreeGetEntryValue(s->co, I2P(data)); |
c895490d | 1173 | |
1174 | if (selection == -1) return NULL; | |
1175 | ||
1176 | switch (selection) { | |
1177 | case NEWT_CHECKBOXTREE_EXPANDED: | |
6f481af2 | 1178 | isOn = 1; |
c895490d | 1179 | case NEWT_CHECKBOXTREE_COLLAPSED: |
6f481af2 | 1180 | isBranch = 1; |
1181 | break; | |
c895490d | 1182 | case NEWT_CHECKBOXTREE_UNSELECTED: |
6f481af2 | 1183 | break; |
c895490d | 1184 | default: |
6f481af2 | 1185 | isOn = 1; |
1186 | break; | |
c895490d | 1187 | } |
1188 | return Py_BuildValue("(ii)", isBranch, isOn); | |
1189 | } | |
1190 | ||
5a6729cf | 1191 | static PyObject * widgetCheckboxTreeGetSel(snackWidget * s, |
6f481af2 | 1192 | PyObject * args) { |
f06c5a99 | 1193 | void ** selection; |
1194 | int numselected; | |
5a6729cf | 1195 | int i; |
1196 | PyObject * sel; | |
f06c5a99 | 1197 | |
2b6641b1 | 1198 | if (!PyArg_ParseTuple(args, "")) |
6f481af2 | 1199 | return NULL; |
2b6641b1 | 1200 | |
72b71fa6 | 1201 | selection = (void **) newtCheckboxTreeGetSelection(s->co, &numselected); |
f06c5a99 | 1202 | |
788ec656 | 1203 | sel = PyList_New(0); |
1204 | ||
5a6729cf | 1205 | if (!selection) { |
6f481af2 | 1206 | return sel; |
f06c5a99 | 1207 | } |
1208 | ||
5a6729cf | 1209 | sel = PyList_New(0); |
1210 | for (i = 0; i < numselected; i++) { | |
6f481af2 | 1211 | PyList_Append(sel, PyInt_FromLong((long) selection[i])); |
5a6729cf | 1212 | } |
1213 | free(selection); | |
f06c5a99 | 1214 | |
5a6729cf | 1215 | return sel; |
f06c5a99 | 1216 | } |
1217 | ||
ce11acc8 | 1218 | static PyObject * pywstrlen(PyObject * s, PyObject * args) |
1219 | { | |
1220 | char *str; | |
1221 | int len = -1; | |
1222 | ||
1223 | if (!PyArg_ParseTuple(args, "s|i", &str, &len)) return NULL; | |
1224 | ||
1225 | return PyInt_FromLong(wstrlen(str, len)); | |
1226 | } | |
1227 | ||
80d03bd8 | 1228 | void init_snack(void) { |
6e25d997 | 1229 | PyObject * d, * m; |
1230 | ||
feef2cb5 | 1231 | setlocale (LC_ALL, ""); |
1232 | bindtextdomain (PACKAGE, LOCALEDIR); | |
1233 | textdomain (PACKAGE); | |
1234 | ||
6e25d997 | 1235 | m = Py_InitModule("_snack", snackModuleMethods); |
1236 | d = PyModule_GetDict(m); | |
1237 | ||
1238 | PyDict_SetItemString(d, "ANCHOR_LEFT", PyInt_FromLong(NEWT_ANCHOR_LEFT)); | |
1239 | PyDict_SetItemString(d, "ANCHOR_TOP", PyInt_FromLong(NEWT_ANCHOR_TOP)); | |
1240 | PyDict_SetItemString(d, "ANCHOR_RIGHT", PyInt_FromLong(NEWT_ANCHOR_RIGHT)); | |
1241 | PyDict_SetItemString(d, "ANCHOR_BOTTOM", | |
6f481af2 | 1242 | PyInt_FromLong(NEWT_ANCHOR_BOTTOM)); |
6e25d997 | 1243 | PyDict_SetItemString(d, "GRID_GROWX", PyInt_FromLong(NEWT_GRID_FLAG_GROWX)); |
1244 | PyDict_SetItemString(d, "GRID_GROWY", PyInt_FromLong(NEWT_GRID_FLAG_GROWY)); | |
ea59ae12 | 1245 | |
d7e202d6 | 1246 | PyDict_SetItemString(d, "FD_READ", PyInt_FromLong(NEWT_FD_READ)); |
1247 | PyDict_SetItemString(d, "FD_WRITE", PyInt_FromLong(NEWT_FD_WRITE)); | |
1248 | PyDict_SetItemString(d, "FD_EXCEPT", PyInt_FromLong(NEWT_FD_EXCEPT)); | |
1249 | ||
ea59ae12 | 1250 | PyDict_SetItemString(d, "FORM_EXIT_HOTKEY", PyString_FromString("hotkey")); |
1251 | PyDict_SetItemString(d, "FORM_EXIT_WIDGET", PyString_FromString("widget")); | |
73390860 | 1252 | PyDict_SetItemString(d, "FORM_EXIT_TIMER", PyString_FromString("timer")); |
d7e202d6 | 1253 | PyDict_SetItemString(d, "FORM_EXIT_FDREADY", PyString_FromString("fdready")); |
ea59ae12 | 1254 | |
1255 | PyDict_SetItemString(d, "KEY_F1", PyInt_FromLong(NEWT_KEY_F1)); | |
1256 | PyDict_SetItemString(d, "KEY_F2", PyInt_FromLong(NEWT_KEY_F2)); | |
1257 | PyDict_SetItemString(d, "KEY_F3", PyInt_FromLong(NEWT_KEY_F3)); | |
1258 | PyDict_SetItemString(d, "KEY_F4", PyInt_FromLong(NEWT_KEY_F4)); | |
1259 | PyDict_SetItemString(d, "KEY_F5", PyInt_FromLong(NEWT_KEY_F5)); | |
1260 | PyDict_SetItemString(d, "KEY_F6", PyInt_FromLong(NEWT_KEY_F6)); | |
1261 | PyDict_SetItemString(d, "KEY_F7", PyInt_FromLong(NEWT_KEY_F7)); | |
1262 | PyDict_SetItemString(d, "KEY_F8", PyInt_FromLong(NEWT_KEY_F8)); | |
1263 | PyDict_SetItemString(d, "KEY_F9", PyInt_FromLong(NEWT_KEY_F9)); | |
1264 | PyDict_SetItemString(d, "KEY_F10", PyInt_FromLong(NEWT_KEY_F10)); | |
1265 | PyDict_SetItemString(d, "KEY_F11", PyInt_FromLong(NEWT_KEY_F11)); | |
1266 | PyDict_SetItemString(d, "KEY_F12", PyInt_FromLong(NEWT_KEY_F12)); | |
feef2cb5 | 1267 | PyDict_SetItemString(d, "KEY_ESC", PyInt_FromLong(NEWT_KEY_ESCAPE)); |
5d678658 | 1268 | |
1269 | PyDict_SetItemString(d, "FLAG_DISABLED", PyInt_FromLong(NEWT_FLAG_DISABLED)); | |
1270 | PyDict_SetItemString(d, "FLAGS_SET", PyInt_FromLong(NEWT_FLAGS_SET)); | |
1271 | PyDict_SetItemString(d, "FLAGS_RESET", PyInt_FromLong(NEWT_FLAGS_RESET)); | |
1272 | PyDict_SetItemString(d, "FLAGS_TOGGLE", PyInt_FromLong(NEWT_FLAGS_TOGGLE)); | |
80d03bd8 | 1273 | } |