summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pitt <martinpitt@gnome.org>2012-10-19 09:55:05 +0200
committerMartin Pitt <martinpitt@gnome.org>2012-10-24 07:12:54 +0200
commit191cf45af44850fc29f2392ae2f0042aed6d13a9 (patch)
treebd1a43b254c6761f5e538aabf0d77bf8a5e306ca
parent326218a20681c1f2234a6eea1ed800382be57626 (diff)
downloadpygobject-191cf45af44850fc29f2392ae2f0042aed6d13a9.tar.gz
Remove static MainLoop, MainContext, and some GSource bindings
glib's MainLoop and MainContext are fully introspectable these days, so remove our static bindings. This reduces our code, as well enables GLib API which hasn't been available through the static bindings before. This also requires dropping our custom static types for GLib Source, Timeout, and Idle. The latter two work fine with introspection and just need tiny overrides for a backwards compatible API. g_source_new() is not introspectable, though, so we need to keep our static wrappers for that. Move them from gi/_glib/pygsource.c to gi/pygi-source.c, so that it can use the GI API. Note that gi/_glib/pygsource.[hc] is still required for the static PollFD type which is used by the static IOChannel binding. Once the latter goes away, PollFD can be dropped as well. https://bugzilla.gnome.org/show_bug.cgi?id=686443
-rw-r--r--docs/Makefile.am6
-rw-r--r--docs/reference/pyglib-classes.xml2
-rw-r--r--docs/reference/pyglib-constants.xml53
-rw-r--r--docs/reference/pyglib-functions.xml58
-rw-r--r--docs/reference/pyglib-maincontext.xml152
-rw-r--r--docs/reference/pyglib-mainloop.xml202
-rw-r--r--gi/Makefile.am2
-rw-r--r--gi/_glib/Makefile.am4
-rw-r--r--gi/_glib/__init__.py12
-rw-r--r--gi/_glib/glibmodule.c45
-rw-r--r--gi/_glib/pyglib.c15
-rw-r--r--gi/_glib/pyglib.h1
-rw-r--r--gi/_glib/pygmaincontext.c126
-rw-r--r--gi/_glib/pygmaincontext.h40
-rw-r--r--gi/_glib/pygmainloop.c362
-rw-r--r--gi/_glib/pygmainloop.h36
-rw-r--r--gi/_glib/pygsource.c640
-rw-r--r--gi/_glib/pygsource.h3
-rw-r--r--gi/_gobject/__init__.py13
-rw-r--r--gi/gimodule.c9
-rw-r--r--gi/overrides/GLib.py116
-rw-r--r--gi/overrides/GObject.py10
-rw-r--r--gi/pygi-private.h1
-rw-r--r--gi/pygi-source.c247
-rw-r--r--gi/pygi-source.h31
-rw-r--r--tests/test_glib.py22
-rw-r--r--tests/test_gobject.py2
-rw-r--r--tests/test_source.py3
28 files changed, 437 insertions, 1776 deletions
diff --git a/docs/Makefile.am b/docs/Makefile.am
index 5920d5fa..c2fc7efa 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -11,8 +11,6 @@ HTML_FILES = \
html/class-gobjectginterface.html \
html/class-gobjectgpointer.html \
html/class-gobject.html \
- html/class-glibmaincontext.html \
- html/class-glibmainloop.html \
html/glib-constants.html \
html/glib-functions.html \
html/gobject-class-reference.html \
@@ -37,9 +35,7 @@ XML_FILES = \
reference/pygobject-gpointer.xml \
reference/pyglib-classes.xml \
reference/pyglib-constants.xml \
- reference/pyglib-functions.xml \
- reference/pyglib-maincontext.xml \
- reference/pyglib-mainloop.xml
+ reference/pyglib-functions.xml
XSL_FILES = \
xsl/common.xsl \
diff --git a/docs/reference/pyglib-classes.xml b/docs/reference/pyglib-classes.xml
index ecc4e5b7..da22b902 100644
--- a/docs/reference/pyglib-classes.xml
+++ b/docs/reference/pyglib-classes.xml
@@ -7,8 +7,6 @@
<title>PyGlibClass Reference</title>
<!-- GLIB CLASSES -->
-<xi:include href="pyglib-maincontext.xml"/>
-<xi:include href="pyglib-mainloop.xml"/>
<xi:include href="pyglib-functions.xml"/>
<xi:include href="pyglib-constants.xml"/>
diff --git a/docs/reference/pyglib-constants.xml b/docs/reference/pyglib-constants.xml
index 4f4f37bd..26462322 100644
--- a/docs/reference/pyglib-constants.xml
+++ b/docs/reference/pyglib-constants.xml
@@ -73,59 +73,6 @@ condition to watch for on an event source.</para>
</refsect2>
- <refsect2 id="glib-priority-constants">
- <title id="glib-priority-constants-title">Glib Priority Constants</title>
-
- <para>The Priority constants specify </para>
-
- <variablelist>
- <varlistentry>
- <term><literal>glib.PRIORITY_HIGH</literal></term>
- <listitem>
- <simpara>Use this for high priority event sources.</simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><literal>glib.PRIORITY_DEFAULT</literal></term>
- <listitem>
- <simpara>Use this for default priority event sources. This
- priority is used when adding timeout functions with the <link
- linkend="function-glib--timeout-add"><function>glib.timeout_add</function>()</link>
- function. This priority is also used for events from the X
- server.</simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><literal>glib.PRIORITY_HIGH_IDLE</literal></term>
- <listitem>
- <simpara>Use this for high priority idle functions. For example,
- glib.PRIORITY_HIGH_IDLE + 10 is used for resizing operations;
- and, glib.PRIORITY_HIGH_IDLE + 20, for redrawing
- operations. (This is done to ensure that any pending resizes are
- processed before any pending redraws, so that widgets are not
- redrawn twice unnecessarily.)</simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><literal>glib.PRIORITY_DEFAULT_IDLE</literal></term>
- <listitem>
- <simpara>Use this for default priority idle functions. This
- priority is used when adding idle functions with the <link
- linkend="function-glib--idle-add"><function>glib.idle_add</function>()</link>
- function.</simpara>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><literal>glib.PRIORITY_LOW</literal></term>
- <listitem>
- <simpara>Use this for very low priority background
- tasks.</simpara>
- </listitem>
- </varlistentry>
- </variablelist>
-
- </refsect2>
-
<refsect2 id="glib-spawn-flag-constants">
<title id="glib-spawn-flag-constants-title">Glib Spawn Flag Constants</title>
diff --git a/docs/reference/pyglib-functions.xml b/docs/reference/pyglib-functions.xml
index 7c4204e3..03540824 100644
--- a/docs/reference/pyglib-functions.xml
+++ b/docs/reference/pyglib-functions.xml
@@ -37,14 +37,6 @@ linkend="function-glib--io-add-watch">glib.io_add_watch</link></methodname>
<methodparam><parameter>callback</parameter></methodparam>
<methodparam><parameter>...</parameter></methodparam>
</methodsynopsis><methodsynopsis language="python">
- <methodname><link
-linkend="function-glib--source-remove">glib.source_remove</link></methodname>
- <methodparam><parameter>tag</parameter></methodparam>
- </methodsynopsis><methodsynopsis language="python">
- <methodname><link
-linkend="function-glib--main-context-default">glib.main_context_default</link></methodname>
- <methodparam></methodparam>
- </methodsynopsis><methodsynopsis language="python">
<methodname><link linkend="function-glib--child-watch-add">glib.child_watch_add</link></methodname>
<methodparam><parameter role="keyword">pid</parameter></methodparam>
<methodparam><parameter role="keyword">function</parameter></methodparam>
@@ -334,56 +326,6 @@ when the condition is matched.</para>
</refsect2>
- <refsect2 id="function-glib--source-remove">
- <title>glib.source_remove</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>glib.source_remove</methodname>
- <methodparam><parameter>tag</parameter></methodparam>
- </methodsynopsis></programlisting>
- <variablelist>
- <varlistentry>
- <term><parameter>tag</parameter>&nbsp;:</term>
- <listitem><simpara>an integer ID</simpara></listitem>
- </varlistentry>
- <varlistentry>
- <term><emphasis>Returns</emphasis>&nbsp;:</term>
- <listitem><simpara><literal>True</literal> if the event source was
-removed</simpara></listitem>
- </varlistentry>
- </variablelist>
-
- <para>The <function>glib.source_remove</function>() function
-removes the event source specified by tag (as returned by the <link
-linkend="function-glib--idle-add"><function>glib.idle_add</function>()</link>,
-<link
-linkend="function-glib--timeout-add"><function>glib.timeout_add</function></link>()
-and <link
-linkend="function-glib--io-add-watch"><function>glib.io_add_watch</function>()</link>
-functions)</para>
-
- </refsect2>
-
- <refsect2 id="function-glib--main-context-default">
- <title>glib.main_context_default</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>glib.main_context_default</methodname>
- <methodparam></methodparam>
- </methodsynopsis></programlisting>
- <variablelist>
- <varlistentry>
- <term><emphasis>Returns</emphasis>&nbsp;:</term>
- <listitem><simpara>the default glib.MainContext
-object</simpara></listitem>
- </varlistentry>
- </variablelist>
-
- <para>The <function>glib.main_context_default</function>() function
-returns the default glib.MainContext object.</para>
-
- </refsect2>
-
<refsect2 id="function-glib--markup-escape-text">
<title>glib.markup_escape_text</title>
diff --git a/docs/reference/pyglib-maincontext.xml b/docs/reference/pyglib-maincontext.xml
deleted file mode 100644
index ee1e9854..00000000
--- a/docs/reference/pyglib-maincontext.xml
+++ /dev/null
@@ -1,152 +0,0 @@
-<?xml version="1.0" standalone="no"?>
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
- "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-
-<refentry id="class-glibmaincontext">
- <refnamediv>
- <refname>glib.MainContext</refname>
-
- <refpurpose>an object representing a set of event sources to be handled
-in a <link
-linkend="class-glibmainloop"><classname>glib.MainLoop</classname></link>.</refpurpose>
- </refnamediv>
-
- <refsect1>
- <title>Synopsis</title>
-
-<classsynopsis language="python">
- <ooclass><classname>glib.MainContext</classname></ooclass>
-<constructorsynopsis language="python">
- <methodname><link linkend="constructor-glibmaincontext">glib.MainContext</link></methodname>
- </constructorsynopsis>
-<methodsynopsis language="python">
- <methodname><link linkend="method-glibmaincontext--iteration">iteration</link></methodname>
- <methodparam><parameter>may_block</parameter></methodparam>
- </methodsynopsis>
-<methodsynopsis language="python">
- <methodname><link linkend="method-glibmaincontext--pending">pending</link></methodname>
- </methodsynopsis>
-</classsynopsis>
-
-</refsect1>
-
- <refsect1>
- <title>Ancestry</title>
-
-<synopsis>+-- <link linkend="class-glibmaincontext">glib.MainContext</link>
-</synopsis>
-
- </refsect1>
-
- <refsect1>
- <title>Description</title>
-
- <para>A <link
-linkend="class-glibmaincontext"><classname>glib.MainContext</classname></link>
-represents a set of event sources that can be run in a single thread. File
-descriptors (plain files, pipes or sockets) and timeouts are the standard
-event sources for <literal>GTK</literal> and <literal>PyGTK</literal> though
-others can be added. Each event source is assigned a priority. The default
-priority, <literal>glib.PRIORITY_DEFAULT</literal>, is 0. Values less
-than 0 denote higher priorities. Values greater than 0 denote lower
-priorities. Events from high priority sources are always processed before
-events from lower priority sources. Single iterations of a <link
-linkend="class-glibmaincontext"><classname>glib.MainContext</classname></link>
-can be run with the <link
-linkend="method-glibmaincontext--iteration"><methodname>iteration</methodname>()</link>
-method.</para>
-
- </refsect1>
-
- <refsect1 id="constructor-glibmaincontext">
- <title>Constructor</title>
-
- <programlisting><constructorsynopsis language="python">
- <methodname>glib.MainContext</methodname>
- </constructorsynopsis></programlisting>
- <variablelist>
- <varlistentry>
- <term><emphasis>Returns</emphasis>&nbsp;:</term>
- <listitem><simpara>a new <link
- linkend="class-glibmaincontext"><classname>glib.MainContext</classname></link>
- object.</simpara></listitem>
- </varlistentry>
- </variablelist>
-
- <para>Creates a new <link
-linkend="class-glibmaincontext"><classname>glib.MainContext</classname></link>
-object.</para>
-
- </refsect1>
-
- <refsect1>
- <title>Methods</title>
-
- <refsect2 id="method-glibmaincontext--iteration">
- <title>glib.MainContext.iteration</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>iteration</methodname>
- </methodsynopsis></programlisting>
- <variablelist>
- <varlistentry>
- <term><parameter>may_block</parameter>&nbsp;:</term>
- <listitem><simpara>if <literal>True</literal> the call may block
- waiting for an event.</simpara></listitem>
- </varlistentry>
- <varlistentry>
- <term><emphasis>Returns</emphasis>&nbsp;:</term>
- <listitem><simpara><literal>True</literal> if events were
- dispatched.</simpara></listitem>
- </varlistentry>
- </variablelist>
-
- <para>The <methodname>iteration</methodname>() method runs a single
-iteration. This involves:</para>
-
- <itemizedlist>
- <listitem>
- <simpara>checking to see if any associated event sources are ready
-to be processed;</simpara>
- </listitem>
- <listitem>
- <simpara>then if no events sources are ready and
-<parameter>may_block</parameter> is <literal>True</literal>, waiting for a
-source to become ready;</simpara>
- </listitem>
- <listitem>
- <simpara>and finally, dispatching the highest priority events
-sources that are ready</simpara>
- </listitem>
- </itemizedlist>
-
- <para>Note that even when <parameter>may_block</parameter> is
-<literal>True</literal>, it is still possible for
-<methodname>iteration</methodname>() to return <literal>False</literal>,
-since the the wait may be interrupted for other reasons than an event source
-becoming ready.</para>
-
- </refsect2>
-
- <refsect2 id="method-glibmaincontext--pending">
- <title>glib.MainContext.pending</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>pending</methodname>
- </methodsynopsis></programlisting>
- <variablelist>
- <varlistentry>
- <term><emphasis>Returns</emphasis>&nbsp;:</term>
- <listitem><simpara><literal>True</literal> if events are
- pending.</simpara></listitem>
- </varlistentry>
- </variablelist>
-
- <para>The <methodname>pending</methodname>() method checks if any
-associated sources have pending events.</para>
-
- </refsect2>
-
- </refsect1>
-
-</refentry>
diff --git a/docs/reference/pyglib-mainloop.xml b/docs/reference/pyglib-mainloop.xml
deleted file mode 100644
index 913e7438..00000000
--- a/docs/reference/pyglib-mainloop.xml
+++ /dev/null
@@ -1,202 +0,0 @@
-<?xml version="1.0" standalone="no"?>
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
- "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-
-<refentry id="class-glibmainloop">
- <refnamediv>
- <refname>glib.MainLoop</refname>
-
- <refpurpose>an object representing the main event loop of a PyGTK
- application.</refpurpose>
- </refnamediv>
-
- <refsect1>
- <title>Synopsis</title>
-
-<classsynopsis language="python">
- <ooclass><classname>glib.MainLoop</classname></ooclass>
-<constructorsynopsis language="python">
- <methodname><link linkend="constructor-glibmainloop">glib.MainLoop</link></methodname>
- <methodparam><parameter>context</parameter><initializer>None</initializer></methodparam>
- <methodparam><parameter>is_running</parameter><initializer>0</initializer></methodparam>
- </constructorsynopsis>
-<methodsynopsis language="python">
- <methodname><link linkend="method-glibmainloop--get-context">get_context</link></methodname>
- </methodsynopsis>
-<methodsynopsis language="python">
- <methodname><link linkend="method-glibmainloop--is-running">is_running</link></methodname>
- </methodsynopsis>
-<methodsynopsis language="python">
- <methodname><link linkend="method-glibmainloop--quit">quit</link></methodname>
- </methodsynopsis>
-<methodsynopsis language="python">
- <methodname><link linkend="method-glibmainloop--run">run</link></methodname>
- </methodsynopsis>
-</classsynopsis>
-
-</refsect1>
-
- <refsect1>
- <title>Ancestry</title>
-
-<synopsis>+-- <link linkend="class-glibmainloop">glib.MainLoop</link>
-</synopsis>
-
- </refsect1>
-
- <refsect1>
- <title>Description</title>
-
- <para><link
-linkend="class-glibmainloop"><classname>glib.MainLoop</classname></link>
-represents a main event loop. A <link
-linkend="class-glibmainloop"><classname>glib.MainLoop</classname></link>
-is created with the <link
-linkend="constructor-glibmainloop">glib.MainLoop</link>()
-constructor. After adding the initial event sources, the <link
-linkend="method-glibmainloop--run"><methodname>run</methodname>()</link>
-method is called. This continuously checks for new events from each of the
-event sources and dispatches them. Finally, the processing of an event from
-one of the sources leads to a call to the <link
-linkend="method-glibmainloop--quit"><methodname>quit</methodname>()</link>
-method to exit the main loop, and the <link
-linkend="method-glibmainloop--run"><methodname>run</methodname>()</link>
-method returns.</para>
-
- <para>It is possible to create new instances of <link
-linkend="class-glibmainloop"><classname>glib.MainLoop</classname></link>
-recursively. This is often used in <literal>PyGTK</literal> applications
-when showing modal dialog boxes. Note that event sources are associated with
-a particular <link
-linkend="class-glibmaincontext"><classname>glib.MainContext</classname></link>,
-and will be checked and dispatched for all main loops associated with that
-<link
-linkend="class-glibmaincontext"><classname>glib.MainContext</classname></link>.</para>
-
- <para><literal>PyGTK</literal> contains wrappers of some of these
-functions, e.g. the <link
-linkend="function-gtk--main"><function>gtk.main</function>()</link>, <link
-linkend="function-gtk--main-quit"><function>gtk.main_quit</function>()</link>
-and <link
-linkend="function-gtk--events-pending"><function>gtk.events_pending</function>()</link>
-functions.</para>
-
- </refsect1>
-
- <refsect1 id="constructor-glibmainloop">
- <title>Constructor</title>
-
- <programlisting><constructorsynopsis language="python">
- <methodname>glib.MainLoop</methodname>
- <methodparam><parameter>context</parameter><initializer>None</initializer></methodparam>
- <methodparam><parameter>is_running</parameter><initializer>None</initializer></methodparam>
- </constructorsynopsis></programlisting>
- <variablelist>
- <varlistentry>
- <term><parameter>context</parameter>&nbsp;:</term>
- <listitem><simpara>a <link
- linkend="class-glibmaincontext"><classname>glib.MainContext</classname></link>
- or <literal>None</literal> to use the default
- context.</simpara></listitem>
- </varlistentry>
- <varlistentry>
- <term><parameter>is_running</parameter>&nbsp;:</term>
- <listitem><simpara>if <literal>True</literal> indicates that the
- loop is running. This is not very important since calling the <link
- linkend="method-glibmainloop--run"><methodname>run</methodname>()</link>
- method will set this to <literal>True</literal>
- anyway.</simpara></listitem>
- </varlistentry>
- <varlistentry>
- <term><emphasis>Returns</emphasis>&nbsp;:</term>
- <listitem><simpara>a new <link
- linkend="class-glibmainloop"><classname>glib.MainLoop</classname></link>
- object.</simpara></listitem>
- </varlistentry>
- </variablelist>
-
- <para>Creates a new <link
-linkend="class-glibmainloop"><classname>glib.MainLoop</classname></link>
-object.</para>
-
- </refsect1>
-
- <refsect1>
- <title>Methods</title>
-
- <refsect2 id="method-glibmainloop--get-context">
- <title>glib.MainLoop.get_context</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>get_context</methodname>
- </methodsynopsis></programlisting>
- <variablelist>
- <varlistentry>
- <term><emphasis>Returns</emphasis>&nbsp;:</term>
- <listitem><simpara>the <link
- linkend="class-glibmaincontext"><classname>glib.MainContext</classname></link>
- the mainloop is associated with</simpara></listitem>
- </varlistentry>
- </variablelist>
-
- <para>The <methodname>get_context</methodname>() method returns the
-<link
-linkend="class-glibmaincontext"><classname>glib.MainContext</classname></link>
-that the mainloop was created with.</para>
-
- </refsect2>
-
- <refsect2 id="method-glibmainloop--is-running">
- <title>glib.MainLoop.is_running</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>is_running</methodname>
- </methodsynopsis></programlisting>
- <variablelist>
- <varlistentry>
- <term><emphasis>Returns</emphasis>&nbsp;:</term>
- <listitem><simpara><literal>True</literal> if the mainloop is
- currently being run.</simpara></listitem>
- </varlistentry>
- </variablelist>
-
- <para>The <methodname>is_running</methodname>() method checks to see
-if the mainloop is currently being run via the <link
-linkend="method-glibmainloop--run"><methodname>run</methodname>()</link>
-method.</para>
-
- </refsect2>
-
- <refsect2 id="method-glibmainloop--quit">
- <title>glib.MainLoop.quit</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>quit</methodname>
- </methodsynopsis></programlisting>
-
- <para>The <methodname>quit</methodname>() method stops the mainloop
-from running. Any subsequent calls to the <link
-linkend="method-glibmainloop--run"><methodname>run</methodname>()</link>
-method will return immediately.</para>
-
- </refsect2>
-
- <refsect2 id="method-glibmainloop--run">
- <title>glib.MainLoop.run</title>
-
- <programlisting><methodsynopsis language="python">
- <methodname>run</methodname>
- </methodsynopsis></programlisting>
-
- <para>The <methodname>run</methodname>() method runs a mainloop until
-the <link
-linkend="method-glibmainloop--quit"><methodname>quit</methodname>()</link>
-method is called. If this is called for the thread of the loop's <link
-linkend="class-glibmaincontext"><classname>glib.MainContext</classname></link>,
-it will process events from the loop, otherwise it will simply wait.</para>
-
- </refsect2>
-
- </refsect1>
-
-</refentry>
diff --git a/gi/Makefile.am b/gi/Makefile.am
index f99e45bf..53d0ddf5 100644
--- a/gi/Makefile.am
+++ b/gi/Makefile.am
@@ -46,6 +46,8 @@ _gi_la_SOURCES = \
pygi-foreign-gvariant.h \
pygi-struct.c \
pygi-struct.h \
+ pygi-source.c \
+ pygi-source.h \
pygi-argument.c \
pygi-argument.h \
pygi-type.c \
diff --git a/gi/_glib/Makefile.am b/gi/_glib/Makefile.am
index 468e7f47..fed1b43f 100644
--- a/gi/_glib/Makefile.am
+++ b/gi/_glib/Makefile.am
@@ -58,10 +58,6 @@ _glib_la_SOURCES = \
pygoptioncontext.h \
pygoptiongroup.c \
pygoptiongroup.h \
- pygmaincontext.c \
- pygmaincontext.h \
- pygmainloop.c \
- pygmainloop.h \
pygsource.c \
pygsource.h \
pygspawn.c \
diff --git a/gi/_glib/__init__.py b/gi/_glib/__init__.py
index 378d9818..b9e5fa4c 100644
--- a/gi/_glib/__init__.py
+++ b/gi/_glib/__init__.py
@@ -27,15 +27,10 @@ _PyGLib_API = _glib._PyGLib_API
# Types
GError = _glib.GError
IOChannel = _glib.IOChannel
-Idle = _glib.Idle
-MainContext = _glib.MainContext
-MainLoop = _glib.MainLoop
OptionContext = _glib.OptionContext
OptionGroup = _glib.OptionGroup
Pid = _glib.Pid
PollFD = _glib.PollFD
-Source = _glib.Source
-Timeout = _glib.Timeout
# Constants
IO_ERR = _glib.IO_ERR
@@ -68,11 +63,6 @@ OPTION_FLAG_NO_ARG = _glib.OPTION_FLAG_NO_ARG
OPTION_FLAG_OPTIONAL_ARG = _glib.OPTION_FLAG_OPTIONAL_ARG
OPTION_FLAG_REVERSE = _glib.OPTION_FLAG_REVERSE
OPTION_REMAINING = _glib.OPTION_REMAINING
-PRIORITY_DEFAULT = _glib.PRIORITY_DEFAULT
-PRIORITY_DEFAULT_IDLE = _glib.PRIORITY_DEFAULT_IDLE
-PRIORITY_HIGH = _glib.PRIORITY_HIGH
-PRIORITY_HIGH_IDLE = _glib.PRIORITY_HIGH_IDLE
-PRIORITY_LOW = _glib.PRIORITY_LOW
SPAWN_CHILD_INHERITS_STDIN = _glib.SPAWN_CHILD_INHERITS_STDIN
SPAWN_DO_NOT_REAP_CHILD = _glib.SPAWN_DO_NOT_REAP_CHILD
SPAWN_FILE_AND_ARGV_ZERO = _glib.SPAWN_FILE_AND_ARGV_ZERO
@@ -88,9 +78,7 @@ get_current_time = _glib.get_current_time
glib_version = _glib.glib_version
idle_add = _glib.idle_add
io_add_watch = _glib.io_add_watch
-main_context_default = _glib.main_context_default
pyglib_version = _glib.pyglib_version
-source_remove = _glib.source_remove
spawn_async = _glib.spawn_async
threads_init = _glib.threads_init
timeout_add = _glib.timeout_add
diff --git a/gi/_glib/glibmodule.c b/gi/_glib/glibmodule.c
index 791bd93a..dbe5054e 100644
--- a/gi/_glib/glibmodule.c
+++ b/gi/_glib/glibmodule.c
@@ -30,8 +30,6 @@
#include "pyglib.h"
#include "pyglib-private.h"
#include "pygiochannel.h"
-#include "pygmaincontext.h"
-#include "pygmainloop.h"
#include "pygoptioncontext.h"
#include "pygoptiongroup.h"
#include "pygsource.h"
@@ -308,23 +306,6 @@ pyglib_io_add_watch(PyObject *self, PyObject *args, PyObject *kwargs)
return PYGLIB_PyLong_FromLong(handler_id);
}
-static PyObject *
-pyglib_source_remove(PyObject *self, PyObject *args)
-{
- guint tag;
-
- if (!PyArg_ParseTuple(args, "I:source_remove", &tag))
- return NULL;
-
- return PyBool_FromLong(g_source_remove(tag));
-}
-
-static PyObject *
-pyglib_main_context_default(PyObject *unused)
-{
- return pyglib_main_context_new(g_main_context_default());
-}
-
static void
child_watch_func(GPid pid, gint status, gpointer data)
{
@@ -465,12 +446,6 @@ static PyMethodDef _glib_functions[] = {
"data specified by data when the child indicated by pid exits.\n"
"Condition is a combination of glib.IO_IN, glib.IO_OUT, glib.IO_PRI,\n"
"gio.IO_ERR and gio.IO_HUB." },
- { "source_remove",
- (PyCFunction)pyglib_source_remove, METH_VARARGS,
- "source_remove(source_id) -> True if removed\n"
- "Removes the event source specified by source id as returned by the\n"
- "glib.idle_add(), glib.timeout_add() or glib.io_add_watch()\n"
- "functions." },
{ "spawn_async",
(PyCFunction)pyglib_spawn_async, METH_VARARGS|METH_KEYWORDS,
"spawn_async(argv, envp=None, working_directory=None,\n"
@@ -479,11 +454,6 @@ static PyMethodDef _glib_functions[] = {
" standard_error=None) -> (pid, stdin, stdout, stderr)\n"
"Execute a child program asynchronously within a glib.MainLoop()\n"
"See the reference manual for a complete reference." },
- { "main_context_default",
- (PyCFunction)pyglib_main_context_default, METH_NOARGS,
- "main_context_default() -> a main context\n"
- "Returns the default main context. This is the main context used\n"
- "for main loop functions when a main loop is not explicitly specified." },
{ "filename_from_utf8",
(PyCFunction)pyglib_filename_from_utf8, METH_VARARGS },
{ "get_current_time",
@@ -498,7 +468,7 @@ static struct _PyGLib_Functions pyglib_api = {
NULL, /* gerror_exception */
NULL, /* block_threads */
NULL, /* unblock_threads */
- pyg_main_context_new,
+ NULL, /* pyg_main_context_new */
pyg_option_context_new,
pyg_option_group_new,
};
@@ -572,17 +542,6 @@ pyglib_register_constants(PyObject *m)
PyModule_AddIntConstant(m, "SPAWN_FILE_AND_ARGV_ZERO",
G_SPAWN_FILE_AND_ARGV_ZERO);
- PyModule_AddIntConstant(m, "PRIORITY_HIGH",
- G_PRIORITY_HIGH);
- PyModule_AddIntConstant(m, "PRIORITY_DEFAULT",
- G_PRIORITY_DEFAULT);
- PyModule_AddIntConstant(m, "PRIORITY_HIGH_IDLE",
- G_PRIORITY_HIGH_IDLE);
- PyModule_AddIntConstant(m, "PRIORITY_DEFAULT_IDLE",
- G_PRIORITY_DEFAULT_IDLE);
- PyModule_AddIntConstant(m, "PRIORITY_LOW",
- G_PRIORITY_LOW);
-
PyModule_AddIntConstant(m, "IO_IN", G_IO_IN);
PyModule_AddIntConstant(m, "IO_OUT", G_IO_OUT);
PyModule_AddIntConstant(m, "IO_PRI", G_IO_PRI);
@@ -652,8 +611,6 @@ PYGLIB_MODULE_START(_glib, "_glib")
pyglib_register_error(d);
pyglib_register_version_tuples(d);
pyglib_iochannel_register_types(d);
- pyglib_mainloop_register_types(d);
- pyglib_maincontext_register_types(d);
pyglib_source_register_types(d);
pyglib_spawn_register_types(d);
pyglib_option_context_register_types(d);
diff --git a/gi/_glib/pyglib.c b/gi/_glib/pyglib.c
index 3508f55d..2e5a0ef2 100644
--- a/gi/_glib/pyglib.c
+++ b/gi/_glib/pyglib.c
@@ -27,7 +27,6 @@
#include <pythread.h>
#include "pyglib.h"
#include "pyglib-private.h"
-#include "pygmaincontext.h"
#include "pygoptioncontext.h"
#include "pygoptiongroup.h"
@@ -411,20 +410,6 @@ pyglib_register_exception_for_domain(gchar *name,
}
/**
- * pyglib_main_context_new:
- * @context: a GMainContext.
- *
- * Creates a wrapper for a GMainContext.
- *
- * Returns: the GMainContext wrapper.
- */
-PyObject *
-pyglib_main_context_new(GMainContext *context)
-{
- return _PyGLib_API->main_context_new(context);
-}
-
-/**
* pyg_option_group_transfer_group:
* @group: a GOptionGroup wrapper
*
diff --git a/gi/_glib/pyglib.h b/gi/_glib/pyglib.h
index 261af7b5..35e40c4d 100644
--- a/gi/_glib/pyglib.h
+++ b/gi/_glib/pyglib.h
@@ -42,7 +42,6 @@ gboolean pyglib_gerror_exception_check(GError **error);
PyObject *pyglib_register_exception_for_domain(gchar *name,
gint error_domain);
gboolean pyglib_threads_enabled(void);
-PyObject * pyglib_main_context_new(GMainContext *context);
void pyglib_set_thread_block_funcs(PyGLibThreadBlockFunc block_threads_func,
PyGLibThreadBlockFunc unblock_threads_func);
void pyglib_block_threads(void);
diff --git a/gi/_glib/pygmaincontext.c b/gi/_glib/pygmaincontext.c
deleted file mode 100644
index a4282ee2..00000000
--- a/gi/_glib/pygmaincontext.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
- * 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"
-
-PYGLIB_DEFINE_TYPE("gi._glib.MainContext", PyGMainContext_Type, PyGMainContext)
-
-/**
- * pyg_main_context_new:
- * @context: a GMainContext.
- *
- * Creates a wrapper for a GMainContext.
- *
- * Returns: the GMainContext wrapper.
- */
-PyObject *
-pyg_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;
-}
-
-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 PyObject*
-pyg_main_context_richcompare(PyObject *self, PyObject *other, int op)
-{
- if (Py_TYPE(self) == Py_TYPE(other) && Py_TYPE(self) == &PyGMainContext_Type)
- return _pyglib_generic_ptr_richcompare(((PyGMainContext*)self)->context,
- ((PyGMainContext*)other)->context,
- op);
- else {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
- }
-}
-
-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 }
-};
-
-void
-pyglib_maincontext_register_types(PyObject *d)
-{
- PyGMainContext_Type.tp_dealloc = (destructor)pyg_main_context_dealloc;
- PyGMainContext_Type.tp_richcompare = pyg_main_context_richcompare;
- PyGMainContext_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
- PyGMainContext_Type.tp_methods = _PyGMainContext_methods;
- PyGMainContext_Type.tp_init = (initproc)pyg_main_context_init;
- PYGLIB_REGISTER_TYPE(d, PyGMainContext_Type, "MainContext");
-}
diff --git a/gi/_glib/pygmaincontext.h b/gi/_glib/pygmaincontext.h
deleted file mode 100644
index 4ffa3c90..00000000
--- a/gi/_glib/pygmaincontext.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- Mode: C; c-basic-offset: 4 -*-
- * pyglib - Python bindings for GLib toolkit.
- * Copyright (C) 1998-2003 James Henstridge
- * 2004-2008 Johan Dahlin
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
- * USA
- */
-
-#ifndef __PYG_MAINCONTEXT_H__
-#define __PYG_MAINCONTEXT_H__
-
-#include <Python.h>
-#include <glib.h>
-
-typedef struct {
- PyObject_HEAD
- GMainContext *context;
-} PyGMainContext;
-
-extern PyTypeObject PyGMainContext_Type;
-
-PyObject* pyg_main_context_new(GMainContext *context);
-
-void pyglib_maincontext_register_types(PyObject *d);
-
-#endif /* __PYG_MAINCONTEXT_H__ */
-
diff --git a/gi/_glib/pygmainloop.c b/gi/_glib/pygmainloop.c
deleted file mode 100644
index 5dabef69..00000000
--- a/gi/_glib/pygmainloop.c
+++ /dev/null
@@ -1,362 +0,0 @@
-/* -*- Mode: C; c-basic-offset: 4 -*-
- * pygtk- Python bindings for the GTK toolkit.
- * Copyright (C) 1998-2003 James Henstridge
- * Copyright (C) 2004 Johan Dahlin
- *
- * pygmainloop.c: GMainLoop 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
- * USA
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <fcntl.h>
-
-#include <Python.h>
-#include <pythread.h>
-#include <glib.h>
-
-#include "pygmainloop.h"
-#include "pygmaincontext.h"
-#include "pyglib.h"
-#include "pyglib-private.h"
-
-static int pipe_fds[2];
-
-typedef struct {
- GSource source;
- GPollFD fd;
-} PySignalWatchSource;
-
-#ifdef DISABLE_THREADING
-static GMainLoop *pyg_current_main_loop = NULL;;
-
-static inline GMainLoop *
-pyg_save_current_main_loop (GMainLoop *main_loop)
-{
- GMainLoop *retval = pyg_current_main_loop;
-
- g_return_val_if_fail(main_loop != NULL, NULL);
-
- pyg_current_main_loop = g_main_loop_ref(main_loop);
-
- return retval;
-}
-
-static inline void
-pyg_restore_current_main_loop (GMainLoop *main_loop)
-{
- if (pyg_current_main_loop != NULL)
- g_main_loop_unref(pyg_current_main_loop);
- pyg_current_main_loop = main_loop;
-}
-
-static inline GMainLoop *
-pyg_get_current_main_loop (void)
-{
- return pyg_current_main_loop;
-}
-#else /* !defined(#ifndef DISABLE_THREADING) */
-
-static int pyg_current_main_loop_key = -1;
-
-static inline GMainLoop *
-pyg_save_current_main_loop (GMainLoop *main_loop)
-{
- GMainLoop *retval;
-
- g_return_val_if_fail(main_loop != NULL, NULL);
-
- if (pyg_current_main_loop_key == -1)
- pyg_current_main_loop_key = PyThread_create_key();
-
- retval = PyThread_get_key_value(pyg_current_main_loop_key);
- PyThread_delete_key_value(pyg_current_main_loop_key);
- PyThread_set_key_value(pyg_current_main_loop_key,
- g_main_loop_ref(main_loop));
-
- return retval;
-}
-
-static inline void
-pyg_restore_current_main_loop (GMainLoop *main_loop)
-{
- GMainLoop *prev;
-
- g_return_if_fail (pyg_current_main_loop_key != -1);
-
- prev = PyThread_get_key_value(pyg_current_main_loop_key);
- if (prev != NULL)
- g_main_loop_unref(prev);
- PyThread_delete_key_value(pyg_current_main_loop_key);
- if (main_loop != NULL)
- PyThread_set_key_value(pyg_current_main_loop_key, main_loop);
-}
-
-static inline GMainLoop *
-pyg_get_current_main_loop (void)
-{
- if (pyg_current_main_loop_key == -1)
- return NULL;
- return PyThread_get_key_value(pyg_current_main_loop_key);
-}
-#endif /* DISABLE_THREADING */
-
-static gboolean
-pyg_signal_watch_prepare(GSource *source,
- int *timeout)
-{
- /* Python only invokes signal handlers from the main thread,
- * so if a thread other than the main thread receives the signal
- * from the kernel, PyErr_CheckSignals() from that thread will
- * do nothing.
- */
-
-#ifdef HAVE_PYSIGNAL_SETWAKEUPFD
- return FALSE;
-#else /* !HAVE_PYSIGNAL_SETWAKEUPFD */
- /* On Windows g_poll() won't be interrupted by a signal
- * (AFAIK), so we need the timeout there too, even if there's
- * only one thread.
- */
-#ifndef PLATFORM_WIN32
- if (!pyglib_threads_enabled())
- return FALSE;
-#endif /* PLATFORM_WIN32 */
-
- /* If we're using 2.5 or an earlier version of python we
- * will default to a timeout every second, be aware,
- * this will cause unnecessary wakeups, see
- * http://bugzilla.gnome.org/show_bug.cgi?id=481569
- */
- *timeout = 1000;
- return FALSE;
-#endif /* HAVE_PYSIGNAL_SETWAKEUPFD */
-}
-
-static gboolean
-pyg_signal_watch_check(GSource *source)
-{
- PyGILState_STATE state;
- GMainLoop *main_loop;
-
-#ifdef HAVE_PYSIGNAL_SETWAKEUPFD
- PySignalWatchSource *real_source = (PySignalWatchSource *)source;
- GPollFD *poll_fd = &real_source->fd;
- unsigned char dummy;
- if (poll_fd->revents & G_IO_IN)
- (void) read(poll_fd->fd, &dummy, 1);
-#endif
-
- state = pyglib_gil_state_ensure();
-
- main_loop = pyg_get_current_main_loop();
-
- if (PyErr_CheckSignals() == -1 && main_loop != NULL) {
- PyErr_SetNone(PyExc_KeyboardInterrupt);
- g_main_loop_quit(main_loop);
- }
-
- pyglib_gil_state_release(state);
-
- return FALSE;
-}
-
-static gboolean
-pyg_signal_watch_dispatch(GSource *source,
- GSourceFunc callback,
- gpointer user_data)
-{
- /* We should never be dispatched */
- g_assert_not_reached();
- return TRUE;
-}
-
-static GSourceFuncs pyg_signal_watch_funcs =
-{
- pyg_signal_watch_prepare,
- pyg_signal_watch_check,
- pyg_signal_watch_dispatch
-};
-
-static GSource *
-pyg_signal_watch_new(void)
-{
- GSource *source = g_source_new(&pyg_signal_watch_funcs,
- sizeof(PySignalWatchSource));
-
-#ifdef HAVE_PYSIGNAL_SETWAKEUPFD
- PySignalWatchSource *real_source = (PySignalWatchSource *)source;
- int flag;
-
- /* Unfortunately we need to create a new pipe here instead of
- * reusing the pipe inside the GMainContext.
- * Ideally an api should be added to GMainContext which allows us
- * to reuse that pipe which would suit us perfectly fine.
- * XXX More efficient than a pipe, we could use an eventfd on Linux
- * kernels that support it.
- */
- gint already_piped = (pipe_fds[0] > 0);
- if (!already_piped) {
- if (pipe(pipe_fds) < 0)
- g_error("Cannot create main loop pipe: %s\n",
- g_strerror(errno));
-
- /* Make both ends of the fd non blocking */
- flag = fcntl(pipe_fds[0], F_GETFL, 0);
- flag |= O_NONBLOCK;
- fcntl(pipe_fds[0], F_SETFL, flag);
- flag = fcntl(pipe_fds[1], F_GETFL, 0);
- flag |= O_NONBLOCK;
- fcntl(pipe_fds[1], F_SETFL, flag);
- }
-
- real_source->fd.fd = pipe_fds[0];
- real_source->fd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
- g_source_add_poll(source, &real_source->fd);
-
- if (!already_piped)
- PySignal_SetWakeupFd(pipe_fds[1]);
-#endif
- return source;
-}
-
-PYGLIB_DEFINE_TYPE("gi._glib.MainLoop", PyGMainLoop_Type, PyGMainLoop)
-
-static int
-pyg_main_loop_init(PyGMainLoop *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "context", "is_running", NULL };
- PyObject *py_context = Py_None;
- int is_running = 0;
- GMainContext *context;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "|Ob:GMainLoop.__init__",
- kwlist, &py_context, &is_running))
- return -1;
-
- if (!PyObject_TypeCheck(py_context, &PyGMainContext_Type) &&
- py_context != Py_None) {
- PyErr_SetString(PyExc_TypeError,
- "context must be a gi._glib.MainContext or None");
- return -1;
- }
-
- if (py_context != Py_None) {
- context = ((PyGMainContext*)py_context)->context;
- } else {
- context = NULL;
- }
-
- self->loop = g_main_loop_new(context, is_running);
-
- self->signal_source = pyg_signal_watch_new();
- g_source_attach(self->signal_source, context);
- g_source_unref(self->signal_source);
-
- return 0;
-}
-
-static void
-pyg_main_loop_dealloc(PyGMainLoop *self)
-{
- if (self->signal_source != NULL) {
- g_source_destroy(self->signal_source);
- self->signal_source = NULL;
- }
-
- if (self->loop != NULL) {
- g_main_loop_unref(self->loop);
- self->loop = NULL;
- }
-
- PyObject_Del(self);
-}
-
-static PyObject*
-pyg_main_loop_richcompare(PyObject *self, PyObject *other, int op)
-{
- if (Py_TYPE(self) == Py_TYPE(other) && Py_TYPE(self) == &PyGMainLoop_Type)
- return _pyglib_generic_ptr_richcompare(((PyGMainLoop*)self)->loop,
- ((PyGMainLoop*)other)->loop,
- op);
- else {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
- }
-}
-
-static PyObject *
-_wrap_g_main_loop_get_context (PyGMainLoop *loop)
-{
- return pyg_main_context_new(g_main_loop_get_context(loop->loop));
-}
-
-static PyObject *
-_wrap_g_main_loop_is_running (PyGMainLoop *self)
-{
- return PyBool_FromLong(g_main_loop_is_running(self->loop));
-}
-
-static PyObject *
-_wrap_g_main_loop_quit (PyGMainLoop *self, PyObject *args, PyObject *kwargs)
-{
- g_main_loop_quit(self->loop);
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-_wrap_g_main_loop_run (PyGMainLoop *self)
-{
- GMainLoop *prev_loop;
-
- prev_loop = pyg_save_current_main_loop(self->loop);
-
- pyglib_begin_allow_threads;
- g_main_loop_run(self->loop);
- pyglib_end_allow_threads;
-
- pyg_restore_current_main_loop(prev_loop);
-
- if (PyErr_Occurred())
- return NULL;
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyMethodDef _PyGMainLoop_methods[] = {
- { "get_context", (PyCFunction)_wrap_g_main_loop_get_context, METH_NOARGS },
- { "is_running", (PyCFunction)_wrap_g_main_loop_is_running, METH_NOARGS },
- { "quit", (PyCFunction)_wrap_g_main_loop_quit, METH_VARARGS|METH_KEYWORDS },
- { "run", (PyCFunction)_wrap_g_main_loop_run, METH_NOARGS },
- { NULL, NULL, 0 }
-};
-
-void
-pyglib_mainloop_register_types(PyObject *d)
-{
- PyGMainLoop_Type.tp_dealloc = (destructor)pyg_main_loop_dealloc;
- PyGMainLoop_Type.tp_richcompare = pyg_main_loop_richcompare;
- PyGMainLoop_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
- PyGMainLoop_Type.tp_methods = _PyGMainLoop_methods;
- PyGMainLoop_Type.tp_init = (initproc)pyg_main_loop_init;
- PYGLIB_REGISTER_TYPE(d, PyGMainLoop_Type, "MainLoop");
-}
diff --git a/gi/_glib/pygmainloop.h b/gi/_glib/pygmainloop.h
deleted file mode 100644
index dec82d84..00000000
--- a/gi/_glib/pygmainloop.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*- Mode: C; c-basic-offset: 4 -*-
- * pyglib - Python bindings for GLib toolkit.
- * Copyright (C) 1998-2003 James Henstridge
- * 2004-2008 Johan Dahlin
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
- * USA
- */
-
-#ifndef __PYG_MAINLOOP_H__
-#define __PYG_MAINLOOP_H__
-
-typedef struct {
- PyObject_HEAD
- GMainLoop *loop;
- GSource *signal_source;
-} PyGMainLoop;
-
-extern PyTypeObject PyGMainLoop_Type;
-
-void pyglib_mainloop_register_types(PyObject *d);
-
-#endif /* __PYG_MAINLOOP_H__ */
-
diff --git a/gi/_glib/pygsource.c b/gi/_glib/pygsource.c
index d11f4745..5a333c4e 100644
--- a/gi/_glib/pygsource.c
+++ b/gi/_glib/pygsource.c
@@ -28,624 +28,11 @@
#endif
#include <Python.h>
-#include <pythread.h>
#include <structmember.h> /* for PyMemberDef */
#include "pyglib.h"
#include "pyglib-private.h"
-#include "pygmaincontext.h"
#include "pygsource.h"
-#define CHECK_DESTROYED(self, ret) G_STMT_START { \
- if ((self)->source == NULL) { \
- PyErr_SetString(PyExc_RuntimeError, "source is destroyed"); \
- return (ret); \
- } \
-} G_STMT_END
-
-
-typedef struct {
- PyObject_HEAD
- GSource *source;
- PyObject *inst_dict;
- PyObject *weakreflist;
- gboolean python_source;
-} PyGSource;
-
-typedef struct
-{
- GSource source;
- PyObject *obj;
-} PyGRealSource;
-
-/* glib.Source */
-
-PYGLIB_DEFINE_TYPE("gi._glib.Source", PyGSource_Type, PyGSource)
-
-static PyObject *
-source_repr(PyGSource *self, const char *type)
-{
- gchar buf[256], *desc;
-
- if (self->source) {
- if (g_source_get_context(self->source))
- desc = "attached";
- else
- desc = "unattached";
- } else {
- desc = "destroyed";
- }
-
- if (type)
- g_snprintf(buf, sizeof(buf), "<%s glib %s source at 0x%lx>",
- desc, type, (long) self);
- else
- g_snprintf(buf, sizeof(buf), "<%s glib source at 0x%lx>",
- desc, (long) self);
-
- return PYGLIB_PyUnicode_FromString(buf);
-}
-
-static PyObject *
-pyg_source_attach(PyGSource *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "context", NULL };
- PyGMainContext *py_context = NULL;
- GMainContext *context = NULL;
- guint id;
-
- if (!PyArg_ParseTupleAndKeywords (args, kwargs,
- "|O!:attach", kwlist,
- &PyGMainContext_Type, &py_context))
- return NULL;
-
- if (py_context)
- context = py_context->context;
-
- CHECK_DESTROYED(self, NULL);
-
- if (self->python_source) {
- PyGRealSource *pysource = (PyGRealSource *)self->source;
- Py_INCREF(pysource->obj);
- }
-
- id = g_source_attach(self->source, context);
- return PYGLIB_PyLong_FromLong(id);
-}
-
-static PyObject *
-pyg_source_destroy(PyGSource *self)
-{
- CHECK_DESTROYED(self, NULL);
-
- if (self->python_source && self->source->context) {
- PyGRealSource *pysource = (PyGRealSource *)self->source;
- Py_DECREF(pysource->obj);
- }
-
- g_source_destroy(self->source);
- self->source = NULL;
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-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;
- gint len;
-
- CHECK_DESTROYED(self, NULL);
-
- len = PyTuple_Size (args);
- if (len < 1) {
- PyErr_SetString(PyExc_TypeError,
- "set_callback requires at least 1 argument");
- return NULL;
- }
-
- first = PySequence_GetSlice(args, 0, 1);
- if (!PyArg_ParseTuple(first, "O:set_callback", &callback)) {
- Py_DECREF (first);
- return NULL;
- }
- Py_DECREF(first);
-
- if (!PyCallable_Check(callback)) {
- PyErr_SetString(PyExc_TypeError, "first argument not callable");
- return NULL;
- }
-
- cbargs = PySequence_GetSlice(args, 1, len);
- if (cbargs == NULL)
- return NULL;
-
- data = Py_BuildValue("(ON)", callback, cbargs);
- if (data == NULL)
- return NULL;
-
- g_source_set_callback(self->source,
- _pyglib_handler_marshal, data,
- _pyglib_destroy_notify);
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-pyg_source_get_context(PyGSource *self)
-{
- GMainContext *context;
-
- CHECK_DESTROYED(self, NULL);
-
- context = g_source_get_context(self->source);
-
- if (context) {
- return pyg_main_context_new(context);
- } else {
- Py_INCREF(Py_None);
- return Py_None;
- }
-}
-
-static PyObject *
-pyg_source_add_poll(PyGSource *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "fd", NULL };
- PyGPollFD *fd;
-
- if (!self->python_source) {
- PyErr_SetString(PyExc_TypeError,
- "add_poll can only be used with sources "
- "implemented in python");
- return NULL;
- }
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "O!:add_poll", kwlist,
- &PyGPollFD_Type, &fd))
- return NULL;
-
- CHECK_DESTROYED(self, NULL);
-
- g_source_add_poll(self->source, &fd->pollfd);
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-pyg_source_remove_poll(PyGSource *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "fd", NULL };
- PyGPollFD *fd;
-
- if (!self->python_source) {
- PyErr_SetString(PyExc_TypeError,
- "remove_poll can only be used with sources "
- "implemented in python");
- return NULL;
- }
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "O!:remove_poll", kwlist,
- &PyGPollFD_Type, &fd))
- return NULL;
-
- CHECK_DESTROYED(self, NULL);
-
- g_source_remove_poll(self->source, &fd->pollfd);
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-pyg_source_get_current_time(PyGSource *self)
-{
- double ret;
-
- CHECK_DESTROYED(self, NULL);
-
- ret = g_get_real_time() * 0.000001;
- return PyFloat_FromDouble(ret);
-}
-
-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 },
- { "remove_poll", (PyCFunction)pyg_source_remove_poll, METH_VARARGS|METH_KEYWORDS },
- { "get_current_time", (PyCFunction)pyg_source_get_current_time, METH_NOARGS },
- { NULL, NULL, 0 }
-};
-
-static PyObject *
-pyg_source_get_dict(PyGSource *self, void *closure)
-{
- if (self->inst_dict == NULL) {
- self->inst_dict = PyDict_New();
- if (self->inst_dict == NULL)
- return NULL;
- }
-
- Py_INCREF(self->inst_dict);
- return self->inst_dict;
-}
-
-static PyObject *
-pyg_source_get_priority(PyGSource *self, void *closure)
-{
- CHECK_DESTROYED(self, NULL);
-
- return PYGLIB_PyLong_FromLong(g_source_get_priority(self->source));
-}
-
-static int
-pyg_source_set_priority(PyGSource *self, PyObject *value, void *closure)
-{
- CHECK_DESTROYED(self, -1);
-
- if (value == NULL) {
- PyErr_SetString(PyExc_TypeError, "cannot delete priority");
- return -1;
- }
-
- if (!PYGLIB_PyLong_Check(value)) {
- PyErr_SetString(PyExc_TypeError, "type mismatch");
- return -1;
- }
-
- g_source_set_priority(self->source, PYGLIB_PyLong_AsLong(value));
-
- return 0;
-}
-
-static PyObject *
-pyg_source_get_can_recurse(PyGSource *self, void *closure)
-{
- CHECK_DESTROYED(self, NULL);
-
- return PyBool_FromLong(g_source_get_can_recurse(self->source));
-}
-
-static int
-pyg_source_set_can_recurse(PyGSource *self, PyObject *value, void *closure)
-{
- CHECK_DESTROYED(self, -1);
-
- if (value == NULL) {
- PyErr_SetString(PyExc_TypeError, "cannot delete can_recurse");
- return -1;
- }
-
- g_source_set_can_recurse(self->source, PyObject_IsTrue(value));
-
- return 0;
-}
-
-static PyObject *
-pyg_source_get_id(PyGSource *self, void *closure)
-{
- CHECK_DESTROYED(self, NULL);
-
- if (g_source_get_context(self->source) == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "source is not attached");
- return NULL;
- }
-
- return PYGLIB_PyLong_FromLong(g_source_get_id(self->source));
-}
-
-static PyGetSetDef pyg_source_getsets[] = {
- { "__dict__", (getter)pyg_source_get_dict, (setter)0 },
- {"priority", (getter)pyg_source_get_priority, (setter)pyg_source_set_priority },
- {"can_recurse", (getter)pyg_source_get_can_recurse, (setter)pyg_source_set_can_recurse },
- {"id", (getter)pyg_source_get_id, (setter)0 },
- {NULL, 0, 0}
-};
-
-static PyObject *
-pyg_source_repr(PyGSource *self)
-{
- return source_repr(self, NULL);
-}
-
-static int
-pyg_source_traverse(PyGSource *self, visitproc visit, void *arg)
-{
- int ret = 0;
-
- if (self->inst_dict) ret = visit(self->inst_dict, arg);
- if (ret != 0) return ret;
-
- return 0;
-}
-
-static int
-pyg_source_clear(PyGSource *self)
-{
- PyObject *tmp;
-
- tmp = self->inst_dict;
- self->inst_dict = NULL;
- Py_XDECREF(tmp);
-
- if (self->source) {
- g_source_unref(self->source);
- self->source = NULL;
- }
-
- return 0;
-}
-
-static void
-pyg_source_dealloc(PyGSource *self)
-{
- /* Must be done first, so that there is no chance of Python's GC being
- * called while tracking this half-deallocated object */
- PyObject_GC_UnTrack((PyObject *)self);
-
- PyObject_ClearWeakRefs((PyObject *)self);
-
- pyg_source_clear(self);
-
- PyObject_GC_Del(self);
-}
-
-static gboolean
-pyg_source_prepare(GSource *source, gint *timeout)
-{
- PyGRealSource *pysource = (PyGRealSource *)source;
- PyObject *t;
- gboolean ret = FALSE;
- gboolean got_err = TRUE;
- PyGILState_STATE state;
-
- state = pyglib_gil_state_ensure();
-
- t = PyObject_CallMethod(pysource->obj, "prepare", NULL);
-
- if (t == NULL) {
- goto bail;
- } else if (!PyObject_IsTrue(t)) {
- got_err = FALSE;
- goto bail;
- } else if (!PyTuple_Check(t)) {
- PyErr_SetString(PyExc_TypeError,
- "source prepare function must return a tuple or False");
- goto bail;
- } else if (PyTuple_Size(t) != 2) {
- PyErr_SetString(PyExc_TypeError,
- "source prepare function return tuple must be exactly "
- "2 elements long");
- goto bail;
- }
-
- ret = PyObject_IsTrue(PyTuple_GET_ITEM(t, 0));
- *timeout = PYGLIB_PyLong_AsLong(PyTuple_GET_ITEM(t, 1));
-
- if (*timeout == -1 && PyErr_Occurred()) {
- ret = FALSE;
- goto bail;
- }
-
- got_err = FALSE;
-
-bail:
- if (got_err)
- PyErr_Print();
-
- Py_XDECREF(t);
-
- pyglib_gil_state_release(state);
-
- return ret;
-}
-
-static gboolean
-pyg_source_check(GSource *source)
-{
- PyGRealSource *pysource = (PyGRealSource *)source;
- PyObject *t;
- gboolean ret;
- PyGILState_STATE state;
-
- state = pyglib_gil_state_ensure();
-
- t = PyObject_CallMethod(pysource->obj, "check", NULL);
-
- if (t == NULL) {
- PyErr_Print();
- ret = FALSE;
- } else {
- ret = PyObject_IsTrue(t);
- Py_DECREF(t);
- }
-
- pyglib_gil_state_release(state);
-
- return ret;
-}
-
-static gboolean
-pyg_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
-{
- PyGRealSource *pysource = (PyGRealSource *)source;
- PyObject *func, *args, *tuple, *t;
- gboolean ret;
- PyGILState_STATE state;
-
- state = pyglib_gil_state_ensure();
-
- if (callback) {
- tuple = user_data;
-
- func = PyTuple_GetItem(tuple, 0);
- args = PyTuple_GetItem(tuple, 1);
- } else {
- func = Py_None;
- args = Py_None;
- }
-
- t = PyObject_CallMethod(pysource->obj, "dispatch", "OO", func, args);
-
- if (t == NULL) {
- PyErr_Print();
- ret = FALSE;
- } else {
- ret = PyObject_IsTrue(t);
- Py_DECREF(t);
- }
-
- pyglib_gil_state_release(state);
-
- return ret;
-}
-
-static void
-pyg_source_finalize(GSource *source)
-{
- PyGRealSource *pysource = (PyGRealSource *)source;
- PyObject *func, *t;
- PyGILState_STATE state;
-
- state = pyglib_gil_state_ensure();
-
- func = PyObject_GetAttrString(pysource->obj, "finalize");
- if (func) {
- t = PyObject_CallObject(func, NULL);
- Py_DECREF(func);
-
- if (t == NULL) {
- PyErr_Print();
- } else {
- Py_DECREF(t);
- }
- }
-
- pyglib_gil_state_release(state);
-}
-
-static GSourceFuncs pyg_source_funcs =
-{
- pyg_source_prepare,
- pyg_source_check,
- pyg_source_dispatch,
- pyg_source_finalize
-};
-
-static int
-pyg_source_init(PyGSource *self, PyObject *args, PyObject *kwargs)
-{
- PyGRealSource *pysource;
-
- self->source = g_source_new(&pyg_source_funcs, sizeof(PyGRealSource));
-
- pysource = (PyGRealSource *)self->source;
- pysource->obj = (PyObject*)self;
-
- self->inst_dict = NULL;
- self->weakreflist = NULL;
-
- self->python_source = TRUE;
-
- return 0;
-}
-
-static void
-pyg_source_free(PyObject *op)
-{
- PyObject_GC_Del(op);
-}
-
-/* glib.Idle */
-
-PYGLIB_DEFINE_TYPE("gi._glib.Idle", PyGIdle_Type, PyGSource)
-
-static PyObject *
-pyg_idle_repr(PyGSource *self)
-{
- return source_repr(self, "idle");
-}
-
-static int
-pyg_idle_init(PyGSource *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "priority", NULL };
- gint priority = G_PRIORITY_DEFAULT_IDLE;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "|i:gi._glib.Idle.__init__", kwlist,
- &priority))
- return -1;
-
- self->source = g_idle_source_new ();
-
- if (priority != G_PRIORITY_DEFAULT_IDLE)
- g_source_set_priority(self->source, priority);
-
- self->inst_dict = NULL;
- self->weakreflist = NULL;
-
- self->python_source = FALSE;
-
- return 0;
-}
-
-/* glib.Timeout */
-
-PYGLIB_DEFINE_TYPE("gi._glib.Timeout", PyGTimeout_Type, PyGSource)
-
-static PyObject *
-pyg_timeout_repr(PyGSource *self)
-{
- return source_repr(self, "timeout");
-}
-
-static int
-pyg_timeout_init(PyGSource *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "interval", "priority", NULL };
- gint priority = G_PRIORITY_DEFAULT;
- guint interval;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "I|i:gi._glib.Timeout.__init__", kwlist,
- &interval, &priority))
- return -1;
-
- self->source = g_timeout_source_new(interval);
-
- if (priority != G_PRIORITY_DEFAULT)
- g_source_set_priority(self->source, priority);
-
- self->inst_dict = NULL;
- self->weakreflist = NULL;
-
- self->python_source = FALSE;
-
- return 0;
-}
-
/* glib.PollFD */
PYGLIB_DEFINE_TYPE("gi._glib.PollFD", PyGPollFD_Type, PyGPollFD)
@@ -702,33 +89,6 @@ pyg_poll_fd_init(PyGPollFD *self, PyObject *args, PyObject *kwargs)
void
pyglib_source_register_types(PyObject *d)
{
- PyGSource_Type.tp_flags = (Py_TPFLAGS_DEFAULT |
- Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_HAVE_GC);
- PyGSource_Type.tp_init = (initproc)pyg_source_init;
- PyGSource_Type.tp_free = (freefunc)pyg_source_free;
- PyGSource_Type.tp_dealloc = (destructor)pyg_source_dealloc;
- PyGSource_Type.tp_methods = pyg_source_methods;
- PyGSource_Type.tp_repr = (reprfunc)pyg_source_repr;
- PyGSource_Type.tp_traverse = (traverseproc)pyg_source_traverse;
- PyGSource_Type.tp_clear = (inquiry)pyg_source_clear;
- PyGSource_Type.tp_getset = pyg_source_getsets;
- PyGSource_Type.tp_weaklistoffset = offsetof(PyGSource, weakreflist);
- PyGSource_Type.tp_dictoffset = offsetof(PyGSource, inst_dict);
- PYGLIB_REGISTER_TYPE(d, PyGSource_Type, "Source");
-
- PyGIdle_Type.tp_repr = (reprfunc)pyg_idle_repr;
- PyGIdle_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
- PyGIdle_Type.tp_base = (PyTypeObject *)&PyGSource_Type;
- PyGIdle_Type.tp_init = (initproc)pyg_idle_init;
- PYGLIB_REGISTER_TYPE(d, PyGIdle_Type, "Idle");
-
- PyGTimeout_Type.tp_repr = (reprfunc)pyg_timeout_repr;
- PyGTimeout_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
- PyGTimeout_Type.tp_base = (PyTypeObject *)&PyGSource_Type;
- PyGTimeout_Type.tp_init = (initproc)pyg_timeout_init;
- PYGLIB_REGISTER_TYPE(d, PyGTimeout_Type, "Timeout");
-
PyGPollFD_Type.tp_dealloc = (destructor)pyg_poll_fd_dealloc;
PyGPollFD_Type.tp_repr = (reprfunc)pyg_poll_fd_repr;
PyGPollFD_Type.tp_flags = Py_TPFLAGS_DEFAULT;
diff --git a/gi/_glib/pygsource.h b/gi/_glib/pygsource.h
index bf2c673f..dbae9ac5 100644
--- a/gi/_glib/pygsource.h
+++ b/gi/_glib/pygsource.h
@@ -22,9 +22,6 @@
#ifndef __PYG_SOURCE_H__
#define __PYG_SOURCE_H__
-extern PyTypeObject PyGSource_Type;
-extern PyTypeObject PyGIdle_Type;
-extern PyTypeObject PyGTimeout_Type;
extern PyTypeObject PyGPollFD_Type;
typedef struct
diff --git a/gi/_gobject/__init__.py b/gi/_gobject/__init__.py
index ba6f7def..2098d273 100644
--- a/gi/_gobject/__init__.py
+++ b/gi/_gobject/__init__.py
@@ -86,21 +86,13 @@ idle_add = _glib.idle_add
timeout_add = _glib.timeout_add
timeout_add_seconds = _glib.timeout_add_seconds
io_add_watch = _glib.io_add_watch
-source_remove = _glib.source_remove
child_watch_add = _glib.child_watch_add
get_current_time = _glib.get_current_time
filename_from_utf8 = _glib.filename_from_utf8
Pid = _glib.Pid
GError = _glib.GError
glib_version = _glib.glib_version
-MainLoop = _glib.MainLoop
-MainContext = _glib.MainContext
-main_context_default = _glib.main_context_default
IOChannel = _glib.IOChannel
-Source = _glib.Source
-Idle = _glib.Idle
-Timeout = _glib.Timeout
-PollFD = _glib.PollFD
OptionGroup = _glib.OptionGroup
OptionContext = _glib.OptionContext
@@ -111,11 +103,6 @@ SPAWN_STDOUT_TO_DEV_NULL = _glib.SPAWN_STDOUT_TO_DEV_NULL
SPAWN_STDERR_TO_DEV_NULL = _glib.SPAWN_STDERR_TO_DEV_NULL
SPAWN_CHILD_INHERITS_STDIN = _glib.SPAWN_CHILD_INHERITS_STDIN
SPAWN_FILE_AND_ARGV_ZERO = _glib.SPAWN_FILE_AND_ARGV_ZERO
-PRIORITY_HIGH = _glib.PRIORITY_HIGH
-PRIORITY_DEFAULT = _glib.PRIORITY_DEFAULT
-PRIORITY_HIGH_IDLE = _glib.PRIORITY_HIGH_IDLE
-PRIORITY_DEFAULT_IDLE = _glib.PRIORITY_DEFAULT_IDLE
-PRIORITY_LOW = _glib.PRIORITY_LOW
IO_IN = _glib.IO_IN
IO_OUT = _glib.IO_OUT
IO_PRI = _glib.IO_PRI
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 6ccd87fe..fcab4681 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -455,6 +455,13 @@ _wrap_pyg_variant_type_from_string (PyObject *self, PyObject *args)
return py_variant;
}
+static PyObject *
+_wrap_pyg_source_new (PyObject *self, PyObject *args)
+{
+ return pyg_source_new ();
+}
+
+
static PyMethodDef _gi_functions[] = {
{ "enum_add", (PyCFunction) _wrap_pyg_enum_add, METH_VARARGS | METH_KEYWORDS },
{ "enum_register_new_gtype_and_add", (PyCFunction) _wrap_pyg_enum_register_new_gtype_and_add, METH_VARARGS | METH_KEYWORDS },
@@ -465,6 +472,8 @@ static PyMethodDef _gi_functions[] = {
{ "hook_up_vfunc_implementation", (PyCFunction) _wrap_pyg_hook_up_vfunc_implementation, METH_VARARGS },
{ "variant_new_tuple", (PyCFunction) _wrap_pyg_variant_new_tuple, METH_VARARGS },
{ "variant_type_from_string", (PyCFunction) _wrap_pyg_variant_type_from_string, METH_VARARGS },
+ { "source_new", (PyCFunction) _wrap_pyg_source_new, METH_NOARGS },
+ { "source_set_callback", (PyCFunction) pyg_source_set_callback, METH_VARARGS },
{ NULL, NULL, 0 }
};
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 3dcc618f..0969cf04 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -19,8 +19,11 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
+import signal
+
from ..importer import modules
-from .._gi import variant_new_tuple, variant_type_from_string
+from .._gi import variant_new_tuple, variant_type_from_string, source_new, source_set_callback
+from ..overrides import override
GLib = modules['GLib']._introspection_module
@@ -422,3 +425,114 @@ for n in ['DESKTOP', 'DOCUMENTS', 'DOWNLOAD', 'MUSIC', 'PICTURES',
'PUBLIC_SHARE', 'TEMPLATES', 'VIDEOS']:
exec('USER_DIRECTORY_%s = GLib.UserDirectory.DIRECTORY_%s' % (n, n))
__all__.append('USER_DIRECTORY_' + n)
+
+
+class MainLoop(GLib.MainLoop):
+ # Backwards compatible constructor API
+ def __new__(cls, context=None):
+ return GLib.MainLoop.new(context, False)
+
+ # Retain classic pygobject behaviour of quitting main loops on SIGINT
+ def __init__(self, context=None):
+ def _handler(loop):
+ loop.quit()
+ loop._quit_by_sigint = True
+
+ self._signal_source = GLib.unix_signal_add_full(
+ GLib.PRIORITY_DEFAULT, signal.SIGINT, _handler, self)
+
+ def __del__(self):
+ GLib.source_remove(self._signal_source)
+
+ def run(self):
+ super(MainLoop, self).run()
+ if hasattr(self, '_quit_by_sigint'):
+ # caught by _main_loop_sigint_handler()
+ raise KeyboardInterrupt
+
+MainLoop = override(MainLoop)
+__all__.append('MainLoop')
+
+
+class MainContext(GLib.MainContext):
+ # Backwards compatible API with default value
+ def iteration(self, may_block=True):
+ return super(MainContext, self).iteration(may_block)
+
+MainContext = override(MainContext)
+__all__.append('MainContext')
+
+
+class Source(GLib.Source):
+ def __new__(cls):
+ # use our custom pyg_source_new() here as g_source_new() is not
+ # bindable
+ source = source_new()
+ source.__class__ = cls
+ setattr(source, '__pygi_custom_source', True)
+ return source
+
+ # Backwards compatible API for optional arguments
+ def attach(self, context=None):
+ id = super(Source, self).attach(context)
+ return id
+
+ def set_callback(self, fn, user_data=None):
+ if hasattr(self, '__pygi_custom_source'):
+ # use our custom pyg_source_set_callback() if for a GSource object
+ # with custom functions
+ source_set_callback(self, fn, user_data)
+ else:
+ # otherwise, for Idle and Timeout, use the standard method
+ super(Source, self).set_callback(fn, user_data)
+
+ def get_current_time(self):
+ return GLib.get_real_time() * 0.000001
+
+ # as get/set_priority are introspected, we can't use the static
+ # property(get_priority, ..) here
+ def __get_priority(self):
+ return self.get_priority()
+
+ def __set_priority(self, value):
+ self.set_priority(value)
+
+ priority = property(__get_priority, __set_priority)
+
+ def __get_can_recurse(self):
+ return self.get_can_recurse()
+
+ def __set_can_recurse(self, value):
+ self.set_can_recurse(value)
+
+ can_recurse = property(__get_can_recurse, __set_can_recurse)
+
+Source = override(Source)
+__all__.append('Source')
+
+
+class Idle(Source):
+ def __new__(cls, priority=GLib.PRIORITY_DEFAULT):
+ source = GLib.idle_source_new()
+ source.__class__ = cls
+ return source
+
+ def __init__(self, priority=GLib.PRIORITY_DEFAULT):
+ super(Source, self).__init__()
+ if priority != GLib.PRIORITY_DEFAULT:
+ self.set_priority(priority)
+
+__all__.append('Idle')
+
+
+class Timeout(Source):
+ def __new__(cls, interval=0, priority=GLib.PRIORITY_DEFAULT):
+ source = GLib.timeout_source_new(interval)
+ source.__class__ = cls
+ return source
+
+ def __init__(self, interval=0, priority=GLib.PRIORITY_DEFAULT):
+ if priority != GLib.PRIORITY_DEFAULT:
+ self.set_priority(priority)
+
+__all__.append('Timeout')
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 3af4d442..e65de7ec 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -27,6 +27,14 @@ __all__ = []
for name in ['markup_escape_text', 'get_application_name',
'set_application_name', 'get_prgname', 'set_prgname',
'main_depth', 'filename_display_basename',
- 'filename_display_name', 'uri_list_extract_uris']:
+ 'filename_display_name', 'uri_list_extract_uris',
+ 'MainLoop', 'MainContext', 'main_context_default',
+ 'source_remove', 'Source', 'Idle', 'Timeout', 'PollFD']:
+ globals()[name] = getattr(GLib, name)
+ __all__.append(name)
+
+# constants are also deprecated, but cannot mark them as such
+for name in ['PRIORITY_DEFAULT', 'PRIORITY_DEFAULT_IDLE', 'PRIORITY_HIGH',
+ 'PRIORITY_HIGH_IDLE', 'PRIORITY_LOW']:
globals()[name] = getattr(GLib, name)
__all__.append(name)
diff --git a/gi/pygi-private.h b/gi/pygi-private.h
index 29ec131b..b8ef1751 100644
--- a/gi/pygi-private.h
+++ b/gi/pygi-private.h
@@ -32,6 +32,7 @@
#include "pygi-signal-closure.h"
#include "pygi-invoke.h"
#include "pygi-cache.h"
+#include "pygi-source.h"
G_BEGIN_DECLS
#if PY_VERSION_HEX >= 0x03000000
diff --git a/gi/pygi-source.c b/gi/pygi-source.c
new file mode 100644
index 00000000..1825a186
--- /dev/null
+++ b/gi/pygi-source.c
@@ -0,0 +1,247 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 1998-2003 James Henstridge
+ * Copyright (C) 2005 Oracle
+ * Copyright (c) 2012 Canonical Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "pygobject.h"
+
+#include "pygi-private.h"
+#include "pyglib.h"
+#include "pyglib-private.h"
+#include "pygi-source.h"
+
+typedef struct
+{
+ GSource source;
+ PyObject *obj;
+} PyGRealSource;
+
+static gboolean
+pyg_source_prepare(GSource *source, gint *timeout)
+{
+ PyGRealSource *pysource = (PyGRealSource *)source;
+ PyObject *t;
+ gboolean ret = FALSE;
+ gboolean got_err = TRUE;
+ PyGILState_STATE state;
+
+ state = pyglib_gil_state_ensure();
+
+ t = PyObject_CallMethod(pysource->obj, "prepare", NULL);
+
+ if (t == NULL) {
+ goto bail;
+ } else if (!PyObject_IsTrue(t)) {
+ got_err = FALSE;
+ goto bail;
+ } else if (!PyTuple_Check(t)) {
+ PyErr_SetString(PyExc_TypeError,
+ "source prepare function must return a tuple or False");
+ goto bail;
+ } else if (PyTuple_Size(t) != 2) {
+ PyErr_SetString(PyExc_TypeError,
+ "source prepare function return tuple must be exactly "
+ "2 elements long");
+ goto bail;
+ }
+
+ ret = PyObject_IsTrue(PyTuple_GET_ITEM(t, 0));
+ *timeout = PYGLIB_PyLong_AsLong(PyTuple_GET_ITEM(t, 1));
+
+ if (*timeout == -1 && PyErr_Occurred()) {
+ ret = FALSE;
+ goto bail;
+ }
+
+ got_err = FALSE;
+
+bail:
+ if (got_err)
+ PyErr_Print();
+
+ Py_XDECREF(t);
+
+ pyglib_gil_state_release(state);
+
+ return ret;
+}
+
+static gboolean
+pyg_source_check(GSource *source)
+{
+ PyGRealSource *pysource = (PyGRealSource *)source;
+ PyObject *t;
+ gboolean ret;
+ PyGILState_STATE state;
+
+ state = pyglib_gil_state_ensure();
+
+ t = PyObject_CallMethod(pysource->obj, "check", NULL);
+
+ if (t == NULL) {
+ PyErr_Print();
+ ret = FALSE;
+ } else {
+ ret = PyObject_IsTrue(t);
+ Py_DECREF(t);
+ }
+
+ pyglib_gil_state_release(state);
+
+ return ret;
+}
+
+static gboolean
+pyg_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
+{
+ PyGRealSource *pysource = (PyGRealSource *)source;
+ PyObject *func, *args, *tuple, *t;
+ gboolean ret;
+ PyGILState_STATE state;
+
+ state = pyglib_gil_state_ensure();
+
+ if (callback) {
+ tuple = user_data;
+
+ func = PyTuple_GetItem(tuple, 0);
+ args = PyTuple_GetItem(tuple, 1);
+ } else {
+ func = Py_None;
+ args = Py_None;
+ }
+
+ t = PyObject_CallMethod(pysource->obj, "dispatch", "OO", func, args);
+
+ if (t == NULL) {
+ PyErr_Print();
+ ret = FALSE;
+ } else {
+ ret = PyObject_IsTrue(t);
+ Py_DECREF(t);
+ }
+
+ pyglib_gil_state_release(state);
+
+ return ret;
+}
+
+static void
+pyg_source_finalize(GSource *source)
+{
+ PyGRealSource *pysource = (PyGRealSource *)source;
+ PyObject *func, *t;
+ PyGILState_STATE state;
+
+ state = pyglib_gil_state_ensure();
+
+ func = PyObject_GetAttrString(pysource->obj, "finalize");
+ if (func) {
+ t = PyObject_CallObject(func, NULL);
+ Py_DECREF(func);
+
+ if (t == NULL) {
+ PyErr_Print();
+ } else {
+ Py_DECREF(t);
+ }
+ }
+
+ pyglib_gil_state_release(state);
+}
+
+static GSourceFuncs pyg_source_funcs =
+{
+ pyg_source_prepare,
+ pyg_source_check,
+ pyg_source_dispatch,
+ pyg_source_finalize
+};
+
+PyObject *
+pyg_source_set_callback(PyGObject *self_module, PyObject *args)
+{
+ PyObject *self, *first, *callback, *cbargs = NULL, *data;
+ PyObject *source_py_type;
+ gint len;
+
+ len = PyTuple_Size (args);
+ if (len < 2) {
+ PyErr_SetString(PyExc_TypeError,
+ "set_callback requires at least 2 arguments");
+ return NULL;
+ }
+
+ first = PySequence_GetSlice(args, 0, 2);
+ if (!PyArg_ParseTuple(first, "OO:set_callback", &self, &callback)) {
+ Py_DECREF (first);
+ return NULL;
+ }
+ Py_DECREF(first);
+
+ source_py_type = _pygi_type_import_by_name ("GLib", "Source");
+ if (!pyg_boxed_check (self, G_TYPE_SOURCE)) {
+ PyErr_SetString(PyExc_TypeError, "first argument is not a GLib.Source");
+ return NULL;
+ }
+
+ if (!PyCallable_Check(callback)) {
+ PyErr_SetString(PyExc_TypeError, "second argument not callable");
+ return NULL;
+ }
+
+ cbargs = PySequence_GetSlice(args, 2, len);
+ if (cbargs == NULL)
+ return NULL;
+
+ data = Py_BuildValue("(ON)", callback, cbargs);
+ if (data == NULL)
+ return NULL;
+
+ g_source_set_callback(pyg_boxed_get (self, GSource),
+ _pyglib_handler_marshal, data,
+ _pyglib_destroy_notify);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+/**
+ * pyg_source_new:
+ *
+ * Wrap the un-bindable g_source_new() and provide wrapper callbacks in the
+ * GSourceFuncs which call back to Python.
+ */
+PyObject*
+pyg_source_new ()
+{
+ PyGRealSource *source = NULL;
+ PyObject *py_type;
+
+ source = (PyGRealSource*) g_source_new (&pyg_source_funcs, sizeof (PyGRealSource));
+
+ py_type = _pygi_type_import_by_name ("GLib", "Source");
+ source->obj = _pygi_boxed_new ( (PyTypeObject *) py_type, source, FALSE);
+
+ return source->obj;
+}
diff --git a/gi/pygi-source.h b/gi/pygi-source.h
new file mode 100644
index 00000000..024cf15b
--- /dev/null
+++ b/gi/pygi-source.h
@@ -0,0 +1,31 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (c) 2012 Canonical Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __PYGI_SOURCE_H__
+#define __PYGI_SOURCE_H__
+
+PyObject *pyg_source_new ();
+PyObject *pyg_source_set_callback (PyGObject *self, PyObject *args);
+
+#endif /* __PYGI_SOURCE_H__ */
+
diff --git a/tests/test_glib.py b/tests/test_glib.py
index 4058faea..21df3186 100644
--- a/tests/test_glib.py
+++ b/tests/test_glib.py
@@ -72,16 +72,32 @@ https://my.org/q?x=1&y=2
self.assertFalse(ml.is_running())
context = ml.get_context()
- self.assertFalse(context.pending())
+ self.assertEqual(context, GLib.MainContext.default())
+ self.assertTrue(context.is_owner() in [True, False])
+ self.assertTrue(context.pending() in [True, False])
self.assertFalse(context.iteration(False))
+ def test_main_loop_with_context(self):
+ context = GLib.MainContext()
+ ml = GLib.MainLoop(context)
+ self.assertFalse(ml.is_running())
+ self.assertEqual(ml.get_context(), context)
+
def test_main_context(self):
# constructor
context = GLib.MainContext()
+ self.assertTrue(context.is_owner() in [True, False])
self.assertFalse(context.pending())
self.assertFalse(context.iteration(False))
+ # GLib API
+ context = GLib.MainContext.default()
+ self.assertTrue(context.is_owner() in [True, False])
+ self.assertTrue(context.pending() in [True, False])
+ self.assertTrue(context.iteration(False) in [True, False])
+
# backwards compatible API
context = GLib.main_context_default()
- self.assertFalse(context.pending())
- self.assertFalse(context.iteration(False))
+ self.assertTrue(context.is_owner() in [True, False])
+ self.assertTrue(context.pending() in [True, False])
+ self.assertTrue(context.iteration(False) in [True, False])
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index de4fc7a9..82bdff98 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -30,6 +30,8 @@ class TestGObjectAPI(unittest.TestCase):
context = GObject.MainContext()
self.assertFalse(context.pending())
+ self.assertLess(GObject.PRIORITY_HIGH, GObject.PRIORITY_DEFAULT)
+
class TestReferenceCounting(unittest.TestCase):
def testRegularObject(self):
diff --git a/tests/test_source.py b/tests/test_source.py
index 98bb0ce6..d77060f3 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -163,9 +163,6 @@ class TestSource(unittest.TestCase):
self.assertGreater(time, 1300000000.0)
self.assertLess(time, 2000000000.0)
- # currently broken with Python 3,
- # https://bugzilla.gnome.org/show_bug.cgi?id=686443
- @unittest.expectedFailure
def testAddRemovePoll(self):
# FIXME: very shallow test, only verifies the API signature
pollfd = GLib.PollFD(99, GLib.IO_IN | GLib.IO_HUP)