/usr/share/doc/python-xlib/html/python-xlib_10.html is in python-xlib 0.14+20091101-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created on September 15, 2015 by texi2html 1.82
texi2html was written by:
Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>The Python X Library: 5.1 Getting Events</title>
<meta name="description" content="The Python X Library: 5.1 Getting Events">
<meta name="keywords" content="The Python X Library: 5.1 Getting Events">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.82">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.roman {font-family:serif; font-weight:normal;}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Getting-Events"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="python-xlib_9.html#Event-Handling" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="python-xlib_11.html#Selecting-Events" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="python-xlib_9.html#Event-Handling" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="python-xlib_9.html#Event-Handling" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="python-xlib_14.html#X-Objects" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="python-xlib.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="python-xlib_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[Index]</td>
<td valign="middle" align="left">[<a href="python-xlib_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<hr size="1">
<a name="Getting-Events-1"></a>
<h2 class="section">5.1 Getting Events</h2>
<p>Events can be sent at any time, not necessarily when the client is ready
to recieve an event. Therefore they must be stored temporarily from that
they are read from the network until the client is ready to handle them.
Read but unhandled events are stored on an event queue in the Display
object. There are two functions to access this queue:
</p>
<dl>
<dt><a name="index-next_005fevent-on-Display"></a><u>Method on Display:</u> <b>next_event</b><i> ( )</i></dt>
<dd>
<p>Return the next event in the event queue. If the event queue is empty,
block until an event is read from the network, and return that one.
</p>
</dd></dl>
<dl>
<dt><a name="index-pending_005fevents-on-Display"></a><u>Method on Display:</u> <b>pending_events</b><i> ( )</i></dt>
<dd>
<p>Return the number of events which can be returned without blocking.
</p>
</dd></dl>
<p>A trivial event loop would simply loop infinitely, waiting for an
event and then handling it. It could look like this:
</p>
<table><tr><td> </td><td><pre class="example">while 1:
event = disp.next_event()
handle_event(event)
</pre></td></tr></table>
<p>However, most applications need more control, e.g. to simultaneously
handle a network connection or at regular intervals schedule timeouts.
The module <code>select</code> is often used for this. <code>Display</code> objects
can be used with <code>select</code>, since they have the required
<code>fileno()</code> method. When <code>select</code> indicates that a
<code>Display</code> object is ready for reading, that means that the server
has sent some data to the client. That alone doesn’t guarantee that an
entire event has arrived, so one must first use <code>pending_events()</code>
to make sure that <code>next_event()</code> will return without blocking. A
simple event loop which waits for events or a one-second timeout looks
like this:
</p>
<table><tr><td> </td><td><pre class="example">while 1:
# Wait for display to send something, or a timeout of one second
readable, w, e = select.select([disp], [], [], 1)
# if no files are ready to be read, it's an timeout
if not readable:
handle_timeout()
# if display is readable, handle as many events as have been recieved
elif disp in readable:
i = disp.pending_events()
while i > 0:
event = disp.next_event()
handle_event(event)
i = i - 1
# loop around to wait for more things to happen
</pre></td></tr></table>
<hr size="1">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="python-xlib_9.html#Event-Handling" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="python-xlib_11.html#Selecting-Events" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="python-xlib_9.html#Event-Handling" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="python-xlib_9.html#Event-Handling" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="python-xlib_14.html#X-Objects" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="python-xlib.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="python-xlib_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[Index]</td>
<td valign="middle" align="left">[<a href="python-xlib_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
<font size="-1">
This document was generated by <em>Build Daemon user</em> on <em>September 15, 2015</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.82</em></a>.
</font>
<br>
</p>
</body>
</html>
|