summaryrefslogtreecommitdiff
path: root/docs/reference/pygtk-gobject-mainloop.xml
blob: 41454038682a2a511977ad2f7ac4ba16222d21e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?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-gobjectmainloop">
  <refnamediv>
    <refname>gobject.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>gobject.MainLoop</classname></ooclass>
<constructorsynopsis language="python">
    <methodname><link linkend="constructor-gobjectmainloop">gobject.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-gobjectmainloop--get-context">get_context</link></methodname>
  </methodsynopsis>
<methodsynopsis language="python">
    <methodname><link linkend="method-gobjectmainloop--is-running">is_running</link></methodname>
  </methodsynopsis>
<methodsynopsis language="python">
    <methodname><link linkend="method-gobjectmainloop--quit">quit</link></methodname>
  </methodsynopsis>
<methodsynopsis language="python">
    <methodname><link linkend="method-gobjectmainloop--run">run</link></methodname>
  </methodsynopsis>
</classsynopsis>

</refsect1>

  <refsect1>
    <title>Ancestry</title>

<synopsis>+-- <link linkend="class-gobjectmainloop">gobject.MainLoop</link>
</synopsis>

  </refsect1>

  <refsect1>
    <title>Description</title>

    <para><link
linkend="class-gobjectmainloop"><classname>gobject.MainLoop</classname></link>
represents a main event loop. A <link
linkend="class-gobjectmainloop"><classname>gobject.MainLoop</classname></link>
is created with the <link
linkend="constructor-gobjectmainloop">gobject.MainLoop</link>()
constructor. After adding the initial event sources, the <link
linkend="method-gobjectmainloop--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-gobjectmainloop--quit"><methodname>quit</methodname>()</link>
method to exit the main loop, and the <link
linkend="method-gobjectmainloop--run"><methodname>run</methodname>()</link>
method returns.</para>

    <para>It is possible to create new instances of <link
linkend="class-gobjectmainloop"><classname>gobject.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-gobjectmaincontext"><classname>gobject.MainContext</classname></link>,
and will be checked and dispatched for all main loops associated with that
<link
linkend="class-gobjectmaincontext"><classname>gobject.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-gobjectmainloop">
    <title>Constructor</title>

    <programlisting><constructorsynopsis language="python">
	<methodname>gobject.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-gobjectmaincontext"><classname>gobject.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-gobjectmainloop--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-gobjectmainloop"><classname>gobject.MainLoop</classname></link>
	object.</simpara></listitem>
      </varlistentry>
    </variablelist>

    <para>Creates a new <link
linkend="class-gobjectmainloop"><classname>gobject.MainLoop</classname></link>
object.</para>

  </refsect1>

  <refsect1>
    <title>Methods</title>

    <refsect2 id="method-gobjectmainloop--get-context">
      <title>gobject.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-gobjectmaincontext"><classname>gobject.MainContext</classname></link>
	  the mainloop is associated with</simpara></listitem>
	</varlistentry>
      </variablelist>

      <para>The <methodname>get_context</methodname>() method returns the
<link
linkend="class-gobjectmaincontext"><classname>gobject.MainContext</classname></link>
that the mainloop was created with.</para>

    </refsect2>

    <refsect2 id="method-gobjectmainloop--is-running">
      <title>gobject.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-gobjectmainloop--run"><methodname>run</methodname>()</link>
method.</para>

    </refsect2>

    <refsect2 id="method-gobjectmainloop--quit">
      <title>gobject.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-gobjectmainloop--run"><methodname>run</methodname>()</link>
method will return immediately.</para>

    </refsect2>

    <refsect2 id="method-gobjectmainloop--run">
      <title>gobject.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-gobjectmainloop--quit"><methodname>quit</methodname>()</link>
method is called. If this is called for the thread of the loop's <link
linkend="class-gobjectmaincontext"><classname>gobject.MainContext</classname></link>,
it will process events from the loop, otherwise it will simply wait.</para>

    </refsect2>

  </refsect1>

</refentry>