blob: 7744a514df80b3d4365695ce1e323a35da37f095 [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.
45Return a window object; window object methods are described below.%
46\footnote{The Python version of STDWIN does not support draw procedures; all
47 drawing requests are reported as draw events.}
48\end{funcdesc}
49
50\begin{funcdesc}{getevent}{}
51Wait for and return the next event.
52An event is returned as a triple: the first element is the event
53type, a small integer; the second element is the window object to which
54the event applies, or
55\code{None}
56if it applies to no window in particular;
57the third element is type-dependent.
58Names for event types and command codes are defined in the standard
Fred Drake4471f201998-11-25 22:38:24 +000059module \module{stdwinevent}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000060\end{funcdesc}
61
62\begin{funcdesc}{pollevent}{}
63Return the next event, if one is immediately available.
64If no event is available, return \code{()}.
65\end{funcdesc}
66
67\begin{funcdesc}{getactive}{}
68Return the window that is currently active, or \code{None} if no
69window is currently active. (This can be emulated by monitoring
70WE_ACTIVATE and WE_DEACTIVATE events.)
71\end{funcdesc}
72
73\begin{funcdesc}{listfontnames}{pattern}
74Return the list of font names in the system that match the pattern (a
75string). The pattern should normally be \code{'*'}; returns all
76available fonts. If the underlying window system is X11, other
77patterns follow the standard X11 font selection syntax (as used e.g.
78in resource definitions), i.e. the wildcard character \code{'*'}
79matches any sequence of characters (including none) and \code{'?'}
80matches any single character.
Guido van Rossum470be141995-03-17 16:07:09 +000081On the Macintosh this function currently returns an empty list.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000082\end{funcdesc}
83
Fred Drakecce10901998-03-17 06:33:25 +000084\begin{funcdesc}{setdefscrollbars}{hflag, vflag}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000085Set the flags controlling whether subsequently opened windows will
86have horizontal and/or vertical scroll bars.
87\end{funcdesc}
88
Fred Drakecce10901998-03-17 06:33:25 +000089\begin{funcdesc}{setdefwinpos}{h, v}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000090Set the default window position for windows opened subsequently.
91\end{funcdesc}
92
Fred Drakecce10901998-03-17 06:33:25 +000093\begin{funcdesc}{setdefwinsize}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000094Set the default window size for windows opened subsequently.
95\end{funcdesc}
96
97\begin{funcdesc}{getdefscrollbars}{}
98Return the flags controlling whether subsequently opened windows will
99have horizontal and/or vertical scroll bars.
100\end{funcdesc}
101
102\begin{funcdesc}{getdefwinpos}{}
103Return the default window position for windows opened subsequently.
104\end{funcdesc}
105
106\begin{funcdesc}{getdefwinsize}{}
107Return the default window size for windows opened subsequently.
108\end{funcdesc}
109
110\begin{funcdesc}{getscrsize}{}
111Return the screen size in pixels.
112\end{funcdesc}
113
114\begin{funcdesc}{getscrmm}{}
115Return the screen size in millimeters.
116\end{funcdesc}
117
118\begin{funcdesc}{fetchcolor}{colorname}
119Return the pixel value corresponding to the given color name.
120Return the default foreground color for unknown color names.
Guido van Rossum16d6e711994-08-08 12:30:22 +0000121Hint: the following code tests whether you are on a machine that
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000122supports more than two colors:
Fred Drake19479911998-02-13 06:58:54 +0000123\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000124if stdwin.fetchcolor('black') <> \
125 stdwin.fetchcolor('red') <> \
126 stdwin.fetchcolor('white'):
127 print 'color machine'
128else:
129 print 'monochrome machine'
Fred Drake19479911998-02-13 06:58:54 +0000130\end{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000131\end{funcdesc}
132
133\begin{funcdesc}{setfgcolor}{pixel}
134Set the default foreground color.
135This will become the default foreground color of windows opened
136subsequently, including dialogs.
137\end{funcdesc}
138
139\begin{funcdesc}{setbgcolor}{pixel}
140Set the default background color.
141This will become the default background color of windows opened
142subsequently, including dialogs.
143\end{funcdesc}
144
145\begin{funcdesc}{getfgcolor}{}
146Return the pixel value of the current default foreground color.
147\end{funcdesc}
148
149\begin{funcdesc}{getbgcolor}{}
150Return the pixel value of the current default background color.
151\end{funcdesc}
152
153\begin{funcdesc}{setfont}{fontname}
154Set the current default font.
155This will become the default font for windows opened subsequently,
Fred Drake4471f201998-11-25 22:38:24 +0000156and is also used by the text measuring functions \function{textwidth()},
157\function{textbreak()}, \function{lineheight()} and
158\function{baseline()} below. This accepts two more optional
159parameters, size and style: Size is the font size (in `points').
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000160Style is a single character specifying the style, as follows:
161\code{'b'} = bold,
162\code{'i'} = italic,
163\code{'o'} = bold + italic,
164\code{'u'} = underline;
165default style is roman.
166Size and style are ignored under X11 but used on the Macintosh.
167(Sorry for all this complexity --- a more uniform interface is being designed.)
168\end{funcdesc}
169
170\begin{funcdesc}{menucreate}{title}
171Create a menu object referring to a global menu (a menu that appears in
172all windows).
173Methods of menu objects are described below.
174Note: normally, menus are created locally; see the window method
Fred Drake4471f201998-11-25 22:38:24 +0000175\method{menucreate()} below.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000176\strong{Warning:} the menu only appears in a window as long as the object
177returned by this call exists.
178\end{funcdesc}
179
Fred Drakecce10901998-03-17 06:33:25 +0000180\begin{funcdesc}{newbitmap}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000181Create a new bitmap object of the given dimensions.
182Methods of bitmap objects are described below.
Guido van Rossum470be141995-03-17 16:07:09 +0000183Not available on the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000184\end{funcdesc}
185
186\begin{funcdesc}{fleep}{}
187Cause a beep or bell (or perhaps a `visual bell' or flash, hence the
188name).
189\end{funcdesc}
190
191\begin{funcdesc}{message}{string}
192Display a dialog box containing the string.
193The user must click OK before the function returns.
194\end{funcdesc}
195
Fred Drakecce10901998-03-17 06:33:25 +0000196\begin{funcdesc}{askync}{prompt, default}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000197Display a dialog that prompts the user to answer a question with yes or
Fred Drake4471f201998-11-25 22:38:24 +0000198no. Return 0 for no, 1 for yes. If the user hits the Return key, the
199default (which must be 0 or 1) is returned. If the user cancels the
200dialog, \exception{KeyboardInterrupt} is raised.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000201\end{funcdesc}
202
Fred Drakecce10901998-03-17 06:33:25 +0000203\begin{funcdesc}{askstr}{prompt, default}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000204Display a dialog that prompts the user for a string.
205If the user hits the Return key, the default string is returned.
Fred Drake4471f201998-11-25 22:38:24 +0000206If the user cancels the dialog, \exception{KeyboardInterrupt} is
207raised.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000208\end{funcdesc}
209
Fred Drakecce10901998-03-17 06:33:25 +0000210\begin{funcdesc}{askfile}{prompt, default, new}
Fred Drake4471f201998-11-25 22:38:24 +0000211Ask the user to specify a filename. If \var{new} is zero it must be
212an existing file; otherwise, it must be a new file. If the user
213cancels the dialog, \exception{KeyboardInterrupt} is raised.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000214\end{funcdesc}
215
Fred Drakecce10901998-03-17 06:33:25 +0000216\begin{funcdesc}{setcutbuffer}{i, string}
Fred Drake4471f201998-11-25 22:38:24 +0000217Store the string in the system's cut buffer number \var{i}, where it
218can be found (for pasting) by other applications. On X11, there are 8
219cut buffers (numbered 0..7). Cut buffer number 0 is the `clipboard'
220on the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000221\end{funcdesc}
222
223\begin{funcdesc}{getcutbuffer}{i}
Fred Drake4471f201998-11-25 22:38:24 +0000224Return the contents of the system's cut buffer number \var{i}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000225\end{funcdesc}
226
227\begin{funcdesc}{rotatecutbuffers}{n}
Fred Drake4471f201998-11-25 22:38:24 +0000228On X11, rotate the 8 cut buffers by \var{n}. Ignored on the
229Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000230\end{funcdesc}
231
232\begin{funcdesc}{getselection}{i}
Fred Drake4471f201998-11-25 22:38:24 +0000233Return X11 selection number \var{i.} Selections are not cut buffers.
234Selection numbers are defined in module \module{stdwinevents}.
235Selection \constant{WS_PRIMARY} is the \dfn{primary} selection (used
236by \program{xterm}, for instance); selection \constant{WS_SECONDARY}
237is the \dfn{secondary} selection; selection \constant{WS_CLIPBOARD} is
238the \dfn{clipboard} selection (used by \program{xclipboard}). On the
239Macintosh, this always returns an empty string.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000240\end{funcdesc}
241
242\begin{funcdesc}{resetselection}{i}
Fred Drake4471f201998-11-25 22:38:24 +0000243Reset selection number \var{i}, if this process owns it. (See window
244method \method{setselection()}).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000245\end{funcdesc}
246
247\begin{funcdesc}{baseline}{}
248Return the baseline of the current font (defined by STDWIN as the
249vertical distance between the baseline and the top of the
250characters).
251\end{funcdesc}
252
253\begin{funcdesc}{lineheight}{}
254Return the total line height of the current font.
255\end{funcdesc}
256
Fred Drakecce10901998-03-17 06:33:25 +0000257\begin{funcdesc}{textbreak}{str, width}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000258Return the number of characters of the string that fit into a space of
259\var{width}
260bits wide when drawn in the curent font.
261\end{funcdesc}
262
263\begin{funcdesc}{textwidth}{str}
264Return the width in bits of the string when drawn in the current font.
265\end{funcdesc}
266
267\begin{funcdesc}{connectionnumber}{}
268\funcline{fileno}{}
269(X11 under \UNIX{} only) Return the ``connection number'' used by the
270underlying X11 implementation. (This is normally the file number of
271the socket.) Both functions return the same value;
Fred Drake4471f201998-11-25 22:38:24 +0000272\method{connectionnumber()} is named after the corresponding function in
273X11 and STDWIN, while \method{fileno()} makes it possible to use the
274\module{stdwin} module as a ``file'' object parameter to
275\function{select.select()}. Note that if \constant{select()} implies that
276input is possible on \module{stdwin}, this does not guarantee that an
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000277event is ready --- it may be some internal communication going on
278between the X server and the client library. Thus, you should call
Fred Drake4471f201998-11-25 22:38:24 +0000279\function{stdwin.pollevent()} until it returns \code{None} to check for
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000280events if you don't want your program to block. Because of internal
Fred Drake4471f201998-11-25 22:38:24 +0000281buffering in X11, it is also possible that \function{stdwin.pollevent()}
282returns an event while \function{select()} does not find \module{stdwin} to
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000283be ready, so you should read any pending events with
Fred Drake4471f201998-11-25 22:38:24 +0000284\function{stdwin.pollevent()} until it returns \code{None} before entering
285a blocking \function{select()} call.
286\withsubitem{(in module select)}{\ttindex{select()}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000287\end{funcdesc}
288
Guido van Rossum470be141995-03-17 16:07:09 +0000289\subsection{Window Objects}
Fred Drake4b3f0311996-12-13 22:04:31 +0000290\nodename{STDWIN Window Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000291
Fred Drake4471f201998-11-25 22:38:24 +0000292Window objects are created by \function{stdwin.open()}. They are closed
293by their \method{close()} method or when they are garbage-collected.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000294Window objects have the following methods:
295
Fred Drake4471f201998-11-25 22:38:24 +0000296\begin{methoddesc}[window]{begindrawing}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000297Return a drawing object, whose methods (described below) allow drawing
298in the window.
Fred Drake4471f201998-11-25 22:38:24 +0000299\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000300
Fred Drake4471f201998-11-25 22:38:24 +0000301\begin{methoddesc}[window]{change}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000302Invalidate the given rectangle; this may cause a draw event.
Fred Drake4471f201998-11-25 22:38:24 +0000303\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000304
Fred Drake4471f201998-11-25 22:38:24 +0000305\begin{methoddesc}[window]{gettitle}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000306Returns the window's title string.
Fred Drake4471f201998-11-25 22:38:24 +0000307\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000308
Fred Drake4471f201998-11-25 22:38:24 +0000309\begin{methoddesc}[window]{getdocsize}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000310\begin{sloppypar}
311Return a pair of integers giving the size of the document as set by
Fred Drake4471f201998-11-25 22:38:24 +0000312\method{setdocsize()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000313\end{sloppypar}
Fred Drake4471f201998-11-25 22:38:24 +0000314\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000315
Fred Drake4471f201998-11-25 22:38:24 +0000316\begin{methoddesc}[window]{getorigin}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000317Return a pair of integers giving the origin of the window with respect
318to the document.
Fred Drake4471f201998-11-25 22:38:24 +0000319\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000320
Fred Drake4471f201998-11-25 22:38:24 +0000321\begin{methoddesc}[window]{gettitle}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000322Return the window's title string.
Fred Drake4471f201998-11-25 22:38:24 +0000323\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000324
Fred Drake4471f201998-11-25 22:38:24 +0000325\begin{methoddesc}[window]{getwinsize}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000326Return a pair of integers giving the size of the window.
Fred Drake4471f201998-11-25 22:38:24 +0000327\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000328
Fred Drake4471f201998-11-25 22:38:24 +0000329\begin{methoddesc}[window]{getwinpos}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000330Return a pair of integers giving the position of the window's upper
331left corner (relative to the upper left corner of the screen).
Fred Drake4471f201998-11-25 22:38:24 +0000332\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000333
Fred Drake4471f201998-11-25 22:38:24 +0000334\begin{methoddesc}[window]{menucreate}{title}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000335Create a menu object referring to a local menu (a menu that appears
336only in this window).
337Methods of menu objects are described below.
Fred Drakeaf8a0151998-01-14 14:51:31 +0000338\strong{Warning:} the menu only appears as long as the object
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000339returned by this call exists.
Fred Drake4471f201998-11-25 22:38:24 +0000340\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000341
Fred Drake4471f201998-11-25 22:38:24 +0000342\begin{methoddesc}[window]{scroll}{rect, point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000343Scroll the given rectangle by the vector given by the point.
Fred Drake4471f201998-11-25 22:38:24 +0000344\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000345
Fred Drake4471f201998-11-25 22:38:24 +0000346\begin{methoddesc}[window]{setdocsize}{point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000347Set the size of the drawing document.
Fred Drake4471f201998-11-25 22:38:24 +0000348\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000349
Fred Drake4471f201998-11-25 22:38:24 +0000350\begin{methoddesc}[window]{setorigin}{point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000351Move the origin of the window (its upper left corner)
352to the given point in the document.
Fred Drake4471f201998-11-25 22:38:24 +0000353\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000354
Fred Drake4471f201998-11-25 22:38:24 +0000355\begin{methoddesc}[window]{setselection}{i, str}
356Attempt to set X11 selection number \var{i} to the string \var{str}.
357(See \module{stdwin} function \function{getselection()} for the
358meaning of \var{i}.) Return true if it succeeds.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000359If succeeds, the window ``owns'' the selection until
Guido van Rossum16d6e711994-08-08 12:30:22 +0000360(a) another application takes ownership of the selection; or
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000361(b) the window is deleted; or
362(c) the application clears ownership by calling
Fred Drake4471f201998-11-25 22:38:24 +0000363\function{stdwin.resetselection(\var{i})}. When another application
364takes ownership of the selection, a \constant{WE_LOST_SEL} event is
365received for no particular window and with the selection number as
366detail. Ignored on the Macintosh.
367\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000368
Fred Drake4471f201998-11-25 22:38:24 +0000369\begin{methoddesc}[window]{settimer}{dsecs}
370Schedule a timer event for the window in \code{\var{dsecs}/10}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000371seconds.
Fred Drake4471f201998-11-25 22:38:24 +0000372\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000373
Fred Drake4471f201998-11-25 22:38:24 +0000374\begin{methoddesc}[window]{settitle}{title}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000375Set the window's title string.
Fred Drake4471f201998-11-25 22:38:24 +0000376\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000377
Fred Drake4471f201998-11-25 22:38:24 +0000378\begin{methoddesc}[window]{setwincursor}{name}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000379\begin{sloppypar}
Fred Drake4471f201998-11-25 22:38:24 +0000380Set the window cursor to a cursor of the given name. It raises
381\exception{RuntimeError} if no cursor of the given name exists.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000382Suitable names include
383\code{'ibeam'},
384\code{'arrow'},
385\code{'cross'},
386\code{'watch'}
387and
388\code{'plus'}.
Fred Drakea5aefba1998-08-14 17:05:17 +0000389On X11, there are many more (see \code{<X11/cursorfont.h>}).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000390\end{sloppypar}
Fred Drake4471f201998-11-25 22:38:24 +0000391\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000392
Fred Drake4471f201998-11-25 22:38:24 +0000393\begin{methoddesc}[window]{setwinpos}{h, v}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000394Set the the position of the window's upper left corner (relative to
395the upper left corner of the screen).
Fred Drake4471f201998-11-25 22:38:24 +0000396\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000397
Fred Drake4471f201998-11-25 22:38:24 +0000398\begin{methoddesc}[window]{setwinsize}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000399Set the window's size.
Fred Drake4471f201998-11-25 22:38:24 +0000400\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000401
Fred Drake4471f201998-11-25 22:38:24 +0000402\begin{methoddesc}[window]{show}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000403Try to ensure that the given rectangle of the document is visible in
404the window.
Fred Drake4471f201998-11-25 22:38:24 +0000405\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000406
Fred Drake4471f201998-11-25 22:38:24 +0000407\begin{methoddesc}[window]{textcreate}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000408Create a text-edit object in the document at the given rectangle.
409Methods of text-edit objects are described below.
Fred Drake4471f201998-11-25 22:38:24 +0000410\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000411
Fred Drake4471f201998-11-25 22:38:24 +0000412\begin{methoddesc}[window]{setactive}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000413Attempt to make this window the active window. If successful, this
414will generate a WE_ACTIVATE event (and a WE_DEACTIVATE event in case
415another window in this application became inactive).
Fred Drake4471f201998-11-25 22:38:24 +0000416\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000417
Fred Drake4471f201998-11-25 22:38:24 +0000418\begin{methoddesc}[window]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000419Discard the window object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000420\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000421
Guido van Rossum470be141995-03-17 16:07:09 +0000422\subsection{Drawing Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000423
424Drawing objects are created exclusively by the window method
Fred Drake4471f201998-11-25 22:38:24 +0000425\method{begindrawing()}. Only one drawing object can exist at any
426given time; the drawing object must be deleted to finish drawing. No
427drawing object may exist when \function{stdwin.getevent()} is called.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000428Drawing objects have the following methods:
429
Fred Drake4471f201998-11-25 22:38:24 +0000430\begin{methoddesc}[drawing]{box}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000431Draw a box just inside a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000432\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000433
Fred Drake4471f201998-11-25 22:38:24 +0000434\begin{methoddesc}[drawing]{circle}{center, radius}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000435Draw a circle with given center point and radius.
Fred Drake4471f201998-11-25 22:38:24 +0000436\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000437
Fred Drake4471f201998-11-25 22:38:24 +0000438\begin{methoddesc}[drawing]{elarc}{center, (rh, rv), (a1, a2)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000439Draw an elliptical arc with given center point.
440\code{(\var{rh}, \var{rv})}
441gives the half sizes of the horizontal and vertical radii.
442\code{(\var{a1}, \var{a2})}
443gives the angles (in degrees) of the begin and end points.
4440 degrees is at 3 o'clock, 90 degrees is at 12 o'clock.
Fred Drake4471f201998-11-25 22:38:24 +0000445\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000446
Fred Drake4471f201998-11-25 22:38:24 +0000447\begin{methoddesc}[drawing]{erase}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000448Erase a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000449\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000450
Fred Drake4471f201998-11-25 22:38:24 +0000451\begin{methoddesc}[drawing]{fillcircle}{center, radius}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000452Draw a filled circle with given center point and radius.
Fred Drake4471f201998-11-25 22:38:24 +0000453\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000454
Fred Drake4471f201998-11-25 22:38:24 +0000455\begin{methoddesc}[drawing]{fillelarc}{center, (rh, rv), (a1, a2)}
456Draw a filled elliptical arc; arguments as for \method{elarc()}.
457\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000458
Fred Drake4471f201998-11-25 22:38:24 +0000459\begin{methoddesc}[drawing]{fillpoly}{points}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000460Draw a filled polygon given by a list (or tuple) of points.
Fred Drake4471f201998-11-25 22:38:24 +0000461\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000462
Fred Drake4471f201998-11-25 22:38:24 +0000463\begin{methoddesc}[drawing]{invert}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000464Invert a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000465\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000466
Fred Drake4471f201998-11-25 22:38:24 +0000467\begin{methoddesc}[drawing]{line}{p1, p2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000468Draw a line from point
469\var{p1}
470to
471\var{p2}.
Fred Drake4471f201998-11-25 22:38:24 +0000472\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000473
Fred Drake4471f201998-11-25 22:38:24 +0000474\begin{methoddesc}[drawing]{paint}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000475Fill a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000476\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000477
Fred Drake4471f201998-11-25 22:38:24 +0000478\begin{methoddesc}[drawing]{poly}{points}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000479Draw the lines connecting the given list (or tuple) of points.
Fred Drake4471f201998-11-25 22:38:24 +0000480\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000481
Fred Drake4471f201998-11-25 22:38:24 +0000482\begin{methoddesc}[drawing]{shade}{rect, percent}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000483Fill a rectangle with a shading pattern that is about
484\var{percent}
485percent filled.
Fred Drake4471f201998-11-25 22:38:24 +0000486\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000487
Fred Drake4471f201998-11-25 22:38:24 +0000488\begin{methoddesc}[drawing]{text}{p, str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000489Draw a string starting at point p (the point specifies the
490top left coordinate of the string).
Fred Drake4471f201998-11-25 22:38:24 +0000491\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000492
Fred Drake4471f201998-11-25 22:38:24 +0000493\begin{methoddesc}[drawing]{xorcircle}{center, radius}
494\funcline{xorelarc}{center, (rh, rv), (a1, a2)}
Fred Drakecce10901998-03-17 06:33:25 +0000495\funcline{xorline}{p1, p2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000496\funcline{xorpoly}{points}
497Draw a circle, an elliptical arc, a line or a polygon, respectively,
498in XOR mode.
Fred Drake4471f201998-11-25 22:38:24 +0000499\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000500
Fred Drake4471f201998-11-25 22:38:24 +0000501\begin{methoddesc}[drawing]{setfgcolor}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000502\funcline{setbgcolor}{}
503\funcline{getfgcolor}{}
504\funcline{getbgcolor}{}
505These functions are similar to the corresponding functions described
Fred Drake4471f201998-11-25 22:38:24 +0000506above for the \module{stdwin}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000507module, but affect or return the colors currently used for drawing
508instead of the global default colors.
509When a drawing object is created, its colors are set to the window's
510default colors, which are in turn initialized from the global default
511colors when the window is created.
Fred Drake4471f201998-11-25 22:38:24 +0000512\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000513
Fred Drake4471f201998-11-25 22:38:24 +0000514\begin{methoddesc}[drawing]{setfont}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000515\funcline{baseline}{}
516\funcline{lineheight}{}
517\funcline{textbreak}{}
518\funcline{textwidth}{}
519These functions are similar to the corresponding functions described
Fred Drake4471f201998-11-25 22:38:24 +0000520above for the \module{stdwin}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000521module, but affect or use the current drawing font instead of
522the global default font.
523When a drawing object is created, its font is set to the window's
524default font, which is in turn initialized from the global default
525font when the window is created.
Fred Drake4471f201998-11-25 22:38:24 +0000526\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000527
Fred Drake4471f201998-11-25 22:38:24 +0000528\begin{methoddesc}[drawing]{bitmap}{point, bitmap, mask}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000529Draw the \var{bitmap} with its top left corner at \var{point}.
530If the optional \var{mask} argument is present, it should be either
531the same object as \var{bitmap}, to draw only those bits that are set
532in the bitmap, in the foreground color, or \code{None}, to draw all
533bits (ones are drawn in the foreground color, zeros in the background
534color).
Guido van Rossum470be141995-03-17 16:07:09 +0000535Not available on the Macintosh.
Fred Drake4471f201998-11-25 22:38:24 +0000536\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000537
Fred Drake4471f201998-11-25 22:38:24 +0000538\begin{methoddesc}[drawing]{cliprect}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000539Set the ``clipping region'' to a rectangle.
540The clipping region limits the effect of all drawing operations, until
541it is changed again or until the drawing object is closed. When a
542drawing object is created the clipping region is set to the entire
543window. When an object to be drawn falls partly outside the clipping
544region, the set of pixels drawn is the intersection of the clipping
545region and the set of pixels that would be drawn by the same operation
546in the absence of a clipping region.
Fred Drake4471f201998-11-25 22:38:24 +0000547\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000548
Fred Drake4471f201998-11-25 22:38:24 +0000549\begin{methoddesc}[drawing]{noclip}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000550Reset the clipping region to the entire window.
Fred Drake4471f201998-11-25 22:38:24 +0000551\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000552
Fred Drake4471f201998-11-25 22:38:24 +0000553\begin{methoddesc}[drawing]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000554\funcline{enddrawing}{}
555Discard the drawing object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000556\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000557
Guido van Rossum470be141995-03-17 16:07:09 +0000558\subsection{Menu Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000559
560A menu object represents a menu.
561The menu is destroyed when the menu object is deleted.
562The following methods are defined:
563
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000564
Fred Drake4471f201998-11-25 22:38:24 +0000565\begin{methoddesc}[menu]{additem}{text, shortcut}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000566Add a menu item with given text.
567The shortcut must be a string of length 1, or omitted (to specify no
568shortcut).
Fred Drake4471f201998-11-25 22:38:24 +0000569\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000570
Fred Drake4471f201998-11-25 22:38:24 +0000571\begin{methoddesc}[menu]{setitem}{i, text}
572Set the text of item number \var{i}.
573\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000574
Fred Drake4471f201998-11-25 22:38:24 +0000575\begin{methoddesc}[menu]{enable}{i, flag}
576Enable or disables item \var{i}.
577\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000578
Fred Drake4471f201998-11-25 22:38:24 +0000579\begin{methoddesc}[menu]{check}{i, flag}
580Set or clear the \dfn{check mark} for item \var{i}.
581\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000582
Fred Drake4471f201998-11-25 22:38:24 +0000583\begin{methoddesc}[menu]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000584Discard the menu object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000585\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000586
Guido van Rossum470be141995-03-17 16:07:09 +0000587\subsection{Bitmap Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000588
589A bitmap represents a rectangular array of bits.
590The top left bit has coordinate (0, 0).
Fred Drake4471f201998-11-25 22:38:24 +0000591A bitmap can be drawn with the \method{bitmap()} method of a drawing object.
Guido van Rossum470be141995-03-17 16:07:09 +0000592Bitmaps are currently not available on the Macintosh.
593
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000594The following methods are defined:
595
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000596
Fred Drake4471f201998-11-25 22:38:24 +0000597\begin{methoddesc}[bitmap]{getsize}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000598Return a tuple representing the width and height of the bitmap.
Fred Drake4471f201998-11-25 22:38:24 +0000599(This returns the values that have been passed to the
600\function{newbitmap()} function.)
601\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000602
Fred Drake4471f201998-11-25 22:38:24 +0000603\begin{methoddesc}[bitmap]{setbit}{point, bit}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000604Set the value of the bit indicated by \var{point} to \var{bit}.
Fred Drake4471f201998-11-25 22:38:24 +0000605\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000606
Fred Drake4471f201998-11-25 22:38:24 +0000607\begin{methoddesc}[bitmap]{getbit}{point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000608Return the value of the bit indicated by \var{point}.
Fred Drake4471f201998-11-25 22:38:24 +0000609\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000610
Fred Drake4471f201998-11-25 22:38:24 +0000611\begin{methoddesc}[bitmap]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000612Discard the bitmap object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000613\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000614
Guido van Rossum470be141995-03-17 16:07:09 +0000615\subsection{Text-edit Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000616
617A text-edit object represents a text-edit block.
Fred Drake4471f201998-11-25 22:38:24 +0000618For semantics, see the STDWIN documentation for \C{} programmers.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000619The following methods exist:
620
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000621
Fred Drake4471f201998-11-25 22:38:24 +0000622\begin{methoddesc}[text-edit]{arrow}{code}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000623Pass an arrow event to the text-edit block.
Fred Drake4471f201998-11-25 22:38:24 +0000624The \var{code} must be one of \constant{WC_LEFT}, \constant{WC_RIGHT},
625\constant{WC_UP} or \constant{WC_DOWN} (see module
626\module{stdwinevents}).
627\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000628
Fred Drake4471f201998-11-25 22:38:24 +0000629\begin{methoddesc}[text-edit]{draw}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000630Pass a draw event to the text-edit block.
631The rectangle specifies the redraw area.
Fred Drake4471f201998-11-25 22:38:24 +0000632\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000633
Fred Drake4471f201998-11-25 22:38:24 +0000634\begin{methoddesc}[text-edit]{event}{type, window, detail}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000635Pass an event gotten from
Fred Drake4471f201998-11-25 22:38:24 +0000636\function{stdwin.getevent()}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000637to the text-edit block.
638Return true if the event was handled.
Fred Drake4471f201998-11-25 22:38:24 +0000639\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000640
Fred Drake4471f201998-11-25 22:38:24 +0000641\begin{methoddesc}[text-edit]{getfocus}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000642Return 2 integers representing the start and end positions of the
643focus, usable as slice indices on the string returned by
Fred Drake4471f201998-11-25 22:38:24 +0000644\method{gettext()}.
645\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000646
Fred Drake4471f201998-11-25 22:38:24 +0000647\begin{methoddesc}[text-edit]{getfocustext}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000648Return the text in the focus.
Fred Drake4471f201998-11-25 22:38:24 +0000649\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000650
Fred Drake4471f201998-11-25 22:38:24 +0000651\begin{methoddesc}[text-edit]{getrect}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000652Return a rectangle giving the actual position of the text-edit block.
653(The bottom coordinate may differ from the initial position because
654the block automatically shrinks or grows to fit.)
Fred Drake4471f201998-11-25 22:38:24 +0000655\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000656
Fred Drake4471f201998-11-25 22:38:24 +0000657\begin{methoddesc}[text-edit]{gettext}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000658Return the entire text buffer.
Fred Drake4471f201998-11-25 22:38:24 +0000659\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000660
Fred Drake4471f201998-11-25 22:38:24 +0000661\begin{methoddesc}[text-edit]{move}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000662Specify a new position for the text-edit block in the document.
Fred Drake4471f201998-11-25 22:38:24 +0000663\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000664
Fred Drake4471f201998-11-25 22:38:24 +0000665\begin{methoddesc}[text-edit]{replace}{str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000666Replace the text in the focus by the given string.
667The new focus is an insert point at the end of the string.
Fred Drake4471f201998-11-25 22:38:24 +0000668\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000669
Fred Drake4471f201998-11-25 22:38:24 +0000670\begin{methoddesc}[text-edit]{setfocus}{i, j}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000671Specify the new focus.
672Out-of-bounds values are silently clipped.
Fred Drake4471f201998-11-25 22:38:24 +0000673\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000674
Fred Drake4471f201998-11-25 22:38:24 +0000675\begin{methoddesc}[text-edit]{settext}{str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000676Replace the entire text buffer by the given string and set the focus
677to \code{(0, 0)}.
Fred Drake4471f201998-11-25 22:38:24 +0000678\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000679
Fred Drake4471f201998-11-25 22:38:24 +0000680\begin{methoddesc}[text-edit]{setview}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000681Set the view rectangle to \var{rect}. If \var{rect} is \code{None},
682viewing mode is reset. In viewing mode, all output from the text-edit
683object is clipped to the viewing rectangle. This may be useful to
684implement your own scrolling text subwindow.
Fred Drake4471f201998-11-25 22:38:24 +0000685\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000686
Fred Drake4471f201998-11-25 22:38:24 +0000687\begin{methoddesc}[text-edit]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000688Discard the text-edit object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000689\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000690
691\subsection{Example}
Guido van Rossum86cb0921995-03-20 12:59:56 +0000692\nodename{STDWIN Example}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000693
694Here is a minimal example of using STDWIN in Python.
695It creates a window and draws the string ``Hello world'' in the top
696left corner of the window.
697The window will be correctly redrawn when covered and re-exposed.
698The program quits when the close icon or menu item is requested.
699
Fred Drake19479911998-02-13 06:58:54 +0000700\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000701import stdwin
702from stdwinevents import *
703
704def main():
705 mywin = stdwin.open('Hello')
706 #
707 while 1:
708 (type, win, detail) = stdwin.getevent()
709 if type == WE_DRAW:
710 draw = win.begindrawing()
711 draw.text((0, 0), 'Hello, world')
712 del draw
713 elif type == WE_CLOSE:
714 break
715
716main()
Fred Drake19479911998-02-13 06:58:54 +0000717\end{verbatim}
Fred Drake4471f201998-11-25 22:38:24 +0000718
Fred Drake295da241998-08-10 19:42:37 +0000719\section{\module{stdwinevents} ---
Fred Drake4471f201998-11-25 22:38:24 +0000720 Constants for use with \module{stdwin}}
Fred Drakeb91e9341998-07-23 17:59:49 +0000721\declaremodule{standard}{stdwinevents}
722
Fred Drake4471f201998-11-25 22:38:24 +0000723\modulesynopsis{Constant definitions for use with \module{stdwin}}
Fred Drakeb91e9341998-07-23 17:59:49 +0000724
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000725
726This module defines constants used by STDWIN for event types
Fred Drake4471f201998-11-25 22:38:24 +0000727(\constant{WE_ACTIVATE} etc.), command codes (\constant{WC_LEFT} etc.)
728and selection types (\constant{WS_PRIMARY} etc.).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000729Read the file for details.
730Suggested usage is
731
Fred Drake19479911998-02-13 06:58:54 +0000732\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000733>>> from stdwinevents import *
734>>>
Fred Drake19479911998-02-13 06:58:54 +0000735\end{verbatim}
Fred Drake4471f201998-11-25 22:38:24 +0000736
Fred Drake295da241998-08-10 19:42:37 +0000737\section{\module{rect} ---
Fred Drake4471f201998-11-25 22:38:24 +0000738 Functions for use with \module{stdwin}}
Fred Drakeb91e9341998-07-23 17:59:49 +0000739\declaremodule{standard}{rect}
740
Fred Drake4471f201998-11-25 22:38:24 +0000741\modulesynopsis{Geometry-related utility function for use with \module{stdwin}}
Fred Drakeb91e9341998-07-23 17:59:49 +0000742
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000743
744This module contains useful operations on rectangles.
Fred Drake4471f201998-11-25 22:38:24 +0000745A rectangle is defined as in module \module{stdwin}:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000746a pair of points, where a point is a pair of integers.
747For example, the rectangle
748
Fred Drake19479911998-02-13 06:58:54 +0000749\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000750(10, 20), (90, 80)
Fred Drake19479911998-02-13 06:58:54 +0000751\end{verbatim}
Fred Drake4471f201998-11-25 22:38:24 +0000752
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000753is a rectangle whose left, top, right and bottom edges are 10, 20, 90
Fred Drake4471f201998-11-25 22:38:24 +0000754and 80, respectively. Note that the positive vertical axis points
755down (as in \module{stdwin}).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000756
757The module defines the following objects:
758
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000759\begin{excdesc}{error}
760The exception raised by functions in this module when they detect an
Fred Drake4471f201998-11-25 22:38:24 +0000761error. The exception argument is a string describing the problem in
762more detail.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000763\end{excdesc}
764
765\begin{datadesc}{empty}
766The rectangle returned when some operations return an empty result.
767This makes it possible to quickly check whether a result is empty:
768
Fred Drake19479911998-02-13 06:58:54 +0000769\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000770>>> import rect
771>>> r1 = (10, 20), (90, 80)
772>>> r2 = (0, 0), (10, 20)
773>>> r3 = rect.intersect([r1, r2])
774>>> if r3 is rect.empty: print 'Empty intersection'
775Empty intersection
776>>>
Fred Drake19479911998-02-13 06:58:54 +0000777\end{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000778\end{datadesc}
779
780\begin{funcdesc}{is_empty}{r}
781Returns true if the given rectangle is empty.
782A rectangle
783\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}
784is empty if
Fred Drake4471f201998-11-25 22:38:24 +0000785\begin{math}\var{left} \geq \var{right}\end{math} or
786\begin{math}\var{top} \geq \var{bottom}\end{math}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000787\end{funcdesc}
788
789\begin{funcdesc}{intersect}{list}
790Returns the intersection of all rectangles in the list argument.
Fred Drake4471f201998-11-25 22:38:24 +0000791It may also be called with a tuple argument. Raises
792\exception{rect.error} if the list is empty. Returns
793\constant{rect.empty} if the intersection of the rectangles is empty.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000794\end{funcdesc}
795
796\begin{funcdesc}{union}{list}
797Returns the smallest rectangle that contains all non-empty rectangles in
Fred Drake4471f201998-11-25 22:38:24 +0000798the list argument. It may also be called with a tuple argument or
799with two or more rectangles as arguments. Returns
800\constant{rect.empty} if the list is empty or all its rectangles are
801empty.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000802\end{funcdesc}
803
Fred Drakecce10901998-03-17 06:33:25 +0000804\begin{funcdesc}{pointinrect}{point, rect}
Fred Drake4471f201998-11-25 22:38:24 +0000805Returns true if the point is inside the rectangle. By definition, a
806point \code{(\var{h}, \var{v})} is inside a rectangle
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000807\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})} if
Fred Drake4471f201998-11-25 22:38:24 +0000808\begin{math}\var{left} \leq \var{h} < \var{right}\end{math} and
809\begin{math}\var{top} \leq \var{v} < \var{bottom}\end{math}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000810\end{funcdesc}
811
Fred Drake4471f201998-11-25 22:38:24 +0000812\begin{funcdesc}{inset}{rect, (dh, dv)}
813Returns a rectangle that lies inside the \var{rect} argument by
814\var{dh} pixels horizontally and \var{dv} pixels vertically. If
815\var{dh} or \var{dv} is negative, the result lies outside \var{rect}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000816\end{funcdesc}
817
818\begin{funcdesc}{rect2geom}{rect}
819Converts a rectangle to geometry representation:
820\code{(\var{left}, \var{top}), (\var{width}, \var{height})}.
821\end{funcdesc}
822
823\begin{funcdesc}{geom2rect}{geom}
824Converts a rectangle given in geometry representation back to the
825standard rectangle representation
826\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}.
827\end{funcdesc}