GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||
GeezerVison is showing python-xlib.github.io — The Python X Library: 5.1 Getting Events
5.1 Getting EventsEvents can be sent at any time, not necessarily when the client is ready to receive 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:
A trivial event loop would simply loop infinitely, waiting for an event and then handling it. It could look like this: while 1: event = disp.next_event() handle_event(event) However, most applications need more control, e.g. to simultaneously
handle a network connection or at regular intervals schedule timeouts.
The module 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 received
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
This document was generated on September 16, 2020 using texi2html 5.0.
| ||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |