blob: 46ff39ff750263faf5f6e1933343a50e4363fcbb [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} ---
18 None}
Fred Drakeb91e9341998-07-23 17:59:49 +000019\declaremodule{builtin}{stdwin}
20
21\modulesynopsis{None}
22
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 Drakea8090641998-01-13 19:10:02 +000027On \UNIX{} running X11, it can only be used if the \code{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
41The following functions are defined in the \code{stdwin} module:
42
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
59module
60\code{stdwinevent}.
61\end{funcdesc}
62
63\begin{funcdesc}{pollevent}{}
64Return the next event, if one is immediately available.
65If no event is available, return \code{()}.
66\end{funcdesc}
67
68\begin{funcdesc}{getactive}{}
69Return the window that is currently active, or \code{None} if no
70window is currently active. (This can be emulated by monitoring
71WE_ACTIVATE and WE_DEACTIVATE events.)
72\end{funcdesc}
73
74\begin{funcdesc}{listfontnames}{pattern}
75Return the list of font names in the system that match the pattern (a
76string). The pattern should normally be \code{'*'}; returns all
77available fonts. If the underlying window system is X11, other
78patterns follow the standard X11 font selection syntax (as used e.g.
79in resource definitions), i.e. the wildcard character \code{'*'}
80matches any sequence of characters (including none) and \code{'?'}
81matches any single character.
Guido van Rossum470be141995-03-17 16:07:09 +000082On the Macintosh this function currently returns an empty list.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000083\end{funcdesc}
84
Fred Drakecce10901998-03-17 06:33:25 +000085\begin{funcdesc}{setdefscrollbars}{hflag, vflag}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000086Set the flags controlling whether subsequently opened windows will
87have horizontal and/or vertical scroll bars.
88\end{funcdesc}
89
Fred Drakecce10901998-03-17 06:33:25 +000090\begin{funcdesc}{setdefwinpos}{h, v}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000091Set the default window position for windows opened subsequently.
92\end{funcdesc}
93
Fred Drakecce10901998-03-17 06:33:25 +000094\begin{funcdesc}{setdefwinsize}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000095Set the default window size for windows opened subsequently.
96\end{funcdesc}
97
98\begin{funcdesc}{getdefscrollbars}{}
99Return the flags controlling whether subsequently opened windows will
100have horizontal and/or vertical scroll bars.
101\end{funcdesc}
102
103\begin{funcdesc}{getdefwinpos}{}
104Return the default window position for windows opened subsequently.
105\end{funcdesc}
106
107\begin{funcdesc}{getdefwinsize}{}
108Return the default window size for windows opened subsequently.
109\end{funcdesc}
110
111\begin{funcdesc}{getscrsize}{}
112Return the screen size in pixels.
113\end{funcdesc}
114
115\begin{funcdesc}{getscrmm}{}
116Return the screen size in millimeters.
117\end{funcdesc}
118
119\begin{funcdesc}{fetchcolor}{colorname}
120Return the pixel value corresponding to the given color name.
121Return the default foreground color for unknown color names.
Guido van Rossum16d6e711994-08-08 12:30:22 +0000122Hint: the following code tests whether you are on a machine that
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000123supports more than two colors:
Fred Drake19479911998-02-13 06:58:54 +0000124\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000125if stdwin.fetchcolor('black') <> \
126 stdwin.fetchcolor('red') <> \
127 stdwin.fetchcolor('white'):
128 print 'color machine'
129else:
130 print 'monochrome machine'
Fred Drake19479911998-02-13 06:58:54 +0000131\end{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000132\end{funcdesc}
133
134\begin{funcdesc}{setfgcolor}{pixel}
135Set the default foreground color.
136This will become the default foreground color of windows opened
137subsequently, including dialogs.
138\end{funcdesc}
139
140\begin{funcdesc}{setbgcolor}{pixel}
141Set the default background color.
142This will become the default background color of windows opened
143subsequently, including dialogs.
144\end{funcdesc}
145
146\begin{funcdesc}{getfgcolor}{}
147Return the pixel value of the current default foreground color.
148\end{funcdesc}
149
150\begin{funcdesc}{getbgcolor}{}
151Return the pixel value of the current default background color.
152\end{funcdesc}
153
154\begin{funcdesc}{setfont}{fontname}
155Set the current default font.
156This will become the default font for windows opened subsequently,
157and is also used by the text measuring functions \code{textwidth},
158\code{textbreak}, \code{lineheight} and \code{baseline} below.
159This accepts two more optional parameters, size and style:
160Size is the font size (in `points').
161Style is a single character specifying the style, as follows:
162\code{'b'} = bold,
163\code{'i'} = italic,
164\code{'o'} = bold + italic,
165\code{'u'} = underline;
166default style is roman.
167Size and style are ignored under X11 but used on the Macintosh.
168(Sorry for all this complexity --- a more uniform interface is being designed.)
169\end{funcdesc}
170
171\begin{funcdesc}{menucreate}{title}
172Create a menu object referring to a global menu (a menu that appears in
173all windows).
174Methods of menu objects are described below.
175Note: normally, menus are created locally; see the window method
176\code{menucreate} below.
177\strong{Warning:} the menu only appears in a window as long as the object
178returned by this call exists.
179\end{funcdesc}
180
Fred Drakecce10901998-03-17 06:33:25 +0000181\begin{funcdesc}{newbitmap}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000182Create a new bitmap object of the given dimensions.
183Methods of bitmap objects are described below.
Guido van Rossum470be141995-03-17 16:07:09 +0000184Not available on the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000185\end{funcdesc}
186
187\begin{funcdesc}{fleep}{}
188Cause a beep or bell (or perhaps a `visual bell' or flash, hence the
189name).
190\end{funcdesc}
191
192\begin{funcdesc}{message}{string}
193Display a dialog box containing the string.
194The user must click OK before the function returns.
195\end{funcdesc}
196
Fred Drakecce10901998-03-17 06:33:25 +0000197\begin{funcdesc}{askync}{prompt, default}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000198Display a dialog that prompts the user to answer a question with yes or
199no.
200Return 0 for no, 1 for yes.
201If the user hits the Return key, the default (which must be 0 or 1) is
202returned.
203If the user cancels the dialog, the
204\code{KeyboardInterrupt}
205exception is raised.
206\end{funcdesc}
207
Fred Drakecce10901998-03-17 06:33:25 +0000208\begin{funcdesc}{askstr}{prompt, default}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000209Display a dialog that prompts the user for a string.
210If the user hits the Return key, the default string is returned.
211If the user cancels the dialog, the
212\code{KeyboardInterrupt}
213exception is raised.
214\end{funcdesc}
215
Fred Drakecce10901998-03-17 06:33:25 +0000216\begin{funcdesc}{askfile}{prompt, default, new}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000217Ask the user to specify a filename.
218If
219\var{new}
220is zero it must be an existing file; otherwise, it must be a new file.
221If the user cancels the dialog, the
222\code{KeyboardInterrupt}
223exception is raised.
224\end{funcdesc}
225
Fred Drakecce10901998-03-17 06:33:25 +0000226\begin{funcdesc}{setcutbuffer}{i, string}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000227Store the string in the system's cut buffer number
228\var{i},
229where it can be found (for pasting) by other applications.
230On X11, there are 8 cut buffers (numbered 0..7).
231Cut buffer number 0 is the `clipboard' on the Macintosh.
232\end{funcdesc}
233
234\begin{funcdesc}{getcutbuffer}{i}
235Return the contents of the system's cut buffer number
236\var{i}.
237\end{funcdesc}
238
239\begin{funcdesc}{rotatecutbuffers}{n}
240On X11, rotate the 8 cut buffers by
241\var{n}.
242Ignored on the Macintosh.
243\end{funcdesc}
244
245\begin{funcdesc}{getselection}{i}
246Return X11 selection number
247\var{i.}
248Selections are not cut buffers.
249Selection numbers are defined in module
250\code{stdwinevents}.
251Selection \code{WS_PRIMARY} is the
252\dfn{primary}
253selection (used by
254xterm,
255for instance);
256selection \code{WS_SECONDARY} is the
257\dfn{secondary}
258selection; selection \code{WS_CLIPBOARD} is the
259\dfn{clipboard}
260selection (used by
261xclipboard).
262On the Macintosh, this always returns an empty string.
263\end{funcdesc}
264
265\begin{funcdesc}{resetselection}{i}
266Reset selection number
267\var{i},
268if this process owns it.
269(See window method
270\code{setselection()}).
271\end{funcdesc}
272
273\begin{funcdesc}{baseline}{}
274Return the baseline of the current font (defined by STDWIN as the
275vertical distance between the baseline and the top of the
276characters).
277\end{funcdesc}
278
279\begin{funcdesc}{lineheight}{}
280Return the total line height of the current font.
281\end{funcdesc}
282
Fred Drakecce10901998-03-17 06:33:25 +0000283\begin{funcdesc}{textbreak}{str, width}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000284Return the number of characters of the string that fit into a space of
285\var{width}
286bits wide when drawn in the curent font.
287\end{funcdesc}
288
289\begin{funcdesc}{textwidth}{str}
290Return the width in bits of the string when drawn in the current font.
291\end{funcdesc}
292
293\begin{funcdesc}{connectionnumber}{}
294\funcline{fileno}{}
295(X11 under \UNIX{} only) Return the ``connection number'' used by the
296underlying X11 implementation. (This is normally the file number of
297the socket.) Both functions return the same value;
298\code{connectionnumber()} is named after the corresponding function in
299X11 and STDWIN, while \code{fileno()} makes it possible to use the
300\code{stdwin} module as a ``file'' object parameter to
301\code{select.select()}. Note that if \code{select()} implies that
302input is possible on \code{stdwin}, this does not guarantee that an
303event is ready --- it may be some internal communication going on
304between the X server and the client library. Thus, you should call
305\code{stdwin.pollevent()} until it returns \code{None} to check for
306events if you don't want your program to block. Because of internal
307buffering in X11, it is also possible that \code{stdwin.pollevent()}
308returns an event while \code{select()} does not find \code{stdwin} to
309be ready, so you should read any pending events with
310\code{stdwin.pollevent()} until it returns \code{None} before entering
311a blocking \code{select()} call.
312\ttindex{select}
313\end{funcdesc}
314
Guido van Rossum470be141995-03-17 16:07:09 +0000315\subsection{Window Objects}
Fred Drake4b3f0311996-12-13 22:04:31 +0000316\nodename{STDWIN Window Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000317
318Window objects are created by \code{stdwin.open()}. They are closed
319by their \code{close()} method or when they are garbage-collected.
320Window objects have the following methods:
321
Fred Drake19479911998-02-13 06:58:54 +0000322\setindexsubitem{(window method)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000323
324\begin{funcdesc}{begindrawing}{}
325Return a drawing object, whose methods (described below) allow drawing
326in the window.
327\end{funcdesc}
328
329\begin{funcdesc}{change}{rect}
330Invalidate the given rectangle; this may cause a draw event.
331\end{funcdesc}
332
333\begin{funcdesc}{gettitle}{}
334Returns the window's title string.
335\end{funcdesc}
336
337\begin{funcdesc}{getdocsize}{}
338\begin{sloppypar}
339Return a pair of integers giving the size of the document as set by
340\code{setdocsize()}.
341\end{sloppypar}
342\end{funcdesc}
343
344\begin{funcdesc}{getorigin}{}
345Return a pair of integers giving the origin of the window with respect
346to the document.
347\end{funcdesc}
348
349\begin{funcdesc}{gettitle}{}
350Return the window's title string.
351\end{funcdesc}
352
353\begin{funcdesc}{getwinsize}{}
354Return a pair of integers giving the size of the window.
355\end{funcdesc}
356
357\begin{funcdesc}{getwinpos}{}
358Return a pair of integers giving the position of the window's upper
359left corner (relative to the upper left corner of the screen).
360\end{funcdesc}
361
362\begin{funcdesc}{menucreate}{title}
363Create a menu object referring to a local menu (a menu that appears
364only in this window).
365Methods of menu objects are described below.
Fred Drakeaf8a0151998-01-14 14:51:31 +0000366\strong{Warning:} the menu only appears as long as the object
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000367returned by this call exists.
368\end{funcdesc}
369
Fred Drakecce10901998-03-17 06:33:25 +0000370\begin{funcdesc}{scroll}{rect, point}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000371Scroll the given rectangle by the vector given by the point.
372\end{funcdesc}
373
374\begin{funcdesc}{setdocsize}{point}
375Set the size of the drawing document.
376\end{funcdesc}
377
378\begin{funcdesc}{setorigin}{point}
379Move the origin of the window (its upper left corner)
380to the given point in the document.
381\end{funcdesc}
382
Fred Drakecce10901998-03-17 06:33:25 +0000383\begin{funcdesc}{setselection}{i, str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000384Attempt to set X11 selection number
385\var{i}
386to the string
387\var{str}.
388(See stdwin method
389\code{getselection()}
390for the meaning of
391\var{i}.)
392Return true if it succeeds.
393If succeeds, the window ``owns'' the selection until
Guido van Rossum16d6e711994-08-08 12:30:22 +0000394(a) another application takes ownership of the selection; or
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000395(b) the window is deleted; or
396(c) the application clears ownership by calling
397\code{stdwin.resetselection(\var{i})}.
398When another application takes ownership of the selection, a
399\code{WE_LOST_SEL}
400event is received for no particular window and with the selection number
401as detail.
402Ignored on the Macintosh.
403\end{funcdesc}
404
405\begin{funcdesc}{settimer}{dsecs}
406Schedule a timer event for the window in
407\code{\var{dsecs}/10}
408seconds.
409\end{funcdesc}
410
411\begin{funcdesc}{settitle}{title}
412Set the window's title string.
413\end{funcdesc}
414
415\begin{funcdesc}{setwincursor}{name}
416\begin{sloppypar}
417Set the window cursor to a cursor of the given name.
418It raises the
419\code{RuntimeError}
420exception if no cursor of the given name exists.
421Suitable names include
422\code{'ibeam'},
423\code{'arrow'},
424\code{'cross'},
425\code{'watch'}
426and
427\code{'plus'}.
Fred Drakea5aefba1998-08-14 17:05:17 +0000428On X11, there are many more (see \code{<X11/cursorfont.h>}).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000429\end{sloppypar}
430\end{funcdesc}
431
Fred Drakecce10901998-03-17 06:33:25 +0000432\begin{funcdesc}{setwinpos}{h, v}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000433Set the the position of the window's upper left corner (relative to
434the upper left corner of the screen).
435\end{funcdesc}
436
Fred Drakecce10901998-03-17 06:33:25 +0000437\begin{funcdesc}{setwinsize}{width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000438Set the window's size.
439\end{funcdesc}
440
441\begin{funcdesc}{show}{rect}
442Try to ensure that the given rectangle of the document is visible in
443the window.
444\end{funcdesc}
445
446\begin{funcdesc}{textcreate}{rect}
447Create a text-edit object in the document at the given rectangle.
448Methods of text-edit objects are described below.
449\end{funcdesc}
450
451\begin{funcdesc}{setactive}{}
452Attempt to make this window the active window. If successful, this
453will generate a WE_ACTIVATE event (and a WE_DEACTIVATE event in case
454another window in this application became inactive).
455\end{funcdesc}
456
457\begin{funcdesc}{close}{}
458Discard the window object. It should not be used again.
459\end{funcdesc}
460
Guido van Rossum470be141995-03-17 16:07:09 +0000461\subsection{Drawing Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000462
463Drawing objects are created exclusively by the window method
464\code{begindrawing()}.
465Only one drawing object can exist at any given time; the drawing object
466must be deleted to finish drawing.
467No drawing object may exist when
468\code{stdwin.getevent()}
469is called.
470Drawing objects have the following methods:
471
Fred Drake19479911998-02-13 06:58:54 +0000472\setindexsubitem{(drawing method)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000473
474\begin{funcdesc}{box}{rect}
475Draw a box just inside a rectangle.
476\end{funcdesc}
477
Fred Drakecce10901998-03-17 06:33:25 +0000478\begin{funcdesc}{circle}{center, radius}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000479Draw a circle with given center point and radius.
480\end{funcdesc}
481
Fred Drakecce10901998-03-17 06:33:25 +0000482\begin{funcdesc}{elarc}{center, \(rh, rv\), \(a1, a2\)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000483Draw an elliptical arc with given center point.
484\code{(\var{rh}, \var{rv})}
485gives the half sizes of the horizontal and vertical radii.
486\code{(\var{a1}, \var{a2})}
487gives the angles (in degrees) of the begin and end points.
4880 degrees is at 3 o'clock, 90 degrees is at 12 o'clock.
489\end{funcdesc}
490
491\begin{funcdesc}{erase}{rect}
492Erase a rectangle.
493\end{funcdesc}
494
Fred Drakecce10901998-03-17 06:33:25 +0000495\begin{funcdesc}{fillcircle}{center, radius}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000496Draw a filled circle with given center point and radius.
497\end{funcdesc}
498
Fred Drakecce10901998-03-17 06:33:25 +0000499\begin{funcdesc}{fillelarc}{center, \(rh, rv\), \(a1, a2\)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000500Draw a filled elliptical arc; arguments as for \code{elarc}.
501\end{funcdesc}
502
503\begin{funcdesc}{fillpoly}{points}
504Draw a filled polygon given by a list (or tuple) of points.
505\end{funcdesc}
506
507\begin{funcdesc}{invert}{rect}
508Invert a rectangle.
509\end{funcdesc}
510
Fred Drakecce10901998-03-17 06:33:25 +0000511\begin{funcdesc}{line}{p1, p2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000512Draw a line from point
513\var{p1}
514to
515\var{p2}.
516\end{funcdesc}
517
518\begin{funcdesc}{paint}{rect}
519Fill a rectangle.
520\end{funcdesc}
521
522\begin{funcdesc}{poly}{points}
523Draw the lines connecting the given list (or tuple) of points.
524\end{funcdesc}
525
Fred Drakecce10901998-03-17 06:33:25 +0000526\begin{funcdesc}{shade}{rect, percent}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000527Fill a rectangle with a shading pattern that is about
528\var{percent}
529percent filled.
530\end{funcdesc}
531
Fred Drakecce10901998-03-17 06:33:25 +0000532\begin{funcdesc}{text}{p, str}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000533Draw a string starting at point p (the point specifies the
534top left coordinate of the string).
535\end{funcdesc}
536
Fred Drakecce10901998-03-17 06:33:25 +0000537\begin{funcdesc}{xorcircle}{center, radius}
538\funcline{xorelarc}{center, \(rh, rv\), \(a1, a2\)}
539\funcline{xorline}{p1, p2}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000540\funcline{xorpoly}{points}
541Draw a circle, an elliptical arc, a line or a polygon, respectively,
542in XOR mode.
543\end{funcdesc}
544
545\begin{funcdesc}{setfgcolor}{}
546\funcline{setbgcolor}{}
547\funcline{getfgcolor}{}
548\funcline{getbgcolor}{}
549These functions are similar to the corresponding functions described
550above for the
551\code{stdwin}
552module, but affect or return the colors currently used for drawing
553instead of the global default colors.
554When a drawing object is created, its colors are set to the window's
555default colors, which are in turn initialized from the global default
556colors when the window is created.
557\end{funcdesc}
558
559\begin{funcdesc}{setfont}{}
560\funcline{baseline}{}
561\funcline{lineheight}{}
562\funcline{textbreak}{}
563\funcline{textwidth}{}
564These functions are similar to the corresponding functions described
565above for the
566\code{stdwin}
567module, but affect or use the current drawing font instead of
568the global default font.
569When a drawing object is created, its font is set to the window's
570default font, which is in turn initialized from the global default
571font when the window is created.
572\end{funcdesc}
573
Fred Drakecce10901998-03-17 06:33:25 +0000574\begin{funcdesc}{bitmap}{point, bitmap, mask}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000575Draw the \var{bitmap} with its top left corner at \var{point}.
576If the optional \var{mask} argument is present, it should be either
577the same object as \var{bitmap}, to draw only those bits that are set
578in the bitmap, in the foreground color, or \code{None}, to draw all
579bits (ones are drawn in the foreground color, zeros in the background
580color).
Guido van Rossum470be141995-03-17 16:07:09 +0000581Not available on the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000582\end{funcdesc}
583
584\begin{funcdesc}{cliprect}{rect}
585Set the ``clipping region'' to a rectangle.
586The clipping region limits the effect of all drawing operations, until
587it is changed again or until the drawing object is closed. When a
588drawing object is created the clipping region is set to the entire
589window. When an object to be drawn falls partly outside the clipping
590region, the set of pixels drawn is the intersection of the clipping
591region and the set of pixels that would be drawn by the same operation
592in the absence of a clipping region.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000593\end{funcdesc}
594
595\begin{funcdesc}{noclip}{}
596Reset the clipping region to the entire window.
597\end{funcdesc}
598
599\begin{funcdesc}{close}{}
600\funcline{enddrawing}{}
601Discard the drawing object. It should not be used again.
602\end{funcdesc}
603
Guido van Rossum470be141995-03-17 16:07:09 +0000604\subsection{Menu Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000605
606A menu object represents a menu.
607The menu is destroyed when the menu object is deleted.
608The following methods are defined:
609
Fred Drake19479911998-02-13 06:58:54 +0000610\setindexsubitem{(menu method)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000611
Fred Drakecce10901998-03-17 06:33:25 +0000612\begin{funcdesc}{additem}{text, shortcut}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000613Add a menu item with given text.
614The shortcut must be a string of length 1, or omitted (to specify no
615shortcut).
616\end{funcdesc}
617
Fred Drakecce10901998-03-17 06:33:25 +0000618\begin{funcdesc}{setitem}{i, text}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000619Set the text of item number
620\var{i}.
621\end{funcdesc}
622
Fred Drakecce10901998-03-17 06:33:25 +0000623\begin{funcdesc}{enable}{i, flag}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000624Enable or disables item
625\var{i}.
626\end{funcdesc}
627
Fred Drakecce10901998-03-17 06:33:25 +0000628\begin{funcdesc}{check}{i, flag}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000629Set or clear the
630\dfn{check mark}
631for item
632\var{i}.
633\end{funcdesc}
634
635\begin{funcdesc}{close}{}
636Discard the menu object. It should not be used again.
637\end{funcdesc}
638
Guido van Rossum470be141995-03-17 16:07:09 +0000639\subsection{Bitmap Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000640
641A bitmap represents a rectangular array of bits.
642The top left bit has coordinate (0, 0).
643A bitmap can be drawn with the \code{bitmap} method of a drawing object.
Guido van Rossum470be141995-03-17 16:07:09 +0000644Bitmaps are currently not available on the Macintosh.
645
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000646The following methods are defined:
647
Fred Drake19479911998-02-13 06:58:54 +0000648\setindexsubitem{(bitmap method)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000649
650\begin{funcdesc}{getsize}{}
651Return a tuple representing the width and height of the bitmap.
652(This returns the values that have been passed to the \code{newbitmap}
653function.)
654\end{funcdesc}
655
Fred Drakecce10901998-03-17 06:33:25 +0000656\begin{funcdesc}{setbit}{point, bit}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000657Set the value of the bit indicated by \var{point} to \var{bit}.
658\end{funcdesc}
659
660\begin{funcdesc}{getbit}{point}
661Return the value of the bit indicated by \var{point}.
662\end{funcdesc}
663
664\begin{funcdesc}{close}{}
665Discard the bitmap object. It should not be used again.
666\end{funcdesc}
667
Guido van Rossum470be141995-03-17 16:07:09 +0000668\subsection{Text-edit Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000669
670A text-edit object represents a text-edit block.
671For semantics, see the STDWIN documentation for C programmers.
672The following methods exist:
673
Fred Drake19479911998-02-13 06:58:54 +0000674\setindexsubitem{(text-edit method)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000675
676\begin{funcdesc}{arrow}{code}
677Pass an arrow event to the text-edit block.
678The
679\var{code}
680must be one of
681\code{WC_LEFT},
682\code{WC_RIGHT},
683\code{WC_UP}
684or
685\code{WC_DOWN}
686(see module
687\code{stdwinevents}).
688\end{funcdesc}
689
690\begin{funcdesc}{draw}{rect}
691Pass a draw event to the text-edit block.
692The rectangle specifies the redraw area.
693\end{funcdesc}
694
Fred Drakecce10901998-03-17 06:33:25 +0000695\begin{funcdesc}{event}{type, window, detail}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000696Pass an event gotten from
697\code{stdwin.getevent()}
698to the text-edit block.
699Return true if the event was handled.
700\end{funcdesc}
701
702\begin{funcdesc}{getfocus}{}
703Return 2 integers representing the start and end positions of the
704focus, usable as slice indices on the string returned by
705\code{gettext()}.
706\end{funcdesc}
707
708\begin{funcdesc}{getfocustext}{}
709Return the text in the focus.
710\end{funcdesc}
711
712\begin{funcdesc}{getrect}{}
713Return a rectangle giving the actual position of the text-edit block.
714(The bottom coordinate may differ from the initial position because
715the block automatically shrinks or grows to fit.)
716\end{funcdesc}
717
718\begin{funcdesc}{gettext}{}
719Return the entire text buffer.
720\end{funcdesc}
721
722\begin{funcdesc}{move}{rect}
723Specify a new position for the text-edit block in the document.
724\end{funcdesc}
725
726\begin{funcdesc}{replace}{str}
727Replace the text in the focus by the given string.
728The new focus is an insert point at the end of the string.
729\end{funcdesc}
730
Fred Drakecce10901998-03-17 06:33:25 +0000731\begin{funcdesc}{setfocus}{i, j}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000732Specify the new focus.
733Out-of-bounds values are silently clipped.
734\end{funcdesc}
735
736\begin{funcdesc}{settext}{str}
737Replace the entire text buffer by the given string and set the focus
738to \code{(0, 0)}.
739\end{funcdesc}
740
741\begin{funcdesc}{setview}{rect}
742Set the view rectangle to \var{rect}. If \var{rect} is \code{None},
743viewing mode is reset. In viewing mode, all output from the text-edit
744object is clipped to the viewing rectangle. This may be useful to
745implement your own scrolling text subwindow.
746\end{funcdesc}
747
748\begin{funcdesc}{close}{}
749Discard the text-edit object. It should not be used again.
750\end{funcdesc}
751
752\subsection{Example}
Guido van Rossum86cb0921995-03-20 12:59:56 +0000753\nodename{STDWIN Example}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000754
755Here is a minimal example of using STDWIN in Python.
756It creates a window and draws the string ``Hello world'' in the top
757left corner of the window.
758The window will be correctly redrawn when covered and re-exposed.
759The program quits when the close icon or menu item is requested.
760
Fred Drake19479911998-02-13 06:58:54 +0000761\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000762import stdwin
763from stdwinevents import *
764
765def main():
766 mywin = stdwin.open('Hello')
767 #
768 while 1:
769 (type, win, detail) = stdwin.getevent()
770 if type == WE_DRAW:
771 draw = win.begindrawing()
772 draw.text((0, 0), 'Hello, world')
773 del draw
774 elif type == WE_CLOSE:
775 break
776
777main()
Fred Drake19479911998-02-13 06:58:54 +0000778\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +0000779%
Fred Drake295da241998-08-10 19:42:37 +0000780\section{\module{stdwinevents} ---
781 None}
Fred Drakeb91e9341998-07-23 17:59:49 +0000782\declaremodule{standard}{stdwinevents}
783
784\modulesynopsis{None}
785
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000786
787This module defines constants used by STDWIN for event types
788(\code{WE_ACTIVATE} etc.), command codes (\code{WC_LEFT} etc.)
789and selection types (\code{WS_PRIMARY} etc.).
790Read the file for details.
791Suggested usage is
792
Fred Drake19479911998-02-13 06:58:54 +0000793\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000794>>> from stdwinevents import *
795>>>
Fred Drake19479911998-02-13 06:58:54 +0000796\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +0000797%
Fred Drake295da241998-08-10 19:42:37 +0000798\section{\module{rect} ---
799 None}
Fred Drakeb91e9341998-07-23 17:59:49 +0000800\declaremodule{standard}{rect}
801
802\modulesynopsis{None}
803
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000804
805This module contains useful operations on rectangles.
806A rectangle is defined as in module
807\code{stdwin}:
808a pair of points, where a point is a pair of integers.
809For example, the rectangle
810
Fred Drake19479911998-02-13 06:58:54 +0000811\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000812(10, 20), (90, 80)
Fred Drake19479911998-02-13 06:58:54 +0000813\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +0000814%
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000815is a rectangle whose left, top, right and bottom edges are 10, 20, 90
816and 80, respectively.
817Note that the positive vertical axis points down (as in
818\code{stdwin}).
819
820The module defines the following objects:
821
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000822\begin{excdesc}{error}
823The exception raised by functions in this module when they detect an
824error.
825The exception argument is a string describing the problem in more
826detail.
827\end{excdesc}
828
829\begin{datadesc}{empty}
830The rectangle returned when some operations return an empty result.
831This makes it possible to quickly check whether a result is empty:
832
Fred Drake19479911998-02-13 06:58:54 +0000833\begin{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000834>>> import rect
835>>> r1 = (10, 20), (90, 80)
836>>> r2 = (0, 0), (10, 20)
837>>> r3 = rect.intersect([r1, r2])
838>>> if r3 is rect.empty: print 'Empty intersection'
839Empty intersection
840>>>
Fred Drake19479911998-02-13 06:58:54 +0000841\end{verbatim}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000842\end{datadesc}
843
844\begin{funcdesc}{is_empty}{r}
845Returns true if the given rectangle is empty.
846A rectangle
847\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}
848is empty if
Fred Drake91eeefd1998-04-29 17:56:44 +0000849%begin{latexonly}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000850\iftexi
Fred Drake91eeefd1998-04-29 17:56:44 +0000851%end{latexonly}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000852\code{\var{left} >= \var{right}} or \code{\var{top} => \var{bottom}}.
Fred Drake91eeefd1998-04-29 17:56:44 +0000853%begin{latexonly}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000854\else
855$\var{left} \geq \var{right}$ or $\var{top} \geq \var{bottom}$.
Fred Drakeaf8a0151998-01-14 14:51:31 +0000856%%JHXXX\emph{left~$\geq$~right} or \emph{top~$\leq$~bottom}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000857\fi
Fred Drake91eeefd1998-04-29 17:56:44 +0000858%end{latexonly}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000859\end{funcdesc}
860
861\begin{funcdesc}{intersect}{list}
862Returns the intersection of all rectangles in the list argument.
863It may also be called with a tuple argument.
864Raises
865\code{rect.error}
866if the list is empty.
867Returns
868\code{rect.empty}
869if the intersection of the rectangles is empty.
870\end{funcdesc}
871
872\begin{funcdesc}{union}{list}
873Returns the smallest rectangle that contains all non-empty rectangles in
874the list argument.
875It may also be called with a tuple argument or with two or more
876rectangles as arguments.
877Returns
878\code{rect.empty}
879if the list is empty or all its rectangles are empty.
880\end{funcdesc}
881
Fred Drakecce10901998-03-17 06:33:25 +0000882\begin{funcdesc}{pointinrect}{point, rect}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000883Returns true if the point is inside the rectangle.
884By definition, a point
885\code{(\var{h}, \var{v})}
886is inside a rectangle
887\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})} if
Fred Drake91eeefd1998-04-29 17:56:44 +0000888%begin{latexonly}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000889\iftexi
Fred Drake91eeefd1998-04-29 17:56:44 +0000890%end{latexonly}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000891\code{\var{left} <= \var{h} < \var{right}} and
892\code{\var{top} <= \var{v} < \var{bottom}}.
Fred Drake91eeefd1998-04-29 17:56:44 +0000893%begin{latexonly}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000894\else
895$\var{left} \leq \var{h} < \var{right}$ and
896$\var{top} \leq \var{v} < \var{bottom}$.
897\fi
Fred Drake91eeefd1998-04-29 17:56:44 +0000898%end{latexonly}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000899\end{funcdesc}
900
Fred Drakecce10901998-03-17 06:33:25 +0000901\begin{funcdesc}{inset}{rect, \(dh, dv\)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000902Returns a rectangle that lies inside the
903\code{rect}
904argument by
905\var{dh}
906pixels horizontally
907and
908\var{dv}
909pixels
910vertically.
911If
912\var{dh}
913or
914\var{dv}
915is negative, the result lies outside
916\var{rect}.
917\end{funcdesc}
918
919\begin{funcdesc}{rect2geom}{rect}
920Converts a rectangle to geometry representation:
921\code{(\var{left}, \var{top}), (\var{width}, \var{height})}.
922\end{funcdesc}
923
924\begin{funcdesc}{geom2rect}{geom}
925Converts a rectangle given in geometry representation back to the
926standard rectangle representation
927\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}.
928\end{funcdesc}