1 /* FL module -- interface to Mark Overmars' FORMS Library. */
3 /* This code works with FORMS version 2.2 (if you defined
4 OBSOLETE_FORMS_CALLS), and 2.3.
5 FORMS can be ftp'ed from ftp.cs.ruu.nl (131.211.80.17), directory
8 /* 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.
15 * (A fix will probably also have to synchronize with the gl module).
20 #include "structmember.h"
22 /* Generic Forms Objects */
26 FL_OBJECT
*ob_generic
;
27 PyMethodDef
*ob_methods
;
28 PyObject
*ob_callback
;
29 PyObject
*ob_callback_arg
;
32 static PyTypeObject GenericObjecttype
;
34 #define is_genericobject(g) ((g)->ob_type == &GenericObjecttype)
36 /* List of all objects (XXX this should be a hash table on address...) */
38 static PyObject
*allgenerics
= NULL
;
39 static int nfreeslots
= 0;
41 /* Add an object to the list of known objects */
44 knowgeneric(genericobject
*g
)
47 /* Create the list if it doesn't already exist */
48 if (allgenerics
== NULL
) {
49 allgenerics
= PyList_New(0);
50 if (allgenerics
== NULL
) {
52 return; /* Too bad, live without allgenerics... */
56 /* Search the list for reusable slots (NULL items) */
57 /* XXX This can be made faster! */
58 n
= PyList_Size(allgenerics
);
59 for (i
= 0; i
< n
; i
++) {
60 if (PyList_GetItem(allgenerics
, i
) == NULL
) {
62 PyList_SetItem(allgenerics
, i
, (PyObject
*)g
);
67 /* Strange... no free slots found... */
70 /* No free entries, append new item to the end */
71 PyList_Append(allgenerics
, (PyObject
*)g
);
74 /* Find an object in the list of known objects */
76 static genericobject
*
77 findgeneric(FL_OBJECT
*generic
)
82 if (allgenerics
== NULL
)
83 return NULL
; /* No objects known yet */
84 n
= PyList_Size(allgenerics
);
85 for (i
= 0; i
< n
; i
++) {
86 g
= (genericobject
*)PyList_GetItem(allgenerics
, i
);
87 if (g
!= NULL
&& g
->ob_generic
== generic
)
90 return NULL
; /* Unknown object */
93 /* Remove an object from the list of known objects */
96 forgetgeneric(genericobject
*g
)
100 Py_XDECREF(g
->ob_callback
);
101 g
->ob_callback
= NULL
;
102 Py_XDECREF(g
->ob_callback_arg
);
103 g
->ob_callback_arg
= NULL
;
104 if (allgenerics
== NULL
)
105 return; /* No objects known yet */
106 n
= PyList_Size(allgenerics
);
107 for (i
= 0; i
< n
; i
++) {
108 if (g
== (genericobject
*)PyList_GetItem(allgenerics
, i
)) {
109 PyList_SetItem(allgenerics
, i
, (PyObject
*)NULL
);
116 /* Called when a form is about to be freed --
117 remove all the objects that we know about from it. */
120 releaseobjects(FL_FORM
*form
)
125 if (allgenerics
== NULL
)
126 return; /* No objects known yet */
127 n
= PyList_Size(allgenerics
);
128 for (i
= 0; i
< n
; i
++) {
129 g
= (genericobject
*)PyList_GetItem(allgenerics
, i
);
130 if (g
!= NULL
&& g
->ob_generic
->form
== form
) {
131 fl_delete_object(g
->ob_generic
);
132 /* The object is now unreachable for
133 do_forms and check_forms, so
134 delete it from the list of known objects */
135 Py_XDECREF(g
->ob_callback
);
136 g
->ob_callback
= NULL
;
137 Py_XDECREF(g
->ob_callback_arg
);
138 g
->ob_callback_arg
= NULL
;
139 PyList_SetItem(allgenerics
, i
, (PyObject
*)NULL
);
146 /* Methods of generic objects */
149 generic_set_call_back(genericobject
*g
, PyObject
*args
)
151 if (PyTuple_GET_SIZE(args
) == 0) {
152 Py_XDECREF(g
->ob_callback
);
153 Py_XDECREF(g
->ob_callback_arg
);
154 g
->ob_callback
= NULL
;
155 g
->ob_callback_arg
= NULL
;
159 if (!PyArg_UnpackTuple(args
, "set_call_back", 2, 2, &a
, &b
)
161 Py_XDECREF(g
->ob_callback
);
162 Py_XDECREF(g
->ob_callback_arg
);
164 Py_INCREF(g
->ob_callback
);
165 g
->ob_callback_arg
= b
;
166 Py_INCREF(g
->ob_callback_arg
);
173 generic_call(genericobject
*g
, void (*func
)(FL_OBJECT
*))
175 (*func
)(g
->ob_generic
);
181 generic_delete_object(genericobject
*g
)
184 res
= generic_call(g
, fl_delete_object
);
191 generic_show_object(genericobject
*g
)
193 return generic_call(g
, fl_show_object
);
197 generic_hide_object(genericobject
*g
)
199 return generic_call(g
, fl_hide_object
);
203 generic_redraw_object(genericobject
*g
)
205 return generic_call(g
, fl_redraw_object
);
208 #ifdef OBSOLETE_FORMS_CALLS
210 /* (un)freeze_object() are obsolete in FORMS 2.2 and unsupported
211 in 2.3. Since there's no foolproof way to tell which version we're
212 using, we omit them unconditionally. */
215 generic_freeze_object(genericobject
*g
)
217 return generic_call(g
, fl_freeze_object
);
221 generic_unfreeze_object(genericobject
*g
)
223 return generic_call(g
, fl_unfreeze_object
);
226 #endif /* OBSOLETE_FORMS_CALLS */
229 generic_activate_object(genericobject
*g
)
231 return generic_call(g
, fl_activate_object
);
235 generic_deactivate_object(genericobject
*g
)
237 return generic_call(g
, fl_deactivate_object
);
241 generic_set_object_shortcut(genericobject
*g
, PyObject
*args
)
244 if (!PyArg_ParseTuple(args
, "s:set_object_shortcut", &str
))
246 fl_set_object_shortcut(g
->ob_generic
, str
);
251 static PyMethodDef generic_methods
[] = {
252 {"set_call_back", (PyCFunction
)generic_set_call_back
, METH_VARARGS
},
253 {"delete_object", (PyCFunction
)generic_delete_object
, METH_NOARGS
},
254 {"show_object", (PyCFunction
)generic_show_object
, METH_NOARGS
},
255 {"hide_object", (PyCFunction
)generic_hide_object
, METH_NOARGS
},
256 {"redraw_object", (PyCFunction
)generic_redraw_object
, METH_NOARGS
},
257 #ifdef OBSOLETE_FORMS_CALLS
258 {"freeze_object", (PyCFunction
)generic_freeze_object
, METH_NOARGS
},
259 {"unfreeze_object", (PyCFunction
)generic_unfreeze_object
, METH_NOARGS
},
261 {"activate_object", (PyCFunction
)generic_activate_object
, METH_NOARGS
},
262 {"deactivate_object", (PyCFunction
)generic_deactivate_object
, METH_NOARGS
},
263 {"set_object_shortcut", (PyCFunction
)generic_set_object_shortcut
, METH_VARARGS
},
264 {NULL
, NULL
} /* sentinel */
268 generic_dealloc(genericobject
*g
)
270 fl_free_object(g
->ob_generic
);
271 Py_XDECREF(g
->ob_callback
);
272 Py_XDECREF(g
->ob_callback_arg
);
276 #define OFF(x) offsetof(FL_OBJECT, x)
278 static struct memberlist generic_memberlist
[] = {
279 {"objclass", T_INT
, OFF(objclass
), RO
},
280 {"type", T_INT
, OFF(type
), RO
},
281 {"boxtype", T_INT
, OFF(boxtype
)},
282 {"x", T_FLOAT
, OFF(x
)},
283 {"y", T_FLOAT
, OFF(y
)},
284 {"w", T_FLOAT
, OFF(w
)},
285 {"h", T_FLOAT
, OFF(h
)},
286 {"col1", T_INT
, OFF(col1
)},
287 {"col2", T_INT
, OFF(col2
)},
288 {"align", T_INT
, OFF(align
)},
289 {"lcol", T_INT
, OFF(lcol
)},
290 {"lsize", T_FLOAT
, OFF(lsize
)},
291 /* "label" is treated specially! */
292 {"lstyle", T_INT
, OFF(lstyle
)},
293 {"pushed", T_INT
, OFF(pushed
), RO
},
294 {"focus", T_INT
, OFF(focus
), RO
},
295 {"belowmouse", T_INT
, OFF(belowmouse
),RO
},
296 /* {"frozen", T_INT, OFF(frozen), RO}, */
297 {"active", T_INT
, OFF(active
)},
298 {"input", T_INT
, OFF(input
)},
299 {"visible", T_INT
, OFF(visible
), RO
},
300 {"radio", T_INT
, OFF(radio
)},
301 {"automatic", T_INT
, OFF(automatic
)},
302 {NULL
} /* Sentinel */
308 generic_getattr(genericobject
*g
, char *name
)
312 /* XXX Ought to special-case name "__methods__" */
313 if (g
-> ob_methods
) {
314 meth
= Py_FindMethod(g
->ob_methods
, (PyObject
*)g
, name
);
315 if (meth
!= NULL
) return meth
;
319 meth
= Py_FindMethod(generic_methods
, (PyObject
*)g
, name
);
324 /* "label" is an exception, getmember only works for char pointers,
325 not for char arrays */
326 if (strcmp(name
, "label") == 0)
327 return PyString_FromString(g
->ob_generic
->label
);
329 return PyMember_Get((char *)g
->ob_generic
, generic_memberlist
, name
);
333 generic_setattr(genericobject
*g
, char *name
, PyObject
*v
)
338 PyErr_SetString(PyExc_TypeError
,
339 "can't delete forms object attributes");
343 /* "label" is an exception: setmember doesn't set strings;
344 and FORMS wants you to call a function to set the label */
345 if (strcmp(name
, "label") == 0) {
346 if (!PyString_Check(v
)) {
347 PyErr_SetString(PyExc_TypeError
,
348 "label attr must be string");
351 fl_set_object_label(g
->ob_generic
, PyString_AsString(v
));
355 ret
= PyMember_Set((char *)g
->ob_generic
, generic_memberlist
, name
, v
);
357 /* Rather than calling all the various set_object_* functions,
358 we call fl_redraw_object here. This is sometimes redundant
359 but I doubt that's a big problem */
361 fl_redraw_object(g
->ob_generic
);
367 generic_repr(genericobject
*g
)
370 PyOS_snprintf(buf
, sizeof(buf
), "<FORMS_object at %p, objclass=%d>",
371 g
, g
->ob_generic
->objclass
);
372 return PyString_FromString(buf
);
375 static PyTypeObject GenericObjecttype
= {
376 PyObject_HEAD_INIT(&PyType_Type
)
378 "fl.FORMS_object", /*tp_name*/
379 sizeof(genericobject
), /*tp_size*/
382 (destructor
)generic_dealloc
, /*tp_dealloc*/
384 (getattrfunc
)generic_getattr
, /*tp_getattr*/
385 (setattrfunc
)generic_setattr
, /*tp_setattr*/
387 (reprfunc
)generic_repr
, /*tp_repr*/
391 newgenericobject(FL_OBJECT
*generic
, PyMethodDef
*methods
)
394 g
= PyObject_New(genericobject
, &GenericObjecttype
);
397 g
-> ob_generic
= generic
;
398 g
->ob_methods
= methods
;
399 g
->ob_callback
= NULL
;
400 g
->ob_callback_arg
= NULL
;
402 return (PyObject
*)g
;
405 /**********************************************************************/
406 /* Some common calling sequences */
408 /* void func (object, float) */
410 call_forms_INf (void (*func
)(FL_OBJECT
*, float), FL_OBJECT
*obj
, PyObject
*args
)
414 if (!PyArg_Parse(args
, "f", ¶meter
)) return NULL
;
416 (*func
) (obj
, parameter
);
422 /* void func (object, float) */
424 call_forms_INfINf (void (*func
)(FL_OBJECT
*, float, float), FL_OBJECT
*obj
, PyObject
*args
)
428 if (!PyArg_Parse(args
, "(ff)", &par1
, &par2
)) return NULL
;
430 (*func
) (obj
, par1
, par2
);
436 /* void func (object, int) */
438 call_forms_INi (void (*func
)(FL_OBJECT
*, int), FL_OBJECT
*obj
, PyObject
*args
)
442 if (!PyArg_Parse(args
, "i", ¶meter
)) return NULL
;
444 (*func
) (obj
, parameter
);
450 /* void func (object, char) */
452 call_forms_INc (void (*func
)(FL_OBJECT
*, int), FL_OBJECT
*obj
, PyObject
*args
)
456 if (!PyArg_Parse(args
, "s", &a
)) return NULL
;
464 /* void func (object, string) */
466 call_forms_INstr (void (*func
)(FL_OBJECT
*, char *), FL_OBJECT
*obj
, PyObject
*args
)
470 if (!PyArg_Parse(args
, "s", &a
)) return NULL
;
479 /* void func (object, int, string) */
481 call_forms_INiINstr (void (*func
)(FL_OBJECT
*, int, char *), FL_OBJECT
*obj
, PyObject
*args
)
486 if (!PyArg_Parse(args
, "(is)", &a
, &b
)) return NULL
;
495 /* void func (object, int, int) */
497 call_forms_INiINi (void (*func
)(FL_OBJECT
*, int, int), FL_OBJECT
*obj
, PyObject
*args
)
501 if (!PyArg_Parse(args
, "(ii)", &par1
, &par2
)) return NULL
;
503 (*func
) (obj
, par1
, par2
);
510 /* int func (object) */
512 call_forms_Ri (int (*func
)(FL_OBJECT
*), FL_OBJECT
*obj
)
516 retval
= (*func
) (obj
);
518 return PyInt_FromLong ((long) retval
);
521 /* char * func (object) */
523 call_forms_Rstr (char * (*func
)(FL_OBJECT
*), FL_OBJECT
*obj
)
533 return PyString_FromString (str
);
536 /* int func (object) */
538 call_forms_Rf (float (*func
)(FL_OBJECT
*), FL_OBJECT
*obj
)
542 retval
= (*func
) (obj
);
544 return PyFloat_FromDouble (retval
);
548 call_forms_OUTfOUTf (void (*func
)(FL_OBJECT
*, float *, float *), FL_OBJECT
*obj
)
552 (*func
) (obj
, &f1
, &f2
);
554 return Py_BuildValue("(ff)", f1
, f2
);
559 call_forms_OUTf (void (*func
)(FL_OBJECT
*, float *), FL_OBJECT
*obj
)
565 return PyFloat_FromDouble (f
);
569 /**********************************************************************/
570 /* Class : browser */
573 set_browser_topline(genericobject
*g
, PyObject
*args
)
575 return call_forms_INi (fl_set_browser_topline
, g
-> ob_generic
, args
);
579 clear_browser(genericobject
*g
)
581 return generic_call (g
, fl_clear_browser
);
585 add_browser_line (genericobject
*g
, PyObject
*args
)
587 return call_forms_INstr (fl_add_browser_line
, g
-> ob_generic
, args
);
591 addto_browser (genericobject
*g
, PyObject
*args
)
593 return call_forms_INstr (fl_addto_browser
, g
-> ob_generic
, args
);
597 insert_browser_line (genericobject
*g
, PyObject
*args
)
599 return call_forms_INiINstr (fl_insert_browser_line
,
600 g
-> ob_generic
, args
);
604 delete_browser_line (genericobject
*g
, PyObject
*args
)
606 return call_forms_INi (fl_delete_browser_line
, g
-> ob_generic
, args
);
610 replace_browser_line (genericobject
*g
, PyObject
*args
)
612 return call_forms_INiINstr (fl_replace_browser_line
,
613 g
-> ob_generic
, args
);
617 get_browser_line(genericobject
*g
, PyObject
*args
)
622 if (!PyArg_Parse(args
, "i", &i
))
625 str
= fl_get_browser_line (g
->ob_generic
, i
);
631 return PyString_FromString (str
);
635 load_browser (genericobject
*g
, PyObject
*args
)
637 /* XXX strictly speaking this is wrong since fl_load_browser
638 XXX returns int, not void */
639 return call_forms_INstr (fl_load_browser
, g
-> ob_generic
, args
);
643 get_browser_maxline(genericobject
*g
)
645 return call_forms_Ri (fl_get_browser_maxline
, g
-> ob_generic
);
649 select_browser_line (genericobject
*g
, PyObject
*args
)
651 return call_forms_INi (fl_select_browser_line
, g
-> ob_generic
, args
);
655 deselect_browser_line (genericobject
*g
, PyObject
*args
)
657 return call_forms_INi (fl_deselect_browser_line
, g
-> ob_generic
, args
);
661 deselect_browser (genericobject
*g
)
663 return generic_call (g
, fl_deselect_browser
);
667 isselected_browser_line (genericobject
*g
, PyObject
*args
)
671 if (!PyArg_Parse(args
, "i", &i
))
674 j
= fl_isselected_browser_line (g
->ob_generic
, i
);
676 return PyInt_FromLong (j
);
680 get_browser (genericobject
*g
)
682 return call_forms_Ri (fl_get_browser
, g
-> ob_generic
);
686 set_browser_fontsize (genericobject
*g
, PyObject
*args
)
688 return call_forms_INf (fl_set_browser_fontsize
, g
-> ob_generic
, args
);
692 set_browser_fontstyle (genericobject
*g
, PyObject
*args
)
694 return call_forms_INi (fl_set_browser_fontstyle
, g
-> ob_generic
, args
);
698 set_browser_specialkey (genericobject
*g
, PyObject
*args
)
700 return call_forms_INc(fl_set_browser_specialkey
, g
-> ob_generic
, args
);
703 static PyMethodDef browser_methods
[] = {
704 {"set_browser_topline", (PyCFunction
)set_browser_topline
,
706 {"clear_browser", (PyCFunction
)clear_browser
,
708 {"add_browser_line", (PyCFunction
)add_browser_line
,
710 {"addto_browser", (PyCFunction
)addto_browser
,
712 {"insert_browser_line", (PyCFunction
)insert_browser_line
,
714 {"delete_browser_line", (PyCFunction
)delete_browser_line
,
716 {"replace_browser_line", (PyCFunction
)replace_browser_line
,
718 {"get_browser_line", (PyCFunction
)get_browser_line
,
720 {"load_browser", (PyCFunction
)load_browser
,
722 {"get_browser_maxline", (PyCFunction
)get_browser_maxline
,
724 {"select_browser_line", (PyCFunction
)select_browser_line
,
726 {"deselect_browser_line", (PyCFunction
)deselect_browser_line
,
728 {"deselect_browser", (PyCFunction
)deselect_browser
,
730 {"isselected_browser_line", (PyCFunction
)isselected_browser_line
,
732 {"get_browser", (PyCFunction
)get_browser
,
734 {"set_browser_fontsize", (PyCFunction
)set_browser_fontsize
,
736 {"set_browser_fontstyle", (PyCFunction
)set_browser_fontstyle
,
738 {"set_browser_specialkey", (PyCFunction
)set_browser_specialkey
,
740 {NULL
, NULL
} /* sentinel */
746 set_button(genericobject
*g
, PyObject
*args
)
748 return call_forms_INi (fl_set_button
, g
-> ob_generic
, args
);
752 get_button(genericobject
*g
)
754 return call_forms_Ri (fl_get_button
, g
-> ob_generic
);
758 get_button_numb(genericobject
*g
)
760 return call_forms_Ri (fl_get_button_numb
, g
-> ob_generic
);
764 set_button_shortcut(genericobject
*g
, PyObject
*args
)
766 return call_forms_INstr (fl_set_button_shortcut
, g
-> ob_generic
, args
);
769 static PyMethodDef button_methods
[] = {
770 {"set_button", (PyCFunction
)set_button
, METH_OLDARGS
},
771 {"get_button", (PyCFunction
)get_button
, METH_NOARGS
},
772 {"get_button_numb", (PyCFunction
)get_button_numb
, METH_NOARGS
},
773 {"set_button_shortcut", (PyCFunction
)set_button_shortcut
, METH_OLDARGS
},
774 {NULL
, NULL
} /* sentinel */
780 set_choice(genericobject
*g
, PyObject
*args
)
782 return call_forms_INi (fl_set_choice
, g
-> ob_generic
, args
);
786 get_choice(genericobject
*g
)
788 return call_forms_Ri (fl_get_choice
, g
-> ob_generic
);
792 clear_choice (genericobject
*g
)
794 return generic_call (g
, fl_clear_choice
);
798 addto_choice (genericobject
*g
, PyObject
*args
)
800 return call_forms_INstr (fl_addto_choice
, g
-> ob_generic
, args
);
804 replace_choice (genericobject
*g
, PyObject
*args
)
806 return call_forms_INiINstr (fl_replace_choice
, g
-> ob_generic
, args
);
810 delete_choice (genericobject
*g
, PyObject
*args
)
812 return call_forms_INi (fl_delete_choice
, g
-> ob_generic
, args
);
816 get_choice_text (genericobject
*g
)
818 return call_forms_Rstr (fl_get_choice_text
, g
-> ob_generic
);
822 set_choice_fontsize (genericobject
*g
, PyObject
*args
)
824 return call_forms_INf (fl_set_choice_fontsize
, g
-> ob_generic
, args
);
828 set_choice_fontstyle (genericobject
*g
, PyObject
*args
)
830 return call_forms_INi (fl_set_choice_fontstyle
, g
-> ob_generic
, args
);
833 static PyMethodDef choice_methods
[] = {
834 {"set_choice", (PyCFunction
)set_choice
, METH_OLDARGS
},
835 {"get_choice", (PyCFunction
)get_choice
, METH_NOARGS
},
836 {"clear_choice", (PyCFunction
)clear_choice
, METH_NOARGS
},
837 {"addto_choice", (PyCFunction
)addto_choice
, METH_OLDARGS
},
838 {"replace_choice", (PyCFunction
)replace_choice
, METH_OLDARGS
},
839 {"delete_choice", (PyCFunction
)delete_choice
, METH_OLDARGS
},
840 {"get_choice_text", (PyCFunction
)get_choice_text
, METH_NOARGS
},
841 {"set_choice_fontsize", (PyCFunction
)set_choice_fontsize
, METH_OLDARGS
},
842 {"set_choice_fontstyle",(PyCFunction
)set_choice_fontstyle
, METH_OLDARGS
},
843 {NULL
, NULL
} /* sentinel */
849 get_clock(genericobject
*g
)
853 fl_get_clock (g
->ob_generic
, &i0
, &i1
, &i2
);
855 return Py_BuildValue("(iii)", i0
, i1
, i2
);
858 static PyMethodDef clock_methods
[] = {
859 {"get_clock", (PyCFunction
)get_clock
, METH_NOARGS
},
860 {NULL
, NULL
} /* sentinel */
863 /* CLass : Counters */
866 get_counter_value(genericobject
*g
)
868 return call_forms_Rf (fl_get_counter_value
, g
-> ob_generic
);
872 set_counter_value (genericobject
*g
, PyObject
*args
)
874 return call_forms_INf (fl_set_counter_value
, g
-> ob_generic
, args
);
878 set_counter_precision (genericobject
*g
, PyObject
*args
)
880 return call_forms_INi (fl_set_counter_precision
, g
-> ob_generic
, args
);
884 set_counter_bounds (genericobject
*g
, PyObject
*args
)
886 return call_forms_INfINf (fl_set_counter_bounds
, g
-> ob_generic
, args
);
890 set_counter_step (genericobject
*g
, PyObject
*args
)
892 return call_forms_INfINf (fl_set_counter_step
, g
-> ob_generic
, args
);
896 set_counter_return (genericobject
*g
, PyObject
*args
)
898 return call_forms_INi (fl_set_counter_return
, g
-> ob_generic
, args
);
901 static PyMethodDef counter_methods
[] = {
902 {"set_counter_value", (PyCFunction
)set_counter_value
,
904 {"get_counter_value", (PyCFunction
)get_counter_value
,
906 {"set_counter_bounds", (PyCFunction
)set_counter_bounds
,
908 {"set_counter_step", (PyCFunction
)set_counter_step
,
910 {"set_counter_precision", (PyCFunction
)set_counter_precision
,
912 {"set_counter_return", (PyCFunction
)set_counter_return
,
914 {NULL
, NULL
} /* sentinel */
921 get_dial_value(genericobject
*g
)
923 return call_forms_Rf (fl_get_dial_value
, g
-> ob_generic
);
927 set_dial_value (genericobject
*g
, PyObject
*args
)
929 return call_forms_INf (fl_set_dial_value
, g
-> ob_generic
, args
);
933 set_dial_bounds (genericobject
*g
, PyObject
*args
)
935 return call_forms_INfINf (fl_set_dial_bounds
, g
-> ob_generic
, args
);
939 get_dial_bounds (genericobject
*g
)
941 return call_forms_OUTfOUTf (fl_get_dial_bounds
, g
-> ob_generic
);
945 set_dial_step (genericobject
*g
, PyObject
*args
)
947 return call_forms_INf (fl_set_dial_step
, g
-> ob_generic
, args
);
950 static PyMethodDef dial_methods
[] = {
951 {"set_dial_value", (PyCFunction
)set_dial_value
, METH_OLDARGS
},
952 {"get_dial_value", (PyCFunction
)get_dial_value
, METH_NOARGS
},
953 {"set_dial_bounds", (PyCFunction
)set_dial_bounds
, METH_OLDARGS
},
954 {"get_dial_bounds", (PyCFunction
)get_dial_bounds
, METH_NOARGS
},
955 {"set_dial_step", (PyCFunction
)set_dial_step
, METH_OLDARGS
},
956 {NULL
, NULL
} /* sentinel */
962 set_input (genericobject
*g
, PyObject
*args
)
964 return call_forms_INstr (fl_set_input
, g
-> ob_generic
, args
);
968 get_input (genericobject
*g
)
970 return call_forms_Rstr (fl_get_input
, g
-> ob_generic
);
974 set_input_color (genericobject
*g
, PyObject
*args
)
976 return call_forms_INfINf (fl_set_input_color
, g
-> ob_generic
, args
);
980 set_input_return (genericobject
*g
, PyObject
*args
)
982 return call_forms_INi (fl_set_input_return
, g
-> ob_generic
, args
);
985 static PyMethodDef input_methods
[] = {
986 {"set_input", (PyCFunction
)set_input
, METH_OLDARGS
},
987 {"get_input", (PyCFunction
)get_input
, METH_NOARGS
},
988 {"set_input_color", (PyCFunction
)set_input_color
, METH_OLDARGS
},
989 {"set_input_return", (PyCFunction
)set_input_return
, METH_OLDARGS
},
990 {NULL
, NULL
} /* sentinel */
997 set_menu (genericobject
*g
, PyObject
*args
)
999 return call_forms_INstr (fl_set_menu
, g
-> ob_generic
, args
);
1003 get_menu (genericobject
*g
)
1005 /* XXX strictly speaking this is wrong since fl_get_menu
1006 XXX returns long, not int */
1007 return call_forms_Ri (fl_get_menu
, g
-> ob_generic
);
1011 get_menu_text (genericobject
*g
)
1013 return call_forms_Rstr (fl_get_menu_text
, g
-> ob_generic
);
1017 addto_menu (genericobject
*g
, PyObject
*args
)
1019 return call_forms_INstr (fl_addto_menu
, g
-> ob_generic
, args
);
1022 static PyMethodDef menu_methods
[] = {
1023 {"set_menu", (PyCFunction
)set_menu
, METH_OLDARGS
},
1024 {"get_menu", (PyCFunction
)get_menu
, METH_NOARGS
},
1025 {"get_menu_text", (PyCFunction
)get_menu_text
, METH_NOARGS
},
1026 {"addto_menu", (PyCFunction
)addto_menu
, METH_OLDARGS
},
1027 {NULL
, NULL
} /* sentinel */
1031 /* Class: Sliders */
1034 get_slider_value(genericobject
*g
)
1036 return call_forms_Rf (fl_get_slider_value
, g
-> ob_generic
);
1040 set_slider_value (genericobject
*g
, PyObject
*args
)
1042 return call_forms_INf (fl_set_slider_value
, g
-> ob_generic
, args
);
1046 set_slider_bounds (genericobject
*g
, PyObject
*args
)
1048 return call_forms_INfINf (fl_set_slider_bounds
, g
-> ob_generic
, args
);
1052 get_slider_bounds (genericobject
*g
)
1054 return call_forms_OUTfOUTf(fl_get_slider_bounds
, g
-> ob_generic
);
1058 set_slider_return (genericobject
*g
, PyObject
*args
)
1060 return call_forms_INf (fl_set_slider_return
, g
-> ob_generic
, args
);
1064 set_slider_size (genericobject
*g
, PyObject
*args
)
1066 return call_forms_INf (fl_set_slider_size
, g
-> ob_generic
, args
);
1070 set_slider_precision (genericobject
*g
, PyObject
*args
)
1072 return call_forms_INi (fl_set_slider_precision
, g
-> ob_generic
, args
);
1076 set_slider_step (genericobject
*g
, PyObject
*args
)
1078 return call_forms_INf (fl_set_slider_step
, g
-> ob_generic
, args
);
1082 static PyMethodDef slider_methods
[] = {
1083 {"set_slider_value", (PyCFunction
)set_slider_value
, METH_OLDARGS
},
1084 {"get_slider_value", (PyCFunction
)get_slider_value
, METH_NOARGS
},
1085 {"set_slider_bounds", (PyCFunction
)set_slider_bounds
, METH_OLDARGS
},
1086 {"get_slider_bounds", (PyCFunction
)get_slider_bounds
, METH_NOARGS
},
1087 {"set_slider_return", (PyCFunction
)set_slider_return
, METH_OLDARGS
},
1088 {"set_slider_size", (PyCFunction
)set_slider_size
, METH_OLDARGS
},
1089 {"set_slider_precision",(PyCFunction
)set_slider_precision
, METH_OLDARGS
},
1090 {"set_slider_step", (PyCFunction
)set_slider_step
, METH_OLDARGS
},
1091 {NULL
, NULL
} /* sentinel */
1095 set_positioner_xvalue (genericobject
*g
, PyObject
*args
)
1097 return call_forms_INf (fl_set_positioner_xvalue
, g
-> ob_generic
, args
);
1101 set_positioner_xbounds (genericobject
*g
, PyObject
*args
)
1103 return call_forms_INfINf (fl_set_positioner_xbounds
,
1104 g
-> ob_generic
, args
);
1108 set_positioner_yvalue (genericobject
*g
, PyObject
*args
)
1110 return call_forms_INf (fl_set_positioner_yvalue
, g
-> ob_generic
, args
);
1114 set_positioner_ybounds (genericobject
*g
, PyObject
*args
)
1116 return call_forms_INfINf (fl_set_positioner_ybounds
,
1117 g
-> ob_generic
, args
);
1121 get_positioner_xvalue (genericobject
*g
)
1123 return call_forms_Rf (fl_get_positioner_xvalue
, g
-> ob_generic
);
1127 get_positioner_xbounds (genericobject
*g
)
1129 return call_forms_OUTfOUTf (fl_get_positioner_xbounds
, g
-> ob_generic
);
1133 get_positioner_yvalue (genericobject
*g
)
1135 return call_forms_Rf (fl_get_positioner_yvalue
, g
-> ob_generic
);
1139 get_positioner_ybounds (genericobject
*g
)
1141 return call_forms_OUTfOUTf (fl_get_positioner_ybounds
, g
-> ob_generic
);
1144 static PyMethodDef positioner_methods
[] = {
1145 {"set_positioner_xvalue", (PyCFunction
)set_positioner_xvalue
,
1147 {"set_positioner_yvalue", (PyCFunction
)set_positioner_yvalue
,
1149 {"set_positioner_xbounds", (PyCFunction
)set_positioner_xbounds
,
1151 {"set_positioner_ybounds", (PyCFunction
)set_positioner_ybounds
,
1153 {"get_positioner_xvalue", (PyCFunction
)get_positioner_xvalue
,
1155 {"get_positioner_yvalue", (PyCFunction
)get_positioner_yvalue
,
1157 {"get_positioner_xbounds", (PyCFunction
)get_positioner_xbounds
,
1159 {"get_positioner_ybounds", (PyCFunction
)get_positioner_ybounds
,
1161 {NULL
, NULL
} /* sentinel */
1167 set_timer (genericobject
*g
, PyObject
*args
)
1169 return call_forms_INf (fl_set_timer
, g
-> ob_generic
, args
);
1173 get_timer (genericobject
*g
)
1175 return call_forms_Rf (fl_get_timer
, g
-> ob_generic
);
1178 static PyMethodDef timer_methods
[] = {
1179 {"set_timer", (PyCFunction
)set_timer
, METH_OLDARGS
},
1180 {"get_timer", (PyCFunction
)get_timer
, METH_NOARGS
},
1181 {NULL
, NULL
} /* sentinel */
1191 static PyTypeObject Formtype
;
1193 #define is_formobject(v) ((v)->ob_type == &Formtype)
1196 form_show_form(formobject
*f
, PyObject
*args
)
1200 if (!PyArg_Parse(args
, "(iis)", &place
, &border
, &name
))
1202 fl_show_form(f
->ob_form
, place
, border
, name
);
1208 form_call(void (*func
)(FL_FORM
*), FL_FORM
*f
)
1217 form_call_INiINi(void (*func
)(FL_FORM
*, int, int), FL_FORM
*f
, PyObject
*args
)
1221 if (!PyArg_Parse(args
, "(ii)", &a
, &b
)) return NULL
;
1230 form_call_INfINf(void (*func
)(FL_FORM
*, float, float), FL_FORM
*f
, PyObject
*args
)
1234 if (!PyArg_Parse(args
, "(ff)", &a
, &b
)) return NULL
;
1243 form_hide_form(formobject
*f
)
1245 return form_call(fl_hide_form
, f
-> ob_form
);
1249 form_redraw_form(formobject
*f
)
1251 return form_call(fl_redraw_form
, f
-> ob_form
);
1255 form_set_form_position(formobject
*f
, PyObject
*args
)
1257 return form_call_INiINi(fl_set_form_position
, f
-> ob_form
, args
);
1261 form_set_form_size(formobject
*f
, PyObject
*args
)
1263 return form_call_INiINi(fl_set_form_size
, f
-> ob_form
, args
);
1267 form_scale_form(formobject
*f
, PyObject
*args
)
1269 return form_call_INfINf(fl_scale_form
, f
-> ob_form
, args
);
1273 generic_add_object(formobject
*f
, PyObject
*args
, FL_OBJECT
*(*func
)(int, float, float, float, float, char*), PyMethodDef
*internal_methods
)
1280 if (!PyArg_Parse(args
,"(iffffs)", &type
,&x
,&y
,&w
,&h
,&name
))
1283 fl_addto_form (f
-> ob_form
);
1285 obj
= (*func
) (type
, x
, y
, w
, h
, name
);
1294 return newgenericobject (obj
, internal_methods
);
1298 form_add_button(formobject
*f
, PyObject
*args
)
1300 return generic_add_object(f
, args
, fl_add_button
, button_methods
);
1304 form_add_lightbutton(formobject
*f
, PyObject
*args
)
1306 return generic_add_object(f
, args
, fl_add_lightbutton
, button_methods
);
1310 form_add_roundbutton(formobject
*f
, PyObject
*args
)
1312 return generic_add_object(f
, args
, fl_add_roundbutton
, button_methods
);
1316 form_add_menu (formobject
*f
, PyObject
*args
)
1318 return generic_add_object(f
, args
, fl_add_menu
, menu_methods
);
1322 form_add_slider(formobject
*f
, PyObject
*args
)
1324 return generic_add_object(f
, args
, fl_add_slider
, slider_methods
);
1328 form_add_valslider(formobject
*f
, PyObject
*args
)
1330 return generic_add_object(f
, args
, fl_add_valslider
, slider_methods
);
1334 form_add_dial(formobject
*f
, PyObject
*args
)
1336 return generic_add_object(f
, args
, fl_add_dial
, dial_methods
);
1340 form_add_counter(formobject
*f
, PyObject
*args
)
1342 return generic_add_object(f
, args
, fl_add_counter
, counter_methods
);
1346 form_add_clock(formobject
*f
, PyObject
*args
)
1348 return generic_add_object(f
, args
, fl_add_clock
, clock_methods
);
1352 form_add_box(formobject
*f
, PyObject
*args
)
1354 return generic_add_object(f
, args
, fl_add_box
,
1355 (PyMethodDef
*)NULL
);
1359 form_add_choice(formobject
*f
, PyObject
*args
)
1361 return generic_add_object(f
, args
, fl_add_choice
, choice_methods
);
1365 form_add_browser(formobject
*f
, PyObject
*args
)
1367 return generic_add_object(f
, args
, fl_add_browser
, browser_methods
);
1371 form_add_positioner(formobject
*f
, PyObject
*args
)
1373 return generic_add_object(f
, args
, fl_add_positioner
,
1374 positioner_methods
);
1378 form_add_input(formobject
*f
, PyObject
*args
)
1380 return generic_add_object(f
, args
, fl_add_input
, input_methods
);
1384 form_add_text(formobject
*f
, PyObject
*args
)
1386 return generic_add_object(f
, args
, fl_add_text
,
1387 (PyMethodDef
*)NULL
);
1391 form_add_timer(formobject
*f
, PyObject
*args
)
1393 return generic_add_object(f
, args
, fl_add_timer
, timer_methods
);
1397 form_freeze_form(formobject
*f
)
1399 return form_call(fl_freeze_form
, f
-> ob_form
);
1403 form_unfreeze_form(formobject
*f
)
1405 return form_call(fl_unfreeze_form
, f
-> ob_form
);
1409 form_activate_form(formobject
*f
)
1411 return form_call(fl_activate_form
, f
-> ob_form
);
1415 form_deactivate_form(formobject
*f
)
1417 return form_call(fl_deactivate_form
, f
-> ob_form
);
1421 form_bgn_group(formobject
*f
, PyObject
*args
)
1425 fl_addto_form(f
-> ob_form
);
1426 obj
= fl_bgn_group();
1434 return newgenericobject (obj
, (PyMethodDef
*) NULL
);
1438 form_end_group(formobject
*f
, PyObject
*args
)
1440 fl_addto_form(f
-> ob_form
);
1448 forms_find_first_or_last(FL_OBJECT
*(*func
)(FL_FORM
*, int, float, float), formobject
*f
, PyObject
*args
)
1455 if (!PyArg_Parse(args
, "(iff)", &type
, &mx
, &my
)) return NULL
;
1457 generic
= (*func
) (f
-> ob_form
, type
, mx
, my
);
1459 if (generic
== NULL
)
1465 g
= findgeneric(generic
);
1467 PyErr_SetString(PyExc_RuntimeError
,
1468 "forms_find_{first|last} returns unknown object");
1472 return (PyObject
*) g
;
1476 form_find_first(formobject
*f
, PyObject
*args
)
1478 return forms_find_first_or_last(fl_find_first
, f
, args
);
1482 form_find_last(formobject
*f
, PyObject
*args
)
1484 return forms_find_first_or_last(fl_find_last
, f
, args
);
1488 form_set_object_focus(formobject
*f
, PyObject
*args
)
1491 if (args
== NULL
|| !is_genericobject(args
)) {
1492 PyErr_BadArgument();
1495 g
= (genericobject
*)args
;
1496 fl_set_object_focus(f
->ob_form
, g
->ob_generic
);
1501 static PyMethodDef form_methods
[] = {
1503 {"show_form", (PyCFunction
)form_show_form
, METH_OLDARGS
},
1504 {"hide_form", (PyCFunction
)form_hide_form
, METH_NOARGS
},
1505 {"redraw_form", (PyCFunction
)form_redraw_form
, METH_NOARGS
},
1506 {"set_form_position", (PyCFunction
)form_set_form_position
, METH_OLDARGS
},
1507 {"set_form_size", (PyCFunction
)form_set_form_size
, METH_OLDARGS
},
1508 {"scale_form", (PyCFunction
)form_scale_form
, METH_OLDARGS
},
1509 {"freeze_form", (PyCFunction
)form_freeze_form
, METH_NOARGS
},
1510 {"unfreeze_form", (PyCFunction
)form_unfreeze_form
, METH_NOARGS
},
1511 {"activate_form", (PyCFunction
)form_activate_form
, METH_NOARGS
},
1512 {"deactivate_form", (PyCFunction
)form_deactivate_form
, METH_NOARGS
},
1513 {"bgn_group", (PyCFunction
)form_bgn_group
, METH_OLDARGS
},
1514 {"end_group", (PyCFunction
)form_end_group
, METH_OLDARGS
},
1515 {"find_first", (PyCFunction
)form_find_first
, METH_OLDARGS
},
1516 {"find_last", (PyCFunction
)form_find_last
, METH_OLDARGS
},
1517 {"set_object_focus", (PyCFunction
)form_set_object_focus
, METH_OLDARGS
},
1520 {"add_button", (PyCFunction
)form_add_button
, METH_OLDARGS
},
1521 /* {"add_bitmap", (method)form_add_bitmap, METH_OLDARGS}, */
1522 {"add_lightbutton", (PyCFunction
)form_add_lightbutton
, METH_OLDARGS
},
1523 {"add_roundbutton", (PyCFunction
)form_add_roundbutton
, METH_OLDARGS
},
1524 {"add_menu", (PyCFunction
)form_add_menu
, METH_OLDARGS
},
1525 {"add_slider", (PyCFunction
)form_add_slider
, METH_OLDARGS
},
1526 {"add_positioner", (PyCFunction
)form_add_positioner
, METH_OLDARGS
},
1527 {"add_valslider", (PyCFunction
)form_add_valslider
, METH_OLDARGS
},
1528 {"add_dial", (PyCFunction
)form_add_dial
, METH_OLDARGS
},
1529 {"add_counter", (PyCFunction
)form_add_counter
, METH_OLDARGS
},
1530 {"add_box", (PyCFunction
)form_add_box
, METH_OLDARGS
},
1531 {"add_clock", (PyCFunction
)form_add_clock
, METH_OLDARGS
},
1532 {"add_choice", (PyCFunction
)form_add_choice
, METH_OLDARGS
},
1533 {"add_browser", (PyCFunction
)form_add_browser
, METH_OLDARGS
},
1534 {"add_input", (PyCFunction
)form_add_input
, METH_OLDARGS
},
1535 {"add_timer", (PyCFunction
)form_add_timer
, METH_OLDARGS
},
1536 {"add_text", (PyCFunction
)form_add_text
, METH_OLDARGS
},
1537 {NULL
, NULL
} /* sentinel */
1541 form_dealloc(formobject
*f
)
1543 releaseobjects(f
->ob_form
);
1544 if (f
->ob_form
->visible
)
1545 fl_hide_form(f
->ob_form
);
1546 fl_free_form(f
->ob_form
);
1550 #define OFF(x) offsetof(FL_FORM, x)
1552 static struct memberlist form_memberlist
[] = {
1553 {"window", T_LONG
, OFF(window
), RO
},
1554 {"w", T_FLOAT
, OFF(w
)},
1555 {"h", T_FLOAT
, OFF(h
)},
1556 {"x", T_FLOAT
, OFF(x
), RO
},
1557 {"y", T_FLOAT
, OFF(y
), RO
},
1558 {"deactivated", T_INT
, OFF(deactivated
)},
1559 {"visible", T_INT
, OFF(visible
), RO
},
1560 {"frozen", T_INT
, OFF(frozen
), RO
},
1561 {"doublebuf", T_INT
, OFF(doublebuf
)},
1562 {NULL
} /* Sentinel */
1568 form_getattr(formobject
*f
, char *name
)
1572 meth
= Py_FindMethod(form_methods
, (PyObject
*)f
, name
);
1576 return PyMember_Get((char *)f
->ob_form
, form_memberlist
, name
);
1580 form_setattr(formobject
*f
, char *name
, PyObject
*v
)
1583 PyErr_SetString(PyExc_TypeError
,
1584 "can't delete form attributes");
1588 return PyMember_Set((char *)f
->ob_form
, form_memberlist
, name
, v
);
1592 form_repr(formobject
*f
)
1595 PyOS_snprintf(buf
, sizeof(buf
), "<FORMS_form at %p, window=%ld>",
1596 f
, f
->ob_form
->window
);
1597 return PyString_FromString(buf
);
1600 static PyTypeObject Formtype
= {
1601 PyObject_HEAD_INIT(&PyType_Type
)
1603 "fl.FORMS_form", /*tp_name*/
1604 sizeof(formobject
), /*tp_size*/
1607 (destructor
)form_dealloc
, /*tp_dealloc*/
1609 (getattrfunc
)form_getattr
, /*tp_getattr*/
1610 (setattrfunc
)form_setattr
, /*tp_setattr*/
1612 (reprfunc
)form_repr
, /*tp_repr*/
1616 newformobject(FL_FORM
*form
)
1619 f
= PyObject_New(formobject
, &Formtype
);
1623 return (PyObject
*)f
;
1627 /* The "fl" module */
1630 forms_make_form(PyObject
*dummy
, PyObject
*args
)
1635 if (!PyArg_Parse(args
, "(iff)", &type
, &w
, &h
))
1637 form
= fl_bgn_form(type
, w
, h
);
1639 /* XXX Actually, cannot happen! */
1644 return newformobject(form
);
1648 forms_activate_all_forms(PyObject
*f
, PyObject
*args
)
1650 fl_activate_all_forms();
1656 forms_deactivate_all_forms(PyObject
*f
, PyObject
*args
)
1658 fl_deactivate_all_forms();
1663 static PyObject
*my_event_callback
= NULL
;
1666 forms_set_event_call_back(PyObject
*dummy
, PyObject
*args
)
1668 if (args
== Py_None
)
1670 my_event_callback
= args
;
1677 forms_do_or_check_forms(PyObject
*dummy
, FL_OBJECT
*(*func
)(void))
1681 PyObject
*arg
, *res
;
1684 Py_BEGIN_ALLOW_THREADS
1685 generic
= (*func
)();
1686 Py_END_ALLOW_THREADS
1687 if (generic
== NULL
) {
1691 if (generic
== FL_EVENT
) {
1694 if (my_event_callback
== NULL
)
1695 return PyInt_FromLong(-1L);
1696 dev
= fl_qread(&val
);
1697 arg
= Py_BuildValue("(ih)", dev
, val
);
1700 res
= PyEval_CallObject(my_event_callback
, arg
);
1704 return NULL
; /* Callback raised exception */
1707 g
= findgeneric(generic
);
1709 /* Object not known to us (some dialogs cause this) */
1710 continue; /* Ignore it */
1712 if (g
->ob_callback
== NULL
) {
1714 return ((PyObject
*) g
);
1716 arg
= PyTuple_Pack(2, (PyObject
*)g
, g
->ob_callback_arg
);
1719 res
= PyEval_CallObject(g
->ob_callback
, arg
);
1723 return NULL
; /* Callback raised exception */
1728 forms_do_forms(PyObject
*dummy
)
1730 return forms_do_or_check_forms(dummy
, fl_do_forms
);
1734 forms_check_forms(PyObject
*dummy
)
1736 return forms_do_or_check_forms(dummy
, fl_check_forms
);
1740 forms_do_only_forms(PyObject
*dummy
)
1742 return forms_do_or_check_forms(dummy
, fl_do_only_forms
);
1746 forms_check_only_forms(PyObject
*dummy
)
1748 return forms_do_or_check_forms(dummy
, fl_check_only_forms
);
1753 fl_call(void (*func
)(void))
1762 forms_set_graphics_mode(PyObject
*dummy
, PyObject
*args
)
1764 int rgbmode
, doublebuf
;
1766 if (!PyArg_Parse(args
, "(ii)", &rgbmode
, &doublebuf
))
1768 fl_set_graphics_mode(rgbmode
,doublebuf
);
1774 forms_get_rgbmode(PyObject
*dummy
, PyObject
*args
)
1776 extern int fl_rgbmode
;
1779 PyErr_BadArgument();
1782 return PyInt_FromLong((long)fl_rgbmode
);
1786 forms_show_errors(PyObject
*dummy
, PyObject
*args
)
1789 if (!PyArg_Parse(args
, "i", &show
))
1791 fl_show_errors(show
);
1797 forms_set_font_name(PyObject
*dummy
, PyObject
*args
)
1801 if (!PyArg_Parse(args
, "(is)", &numb
, &name
))
1803 fl_set_font_name(numb
, name
);
1810 forms_qdevice(PyObject
*self
, PyObject
*args
)
1813 if (!PyArg_Parse(args
, "h", &arg1
))
1821 forms_unqdevice(PyObject
*self
, PyObject
*args
)
1824 if (!PyArg_Parse(args
, "h", &arg1
))
1832 forms_isqueued(PyObject
*self
, PyObject
*args
)
1836 if (!PyArg_Parse(args
, "h", &arg1
))
1838 retval
= fl_isqueued(arg1
);
1840 return PyInt_FromLong(retval
);
1844 forms_qtest(PyObject
*self
, PyObject
*args
)
1847 retval
= fl_qtest();
1848 return PyInt_FromLong(retval
);
1853 forms_qread(PyObject
*self
, PyObject
*args
)
1857 Py_BEGIN_ALLOW_THREADS
1858 dev
= fl_qread(&val
);
1859 Py_END_ALLOW_THREADS
1860 return Py_BuildValue("(ih)", dev
, val
);
1864 forms_qreset(PyObject
*self
)
1872 forms_qenter(PyObject
*self
, PyObject
*args
)
1875 if (!PyArg_Parse(args
, "(hh)", &arg1
, &arg2
))
1877 fl_qenter(arg1
, arg2
);
1883 forms_color(PyObject
*self
, PyObject
*args
)
1887 if (!PyArg_Parse(args
, "i", &arg
)) return NULL
;
1889 fl_color((short) arg
);
1896 forms_mapcolor(PyObject
*self
, PyObject
*args
)
1898 int arg0
, arg1
, arg2
, arg3
;
1900 if (!PyArg_Parse(args
, "(iiii)", &arg0
, &arg1
, &arg2
, &arg3
))
1903 fl_mapcolor(arg0
, (short) arg1
, (short) arg2
, (short) arg3
);
1910 forms_getmcolor(PyObject
*self
, PyObject
*args
)
1915 if (!PyArg_Parse(args
, "i", &arg
)) return NULL
;
1917 fl_getmcolor(arg
, &r
, &g
, &b
);
1919 return Py_BuildValue("(hhh)", r
, g
, b
);
1923 forms_get_mouse(PyObject
*self
)
1927 fl_get_mouse(&x
, &y
);
1929 return Py_BuildValue("(ff)", x
, y
);
1933 forms_tie(PyObject
*self
, PyObject
*args
)
1935 short arg1
, arg2
, arg3
;
1936 if (!PyArg_Parse(args
, "(hhh)", &arg1
, &arg2
, &arg3
))
1938 fl_tie(arg1
, arg2
, arg3
);
1944 forms_show_message(PyObject
*f
, PyObject
*args
)
1948 if (!PyArg_Parse(args
, "(sss)", &a
, &b
, &c
)) return NULL
;
1950 Py_BEGIN_ALLOW_THREADS
1951 fl_show_message(a
, b
, c
);
1952 Py_END_ALLOW_THREADS
1959 forms_show_choice(PyObject
*f
, PyObject
*args
)
1961 char *m1
, *m2
, *m3
, *b1
, *b2
, *b3
;
1966 if (args
== NULL
|| !PyTuple_Check(args
)) {
1967 PyErr_BadArgument();
1970 nb
= PyTuple_Size(args
) - 3;
1972 PyErr_SetString(PyExc_TypeError
,
1973 "need at least one button label");
1976 if (PyInt_Check(PyTuple_GetItem(args
, 3))) {
1977 PyErr_SetString(PyExc_TypeError
,
1978 "'number-of-buttons' argument not needed");
1982 case 1: format
= "(ssss)"; break;
1983 case 2: format
= "(sssss)"; break;
1984 case 3: format
= "(ssssss)"; break;
1986 PyErr_SetString(PyExc_TypeError
, "too many button labels");
1990 if (!PyArg_Parse(args
, format
, &m1
, &m2
, &m3
, &b1
, &b2
, &b3
))
1993 Py_BEGIN_ALLOW_THREADS
1994 rv
= fl_show_choice(m1
, m2
, m3
, nb
, b1
, b2
, b3
);
1995 Py_END_ALLOW_THREADS
1996 return PyInt_FromLong(rv
);
2000 forms_show_question(PyObject
*f
, PyObject
*args
)
2005 if (!PyArg_Parse(args
, "(sss)", &a
, &b
, &c
)) return NULL
;
2007 Py_BEGIN_ALLOW_THREADS
2008 ret
= fl_show_question(a
, b
, c
);
2009 Py_END_ALLOW_THREADS
2011 return PyInt_FromLong((long) ret
);
2015 forms_show_input(PyObject
*f
, PyObject
*args
)
2020 if (!PyArg_Parse(args
, "(ss)", &a
, &b
)) return NULL
;
2022 Py_BEGIN_ALLOW_THREADS
2023 str
= fl_show_input(a
, b
);
2024 Py_END_ALLOW_THREADS
2030 return PyString_FromString(str
);
2034 forms_file_selector(PyObject
*f
, PyObject
*args
)
2037 char *a
, *b
, *c
, *d
;
2039 if (!PyArg_Parse(args
, "(ssss)", &a
, &b
, &c
, &d
)) return NULL
;
2041 Py_BEGIN_ALLOW_THREADS
2042 str
= fl_show_file_selector(a
, b
, c
, d
);
2043 Py_END_ALLOW_THREADS
2049 return PyString_FromString(str
);
2054 forms_file_selector_func(PyObject
*args
, char *(*func
)(void))
2064 return PyString_FromString(str
);
2068 forms_get_directory(PyObject
*f
, PyObject
*args
)
2070 return forms_file_selector_func(args
, fl_get_directory
);
2074 forms_get_pattern(PyObject
*f
, PyObject
*args
)
2076 return forms_file_selector_func(args
, fl_get_pattern
);
2080 forms_get_filename(PyObject
*f
, PyObject
*args
)
2082 return forms_file_selector_func(args
, fl_get_filename
);
2085 static PyMethodDef forms_methods
[] = {
2087 {"make_form", forms_make_form
, METH_OLDARGS
},
2088 {"activate_all_forms", forms_activate_all_forms
, METH_OLDARGS
},
2089 {"deactivate_all_forms",forms_deactivate_all_forms
, METH_OLDARGS
},
2090 /* gl support wrappers */
2091 {"qdevice", forms_qdevice
, METH_OLDARGS
},
2092 {"unqdevice", forms_unqdevice
, METH_OLDARGS
},
2093 {"isqueued", forms_isqueued
, METH_OLDARGS
},
2094 {"qtest", forms_qtest
, METH_OLDARGS
},
2095 {"qread", forms_qread
, METH_OLDARGS
},
2096 /* {"blkqread", forms_blkqread, METH_OLDARGS}, */
2097 {"qreset", forms_qreset
, METH_NOARGS
},
2098 {"qenter", forms_qenter
, METH_OLDARGS
},
2099 {"get_mouse", forms_get_mouse
, METH_NOARGS
},
2100 {"tie", forms_tie
, METH_OLDARGS
},
2101 /* {"new_events", forms_new_events, METH_OLDARGS}, */
2102 {"color", forms_color
, METH_OLDARGS
},
2103 {"mapcolor", forms_mapcolor
, METH_OLDARGS
},
2104 {"getmcolor", forms_getmcolor
, METH_OLDARGS
},
2106 {"do_forms", forms_do_forms
, METH_NOARGS
},
2107 {"do_only_forms", forms_do_only_forms
, METH_NOARGS
},
2108 {"check_forms", forms_check_forms
, METH_NOARGS
},
2109 {"check_only_forms", forms_check_only_forms
, METH_NOARGS
},
2110 {"set_event_call_back", forms_set_event_call_back
, METH_OLDARGS
},
2112 {"show_message", forms_show_message
, METH_OLDARGS
},
2113 {"show_question", forms_show_question
, METH_OLDARGS
},
2114 {"show_choice", forms_show_choice
, METH_OLDARGS
},
2115 {"show_input", forms_show_input
, METH_OLDARGS
},
2116 {"show_file_selector", forms_file_selector
, METH_OLDARGS
},
2117 {"file_selector", forms_file_selector
, METH_OLDARGS
}, /* BW compat */
2118 {"get_directory", forms_get_directory
, METH_OLDARGS
},
2119 {"get_pattern", forms_get_pattern
, METH_OLDARGS
},
2120 {"get_filename", forms_get_filename
, METH_OLDARGS
},
2121 {"set_graphics_mode", forms_set_graphics_mode
, METH_OLDARGS
},
2122 {"get_rgbmode", forms_get_rgbmode
, METH_OLDARGS
},
2123 {"show_errors", forms_show_errors
, METH_OLDARGS
},
2124 {"set_font_name", forms_set_font_name
, METH_OLDARGS
},
2125 {NULL
, NULL
} /* sentinel */
2132 if (PyErr_WarnPy3k("the fl module has been removed in "
2133 "Python 3.0", 2) < 0)
2136 Py_InitModule("fl", forms_methods
);