From aa9ad01a98ff1a9e6211e5311606f1d4d124eba5 Mon Sep 17 00:00:00 2001 From: John Ehresman Date: Fri, 16 Sep 2005 20:22:45 +0000 Subject: Add gobject.Warning Warning subclass and redirect all g_log messages for 2005-09-16 John Ehresman * 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 --- gobject/gobjectmodule.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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); + } -- cgit