Thread: [Python-gtkextra-commits] CVS: python-gtkextra2/gtkextra gtkextra-types.defs,1.4,1.5 gtkextra.defs,1
Status: Beta
Brought to you by:
treeves
From: <pyt...@li...> - 2002-12-31 18:04:23
|
Update of /cvsroot/python-gtkextra/python-gtkextra2/gtkextra In directory sc8-pr-cvs1:/tmp/cvs-serv27404/gtkextra Modified Files: gtkextra-types.defs gtkextra.defs gtkextra.override Log Message: more Index: gtkextra-types.defs =================================================================== RCS file: /cvsroot/python-gtkextra/python-gtkextra2/gtkextra/gtkextra-types.defs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** gtkextra-types.defs 24 Dec 2002 18:49:10 -0000 1.4 --- gtkextra-types.defs 31 Dec 2002 18:04:19 -0000 1.5 *************** *** 88,92 **** ) - ;; Missed by h2def.py (define-object PlotCanvas (in-module "Gtk") --- 88,91 ---- *************** *** 249,253 **** ; Also gtkextra code needs all of those boxed fixed up with types and macros. ! (define-boxed GtkPlotLine (in-module "Gtk") (c-name "GtkPlotLine") --- 248,252 ---- ; Also gtkextra code needs all of those boxed fixed up with types and macros. ! (define-boxed PlotLine (in-module "Gtk") (c-name "GtkPlotLine") *************** *** 258,261 **** --- 257,266 ---- '("GdkJoinStyle" "join_style") ) + ) + + (define-boxed PlotMarker + (in-module "Gtk") + (c-name "GtkPlotMarker") + (gtype-id "GTK_TYPE_PLOT_MARKER") ) Index: gtkextra.defs =================================================================== RCS file: /cvsroot/python-gtkextra/python-gtkextra2/gtkextra/gtkextra.defs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** gtkextra.defs 24 Dec 2002 18:49:10 -0000 1.6 --- gtkextra.defs 31 Dec 2002 18:04:19 -0000 1.7 *************** *** 4266,4270 **** (parameters '("GdkPixmap*" "pixmap") ! '("GdkBitmap*" "mask") ) ) --- 4266,4270 ---- (parameters '("GdkPixmap*" "pixmap") ! '("GdkBitmap*" "mask" (default "NULL") (null-ok)) ) ) Index: gtkextra.override =================================================================== RCS file: /cvsroot/python-gtkextra/python-gtkextra2/gtkextra/gtkextra.override,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** gtkextra.override 30 Dec 2002 20:42:13 -0000 1.7 --- gtkextra.override 31 Dec 2002 18:04:19 -0000 1.8 *************** *** 31,34 **** --- 31,35 ---- static PyObject *pygtkextra_data_from_pyobject_callback = NULL; + static const gchar *function_key = "pygtkextra::function"; /* *************** *** 93,96 **** --- 94,132 ---- } + #define GTK_TYPE_PLOT_MARKER (gtk_plot_marker_get_type ()) + GtkPlotMarker* + gtk_plot_marker_copy (const GtkPlotMarker *marker) + { + /* FIXME: am I correct? */ + GtkPlotMarker *copy; + g_return_val_if_fail (marker != NULL, NULL); + copy = g_new (GtkPlotMarker, 1); + *copy = *marker; + if (marker->data) + g_object_ref (G_OBJECT (marker->data)); + return copy; + } + + void + gtk_plot_marker_free (GtkPlotMarker *marker) + { + /* FIXME: am I correct? */ + g_return_if_fail (marker != NULL); + if (marker->data) + g_object_unref (G_OBJECT (marker->data)); + g_free (marker); + } + + static GType + gtk_plot_marker_get_type (void) + { + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static ("GtkPlotMarker", + (GBoxedCopyFunc) gtk_plot_marker_copy, + (GBoxedFreeFunc) gtk_plot_marker_free); + return our_type; + } + #define GTK_TYPE_PLOT_TEXT (gtk_plot_text_get_type ()) static GType *************** *** 261,264 **** --- 297,395 ---- } + static gdouble + pygtkextra_plot_function (GtkPlot *plot, + GtkPlotData *data, + gdouble x, + gboolean *error) + { + PyObject *py_function = NULL, *py_result = NULL, *py_data = NULL; + gdouble y = 0.0; + + py_data = pygobject_new((GObject*) data); + py_function = pygtkextra_get_data((PyGObject*) py_data, function_key); + + *error = TRUE; + + if (py_function == Py_None) { + PyErr_SetString(PyExc_TypeError, + "could not retrieve the python plot function"); + } + else { + py_result = PyEval_CallFunction(py_function, "(d)", x); + if (py_result) { + PyObject *py_value; + if (PyFloat_Check(py_result)) { + y = PyFloat_AS_DOUBLE(py_result); + *error = FALSE; + } else if (PyNumber_Check(py_result) && (py_value = PyNumber_Float(py_result))) { + y = PyFloat_AS_DOUBLE(py_value); + Py_DECREF(py_value); + *error = FALSE; + } else if (py_result != Py_None) { + PyErr_SetString(PyExc_TypeError, + "plot function must return number or None"); + } + } + } + + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + } + + Py_XDECREF(py_function); + Py_XDECREF(py_result); + Py_XDECREF(py_data); + return y; + } + + static gdouble + pygtkextra_plot_function_3D (GtkPlot *plot, + GtkPlotData *data, + gdouble x, gdouble y, + gboolean *error) + { + PyObject *py_function = NULL, *py_result = NULL, *py_data = NULL; + gdouble z = 0.0; + + py_data = pygobject_new((GObject*) data); + py_function = pygtkextra_get_data((PyGObject*) py_data, function_key); + + *error = TRUE; + + if (py_function == Py_None) { + PyErr_SetString(PyExc_TypeError, + "could not retrieve the python plot function"); + } + else { + py_result = PyEval_CallFunction(py_function, "(dd)", x, y); + if (py_result) { + PyObject *py_value; + if (PyFloat_Check(py_result)) { + z = PyFloat_AS_DOUBLE(py_result); + *error = FALSE; + } else if (PyNumber_Check(py_result) && (py_value = PyNumber_Float(py_result))) { + z = PyFloat_AS_DOUBLE(py_value); + Py_DECREF(py_value); + *error = FALSE; + } else if (py_result != Py_None) { + PyErr_SetString(PyExc_TypeError, + "plot function must return number or None"); + } + } + } + + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + } + + Py_XDECREF(py_function); + Py_XDECREF(py_result); + Py_XDECREF(py_data); + + return z; + } + /* ---------------------------------------------------------------------- */ %% *************** *** 387,390 **** --- 518,522 ---- goto do_err; \ Py_DECREF(py_ ## _x ##_out); \ + gtk_plot_data_set_ ## _x (GTK_PLOT_DATA(self->obj), NULL); \ gtk_plot_data_set_ ## _x (GTK_PLOT_DATA(self->obj), _x); \ *************** *** 547,550 **** --- 679,716 ---- } %% + %% + override gtk_plot_new kwargs + static int + _wrap_gtk_plot_new(PyGObject *self, PyObject *args, PyObject *kwargs) + { + static char *kwlist1[] = { "drawable", NULL }; + static char *kwlist2[] = { "width", "height", "drawable", NULL }; + PyGObject *drawable = NULL; + + if (PyArg_ParseTupleAndKeywords(args, kwargs, "|O!:GtkPlot.__init__", + kwlist1, &PyGdkDrawable_Type, &drawable)) { + self->obj = (GObject *)gtk_plot_new(drawable ? GDK_DRAWABLE(drawable->obj) : NULL); + } + else { + double width, height; + PyErr_Clear(); + /* It would have been nice if optional arguments were last in prototype. */ + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "dd|O!:GtkPlot.__init__", + kwlist2, + &width, &height, + &PyGdkDrawable_Type, &drawable)) + return -1; + self->obj = (GObject *)gtk_plot_new_with_size(drawable ? GDK_DRAWABLE(drawable->obj) : NULL, + width, height); + } + + if (!self->obj) { + PyErr_SetString(PyExc_RuntimeError, "could not create GtkPlot object"); + return -1; + } + pygobject_register_wrapper((PyObject *)self); + return 0; + } + %% override gtk_plot_get_internal_allocation noargs static PyObject * *************** *** 567,571 **** return NULL; gtk_plot_add_data(GTK_PLOT(self->obj), GTK_PLOT_DATA(data->obj)); ! g_snprintf(key, sizeof(key), "data_%p", data); pygtkextra_set_data(self, key, (PyObject*) data); Py_INCREF(Py_None); --- 733,737 ---- return NULL; gtk_plot_add_data(GTK_PLOT(self->obj), GTK_PLOT_DATA(data->obj)); ! g_snprintf(key, sizeof(key), "data_%p", data->obj); pygtkextra_set_data(self, key, (PyObject*) data); Py_INCREF(Py_None); *************** *** 585,593 **** return NULL; ret = gtk_plot_remove_data(GTK_PLOT(self->obj), GTK_PLOT_DATA(data->obj)); ! g_snprintf(key, sizeof(key), "data_%p", data); pygtkextra_set_data(self, key, Py_None); /* not perfect, but harmless */ return PyInt_FromLong(ret); } %% override gtk_plot_get_pixel static PyObject * --- 751,781 ---- return NULL; ret = gtk_plot_remove_data(GTK_PLOT(self->obj), GTK_PLOT_DATA(data->obj)); ! g_snprintf(key, sizeof(key), "data_%p", data->obj); pygtkextra_set_data(self, key, Py_None); /* not perfect, but harmless */ return PyInt_FromLong(ret); } %% + override gtk_plot_add_function kwargs + static PyObject * + _wrap_gtk_plot_add_function(PyGObject *self, PyObject *args, PyObject *kwargs) + { + static char *kwlist[] = { "function", NULL }; + PyObject *function; + PyObject *data; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GtkPlot.add_function", kwlist, &function)) + return NULL; + + if (!PyCallable_Check(function)) { + PyErr_SetString(PyExc_RuntimeError, "function argument must be callable"); + return NULL; + } + + data = pygobject_new( (GObject*) gtk_plot_add_function(GTK_PLOT(self->obj), pygtkextra_plot_function)); + pygtkextra_set_data( (PyGObject*) data, function_key, function); + + return data; + } + %% override gtk_plot_get_pixel static PyObject * *************** *** 692,696 **** } %% ! override gtk_plot3d_new static int _wrap_gtk_plot3d_new(PyGObject *self, PyObject *args, PyObject *kwargs) --- 880,884 ---- } %% ! override gtk_plot3d_new kwargs static int _wrap_gtk_plot3d_new(PyGObject *self, PyObject *args, PyObject *kwargs) *************** *** 702,706 **** if (PyArg_ParseTupleAndKeywords(args, kwargs, "|O!:GtkPlot3D.__init__", kwlist1, &PyGdkDrawable_Type, &drawable)) { ! self->obj = (GObject *)gtk_plot3d_new(GDK_DRAWABLE(drawable->obj)); } else { --- 890,894 ---- if (PyArg_ParseTupleAndKeywords(args, kwargs, "|O!:GtkPlot3D.__init__", kwlist1, &PyGdkDrawable_Type, &drawable)) { ! self->obj = (GObject *)gtk_plot3d_new(drawable ? GDK_DRAWABLE(drawable->obj) : NULL); } else { *************** *** 713,722 **** &PyGdkDrawable_Type, &drawable)) return -1; ! if (drawable) ! self->obj = (GObject *)gtk_plot3d_new_with_size(GDK_DRAWABLE(drawable->obj), ! width, height); ! else ! self->obj = (GObject *)gtk_plot3d_new_with_size(NULL, ! width, height); } --- 901,906 ---- &PyGdkDrawable_Type, &drawable)) return -1; ! self->obj = (GObject *)gtk_plot3d_new_with_size(drawable ? GDK_DRAWABLE(drawable->obj) : NULL, ! width, height); } *************** *** 729,735 **** } %% ignore plot3d_construct plot3d_construct_with_size %% ! ignore-glob *_get_type --- 913,970 ---- } %% + override gtk_plot3d_major_grids_visible noargs + static PyObject * + _wrap_gtk_plot3d_major_grids_visible(PyGObject *self) + { + gboolean x, y, z; + gtk_plot3d_major_grids_visible(GTK_PLOT3D(self->obj), &x, &y, &z); + return Py_BuildValue("(iiii)", (int) x, (int) x, (int) x, (int) x); + } + %% + override gtk_plot3d_minor_grids_visible noargs + static PyObject * + _wrap_gtk_plot3d_minor_grids_visible(PyGObject *self) + { + gboolean x, y, z; + gtk_plot3d_minor_grids_visible(GTK_PLOT3D(self->obj), &x, &y, &z); + return Py_BuildValue("(iiii)", (int) x, (int) x, (int) x, (int) x); + } + %% + %% ignore plot3d_construct plot3d_construct_with_size + %% ! override gtk_plot_surface_new kwargs ! static int ! _wrap_gtk_plot_surface_new(PyGObject *self, PyObject *args, PyObject *kwargs) ! { ! static char *kwlist[] = { "function", NULL }; ! PyObject *function = NULL; ! ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O:GtkPlotSurface.__init__", kwlist, &function)) ! return -1; ! ! if (!function) ! self->obj = (GObject *)gtk_plot_surface_new(); ! else { ! if (!PyCallable_Check(function)) { ! PyErr_SetString(PyExc_RuntimeError, "function argument must be callable"); ! return -1; ! } ! self->obj = (GObject *)gtk_plot_surface_new_function(pygtkextra_plot_function_3D); ! if(self->obj) ! pygtkextra_set_data(self, function_key, function); ! } ! if (!self->obj) { ! PyErr_SetString(PyExc_RuntimeError, "could not create GtkPlotSurface object"); ! return -1; ! } ! pygobject_register_wrapper((PyObject *)self); ! return 0; ! } ! %% ! ignore-glob ! *_get_type ! *_construct |