[Python-gtkextra-commits] CVS: python-gtkextra2/gtkextra gtkextra.defs,1.8,1.9 gtkextra.override,1.1
Status: Beta
Brought to you by:
treeves
From: <pyt...@li...> - 2003-01-14 15:33:27
|
Update of /cvsroot/python-gtkextra/python-gtkextra2/gtkextra In directory sc8-pr-cvs1:/tmp/cvs-serv5904/gtkextra Modified Files: gtkextra.defs gtkextra.override gtkextramodule.c Log Message: support GtkPlotData functions and iterators Index: gtkextra.defs =================================================================== RCS file: /cvsroot/python-gtkextra/python-gtkextra2/gtkextra/gtkextra.defs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** gtkextra.defs 2 Jan 2003 22:00:55 -0000 1.8 --- gtkextra.defs 14 Jan 2003 15:32:09 -0000 1.9 *************** *** 2415,2419 **** '("gfloat" "line_width") '("const-GdkColor*" "color") ! '("const-GdkColor*" "border_color" (default "NULL") (null-ok)) ) ) --- 2415,2419 ---- '("gfloat" "line_width") '("const-GdkColor*" "color") ! '("const-GdkColor*" "border_color") ) ) Index: gtkextra.override =================================================================== RCS file: /cvsroot/python-gtkextra/python-gtkextra2/gtkextra/gtkextra.override,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** gtkextra.override 10 Jan 2003 20:34:08 -0000 1.11 --- gtkextra.override 14 Jan 2003 15:32:24 -0000 1.12 *************** *** 32,35 **** --- 32,36 ---- static PyObject *pygtkextra_data_from_pyobject_callback = NULL; static const gchar *function_key = "pygtkextra::function"; + static const gchar *iterator_key = "pygtkextra::iterator"; /* *************** *** 405,408 **** --- 406,514 ---- } + static gint + pygtkextra_get_double(PyObject *py_obj, gdouble *pd) + { + PyObject *py_value; + + if (PyFloat_Check(py_obj)) { + *pd = PyFloat_AS_DOUBLE(py_obj); + return 0; + } else if (PyNumber_Check(py_obj) && (py_value = PyNumber_Float(py_obj))) { + *pd = PyFloat_AS_DOUBLE(py_value); + Py_DECREF(py_value); + return 0; + } + return -1; + } + + static void + pygtkextra_plot_iterator (GtkPlot *plot, + GtkPlotData *data, + gint iter, + gdouble *x, + gdouble *y, + gdouble *z, + gdouble *a, + gdouble *dx, + gdouble *dy, + gdouble *dz, + gdouble *da, + gchar **label, + gboolean *error) + { + PyObject *py_iterator = NULL, *py_result = NULL, *py_data = NULL, *py_plot = NULL; + + py_data = pygobject_new((GObject*) data); + py_plot = pygobject_new((GObject*) plot); + py_iterator = pygtkextra_get_data((PyGObject*) py_data, iterator_key); + + *error = FALSE; + + if (py_iterator == Py_None) { + PyErr_SetString(PyExc_TypeError, "could not retrieve the python plot iterator"); + goto cleanup; + } + py_result = PyEval_CallFunction(py_iterator, "(OOi)", py_plot, py_data, iter); + if (py_result) { + int i, mask_bit_cnt=0; + + if (!PyTuple_Check(py_result)) { + PyErr_SetString(PyExc_TypeError, "plot iterator must return a tuple"); + goto cleanup; + } + + for (i = 0; i < 9 ; i++) + if (data->iterator_mask & (0x1 << i)) + mask_bit_cnt ++; + + if ( PyTuple_GET_SIZE(py_result) != mask_bit_cnt ) { + PyErr_SetString(PyExc_TypeError, "iterator_mask and iterator fuction's results are mismatched"); + goto cleanup; + } + + i = 0; + + #define _DO_ONE(_x, _X) \ + if ( data->iterator_mask & GTK_PLOT_DATA_ ## _X) { \ + if ( pygtkextra_get_double(PyTuple_GET_ITEM(py_result, i++), _x)) { \ + PyErr_SetString(PyExc_TypeError, #_x " must be a number"); \ + goto cleanup; \ + } \ + } + + _DO_ONE(x, X); + _DO_ONE(y, Y); + _DO_ONE(z, Z); + _DO_ONE(a, A); + _DO_ONE(dx, DX); + _DO_ONE(dy, DY); + _DO_ONE(dz, DZ); + _DO_ONE(da, DA); + + #undef _DO_ONE + + if ( data->iterator_mask & GTK_PLOT_DATA_LABELS) { + PyObject *py_value = PyTuple_GET_ITEM(py_result, i); + if ( !PyString_Check(py_value) ) { + PyErr_SetString(PyExc_TypeError, "label must be a string"); + goto cleanup; + } + *label = PyString_AS_STRING(py_value); /* FIXME: Is this safe here? */ + } + } + + cleanup: + if (PyErr_Occurred()) { + *error = TRUE; + PyErr_Print(); + PyErr_Clear(); + } + + Py_XDECREF(py_iterator); + Py_XDECREF(py_result); + Py_XDECREF(py_data); + Py_XDECREF(py_plot); + } + /* ---------------------------------------------------------------------- */ %% *************** *** 456,459 **** --- 562,612 ---- } %% + override gtk_plot_data_new kwargs + static int + _wrap_gtk_plot_data_new(PyGObject *self, PyObject *args, PyObject *kwargs) + { + static char *kwlist1[] = { NULL }; + static char *kwlist2[] = { "function", NULL }; + static char *kwlist3[] = { "iterator", "npoints", "iterator_mask", NULL }; + PyObject *function, *iterator; + gint npoints, iterator_mask; + + if (PyArg_ParseTupleAndKeywords(args, kwargs, ":GtkPlotData.__init__", kwlist1)) { + self->obj = (GObject *)gtk_plot_data_new(); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwargs, "O:GtkPlotData.__init__", + kwlist2, &function)) { + if (!PyCallable_Check(function)) { + PyErr_SetString(PyExc_RuntimeError, "function argument must be callable"); + return -1; + } + self->obj = (GObject *)gtk_plot_data_new_function(pygtkextra_plot_function); + if(self->obj) + pygtkextra_set_data(self, function_key, function); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwargs, "Oii:GtkPlotData.__init__", + kwlist3, &iterator, &npoints, &iterator_mask)) { + if (!PyCallable_Check(iterator)) { + PyErr_SetString(PyExc_RuntimeError, "iterator argument must be callable"); + return -1; + } + + self->obj = (GObject *)gtk_plot_data_new_iterator(pygtkextra_plot_iterator, npoints, iterator_mask); + if(self->obj) + pygtkextra_set_data(self, iterator_key, iterator); + } + else + return -1; + + if (!self->obj) { + PyErr_SetString(PyExc_RuntimeError, "could not create GtkPlotData object"); + return -1; + } + pygobject_register_wrapper((PyObject *)self); + return 0; + } + %% override gtk_plot_data_set_points kwargs static PyObject * *************** *** 687,690 **** --- 840,845 ---- %% ignore + gtk_plot_data_construct_function + gtk_plot_data_construct_iterator gtk_plot_data_get_points gtk_plot_data_get_x Index: gtkextramodule.c =================================================================== RCS file: /cvsroot/python-gtkextra/python-gtkextra2/gtkextra/gtkextramodule.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** gtkextramodule.c 9 Jan 2003 13:10:50 -0000 1.7 --- gtkextramodule.c 14 Jan 2003 15:32:34 -0000 1.8 *************** *** 29,47 **** pygtkextra_add_constants(m, "GTK_"); /* These were #defines's */ ! PyModule_AddIntConstant(m, "PLOT_LETTER_W", GTK_PLOT_LETTER_W); ! PyModule_AddIntConstant(m, "PLOT_LETTER_H", GTK_PLOT_LETTER_H); ! PyModule_AddIntConstant(m, "PLOT_LEGAL_W", GTK_PLOT_LEGAL_W); ! PyModule_AddIntConstant(m, "PLOT_LEGAL_H", GTK_PLOT_LEGAL_H); ! PyModule_AddIntConstant(m, "PLOT_A4_W", GTK_PLOT_A4_W); ! PyModule_AddIntConstant(m, "PLOT_A4_H", GTK_PLOT_A4_H); ! PyModule_AddIntConstant(m, "PLOT_EXECUTIVE_W", GTK_PLOT_EXECUTIVE_W); ! PyModule_AddIntConstant(m, "PLOT_EXECUTIVE_H", GTK_PLOT_EXECUTIVE_H); ! PyModule_AddIntConstant(m, "PLOT_CANVAS_DND_FLAGS", GTK_PLOT_CANVAS_DND_FLAGS); /* These were anonymous enum's. They really should be fixed in gtkextra. */ ! PyModule_AddIntConstant(m, "ICON_LIST_ICON", GTK_ICON_LIST_ICON); ! PyModule_AddIntConstant(m, "ICON_LIST_TEXT_RIGHT", GTK_ICON_LIST_TEXT_RIGHT); ! PyModule_AddIntConstant(m, "ICON_LIST_TEXT_BELOW", GTK_ICON_LIST_TEXT_BELOW); if (PyErr_Occurred()) --- 29,62 ---- pygtkextra_add_constants(m, "GTK_"); + #define _ADD_CONST( _x ) \ + PyModule_AddIntConstant(m, #_x, GTK_ ## _x); + /* These were #defines's */ ! _ADD_CONST(PLOT_LETTER_W); ! _ADD_CONST(PLOT_LETTER_H); ! _ADD_CONST(PLOT_LEGAL_W); ! _ADD_CONST(PLOT_LEGAL_H); ! _ADD_CONST(PLOT_A4_W); ! _ADD_CONST(PLOT_A4_H); ! _ADD_CONST(PLOT_EXECUTIVE_W); ! _ADD_CONST(PLOT_EXECUTIVE_H); ! _ADD_CONST(PLOT_CANVAS_DND_FLAGS); /* These were anonymous enum's. They really should be fixed in gtkextra. */ ! _ADD_CONST(ICON_LIST_ICON); ! _ADD_CONST(ICON_LIST_TEXT_RIGHT); ! _ADD_CONST(ICON_LIST_TEXT_BELOW); ! ! _ADD_CONST(PLOT_DATA_X); ! _ADD_CONST(PLOT_DATA_Y); ! _ADD_CONST(PLOT_DATA_Z); ! _ADD_CONST(PLOT_DATA_A); ! _ADD_CONST(PLOT_DATA_DX); ! _ADD_CONST(PLOT_DATA_DY); ! _ADD_CONST(PLOT_DATA_DZ); ! _ADD_CONST(PLOT_DATA_DA); ! _ADD_CONST(PLOT_DATA_LABELS); ! ! #undef _ADD_CONST if (PyErr_Occurred()) |