[pygobject] Wrap GLib.Source.is_destroyed() method
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Wrap GLib.Source.is_destroyed() method
- Date: Wed, 4 Apr 2012 15:55:49 +0000 (UTC)
commit d4054be9de3b7e4ed64c8172ebbde0a697462c79
Author: Martin Pitt <martinpitt gnome org>
Date: Wed Apr 4 17:54:52 2012 +0200
Wrap GLib.Source.is_destroyed() method
Based on original patch from Bryan Silverthorn.
https://bugzilla.gnome.org/show_bug.cgi?id=524719
gi/_glib/pygsource.c | 15 +++++++++++++++
tests/test_source.py | 24 ++++++++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/gi/_glib/pygsource.c b/gi/_glib/pygsource.c
index 6c290a8..d11f474 100644
--- a/gi/_glib/pygsource.c
+++ b/gi/_glib/pygsource.c
@@ -130,6 +130,20 @@ pyg_source_destroy(PyGSource *self)
}
static PyObject *
+pyg_source_is_destroyed(PyGSource *self)
+{
+ PyObject *result;
+
+ if (self->source == NULL || g_source_is_destroyed(self->source))
+ result = Py_True;
+ else
+ result = Py_False;
+
+ Py_INCREF(result);
+ return result;
+}
+
+static PyObject *
pyg_source_set_callback(PyGSource *self, PyObject *args)
{
PyObject *first, *callback, *cbargs = NULL, *data;
@@ -255,6 +269,7 @@ pyg_source_get_current_time(PyGSource *self)
static PyMethodDef pyg_source_methods[] = {
{ "attach", (PyCFunction)pyg_source_attach, METH_VARARGS|METH_KEYWORDS },
{ "destroy", (PyCFunction)pyg_source_destroy, METH_NOARGS },
+ { "is_destroyed", (PyCFunction)pyg_source_is_destroyed, METH_NOARGS },
{ "set_callback", (PyCFunction)pyg_source_set_callback, METH_VARARGS },
{ "get_context", (PyCFunction)pyg_source_get_context, METH_NOARGS },
{ "add_poll", (PyCFunction)pyg_source_add_poll, METH_KEYWORDS },
diff --git a/tests/test_source.py b/tests/test_source.py
index 85362ad..fe674cd 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -89,6 +89,30 @@ class TestSource(unittest.TestCase):
assert dispatched[0]
+ def testIsDestroyedSimple(self):
+ s = GLib.Source()
+
+ self.assertFalse(s.is_destroyed())
+ s.destroy()
+ self.assertTrue(s.is_destroyed())
+
+ c = GLib.MainContext()
+ s = GLib.Source()
+ s.attach(c)
+ self.assertFalse(s.is_destroyed())
+ s.destroy()
+ self.assertTrue(s.is_destroyed())
+
+ def testIsDestroyedContext(self):
+ def f():
+ c = GLib.MainContext()
+ s = GLib.Source()
+ s.attach(c)
+ return s
+
+ s = f()
+ self.assertTrue(s.is_destroyed())
+
class TestTimeout(unittest.TestCase):
def test504337(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]