summaryrefslogtreecommitdiffstats
path: root/glib/pygmaincontext.c
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2008-07-20 14:17:04 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-07-20 14:17:04 +0000
commit45ccf5f6ff1a1805ed326b397c70cf55bba28124 (patch)
tree59b30668a1b28efced9f417b1e6bc2f4bc9709ec /glib/pygmaincontext.c
parent9cd866c9066eaa933b54e77225ada672fcfacad3 (diff)
downloadpygobject-45ccf5f6ff1a1805ed326b397c70cf55bba28124.tar.gz
pygobject-45ccf5f6ff1a1805ed326b397c70cf55bba28124.tar.xz
pygobject-45ccf5f6ff1a1805ed326b397c70cf55bba28124.zip
Move maincontext and mainloop over to glib. Update the threadstate api to
2008-07-20 Johan Dahlin <johan@gnome.org> * glib/Makefile.am: * glib/glibmodule.c (pyglib_main_context_default), (init_glib): * glib/pyglib.c (pyglib_init), (pyglib_threads_enabled), (pyglib_main_context_new): * glib/pyglib.h: * glib/pygmaincontext.c (_wrap_g_main_context_iteration), (pyglib_maincontext_register_types): * glib/pygmaincontext.h: * glib/pygmainloop.c (pyg_signal_watch_prepare), (pyg_signal_watch_check), (pyg_main_loop_new), (_wrap_g_main_loop_get_context), (_wrap_g_main_loop_run), (pyglib_mainloop_register_types): * glib/pygmainloop.h: * gobject/Makefile.am: * gobject/__init__.py: * gobject/gobjectmodule.c (pyg_destroy_notify), (pyobject_free), (pyg_object_set_property), (pyg_object_get_property), (_pyg_signal_accumulator), (pygobject__g_instance_init), (pyg_handler_marshal), (pygobject_gil_state_ensure), (pygobject_gil_state_release), (marshal_emission_hook), (_log_func), (init_gobject): * gobject/pygboxed.c (pyg_boxed_dealloc), (pyg_boxed_new): * gobject/pygenum.c (pyg_enum_add): * gobject/pygflags.c (pyg_flags_add): * gobject/pygiochannel.c (pyg_iowatch_marshal): * gobject/pygmaincontext.c: * gobject/pygmainloop.c: * gobject/pygobject-private.h: * gobject/pygobject.c (pygobject_data_free), (pyg_toggle_notify), (pygobject_new_with_interfaces), (pygobject_weak_ref_notify): * gobject/pygobject.h: * gobject/pygoptiongroup.c (destroy_g_group), (arg_func): * gobject/pygpointer.c (pyg_pointer_new): * gobject/pygsource.c (pyg_source_get_context), (pyg_source_prepare), (pyg_source_check), (pyg_source_dispatch), (pyg_source_finalize): * gobject/pygtype.c (pyg_closure_invalidate), (pyg_closure_marshal), (pyg_signal_class_closure_marshal): * tests/common.py: Move maincontext and mainloop over to glib. Update the threadstate api to use the variant in glib. svn path=/trunk/; revision=843
Diffstat (limited to 'glib/pygmaincontext.c')
-rw-r--r--glib/pygmaincontext.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/glib/pygmaincontext.c b/glib/pygmaincontext.c
new file mode 100644
index 0000000..c969af5
--- /dev/null
+++ b/glib/pygmaincontext.c
@@ -0,0 +1,133 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygtk- Python bindings for the GTK toolkit.
+ * Copyright (C) 1998-2003 James Henstridge
+ *
+ * pygmaincontext.c: GMainContext wrapper
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <Python.h>
+#include <pythread.h>
+#include <glib.h>
+#include "pygmaincontext.h"
+#include "pyglib.h"
+#include "pyglib-private.h"
+
+static int
+pyg_main_context_init(PyGMainContext *self)
+{
+ self->context = g_main_context_new();
+ return 0;
+}
+
+static void
+pyg_main_context_dealloc(PyGMainContext *self)
+{
+ if (self->context != NULL) {
+ g_main_context_unref(self->context);
+ self->context = NULL;
+ }
+
+ PyObject_Del(self);
+}
+
+static int
+pyg_main_context_compare(PyGMainContext *self, PyGMainContext *v)
+{
+ if (self->context == v->context) return 0;
+ if (self->context > v->context) return -1;
+ return 1;
+}
+
+static PyObject *
+_wrap_g_main_context_iteration (PyGMainContext *self, PyObject *args)
+{
+ gboolean ret, may_block = TRUE;
+
+ if (!PyArg_ParseTuple(args, "|i:GMainContext.iteration",
+ &may_block))
+ return NULL;
+
+ pyglib_begin_allow_threads;
+ ret = g_main_context_iteration(self->context, may_block);
+ pyglib_end_allow_threads;
+
+ return PyBool_FromLong(ret);
+}
+
+static PyObject *
+_wrap_g_main_context_pending (PyGMainContext *self)
+{
+ return PyBool_FromLong(g_main_context_pending(self->context));
+}
+
+static PyMethodDef _PyGMainContext_methods[] = {
+ { "iteration", (PyCFunction)_wrap_g_main_context_iteration, METH_VARARGS },
+ { "pending", (PyCFunction)_wrap_g_main_context_pending, METH_NOARGS },
+ { NULL, NULL, 0 }
+};
+
+PyTypeObject PyGMainContext_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ "glib.MainContext",
+ sizeof(PyGMainContext),
+ 0,
+ /* methods */
+ (destructor)pyg_main_context_dealloc,
+ (printfunc)0,
+ (getattrfunc)0,
+ (setattrfunc)0,
+ (cmpfunc)pyg_main_context_compare,
+ (reprfunc)0,
+ 0,
+ 0,
+ 0,
+ (hashfunc)0,
+ (ternaryfunc)0,
+ (reprfunc)0,
+ (getattrofunc)0,
+ (setattrofunc)0,
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ NULL,
+ (traverseproc)0,
+ (inquiry)0,
+ (richcmpfunc)0,
+ 0,
+ (getiterfunc)0,
+ (iternextfunc)0,
+ _PyGMainContext_methods,
+ 0,
+ 0,
+ NULL,
+ NULL,
+ (descrgetfunc)0,
+ (descrsetfunc)0,
+ 0,
+ (initproc)pyg_main_context_init,
+};
+
+void
+pyglib_maincontext_register_types(PyObject *d)
+{
+ PYGLIB_REGISTER_TYPE(d, PyGMainContext_Type, "MainContext");
+}