File: ch-TimeoutsIOAndIdleFunctions.html

package info (click to toggle)
python-gtk2-tutorial 2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,376 kB
  • ctags: 918
  • sloc: python: 5,731; makefile: 36
file content (19 lines) | stat: -rw-r--r-- 3,950 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter19.Timeouts, IO and Idle Functions</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PyGTK 2.0 Tutorial"><link rel="up" href="index.html" title="PyGTK 2.0 Tutorial"><link rel="previous" href="sec-WidgetStyles.html" title="18.5.Widget Styles"><link rel="next" href="sec-MonitoringIO.html" title="19.2.Monitoring IO"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter19.Timeouts, IO and Idle Functions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-WidgetStyles.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="sec-MonitoringIO.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="ch-TimeoutsIOAndIdleFunctions"></a>Chapter19.Timeouts, IO and Idle Functions</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch-TimeoutsIOAndIdleFunctions.html#sec-Timeouts">19.1. Timeouts</a></span></dt><dt><span class="sect1"><a href="sec-MonitoringIO.html">19.2. Monitoring IO</a></span></dt><dt><span class="sect1"><a href="sec-IdleFunctions.html">19.3. Idle Functions</a></span></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec-Timeouts"></a>19.1.Timeouts</h2></div></div><div></div></div><p>You may be wondering how you make GTK do useful work when in
<tt class="function">main</tt>(). Well, you have several options. Using the
following gobject module function you can create a timeout function that
will be called every "interval" milliseconds.</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  source_id = gobject.timeout_add(<i class="parameter"><tt>interval</tt></i>, <i class="parameter"><tt>function</tt></i>, ...)
</pre></td></tr></table><p>The <i class="parameter"><tt>interval</tt></i> argument is the number of
milliseconds between calls to your function. The
<i class="parameter"><tt>function</tt></i> argument is the callback you wish to have
called. Any arguments after the second are passed to the function as
data. The return value is an integer "source_id" which may be used to stop
the timeout by calling:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  gobject.source_remove(<i class="parameter"><tt>source_id</tt></i>)
</pre></td></tr></table><p>You may also stop the timeout callback function from being
called again by returning zero or <tt class="literal">FALSE</tt> from your
callback. If you want your callback to be called again, it should return
<tt class="literal">TRUE</tt>.</p><p>Your callback should look something like this:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
  def timeout_callback(...):
</pre></td></tr></table><p>The number of arguments to the callback should match the number
of data arguments specified in <tt class="function">timeout_add</tt>().</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-WidgetStyles.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><a accesskey="n" href="sec-MonitoringIO.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">18.5.Widget Styles</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">19.2.Monitoring IO</td></tr></table></div></body></html>