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