The 0.5 release happened on 2/15, not on 2/14. :-)
[python/dscho.git] / Modules / flmodule.c
blobc921d4bca37f1f6a69fa70a8d540513fb6459053
1 /**********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
15 permission.
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
32 /* FL module -- interface to Mark Overmars' FORMS Library. */
34 /* This code works with FORMS version 2.2 (if you defined
35 OBSOLETE_FORMS_CALLS), and 2.3.
36 FORMS can be ftp'ed from ftp.cs.ruu.nl (131.211.80.17), directory
37 /pub/SGI/FORMS. */
39 /* A half-hearted attempt has been made to allow programs using this
40 * module to exploit parallelism (through the threads module). No provisions
41 * have been made for multiple threads to use this module at the same time,
42 * though. So, a program with a forms thread and a non-forms thread will work
43 * fine but a program with two threads using forms will probably crash (unless
44 * the program takes precaution to ensure that only one thread can be in
45 * this module at any time). This will have to be fixed some time.
46 * (A fix will probably also have to synchronise with the gl module).
49 #include "Python.h"
50 #include "forms.h"
51 #include "structmember.h"
53 /* Generic Forms Objects */
55 typedef struct {
56 PyObject_HEAD
57 FL_OBJECT *ob_generic;
58 PyMethodDef *ob_methods;
59 PyObject *ob_callback;
60 PyObject *ob_callback_arg;
61 } genericobject;
63 staticforward PyTypeObject GenericObjecttype;
65 #define is_genericobject(g) ((g)->ob_type == &GenericObjecttype)
67 /* List of all objects (XXX this should be a hash table on address...) */
69 static PyObject *allgenerics = NULL;
70 static int nfreeslots = 0;
72 /* Add an object to the list of known objects */
74 static void
75 knowgeneric(g)
76 genericobject *g;
78 int i, n;
79 /* Create the list if it doesn't already exist */
80 if (allgenerics == NULL) {
81 allgenerics = PyList_New(0);
82 if (allgenerics == NULL) {
83 PyErr_Clear();
84 return; /* Too bad, live without allgenerics... */
87 if (nfreeslots > 0) {
88 /* Search the list for reusable slots (NULL items) */
89 /* XXX This can be made faster! */
90 n = PyList_Size(allgenerics);
91 for (i = 0; i < n; i++) {
92 if (PyList_GetItem(allgenerics, i) == NULL) {
93 Py_INCREF(g);
94 PyList_SetItem(allgenerics, i, (PyObject *)g);
95 nfreeslots--;
96 return;
99 /* Strange... no free slots found... */
100 nfreeslots = 0;
102 /* No free entries, append new item to the end */
103 PyList_Append(allgenerics, (PyObject *)g);
106 /* Find an object in the list of known objects */
108 static genericobject *
109 findgeneric(generic)
110 FL_OBJECT *generic;
112 int i, n;
113 genericobject *g;
115 if (allgenerics == NULL)
116 return NULL; /* No objects known yet */
117 n = PyList_Size(allgenerics);
118 for (i = 0; i < n; i++) {
119 g = (genericobject *)PyList_GetItem(allgenerics, i);
120 if (g != NULL && g->ob_generic == generic)
121 return g;
123 return NULL; /* Unknown object */
126 /* Remove an object from the list of known objects */
128 static void
129 forgetgeneric(g)
130 genericobject *g;
132 int i, n;
134 Py_XDECREF(g->ob_callback);
135 g->ob_callback = NULL;
136 Py_XDECREF(g->ob_callback_arg);
137 g->ob_callback_arg = NULL;
138 if (allgenerics == NULL)
139 return; /* No objects known yet */
140 n = PyList_Size(allgenerics);
141 for (i = 0; i < n; i++) {
142 if (g == (genericobject *)PyList_GetItem(allgenerics, i)) {
143 PyList_SetItem(allgenerics, i, (PyObject *)NULL);
144 nfreeslots++;
145 break;
150 /* Called when a form is about to be freed --
151 remove all the objects that we know about from it. */
153 static void
154 releaseobjects(form)
155 FL_FORM *form;
157 int i, n;
158 genericobject *g;
160 if (allgenerics == NULL)
161 return; /* No objects known yet */
162 n = PyList_Size(allgenerics);
163 for (i = 0; i < n; i++) {
164 g = (genericobject *)PyList_GetItem(allgenerics, i);
165 if (g != NULL && g->ob_generic->form == form) {
166 fl_delete_object(g->ob_generic);
167 /* The object is now unreachable for
168 do_forms and check_forms, so
169 delete it from the list of known objects */
170 Py_XDECREF(g->ob_callback);
171 g->ob_callback = NULL;
172 Py_XDECREF(g->ob_callback_arg);
173 g->ob_callback_arg = NULL;
174 PyList_SetItem(allgenerics, i, (PyObject *)NULL);
175 nfreeslots++;
181 /* Methods of generic objects */
183 static PyObject *
184 generic_set_call_back(g, args)
185 genericobject *g;
186 PyObject *args;
188 if (args == NULL) {
189 Py_XDECREF(g->ob_callback);
190 Py_XDECREF(g->ob_callback_arg);
191 g->ob_callback = NULL;
192 g->ob_callback_arg = NULL;
194 else {
195 if (!PyTuple_Check(args) || PyTuple_Size(args) != 2) {
196 PyErr_BadArgument();
197 return NULL;
199 Py_XDECREF(g->ob_callback);
200 Py_XDECREF(g->ob_callback_arg);
201 g->ob_callback = PyTuple_GetItem(args, 0);
202 Py_INCREF(g->ob_callback);
203 g->ob_callback_arg = PyTuple_GetItem(args, 1);
204 Py_INCREF(g->ob_callback_arg);
206 Py_INCREF(Py_None);
207 return Py_None;
210 static PyObject *
211 generic_call(g, args, func)
212 genericobject *g;
213 PyObject *args;
214 void (*func)(FL_OBJECT *);
216 if (!PyArg_NoArgs(args))
217 return NULL;
218 (*func)(g->ob_generic);
219 Py_INCREF(Py_None);
220 return Py_None;
223 static PyObject *
224 generic_delete_object(g, args)
225 genericobject *g;
226 PyObject *args;
228 PyObject *res;
229 res = generic_call(g, args, fl_delete_object);
230 if (res != NULL)
231 forgetgeneric(g);
232 return res;
235 static PyObject *
236 generic_show_object(g, args)
237 genericobject *g;
238 PyObject *args;
240 return generic_call(g, args, fl_show_object);
243 static PyObject *
244 generic_hide_object(g, args)
245 genericobject *g;
246 PyObject *args;
248 return generic_call(g, args, fl_hide_object);
251 static PyObject *
252 generic_redraw_object(g, args)
253 genericobject *g;
254 PyObject *args;
256 return generic_call(g, args, fl_redraw_object);
259 #ifdef OBSOLETE_FORMS_CALLS
261 /* (un)freeze_object() are obsolete in FORMS 2.2 and unsupported
262 in 2.3. Since there's no foolproof way to tell which version we're
263 using, we omit them unconditionally. */
265 static PyObject *
266 generic_freeze_object(g, args)
267 genericobject *g;
268 PyObject *args;
270 return generic_call(g, args, fl_freeze_object);
273 static PyObject *
274 generic_unfreeze_object(g, args)
275 genericobject *g;
276 PyObject *args;
278 return generic_call(g, args, fl_unfreeze_object);
281 #endif /* OBSOLETE_FORMS_CALLS */
283 static PyObject *
284 generic_activate_object(g, args)
285 genericobject *g;
286 PyObject *args;
288 return generic_call(g, args, fl_activate_object);
291 static PyObject *
292 generic_deactivate_object(g, args)
293 genericobject *g;
294 PyObject *args;
296 return generic_call(g, args, fl_deactivate_object);
299 static PyObject *
300 generic_set_object_shortcut(g, args)
301 genericobject *g;
302 PyObject *args;
304 char *str;
305 if (!PyArg_Parse(args, "s", &str))
306 return NULL;
307 fl_set_object_shortcut(g->ob_generic, str);
308 Py_INCREF(Py_None);
309 return Py_None;
312 static PyMethodDef generic_methods[] = {
313 {"set_call_back", (PyCFunction)generic_set_call_back},
314 {"delete_object", (PyCFunction)generic_delete_object},
315 {"show_object", (PyCFunction)generic_show_object},
316 {"hide_object", (PyCFunction)generic_hide_object},
317 {"redraw_object", (PyCFunction)generic_redraw_object},
318 #ifdef OBSOLETE_FORMS_CALLS
319 {"freeze_object", (PyCFunction)generic_freeze_object},
320 {"unfreeze_object", (PyCFunction)generic_unfreeze_object},
321 #endif
322 {"activate_object", (PyCFunction)generic_activate_object},
323 {"deactivate_object", (PyCFunction)generic_deactivate_object},
324 {"set_object_shortcut", (PyCFunction)generic_set_object_shortcut},
325 {NULL, NULL} /* sentinel */
328 static void
329 generic_dealloc(g)
330 genericobject *g;
332 fl_free_object(g->ob_generic);
333 Py_XDECREF(g->ob_callback);
334 Py_XDECREF(g->ob_callback_arg);
335 PyMem_DEL(g);
338 #define OFF(x) offsetof(FL_OBJECT, x)
340 static struct memberlist generic_memberlist[] = {
341 {"objclass", T_INT, OFF(objclass), RO},
342 {"type", T_INT, OFF(type), RO},
343 {"boxtype", T_INT, OFF(boxtype)},
344 {"x", T_FLOAT, OFF(x)},
345 {"y", T_FLOAT, OFF(y)},
346 {"w", T_FLOAT, OFF(w)},
347 {"h", T_FLOAT, OFF(h)},
348 {"col1", T_INT, OFF(col1)},
349 {"col2", T_INT, OFF(col2)},
350 {"align", T_INT, OFF(align)},
351 {"lcol", T_INT, OFF(lcol)},
352 {"lsize", T_FLOAT, OFF(lsize)},
353 /* "label" is treated specially! */
354 {"lstyle", T_INT, OFF(lstyle)},
355 {"pushed", T_INT, OFF(pushed), RO},
356 {"focus", T_INT, OFF(focus), RO},
357 {"belowmouse", T_INT, OFF(belowmouse),RO},
358 /* {"frozen", T_INT, OFF(frozen), RO}, */
359 {"active", T_INT, OFF(active)},
360 {"input", T_INT, OFF(input)},
361 {"visible", T_INT, OFF(visible), RO},
362 {"radio", T_INT, OFF(radio)},
363 {"automatic", T_INT, OFF(automatic)},
364 {NULL} /* Sentinel */
367 #undef OFF
369 static PyObject *
370 generic_getattr(g, name)
371 genericobject *g;
372 char *name;
374 PyObject *meth;
376 /* XXX Ought to special-case name "__methods__" */
377 if (g-> ob_methods) {
378 meth = Py_FindMethod(g->ob_methods, (PyObject *)g, name);
379 if (meth != NULL) return meth;
380 PyErr_Clear();
383 meth = Py_FindMethod(generic_methods, (PyObject *)g, name);
384 if (meth != NULL)
385 return meth;
386 PyErr_Clear();
388 /* "label" is an exception, getmember only works for char pointers,
389 not for char arrays */
390 if (strcmp(name, "label") == 0)
391 return PyString_FromString(g->ob_generic->label);
393 return PyMember_Get((char *)g->ob_generic, generic_memberlist, name);
396 static int
397 generic_setattr(g, name, v)
398 genericobject *g;
399 char *name;
400 PyObject *v;
402 int ret;
404 if (v == NULL) {
405 PyErr_SetString(PyExc_TypeError,
406 "can't delete forms object attributes");
407 return -1;
410 /* "label" is an exception: setmember doesn't set strings;
411 and FORMS wants you to call a function to set the label */
412 if (strcmp(name, "label") == 0) {
413 if (!PyString_Check(v)) {
414 PyErr_SetString(PyExc_TypeError,
415 "label attr must be string");
416 return -1;
418 fl_set_object_label(g->ob_generic, PyString_AsString(v));
419 return 0;
422 ret = PyMember_Set((char *)g->ob_generic, generic_memberlist, name, v);
424 /* Rather than calling all the various set_object_* functions,
425 we call fl_redraw_object here. This is sometimes redundant
426 but I doubt that's a big problem */
427 if (ret == 0)
428 fl_redraw_object(g->ob_generic);
430 return ret;
433 static PyObject *
434 generic_repr(g)
435 genericobject *g;
437 char buf[100];
438 sprintf(buf, "<FORMS_object at %lx, objclass=%d>",
439 (long)g, g->ob_generic->objclass);
440 return PyString_FromString(buf);
443 static PyTypeObject GenericObjecttype = {
444 PyObject_HEAD_INIT(&PyType_Type)
445 0, /*ob_size*/
446 "FORMS_object", /*tp_name*/
447 sizeof(genericobject), /*tp_size*/
448 0, /*tp_itemsize*/
449 /* methods */
450 (destructor)generic_dealloc, /*tp_dealloc*/
451 0, /*tp_print*/
452 (getattrfunc)generic_getattr, /*tp_getattr*/
453 (setattrfunc)generic_setattr, /*tp_setattr*/
454 0, /*tp_compare*/
455 (reprfunc)generic_repr, /*tp_repr*/
458 static PyObject *
459 newgenericobject(generic, methods)
460 FL_OBJECT *generic;
461 PyMethodDef *methods;
463 genericobject *g;
464 g = PyObject_NEW(genericobject, &GenericObjecttype);
465 if (g == NULL)
466 return NULL;
467 g-> ob_generic = generic;
468 g->ob_methods = methods;
469 g->ob_callback = NULL;
470 g->ob_callback_arg = NULL;
471 knowgeneric(g);
472 return (PyObject *)g;
475 /**********************************************************************/
476 /* Some common calling sequences */
478 /* void func (object, float) */
479 static PyObject *
480 call_forms_INf (func, obj, args)
481 void (*func)(FL_OBJECT *, float);
482 FL_OBJECT *obj;
483 PyObject *args;
485 float parameter;
487 if (!PyArg_Parse(args, "f", &parameter)) return NULL;
489 (*func) (obj, parameter);
491 Py_INCREF(Py_None);
492 return Py_None;
495 /* void func (object, float) */
496 static PyObject *
497 call_forms_INfINf (func, obj, args)
498 void (*func)(FL_OBJECT *, float, float);
499 FL_OBJECT *obj;
500 PyObject *args;
502 float par1, par2;
504 if (!PyArg_Parse(args, "(ff)", &par1, &par2)) return NULL;
506 (*func) (obj, par1, par2);
508 Py_INCREF(Py_None);
509 return Py_None;
512 /* void func (object, int) */
513 static PyObject *
514 call_forms_INi (func, obj, args)
515 void (*func)(FL_OBJECT *, int);
516 FL_OBJECT *obj;
517 PyObject *args;
519 int parameter;
521 if (!PyArg_Parse(args, "i", &parameter)) return NULL;
523 (*func) (obj, parameter);
525 Py_INCREF(Py_None);
526 return Py_None;
529 /* void func (object, char) */
530 static PyObject *
531 call_forms_INc (func, obj, args)
532 void (*func)(FL_OBJECT *, int);
533 FL_OBJECT *obj;
534 PyObject *args;
536 char *a;
538 if (!PyArg_Parse(args, "s", &a)) return NULL;
540 (*func) (obj, a[0]);
542 Py_INCREF(Py_None);
543 return Py_None;
546 /* void func (object, string) */
547 static PyObject *
548 call_forms_INstr (func, obj, args)
549 void (*func)(FL_OBJECT *, char *);
550 FL_OBJECT *obj;
551 PyObject *args;
553 char *a;
555 if (!PyArg_Parse(args, "s", &a)) return NULL;
557 (*func) (obj, a);
559 Py_INCREF(Py_None);
560 return Py_None;
564 /* void func (object, int, string) */
565 static PyObject *
566 call_forms_INiINstr (func, obj, args)
567 void (*func)(FL_OBJECT *, int, char *);
568 FL_OBJECT *obj;
569 PyObject *args;
571 char *b;
572 int a;
574 if (!PyArg_Parse(args, "(is)", &a, &b)) return NULL;
576 (*func) (obj, a, b);
578 Py_INCREF(Py_None);
579 return Py_None;
582 #ifdef UNUSED
583 /* void func (object, int, int) */
584 static PyObject *
585 call_forms_INiINi (func, obj, args)
586 void (*func)(FL_OBJECT *, int, int);
587 FL_OBJECT *obj;
588 PyObject *args;
590 int par1, par2;
592 if (!PyArg_Parse(args, "(ii)", &par1, &par2)) return NULL;
594 (*func) (obj, par1, par2);
596 Py_INCREF(Py_None);
597 return Py_None;
599 #endif
601 /* int func (object) */
602 static PyObject *
603 call_forms_Ri (func, obj, args)
604 int (*func)(FL_OBJECT *);
605 FL_OBJECT *obj;
606 PyObject *args;
608 int retval;
610 if (!PyArg_NoArgs(args)) return NULL;
612 retval = (*func) (obj);
614 return PyInt_FromLong ((long) retval);
617 /* char * func (object) */
618 static PyObject *
619 call_forms_Rstr (func, obj, args)
620 char * (*func)(FL_OBJECT *);
621 FL_OBJECT *obj;
622 PyObject *args;
624 char *str;
626 if (!PyArg_NoArgs(args)) return NULL;
628 str = (*func) (obj);
630 if (str == NULL) {
631 Py_INCREF(Py_None);
632 return Py_None;
634 return PyString_FromString (str);
637 /* int func (object) */
638 static PyObject *
639 call_forms_Rf (func, obj, args)
640 float (*func)(FL_OBJECT *);
641 FL_OBJECT *obj;
642 PyObject *args;
644 float retval;
646 if (!PyArg_NoArgs(args)) return NULL;
648 retval = (*func) (obj);
650 return PyFloat_FromDouble (retval);
653 static PyObject *
654 call_forms_OUTfOUTf (func, obj, args)
655 void (*func)(FL_OBJECT *, float *, float *);
656 FL_OBJECT *obj;
657 PyObject *args;
659 float f1, f2;
661 if (!PyArg_NoArgs(args)) return NULL;
663 (*func) (obj, &f1, &f2);
665 return Py_BuildValue("(ff)", f1, f2);
668 #ifdef UNUSED
669 static PyObject *
670 call_forms_OUTf (func, obj, args)
671 void (*func)(FL_OBJECT *, float *);
672 FL_OBJECT *obj;
673 PyObject *args;
675 float f;
677 if (!PyArg_NoArgs(args)) return NULL;
679 (*func) (obj, &f);
681 return PyFloat_FromDouble (f);
683 #endif
685 /**********************************************************************/
686 /* Class : browser */
688 static PyObject *
689 set_browser_topline(g, args)
690 genericobject *g;
691 PyObject *args;
693 return call_forms_INi (fl_set_browser_topline, g-> ob_generic, args);
696 static PyObject *
697 clear_browser(g, args)
698 genericobject *g;
699 PyObject *args;
701 return generic_call (g, args, fl_clear_browser);
704 static PyObject *
705 add_browser_line (g, args)
706 genericobject *g;
707 PyObject *args;
709 return call_forms_INstr (fl_add_browser_line, g-> ob_generic, args);
712 static PyObject *
713 addto_browser (g, args)
714 genericobject *g;
715 PyObject *args;
717 return call_forms_INstr (fl_addto_browser, g-> ob_generic, args);
720 static PyObject *
721 insert_browser_line (g, args)
722 genericobject *g;
723 PyObject *args;
725 return call_forms_INiINstr (fl_insert_browser_line,
726 g-> ob_generic, args);
729 static PyObject *
730 delete_browser_line (g, args)
731 genericobject *g;
732 PyObject *args;
734 return call_forms_INi (fl_delete_browser_line, g-> ob_generic, args);
737 static PyObject *
738 replace_browser_line (g, args)
739 genericobject *g;
740 PyObject *args;
742 return call_forms_INiINstr (fl_replace_browser_line,
743 g-> ob_generic, args);
746 static PyObject *
747 get_browser_line(g, args)
748 genericobject *g;
749 PyObject *args;
751 int i;
752 char *str;
754 if (!PyArg_Parse(args, "i", &i))
755 return NULL;
757 str = fl_get_browser_line (g->ob_generic, i);
759 if (str == NULL) {
760 Py_INCREF(Py_None);
761 return Py_None;
763 return PyString_FromString (str);
766 static PyObject *
767 load_browser (g, args)
768 genericobject *g;
769 PyObject *args;
771 /* XXX strictly speaking this is wrong since fl_load_browser
772 XXX returns int, not void */
773 return call_forms_INstr (fl_load_browser, g-> ob_generic, args);
776 static PyObject *
777 get_browser_maxline(g, args)
778 genericobject *g;
779 PyObject *args;
781 return call_forms_Ri (fl_get_browser_maxline, g-> ob_generic, args);
784 static PyObject *
785 select_browser_line (g, args)
786 genericobject *g;
787 PyObject *args;
789 return call_forms_INi (fl_select_browser_line, g-> ob_generic, args);
792 static PyObject *
793 deselect_browser_line (g, args)
794 genericobject *g;
795 PyObject *args;
797 return call_forms_INi (fl_deselect_browser_line, g-> ob_generic, args);
800 static PyObject *
801 deselect_browser (g, args)
802 genericobject *g;
803 PyObject *args;
805 return generic_call (g, args, fl_deselect_browser);
808 static PyObject *
809 isselected_browser_line (g, args)
810 genericobject *g;
811 PyObject *args;
813 int i, j;
815 if (!PyArg_Parse(args, "i", &i))
816 return NULL;
818 j = fl_isselected_browser_line (g->ob_generic, i);
820 return PyInt_FromLong (j);
823 static PyObject *
824 get_browser (g, args)
825 genericobject *g;
826 PyObject *args;
828 return call_forms_Ri (fl_get_browser, g-> ob_generic, args);
831 static PyObject *
832 set_browser_fontsize (g, args)
833 genericobject *g;
834 PyObject *args;
836 return call_forms_INf (fl_set_browser_fontsize, g-> ob_generic, args);
839 static PyObject *
840 set_browser_fontstyle (g, args)
841 genericobject *g;
842 PyObject *args;
844 return call_forms_INi (fl_set_browser_fontstyle, g-> ob_generic, args);
847 static PyObject *
848 set_browser_specialkey (g, args)
849 genericobject *g;
850 PyObject *args;
852 return call_forms_INc(fl_set_browser_specialkey, g-> ob_generic, args);
855 static PyMethodDef browser_methods[] = {
856 {"set_browser_topline", (PyCFunction)set_browser_topline},
857 {"clear_browser", (PyCFunction)clear_browser},
858 {"add_browser_line", (PyCFunction)add_browser_line},
859 {"addto_browser", (PyCFunction)addto_browser},
860 {"insert_browser_line", (PyCFunction)insert_browser_line},
861 {"delete_browser_line", (PyCFunction)delete_browser_line},
862 {"replace_browser_line", (PyCFunction)replace_browser_line},
863 {"get_browser_line", (PyCFunction)get_browser_line},
864 {"load_browser", (PyCFunction)load_browser},
865 {"get_browser_maxline", (PyCFunction)get_browser_maxline},
866 {"select_browser_line", (PyCFunction)select_browser_line},
867 {"deselect_browser_line", (PyCFunction)deselect_browser_line},
868 {"deselect_browser", (PyCFunction)deselect_browser},
869 {"isselected_browser_line", (PyCFunction)isselected_browser_line},
870 {"get_browser", (PyCFunction)get_browser},
871 {"set_browser_fontsize", (PyCFunction)set_browser_fontsize},
872 {"set_browser_fontstyle", (PyCFunction)set_browser_fontstyle},
873 {"set_browser_specialkey", (PyCFunction)set_browser_specialkey},
874 {NULL, NULL} /* sentinel */
877 /* Class: button */
879 static PyObject *
880 set_button(g, args)
881 genericobject *g;
882 PyObject *args;
884 return call_forms_INi (fl_set_button, g-> ob_generic, args);
887 static PyObject *
888 get_button(g, args)
889 genericobject *g;
890 PyObject *args;
892 return call_forms_Ri (fl_get_button, g-> ob_generic, args);
895 static PyObject *
896 get_button_numb(g, args)
897 genericobject *g;
898 PyObject *args;
900 return call_forms_Ri (fl_get_button_numb, g-> ob_generic, args);
903 static PyObject *
904 set_button_shortcut(g, args)
905 genericobject *g;
906 PyObject *args;
908 return call_forms_INstr (fl_set_button_shortcut, g-> ob_generic, args);
911 static PyMethodDef button_methods[] = {
912 {"set_button", (PyCFunction)set_button},
913 {"get_button", (PyCFunction)get_button},
914 {"get_button_numb", (PyCFunction)get_button_numb},
915 {"set_button_shortcut", (PyCFunction)set_button_shortcut},
916 {NULL, NULL} /* sentinel */
919 /* Class: choice */
921 static PyObject *
922 set_choice(g, args)
923 genericobject *g;
924 PyObject *args;
926 return call_forms_INi (fl_set_choice, g-> ob_generic, args);
929 static PyObject *
930 get_choice(g, args)
931 genericobject *g;
932 PyObject *args;
934 return call_forms_Ri (fl_get_choice, g-> ob_generic, args);
937 static PyObject *
938 clear_choice (g, args)
939 genericobject *g;
940 PyObject *args;
942 return generic_call (g, args, fl_clear_choice);
945 static PyObject *
946 addto_choice (g, args)
947 genericobject *g;
948 PyObject *args;
950 return call_forms_INstr (fl_addto_choice, g-> ob_generic, args);
953 static PyObject *
954 replace_choice (g, args)
955 genericobject *g;
956 PyObject *args;
958 return call_forms_INiINstr (fl_replace_choice, g-> ob_generic, args);
961 static PyObject *
962 delete_choice (g, args)
963 genericobject *g;
964 PyObject *args;
966 return call_forms_INi (fl_delete_choice, g-> ob_generic, args);
969 static PyObject *
970 get_choice_text (g, args)
971 genericobject *g;
972 PyObject *args;
974 return call_forms_Rstr (fl_get_choice_text, g-> ob_generic, args);
977 static PyObject *
978 set_choice_fontsize (g, args)
979 genericobject *g;
980 PyObject *args;
982 return call_forms_INf (fl_set_choice_fontsize, g-> ob_generic, args);
985 static PyObject *
986 set_choice_fontstyle (g, args)
987 genericobject *g;
988 PyObject *args;
990 return call_forms_INi (fl_set_choice_fontstyle, g-> ob_generic, args);
993 static PyMethodDef choice_methods[] = {
994 {"set_choice", (PyCFunction)set_choice},
995 {"get_choice", (PyCFunction)get_choice},
996 {"clear_choice", (PyCFunction)clear_choice},
997 {"addto_choice", (PyCFunction)addto_choice},
998 {"replace_choice", (PyCFunction)replace_choice},
999 {"delete_choice", (PyCFunction)delete_choice},
1000 {"get_choice_text", (PyCFunction)get_choice_text},
1001 {"set_choice_fontsize", (PyCFunction)set_choice_fontsize},
1002 {"set_choice_fontstyle",(PyCFunction)set_choice_fontstyle},
1003 {NULL, NULL} /* sentinel */
1006 /* Class : Clock */
1008 static PyObject *
1009 get_clock(g, args)
1010 genericobject *g;
1011 PyObject *args;
1013 int i0, i1, i2;
1015 if (!PyArg_NoArgs(args))
1016 return NULL;
1018 fl_get_clock (g->ob_generic, &i0, &i1, &i2);
1020 return Py_BuildValue("(iii)", i0, i1, i2);
1023 static PyMethodDef clock_methods[] = {
1024 {"get_clock", (PyCFunction)get_clock},
1025 {NULL, NULL} /* sentinel */
1028 /* CLass : Counters */
1030 static PyObject *
1031 get_counter_value(g, args)
1032 genericobject *g;
1033 PyObject *args;
1035 return call_forms_Rf (fl_get_counter_value, g-> ob_generic, args);
1038 static PyObject *
1039 set_counter_value (g, args)
1040 genericobject *g;
1041 PyObject *args;
1043 return call_forms_INf (fl_set_counter_value, g-> ob_generic, args);
1046 static PyObject *
1047 set_counter_precision (g, args)
1048 genericobject *g;
1049 PyObject *args;
1051 return call_forms_INi (fl_set_counter_precision, g-> ob_generic, args);
1054 static PyObject *
1055 set_counter_bounds (g, args)
1056 genericobject *g;
1057 PyObject *args;
1059 return call_forms_INfINf (fl_set_counter_bounds, g-> ob_generic, args);
1062 static PyObject *
1063 set_counter_step (g, args)
1064 genericobject *g;
1065 PyObject *args;
1067 return call_forms_INfINf (fl_set_counter_step, g-> ob_generic, args);
1070 static PyObject *
1071 set_counter_return (g, args)
1072 genericobject *g;
1073 PyObject *args;
1075 return call_forms_INi (fl_set_counter_return, g-> ob_generic, args);
1078 static PyMethodDef counter_methods[] = {
1079 {"set_counter_value", (PyCFunction)set_counter_value},
1080 {"get_counter_value", (PyCFunction)get_counter_value},
1081 {"set_counter_bounds", (PyCFunction)set_counter_bounds},
1082 {"set_counter_step", (PyCFunction)set_counter_step},
1083 {"set_counter_precision", (PyCFunction)set_counter_precision},
1084 {"set_counter_return", (PyCFunction)set_counter_return},
1085 {NULL, NULL} /* sentinel */
1089 /* Class: Dials */
1091 static PyObject *
1092 get_dial_value(g, args)
1093 genericobject *g;
1094 PyObject *args;
1096 return call_forms_Rf (fl_get_dial_value, g-> ob_generic, args);
1099 static PyObject *
1100 set_dial_value (g, args)
1101 genericobject *g;
1102 PyObject *args;
1104 return call_forms_INf (fl_set_dial_value, g-> ob_generic, args);
1107 static PyObject *
1108 set_dial_bounds (g, args)
1109 genericobject *g;
1110 PyObject *args;
1112 return call_forms_INfINf (fl_set_dial_bounds, g-> ob_generic, args);
1115 static PyObject *
1116 get_dial_bounds (g, args)
1117 genericobject *g;
1118 PyObject *args;
1120 return call_forms_OUTfOUTf (fl_get_dial_bounds, g-> ob_generic, args);
1123 static PyObject *
1124 set_dial_step (g, args)
1125 genericobject *g;
1126 PyObject *args;
1128 return call_forms_INf (fl_set_dial_step, g-> ob_generic, args);
1131 static PyMethodDef dial_methods[] = {
1132 {"set_dial_value", (PyCFunction)set_dial_value},
1133 {"get_dial_value", (PyCFunction)get_dial_value},
1134 {"set_dial_bounds", (PyCFunction)set_dial_bounds},
1135 {"get_dial_bounds", (PyCFunction)get_dial_bounds},
1136 {"set_dial_step", (PyCFunction)set_dial_step},
1137 {NULL, NULL} /* sentinel */
1140 /* Class : Input */
1142 static PyObject *
1143 set_input (g, args)
1144 genericobject *g;
1145 PyObject *args;
1147 return call_forms_INstr (fl_set_input, g-> ob_generic, args);
1150 static PyObject *
1151 get_input (g, args)
1152 genericobject *g;
1153 PyObject *args;
1155 return call_forms_Rstr (fl_get_input, g-> ob_generic, args);
1158 static PyObject *
1159 set_input_color (g, args)
1160 genericobject *g;
1161 PyObject *args;
1163 return call_forms_INfINf (fl_set_input_color, g-> ob_generic, args);
1166 static PyObject *
1167 set_input_return (g, args)
1168 genericobject *g;
1169 PyObject *args;
1171 return call_forms_INi (fl_set_input_return, g-> ob_generic, args);
1174 static PyMethodDef input_methods[] = {
1175 {"set_input", (PyCFunction)set_input},
1176 {"get_input", (PyCFunction)get_input},
1177 {"set_input_color", (PyCFunction)set_input_color},
1178 {"set_input_return", (PyCFunction)set_input_return},
1179 {NULL, NULL} /* sentinel */
1183 /* Class : Menu */
1185 static PyObject *
1186 set_menu (g, args)
1187 genericobject *g;
1188 PyObject *args;
1190 return call_forms_INstr (fl_set_menu, g-> ob_generic, args);
1193 static PyObject *
1194 get_menu (g, args)
1195 genericobject *g;
1196 PyObject *args;
1198 /* XXX strictly speaking this is wrong since fl_get_menu
1199 XXX returns long, not int */
1200 return call_forms_Ri (fl_get_menu, g-> ob_generic, args);
1203 static PyObject *
1204 get_menu_text (g, args)
1205 genericobject *g;
1206 PyObject *args;
1208 return call_forms_Rstr (fl_get_menu_text, g-> ob_generic, args);
1211 static PyObject *
1212 addto_menu (g, args)
1213 genericobject *g;
1214 PyObject *args;
1216 return call_forms_INstr (fl_addto_menu, g-> ob_generic, args);
1219 static PyMethodDef menu_methods[] = {
1220 {"set_menu", (PyCFunction)set_menu},
1221 {"get_menu", (PyCFunction)get_menu},
1222 {"get_menu_text", (PyCFunction)get_menu_text},
1223 {"addto_menu", (PyCFunction)addto_menu},
1224 {NULL, NULL} /* sentinel */
1228 /* Class: Sliders */
1230 static PyObject *
1231 get_slider_value(g, args)
1232 genericobject *g;
1233 PyObject *args;
1235 return call_forms_Rf (fl_get_slider_value, g-> ob_generic, args);
1238 static PyObject *
1239 set_slider_value (g, args)
1240 genericobject *g;
1241 PyObject *args;
1243 return call_forms_INf (fl_set_slider_value, g-> ob_generic, args);
1246 static PyObject *
1247 set_slider_bounds (g, args)
1248 genericobject *g;
1249 PyObject *args;
1251 return call_forms_INfINf (fl_set_slider_bounds, g-> ob_generic, args);
1254 static PyObject *
1255 get_slider_bounds (g, args)
1256 genericobject *g;
1257 PyObject *args;
1259 return call_forms_OUTfOUTf(fl_get_slider_bounds, g-> ob_generic, args);
1262 static PyObject *
1263 set_slider_return (g, args)
1264 genericobject *g;
1265 PyObject *args;
1267 return call_forms_INf (fl_set_slider_return, g-> ob_generic, args);
1270 static PyObject *
1271 set_slider_size (g, args)
1272 genericobject *g;
1273 PyObject *args;
1275 return call_forms_INf (fl_set_slider_size, g-> ob_generic, args);
1278 static PyObject *
1279 set_slider_precision (g, args)
1280 genericobject *g;
1281 PyObject *args;
1283 return call_forms_INi (fl_set_slider_precision, g-> ob_generic, args);
1286 static PyObject *
1287 set_slider_step (g, args)
1288 genericobject *g;
1289 PyObject *args;
1291 return call_forms_INf (fl_set_slider_step, g-> ob_generic, args);
1295 static PyMethodDef slider_methods[] = {
1296 {"set_slider_value", (PyCFunction)set_slider_value},
1297 {"get_slider_value", (PyCFunction)get_slider_value},
1298 {"set_slider_bounds", (PyCFunction)set_slider_bounds},
1299 {"get_slider_bounds", (PyCFunction)get_slider_bounds},
1300 {"set_slider_return", (PyCFunction)set_slider_return},
1301 {"set_slider_size", (PyCFunction)set_slider_size},
1302 {"set_slider_precision",(PyCFunction)set_slider_precision},
1303 {"set_slider_step", (PyCFunction)set_slider_step},
1304 {NULL, NULL} /* sentinel */
1307 static PyObject *
1308 set_positioner_xvalue (g, args)
1309 genericobject *g;
1310 PyObject *args;
1312 return call_forms_INf (fl_set_positioner_xvalue, g-> ob_generic, args);
1315 static PyObject *
1316 set_positioner_xbounds (g, args)
1317 genericobject *g;
1318 PyObject *args;
1320 return call_forms_INfINf (fl_set_positioner_xbounds,
1321 g-> ob_generic, args);
1324 static PyObject *
1325 set_positioner_yvalue (g, args)
1326 genericobject *g;
1327 PyObject *args;
1329 return call_forms_INf (fl_set_positioner_yvalue, g-> ob_generic, args);
1332 static PyObject *
1333 set_positioner_ybounds (g, args)
1334 genericobject *g;
1335 PyObject *args;
1337 return call_forms_INfINf (fl_set_positioner_ybounds,
1338 g-> ob_generic, args);
1341 static PyObject *
1342 get_positioner_xvalue (g, args)
1343 genericobject *g;
1344 PyObject *args;
1346 return call_forms_Rf (fl_get_positioner_xvalue, g-> ob_generic, args);
1349 static PyObject *
1350 get_positioner_xbounds (g, args)
1351 genericobject *g;
1352 PyObject *args;
1354 return call_forms_OUTfOUTf (fl_get_positioner_xbounds,
1355 g-> ob_generic, args);
1358 static PyObject *
1359 get_positioner_yvalue (g, args)
1360 genericobject *g;
1361 PyObject *args;
1363 return call_forms_Rf (fl_get_positioner_yvalue, g-> ob_generic, args);
1366 static PyObject *
1367 get_positioner_ybounds (g, args)
1368 genericobject *g;
1369 PyObject *args;
1371 return call_forms_OUTfOUTf (fl_get_positioner_ybounds,
1372 g-> ob_generic, args);
1375 static PyMethodDef positioner_methods[] = {
1376 {"set_positioner_xvalue", (PyCFunction)set_positioner_xvalue},
1377 {"set_positioner_yvalue", (PyCFunction)set_positioner_yvalue},
1378 {"set_positioner_xbounds", (PyCFunction)set_positioner_xbounds},
1379 {"set_positioner_ybounds", (PyCFunction)set_positioner_ybounds},
1380 {"get_positioner_xvalue", (PyCFunction)get_positioner_xvalue},
1381 {"get_positioner_yvalue", (PyCFunction)get_positioner_yvalue},
1382 {"get_positioner_xbounds", (PyCFunction)get_positioner_xbounds},
1383 {"get_positioner_ybounds", (PyCFunction)get_positioner_ybounds},
1384 {NULL, NULL} /* sentinel */
1387 /* Class timer */
1389 static PyObject *
1390 set_timer (g, args)
1391 genericobject *g;
1392 PyObject *args;
1394 return call_forms_INf (fl_set_timer, g-> ob_generic, args);
1397 static PyObject *
1398 get_timer (g, args)
1399 genericobject *g;
1400 PyObject *args;
1402 return call_forms_Rf (fl_get_timer, g-> ob_generic, args);
1405 static PyMethodDef timer_methods[] = {
1406 {"set_timer", (PyCFunction)set_timer},
1407 {"get_timer", (PyCFunction)get_timer},
1408 {NULL, NULL} /* sentinel */
1411 /* Form objects */
1413 typedef struct {
1414 PyObject_HEAD
1415 FL_FORM *ob_form;
1416 } formobject;
1418 staticforward PyTypeObject Formtype;
1420 #define is_formobject(v) ((v)->ob_type == &Formtype)
1422 static PyObject *
1423 form_show_form(f, args)
1424 formobject *f;
1425 PyObject *args;
1427 int place, border;
1428 char *name;
1429 if (!PyArg_Parse(args, "(iis)", &place, &border, &name))
1430 return NULL;
1431 fl_show_form(f->ob_form, place, border, name);
1432 Py_INCREF(Py_None);
1433 return Py_None;
1436 static PyObject *
1437 form_call(func, f, args)
1438 FL_FORM *f;
1439 PyObject *args;
1440 void (*func)(FL_FORM *);
1442 if (!PyArg_NoArgs(args)) return NULL;
1444 (*func)(f);
1446 Py_INCREF(Py_None);
1447 return Py_None;
1450 static PyObject *
1451 form_call_INiINi(func, f, args)
1452 FL_FORM *f;
1453 PyObject *args;
1454 void (*func)(FL_FORM *, int, int);
1456 int a, b;
1458 if (!PyArg_Parse(args, "(ii)", &a, &b)) return NULL;
1460 (*func)(f, a, b);
1462 Py_INCREF(Py_None);
1463 return Py_None;
1466 static PyObject *
1467 form_call_INfINf(func, f, args)
1468 FL_FORM *f;
1469 PyObject *args;
1470 void (*func)(FL_FORM *, float, float);
1472 float a, b;
1474 if (!PyArg_Parse(args, "(ff)", &a, &b)) return NULL;
1476 (*func)(f, a, b);
1478 Py_INCREF(Py_None);
1479 return Py_None;
1482 static PyObject *
1483 form_hide_form(f, args)
1484 formobject *f;
1485 PyObject *args;
1487 return form_call(fl_hide_form, f-> ob_form, args);
1490 static PyObject *
1491 form_redraw_form(f, args)
1492 formobject *f;
1493 PyObject *args;
1495 return form_call(fl_redraw_form, f-> ob_form, args);
1498 static PyObject *
1499 form_set_form_position(f, args)
1500 formobject *f;
1501 PyObject *args;
1503 return form_call_INiINi(fl_set_form_position, f-> ob_form, args);
1506 static PyObject *
1507 form_set_form_size(f, args)
1508 formobject *f;
1509 PyObject *args;
1511 return form_call_INiINi(fl_set_form_size, f-> ob_form, args);
1514 static PyObject *
1515 form_scale_form(f, args)
1516 formobject *f;
1517 PyObject *args;
1519 return form_call_INfINf(fl_scale_form, f-> ob_form, args);
1522 static PyObject *
1523 generic_add_object(f, args, func, internal_methods)
1524 formobject *f;
1525 PyObject *args;
1526 FL_OBJECT *(*func)(int, float, float, float, float, char*);
1527 PyMethodDef *internal_methods;
1529 int type;
1530 float x, y, w, h;
1531 char *name;
1532 FL_OBJECT *obj;
1534 if (!PyArg_Parse(args,"(iffffs)", &type,&x,&y,&w,&h,&name))
1535 return NULL;
1537 fl_addto_form (f-> ob_form);
1539 obj = (*func) (type, x, y, w, h, name);
1541 fl_end_form();
1543 if (obj == NULL) {
1544 PyErr_NoMemory();
1545 return NULL;
1548 return newgenericobject (obj, internal_methods);
1551 static PyObject *
1552 form_add_button(f, args)
1553 formobject *f;
1554 PyObject *args;
1556 return generic_add_object(f, args, fl_add_button, button_methods);
1559 static PyObject *
1560 form_add_lightbutton(f, args)
1561 formobject *f;
1562 PyObject *args;
1564 return generic_add_object(f, args, fl_add_lightbutton, button_methods);
1567 static PyObject *
1568 form_add_roundbutton(f, args)
1569 formobject *f;
1570 PyObject *args;
1572 return generic_add_object(f, args, fl_add_roundbutton, button_methods);
1575 static PyObject *
1576 form_add_menu (f, args)
1577 formobject *f;
1578 PyObject *args;
1580 return generic_add_object(f, args, fl_add_menu, menu_methods);
1583 static PyObject *
1584 form_add_slider(f, args)
1585 formobject *f;
1586 PyObject *args;
1588 return generic_add_object(f, args, fl_add_slider, slider_methods);
1591 static PyObject *
1592 form_add_valslider(f, args)
1593 formobject *f;
1594 PyObject *args;
1596 return generic_add_object(f, args, fl_add_valslider, slider_methods);
1599 static PyObject *
1600 form_add_dial(f, args)
1601 formobject *f;
1602 PyObject *args;
1604 return generic_add_object(f, args, fl_add_dial, dial_methods);
1607 static PyObject *
1608 form_add_counter(f, args)
1609 formobject *f;
1610 PyObject *args;
1612 return generic_add_object(f, args, fl_add_counter, counter_methods);
1615 static PyObject *
1616 form_add_clock(f, args)
1617 formobject *f;
1618 PyObject *args;
1620 return generic_add_object(f, args, fl_add_clock, clock_methods);
1623 static PyObject *
1624 form_add_box(f, args)
1625 formobject *f;
1626 PyObject *args;
1628 return generic_add_object(f, args, fl_add_box,
1629 (PyMethodDef *)NULL);
1632 static PyObject *
1633 form_add_choice(f, args)
1634 formobject *f;
1635 PyObject *args;
1637 return generic_add_object(f, args, fl_add_choice, choice_methods);
1640 static PyObject *
1641 form_add_browser(f, args)
1642 formobject *f;
1643 PyObject *args;
1645 return generic_add_object(f, args, fl_add_browser, browser_methods);
1648 static PyObject *
1649 form_add_positioner(f, args)
1650 formobject *f;
1651 PyObject *args;
1653 return generic_add_object(f, args, fl_add_positioner,
1654 positioner_methods);
1657 static PyObject *
1658 form_add_input(f, args)
1659 formobject *f;
1660 PyObject *args;
1662 return generic_add_object(f, args, fl_add_input, input_methods);
1665 static PyObject *
1666 form_add_text(f, args)
1667 formobject *f;
1668 PyObject *args;
1670 return generic_add_object(f, args, fl_add_text,
1671 (PyMethodDef *)NULL);
1674 static PyObject *
1675 form_add_timer(f, args)
1676 formobject *f;
1677 PyObject *args;
1679 return generic_add_object(f, args, fl_add_timer, timer_methods);
1682 static PyObject *
1683 form_freeze_form(f, args)
1684 formobject *f;
1685 PyObject *args;
1687 return form_call(fl_freeze_form, f-> ob_form, args);
1690 static PyObject *
1691 form_unfreeze_form(f, args)
1692 formobject *f;
1693 PyObject *args;
1695 return form_call(fl_unfreeze_form, f-> ob_form, args);
1698 static PyObject *
1699 form_activate_form(f, args)
1700 formobject *f;
1701 PyObject *args;
1703 return form_call(fl_activate_form, f-> ob_form, args);
1706 static PyObject *
1707 form_deactivate_form(f, args)
1708 formobject *f;
1709 PyObject *args;
1711 return form_call(fl_deactivate_form, f-> ob_form, args);
1714 static PyObject *
1715 form_bgn_group(f, args)
1716 formobject *f;
1717 PyObject *args;
1719 FL_OBJECT *obj;
1721 fl_addto_form(f-> ob_form);
1722 obj = fl_bgn_group();
1723 fl_end_form();
1725 if (obj == NULL) {
1726 PyErr_NoMemory();
1727 return NULL;
1730 return newgenericobject (obj, (PyMethodDef *) NULL);
1733 static PyObject *
1734 form_end_group(f, args)
1735 formobject *f;
1736 PyObject *args;
1738 fl_addto_form(f-> ob_form);
1739 fl_end_group();
1740 fl_end_form();
1741 Py_INCREF(Py_None);
1742 return Py_None;
1745 static PyObject *
1746 forms_find_first_or_last(func, f, args)
1747 FL_OBJECT *(*func)(FL_FORM *, int, float, float);
1748 formobject *f;
1749 PyObject *args;
1751 int type;
1752 float mx, my;
1753 FL_OBJECT *generic;
1754 genericobject *g;
1756 if (!PyArg_Parse(args, "(iff)", &type, &mx, &my)) return NULL;
1758 generic = (*func) (f-> ob_form, type, mx, my);
1760 if (generic == NULL)
1762 Py_INCREF(Py_None);
1763 return Py_None;
1766 g = findgeneric(generic);
1767 if (g == NULL) {
1768 PyErr_SetString(PyExc_RuntimeError,
1769 "forms_find_{first|last} returns unknown object");
1770 return NULL;
1772 Py_INCREF(g);
1773 return (PyObject *) g;
1776 static PyObject *
1777 form_find_first(f, args)
1778 formobject *f;
1779 PyObject *args;
1781 return forms_find_first_or_last(fl_find_first, f, args);
1784 static PyObject *
1785 form_find_last(f, args)
1786 formobject *f;
1787 PyObject *args;
1789 return forms_find_first_or_last(fl_find_last, f, args);
1792 static PyObject *
1793 form_set_object_focus(f, args)
1794 formobject *f;
1795 PyObject *args;
1797 genericobject *g;
1798 if (args == NULL || !is_genericobject(args)) {
1799 PyErr_BadArgument();
1800 return NULL;
1802 g = (genericobject *)args;
1803 fl_set_object_focus(f->ob_form, g->ob_generic);
1804 Py_INCREF(Py_None);
1805 return Py_None;
1808 static PyMethodDef form_methods[] = {
1809 /* adm */
1810 {"show_form", (PyCFunction)form_show_form},
1811 {"hide_form", (PyCFunction)form_hide_form},
1812 {"redraw_form", (PyCFunction)form_redraw_form},
1813 {"set_form_position", (PyCFunction)form_set_form_position},
1814 {"set_form_size", (PyCFunction)form_set_form_size},
1815 {"scale_form", (PyCFunction)form_scale_form},
1816 {"freeze_form", (PyCFunction)form_freeze_form},
1817 {"unfreeze_form", (PyCFunction)form_unfreeze_form},
1818 {"activate_form", (PyCFunction)form_activate_form},
1819 {"deactivate_form", (PyCFunction)form_deactivate_form},
1820 {"bgn_group", (PyCFunction)form_bgn_group},
1821 {"end_group", (PyCFunction)form_end_group},
1822 {"find_first", (PyCFunction)form_find_first},
1823 {"find_last", (PyCFunction)form_find_last},
1824 {"set_object_focus", (PyCFunction)form_set_object_focus},
1826 /* basic objects */
1827 {"add_button", (PyCFunction)form_add_button},
1828 /* {"add_bitmap", (method)form_add_bitmap}, */
1829 {"add_lightbutton", (PyCFunction)form_add_lightbutton},
1830 {"add_roundbutton", (PyCFunction)form_add_roundbutton},
1831 {"add_menu", (PyCFunction)form_add_menu},
1832 {"add_slider", (PyCFunction)form_add_slider},
1833 {"add_positioner", (PyCFunction)form_add_positioner},
1834 {"add_valslider", (PyCFunction)form_add_valslider},
1835 {"add_dial", (PyCFunction)form_add_dial},
1836 {"add_counter", (PyCFunction)form_add_counter},
1837 {"add_box", (PyCFunction)form_add_box},
1838 {"add_clock", (PyCFunction)form_add_clock},
1839 {"add_choice", (PyCFunction)form_add_choice},
1840 {"add_browser", (PyCFunction)form_add_browser},
1841 {"add_input", (PyCFunction)form_add_input},
1842 {"add_timer", (PyCFunction)form_add_timer},
1843 {"add_text", (PyCFunction)form_add_text},
1844 {NULL, NULL} /* sentinel */
1847 static void
1848 form_dealloc(f)
1849 formobject *f;
1851 releaseobjects(f->ob_form);
1852 if (f->ob_form->visible)
1853 fl_hide_form(f->ob_form);
1854 fl_free_form(f->ob_form);
1855 PyMem_DEL(f);
1858 #define OFF(x) offsetof(FL_FORM, x)
1860 static struct memberlist form_memberlist[] = {
1861 {"window", T_LONG, OFF(window), RO},
1862 {"w", T_FLOAT, OFF(w)},
1863 {"h", T_FLOAT, OFF(h)},
1864 {"x", T_FLOAT, OFF(x), RO},
1865 {"y", T_FLOAT, OFF(y), RO},
1866 {"deactivated", T_INT, OFF(deactivated)},
1867 {"visible", T_INT, OFF(visible), RO},
1868 {"frozen", T_INT, OFF(frozen), RO},
1869 {"doublebuf", T_INT, OFF(doublebuf)},
1870 {NULL} /* Sentinel */
1873 #undef OFF
1875 static PyObject *
1876 form_getattr(f, name)
1877 formobject *f;
1878 char *name;
1880 PyObject *meth;
1882 meth = Py_FindMethod(form_methods, (PyObject *)f, name);
1883 if (meth != NULL)
1884 return meth;
1885 PyErr_Clear();
1886 return PyMember_Get((char *)f->ob_form, form_memberlist, name);
1889 static int
1890 form_setattr(f, name, v)
1891 formobject *f;
1892 char *name;
1893 PyObject *v;
1895 if (v == NULL) {
1896 PyErr_SetString(PyExc_TypeError,
1897 "can't delete form attributes");
1898 return -1;
1901 return PyMember_Set((char *)f->ob_form, form_memberlist, name, v);
1904 static PyObject *
1905 form_repr(f)
1906 formobject *f;
1908 char buf[100];
1909 sprintf(buf, "<FORMS_form at %lx, window=%ld>",
1910 (long)f, f->ob_form->window);
1911 return PyString_FromString(buf);
1914 static PyTypeObject Formtype = {
1915 PyObject_HEAD_INIT(&PyType_Type)
1916 0, /*ob_size*/
1917 "FORMS_form", /*tp_name*/
1918 sizeof(formobject), /*tp_size*/
1919 0, /*tp_itemsize*/
1920 /* methods */
1921 (destructor)form_dealloc, /*tp_dealloc*/
1922 0, /*tp_print*/
1923 (getattrfunc)form_getattr, /*tp_getattr*/
1924 (setattrfunc)form_setattr, /*tp_setattr*/
1925 0, /*tp_compare*/
1926 (reprfunc)form_repr, /*tp_repr*/
1929 static PyObject *
1930 newformobject(form)
1931 FL_FORM *form;
1933 formobject *f;
1934 f = PyObject_NEW(formobject, &Formtype);
1935 if (f == NULL)
1936 return NULL;
1937 f->ob_form = form;
1938 return (PyObject *)f;
1942 /* The "fl" module */
1944 static PyObject *
1945 forms_make_form(dummy, args)
1946 PyObject *dummy;
1947 PyObject *args;
1949 int type;
1950 float w, h;
1951 FL_FORM *form;
1952 if (!PyArg_Parse(args, "(iff)", &type, &w, &h))
1953 return NULL;
1954 form = fl_bgn_form(type, w, h);
1955 if (form == NULL) {
1956 /* XXX Actually, cannot happen! */
1957 PyErr_NoMemory();
1958 return NULL;
1960 fl_end_form();
1961 return newformobject(form);
1964 static PyObject *
1965 forms_activate_all_forms(f, args)
1966 PyObject *f;
1967 PyObject *args;
1969 fl_activate_all_forms();
1970 Py_INCREF(Py_None);
1971 return Py_None;
1974 static PyObject *
1975 forms_deactivate_all_forms(f, args)
1976 PyObject *f;
1977 PyObject *args;
1979 fl_deactivate_all_forms();
1980 Py_INCREF(Py_None);
1981 return Py_None;
1984 static PyObject *my_event_callback = NULL;
1986 static PyObject *
1987 forms_set_event_call_back(dummy, args)
1988 PyObject *dummy;
1989 PyObject *args;
1991 if (args == Py_None)
1992 args = NULL;
1993 my_event_callback = args;
1994 Py_XINCREF(args);
1995 Py_INCREF(Py_None);
1996 return Py_None;
1999 static PyObject *
2000 forms_do_or_check_forms(dummy, args, func)
2001 PyObject *dummy;
2002 PyObject *args;
2003 FL_OBJECT *(*func)();
2005 FL_OBJECT *generic;
2006 genericobject *g;
2007 PyObject *arg, *res;
2009 if (!PyArg_NoArgs(args))
2010 return NULL;
2012 for (;;) {
2013 Py_BEGIN_ALLOW_THREADS
2014 generic = (*func)();
2015 Py_END_ALLOW_THREADS
2016 if (generic == NULL) {
2017 Py_INCREF(Py_None);
2018 return Py_None;
2020 if (generic == FL_EVENT) {
2021 int dev;
2022 short val;
2023 if (my_event_callback == NULL)
2024 return PyInt_FromLong(-1L);
2025 dev = fl_qread(&val);
2026 arg = Py_BuildValue("(ih)", dev, val);
2027 if (arg == NULL)
2028 return NULL;
2029 res = PyEval_CallObject(my_event_callback, arg);
2030 Py_XDECREF(res);
2031 Py_DECREF(arg);
2032 if (res == NULL)
2033 return NULL; /* Callback raised exception */
2034 continue;
2036 g = findgeneric(generic);
2037 if (g == NULL) {
2038 /* Object not known to us (some dialogs cause this) */
2039 continue; /* Ignore it */
2041 if (g->ob_callback == NULL) {
2042 Py_INCREF(g);
2043 return ((PyObject *) g);
2045 arg = Py_BuildValue("(OO)", (PyObject *)g, g->ob_callback_arg);
2046 if (arg == NULL)
2047 return NULL;
2048 res = PyEval_CallObject(g->ob_callback, arg);
2049 Py_XDECREF(res);
2050 Py_DECREF(arg);
2051 if (res == NULL)
2052 return NULL; /* Callback raised exception */
2056 static PyObject *
2057 forms_do_forms(dummy, args)
2058 PyObject *dummy;
2059 PyObject *args;
2061 return forms_do_or_check_forms(dummy, args, fl_do_forms);
2064 static PyObject *
2065 forms_check_forms(dummy, args)
2066 PyObject *dummy;
2067 PyObject *args;
2069 return forms_do_or_check_forms(dummy, args, fl_check_forms);
2072 static PyObject *
2073 forms_do_only_forms(dummy, args)
2074 PyObject *dummy;
2075 PyObject *args;
2077 return forms_do_or_check_forms(dummy, args, fl_do_only_forms);
2080 static PyObject *
2081 forms_check_only_forms(dummy, args)
2082 PyObject *dummy;
2083 PyObject *args;
2085 return forms_do_or_check_forms(dummy, args, fl_check_only_forms);
2088 #ifdef UNUSED
2089 static PyObject *
2090 fl_call(func, args)
2091 PyObject *args;
2092 void (*func)();
2094 if (!PyArg_NoArgs(args))
2095 return NULL;
2096 (*func)();
2097 Py_INCREF(Py_None);
2098 return Py_None;
2100 #endif
2102 static PyObject *
2103 forms_set_graphics_mode(dummy, args)
2104 PyObject *dummy;
2105 PyObject *args;
2107 int rgbmode, doublebuf;
2109 if (!PyArg_Parse(args, "(ii)", &rgbmode, &doublebuf))
2110 return NULL;
2111 fl_set_graphics_mode(rgbmode,doublebuf);
2112 Py_INCREF(Py_None);
2113 return Py_None;
2116 static PyObject *
2117 forms_get_rgbmode(dummy, args)
2118 PyObject *dummy;
2119 PyObject *args;
2121 extern int fl_rgbmode;
2123 if (args != NULL) {
2124 PyErr_BadArgument();
2125 return NULL;
2127 return PyInt_FromLong((long)fl_rgbmode);
2130 static PyObject *
2131 forms_show_errors(dummy, args)
2132 PyObject *dummy;
2133 PyObject *args;
2135 int show;
2136 if (!PyArg_Parse(args, "i", &show))
2137 return NULL;
2138 fl_show_errors(show);
2139 Py_INCREF(Py_None);
2140 return Py_None;
2143 static PyObject *
2144 forms_set_font_name(dummy, args)
2145 PyObject *dummy;
2146 PyObject *args;
2148 int numb;
2149 char *name;
2150 if (!PyArg_Parse(args, "(is)", &numb, &name))
2151 return NULL;
2152 fl_set_font_name(numb, name);
2153 Py_INCREF(Py_None);
2154 return Py_None;
2158 static PyObject *
2159 forms_qdevice(self, args)
2160 PyObject *self;
2161 PyObject *args;
2163 short arg1;
2164 if (!PyArg_Parse(args, "h", &arg1))
2165 return NULL;
2166 fl_qdevice(arg1);
2167 Py_INCREF(Py_None);
2168 return Py_None;
2171 static PyObject *
2172 forms_unqdevice(self, args)
2173 PyObject *self;
2174 PyObject *args;
2176 short arg1;
2177 if (!PyArg_Parse(args, "h", &arg1))
2178 return NULL;
2179 fl_unqdevice(arg1);
2180 Py_INCREF(Py_None);
2181 return Py_None;
2184 static PyObject *
2185 forms_isqueued(self, args)
2186 PyObject *self;
2187 PyObject *args;
2189 long retval;
2190 short arg1;
2191 if (!PyArg_Parse(args, "h", &arg1))
2192 return NULL;
2193 retval = fl_isqueued(arg1);
2195 return PyInt_FromLong(retval);
2198 static PyObject *
2199 forms_qtest(self, args)
2200 PyObject *self;
2201 PyObject *args;
2203 long retval;
2204 retval = fl_qtest();
2205 return PyInt_FromLong(retval);
2209 static PyObject *
2210 forms_qread(self, args)
2211 PyObject *self;
2212 PyObject *args;
2214 int dev;
2215 short val;
2216 Py_BEGIN_ALLOW_THREADS
2217 dev = fl_qread(&val);
2218 Py_END_ALLOW_THREADS
2219 return Py_BuildValue("(ih)", dev, val);
2222 static PyObject *
2223 forms_qreset(self, args)
2224 PyObject *self;
2225 PyObject *args;
2227 if (!PyArg_NoArgs(args)) return NULL;
2229 fl_qreset();
2230 Py_INCREF(Py_None);
2231 return Py_None;
2234 static PyObject *
2235 forms_qenter(self, args)
2236 PyObject *self;
2237 PyObject *args;
2239 short arg1, arg2;
2240 if (!PyArg_Parse(args, "(hh)", &arg1, &arg2))
2241 return NULL;
2242 fl_qenter(arg1, arg2);
2243 Py_INCREF(Py_None);
2244 return Py_None;
2247 static PyObject *
2248 forms_color(self, args)
2249 PyObject *self;
2250 PyObject *args;
2252 int arg;
2254 if (!PyArg_Parse(args, "i", &arg)) return NULL;
2256 fl_color((short) arg);
2258 Py_INCREF(Py_None);
2259 return Py_None;
2262 static PyObject *
2263 forms_mapcolor(self, args)
2264 PyObject *self;
2265 PyObject *args;
2267 int arg0, arg1, arg2, arg3;
2269 if (!PyArg_Parse(args, "(iiii)", &arg0, &arg1, &arg2, &arg3))
2270 return NULL;
2272 fl_mapcolor(arg0, (short) arg1, (short) arg2, (short) arg3);
2274 Py_INCREF(Py_None);
2275 return Py_None;
2278 static PyObject *
2279 forms_getmcolor(self, args)
2280 PyObject *self;
2281 PyObject *args;
2283 int arg;
2284 short r, g, b;
2286 if (!PyArg_Parse(args, "i", &arg)) return NULL;
2288 fl_getmcolor(arg, &r, &g, &b);
2290 return Py_BuildValue("(hhh)", r, g, b);
2293 static PyObject *
2294 forms_get_mouse(self, args)
2295 PyObject *self;
2296 PyObject *args;
2298 float x, y;
2300 if (!PyArg_NoArgs(args)) return NULL;
2302 fl_get_mouse(&x, &y);
2304 return Py_BuildValue("(ff)", x, y);
2307 static PyObject *
2308 forms_tie(self, args)
2309 PyObject *self;
2310 PyObject *args;
2312 short arg1, arg2, arg3;
2313 if (!PyArg_Parse(args, "(hhh)", &arg1, &arg2, &arg3))
2314 return NULL;
2315 fl_tie(arg1, arg2, arg3);
2316 Py_INCREF(Py_None);
2317 return Py_None;
2320 static PyObject *
2321 forms_show_message(f, args)
2322 PyObject *f;
2323 PyObject *args;
2325 char *a, *b, *c;
2327 if (!PyArg_Parse(args, "(sss)", &a, &b, &c)) return NULL;
2329 Py_BEGIN_ALLOW_THREADS
2330 fl_show_message(a, b, c);
2331 Py_END_ALLOW_THREADS
2333 Py_INCREF(Py_None);
2334 return Py_None;
2337 static PyObject *
2338 forms_show_choice(f, args)
2339 PyObject *f;
2340 PyObject *args;
2342 char *m1, *m2, *m3, *b1, *b2, *b3;
2343 int nb;
2344 char *format;
2345 long rv;
2347 if (args == NULL || !PyTuple_Check(args)) {
2348 PyErr_BadArgument();
2349 return NULL;
2351 nb = PyTuple_Size(args) - 3;
2352 if (nb <= 0) {
2353 PyErr_SetString(PyExc_TypeError,
2354 "need at least one button label");
2355 return NULL;
2357 if (PyInt_Check(PyTuple_GetItem(args, 3))) {
2358 PyErr_SetString(PyExc_TypeError,
2359 "'number-of-buttons' argument not needed");
2360 return NULL;
2362 switch (nb) {
2363 case 1: format = "(ssss)"; break;
2364 case 2: format = "(sssss)"; break;
2365 case 3: format = "(ssssss)"; break;
2366 default:
2367 PyErr_SetString(PyExc_TypeError, "too many button labels");
2368 return NULL;
2371 if (!PyArg_Parse(args, format, &m1, &m2, &m3, &b1, &b2, &b3))
2372 return NULL;
2374 Py_BEGIN_ALLOW_THREADS
2375 rv = fl_show_choice(m1, m2, m3, nb, b1, b2, b3);
2376 Py_END_ALLOW_THREADS
2377 return PyInt_FromLong(rv);
2380 static PyObject *
2381 forms_show_question(f, args)
2382 PyObject *f;
2383 PyObject *args;
2385 int ret;
2386 char *a, *b, *c;
2388 if (!PyArg_Parse(args, "(sss)", &a, &b, &c)) return NULL;
2390 Py_BEGIN_ALLOW_THREADS
2391 ret = fl_show_question(a, b, c);
2392 Py_END_ALLOW_THREADS
2394 return PyInt_FromLong((long) ret);
2397 static PyObject *
2398 forms_show_input(f, args)
2399 PyObject *f;
2400 PyObject *args;
2402 char *str;
2403 char *a, *b;
2405 if (!PyArg_Parse(args, "(ss)", &a, &b)) return NULL;
2407 Py_BEGIN_ALLOW_THREADS
2408 str = fl_show_input(a, b);
2409 Py_END_ALLOW_THREADS
2411 if (str == NULL) {
2412 Py_INCREF(Py_None);
2413 return Py_None;
2415 return PyString_FromString(str);
2418 static PyObject *
2419 forms_file_selector(f, args)
2420 PyObject *f;
2421 PyObject *args;
2423 char *str;
2424 char *a, *b, *c, *d;
2426 if (!PyArg_Parse(args, "(ssss)", &a, &b, &c, &d)) return NULL;
2428 Py_BEGIN_ALLOW_THREADS
2429 str = fl_show_file_selector(a, b, c, d);
2430 Py_END_ALLOW_THREADS
2432 if (str == NULL) {
2433 Py_INCREF(Py_None);
2434 return Py_None;
2436 return PyString_FromString(str);
2440 static PyObject *
2441 forms_file_selector_func(args, func)
2442 PyObject *args;
2443 char *(*func)();
2445 char *str;
2447 str = (*func) ();
2449 if (str == NULL) {
2450 Py_INCREF(Py_None);
2451 return Py_None;
2453 return PyString_FromString(str);
2456 static PyObject *
2457 forms_get_directory(f, args)
2458 PyObject *f;
2459 PyObject *args;
2461 return forms_file_selector_func(args, fl_get_directory);
2464 static PyObject *
2465 forms_get_pattern(f, args)
2466 PyObject *f;
2467 PyObject *args;
2469 return forms_file_selector_func(args, fl_get_pattern);
2472 static PyObject *
2473 forms_get_filename(f, args)
2474 PyObject *f;
2475 PyObject *args;
2477 return forms_file_selector_func(args, fl_get_filename);
2480 static PyMethodDef forms_methods[] = {
2481 /* adm */
2482 {"make_form", forms_make_form},
2483 {"activate_all_forms", forms_activate_all_forms},
2484 {"deactivate_all_forms",forms_deactivate_all_forms},
2485 /* gl support wrappers */
2486 {"qdevice", forms_qdevice},
2487 {"unqdevice", forms_unqdevice},
2488 {"isqueued", forms_isqueued},
2489 {"qtest", forms_qtest},
2490 {"qread", forms_qread},
2491 /* {"blkqread", forms_blkqread}, */
2492 {"qreset", forms_qreset},
2493 {"qenter", forms_qenter},
2494 {"get_mouse", forms_get_mouse},
2495 {"tie", forms_tie},
2496 /* {"new_events", forms_new_events}, */
2497 {"color", forms_color},
2498 {"mapcolor", forms_mapcolor},
2499 {"getmcolor", forms_getmcolor},
2500 /* interaction */
2501 {"do_forms", forms_do_forms},
2502 {"do_only_forms", forms_do_only_forms},
2503 {"check_forms", forms_check_forms},
2504 {"check_only_forms", forms_check_only_forms},
2505 {"set_event_call_back", forms_set_event_call_back},
2506 /* goodies */
2507 {"show_message", forms_show_message},
2508 {"show_question", forms_show_question},
2509 {"show_choice", forms_show_choice},
2510 {"show_input", forms_show_input},
2511 {"show_file_selector", forms_file_selector},
2512 {"file_selector", forms_file_selector}, /* BW compat */
2513 {"get_directory", forms_get_directory},
2514 {"get_pattern", forms_get_pattern},
2515 {"get_filename", forms_get_filename},
2516 {"set_graphics_mode", forms_set_graphics_mode},
2517 {"get_rgbmode", forms_get_rgbmode},
2518 {"show_errors", forms_show_errors},
2519 {"set_font_name", forms_set_font_name},
2520 {NULL, NULL} /* sentinel */
2523 DL_EXPORT(void)
2524 initfl()
2526 Py_InitModule("fl", forms_methods);
2527 foreground();
2528 fl_init();