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