source: vendor/python/2.5/Doc/lib/libstdwin.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

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