blob: a75edf67111f9997582778b0affdbc7b29034d9f [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
Fred Drake0aa811c2001-10-20 04:24:09 +00007\warning{Using STDWIN is not recommended for new
Guido van Rossumecde7811995-03-28 13:35:14 +00008applications. 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
Fred Drake0aa811c2001-10-20 04:24:09 +000015native toolkit interfaces for the Macintosh.}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000016
Fred Drakeffbe6871999-04-22 21:23:22 +000017
Fred Drake295da241998-08-10 19:42:37 +000018\section{\module{stdwin} ---
Fred Drake8ee679f2001-07-14 02:50:55 +000019 Platform-independent Graphical User Interface System}
Fred Drakeb91e9341998-07-23 17:59:49 +000020
Fred Drakeffbe6871999-04-22 21:23:22 +000021\declaremodule{builtin}{stdwin}
Fred Drake8ee679f2001-07-14 02:50:55 +000022\modulesynopsis{Older graphical user interface system for X11 and Macintosh.}
Fred Drakeb91e9341998-07-23 17:59:49 +000023
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000024
25This module defines several new object types and functions that
Guido van Rossumecde7811995-03-28 13:35:14 +000026provide access to the functionality of STDWIN.
Guido van Rossum470be141995-03-17 16:07:09 +000027
Fred Drake4471f201998-11-25 22:38:24 +000028On \UNIX{} running X11, it can only be used if the \envvar{DISPLAY}
Fred Drake6e9ea591999-11-09 19:44:44 +000029environment variable is set or an explicit
30\programopt{-display} \var{displayname} argument is passed to the
31Python interpreter.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000032
33Functions have names that usually resemble their C STDWIN counterparts
Fred Drake6e9ea591999-11-09 19:44:44 +000034with the initial `w' dropped. Points are represented by pairs of
35integers; rectangles by pairs of points. For a complete description
36of STDWIN please refer to the documentation of STDWIN for C
37programmers (aforementioned CWI report).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000038
Fred Drake3a0351c1998-04-04 07:23:21 +000039\subsection{Functions Defined in Module \module{stdwin}}
Guido van Rossum86cb0921995-03-20 12:59:56 +000040\nodename{STDWIN Functions}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000041
Fred Drake4471f201998-11-25 22:38:24 +000042The following functions are defined in the \module{stdwin} module:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000043
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000044\begin{funcdesc}{open}{title}
45Open a new window whose initial title is given by the string argument.
Fred Drakeea003fc1999-04-05 21:59:15 +000046Return a window object; window object methods are described
47below.\footnote{
48 The Python version of STDWIN does not support draw procedures;
49 all drawing requests are reported as draw events.}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000050\end{funcdesc}
51
52\begin{funcdesc}{getevent}{}
53Wait for and return the next event.
54An event is returned as a triple: the first element is the event
55type, a small integer; the second element is the window object to which
56the event applies, or
57\code{None}
58if it applies to no window in particular;
59the third element is type-dependent.
60Names for event types and command codes are defined in the standard
Fred Drakeffbe6871999-04-22 21:23:22 +000061module \refmodule{stdwinevents}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000062\end{funcdesc}
63
64\begin{funcdesc}{pollevent}{}
65Return the next event, if one is immediately available.
66If no event is available, return \code{()}.
67\end{funcdesc}
68
69\begin{funcdesc}{getactive}{}
70Return the window that is currently active, or \code{None} if no
71window is currently active. (This can be emulated by monitoring
72WE_ACTIVATE and WE_DEACTIVATE events.)
73\end{funcdesc}
74
75\begin{funcdesc}{listfontnames}{pattern}
76Return the list of font names in the system that match the pattern (a
77string). The pattern should normally be \code{'*'}; returns all
78available fonts. If the underlying window system is X11, other
79patterns follow the standard X11 font selection syntax (as used e.g.
80in resource definitions), i.e. the wildcard character \code{'*'}
81matches any sequence of characters (including none) and \code{'?'}
82matches any single character.
Guido van Rossum470be141995-03-17 16:07:09 +000083On the Macintosh this function currently returns an empty list.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000084\end{funcdesc}
85
Fred Drakecce10901998-03-17 06:33:25 +000086\begin{funcdesc}{setdefscrollbars}{hflag, vflag}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000087Set the flags controlling whether subsequently opened windows will
88have horizontal and/or vertical scroll bars.
89\end{funcdesc}
90
Fred Drakecce10901998-03-17 06:33:25 +000091\begin{funcdesc}{setdefwinpos}{h, v}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000092Set the default window position for windows opened subsequently.
93\end{funcdesc}
94
Fred Drakecce10901998-03-17 06:33:25 +000095\begin{funcdesc}{setdefwinsize}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000096Set the default window size for windows opened subsequently.
97\end{funcdesc}
98
99\begin{funcdesc}{getdefscrollbars}{}
100Return the flags controlling whether subsequently opened windows will
101have horizontal and/or vertical scroll bars.
102\end{funcdesc}
103
104\begin{funcdesc}{getdefwinpos}{}
105Return the default window position for windows opened subsequently.
106\end{funcdesc}
107
108\begin{funcdesc}{getdefwinsize}{}
109Return the default window size for windows opened subsequently.
110\end{funcdesc}
111
112\begin{funcdesc}{getscrsize}{}
113Return the screen size in pixels.
114\end{funcdesc}
115
116\begin{funcdesc}{getscrmm}{}
117Return the screen size in millimeters.
118\end{funcdesc}
119
120\begin{funcdesc}{fetchcolor}{colorname}
121Return the pixel value corresponding to the given color name.
122Return the default foreground color for unknown color names.
Guido van Rossum16d6e711994-08-08 12:30:22 +0000123Hint: the following code tests whether you are on a machine that
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000124supports more than two colors:
Fred Drake19479911998-02-13 06:58:54 +0000125\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000126if stdwin.fetchcolor('black') <> \
127 stdwin.fetchcolor('red') <> \
128 stdwin.fetchcolor('white'):
129 print 'color machine'
130else:
131 print 'monochrome machine'
Fred Drake19479911998-02-13 06:58:54 +0000132\end{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000133\end{funcdesc}
134
135\begin{funcdesc}{setfgcolor}{pixel}
136Set the default foreground color.
137This will become the default foreground color of windows opened
138subsequently, including dialogs.
139\end{funcdesc}
140
141\begin{funcdesc}{setbgcolor}{pixel}
142Set the default background color.
143This will become the default background color of windows opened
144subsequently, including dialogs.
145\end{funcdesc}
146
147\begin{funcdesc}{getfgcolor}{}
148Return the pixel value of the current default foreground color.
149\end{funcdesc}
150
151\begin{funcdesc}{getbgcolor}{}
152Return the pixel value of the current default background color.
153\end{funcdesc}
154
155\begin{funcdesc}{setfont}{fontname}
156Set the current default font.
157This will become the default font for windows opened subsequently,
Fred Drake4471f201998-11-25 22:38:24 +0000158and is also used by the text measuring functions \function{textwidth()},
159\function{textbreak()}, \function{lineheight()} and
160\function{baseline()} below. This accepts two more optional
161parameters, size and style: Size is the font size (in `points').
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000162Style is a single character specifying the style, as follows:
163\code{'b'} = bold,
164\code{'i'} = italic,
165\code{'o'} = bold + italic,
166\code{'u'} = underline;
167default style is roman.
168Size and style are ignored under X11 but used on the Macintosh.
169(Sorry for all this complexity --- a more uniform interface is being designed.)
170\end{funcdesc}
171
172\begin{funcdesc}{menucreate}{title}
173Create a menu object referring to a global menu (a menu that appears in
174all windows).
175Methods of menu objects are described below.
176Note: normally, menus are created locally; see the window method
Fred Drake4471f201998-11-25 22:38:24 +0000177\method{menucreate()} below.
Fred Drake0aa811c2001-10-20 04:24:09 +0000178\warning{The menu only appears in a window as long as the object
179returned by this call exists.}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000180\end{funcdesc}
181
Fred Drakecce10901998-03-17 06:33:25 +0000182\begin{funcdesc}{newbitmap}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000183Create a new bitmap object of the given dimensions.
184Methods of bitmap objects are described below.
Guido van Rossum470be141995-03-17 16:07:09 +0000185Not available on the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000186\end{funcdesc}
187
188\begin{funcdesc}{fleep}{}
189Cause a beep or bell (or perhaps a `visual bell' or flash, hence the
190name).
191\end{funcdesc}
192
193\begin{funcdesc}{message}{string}
194Display a dialog box containing the string.
195The user must click OK before the function returns.
196\end{funcdesc}
197
Fred Drakecce10901998-03-17 06:33:25 +0000198\begin{funcdesc}{askync}{prompt, default}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000199Display a dialog that prompts the user to answer a question with yes or
Fred Drake4471f201998-11-25 22:38:24 +0000200no. Return 0 for no, 1 for yes. If the user hits the Return key, the
201default (which must be 0 or 1) is returned. If the user cancels the
202dialog, \exception{KeyboardInterrupt} is raised.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000203\end{funcdesc}
204
Fred Drakecce10901998-03-17 06:33:25 +0000205\begin{funcdesc}{askstr}{prompt, default}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000206Display a dialog that prompts the user for a string.
207If the user hits the Return key, the default string is returned.
Fred Drake4471f201998-11-25 22:38:24 +0000208If the user cancels the dialog, \exception{KeyboardInterrupt} is
209raised.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000210\end{funcdesc}
211
Fred Drakecce10901998-03-17 06:33:25 +0000212\begin{funcdesc}{askfile}{prompt, default, new}
Fred Drake4471f201998-11-25 22:38:24 +0000213Ask the user to specify a filename. If \var{new} is zero it must be
214an existing file; otherwise, it must be a new file. If the user
215cancels the dialog, \exception{KeyboardInterrupt} is raised.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000216\end{funcdesc}
217
Fred Drakecce10901998-03-17 06:33:25 +0000218\begin{funcdesc}{setcutbuffer}{i, string}
Fred Drake4471f201998-11-25 22:38:24 +0000219Store the string in the system's cut buffer number \var{i}, where it
220can be found (for pasting) by other applications. On X11, there are 8
221cut buffers (numbered 0..7). Cut buffer number 0 is the `clipboard'
222on the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000223\end{funcdesc}
224
225\begin{funcdesc}{getcutbuffer}{i}
Fred Drake4471f201998-11-25 22:38:24 +0000226Return the contents of the system's cut buffer number \var{i}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000227\end{funcdesc}
228
229\begin{funcdesc}{rotatecutbuffers}{n}
Fred Drake4471f201998-11-25 22:38:24 +0000230On X11, rotate the 8 cut buffers by \var{n}. Ignored on the
231Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000232\end{funcdesc}
233
234\begin{funcdesc}{getselection}{i}
Fred Drake4471f201998-11-25 22:38:24 +0000235Return X11 selection number \var{i.} Selections are not cut buffers.
Fred Drakeffbe6871999-04-22 21:23:22 +0000236Selection numbers are defined in module \refmodule{stdwinevents}.
Fred Drake4471f201998-11-25 22:38:24 +0000237Selection \constant{WS_PRIMARY} is the \dfn{primary} selection (used
238by \program{xterm}, for instance); selection \constant{WS_SECONDARY}
239is the \dfn{secondary} selection; selection \constant{WS_CLIPBOARD} is
240the \dfn{clipboard} selection (used by \program{xclipboard}). On the
241Macintosh, this always returns an empty string.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000242\end{funcdesc}
243
244\begin{funcdesc}{resetselection}{i}
Fred Drake4471f201998-11-25 22:38:24 +0000245Reset selection number \var{i}, if this process owns it. (See window
246method \method{setselection()}).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000247\end{funcdesc}
248
249\begin{funcdesc}{baseline}{}
250Return the baseline of the current font (defined by STDWIN as the
251vertical distance between the baseline and the top of the
252characters).
253\end{funcdesc}
254
255\begin{funcdesc}{lineheight}{}
256Return the total line height of the current font.
257\end{funcdesc}
258
Fred Drakecce10901998-03-17 06:33:25 +0000259\begin{funcdesc}{textbreak}{str, width}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000260Return the number of characters of the string that fit into a space of
261\var{width}
Thomas Woutersf8316632000-07-16 19:01:10 +0000262bits wide when drawn in the current font.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000263\end{funcdesc}
264
265\begin{funcdesc}{textwidth}{str}
266Return the width in bits of the string when drawn in the current font.
267\end{funcdesc}
268
269\begin{funcdesc}{connectionnumber}{}
270\funcline{fileno}{}
271(X11 under \UNIX{} only) Return the ``connection number'' used by the
272underlying X11 implementation. (This is normally the file number of
273the socket.) Both functions return the same value;
Fred Drake4471f201998-11-25 22:38:24 +0000274\method{connectionnumber()} is named after the corresponding function in
275X11 and STDWIN, while \method{fileno()} makes it possible to use the
276\module{stdwin} module as a ``file'' object parameter to
277\function{select.select()}. Note that if \constant{select()} implies that
278input is possible on \module{stdwin}, this does not guarantee that an
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000279event is ready --- it may be some internal communication going on
280between the X server and the client library. Thus, you should call
Fred Drake4471f201998-11-25 22:38:24 +0000281\function{stdwin.pollevent()} until it returns \code{None} to check for
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000282events if you don't want your program to block. Because of internal
Fred Drake4471f201998-11-25 22:38:24 +0000283buffering in X11, it is also possible that \function{stdwin.pollevent()}
284returns an event while \function{select()} does not find \module{stdwin} to
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000285be ready, so you should read any pending events with
Fred Drake4471f201998-11-25 22:38:24 +0000286\function{stdwin.pollevent()} until it returns \code{None} before entering
287a blocking \function{select()} call.
288\withsubitem{(in module select)}{\ttindex{select()}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000289\end{funcdesc}
290
Guido van Rossum470be141995-03-17 16:07:09 +0000291\subsection{Window Objects}
Fred Drake4b3f0311996-12-13 22:04:31 +0000292\nodename{STDWIN Window Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000293
Fred Drake4471f201998-11-25 22:38:24 +0000294Window objects are created by \function{stdwin.open()}. They are closed
295by their \method{close()} method or when they are garbage-collected.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000296Window objects have the following methods:
297
Fred Drake4471f201998-11-25 22:38:24 +0000298\begin{methoddesc}[window]{begindrawing}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000299Return a drawing object, whose methods (described below) allow drawing
300in the window.
Fred Drake4471f201998-11-25 22:38:24 +0000301\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000302
Fred Drake4471f201998-11-25 22:38:24 +0000303\begin{methoddesc}[window]{change}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000304Invalidate the given rectangle; this may cause a draw event.
Fred Drake4471f201998-11-25 22:38:24 +0000305\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000306
Fred Drake4471f201998-11-25 22:38:24 +0000307\begin{methoddesc}[window]{gettitle}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000308Returns the window's title string.
Fred Drake4471f201998-11-25 22:38:24 +0000309\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000310
Fred Drake4471f201998-11-25 22:38:24 +0000311\begin{methoddesc}[window]{getdocsize}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000312\begin{sloppypar}
313Return a pair of integers giving the size of the document as set by
Fred Drake4471f201998-11-25 22:38:24 +0000314\method{setdocsize()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000315\end{sloppypar}
Fred Drake4471f201998-11-25 22:38:24 +0000316\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000317
Fred Drake4471f201998-11-25 22:38:24 +0000318\begin{methoddesc}[window]{getorigin}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000319Return a pair of integers giving the origin of the window with respect
320to the document.
Fred Drake4471f201998-11-25 22:38:24 +0000321\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000322
Fred Drake4471f201998-11-25 22:38:24 +0000323\begin{methoddesc}[window]{gettitle}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000324Return the window's title string.
Fred Drake4471f201998-11-25 22:38:24 +0000325\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000326
Fred Drake4471f201998-11-25 22:38:24 +0000327\begin{methoddesc}[window]{getwinsize}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000328Return a pair of integers giving the size of the window.
Fred Drake4471f201998-11-25 22:38:24 +0000329\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000330
Fred Drake4471f201998-11-25 22:38:24 +0000331\begin{methoddesc}[window]{getwinpos}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000332Return a pair of integers giving the position of the window's upper
333left corner (relative to the upper left corner of the screen).
Fred Drake4471f201998-11-25 22:38:24 +0000334\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000335
Fred Drake4471f201998-11-25 22:38:24 +0000336\begin{methoddesc}[window]{menucreate}{title}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000337Create a menu object referring to a local menu (a menu that appears
338only in this window).
339Methods of menu objects are described below.
Fred Drake0aa811c2001-10-20 04:24:09 +0000340\warning{The menu only appears as long as the object
341returned by this call exists.}
Fred Drake4471f201998-11-25 22:38:24 +0000342\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000343
Fred Drake4471f201998-11-25 22:38:24 +0000344\begin{methoddesc}[window]{scroll}{rect, point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000345Scroll the given rectangle by the vector given by the point.
Fred Drake4471f201998-11-25 22:38:24 +0000346\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000347
Fred Drake4471f201998-11-25 22:38:24 +0000348\begin{methoddesc}[window]{setdocsize}{point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000349Set the size of the drawing document.
Fred Drake4471f201998-11-25 22:38:24 +0000350\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000351
Fred Drake4471f201998-11-25 22:38:24 +0000352\begin{methoddesc}[window]{setorigin}{point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000353Move the origin of the window (its upper left corner)
354to the given point in the document.
Fred Drake4471f201998-11-25 22:38:24 +0000355\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000356
Fred Drake4471f201998-11-25 22:38:24 +0000357\begin{methoddesc}[window]{setselection}{i, str}
358Attempt to set X11 selection number \var{i} to the string \var{str}.
359(See \module{stdwin} function \function{getselection()} for the
360meaning of \var{i}.) Return true if it succeeds.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000361If succeeds, the window ``owns'' the selection until
Guido van Rossum16d6e711994-08-08 12:30:22 +0000362(a) another application takes ownership of the selection; or
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000363(b) the window is deleted; or
364(c) the application clears ownership by calling
Fred Drake4471f201998-11-25 22:38:24 +0000365\function{stdwin.resetselection(\var{i})}. When another application
366takes ownership of the selection, a \constant{WE_LOST_SEL} event is
367received for no particular window and with the selection number as
368detail. Ignored on the Macintosh.
369\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000370
Fred Drake4471f201998-11-25 22:38:24 +0000371\begin{methoddesc}[window]{settimer}{dsecs}
372Schedule a timer event for the window in \code{\var{dsecs}/10}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000373seconds.
Fred Drake4471f201998-11-25 22:38:24 +0000374\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000375
Fred Drake4471f201998-11-25 22:38:24 +0000376\begin{methoddesc}[window]{settitle}{title}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000377Set the window's title string.
Fred Drake4471f201998-11-25 22:38:24 +0000378\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000379
Fred Drake4471f201998-11-25 22:38:24 +0000380\begin{methoddesc}[window]{setwincursor}{name}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000381\begin{sloppypar}
Fred Drake4471f201998-11-25 22:38:24 +0000382Set the window cursor to a cursor of the given name. It raises
383\exception{RuntimeError} if no cursor of the given name exists.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000384Suitable names include
385\code{'ibeam'},
386\code{'arrow'},
387\code{'cross'},
388\code{'watch'}
389and
390\code{'plus'}.
Fred Drakea5aefba1998-08-14 17:05:17 +0000391On X11, there are many more (see \code{<X11/cursorfont.h>}).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000392\end{sloppypar}
Fred Drake4471f201998-11-25 22:38:24 +0000393\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000394
Fred Drake4471f201998-11-25 22:38:24 +0000395\begin{methoddesc}[window]{setwinpos}{h, v}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000396Set the the position of the window's upper left corner (relative to
397the upper left corner of the screen).
Fred Drake4471f201998-11-25 22:38:24 +0000398\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000399
Fred Drake4471f201998-11-25 22:38:24 +0000400\begin{methoddesc}[window]{setwinsize}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000401Set the window's size.
Fred Drake4471f201998-11-25 22:38:24 +0000402\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000403
Fred Drake4471f201998-11-25 22:38:24 +0000404\begin{methoddesc}[window]{show}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000405Try to ensure that the given rectangle of the document is visible in
406the window.
Fred Drake4471f201998-11-25 22:38:24 +0000407\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000408
Fred Drake4471f201998-11-25 22:38:24 +0000409\begin{methoddesc}[window]{textcreate}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000410Create a text-edit object in the document at the given rectangle.
411Methods of text-edit objects are described below.
Fred Drake4471f201998-11-25 22:38:24 +0000412\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000413
Fred Drake4471f201998-11-25 22:38:24 +0000414\begin{methoddesc}[window]{setactive}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000415Attempt to make this window the active window. If successful, this
416will generate a WE_ACTIVATE event (and a WE_DEACTIVATE event in case
417another window in this application became inactive).
Fred Drake4471f201998-11-25 22:38:24 +0000418\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000419
Fred Drake4471f201998-11-25 22:38:24 +0000420\begin{methoddesc}[window]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000421Discard the window object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000422\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000423
Guido van Rossum470be141995-03-17 16:07:09 +0000424\subsection{Drawing Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000425
426Drawing objects are created exclusively by the window method
Fred Drake4471f201998-11-25 22:38:24 +0000427\method{begindrawing()}. Only one drawing object can exist at any
428given time; the drawing object must be deleted to finish drawing. No
429drawing object may exist when \function{stdwin.getevent()} is called.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000430Drawing objects have the following methods:
431
Fred Drake4471f201998-11-25 22:38:24 +0000432\begin{methoddesc}[drawing]{box}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000433Draw a box just inside a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000434\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000435
Fred Drake4471f201998-11-25 22:38:24 +0000436\begin{methoddesc}[drawing]{circle}{center, radius}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000437Draw a circle with given center point and radius.
Fred Drake4471f201998-11-25 22:38:24 +0000438\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000439
Fred Drake4471f201998-11-25 22:38:24 +0000440\begin{methoddesc}[drawing]{elarc}{center, (rh, rv), (a1, a2)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000441Draw an elliptical arc with given center point.
442\code{(\var{rh}, \var{rv})}
443gives the half sizes of the horizontal and vertical radii.
444\code{(\var{a1}, \var{a2})}
445gives the angles (in degrees) of the begin and end points.
4460 degrees is at 3 o'clock, 90 degrees is at 12 o'clock.
Fred Drake4471f201998-11-25 22:38:24 +0000447\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000448
Fred Drake4471f201998-11-25 22:38:24 +0000449\begin{methoddesc}[drawing]{erase}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000450Erase a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000451\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000452
Fred Drake4471f201998-11-25 22:38:24 +0000453\begin{methoddesc}[drawing]{fillcircle}{center, radius}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000454Draw a filled circle with given center point and radius.
Fred Drake4471f201998-11-25 22:38:24 +0000455\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000456
Fred Drake4471f201998-11-25 22:38:24 +0000457\begin{methoddesc}[drawing]{fillelarc}{center, (rh, rv), (a1, a2)}
458Draw a filled elliptical arc; arguments as for \method{elarc()}.
459\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000460
Fred Drake4471f201998-11-25 22:38:24 +0000461\begin{methoddesc}[drawing]{fillpoly}{points}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000462Draw a filled polygon given by a list (or tuple) of points.
Fred Drake4471f201998-11-25 22:38:24 +0000463\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000464
Fred Drake4471f201998-11-25 22:38:24 +0000465\begin{methoddesc}[drawing]{invert}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000466Invert a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000467\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000468
Fred Drake4471f201998-11-25 22:38:24 +0000469\begin{methoddesc}[drawing]{line}{p1, p2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000470Draw a line from point
471\var{p1}
472to
473\var{p2}.
Fred Drake4471f201998-11-25 22:38:24 +0000474\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000475
Fred Drake4471f201998-11-25 22:38:24 +0000476\begin{methoddesc}[drawing]{paint}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000477Fill a rectangle.
Fred Drake4471f201998-11-25 22:38:24 +0000478\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000479
Fred Drake4471f201998-11-25 22:38:24 +0000480\begin{methoddesc}[drawing]{poly}{points}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000481Draw the lines connecting the given list (or tuple) of points.
Fred Drake4471f201998-11-25 22:38:24 +0000482\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000483
Fred Drake4471f201998-11-25 22:38:24 +0000484\begin{methoddesc}[drawing]{shade}{rect, percent}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000485Fill a rectangle with a shading pattern that is about
486\var{percent}
487percent filled.
Fred Drake4471f201998-11-25 22:38:24 +0000488\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000489
Fred Drake4471f201998-11-25 22:38:24 +0000490\begin{methoddesc}[drawing]{text}{p, str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000491Draw a string starting at point p (the point specifies the
492top left coordinate of the string).
Fred Drake4471f201998-11-25 22:38:24 +0000493\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000494
Fred Drake4471f201998-11-25 22:38:24 +0000495\begin{methoddesc}[drawing]{xorcircle}{center, radius}
496\funcline{xorelarc}{center, (rh, rv), (a1, a2)}
Fred Drakecce10901998-03-17 06:33:25 +0000497\funcline{xorline}{p1, p2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000498\funcline{xorpoly}{points}
499Draw a circle, an elliptical arc, a line or a polygon, respectively,
500in XOR mode.
Fred Drake4471f201998-11-25 22:38:24 +0000501\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000502
Fred Drake4471f201998-11-25 22:38:24 +0000503\begin{methoddesc}[drawing]{setfgcolor}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000504\funcline{setbgcolor}{}
505\funcline{getfgcolor}{}
506\funcline{getbgcolor}{}
507These functions are similar to the corresponding functions described
Fred Drake4471f201998-11-25 22:38:24 +0000508above for the \module{stdwin}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000509module, but affect or return the colors currently used for drawing
510instead of the global default colors.
511When a drawing object is created, its colors are set to the window's
512default colors, which are in turn initialized from the global default
513colors when the window is created.
Fred Drake4471f201998-11-25 22:38:24 +0000514\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000515
Fred Drake4471f201998-11-25 22:38:24 +0000516\begin{methoddesc}[drawing]{setfont}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000517\funcline{baseline}{}
518\funcline{lineheight}{}
519\funcline{textbreak}{}
520\funcline{textwidth}{}
521These functions are similar to the corresponding functions described
Fred Drake4471f201998-11-25 22:38:24 +0000522above for the \module{stdwin}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000523module, but affect or use the current drawing font instead of
524the global default font.
525When a drawing object is created, its font is set to the window's
526default font, which is in turn initialized from the global default
527font when the window is created.
Fred Drake4471f201998-11-25 22:38:24 +0000528\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000529
Fred Drake4471f201998-11-25 22:38:24 +0000530\begin{methoddesc}[drawing]{bitmap}{point, bitmap, mask}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000531Draw the \var{bitmap} with its top left corner at \var{point}.
532If the optional \var{mask} argument is present, it should be either
533the same object as \var{bitmap}, to draw only those bits that are set
534in the bitmap, in the foreground color, or \code{None}, to draw all
535bits (ones are drawn in the foreground color, zeros in the background
536color).
Guido van Rossum470be141995-03-17 16:07:09 +0000537Not available on the Macintosh.
Fred Drake4471f201998-11-25 22:38:24 +0000538\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000539
Fred Drake4471f201998-11-25 22:38:24 +0000540\begin{methoddesc}[drawing]{cliprect}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000541Set the ``clipping region'' to a rectangle.
542The clipping region limits the effect of all drawing operations, until
543it is changed again or until the drawing object is closed. When a
544drawing object is created the clipping region is set to the entire
545window. When an object to be drawn falls partly outside the clipping
546region, the set of pixels drawn is the intersection of the clipping
547region and the set of pixels that would be drawn by the same operation
548in the absence of a clipping region.
Fred Drake4471f201998-11-25 22:38:24 +0000549\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000550
Fred Drake4471f201998-11-25 22:38:24 +0000551\begin{methoddesc}[drawing]{noclip}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000552Reset the clipping region to the entire window.
Fred Drake4471f201998-11-25 22:38:24 +0000553\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000554
Fred Drake4471f201998-11-25 22:38:24 +0000555\begin{methoddesc}[drawing]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000556\funcline{enddrawing}{}
557Discard the drawing object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000558\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000559
Guido van Rossum470be141995-03-17 16:07:09 +0000560\subsection{Menu Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000561
562A menu object represents a menu.
563The menu is destroyed when the menu object is deleted.
564The following methods are defined:
565
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000566
Fred Drake4471f201998-11-25 22:38:24 +0000567\begin{methoddesc}[menu]{additem}{text, shortcut}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000568Add a menu item with given text.
569The shortcut must be a string of length 1, or omitted (to specify no
570shortcut).
Fred Drake4471f201998-11-25 22:38:24 +0000571\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000572
Fred Drake4471f201998-11-25 22:38:24 +0000573\begin{methoddesc}[menu]{setitem}{i, text}
574Set the text of item number \var{i}.
575\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000576
Fred Drake4471f201998-11-25 22:38:24 +0000577\begin{methoddesc}[menu]{enable}{i, flag}
578Enable or disables item \var{i}.
579\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000580
Fred Drake4471f201998-11-25 22:38:24 +0000581\begin{methoddesc}[menu]{check}{i, flag}
582Set or clear the \dfn{check mark} for item \var{i}.
583\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000584
Fred Drake4471f201998-11-25 22:38:24 +0000585\begin{methoddesc}[menu]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000586Discard the menu object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000587\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000588
Guido van Rossum470be141995-03-17 16:07:09 +0000589\subsection{Bitmap Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000590
591A bitmap represents a rectangular array of bits.
592The top left bit has coordinate (0, 0).
Fred Drake4471f201998-11-25 22:38:24 +0000593A bitmap can be drawn with the \method{bitmap()} method of a drawing object.
Guido van Rossum470be141995-03-17 16:07:09 +0000594Bitmaps are currently not available on the Macintosh.
595
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000596The following methods are defined:
597
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000598
Fred Drake4471f201998-11-25 22:38:24 +0000599\begin{methoddesc}[bitmap]{getsize}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000600Return a tuple representing the width and height of the bitmap.
Fred Drake4471f201998-11-25 22:38:24 +0000601(This returns the values that have been passed to the
602\function{newbitmap()} function.)
603\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000604
Fred Drake4471f201998-11-25 22:38:24 +0000605\begin{methoddesc}[bitmap]{setbit}{point, bit}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000606Set the value of the bit indicated by \var{point} to \var{bit}.
Fred Drake4471f201998-11-25 22:38:24 +0000607\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000608
Fred Drake4471f201998-11-25 22:38:24 +0000609\begin{methoddesc}[bitmap]{getbit}{point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000610Return the value of the bit indicated by \var{point}.
Fred Drake4471f201998-11-25 22:38:24 +0000611\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000612
Fred Drake4471f201998-11-25 22:38:24 +0000613\begin{methoddesc}[bitmap]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000614Discard the bitmap object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000615\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000616
Guido van Rossum470be141995-03-17 16:07:09 +0000617\subsection{Text-edit Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000618
619A text-edit object represents a text-edit block.
Fred Drake4471f201998-11-25 22:38:24 +0000620For semantics, see the STDWIN documentation for \C{} programmers.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000621The following methods exist:
622
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000623
Fred Drake4471f201998-11-25 22:38:24 +0000624\begin{methoddesc}[text-edit]{arrow}{code}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000625Pass an arrow event to the text-edit block.
Fred Drake4471f201998-11-25 22:38:24 +0000626The \var{code} must be one of \constant{WC_LEFT}, \constant{WC_RIGHT},
627\constant{WC_UP} or \constant{WC_DOWN} (see module
Fred Drakeffbe6871999-04-22 21:23:22 +0000628\refmodule{stdwinevents}).
Fred Drake4471f201998-11-25 22:38:24 +0000629\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000630
Fred Drake4471f201998-11-25 22:38:24 +0000631\begin{methoddesc}[text-edit]{draw}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000632Pass a draw event to the text-edit block.
633The rectangle specifies the redraw area.
Fred Drake4471f201998-11-25 22:38:24 +0000634\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000635
Fred Drake4471f201998-11-25 22:38:24 +0000636\begin{methoddesc}[text-edit]{event}{type, window, detail}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000637Pass an event gotten from
Fred Drake4471f201998-11-25 22:38:24 +0000638\function{stdwin.getevent()}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000639to the text-edit block.
640Return true if the event was handled.
Fred Drake4471f201998-11-25 22:38:24 +0000641\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000642
Fred Drake4471f201998-11-25 22:38:24 +0000643\begin{methoddesc}[text-edit]{getfocus}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000644Return 2 integers representing the start and end positions of the
645focus, usable as slice indices on the string returned by
Fred Drake4471f201998-11-25 22:38:24 +0000646\method{gettext()}.
647\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000648
Fred Drake4471f201998-11-25 22:38:24 +0000649\begin{methoddesc}[text-edit]{getfocustext}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000650Return the text in the focus.
Fred Drake4471f201998-11-25 22:38:24 +0000651\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000652
Fred Drake4471f201998-11-25 22:38:24 +0000653\begin{methoddesc}[text-edit]{getrect}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000654Return a rectangle giving the actual position of the text-edit block.
655(The bottom coordinate may differ from the initial position because
656the block automatically shrinks or grows to fit.)
Fred Drake4471f201998-11-25 22:38:24 +0000657\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000658
Fred Drake4471f201998-11-25 22:38:24 +0000659\begin{methoddesc}[text-edit]{gettext}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000660Return the entire text buffer.
Fred Drake4471f201998-11-25 22:38:24 +0000661\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000662
Fred Drake4471f201998-11-25 22:38:24 +0000663\begin{methoddesc}[text-edit]{move}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000664Specify a new position for the text-edit block in the document.
Fred Drake4471f201998-11-25 22:38:24 +0000665\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000666
Fred Drake4471f201998-11-25 22:38:24 +0000667\begin{methoddesc}[text-edit]{replace}{str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000668Replace the text in the focus by the given string.
669The new focus is an insert point at the end of the string.
Fred Drake4471f201998-11-25 22:38:24 +0000670\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000671
Fred Drake4471f201998-11-25 22:38:24 +0000672\begin{methoddesc}[text-edit]{setfocus}{i, j}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000673Specify the new focus.
674Out-of-bounds values are silently clipped.
Fred Drake4471f201998-11-25 22:38:24 +0000675\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000676
Fred Drake4471f201998-11-25 22:38:24 +0000677\begin{methoddesc}[text-edit]{settext}{str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000678Replace the entire text buffer by the given string and set the focus
679to \code{(0, 0)}.
Fred Drake4471f201998-11-25 22:38:24 +0000680\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000681
Fred Drake4471f201998-11-25 22:38:24 +0000682\begin{methoddesc}[text-edit]{setview}{rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000683Set the view rectangle to \var{rect}. If \var{rect} is \code{None},
684viewing mode is reset. In viewing mode, all output from the text-edit
685object is clipped to the viewing rectangle. This may be useful to
686implement your own scrolling text subwindow.
Fred Drake4471f201998-11-25 22:38:24 +0000687\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000688
Fred Drake4471f201998-11-25 22:38:24 +0000689\begin{methoddesc}[text-edit]{close}{}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000690Discard the text-edit object. It should not be used again.
Fred Drake4471f201998-11-25 22:38:24 +0000691\end{methoddesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000692
693\subsection{Example}
Guido van Rossum86cb0921995-03-20 12:59:56 +0000694\nodename{STDWIN Example}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000695
696Here is a minimal example of using STDWIN in Python.
697It creates a window and draws the string ``Hello world'' in the top
698left corner of the window.
699The window will be correctly redrawn when covered and re-exposed.
700The program quits when the close icon or menu item is requested.
701
Fred Drake19479911998-02-13 06:58:54 +0000702\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000703import stdwin
704from stdwinevents import *
705
706def main():
707 mywin = stdwin.open('Hello')
708 #
709 while 1:
710 (type, win, detail) = stdwin.getevent()
711 if type == WE_DRAW:
712 draw = win.begindrawing()
713 draw.text((0, 0), 'Hello, world')
714 del draw
715 elif type == WE_CLOSE:
716 break
717
718main()
Fred Drake19479911998-02-13 06:58:54 +0000719\end{verbatim}
Fred Drake4471f201998-11-25 22:38:24 +0000720
Fred Drakeffbe6871999-04-22 21:23:22 +0000721
Fred Drake295da241998-08-10 19:42:37 +0000722\section{\module{stdwinevents} ---
Fred Drake4471f201998-11-25 22:38:24 +0000723 Constants for use with \module{stdwin}}
Fred Drakeb91e9341998-07-23 17:59:49 +0000724
Fred Drakeffbe6871999-04-22 21:23:22 +0000725\declaremodule{standard}{stdwinevents}
Fred Drake4471f201998-11-25 22:38:24 +0000726\modulesynopsis{Constant definitions for use with \module{stdwin}}
Fred Drakeb91e9341998-07-23 17:59:49 +0000727
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000728
729This module defines constants used by STDWIN for event types
Fred Drake4471f201998-11-25 22:38:24 +0000730(\constant{WE_ACTIVATE} etc.), command codes (\constant{WC_LEFT} etc.)
731and selection types (\constant{WS_PRIMARY} etc.).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000732Read the file for details.
733Suggested usage is
734
Fred Drake19479911998-02-13 06:58:54 +0000735\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000736>>> from stdwinevents import *
737>>>
Fred Drake19479911998-02-13 06:58:54 +0000738\end{verbatim}
Fred Drake4471f201998-11-25 22:38:24 +0000739
Fred Drakeffbe6871999-04-22 21:23:22 +0000740
Fred Drake295da241998-08-10 19:42:37 +0000741\section{\module{rect} ---
Fred Drake4471f201998-11-25 22:38:24 +0000742 Functions for use with \module{stdwin}}
Fred Drakeb91e9341998-07-23 17:59:49 +0000743
Fred Drakeffbe6871999-04-22 21:23:22 +0000744\declaremodule{standard}{rect}
745\modulesynopsis{Geometry-related utility function for use with
746 \module{stdwin}.}
Fred Drakeb91e9341998-07-23 17:59:49 +0000747
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000748
749This module contains useful operations on rectangles.
Fred Drakeffbe6871999-04-22 21:23:22 +0000750A rectangle is defined as in module \refmodule{stdwin}:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000751a pair of points, where a point is a pair of integers.
752For example, the rectangle
753
Fred Drake19479911998-02-13 06:58:54 +0000754\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000755(10, 20), (90, 80)
Fred Drake19479911998-02-13 06:58:54 +0000756\end{verbatim}
Fred Drake4471f201998-11-25 22:38:24 +0000757
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000758is a rectangle whose left, top, right and bottom edges are 10, 20, 90
Fred Drake4471f201998-11-25 22:38:24 +0000759and 80, respectively. Note that the positive vertical axis points
Fred Drakeffbe6871999-04-22 21:23:22 +0000760down (as in \refmodule{stdwin}).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000761
762The module defines the following objects:
763
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000764\begin{excdesc}{error}
765The exception raised by functions in this module when they detect an
Fred Drake4471f201998-11-25 22:38:24 +0000766error. The exception argument is a string describing the problem in
767more detail.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000768\end{excdesc}
769
770\begin{datadesc}{empty}
771The rectangle returned when some operations return an empty result.
772This makes it possible to quickly check whether a result is empty:
773
Fred Drake19479911998-02-13 06:58:54 +0000774\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000775>>> import rect
776>>> r1 = (10, 20), (90, 80)
777>>> r2 = (0, 0), (10, 20)
778>>> r3 = rect.intersect([r1, r2])
779>>> if r3 is rect.empty: print 'Empty intersection'
780Empty intersection
781>>>
Fred Drake19479911998-02-13 06:58:54 +0000782\end{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000783\end{datadesc}
784
785\begin{funcdesc}{is_empty}{r}
786Returns true if the given rectangle is empty.
787A rectangle
788\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}
789is empty if
Fred Drake4471f201998-11-25 22:38:24 +0000790\begin{math}\var{left} \geq \var{right}\end{math} or
791\begin{math}\var{top} \geq \var{bottom}\end{math}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000792\end{funcdesc}
793
794\begin{funcdesc}{intersect}{list}
795Returns the intersection of all rectangles in the list argument.
Fred Drake4471f201998-11-25 22:38:24 +0000796It may also be called with a tuple argument. Raises
797\exception{rect.error} if the list is empty. Returns
798\constant{rect.empty} if the intersection of the rectangles is empty.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000799\end{funcdesc}
800
801\begin{funcdesc}{union}{list}
802Returns the smallest rectangle that contains all non-empty rectangles in
Fred Drake4471f201998-11-25 22:38:24 +0000803the list argument. It may also be called with a tuple argument or
804with two or more rectangles as arguments. Returns
805\constant{rect.empty} if the list is empty or all its rectangles are
806empty.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000807\end{funcdesc}
808
Fred Drakecce10901998-03-17 06:33:25 +0000809\begin{funcdesc}{pointinrect}{point, rect}
Fred Drake4471f201998-11-25 22:38:24 +0000810Returns true if the point is inside the rectangle. By definition, a
811point \code{(\var{h}, \var{v})} is inside a rectangle
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000812\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})} if
Fred Drake4471f201998-11-25 22:38:24 +0000813\begin{math}\var{left} \leq \var{h} < \var{right}\end{math} and
814\begin{math}\var{top} \leq \var{v} < \var{bottom}\end{math}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000815\end{funcdesc}
816
Fred Drake4471f201998-11-25 22:38:24 +0000817\begin{funcdesc}{inset}{rect, (dh, dv)}
818Returns a rectangle that lies inside the \var{rect} argument by
819\var{dh} pixels horizontally and \var{dv} pixels vertically. If
820\var{dh} or \var{dv} is negative, the result lies outside \var{rect}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000821\end{funcdesc}
822
823\begin{funcdesc}{rect2geom}{rect}
824Converts a rectangle to geometry representation:
825\code{(\var{left}, \var{top}), (\var{width}, \var{height})}.
826\end{funcdesc}
827
828\begin{funcdesc}{geom2rect}{geom}
829Converts a rectangle given in geometry representation back to the
830standard rectangle representation
831\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}.
832\end{funcdesc}