diff options
Diffstat (limited to 'glib/pyglib.c')
-rw-r--r-- | glib/pyglib.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/glib/pyglib.c b/glib/pyglib.c index 57bc095..3f7ebbd 100644 --- a/glib/pyglib.c +++ b/glib/pyglib.c @@ -27,10 +27,14 @@ #include <pythread.h> #include "pyglib.h" #include "pyglib-private.h" +#include "pygmaincontext.h" static struct _PyGLib_Functions *_PyGLib_API; static int pyglib_thread_state_tls_key; +static PyTypeObject *_PyGMainContext_Type; +#define PyGMainContext_Type (*_PyGMainContext_Type) + void pyglib_init(void) { @@ -63,6 +67,8 @@ pyglib_init(void) "could not import glib (could not find _PyGLib_API object)"); Py_DECREF(glib); } + + _PyGMainContext_Type = (PyTypeObject*)PyObject_GetAttrString(glib, "MainContext"); } void @@ -71,6 +77,12 @@ pyglib_init_internal(PyObject *api) _PyGLib_API = (struct _PyGLib_Functions *) PyCObject_AsVoidPtr(api); } +gboolean +pyglib_threads_enabled(void) +{ + return _PyGLib_API->threads_enabled; +} + PyGILState_STATE pyglib_gil_state_ensure(void) { @@ -255,3 +267,25 @@ bad_gerror: PyErr_Print(); return -2; } + +/** + * pyglib_main_context_new: + * @context: a GMainContext. + * + * Creates a wrapper for a GMainContext. + * + * Returns: the GMainContext wrapper. + */ +PyObject * +pyglib_main_context_new(GMainContext *context) +{ + PyGMainContext *self; + + self = (PyGMainContext *)PyObject_NEW(PyGMainContext, + &PyGMainContext_Type); + if (self == NULL) + return NULL; + + self->context = g_main_context_ref(context); + return (PyObject *)self; +} |