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