blob: 483ce6efed3fd43d9d853170ec35d3197274dffa [file] [log] [blame]
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001/* FL module -- interface to Mark Overmars' FORMS Library. */
2
Roger E. Masse7ba4c071997-01-03 22:17:11 +00003/* This code works with FORMS version 2.2 (if you defined
4 OBSOLETE_FORMS_CALLS), and 2.3.
Guido van Rossumf1dc5661993-07-05 10:31:29 +00005 FORMS can be ftp'ed from ftp.cs.ruu.nl (131.211.80.17), directory
6 /pub/SGI/FORMS. */
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00007
Jack Jansen743db361992-08-13 14:13:11 +00008/* A half-hearted attempt has been made to allow programs using this
9 * module to exploit parallelism (through the threads module). No provisions
10 * have been made for multiple threads to use this module at the same time,
11 * though. So, a program with a forms thread and a non-forms thread will work
12 * fine but a program with two threads using forms will probably crash (unless
13 * the program takes precaution to ensure that only one thread can be in
14 * this module at any time). This will have to be fixed some time.
Thomas Wouters7e474022000-07-16 12:04:32 +000015 * (A fix will probably also have to synchronize with the gl module).
Jack Jansen743db361992-08-13 14:13:11 +000016 */
17
Roger E. Masse7ba4c071997-01-03 22:17:11 +000018#include "Python.h"
Guido van Rossumc7df79e1991-08-07 11:32:58 +000019#include "forms.h"
Guido van Rossumc7df79e1991-08-07 11:32:58 +000020#include "structmember.h"
Guido van Rossumc7df79e1991-08-07 11:32:58 +000021
22/* Generic Forms Objects */
23
24typedef struct {
Roger E. Masse7ba4c071997-01-03 22:17:11 +000025 PyObject_HEAD
Guido van Rossumc7df79e1991-08-07 11:32:58 +000026 FL_OBJECT *ob_generic;
Roger E. Masse7ba4c071997-01-03 22:17:11 +000027 PyMethodDef *ob_methods;
28 PyObject *ob_callback;
29 PyObject *ob_callback_arg;
Guido van Rossumc7df79e1991-08-07 11:32:58 +000030} genericobject;
31
Roger E. Masse7ba4c071997-01-03 22:17:11 +000032staticforward PyTypeObject GenericObjecttype;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000033
34#define is_genericobject(g) ((g)->ob_type == &GenericObjecttype)
35
36/* List of all objects (XXX this should be a hash table on address...) */
Guido van Rossumc7df79e1991-08-07 11:32:58 +000037
Roger E. Masse7ba4c071997-01-03 22:17:11 +000038static PyObject *allgenerics = NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000039static int nfreeslots = 0;
40
41/* Add an object to the list of known objects */
Guido van Rossumc7df79e1991-08-07 11:32:58 +000042
43static void
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +000044knowgeneric(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +000045{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000046 int i, n;
47 /* Create the list if it doesn't already exist */
Guido van Rossumc7df79e1991-08-07 11:32:58 +000048 if (allgenerics == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +000049 allgenerics = PyList_New(0);
Guido van Rossumc7df79e1991-08-07 11:32:58 +000050 if (allgenerics == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +000051 PyErr_Clear();
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000052 return; /* Too bad, live without allgenerics... */
Guido van Rossumc7df79e1991-08-07 11:32:58 +000053 }
54 }
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000055 if (nfreeslots > 0) {
56 /* Search the list for reusable slots (NULL items) */
57 /* XXX This can be made faster! */
Roger E. Masse7ba4c071997-01-03 22:17:11 +000058 n = PyList_Size(allgenerics);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000059 for (i = 0; i < n; i++) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +000060 if (PyList_GetItem(allgenerics, i) == NULL) {
61 Py_INCREF(g);
62 PyList_SetItem(allgenerics, i, (PyObject *)g);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000063 nfreeslots--;
64 return;
65 }
66 }
67 /* Strange... no free slots found... */
68 nfreeslots = 0;
69 }
70 /* No free entries, append new item to the end */
Roger E. Masse7ba4c071997-01-03 22:17:11 +000071 PyList_Append(allgenerics, (PyObject *)g);
Guido van Rossumc7df79e1991-08-07 11:32:58 +000072}
73
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000074/* Find an object in the list of known objects */
75
Guido van Rossumc7df79e1991-08-07 11:32:58 +000076static genericobject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +000077findgeneric(FL_OBJECT *generic)
Guido van Rossumc7df79e1991-08-07 11:32:58 +000078{
79 int i, n;
80 genericobject *g;
81
82 if (allgenerics == NULL)
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000083 return NULL; /* No objects known yet */
Roger E. Masse7ba4c071997-01-03 22:17:11 +000084 n = PyList_Size(allgenerics);
Guido van Rossumc7df79e1991-08-07 11:32:58 +000085 for (i = 0; i < n; i++) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +000086 g = (genericobject *)PyList_GetItem(allgenerics, i);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000087 if (g != NULL && g->ob_generic == generic)
Guido van Rossumc7df79e1991-08-07 11:32:58 +000088 return g;
89 }
90 return NULL; /* Unknown object */
91}
92
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +000093/* Remove an object from the list of known objects */
94
95static void
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +000096forgetgeneric(genericobject *g)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +000097{
98 int i, n;
99
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000100 Py_XDECREF(g->ob_callback);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000101 g->ob_callback = NULL;
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000102 Py_XDECREF(g->ob_callback_arg);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000103 g->ob_callback_arg = NULL;
104 if (allgenerics == NULL)
105 return; /* No objects known yet */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000106 n = PyList_Size(allgenerics);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000107 for (i = 0; i < n; i++) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000108 if (g == (genericobject *)PyList_GetItem(allgenerics, i)) {
109 PyList_SetItem(allgenerics, i, (PyObject *)NULL);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000110 nfreeslots++;
111 break;
112 }
113 }
114}
115
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000116/* Called when a form is about to be freed --
117 remove all the objects that we know about from it. */
118
119static void
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000120releaseobjects(FL_FORM *form)
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000121{
122 int i, n;
123 genericobject *g;
124
125 if (allgenerics == NULL)
126 return; /* No objects known yet */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000127 n = PyList_Size(allgenerics);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000128 for (i = 0; i < n; i++) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000129 g = (genericobject *)PyList_GetItem(allgenerics, i);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000130 if (g != NULL && g->ob_generic->form == form) {
131 fl_delete_object(g->ob_generic);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000132 /* The object is now unreachable for
133 do_forms and check_forms, so
134 delete it from the list of known objects */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000135 Py_XDECREF(g->ob_callback);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000136 g->ob_callback = NULL;
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000137 Py_XDECREF(g->ob_callback_arg);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000138 g->ob_callback_arg = NULL;
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000139 PyList_SetItem(allgenerics, i, (PyObject *)NULL);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000140 nfreeslots++;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000141 }
142 }
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000143}
144
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000145
146/* Methods of generic objects */
147
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000148static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000149generic_set_call_back(genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000150{
151 if (args == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000152 Py_XDECREF(g->ob_callback);
153 Py_XDECREF(g->ob_callback_arg);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000154 g->ob_callback = NULL;
155 g->ob_callback_arg = NULL;
156 }
157 else {
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000158 if (!PyTuple_Check(args) || PyTuple_Size(args) != 2) {
159 PyErr_BadArgument();
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000160 return NULL;
161 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000162 Py_XDECREF(g->ob_callback);
163 Py_XDECREF(g->ob_callback_arg);
164 g->ob_callback = PyTuple_GetItem(args, 0);
165 Py_INCREF(g->ob_callback);
166 g->ob_callback_arg = PyTuple_GetItem(args, 1);
167 Py_INCREF(g->ob_callback_arg);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000168 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000169 Py_INCREF(Py_None);
170 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000171}
172
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000173static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000174generic_call(genericobject *g, void (*func)(FL_OBJECT *))
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000175{
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000176 (*func)(g->ob_generic);
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000177 Py_INCREF(Py_None);
178 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000179}
180
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000181static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000182generic_delete_object(genericobject *g)
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000183{
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000184 PyObject *res;
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000185 res = generic_call(g, fl_delete_object);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000186 if (res != NULL)
187 forgetgeneric(g);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000188 return res;
189}
190
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000191static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000192generic_show_object(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000193{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000194 return generic_call(g, fl_show_object);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000195}
196
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000197static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000198generic_hide_object(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000199{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000200 return generic_call(g, fl_hide_object);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000201}
202
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000203static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000204generic_redraw_object(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000205{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000206 return generic_call(g, fl_redraw_object);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000207}
208
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000209#ifdef OBSOLETE_FORMS_CALLS
210
211 /* (un)freeze_object() are obsolete in FORMS 2.2 and unsupported
212 in 2.3. Since there's no foolproof way to tell which version we're
213 using, we omit them unconditionally. */
214
215static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000216generic_freeze_object(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000217{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000218 return generic_call(g, fl_freeze_object);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000219}
220
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000221static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000222generic_unfreeze_object(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000223{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000224 return generic_call(g, fl_unfreeze_object);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000225}
226
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000227#endif /* OBSOLETE_FORMS_CALLS */
228
229static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000230generic_activate_object(genericobject *g)
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000231{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000232 return generic_call(g, fl_activate_object);
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000233}
234
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000235static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000236generic_deactivate_object(genericobject *g)
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000237{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000238 return generic_call(g, fl_deactivate_object);
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000239}
240
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000241static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000242generic_set_object_shortcut(genericobject *g, PyObject *args)
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000243{
244 char *str;
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000245 if (!PyArg_ParseTuple(args, "s:set_object_shortcut", &str))
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000246 return NULL;
247 fl_set_object_shortcut(g->ob_generic, str);
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000248 Py_INCREF(Py_None);
249 return Py_None;
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000250}
251
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000252static PyMethodDef generic_methods[] = {
Martin v. Löwis43b936d2002-01-17 23:15:58 +0000253 {"set_call_back", (PyCFunction)generic_set_call_back, METH_OLDARGS},
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000254 {"delete_object", (PyCFunction)generic_delete_object, METH_NOARGS},
255 {"show_object", (PyCFunction)generic_show_object, METH_NOARGS},
256 {"hide_object", (PyCFunction)generic_hide_object, METH_NOARGS},
257 {"redraw_object", (PyCFunction)generic_redraw_object, METH_NOARGS},
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000258#ifdef OBSOLETE_FORMS_CALLS
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000259 {"freeze_object", (PyCFunction)generic_freeze_object, METH_NOARGS},
260 {"unfreeze_object", (PyCFunction)generic_unfreeze_object, METH_NOARGS},
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000261#endif
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000262 {"activate_object", (PyCFunction)generic_activate_object, METH_NOARGS},
263 {"deactivate_object", (PyCFunction)generic_deactivate_object, METH_NOARGS},
Martin v. Löwis43b936d2002-01-17 23:15:58 +0000264 {"set_object_shortcut", (PyCFunction)generic_set_object_shortcut, METH_OLDARGS},
Guido van Rossum03747111991-08-08 12:10:01 +0000265 {NULL, NULL} /* sentinel */
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000266};
267
268static void
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000269generic_dealloc(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000270{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000271 fl_free_object(g->ob_generic);
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000272 Py_XDECREF(g->ob_callback);
273 Py_XDECREF(g->ob_callback_arg);
Guido van Rossumb18618d2000-05-03 23:44:39 +0000274 PyObject_Del(g);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000275}
276
277#define OFF(x) offsetof(FL_OBJECT, x)
278
279static struct memberlist generic_memberlist[] = {
280 {"objclass", T_INT, OFF(objclass), RO},
281 {"type", T_INT, OFF(type), RO},
282 {"boxtype", T_INT, OFF(boxtype)},
283 {"x", T_FLOAT, OFF(x)},
284 {"y", T_FLOAT, OFF(y)},
285 {"w", T_FLOAT, OFF(w)},
286 {"h", T_FLOAT, OFF(h)},
287 {"col1", T_INT, OFF(col1)},
288 {"col2", T_INT, OFF(col2)},
289 {"align", T_INT, OFF(align)},
290 {"lcol", T_INT, OFF(lcol)},
291 {"lsize", T_FLOAT, OFF(lsize)},
292 /* "label" is treated specially! */
293 {"lstyle", T_INT, OFF(lstyle)},
294 {"pushed", T_INT, OFF(pushed), RO},
295 {"focus", T_INT, OFF(focus), RO},
296 {"belowmouse", T_INT, OFF(belowmouse),RO},
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000297/* {"frozen", T_INT, OFF(frozen), RO}, */
Guido van Rossum7066dd71992-09-17 17:54:56 +0000298 {"active", T_INT, OFF(active)},
299 {"input", T_INT, OFF(input)},
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000300 {"visible", T_INT, OFF(visible), RO},
Guido van Rossum7066dd71992-09-17 17:54:56 +0000301 {"radio", T_INT, OFF(radio)},
302 {"automatic", T_INT, OFF(automatic)},
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000303 {NULL} /* Sentinel */
304};
305
Guido van Rossumd97f0481991-11-19 20:26:28 +0000306#undef OFF
307
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000308static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000309generic_getattr(genericobject *g, char *name)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000310{
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000311 PyObject *meth;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000312
313 /* XXX Ought to special-case name "__methods__" */
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000314 if (g-> ob_methods) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000315 meth = Py_FindMethod(g->ob_methods, (PyObject *)g, name);
Guido van Rossum03747111991-08-08 12:10:01 +0000316 if (meth != NULL) return meth;
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000317 PyErr_Clear();
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000318 }
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000319
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000320 meth = Py_FindMethod(generic_methods, (PyObject *)g, name);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000321 if (meth != NULL)
322 return meth;
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000323 PyErr_Clear();
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000324
325 /* "label" is an exception, getmember only works for char pointers,
326 not for char arrays */
327 if (strcmp(name, "label") == 0)
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000328 return PyString_FromString(g->ob_generic->label);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000329
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000330 return PyMember_Get((char *)g->ob_generic, generic_memberlist, name);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000331}
332
333static int
Sjoerd Mullender0ae52842000-07-12 10:43:11 +0000334generic_setattr(genericobject *g, char *name, PyObject *v)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000335{
336 int ret;
337
338 if (v == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000339 PyErr_SetString(PyExc_TypeError,
340 "can't delete forms object attributes");
Guido van Rossum3dd8c981992-06-03 17:07:49 +0000341 return -1;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000342 }
343
344 /* "label" is an exception: setmember doesn't set strings;
345 and FORMS wants you to call a function to set the label */
346 if (strcmp(name, "label") == 0) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000347 if (!PyString_Check(v)) {
348 PyErr_SetString(PyExc_TypeError,
349 "label attr must be string");
Guido van Rossum3dd8c981992-06-03 17:07:49 +0000350 return -1;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000351 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000352 fl_set_object_label(g->ob_generic, PyString_AsString(v));
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000353 return 0;
354 }
355
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000356 ret = PyMember_Set((char *)g->ob_generic, generic_memberlist, name, v);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000357
358 /* Rather than calling all the various set_object_* functions,
359 we call fl_redraw_object here. This is sometimes redundant
360 but I doubt that's a big problem */
361 if (ret == 0)
362 fl_redraw_object(g->ob_generic);
363
364 return ret;
365}
366
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000367static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000368generic_repr(genericobject *g)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000369{
370 char buf[100];
Tim Peters885d4572001-11-28 20:27:42 +0000371 PyOS_snprintf(buf, sizeof(buf), "<FORMS_object at %p, objclass=%d>",
372 g, g->ob_generic->objclass);
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000373 return PyString_FromString(buf);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000374}
375
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000376static PyTypeObject GenericObjecttype = {
377 PyObject_HEAD_INIT(&PyType_Type)
Guido van Rossumb6775db1994-08-01 11:34:53 +0000378 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +0000379 "fl.FORMS_object", /*tp_name*/
Guido van Rossumb6775db1994-08-01 11:34:53 +0000380 sizeof(genericobject), /*tp_size*/
381 0, /*tp_itemsize*/
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000382 /* methods */
Guido van Rossumb6775db1994-08-01 11:34:53 +0000383 (destructor)generic_dealloc, /*tp_dealloc*/
384 0, /*tp_print*/
385 (getattrfunc)generic_getattr, /*tp_getattr*/
386 (setattrfunc)generic_setattr, /*tp_setattr*/
387 0, /*tp_compare*/
388 (reprfunc)generic_repr, /*tp_repr*/
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000389};
390
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000391static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000392newgenericobject(FL_OBJECT *generic, PyMethodDef *methods)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000393{
394 genericobject *g;
Guido van Rossumb18618d2000-05-03 23:44:39 +0000395 g = PyObject_New(genericobject, &GenericObjecttype);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000396 if (g == NULL)
397 return NULL;
398 g-> ob_generic = generic;
399 g->ob_methods = methods;
400 g->ob_callback = NULL;
401 g->ob_callback_arg = NULL;
402 knowgeneric(g);
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000403 return (PyObject *)g;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000404}
405
406/**********************************************************************/
407/* Some common calling sequences */
408
409/* void func (object, float) */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000410static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000411call_forms_INf (void (*func)(FL_OBJECT *, float), FL_OBJECT *obj, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000412{
Guido van Rossum03747111991-08-08 12:10:01 +0000413 float parameter;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000414
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000415 if (!PyArg_Parse(args, "f", &parameter)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000416
Guido van Rossum03747111991-08-08 12:10:01 +0000417 (*func) (obj, parameter);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000418
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000419 Py_INCREF(Py_None);
420 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000421}
422
423/* void func (object, float) */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000424static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000425call_forms_INfINf (void (*func)(FL_OBJECT *, float, float), FL_OBJECT *obj, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000426{
Guido van Rossum03747111991-08-08 12:10:01 +0000427 float par1, par2;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000428
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000429 if (!PyArg_Parse(args, "(ff)", &par1, &par2)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000430
Guido van Rossum03747111991-08-08 12:10:01 +0000431 (*func) (obj, par1, par2);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000432
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000433 Py_INCREF(Py_None);
434 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000435}
436
437/* void func (object, int) */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000438static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000439call_forms_INi (void (*func)(FL_OBJECT *, int), FL_OBJECT *obj, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000440{
Guido van Rossum03747111991-08-08 12:10:01 +0000441 int parameter;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000442
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000443 if (!PyArg_Parse(args, "i", &parameter)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000444
Guido van Rossum03747111991-08-08 12:10:01 +0000445 (*func) (obj, parameter);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000446
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000447 Py_INCREF(Py_None);
448 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000449}
450
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000451/* void func (object, char) */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000452static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000453call_forms_INc (void (*func)(FL_OBJECT *, int), FL_OBJECT *obj, PyObject *args)
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000454{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000455 char *a;
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000456
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000457 if (!PyArg_Parse(args, "s", &a)) return NULL;
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000458
Guido van Rossumfc58e581992-01-27 16:45:55 +0000459 (*func) (obj, a[0]);
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000460
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000461 Py_INCREF(Py_None);
462 return Py_None;
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000463}
464
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000465/* void func (object, string) */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000466static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000467call_forms_INstr (void (*func)(FL_OBJECT *, char *), FL_OBJECT *obj, PyObject *args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000468{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000469 char *a;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000470
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000471 if (!PyArg_Parse(args, "s", &a)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000472
Guido van Rossumfc58e581992-01-27 16:45:55 +0000473 (*func) (obj, a);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000474
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000475 Py_INCREF(Py_None);
476 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000477}
478
479
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000480/* void func (object, int, string) */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000481static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000482call_forms_INiINstr (void (*func)(FL_OBJECT *, int, char *), FL_OBJECT *obj, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000483{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000484 char *b;
485 int a;
Guido van Rossum03747111991-08-08 12:10:01 +0000486
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000487 if (!PyArg_Parse(args, "(is)", &a, &b)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +0000488
Guido van Rossumfc58e581992-01-27 16:45:55 +0000489 (*func) (obj, a, b);
Guido van Rossum03747111991-08-08 12:10:01 +0000490
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000491 Py_INCREF(Py_None);
492 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000493}
494
Guido van Rossum03747111991-08-08 12:10:01 +0000495#ifdef UNUSED
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000496/* void func (object, int, int) */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000497static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000498call_forms_INiINi (void (*func)(FL_OBJECT *, int, int), FL_OBJECT *obj, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000499{
Guido van Rossum03747111991-08-08 12:10:01 +0000500 int par1, par2;
501
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000502 if (!PyArg_Parse(args, "(ii)", &par1, &par2)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +0000503
504 (*func) (obj, par1, par2);
505
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000506 Py_INCREF(Py_None);
507 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000508}
Guido van Rossum03747111991-08-08 12:10:01 +0000509#endif
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000510
511/* int func (object) */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000512static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000513call_forms_Ri (int (*func)(FL_OBJECT *), FL_OBJECT *obj)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000514{
Guido van Rossum03747111991-08-08 12:10:01 +0000515 int retval;
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000516
Guido van Rossum03747111991-08-08 12:10:01 +0000517 retval = (*func) (obj);
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000518
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000519 return PyInt_FromLong ((long) retval);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000520}
521
522/* char * func (object) */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000523static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000524call_forms_Rstr (char * (*func)(FL_OBJECT *), FL_OBJECT *obj)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000525{
Guido van Rossum03747111991-08-08 12:10:01 +0000526 char *str;
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000527
Guido van Rossum03747111991-08-08 12:10:01 +0000528 str = (*func) (obj);
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000529
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000530 if (str == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000531 Py_INCREF(Py_None);
532 return Py_None;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000533 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000534 return PyString_FromString (str);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000535}
536
537/* int func (object) */
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000538static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000539call_forms_Rf (float (*func)(FL_OBJECT *), FL_OBJECT *obj)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000540{
Guido van Rossum03747111991-08-08 12:10:01 +0000541 float retval;
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000542
Guido van Rossum03747111991-08-08 12:10:01 +0000543 retval = (*func) (obj);
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000544
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000545 return PyFloat_FromDouble (retval);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000546}
547
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000548static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000549call_forms_OUTfOUTf (void (*func)(FL_OBJECT *, float *, float *), FL_OBJECT *obj)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000550{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000551 float f1, f2;
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000552
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000553 (*func) (obj, &f1, &f2);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000554
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000555 return Py_BuildValue("(ff)", f1, f2);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000556}
557
Guido van Rossum03747111991-08-08 12:10:01 +0000558#ifdef UNUSED
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000559static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000560call_forms_OUTf (void (*func)(FL_OBJECT *, float *), FL_OBJECT *obj)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000561{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000562 float f;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000563
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000564 (*func) (obj, &f);
565
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000566 return PyFloat_FromDouble (f);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000567}
Guido van Rossum03747111991-08-08 12:10:01 +0000568#endif
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000569
570/**********************************************************************/
571/* Class : browser */
572
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000573static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000574set_browser_topline(genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000575{
Guido van Rossum03747111991-08-08 12:10:01 +0000576 return call_forms_INi (fl_set_browser_topline, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000577}
578
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000579static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000580clear_browser(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000581{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000582 return generic_call (g, fl_clear_browser);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000583}
584
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000585static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000586add_browser_line (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000587{
Guido van Rossum03747111991-08-08 12:10:01 +0000588 return call_forms_INstr (fl_add_browser_line, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000589}
590
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000591static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000592addto_browser (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000593{
Guido van Rossum03747111991-08-08 12:10:01 +0000594 return call_forms_INstr (fl_addto_browser, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000595}
596
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000597static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000598insert_browser_line (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000599{
Guido van Rossum03747111991-08-08 12:10:01 +0000600 return call_forms_INiINstr (fl_insert_browser_line,
601 g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000602}
603
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000604static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000605delete_browser_line (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000606{
Guido van Rossum03747111991-08-08 12:10:01 +0000607 return call_forms_INi (fl_delete_browser_line, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000608}
609
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000610static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000611replace_browser_line (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000612{
Guido van Rossum03747111991-08-08 12:10:01 +0000613 return call_forms_INiINstr (fl_replace_browser_line,
614 g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000615}
616
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000617static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000618get_browser_line(genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000619{
620 int i;
621 char *str;
622
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000623 if (!PyArg_Parse(args, "i", &i))
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000624 return NULL;
625
626 str = fl_get_browser_line (g->ob_generic, i);
627
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000628 if (str == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000629 Py_INCREF(Py_None);
630 return Py_None;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000631 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000632 return PyString_FromString (str);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000633}
634
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000635static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000636load_browser (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000637{
Guido van Rossumabe58351991-08-08 12:34:44 +0000638 /* XXX strictly speaking this is wrong since fl_load_browser
639 XXX returns int, not void */
Guido van Rossum03747111991-08-08 12:10:01 +0000640 return call_forms_INstr (fl_load_browser, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000641}
642
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000643static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000644get_browser_maxline(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000645{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000646 return call_forms_Ri (fl_get_browser_maxline, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000647}
648
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000649static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000650select_browser_line (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000651{
Guido van Rossum03747111991-08-08 12:10:01 +0000652 return call_forms_INi (fl_select_browser_line, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000653}
654
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000655static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000656deselect_browser_line (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000657{
Guido van Rossum03747111991-08-08 12:10:01 +0000658 return call_forms_INi (fl_deselect_browser_line, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000659}
660
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000661static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000662deselect_browser (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000663{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000664 return generic_call (g, fl_deselect_browser);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000665}
666
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000667static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000668isselected_browser_line (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000669{
670 int i, j;
Guido van Rossum03747111991-08-08 12:10:01 +0000671
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000672 if (!PyArg_Parse(args, "i", &i))
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000673 return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +0000674
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000675 j = fl_isselected_browser_line (g->ob_generic, i);
Guido van Rossum03747111991-08-08 12:10:01 +0000676
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000677 return PyInt_FromLong (j);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000678}
679
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000680static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000681get_browser (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000682{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000683 return call_forms_Ri (fl_get_browser, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000684}
685
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000686static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000687set_browser_fontsize (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000688{
Guido van Rossum03747111991-08-08 12:10:01 +0000689 return call_forms_INf (fl_set_browser_fontsize, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000690}
691
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000692static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000693set_browser_fontstyle (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000694{
Guido van Rossum03747111991-08-08 12:10:01 +0000695 return call_forms_INi (fl_set_browser_fontstyle, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000696}
697
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000698static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000699set_browser_specialkey (genericobject *g, PyObject *args)
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000700{
701 return call_forms_INc(fl_set_browser_specialkey, g-> ob_generic, args);
702}
703
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000704static PyMethodDef browser_methods[] = {
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000705 {"set_browser_topline", (PyCFunction)set_browser_topline,
706 METH_OLDARGS},
707 {"clear_browser", (PyCFunction)clear_browser,
708 METH_NOARGS},
709 {"add_browser_line", (PyCFunction)add_browser_line,
710 METH_OLDARGS},
711 {"addto_browser", (PyCFunction)addto_browser,
712 METH_OLDARGS},
713 {"insert_browser_line", (PyCFunction)insert_browser_line,
714 METH_OLDARGS},
715 {"delete_browser_line", (PyCFunction)delete_browser_line,
716 METH_OLDARGS},
717 {"replace_browser_line", (PyCFunction)replace_browser_line,
718 METH_OLDARGS},
719 {"get_browser_line", (PyCFunction)get_browser_line,
720 METH_OLDARGS},
721 {"load_browser", (PyCFunction)load_browser,
722 METH_OLDARGS},
723 {"get_browser_maxline", (PyCFunction)get_browser_maxline,
724 METH_NOARGS,}
725 {"select_browser_line", (PyCFunction)select_browser_line,
726 METH_OLDARGS},
727 {"deselect_browser_line", (PyCFunction)deselect_browser_line,
728 METH_OLDARGS},
729 {"deselect_browser", (PyCFunction)deselect_browser,
730 METH_NOARGS,}
731 {"isselected_browser_line", (PyCFunction)isselected_browser_line,
732 METH_OLDARGS},
733 {"get_browser", (PyCFunction)get_browser,
734 METH_NOARGS,}
735 {"set_browser_fontsize", (PyCFunction)set_browser_fontsize,
736 METH_OLDARGS},
737 {"set_browser_fontstyle", (PyCFunction)set_browser_fontstyle,
738 METH_OLDARGS},
739 {"set_browser_specialkey", (PyCFunction)set_browser_specialkey,
740 METH_OLDARGS},
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000741 {NULL, NULL} /* sentinel */
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000742};
743
744/* Class: button */
745
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000746static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000747set_button(genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000748{
Guido van Rossum03747111991-08-08 12:10:01 +0000749 return call_forms_INi (fl_set_button, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000750}
751
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000752static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000753get_button(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000754{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000755 return call_forms_Ri (fl_get_button, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000756}
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000757
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000758static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000759get_button_numb(genericobject *g)
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000760{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000761 return call_forms_Ri (fl_get_button_numb, g-> ob_generic);
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000762}
763
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000764static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000765set_button_shortcut(genericobject *g, PyObject *args)
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000766{
767 return call_forms_INstr (fl_set_button_shortcut, g-> ob_generic, args);
768}
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000769
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000770static PyMethodDef button_methods[] = {
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000771 {"set_button", (PyCFunction)set_button, METH_OLDARGS},
772 {"get_button", (PyCFunction)get_button, METH_NOARGS},
773 {"get_button_numb", (PyCFunction)get_button_numb, METH_NOARGS},
774 {"set_button_shortcut", (PyCFunction)set_button_shortcut, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000775 {NULL, NULL} /* sentinel */
776};
777
778/* Class: choice */
779
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000780static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000781set_choice(genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000782{
Guido van Rossum03747111991-08-08 12:10:01 +0000783 return call_forms_INi (fl_set_choice, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000784}
785
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000786static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000787get_choice(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000788{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000789 return call_forms_Ri (fl_get_choice, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000790}
791
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000792static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000793clear_choice (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000794{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000795 return generic_call (g, fl_clear_choice);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000796}
797
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000798static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000799addto_choice (genericobject *g, PyObject *args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000800{
Guido van Rossum03747111991-08-08 12:10:01 +0000801 return call_forms_INstr (fl_addto_choice, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000802}
803
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000804static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000805replace_choice (genericobject *g, PyObject *args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000806{
Guido van Rossum03747111991-08-08 12:10:01 +0000807 return call_forms_INiINstr (fl_replace_choice, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000808}
809
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000810static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000811delete_choice (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000812{
Guido van Rossum03747111991-08-08 12:10:01 +0000813 return call_forms_INi (fl_delete_choice, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000814}
815
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000816static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000817get_choice_text (genericobject *g)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000818{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000819 return call_forms_Rstr (fl_get_choice_text, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000820}
821
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000822static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000823set_choice_fontsize (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000824{
Guido van Rossum03747111991-08-08 12:10:01 +0000825 return call_forms_INf (fl_set_choice_fontsize, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000826}
827
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000828static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000829set_choice_fontstyle (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000830{
Guido van Rossum03747111991-08-08 12:10:01 +0000831 return call_forms_INi (fl_set_choice_fontstyle, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000832}
833
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000834static PyMethodDef choice_methods[] = {
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000835 {"set_choice", (PyCFunction)set_choice, METH_OLDARGS},
836 {"get_choice", (PyCFunction)get_choice, METH_NOARGS},
837 {"clear_choice", (PyCFunction)clear_choice, METH_NOARGS},
838 {"addto_choice", (PyCFunction)addto_choice, METH_OLDARGS},
839 {"replace_choice", (PyCFunction)replace_choice, METH_OLDARGS},
840 {"delete_choice", (PyCFunction)delete_choice, METH_OLDARGS},
841 {"get_choice_text", (PyCFunction)get_choice_text, METH_NOARGS},
842 {"set_choice_fontsize", (PyCFunction)set_choice_fontsize, METH_OLDARGS},
843 {"set_choice_fontstyle",(PyCFunction)set_choice_fontstyle, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000844 {NULL, NULL} /* sentinel */
845};
846
847/* Class : Clock */
848
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000849static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000850get_clock(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000851{
852 int i0, i1, i2;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000853
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000854 fl_get_clock (g->ob_generic, &i0, &i1, &i2);
855
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000856 return Py_BuildValue("(iii)", i0, i1, i2);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000857}
858
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000859static PyMethodDef clock_methods[] = {
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000860 {"get_clock", (PyCFunction)get_clock, METH_NOARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000861 {NULL, NULL} /* sentinel */
862};
863
864/* CLass : Counters */
865
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000866static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000867get_counter_value(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000868{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000869 return call_forms_Rf (fl_get_counter_value, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000870}
871
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000872static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000873set_counter_value (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000874{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000875 return call_forms_INf (fl_set_counter_value, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000876}
877
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000878static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000879set_counter_precision (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000880{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000881 return call_forms_INi (fl_set_counter_precision, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000882}
883
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000884static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000885set_counter_bounds (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000886{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000887 return call_forms_INfINf (fl_set_counter_bounds, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000888}
889
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000890static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000891set_counter_step (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000892{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000893 return call_forms_INfINf (fl_set_counter_step, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000894}
895
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000896static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000897set_counter_return (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000898{
Guido van Rossum03747111991-08-08 12:10:01 +0000899 return call_forms_INi (fl_set_counter_return, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000900}
901
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000902static PyMethodDef counter_methods[] = {
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000903 {"set_counter_value", (PyCFunction)set_counter_value,
904 METH_OLDARGS},
905 {"get_counter_value", (PyCFunction)get_counter_value,
906 METH_NOARGS},
907 {"set_counter_bounds", (PyCFunction)set_counter_bounds,
908 METH_OLDARGS},
909 {"set_counter_step", (PyCFunction)set_counter_step,
910 METH_OLDARGS},
911 {"set_counter_precision", (PyCFunction)set_counter_precision,
912 METH_OLDARGS},
913 {"set_counter_return", (PyCFunction)set_counter_return,
914 METH_OLDARGS},
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000915 {NULL, NULL} /* sentinel */
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000916};
917
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000918
919/* Class: Dials */
920
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000921static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000922get_dial_value(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000923{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000924 return call_forms_Rf (fl_get_dial_value, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000925}
926
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000927static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000928set_dial_value (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000929{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000930 return call_forms_INf (fl_set_dial_value, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000931}
932
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000933static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000934set_dial_bounds (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000935{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000936 return call_forms_INfINf (fl_set_dial_bounds, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000937}
938
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000939static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000940get_dial_bounds (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000941{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000942 return call_forms_OUTfOUTf (fl_get_dial_bounds, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000943}
944
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000945static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000946set_dial_step (genericobject *g, PyObject *args)
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000947{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000948 return call_forms_INf (fl_set_dial_step, g-> ob_generic, args);
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000949}
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000950
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000951static PyMethodDef dial_methods[] = {
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000952 {"set_dial_value", (PyCFunction)set_dial_value, METH_OLDARGS},
953 {"get_dial_value", (PyCFunction)get_dial_value, METH_NOARGS},
954 {"set_dial_bounds", (PyCFunction)set_dial_bounds, METH_OLDARGS},
955 {"get_dial_bounds", (PyCFunction)get_dial_bounds, METH_NOARGS},
956 {"set_dial_step", (PyCFunction)set_dial_step, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000957 {NULL, NULL} /* sentinel */
958};
959
960/* Class : Input */
961
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000962static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000963set_input (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000964{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000965 return call_forms_INstr (fl_set_input, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000966}
967
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000968static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000969get_input (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000970{
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000971 return call_forms_Rstr (fl_get_input, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000972}
973
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000974static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000975set_input_color (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000976{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000977 return call_forms_INfINf (fl_set_input_color, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000978}
979
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000980static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000981set_input_return (genericobject *g, PyObject *args)
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000982{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000983 return call_forms_INi (fl_set_input_return, g-> ob_generic, args);
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000984}
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000985
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000986static PyMethodDef input_methods[] = {
Neal Norwitz28faa1b2002-03-31 15:56:56 +0000987 {"set_input", (PyCFunction)set_input, METH_OLDARGS},
988 {"get_input", (PyCFunction)get_input, METH_NOARGS},
989 {"set_input_color", (PyCFunction)set_input_color, METH_OLDARGS},
990 {"set_input_return", (PyCFunction)set_input_return, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000991 {NULL, NULL} /* sentinel */
992};
993
994
995/* Class : Menu */
996
Roger E. Masse7ba4c071997-01-03 22:17:11 +0000997static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000998set_menu (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000999{
Guido van Rossumabe58351991-08-08 12:34:44 +00001000 return call_forms_INstr (fl_set_menu, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001001}
1002
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001003static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001004get_menu (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001005{
Guido van Rossumabe58351991-08-08 12:34:44 +00001006 /* XXX strictly speaking this is wrong since fl_get_menu
1007 XXX returns long, not int */
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001008 return call_forms_Ri (fl_get_menu, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001009}
1010
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001011static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001012get_menu_text (genericobject *g)
Guido van Rossum8b17d6b1993-03-30 13:18:41 +00001013{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001014 return call_forms_Rstr (fl_get_menu_text, g-> ob_generic);
Guido van Rossum8b17d6b1993-03-30 13:18:41 +00001015}
1016
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001017static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001018addto_menu (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001019{
Guido van Rossumabe58351991-08-08 12:34:44 +00001020 return call_forms_INstr (fl_addto_menu, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001021}
1022
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001023static PyMethodDef menu_methods[] = {
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001024 {"set_menu", (PyCFunction)set_menu, METH_OLDARGS},
1025 {"get_menu", (PyCFunction)get_menu, METH_NOARGS},
1026 {"get_menu_text", (PyCFunction)get_menu_text, METH_NOARGS},
1027 {"addto_menu", (PyCFunction)addto_menu, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001028 {NULL, NULL} /* sentinel */
1029};
1030
1031
1032/* Class: Sliders */
1033
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001034static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001035get_slider_value(genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001036{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001037 return call_forms_Rf (fl_get_slider_value, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001038}
1039
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001040static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001041set_slider_value (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001042{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001043 return call_forms_INf (fl_set_slider_value, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001044}
1045
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001046static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001047set_slider_bounds (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001048{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001049 return call_forms_INfINf (fl_set_slider_bounds, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001050}
1051
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001052static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001053get_slider_bounds (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001054{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001055 return call_forms_OUTfOUTf(fl_get_slider_bounds, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001056}
1057
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001058static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001059set_slider_return (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001060{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001061 return call_forms_INf (fl_set_slider_return, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001062}
1063
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001064static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001065set_slider_size (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001066{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001067 return call_forms_INf (fl_set_slider_size, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001068}
1069
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001070static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001071set_slider_precision (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001072{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001073 return call_forms_INi (fl_set_slider_precision, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001074}
1075
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001076static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001077set_slider_step (genericobject *g, PyObject *args)
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001078{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001079 return call_forms_INf (fl_set_slider_step, g-> ob_generic, args);
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001080}
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001081
1082
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001083static PyMethodDef slider_methods[] = {
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001084 {"set_slider_value", (PyCFunction)set_slider_value, METH_OLDARGS},
1085 {"get_slider_value", (PyCFunction)get_slider_value, METH_NOARGS},
1086 {"set_slider_bounds", (PyCFunction)set_slider_bounds, METH_OLDARGS},
1087 {"get_slider_bounds", (PyCFunction)get_slider_bounds, METH_NOARGS},
1088 {"set_slider_return", (PyCFunction)set_slider_return, METH_OLDARGS},
1089 {"set_slider_size", (PyCFunction)set_slider_size, METH_OLDARGS},
1090 {"set_slider_precision",(PyCFunction)set_slider_precision, METH_OLDARGS},
1091 {"set_slider_step", (PyCFunction)set_slider_step, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001092 {NULL, NULL} /* sentinel */
1093};
1094
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001095static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001096set_positioner_xvalue (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001097{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001098 return call_forms_INf (fl_set_positioner_xvalue, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001099}
1100
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001101static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001102set_positioner_xbounds (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001103{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001104 return call_forms_INfINf (fl_set_positioner_xbounds,
1105 g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001106}
1107
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001108static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001109set_positioner_yvalue (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001110{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001111 return call_forms_INf (fl_set_positioner_yvalue, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001112}
1113
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001114static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001115set_positioner_ybounds (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001116{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001117 return call_forms_INfINf (fl_set_positioner_ybounds,
1118 g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001119}
1120
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001121static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001122get_positioner_xvalue (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001123{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001124 return call_forms_Rf (fl_get_positioner_xvalue, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001125}
1126
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001127static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001128get_positioner_xbounds (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001129{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001130 return call_forms_OUTfOUTf (fl_get_positioner_xbounds, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001131}
1132
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001133static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001134get_positioner_yvalue (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001135{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001136 return call_forms_Rf (fl_get_positioner_yvalue, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001137}
1138
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001139static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001140get_positioner_ybounds (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001141{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001142 return call_forms_OUTfOUTf (fl_get_positioner_ybounds, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001143}
1144
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001145static PyMethodDef positioner_methods[] = {
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001146 {"set_positioner_xvalue", (PyCFunction)set_positioner_xvalue,
1147 METH_OLDARGS},
1148 {"set_positioner_yvalue", (PyCFunction)set_positioner_yvalue,
1149 METH_OLDARGS},
1150 {"set_positioner_xbounds", (PyCFunction)set_positioner_xbounds,
1151 METH_OLDARGS},
1152 {"set_positioner_ybounds", (PyCFunction)set_positioner_ybounds,
1153 METH_OLDARGS},
1154 {"get_positioner_xvalue", (PyCFunction)get_positioner_xvalue,
1155 METH_NOARGS},
1156 {"get_positioner_yvalue", (PyCFunction)get_positioner_yvalue,
1157 METH_NOARGS},
1158 {"get_positioner_xbounds", (PyCFunction)get_positioner_xbounds,
1159 METH_NOARGS},
1160 {"get_positioner_ybounds", (PyCFunction)get_positioner_ybounds,
1161 METH_NOARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001162 {NULL, NULL} /* sentinel */
1163};
1164
1165/* Class timer */
1166
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001167static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001168set_timer (genericobject *g, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001169{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001170 return call_forms_INf (fl_set_timer, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001171}
1172
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001173static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001174get_timer (genericobject *g)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001175{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001176 return call_forms_Rf (fl_get_timer, g-> ob_generic);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001177}
1178
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001179static PyMethodDef timer_methods[] = {
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001180 {"set_timer", (PyCFunction)set_timer, METH_OLDARGS},
1181 {"get_timer", (PyCFunction)get_timer, METH_NOARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001182 {NULL, NULL} /* sentinel */
1183};
1184
1185/* Form objects */
1186
1187typedef struct {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001188 PyObject_HEAD
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001189 FL_FORM *ob_form;
1190} formobject;
1191
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001192staticforward PyTypeObject Formtype;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001193
1194#define is_formobject(v) ((v)->ob_type == &Formtype)
1195
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001196static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001197form_show_form(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001198{
1199 int place, border;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001200 char *name;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001201 if (!PyArg_Parse(args, "(iis)", &place, &border, &name))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001202 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001203 fl_show_form(f->ob_form, place, border, name);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001204 Py_INCREF(Py_None);
1205 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001206}
1207
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001208static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001209form_call(void (*func)(FL_FORM *), FL_FORM *f)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001210{
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001211 (*func)(f);
1212
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001213 Py_INCREF(Py_None);
1214 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001215}
1216
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001217static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001218form_call_INiINi(void (*func)(FL_FORM *, int, int), FL_FORM *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001219{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001220 int a, b;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001221
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001222 if (!PyArg_Parse(args, "(ii)", &a, &b)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001223
1224 (*func)(f, a, b);
1225
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001226 Py_INCREF(Py_None);
1227 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001228}
1229
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001230static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001231form_call_INfINf(void (*func)(FL_FORM *, float, float), FL_FORM *f, PyObject *args)
Guido van Rossumf1dc5661993-07-05 10:31:29 +00001232{
1233 float a, b;
1234
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001235 if (!PyArg_Parse(args, "(ff)", &a, &b)) return NULL;
Guido van Rossumf1dc5661993-07-05 10:31:29 +00001236
1237 (*func)(f, a, b);
1238
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001239 Py_INCREF(Py_None);
1240 return Py_None;
Guido van Rossumf1dc5661993-07-05 10:31:29 +00001241}
1242
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001243static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001244form_hide_form(formobject *f)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001245{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001246 return form_call(fl_hide_form, f-> ob_form);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001247}
1248
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001249static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001250form_redraw_form(formobject *f)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001251{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001252 return form_call(fl_redraw_form, f-> ob_form);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001253}
1254
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001255static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001256form_set_form_position(formobject *f, PyObject *args)
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001257{
1258 return form_call_INiINi(fl_set_form_position, f-> ob_form, args);
1259}
1260
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001261static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001262form_set_form_size(formobject *f, PyObject *args)
Guido van Rossumf1dc5661993-07-05 10:31:29 +00001263{
1264 return form_call_INiINi(fl_set_form_size, f-> ob_form, args);
1265}
1266
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001267static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001268form_scale_form(formobject *f, PyObject *args)
Guido van Rossumf1dc5661993-07-05 10:31:29 +00001269{
1270 return form_call_INfINf(fl_scale_form, f-> ob_form, args);
1271}
1272
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001273static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001274generic_add_object(formobject *f, PyObject *args, FL_OBJECT *(*func)(int, float, float, float, float, char*), PyMethodDef *internal_methods)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001275{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001276 int type;
1277 float x, y, w, h;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001278 char *name;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001279 FL_OBJECT *obj;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001280
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001281 if (!PyArg_Parse(args,"(iffffs)", &type,&x,&y,&w,&h,&name))
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001282 return NULL;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001283
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001284 fl_addto_form (f-> ob_form);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001285
Guido van Rossumfc58e581992-01-27 16:45:55 +00001286 obj = (*func) (type, x, y, w, h, name);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001287
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001288 fl_end_form();
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001289
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001290 if (obj == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001291 PyErr_NoMemory();
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001292 return NULL;
1293 }
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001294
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001295 return newgenericobject (obj, internal_methods);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001296}
1297
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001298static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001299form_add_button(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001300{
1301 return generic_add_object(f, args, fl_add_button, button_methods);
1302}
1303
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001304static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001305form_add_lightbutton(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001306{
1307 return generic_add_object(f, args, fl_add_lightbutton, button_methods);
1308}
1309
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001310static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001311form_add_roundbutton(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001312{
1313 return generic_add_object(f, args, fl_add_roundbutton, button_methods);
1314}
1315
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001316static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001317form_add_menu (formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001318{
1319 return generic_add_object(f, args, fl_add_menu, menu_methods);
1320}
1321
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001322static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001323form_add_slider(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001324{
1325 return generic_add_object(f, args, fl_add_slider, slider_methods);
1326}
1327
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001328static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001329form_add_valslider(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001330{
1331 return generic_add_object(f, args, fl_add_valslider, slider_methods);
1332}
1333
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001334static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001335form_add_dial(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001336{
1337 return generic_add_object(f, args, fl_add_dial, dial_methods);
1338}
1339
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001340static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001341form_add_counter(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001342{
1343 return generic_add_object(f, args, fl_add_counter, counter_methods);
1344}
1345
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001346static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001347form_add_clock(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001348{
1349 return generic_add_object(f, args, fl_add_clock, clock_methods);
1350}
1351
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001352static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001353form_add_box(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001354{
Guido van Rossum03747111991-08-08 12:10:01 +00001355 return generic_add_object(f, args, fl_add_box,
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001356 (PyMethodDef *)NULL);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001357}
1358
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001359static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001360form_add_choice(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001361{
1362 return generic_add_object(f, args, fl_add_choice, choice_methods);
1363}
1364
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001365static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001366form_add_browser(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001367{
1368 return generic_add_object(f, args, fl_add_browser, browser_methods);
1369}
1370
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001371static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001372form_add_positioner(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001373{
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001374 return generic_add_object(f, args, fl_add_positioner,
1375 positioner_methods);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001376}
1377
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001378static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001379form_add_input(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001380{
1381 return generic_add_object(f, args, fl_add_input, input_methods);
1382}
1383
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001384static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001385form_add_text(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001386{
Guido van Rossum03747111991-08-08 12:10:01 +00001387 return generic_add_object(f, args, fl_add_text,
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001388 (PyMethodDef *)NULL);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001389}
1390
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001391static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001392form_add_timer(formobject *f, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001393{
1394 return generic_add_object(f, args, fl_add_timer, timer_methods);
1395}
1396
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001397static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001398form_freeze_form(formobject *f)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001399{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001400 return form_call(fl_freeze_form, f-> ob_form);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001401}
1402
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001403static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001404form_unfreeze_form(formobject *f)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001405{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001406 return form_call(fl_unfreeze_form, f-> ob_form);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001407}
1408
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001409static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001410form_activate_form(formobject *f)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001411{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001412 return form_call(fl_activate_form, f-> ob_form);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001413}
1414
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001415static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001416form_deactivate_form(formobject *f)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001417{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001418 return form_call(fl_deactivate_form, f-> ob_form);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001419}
1420
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001421static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001422form_bgn_group(formobject *f, PyObject *args)
Guido van Rossum03747111991-08-08 12:10:01 +00001423{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001424 FL_OBJECT *obj;
1425
1426 fl_addto_form(f-> ob_form);
1427 obj = fl_bgn_group();
1428 fl_end_form();
1429
1430 if (obj == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001431 PyErr_NoMemory();
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001432 return NULL;
1433 }
1434
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001435 return newgenericobject (obj, (PyMethodDef *) NULL);
Guido van Rossum03747111991-08-08 12:10:01 +00001436}
1437
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001438static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001439form_end_group(formobject *f, PyObject *args)
Guido van Rossum03747111991-08-08 12:10:01 +00001440{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001441 fl_addto_form(f-> ob_form);
Guido van Rossum03747111991-08-08 12:10:01 +00001442 fl_end_group();
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001443 fl_end_form();
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001444 Py_INCREF(Py_None);
1445 return Py_None;
Guido van Rossum03747111991-08-08 12:10:01 +00001446}
1447
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001448static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001449forms_find_first_or_last(FL_OBJECT *(*func)(FL_FORM *, int, float, float), formobject *f, PyObject *args)
Guido van Rossum75cc8981991-08-08 12:07:45 +00001450{
1451 int type;
1452 float mx, my;
1453 FL_OBJECT *generic;
1454 genericobject *g;
1455
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001456 if (!PyArg_Parse(args, "(iff)", &type, &mx, &my)) return NULL;
Guido van Rossum75cc8981991-08-08 12:07:45 +00001457
Guido van Rossum03747111991-08-08 12:10:01 +00001458 generic = (*func) (f-> ob_form, type, mx, my);
Guido van Rossum75cc8981991-08-08 12:07:45 +00001459
1460 if (generic == NULL)
1461 {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001462 Py_INCREF(Py_None);
1463 return Py_None;
Guido van Rossum75cc8981991-08-08 12:07:45 +00001464 }
1465
1466 g = findgeneric(generic);
1467 if (g == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001468 PyErr_SetString(PyExc_RuntimeError,
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001469 "forms_find_{first|last} returns unknown object");
Guido van Rossum75cc8981991-08-08 12:07:45 +00001470 return NULL;
1471 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001472 Py_INCREF(g);
1473 return (PyObject *) g;
Guido van Rossum75cc8981991-08-08 12:07:45 +00001474}
1475
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001476static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001477form_find_first(formobject *f, PyObject *args)
Guido van Rossum75cc8981991-08-08 12:07:45 +00001478{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001479 return forms_find_first_or_last(fl_find_first, f, args);
Guido van Rossum75cc8981991-08-08 12:07:45 +00001480}
1481
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001482static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001483form_find_last(formobject *f, PyObject *args)
Guido van Rossum75cc8981991-08-08 12:07:45 +00001484{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001485 return forms_find_first_or_last(fl_find_last, f, args);
Guido van Rossum75cc8981991-08-08 12:07:45 +00001486}
1487
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001488static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001489form_set_object_focus(formobject *f, PyObject *args)
Guido van Rossum7066dd71992-09-17 17:54:56 +00001490{
1491 genericobject *g;
1492 if (args == NULL || !is_genericobject(args)) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001493 PyErr_BadArgument();
Guido van Rossum7066dd71992-09-17 17:54:56 +00001494 return NULL;
1495 }
1496 g = (genericobject *)args;
1497 fl_set_object_focus(f->ob_form, g->ob_generic);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001498 Py_INCREF(Py_None);
1499 return Py_None;
Guido van Rossum7066dd71992-09-17 17:54:56 +00001500}
1501
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001502static PyMethodDef form_methods[] = {
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001503/* adm */
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001504 {"show_form", (PyCFunction)form_show_form, METH_OLDARGS},
1505 {"hide_form", (PyCFunction)form_hide_form, METH_NOARGS},
1506 {"redraw_form", (PyCFunction)form_redraw_form, METH_NOARGS},
1507 {"set_form_position", (PyCFunction)form_set_form_position, METH_OLDARGS},
1508 {"set_form_size", (PyCFunction)form_set_form_size, METH_OLDARGS},
1509 {"scale_form", (PyCFunction)form_scale_form, METH_OLDARGS},
1510 {"freeze_form", (PyCFunction)form_freeze_form, METH_NOARGS},
1511 {"unfreeze_form", (PyCFunction)form_unfreeze_form, METH_NOARGS},
1512 {"activate_form", (PyCFunction)form_activate_form, METH_NOARGS},
1513 {"deactivate_form", (PyCFunction)form_deactivate_form, METH_NOARGS},
1514 {"bgn_group", (PyCFunction)form_bgn_group, METH_OLDARGS},
1515 {"end_group", (PyCFunction)form_end_group, METH_OLDARGS},
1516 {"find_first", (PyCFunction)form_find_first, METH_OLDARGS},
1517 {"find_last", (PyCFunction)form_find_last, METH_OLDARGS},
1518 {"set_object_focus", (PyCFunction)form_set_object_focus, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001519
1520/* basic objects */
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001521 {"add_button", (PyCFunction)form_add_button, METH_OLDARGS},
1522/* {"add_bitmap", (method)form_add_bitmap, METH_OLDARGS}, */
1523 {"add_lightbutton", (PyCFunction)form_add_lightbutton, METH_OLDARGS},
1524 {"add_roundbutton", (PyCFunction)form_add_roundbutton, METH_OLDARGS},
1525 {"add_menu", (PyCFunction)form_add_menu, METH_OLDARGS},
1526 {"add_slider", (PyCFunction)form_add_slider, METH_OLDARGS},
1527 {"add_positioner", (PyCFunction)form_add_positioner, METH_OLDARGS},
1528 {"add_valslider", (PyCFunction)form_add_valslider, METH_OLDARGS},
1529 {"add_dial", (PyCFunction)form_add_dial, METH_OLDARGS},
1530 {"add_counter", (PyCFunction)form_add_counter, METH_OLDARGS},
1531 {"add_box", (PyCFunction)form_add_box, METH_OLDARGS},
1532 {"add_clock", (PyCFunction)form_add_clock, METH_OLDARGS},
1533 {"add_choice", (PyCFunction)form_add_choice, METH_OLDARGS},
1534 {"add_browser", (PyCFunction)form_add_browser, METH_OLDARGS},
1535 {"add_input", (PyCFunction)form_add_input, METH_OLDARGS},
1536 {"add_timer", (PyCFunction)form_add_timer, METH_OLDARGS},
1537 {"add_text", (PyCFunction)form_add_text, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001538 {NULL, NULL} /* sentinel */
1539};
1540
1541static void
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001542form_dealloc(formobject *f)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001543{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001544 releaseobjects(f->ob_form);
Guido van Rossum336b5911992-04-08 11:16:25 +00001545 if (f->ob_form->visible)
1546 fl_hide_form(f->ob_form);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001547 fl_free_form(f->ob_form);
Guido van Rossumb18618d2000-05-03 23:44:39 +00001548 PyObject_Del(f);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001549}
1550
Guido van Rossumd97f0481991-11-19 20:26:28 +00001551#define OFF(x) offsetof(FL_FORM, x)
1552
Guido van Rossum32db5e31991-11-12 15:43:18 +00001553static struct memberlist form_memberlist[] = {
1554 {"window", T_LONG, OFF(window), RO},
1555 {"w", T_FLOAT, OFF(w)},
1556 {"h", T_FLOAT, OFF(h)},
Guido van Rossum7066dd71992-09-17 17:54:56 +00001557 {"x", T_FLOAT, OFF(x), RO},
1558 {"y", T_FLOAT, OFF(y), RO},
Guido van Rossum32db5e31991-11-12 15:43:18 +00001559 {"deactivated", T_INT, OFF(deactivated)},
Guido van Rossum7066dd71992-09-17 17:54:56 +00001560 {"visible", T_INT, OFF(visible), RO},
1561 {"frozen", T_INT, OFF(frozen), RO},
Guido van Rossum32db5e31991-11-12 15:43:18 +00001562 {"doublebuf", T_INT, OFF(doublebuf)},
1563 {NULL} /* Sentinel */
1564};
1565
Guido van Rossumd97f0481991-11-19 20:26:28 +00001566#undef OFF
1567
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001568static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001569form_getattr(formobject *f, char *name)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001570{
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001571 PyObject *meth;
Guido van Rossum32db5e31991-11-12 15:43:18 +00001572
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001573 meth = Py_FindMethod(form_methods, (PyObject *)f, name);
Guido van Rossum32db5e31991-11-12 15:43:18 +00001574 if (meth != NULL)
1575 return meth;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001576 PyErr_Clear();
1577 return PyMember_Get((char *)f->ob_form, form_memberlist, name);
Guido van Rossum32db5e31991-11-12 15:43:18 +00001578}
1579
1580static int
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001581form_setattr(formobject *f, char *name, PyObject *v)
Guido van Rossum32db5e31991-11-12 15:43:18 +00001582{
Guido van Rossum32db5e31991-11-12 15:43:18 +00001583 if (v == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001584 PyErr_SetString(PyExc_TypeError,
1585 "can't delete form attributes");
Guido van Rossum3863abb1996-09-11 23:31:07 +00001586 return -1;
Guido van Rossum32db5e31991-11-12 15:43:18 +00001587 }
1588
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001589 return PyMember_Set((char *)f->ob_form, form_memberlist, name, v);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001590}
1591
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001592static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001593form_repr(formobject *f)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001594{
1595 char buf[100];
Tim Peters885d4572001-11-28 20:27:42 +00001596 PyOS_snprintf(buf, sizeof(buf), "<FORMS_form at %p, window=%ld>",
1597 f, f->ob_form->window);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001598 return PyString_FromString(buf);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001599}
1600
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001601static PyTypeObject Formtype = {
1602 PyObject_HEAD_INIT(&PyType_Type)
Guido van Rossumb6775db1994-08-01 11:34:53 +00001603 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +00001604 "fl.FORMS_form", /*tp_name*/
Guido van Rossumb6775db1994-08-01 11:34:53 +00001605 sizeof(formobject), /*tp_size*/
1606 0, /*tp_itemsize*/
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001607 /* methods */
Guido van Rossumb6775db1994-08-01 11:34:53 +00001608 (destructor)form_dealloc, /*tp_dealloc*/
1609 0, /*tp_print*/
1610 (getattrfunc)form_getattr, /*tp_getattr*/
1611 (setattrfunc)form_setattr, /*tp_setattr*/
1612 0, /*tp_compare*/
1613 (reprfunc)form_repr, /*tp_repr*/
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001614};
1615
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001616static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001617newformobject(FL_FORM *form)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001618{
1619 formobject *f;
Guido van Rossumb18618d2000-05-03 23:44:39 +00001620 f = PyObject_New(formobject, &Formtype);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001621 if (f == NULL)
1622 return NULL;
1623 f->ob_form = form;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001624 return (PyObject *)f;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001625}
1626
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001627
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001628/* The "fl" module */
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001629
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001630static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001631forms_make_form(PyObject *dummy, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001632{
1633 int type;
1634 float w, h;
1635 FL_FORM *form;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001636 if (!PyArg_Parse(args, "(iff)", &type, &w, &h))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001637 return NULL;
1638 form = fl_bgn_form(type, w, h);
1639 if (form == NULL) {
1640 /* XXX Actually, cannot happen! */
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001641 PyErr_NoMemory();
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001642 return NULL;
1643 }
1644 fl_end_form();
1645 return newformobject(form);
1646}
1647
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001648static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001649forms_activate_all_forms(PyObject *f, PyObject *args)
Guido van Rossum2bac4d31992-03-27 17:20:21 +00001650{
1651 fl_activate_all_forms();
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001652 Py_INCREF(Py_None);
1653 return Py_None;
Guido van Rossum2bac4d31992-03-27 17:20:21 +00001654}
1655
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001656static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001657forms_deactivate_all_forms(PyObject *f, PyObject *args)
Guido van Rossum2bac4d31992-03-27 17:20:21 +00001658{
1659 fl_deactivate_all_forms();
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001660 Py_INCREF(Py_None);
1661 return Py_None;
Guido van Rossum2bac4d31992-03-27 17:20:21 +00001662}
1663
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001664static PyObject *my_event_callback = NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001665
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001666static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001667forms_set_event_call_back(PyObject *dummy, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001668{
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001669 if (args == Py_None)
Guido van Rossumf6da4f61993-07-26 15:24:57 +00001670 args = NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001671 my_event_callback = args;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001672 Py_XINCREF(args);
1673 Py_INCREF(Py_None);
1674 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001675}
1676
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001677static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001678forms_do_or_check_forms(PyObject *dummy, FL_OBJECT *(*func)(void))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001679{
1680 FL_OBJECT *generic;
1681 genericobject *g;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001682 PyObject *arg, *res;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001683
1684 for (;;) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001685 Py_BEGIN_ALLOW_THREADS
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001686 generic = (*func)();
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001687 Py_END_ALLOW_THREADS
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001688 if (generic == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001689 Py_INCREF(Py_None);
1690 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001691 }
1692 if (generic == FL_EVENT) {
1693 int dev;
1694 short val;
1695 if (my_event_callback == NULL)
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001696 return PyInt_FromLong(-1L);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001697 dev = fl_qread(&val);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001698 arg = Py_BuildValue("(ih)", dev, val);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001699 if (arg == NULL)
1700 return NULL;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001701 res = PyEval_CallObject(my_event_callback, arg);
1702 Py_XDECREF(res);
1703 Py_DECREF(arg);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001704 if (res == NULL)
1705 return NULL; /* Callback raised exception */
1706 continue;
1707 }
1708 g = findgeneric(generic);
1709 if (g == NULL) {
Guido van Rossuma9e7dc11992-10-18 18:53:57 +00001710 /* Object not known to us (some dialogs cause this) */
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00001711 continue; /* Ignore it */
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001712 }
1713 if (g->ob_callback == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001714 Py_INCREF(g);
1715 return ((PyObject *) g);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001716 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001717 arg = Py_BuildValue("(OO)", (PyObject *)g, g->ob_callback_arg);
Guido van Rossume5372401993-03-16 12:15:04 +00001718 if (arg == NULL)
1719 return NULL;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001720 res = PyEval_CallObject(g->ob_callback, arg);
1721 Py_XDECREF(res);
1722 Py_DECREF(arg);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001723 if (res == NULL)
1724 return NULL; /* Callback raised exception */
1725 }
1726}
1727
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001728static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001729forms_do_forms(PyObject *dummy)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001730{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001731 return forms_do_or_check_forms(dummy, fl_do_forms);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001732}
1733
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001734static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001735forms_check_forms(PyObject *dummy)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001736{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001737 return forms_do_or_check_forms(dummy, fl_check_forms);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001738}
1739
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001740static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001741forms_do_only_forms(PyObject *dummy)
Guido van Rossum7066dd71992-09-17 17:54:56 +00001742{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001743 return forms_do_or_check_forms(dummy, fl_do_only_forms);
Guido van Rossum7066dd71992-09-17 17:54:56 +00001744}
1745
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001746static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001747forms_check_only_forms(PyObject *dummy)
Guido van Rossum7066dd71992-09-17 17:54:56 +00001748{
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001749 return forms_do_or_check_forms(dummy, fl_check_only_forms);
Guido van Rossum7066dd71992-09-17 17:54:56 +00001750}
1751
Guido van Rossum03747111991-08-08 12:10:01 +00001752#ifdef UNUSED
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001753static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001754fl_call(void (*func)(void))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001755{
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001756 (*func)();
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001757 Py_INCREF(Py_None);
1758 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001759}
Guido van Rossum03747111991-08-08 12:10:01 +00001760#endif
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001761
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001762static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001763forms_set_graphics_mode(PyObject *dummy, PyObject *args)
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001764{
1765 int rgbmode, doublebuf;
1766
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001767 if (!PyArg_Parse(args, "(ii)", &rgbmode, &doublebuf))
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001768 return NULL;
1769 fl_set_graphics_mode(rgbmode,doublebuf);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001770 Py_INCREF(Py_None);
1771 return Py_None;
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001772}
1773
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001774static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001775forms_get_rgbmode(PyObject *dummy, PyObject *args)
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001776{
Guido van Rossum7066dd71992-09-17 17:54:56 +00001777 extern int fl_rgbmode;
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001778
1779 if (args != NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001780 PyErr_BadArgument();
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001781 return NULL;
1782 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001783 return PyInt_FromLong((long)fl_rgbmode);
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001784}
Guido van Rossum7066dd71992-09-17 17:54:56 +00001785
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001786static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001787forms_show_errors(PyObject *dummy, PyObject *args)
Guido van Rossum7066dd71992-09-17 17:54:56 +00001788{
1789 int show;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001790 if (!PyArg_Parse(args, "i", &show))
Guido van Rossum7066dd71992-09-17 17:54:56 +00001791 return NULL;
1792 fl_show_errors(show);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001793 Py_INCREF(Py_None);
1794 return Py_None;
Guido van Rossum7066dd71992-09-17 17:54:56 +00001795}
1796
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001797static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001798forms_set_font_name(PyObject *dummy, PyObject *args)
Guido van Rossum7066dd71992-09-17 17:54:56 +00001799{
1800 int numb;
1801 char *name;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001802 if (!PyArg_Parse(args, "(is)", &numb, &name))
Guido van Rossum7066dd71992-09-17 17:54:56 +00001803 return NULL;
1804 fl_set_font_name(numb, name);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001805 Py_INCREF(Py_None);
1806 return Py_None;
Guido van Rossum7066dd71992-09-17 17:54:56 +00001807}
1808
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001809
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001810static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001811forms_qdevice(PyObject *self, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001812{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001813 short arg1;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001814 if (!PyArg_Parse(args, "h", &arg1))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001815 return NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001816 fl_qdevice(arg1);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001817 Py_INCREF(Py_None);
1818 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001819}
1820
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001821static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001822forms_unqdevice(PyObject *self, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001823{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001824 short arg1;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001825 if (!PyArg_Parse(args, "h", &arg1))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001826 return NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001827 fl_unqdevice(arg1);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001828 Py_INCREF(Py_None);
1829 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001830}
1831
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001832static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001833forms_isqueued(PyObject *self, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001834{
Guido van Rossum03747111991-08-08 12:10:01 +00001835 long retval;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001836 short arg1;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001837 if (!PyArg_Parse(args, "h", &arg1))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001838 return NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001839 retval = fl_isqueued(arg1);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001840
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001841 return PyInt_FromLong(retval);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001842}
1843
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001844static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001845forms_qtest(PyObject *self, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001846{
1847 long retval;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001848 retval = fl_qtest();
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001849 return PyInt_FromLong(retval);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001850}
1851
1852
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001853static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001854forms_qread(PyObject *self, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001855{
Guido van Rossume5372401993-03-16 12:15:04 +00001856 int dev;
1857 short val;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001858 Py_BEGIN_ALLOW_THREADS
Guido van Rossume5372401993-03-16 12:15:04 +00001859 dev = fl_qread(&val);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001860 Py_END_ALLOW_THREADS
1861 return Py_BuildValue("(ih)", dev, val);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001862}
1863
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001864static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001865forms_qreset(PyObject *self)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001866{
Guido van Rossum03747111991-08-08 12:10:01 +00001867 fl_qreset();
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001868 Py_INCREF(Py_None);
1869 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001870}
1871
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001872static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001873forms_qenter(PyObject *self, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001874{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001875 short arg1, arg2;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001876 if (!PyArg_Parse(args, "(hh)", &arg1, &arg2))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001877 return NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001878 fl_qenter(arg1, arg2);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001879 Py_INCREF(Py_None);
1880 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001881}
1882
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001883static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001884forms_color(PyObject *self, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001885{
1886 int arg;
1887
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001888 if (!PyArg_Parse(args, "i", &arg)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001889
1890 fl_color((short) arg);
1891
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001892 Py_INCREF(Py_None);
1893 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001894}
1895
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001896static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001897forms_mapcolor(PyObject *self, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001898{
1899 int arg0, arg1, arg2, arg3;
1900
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001901 if (!PyArg_Parse(args, "(iiii)", &arg0, &arg1, &arg2, &arg3))
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001902 return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001903
1904 fl_mapcolor(arg0, (short) arg1, (short) arg2, (short) arg3);
1905
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001906 Py_INCREF(Py_None);
1907 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001908}
1909
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001910static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001911forms_getmcolor(PyObject *self, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001912{
Guido van Rossum03747111991-08-08 12:10:01 +00001913 int arg;
1914 short r, g, b;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001915
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001916 if (!PyArg_Parse(args, "i", &arg)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001917
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001918 fl_getmcolor(arg, &r, &g, &b);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001919
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001920 return Py_BuildValue("(hhh)", r, g, b);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001921}
1922
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001923static PyObject *
Neal Norwitz28faa1b2002-03-31 15:56:56 +00001924forms_get_mouse(PyObject *self)
Guido van Rossum75cc8981991-08-08 12:07:45 +00001925{
Guido van Rossume5372401993-03-16 12:15:04 +00001926 float x, y;
Guido van Rossum75cc8981991-08-08 12:07:45 +00001927
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001928 fl_get_mouse(&x, &y);
Guido van Rossum75cc8981991-08-08 12:07:45 +00001929
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001930 return Py_BuildValue("(ff)", x, y);
Guido van Rossum75cc8981991-08-08 12:07:45 +00001931}
1932
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001933static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001934forms_tie(PyObject *self, PyObject *args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001935{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001936 short arg1, arg2, arg3;
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001937 if (!PyArg_Parse(args, "(hhh)", &arg1, &arg2, &arg3))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001938 return NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001939 fl_tie(arg1, arg2, arg3);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001940 Py_INCREF(Py_None);
1941 return Py_None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001942}
1943
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001944static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001945forms_show_message(PyObject *f, PyObject *args)
Guido van Rossum03747111991-08-08 12:10:01 +00001946{
Guido van Rossumfc58e581992-01-27 16:45:55 +00001947 char *a, *b, *c;
Guido van Rossum03747111991-08-08 12:10:01 +00001948
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001949 if (!PyArg_Parse(args, "(sss)", &a, &b, &c)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +00001950
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001951 Py_BEGIN_ALLOW_THREADS
Guido van Rossumfc58e581992-01-27 16:45:55 +00001952 fl_show_message(a, b, c);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001953 Py_END_ALLOW_THREADS
Guido van Rossum03747111991-08-08 12:10:01 +00001954
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001955 Py_INCREF(Py_None);
1956 return Py_None;
Guido van Rossum03747111991-08-08 12:10:01 +00001957}
1958
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001959static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001960forms_show_choice(PyObject *f, PyObject *args)
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00001961{
1962 char *m1, *m2, *m3, *b1, *b2, *b3;
1963 int nb;
1964 char *format;
Guido van Rossum7066dd71992-09-17 17:54:56 +00001965 long rv;
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00001966
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001967 if (args == NULL || !PyTuple_Check(args)) {
1968 PyErr_BadArgument();
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00001969 return NULL;
1970 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001971 nb = PyTuple_Size(args) - 3;
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00001972 if (nb <= 0) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001973 PyErr_SetString(PyExc_TypeError,
1974 "need at least one button label");
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00001975 return NULL;
1976 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001977 if (PyInt_Check(PyTuple_GetItem(args, 3))) {
1978 PyErr_SetString(PyExc_TypeError,
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00001979 "'number-of-buttons' argument not needed");
1980 return NULL;
1981 }
1982 switch (nb) {
1983 case 1: format = "(ssss)"; break;
1984 case 2: format = "(sssss)"; break;
1985 case 3: format = "(ssssss)"; break;
1986 default:
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001987 PyErr_SetString(PyExc_TypeError, "too many button labels");
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00001988 return NULL;
1989 }
1990
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001991 if (!PyArg_Parse(args, format, &m1, &m2, &m3, &b1, &b2, &b3))
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00001992 return NULL;
1993
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001994 Py_BEGIN_ALLOW_THREADS
Jack Jansen743db361992-08-13 14:13:11 +00001995 rv = fl_show_choice(m1, m2, m3, nb, b1, b2, b3);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00001996 Py_END_ALLOW_THREADS
1997 return PyInt_FromLong(rv);
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00001998}
1999
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002000static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00002001forms_show_question(PyObject *f, PyObject *args)
Guido van Rossum03747111991-08-08 12:10:01 +00002002{
Guido van Rossumfc58e581992-01-27 16:45:55 +00002003 int ret;
2004 char *a, *b, *c;
Guido van Rossum03747111991-08-08 12:10:01 +00002005
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002006 if (!PyArg_Parse(args, "(sss)", &a, &b, &c)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +00002007
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002008 Py_BEGIN_ALLOW_THREADS
Guido van Rossumfc58e581992-01-27 16:45:55 +00002009 ret = fl_show_question(a, b, c);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002010 Py_END_ALLOW_THREADS
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002011
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002012 return PyInt_FromLong((long) ret);
Guido van Rossum03747111991-08-08 12:10:01 +00002013}
2014
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002015static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00002016forms_show_input(PyObject *f, PyObject *args)
Guido van Rossum03747111991-08-08 12:10:01 +00002017{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002018 char *str;
Guido van Rossumfc58e581992-01-27 16:45:55 +00002019 char *a, *b;
Guido van Rossum03747111991-08-08 12:10:01 +00002020
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002021 if (!PyArg_Parse(args, "(ss)", &a, &b)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +00002022
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002023 Py_BEGIN_ALLOW_THREADS
Guido van Rossumfc58e581992-01-27 16:45:55 +00002024 str = fl_show_input(a, b);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002025 Py_END_ALLOW_THREADS
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002026
2027 if (str == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002028 Py_INCREF(Py_None);
2029 return Py_None;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002030 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002031 return PyString_FromString(str);
Guido van Rossum03747111991-08-08 12:10:01 +00002032}
2033
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002034static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00002035forms_file_selector(PyObject *f, PyObject *args)
Guido van Rossum03747111991-08-08 12:10:01 +00002036{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002037 char *str;
Guido van Rossumfc58e581992-01-27 16:45:55 +00002038 char *a, *b, *c, *d;
Guido van Rossum03747111991-08-08 12:10:01 +00002039
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002040 if (!PyArg_Parse(args, "(ssss)", &a, &b, &c, &d)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +00002041
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002042 Py_BEGIN_ALLOW_THREADS
Guido van Rossumfc58e581992-01-27 16:45:55 +00002043 str = fl_show_file_selector(a, b, c, d);
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002044 Py_END_ALLOW_THREADS
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002045
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002046 if (str == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002047 Py_INCREF(Py_None);
2048 return Py_None;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002049 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002050 return PyString_FromString(str);
Guido van Rossum03747111991-08-08 12:10:01 +00002051}
2052
2053
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002054static PyObject *
Thomas Woutersbd4bc4e2000-07-22 23:57:55 +00002055forms_file_selector_func(PyObject *args, char *(*func)(void))
Guido van Rossum03747111991-08-08 12:10:01 +00002056{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002057 char *str;
Guido van Rossum03747111991-08-08 12:10:01 +00002058
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002059 str = (*func) ();
2060
2061 if (str == NULL) {
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002062 Py_INCREF(Py_None);
2063 return Py_None;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002064 }
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002065 return PyString_FromString(str);
Guido van Rossum03747111991-08-08 12:10:01 +00002066}
2067
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002068static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00002069forms_get_directory(PyObject *f, PyObject *args)
Guido van Rossum03747111991-08-08 12:10:01 +00002070{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002071 return forms_file_selector_func(args, fl_get_directory);
Guido van Rossum03747111991-08-08 12:10:01 +00002072}
2073
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002074static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00002075forms_get_pattern(PyObject *f, PyObject *args)
Guido van Rossum03747111991-08-08 12:10:01 +00002076{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002077 return forms_file_selector_func(args, fl_get_pattern);
Guido van Rossum03747111991-08-08 12:10:01 +00002078}
2079
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002080static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00002081forms_get_filename(PyObject *f, PyObject *args)
Guido van Rossum03747111991-08-08 12:10:01 +00002082{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002083 return forms_file_selector_func(args, fl_get_filename);
Guido van Rossum03747111991-08-08 12:10:01 +00002084}
2085
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002086static PyMethodDef forms_methods[] = {
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002087/* adm */
Martin v. Löwis43b936d2002-01-17 23:15:58 +00002088 {"make_form", forms_make_form, METH_OLDARGS},
2089 {"activate_all_forms", forms_activate_all_forms, METH_OLDARGS},
2090 {"deactivate_all_forms",forms_deactivate_all_forms, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002091/* gl support wrappers */
Martin v. Löwis43b936d2002-01-17 23:15:58 +00002092 {"qdevice", forms_qdevice, METH_OLDARGS},
2093 {"unqdevice", forms_unqdevice, METH_OLDARGS},
2094 {"isqueued", forms_isqueued, METH_OLDARGS},
2095 {"qtest", forms_qtest, METH_OLDARGS},
2096 {"qread", forms_qread, METH_OLDARGS},
2097/* {"blkqread", forms_blkqread, METH_OLDARGS}, */
Neal Norwitz28faa1b2002-03-31 15:56:56 +00002098 {"qreset", forms_qreset, METH_NOARGS},
Martin v. Löwis43b936d2002-01-17 23:15:58 +00002099 {"qenter", forms_qenter, METH_OLDARGS},
Neal Norwitz28faa1b2002-03-31 15:56:56 +00002100 {"get_mouse", forms_get_mouse, METH_NOARGS},
Martin v. Löwis43b936d2002-01-17 23:15:58 +00002101 {"tie", forms_tie, METH_OLDARGS},
2102/* {"new_events", forms_new_events, METH_OLDARGS}, */
2103 {"color", forms_color, METH_OLDARGS},
2104 {"mapcolor", forms_mapcolor, METH_OLDARGS},
2105 {"getmcolor", forms_getmcolor, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002106/* interaction */
Neal Norwitz28faa1b2002-03-31 15:56:56 +00002107 {"do_forms", forms_do_forms, METH_NOARGS},
2108 {"do_only_forms", forms_do_only_forms, METH_NOARGS},
2109 {"check_forms", forms_check_forms, METH_NOARGS},
2110 {"check_only_forms", forms_check_only_forms, METH_NOARGS},
Martin v. Löwis43b936d2002-01-17 23:15:58 +00002111 {"set_event_call_back", forms_set_event_call_back, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002112/* goodies */
Martin v. Löwis43b936d2002-01-17 23:15:58 +00002113 {"show_message", forms_show_message, METH_OLDARGS},
2114 {"show_question", forms_show_question, METH_OLDARGS},
2115 {"show_choice", forms_show_choice, METH_OLDARGS},
2116 {"show_input", forms_show_input, METH_OLDARGS},
2117 {"show_file_selector", forms_file_selector, METH_OLDARGS},
2118 {"file_selector", forms_file_selector, METH_OLDARGS}, /* BW compat */
2119 {"get_directory", forms_get_directory, METH_OLDARGS},
2120 {"get_pattern", forms_get_pattern, METH_OLDARGS},
2121 {"get_filename", forms_get_filename, METH_OLDARGS},
2122 {"set_graphics_mode", forms_set_graphics_mode, METH_OLDARGS},
2123 {"get_rgbmode", forms_get_rgbmode, METH_OLDARGS},
2124 {"show_errors", forms_show_errors, METH_OLDARGS},
2125 {"set_font_name", forms_set_font_name, METH_OLDARGS},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002126 {NULL, NULL} /* sentinel */
2127};
2128
Guido van Rossum3886bb61998-12-04 18:50:17 +00002129DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00002130initfl(void)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002131{
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002132 Py_InitModule("fl", forms_methods);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002133 foreground();
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00002134 fl_init();
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002135}
Roger E. Masse7ba4c071997-01-03 22:17:11 +00002136
2137
2138