Mercurial > pidgin
changeset 18679:6b16fca71f8b
Add some more functions for GntTree. One point to note is that the key
for each row in a tree needs to be a GObject, which, really is quite simple
to do in python (examples coming up shortly).
There is a wrapper for gpointer, which I am going to remove shortly.
I also need to fix the install location. The way to go, I think, is to
change the configure script in libgnt/configure.ac. This involves checking
for python and doing things of that sort.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 28 Jul 2007 11:16:05 +0000 |
parents | c5bf7a32968c |
children | fd01bac27b79 |
files | finch/libgnt/pygnt/Makefile.am finch/libgnt/pygnt/Makefile.make finch/libgnt/pygnt/common.h finch/libgnt/pygnt/dbus-gnt finch/libgnt/pygnt/gendef.sh finch/libgnt/pygnt/gntmodule.c finch/libgnt/pygnt/gnttree.override finch/libgnt/pygnt/test.py |
diffstat | 8 files changed, 229 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/finch/libgnt/pygnt/Makefile.am Sat Jul 28 11:16:05 2007 +0000 @@ -0,0 +1,38 @@ +EXTRA_DIST = gendef.sh + +pg_LTLIBRARIES = gnt.la + +pgdir = $(libdir) + +sources = \ + gnt.def \ + gnt.override \ + gntfilesel.override \ + gnttree.override + +gnt_la_SOURCES = gnt.c common.c common.h gntmodule.c + +gnt_la_LDFLAGS = -module -avoid-version \ + `pkg-config --libs pygobject-2.0` + +gnt_la_LIBADD = \ + $(GLIB_LIBS) \ + ../libgnt.la + +AM_CPPFLAGS = \ + -I../ \ + $(GLIB_CFLAGS) \ + $(GNT_CFLAGS) \ + -I/usr/include/python2.4 \ + `pkg-config --cflags pygobject-2.0` + +CLEANFILES = gnt.def gnt.c gnt.defe + +gnt.def: $(srcdir)/../*.h + $(srcdir)/gendef.sh + +gnt.c: $(sources) + pygtk-codegen-2.0 --prefix gnt \ + --override gnt.override \ + gnt.def > $@ +
--- a/finch/libgnt/pygnt/Makefile.make Fri Jul 27 16:13:34 2007 +0000 +++ b/finch/libgnt/pygnt/Makefile.make Sat Jul 28 11:16:05 2007 +0000 @@ -10,5 +10,7 @@ --override gnt.override \ gnt.def > $@ +#python codegen/codegen.py --prefix gnt \ + clean: @rm *.so *.o gnt.c
--- a/finch/libgnt/pygnt/common.h Fri Jul 27 16:13:34 2007 +0000 +++ b/finch/libgnt/pygnt/common.h Sat Jul 28 11:16:05 2007 +0000 @@ -3,3 +3,5 @@ PyObject *create_pyobject_from_string_list(GList *list); +PyObject *create_mygpointer(gpointer data); +
--- a/finch/libgnt/pygnt/dbus-gnt Fri Jul 27 16:13:34 2007 +0000 +++ b/finch/libgnt/pygnt/dbus-gnt Sat Jul 28 11:16:05 2007 +0000 @@ -24,6 +24,7 @@ key = get_dict_key(conv) stuff = convwins[key] stuff[0].destroy() + # if a conv window is closed, then reopened, this thing crashes convwins[key] = None def wrote_msg(account, who, msg, conv, flags): @@ -34,7 +35,8 @@ tv.append_text_with_flags(who + ": ", 1) tv.append_text_with_flags(msg, 0) tv.scroll(0) - stuff[0].set_urgent() + if flags & 3: + stuff[0].set_urgent() bus = dbus.SessionBus() obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") @@ -91,6 +93,7 @@ tv.clear() win.show() convwins[key] = [win, tv, entry] + # XXX: listen to "destroy" for the window, and reset the key return convwins[key] def show_buddylist():
--- a/finch/libgnt/pygnt/gendef.sh Fri Jul 27 16:13:34 2007 +0000 +++ b/finch/libgnt/pygnt/gendef.sh Sat Jul 28 11:16:05 2007 +0000 @@ -28,7 +28,7 @@ gnt.h" # Generate the def file -rm gnt.def +rm -f gnt.def for file in $FILES do python /usr/share/pygtk/2.0/codegen/h2def.py ../$file >> gnt.def
--- a/finch/libgnt/pygnt/gntmodule.c Fri Jul 27 16:13:34 2007 +0000 +++ b/finch/libgnt/pygnt/gntmodule.c Sat Jul 28 11:16:05 2007 +0000 @@ -1,5 +1,62 @@ #include <pygobject.h> +/* {{{ Wrapper for gpointer */ + +typedef struct { + PyObject_HEAD + PyGPointer *data; +} mygpointer; + +static PyObject * +mygpointer_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + mygpointer *self = (mygpointer*)type->tp_alloc(type, 0); + self->data = NULL; + return (PyObject*)self; +} + +static const PyMethodDef mygpointer_methods[] = { + /*{"value", (PyCFunction)get_value, METH_NOARGS, NULL},*/ + {NULL, NULL, 0, NULL} +}; + +static int +mygpointer_init(mygpointer *self, PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {"data", NULL}; + PyObject *data = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, + &data)) + return -1; + + Py_INCREF(data); + Py_DECREF(self->data); + self->data = data; + + return 0; +} + +static PyTypeObject mygpointer_type = { + PyObject_HEAD_INIT(&PyType_Type) + .tp_name = "gpointer", + .tp_basicsize = sizeof(mygpointer), + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_doc = "gpointer stuff", + .tp_members = NULL, + .tp_init = mygpointer_init, + .tp_new = mygpointer_new, + .tp_methods = mygpointer_methods +}; + +PyObject *create_mygpointer(gpointer data) +{ + mygpointer *p = mygpointer_new(&mygpointer_type, NULL, NULL); + p->data = data; + return (PyObject *)p; +} +/* }}} Wrapper for gpointer */ + void gnt_register_classes (PyObject *d); extern PyMethodDef gnt_functions[]; @@ -9,11 +66,15 @@ PyObject *m, *d; init_pygobject (); - + + if (PyType_Ready(&mygpointer_type) < 0) + return; + m = Py_InitModule ("gnt", gnt_functions); d = PyModule_GetDict (m); gnt_register_classes (d); + gnt_add_constants(m, "GNT_"); if (PyErr_Occurred ()) { Py_FatalError ("can't initialise module sad");
--- a/finch/libgnt/pygnt/gnttree.override Fri Jul 27 16:13:34 2007 +0000 +++ b/finch/libgnt/pygnt/gnttree.override Sat Jul 28 11:16:05 2007 +0000 @@ -49,7 +49,7 @@ return NULL; } while (list) { - PyObject *obj = pyg_pointer_new(G_TYPE_POINTER, list->data); + PyObject *obj = list->data; PyList_Append(py_list, obj); Py_DECREF(obj); list = list->next; @@ -63,7 +63,7 @@ { static char *kwlist[] = {"key", "row", "parent", "bigbro", NULL}; PyObject *py_list; - gpointer key, parent, bigbro; + PyGObject *key, *parent, *bigbro; int len, i; GList *list = NULL; GntTreeRow *row; @@ -100,4 +100,65 @@ Py_INCREF(Py_None); return Py_None; } +%% +override gnt_tree_get_selection_data noargs +static PyObject * +_wrap_gnt_tree_get_selection_data(PyGObject *self) +{ + PyObject *ret = gnt_tree_get_selection_data(GNT_TREE(self->obj)); + if (!ret) + ret = Py_None; + Py_INCREF(ret); + return ret; +} +%% +override gnt_tree_change_text +static PyObject * +_wrap_gnt_tree_change_text(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "key", "colno", "text", NULL }; + char *text; + int colno; + gpointer key; + if (!PyArg_ParseTupleAndKeywords(args, kwargs,"Ois:GntTree.change_text", kwlist, &key, &colno, &text)) + return NULL; + + gnt_tree_change_text(GNT_TREE(self->obj), key, colno, text); + + Py_INCREF(Py_None); + return Py_None; +} +%% +override gnt_tree_set_row_flags +static PyObject * +_wrap_gnt_tree_set_row_flags(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "key", "flag", NULL }; + int flag; + gpointer key; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs,"Oi:GntTree.set_row_flags", kwlist, &key, &flag)) + return NULL; + + gnt_tree_set_row_flags(GNT_TREE(self->obj), key, flag); + + Py_INCREF(Py_None); + return Py_None; +} +%% +override gnt_tree_remove +static PyObject * +_wrap_gnt_tree_remove(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "key", NULL }; + gpointer key; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O:GntTree.remove", kwlist, &key)) + return NULL; + + gnt_tree_remove(GNT_TREE(self->obj), key); + + Py_INCREF(Py_None); + return Py_None; +}
--- a/finch/libgnt/pygnt/test.py Fri Jul 27 16:13:34 2007 +0000 +++ b/finch/libgnt/pygnt/test.py Sat Jul 28 11:16:05 2007 +0000 @@ -1,18 +1,59 @@ #!/usr/bin/python +import gobject import gnt +class MyObject(gobject.GObject): + __gproperties__ = { + 'mytype': (gobject.TYPE_INT, 'mytype', 'the type of the object', + 0, 10000, 0, gobject.PARAM_READWRITE), + 'string': (gobject.TYPE_STRING, 'string property', 'the string', + None, gobject.PARAM_READWRITE), + 'gobject': (gobject.TYPE_OBJECT, 'object property', 'the object', + gobject.PARAM_READWRITE), + } + + def __init__(self, type = 'string', value = None): + self.__gobject_init__() + self.set_property(type, value) + + def do_set_property(self, pspec, value): + if pspec.name == 'string': + self.string = value + self.type = gobject.TYPE_STRING + elif pspec.name == 'gobject': + self.gobject = value + self.type = gobject.TYPE_OBJECT + else: + raise AttributeError, 'unknown property %s' % pspec.name + def do_get_property(self, pspec): + if pspec.name == 'string': + return self.string + elif pspec.name == 'gobject': + return self.gobject + elif pspec.name == 'mytype': + return self.type + else: + raise AttributeError, 'unknown property %s' % pspec.name +gobject.type_register(MyObject) + def button_activate(button, tree): - list = tree.get_selection_text_list() - str = "" - for i in list: - str = str + i - entry.set_text("clicked!!!" + str) + list = tree.get_selection_text_list() + ent = tree.get_selection_data() + if ent.type == gobject.TYPE_STRING: + str = "" + for i in list: + str = str + i + entry.set_text("clicked!!!" + str) + elif ent.type == gobject.TYPE_OBJECT: + ent.gobject.set_text("mwhahaha!!!") gnt.gnt_init() win = gnt.Window() entry = gnt.Entry("") +obj = MyObject() +obj.set_property('gobject', entry) win.add_widget(entry) win.set_title("Entry") @@ -27,12 +68,20 @@ # so random non-string values can be used as the key for a row in a GntTree! last = None for i in range(1, 100): - tree.add_row_after(i, [str(i), ""], None, i-1) -tree.add_row_after(entry, ["asd"], None, None) -tree.add_row_after("b", ["123", ""], entry, None) + key = MyObject('string', str(i)) + tree.add_row_after(key, [str(i)], None, last) + last = key + +tree.add_row_after(MyObject('gobject', entry), ["asd"], None, None) +tree.add_row_after(MyObject('string', "b"), ["123"], MyObject('gobject', entry), None) button.connect("activate", button_activate, tree) +tv = gnt.TextView() + +win.add_widget(tv) +tv.append_text_with_flags("What up!!", gnt.TEXT_FLAG_BOLD) + win.show() gnt.gnt_main()