diff options
author | James Henstridge <james@daa.com.au> | 2001-03-27 14:04:32 +0000 |
---|---|---|
committer | James Henstridge <jamesh@src.gnome.org> | 2001-03-27 14:04:32 +0000 |
commit | 5d67cea99789d0c8307ad3640387f741760c7c5e (patch) | |
tree | 9abdc1e09d36c22bd2db3d9b8ff45f6b1852ea51 | |
parent | 52ef209f971c317bf6e55763d1f3737d7a267886 (diff) | |
download | pygobject-5d67cea99789d0c8307ad3640387f741760c7c5e.tar.gz pygobject-5d67cea99789d0c8307ad3640387f741760c7c5e.tar.xz pygobject-5d67cea99789d0c8307ad3640387f741760c7c5e.zip |
simple example program that adds a signal to a class, connects a handler
2001-03-27 James Henstridge <james@daa.com.au>
* examples/gobject/signal.py: simple example program that adds a
signal to a class, connects a handler to an instance of that
class, and finally emits that signal. Messages are printed by
both the signal handler and class method closure.
* gobjectmodule.c (pyg_signal_class_closure_marshal): convert
dashes in signal name to underscores. Why does g_siganl_name use
dashes?
(pyg_signal_class_closure_marshal): fix off by one error when
setting up the python argument tuple. The first element was
getting left uninitialised. Signals introduced in python now
work.
* gtk/gtk.defs (GtkFileSelection.get_filename): return value is
const.
* gtk/gtk.override (_wrap_gtk_list_store_set_value): change name.
(_wrap_gtk_tree_store_insert): change name.
* gtk/gtk.defs (GtkListStore.set_value): change from set_cell to
set_value.
(GtkListStore.set_value): same here.
-rw-r--r-- | examples/signal.py | 20 | ||||
-rw-r--r-- | gobject/gobjectmodule.c | 23 |
2 files changed, 39 insertions, 4 deletions
diff --git a/examples/signal.py b/examples/signal.py new file mode 100644 index 0000000..6fd622d --- /dev/null +++ b/examples/signal.py @@ -0,0 +1,20 @@ +import ltihooks, ExtensionClass +import gobject + +class C(gobject.GObject): + def do_my_signal(self, arg): + print "class closure for `my_signal' called with argument", arg + +gobject.signal_new("my_signal", C, gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, (gobject.TYPE_INT, )) + +def my_signal_handler(object, arg, *extra): + print "handler for `my_signal' called with argument", arg, \ + "and extra args", extra + +inst = C() + +print "instance id 0x%x" % id(inst) + +inst.connect("my_signal", my_signal_handler, 1, 2, 3) +inst.emit("my_signal", 42) diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index 3107374..119ee27 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -665,7 +665,7 @@ pyg_signal_class_closure_marshal(GClosure *closure, GObject *object; PyObject *object_wrapper; GSignalInvocationHint *hint = (GSignalInvocationHint *)invocation_hint; - gchar *method_name; + gchar *method_name, *tmp; PyObject *method; PyObject *params, *ret; guint i; @@ -682,12 +682,19 @@ pyg_signal_class_closure_marshal(GClosure *closure, /* construct method name for this class closure */ method_name = g_strconcat("do_", g_signal_name(hint->signal_id), NULL); + + /* convert dashes to underscores. For some reason, g_signal_name + * seems to convert all the underscores in the signal name to + dashes??? */ + for (tmp = method_name; *tmp != '\0'; tmp++) + if (*tmp == '-') *tmp = '_'; + method = PyObject_GetAttrString(object_wrapper, method_name); g_free(method_name); + if (!method) { PyErr_Clear(); Py_DECREF(object_wrapper); - g_message("no class closure to call"); return; } Py_DECREF(object_wrapper); @@ -703,7 +710,7 @@ pyg_signal_class_closure_marshal(GClosure *closure, /* XXXX - clean up if threading was used */ return; } - PyTuple_SetItem(params, i, item); + PyTuple_SetItem(params, i - 1, item); } ret = PyObject_CallObject(method, params); @@ -1504,7 +1511,7 @@ pyg_signal_new(PyObject *self, PyObject *args) &py_type, &signal_flags, &return_type, &py_param_types)) return NULL; - if (pygobject_check(py_type, &PyGObject_Type)) { + if (ExtensionClassSubclass_Check(py_type, &PyGObject_Type)) { PyObject *gtype = PyObject_GetAttrString(py_type, "__gtype__"); if (!gtype) { @@ -1614,6 +1621,14 @@ initgobject(void) PyCObject_FromVoidPtr(&functions, NULL)); /* some constants */ + PyModule_AddIntConstant(m, "SIGNAL_RUN_FIRST", G_SIGNAL_RUN_FIRST); + PyModule_AddIntConstant(m, "SIGNAL_RUN_LAST", G_SIGNAL_RUN_LAST); + PyModule_AddIntConstant(m, "SIGNAL_RUN_CLEANUP", G_SIGNAL_RUN_CLEANUP); + PyModule_AddIntConstant(m, "SIGNAL_NO_RECURSE", G_SIGNAL_NO_RECURSE); + PyModule_AddIntConstant(m, "SIGNAL_DETAILED", G_SIGNAL_DETAILED); + PyModule_AddIntConstant(m, "SIGNAL_ACTION", G_SIGNAL_ACTION); + PyModule_AddIntConstant(m, "SIGNAL_NO_HOOKS", G_SIGNAL_NO_HOOKS); + PyModule_AddIntConstant(m, "TYPE_INVALID", G_TYPE_INVALID); PyModule_AddIntConstant(m, "TYPE_NONE", G_TYPE_NONE); PyModule_AddIntConstant(m, "TYPE_INTERFACE", G_TYPE_INTERFACE); |