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