summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Henstridge <james@daa.com.au>2001-03-27 14:04:33 +0000
committerJames Henstridge <jamesh@src.gnome.org>2001-03-27 14:04:33 +0000
commit58dd3fade17ae683237464daf5e4ec8c7d723477 (patch)
tree7a4ca5567e16c40f02c7ea9699d76d94810961e8
parentb8d87b6e13422ec6bcf1df17e9cd4fdcc6e4bb5f (diff)
downloadpygtk-58dd3fade17ae683237464daf5e4ec8c7d723477.tar.gz
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--ChangeLog23
-rw-r--r--Makefile.am1
-rw-r--r--examples/gobject/signal.py20
-rw-r--r--gobject/gobjectmodule.c23
-rw-r--r--gobjectmodule.c23
-rw-r--r--gtk/gtk.defs10
-rw-r--r--gtk/gtk.override24
7 files changed, 101 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index b1e07f3b..9f0cc0f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,28 @@
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.
+
* gobjectmodule.c (pyg_signal_class_closure_get): new function to
get the closure used as the `class closure' for signals. We only
need one, as we can get all the information we need from the
diff --git a/Makefile.am b/Makefile.am
index 88142486..f7ac8bef 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,6 +24,7 @@ EXTRA_DIST = \
pygtk.spec \
MAPPING \
ExtensionClass.stx \
+ examples/gobject/signal.py \
examples/imlib/view.py \
examples/ide/gtkcons.py \
examples/ide/gtkdb.py \
diff --git a/examples/gobject/signal.py b/examples/gobject/signal.py
new file mode 100644
index 00000000..6fd622d2
--- /dev/null
+++ b/examples/gobject/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);
diff --git a/gobjectmodule.c b/gobjectmodule.c
index 3107374d..119ee271 100644
--- a/gobjectmodule.c
+++ b/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);
diff --git a/gtk/gtk.defs b/gtk/gtk.defs
index ce9f63f7..bae40b90 100644
--- a/gtk/gtk.defs
+++ b/gtk/gtk.defs
@@ -4743,7 +4743,7 @@
(method get_filename
(of-object FileSelection (Gtk))
(c-name gtk_file_selection_get_filename)
- (return-type gchar*)
+ (return-type const-gchar*)
)
(method complete
@@ -6163,9 +6163,9 @@
(parameter (type-and-name GType type))
)
-(method set_cell
+(method set_value
(of-object ListStore (Gtk))
- (c-name gtk_list_store_set_cell)
+ (c-name gtk_list_store_set_value)
(return-type none)
(parameter (type-and-name GtkTreeIter* iter))
(parameter (type-and-name gint column))
@@ -11762,9 +11762,9 @@
(parameter (type-and-name GType type))
)
-(method set_cell
+(method set_value
(of-object TreeStore (Gtk))
- (c-name gtk_tree_store_set_cell)
+ (c-name gtk_tree_store_set_value)
(return-type none)
(parameter (type-and-name GtkTreeIter* iter))
(parameter (type-and-name gint column))
diff --git a/gtk/gtk.override b/gtk/gtk.override
index 30583a84..371baa23 100644
--- a/gtk/gtk.override
+++ b/gtk/gtk.override
@@ -1674,16 +1674,18 @@ _wrap_gtk_list_store_new(PyGObject *self, PyObject *args)
return Py_None;
}
%%
-override gtk_list_store_set_cell kwargs
+override gtk_list_store_set_value kwargs
static PyObject *
-_wrap_gtk_list_store_set_cell(PyGObject *self, PyObject *args, PyObject*kwargs)
+_wrap_gtk_list_store_set_value(PyGObject *self, PyObject *args,
+ PyObject *kwargs)
{
static char *kwlist[] = { "iter", "column", "value", NULL };
PyObject *iter, *pyvalue;
gint column;
GValue value = { 0 };
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!iO:GtkListStore.set_cell",
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O!iO:GtkListStore.set_value",
kwlist, &PyGtkTreeIter_Type, &iter,
&column, &pyvalue))
return NULL;
@@ -1698,8 +1700,8 @@ _wrap_gtk_list_store_set_cell(PyGObject *self, PyObject *args, PyObject*kwargs)
"value is of the wrong type for this column");
return NULL;
}
- gtk_list_store_set_cell(GTK_LIST_STORE(self->obj), PyGtkTreeIter_Get(iter),
- column, &value);
+ gtk_list_store_set_value(GTK_LIST_STORE(self->obj),
+ PyGtkTreeIter_Get(iter), column, &value);
g_value_unset(&value);
Py_INCREF(Py_None);
return Py_None;
@@ -1821,16 +1823,18 @@ _wrap_gtk_tree_store_new(PyGObject *self, PyObject *args)
return Py_None;
}
%%
-override gtk_tree_store_set_cell kwargs
+override gtk_tree_store_set_value kwargs
static PyObject *
-_wrap_gtk_tree_store_set_cell(PyGObject *self, PyObject *args, PyObject*kwargs)
+_wrap_gtk_tree_store_set_value(PyGObject *self, PyObject *args,
+ PyObject *kwargs)
{
static char *kwlist[] = { "iter", "column", "value", NULL };
PyObject *iter, *pyvalue;
gint column;
GValue value = { 0 };
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!iO:GtkTreeStore.set_cell",
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O!iO:GtkTreeStore.set_value",
kwlist, &PyGtkTreeIter_Type, &iter,
&column, &pyvalue))
return NULL;
@@ -1845,8 +1849,8 @@ _wrap_gtk_tree_store_set_cell(PyGObject *self, PyObject *args, PyObject*kwargs)
"value is of the wrong type for this column");
return NULL;
}
- gtk_tree_store_set_cell(GTK_TREE_STORE(self->obj), PyGtkTreeIter_Get(iter),
- column, &value);
+ gtk_tree_store_set_value(GTK_TREE_STORE(self->obj),
+ PyGtkTreeIter_Get(iter), column, &value);
g_value_unset(&value);
Py_INCREF(Py_None);
return Py_None;