summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ehresman <jpe@wingware.com>2005-09-16 20:22:45 +0000
committerJohn Ehresman <jpe@src.gnome.org>2005-09-16 20:22:45 +0000
commitaa9ad01a98ff1a9e6211e5311606f1d4d124eba5 (patch)
tree5ff1bb878f9d4c1f094c85cac6fdc5019494a9ab
parentdf571264325479476c8a534fa5ba2ca75ec397ed (diff)
downloadpygobject-aa9ad01a98ff1a9e6211e5311606f1d4d124eba5.tar.gz
pygobject-aa9ad01a98ff1a9e6211e5311606f1d4d124eba5.tar.xz
pygobject-aa9ad01a98ff1a9e6211e5311606f1d4d124eba5.zip
Add gobject.Warning Warning subclass and redirect all g_log messages for
2005-09-16 John Ehresman <jpe@wingware.com> * gobjectmodule.c (initgobject): Add gobject.Warning Warning subclass and redirect all g_log messages for the "GLib", "Glib-GObject", and "GThread" domains to the python warning system * pangomodule.c (initpango): Add pango.Warning Warning subclass and redirect all g_log messages for the "Pango" domain to the python warning system * gtkmodule.c (initgtk): Move gtk Warning subclass from the gdk module to the gtk module and added redirections for g_log messages for the "Gdk" and "GdkPixbuf" domains to the python warning system * gtk/__init__.py: Set gdk.Warning = gtk.Warning for backward compatibility
-rw-r--r--gobject/gobjectmodule.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 0a84488..0bcc98e 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -2615,6 +2615,20 @@ pyg_set_object_has_new_constructor(GType type)
g_type_set_qdata(type, pygobject_has_updated_constructor_key, GINT_TO_POINTER(1));
}
+static void
+_log_func(const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
+{
+ PyGILState_STATE state;
+ PyObject* warning = user_data;
+
+ state = pyg_gil_state_ensure();
+ PyErr_Warn(warning, (char *) message);
+ pyg_gil_state_release(state);
+}
+
/* ----------------- gobject module initialisation -------------- */
struct _PyGObject_Functions pygobject_api_functions = {
@@ -2706,6 +2720,8 @@ initgobject(void)
{
PyObject *m, *d, *o, *tuple;
PyObject *descr;
+ PyObject *warning;
+
PyGParamSpec_Type.ob_type = &PyType_Type;
m = Py_InitModule("gobject", pygobject_functions);
@@ -2884,4 +2900,14 @@ initgobject(void)
pyg_register_gtype_custom(G_TYPE_STRV,
_pyg_strv_from_gvalue,
_pyg_strv_to_gvalue);
+
+ warning = PyErr_NewException("gobject.Warning", PyExc_Warning, NULL);
+ PyDict_SetItemString(d, "Warning", warning);
+ g_log_set_handler("GLib", G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING,
+ _log_func, warning);
+ g_log_set_handler("GLib-GObject", G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING,
+ _log_func, warning);
+ g_log_set_handler("GThread", G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING,
+ _log_func, warning);
+
}