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