You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2144 lines
56 KiB

35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
35 years ago
  1. /* FL module -- interface to Mark Overmars' FORMS Library. */
  2. /* This code works with FORMS version 2.2 (if you defined
  3. OBSOLETE_FORMS_CALLS), and 2.3.
  4. FORMS can be ftp'ed from ftp.cs.ruu.nl (131.211.80.17), directory
  5. /pub/SGI/FORMS. */
  6. /* A half-hearted attempt has been made to allow programs using this
  7. * module to exploit parallelism (through the threads module). No provisions
  8. * have been made for multiple threads to use this module at the same time,
  9. * though. So, a program with a forms thread and a non-forms thread will work
  10. * fine but a program with two threads using forms will probably crash (unless
  11. * the program takes precaution to ensure that only one thread can be in
  12. * this module at any time). This will have to be fixed some time.
  13. * (A fix will probably also have to synchronize with the gl module).
  14. */
  15. #include "Python.h"
  16. #include "forms.h"
  17. #include "structmember.h"
  18. /* Generic Forms Objects */
  19. typedef struct {
  20. PyObject_HEAD
  21. FL_OBJECT *ob_generic;
  22. PyMethodDef *ob_methods;
  23. PyObject *ob_callback;
  24. PyObject *ob_callback_arg;
  25. } genericobject;
  26. static PyTypeObject GenericObjecttype;
  27. #define is_genericobject(g) ((g)->ob_type == &GenericObjecttype)
  28. /* List of all objects (XXX this should be a hash table on address...) */
  29. static PyObject *allgenerics = NULL;
  30. static int nfreeslots = 0;
  31. /* Add an object to the list of known objects */
  32. static void
  33. knowgeneric(genericobject *g)
  34. {
  35. int i, n;
  36. /* Create the list if it doesn't already exist */
  37. if (allgenerics == NULL) {
  38. allgenerics = PyList_New(0);
  39. if (allgenerics == NULL) {
  40. PyErr_Clear();
  41. return; /* Too bad, live without allgenerics... */
  42. }
  43. }
  44. if (nfreeslots > 0) {
  45. /* Search the list for reusable slots (NULL items) */
  46. /* XXX This can be made faster! */
  47. n = PyList_Size(allgenerics);
  48. for (i = 0; i < n; i++) {
  49. if (PyList_GetItem(allgenerics, i) == NULL) {
  50. Py_INCREF(g);
  51. PyList_SetItem(allgenerics, i, (PyObject *)g);
  52. nfreeslots--;
  53. return;
  54. }
  55. }
  56. /* Strange... no free slots found... */
  57. nfreeslots = 0;
  58. }
  59. /* No free entries, append new item to the end */
  60. PyList_Append(allgenerics, (PyObject *)g);
  61. }
  62. /* Find an object in the list of known objects */
  63. static genericobject *
  64. findgeneric(FL_OBJECT *generic)
  65. {
  66. int i, n;
  67. genericobject *g;
  68. if (allgenerics == NULL)
  69. return NULL; /* No objects known yet */
  70. n = PyList_Size(allgenerics);
  71. for (i = 0; i < n; i++) {
  72. g = (genericobject *)PyList_GetItem(allgenerics, i);
  73. if (g != NULL && g->ob_generic == generic)
  74. return g;
  75. }
  76. return NULL; /* Unknown object */
  77. }
  78. /* Remove an object from the list of known objects */
  79. static void
  80. forgetgeneric(genericobject *g)
  81. {
  82. int i, n;
  83. Py_XDECREF(g->ob_callback);
  84. g->ob_callback = NULL;
  85. Py_XDECREF(g->ob_callback_arg);
  86. g->ob_callback_arg = NULL;
  87. if (allgenerics == NULL)
  88. return; /* No objects known yet */
  89. n = PyList_Size(allgenerics);
  90. for (i = 0; i < n; i++) {
  91. if (g == (genericobject *)PyList_GetItem(allgenerics, i)) {
  92. PyList_SetItem(allgenerics, i, (PyObject *)NULL);
  93. nfreeslots++;
  94. break;
  95. }
  96. }
  97. }
  98. /* Called when a form is about to be freed --
  99. remove all the objects that we know about from it. */
  100. static void
  101. releaseobjects(FL_FORM *form)
  102. {
  103. int i, n;
  104. genericobject *g;
  105. if (allgenerics == NULL)
  106. return; /* No objects known yet */
  107. n = PyList_Size(allgenerics);
  108. for (i = 0; i < n; i++) {
  109. g = (genericobject *)PyList_GetItem(allgenerics, i);
  110. if (g != NULL && g->ob_generic->form == form) {
  111. fl_delete_object(g->ob_generic);
  112. /* The object is now unreachable for
  113. do_forms and check_forms, so
  114. delete it from the list of known objects */
  115. Py_XDECREF(g->ob_callback);
  116. g->ob_callback = NULL;
  117. Py_XDECREF(g->ob_callback_arg);
  118. g->ob_callback_arg = NULL;
  119. PyList_SetItem(allgenerics, i, (PyObject *)NULL);
  120. nfreeslots++;
  121. }
  122. }
  123. }
  124. /* Methods of generic objects */
  125. static PyObject *
  126. generic_set_call_back(genericobject *g, PyObject *args)
  127. {
  128. if (PyTuple_GET_SIZE(args) == 0) {
  129. Py_XDECREF(g->ob_callback);
  130. Py_XDECREF(g->ob_callback_arg);
  131. g->ob_callback = NULL;
  132. g->ob_callback_arg = NULL;
  133. }
  134. else {
  135. PyObject *a, *b;
  136. if (!PyArg_UnpackTuple(args, "set_call_back", 2, 2, &a, &b))
  137. return NULL;
  138. Py_XDECREF(g->ob_callback);
  139. Py_XDECREF(g->ob_callback_arg);
  140. g->ob_callback = a;
  141. Py_INCREF(g->ob_callback);
  142. g->ob_callback_arg = b;
  143. Py_INCREF(g->ob_callback_arg);
  144. }
  145. Py_INCREF(Py_None);
  146. return Py_None;
  147. }
  148. static PyObject *
  149. generic_call(genericobject *g, void (*func)(FL_OBJECT *))
  150. {
  151. (*func)(g->ob_generic);
  152. Py_INCREF(Py_None);
  153. return Py_None;
  154. }
  155. static PyObject *
  156. generic_delete_object(genericobject *g)
  157. {
  158. PyObject *res;
  159. res = generic_call(g, fl_delete_object);
  160. if (res != NULL)
  161. forgetgeneric(g);
  162. return res;
  163. }
  164. static PyObject *
  165. generic_show_object(genericobject *g)
  166. {
  167. return generic_call(g, fl_show_object);
  168. }
  169. static PyObject *
  170. generic_hide_object(genericobject *g)
  171. {
  172. return generic_call(g, fl_hide_object);
  173. }
  174. static PyObject *
  175. generic_redraw_object(genericobject *g)
  176. {
  177. return generic_call(g, fl_redraw_object);
  178. }
  179. #ifdef OBSOLETE_FORMS_CALLS
  180. /* (un)freeze_object() are obsolete in FORMS 2.2 and unsupported
  181. in 2.3. Since there's no foolproof way to tell which version we're
  182. using, we omit them unconditionally. */
  183. static PyObject *
  184. generic_freeze_object(genericobject *g)
  185. {
  186. return generic_call(g, fl_freeze_object);
  187. }
  188. static PyObject *
  189. generic_unfreeze_object(genericobject *g)
  190. {
  191. return generic_call(g, fl_unfreeze_object);
  192. }
  193. #endif /* OBSOLETE_FORMS_CALLS */
  194. static PyObject *
  195. generic_activate_object(genericobject *g)
  196. {
  197. return generic_call(g, fl_activate_object);
  198. }
  199. static PyObject *
  200. generic_deactivate_object(genericobject *g)
  201. {
  202. return generic_call(g, fl_deactivate_object);
  203. }
  204. static PyObject *
  205. generic_set_object_shortcut(genericobject *g, PyObject *args)
  206. {
  207. char *str;
  208. if (!PyArg_ParseTuple(args, "s:set_object_shortcut", &str))
  209. return NULL;
  210. fl_set_object_shortcut(g->ob_generic, str);
  211. Py_INCREF(Py_None);
  212. return Py_None;
  213. }
  214. static PyMethodDef generic_methods[] = {
  215. {"set_call_back", (PyCFunction)generic_set_call_back, METH_VARARGS},
  216. {"delete_object", (PyCFunction)generic_delete_object, METH_NOARGS},
  217. {"show_object", (PyCFunction)generic_show_object, METH_NOARGS},
  218. {"hide_object", (PyCFunction)generic_hide_object, METH_NOARGS},
  219. {"redraw_object", (PyCFunction)generic_redraw_object, METH_NOARGS},
  220. #ifdef OBSOLETE_FORMS_CALLS
  221. {"freeze_object", (PyCFunction)generic_freeze_object, METH_NOARGS},
  222. {"unfreeze_object", (PyCFunction)generic_unfreeze_object, METH_NOARGS},
  223. #endif
  224. {"activate_object", (PyCFunction)generic_activate_object, METH_NOARGS},
  225. {"deactivate_object", (PyCFunction)generic_deactivate_object, METH_NOARGS},
  226. {"set_object_shortcut", (PyCFunction)generic_set_object_shortcut, METH_VARARGS},
  227. {NULL, NULL} /* sentinel */
  228. };
  229. static void
  230. generic_dealloc(genericobject *g)
  231. {
  232. fl_free_object(g->ob_generic);
  233. Py_XDECREF(g->ob_callback);
  234. Py_XDECREF(g->ob_callback_arg);
  235. PyObject_Del(g);
  236. }
  237. #define OFF(x) offsetof(FL_OBJECT, x)
  238. static struct memberlist generic_memberlist[] = {
  239. {"objclass", T_INT, OFF(objclass), RO},
  240. {"type", T_INT, OFF(type), RO},
  241. {"boxtype", T_INT, OFF(boxtype)},
  242. {"x", T_FLOAT, OFF(x)},
  243. {"y", T_FLOAT, OFF(y)},
  244. {"w", T_FLOAT, OFF(w)},
  245. {"h", T_FLOAT, OFF(h)},
  246. {"col1", T_INT, OFF(col1)},
  247. {"col2", T_INT, OFF(col2)},
  248. {"align", T_INT, OFF(align)},
  249. {"lcol", T_INT, OFF(lcol)},
  250. {"lsize", T_FLOAT, OFF(lsize)},
  251. /* "label" is treated specially! */
  252. {"lstyle", T_INT, OFF(lstyle)},
  253. {"pushed", T_INT, OFF(pushed), RO},
  254. {"focus", T_INT, OFF(focus), RO},
  255. {"belowmouse", T_INT, OFF(belowmouse),RO},
  256. /* {"frozen", T_INT, OFF(frozen), RO}, */
  257. {"active", T_INT, OFF(active)},
  258. {"input", T_INT, OFF(input)},
  259. {"visible", T_INT, OFF(visible), RO},
  260. {"radio", T_INT, OFF(radio)},
  261. {"automatic", T_INT, OFF(automatic)},
  262. {NULL} /* Sentinel */
  263. };
  264. #undef OFF
  265. static PyObject *
  266. generic_getattr(genericobject *g, char *name)
  267. {
  268. PyObject *meth;
  269. /* XXX Ought to special-case name "__methods__" */
  270. if (g-> ob_methods) {
  271. meth = Py_FindMethod(g->ob_methods, (PyObject *)g, name);
  272. if (meth != NULL) return meth;
  273. PyErr_Clear();
  274. }
  275. meth = Py_FindMethod(generic_methods, (PyObject *)g, name);
  276. if (meth != NULL)
  277. return meth;
  278. PyErr_Clear();
  279. /* "label" is an exception, getmember only works for char pointers,
  280. not for char arrays */
  281. if (strcmp(name, "label") == 0)
  282. return PyString_FromString(g->ob_generic->label);
  283. return PyMember_Get((char *)g->ob_generic, generic_memberlist, name);
  284. }
  285. static int
  286. generic_setattr(genericobject *g, char *name, PyObject *v)
  287. {
  288. int ret;
  289. if (v == NULL) {
  290. PyErr_SetString(PyExc_TypeError,
  291. "can't delete forms object attributes");
  292. return -1;
  293. }
  294. /* "label" is an exception: setmember doesn't set strings;
  295. and FORMS wants you to call a function to set the label */
  296. if (strcmp(name, "label") == 0) {
  297. if (!PyString_Check(v)) {
  298. PyErr_SetString(PyExc_TypeError,
  299. "label attr must be string");
  300. return -1;
  301. }
  302. fl_set_object_label(g->ob_generic, PyString_AsString(v));
  303. return 0;
  304. }
  305. ret = PyMember_Set((char *)g->ob_generic, generic_memberlist, name, v);
  306. /* Rather than calling all the various set_object_* functions,
  307. we call fl_redraw_object here. This is sometimes redundant
  308. but I doubt that's a big problem */
  309. if (ret == 0)
  310. fl_redraw_object(g->ob_generic);
  311. return ret;
  312. }
  313. static PyObject *
  314. generic_repr(genericobject *g)
  315. {
  316. char buf[100];
  317. PyOS_snprintf(buf, sizeof(buf), "<FORMS_object at %p, objclass=%d>",
  318. g, g->ob_generic->objclass);
  319. return PyString_FromString(buf);
  320. }
  321. static PyTypeObject GenericObjecttype = {
  322. PyObject_HEAD_INIT(&PyType_Type)
  323. 0, /*ob_size*/
  324. "fl.FORMS_object", /*tp_name*/
  325. sizeof(genericobject), /*tp_size*/
  326. 0, /*tp_itemsize*/
  327. /* methods */
  328. (destructor)generic_dealloc, /*tp_dealloc*/
  329. 0, /*tp_print*/
  330. (getattrfunc)generic_getattr, /*tp_getattr*/
  331. (setattrfunc)generic_setattr, /*tp_setattr*/
  332. 0, /*tp_compare*/
  333. (reprfunc)generic_repr, /*tp_repr*/
  334. };
  335. static PyObject *
  336. newgenericobject(FL_OBJECT *generic, PyMethodDef *methods)
  337. {
  338. genericobject *g;
  339. g = PyObject_New(genericobject, &GenericObjecttype);
  340. if (g == NULL)
  341. return NULL;
  342. g-> ob_generic = generic;
  343. g->ob_methods = methods;
  344. g->ob_callback = NULL;
  345. g->ob_callback_arg = NULL;
  346. knowgeneric(g);
  347. return (PyObject *)g;
  348. }
  349. /**********************************************************************/
  350. /* Some common calling sequences */
  351. /* void func (object, float) */
  352. static PyObject *
  353. call_forms_INf (void (*func)(FL_OBJECT *, float), FL_OBJECT *obj, PyObject *args)
  354. {
  355. float parameter;
  356. if (!PyArg_Parse(args, "f", &parameter)) return NULL;
  357. (*func) (obj, parameter);
  358. Py_INCREF(Py_None);
  359. return Py_None;
  360. }
  361. /* void func (object, float) */
  362. static PyObject *
  363. call_forms_INfINf (void (*func)(FL_OBJECT *, float, float), FL_OBJECT *obj, PyObject *args)
  364. {
  365. float par1, par2;
  366. if (!PyArg_Parse(args, "(ff)", &par1, &par2)) return NULL;
  367. (*func) (obj, par1, par2);
  368. Py_INCREF(Py_None);
  369. return Py_None;
  370. }
  371. /* void func (object, int) */
  372. static PyObject *
  373. call_forms_INi (void (*func)(FL_OBJECT *, int), FL_OBJECT *obj, PyObject *args)
  374. {
  375. int parameter;
  376. if (!PyArg_Parse(args, "i", &parameter)) return NULL;
  377. (*func) (obj, parameter);
  378. Py_INCREF(Py_None);
  379. return Py_None;
  380. }
  381. /* void func (object, char) */
  382. static PyObject *
  383. call_forms_INc (void (*func)(FL_OBJECT *, int), FL_OBJECT *obj, PyObject *args)
  384. {
  385. char *a;
  386. if (!PyArg_Parse(args, "s", &a)) return NULL;
  387. (*func) (obj, a[0]);
  388. Py_INCREF(Py_None);
  389. return Py_None;
  390. }
  391. /* void func (object, string) */
  392. static PyObject *
  393. call_forms_INstr (void (*func)(FL_OBJECT *, char *), FL_OBJECT *obj, PyObject *args)
  394. {
  395. char *a;
  396. if (!PyArg_Parse(args, "s", &a)) return NULL;
  397. (*func) (obj, a);
  398. Py_INCREF(Py_None);
  399. return Py_None;
  400. }
  401. /* void func (object, int, string) */
  402. static PyObject *
  403. call_forms_INiINstr (void (*func)(FL_OBJECT *, int, char *), FL_OBJECT *obj, PyObject *args)
  404. {
  405. char *b;
  406. int a;
  407. if (!PyArg_Parse(args, "(is)", &a, &b)) return NULL;
  408. (*func) (obj, a, b);
  409. Py_INCREF(Py_None);
  410. return Py_None;
  411. }
  412. #ifdef UNUSED
  413. /* void func (object, int, int) */
  414. static PyObject *
  415. call_forms_INiINi (void (*func)(FL_OBJECT *, int, int), FL_OBJECT *obj, PyObject *args)
  416. {
  417. int par1, par2;
  418. if (!PyArg_Parse(args, "(ii)", &par1, &par2)) return NULL;
  419. (*func) (obj, par1, par2);
  420. Py_INCREF(Py_None);
  421. return Py_None;
  422. }
  423. #endif
  424. /* int func (object) */
  425. static PyObject *
  426. call_forms_Ri (int (*func)(FL_OBJECT *), FL_OBJECT *obj)
  427. {
  428. int retval;
  429. retval = (*func) (obj);
  430. return PyInt_FromLong ((long) retval);
  431. }
  432. /* char * func (object) */
  433. static PyObject *
  434. call_forms_Rstr (char * (*func)(FL_OBJECT *), FL_OBJECT *obj)
  435. {
  436. char *str;
  437. str = (*func) (obj);
  438. if (str == NULL) {
  439. Py_INCREF(Py_None);
  440. return Py_None;
  441. }
  442. return PyString_FromString (str);
  443. }
  444. /* int func (object) */
  445. static PyObject *
  446. call_forms_Rf (float (*func)(FL_OBJECT *), FL_OBJECT *obj)
  447. {
  448. float retval;
  449. retval = (*func) (obj);
  450. return PyFloat_FromDouble (retval);
  451. }
  452. static PyObject *
  453. call_forms_OUTfOUTf (void (*func)(FL_OBJECT *, float *, float *), FL_OBJECT *obj)
  454. {
  455. float f1, f2;
  456. (*func) (obj, &f1, &f2);
  457. return Py_BuildValue("(ff)", f1, f2);
  458. }
  459. #ifdef UNUSED
  460. static PyObject *
  461. call_forms_OUTf (void (*func)(FL_OBJECT *, float *), FL_OBJECT *obj)
  462. {
  463. float f;
  464. (*func) (obj, &f);
  465. return PyFloat_FromDouble (f);
  466. }
  467. #endif
  468. /**********************************************************************/
  469. /* Class : browser */
  470. static PyObject *
  471. set_browser_topline(genericobject *g, PyObject *args)
  472. {
  473. return call_forms_INi (fl_set_browser_topline, g-> ob_generic, args);
  474. }
  475. static PyObject *
  476. clear_browser(genericobject *g)
  477. {
  478. return generic_call (g, fl_clear_browser);
  479. }
  480. static PyObject *
  481. add_browser_line (genericobject *g, PyObject *args)
  482. {
  483. return call_forms_INstr (fl_add_browser_line, g-> ob_generic, args);
  484. }
  485. static PyObject *
  486. addto_browser (genericobject *g, PyObject *args)
  487. {
  488. return call_forms_INstr (fl_addto_browser, g-> ob_generic, args);
  489. }
  490. static PyObject *
  491. insert_browser_line (genericobject *g, PyObject *args)
  492. {
  493. return call_forms_INiINstr (fl_insert_browser_line,
  494. g-> ob_generic, args);
  495. }
  496. static PyObject *
  497. delete_browser_line (genericobject *g, PyObject *args)
  498. {
  499. return call_forms_INi (fl_delete_browser_line, g-> ob_generic, args);
  500. }
  501. static PyObject *
  502. replace_browser_line (genericobject *g, PyObject *args)
  503. {
  504. return call_forms_INiINstr (fl_replace_browser_line,
  505. g-> ob_generic, args);
  506. }
  507. static PyObject *
  508. get_browser_line(genericobject *g, PyObject *args)
  509. {
  510. int i;
  511. char *str;
  512. if (!PyArg_Parse(args, "i", &i))
  513. return NULL;
  514. str = fl_get_browser_line (g->ob_generic, i);
  515. if (str == NULL) {
  516. Py_INCREF(Py_None);
  517. return Py_None;
  518. }
  519. return PyString_FromString (str);
  520. }
  521. static PyObject *
  522. load_browser (genericobject *g, PyObject *args)
  523. {
  524. /* XXX strictly speaking this is wrong since fl_load_browser
  525. XXX returns int, not void */
  526. return call_forms_INstr (fl_load_browser, g-> ob_generic, args);
  527. }
  528. static PyObject *
  529. get_browser_maxline(genericobject *g)
  530. {
  531. return call_forms_Ri (fl_get_browser_maxline, g-> ob_generic);
  532. }
  533. static PyObject *
  534. select_browser_line (genericobject *g, PyObject *args)
  535. {
  536. return call_forms_INi (fl_select_browser_line, g-> ob_generic, args);
  537. }
  538. static PyObject *
  539. deselect_browser_line (genericobject *g, PyObject *args)
  540. {
  541. return call_forms_INi (fl_deselect_browser_line, g-> ob_generic, args);
  542. }
  543. static PyObject *
  544. deselect_browser (genericobject *g)
  545. {
  546. return generic_call (g, fl_deselect_browser);
  547. }
  548. static PyObject *
  549. isselected_browser_line (genericobject *g, PyObject *args)
  550. {
  551. int i, j;
  552. if (!PyArg_Parse(args, "i", &i))
  553. return NULL;
  554. j = fl_isselected_browser_line (g->ob_generic, i);
  555. return PyInt_FromLong (j);
  556. }
  557. static PyObject *
  558. get_browser (genericobject *g)
  559. {
  560. return call_forms_Ri (fl_get_browser, g-> ob_generic);
  561. }
  562. static PyObject *
  563. set_browser_fontsize (genericobject *g, PyObject *args)
  564. {
  565. return call_forms_INf (fl_set_browser_fontsize, g-> ob_generic, args);
  566. }
  567. static PyObject *
  568. set_browser_fontstyle (genericobject *g, PyObject *args)
  569. {
  570. return call_forms_INi (fl_set_browser_fontstyle, g-> ob_generic, args);
  571. }
  572. static PyObject *
  573. set_browser_specialkey (genericobject *g, PyObject *args)
  574. {
  575. return call_forms_INc(fl_set_browser_specialkey, g-> ob_generic, args);
  576. }
  577. static PyMethodDef browser_methods[] = {
  578. {"set_browser_topline", (PyCFunction)set_browser_topline,
  579. METH_OLDARGS},
  580. {"clear_browser", (PyCFunction)clear_browser,
  581. METH_NOARGS},
  582. {"add_browser_line", (PyCFunction)add_browser_line,
  583. METH_OLDARGS},
  584. {"addto_browser", (PyCFunction)addto_browser,
  585. METH_OLDARGS},
  586. {"insert_browser_line", (PyCFunction)insert_browser_line,
  587. METH_OLDARGS},
  588. {"delete_browser_line", (PyCFunction)delete_browser_line,
  589. METH_OLDARGS},
  590. {"replace_browser_line", (PyCFunction)replace_browser_line,
  591. METH_OLDARGS},
  592. {"get_browser_line", (PyCFunction)get_browser_line,
  593. METH_OLDARGS},
  594. {"load_browser", (PyCFunction)load_browser,
  595. METH_OLDARGS},
  596. {"get_browser_maxline", (PyCFunction)get_browser_maxline,
  597. METH_NOARGS,}
  598. {"select_browser_line", (PyCFunction)select_browser_line,
  599. METH_OLDARGS},
  600. {"deselect_browser_line", (PyCFunction)deselect_browser_line,
  601. METH_OLDARGS},
  602. {"deselect_browser", (PyCFunction)deselect_browser,
  603. METH_NOARGS,}
  604. {"isselected_browser_line", (PyCFunction)isselected_browser_line,
  605. METH_OLDARGS},
  606. {"get_browser", (PyCFunction)get_browser,
  607. METH_NOARGS,}
  608. {"set_browser_fontsize", (PyCFunction)set_browser_fontsize,
  609. METH_OLDARGS},
  610. {"set_browser_fontstyle", (PyCFunction)set_browser_fontstyle,
  611. METH_OLDARGS},
  612. {"set_browser_specialkey", (PyCFunction)set_browser_specialkey,
  613. METH_OLDARGS},
  614. {NULL, NULL} /* sentinel */
  615. };
  616. /* Class: button */
  617. static PyObject *
  618. set_button(genericobject *g, PyObject *args)
  619. {
  620. return call_forms_INi (fl_set_button, g-> ob_generic, args);
  621. }
  622. static PyObject *
  623. get_button(genericobject *g)
  624. {
  625. return call_forms_Ri (fl_get_button, g-> ob_generic);
  626. }
  627. static PyObject *
  628. get_button_numb(genericobject *g)
  629. {
  630. return call_forms_Ri (fl_get_button_numb, g-> ob_generic);
  631. }
  632. static PyObject *
  633. set_button_shortcut(genericobject *g, PyObject *args)
  634. {
  635. return call_forms_INstr (fl_set_button_shortcut, g-> ob_generic, args);
  636. }
  637. static PyMethodDef button_methods[] = {
  638. {"set_button", (PyCFunction)set_button, METH_OLDARGS},
  639. {"get_button", (PyCFunction)get_button, METH_NOARGS},
  640. {"get_button_numb", (PyCFunction)get_button_numb, METH_NOARGS},
  641. {"set_button_shortcut", (PyCFunction)set_button_shortcut, METH_OLDARGS},
  642. {NULL, NULL} /* sentinel */
  643. };
  644. /* Class: choice */
  645. static PyObject *
  646. set_choice(genericobject *g, PyObject *args)
  647. {
  648. return call_forms_INi (fl_set_choice, g-> ob_generic, args);
  649. }
  650. static PyObject *
  651. get_choice(genericobject *g)
  652. {
  653. return call_forms_Ri (fl_get_choice, g-> ob_generic);
  654. }
  655. static PyObject *
  656. clear_choice (genericobject *g)
  657. {
  658. return generic_call (g, fl_clear_choice);
  659. }
  660. static PyObject *
  661. addto_choice (genericobject *g, PyObject *args)
  662. {
  663. return call_forms_INstr (fl_addto_choice, g-> ob_generic, args);
  664. }
  665. static PyObject *
  666. replace_choice (genericobject *g, PyObject *args)
  667. {
  668. return call_forms_INiINstr (fl_replace_choice, g-> ob_generic, args);
  669. }
  670. static PyObject *
  671. delete_choice (genericobject *g, PyObject *args)
  672. {
  673. return call_forms_INi (fl_delete_choice, g-> ob_generic, args);
  674. }
  675. static PyObject *
  676. get_choice_text (genericobject *g)
  677. {
  678. return call_forms_Rstr (fl_get_choice_text, g-> ob_generic);
  679. }
  680. static PyObject *
  681. set_choice_fontsize (genericobject *g, PyObject *args)
  682. {
  683. return call_forms_INf (fl_set_choice_fontsize, g-> ob_generic, args);
  684. }
  685. static PyObject *
  686. set_choice_fontstyle (genericobject *g, PyObject *args)
  687. {
  688. return call_forms_INi (fl_set_choice_fontstyle, g-> ob_generic, args);
  689. }
  690. static PyMethodDef choice_methods[] = {
  691. {"set_choice", (PyCFunction)set_choice, METH_OLDARGS},
  692. {"get_choice", (PyCFunction)get_choice, METH_NOARGS},
  693. {"clear_choice", (PyCFunction)clear_choice, METH_NOARGS},
  694. {"addto_choice", (PyCFunction)addto_choice, METH_OLDARGS},
  695. {"replace_choice", (PyCFunction)replace_choice, METH_OLDARGS},
  696. {"delete_choice", (PyCFunction)delete_choice, METH_OLDARGS},
  697. {"get_choice_text", (PyCFunction)get_choice_text, METH_NOARGS},
  698. {"set_choice_fontsize", (PyCFunction)set_choice_fontsize, METH_OLDARGS},
  699. {"set_choice_fontstyle",(PyCFunction)set_choice_fontstyle, METH_OLDARGS},
  700. {NULL, NULL} /* sentinel */
  701. };
  702. /* Class : Clock */
  703. static PyObject *
  704. get_clock(genericobject *g)
  705. {
  706. int i0, i1, i2;
  707. fl_get_clock (g->ob_generic, &i0, &i1, &i2);
  708. return Py_BuildValue("(iii)", i0, i1, i2);
  709. }
  710. static PyMethodDef clock_methods[] = {
  711. {"get_clock", (PyCFunction)get_clock, METH_NOARGS},
  712. {NULL, NULL} /* sentinel */
  713. };
  714. /* CLass : Counters */
  715. static PyObject *
  716. get_counter_value(genericobject *g)
  717. {
  718. return call_forms_Rf (fl_get_counter_value, g-> ob_generic);
  719. }
  720. static PyObject *
  721. set_counter_value (genericobject *g, PyObject *args)
  722. {
  723. return call_forms_INf (fl_set_counter_value, g-> ob_generic, args);
  724. }
  725. static PyObject *
  726. set_counter_precision (genericobject *g, PyObject *args)
  727. {
  728. return call_forms_INi (fl_set_counter_precision, g-> ob_generic, args);
  729. }
  730. static PyObject *
  731. set_counter_bounds (genericobject *g, PyObject *args)
  732. {
  733. return call_forms_INfINf (fl_set_counter_bounds, g-> ob_generic, args);
  734. }
  735. static PyObject *
  736. set_counter_step (genericobject *g, PyObject *args)
  737. {
  738. return call_forms_INfINf (fl_set_counter_step, g-> ob_generic, args);
  739. }
  740. static PyObject *
  741. set_counter_return (genericobject *g, PyObject *args)
  742. {
  743. return call_forms_INi (fl_set_counter_return, g-> ob_generic, args);
  744. }
  745. static PyMethodDef counter_methods[] = {
  746. {"set_counter_value", (PyCFunction)set_counter_value,
  747. METH_OLDARGS},
  748. {"get_counter_value", (PyCFunction)get_counter_value,
  749. METH_NOARGS},
  750. {"set_counter_bounds", (PyCFunction)set_counter_bounds,
  751. METH_OLDARGS},
  752. {"set_counter_step", (PyCFunction)set_counter_step,
  753. METH_OLDARGS},
  754. {"set_counter_precision", (PyCFunction)set_counter_precision,
  755. METH_OLDARGS},
  756. {"set_counter_return", (PyCFunction)set_counter_return,
  757. METH_OLDARGS},
  758. {NULL, NULL} /* sentinel */
  759. };
  760. /* Class: Dials */
  761. static PyObject *
  762. get_dial_value(genericobject *g)
  763. {
  764. return call_forms_Rf (fl_get_dial_value, g-> ob_generic);
  765. }
  766. static PyObject *
  767. set_dial_value (genericobject *g, PyObject *args)
  768. {
  769. return call_forms_INf (fl_set_dial_value, g-> ob_generic, args);
  770. }
  771. static PyObject *
  772. set_dial_bounds (genericobject *g, PyObject *args)
  773. {
  774. return call_forms_INfINf (fl_set_dial_bounds, g-> ob_generic, args);
  775. }
  776. static PyObject *
  777. get_dial_bounds (genericobject *g)
  778. {
  779. return call_forms_OUTfOUTf (fl_get_dial_bounds, g-> ob_generic);
  780. }
  781. static PyObject *
  782. set_dial_step (genericobject *g, PyObject *args)
  783. {
  784. return call_forms_INf (fl_set_dial_step, g-> ob_generic, args);
  785. }
  786. static PyMethodDef dial_methods[] = {
  787. {"set_dial_value", (PyCFunction)set_dial_value, METH_OLDARGS},
  788. {"get_dial_value", (PyCFunction)get_dial_value, METH_NOARGS},
  789. {"set_dial_bounds", (PyCFunction)set_dial_bounds, METH_OLDARGS},
  790. {"get_dial_bounds", (PyCFunction)get_dial_bounds, METH_NOARGS},
  791. {"set_dial_step", (PyCFunction)set_dial_step, METH_OLDARGS},
  792. {NULL, NULL} /* sentinel */
  793. };
  794. /* Class : Input */
  795. static PyObject *
  796. set_input (genericobject *g, PyObject *args)
  797. {
  798. return call_forms_INstr (fl_set_input, g-> ob_generic, args);
  799. }
  800. static PyObject *
  801. get_input (genericobject *g)
  802. {
  803. return call_forms_Rstr (fl_get_input, g-> ob_generic);
  804. }
  805. static PyObject *
  806. set_input_color (genericobject *g, PyObject *args)
  807. {
  808. return call_forms_INfINf (fl_set_input_color, g-> ob_generic, args);
  809. }
  810. static PyObject *
  811. set_input_return (genericobject *g, PyObject *args)
  812. {
  813. return call_forms_INi (fl_set_input_return, g-> ob_generic, args);
  814. }
  815. static PyMethodDef input_methods[] = {
  816. {"set_input", (PyCFunction)set_input, METH_OLDARGS},
  817. {"get_input", (PyCFunction)get_input, METH_NOARGS},
  818. {"set_input_color", (PyCFunction)set_input_color, METH_OLDARGS},
  819. {"set_input_return", (PyCFunction)set_input_return, METH_OLDARGS},
  820. {NULL, NULL} /* sentinel */
  821. };
  822. /* Class : Menu */
  823. static PyObject *
  824. set_menu (genericobject *g, PyObject *args)
  825. {
  826. return call_forms_INstr (fl_set_menu, g-> ob_generic, args);
  827. }
  828. static PyObject *
  829. get_menu (genericobject *g)
  830. {
  831. /* XXX strictly speaking this is wrong since fl_get_menu
  832. XXX returns long, not int */
  833. return call_forms_Ri (fl_get_menu, g-> ob_generic);
  834. }
  835. static PyObject *
  836. get_menu_text (genericobject *g)
  837. {
  838. return call_forms_Rstr (fl_get_menu_text, g-> ob_generic);
  839. }
  840. static PyObject *
  841. addto_menu (genericobject *g, PyObject *args)
  842. {
  843. return call_forms_INstr (fl_addto_menu, g-> ob_generic, args);
  844. }
  845. static PyMethodDef menu_methods[] = {
  846. {"set_menu", (PyCFunction)set_menu, METH_OLDARGS},
  847. {"get_menu", (PyCFunction)get_menu, METH_NOARGS},
  848. {"get_menu_text", (PyCFunction)get_menu_text, METH_NOARGS},
  849. {"addto_menu", (PyCFunction)addto_menu, METH_OLDARGS},
  850. {NULL, NULL} /* sentinel */
  851. };
  852. /* Class: Sliders */
  853. static PyObject *
  854. get_slider_value(genericobject *g)
  855. {
  856. return call_forms_Rf (fl_get_slider_value, g-> ob_generic);
  857. }
  858. static PyObject *
  859. set_slider_value (genericobject *g, PyObject *args)
  860. {
  861. return call_forms_INf (fl_set_slider_value, g-> ob_generic, args);
  862. }
  863. static PyObject *
  864. set_slider_bounds (genericobject *g, PyObject *args)
  865. {
  866. return call_forms_INfINf (fl_set_slider_bounds, g-> ob_generic, args);
  867. }
  868. static PyObject *
  869. get_slider_bounds (genericobject *g)
  870. {
  871. return call_forms_OUTfOUTf(fl_get_slider_bounds, g-> ob_generic);
  872. }
  873. static PyObject *
  874. set_slider_return (genericobject *g, PyObject *args)
  875. {
  876. return call_forms_INf (fl_set_slider_return, g-> ob_generic, args);
  877. }
  878. static PyObject *
  879. set_slider_size (genericobject *g, PyObject *args)
  880. {
  881. return call_forms_INf (fl_set_slider_size, g-> ob_generic, args);
  882. }
  883. static PyObject *
  884. set_slider_precision (genericobject *g, PyObject *args)
  885. {
  886. return call_forms_INi (fl_set_slider_precision, g-> ob_generic, args);
  887. }
  888. static PyObject *
  889. set_slider_step (genericobject *g, PyObject *args)
  890. {
  891. return call_forms_INf (fl_set_slider_step, g-> ob_generic, args);
  892. }
  893. static PyMethodDef slider_methods[] = {
  894. {"set_slider_value", (PyCFunction)set_slider_value, METH_OLDARGS},
  895. {"get_slider_value", (PyCFunction)get_slider_value, METH_NOARGS},
  896. {"set_slider_bounds", (PyCFunction)set_slider_bounds, METH_OLDARGS},
  897. {"get_slider_bounds", (PyCFunction)get_slider_bounds, METH_NOARGS},
  898. {"set_slider_return", (PyCFunction)set_slider_return, METH_OLDARGS},
  899. {"set_slider_size", (PyCFunction)set_slider_size, METH_OLDARGS},
  900. {"set_slider_precision",(PyCFunction)set_slider_precision, METH_OLDARGS},
  901. {"set_slider_step", (PyCFunction)set_slider_step, METH_OLDARGS},
  902. {NULL, NULL} /* sentinel */
  903. };
  904. static PyObject *
  905. set_positioner_xvalue (genericobject *g, PyObject *args)
  906. {
  907. return call_forms_INf (fl_set_positioner_xvalue, g-> ob_generic, args);
  908. }
  909. static PyObject *
  910. set_positioner_xbounds (genericobject *g, PyObject *args)
  911. {
  912. return call_forms_INfINf (fl_set_positioner_xbounds,
  913. g-> ob_generic, args);
  914. }
  915. static PyObject *
  916. set_positioner_yvalue (genericobject *g, PyObject *args)
  917. {
  918. return call_forms_INf (fl_set_positioner_yvalue, g-> ob_generic, args);
  919. }
  920. static PyObject *
  921. set_positioner_ybounds (genericobject *g, PyObject *args)
  922. {
  923. return call_forms_INfINf (fl_set_positioner_ybounds,
  924. g-> ob_generic, args);
  925. }
  926. static PyObject *
  927. get_positioner_xvalue (genericobject *g)
  928. {
  929. return call_forms_Rf (fl_get_positioner_xvalue, g-> ob_generic);
  930. }
  931. static PyObject *
  932. get_positioner_xbounds (genericobject *g)
  933. {
  934. return call_forms_OUTfOUTf (fl_get_positioner_xbounds, g-> ob_generic);
  935. }
  936. static PyObject *
  937. get_positioner_yvalue (genericobject *g)
  938. {
  939. return call_forms_Rf (fl_get_positioner_yvalue, g-> ob_generic);
  940. }
  941. static PyObject *
  942. get_positioner_ybounds (genericobject *g)
  943. {
  944. return call_forms_OUTfOUTf (fl_get_positioner_ybounds, g-> ob_generic);
  945. }
  946. static PyMethodDef positioner_methods[] = {
  947. {"set_positioner_xvalue", (PyCFunction)set_positioner_xvalue,
  948. METH_OLDARGS},
  949. {"set_positioner_yvalue", (PyCFunction)set_positioner_yvalue,
  950. METH_OLDARGS},
  951. {"set_positioner_xbounds", (PyCFunction)set_positioner_xbounds,
  952. METH_OLDARGS},
  953. {"set_positioner_ybounds", (PyCFunction)set_positioner_ybounds,
  954. METH_OLDARGS},
  955. {"get_positioner_xvalue", (PyCFunction)get_positioner_xvalue,
  956. METH_NOARGS},
  957. {"get_positioner_yvalue", (PyCFunction)get_positioner_yvalue,
  958. METH_NOARGS},
  959. {"get_positioner_xbounds", (PyCFunction)get_positioner_xbounds,
  960. METH_NOARGS},
  961. {"get_positioner_ybounds", (PyCFunction)get_positioner_ybounds,
  962. METH_NOARGS},
  963. {NULL, NULL} /* sentinel */
  964. };
  965. /* Class timer */
  966. static PyObject *
  967. set_timer (genericobject *g, PyObject *args)
  968. {
  969. return call_forms_INf (fl_set_timer, g-> ob_generic, args);
  970. }
  971. static PyObject *
  972. get_timer (genericobject *g)
  973. {
  974. return call_forms_Rf (fl_get_timer, g-> ob_generic);
  975. }
  976. static PyMethodDef timer_methods[] = {
  977. {"set_timer", (PyCFunction)set_timer, METH_OLDARGS},
  978. {"get_timer", (PyCFunction)get_timer, METH_NOARGS},
  979. {NULL, NULL} /* sentinel */
  980. };
  981. /* Form objects */
  982. typedef struct {
  983. PyObject_HEAD
  984. FL_FORM *ob_form;
  985. } formobject;
  986. static PyTypeObject Formtype;
  987. #define is_formobject(v) ((v)->ob_type == &Formtype)
  988. static PyObject *
  989. form_show_form(formobject *f, PyObject *args)
  990. {
  991. int place, border;
  992. char *name;
  993. if (!PyArg_Parse(args, "(iis)", &place, &border, &name))
  994. return NULL;
  995. fl_show_form(f->ob_form, place, border, name);
  996. Py_INCREF(Py_None);
  997. return Py_None;
  998. }
  999. static PyObject *
  1000. form_call(void (*func)(FL_FORM *), FL_FORM *f)
  1001. {
  1002. (*func)(f);
  1003. Py_INCREF(Py_None);
  1004. return Py_None;
  1005. }
  1006. static PyObject *
  1007. form_call_INiINi(void (*func)(FL_FORM *, int, int), FL_FORM *f, PyObject *args)
  1008. {
  1009. int a, b;
  1010. if (!PyArg_Parse(args, "(ii)", &a, &b)) return NULL;
  1011. (*func)(f, a, b);
  1012. Py_INCREF(Py_None);
  1013. return Py_None;
  1014. }
  1015. static PyObject *
  1016. form_call_INfINf(void (*func)(FL_FORM *, float, float), FL_FORM *f, PyObject *args)
  1017. {
  1018. float a, b;
  1019. if (!PyArg_Parse(args, "(ff)", &a, &b)) return NULL;
  1020. (*func)(f, a, b);
  1021. Py_INCREF(Py_None);
  1022. return Py_None;
  1023. }
  1024. static PyObject *
  1025. form_hide_form(formobject *f)
  1026. {
  1027. return form_call(fl_hide_form, f-> ob_form);
  1028. }
  1029. static PyObject *
  1030. form_redraw_form(formobject *f)
  1031. {
  1032. return form_call(fl_redraw_form, f-> ob_form);
  1033. }
  1034. static PyObject *
  1035. form_set_form_position(formobject *f, PyObject *args)
  1036. {
  1037. return form_call_INiINi(fl_set_form_position, f-> ob_form, args);
  1038. }
  1039. static PyObject *
  1040. form_set_form_size(formobject *f, PyObject *args)
  1041. {
  1042. return form_call_INiINi(fl_set_form_size, f-> ob_form, args);
  1043. }
  1044. static PyObject *
  1045. form_scale_form(formobject *f, PyObject *args)
  1046. {
  1047. return form_call_INfINf(fl_scale_form, f-> ob_form, args);
  1048. }
  1049. static PyObject *
  1050. generic_add_object(formobject *f, PyObject *args, FL_OBJECT *(*func)(int, float, float, float, float, char*), PyMethodDef *internal_methods)
  1051. {
  1052. int type;
  1053. float x, y, w, h;
  1054. char *name;
  1055. FL_OBJECT *obj;
  1056. if (!PyArg_Parse(args,"(iffffs)", &type,&x,&y,&w,&h,&name))
  1057. return NULL;
  1058. fl_addto_form (f-> ob_form);
  1059. obj = (*func) (type, x, y, w, h, name);
  1060. fl_end_form();
  1061. if (obj == NULL) {
  1062. PyErr_NoMemory();
  1063. return NULL;
  1064. }
  1065. return newgenericobject (obj, internal_methods);
  1066. }
  1067. static PyObject *
  1068. form_add_button(formobject *f, PyObject *args)
  1069. {
  1070. return generic_add_object(f, args, fl_add_button, button_methods);
  1071. }
  1072. static PyObject *
  1073. form_add_lightbutton(formobject *f, PyObject *args)
  1074. {
  1075. return generic_add_object(f, args, fl_add_lightbutton, button_methods);
  1076. }
  1077. static PyObject *
  1078. form_add_roundbutton(formobject *f, PyObject *args)
  1079. {
  1080. return generic_add_object(f, args, fl_add_roundbutton, button_methods);
  1081. }
  1082. static PyObject *
  1083. form_add_menu (formobject *f, PyObject *args)
  1084. {
  1085. return generic_add_object(f, args, fl_add_menu, menu_methods);
  1086. }
  1087. static PyObject *
  1088. form_add_slider(formobject *f, PyObject *args)
  1089. {
  1090. return generic_add_object(f, args, fl_add_slider, slider_methods);
  1091. }
  1092. static PyObject *
  1093. form_add_valslider(formobject *f, PyObject *args)
  1094. {
  1095. return generic_add_object(f, args, fl_add_valslider, slider_methods);
  1096. }
  1097. static PyObject *
  1098. form_add_dial(formobject *f, PyObject *args)
  1099. {
  1100. return generic_add_object(f, args, fl_add_dial, dial_methods);
  1101. }
  1102. static PyObject *
  1103. form_add_counter(formobject *f, PyObject *args)
  1104. {
  1105. return generic_add_object(f, args, fl_add_counter, counter_methods);
  1106. }
  1107. static PyObject *
  1108. form_add_clock(formobject *f, PyObject *args)
  1109. {
  1110. return generic_add_object(f, args, fl_add_clock, clock_methods);
  1111. }
  1112. static PyObject *
  1113. form_add_box(formobject *f, PyObject *args)
  1114. {
  1115. return generic_add_object(f, args, fl_add_box,
  1116. (PyMethodDef *)NULL);
  1117. }
  1118. static PyObject *
  1119. form_add_choice(formobject *f, PyObject *args)
  1120. {
  1121. return generic_add_object(f, args, fl_add_choice, choice_methods);
  1122. }
  1123. static PyObject *
  1124. form_add_browser(formobject *f, PyObject *args)
  1125. {
  1126. return generic_add_object(f, args, fl_add_browser, browser_methods);
  1127. }
  1128. static PyObject *
  1129. form_add_positioner(formobject *f, PyObject *args)
  1130. {
  1131. return generic_add_object(f, args, fl_add_positioner,
  1132. positioner_methods);
  1133. }
  1134. static PyObject *
  1135. form_add_input(formobject *f, PyObject *args)
  1136. {
  1137. return generic_add_object(f, args, fl_add_input, input_methods);
  1138. }
  1139. static PyObject *
  1140. form_add_text(formobject *f, PyObject *args)
  1141. {
  1142. return generic_add_object(f, args, fl_add_text,
  1143. (PyMethodDef *)NULL);
  1144. }
  1145. static PyObject *
  1146. form_add_timer(formobject *f, PyObject *args)
  1147. {
  1148. return generic_add_object(f, args, fl_add_timer, timer_methods);
  1149. }
  1150. static PyObject *
  1151. form_freeze_form(formobject *f)
  1152. {
  1153. return form_call(fl_freeze_form, f-> ob_form);
  1154. }
  1155. static PyObject *
  1156. form_unfreeze_form(formobject *f)
  1157. {
  1158. return form_call(fl_unfreeze_form, f-> ob_form);
  1159. }
  1160. static PyObject *
  1161. form_activate_form(formobject *f)
  1162. {
  1163. return form_call(fl_activate_form, f-> ob_form);
  1164. }
  1165. static PyObject *
  1166. form_deactivate_form(formobject *f)
  1167. {
  1168. return form_call(fl_deactivate_form, f-> ob_form);
  1169. }
  1170. static PyObject *
  1171. form_bgn_group(formobject *f, PyObject *args)
  1172. {
  1173. FL_OBJECT *obj;
  1174. fl_addto_form(f-> ob_form);
  1175. obj = fl_bgn_group();
  1176. fl_end_form();
  1177. if (obj == NULL) {
  1178. PyErr_NoMemory();
  1179. return NULL;
  1180. }
  1181. return newgenericobject (obj, (PyMethodDef *) NULL);
  1182. }
  1183. static PyObject *
  1184. form_end_group(formobject *f, PyObject *args)
  1185. {
  1186. fl_addto_form(f-> ob_form);
  1187. fl_end_group();
  1188. fl_end_form();
  1189. Py_INCREF(Py_None);
  1190. return Py_None;
  1191. }
  1192. static PyObject *
  1193. forms_find_first_or_last(FL_OBJECT *(*func)(FL_FORM *, int, float, float), formobject *f, PyObject *args)
  1194. {
  1195. int type;
  1196. float mx, my;
  1197. FL_OBJECT *generic;
  1198. genericobject *g;
  1199. if (!PyArg_Parse(args, "(iff)", &type, &mx, &my)) return NULL;
  1200. generic = (*func) (f-> ob_form, type, mx, my);
  1201. if (generic == NULL)
  1202. {
  1203. Py_INCREF(Py_None);
  1204. return Py_None;
  1205. }
  1206. g = findgeneric(generic);
  1207. if (g == NULL) {
  1208. PyErr_SetString(PyExc_RuntimeError,
  1209. "forms_find_{first|last} returns unknown object");
  1210. return NULL;
  1211. }
  1212. Py_INCREF(g);
  1213. return (PyObject *) g;
  1214. }
  1215. static PyObject *
  1216. form_find_first(formobject *f, PyObject *args)
  1217. {
  1218. return forms_find_first_or_last(fl_find_first, f, args);
  1219. }
  1220. static PyObject *
  1221. form_find_last(formobject *f, PyObject *args)
  1222. {
  1223. return forms_find_first_or_last(fl_find_last, f, args);
  1224. }
  1225. static PyObject *
  1226. form_set_object_focus(formobject *f, PyObject *args)
  1227. {
  1228. genericobject *g;
  1229. if (args == NULL || !is_genericobject(args)) {
  1230. PyErr_BadArgument();
  1231. return NULL;
  1232. }
  1233. g = (genericobject *)args;
  1234. fl_set_object_focus(f->ob_form, g->ob_generic);
  1235. Py_INCREF(Py_None);
  1236. return Py_None;
  1237. }
  1238. static PyMethodDef form_methods[] = {
  1239. /* adm */
  1240. {"show_form", (PyCFunction)form_show_form, METH_OLDARGS},
  1241. {"hide_form", (PyCFunction)form_hide_form, METH_NOARGS},
  1242. {"redraw_form", (PyCFunction)form_redraw_form, METH_NOARGS},
  1243. {"set_form_position", (PyCFunction)form_set_form_position, METH_OLDARGS},
  1244. {"set_form_size", (PyCFunction)form_set_form_size, METH_OLDARGS},
  1245. {"scale_form", (PyCFunction)form_scale_form, METH_OLDARGS},
  1246. {"freeze_form", (PyCFunction)form_freeze_form, METH_NOARGS},
  1247. {"unfreeze_form", (PyCFunction)form_unfreeze_form, METH_NOARGS},
  1248. {"activate_form", (PyCFunction)form_activate_form, METH_NOARGS},
  1249. {"deactivate_form", (PyCFunction)form_deactivate_form, METH_NOARGS},
  1250. {"bgn_group", (PyCFunction)form_bgn_group, METH_OLDARGS},
  1251. {"end_group", (PyCFunction)form_end_group, METH_OLDARGS},
  1252. {"find_first", (PyCFunction)form_find_first, METH_OLDARGS},
  1253. {"find_last", (PyCFunction)form_find_last, METH_OLDARGS},
  1254. {"set_object_focus", (PyCFunction)form_set_object_focus, METH_OLDARGS},
  1255. /* basic objects */
  1256. {"add_button", (PyCFunction)form_add_button, METH_OLDARGS},
  1257. /* {"add_bitmap", (method)form_add_bitmap, METH_OLDARGS}, */
  1258. {"add_lightbutton", (PyCFunction)form_add_lightbutton, METH_OLDARGS},
  1259. {"add_roundbutton", (PyCFunction)form_add_roundbutton, METH_OLDARGS},
  1260. {"add_menu", (PyCFunction)form_add_menu, METH_OLDARGS},
  1261. {"add_slider", (PyCFunction)form_add_slider, METH_OLDARGS},
  1262. {"add_positioner", (PyCFunction)form_add_positioner, METH_OLDARGS},
  1263. {"add_valslider", (PyCFunction)form_add_valslider, METH_OLDARGS},
  1264. {"add_dial", (PyCFunction)form_add_dial, METH_OLDARGS},
  1265. {"add_counter", (PyCFunction)form_add_counter, METH_OLDARGS},
  1266. {"add_box", (PyCFunction)form_add_box, METH_OLDARGS},
  1267. {"add_clock", (PyCFunction)form_add_clock, METH_OLDARGS},
  1268. {"add_choice", (PyCFunction)form_add_choice, METH_OLDARGS},
  1269. {"add_browser", (PyCFunction)form_add_browser, METH_OLDARGS},
  1270. {"add_input", (PyCFunction)form_add_input, METH_OLDARGS},
  1271. {"add_timer", (PyCFunction)form_add_timer, METH_OLDARGS},
  1272. {"add_text", (PyCFunction)form_add_text, METH_OLDARGS},
  1273. {NULL, NULL} /* sentinel */
  1274. };
  1275. static void
  1276. form_dealloc(formobject *f)
  1277. {
  1278. releaseobjects(f->ob_form);
  1279. if (f->ob_form->visible)
  1280. fl_hide_form(f->ob_form);
  1281. fl_free_form(f->ob_form);
  1282. PyObject_Del(f);
  1283. }
  1284. #define OFF(x) offsetof(FL_FORM, x)
  1285. static struct memberlist form_memberlist[] = {
  1286. {"window", T_LONG, OFF(window), RO},
  1287. {"w", T_FLOAT, OFF(w)},
  1288. {"h", T_FLOAT, OFF(h)},
  1289. {"x", T_FLOAT, OFF(x), RO},
  1290. {"y", T_FLOAT, OFF(y), RO},
  1291. {"deactivated", T_INT, OFF(deactivated)},
  1292. {"visible", T_INT, OFF(visible), RO},
  1293. {"frozen", T_INT, OFF(frozen), RO},
  1294. {"doublebuf", T_INT, OFF(doublebuf)},
  1295. {NULL} /* Sentinel */
  1296. };
  1297. #undef OFF
  1298. static PyObject *
  1299. form_getattr(formobject *f, char *name)
  1300. {
  1301. PyObject *meth;
  1302. meth = Py_FindMethod(form_methods, (PyObject *)f, name);
  1303. if (meth != NULL)
  1304. return meth;
  1305. PyErr_Clear();
  1306. return PyMember_Get((char *)f->ob_form, form_memberlist, name);
  1307. }
  1308. static int
  1309. form_setattr(formobject *f, char *name, PyObject *v)
  1310. {
  1311. if (v == NULL) {
  1312. PyErr_SetString(PyExc_TypeError,
  1313. "can't delete form attributes");
  1314. return -1;
  1315. }
  1316. return PyMember_Set((char *)f->ob_form, form_memberlist, name, v);
  1317. }
  1318. static PyObject *
  1319. form_repr(formobject *f)
  1320. {
  1321. char buf[100];
  1322. PyOS_snprintf(buf, sizeof(buf), "<FORMS_form at %p, window=%ld>",
  1323. f, f->ob_form->window);
  1324. return PyString_FromString(buf);
  1325. }
  1326. static PyTypeObject Formtype = {
  1327. PyObject_HEAD_INIT(&PyType_Type)
  1328. 0, /*ob_size*/
  1329. "fl.FORMS_form", /*tp_name*/
  1330. sizeof(formobject), /*tp_size*/
  1331. 0, /*tp_itemsize*/
  1332. /* methods */
  1333. (destructor)form_dealloc, /*tp_dealloc*/
  1334. 0, /*tp_print*/
  1335. (getattrfunc)form_getattr, /*tp_getattr*/
  1336. (setattrfunc)form_setattr, /*tp_setattr*/
  1337. 0, /*tp_compare*/
  1338. (reprfunc)form_repr, /*tp_repr*/
  1339. };
  1340. static PyObject *
  1341. newformobject(FL_FORM *form)
  1342. {
  1343. formobject *f;
  1344. f = PyObject_New(formobject, &Formtype);
  1345. if (f == NULL)
  1346. return NULL;
  1347. f->ob_form = form;
  1348. return (PyObject *)f;
  1349. }
  1350. /* The "fl" module */
  1351. static PyObject *
  1352. forms_make_form(PyObject *dummy, PyObject *args)
  1353. {
  1354. int type;
  1355. float w, h;
  1356. FL_FORM *form;
  1357. if (!PyArg_Parse(args, "(iff)", &type, &w, &h))
  1358. return NULL;
  1359. form = fl_bgn_form(type, w, h);
  1360. if (form == NULL) {
  1361. /* XXX Actually, cannot happen! */
  1362. PyErr_NoMemory();
  1363. return NULL;
  1364. }
  1365. fl_end_form();
  1366. return newformobject(form);
  1367. }
  1368. static PyObject *
  1369. forms_activate_all_forms(PyObject *f, PyObject *args)
  1370. {
  1371. fl_activate_all_forms();
  1372. Py_INCREF(Py_None);
  1373. return Py_None;
  1374. }
  1375. static PyObject *
  1376. forms_deactivate_all_forms(PyObject *f, PyObject *args)
  1377. {
  1378. fl_deactivate_all_forms();
  1379. Py_INCREF(Py_None);
  1380. return Py_None;
  1381. }
  1382. static PyObject *my_event_callback = NULL;
  1383. static PyObject *
  1384. forms_set_event_call_back(PyObject *dummy, PyObject *args)
  1385. {
  1386. if (args == Py_None)
  1387. args = NULL;
  1388. my_event_callback = args;
  1389. Py_XINCREF(args);
  1390. Py_INCREF(Py_None);
  1391. return Py_None;
  1392. }
  1393. static PyObject *
  1394. forms_do_or_check_forms(PyObject *dummy, FL_OBJECT *(*func)(void))
  1395. {
  1396. FL_OBJECT *generic;
  1397. genericobject *g;
  1398. PyObject *arg, *res;
  1399. for (;;) {
  1400. Py_BEGIN_ALLOW_THREADS
  1401. generic = (*func)();
  1402. Py_END_ALLOW_THREADS
  1403. if (generic == NULL) {
  1404. Py_INCREF(Py_None);
  1405. return Py_None;
  1406. }
  1407. if (generic == FL_EVENT) {
  1408. int dev;
  1409. short val;
  1410. if (my_event_callback == NULL)
  1411. return PyInt_FromLong(-1L);
  1412. dev = fl_qread(&val);
  1413. arg = Py_BuildValue("(ih)", dev, val);
  1414. if (arg == NULL)
  1415. return NULL;
  1416. res = PyEval_CallObject(my_event_callback, arg);
  1417. Py_XDECREF(res);
  1418. Py_DECREF(arg);
  1419. if (res == NULL)
  1420. return NULL; /* Callback raised exception */
  1421. continue;
  1422. }
  1423. g = findgeneric(generic);
  1424. if (g == NULL) {
  1425. /* Object not known to us (some dialogs cause this) */
  1426. continue; /* Ignore it */
  1427. }
  1428. if (g->ob_callback == NULL) {
  1429. Py_INCREF(g);
  1430. return ((PyObject *) g);
  1431. }
  1432. arg = PyTuple_Pack(2, (PyObject *)g, g->ob_callback_arg);
  1433. if (arg == NULL)
  1434. return NULL;
  1435. res = PyEval_CallObject(g->ob_callback, arg);
  1436. Py_XDECREF(res);
  1437. Py_DECREF(arg);
  1438. if (res == NULL)
  1439. return NULL; /* Callback raised exception */
  1440. }
  1441. }
  1442. static PyObject *
  1443. forms_do_forms(PyObject *dummy)
  1444. {
  1445. return forms_do_or_check_forms(dummy, fl_do_forms);
  1446. }
  1447. static PyObject *
  1448. forms_check_forms(PyObject *dummy)
  1449. {
  1450. return forms_do_or_check_forms(dummy, fl_check_forms);
  1451. }
  1452. static PyObject *
  1453. forms_do_only_forms(PyObject *dummy)
  1454. {
  1455. return forms_do_or_check_forms(dummy, fl_do_only_forms);
  1456. }
  1457. static PyObject *
  1458. forms_check_only_forms(PyObject *dummy)
  1459. {
  1460. return forms_do_or_check_forms(dummy, fl_check_only_forms);
  1461. }
  1462. #ifdef UNUSED
  1463. static PyObject *
  1464. fl_call(void (*func)(void))
  1465. {
  1466. (*func)();
  1467. Py_INCREF(Py_None);
  1468. return Py_None;
  1469. }
  1470. #endif
  1471. static PyObject *
  1472. forms_set_graphics_mode(PyObject *dummy, PyObject *args)
  1473. {
  1474. int rgbmode, doublebuf;
  1475. if (!PyArg_Parse(args, "(ii)", &rgbmode, &doublebuf))
  1476. return NULL;
  1477. fl_set_graphics_mode(rgbmode,doublebuf);
  1478. Py_INCREF(Py_None);
  1479. return Py_None;
  1480. }
  1481. static PyObject *
  1482. forms_get_rgbmode(PyObject *dummy, PyObject *args)
  1483. {
  1484. extern int fl_rgbmode;
  1485. if (args != NULL) {
  1486. PyErr_BadArgument();
  1487. return NULL;
  1488. }
  1489. return PyInt_FromLong((long)fl_rgbmode);
  1490. }
  1491. static PyObject *
  1492. forms_show_errors(PyObject *dummy, PyObject *args)
  1493. {
  1494. int show;
  1495. if (!PyArg_Parse(args, "i", &show))
  1496. return NULL;
  1497. fl_show_errors(show);
  1498. Py_INCREF(Py_None);
  1499. return Py_None;
  1500. }
  1501. static PyObject *
  1502. forms_set_font_name(PyObject *dummy, PyObject *args)
  1503. {
  1504. int numb;
  1505. char *name;
  1506. if (!PyArg_Parse(args, "(is)", &numb, &name))
  1507. return NULL;
  1508. fl_set_font_name(numb, name);
  1509. Py_INCREF(Py_None);
  1510. return Py_None;
  1511. }
  1512. static PyObject *
  1513. forms_qdevice(PyObject *self, PyObject *args)
  1514. {
  1515. short arg1;
  1516. if (!PyArg_Parse(args, "h", &arg1))
  1517. return NULL;
  1518. fl_qdevice(arg1);
  1519. Py_INCREF(Py_None);
  1520. return Py_None;
  1521. }
  1522. static PyObject *
  1523. forms_unqdevice(PyObject *self, PyObject *args)
  1524. {
  1525. short arg1;
  1526. if (!PyArg_Parse(args, "h", &arg1))
  1527. return NULL;
  1528. fl_unqdevice(arg1);
  1529. Py_INCREF(Py_None);
  1530. return Py_None;
  1531. }
  1532. static PyObject *
  1533. forms_isqueued(PyObject *self, PyObject *args)
  1534. {
  1535. long retval;
  1536. short arg1;
  1537. if (!PyArg_Parse(args, "h", &arg1))
  1538. return NULL;
  1539. retval = fl_isqueued(arg1);
  1540. return PyInt_FromLong(retval);
  1541. }
  1542. static PyObject *
  1543. forms_qtest(PyObject *self, PyObject *args)
  1544. {
  1545. long retval;
  1546. retval = fl_qtest();
  1547. return PyInt_FromLong(retval);
  1548. }
  1549. static PyObject *
  1550. forms_qread(PyObject *self, PyObject *args)
  1551. {
  1552. int dev;
  1553. short val;
  1554. Py_BEGIN_ALLOW_THREADS
  1555. dev = fl_qread(&val);
  1556. Py_END_ALLOW_THREADS
  1557. return Py_BuildValue("(ih)", dev, val);
  1558. }
  1559. static PyObject *
  1560. forms_qreset(PyObject *self)
  1561. {
  1562. fl_qreset();
  1563. Py_INCREF(Py_None);
  1564. return Py_None;
  1565. }
  1566. static PyObject *
  1567. forms_qenter(PyObject *self, PyObject *args)
  1568. {
  1569. short arg1, arg2;
  1570. if (!PyArg_Parse(args, "(hh)", &arg1, &arg2))
  1571. return NULL;
  1572. fl_qenter(arg1, arg2);
  1573. Py_INCREF(Py_None);
  1574. return Py_None;
  1575. }
  1576. static PyObject *
  1577. forms_color(PyObject *self, PyObject *args)
  1578. {
  1579. int arg;
  1580. if (!PyArg_Parse(args, "i", &arg)) return NULL;
  1581. fl_color((short) arg);
  1582. Py_INCREF(Py_None);
  1583. return Py_None;
  1584. }
  1585. static PyObject *
  1586. forms_mapcolor(PyObject *self, PyObject *args)
  1587. {
  1588. int arg0, arg1, arg2, arg3;
  1589. if (!PyArg_Parse(args, "(iiii)", &arg0, &arg1, &arg2, &arg3))
  1590. return NULL;
  1591. fl_mapcolor(arg0, (short) arg1, (short) arg2, (short) arg3);
  1592. Py_INCREF(Py_None);
  1593. return Py_None;
  1594. }
  1595. static PyObject *
  1596. forms_getmcolor(PyObject *self, PyObject *args)
  1597. {
  1598. int arg;
  1599. short r, g, b;
  1600. if (!PyArg_Parse(args, "i", &arg)) return NULL;
  1601. fl_getmcolor(arg, &r, &g, &b);
  1602. return Py_BuildValue("(hhh)", r, g, b);
  1603. }
  1604. static PyObject *
  1605. forms_get_mouse(PyObject *self)
  1606. {
  1607. float x, y;
  1608. fl_get_mouse(&x, &y);
  1609. return Py_BuildValue("(ff)", x, y);
  1610. }
  1611. static PyObject *
  1612. forms_tie(PyObject *self, PyObject *args)
  1613. {
  1614. short arg1, arg2, arg3;
  1615. if (!PyArg_Parse(args, "(hhh)", &arg1, &arg2, &arg3))
  1616. return NULL;
  1617. fl_tie(arg1, arg2, arg3);
  1618. Py_INCREF(Py_None);
  1619. return Py_None;
  1620. }
  1621. static PyObject *
  1622. forms_show_message(PyObject *f, PyObject *args)
  1623. {
  1624. char *a, *b, *c;
  1625. if (!PyArg_Parse(args, "(sss)", &a, &b, &c)) return NULL;
  1626. Py_BEGIN_ALLOW_THREADS
  1627. fl_show_message(a, b, c);
  1628. Py_END_ALLOW_THREADS
  1629. Py_INCREF(Py_None);
  1630. return Py_None;
  1631. }
  1632. static PyObject *
  1633. forms_show_choice(PyObject *f, PyObject *args)
  1634. {
  1635. char *m1, *m2, *m3, *b1, *b2, *b3;
  1636. int nb;
  1637. char *format;
  1638. long rv;
  1639. if (args == NULL || !PyTuple_Check(args)) {
  1640. PyErr_BadArgument();
  1641. return NULL;
  1642. }
  1643. nb = PyTuple_Size(args) - 3;
  1644. if (nb <= 0) {
  1645. PyErr_SetString(PyExc_TypeError,
  1646. "need at least one button label");
  1647. return NULL;
  1648. }
  1649. if (PyInt_Check(PyTuple_GetItem(args, 3))) {
  1650. PyErr_SetString(PyExc_TypeError,
  1651. "'number-of-buttons' argument not needed");
  1652. return NULL;
  1653. }
  1654. switch (nb) {
  1655. case 1: format = "(ssss)"; break;
  1656. case 2: format = "(sssss)"; break;
  1657. case 3: format = "(ssssss)"; break;
  1658. default:
  1659. PyErr_SetString(PyExc_TypeError, "too many button labels");
  1660. return NULL;
  1661. }
  1662. if (!PyArg_Parse(args, format, &m1, &m2, &m3, &b1, &b2, &b3))
  1663. return NULL;
  1664. Py_BEGIN_ALLOW_THREADS
  1665. rv = fl_show_choice(m1, m2, m3, nb, b1, b2, b3);
  1666. Py_END_ALLOW_THREADS
  1667. return PyInt_FromLong(rv);
  1668. }
  1669. static PyObject *
  1670. forms_show_question(PyObject *f, PyObject *args)
  1671. {
  1672. int ret;
  1673. char *a, *b, *c;
  1674. if (!PyArg_Parse(args, "(sss)", &a, &b, &c)) return NULL;
  1675. Py_BEGIN_ALLOW_THREADS
  1676. ret = fl_show_question(a, b, c);
  1677. Py_END_ALLOW_THREADS
  1678. return PyInt_FromLong((long) ret);
  1679. }
  1680. static PyObject *
  1681. forms_show_input(PyObject *f, PyObject *args)
  1682. {
  1683. char *str;
  1684. char *a, *b;
  1685. if (!PyArg_Parse(args, "(ss)", &a, &b)) return NULL;
  1686. Py_BEGIN_ALLOW_THREADS
  1687. str = fl_show_input(a, b);
  1688. Py_END_ALLOW_THREADS
  1689. if (str == NULL) {
  1690. Py_INCREF(Py_None);
  1691. return Py_None;
  1692. }
  1693. return PyString_FromString(str);
  1694. }
  1695. static PyObject *
  1696. forms_file_selector(PyObject *f, PyObject *args)
  1697. {
  1698. char *str;
  1699. char *a, *b, *c, *d;
  1700. if (!PyArg_Parse(args, "(ssss)", &a, &b, &c, &d)) return NULL;
  1701. Py_BEGIN_ALLOW_THREADS
  1702. str = fl_show_file_selector(a, b, c, d);
  1703. Py_END_ALLOW_THREADS
  1704. if (str == NULL) {
  1705. Py_INCREF(Py_None);
  1706. return Py_None;
  1707. }
  1708. return PyString_FromString(str);
  1709. }
  1710. static PyObject *
  1711. forms_file_selector_func(PyObject *args, char *(*func)(void))
  1712. {
  1713. char *str;
  1714. str = (*func) ();
  1715. if (str == NULL) {
  1716. Py_INCREF(Py_None);
  1717. return Py_None;
  1718. }
  1719. return PyString_FromString(str);
  1720. }
  1721. static PyObject *
  1722. forms_get_directory(PyObject *f, PyObject *args)
  1723. {
  1724. return forms_file_selector_func(args, fl_get_directory);
  1725. }
  1726. static PyObject *
  1727. forms_get_pattern(PyObject *f, PyObject *args)
  1728. {
  1729. return forms_file_selector_func(args, fl_get_pattern);
  1730. }
  1731. static PyObject *
  1732. forms_get_filename(PyObject *f, PyObject *args)
  1733. {
  1734. return forms_file_selector_func(args, fl_get_filename);
  1735. }
  1736. static PyMethodDef forms_methods[] = {
  1737. /* adm */
  1738. {"make_form", forms_make_form, METH_OLDARGS},
  1739. {"activate_all_forms", forms_activate_all_forms, METH_OLDARGS},
  1740. {"deactivate_all_forms",forms_deactivate_all_forms, METH_OLDARGS},
  1741. /* gl support wrappers */
  1742. {"qdevice", forms_qdevice, METH_OLDARGS},
  1743. {"unqdevice", forms_unqdevice, METH_OLDARGS},
  1744. {"isqueued", forms_isqueued, METH_OLDARGS},
  1745. {"qtest", forms_qtest, METH_OLDARGS},
  1746. {"qread", forms_qread, METH_OLDARGS},
  1747. /* {"blkqread", forms_blkqread, METH_OLDARGS}, */
  1748. {"qreset", forms_qreset, METH_NOARGS},
  1749. {"qenter", forms_qenter, METH_OLDARGS},
  1750. {"get_mouse", forms_get_mouse, METH_NOARGS},
  1751. {"tie", forms_tie, METH_OLDARGS},
  1752. /* {"new_events", forms_new_events, METH_OLDARGS}, */
  1753. {"color", forms_color, METH_OLDARGS},
  1754. {"mapcolor", forms_mapcolor, METH_OLDARGS},
  1755. {"getmcolor", forms_getmcolor, METH_OLDARGS},
  1756. /* interaction */
  1757. {"do_forms", forms_do_forms, METH_NOARGS},
  1758. {"do_only_forms", forms_do_only_forms, METH_NOARGS},
  1759. {"check_forms", forms_check_forms, METH_NOARGS},
  1760. {"check_only_forms", forms_check_only_forms, METH_NOARGS},
  1761. {"set_event_call_back", forms_set_event_call_back, METH_OLDARGS},
  1762. /* goodies */
  1763. {"show_message", forms_show_message, METH_OLDARGS},
  1764. {"show_question", forms_show_question, METH_OLDARGS},
  1765. {"show_choice", forms_show_choice, METH_OLDARGS},
  1766. {"show_input", forms_show_input, METH_OLDARGS},
  1767. {"show_file_selector", forms_file_selector, METH_OLDARGS},
  1768. {"file_selector", forms_file_selector, METH_OLDARGS}, /* BW compat */
  1769. {"get_directory", forms_get_directory, METH_OLDARGS},
  1770. {"get_pattern", forms_get_pattern, METH_OLDARGS},
  1771. {"get_filename", forms_get_filename, METH_OLDARGS},
  1772. {"set_graphics_mode", forms_set_graphics_mode, METH_OLDARGS},
  1773. {"get_rgbmode", forms_get_rgbmode, METH_OLDARGS},
  1774. {"show_errors", forms_show_errors, METH_OLDARGS},
  1775. {"set_font_name", forms_set_font_name, METH_OLDARGS},
  1776. {NULL, NULL} /* sentinel */
  1777. };
  1778. PyMODINIT_FUNC
  1779. initfl(void)
  1780. {
  1781. if (PyErr_WarnPy3k("the fl module has been removed in "
  1782. "Python 3.0", 2) < 0)
  1783. return;
  1784. Py_InitModule("fl", forms_methods);
  1785. if (m == NULL)
  1786. return;
  1787. foreground();
  1788. fl_init();
  1789. }