blob: a4f195f6b8babaee2b3d5537605ac0fd3c41caae [file] [log] [blame]
Guido van Rossumecde7811995-03-28 13:35:14 +00001\chapter{Standard Windowing Interface}
2
3The modules in this chapter are available only on those systems where
4the STDWIN library is available. STDWIN runs on \UNIX{} under X11 and
5on the Macintosh. See CWI report CS-R8817.
6
7\strong{Warning:} Using STDWIN is not recommended for new
8applications. It has never been ported to Microsoft Windows or
9Windows NT, and for X11 or the Macintosh it lacks important
10functionality --- in particular, it has no tools for the construction
11of dialogs. For most platforms, alternative, native solutions exist
12(though none are currently documented in this manual): Tkinter for
13\UNIX{} under X11, native Xt with Motif or Athena widgets for \UNIX{}
14under X11, Win32 for Windows and Windows NT, and a collection of
15native toolkit interfaces for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000016
Fred Drake295da241998-08-10 19:42:37 +000017\section{\module{stdwin} ---
Fred Drake4471f201998-11-25 22:38:24 +000018 Platform-independent GUI System}
Fred Drakeb91e9341998-07-23 17:59:49 +000019\declaremodule{builtin}{stdwin}
20
Fred Drake4471f201998-11-25 22:38:24 +000021\modulesynopsis{Older GUI system for X11 and Macintosh}
Fred Drakeb91e9341998-07-23 17:59:49 +000022
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000023
24This module defines several new object types and functions that
Guido van Rossumecde7811995-03-28 13:35:14 +000025provide access to the functionality of STDWIN.
Guido van Rossum470be141995-03-17 16:07:09 +000026
Fred Drake4471f201998-11-25 22:38:24 +000027On \UNIX{} running X11, it can only be used if the \envvar{DISPLAY}
Guido van Rossum470be141995-03-17 16:07:09 +000028environment variable is set or an explicit \samp{-display
29\var{displayname}} argument is passed to the Python interpreter.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000030
31Functions have names that usually resemble their C STDWIN counterparts
32with the initial `w' dropped.
33Points are represented by pairs of integers; rectangles
34by pairs of points.
35For a complete description of STDWIN please refer to the documentation
36of STDWIN for C programmers (aforementioned CWI report).
37
Fred Drake3a0351c1998-04-04 07:23:21 +000038\subsection{Functions Defined in Module \module{stdwin}}
Guido van Rossum86cb0921995-03-20 12:59:56 +000039\nodename{STDWIN Functions}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000040
Fred Drake4471f201998-11-25 22:38:24 +000041The following functions are defined in the \module{stdwin} module:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000042
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000043\begin{funcdesc}{open}{title}
44Open a new window whose initial title is given by the string argument.
Fred Drakeea003fc1999-04-05 21:59:15 +000045Return a window object; window object methods are described
46below.\footnote{
47 The Python version of STDWIN does not support draw procedures;
48 all drawing requests are reported as draw events.}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000049\end{funcdesc}
50
51\begin{funcdesc}{getevent}{}
52Wait for and return the next event.
53An event is returned as a triple: the first element is the event
54type, a small integer; the second element is the window object to which
55the event applies, or
56\code{None}
57if it applies to no window in particular;
58the third element is type-dependent.
59Names for event types and command codes are defined in the standard
Fred Drake4471f201998-11-25 22:38:24 +000060module \module{stdwinevent}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000061\end{funcdesc}
62
63\begin{funcdesc}{pollevent}{}
64Return the next event, if one is immediately available.
65If no event is available, return \code{()}.
66\end{funcdesc}
67
68\begin{funcdesc}{getactive}{}
69Return the window that is currently active, or \code{None} if no
70window is currently active. (This can be emulated by monitoring
71WE_ACTIVATE and WE_DEACTIVATE events.)
72\end{funcdesc}
73
74\begin{funcdesc}{listfontnames}{pattern}
75Return the list of font names in the system that match the pattern (a
76string). The pattern should normally be \code{'*'}; returns all
77available fonts. If the underlying window system is X11, other
78patterns follow the standard X11 font selection syntax (as used e.g.
79in resource definitions), i.e. the wildcard character \code{'*'}
80matches any sequence of characters (including none) and \code{'?'}
81matches any single character.
Guido van Rossum470be141995-03-17 16:07:09 +000082On the Macintosh this function currently returns an empty list.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000083\end{funcdesc}
84
Fred Drakecce10901998-03-17 06:33:25 +000085\begin{funcdesc}{setdefscrollbars}{hflag, vflag}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000086Set the flags controlling whether subsequently opened windows will
87have horizontal and/or vertical scroll bars.
88\end{funcdesc}
89
Fred Drakecce10901998-03-17 06:33:25 +000090\begin{funcdesc}{setdefwinpos}{h, v}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000091Set the default window position for windows opened subsequently.
92\end{funcdesc}
93
Fred Drakecce10901998-03-17 06:33:25 +000094\begin{funcdesc}{setdefwinsize}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000095Set the default window size for windows opened subsequently.
96\end{funcdesc}
97
98\begin{funcdesc}{getdefscrollbars}{}
99Return the flags controlling whether subsequently opened windows will
100have horizontal and/or vertical scroll bars.
101\end{funcdesc}
102
103\begin{funcdesc}{getdefwinpos}{}
104Return the default window position for windows opened subsequently.
105\end{funcdesc}
106
107\begin{funcdesc}{getdefwinsize}{}
108Return the default window size for windows opened subsequently.
109\end{funcdesc}
110
111\begin{funcdesc}{getscrsize}{}
112Return the screen size in pixels.
113\end{funcdesc}
114
115\begin{funcdesc}{getscrmm}{}
116Return the screen size in millimeters.
117\end{funcdesc}
118
119\begin{funcdesc}{fetchcolor}{colorname}
120Return the pixel value corresponding to the given color name.
121Return the default foreground color for unknown color names.
Guido van Rossum16d6e711994-08-08 12:30:22 +0000122Hint: the following code tests whether you are on a machine that
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000123supports more than two colors:
Fred Drake19479911998-02-13 06:58:54 +0000124\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000125if stdwin.fetchcolor('black') <> \
126 stdwin.fetchcolor('red') <> \
127 stdwin.fetchcolor('white'):
128 print 'color machine'
129else:
130 print 'monochrome machine'
Fred Drake19479911998-02-13 06:58:54 +0000131\end{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000132\end{funcdesc}
133
134\begin{funcdesc}{setfgcolor}{pixel}
135Set the default foreground color.
136This will become the default foreground color of windows opened
137subsequently, including dialogs.
138\end{funcdesc}
139
140\begin{funcdesc}{setbgcolor}{pixel}
141Set the default background color.
142This will become the default background color of windows opened
143subsequently, including dialogs.
144\end{funcdesc}
145
146\begin{funcdesc}{getfgcolor}{}
147Return the pixel value of the current default foreground color.
148\end{funcdesc}
149
150\begin{funcdesc}{getbgcolor}{}
151Return the pixel value of the current default background color.
152\end{funcdesc}
153
154\begin{funcdesc}{setfont}{fontname}
155Set the current default font.
156This will become the default font for windows opened subsequently,
Fred Drake4471f201998-11-25 22:38:24 +0000157and is also used by the text measuring functions \function{textwidth()},
158\function{textbreak()}, \function{lineheight()} and
159\function{baseline()} below. This accepts two more optional
160parameters, size and style: Size is the font size (in `points').
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000161Style is a single character specifying the style, as follows:
162\code{'b'} = bold,
163\code{'i'} = italic,
164\code{'o'} = bold + italic,
165\code{'u'} = underline;
166default style is roman.
167Size and style are ignored under X11 but used on the Macintosh.
168(Sorry for all this complexity --- a more uniform interface is being designed.)
169\end{funcdesc}
170
171\begin{funcdesc}{menucreate}{title}
172Create a menu object referring to a global menu (a menu that appears in
173all windows).
174Methods of menu objects are described below.
175Note: normally, menus are created locally; see the window method
Fred Drake4471f201998-11-25 22:38:24 +0000176\method{menucreate()} below.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000177\strong{Warning:} the menu only appears in a window as long as the object
178returned by this call exists.
179\end{funcdesc}
180
Fred Drakecce10901998-03-17 06:33:25 +0000181\begin{funcdesc}{newbitmap}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000182Create a new bitmap object of the given dimensions.
183Methods of bitmap objects are described below.
Guido van Rossum470be141995-03-17 16:07:09 +0000184Not available on the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000185\end{funcdesc}
186
187\begin{funcdesc}{fleep}{}
188Cause a beep or bell (or perhaps a `visual bell' or flash, hence the
189name).
190\end{funcdesc}
191
192\begin{funcdesc}{message}{string}
193Display a dialog box containing the string.
194The user must click OK before the function returns.
195\end{funcdesc}
196
Fred Drakecce10901998-03-17 06:33:25 +0000197\begin{funcdesc}{askync}{prompt, default}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000198Display a dialog that prompts the user to answer a question with yes or
Fred Drake4471f201998-11-25 22:38:24 +0000199no. Return 0 for no, 1 for yes. If the user hits the Return key, the
200default (which must be 0 or 1) is returned. If the user cancels the
201dialog, \exception{KeyboardInterrupt} is raised.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000202\end{funcdesc}
203
Fred Drakecce10901998-03-17 06:33:25 +0000204\begin{funcdesc}{askstr}{prompt, default}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000205Display a dialog that prompts the user for a string.
206If the user hits the Return key, the default string is returned.
Fred Drake4471f201998-11-25 22:38:24 +0000207If the user cancels the dialog, \exception{KeyboardInterrupt} is
208raised.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000209\end{funcdesc}
210
Fred Drakecce10901998-03-17 06:33:25 +0000211\begin{funcdesc}{askfile}{prompt, default, new}
Fred Drake4471f201998-11-25 22:38:24 +0000212Ask the user to specify a filename. If \var{new} is zero it must be
213an existing file; otherwise, it must be a new file. If the user
214cancels the dialog, \exception{KeyboardInterrupt} is raised.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000215\end{funcdesc}
216
Fred Drakecce10901998-03-17 06:33:25 +0000217\begin{funcdesc}{setcutbuffer}{i, string}
Fred Drake4471f201998-11-25 22:38:24 +0000218Store the string in the system's cut buffer number \var{i}, where it
219can be found (for pasting) by other applications. On X11, there are 8
220cut buffers (numbered 0..7). Cut buffer number 0 is the `clipboard'
221on the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000222\end{funcdesc}
223
224\begin{funcdesc}{getcutbuffer}{i}
Fred Drake4471f201998-11-25 22:38:24 +0000225Return the contents of the system's cut buffer number \var{i}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000226\end{funcdesc}
227
228\begin{funcdesc}{rotatecutbuffers}{n}
Fred Drake4471f201998-11-25 22:38:24 +0000229On X11, rotate the 8 cut buffers by \var{n}. Ignored on the
230Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000231\end{funcdesc}
232
233\begin{funcdesc}{getselection}{i}
Fred Drake4471f201998-11-25 22:38:24 +0000234Return X11 selection number \var{i.} Selections are not cut buffers.
235Selection numbers are defined in module \module{stdwinevents}.
236Selection \constant{WS_PRIMARY} is the \dfn{primary} selection (used
237by \program{xterm}, for instance); selection \constant{WS_SECONDARY}
238is the \dfn{secondary} selection; selection \constant{WS_CLIPBOARD} is
239the \dfn{clipboard} selection (used by \program{xclipboard}). On the
240Macintosh, this always returns an empty string.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000241\end{funcdesc}
242
243\begin{funcdesc}{resetselection}{i}
Fred Drake4471f201998-11-25 22:38:24 +0000244Reset selection number \var{i}, if this process owns it. (See window
245method \method{setselection()}).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000246\end{funcdesc}
247
248\begin{funcdesc}{baseline}{}
249Return the baseline of the current font (defined by STDWIN as the
250vertical distance between the baseline and the top of the
251characters).
252\end{funcdesc}
253
254\begin{funcdesc}{lineheight}{}
255Return the total line height of the current font.
256\end{funcdesc}
257
Fred Drakecce10901998-03-17 06:33:25 +0000258\begin{funcdesc}{textbreak}{str, width}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000259Return the number of characters of the string that fit into a space of
260\var{width}
261bits wide when drawn in the curent font.
262\end{funcdesc}
263
264\begin{funcdesc}{textwidth}{str}
265Return the width in bits of the string when drawn in the current font.
266\end{funcdesc}
267
268\begin{funcdesc}{connectionnumber}{}
269\funcline{fileno}{}
270(X11 under \UNIX{} only) Return the ``connection number'' used by the
271underlying X11 implementation. (This is normally the file number of
272the socket.) Both functions return the same value;
Fred Drake4471f201998-11-25 22:38:24 +0000273\method{connectionnumber()} is named after the corresponding function in
274X11 and STDWIN, while \method{fileno()} makes it possible to use the
275\module{stdwin} module as a ``file'' object parameter to
276\function{select.select()}. Note that if \constant{select()} implies that
277input is possible on \module{stdwin}, this does not guarantee that an
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000278event is ready --- it may be some internal communication going on
279between the X server and the client library. Thus, you should call
Fred Drake4471f201998-11-25 22:38:24 +0000280\function{stdwin.pollevent()} until it returns \code{None} to check for
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000281events if you don't want your program to block. Because of internal
Fred Drake4471f201998-11-25 22:38:24 +0000282buffering in X11, it is also possible that \function{stdwin.pollevent()}
283returns an event while \function{select()} does not find \module{stdwin} to
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000284be ready, so you should read any pending events with
Fred Drake4471f201998-11-25 22:38:24 +0000285\function{stdwin.pollevent()} until it returns \code{None} before entering
286a blocking \function{select()} call.
287\withsubitem{(in module select)}{\ttindex{select()}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000288\end{funcdesc}
289
Guido van Rossum470be141995-03-17 16:07:09 +0000290\subsection{Window Objects}
Fred Drake4b3f0311996-12-13 22:04:31 +0000291\nodename{STDWIN Window Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000292
Fred Drake4471f201998-11-25 22:38:24 +0000293Window objects are created by \function{stdwin.open()}. They are closed
294by their \method{close()} method or when they are garbage-collected.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000295Window objects have the following methods:
296
Fred Drake4471f201998-11-25 22:38:24 +0000297\begin{methoddesc}[window]{begindrawing}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000298Return a drawing object, whose methods (described below) allow drawing
299in the window.
Fred Drake4471f201998-11-25 22:38:24 +0000300\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000301
Fred Drake4471f201998-11-25 22:38:24 +0000302\begin{methoddesc}[window]{change}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000303Invalidate the given rectangle; this may cause a draw event.
Fred Drake4471f201998-11-25 22:38:24 +0000304\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000305
Fred Drake4471f201998-11-25 22:38:24 +0000306\begin{methoddesc}[window]{gettitle}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000307Returns the window's title string.
Fred Drake4471f201998-11-25 22:38:24 +0000308\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000309
Fred Drake4471f201998-11-25 22:38:24 +0000310\begin{methoddesc}[window]{getdocsize}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000311\begin{sloppypar}
312Return a pair of integers giving the size of the document as set by
Fred Drake4471f201998-11-25 22:38:24 +0000313\method{setdocsize()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000314\end{sloppypar}
Fred Drake4471f201998-11-25 22:38:24 +0000315\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000316
Fred Drake4471f201998-11-25 22:38:24 +0000317\begin{methoddesc}[window]{getorigin}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000318Return a pair of integers giving the origin of the window with respect
319to the document.
Fred Drake4471f201998-11-25 22:38:24 +0000320\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000321
Fred Drake4471f201998-11-25 22:38:24 +0000322\begin{methoddesc}[window]{gettitle}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000323Return the window's title string.
Fred Drake4471f201998-11-25 22:38:24 +0000324\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000325
Fred Drake4471f201998-11-25 22:38:24 +0000326\begin{methoddesc}[window]{getwinsize}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000327Return a pair of integers giving the size of the window.
Fred Drake4471f201998-11-25 22:38:24 +0000328\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000329
Fred Drake4471f201998-11-25 22:38:24 +0000330\begin{methoddesc}[window]{getwinpos}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000331Return a pair of integers giving the position of the window's upper
332left corner (relative to the upper left corner of the screen).
Fred Drake4471f201998-11-25 22:38:24 +0000333\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000334
Fred Drake4471f201998-11-25 22:38:24 +0000335\begin{methoddesc}[window]{menucreate}{title}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000336Create a menu object referring to a local menu (a menu that appears
337only in this window).
338Methods of menu objects are described below.
Fred Drakeaf8a0151998-01-14 14:51:31 +0000339\strong{Warning:} the menu only appears as long as the object
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000340returned by this call exists.
Fred Drake4471f201998-11-25 22:38:24 +0000341\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000342
Fred Drake4471f201998-11-25 22:38:24 +0000343\begin{methoddesc}[window]{scroll}{rect, point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000344Scroll the given rectangle by the vector given by the point.
Fred Drake4471f201998-11-25 22:38:24 +0000345\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000346
Fred Drake4471f201998-11-25 22:38:24 +0000347\begin{methoddesc}[window]{setdocsize}{point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000348Set the size of the drawing document.
Fred Drake4471f201998-11-25 22:38:24 +0000349\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000350
Fred Drake4471f201998-11-25 22:38:24 +0000351\begin{methoddesc}[window]{setorigin}{point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000352Move the origin of the window (its upper left corner)
353to the given point in the document.
Fred Drake4471f201998-11-25 22:38:24 +0000354\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000355
Fred Drake4471f201998-11-25 22:38:24 +0000356\begin{methoddesc}[window]{setselection}{i, str}
357Attempt to set X11 selection number \var{i} to the string \var{str}.
358(See \module{stdwin} function \function{getselection()} for the
359meaning of \var{i}.) Return true if it succeeds.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000360If succeeds, the window ``owns'' the selection until
Guido van Rossum16d6e711994-08-08 12:30:22 +0000361(a) another application takes ownership of the selection; or
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000362(b) the window is deleted; or
363(c) the application clears ownership by calling
Fred Drake4471f201998-11-25 22:38:24 +0000364\function{stdwin.resetselection(\var{i})}. When another application
365takes ownership of the selection, a \constant{WE_LOST_SEL} event is
366received for no particular window and with the selection number as
367detail. Ignored on the Macintosh.
368\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000369
Fred Drake4471f201998-11-25 22:38:24 +0000370\begin{methoddesc}[window]{settimer}{dsecs}
371Schedule a timer event for the window in \code{\var{dsecs}/10}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000372seconds.
Fred Drake4471f201998-11-25 22:38:24 +0000373\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000374
Fred Drake4471f201998-11-25 22:38:24 +0000375\begin{methoddesc}[window]{settitle}{title}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000376Set the window's title string.
Fred Drake4471f201998-11-25 22:38:24 +0000377\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000378
Fred Drake4471f201998-11-25 22:38:24 +0000379\begin{methoddesc}[window]{setwincursor}{name}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000380\begin{sloppypar}
Fred Drake4471f201998-11-25 22:38:24 +0000381Set the window cursor to a cursor of the given name. It raises
382\exception{RuntimeError} if no cursor of the given name exists.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000383Suitable names include
384\code{'ibeam'},
385\code{'arrow'},
386\code{'cross'},
387\code{'watch'}
388and
389\code{'plus'}.
Fred Drakea5aefba1998-08-14 17:05:17 +0000390On X11, there are many more (see \code{<X11/cursorfont.h>}).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000391\end{sloppypar}
Fred Drake4471f201998-11-25 22:38:24 +0000392\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000393
Fred Drake4471f201998-11-25 22:38:24 +0000394\begin{methoddesc}[window]{setwinpos}{h, v}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000395Set the the position of the window's upper left corner (relative to
396the upper left corner of the screen).
Fred Drake4471f201998-11-25 22:38:24 +0000397\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000398
Fred Drake4471f201998-11-25 22:38:24 +0000399\begin{methoddesc}[window]{setwinsize}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000400Set the window's size.
Fred Drake4471f201998-11-25 22:38:24 +0000401\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000402
Fred Drake4471f201998-11-25 22:38:24 +0000403\begin{methoddesc}[window]{show}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000404Try to ensure that the given rectangle of the document is visible in
405the window.
Fred Drake4471f201998-11-25 22:38:24 +0000406\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000407
Fred Drake4471f201998-11-25 22:38:24 +0000408\begin{methoddesc}[window]{textcreate}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000409Create a text-edit object in the document at the given rectangle.
410Methods of text-edit objects are described below.
Fred Drake4471f201998-11-25 22:38:24 +0000411\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000412
Fred Drake4471f201998-11-25 22:38:24 +0000413\begin{methoddesc}[window]{setactive}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000414Attempt to make this window the active window. If successful, this
415will generate a WE_ACTIVATE event (and a WE_DEACTIVATE event in case
416another window in this application became inactive).
Fred Drake4471f201998-11-25 22:38:24 +0000417\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000418
Fred Drake4471f201998-11-25 22:38:24 +0000419\begin{methoddesc}[window]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000420Discard the window object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000421\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000422
Guido van Rossum470be141995-03-17 16:07:09 +0000423\subsection{Drawing Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000424
425Drawing objects are created exclusively by the window method
Fred Drake4471f201998-11-25 22:38:24 +0000426\method{begindrawing()}. Only one drawing object can exist at any
427given time; the drawing object must be deleted to finish drawing. No
428drawing object may exist when \function{stdwin.getevent()} is called.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000429Drawing objects have the following methods:
430
Fred Drake4471f201998-11-25 22:38:24 +0000431\begin{methoddesc}[drawing]{box}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000432Draw a box just inside a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000433\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000434
Fred Drake4471f201998-11-25 22:38:24 +0000435\begin{methoddesc}[drawing]{circle}{center, radius}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000436Draw a circle with given center point and radius.
Fred Drake4471f201998-11-25 22:38:24 +0000437\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000438
Fred Drake4471f201998-11-25 22:38:24 +0000439\begin{methoddesc}[drawing]{elarc}{center, (rh, rv), (a1, a2)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000440Draw an elliptical arc with given center point.
441\code{(\var{rh}, \var{rv})}
442gives the half sizes of the horizontal and vertical radii.
443\code{(\var{a1}, \var{a2})}
444gives the angles (in degrees) of the begin and end points.
4450 degrees is at 3 o'clock, 90 degrees is at 12 o'clock.
Fred Drake4471f201998-11-25 22:38:24 +0000446\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000447
Fred Drake4471f201998-11-25 22:38:24 +0000448\begin{methoddesc}[drawing]{erase}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000449Erase a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000450\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000451
Fred Drake4471f201998-11-25 22:38:24 +0000452\begin{methoddesc}[drawing]{fillcircle}{center, radius}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000453Draw a filled circle with given center point and radius.
Fred Drake4471f201998-11-25 22:38:24 +0000454\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000455
Fred Drake4471f201998-11-25 22:38:24 +0000456\begin{methoddesc}[drawing]{fillelarc}{center, (rh, rv), (a1, a2)}
457Draw a filled elliptical arc; arguments as for \method{elarc()}.
458\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000459
Fred Drake4471f201998-11-25 22:38:24 +0000460\begin{methoddesc}[drawing]{fillpoly}{points}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000461Draw a filled polygon given by a list (or tuple) of points.
Fred Drake4471f201998-11-25 22:38:24 +0000462\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000463
Fred Drake4471f201998-11-25 22:38:24 +0000464\begin{methoddesc}[drawing]{invert}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000465Invert a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000466\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000467
Fred Drake4471f201998-11-25 22:38:24 +0000468\begin{methoddesc}[drawing]{line}{p1, p2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000469Draw a line from point
470\var{p1}
471to
472\var{p2}.
Fred Drake4471f201998-11-25 22:38:24 +0000473\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000474
Fred Drake4471f201998-11-25 22:38:24 +0000475\begin{methoddesc}[drawing]{paint}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000476Fill a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000477\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000478
Fred Drake4471f201998-11-25 22:38:24 +0000479\begin{methoddesc}[drawing]{poly}{points}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000480Draw the lines connecting the given list (or tuple) of points.
Fred Drake4471f201998-11-25 22:38:24 +0000481\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000482
Fred Drake4471f201998-11-25 22:38:24 +0000483\begin{methoddesc}[drawing]{shade}{rect, percent}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000484Fill a rectangle with a shading pattern that is about
485\var{percent}
486percent filled.
Fred Drake4471f201998-11-25 22:38:24 +0000487\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000488
Fred Drake4471f201998-11-25 22:38:24 +0000489\begin{methoddesc}[drawing]{text}{p, str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000490Draw a string starting at point p (the point specifies the
491top left coordinate of the string).
Fred Drake4471f201998-11-25 22:38:24 +0000492\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000493
Fred Drake4471f201998-11-25 22:38:24 +0000494\begin{methoddesc}[drawing]{xorcircle}{center, radius}
495\funcline{xorelarc}{center, (rh, rv), (a1, a2)}
Fred Drakecce10901998-03-17 06:33:25 +0000496\funcline{xorline}{p1, p2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000497\funcline{xorpoly}{points}
498Draw a circle, an elliptical arc, a line or a polygon, respectively,
499in XOR mode.
Fred Drake4471f201998-11-25 22:38:24 +0000500\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000501
Fred Drake4471f201998-11-25 22:38:24 +0000502\begin{methoddesc}[drawing]{setfgcolor}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000503\funcline{setbgcolor}{}
504\funcline{getfgcolor}{}
505\funcline{getbgcolor}{}
506These functions are similar to the corresponding functions described
Fred Drake4471f201998-11-25 22:38:24 +0000507above for the \module{stdwin}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000508module, but affect or return the colors currently used for drawing
509instead of the global default colors.
510When a drawing object is created, its colors are set to the window's
511default colors, which are in turn initialized from the global default
512colors when the window is created.
Fred Drake4471f201998-11-25 22:38:24 +0000513\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000514
Fred Drake4471f201998-11-25 22:38:24 +0000515\begin{methoddesc}[drawing]{setfont}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000516\funcline{baseline}{}
517\funcline{lineheight}{}
518\funcline{textbreak}{}
519\funcline{textwidth}{}
520These functions are similar to the corresponding functions described
Fred Drake4471f201998-11-25 22:38:24 +0000521above for the \module{stdwin}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000522module, but affect or use the current drawing font instead of
523the global default font.
524When a drawing object is created, its font is set to the window's
525default font, which is in turn initialized from the global default
526font when the window is created.
Fred Drake4471f201998-11-25 22:38:24 +0000527\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000528
Fred Drake4471f201998-11-25 22:38:24 +0000529\begin{methoddesc}[drawing]{bitmap}{point, bitmap, mask}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000530Draw the \var{bitmap} with its top left corner at \var{point}.
531If the optional \var{mask} argument is present, it should be either
532the same object as \var{bitmap}, to draw only those bits that are set
533in the bitmap, in the foreground color, or \code{None}, to draw all
534bits (ones are drawn in the foreground color, zeros in the background
535color).
Guido van Rossum470be141995-03-17 16:07:09 +0000536Not available on the Macintosh.
Fred Drake4471f201998-11-25 22:38:24 +0000537\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000538
Fred Drake4471f201998-11-25 22:38:24 +0000539\begin{methoddesc}[drawing]{cliprect}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000540Set the ``clipping region'' to a rectangle.
541The clipping region limits the effect of all drawing operations, until
542it is changed again or until the drawing object is closed. When a
543drawing object is created the clipping region is set to the entire
544window. When an object to be drawn falls partly outside the clipping
545region, the set of pixels drawn is the intersection of the clipping
546region and the set of pixels that would be drawn by the same operation
547in the absence of a clipping region.
Fred Drake4471f201998-11-25 22:38:24 +0000548\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000549
Fred Drake4471f201998-11-25 22:38:24 +0000550\begin{methoddesc}[drawing]{noclip}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000551Reset the clipping region to the entire window.
Fred Drake4471f201998-11-25 22:38:24 +0000552\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000553
Fred Drake4471f201998-11-25 22:38:24 +0000554\begin{methoddesc}[drawing]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000555\funcline{enddrawing}{}
556Discard the drawing object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000557\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000558
Guido van Rossum470be141995-03-17 16:07:09 +0000559\subsection{Menu Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000560
561A menu object represents a menu.
562The menu is destroyed when the menu object is deleted.
563The following methods are defined:
564
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000565
Fred Drake4471f201998-11-25 22:38:24 +0000566\begin{methoddesc}[menu]{additem}{text, shortcut}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000567Add a menu item with given text.
568The shortcut must be a string of length 1, or omitted (to specify no
569shortcut).
Fred Drake4471f201998-11-25 22:38:24 +0000570\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000571
Fred Drake4471f201998-11-25 22:38:24 +0000572\begin{methoddesc}[menu]{setitem}{i, text}
573Set the text of item number \var{i}.
574\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000575
Fred Drake4471f201998-11-25 22:38:24 +0000576\begin{methoddesc}[menu]{enable}{i, flag}
577Enable or disables item \var{i}.
578\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000579
Fred Drake4471f201998-11-25 22:38:24 +0000580\begin{methoddesc}[menu]{check}{i, flag}
581Set or clear the \dfn{check mark} for item \var{i}.
582\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000583
Fred Drake4471f201998-11-25 22:38:24 +0000584\begin{methoddesc}[menu]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000585Discard the menu object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000586\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000587
Guido van Rossum470be141995-03-17 16:07:09 +0000588\subsection{Bitmap Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000589
590A bitmap represents a rectangular array of bits.
591The top left bit has coordinate (0, 0).
Fred Drake4471f201998-11-25 22:38:24 +0000592A bitmap can be drawn with the \method{bitmap()} method of a drawing object.
Guido van Rossum470be141995-03-17 16:07:09 +0000593Bitmaps are currently not available on the Macintosh.
594
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000595The following methods are defined:
596
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000597
Fred Drake4471f201998-11-25 22:38:24 +0000598\begin{methoddesc}[bitmap]{getsize}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000599Return a tuple representing the width and height of the bitmap.
Fred Drake4471f201998-11-25 22:38:24 +0000600(This returns the values that have been passed to the
601\function{newbitmap()} function.)
602\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000603
Fred Drake4471f201998-11-25 22:38:24 +0000604\begin{methoddesc}[bitmap]{setbit}{point, bit}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000605Set the value of the bit indicated by \var{point} to \var{bit}.
Fred Drake4471f201998-11-25 22:38:24 +0000606\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000607
Fred Drake4471f201998-11-25 22:38:24 +0000608\begin{methoddesc}[bitmap]{getbit}{point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000609Return the value of the bit indicated by \var{point}.
Fred Drake4471f201998-11-25 22:38:24 +0000610\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000611
Fred Drake4471f201998-11-25 22:38:24 +0000612\begin{methoddesc}[bitmap]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000613Discard the bitmap object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000614\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000615
Guido van Rossum470be141995-03-17 16:07:09 +0000616\subsection{Text-edit Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000617
618A text-edit object represents a text-edit block.
Fred Drake4471f201998-11-25 22:38:24 +0000619For semantics, see the STDWIN documentation for \C{} programmers.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000620The following methods exist:
621
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000622
Fred Drake4471f201998-11-25 22:38:24 +0000623\begin{methoddesc}[text-edit]{arrow}{code}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000624Pass an arrow event to the text-edit block.
Fred Drake4471f201998-11-25 22:38:24 +0000625The \var{code} must be one of \constant{WC_LEFT}, \constant{WC_RIGHT},
626\constant{WC_UP} or \constant{WC_DOWN} (see module
627\module{stdwinevents}).
628\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000629
Fred Drake4471f201998-11-25 22:38:24 +0000630\begin{methoddesc}[text-edit]{draw}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000631Pass a draw event to the text-edit block.
632The rectangle specifies the redraw area.
Fred Drake4471f201998-11-25 22:38:24 +0000633\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000634
Fred Drake4471f201998-11-25 22:38:24 +0000635\begin{methoddesc}[text-edit]{event}{type, window, detail}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000636Pass an event gotten from
Fred Drake4471f201998-11-25 22:38:24 +0000637\function{stdwin.getevent()}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000638to the text-edit block.
639Return true if the event was handled.
Fred Drake4471f201998-11-25 22:38:24 +0000640\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000641
Fred Drake4471f201998-11-25 22:38:24 +0000642\begin{methoddesc}[text-edit]{getfocus}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000643Return 2 integers representing the start and end positions of the
644focus, usable as slice indices on the string returned by
Fred Drake4471f201998-11-25 22:38:24 +0000645\method{gettext()}.
646\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000647
Fred Drake4471f201998-11-25 22:38:24 +0000648\begin{methoddesc}[text-edit]{getfocustext}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000649Return the text in the focus.
Fred Drake4471f201998-11-25 22:38:24 +0000650\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000651
Fred Drake4471f201998-11-25 22:38:24 +0000652\begin{methoddesc}[text-edit]{getrect}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000653Return a rectangle giving the actual position of the text-edit block.
654(The bottom coordinate may differ from the initial position because
655the block automatically shrinks or grows to fit.)
Fred Drake4471f201998-11-25 22:38:24 +0000656\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000657
Fred Drake4471f201998-11-25 22:38:24 +0000658\begin{methoddesc}[text-edit]{gettext}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000659Return the entire text buffer.
Fred Drake4471f201998-11-25 22:38:24 +0000660\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000661
Fred Drake4471f201998-11-25 22:38:24 +0000662\begin{methoddesc}[text-edit]{move}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000663Specify a new position for the text-edit block in the document.
Fred Drake4471f201998-11-25 22:38:24 +0000664\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000665
Fred Drake4471f201998-11-25 22:38:24 +0000666\begin{methoddesc}[text-edit]{replace}{str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000667Replace the text in the focus by the given string.
668The new focus is an insert point at the end of the string.
Fred Drake4471f201998-11-25 22:38:24 +0000669\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000670
Fred Drake4471f201998-11-25 22:38:24 +0000671\begin{methoddesc}[text-edit]{setfocus}{i, j}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000672Specify the new focus.
673Out-of-bounds values are silently clipped.
Fred Drake4471f201998-11-25 22:38:24 +0000674\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000675
Fred Drake4471f201998-11-25 22:38:24 +0000676\begin{methoddesc}[text-edit]{settext}{str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000677Replace the entire text buffer by the given string and set the focus
678to \code{(0, 0)}.
Fred Drake4471f201998-11-25 22:38:24 +0000679\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000680
Fred Drake4471f201998-11-25 22:38:24 +0000681\begin{methoddesc}[text-edit]{setview}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000682Set the view rectangle to \var{rect}. If \var{rect} is \code{None},
683viewing mode is reset. In viewing mode, all output from the text-edit
684object is clipped to the viewing rectangle. This may be useful to
685implement your own scrolling text subwindow.
Fred Drake4471f201998-11-25 22:38:24 +0000686\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000687
Fred Drake4471f201998-11-25 22:38:24 +0000688\begin{methoddesc}[text-edit]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000689Discard the text-edit object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000690\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000691
692\subsection{Example}
Guido van Rossum86cb0921995-03-20 12:59:56 +0000693\nodename{STDWIN Example}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000694
695Here is a minimal example of using STDWIN in Python.
696It creates a window and draws the string ``Hello world'' in the top
697left corner of the window.
698The window will be correctly redrawn when covered and re-exposed.
699The program quits when the close icon or menu item is requested.
700
Fred Drake19479911998-02-13 06:58:54 +0000701\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000702import stdwin
703from stdwinevents import *
704
705def main():
706 mywin = stdwin.open('Hello')
707 #
708 while 1:
709 (type, win, detail) = stdwin.getevent()
710 if type == WE_DRAW:
711 draw = win.begindrawing()
712 draw.text((0, 0), 'Hello, world')
713 del draw
714 elif type == WE_CLOSE:
715 break
716
717main()
Fred Drake19479911998-02-13 06:58:54 +0000718\end{verbatim}
Fred Drake4471f201998-11-25 22:38:24 +0000719
Fred Drake295da241998-08-10 19:42:37 +0000720\section{\module{stdwinevents} ---
Fred Drake4471f201998-11-25 22:38:24 +0000721 Constants for use with \module{stdwin}}
Fred Drakeb91e9341998-07-23 17:59:49 +0000722\declaremodule{standard}{stdwinevents}
723
Fred Drake4471f201998-11-25 22:38:24 +0000724\modulesynopsis{Constant definitions for use with \module{stdwin}}
Fred Drakeb91e9341998-07-23 17:59:49 +0000725
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000726
727This module defines constants used by STDWIN for event types
Fred Drake4471f201998-11-25 22:38:24 +0000728(\constant{WE_ACTIVATE} etc.), command codes (\constant{WC_LEFT} etc.)
729and selection types (\constant{WS_PRIMARY} etc.).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000730Read the file for details.
731Suggested usage is
732
Fred Drake19479911998-02-13 06:58:54 +0000733\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000734>>> from stdwinevents import *
735>>>
Fred Drake19479911998-02-13 06:58:54 +0000736\end{verbatim}
Fred Drake4471f201998-11-25 22:38:24 +0000737
Fred Drake295da241998-08-10 19:42:37 +0000738\section{\module{rect} ---
Fred Drake4471f201998-11-25 22:38:24 +0000739 Functions for use with \module{stdwin}}
Fred Drakeb91e9341998-07-23 17:59:49 +0000740\declaremodule{standard}{rect}
741
Fred Drake4471f201998-11-25 22:38:24 +0000742\modulesynopsis{Geometry-related utility function for use with \module{stdwin}}
Fred Drakeb91e9341998-07-23 17:59:49 +0000743
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000744
745This module contains useful operations on rectangles.
Fred Drake4471f201998-11-25 22:38:24 +0000746A rectangle is defined as in module \module{stdwin}:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000747a pair of points, where a point is a pair of integers.
748For example, the rectangle
749
Fred Drake19479911998-02-13 06:58:54 +0000750\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000751(10, 20), (90, 80)
Fred Drake19479911998-02-13 06:58:54 +0000752\end{verbatim}
Fred Drake4471f201998-11-25 22:38:24 +0000753
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000754is a rectangle whose left, top, right and bottom edges are 10, 20, 90
Fred Drake4471f201998-11-25 22:38:24 +0000755and 80, respectively. Note that the positive vertical axis points
756down (as in \module{stdwin}).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000757
758The module defines the following objects:
759
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000760\begin{excdesc}{error}
761The exception raised by functions in this module when they detect an
Fred Drake4471f201998-11-25 22:38:24 +0000762error. The exception argument is a string describing the problem in
763more detail.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000764\end{excdesc}
765
766\begin{datadesc}{empty}
767The rectangle returned when some operations return an empty result.
768This makes it possible to quickly check whether a result is empty:
769
Fred Drake19479911998-02-13 06:58:54 +0000770\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000771>>> import rect
772>>> r1 = (10, 20), (90, 80)
773>>> r2 = (0, 0), (10, 20)
774>>> r3 = rect.intersect([r1, r2])
775>>> if r3 is rect.empty: print 'Empty intersection'
776Empty intersection
777>>>
Fred Drake19479911998-02-13 06:58:54 +0000778\end{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000779\end{datadesc}
780
781\begin{funcdesc}{is_empty}{r}
782Returns true if the given rectangle is empty.
783A rectangle
784\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}
785is empty if
Fred Drake4471f201998-11-25 22:38:24 +0000786\begin{math}\var{left} \geq \var{right}\end{math} or
787\begin{math}\var{top} \geq \var{bottom}\end{math}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000788\end{funcdesc}
789
790\begin{funcdesc}{intersect}{list}
791Returns the intersection of all rectangles in the list argument.
Fred Drake4471f201998-11-25 22:38:24 +0000792It may also be called with a tuple argument. Raises
793\exception{rect.error} if the list is empty. Returns
794\constant{rect.empty} if the intersection of the rectangles is empty.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000795\end{funcdesc}
796
797\begin{funcdesc}{union}{list}
798Returns the smallest rectangle that contains all non-empty rectangles in
Fred Drake4471f201998-11-25 22:38:24 +0000799the list argument. It may also be called with a tuple argument or
800with two or more rectangles as arguments. Returns
801\constant{rect.empty} if the list is empty or all its rectangles are
802empty.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000803\end{funcdesc}
804
Fred Drakecce10901998-03-17 06:33:25 +0000805\begin{funcdesc}{pointinrect}{point, rect}
Fred Drake4471f201998-11-25 22:38:24 +0000806Returns true if the point is inside the rectangle. By definition, a
807point \code{(\var{h}, \var{v})} is inside a rectangle
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000808\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})} if
Fred Drake4471f201998-11-25 22:38:24 +0000809\begin{math}\var{left} \leq \var{h} < \var{right}\end{math} and
810\begin{math}\var{top} \leq \var{v} < \var{bottom}\end{math}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000811\end{funcdesc}
812
Fred Drake4471f201998-11-25 22:38:24 +0000813\begin{funcdesc}{inset}{rect, (dh, dv)}
814Returns a rectangle that lies inside the \var{rect} argument by
815\var{dh} pixels horizontally and \var{dv} pixels vertically. If
816\var{dh} or \var{dv} is negative, the result lies outside \var{rect}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000817\end{funcdesc}
818
819\begin{funcdesc}{rect2geom}{rect}
820Converts a rectangle to geometry representation:
821\code{(\var{left}, \var{top}), (\var{width}, \var{height})}.
822\end{funcdesc}
823
824\begin{funcdesc}{geom2rect}{geom}
825Converts a rectangle given in geometry representation back to the
826standard rectangle representation
827\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}.
828\end{funcdesc}