diff options
-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 00000000..6fd622d2 --- /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 3107374d..119ee271 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); |