Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1 | % Format this file with latex. |
| 2 | |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 3 | %\documentstyle[palatino,11pt,myformat]{article} |
| 4 | \documentstyle[11pt,myformat]{article} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 5 | |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 6 | % A command to force the text after an item to start on a new line |
| 7 | \newcommand{\itembreak}{ |
| 8 | \mbox{}\\*[0mm] |
| 9 | } |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 10 | |
| 11 | \title{\bf |
| 12 | Python Library Reference \\ |
| 13 | (DRAFT) |
| 14 | } |
| 15 | |
| 16 | \author{ |
| 17 | Guido van Rossum \\ |
| 18 | Dept. CST, CWI, Kruislaan 413 \\ |
| 19 | 1098 SJ Amsterdam, The Netherlands \\ |
| 20 | E-mail: {\tt guido@cwi.nl} |
| 21 | } |
| 22 | |
| 23 | \begin{document} |
| 24 | |
| 25 | \pagenumbering{roman} |
| 26 | |
| 27 | \maketitle |
| 28 | |
| 29 | \begin{abstract} |
| 30 | |
| 31 | \noindent |
| 32 | This document describes the built-in types, exceptions and functions and |
| 33 | the standard modules that come with the {\Python} system. |
| 34 | It assumes basic knowledge about the {\Python} language. |
| 35 | For an informal introduction to the language, see the Tutorial document. |
| 36 | The Language Reference document (XXX not yet existing) |
| 37 | gives a more formal reference to the language. |
| 38 | |
| 39 | \end{abstract} |
| 40 | |
| 41 | \pagebreak |
| 42 | |
| 43 | \tableofcontents |
| 44 | |
| 45 | \pagebreak |
| 46 | |
| 47 | \pagenumbering{arabic} |
| 48 | |
| 49 | \section{Introduction} |
| 50 | |
| 51 | The {\Python} library consists of three parts, with different levels of |
| 52 | integration with the interpreter. |
| 53 | Closest to the interpreter are built-in types, exceptions and functions. |
| 54 | Next are built-in modules, which are written in C and linked statically |
| 55 | with the interpreter. |
| 56 | Finally there are standard modules that are implemented entirely in |
| 57 | {\Python}, but are always available. |
| 58 | For efficiency, some standard modules may become built-in modules in |
| 59 | future versions of the interpreter. |
| 60 | |
| 61 | \section{Built-in Types, Exceptions and Functions} |
| 62 | |
| 63 | Names for built-in exceptions and functions are found in a separate |
| 64 | read-only symbol table which cannot be modified. |
| 65 | This table is searched last, so local and global user-defined names can |
| 66 | override built-in names. |
| 67 | Built-in types have no names but are created by syntactic constructs |
| 68 | (such as constants) or built-in functions. |
| 69 | They are described together here for easy reference.% |
| 70 | \footnote{ |
| 71 | The descriptions sorely lack explanations of the exceptions that |
| 72 | may be raised---this will be fixed in a future version of this |
| 73 | document. |
| 74 | } |
| 75 | |
| 76 | \subsection{Built-in Types} |
| 77 | |
| 78 | The following sections describe the standard types that are built into the |
| 79 | interpreter. |
| 80 | \subsubsection{Numeric Types} |
| 81 | |
| 82 | There are two numeric types: integers and floating point numbers. |
| 83 | Integers are implemented using {\tt long} in C, so they have at least 32 |
| 84 | bits of precision. |
| 85 | Floating point numbers are implemented using {\tt double} in C. |
| 86 | All bets on precision are off. |
| 87 | Numbers are created by numeric constants or as the result of built-in |
| 88 | functions and operators. |
| 89 | |
| 90 | Numeric types support the following operations: |
| 91 | |
| 92 | \begin{center} |
| 93 | \begin{tabular}{|c|l|c|} |
| 94 | \hline |
| 95 | Operation & Result & Notes \\ |
| 96 | \hline |
| 97 | {\tt abs}({\em x}) & absolute value of {\em x} & \\ |
| 98 | {\tt int}({\em x}) & {\em x} converted to integer & (1) \\ |
| 99 | {\tt float}({\em x}) & {\em x} converted to floating point & \\ |
| 100 | {\tt -}{\em x} & {\em x} negated & \\ |
| 101 | {\tt +}{\em x} & {\em x} unchanged & \\ |
| 102 | {\em x}{\tt +}{\em y} & sum of {\em x} and {\em y} & \\ |
| 103 | {\em x}{\tt -}{\em y} & difference of {\em x} and {\em y} & \\ |
| 104 | {\em x}{\tt *}{\em y} & product of {\em x} and {\em y} & \\ |
| 105 | {\em x}{\tt /}{\em y} & quotient of {\em x} and {\em y} & (2) \\ |
| 106 | {\em x}{\tt \%}{\em y} & remainder of {\em x}{\tt /}{\em y} & (3) \\ |
| 107 | \hline |
| 108 | \end{tabular} |
| 109 | \end{center} |
| 110 | |
| 111 | \noindent |
| 112 | Notes: |
| 113 | \begin{description} |
| 114 | \item[(1)] |
| 115 | This may round or truncate as in C; see functions {\tt floor} and |
| 116 | {\tt ceil} in module {\tt math}. |
| 117 | \item[(2)] |
| 118 | Integer division is defined as in C: the result is an integer; with |
| 119 | positive operands, it truncates towards zero; with a negative operand, |
| 120 | the result is unspecified. |
| 121 | \item[(3)] |
| 122 | Only defined for integers. |
| 123 | \end{description} |
| 124 | |
| 125 | Mixed arithmetic is not supported; both operands must have the same type. |
| 126 | Mixed comparisons return the wrong result (floats always compare smaller |
| 127 | than integers).% |
| 128 | \footnote{ |
| 129 | These restrictions are bugs in the language definitions and will be |
| 130 | fixed in the future. |
| 131 | } |
| 132 | \subsubsection{Sequence Types} |
| 133 | |
| 134 | There are three sequence types: strings, lists and tuples. |
| 135 | Strings constants are written in single quotes: {\tt 'xyzzy'}. |
| 136 | Lists are constructed with square brackets: {\tt [a,~b,~c]}. |
| 137 | Tuples are constructed by the comma operator or with an empty set of |
| 138 | parentheses: {\tt a,~b,~c} or {\tt ()}. |
| 139 | |
| 140 | Sequence types support the following operations ({\em s} and {\em t} are |
| 141 | sequences of the same type; {\em n}, {\em i} and {\em j} are integers): |
| 142 | |
| 143 | \begin{center} |
| 144 | \begin{tabular}{|c|l|c|} |
| 145 | \hline |
| 146 | Operation & Result & Notes \\ |
| 147 | \hline |
| 148 | {\tt len}({\em s}) & length of {\em s} & \\ |
| 149 | {\tt min}({\em s}) & smallest item of {\em s} & \\ |
| 150 | {\tt max}({\em s}) & largest item of {\em s} & \\ |
| 151 | {\em x} {\tt in} {\em s} & |
| 152 | true if an item of {\em s} is equal to {\em x} & \\ |
| 153 | {\em x} {\tt not} {\tt in} {\em s} & |
| 154 | false if an item of {\em s} is equal to {\em x} & \\ |
| 155 | {\em s}{\tt +}{\em t} & the concatenation of {\em s} and {\em t} & \\ |
| 156 | {\em s}{\tt *}{\em n}, {\em n}*{\em s} & |
| 157 | {\em n} copies of {\em s} concatenated & (1) \\ |
| 158 | {\em s}[{\em i}] & {\em i}'th item of {\em s} & \\ |
| 159 | {\em s}[{\em i}:{\em j}] & |
| 160 | slice of {\em s} from {\em i} to {\em j} & (2) \\ |
| 161 | \hline |
| 162 | \end{tabular} |
| 163 | \end{center} |
| 164 | |
| 165 | \noindent |
| 166 | Notes: |
| 167 | \begin{description} |
| 168 | \item[(1)] |
| 169 | Sequence repetition is only supported for strings. |
| 170 | \item[(2)] |
| 171 | The slice of $s$ from $i$ to $j$ is defined as the sequence |
| 172 | of items with index $k$ such that $i \leq k < j$. |
| 173 | Special rules apply for negative and omitted indices; see the Tutorial |
| 174 | or the Reference Manual. |
| 175 | \end{description} |
| 176 | |
| 177 | \paragraph{Mutable Sequence Types.} |
| 178 | |
| 179 | List objects support additional operations that allow in-place |
| 180 | modification of the object. |
| 181 | These operations would be supported by other mutable sequence types |
| 182 | (when added to the language) as well. |
| 183 | Strings and tuples are immutable sequence types and such objects cannot |
| 184 | be modified once created. |
| 185 | The following operations are defined on mutable sequence types (where |
| 186 | {\em x} is an arbitrary object): |
| 187 | |
| 188 | \begin{center} |
| 189 | \begin{tabular}{|c|l|} |
| 190 | \hline |
| 191 | Operation & Result \\ |
| 192 | \hline |
| 193 | {\em s}[{\em i}] = {\em x} & |
| 194 | item {\em i} of {\em s} is replaced by {\em x} \\ |
| 195 | {\em s}[{\em i}:{\em j}] = {\em t} & |
| 196 | slice of {\em s} from {\em i} to {\em j} is replaced by {\em t} \\ |
| 197 | {\tt del} {\em s}[{\em i}:{\em j}] & |
| 198 | same as {\em s}[{\em i}:{\em j}] = [] \\ |
| 199 | {\em s}.{\tt append}({\em x}) & |
| 200 | same as {\em s}[{\tt len}({\em x}):{\tt len}({\em x})] = [{\em x}] \\ |
| 201 | {\em s}.{\tt insert}({\em i}, {\em x}) & |
| 202 | same as {\em s}[{\em i}:{\em i}] = [{\em x}] \\ |
| 203 | {\em s}.{\tt sort}() & |
| 204 | the items of {\em s} are permuted to satisfy \\ |
| 205 | & |
| 206 | $s[i] \leq s[j]$ for $i < j$\\ |
| 207 | \hline |
| 208 | \end{tabular} |
| 209 | \end{center} |
| 210 | |
| 211 | \subsubsection{Mapping Types} |
| 212 | |
| 213 | A |
| 214 | {\em mapping} |
| 215 | object maps values of one type (the key type) to arbitrary objects. |
| 216 | Mappings are mutable objects. |
| 217 | There is currently only one mapping type, the |
| 218 | {\em dictionary}. |
| 219 | A dictionary's keys are strings. |
| 220 | An empty dictionary is created by the expression \verb"{}". |
| 221 | An extension of this notation is used to display dictionaries when |
| 222 | written (see the example below). |
| 223 | |
| 224 | The following operations are defined on mappings (where {\em a} is a |
| 225 | mapping, {\em k} is a key and {\em x} is an arbitrary object): |
| 226 | |
| 227 | \begin{center} |
| 228 | \begin{tabular}{|c|l|c|} |
| 229 | \hline |
| 230 | Operation & Result & Notes\\ |
| 231 | \hline |
| 232 | {\tt len}({\em a}) & the number of elements in {\em a} & \\ |
| 233 | {\em a}[{\em k}] & the item of {\em a} with key {\em k} & \\ |
| 234 | {\em a}[{\em k}] = {\em x} & set {\em a}[{\em k}] to {\em x} & \\ |
| 235 | {\tt del} {\em a}[{\em k}] & remove {\em a}[{\em k}] from {\em a} & \\ |
| 236 | {\em a}.{\tt keys}() & a copy of {\em a}'s list of keys & (1) \\ |
| 237 | {\em a}.{\tt has\_key}({\em k}) & true if {\em a} has a key {\em k} & \\ |
| 238 | \hline |
| 239 | \end{tabular} |
| 240 | \end{center} |
| 241 | |
| 242 | \noindent |
| 243 | Notes: |
| 244 | \begin{description} |
| 245 | \item[(1)] |
| 246 | Keys are listed in random order. |
| 247 | \end{description} |
| 248 | |
| 249 | A small example using a dictionary: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 250 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 251 | >>> tel = {} |
| 252 | >>> tel['jack'] = 4098 |
| 253 | >>> tel['sape'] = 4139 |
| 254 | >>> tel['guido'] = 4127 |
| 255 | >>> tel['jack'] |
| 256 | 4098 |
| 257 | >>> tel |
| 258 | {'sape': 4139; 'guido': 4127; 'jack': 4098} |
| 259 | >>> del tel['sape'] |
| 260 | >>> tel['irv'] = 4127 |
| 261 | >>> tel |
| 262 | {'guido': 4127; 'irv': 4127; 'jack': 4098} |
| 263 | >>> tel.keys() |
| 264 | ['guido', 'irv', 'jack'] |
| 265 | >>> tel.has_key('guido') |
| 266 | 1 |
| 267 | >>> |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 268 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 269 | \subsubsection{Other Built-in Types} |
| 270 | |
| 271 | The interpreter supports several other kinds of objects. |
| 272 | Most of these support only one or two operations. |
| 273 | |
| 274 | \paragraph{Modules.} |
| 275 | |
| 276 | The only operation on a module is member acces: {\em m}{\tt .}{\em name}, |
| 277 | where {\em m} is a module and {\em name} accesses a name defined in |
| 278 | {\em m}'s symbol table. |
| 279 | Module members can be assigned to. |
| 280 | |
| 281 | \paragraph{Classes and Class Objects.} |
| 282 | |
| 283 | XXX Classes will be explained at length in a later version of this |
| 284 | document. |
| 285 | |
| 286 | \paragraph{Functions.} |
| 287 | |
| 288 | Function objects are created by function definitions. |
| 289 | The only operation on a function object is to call it: |
| 290 | {\em func}({\em optional-arguments}). |
| 291 | |
| 292 | Built-in functions have a different type than user-defined functions, |
| 293 | but they support the same operation. |
| 294 | |
| 295 | \paragraph{Methods.} |
| 296 | |
| 297 | Methods are functions that are called using the member acces notation. |
| 298 | There are two flavors: built-in methods (such as {\tt append()} on |
| 299 | lists) and class member methods. |
| 300 | Built-in methods are described with the types that support them. |
| 301 | XXX Class member methods will be described in a later version of this |
| 302 | document. |
| 303 | |
| 304 | \paragraph{Type Objects.} |
| 305 | |
| 306 | Type objects represent the various object types. |
| 307 | An object's type is accessed by the built-in function |
| 308 | {\tt type()}. |
| 309 | There are no operations on type objects. |
| 310 | |
| 311 | \paragraph{The Null Object.} |
| 312 | |
| 313 | This object is returned by functions that don't explicitly return a |
| 314 | value. |
| 315 | It supports no operations. |
| 316 | There is exactly one null object. |
| 317 | |
| 318 | \paragraph{File Objects.} |
| 319 | |
| 320 | File objects are implemented using C's |
| 321 | {\em stdio} |
| 322 | package and can be created with the built-in function |
| 323 | {\tt open()}. |
| 324 | They have the following methods: |
| 325 | \begin{description} |
| 326 | \item[{\tt close()}] |
| 327 | Closes the file. |
| 328 | A closed file cannot be read or written anymore. |
| 329 | \item[{\tt read(size)}] |
| 330 | Reads at most |
| 331 | {\tt size} |
| 332 | bytes from the file (less if the read hits EOF). |
| 333 | The bytes are returned as a string object. |
| 334 | An empty string is returned when EOF is hit immediately. |
| 335 | (For certain files, like ttys, it makes sense to continue reading after |
| 336 | an EOF is hit.) |
| 337 | \item[{\tt readline(size)}] |
| 338 | Reads a line of at most |
| 339 | {\tt size} |
| 340 | bytes from the file. |
| 341 | A trailing newline character, if present, is kept in the string. |
| 342 | The size is optional and defaults to a large number (but not infinity). |
| 343 | EOF is reported as by |
| 344 | {\tt read().} |
| 345 | \item[{\tt write(str)}] |
| 346 | Writes a string to the file. |
| 347 | Returns no value. |
| 348 | \end{description} |
| 349 | |
| 350 | \subsection{Built-in Exceptions} |
| 351 | |
| 352 | The following exceptions can be generated by the interpreter or |
| 353 | built-in functions. |
| 354 | Except where mentioned, they have a string argument (also known as the |
| 355 | `associated value' of an exception) indicating the detailed cause of the |
| 356 | error. |
| 357 | The strings listed with the exception names are their values when used |
| 358 | in an expression or printed. |
| 359 | \begin{description} |
| 360 | \item[{\tt EOFError = 'end-of-file read'} (no argument)] |
| 361 | %.br |
| 362 | Raised when a built-in function ({\tt input()} or {\tt raw\_input()}) |
| 363 | hits an end-of-file condition (EOF) without reading any data. |
| 364 | (N.B.: the {\tt read()} and {\tt readline()} methods of file objects |
| 365 | return an empty string when they hit EOF.) |
| 366 | \item[{\tt KeyboardInterrupt = 'end-of-file read'} (no argument)] |
| 367 | %.br |
| 368 | Raised when the user hits the interrupt key (normally Control-C or DEL). |
| 369 | During execution, a check for interrupts is made regularly. |
| 370 | Interrupts typed when a built-in function ({\tt input()} or |
| 371 | {\tt raw\_input()}) is waiting for input also raise this exception. |
| 372 | \item[{\tt MemoryError = 'out of memory'}] |
| 373 | %.br |
| 374 | Raised when an operation runs out of memory but the situation |
| 375 | may still be rescued (by deleting some objects). |
| 376 | \item[{\tt NameError = 'undefined name'}] |
| 377 | %.br |
| 378 | Raised when a name is not found. |
| 379 | This applies to unqualified names, module names (on {\tt import}), |
| 380 | module members and object methods. |
| 381 | The string argument is the name that could not be found. |
| 382 | \item[{\tt RuntimeError = 'run-time error'}] |
| 383 | %.br |
| 384 | Raised for a variety of reasons, e.g., division by zero or index out of |
| 385 | range. |
| 386 | \item[{\tt SystemError = 'system error'}] |
| 387 | %.br |
| 388 | Raised when the interpreter finds an internal error, but the situation |
| 389 | does not look so serious to cause it to abandon all hope. |
| 390 | \item[{\tt TypeError = 'type error'}] |
| 391 | %.br |
| 392 | Raised when an operation or built-in function is applied to an object of |
| 393 | inappropriate type. |
| 394 | \end{description} |
| 395 | |
| 396 | \subsection{Built-in Functions} |
| 397 | |
| 398 | The {\Python} interpreter has a small number of functions built into it that |
| 399 | are always available. |
| 400 | They are listed here in alphabetical order. |
| 401 | \begin{description} |
| 402 | \item[{\tt abs(x)}] |
| 403 | Returns the absolute value of a number. |
| 404 | The argument may be an integer or floating point number. |
| 405 | \item[{\tt dir()}] |
| 406 | Without arguments, this function returns the list of names in the |
| 407 | current local symbol table, sorted alphabetically. |
| 408 | With a module object as argument, it returns the sorted list of names in |
| 409 | that module's global symbol table. |
| 410 | For example: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 411 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 412 | >>> import sys |
| 413 | >>> dir() |
| 414 | ['sys'] |
| 415 | >>> dir(sys) |
| 416 | ['argv', 'exit', 'modules', 'path', 'stderr', 'stdin', 'stdout'] |
| 417 | >>> |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 418 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 419 | \item[{\tt divmod(a, b)}] |
| 420 | %.br |
| 421 | Takes two integers as arguments and returns a pair of integers |
| 422 | consisting of their quotient and remainder. |
| 423 | For |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 424 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 425 | q, r = divmod(a, b) |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 426 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 427 | the invariants are: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 428 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 429 | a = q*b + r |
| 430 | abs(r) < abs(b) |
| 431 | r has the same sign as b |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 432 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 433 | For example: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 434 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 435 | >>> divmod(100, 7) |
| 436 | (14, 2) |
| 437 | >>> divmod(-100, 7) |
| 438 | (-15, 5) |
| 439 | >>> divmod(100, -7) |
| 440 | (-15, -5) |
| 441 | >>> divmod(-100, -7) |
| 442 | (14, -2) |
| 443 | >>> |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 444 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 445 | \item[{\tt eval(s)}] |
| 446 | Takes a string as argument and parses and evaluates it as a {\Python} |
| 447 | expression. |
| 448 | The expression is executed using the current local and global symbol |
| 449 | tables. |
| 450 | Syntax errors are reported as exceptions. |
| 451 | For example: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 452 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 453 | >>> x = 1 |
| 454 | >>> eval('x+1') |
| 455 | 2 |
| 456 | >>> |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 457 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 458 | \item[{\tt exec(s)}] |
| 459 | Takes a string as argument and parses and evaluates it as a sequence of |
| 460 | {\Python} statements. |
| 461 | The string should end with a newline (\verb"'\n'"). |
| 462 | The statement is executed using the current local and global symbol |
| 463 | tables. |
| 464 | Syntax errors are reported as exceptions. |
| 465 | For example: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 466 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 467 | >>> x = 1 |
| 468 | >>> exec('x = x+1\n') |
| 469 | >>> x |
| 470 | 2 |
| 471 | >>> |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 472 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 473 | \item[{\tt float(x)}] |
| 474 | Converts a number to floating point. |
| 475 | The argument may be an integer or floating point number. |
| 476 | \item[{\tt input(s)}] |
| 477 | Equivalent to |
| 478 | {\tt eval(raw\_input(s))}. |
| 479 | As for |
| 480 | {\tt raw\_input()}, |
| 481 | the argument is optional. |
| 482 | \item[{\tt len(s)}] |
| 483 | Returns the length (the number of items) of an object. |
| 484 | The argument may be a sequence (string, tuple or list) or a mapping |
| 485 | (dictionary). |
| 486 | \item[{\tt max(s)}] |
| 487 | Returns the largest item of a non-empty sequence (string, tuple or list). |
| 488 | \item[{\tt min(s)}] |
| 489 | Returns the smallest item of a non-empty sequence (string, tuple or list). |
| 490 | \item[{\tt open(name, mode)}] |
| 491 | %.br |
| 492 | Returns a file object (described earlier under Built-in Types). |
| 493 | The string arguments are the same as for stdio's |
| 494 | {\tt fopen()}: |
| 495 | {\tt 'r'} |
| 496 | opens the file for reading, |
| 497 | {\tt 'w'} |
| 498 | opens it for writing (truncating an existing file), |
| 499 | {\tt 'a'} |
| 500 | opens it for appending.% |
| 501 | \footnote{ |
| 502 | This function should go into a built-in module |
| 503 | {\tt io}. |
| 504 | } |
| 505 | \item[{\tt range()}] |
| 506 | This is a versatile function to create lists containing arithmetic |
| 507 | progressions of integers. |
| 508 | With two integer arguments, it returns the ascending sequence of |
| 509 | integers starting at the first and ending one before the second |
| 510 | argument. |
| 511 | A single argument is used as the end point of the sequence, with 0 used |
| 512 | as the starting point. |
| 513 | A third argument specifies the step size; negative steps are allowed and |
| 514 | work as expected, but don't specify a zero step. |
| 515 | The resulting list may be empty. |
| 516 | For example: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 517 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 518 | >>> range(10) |
| 519 | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
| 520 | >>> range(1, 1+10) |
| 521 | [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
| 522 | >>> range(0, 30, 5) |
| 523 | [0, 5, 10, 15, 20, 25] |
| 524 | >>> range(0, 10, 3) |
| 525 | [0, 3, 6, 9] |
| 526 | >>> range(0, -10, -1) |
| 527 | [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] |
| 528 | >>> range(0) |
| 529 | [] |
| 530 | >>> range(1, 0) |
| 531 | [] |
| 532 | >>> |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 533 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 534 | \item[{\tt raw\_input(s)}] |
| 535 | %.br |
| 536 | The argument is optional; if present, it is written to standard output |
| 537 | without a trailing newline. |
| 538 | The function then reads a line from input, converts it to a string |
| 539 | (stripping a trailing newline), and returns that. |
| 540 | EOF is reported as an exception. |
| 541 | For example: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 542 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 543 | >>> raw_input('Type anything: ') |
| 544 | Type anything: Teenage Mutant Ninja Turtles |
| 545 | 'Teenage Mutant Ninja Turtles' |
| 546 | >>> |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 547 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 548 | \item[{\tt type(x)}] |
| 549 | Returns the type of an object. |
| 550 | Types are objects themselves: |
| 551 | the type of a type object is its own type. |
| 552 | \end{description} |
| 553 | |
| 554 | \section{Built-in Modules} |
| 555 | |
| 556 | The modules described in this section are built into the interpreter. |
| 557 | They must be imported using |
| 558 | {\tt import}. |
| 559 | Some modules are not always available; it is a configuration option to |
| 560 | provide them. |
| 561 | Details are listed with the descriptions, but the best way to see if |
| 562 | a module exists in a particular implementation is to attempt to import |
| 563 | it. |
| 564 | |
| 565 | \subsection{Built-in Module {\tt sys}} |
| 566 | |
| 567 | This module provides access to some variables used or maintained by the |
| 568 | interpreter and to functions that interact strongly with the interpreter. |
| 569 | It is always available. |
| 570 | \begin{description} |
| 571 | \item[{\tt argv}] |
| 572 | The list of command line arguments passed to a {\Python} script. |
| 573 | {\tt sys.argv[0]} |
| 574 | is the script name. |
| 575 | If no script name was passed to the {\Python} interpreter, |
| 576 | {\tt sys.argv} |
| 577 | is empty. |
| 578 | \item[{\tt exit(n)}] |
| 579 | Exits from {\Python} with numeric exit status |
| 580 | {\tt n}. |
| 581 | This closes all open files and performs other cleanup-actions required by |
| 582 | the interpreter (but |
| 583 | {\em finally clauses} |
| 584 | of |
| 585 | {\tt try} |
| 586 | statements are not executed!). |
| 587 | \item[{\tt modules}] |
| 588 | Gives the list of modules that have already been loaded. |
| 589 | This can be manipulated to force reloading of modules and other tricks. |
| 590 | \item[{\tt path}] |
| 591 | A list of strings that specifies the search path for modules. |
| 592 | Initialized from the environment variable {\tt PYTHONPATH}, or an |
| 593 | installation-dependent default. |
| 594 | \item[{\tt ps1,~ps2}] |
| 595 | Strings specifying the primary and secondary prompt of the interpreter. |
| 596 | These are only defined if the interpreter is in interactive mode. |
| 597 | Their initial values in this case are |
| 598 | {\tt '>>> '} |
| 599 | and |
| 600 | {\tt '... '}. |
| 601 | \item[{\tt stdin, stdout, stderr}] |
| 602 | %.br |
| 603 | File objects corresponding to the interpreter's standard input, output |
| 604 | and error streams. |
| 605 | {\tt sys.stdin} |
| 606 | is used for all interpreter input except for scripts but including calls |
| 607 | to |
| 608 | {\tt input()} |
| 609 | and |
| 610 | {\tt raw\_input()}. |
| 611 | {\tt sys.stdout} |
| 612 | is used for the output of |
| 613 | {\tt print} and expression statements |
| 614 | and for the prompts of |
| 615 | {\tt input()} |
| 616 | and |
| 617 | {\tt raw\_input()}. |
| 618 | The interpreter's own prompts and its error messages are written to |
| 619 | stderr. |
| 620 | Assigning to |
| 621 | {\tt sys.stderr} |
| 622 | has no effect on the interpreter; it can be used to write error messages |
| 623 | to stderr using |
| 624 | {\tt print}. |
| 625 | \end{description} |
| 626 | |
| 627 | \subsection{Built-in Module {\tt math}} |
| 628 | |
| 629 | This module is always available. |
| 630 | It provides access to the mathematical functions defined by the C |
| 631 | standard. |
| 632 | They are: |
| 633 | {\tt acos(x)}, |
| 634 | {\tt asin(x)}, |
| 635 | {\tt atan(x)}, |
| 636 | {\tt atan2(x,y)}, |
| 637 | {\tt ceil(x)}, |
| 638 | {\tt cos(x)}, |
| 639 | {\tt cosh(x)}, |
| 640 | {\tt exp(x)}, |
| 641 | {\tt fabs(x)}, |
| 642 | {\tt floor(x)}, |
| 643 | %{\tt fmod(...)} XXX not yet |
| 644 | %{\tt frexp(...)} XXX not yet |
| 645 | %{\tt ldexp(...)} XXX not yet |
| 646 | {\tt log(x)}, |
| 647 | {\tt log10(x)}, |
| 648 | %{\tt modf(...)} XXX not yet |
| 649 | {\tt pow(x,y)}, |
| 650 | {\tt sin(x)}, |
| 651 | {\tt sinh(x)}, |
| 652 | {\tt sqrt(x)}, |
| 653 | {\tt tan(x)}, |
| 654 | {\tt tanh(x)}. |
| 655 | |
| 656 | It also defines two mathematical constants: |
| 657 | {\tt pi} |
| 658 | and |
| 659 | {\tt e}. |
| 660 | |
| 661 | \subsection{Built-in Module {\tt time}} |
| 662 | |
| 663 | This module provides various time-related functions. |
| 664 | It is always available. |
| 665 | Functions are: |
| 666 | \begin{description} |
| 667 | \item[{\tt sleep(secs)}] |
| 668 | Suspends execution for the given number of seconds. |
| 669 | \item[{\tt time()}] |
| 670 | Returns the time in seconds since the Epoch (Thursday January 1, |
| 671 | 00:00:00, 1970 UCT on \UNIX\ machines). |
| 672 | \end{description} |
| 673 | |
| 674 | \noindent |
| 675 | In some versions (Amoeba, Mac) the following functions also exist: |
| 676 | \begin{description} |
| 677 | \item[{\tt millisleep(msecs)}] |
| 678 | Suspends execution for the given number of milliseconds. |
| 679 | \item[{\tt millitimer()}] |
| 680 | Returns the number of milliseconds of real time elapsed since some point |
| 681 | in the past that is fixed per execution of the python interpreter (but |
| 682 | may change in each following run). |
| 683 | \end{description} |
| 684 | |
| 685 | \noindent |
| 686 | The granularity of the milliseconds functions may be more than a |
| 687 | millisecond (100 msecs on Amoeba, 1/60 sec on the Mac). |
| 688 | |
| 689 | \subsection{Built-in Module {\tt posix}} |
| 690 | |
| 691 | This module provides access to operating system functionality that is |
| 692 | standardized by the C Standard and the POSIX standard (a thinly diguised |
| 693 | {\UNIX} interface). |
| 694 | It is available in all {\Python} versions except on the Macintosh. |
| 695 | Errors are reported exceptions. |
| 696 | It defines the following items: |
| 697 | \begin{description} |
| 698 | \item[{\tt chdir(path)}] |
| 699 | Changes the current directory to |
| 700 | {\tt path}. |
| 701 | \item[{\tt chmod(path, mode)}] |
| 702 | Change the mode of |
| 703 | {\tt path} |
| 704 | to the numeric |
| 705 | {\tt mode}. |
| 706 | \item[{\tt environ}] |
| 707 | A dictionary representing the string environment at the time |
| 708 | the interpreter was started. |
| 709 | (Modifying this dictionary does not affect the string environment of the |
| 710 | interpreter.) |
| 711 | For example, |
| 712 | {\tt posix.environ['HOME']} |
| 713 | is the pathname of your home directory, equivalent to |
| 714 | {\tt getenv("HOME")} |
| 715 | in C. |
| 716 | \item[{\tt error = 'posix.error'}] |
| 717 | %.br |
| 718 | The exception raised when an POSIX function returns an error. |
| 719 | The value accompanying this exception is a pair containing the numeric |
| 720 | error code from |
| 721 | {\tt errno} |
| 722 | and the corresponding string, as would be printed by the C function |
| 723 | {\tt perror()}. |
| 724 | \item[{\tt getcwd()}] |
| 725 | Returns a string representing the current working directory. |
| 726 | \item[{\tt link(src, dst)}] |
| 727 | Creates a hard link pointing to |
| 728 | {\tt src} |
| 729 | named |
| 730 | {\tt dst}. |
| 731 | \item[{\tt listdir(path)}] |
| 732 | Returns a list containing the names of the entries in the |
| 733 | directory. |
| 734 | The list is in arbitrary order. |
| 735 | It includes the special entries |
| 736 | {\tt '.'} |
| 737 | and |
| 738 | {\tt '..'} |
| 739 | if they are present in the directory. |
| 740 | \item[{\tt mkdir(path, mode)}] |
| 741 | Creates a directory named |
| 742 | {\tt path} |
| 743 | with numeric mode |
| 744 | {\tt mode}. |
| 745 | \item[{\tt rename(src, dst)}] |
| 746 | Renames the file or directory |
| 747 | {\tt src} |
| 748 | to |
| 749 | {\tt dst}. |
| 750 | \item[{\tt rmdir(path)}] |
| 751 | Removes the directory |
| 752 | {\tt path}. |
| 753 | \item[{\tt stat(path)}] |
| 754 | Performs a |
| 755 | {\em stat} |
| 756 | system call on the given path. |
| 757 | The return value is a tuple of at least 10 integers giving the most |
| 758 | important (and portable) members of the |
| 759 | {\em stat} |
| 760 | structure, in the order |
| 761 | {\tt st\_mode}, |
| 762 | {\tt st\_ino}, |
| 763 | {\tt st\_dev}, |
| 764 | {\tt st\_nlink}, |
| 765 | {\tt st\_uid}, |
| 766 | {\tt st\_gid}, |
| 767 | {\tt st\_size}, |
| 768 | {\tt st\_atime}, |
| 769 | {\tt st\_mtime}, |
| 770 | {\tt st\_ctime}. |
| 771 | More items may be added at the end by some implementations. |
| 772 | \item[{\tt system(command)}] |
| 773 | Executes the command (a string) in a subshell. |
| 774 | This is implemented by calling the Standard C function |
| 775 | {\tt system()}, |
| 776 | and has the same limitations. |
| 777 | Changes to |
| 778 | {\tt posix.environ}, |
| 779 | {\tt sys.stdin} |
| 780 | etc. are not reflected in the environment of the executed command. |
| 781 | The return value is the exit status of the process as returned by |
| 782 | Standard C |
| 783 | {\tt system()}. |
| 784 | \item[{\tt umask(mask)}] |
| 785 | Sets the current numeric umask and returns the previous umask. |
| 786 | \item[{\tt unlink(path)}] |
| 787 | Unlinks the file |
| 788 | {\tt path}. |
| 789 | \item[{\tt utimes(path, (atime, mtime))}] |
| 790 | %.br |
| 791 | Sets the access and modified time of the file to the given values. |
| 792 | (The second argument is a tuple of two items.) |
| 793 | \end{description} |
| 794 | |
| 795 | The following functions are only available on systems that support |
| 796 | symbolic links: |
| 797 | \begin{description} |
| 798 | \item[{\tt lstat(path)}] |
| 799 | Like |
| 800 | {\tt stat()}, |
| 801 | but does not follow symbolic links. |
| 802 | \item[{\tt readlink(path)}] |
| 803 | Returns a string representing the path to which the symbolic link |
| 804 | points. |
| 805 | \item[{\tt symlink(src, dst)}] |
| 806 | Creates a symbolic link pointing to |
| 807 | {\tt src} |
| 808 | named |
| 809 | {\tt dst}. |
| 810 | \end{description} |
| 811 | |
| 812 | \subsection{Built-in Module {\tt stdwin}} |
| 813 | |
| 814 | This module defines several new object types and functions that |
| 815 | provide access to the functionality of the Standard Window System |
| 816 | Interface, STDWIN [CWI report CR-R8817]. |
| 817 | It is available on systems to which STDWIN has been ported (which is |
| 818 | most systems). |
| 819 | It is only available if the {\tt DISPLAY} environment variable is set |
| 820 | or an explicit `{\tt -display \it displayname}' argument is passed to |
| 821 | the interpreter. |
| 822 | |
| 823 | Functions have names that usually resemble their C STDWIN counterparts |
| 824 | with the initial `w' dropped. |
| 825 | Points are represented by pairs of integers; rectangles |
| 826 | by pairs of points. |
| 827 | For a complete description of STDWIN please refer to the documentation |
| 828 | of STDWIN for C programmers (aforementioned CWI report). |
| 829 | \subsubsection{Functions Defined in Module {\tt stdwin}} |
| 830 | |
| 831 | The following functions are defined in the {\tt stdwin} module: |
| 832 | \begin{description} |
| 833 | \item[{\tt open(title)}] |
| 834 | %.br |
| 835 | Opens a new window whose initial title is given by the string argument. |
| 836 | Returns a window object; window object methods are described below.% |
| 837 | \footnote{ |
| 838 | The {\Python} version of STDWIN does not support draw procedures; all |
| 839 | drawing requests are reported as draw events. |
| 840 | } |
| 841 | \item[{\tt getevent()}] |
| 842 | %.br |
| 843 | Waits for and returns the next event. |
| 844 | An event is returned as a triple: the first element is the event |
| 845 | type, a small integer; the second element is the window object to which |
| 846 | the event applies, or |
| 847 | {\tt None} |
| 848 | if it applies to no window in particular; |
| 849 | the third element is type-dependent. |
| 850 | Names for event types and command codes are defined in the standard |
| 851 | module |
| 852 | {\tt stdwinevent}. |
| 853 | \item[{\tt setdefwinpos(h, v)}] |
| 854 | %.br |
| 855 | Sets the default window position. |
| 856 | \item[{\tt setdefwinsize(width, height)}] |
| 857 | %.br |
| 858 | Sets the default window size. |
| 859 | \item[{\tt menucreate(title)}] |
| 860 | %.br |
| 861 | Creates a menu object referring to a global menu (a menu that appears in |
| 862 | all windows). |
| 863 | Methods of menu objects are described below. |
| 864 | \item[{\tt fleep()}] |
| 865 | %.br |
| 866 | Causes a beep or bell (or perhaps a `visual bell' or flash, hence the |
| 867 | name). |
| 868 | \item[{\tt message(string)}] |
| 869 | %.br |
| 870 | Displays a dialog box containing the string. |
| 871 | The user must click OK before the function returns. |
| 872 | \item[{\tt askync(prompt, default)}] |
| 873 | %.br |
| 874 | Displays a dialog that prompts the user to answer a question with yes or |
| 875 | no. |
| 876 | The function returns 0 for no, 1 for yes. |
| 877 | If the user hits the Return key, the default (which must be 0 or 1) is |
| 878 | returned. |
| 879 | If the user cancels the dialog, the |
| 880 | {\tt KeyboardInterrupt} |
| 881 | exception is raised. |
| 882 | \item[{\tt askstr(prompt, default)}] |
| 883 | %.br |
| 884 | Displays a dialog that prompts the user for a string. |
| 885 | If the user hits the Return key, the default string is returned. |
| 886 | If the user cancels the dialog, the |
| 887 | {\tt KeyboardInterrupt} |
| 888 | exception is raised. |
| 889 | \item[{\tt askfile(prompt, default, new)}] |
| 890 | %.br |
| 891 | Asks the user to specify a filename. |
| 892 | If |
| 893 | {\tt new} |
| 894 | is zero it must be an existing file; otherwise, it must be a new file. |
| 895 | If the user cancels the dialog, the |
| 896 | {\tt KeyboardInterrupt} |
| 897 | exception is raised. |
| 898 | \item[{\tt setcutbuffer(i, string)}] |
| 899 | %.br |
| 900 | Stores the string in the system's cut buffer number |
| 901 | {\tt i}, |
| 902 | where it can be found (for pasting) by other applications. |
| 903 | On X11, there are 8 cut buffers (numbered 0..7). |
| 904 | Cut buffer number 0 is the `clipboard' on the Macintosh. |
| 905 | \item[{\tt getcutbuffer(i)}] |
| 906 | %.br |
| 907 | Returns the contents of the system's cut buffer number |
| 908 | {\tt i}. |
| 909 | \item[{\tt rotatebutbuffers(n)}] |
| 910 | %.br |
| 911 | On X11, this rotates the 8 cut buffers by |
| 912 | {\tt n}. |
| 913 | Ignored on the Macintosh. |
| 914 | \item[{\tt getselection(i)}] |
| 915 | %.br |
| 916 | Returns X11 selection number |
| 917 | {\tt i.} |
| 918 | Selections are not cut buffers. |
| 919 | Selection numbers are defined in module |
| 920 | {\tt stdwinevents}. |
| 921 | Selection {\tt WS\_PRIMARY} is the |
| 922 | {\em primary} |
| 923 | selection (used by |
| 924 | xterm, |
| 925 | for instance); |
| 926 | selection {\tt WS\_SECONDARY} is the |
| 927 | {\em secondary} |
| 928 | selection; selection {\tt WS\_CLIPBOARD} is the |
| 929 | {\em clipboard} |
| 930 | selection (used by |
| 931 | xclipboard). |
| 932 | On the Macintosh, this always returns an empty string. |
| 933 | \item[{\tt resetselection(i)}] |
| 934 | %.br |
| 935 | Resets selection number |
| 936 | {\tt i}, |
| 937 | if this process owns it. |
| 938 | (See window method |
| 939 | {\tt setselection()}). |
| 940 | \item[{\tt baseline()}] |
| 941 | %.br |
| 942 | Return the baseline of the current font (defined by STDWIN as the |
| 943 | vertical distance between the baseline and the top of the |
| 944 | characters).% |
| 945 | \footnote{ |
| 946 | There is no way yet to set the current font. |
| 947 | This will change in a future version. |
| 948 | } |
| 949 | \item[{\tt lineheight()}] |
| 950 | %.br |
| 951 | Return the total line height of the current font. |
| 952 | \item[{\tt textbreak(str, width)}] |
| 953 | %.br |
| 954 | Return the number of characters of the string that fit into a space of |
| 955 | {\tt width} |
| 956 | bits wide when drawn in the curent font. |
| 957 | \item[{\tt textwidth(str)}] |
| 958 | %.br |
| 959 | Return the width in bits of the string when drawn in the current font. |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 960 | \end{description} |
| 961 | |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 962 | \subsubsection{Window Object Methods} |
| 963 | |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 964 | Window objects are created by |
| 965 | {\tt stdwin.open()}. |
| 966 | There is no explicit function to close a window; windows are closed when |
| 967 | they are garbage-collected. |
| 968 | Window objects have the following methods: |
| 969 | \begin{description} |
| 970 | \item[{\tt begindrawing()}] |
| 971 | Returns a drawing object, whose methods (described below) allow drawing |
| 972 | in the window. |
| 973 | \item[{\tt change(rect)}] |
| 974 | Invalidates the given rectangle; this may cause a draw event. |
| 975 | \item[{\tt gettitle()}] |
| 976 | Returns the window's title string. |
| 977 | \item[{\tt getdocsize()}] |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 978 | \begin{sloppypar} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 979 | Returns a pair of integers giving the size of the document as set by |
| 980 | {\tt setdocsize()}. |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 981 | \end{sloppypar} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 982 | \item[{\tt getorigin()}] |
| 983 | Returns a pair of integers giving the origin of the window with respect |
| 984 | to the document. |
| 985 | \item[{\tt getwinsize()}] |
| 986 | Returns a pair of integers giving the size of the window. |
| 987 | \item[{\tt menucreate(title)}] |
| 988 | Creates a menu object referring to a local menu (a menu that appears |
| 989 | only in this window). |
| 990 | Methods menu objects are described below. |
| 991 | \item[{\tt scroll(rect,~point)}] |
| 992 | Scrolls the given rectangle by the vector given by the point. |
| 993 | \item[{\tt setwincursor(name)}] |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 994 | \begin{sloppypar} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 995 | Sets the window cursor to a cursor of the given name. |
| 996 | It raises the |
| 997 | {\tt Runtime\-Error} |
| 998 | exception if no cursor of the given name exists. |
| 999 | Suitable names are |
| 1000 | {\tt 'ibeam'}, |
| 1001 | {\tt 'arrow'}, |
| 1002 | {\tt 'cross'}, |
| 1003 | {\tt 'watch'} |
| 1004 | and |
| 1005 | {\tt 'plus'}. |
| 1006 | On X11, there are many more (see |
| 1007 | {\tt <X11/cursorfont.h>}). |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1008 | \end{sloppypar} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1009 | \item[{\tt setdocsize(point)}] |
| 1010 | Sets the size of the drawing document. |
| 1011 | \item[{\tt setorigin(point)}] |
| 1012 | Moves the origin of the window to the given point in the document. |
| 1013 | \item[{\tt setselection(i, str)}] |
| 1014 | Attempts to set X11 selection number |
| 1015 | {\tt i} |
| 1016 | to the string |
| 1017 | {\tt str}. |
| 1018 | (See stdwin method |
| 1019 | {\tt getselection()} |
| 1020 | for the meaning of |
| 1021 | {\tt i}.) |
| 1022 | Returns true if it succeeds. |
| 1023 | If it succeeds, the window ``owns'' the selection until |
| 1024 | (a) another applications takes ownership of the selection; or |
| 1025 | (b) the window is deleted; or |
| 1026 | (c) the application clears ownership by calling |
| 1027 | {\tt stdwin.resetselection(i)}. |
| 1028 | When another application takes ownership of the selection, a |
| 1029 | {\tt WE\_LOST\_SEL} |
| 1030 | event is received for no particular window and with the selection number |
| 1031 | as detail. |
| 1032 | Ignored on the Macintosh. |
| 1033 | \item[{\tt settitle(title)}] |
| 1034 | Sets the window's title string. |
| 1035 | \item[{\tt settimer(dsecs)}] |
| 1036 | Schedules a timer event for the window in |
| 1037 | {\tt dsecs/10} |
| 1038 | seconds. |
| 1039 | \item[{\tt show(rect)}] |
| 1040 | Tries to ensure that the given rectangle of the document is visible in |
| 1041 | the window. |
| 1042 | \item[{\tt textcreate(rect)}] |
| 1043 | Creates a text-edit object in the document at the given rectangle. |
| 1044 | Methods of text-edit objects are described below. |
| 1045 | \end{description} |
| 1046 | |
| 1047 | \subsubsection{Drawing Object Methods} |
| 1048 | |
| 1049 | Drawing objects are created exclusively by the window method |
| 1050 | {\tt begindrawing()}. |
| 1051 | Only one drawing object can exist at any given time; the drawing object |
| 1052 | must be deleted to finish drawing. |
| 1053 | No drawing object may exist when |
| 1054 | {\tt stdwin.getevent()} |
| 1055 | is called. |
| 1056 | Drawing objects have the following methods: |
| 1057 | \begin{description} |
| 1058 | \item[{\tt box(rect)}] |
| 1059 | Draws a box around a rectangle. |
| 1060 | \item[{\tt circle(center, radius)}] |
| 1061 | %.br |
| 1062 | Draws a circle with given center point and radius. |
| 1063 | \item[{\tt elarc(center, (rh, rv), (a1, a2))}] |
| 1064 | %.br |
| 1065 | Draws an elliptical arc with given center point. |
| 1066 | {\tt (rh, rv)} |
| 1067 | gives the half sizes of the horizontal and vertical radii. |
| 1068 | {\tt (a1, a2)} |
| 1069 | gives the angles (in degrees) of the begin and end points. |
| 1070 | 0 degrees is at 3 o'clock, 90 degrees is at 12 o'clock. |
| 1071 | \item[{\tt erase(rect)}] |
| 1072 | Erases a rectangle. |
| 1073 | \item[{\tt invert(rect)}] |
| 1074 | Inverts a rectangle. |
| 1075 | \item[{\tt line(p1, p2)}] |
| 1076 | Draws a line from point |
| 1077 | {\tt p1} |
| 1078 | to |
| 1079 | {\tt p2}. |
| 1080 | \item[{\tt paint(rect)}] |
| 1081 | Fills a rectangle. |
| 1082 | \item[{\tt text(p, str)}] |
| 1083 | Draws a string starting at point p (the point specifies the |
| 1084 | top left coordinate of the string). |
| 1085 | \item[{\tt shade(rect, percent)}] |
| 1086 | %.br |
| 1087 | Fills a rectangle with a shading pattern that is about |
| 1088 | {\tt percent} |
| 1089 | percent filled. |
| 1090 | \item[{\tt xorline(p1, p2)}] |
| 1091 | Draws a line in XOR mode. |
| 1092 | \item[{\tt baseline(), lineheight(), textbreak(), textwidth()}] |
| 1093 | %.br |
| 1094 | These functions are similar to the corresponding functions described |
| 1095 | above for the |
| 1096 | {\tt stdwin} |
| 1097 | module, but use the current font of the window instead of the (global) |
| 1098 | default font. |
| 1099 | \end{description} |
| 1100 | |
| 1101 | \subsubsection{Menu Object Methods} |
| 1102 | |
| 1103 | A menu object represents a menu. |
| 1104 | The menu is destroyed when the menu object is deleted. |
| 1105 | The following methods are defined: |
| 1106 | \begin{description} |
| 1107 | \item[{\tt additem(text, shortcut)}] |
| 1108 | %.br |
| 1109 | Adds a menu item with given text. |
| 1110 | The shortcut must be a string of length 1, or omitted (to specify no |
| 1111 | shortcut). |
| 1112 | \item[{\tt setitem(i, text)}] |
| 1113 | Sets the text of item number |
| 1114 | {\tt i}. |
| 1115 | \item[{\tt enable(i, flag)}] |
| 1116 | Enables or disables item |
| 1117 | {\tt i}. |
| 1118 | \item[{\tt check(i, flag)}] |
| 1119 | Sets or clears the |
| 1120 | {\em check mark} |
| 1121 | for item |
| 1122 | {\tt i}. |
| 1123 | \end{description} |
| 1124 | |
| 1125 | \subsubsection{Text-edit Object Methods} |
| 1126 | |
| 1127 | A text-edit object represents a text-edit block. |
| 1128 | For semantics, see the STDWIN documentation for C programmers. |
| 1129 | The following methods exist: |
| 1130 | \begin{description} |
| 1131 | \item[{\tt arrow(code)}] |
| 1132 | Passes an arrow event to the text-edit block. |
| 1133 | The |
| 1134 | {\tt code} |
| 1135 | must be one of |
| 1136 | {\tt WC\_LEFT}, |
| 1137 | {\tt WC\_RIGHT}, |
| 1138 | {\tt WC\_UP} |
| 1139 | or |
| 1140 | {\tt WC\_DOWN} |
| 1141 | (see module |
| 1142 | {\tt stdwinevents}). |
| 1143 | \item[{\tt draw(rect)}] |
| 1144 | Passes a draw event to the text-edit block. |
| 1145 | The rectangle specifies the redraw area. |
| 1146 | \item[{\tt event(type, window, detail)}] |
| 1147 | %.br |
| 1148 | Passes an event gotten from |
| 1149 | {\tt stdwin.getevent()} |
| 1150 | to the text-edit block. |
| 1151 | Returns true if the event was handled. |
| 1152 | \item[{\tt getfocus()}] |
| 1153 | Returns 2 integers representing the start and end positions of the |
| 1154 | focus, usable as slice indices on the string returned by |
| 1155 | {\tt getfocustext()}. |
| 1156 | \item[{\tt getfocustext()}] |
| 1157 | Returns the text in the focus. |
| 1158 | \item[{\tt getrect()}] |
| 1159 | Returns a rectangle giving the actual position of the text-edit block. |
| 1160 | (The bottom coordinate may differ from the initial position because |
| 1161 | the block automatically shrinks or grows to fit.) |
| 1162 | \item[{\tt gettext()}] |
| 1163 | Returns the entire text buffer. |
| 1164 | \item[{\tt move(rect)}] |
| 1165 | Specifies a new position for the text-edit block in the document. |
| 1166 | \item[{\tt replace(str)}] |
| 1167 | Replaces the focus by the given string. |
| 1168 | The new focus is an insert point at the end of the string. |
| 1169 | \item[{\tt setfocus(i,~j)}] |
| 1170 | Specifies the new focus. |
| 1171 | Out-of-bounds values are silently clipped. |
| 1172 | \end{description} |
| 1173 | |
| 1174 | \subsection{Built-in Module {\tt amoeba}} |
| 1175 | |
| 1176 | This module provides some object types and operations useful for |
| 1177 | Amoeba applications. |
| 1178 | It is only available on systems that support Amoeba operations. |
| 1179 | RPC errors and other Amoeba errors are reported as the exception |
| 1180 | {\tt amoeba.error = 'amoeba.error'}. |
| 1181 | The module |
| 1182 | {\tt amoeba} |
| 1183 | defines the following items: |
| 1184 | \begin{description} |
| 1185 | \item[{\tt name\_append(path,~cap)}] |
| 1186 | %.br |
| 1187 | Stores a capability in the Amoeba directory tree. |
| 1188 | Arguments are the pathname (a string) and the capability (a capability |
| 1189 | object as returned by |
| 1190 | {\tt name\_lookup()}). |
| 1191 | \item[{\tt name\_delete(path)}] |
| 1192 | %.br |
| 1193 | Deletes a capability from the Amoeba directory tree. |
| 1194 | Argument is the pathname. |
| 1195 | \item[{\tt name\_lookup(path)}] |
| 1196 | %.br |
| 1197 | Looks up a capability. |
| 1198 | Argument is the pathname. |
| 1199 | Returns a |
| 1200 | {\em capability} |
| 1201 | object, to which various interesting operations apply, described below. |
| 1202 | \item[{\tt name\_replace(path,~cap)}] |
| 1203 | %.br |
| 1204 | Replaces a capability in the Amoeba directory tree. |
| 1205 | Arguments are the pathname and the new capability. |
| 1206 | (This differs from |
| 1207 | {\tt name\_append()} |
| 1208 | in the behavior when the pathname already exists: |
| 1209 | {\tt name\_append()} |
| 1210 | finds this an error while |
| 1211 | {\tt name\_replace()} |
| 1212 | allows it, as its name suggests.) |
| 1213 | \item[{\tt capv}] |
| 1214 | A table representing the capability environment at the time the |
| 1215 | interpreter was started. |
| 1216 | (Alas, modifying this table does not affect the capability environment |
| 1217 | of the interpreter.) |
| 1218 | For example, |
| 1219 | {\tt amoeba.capv['ROOT']} |
| 1220 | is the capability of your root directory, similar to |
| 1221 | {\tt getcap("ROOT")} |
| 1222 | in C. |
| 1223 | \item[{\tt error = 'amoeba.error'}] |
| 1224 | %.br |
| 1225 | The exception raised when an Amoeba function returns an error. |
| 1226 | The value accompanying this exception is a pair containing the numeric |
| 1227 | error code and the corresponding string, as returned by the C function |
| 1228 | {\tt err\_why()}. |
| 1229 | \item[{\tt timeout(msecs)}] |
| 1230 | %.br |
| 1231 | Sets the transaction timeout, in milliseconds. |
| 1232 | Returns the previous timeout. |
| 1233 | Initially, the timeout is set to 2 seconds by the {\Python} interpreter. |
| 1234 | \end{description} |
| 1235 | |
| 1236 | \subsubsection{Capability Operations} |
| 1237 | |
| 1238 | Capabilities are written in a convenient ASCII format, also used by the |
| 1239 | Amoeba utilities |
| 1240 | {\em c2a}(U) |
| 1241 | and |
| 1242 | {\em a2c}(U). |
| 1243 | For example: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1244 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1245 | >>> amoeba.name_lookup('/profile/cap') |
| 1246 | aa:1c:95:52:6a:fa/14(ff)/8e:ba:5b:8:11:1a |
| 1247 | >>> |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1248 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1249 | The following methods are defined for capability objects. |
| 1250 | \begin{description} |
| 1251 | \item[{\tt dir\_list()}] |
| 1252 | Returns a list of the names of the entries in an Amoeba directory. |
| 1253 | \item[{\tt b\_read(offset, maxsize)}] |
| 1254 | %.br |
| 1255 | Reads (at most) |
| 1256 | {\tt maxsize} |
| 1257 | bytes from a bullet file at offset |
| 1258 | {\tt offset.} |
| 1259 | The data is returned as a string. |
| 1260 | EOF is reported as an empty string. |
| 1261 | \item[{\tt b\_size()}] |
| 1262 | Returns the size of a bullet file. |
| 1263 | \item[{\tt dir\_append(), dir\_delete(), dir\_lookup(), dir\_replace()}] |
| 1264 | %.br |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1265 | \itembreak |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1266 | Like the corresponding |
| 1267 | {\tt name\_*} |
| 1268 | functions, but with a path relative to the capability. |
| 1269 | (For paths beginning with a slash the capability is ignored, since this |
| 1270 | is the defined semantics for Amoeba.) |
| 1271 | \item[{\tt std\_info()}] |
| 1272 | Returns the standard info string of the object. |
| 1273 | \item[{\tt tod\_gettime()}] |
| 1274 | Returns the time (in seconds since the Epoch, in UCT, as for POSIX) from |
| 1275 | a time server. |
| 1276 | \item[{\tt tod\_settime(t)}] |
| 1277 | Sets the time kept by a time server. |
| 1278 | \end{description} |
| 1279 | |
| 1280 | \subsection{Built-in Module {\tt audio}} |
| 1281 | |
| 1282 | This module provides rudimentary access to the audio I/O device |
| 1283 | {\tt /dev/audio} |
| 1284 | on the Silicon Graphics Personal IRIS; see audio(7). |
| 1285 | It supports the following operations: |
| 1286 | \begin{description} |
| 1287 | \item[{\tt setoutgain(n)}] |
| 1288 | Sets the output gain (0-255). |
| 1289 | \item[{\tt getoutgain()}] |
| 1290 | Returns the output gain. |
| 1291 | \item[{\tt setrate(n)}] |
| 1292 | Sets the sampling rate: 1=32K/sec, 2=16K/sec, 3=8K/sec. |
| 1293 | \item[{\tt setduration(n)}] |
| 1294 | Sets the `sound duration' in units of 1/100 seconds. |
| 1295 | \item[{\tt read(n)}] |
| 1296 | Reads a chunk of |
| 1297 | {\tt n} |
| 1298 | sampled bytes from the audio input (line in or microphone). |
| 1299 | The chunk is returned as a string of length n. |
| 1300 | Each byte encodes one sample as a signed 8-bit quantity using linear |
| 1301 | encoding. |
| 1302 | This string can be converted to numbers using {\tt chr2num()} described |
| 1303 | below. |
| 1304 | \item[{\tt write(buf)}] |
| 1305 | Writes a chunk of samples to the audio output (speaker). |
| 1306 | \end{description} |
| 1307 | |
| 1308 | These operations support asynchronous audio I/O: |
| 1309 | \begin{description} |
| 1310 | \item[{\tt start\_recording(n)}] |
| 1311 | %.br |
| 1312 | Starts a second thread (a process with shared memory) that begins reading |
| 1313 | {\tt n} |
| 1314 | bytes from the audio device. |
| 1315 | The main thread immediately continues. |
| 1316 | \item[{\tt wait\_recording()}] |
| 1317 | %.br |
| 1318 | Waits for the second thread to finish and returns the data read. |
| 1319 | \item[{\tt stop\_recording()}] |
| 1320 | %.br |
| 1321 | Makes the second thread stop reading as soon as possible. |
| 1322 | Returns the data read so far. |
| 1323 | \item[{\tt poll\_recording()}] |
| 1324 | %.br |
| 1325 | Returns true if the second thread has finished reading (so |
| 1326 | {\tt wait\_recording()} would return the data without delay). |
| 1327 | \item[{\tt start\_playing(chunk)}, {\tt wait\_playing()}, |
| 1328 | {\tt stop\_playing()}, {\tt poll\_playing()}] |
| 1329 | %.br |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1330 | \begin{sloppypar} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1331 | Similar but for output. |
| 1332 | {\tt stop\_playing()} |
| 1333 | returns a lower bound for the number of bytes actually played (not very |
| 1334 | accurate). |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1335 | \end{sloppypar} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1336 | \end{description} |
| 1337 | |
| 1338 | The following operations do not affect the audio device but are |
| 1339 | implemented in C for efficiency: |
| 1340 | \begin{description} |
| 1341 | \item[{\tt amplify(buf, f1, f2)}] |
| 1342 | %.br |
| 1343 | Amplifies a chunk of samples by a variable factor changing from |
| 1344 | {\tt f1}/256 to {\tt f2}/256. |
| 1345 | Negative factors are allowed. |
| 1346 | Resulting values that are to large to fit in a byte are clipped. |
| 1347 | \item[{\tt reverse(buf)}] |
| 1348 | %.br |
| 1349 | Returns a chunk of samples backwards. |
| 1350 | \item[{\tt add(buf1, buf2)}] |
| 1351 | %.br |
| 1352 | Bytewise adds two chunks of samples. |
| 1353 | Bytes that exceed the range are clipped. |
| 1354 | If one buffer shorter, it is assumed to be padded with zeros. |
| 1355 | \item[{\tt chr2num(buf)}] |
| 1356 | %.br |
| 1357 | Converts a string of sampled bytes as returned by {\tt read()} into |
| 1358 | a list containing the numeric values of the samples. |
| 1359 | \item[{\tt num2chr(list)}] |
| 1360 | %.br |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1361 | \begin{sloppypar} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1362 | Converts a list as returned by |
| 1363 | {\tt chr2num()} |
| 1364 | back to a buffer acceptable by |
| 1365 | {\tt write()}. |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1366 | \end{sloppypar} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1367 | \end{description} |
| 1368 | |
| 1369 | \subsection{Built-in Module {\tt gl}} |
| 1370 | |
| 1371 | This module provides access to the Silicon Graphics |
| 1372 | {\em Graphics Library}. |
| 1373 | It is available only on Silicon Graphics machines. |
| 1374 | |
| 1375 | {\bf Warning:} |
| 1376 | Some illegal calls to the GL library cause the {\Python} interpreter to dump |
| 1377 | core. |
| 1378 | In particular, the use of most GL calls is unsafe before the first |
| 1379 | window is opened. |
| 1380 | |
| 1381 | The module is too large to document here in its entirety, but the |
| 1382 | following should help you to get started. |
| 1383 | The parameter conventions for the C functions are translated to {\Python} as |
| 1384 | follows: |
| 1385 | |
| 1386 | \begin{itemize} |
| 1387 | \item |
| 1388 | All (short, long, unsigned) int values are represented by {\Python} |
| 1389 | integers. |
| 1390 | \item |
| 1391 | All float and double values are represented by {\Python} floating point |
| 1392 | numbers. |
| 1393 | In most cases, {\Python} integers are also allowed. |
| 1394 | \item |
| 1395 | All arrays are represented by one-dimensional {\Python} lists. |
| 1396 | In most cases, tuples are also allowed. |
| 1397 | \item |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1398 | \begin{sloppypar} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1399 | All string and character arguments are represented by {\Python} strings, |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1400 | for instance, |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1401 | {\tt winopen('Hi~There!')} |
| 1402 | and |
| 1403 | {\tt rotate(900,~'z')}. |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1404 | \end{sloppypar} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1405 | \item |
| 1406 | All (short, long, unsigned) integer arguments or return values that are |
| 1407 | only used to specify the length of an array argument are omitted. |
| 1408 | For example, the C call |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1409 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1410 | lmdef(deftype, index, np, props) |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1411 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1412 | is translated to {\Python} as |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1413 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1414 | lmdef(deftype, index, props) |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1415 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1416 | \item |
| 1417 | Output arguments are omitted from the argument list; they are |
| 1418 | transmitted as function return values instead. |
| 1419 | If more than one value must be returned, the return value is a tuple. |
| 1420 | If the C function has both a regular return value (that is not omitted |
| 1421 | because of the previous rule) and an output argument, the return value |
| 1422 | comes first in the tuple. |
| 1423 | Examples: the C call |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1424 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1425 | getmcolor(i, &red, &green, &blue) |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1426 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1427 | is translated to {\Python} as |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1428 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1429 | red, green, blue = getmcolor(i) |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1430 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1431 | \end{itemize} |
| 1432 | |
| 1433 | The following functions are non-standard or have special argument |
| 1434 | conventions: |
| 1435 | \begin{description} |
| 1436 | \item[{\tt varray()}] |
| 1437 | Equivalent to but faster than a number of |
| 1438 | {\tt v3d()} |
| 1439 | calls. |
| 1440 | The argument is a list (or tuple) of points. |
| 1441 | Each point must be a tuple of coordinates (x, y, z) or (x, y). |
| 1442 | The points may be 2- or 3-dimensional but must all have the |
| 1443 | same dimension. |
| 1444 | Float and int values may be mixed however. |
| 1445 | The points are always converted to 3D double precision points |
| 1446 | by assuming z=0.0 if necessary (as indicated in the man page), |
| 1447 | and for each point |
| 1448 | {\tt v3d()} |
| 1449 | is called. |
| 1450 | \item[{\tt nvarray()}] |
| 1451 | Equivalent to but faster than a number of |
| 1452 | {\tt n3f} |
| 1453 | and |
| 1454 | {\tt v3f} |
| 1455 | calls. |
| 1456 | The argument is an array (list or tuple) of pairs of normals and points. |
| 1457 | Each pair is a tuple of a point and a normal for that point. |
| 1458 | Each point or normal must be a tuple of coordinates (x, y, z). |
| 1459 | Three coordinates must be given. |
| 1460 | Float and int values may be mixed. |
| 1461 | For each pair, |
| 1462 | {\tt n3f()} |
| 1463 | is called for the normal, and then |
| 1464 | {\tt v3f()} |
| 1465 | is called for the point. |
| 1466 | \item[{\tt vnarray()}] |
| 1467 | Similar to |
| 1468 | {\tt nvarray()} |
| 1469 | but the pairs have the point first and the normal second. |
| 1470 | \item[{\tt nurbssurface(s\_k[], t\_k[], ctl[][], s\_ord, t\_ord, type)}] |
| 1471 | %.br |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1472 | \itembreak |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1473 | Defines a nurbs surface. |
| 1474 | The dimensions of |
| 1475 | {\tt ctl[][]} |
| 1476 | are computed as follows: |
| 1477 | {\tt [len(s\_k)~-~s\_ord]}, |
| 1478 | {\tt [len(t\_k)~-~t\_ord]}. |
| 1479 | \item[{\tt nurbscurve(knots, ctlpoints, order, type)}] |
| 1480 | %.br |
| 1481 | Defines a nurbs curve. |
| 1482 | The length of ctlpoints is |
| 1483 | {\tt len(knots)~-~order}. |
| 1484 | \item[{\tt pwlcurve(points, type)}] |
| 1485 | %.br |
| 1486 | Defines a piecewise-linear curve. |
| 1487 | {\tt points} |
| 1488 | is a list of points. |
| 1489 | {\tt type} |
| 1490 | must be |
| 1491 | {\tt N\_ST}. |
| 1492 | \item[{\tt pick(n), select(n)}] |
| 1493 | %.br |
| 1494 | The only argument to these functions specifies the desired size of the |
| 1495 | pick or select buffer. |
| 1496 | \item[{\tt endpick(), endselect()}] |
| 1497 | %.br |
| 1498 | These functions have no arguments. |
| 1499 | They return a list of integers representing the used part of the |
| 1500 | pick/select buffer. |
| 1501 | No method is provided to detect buffer overrun. |
| 1502 | \end{description} |
| 1503 | |
| 1504 | Here is a tiny but complete example GL program in {\Python}: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1505 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1506 | import gl, GL, time |
| 1507 | |
| 1508 | def main(): |
| 1509 | gl.foreground() |
| 1510 | gl.prefposition(500, 900, 500, 900) |
| 1511 | w = gl.winopen('CrissCross') |
| 1512 | gl.ortho2(0.0, 400.0, 0.0, 400.0) |
| 1513 | gl.color(GL.WHITE) |
| 1514 | gl.clear() |
| 1515 | gl.color(GL.RED) |
| 1516 | gl.bgnline() |
| 1517 | gl.v2f(0.0, 0.0) |
| 1518 | gl.v2f(400.0, 400.0) |
| 1519 | gl.endline() |
| 1520 | gl.bgnline() |
| 1521 | gl.v2f(400.0, 0.0) |
| 1522 | gl.v2f(0.0, 400.0) |
| 1523 | gl.endline() |
| 1524 | time.sleep(5) |
| 1525 | |
| 1526 | main() |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1527 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1528 | |
| 1529 | \subsection{Built-in Module {\tt pnl}} |
| 1530 | |
| 1531 | This module provides access to the |
| 1532 | {\em Panel Library} |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1533 | built by NASA Ames (to get it, send e-mail to |
| 1534 | {\tt panel-request@nas.nasa.gov}). |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1535 | All access to it should be done through the standard module |
| 1536 | {\tt panel}, |
| 1537 | which transparantly exports most functions from |
| 1538 | {\tt pnl} |
| 1539 | but redefines |
| 1540 | {\tt pnl.dopanel()}. |
| 1541 | |
| 1542 | {\bf Warning:} |
| 1543 | the {\Python} interpreter will dump core if you don't create a GL window |
| 1544 | before calling |
| 1545 | {\tt pnl.mkpanel()}. |
| 1546 | |
| 1547 | The module is too large to document here in its entirety. |
| 1548 | |
| 1549 | \section{Standard Modules} |
| 1550 | |
| 1551 | The following standard modules are defined. |
| 1552 | They are available in one of the directories in the default module |
| 1553 | search path (try printing |
| 1554 | {\tt sys.path} |
| 1555 | to find out the default search path.) |
| 1556 | |
| 1557 | \subsection{Standard Module {\tt string}} |
| 1558 | |
| 1559 | This module defines some constants useful for checking character |
| 1560 | classes, some exceptions, and some useful string functions. |
| 1561 | The constants are: |
| 1562 | \begin{description} |
| 1563 | \item[{\tt digits}] |
| 1564 | The string |
| 1565 | {\tt '0123456789'}. |
| 1566 | \item[{\tt hexdigits}] |
| 1567 | The string |
| 1568 | {\tt '0123456789abcdefABCDEF'}. |
| 1569 | \item[{\tt letters}] |
| 1570 | The concatenation of the strings |
| 1571 | {\tt lowercase} |
| 1572 | and |
| 1573 | {\tt uppercase} |
| 1574 | described below. |
| 1575 | \item[{\tt lowercase}] |
| 1576 | The string |
| 1577 | {\tt 'abcdefghijklmnopqrstuvwxyz'}. |
| 1578 | \item[{\tt octdigits}] |
| 1579 | The string |
| 1580 | {\tt '01234567'}. |
| 1581 | \item[{\tt uppercase}] |
| 1582 | The string |
| 1583 | {\tt 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}. |
| 1584 | \item[{\tt whitespace}] |
| 1585 | A string containing all characters that are considered whitespace, |
| 1586 | i.e., |
| 1587 | space, tab and newline. |
| 1588 | This definition is used by |
| 1589 | {\tt split()} |
| 1590 | and |
| 1591 | {\tt strip()}. |
| 1592 | \end{description} |
| 1593 | |
| 1594 | The exceptions are: |
| 1595 | \begin{description} |
| 1596 | \item[{\tt atoi\_error = 'non-numeric argument to string.atoi'}] |
| 1597 | %.br |
| 1598 | Exception raised by |
| 1599 | {\tt atoi} |
| 1600 | when a non-numeric string argument is detected. |
| 1601 | The exception argument is the offending string. |
| 1602 | \item[{\tt index\_error = 'substring not found in string.index'}] |
| 1603 | %.br |
| 1604 | Exception raised by |
| 1605 | {\tt index} |
| 1606 | when |
| 1607 | {\tt sub} |
| 1608 | is not found. |
| 1609 | The argument are the offending arguments to index: {\tt (s, sub)}. |
| 1610 | \end{description} |
| 1611 | |
| 1612 | The functions are: |
| 1613 | \begin{description} |
| 1614 | \item[{\tt atoi(s)}] |
| 1615 | Converts a string to a number. |
| 1616 | The string must consist of one or more digits, optionally preceded by a |
| 1617 | sign ({\tt '+'} or {\tt '-'}). |
| 1618 | \item[{\tt index(s, sub)}] |
| 1619 | Returns the lowest index in |
| 1620 | {\tt s} |
| 1621 | where the substring |
| 1622 | {\tt sub} |
| 1623 | is found. |
| 1624 | \item[{\tt lower(s)}] |
| 1625 | Convert letters to lower case. |
| 1626 | \item[{\tt split(s)}] |
| 1627 | Returns a list of the whitespace-delimited words of the string |
| 1628 | {\tt s}. |
| 1629 | \item[{\tt splitfields(s, sep)}] |
| 1630 | %.br |
| 1631 | Returns a list containing the fields of the string |
| 1632 | {\tt s}, |
| 1633 | using the string |
| 1634 | {\tt sep} |
| 1635 | as a separator. |
| 1636 | The list will have one more items than the number of non-overlapping |
| 1637 | occurrences of the separator in the string. |
| 1638 | Thus, |
| 1639 | {\tt string.splitfields(s, ' ')} |
| 1640 | is not the same as |
| 1641 | {\tt string.split(s)}, |
| 1642 | as the latter only returns non-empty words. |
| 1643 | \item[{\tt strip(s)}] |
| 1644 | Removes leading and trailing whitespace from the string |
| 1645 | {\tt s}. |
| 1646 | \item[{\tt swapcase(s)}] |
| 1647 | Converts lower case letters to upper case and vice versa. |
| 1648 | \item[{\tt upper(s)}] |
| 1649 | Convert letters to upper case. |
| 1650 | \item[{\tt ljust(s, width), rjust(s, width), center(s, width)}] |
| 1651 | %.br |
| 1652 | These functions respectively left-justify, right-justify and center a |
| 1653 | string in a field of given width. |
| 1654 | They return a string that is at least |
| 1655 | {\tt width} |
| 1656 | characters wide, created by padding the string |
| 1657 | {\tt s} |
| 1658 | with spaces until the given width on the right, left or both sides. |
| 1659 | The string is never truncated. |
| 1660 | \end{description} |
| 1661 | |
| 1662 | \subsection{Standard Module {\tt path}} |
| 1663 | |
| 1664 | This module implements some useful functions on POSIX pathnames. |
| 1665 | \begin{description} |
| 1666 | \item[{\tt basename(p)}] |
| 1667 | Returns the base name of pathname |
| 1668 | {\tt p}. |
| 1669 | This is the second half of the pair returned by |
| 1670 | {\tt path.split(p)}. |
| 1671 | \item[{\tt cat(p, q)}] |
| 1672 | Performs intelligent pathname concatenation on paths |
| 1673 | {\tt p} |
| 1674 | and |
| 1675 | {\tt q}: |
| 1676 | If |
| 1677 | {\tt q} |
| 1678 | is an absolute path, the return value is |
| 1679 | {\tt q}. |
| 1680 | Otherwise, the concatenation of |
| 1681 | {\tt p} |
| 1682 | and |
| 1683 | {\tt q} |
| 1684 | is returned, with a slash ({\tt '/'}) inserted unless |
| 1685 | {\tt p} |
| 1686 | is empty or ends in a slash. |
| 1687 | \item[{\tt commonprefix(list)}] |
| 1688 | %.br |
| 1689 | Returns the longest string that is a prefix of all strings in |
| 1690 | {\tt list}. |
| 1691 | If |
| 1692 | {\tt list} |
| 1693 | is empty, the empty string ({\tt ''}) is returned. |
| 1694 | \item[{\tt exists(p)}] |
| 1695 | Returns true if |
| 1696 | {\tt p} |
| 1697 | refers to an existing path. |
| 1698 | \item[{\tt isdir(p)}] |
| 1699 | Returns true if |
| 1700 | {\tt p} |
| 1701 | refers to an existing directory. |
| 1702 | \item[{\tt islink(p)}] |
| 1703 | Returns true if |
| 1704 | {\tt p} |
| 1705 | refers to a directory entry that is a symbolic link. |
| 1706 | Always false if symbolic links are not supported. |
| 1707 | \item[{\tt ismount(p)}] |
| 1708 | Returns true if |
| 1709 | {\tt p} |
| 1710 | is an absolute path that occurs in the mount table as output by the |
| 1711 | {\tt /etc/mount} |
| 1712 | utility. |
| 1713 | This output is read once when the function is used for the first |
| 1714 | time.% |
| 1715 | \footnote{ |
| 1716 | Is there a better way to check for mount points? |
| 1717 | } |
| 1718 | \item[{\tt split(p)}] |
| 1719 | Returns a pair |
| 1720 | {\tt (head,~tail)} |
| 1721 | such that |
| 1722 | {\tt tail} |
| 1723 | contains no slashes and |
| 1724 | {\tt path.cat(head, tail)} |
| 1725 | is equal to |
| 1726 | {\tt p}. |
| 1727 | \item[{\tt walk(p, visit, arg)}] |
| 1728 | %.br |
| 1729 | Calls the function |
| 1730 | {\tt visit} |
| 1731 | with arguments |
| 1732 | {\tt (arg, dirname, names)} |
| 1733 | for each directory in the directory tree rooted at |
| 1734 | {\tt p} |
| 1735 | (including |
| 1736 | {\tt p} |
| 1737 | itself, if it is a directory). |
| 1738 | The argument |
| 1739 | {\tt dirname} |
| 1740 | specifies the visited directory, the argument |
| 1741 | {\tt names} |
| 1742 | lists the files in the directory (gotten from |
| 1743 | {\tt posix.listdir(dirname)}). |
| 1744 | The |
| 1745 | {\tt visit} |
| 1746 | function may modify |
| 1747 | {\tt names} |
| 1748 | to influence the set of directories visited below |
| 1749 | {\tt dirname}, |
| 1750 | e.g., |
| 1751 | to avoid visiting certain parts of the tree. |
| 1752 | (The object referred to by |
| 1753 | {\tt names} |
| 1754 | must be modified in place, using |
| 1755 | {\tt del} |
| 1756 | or slice assignment.) |
| 1757 | \end{description} |
| 1758 | |
| 1759 | \subsection{Standard Module {\tt getopt}} |
| 1760 | |
| 1761 | This module helps scripts to parse the command line arguments in |
| 1762 | {\tt sys.argv}. |
| 1763 | It uses the same conventions as the {\UNIX} |
| 1764 | {\tt getopt()} |
| 1765 | function. |
| 1766 | It defines the function |
| 1767 | {\tt getopt.getopt(args, options)} |
| 1768 | and the exception |
| 1769 | {\tt getopt.error}. |
| 1770 | |
| 1771 | The first argument to |
| 1772 | {\tt getopt()} |
| 1773 | is the argument list passed to the script with its first element |
| 1774 | chopped off (i.e., |
| 1775 | {\tt sys.argv[1:]}). |
| 1776 | The second argument is the string of option letters that the |
| 1777 | script wants to recognize, with options that require an argument |
| 1778 | followed by a colon (i.e., the same format that {\UNIX} |
| 1779 | {\tt getopt()} |
| 1780 | uses). |
| 1781 | The return value consists of two elements: the first is a list of |
| 1782 | option-and-value pairs; the second is the list of program arguments |
| 1783 | left after the option list was stripped (this is a trailing slice of the |
| 1784 | first argument). |
| 1785 | Each option-and-value pair returned has the option as its first element, |
| 1786 | prefixed with a hyphen (e.g., |
| 1787 | {\tt '-x'}), |
| 1788 | and the option argument as its second element, or an empty string if the |
| 1789 | option has no argument. |
| 1790 | The options occur in the list in the same order in which they were |
| 1791 | found, thus allowing multiple occurrences. |
| 1792 | Example: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1793 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1794 | >>> import getopt, string |
| 1795 | >>> args = string.split('-a -b -cfoo -d bar a1 a2') |
| 1796 | >>> args |
| 1797 | ['-a', '-b', '-cfoo', '-d', 'bar', 'a1', 'a2'] |
| 1798 | >>> optlist, args = getopt.getopt(args, 'abc:d:') |
| 1799 | >>> optlist |
| 1800 | [('-a', ''), ('-b', ''), ('-c', 'foo'), ('-d', 'bar')] |
| 1801 | >>> args |
| 1802 | ['a1', 'a2'] |
| 1803 | >>> |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1804 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1805 | The exception |
| 1806 | {\tt getopt.error = 'getopt error'} |
| 1807 | is raised when an unrecognized option is found in the argument list or |
| 1808 | when an option requiring an argument is given none. |
| 1809 | The argument to the exception is a string indicating the cause of the |
| 1810 | error. |
| 1811 | |
| 1812 | \subsection{Standard Module {\tt rand}} |
| 1813 | |
| 1814 | This module implements a pseudo-random number generator similar to |
| 1815 | {\tt rand()} |
| 1816 | in C. |
| 1817 | It defines the following functions: |
| 1818 | \begin{description} |
| 1819 | \item[{\tt rand()}] |
| 1820 | Returns an integer random number in the range [0 ... 32768). |
| 1821 | \item[{\tt choice(s)}] |
| 1822 | Returns a random element from the sequence (string, tuple or list) |
| 1823 | {\tt s.} |
| 1824 | \item[{\tt srand(seed)}] |
| 1825 | Initializes the random number generator with the given integral seed. |
| 1826 | When the module is first imported, the random number is initialized with |
| 1827 | the current time. |
| 1828 | \end{description} |
| 1829 | |
| 1830 | \subsection{Standard Module {\tt whrandom}} |
| 1831 | |
| 1832 | This module implements a Wichmann-Hill pseudo-random number generator. |
| 1833 | It defines the following functions: |
| 1834 | \begin{description} |
| 1835 | \item[{\tt random()}] |
| 1836 | Returns the next random floating point number in the range [0.0 ... 1.0). |
| 1837 | \item[{\tt seed(x, y, z)}] |
| 1838 | Initializes the random number generator from the integers |
| 1839 | {\tt x}, |
| 1840 | {\tt y} |
| 1841 | and |
| 1842 | {\tt z}. |
| 1843 | When the module is first imported, the random number is initialized |
| 1844 | using values derived from the current time. |
| 1845 | \end{description} |
| 1846 | |
| 1847 | \subsection{Standard Module {\tt stdwinevents}} |
| 1848 | |
| 1849 | This module defines constants used by STDWIN for event types |
| 1850 | ({\tt WE\_ACTIVATE} etc.), command codes ({\tt WC\_LEFT} etc.) |
| 1851 | and selection types ({\tt WS\_PRIMARY} etc.). |
| 1852 | Read the file for details. |
| 1853 | Suggested usage is |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1854 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1855 | >>> from stdwinevents import * |
| 1856 | >>> |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1857 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1858 | |
| 1859 | \subsection{Standard Module {\tt rect}} |
| 1860 | |
| 1861 | This module contains useful operations on rectangles. |
| 1862 | A rectangle is defined as in module |
| 1863 | {\tt stdwin}: |
| 1864 | a pair of points, where a point is a pair of integers. |
| 1865 | For example, the rectangle |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1866 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1867 | (10, 20), (90, 80) |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1868 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1869 | is a rectangle whose left, top, right and bottom edges are 10, 20, 90 |
| 1870 | and 80, respectively. |
| 1871 | Note that the positive vertical axis points down (as in |
| 1872 | {\tt stdwin}). |
| 1873 | |
| 1874 | The module defines the following objects: |
| 1875 | \begin{description} |
| 1876 | \item[{\tt error = 'rect.error'}] |
| 1877 | %.br |
| 1878 | The exception raised by functions in this module when they detect an |
| 1879 | error. |
| 1880 | The exception argument is a string describing the problem in more |
| 1881 | detail. |
| 1882 | \item[{\tt empty}] |
| 1883 | %.br |
| 1884 | The rectangle returned when some operations return an empty result. |
| 1885 | This makes it possible to quickly check whether a result is empty: |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1886 | \bcode\begin{verbatim} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1887 | >>> import rect |
| 1888 | >>> r1 = (10, 20), (90, 80) |
| 1889 | >>> r2 = (0, 0), (10, 20) |
| 1890 | >>> r3 = rect.intersect(r1, r2) |
| 1891 | >>> if r3 is rect.empty: print 'Empty intersection' |
| 1892 | Empty intersection |
| 1893 | >>> |
Guido van Rossum | d38b764 | 1991-01-25 13:26:13 +0000 | [diff] [blame] | 1894 | \end{verbatim}\ecode |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 1895 | \item[{\tt is\_empty(r)}] |
| 1896 | %.br |
| 1897 | Returns true if the given rectangle is empty. |
| 1898 | A rectangle |
| 1899 | {\em (left,~top), (right,~bottom)} |
| 1900 | is empty if |
| 1901 | {\em left~$\geq$~right} |
| 1902 | or |
| 1903 | {\em top~$\leq$~bottom}. |
| 1904 | \item[{\tt intersect(list)}] |
| 1905 | %.br |
| 1906 | Returns the intersection of all rectangles in the list argument. |
| 1907 | It may also be called with a tuple argument or with two or more |
| 1908 | rectangles as arguments. |
| 1909 | Raises |
| 1910 | {\tt rect.error} |
| 1911 | if the list is empty. |
| 1912 | Returns |
| 1913 | {\tt rect.empty} |
| 1914 | if the intersection of the rectangles is empty. |
| 1915 | \item[{\tt union(list)}] |
| 1916 | %.br |
| 1917 | Returns the smallest rectangle that contains all non-empty rectangles in |
| 1918 | the list argument. |
| 1919 | It may also be called with a tuple argument or with two or more |
| 1920 | rectangles as arguments. |
| 1921 | Returns |
| 1922 | {\tt rect.empty} |
| 1923 | if the list is empty or all its rectangles are empty. |
| 1924 | \item[{\tt pointinrect(point, rect)}] |
| 1925 | %.br |
| 1926 | Returns true if the point is inside the rectangle. |
| 1927 | By definition, a point |
| 1928 | {\em (h,~v)} |
| 1929 | is inside a rectangle |
| 1930 | {\em (left,~top),} |
| 1931 | {\em (right,~bottom)} |
| 1932 | if |
| 1933 | {\em left~$\leq$~h~$<$~right} |
| 1934 | and |
| 1935 | {\em top~$\leq$~v~$<$~bottom}. |
| 1936 | \item[{\tt inset(rect, (dh, dv))}] |
| 1937 | %.br |
| 1938 | Returns a rectangle that lies inside the |
| 1939 | {\tt rect} |
| 1940 | argument by |
| 1941 | {\tt dh} |
| 1942 | pixels horizontally |
| 1943 | and |
| 1944 | {\tt dv} |
| 1945 | pixels |
| 1946 | vertically. |
| 1947 | If |
| 1948 | {\tt dh} |
| 1949 | or |
| 1950 | {\tt dv} |
| 1951 | is negative, the result lies outside |
| 1952 | {\tt rect}. |
| 1953 | \item[{\tt rect2geom(rect)}] |
| 1954 | %.br |
| 1955 | Converts a rectangle to geometry representation: |
| 1956 | {\em (left,~top),} |
| 1957 | {\em (width,~height)}. |
| 1958 | \item[{\tt geom2rect(geom)}] |
| 1959 | %.br |
| 1960 | Converts a rectangle given in geometry representation back to the |
| 1961 | standard rectangle representation |
| 1962 | {\em (left,~top),} |
| 1963 | {\em (right,~bottom)}. |
| 1964 | \end{description} |
| 1965 | |
| 1966 | \subsection{Standard Modules {\tt GL} and {\tt DEVICE}} |
| 1967 | |
| 1968 | These modules define the constants used by the Silicon Graphics |
| 1969 | {\em Graphics Library} |
| 1970 | that C programmers find in the header files |
| 1971 | {\tt <gl/gl.h>} |
| 1972 | and |
| 1973 | {\tt <gl/device.h>}. |
| 1974 | Read the module files for details. |
| 1975 | |
| 1976 | \subsection{Standard Module {\tt panel}} |
| 1977 | |
| 1978 | This module should be used instead of the built-in module |
| 1979 | {\tt pnl} |
| 1980 | to interface with the |
| 1981 | {\em Panel Library}. |
| 1982 | |
| 1983 | The module is too large to document here in its entirety. |
| 1984 | One interesting function: |
| 1985 | \begin{description} |
| 1986 | \item[{\tt defpanellist(filename)}] |
| 1987 | %.br |
| 1988 | Parses a panel description file containing S-expressions written by the |
| 1989 | {\em Panel Editor} |
| 1990 | that accompanies the Panel Library and creates the described panels. |
| 1991 | It returns a list of panel objects. |
| 1992 | \end{description} |
| 1993 | |
| 1994 | {\bf Warning:} |
| 1995 | the {\Python} interpreter will dump core if you don't create a GL window |
| 1996 | before calling |
| 1997 | {\tt panel.mkpanel()} |
| 1998 | or |
| 1999 | {\tt panel.defpanellist()}. |
| 2000 | |
Guido van Rossum | 0ed6918 | 1991-01-24 16:54:15 +0000 | [diff] [blame] | 2001 | \subsection{Standard Module {\tt panelparser}} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 2002 | |
| 2003 | This module defines a self-contained parser for S-expressions as output |
| 2004 | by the Panel Editor (which is written in Scheme so it can't help writing |
| 2005 | S-expressions). |
| 2006 | The relevant function is |
Guido van Rossum | 0ed6918 | 1991-01-24 16:54:15 +0000 | [diff] [blame] | 2007 | {\tt panelparser.parse\_file(file)} |
Guido van Rossum | 515834a | 1991-01-22 11:45:29 +0000 | [diff] [blame] | 2008 | which has a file object (not a filename!) as argument and returns a list |
| 2009 | of parsed S-expressions. |
| 2010 | Each S-expression is converted into a {\Python} list, with atoms converted |
| 2011 | to {\Python} strings and sub-expressions (recursively) to {\Python} lists. |
| 2012 | For more details, read the module file. |
| 2013 | |
| 2014 | \subsection{P.M.} |
| 2015 | |
| 2016 | \begin{verse} |
| 2017 | commands |
| 2018 | |
| 2019 | cmp? |
| 2020 | |
| 2021 | *cache? |
| 2022 | |
| 2023 | localtime? |
| 2024 | |
| 2025 | calendar? |
| 2026 | |
| 2027 | \_\_dict? |
| 2028 | \end{verse} |
| 2029 | |
| 2030 | \end{document} |