diff options
author | James Henstridge <james@daa.com.au> | 1999-08-03 10:35:13 +0000 |
---|---|---|
committer | James Henstridge <jamesh@src.gnome.org> | 1999-08-03 10:35:13 +0000 |
commit | f19bac550846ef455704840f97711989bc640f62 (patch) | |
tree | 1daf54ce3969724c0e79815cbafd08002c34fa02 | |
parent | f50c95a9ec48b77673437e21fabc9f5ab79861b0 (diff) | |
download | pygtk-f19bac550846ef455704840f97711989bc640f62.tar.gz |
added descriptions of the new routines.
1999-08-03 James Henstridge <james@daa.com.au>
* description.py (GdkWindow): added descriptions of the new routines.
* gtkmodule.c (GdkWindow.property_{get,change,delete}): new functions
for manipulating the properties on a window.
* gtk.py (_window_foreign_new, _root_window): added wrappers for
the new functions.
* gtkmodule.c: added xid attribute to GdkWindow's, and added functions
gdk_window_foreign_new and gdk_get_root_win. The second function is
simply a wrapper that returns a GdkWindow for the root window.
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | description.py | 18 | ||||
-rw-r--r-- | gtk.py | 7 | ||||
-rw-r--r-- | gtkmodule.c | 208 |
4 files changed, 243 insertions, 4 deletions
@@ -1,3 +1,17 @@ +1999-08-03 James Henstridge <james@daa.com.au> + + * description.py (GdkWindow): added descriptions of the new routines. + + * gtkmodule.c (GdkWindow.property_{get,change,delete}): new functions + for manipulating the properties on a window. + + * gtk.py (_window_foreign_new, _root_window): added wrappers for + the new functions. + + * gtkmodule.c: added xid attribute to GdkWindow's, and added functions + gdk_window_foreign_new and gdk_get_root_win. The second function is + simply a wrapper that returns a GdkWindow for the root window. + 1999-08-02 James Henstridge <james@daa.com.au> * libglade.py: new file that wraps the _libglade module. diff --git a/description.py b/description.py index 505c5d56..444f45ef 100644 --- a/description.py +++ b/description.py @@ -286,6 +286,9 @@ class GdkWindow: pointer = (_, _) pointer_state = _ + """The X window ID of the window""" + xid = _ + def new_gc(self, foreground=None, background=None, font=None, tile=None, stipple=None, clip_mask=None, function=None, fill=None, subwindow_mode=None, @@ -301,6 +304,21 @@ class GdkWindow: def set_cursor(self, cursor): """Sets the cursor for this window""" pass + + """The property argument can be an atom, int or string here""" + def property_get(self, property, type=AnyPropertyType, delete=FALSE): + """Gets a property on the window. On success, returns a + tuple like (type, format, data) where type is an atom, + format is 8,16 or 32 and data is the data (a string for + format=8, a tuple of ints otherwise). On failure, None is + returned. The property may optionally be deleted as well.""" + pass + def property_change(self, property, type, format, mode, data): + """Change the value of a property.""" + pass + def property_delete(self, property): + """Delete a property if it exists.""" + pass """Aliases for GdkWindow. GdkPixmap refers to an offscreen pixmap. GdkDrawable refers to either a GdkWindow or a GdkPixmap""" @@ -2662,3 +2662,10 @@ def threads_leave(): def gdk_flush(): _gtk.gdk_flush() + +# these are prefixed with underscores, since they are low level, and +# would break if pygtk was ported to windows. +def _window_foreign_new(xid): + return _gtk.gdk_window_foreign_new(xid) +def _root_window(): + return _gtk.gdk_get_root_win() diff --git a/gtkmodule.c b/gtkmodule.c index 02dbcce7..adaaba5b 100644 --- a/gtkmodule.c +++ b/gtkmodule.c @@ -22,6 +22,11 @@ #include <sysmodule.h> #include <gtk/gtk.h> +#define WITH_XSTUFF +#ifdef WITH_XSTUFF +#include <gdk/gdkx.h> +#endif + #define _INSIDE_PYGTK_ #include "pygtk.h" @@ -1316,9 +1321,176 @@ static PyObject *PyGdkWindow_SetCursor(PyGdkWindow_Object *self, return Py_None; } +static PyObject *PyGdkWindow_PropertyGet(PyGdkWindow_Object *self, + PyObject *args) { + GdkAtom property, type = 0; + gint pdelete = FALSE; + + GdkAtom atype; + gint aformat, alength; + guchar *data; + + if (!PyArg_ParseTuple(args, "i|ii:GdkWindow.property_get", &property, + &type, &pdelete)) { + gchar *propname; + + PyErr_Clear(); + if (!PyArg_ParseTuple(args, "s|ii:GdkWindow.property_get", &propname, + &type, &pdelete)) + return NULL; + property = gdk_atom_intern(propname, FALSE); + } + if (gdk_property_get(self->obj, property, type, 0, 9999, pdelete, + &atype, &aformat, &alength, &data)) { + /* success */ + PyObject *pdata; + gint i; + guint16 *data16; + guint32 *data32; + switch (aformat) { + case 8: + pdata = PyString_FromStringAndSize(data, alength); + break; + case 16: + data16 = (guint16 *)data; + pdata = PyTuple_New(alength); + for (i = 0; i < alength; i++) + PyTuple_SetItem(pdata, i, PyInt_FromLong(data16[i])); + break; + case 32: + data32 = (guint32 *)data; + pdata = PyTuple_New(alength); + for (i = 0; i < alength; i++) + PyTuple_SetItem(pdata, i, PyInt_FromLong(data32[i])); + break; + default: + g_warning("got a property format != 8, 16 or 32"); + g_assert_not_reached(); + } + g_free(data); + return Py_BuildValue("(OiO)", PyGdkAtom_New(atype), aformat, pdata); + } else { + Py_INCREF(Py_None); + return Py_None; + } +} + +static PyObject *PyGdkWindow_PropertyChange(PyGdkWindow_Object *self, + PyObject *args) { + GdkAtom property, type; + gint format; + PyObject *py_mode, *pdata; + GdkPropMode mode; + guchar *data; + gint nelements; + + if (!PyArg_ParseTuple(args, "iiiOO:GdkWindow.property_change", &property, + &type, &format, &py_mode, &pdata)) { + gchar *propname; + + PyErr_Clear(); + if (!PyArg_ParseTuple(args, "siiOO:GdkWindow.property_change", + &propname, &type, &format, &py_mode, &pdata)) + return NULL; + property = gdk_atom_intern(propname, FALSE); + } + if (PyGtkEnum_get_value(GTK_TYPE_GDK_PROP_MODE, py_mode, (gint *)&mode)) + return NULL; + switch (format) { + case 8: + if (!PyString_Check(pdata)) { + PyErr_SetString(PyExc_TypeError, "data not a string and format=8"); + return NULL; + } + data = PyString_AsString(pdata); + nelements = PyString_Size(pdata); + break; + case 16: + { + guint16 *data16; + gint i; + + if (!PySequence_Check(pdata)) { + PyErr_SetString(PyExc_TypeError, "data not a sequence and format=16"); + return NULL; + } + nelements = PySequence_Length(pdata); + data16 = g_new(guint16, nelements); + data = (guchar *)data; + for (i = 0; i < nelements; i++) { + PyObject *item = PyNumber_Int(PySequence_GetItem(pdata, i)); + if (!item) { + g_free(data16); + PyErr_Clear(); + PyErr_SetString(PyExc_TypeError,"data element not an int"); + return NULL; + } + data16[i] = PyInt_AsLong(item); + Py_DECREF(item); + } + } + break; + case 32: + { + guint32 *data32; + gint i; + + if (!PySequence_Check(pdata)) { + PyErr_SetString(PyExc_TypeError, "data not a sequence and format=32"); + return NULL; + } + nelements = PySequence_Length(pdata); + data32 = g_new(guint32, nelements); + data = (guchar *)data; + for (i = 0; i < nelements; i++) { + PyObject *item = PyNumber_Int(PySequence_GetItem(pdata, i)); + if (!item) { + g_free(data32); + PyErr_Clear(); + PyErr_SetString(PyExc_TypeError,"data element not an int"); + return NULL; + } + data32[i] = PyInt_AsLong(item); + Py_DECREF(item); + } + } + break; + default: + PyErr_SetString(PyExc_TypeError, "format must be 8, 16 or 32"); + return NULL; + break; + } + gdk_property_change(self->obj, property, type, format, mode, + data, nelements); + if (format != 8) + g_free(data); + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *PyGdkWindow_PropertyDelete(PyGdkWindow_Object *self, + PyObject *args) { + GdkAtom property; + + if (!PyArg_ParseTuple(args, "i:GdkWindow.property_delete", &property)) { + gchar *propname; + + PyErr_Clear(); + if (!PyArg_ParseTuple(args, "s:GdkWindow.property_delete", &propname)) + return NULL; + property = gdk_atom_intern(propname, FALSE); + } + gdk_property_delete(self->obj, property); + Py_INCREF(Py_None); + return Py_None; +} + static PyMethodDef PyGdkWindow_methods[] = { {"new_gc", (PyCFunction)PyGdkWindow_NewGC, METH_VARARGS|METH_KEYWORDS, NULL}, {"set_cursor", (PyCFunction)PyGdkWindow_SetCursor, METH_VARARGS, NULL}, + {"property_get", (PyCFunction)PyGdkWindow_PropertyGet, METH_VARARGS, NULL}, + {"property_change", (PyCFunction)PyGdkWindow_PropertyChange, METH_VARARGS, NULL}, + {"property_delete", (PyCFunction)PyGdkWindow_PropertyDelete, METH_VARARGS, NULL}, {NULL, 0, 0, NULL} }; @@ -1329,9 +1501,9 @@ PyGdkWindow_GetAttr(PyGdkWindow_Object *self, char *key) { GdkModifierType p_mask; if (!strcmp(key, "__members__")) - return Py_BuildValue("[ssssssssssss]", "children", "colormap", "depth", + return Py_BuildValue("[sssssssssssss]", "children", "colormap", "depth", "height", "parent", "pointer", "pointer_state", - "toplevel", "type", "width", "x", "y"); + "toplevel", "type", "width", "x", "xid", "y"); if (!strcmp(key, "width")) { gdk_window_get_size(win, &x, NULL); return PyInt_FromLong(x); @@ -1358,8 +1530,13 @@ PyGdkWindow_GetAttr(PyGdkWindow_Object *self, char *key) { gdk_window_get_pointer(win, NULL, NULL, &p_mask); return PyInt_FromLong(p_mask); } - if (!strcmp(key, "parent")) - return PyGdkWindow_New(gdk_window_get_parent(win)); + if (!strcmp(key, "parent")) { + GdkWindow *par = gdk_window_get_parent(win); + if (par) + return PyGdkWindow_New(par); + Py_INCREF(Py_None); + return Py_None; + } if (!strcmp(key, "toplevel")) return PyGdkWindow_New(gdk_window_get_toplevel(win)); if (!strcmp(key, "children")) { @@ -1378,6 +1555,10 @@ PyGdkWindow_GetAttr(PyGdkWindow_Object *self, char *key) { gdk_window_get_geometry(win, NULL, NULL, NULL, NULL, &x); return PyInt_FromLong(x); } +#ifdef WITH_XSTUFF + if (!strcmp(key, "xid")) + return PyInt_FromLong(GDK_WINDOW_XWINDOW(win)); +#endif return Py_FindMethod(PyGdkWindow_methods, (PyObject *)self, key); } @@ -5075,6 +5256,21 @@ static PyObject *_wrap_gdk_color_alloc(PyObject *self, PyObject *args) { return PyGdkColor_New(&gdk_color); } +#ifdef WITH_XSTUFF +static PyObject *_wrap_gdk_window_foreign_new(PyObject *self, PyObject *args) { + guint32 winid; + + if (!PyArg_ParseTuple(args, "i:gdk_window_foreign_new", &winid)) + return NULL; + return PyGdkWindow_New(gdk_window_foreign_new(winid)); +} +static PyObject *_wrap_gdk_get_root_win(PyObject *self, PyObject *args) { + if (!PyArg_ParseTuple(args, ":gdk_get_root_win")) + return NULL; + return PyGdkWindow_New(gdk_window_foreign_new(GDK_ROOT_WINDOW())); +} +#endif + static PyObject *_wrap_gtk_label_get(PyObject *self, PyObject *args) { PyObject *label; char *text; @@ -5750,6 +5946,10 @@ static PyMethodDef _gtkmoduleMethods[] = { { "gdk_color_alloc", _wrap_gdk_color_alloc, 1 }, { "gdk_threads_enter", _wrap_gdk_threads_enter, 1 }, { "gdk_threads_leave", _wrap_gdk_threads_leave, 1 }, +#ifdef WITH_XSTUFF + { "gdk_window_foreign_new", _wrap_gdk_window_foreign_new, 1 }, + { "gdk_get_root_win", _wrap_gdk_get_root_win, 1 }, +#endif { NULL, NULL } }; |