blob: 514252f44260b262f099118bd7bd68667e325d82 [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
17\section{Built-in Module \sectcode{stdwin}}
18\bimodindex{stdwin}
19
20This module defines several new object types and functions that
Guido van Rossumecde7811995-03-28 13:35:14 +000021provide access to the functionality of STDWIN.
Guido van Rossum470be141995-03-17 16:07:09 +000022
23On Unix running X11, it can only be used if the \code{DISPLAY}
24environment variable is set or an explicit \samp{-display
25\var{displayname}} argument is passed to the Python interpreter.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000026
27Functions have names that usually resemble their C STDWIN counterparts
28with the initial `w' dropped.
29Points are represented by pairs of integers; rectangles
30by pairs of points.
31For a complete description of STDWIN please refer to the documentation
32of STDWIN for C programmers (aforementioned CWI report).
33
34\subsection{Functions Defined in Module \sectcode{stdwin}}
Guido van Rossum86cb0921995-03-20 12:59:56 +000035\nodename{STDWIN Functions}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000036
37The following functions are defined in the \code{stdwin} module:
38
39\renewcommand{\indexsubitem}{(in module stdwin)}
40\begin{funcdesc}{open}{title}
41Open a new window whose initial title is given by the string argument.
42Return a window object; window object methods are described below.%
43\footnote{The Python version of STDWIN does not support draw procedures; all
44 drawing requests are reported as draw events.}
45\end{funcdesc}
46
47\begin{funcdesc}{getevent}{}
48Wait for and return the next event.
49An event is returned as a triple: the first element is the event
50type, a small integer; the second element is the window object to which
51the event applies, or
52\code{None}
53if it applies to no window in particular;
54the third element is type-dependent.
55Names for event types and command codes are defined in the standard
56module
57\code{stdwinevent}.
58\end{funcdesc}
59
60\begin{funcdesc}{pollevent}{}
61Return the next event, if one is immediately available.
62If no event is available, return \code{()}.
63\end{funcdesc}
64
65\begin{funcdesc}{getactive}{}
66Return the window that is currently active, or \code{None} if no
67window is currently active. (This can be emulated by monitoring
68WE_ACTIVATE and WE_DEACTIVATE events.)
69\end{funcdesc}
70
71\begin{funcdesc}{listfontnames}{pattern}
72Return the list of font names in the system that match the pattern (a
73string). The pattern should normally be \code{'*'}; returns all
74available fonts. If the underlying window system is X11, other
75patterns follow the standard X11 font selection syntax (as used e.g.
76in resource definitions), i.e. the wildcard character \code{'*'}
77matches any sequence of characters (including none) and \code{'?'}
78matches any single character.
Guido van Rossum470be141995-03-17 16:07:09 +000079On the Macintosh this function currently returns an empty list.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000080\end{funcdesc}
81
82\begin{funcdesc}{setdefscrollbars}{hflag\, vflag}
83Set the flags controlling whether subsequently opened windows will
84have horizontal and/or vertical scroll bars.
85\end{funcdesc}
86
87\begin{funcdesc}{setdefwinpos}{h\, v}
88Set the default window position for windows opened subsequently.
89\end{funcdesc}
90
91\begin{funcdesc}{setdefwinsize}{width\, height}
92Set the default window size for windows opened subsequently.
93\end{funcdesc}
94
95\begin{funcdesc}{getdefscrollbars}{}
96Return the flags controlling whether subsequently opened windows will
97have horizontal and/or vertical scroll bars.
98\end{funcdesc}
99
100\begin{funcdesc}{getdefwinpos}{}
101Return the default window position for windows opened subsequently.
102\end{funcdesc}
103
104\begin{funcdesc}{getdefwinsize}{}
105Return the default window size for windows opened subsequently.
106\end{funcdesc}
107
108\begin{funcdesc}{getscrsize}{}
109Return the screen size in pixels.
110\end{funcdesc}
111
112\begin{funcdesc}{getscrmm}{}
113Return the screen size in millimeters.
114\end{funcdesc}
115
116\begin{funcdesc}{fetchcolor}{colorname}
117Return the pixel value corresponding to the given color name.
118Return the default foreground color for unknown color names.
Guido van Rossum16d6e711994-08-08 12:30:22 +0000119Hint: the following code tests whether you are on a machine that
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000120supports more than two colors:
121\bcode\begin{verbatim}
122if stdwin.fetchcolor('black') <> \
123 stdwin.fetchcolor('red') <> \
124 stdwin.fetchcolor('white'):
125 print 'color machine'
126else:
127 print 'monochrome machine'
128\end{verbatim}\ecode
129\end{funcdesc}
130
131\begin{funcdesc}{setfgcolor}{pixel}
132Set the default foreground color.
133This will become the default foreground color of windows opened
134subsequently, including dialogs.
135\end{funcdesc}
136
137\begin{funcdesc}{setbgcolor}{pixel}
138Set the default background color.
139This will become the default background color of windows opened
140subsequently, including dialogs.
141\end{funcdesc}
142
143\begin{funcdesc}{getfgcolor}{}
144Return the pixel value of the current default foreground color.
145\end{funcdesc}
146
147\begin{funcdesc}{getbgcolor}{}
148Return the pixel value of the current default background color.
149\end{funcdesc}
150
151\begin{funcdesc}{setfont}{fontname}
152Set the current default font.
153This will become the default font for windows opened subsequently,
154and is also used by the text measuring functions \code{textwidth},
155\code{textbreak}, \code{lineheight} and \code{baseline} below.
156This accepts two more optional parameters, size and style:
157Size is the font size (in `points').
158Style is a single character specifying the style, as follows:
159\code{'b'} = bold,
160\code{'i'} = italic,
161\code{'o'} = bold + italic,
162\code{'u'} = underline;
163default style is roman.
164Size and style are ignored under X11 but used on the Macintosh.
165(Sorry for all this complexity --- a more uniform interface is being designed.)
166\end{funcdesc}
167
168\begin{funcdesc}{menucreate}{title}
169Create a menu object referring to a global menu (a menu that appears in
170all windows).
171Methods of menu objects are described below.
172Note: normally, menus are created locally; see the window method
173\code{menucreate} below.
174\strong{Warning:} the menu only appears in a window as long as the object
175returned by this call exists.
176\end{funcdesc}
177
178\begin{funcdesc}{newbitmap}{width\, height}
179Create a new bitmap object of the given dimensions.
180Methods of bitmap objects are described below.
Guido van Rossum470be141995-03-17 16:07:09 +0000181Not available on the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000182\end{funcdesc}
183
184\begin{funcdesc}{fleep}{}
185Cause a beep or bell (or perhaps a `visual bell' or flash, hence the
186name).
187\end{funcdesc}
188
189\begin{funcdesc}{message}{string}
190Display a dialog box containing the string.
191The user must click OK before the function returns.
192\end{funcdesc}
193
194\begin{funcdesc}{askync}{prompt\, default}
195Display a dialog that prompts the user to answer a question with yes or
196no.
197Return 0 for no, 1 for yes.
198If the user hits the Return key, the default (which must be 0 or 1) is
199returned.
200If the user cancels the dialog, the
201\code{KeyboardInterrupt}
202exception is raised.
203\end{funcdesc}
204
205\begin{funcdesc}{askstr}{prompt\, default}
206Display a dialog that prompts the user for a string.
207If the user hits the Return key, the default string is returned.
208If the user cancels the dialog, the
209\code{KeyboardInterrupt}
210exception is raised.
211\end{funcdesc}
212
213\begin{funcdesc}{askfile}{prompt\, default\, new}
214Ask the user to specify a filename.
215If
216\var{new}
217is zero it must be an existing file; otherwise, it must be a new file.
218If the user cancels the dialog, the
219\code{KeyboardInterrupt}
220exception is raised.
221\end{funcdesc}
222
223\begin{funcdesc}{setcutbuffer}{i\, string}
224Store the string in the system's cut buffer number
225\var{i},
226where it can be found (for pasting) by other applications.
227On X11, there are 8 cut buffers (numbered 0..7).
228Cut buffer number 0 is the `clipboard' on the Macintosh.
229\end{funcdesc}
230
231\begin{funcdesc}{getcutbuffer}{i}
232Return the contents of the system's cut buffer number
233\var{i}.
234\end{funcdesc}
235
236\begin{funcdesc}{rotatecutbuffers}{n}
237On X11, rotate the 8 cut buffers by
238\var{n}.
239Ignored on the Macintosh.
240\end{funcdesc}
241
242\begin{funcdesc}{getselection}{i}
243Return X11 selection number
244\var{i.}
245Selections are not cut buffers.
246Selection numbers are defined in module
247\code{stdwinevents}.
248Selection \code{WS_PRIMARY} is the
249\dfn{primary}
250selection (used by
251xterm,
252for instance);
253selection \code{WS_SECONDARY} is the
254\dfn{secondary}
255selection; selection \code{WS_CLIPBOARD} is the
256\dfn{clipboard}
257selection (used by
258xclipboard).
259On the Macintosh, this always returns an empty string.
260\end{funcdesc}
261
262\begin{funcdesc}{resetselection}{i}
263Reset selection number
264\var{i},
265if this process owns it.
266(See window method
267\code{setselection()}).
268\end{funcdesc}
269
270\begin{funcdesc}{baseline}{}
271Return the baseline of the current font (defined by STDWIN as the
272vertical distance between the baseline and the top of the
273characters).
274\end{funcdesc}
275
276\begin{funcdesc}{lineheight}{}
277Return the total line height of the current font.
278\end{funcdesc}
279
280\begin{funcdesc}{textbreak}{str\, width}
281Return the number of characters of the string that fit into a space of
282\var{width}
283bits wide when drawn in the curent font.
284\end{funcdesc}
285
286\begin{funcdesc}{textwidth}{str}
287Return the width in bits of the string when drawn in the current font.
288\end{funcdesc}
289
290\begin{funcdesc}{connectionnumber}{}
291\funcline{fileno}{}
292(X11 under \UNIX{} only) Return the ``connection number'' used by the
293underlying X11 implementation. (This is normally the file number of
294the socket.) Both functions return the same value;
295\code{connectionnumber()} is named after the corresponding function in
296X11 and STDWIN, while \code{fileno()} makes it possible to use the
297\code{stdwin} module as a ``file'' object parameter to
298\code{select.select()}. Note that if \code{select()} implies that
299input is possible on \code{stdwin}, this does not guarantee that an
300event is ready --- it may be some internal communication going on
301between the X server and the client library. Thus, you should call
302\code{stdwin.pollevent()} until it returns \code{None} to check for
303events if you don't want your program to block. Because of internal
304buffering in X11, it is also possible that \code{stdwin.pollevent()}
305returns an event while \code{select()} does not find \code{stdwin} to
306be ready, so you should read any pending events with
307\code{stdwin.pollevent()} until it returns \code{None} before entering
308a blocking \code{select()} call.
309\ttindex{select}
310\end{funcdesc}
311
Guido van Rossum470be141995-03-17 16:07:09 +0000312\subsection{Window Objects}
Fred Drake4b3f0311996-12-13 22:04:31 +0000313\nodename{STDWIN Window Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000314
315Window objects are created by \code{stdwin.open()}. They are closed
316by their \code{close()} method or when they are garbage-collected.
317Window objects have the following methods:
318
319\renewcommand{\indexsubitem}{(window method)}
320
321\begin{funcdesc}{begindrawing}{}
322Return a drawing object, whose methods (described below) allow drawing
323in the window.
324\end{funcdesc}
325
326\begin{funcdesc}{change}{rect}
327Invalidate the given rectangle; this may cause a draw event.
328\end{funcdesc}
329
330\begin{funcdesc}{gettitle}{}
331Returns the window's title string.
332\end{funcdesc}
333
334\begin{funcdesc}{getdocsize}{}
335\begin{sloppypar}
336Return a pair of integers giving the size of the document as set by
337\code{setdocsize()}.
338\end{sloppypar}
339\end{funcdesc}
340
341\begin{funcdesc}{getorigin}{}
342Return a pair of integers giving the origin of the window with respect
343to the document.
344\end{funcdesc}
345
346\begin{funcdesc}{gettitle}{}
347Return the window's title string.
348\end{funcdesc}
349
350\begin{funcdesc}{getwinsize}{}
351Return a pair of integers giving the size of the window.
352\end{funcdesc}
353
354\begin{funcdesc}{getwinpos}{}
355Return a pair of integers giving the position of the window's upper
356left corner (relative to the upper left corner of the screen).
357\end{funcdesc}
358
359\begin{funcdesc}{menucreate}{title}
360Create a menu object referring to a local menu (a menu that appears
361only in this window).
362Methods of menu objects are described below.
363{\bf Warning:} the menu only appears as long as the object
364returned by this call exists.
365\end{funcdesc}
366
367\begin{funcdesc}{scroll}{rect\, point}
368Scroll the given rectangle by the vector given by the point.
369\end{funcdesc}
370
371\begin{funcdesc}{setdocsize}{point}
372Set the size of the drawing document.
373\end{funcdesc}
374
375\begin{funcdesc}{setorigin}{point}
376Move the origin of the window (its upper left corner)
377to the given point in the document.
378\end{funcdesc}
379
380\begin{funcdesc}{setselection}{i\, str}
381Attempt to set X11 selection number
382\var{i}
383to the string
384\var{str}.
385(See stdwin method
386\code{getselection()}
387for the meaning of
388\var{i}.)
389Return true if it succeeds.
390If succeeds, the window ``owns'' the selection until
Guido van Rossum16d6e711994-08-08 12:30:22 +0000391(a) another application takes ownership of the selection; or
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000392(b) the window is deleted; or
393(c) the application clears ownership by calling
394\code{stdwin.resetselection(\var{i})}.
395When another application takes ownership of the selection, a
396\code{WE_LOST_SEL}
397event is received for no particular window and with the selection number
398as detail.
399Ignored on the Macintosh.
400\end{funcdesc}
401
402\begin{funcdesc}{settimer}{dsecs}
403Schedule a timer event for the window in
404\code{\var{dsecs}/10}
405seconds.
406\end{funcdesc}
407
408\begin{funcdesc}{settitle}{title}
409Set the window's title string.
410\end{funcdesc}
411
412\begin{funcdesc}{setwincursor}{name}
413\begin{sloppypar}
414Set the window cursor to a cursor of the given name.
415It raises the
416\code{RuntimeError}
417exception if no cursor of the given name exists.
418Suitable names include
419\code{'ibeam'},
420\code{'arrow'},
421\code{'cross'},
422\code{'watch'}
423and
424\code{'plus'}.
425On X11, there are many more (see
426\file{<X11/cursorfont.h>}).
427\end{sloppypar}
428\end{funcdesc}
429
430\begin{funcdesc}{setwinpos}{h\, v}
431Set the the position of the window's upper left corner (relative to
432the upper left corner of the screen).
433\end{funcdesc}
434
435\begin{funcdesc}{setwinsize}{width\, height}
436Set the window's size.
437\end{funcdesc}
438
439\begin{funcdesc}{show}{rect}
440Try to ensure that the given rectangle of the document is visible in
441the window.
442\end{funcdesc}
443
444\begin{funcdesc}{textcreate}{rect}
445Create a text-edit object in the document at the given rectangle.
446Methods of text-edit objects are described below.
447\end{funcdesc}
448
449\begin{funcdesc}{setactive}{}
450Attempt to make this window the active window. If successful, this
451will generate a WE_ACTIVATE event (and a WE_DEACTIVATE event in case
452another window in this application became inactive).
453\end{funcdesc}
454
455\begin{funcdesc}{close}{}
456Discard the window object. It should not be used again.
457\end{funcdesc}
458
Guido van Rossum470be141995-03-17 16:07:09 +0000459\subsection{Drawing Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000460
461Drawing objects are created exclusively by the window method
462\code{begindrawing()}.
463Only one drawing object can exist at any given time; the drawing object
464must be deleted to finish drawing.
465No drawing object may exist when
466\code{stdwin.getevent()}
467is called.
468Drawing objects have the following methods:
469
470\renewcommand{\indexsubitem}{(drawing method)}
471
472\begin{funcdesc}{box}{rect}
473Draw a box just inside a rectangle.
474\end{funcdesc}
475
476\begin{funcdesc}{circle}{center\, radius}
477Draw a circle with given center point and radius.
478\end{funcdesc}
479
480\begin{funcdesc}{elarc}{center\, \(rh\, rv\)\, \(a1\, a2\)}
481Draw an elliptical arc with given center point.
482\code{(\var{rh}, \var{rv})}
483gives the half sizes of the horizontal and vertical radii.
484\code{(\var{a1}, \var{a2})}
485gives the angles (in degrees) of the begin and end points.
4860 degrees is at 3 o'clock, 90 degrees is at 12 o'clock.
487\end{funcdesc}
488
489\begin{funcdesc}{erase}{rect}
490Erase a rectangle.
491\end{funcdesc}
492
493\begin{funcdesc}{fillcircle}{center\, radius}
494Draw a filled circle with given center point and radius.
495\end{funcdesc}
496
497\begin{funcdesc}{fillelarc}{center\, \(rh\, rv\)\, \(a1\, a2\)}
498Draw a filled elliptical arc; arguments as for \code{elarc}.
499\end{funcdesc}
500
501\begin{funcdesc}{fillpoly}{points}
502Draw a filled polygon given by a list (or tuple) of points.
503\end{funcdesc}
504
505\begin{funcdesc}{invert}{rect}
506Invert a rectangle.
507\end{funcdesc}
508
509\begin{funcdesc}{line}{p1\, p2}
510Draw a line from point
511\var{p1}
512to
513\var{p2}.
514\end{funcdesc}
515
516\begin{funcdesc}{paint}{rect}
517Fill a rectangle.
518\end{funcdesc}
519
520\begin{funcdesc}{poly}{points}
521Draw the lines connecting the given list (or tuple) of points.
522\end{funcdesc}
523
524\begin{funcdesc}{shade}{rect\, percent}
525Fill a rectangle with a shading pattern that is about
526\var{percent}
527percent filled.
528\end{funcdesc}
529
530\begin{funcdesc}{text}{p\, str}
531Draw a string starting at point p (the point specifies the
532top left coordinate of the string).
533\end{funcdesc}
534
535\begin{funcdesc}{xorcircle}{center\, radius}
536\funcline{xorelarc}{center\, \(rh\, rv\)\, \(a1\, a2\)}
537\funcline{xorline}{p1\, p2}
538\funcline{xorpoly}{points}
539Draw a circle, an elliptical arc, a line or a polygon, respectively,
540in XOR mode.
541\end{funcdesc}
542
543\begin{funcdesc}{setfgcolor}{}
544\funcline{setbgcolor}{}
545\funcline{getfgcolor}{}
546\funcline{getbgcolor}{}
547These functions are similar to the corresponding functions described
548above for the
549\code{stdwin}
550module, but affect or return the colors currently used for drawing
551instead of the global default colors.
552When a drawing object is created, its colors are set to the window's
553default colors, which are in turn initialized from the global default
554colors when the window is created.
555\end{funcdesc}
556
557\begin{funcdesc}{setfont}{}
558\funcline{baseline}{}
559\funcline{lineheight}{}
560\funcline{textbreak}{}
561\funcline{textwidth}{}
562These functions are similar to the corresponding functions described
563above for the
564\code{stdwin}
565module, but affect or use the current drawing font instead of
566the global default font.
567When a drawing object is created, its font is set to the window's
568default font, which is in turn initialized from the global default
569font when the window is created.
570\end{funcdesc}
571
572\begin{funcdesc}{bitmap}{point\, bitmap\, mask}
573Draw the \var{bitmap} with its top left corner at \var{point}.
574If the optional \var{mask} argument is present, it should be either
575the same object as \var{bitmap}, to draw only those bits that are set
576in the bitmap, in the foreground color, or \code{None}, to draw all
577bits (ones are drawn in the foreground color, zeros in the background
578color).
Guido van Rossum470be141995-03-17 16:07:09 +0000579Not available on the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000580\end{funcdesc}
581
582\begin{funcdesc}{cliprect}{rect}
583Set the ``clipping region'' to a rectangle.
584The clipping region limits the effect of all drawing operations, until
585it is changed again or until the drawing object is closed. When a
586drawing object is created the clipping region is set to the entire
587window. When an object to be drawn falls partly outside the clipping
588region, the set of pixels drawn is the intersection of the clipping
589region and the set of pixels that would be drawn by the same operation
590in the absence of a clipping region.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000591\end{funcdesc}
592
593\begin{funcdesc}{noclip}{}
594Reset the clipping region to the entire window.
595\end{funcdesc}
596
597\begin{funcdesc}{close}{}
598\funcline{enddrawing}{}
599Discard the drawing object. It should not be used again.
600\end{funcdesc}
601
Guido van Rossum470be141995-03-17 16:07:09 +0000602\subsection{Menu Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000603
604A menu object represents a menu.
605The menu is destroyed when the menu object is deleted.
606The following methods are defined:
607
608\renewcommand{\indexsubitem}{(menu method)}
609
610\begin{funcdesc}{additem}{text\, shortcut}
611Add a menu item with given text.
612The shortcut must be a string of length 1, or omitted (to specify no
613shortcut).
614\end{funcdesc}
615
616\begin{funcdesc}{setitem}{i\, text}
617Set the text of item number
618\var{i}.
619\end{funcdesc}
620
621\begin{funcdesc}{enable}{i\, flag}
622Enable or disables item
623\var{i}.
624\end{funcdesc}
625
626\begin{funcdesc}{check}{i\, flag}
627Set or clear the
628\dfn{check mark}
629for item
630\var{i}.
631\end{funcdesc}
632
633\begin{funcdesc}{close}{}
634Discard the menu object. It should not be used again.
635\end{funcdesc}
636
Guido van Rossum470be141995-03-17 16:07:09 +0000637\subsection{Bitmap Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000638
639A bitmap represents a rectangular array of bits.
640The top left bit has coordinate (0, 0).
641A bitmap can be drawn with the \code{bitmap} method of a drawing object.
Guido van Rossum470be141995-03-17 16:07:09 +0000642Bitmaps are currently not available on the Macintosh.
643
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000644The following methods are defined:
645
646\renewcommand{\indexsubitem}{(bitmap method)}
647
648\begin{funcdesc}{getsize}{}
649Return a tuple representing the width and height of the bitmap.
650(This returns the values that have been passed to the \code{newbitmap}
651function.)
652\end{funcdesc}
653
654\begin{funcdesc}{setbit}{point\, bit}
655Set the value of the bit indicated by \var{point} to \var{bit}.
656\end{funcdesc}
657
658\begin{funcdesc}{getbit}{point}
659Return the value of the bit indicated by \var{point}.
660\end{funcdesc}
661
662\begin{funcdesc}{close}{}
663Discard the bitmap object. It should not be used again.
664\end{funcdesc}
665
Guido van Rossum470be141995-03-17 16:07:09 +0000666\subsection{Text-edit Objects}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000667
668A text-edit object represents a text-edit block.
669For semantics, see the STDWIN documentation for C programmers.
670The following methods exist:
671
672\renewcommand{\indexsubitem}{(text-edit method)}
673
674\begin{funcdesc}{arrow}{code}
675Pass an arrow event to the text-edit block.
676The
677\var{code}
678must be one of
679\code{WC_LEFT},
680\code{WC_RIGHT},
681\code{WC_UP}
682or
683\code{WC_DOWN}
684(see module
685\code{stdwinevents}).
686\end{funcdesc}
687
688\begin{funcdesc}{draw}{rect}
689Pass a draw event to the text-edit block.
690The rectangle specifies the redraw area.
691\end{funcdesc}
692
693\begin{funcdesc}{event}{type\, window\, detail}
694Pass an event gotten from
695\code{stdwin.getevent()}
696to the text-edit block.
697Return true if the event was handled.
698\end{funcdesc}
699
700\begin{funcdesc}{getfocus}{}
701Return 2 integers representing the start and end positions of the
702focus, usable as slice indices on the string returned by
703\code{gettext()}.
704\end{funcdesc}
705
706\begin{funcdesc}{getfocustext}{}
707Return the text in the focus.
708\end{funcdesc}
709
710\begin{funcdesc}{getrect}{}
711Return a rectangle giving the actual position of the text-edit block.
712(The bottom coordinate may differ from the initial position because
713the block automatically shrinks or grows to fit.)
714\end{funcdesc}
715
716\begin{funcdesc}{gettext}{}
717Return the entire text buffer.
718\end{funcdesc}
719
720\begin{funcdesc}{move}{rect}
721Specify a new position for the text-edit block in the document.
722\end{funcdesc}
723
724\begin{funcdesc}{replace}{str}
725Replace the text in the focus by the given string.
726The new focus is an insert point at the end of the string.
727\end{funcdesc}
728
729\begin{funcdesc}{setfocus}{i\, j}
730Specify the new focus.
731Out-of-bounds values are silently clipped.
732\end{funcdesc}
733
734\begin{funcdesc}{settext}{str}
735Replace the entire text buffer by the given string and set the focus
736to \code{(0, 0)}.
737\end{funcdesc}
738
739\begin{funcdesc}{setview}{rect}
740Set the view rectangle to \var{rect}. If \var{rect} is \code{None},
741viewing mode is reset. In viewing mode, all output from the text-edit
742object is clipped to the viewing rectangle. This may be useful to
743implement your own scrolling text subwindow.
744\end{funcdesc}
745
746\begin{funcdesc}{close}{}
747Discard the text-edit object. It should not be used again.
748\end{funcdesc}
749
750\subsection{Example}
Guido van Rossum86cb0921995-03-20 12:59:56 +0000751\nodename{STDWIN Example}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000752
753Here is a minimal example of using STDWIN in Python.
754It creates a window and draws the string ``Hello world'' in the top
755left corner of the window.
756The window will be correctly redrawn when covered and re-exposed.
757The program quits when the close icon or menu item is requested.
758
759\bcode\begin{verbatim}
760import stdwin
761from stdwinevents import *
762
763def main():
764 mywin = stdwin.open('Hello')
765 #
766 while 1:
767 (type, win, detail) = stdwin.getevent()
768 if type == WE_DRAW:
769 draw = win.begindrawing()
770 draw.text((0, 0), 'Hello, world')
771 del draw
772 elif type == WE_CLOSE:
773 break
774
775main()
776\end{verbatim}\ecode
Guido van Rossume47da0a1997-07-17 16:34:52 +0000777%
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000778\section{Standard Module \sectcode{stdwinevents}}
779\stmodindex{stdwinevents}
780
781This module defines constants used by STDWIN for event types
782(\code{WE_ACTIVATE} etc.), command codes (\code{WC_LEFT} etc.)
783and selection types (\code{WS_PRIMARY} etc.).
784Read the file for details.
785Suggested usage is
786
787\bcode\begin{verbatim}
788>>> from stdwinevents import *
789>>>
790\end{verbatim}\ecode
Guido van Rossume47da0a1997-07-17 16:34:52 +0000791%
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000792\section{Standard Module \sectcode{rect}}
793\stmodindex{rect}
794
795This module contains useful operations on rectangles.
796A rectangle is defined as in module
797\code{stdwin}:
798a pair of points, where a point is a pair of integers.
799For example, the rectangle
800
801\bcode\begin{verbatim}
802(10, 20), (90, 80)
803\end{verbatim}\ecode
Guido van Rossume47da0a1997-07-17 16:34:52 +0000804%
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000805is a rectangle whose left, top, right and bottom edges are 10, 20, 90
806and 80, respectively.
807Note that the positive vertical axis points down (as in
808\code{stdwin}).
809
810The module defines the following objects:
811
812\renewcommand{\indexsubitem}{(in module rect)}
813\begin{excdesc}{error}
814The exception raised by functions in this module when they detect an
815error.
816The exception argument is a string describing the problem in more
817detail.
818\end{excdesc}
819
820\begin{datadesc}{empty}
821The rectangle returned when some operations return an empty result.
822This makes it possible to quickly check whether a result is empty:
823
824\bcode\begin{verbatim}
825>>> import rect
826>>> r1 = (10, 20), (90, 80)
827>>> r2 = (0, 0), (10, 20)
828>>> r3 = rect.intersect([r1, r2])
829>>> if r3 is rect.empty: print 'Empty intersection'
830Empty intersection
831>>>
832\end{verbatim}\ecode
833\end{datadesc}
834
835\begin{funcdesc}{is_empty}{r}
836Returns true if the given rectangle is empty.
837A rectangle
838\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}
839is empty if
840\iftexi
841\code{\var{left} >= \var{right}} or \code{\var{top} => \var{bottom}}.
842\else
843$\var{left} \geq \var{right}$ or $\var{top} \geq \var{bottom}$.
844%%JHXXX{\em left~$\geq$~right} or {\em top~$\leq$~bottom}.
845\fi
846\end{funcdesc}
847
848\begin{funcdesc}{intersect}{list}
849Returns the intersection of all rectangles in the list argument.
850It may also be called with a tuple argument.
851Raises
852\code{rect.error}
853if the list is empty.
854Returns
855\code{rect.empty}
856if the intersection of the rectangles is empty.
857\end{funcdesc}
858
859\begin{funcdesc}{union}{list}
860Returns the smallest rectangle that contains all non-empty rectangles in
861the list argument.
862It may also be called with a tuple argument or with two or more
863rectangles as arguments.
864Returns
865\code{rect.empty}
866if the list is empty or all its rectangles are empty.
867\end{funcdesc}
868
869\begin{funcdesc}{pointinrect}{point\, rect}
870Returns true if the point is inside the rectangle.
871By definition, a point
872\code{(\var{h}, \var{v})}
873is inside a rectangle
874\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})} if
875\iftexi
876\code{\var{left} <= \var{h} < \var{right}} and
877\code{\var{top} <= \var{v} < \var{bottom}}.
878\else
879$\var{left} \leq \var{h} < \var{right}$ and
880$\var{top} \leq \var{v} < \var{bottom}$.
881\fi
882\end{funcdesc}
883
884\begin{funcdesc}{inset}{rect\, \(dh\, dv\)}
885Returns a rectangle that lies inside the
886\code{rect}
887argument by
888\var{dh}
889pixels horizontally
890and
891\var{dv}
892pixels
893vertically.
894If
895\var{dh}
896or
897\var{dv}
898is negative, the result lies outside
899\var{rect}.
900\end{funcdesc}
901
902\begin{funcdesc}{rect2geom}{rect}
903Converts a rectangle to geometry representation:
904\code{(\var{left}, \var{top}), (\var{width}, \var{height})}.
905\end{funcdesc}
906
907\begin{funcdesc}{geom2rect}{geom}
908Converts a rectangle given in geometry representation back to the
909standard rectangle representation
910\code{(\var{left}, \var{top}), (\var{right}, \var{bottom})}.
911\end{funcdesc}