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