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