Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 524b588 | 1995-01-04 19:10:35 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 32 | /* Stdwin module */ |
| 33 | |
| 34 | /* Stdwin itself is a module, not a separate object type. |
| 35 | Object types defined here: |
| 36 | wp: a window |
| 37 | dp: a drawing structure (only one can exist at a time) |
| 38 | mp: a menu |
| 39 | tp: a textedit block |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 40 | bp: a bitmap |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 41 | */ |
| 42 | |
| 43 | /* Rules for translating C stdwin function calls into Python stwin: |
| 44 | - All names drop their initial letter 'w' |
| 45 | - Functions with a window as first parameter are methods of window objects |
| 46 | - There is no equivalent for wclose(); just delete the window object |
| 47 | (all references to it!) (XXX maybe this is a bad idea) |
| 48 | - w.begindrawing() returns a drawing object |
| 49 | - There is no equivalent for wenddrawing(win); just delete the drawing |
| 50 | object (all references to it!) (XXX maybe this is a bad idea) |
| 51 | - Functions that may only be used inside wbegindrawing / wendddrawing |
| 52 | are methods of the drawing object; this includes the text measurement |
| 53 | functions (which however have doubles as module functions). |
| 54 | - Methods of the drawing object drop an initial 'draw' from their name |
| 55 | if they have it, e.g., wdrawline() --> d.line() |
| 56 | - The obvious type conversions: int --> intobject; string --> stringobject |
| 57 | - A text parameter followed by a length parameter is only a text (string) |
| 58 | parameter in Python |
| 59 | - A point or other pair of horizontal and vertical coordinates is always |
| 60 | a pair of integers in Python |
| 61 | - Two points forming a rectangle or endpoints of a line segment are a |
| 62 | pair of points in Python |
| 63 | - The arguments to d.elarc() are three points. |
| 64 | - The functions wgetclip() and wsetclip() are translated into |
| 65 | stdwin.getcutbuffer() and stdwin.setcutbuffer(); 'clip' is really |
| 66 | a bad word for what these functions do (clipping has a different |
| 67 | meaning in the drawing world), while cutbuffer is standard X jargon. |
Guido van Rossum | 01769f0 | 1990-10-30 13:39:00 +0000 | [diff] [blame] | 68 | XXX This must change again in the light of changes to stdwin! |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 69 | - For textedit, similar rules hold, but they are less strict. |
| 70 | XXX more? |
| 71 | */ |
| 72 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 73 | #include "Python.h" |
| 74 | |
Jack Jansen | dc977a9 | 1995-08-14 12:17:18 +0000 | [diff] [blame] | 75 | #ifdef macintosh |
| 76 | #include "macglue.h" |
| 77 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 78 | |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 79 | #ifdef macintosh |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 80 | #include ":::stdwin:H:stdwin.h" |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 81 | #else /* !macintosh */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 82 | #include "stdwin.h" |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 83 | #define HAVE_BITMAPS |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 84 | #endif /* !macintosh */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 85 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 86 | #ifdef WITH_THREAD |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 87 | |
| 88 | #include "thread.h" |
| 89 | |
| 90 | static type_lock StdwinLock; /* Lock held when interpreter not locked */ |
| 91 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 92 | #define BGN_STDWIN Py_BEGIN_ALLOW_THREADS acquire_lock(StdwinLock, 1); |
| 93 | #define RET_STDWIN release_lock(StdwinLock); Py_BLOCK_THREADS |
| 94 | #define END_STDWIN release_lock(StdwinLock); Py_END_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 95 | |
| 96 | #else |
| 97 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 98 | #define BGN_STDWIN Py_BEGIN_ALLOW_THREADS |
| 99 | #define RET_STDWIN Py_BLOCK_THREADS |
| 100 | #define END_STDWIN Py_END_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 101 | |
| 102 | #endif |
| 103 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 104 | #define getpointarg(v, a) PyArg_Parse(v, "(ii)", a, (a)+1) |
| 105 | #define get3pointarg(v, a) PyArg_Parse(v, "((ii)(ii)(ii))", \ |
| 106 | a, a+1, a+2, a+3, a+4, a+5) |
| 107 | #define getrectarg(v, a) PyArg_Parse(v, "((ii)(ii))", a, a+1, a+2, a+3) |
| 108 | #define getrectintarg(v, a) PyArg_Parse(v, "(((ii)(ii))i)", \ |
| 109 | a, a+1, a+2, a+3, a+4) |
| 110 | #define getpointintarg(v, a) PyArg_Parse(v, "((ii)i)", a, a+1, a+2) |
| 111 | #define getrectpointarg(v, a) PyArg_Parse(v, "(((ii)(ii))(ii))", \ |
| 112 | a, a+1, a+2, a+3, a+4, a+5) |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 113 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 114 | static PyObject *StdwinError; /* Exception stdwin.error */ |
Guido van Rossum | 87e7ea7 | 1991-12-10 14:00:03 +0000 | [diff] [blame] | 115 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 116 | /* Window and menu object types declared here because of forward references */ |
| 117 | |
| 118 | typedef struct { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 119 | PyObject_HEAD |
| 120 | PyObject *w_title; |
| 121 | WINDOW *w_win; |
| 122 | PyObject *w_attr; /* Attributes dictionary */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 123 | } windowobject; |
| 124 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 125 | staticforward PyTypeObject Windowtype; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 126 | |
| 127 | #define is_windowobject(wp) ((wp)->ob_type == &Windowtype) |
| 128 | |
| 129 | typedef struct { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 130 | PyObject_HEAD |
| 131 | MENU *m_menu; |
| 132 | int m_id; |
| 133 | PyObject *m_attr; /* Attributes dictionary */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 134 | } menuobject; |
| 135 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 136 | staticforward PyTypeObject Menutype; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 137 | |
| 138 | #define is_menuobject(mp) ((mp)->ob_type == &Menutype) |
| 139 | |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 140 | typedef struct { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 141 | PyObject_HEAD |
| 142 | BITMAP *b_bitmap; |
| 143 | PyObject *b_attr; /* Attributes dictionary */ |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 144 | } bitmapobject; |
| 145 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 146 | staticforward PyTypeObject Bitmaptype; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 147 | |
| 148 | #define is_bitmapobject(mp) ((mp)->ob_type == &Bitmaptype) |
| 149 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 150 | |
| 151 | /* Strongly stdwin-specific argument handlers */ |
| 152 | |
| 153 | static int |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 154 | getmenudetail(v, ep) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 155 | PyObject *v; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 156 | EVENT *ep; |
| 157 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 158 | menuobject *mp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 159 | if (!PyArg_Parse(v, "(Oi)", &mp, &ep->u.m.item)) |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 160 | return 0; |
| 161 | if (!is_menuobject(mp)) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 162 | return PyErr_BadArgument(); |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 163 | ep->u.m.id = mp->m_id; |
| 164 | return 1; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static int |
| 168 | geteventarg(v, ep) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 169 | PyObject *v; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 170 | EVENT *ep; |
| 171 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 172 | PyObject *wp, *detail; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 173 | int a[4]; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 174 | if (!PyArg_Parse(v, "(iOO)", &ep->type, &wp, &detail)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 175 | return 0; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 176 | if (is_windowobject(wp)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 177 | ep->window = ((windowobject *)wp) -> w_win; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 178 | else if (wp == Py_None) |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 179 | ep->window = NULL; |
| 180 | else |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 181 | return PyErr_BadArgument(); |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 182 | switch (ep->type) { |
| 183 | case WE_CHAR: { |
| 184 | char c; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 185 | if (!PyArg_Parse(detail, "c", &c)) |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 186 | return 0; |
| 187 | ep->u.character = c; |
| 188 | return 1; |
| 189 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 190 | case WE_COMMAND: |
| 191 | return getintarg(detail, &ep->u.command); |
| 192 | case WE_DRAW: |
| 193 | if (!getrectarg(detail, a)) |
| 194 | return 0; |
| 195 | ep->u.area.left = a[0]; |
| 196 | ep->u.area.top = a[1]; |
| 197 | ep->u.area.right = a[2]; |
| 198 | ep->u.area.bottom = a[3]; |
| 199 | return 1; |
| 200 | case WE_MOUSE_DOWN: |
| 201 | case WE_MOUSE_UP: |
| 202 | case WE_MOUSE_MOVE: |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 203 | return PyArg_Parse(detail, "((ii)iii)", |
| 204 | &ep->u.where.h, &ep->u.where.v, |
| 205 | &ep->u.where.clicks, |
| 206 | &ep->u.where.button, |
| 207 | &ep->u.where.mask); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 208 | case WE_MENU: |
| 209 | return getmenudetail(detail, ep); |
Guido van Rossum | 3ee199e | 1992-06-30 12:48:26 +0000 | [diff] [blame] | 210 | case WE_KEY: |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 211 | return PyArg_Parse(detail, "(ii)", |
| 212 | &ep->u.key.code, &ep->u.key.mask); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 213 | default: |
| 214 | return 1; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | |
| 219 | /* Return construction tools */ |
| 220 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 221 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 222 | makepoint(a, b) |
| 223 | int a, b; |
| 224 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 225 | return Py_BuildValue("(ii)", a, b); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 228 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 229 | makerect(a, b, c, d) |
| 230 | int a, b, c, d; |
| 231 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 232 | return Py_BuildValue("((ii)(ii))", a, b, c, d); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | |
| 236 | /* Drawing objects */ |
| 237 | |
| 238 | typedef struct { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 239 | PyObject_HEAD |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 240 | windowobject *d_ref; |
| 241 | } drawingobject; |
| 242 | |
| 243 | static drawingobject *Drawing; /* Set to current drawing object, or NULL */ |
| 244 | |
| 245 | /* Drawing methods */ |
| 246 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 247 | static PyObject * |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 248 | drawing_close(dp) |
| 249 | drawingobject *dp; |
| 250 | { |
| 251 | if (dp->d_ref != NULL) { |
| 252 | wenddrawing(dp->d_ref->w_win); |
| 253 | Drawing = NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 254 | Py_DECREF(dp->d_ref); |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 255 | dp->d_ref = NULL; |
| 256 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 257 | Py_INCREF(Py_None); |
| 258 | return Py_None; |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 259 | } |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 260 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 261 | static void |
| 262 | drawing_dealloc(dp) |
| 263 | drawingobject *dp; |
| 264 | { |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 265 | if (dp->d_ref != NULL) { |
| 266 | wenddrawing(dp->d_ref->w_win); |
| 267 | Drawing = NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 268 | Py_DECREF(dp->d_ref); |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 269 | dp->d_ref = NULL; |
| 270 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 271 | free((char *)dp); |
| 272 | } |
| 273 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 274 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 275 | drawing_generic(dp, args, func) |
| 276 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 277 | PyObject *args; |
| 278 | void (*func) Py_FPROTO((int, int, int, int)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 279 | { |
| 280 | int a[4]; |
| 281 | if (!getrectarg(args, a)) |
| 282 | return NULL; |
| 283 | (*func)(a[0], a[1], a[2], a[3]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 284 | Py_INCREF(Py_None); |
| 285 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 288 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 289 | drawing_line(dp, args) |
| 290 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 291 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 292 | { |
Guido van Rossum | bf10973 | 1991-03-06 13:14:12 +0000 | [diff] [blame] | 293 | return drawing_generic(dp, args, wdrawline); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 296 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 297 | drawing_xorline(dp, args) |
| 298 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 299 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 300 | { |
Guido van Rossum | bf10973 | 1991-03-06 13:14:12 +0000 | [diff] [blame] | 301 | return drawing_generic(dp, args, wxorline); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 304 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 305 | drawing_circle(dp, args) |
| 306 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 307 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 308 | { |
| 309 | int a[3]; |
| 310 | if (!getpointintarg(args, a)) |
| 311 | return NULL; |
| 312 | wdrawcircle(a[0], a[1], a[2]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 313 | Py_INCREF(Py_None); |
| 314 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 315 | } |
Guido van Rossum | a2a181a | 1991-05-14 12:09:25 +0000 | [diff] [blame] | 316 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 317 | static PyObject * |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 318 | drawing_fillcircle(dp, args) |
| 319 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 320 | PyObject *args; |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 321 | { |
| 322 | int a[3]; |
| 323 | if (!getpointintarg(args, a)) |
| 324 | return NULL; |
| 325 | wfillcircle(a[0], a[1], a[2]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 326 | Py_INCREF(Py_None); |
| 327 | return Py_None; |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 328 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 329 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 330 | static PyObject * |
Guido van Rossum | a2a181a | 1991-05-14 12:09:25 +0000 | [diff] [blame] | 331 | drawing_xorcircle(dp, args) |
| 332 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 333 | PyObject *args; |
Guido van Rossum | a2a181a | 1991-05-14 12:09:25 +0000 | [diff] [blame] | 334 | { |
| 335 | int a[3]; |
| 336 | if (!getpointintarg(args, a)) |
| 337 | return NULL; |
| 338 | wxorcircle(a[0], a[1], a[2]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 339 | Py_INCREF(Py_None); |
| 340 | return Py_None; |
Guido van Rossum | a2a181a | 1991-05-14 12:09:25 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 343 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 344 | drawing_elarc(dp, args) |
| 345 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 346 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 347 | { |
| 348 | int a[6]; |
| 349 | if (!get3pointarg(args, a)) |
| 350 | return NULL; |
| 351 | wdrawelarc(a[0], a[1], a[2], a[3], a[4], a[5]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 352 | Py_INCREF(Py_None); |
| 353 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 356 | static PyObject * |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 357 | drawing_fillelarc(dp, args) |
| 358 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 359 | PyObject *args; |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 360 | { |
| 361 | int a[6]; |
| 362 | if (!get3pointarg(args, a)) |
| 363 | return NULL; |
| 364 | wfillelarc(a[0], a[1], a[2], a[3], a[4], a[5]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 365 | Py_INCREF(Py_None); |
| 366 | return Py_None; |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 369 | static PyObject * |
Guido van Rossum | a2a181a | 1991-05-14 12:09:25 +0000 | [diff] [blame] | 370 | drawing_xorelarc(dp, args) |
| 371 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 372 | PyObject *args; |
Guido van Rossum | a2a181a | 1991-05-14 12:09:25 +0000 | [diff] [blame] | 373 | { |
| 374 | int a[6]; |
| 375 | if (!get3pointarg(args, a)) |
| 376 | return NULL; |
| 377 | wxorelarc(a[0], a[1], a[2], a[3], a[4], a[5]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 378 | Py_INCREF(Py_None); |
| 379 | return Py_None; |
Guido van Rossum | a2a181a | 1991-05-14 12:09:25 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 382 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 383 | drawing_box(dp, args) |
| 384 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 385 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 386 | { |
Guido van Rossum | bf10973 | 1991-03-06 13:14:12 +0000 | [diff] [blame] | 387 | return drawing_generic(dp, args, wdrawbox); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 390 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 391 | drawing_erase(dp, args) |
| 392 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 393 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 394 | { |
Guido van Rossum | bf10973 | 1991-03-06 13:14:12 +0000 | [diff] [blame] | 395 | return drawing_generic(dp, args, werase); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 398 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 399 | drawing_paint(dp, args) |
| 400 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 401 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 402 | { |
Guido van Rossum | bf10973 | 1991-03-06 13:14:12 +0000 | [diff] [blame] | 403 | return drawing_generic(dp, args, wpaint); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 406 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 407 | drawing_invert(dp, args) |
| 408 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 409 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 410 | { |
Guido van Rossum | bf10973 | 1991-03-06 13:14:12 +0000 | [diff] [blame] | 411 | return drawing_generic(dp, args, winvert); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 414 | static POINT * |
| 415 | getpointsarray(v, psize) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 416 | PyObject *v; |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 417 | int *psize; |
| 418 | { |
| 419 | int n = -1; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 420 | PyObject * (*getitem) Py_PROTO((PyObject *, int)); |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 421 | int i; |
| 422 | POINT *points; |
| 423 | |
| 424 | if (v == NULL) |
| 425 | ; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 426 | else if (PyList_Check(v)) { |
| 427 | n = PyList_Size(v); |
| 428 | getitem = PyList_GetItem; |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 429 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 430 | else if (PyTuple_Check(v)) { |
| 431 | n = PyTuple_Size(v); |
| 432 | getitem = PyTuple_GetItem; |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | if (n <= 0) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 436 | (void) PyErr_BadArgument(); |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 437 | return NULL; |
| 438 | } |
| 439 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 440 | points = PyMem_NEW(POINT, n); |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 441 | if (points == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 442 | (void) PyErr_NoMemory(); |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 443 | return NULL; |
| 444 | } |
| 445 | |
| 446 | for (i = 0; i < n; i++) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 447 | PyObject *w = (*getitem)(v, i); |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 448 | int a[2]; |
| 449 | if (!getpointarg(w, a)) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 450 | PyMem_DEL(points); |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 451 | return NULL; |
| 452 | } |
| 453 | points[i].h = a[0]; |
| 454 | points[i].v = a[1]; |
| 455 | } |
| 456 | |
| 457 | *psize = n; |
| 458 | return points; |
| 459 | } |
| 460 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 461 | static PyObject * |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 462 | drawing_poly(dp, args) |
| 463 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 464 | PyObject *args; |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 465 | { |
| 466 | int n; |
| 467 | POINT *points = getpointsarray(args, &n); |
| 468 | if (points == NULL) |
| 469 | return NULL; |
| 470 | wdrawpoly(n, points); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 471 | PyMem_DEL(points); |
| 472 | Py_INCREF(Py_None); |
| 473 | return Py_None; |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 474 | } |
| 475 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 476 | static PyObject * |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 477 | drawing_fillpoly(dp, args) |
| 478 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 479 | PyObject *args; |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 480 | { |
| 481 | int n; |
| 482 | POINT *points = getpointsarray(args, &n); |
| 483 | if (points == NULL) |
| 484 | return NULL; |
| 485 | wfillpoly(n, points); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 486 | PyMem_DEL(points); |
| 487 | Py_INCREF(Py_None); |
| 488 | return Py_None; |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 489 | } |
| 490 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 491 | static PyObject * |
Guido van Rossum | a2a181a | 1991-05-14 12:09:25 +0000 | [diff] [blame] | 492 | drawing_xorpoly(dp, args) |
| 493 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 494 | PyObject *args; |
Guido van Rossum | a2a181a | 1991-05-14 12:09:25 +0000 | [diff] [blame] | 495 | { |
| 496 | int n; |
| 497 | POINT *points = getpointsarray(args, &n); |
| 498 | if (points == NULL) |
| 499 | return NULL; |
| 500 | wxorpoly(n, points); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 501 | PyMem_DEL(points); |
| 502 | Py_INCREF(Py_None); |
| 503 | return Py_None; |
Guido van Rossum | a2a181a | 1991-05-14 12:09:25 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 506 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 507 | drawing_cliprect(dp, args) |
| 508 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 509 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 510 | { |
Guido van Rossum | bf10973 | 1991-03-06 13:14:12 +0000 | [diff] [blame] | 511 | return drawing_generic(dp, args, wcliprect); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 514 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 515 | drawing_noclip(dp, args) |
| 516 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 517 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 518 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 519 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 520 | return NULL; |
| 521 | wnoclip(); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 522 | Py_INCREF(Py_None); |
| 523 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 524 | } |
| 525 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 526 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 527 | drawing_shade(dp, args) |
| 528 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 529 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 530 | { |
| 531 | int a[5]; |
| 532 | if (!getrectintarg(args, a)) |
| 533 | return NULL; |
| 534 | wshade(a[0], a[1], a[2], a[3], a[4]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 535 | Py_INCREF(Py_None); |
| 536 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 539 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 540 | drawing_text(dp, args) |
| 541 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 542 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 543 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 544 | int h, v, size; |
| 545 | char *text; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 546 | if (!PyArg_Parse(args, "((ii)s#)", &h, &v, &text, &size)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 547 | return NULL; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 548 | wdrawtext(h, v, text, size); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 549 | Py_INCREF(Py_None); |
| 550 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /* The following four are also used as stdwin functions */ |
| 554 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 555 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 556 | drawing_lineheight(dp, args) |
| 557 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 558 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 559 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 560 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 561 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 562 | return PyInt_FromLong((long)wlineheight()); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 565 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 566 | drawing_baseline(dp, args) |
| 567 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 568 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 569 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 570 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 571 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 572 | return PyInt_FromLong((long)wbaseline()); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 575 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 576 | drawing_textwidth(dp, args) |
| 577 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 578 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 579 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 580 | char *text; |
| 581 | int size; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 582 | if (!PyArg_Parse(args, "s#", &text, &size)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 583 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 584 | return PyInt_FromLong((long)wtextwidth(text, size)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 587 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 588 | drawing_textbreak(dp, args) |
| 589 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 590 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 591 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 592 | char *text; |
| 593 | int size, width; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 594 | if (!PyArg_Parse(args, "(s#i)", &text, &size, &width)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 595 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 596 | return PyInt_FromLong((long)wtextbreak(text, size, width)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 599 | static PyObject * |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 600 | drawing_setfont(self, args) |
| 601 | drawingobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 602 | PyObject *args; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 603 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 604 | char *font; |
| 605 | char style = '\0'; |
| 606 | int size = 0; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 607 | if (args == NULL || !PyTuple_Check(args)) { |
| 608 | if (!PyArg_Parse(args, "z", &font)) |
Guido van Rossum | 50429a1 | 1991-04-04 15:24:07 +0000 | [diff] [blame] | 609 | return NULL; |
| 610 | } |
| 611 | else { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 612 | int n = PyTuple_Size(args); |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 613 | if (n == 2) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 614 | if (!PyArg_Parse(args, "(zi)", &font, &size)) |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 615 | return NULL; |
| 616 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 617 | else if (!PyArg_Parse(args, "(zic)", &font, &size, &style)) { |
| 618 | PyErr_Clear(); |
| 619 | if (!PyArg_Parse(args, "(zci)", &font, &style, &size)) |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 620 | return NULL; |
Guido van Rossum | 50429a1 | 1991-04-04 15:24:07 +0000 | [diff] [blame] | 621 | } |
| 622 | } |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 623 | if (font != NULL) { |
| 624 | if (!wsetfont(font)) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 625 | PyErr_SetString(StdwinError, "font not found"); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 626 | return NULL; |
| 627 | } |
| 628 | } |
Guido van Rossum | 50429a1 | 1991-04-04 15:24:07 +0000 | [diff] [blame] | 629 | if (size != 0) |
| 630 | wsetsize(size); |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 631 | switch (style) { |
| 632 | case 'b': |
| 633 | wsetbold(); |
| 634 | break; |
| 635 | case 'i': |
| 636 | wsetitalic(); |
| 637 | break; |
| 638 | case 'o': |
| 639 | wsetbolditalic(); |
| 640 | break; |
| 641 | case 'u': |
| 642 | wsetunderline(); |
| 643 | break; |
| 644 | case 'p': |
| 645 | wsetplain(); |
| 646 | break; |
| 647 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 648 | Py_INCREF(Py_None); |
| 649 | return Py_None; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 652 | static PyObject * |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 653 | drawing_getbgcolor(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 654 | PyObject *self; |
| 655 | PyObject *args; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 656 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 657 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 658 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 659 | return PyInt_FromLong((long)wgetbgcolor()); |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 662 | static PyObject * |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 663 | drawing_getfgcolor(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 664 | PyObject *self; |
| 665 | PyObject *args; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 666 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 667 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 668 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 669 | return PyInt_FromLong((long)wgetfgcolor()); |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 670 | } |
| 671 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 672 | static PyObject * |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 673 | drawing_setbgcolor(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 674 | PyObject *self; |
| 675 | PyObject *args; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 676 | { |
| 677 | long color; |
| 678 | if (!getlongarg(args, &color)) |
| 679 | return NULL; |
| 680 | wsetbgcolor((COLOR)color); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 681 | Py_INCREF(Py_None); |
| 682 | return Py_None; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 683 | } |
| 684 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 685 | static PyObject * |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 686 | drawing_setfgcolor(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 687 | PyObject *self; |
| 688 | PyObject *args; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 689 | { |
| 690 | long color; |
| 691 | if (!getlongarg(args, &color)) |
| 692 | return NULL; |
| 693 | wsetfgcolor((COLOR)color); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 694 | Py_INCREF(Py_None); |
| 695 | return Py_None; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 696 | } |
| 697 | |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 698 | #ifdef HAVE_BITMAPS |
| 699 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 700 | static PyObject * |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 701 | drawing_bitmap(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 702 | PyObject *self; |
| 703 | PyObject *args; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 704 | { |
| 705 | int h, v; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 706 | PyObject *bp; |
| 707 | PyObject *mask = NULL; |
| 708 | if (!PyArg_Parse(args, "((ii)O)", &h, &v, &bp)) { |
| 709 | PyErr_Clear(); |
| 710 | if (!PyArg_Parse(args, "((ii)OO)", &h, &v, &bp, &mask)) |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 711 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 712 | if (mask == Py_None) |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 713 | mask = NULL; |
| 714 | else if (!is_bitmapobject(mask)) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 715 | PyErr_BadArgument(); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 716 | return NULL; |
| 717 | } |
| 718 | } |
| 719 | if (!is_bitmapobject(bp)) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 720 | PyErr_BadArgument(); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 721 | return NULL; |
| 722 | } |
| 723 | if (((bitmapobject *)bp)->b_bitmap == NULL || |
| 724 | mask != NULL && ((bitmapobject *)mask)->b_bitmap == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 725 | PyErr_SetString(StdwinError, "bitmap object already close"); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 726 | return NULL; |
| 727 | } |
| 728 | if (mask == NULL) |
| 729 | wdrawbitmap(h, v, ((bitmapobject *)bp)->b_bitmap, ALLBITS); |
| 730 | else |
| 731 | wdrawbitmap(h, v, |
| 732 | ((bitmapobject *)bp)->b_bitmap, |
| 733 | ((bitmapobject *)bp)->b_bitmap); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 734 | Py_INCREF(Py_None); |
| 735 | return Py_None; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 736 | } |
| 737 | |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 738 | #endif /* HAVE_BITMAPS */ |
| 739 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 740 | static PyMethodDef drawing_methods[] = { |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 741 | #ifdef HAVE_BITMAPS |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 742 | {"bitmap", (PyCFunction)drawing_bitmap}, |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 743 | #endif |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 744 | {"box", (PyCFunction)drawing_box}, |
| 745 | {"circle", (PyCFunction)drawing_circle}, |
| 746 | {"cliprect", (PyCFunction)drawing_cliprect}, |
| 747 | {"close", (PyCFunction)drawing_close}, |
| 748 | {"elarc", (PyCFunction)drawing_elarc}, |
| 749 | {"enddrawing", (PyCFunction)drawing_close}, |
| 750 | {"erase", (PyCFunction)drawing_erase}, |
| 751 | {"fillcircle", (PyCFunction)drawing_fillcircle}, |
| 752 | {"fillelarc", (PyCFunction)drawing_fillelarc}, |
| 753 | {"fillpoly", (PyCFunction)drawing_fillpoly}, |
| 754 | {"invert", (PyCFunction)drawing_invert}, |
| 755 | {"line", (PyCFunction)drawing_line}, |
| 756 | {"noclip", (PyCFunction)drawing_noclip}, |
| 757 | {"paint", (PyCFunction)drawing_paint}, |
| 758 | {"poly", (PyCFunction)drawing_poly}, |
| 759 | {"shade", (PyCFunction)drawing_shade}, |
| 760 | {"text", (PyCFunction)drawing_text}, |
| 761 | {"xorcircle", (PyCFunction)drawing_xorcircle}, |
| 762 | {"xorelarc", (PyCFunction)drawing_xorelarc}, |
| 763 | {"xorline", (PyCFunction)drawing_xorline}, |
| 764 | {"xorpoly", (PyCFunction)drawing_xorpoly}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 765 | |
| 766 | /* Text measuring methods: */ |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 767 | {"baseline", (PyCFunction)drawing_baseline}, |
| 768 | {"lineheight", (PyCFunction)drawing_lineheight}, |
| 769 | {"textbreak", (PyCFunction)drawing_textbreak}, |
| 770 | {"textwidth", (PyCFunction)drawing_textwidth}, |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 771 | |
| 772 | /* Font setting methods: */ |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 773 | {"setfont", (PyCFunction)drawing_setfont}, |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 774 | |
| 775 | /* Color methods: */ |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 776 | {"getbgcolor", (PyCFunction)drawing_getbgcolor}, |
| 777 | {"getfgcolor", (PyCFunction)drawing_getfgcolor}, |
| 778 | {"setbgcolor", (PyCFunction)drawing_setbgcolor}, |
| 779 | {"setfgcolor", (PyCFunction)drawing_setfgcolor}, |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 780 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 781 | {NULL, NULL} /* sentinel */ |
| 782 | }; |
| 783 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 784 | static PyObject * |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 785 | drawing_getattr(dp, name) |
| 786 | drawingobject *dp; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 787 | char *name; |
| 788 | { |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 789 | if (dp->d_ref == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 790 | PyErr_SetString(StdwinError, "drawing object already closed"); |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 791 | return NULL; |
| 792 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 793 | return Py_FindMethod(drawing_methods, (PyObject *)dp, name); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 794 | } |
| 795 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 796 | PyTypeObject Drawingtype = { |
| 797 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 798 | 0, /*ob_size*/ |
| 799 | "drawing", /*tp_name*/ |
| 800 | sizeof(drawingobject), /*tp_size*/ |
| 801 | 0, /*tp_itemsize*/ |
| 802 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 803 | (destructor)drawing_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 804 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 805 | (getattrfunc)drawing_getattr, /*tp_getattr*/ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 806 | 0, /*tp_setattr*/ |
| 807 | 0, /*tp_compare*/ |
| 808 | 0, /*tp_repr*/ |
| 809 | }; |
| 810 | |
| 811 | |
| 812 | /* Text(edit) objects */ |
| 813 | |
| 814 | typedef struct { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 815 | PyObject_HEAD |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 816 | TEXTEDIT *t_text; |
| 817 | windowobject *t_ref; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 818 | PyObject *t_attr; /* Attributes dictionary */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 819 | } textobject; |
| 820 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 821 | staticforward PyTypeObject Texttype; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 822 | |
| 823 | static textobject * |
| 824 | newtextobject(wp, left, top, right, bottom) |
| 825 | windowobject *wp; |
| 826 | int left, top, right, bottom; |
| 827 | { |
| 828 | textobject *tp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 829 | tp = PyObject_NEW(textobject, &Texttype); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 830 | if (tp == NULL) |
| 831 | return NULL; |
| 832 | tp->t_attr = NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 833 | Py_INCREF(wp); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 834 | tp->t_ref = wp; |
| 835 | tp->t_text = tecreate(wp->w_win, left, top, right, bottom); |
| 836 | if (tp->t_text == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 837 | Py_DECREF(tp); |
| 838 | return (textobject *) PyErr_NoMemory(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 839 | } |
| 840 | return tp; |
| 841 | } |
| 842 | |
| 843 | /* Text(edit) methods */ |
| 844 | |
| 845 | static void |
| 846 | text_dealloc(tp) |
| 847 | textobject *tp; |
| 848 | { |
| 849 | if (tp->t_text != NULL) |
| 850 | tefree(tp->t_text); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 851 | Py_XDECREF(tp->t_attr); |
| 852 | Py_XDECREF(tp->t_ref); |
| 853 | PyMem_DEL(tp); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 856 | static PyObject * |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 857 | text_close(tp, args) |
| 858 | textobject *tp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 859 | PyObject *args; |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 860 | { |
| 861 | if (tp->t_text != NULL) { |
| 862 | tefree(tp->t_text); |
| 863 | tp->t_text = NULL; |
| 864 | } |
| 865 | if (tp->t_attr != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 866 | Py_DECREF(tp->t_attr); |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 867 | tp->t_attr = NULL; |
| 868 | } |
| 869 | if (tp->t_ref != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 870 | Py_DECREF(tp->t_ref); |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 871 | tp->t_ref = NULL; |
| 872 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 873 | Py_INCREF(Py_None); |
| 874 | return Py_None; |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 877 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 878 | text_arrow(self, args) |
| 879 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 880 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 881 | { |
| 882 | int code; |
| 883 | if (!getintarg(args, &code)) |
| 884 | return NULL; |
| 885 | tearrow(self->t_text, code); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 886 | Py_INCREF(Py_None); |
| 887 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 890 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 891 | text_draw(self, args) |
| 892 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 893 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 894 | { |
| 895 | register TEXTEDIT *tp = self->t_text; |
| 896 | int a[4]; |
| 897 | int left, top, right, bottom; |
| 898 | if (!getrectarg(args, a)) |
| 899 | return NULL; |
| 900 | if (Drawing != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 901 | PyErr_SetString(StdwinError, "already drawing"); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 902 | return NULL; |
| 903 | } |
| 904 | /* Clip to text area and ignore if area is empty */ |
| 905 | left = tegetleft(tp); |
| 906 | top = tegettop(tp); |
| 907 | right = tegetright(tp); |
| 908 | bottom = tegetbottom(tp); |
| 909 | if (a[0] < left) a[0] = left; |
| 910 | if (a[1] < top) a[1] = top; |
| 911 | if (a[2] > right) a[2] = right; |
| 912 | if (a[3] > bottom) a[3] = bottom; |
| 913 | if (a[0] < a[2] && a[1] < a[3]) { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 914 | wbegindrawing(self->t_ref->w_win); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 915 | tedrawnew(tp, a[0], a[1], a[2], a[3]); |
| 916 | wenddrawing(self->t_ref->w_win); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 917 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 918 | Py_INCREF(Py_None); |
| 919 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 922 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 923 | text_event(self, args) |
| 924 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 925 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 926 | { |
| 927 | register TEXTEDIT *tp = self->t_text; |
| 928 | EVENT e; |
| 929 | if (!geteventarg(args, &e)) |
| 930 | return NULL; |
| 931 | if (e.type == WE_MOUSE_DOWN) { |
Guido van Rossum | 33f1770 | 1991-02-13 23:19:39 +0000 | [diff] [blame] | 932 | /* Cheat at the margins */ |
| 933 | int width, height; |
| 934 | wgetdocsize(e.window, &width, &height); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 935 | if (e.u.where.h < 0 && tegetleft(tp) == 0) |
| 936 | e.u.where.h = 0; |
Guido van Rossum | 33f1770 | 1991-02-13 23:19:39 +0000 | [diff] [blame] | 937 | else if (e.u.where.h > width && tegetright(tp) == width) |
| 938 | e.u.where.h = width; |
| 939 | if (e.u.where.v < 0 && tegettop(tp) == 0) |
| 940 | e.u.where.v = 0; |
| 941 | else if (e.u.where.v > height && tegetright(tp) == height) |
| 942 | e.u.where.v = height; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 943 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 944 | return PyInt_FromLong((long) teevent(tp, &e)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 945 | } |
| 946 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 947 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 948 | text_getfocus(self, args) |
| 949 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 950 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 951 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 952 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 953 | return NULL; |
| 954 | return makepoint(tegetfoc1(self->t_text), tegetfoc2(self->t_text)); |
| 955 | } |
| 956 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 957 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 958 | text_getfocustext(self, args) |
| 959 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 960 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 961 | { |
| 962 | int f1, f2; |
| 963 | char *text; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 964 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 965 | return NULL; |
| 966 | f1 = tegetfoc1(self->t_text); |
| 967 | f2 = tegetfoc2(self->t_text); |
| 968 | text = tegettext(self->t_text); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 969 | return PyString_FromStringAndSize(text + f1, f2-f1); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 972 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 973 | text_getrect(self, args) |
| 974 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 975 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 976 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 977 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 978 | return NULL; |
| 979 | return makerect(tegetleft(self->t_text), |
| 980 | tegettop(self->t_text), |
| 981 | tegetright(self->t_text), |
| 982 | tegetbottom(self->t_text)); |
| 983 | } |
| 984 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 985 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 986 | text_gettext(self, args) |
| 987 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 988 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 989 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 990 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 991 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 992 | return PyString_FromStringAndSize(tegettext(self->t_text), |
| 993 | tegetlen(self->t_text)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 996 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 997 | text_move(self, args) |
| 998 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 999 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1000 | { |
| 1001 | int a[4]; |
| 1002 | if (!getrectarg(args, a)) |
| 1003 | return NULL; |
| 1004 | temovenew(self->t_text, a[0], a[1], a[2], a[3]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1005 | Py_INCREF(Py_None); |
| 1006 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1009 | static PyObject * |
Guido van Rossum | 4b9cf8e | 1991-05-28 21:57:04 +0000 | [diff] [blame] | 1010 | text_replace(self, args) |
| 1011 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1012 | PyObject *args; |
Guido van Rossum | 4b9cf8e | 1991-05-28 21:57:04 +0000 | [diff] [blame] | 1013 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1014 | char *text; |
Guido van Rossum | 4b9cf8e | 1991-05-28 21:57:04 +0000 | [diff] [blame] | 1015 | if (!getstrarg(args, &text)) |
| 1016 | return NULL; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1017 | tereplace(self->t_text, text); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1018 | Py_INCREF(Py_None); |
| 1019 | return Py_None; |
Guido van Rossum | 4b9cf8e | 1991-05-28 21:57:04 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1022 | static PyObject * |
Guido van Rossum | 4b9cf8e | 1991-05-28 21:57:04 +0000 | [diff] [blame] | 1023 | text_setactive(self, args) |
| 1024 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1025 | PyObject *args; |
Guido van Rossum | 4b9cf8e | 1991-05-28 21:57:04 +0000 | [diff] [blame] | 1026 | { |
| 1027 | int flag; |
| 1028 | if (!getintarg(args, &flag)) |
| 1029 | return NULL; |
| 1030 | tesetactive(self->t_text, flag); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1031 | Py_INCREF(Py_None); |
| 1032 | return Py_None; |
Guido van Rossum | 4b9cf8e | 1991-05-28 21:57:04 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1035 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1036 | text_setfocus(self, args) |
| 1037 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1038 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1039 | { |
| 1040 | int a[2]; |
| 1041 | if (!getpointarg(args, a)) |
| 1042 | return NULL; |
| 1043 | tesetfocus(self->t_text, a[0], a[1]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1044 | Py_INCREF(Py_None); |
| 1045 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1048 | static PyObject * |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 1049 | text_settext(self, args) |
| 1050 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1051 | PyObject *args; |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 1052 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1053 | char *text; |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 1054 | char *buf; |
| 1055 | int size; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1056 | if (!PyArg_Parse(args, "s#", &text, &size)) |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 1057 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1058 | if ((buf = PyMem_NEW(char, size)) == NULL) { |
| 1059 | return PyErr_NoMemory(); |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 1060 | } |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1061 | memcpy(buf, text, size); |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 1062 | tesetbuf(self->t_text, buf, size); /* Becomes owner of buffer */ |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1063 | Py_INCREF(Py_None); |
| 1064 | return Py_None; |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1067 | static PyObject * |
Guido van Rossum | 4b9cf8e | 1991-05-28 21:57:04 +0000 | [diff] [blame] | 1068 | text_setview(self, args) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1069 | textobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1070 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1071 | { |
Guido van Rossum | 4b9cf8e | 1991-05-28 21:57:04 +0000 | [diff] [blame] | 1072 | int a[4]; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1073 | if (args == Py_None) |
Guido van Rossum | 4b9cf8e | 1991-05-28 21:57:04 +0000 | [diff] [blame] | 1074 | tenoview(self->t_text); |
| 1075 | else { |
| 1076 | if (!getrectarg(args, a)) |
| 1077 | return NULL; |
| 1078 | tesetview(self->t_text, a[0], a[1], a[2], a[3]); |
| 1079 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1080 | Py_INCREF(Py_None); |
| 1081 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1084 | static PyMethodDef text_methods[] = { |
| 1085 | {"arrow", (PyCFunction)text_arrow}, |
| 1086 | {"close", (PyCFunction)text_close}, |
| 1087 | {"draw", (PyCFunction)text_draw}, |
| 1088 | {"event", (PyCFunction)text_event}, |
| 1089 | {"getfocus", (PyCFunction)text_getfocus}, |
| 1090 | {"getfocustext",(PyCFunction)text_getfocustext}, |
| 1091 | {"getrect", (PyCFunction)text_getrect}, |
| 1092 | {"gettext", (PyCFunction)text_gettext}, |
| 1093 | {"move", (PyCFunction)text_move}, |
| 1094 | {"replace", (PyCFunction)text_replace}, |
| 1095 | {"setactive", (PyCFunction)text_setactive}, |
| 1096 | {"setfocus", (PyCFunction)text_setfocus}, |
| 1097 | {"settext", (PyCFunction)text_settext}, |
| 1098 | {"setview", (PyCFunction)text_setview}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1099 | {NULL, NULL} /* sentinel */ |
| 1100 | }; |
| 1101 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1102 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1103 | text_getattr(tp, name) |
| 1104 | textobject *tp; |
| 1105 | char *name; |
| 1106 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1107 | PyObject *v = NULL; |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 1108 | if (tp->t_ref == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1109 | PyErr_SetString(StdwinError, "text object already closed"); |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 1110 | return NULL; |
| 1111 | } |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1112 | if (strcmp(name, "__dict__") == 0) { |
| 1113 | v = tp->t_attr; |
| 1114 | if (v == NULL) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1115 | v = Py_None; |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1116 | } |
| 1117 | else if (tp->t_attr != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1118 | v = PyDict_GetItemString(tp->t_attr, name); |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1119 | } |
| 1120 | if (v != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1121 | Py_INCREF(v); |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1122 | return v; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1123 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1124 | return Py_FindMethod(text_methods, (PyObject *)tp, name); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | static int |
| 1128 | text_setattr(tp, name, v) |
| 1129 | textobject *tp; |
| 1130 | char *name; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1131 | PyObject *v; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1132 | { |
| 1133 | if (tp->t_attr == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1134 | tp->t_attr = PyDict_New(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1135 | if (tp->t_attr == NULL) |
| 1136 | return -1; |
| 1137 | } |
Guido van Rossum | 94472a0 | 1992-09-04 09:45:18 +0000 | [diff] [blame] | 1138 | if (v == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1139 | int rv = PyDict_DelItemString(tp->t_attr, name); |
Guido van Rossum | 94472a0 | 1992-09-04 09:45:18 +0000 | [diff] [blame] | 1140 | if (rv < 0) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1141 | PyErr_SetString(PyExc_AttributeError, |
| 1142 | "delete non-existing text object attribute"); |
Guido van Rossum | 94472a0 | 1992-09-04 09:45:18 +0000 | [diff] [blame] | 1143 | return rv; |
| 1144 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1145 | else |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1146 | return PyDict_SetItemString(tp->t_attr, name, v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1149 | statichere PyTypeObject Texttype = { |
| 1150 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1151 | 0, /*ob_size*/ |
| 1152 | "textedit", /*tp_name*/ |
| 1153 | sizeof(textobject), /*tp_size*/ |
| 1154 | 0, /*tp_itemsize*/ |
| 1155 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1156 | (destructor)text_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1157 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1158 | (getattrfunc)text_getattr, /*tp_getattr*/ |
| 1159 | (setattrfunc)text_setattr, /*tp_setattr*/ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1160 | 0, /*tp_compare*/ |
| 1161 | 0, /*tp_repr*/ |
| 1162 | }; |
| 1163 | |
| 1164 | |
| 1165 | /* Menu objects */ |
| 1166 | |
Guido van Rossum | 2d14e21 | 1991-02-19 12:26:49 +0000 | [diff] [blame] | 1167 | #define IDOFFSET 10 /* Menu IDs we use start here */ |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 1168 | #define MAXNMENU 200 /* Max #menus we allow */ |
Guido van Rossum | 2d14e21 | 1991-02-19 12:26:49 +0000 | [diff] [blame] | 1169 | static menuobject *menulist[MAXNMENU]; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1170 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1171 | static menuobject *newmenuobject Py_PROTO((char *)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1172 | static menuobject * |
| 1173 | newmenuobject(title) |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1174 | char *title; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1175 | { |
| 1176 | int id; |
| 1177 | MENU *menu; |
| 1178 | menuobject *mp; |
Guido van Rossum | 2d14e21 | 1991-02-19 12:26:49 +0000 | [diff] [blame] | 1179 | for (id = 0; id < MAXNMENU; id++) { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1180 | if (menulist[id] == NULL) |
| 1181 | break; |
| 1182 | } |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 1183 | if (id >= MAXNMENU) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1184 | PyErr_SetString(StdwinError, "creating too many menus"); |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 1185 | return NULL; |
| 1186 | } |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1187 | menu = wmenucreate(id + IDOFFSET, title); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1188 | if (menu == NULL) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1189 | return (menuobject *) PyErr_NoMemory(); |
| 1190 | mp = PyObject_NEW(menuobject, &Menutype); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1191 | if (mp != NULL) { |
| 1192 | mp->m_menu = menu; |
Guido van Rossum | 2d14e21 | 1991-02-19 12:26:49 +0000 | [diff] [blame] | 1193 | mp->m_id = id + IDOFFSET; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1194 | mp->m_attr = NULL; |
| 1195 | menulist[id] = mp; |
| 1196 | } |
| 1197 | else |
| 1198 | wmenudelete(menu); |
| 1199 | return mp; |
| 1200 | } |
| 1201 | |
| 1202 | /* Menu methods */ |
| 1203 | |
| 1204 | static void |
| 1205 | menu_dealloc(mp) |
| 1206 | menuobject *mp; |
| 1207 | { |
| 1208 | |
Guido van Rossum | 2d14e21 | 1991-02-19 12:26:49 +0000 | [diff] [blame] | 1209 | int id = mp->m_id - IDOFFSET; |
| 1210 | if (id >= 0 && id < MAXNMENU && menulist[id] == mp) { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1211 | menulist[id] = NULL; |
| 1212 | } |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 1213 | if (mp->m_menu != NULL) |
| 1214 | wmenudelete(mp->m_menu); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1215 | Py_XDECREF(mp->m_attr); |
| 1216 | PyMem_DEL(mp); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1219 | static PyObject * |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 1220 | menu_close(mp, args) |
| 1221 | menuobject *mp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1222 | PyObject *args; |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 1223 | { |
| 1224 | int id = mp->m_id - IDOFFSET; |
| 1225 | if (id >= 0 && id < MAXNMENU && menulist[id] == mp) { |
| 1226 | menulist[id] = NULL; |
| 1227 | } |
| 1228 | mp->m_id = -1; |
| 1229 | if (mp->m_menu != NULL) |
| 1230 | wmenudelete(mp->m_menu); |
| 1231 | mp->m_menu = NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1232 | Py_XDECREF(mp->m_attr); |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 1233 | mp->m_attr = NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1234 | Py_INCREF(Py_None); |
| 1235 | return Py_None; |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1238 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1239 | menu_additem(self, args) |
| 1240 | menuobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1241 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1242 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1243 | char *text; |
| 1244 | int shortcut = -1; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1245 | if (PyTuple_Check(args)) { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1246 | char c; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1247 | if (!PyArg_Parse(args, "(sc)", &text, &c)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1248 | return NULL; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1249 | shortcut = c; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1250 | } |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1251 | else if (!getstrarg(args, &text)) |
| 1252 | return NULL; |
| 1253 | wmenuadditem(self->m_menu, text, shortcut); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1254 | Py_INCREF(Py_None); |
| 1255 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1258 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1259 | menu_setitem(self, args) |
| 1260 | menuobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1261 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1262 | { |
| 1263 | int index; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1264 | char *text; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1265 | if (!PyArg_Parse(args, "(is)", &index, &text)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1266 | return NULL; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1267 | wmenusetitem(self->m_menu, index, text); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1268 | Py_INCREF(Py_None); |
| 1269 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1272 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1273 | menu_enable(self, args) |
| 1274 | menuobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1275 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1276 | { |
| 1277 | int index; |
| 1278 | int flag; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1279 | if (!PyArg_Parse(args, "(ii)", &index, &flag)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1280 | return NULL; |
| 1281 | wmenuenable(self->m_menu, index, flag); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1282 | Py_INCREF(Py_None); |
| 1283 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1286 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1287 | menu_check(self, args) |
| 1288 | menuobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1289 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1290 | { |
| 1291 | int index; |
| 1292 | int flag; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1293 | if (!PyArg_Parse(args, "(ii)", &index, &flag)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1294 | return NULL; |
| 1295 | wmenucheck(self->m_menu, index, flag); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1296 | Py_INCREF(Py_None); |
| 1297 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1300 | static PyMethodDef menu_methods[] = { |
| 1301 | {"additem", (PyCFunction)menu_additem}, |
| 1302 | {"setitem", (PyCFunction)menu_setitem}, |
| 1303 | {"enable", (PyCFunction)menu_enable}, |
| 1304 | {"check", (PyCFunction)menu_check}, |
| 1305 | {"close", (PyCFunction)menu_close}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1306 | {NULL, NULL} /* sentinel */ |
| 1307 | }; |
| 1308 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1309 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1310 | menu_getattr(mp, name) |
| 1311 | menuobject *mp; |
| 1312 | char *name; |
| 1313 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1314 | PyObject *v = NULL; |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 1315 | if (mp->m_menu == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1316 | PyErr_SetString(StdwinError, "menu object already closed"); |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 1317 | return NULL; |
| 1318 | } |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1319 | if (strcmp(name, "__dict__") == 0) { |
| 1320 | v = mp->m_attr; |
| 1321 | if (v == NULL) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1322 | v = Py_None; |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1323 | } |
| 1324 | else if (mp->m_attr != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1325 | v = PyDict_GetItemString(mp->m_attr, name); |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1326 | } |
| 1327 | if (v != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1328 | Py_INCREF(v); |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1329 | return v; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1330 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1331 | return Py_FindMethod(menu_methods, (PyObject *)mp, name); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | static int |
| 1335 | menu_setattr(mp, name, v) |
| 1336 | menuobject *mp; |
| 1337 | char *name; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1338 | PyObject *v; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1339 | { |
| 1340 | if (mp->m_attr == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1341 | mp->m_attr = PyDict_New(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1342 | if (mp->m_attr == NULL) |
| 1343 | return -1; |
| 1344 | } |
Guido van Rossum | 94472a0 | 1992-09-04 09:45:18 +0000 | [diff] [blame] | 1345 | if (v == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1346 | int rv = PyDict_DelItemString(mp->m_attr, name); |
Guido van Rossum | 94472a0 | 1992-09-04 09:45:18 +0000 | [diff] [blame] | 1347 | if (rv < 0) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1348 | PyErr_SetString(PyExc_AttributeError, |
| 1349 | "delete non-existing menu object attribute"); |
Guido van Rossum | 94472a0 | 1992-09-04 09:45:18 +0000 | [diff] [blame] | 1350 | return rv; |
| 1351 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1352 | else |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1353 | return PyDict_SetItemString(mp->m_attr, name, v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1356 | statichere PyTypeObject Menutype = { |
| 1357 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1358 | 0, /*ob_size*/ |
| 1359 | "menu", /*tp_name*/ |
| 1360 | sizeof(menuobject), /*tp_size*/ |
| 1361 | 0, /*tp_itemsize*/ |
| 1362 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1363 | (destructor)menu_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1364 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1365 | (getattrfunc)menu_getattr, /*tp_getattr*/ |
| 1366 | (setattrfunc)menu_setattr, /*tp_setattr*/ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1367 | 0, /*tp_compare*/ |
| 1368 | 0, /*tp_repr*/ |
| 1369 | }; |
| 1370 | |
| 1371 | |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 1372 | #ifdef HAVE_BITMAPS |
| 1373 | |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1374 | /* Bitmaps objects */ |
| 1375 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1376 | static bitmapobject *newbitmapobject Py_PROTO((int, int)); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1377 | static bitmapobject * |
| 1378 | newbitmapobject(width, height) |
| 1379 | int width, height; |
| 1380 | { |
| 1381 | BITMAP *bitmap; |
| 1382 | bitmapobject *bp; |
| 1383 | bitmap = wnewbitmap(width, height); |
| 1384 | if (bitmap == NULL) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1385 | return (bitmapobject *) PyErr_NoMemory(); |
| 1386 | bp = PyObject_NEW(bitmapobject, &Bitmaptype); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1387 | if (bp != NULL) { |
| 1388 | bp->b_bitmap = bitmap; |
| 1389 | bp->b_attr = NULL; |
| 1390 | } |
| 1391 | else |
| 1392 | wfreebitmap(bitmap); |
| 1393 | return bp; |
| 1394 | } |
| 1395 | |
| 1396 | /* Bitmap methods */ |
| 1397 | |
| 1398 | static void |
| 1399 | bitmap_dealloc(bp) |
| 1400 | bitmapobject *bp; |
| 1401 | { |
| 1402 | if (bp->b_bitmap != NULL) |
| 1403 | wfreebitmap(bp->b_bitmap); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1404 | Py_XDECREF(bp->b_attr); |
| 1405 | PyMem_DEL(bp); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1406 | } |
| 1407 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1408 | static PyObject * |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1409 | bitmap_close(bp, args) |
| 1410 | bitmapobject *bp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1411 | PyObject *args; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1412 | { |
| 1413 | if (bp->b_bitmap != NULL) |
| 1414 | wfreebitmap(bp->b_bitmap); |
| 1415 | bp->b_bitmap = NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1416 | Py_XDECREF(bp->b_attr); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1417 | bp->b_attr = NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1418 | Py_INCREF(Py_None); |
| 1419 | return Py_None; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1422 | static PyObject * |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1423 | bitmap_setbit(self, args) |
| 1424 | bitmapobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1425 | PyObject *args; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1426 | { |
| 1427 | int a[3]; |
| 1428 | if (!getpointintarg(args, a)) |
| 1429 | return NULL; |
| 1430 | wsetbit(self->b_bitmap, a[0], a[1], a[2]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1431 | Py_INCREF(Py_None); |
| 1432 | return Py_None; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1435 | static PyObject * |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1436 | bitmap_getbit(self, args) |
| 1437 | bitmapobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1438 | PyObject *args; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1439 | { |
| 1440 | int a[2]; |
| 1441 | if (!getpointarg(args, a)) |
| 1442 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1443 | return PyInt_FromLong((long) wgetbit(self->b_bitmap, a[0], a[1])); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1446 | static PyObject * |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1447 | bitmap_getsize(self, args) |
| 1448 | bitmapobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1449 | PyObject *args; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1450 | { |
| 1451 | int width, height; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1452 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1453 | return NULL; |
| 1454 | wgetbitmapsize(self->b_bitmap, &width, &height); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1455 | return Py_BuildValue("(ii)", width, height); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1458 | static PyMethodDef bitmap_methods[] = { |
| 1459 | {"close", (PyCFunction)bitmap_close}, |
| 1460 | {"getsize", (PyCFunction)bitmap_getsize}, |
| 1461 | {"getbit", (PyCFunction)bitmap_getbit}, |
| 1462 | {"setbit", (PyCFunction)bitmap_setbit}, |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1463 | {NULL, NULL} /* sentinel */ |
| 1464 | }; |
| 1465 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1466 | static PyObject * |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1467 | bitmap_getattr(bp, name) |
| 1468 | bitmapobject *bp; |
| 1469 | char *name; |
| 1470 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1471 | PyObject *v = NULL; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1472 | if (bp->b_bitmap == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1473 | PyErr_SetString(StdwinError, "bitmap object already closed"); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1474 | return NULL; |
| 1475 | } |
| 1476 | if (strcmp(name, "__dict__") == 0) { |
| 1477 | v = bp->b_attr; |
| 1478 | if (v == NULL) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1479 | v = Py_None; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1480 | } |
| 1481 | else if (bp->b_attr != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1482 | v = PyDict_GetItemString(bp->b_attr, name); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1483 | } |
| 1484 | if (v != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1485 | Py_INCREF(v); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1486 | return v; |
| 1487 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1488 | return Py_FindMethod(bitmap_methods, (PyObject *)bp, name); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | static int |
| 1492 | bitmap_setattr(bp, name, v) |
| 1493 | bitmapobject *bp; |
| 1494 | char *name; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1495 | PyObject *v; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1496 | { |
| 1497 | if (bp->b_attr == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1498 | bp->b_attr = PyDict_New(); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1499 | if (bp->b_attr == NULL) |
| 1500 | return -1; |
| 1501 | } |
| 1502 | if (v == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1503 | int rv = PyDict_DelItemString(bp->b_attr, name); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1504 | if (rv < 0) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1505 | PyErr_SetString(PyExc_AttributeError, |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1506 | "delete non-existing bitmap object attribute"); |
| 1507 | return rv; |
| 1508 | } |
| 1509 | else |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1510 | return PyDict_SetItemString(bp->b_attr, name, v); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1513 | statichere PyTypeObject Bitmaptype = { |
| 1514 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1515 | 0, /*ob_size*/ |
| 1516 | "bitmap", /*tp_name*/ |
| 1517 | sizeof(bitmapobject), /*tp_size*/ |
| 1518 | 0, /*tp_itemsize*/ |
| 1519 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1520 | (destructor)bitmap_dealloc, /*tp_dealloc*/ |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1521 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1522 | (getattrfunc)bitmap_getattr, /*tp_getattr*/ |
| 1523 | (setattrfunc)bitmap_setattr, /*tp_setattr*/ |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1524 | 0, /*tp_compare*/ |
| 1525 | 0, /*tp_repr*/ |
| 1526 | }; |
| 1527 | |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 1528 | #endif /* HAVE_BITMAPS */ |
| 1529 | |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1530 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1531 | /* Windows */ |
| 1532 | |
| 1533 | #define MAXNWIN 50 |
| 1534 | static windowobject *windowlist[MAXNWIN]; |
| 1535 | |
| 1536 | /* Window methods */ |
| 1537 | |
| 1538 | static void |
| 1539 | window_dealloc(wp) |
| 1540 | windowobject *wp; |
| 1541 | { |
| 1542 | if (wp->w_win != NULL) { |
| 1543 | int tag = wgettag(wp->w_win); |
| 1544 | if (tag >= 0 && tag < MAXNWIN) |
| 1545 | windowlist[tag] = NULL; |
| 1546 | else |
| 1547 | fprintf(stderr, "XXX help! tag %d in window_dealloc\n", |
| 1548 | tag); |
| 1549 | wclose(wp->w_win); |
| 1550 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1551 | Py_DECREF(wp->w_title); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1552 | if (wp->w_attr != NULL) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1553 | Py_DECREF(wp->w_attr); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1554 | free((char *)wp); |
| 1555 | } |
| 1556 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1557 | static PyObject * |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 1558 | window_close(wp, args) |
| 1559 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1560 | PyObject *args; |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 1561 | { |
| 1562 | if (wp->w_win != NULL) { |
| 1563 | int tag = wgettag(wp->w_win); |
| 1564 | if (tag >= 0 && tag < MAXNWIN) |
| 1565 | windowlist[tag] = NULL; |
| 1566 | wclose(wp->w_win); |
| 1567 | wp->w_win = NULL; |
| 1568 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1569 | Py_INCREF(Py_None); |
| 1570 | return Py_None; |
Guido van Rossum | 3c28474 | 1991-11-27 14:54:54 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1573 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1574 | window_begindrawing(wp, args) |
| 1575 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1576 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1577 | { |
| 1578 | drawingobject *dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1579 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1580 | return NULL; |
| 1581 | if (Drawing != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1582 | PyErr_SetString(StdwinError, "already drawing"); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1583 | return NULL; |
| 1584 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1585 | dp = PyObject_NEW(drawingobject, &Drawingtype); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1586 | if (dp == NULL) |
| 1587 | return NULL; |
| 1588 | Drawing = dp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1589 | Py_INCREF(wp); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1590 | dp->d_ref = wp; |
| 1591 | wbegindrawing(wp->w_win); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1592 | return (PyObject *)dp; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1595 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1596 | window_change(wp, args) |
| 1597 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1598 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1599 | { |
| 1600 | int a[4]; |
| 1601 | if (!getrectarg(args, a)) |
| 1602 | return NULL; |
| 1603 | wchange(wp->w_win, a[0], a[1], a[2], a[3]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1604 | Py_INCREF(Py_None); |
| 1605 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1608 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1609 | window_gettitle(wp, args) |
| 1610 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1611 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1612 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1613 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1614 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1615 | Py_INCREF(wp->w_title); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1616 | return wp->w_title; |
| 1617 | } |
| 1618 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1619 | static PyObject * |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 1620 | window_getwinpos(wp, args) |
| 1621 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1622 | PyObject *args; |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 1623 | { |
| 1624 | int h, v; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1625 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 1626 | return NULL; |
| 1627 | wgetwinpos(wp->w_win, &h, &v); |
| 1628 | return makepoint(h, v); |
| 1629 | } |
| 1630 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1631 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1632 | window_getwinsize(wp, args) |
| 1633 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1634 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1635 | { |
| 1636 | int width, height; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1637 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1638 | return NULL; |
| 1639 | wgetwinsize(wp->w_win, &width, &height); |
| 1640 | return makepoint(width, height); |
| 1641 | } |
| 1642 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1643 | static PyObject * |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1644 | window_setwinpos(wp, args) |
| 1645 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1646 | PyObject *args; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1647 | { |
| 1648 | int a[2]; |
| 1649 | if (!getpointarg(args, a)) |
| 1650 | return NULL; |
| 1651 | wsetwinpos(wp->w_win, a[0], a[1]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1652 | Py_INCREF(Py_None); |
| 1653 | return Py_None; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1656 | static PyObject * |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1657 | window_setwinsize(wp, args) |
| 1658 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1659 | PyObject *args; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1660 | { |
| 1661 | int a[2]; |
| 1662 | if (!getpointarg(args, a)) |
| 1663 | return NULL; |
| 1664 | wsetwinsize(wp->w_win, a[0], a[1]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1665 | Py_INCREF(Py_None); |
| 1666 | return Py_None; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1669 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1670 | window_getdocsize(wp, args) |
| 1671 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1672 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1673 | { |
| 1674 | int width, height; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1675 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1676 | return NULL; |
| 1677 | wgetdocsize(wp->w_win, &width, &height); |
| 1678 | return makepoint(width, height); |
| 1679 | } |
| 1680 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1681 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1682 | window_getorigin(wp, args) |
| 1683 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1684 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1685 | { |
| 1686 | int width, height; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1687 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1688 | return NULL; |
| 1689 | wgetorigin(wp->w_win, &width, &height); |
| 1690 | return makepoint(width, height); |
| 1691 | } |
| 1692 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1693 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1694 | window_scroll(wp, args) |
| 1695 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1696 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1697 | { |
| 1698 | int a[6]; |
| 1699 | if (!getrectpointarg(args, a)) |
| 1700 | return NULL; |
| 1701 | wscroll(wp->w_win, a[0], a[1], a[2], a[3], a[4], a[5]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1702 | Py_INCREF(Py_None); |
| 1703 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1706 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1707 | window_setdocsize(wp, args) |
| 1708 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1709 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1710 | { |
| 1711 | int a[2]; |
| 1712 | if (!getpointarg(args, a)) |
| 1713 | return NULL; |
| 1714 | wsetdocsize(wp->w_win, a[0], a[1]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1715 | Py_INCREF(Py_None); |
| 1716 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1719 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1720 | window_setorigin(wp, args) |
| 1721 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1722 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1723 | { |
| 1724 | int a[2]; |
| 1725 | if (!getpointarg(args, a)) |
| 1726 | return NULL; |
| 1727 | wsetorigin(wp->w_win, a[0], a[1]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1728 | Py_INCREF(Py_None); |
| 1729 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1732 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1733 | window_settitle(wp, args) |
| 1734 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1735 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1736 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1737 | PyObject *title; |
| 1738 | if (!PyArg_Parse(args, "S", &title)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1739 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1740 | Py_DECREF(wp->w_title); |
| 1741 | Py_INCREF(title); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1742 | wp->w_title = title; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1743 | wsettitle(wp->w_win, PyString_AsString(title)); |
| 1744 | Py_INCREF(Py_None); |
| 1745 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1748 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1749 | window_show(wp, args) |
| 1750 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1751 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1752 | { |
| 1753 | int a[4]; |
| 1754 | if (!getrectarg(args, a)) |
| 1755 | return NULL; |
| 1756 | wshow(wp->w_win, a[0], a[1], a[2], a[3]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1757 | Py_INCREF(Py_None); |
| 1758 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1761 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1762 | window_settimer(wp, args) |
| 1763 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1764 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1765 | { |
| 1766 | int a; |
| 1767 | if (!getintarg(args, &a)) |
| 1768 | return NULL; |
| 1769 | wsettimer(wp->w_win, a); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1770 | Py_INCREF(Py_None); |
| 1771 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1774 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1775 | window_menucreate(self, args) |
| 1776 | windowobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1777 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1778 | { |
| 1779 | menuobject *mp; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1780 | char *title; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1781 | if (!getstrarg(args, &title)) |
| 1782 | return NULL; |
| 1783 | wmenusetdeflocal(1); |
| 1784 | mp = newmenuobject(title); |
| 1785 | if (mp == NULL) |
| 1786 | return NULL; |
| 1787 | wmenuattach(self->w_win, mp->m_menu); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1788 | return (PyObject *)mp; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1791 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1792 | window_textcreate(self, args) |
| 1793 | windowobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1794 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1795 | { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1796 | int a[4]; |
| 1797 | if (!getrectarg(args, a)) |
| 1798 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1799 | return (PyObject *)newtextobject(self, a[0], a[1], a[2], a[3]); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1800 | } |
| 1801 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1802 | static PyObject * |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 1803 | window_setselection(self, args) |
| 1804 | windowobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1805 | PyObject *args; |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 1806 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1807 | int sel, size, ok; |
| 1808 | char *text; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1809 | if (!PyArg_Parse(args, "(is#)", &sel, &text, &size)) |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 1810 | return NULL; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1811 | ok = wsetselection(self->w_win, sel, text, size); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1812 | return PyInt_FromLong(ok); |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 1813 | } |
| 1814 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1815 | static PyObject * |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 1816 | window_setwincursor(self, args) |
| 1817 | windowobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1818 | PyObject *args; |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 1819 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1820 | char *name; |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 1821 | CURSOR *c; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1822 | if (!PyArg_Parse(args, "z", &name)) |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 1823 | return NULL; |
Guido van Rossum | 3c8ba7a | 1992-02-05 11:15:00 +0000 | [diff] [blame] | 1824 | if (name == NULL) |
| 1825 | c = NULL; |
| 1826 | else { |
| 1827 | c = wfetchcursor(name); |
| 1828 | if (c == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1829 | PyErr_SetString(StdwinError, "no such cursor"); |
Guido van Rossum | 3c8ba7a | 1992-02-05 11:15:00 +0000 | [diff] [blame] | 1830 | return NULL; |
| 1831 | } |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 1832 | } |
| 1833 | wsetwincursor(self->w_win, c); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1834 | Py_INCREF(Py_None); |
| 1835 | return Py_None; |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1838 | static PyObject * |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1839 | window_setactive(self, args) |
| 1840 | windowobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1841 | PyObject *args; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1842 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1843 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1844 | return NULL; |
| 1845 | wsetactive(self->w_win); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1846 | Py_INCREF(Py_None); |
| 1847 | return Py_None; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
Guido van Rossum | 8dcbbac | 1991-07-27 21:42:24 +0000 | [diff] [blame] | 1850 | #ifdef CWI_HACKS |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1851 | static PyObject * |
Guido van Rossum | 8dcbbac | 1991-07-27 21:42:24 +0000 | [diff] [blame] | 1852 | window_getxwindowid(self, args) |
| 1853 | windowobject *self; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1854 | PyObject *args; |
Guido van Rossum | 8dcbbac | 1991-07-27 21:42:24 +0000 | [diff] [blame] | 1855 | { |
| 1856 | long wid = wgetxwindowid(self->w_win); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1857 | return PyInt_FromLong(wid); |
Guido van Rossum | 8dcbbac | 1991-07-27 21:42:24 +0000 | [diff] [blame] | 1858 | } |
| 1859 | #endif |
| 1860 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1861 | static PyMethodDef window_methods[] = { |
| 1862 | {"begindrawing",(PyCFunction)window_begindrawing}, |
| 1863 | {"change", (PyCFunction)window_change}, |
| 1864 | {"close", (PyCFunction)window_close}, |
| 1865 | {"getdocsize", (PyCFunction)window_getdocsize}, |
| 1866 | {"getorigin", (PyCFunction)window_getorigin}, |
| 1867 | {"gettitle", (PyCFunction)window_gettitle}, |
| 1868 | {"getwinpos", (PyCFunction)window_getwinpos}, |
| 1869 | {"getwinsize", (PyCFunction)window_getwinsize}, |
| 1870 | {"menucreate", (PyCFunction)window_menucreate}, |
| 1871 | {"scroll", (PyCFunction)window_scroll}, |
| 1872 | {"setactive", (PyCFunction)window_setactive}, |
| 1873 | {"setdocsize", (PyCFunction)window_setdocsize}, |
| 1874 | {"setorigin", (PyCFunction)window_setorigin}, |
| 1875 | {"setselection",(PyCFunction)window_setselection}, |
| 1876 | {"settimer", (PyCFunction)window_settimer}, |
| 1877 | {"settitle", (PyCFunction)window_settitle}, |
| 1878 | {"setwincursor",(PyCFunction)window_setwincursor}, |
| 1879 | {"setwinpos", (PyCFunction)window_setwinpos}, |
| 1880 | {"setwinsize", (PyCFunction)window_setwinsize}, |
| 1881 | {"show", (PyCFunction)window_show}, |
| 1882 | {"textcreate", (PyCFunction)window_textcreate}, |
Guido van Rossum | 8dcbbac | 1991-07-27 21:42:24 +0000 | [diff] [blame] | 1883 | #ifdef CWI_HACKS |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1884 | {"getxwindowid",(PyCFunction)window_getxwindowid}, |
Guido van Rossum | 8dcbbac | 1991-07-27 21:42:24 +0000 | [diff] [blame] | 1885 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1886 | {NULL, NULL} /* sentinel */ |
| 1887 | }; |
| 1888 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1889 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1890 | window_getattr(wp, name) |
| 1891 | windowobject *wp; |
| 1892 | char *name; |
| 1893 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1894 | PyObject *v = NULL; |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 1895 | if (wp->w_win == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1896 | PyErr_SetString(StdwinError, "window already closed"); |
Guido van Rossum | 77b4604 | 1992-01-14 18:41:24 +0000 | [diff] [blame] | 1897 | return NULL; |
| 1898 | } |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1899 | if (strcmp(name, "__dict__") == 0) { |
| 1900 | v = wp->w_attr; |
| 1901 | if (v == NULL) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1902 | v = Py_None; |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1903 | } |
| 1904 | else if (wp->w_attr != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1905 | v = PyDict_GetItemString(wp->w_attr, name); |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1906 | } |
| 1907 | if (v != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1908 | Py_INCREF(v); |
Guido van Rossum | 85f5076 | 1991-10-20 20:22:50 +0000 | [diff] [blame] | 1909 | return v; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1910 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1911 | return Py_FindMethod(window_methods, (PyObject *)wp, name); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | static int |
| 1915 | window_setattr(wp, name, v) |
| 1916 | windowobject *wp; |
| 1917 | char *name; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1918 | PyObject *v; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1919 | { |
| 1920 | if (wp->w_attr == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1921 | wp->w_attr = PyDict_New(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1922 | if (wp->w_attr == NULL) |
| 1923 | return -1; |
| 1924 | } |
Guido van Rossum | 94472a0 | 1992-09-04 09:45:18 +0000 | [diff] [blame] | 1925 | if (v == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1926 | int rv = PyDict_DelItemString(wp->w_attr, name); |
Guido van Rossum | 94472a0 | 1992-09-04 09:45:18 +0000 | [diff] [blame] | 1927 | if (rv < 0) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1928 | PyErr_SetString(PyExc_AttributeError, |
| 1929 | "delete non-existing menu object attribute"); |
Guido van Rossum | 94472a0 | 1992-09-04 09:45:18 +0000 | [diff] [blame] | 1930 | return rv; |
| 1931 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1932 | else |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1933 | return PyDict_SetItemString(wp->w_attr, name, v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1936 | statichere PyTypeObject Windowtype = { |
| 1937 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1938 | 0, /*ob_size*/ |
| 1939 | "window", /*tp_name*/ |
| 1940 | sizeof(windowobject), /*tp_size*/ |
| 1941 | 0, /*tp_itemsize*/ |
| 1942 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1943 | (destructor)window_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 1944 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1945 | (getattrfunc)window_getattr, /*tp_getattr*/ |
| 1946 | (setattrfunc)window_setattr, /*tp_setattr*/ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1947 | 0, /*tp_compare*/ |
| 1948 | 0, /*tp_repr*/ |
| 1949 | }; |
| 1950 | |
| 1951 | /* Stdwin methods */ |
| 1952 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1953 | static PyObject * |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 1954 | stdwin_done(sw, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1955 | PyObject *sw; |
| 1956 | PyObject *args; |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 1957 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1958 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 1959 | return NULL; |
| 1960 | wdone(); |
| 1961 | /* XXX There is no protection against continued use of |
| 1962 | XXX stdwin functions or objects after this call is made. |
| 1963 | XXX Use at own risk */ |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1964 | Py_INCREF(Py_None); |
| 1965 | return Py_None; |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1968 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1969 | stdwin_open(sw, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1970 | PyObject *sw; |
| 1971 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1972 | { |
| 1973 | int tag; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1974 | PyObject *title; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1975 | windowobject *wp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1976 | if (!PyArg_Parse(args, "S", &title)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1977 | return NULL; |
| 1978 | for (tag = 0; tag < MAXNWIN; tag++) { |
| 1979 | if (windowlist[tag] == NULL) |
| 1980 | break; |
| 1981 | } |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 1982 | if (tag >= MAXNWIN) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1983 | PyErr_SetString(StdwinError, "creating too many windows"); |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 1984 | return NULL; |
| 1985 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1986 | wp = PyObject_NEW(windowobject, &Windowtype); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1987 | if (wp == NULL) |
| 1988 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1989 | Py_INCREF(title); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1990 | wp->w_title = title; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1991 | wp->w_win = wopen(PyString_AsString(title), (void (*)()) NULL); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1992 | wp->w_attr = NULL; |
| 1993 | if (wp->w_win == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1994 | Py_DECREF(wp); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1995 | return NULL; |
| 1996 | } |
| 1997 | windowlist[tag] = wp; |
| 1998 | wsettag(wp->w_win, tag); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 1999 | return (PyObject *)wp; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2000 | } |
| 2001 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2002 | static PyObject * |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2003 | window2object(win) |
| 2004 | WINDOW *win; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2005 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2006 | PyObject *w; |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2007 | if (win == NULL) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2008 | w = Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2009 | else { |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2010 | int tag = wgettag(win); |
| 2011 | if (tag < 0 || tag >= MAXNWIN || windowlist[tag] == NULL || |
| 2012 | windowlist[tag]->w_win != win) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2013 | w = Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2014 | else |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2015 | w = (PyObject *)windowlist[tag]; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2016 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2017 | Py_INCREF(w); |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2018 | return w; |
| 2019 | } |
| 2020 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2021 | static PyObject * |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2022 | stdwin_get_poll_event(poll, args) |
| 2023 | int poll; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2024 | PyObject *args; |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2025 | { |
| 2026 | EVENT e; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2027 | PyObject *u, *v, *w; |
| 2028 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2029 | return NULL; |
| 2030 | if (Drawing != NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2031 | PyErr_SetString(StdwinError, |
| 2032 | "cannot getevent() while drawing"); |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2033 | return NULL; |
| 2034 | } |
| 2035 | again: |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2036 | BGN_STDWIN |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2037 | if (poll) { |
| 2038 | if (!wpollevent(&e)) { |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2039 | RET_STDWIN |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2040 | Py_INCREF(Py_None); |
| 2041 | return Py_None; |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2042 | } |
| 2043 | } |
| 2044 | else |
| 2045 | wgetevent(&e); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2046 | END_STDWIN |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2047 | if (e.type == WE_COMMAND && e.u.command == WC_CANCEL) { |
| 2048 | /* Turn keyboard interrupts into exceptions */ |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2049 | PyErr_SetNone(PyExc_KeyboardInterrupt); |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2050 | return NULL; |
| 2051 | } |
| 2052 | if (e.type == WE_COMMAND && e.u.command == WC_CLOSE) { |
| 2053 | /* Turn WC_CLOSE commands into WE_CLOSE events */ |
| 2054 | e.type = WE_CLOSE; |
| 2055 | } |
Guido van Rossum | 2ee12f4 | 1992-04-13 15:54:35 +0000 | [diff] [blame] | 2056 | v = window2object(e.window); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2057 | switch (e.type) { |
| 2058 | case WE_CHAR: |
| 2059 | { |
| 2060 | char c[1]; |
| 2061 | c[0] = e.u.character; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2062 | w = PyString_FromStringAndSize(c, 1); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2063 | } |
| 2064 | break; |
| 2065 | case WE_COMMAND: |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2066 | w = PyInt_FromLong((long)e.u.command); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2067 | break; |
| 2068 | case WE_DRAW: |
| 2069 | w = makerect(e.u.area.left, e.u.area.top, |
| 2070 | e.u.area.right, e.u.area.bottom); |
| 2071 | break; |
| 2072 | case WE_MOUSE_DOWN: |
| 2073 | case WE_MOUSE_MOVE: |
| 2074 | case WE_MOUSE_UP: |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2075 | w = Py_BuildValue("((ii)iii)", |
| 2076 | e.u.where.h, e.u.where.v, |
| 2077 | e.u.where.clicks, |
| 2078 | e.u.where.button, |
| 2079 | e.u.where.mask); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2080 | break; |
| 2081 | case WE_MENU: |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2082 | if (e.u.m.id >= IDOFFSET && |
| 2083 | e.u.m.id < IDOFFSET+MAXNMENU && |
| 2084 | menulist[e.u.m.id - IDOFFSET] != NULL) |
| 2085 | { |
| 2086 | w = Py_BuildValue("(Oi)", |
| 2087 | menulist[e.u.m.id - IDOFFSET], |
| 2088 | e.u.m.item); |
| 2089 | } |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2090 | else { |
| 2091 | /* Ghost menu event. |
| 2092 | Can occur only on the Mac if another part |
| 2093 | of the aplication has installed a menu; |
| 2094 | like the THINK C console library. */ |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2095 | Py_DECREF(v); |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2096 | goto again; |
| 2097 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2098 | break; |
Guido van Rossum | 3ee199e | 1992-06-30 12:48:26 +0000 | [diff] [blame] | 2099 | case WE_KEY: |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2100 | w = Py_BuildValue("(ii)", e.u.key.code, e.u.key.mask); |
Guido van Rossum | 3ee199e | 1992-06-30 12:48:26 +0000 | [diff] [blame] | 2101 | break; |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2102 | case WE_LOST_SEL: |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2103 | w = PyInt_FromLong((long)e.u.sel); |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2104 | break; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2105 | default: |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2106 | w = Py_None; |
| 2107 | Py_INCREF(w); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2108 | break; |
| 2109 | } |
| 2110 | if (w == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2111 | Py_DECREF(v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2112 | return NULL; |
| 2113 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2114 | u = Py_BuildValue("(iOO)", e.type, v, w); |
| 2115 | Py_XDECREF(v); |
| 2116 | Py_XDECREF(w); |
Guido van Rossum | 2ee12f4 | 1992-04-13 15:54:35 +0000 | [diff] [blame] | 2117 | return u; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2120 | static PyObject * |
Guido van Rossum | e8e7cf4 | 1991-01-16 14:06:18 +0000 | [diff] [blame] | 2121 | stdwin_getevent(sw, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2122 | PyObject *sw; |
| 2123 | PyObject *args; |
Guido van Rossum | e8e7cf4 | 1991-01-16 14:06:18 +0000 | [diff] [blame] | 2124 | { |
| 2125 | return stdwin_get_poll_event(0, args); |
| 2126 | } |
| 2127 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2128 | static PyObject * |
Guido van Rossum | e8e7cf4 | 1991-01-16 14:06:18 +0000 | [diff] [blame] | 2129 | stdwin_pollevent(sw, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2130 | PyObject *sw; |
| 2131 | PyObject *args; |
Guido van Rossum | e8e7cf4 | 1991-01-16 14:06:18 +0000 | [diff] [blame] | 2132 | { |
| 2133 | return stdwin_get_poll_event(1, args); |
| 2134 | } |
| 2135 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2136 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2137 | stdwin_setdefwinpos(sw, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2138 | PyObject *sw; |
| 2139 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2140 | { |
| 2141 | int a[2]; |
| 2142 | if (!getpointarg(args, a)) |
| 2143 | return NULL; |
| 2144 | wsetdefwinpos(a[0], a[1]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2145 | Py_INCREF(Py_None); |
| 2146 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2149 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2150 | stdwin_setdefwinsize(sw, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2151 | PyObject *sw; |
| 2152 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2153 | { |
| 2154 | int a[2]; |
| 2155 | if (!getpointarg(args, a)) |
| 2156 | return NULL; |
| 2157 | wsetdefwinsize(a[0], a[1]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2158 | Py_INCREF(Py_None); |
| 2159 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2162 | static PyObject * |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2163 | stdwin_setdefscrollbars(sw, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2164 | PyObject *sw; |
| 2165 | PyObject *args; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2166 | { |
| 2167 | int a[2]; |
| 2168 | if (!getpointarg(args, a)) |
| 2169 | return NULL; |
| 2170 | wsetdefscrollbars(a[0], a[1]); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2171 | Py_INCREF(Py_None); |
| 2172 | return Py_None; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2175 | static PyObject * |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 2176 | stdwin_getdefwinpos(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2177 | PyObject *self; |
| 2178 | PyObject *args; |
Guido van Rossum | 33f1770 | 1991-02-13 23:19:39 +0000 | [diff] [blame] | 2179 | { |
| 2180 | int h, v; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2181 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 33f1770 | 1991-02-13 23:19:39 +0000 | [diff] [blame] | 2182 | return NULL; |
| 2183 | wgetdefwinpos(&h, &v); |
| 2184 | return makepoint(h, v); |
| 2185 | } |
| 2186 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2187 | static PyObject * |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 2188 | stdwin_getdefwinsize(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2189 | PyObject *self; |
| 2190 | PyObject *args; |
Guido van Rossum | 33f1770 | 1991-02-13 23:19:39 +0000 | [diff] [blame] | 2191 | { |
| 2192 | int width, height; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2193 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 33f1770 | 1991-02-13 23:19:39 +0000 | [diff] [blame] | 2194 | return NULL; |
| 2195 | wgetdefwinsize(&width, &height); |
| 2196 | return makepoint(width, height); |
| 2197 | } |
| 2198 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2199 | static PyObject * |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 2200 | stdwin_getdefscrollbars(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2201 | PyObject *self; |
| 2202 | PyObject *args; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2203 | { |
| 2204 | int h, v; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2205 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2206 | return NULL; |
| 2207 | wgetdefscrollbars(&h, &v); |
| 2208 | return makepoint(h, v); |
| 2209 | } |
| 2210 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2211 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2212 | stdwin_menucreate(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2213 | PyObject *self; |
| 2214 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2215 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2216 | char *title; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2217 | if (!getstrarg(args, &title)) |
| 2218 | return NULL; |
| 2219 | wmenusetdeflocal(0); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2220 | return (PyObject *)newmenuobject(title); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2223 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2224 | stdwin_askfile(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2225 | PyObject *self; |
| 2226 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2227 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2228 | char *prompt, *dflt; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2229 | int new, ret; |
| 2230 | char buf[256]; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2231 | if (!PyArg_Parse(args, "(ssi)", &prompt, &dflt, &new)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2232 | return NULL; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2233 | strncpy(buf, dflt, sizeof buf); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2234 | buf[sizeof buf - 1] = '\0'; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2235 | BGN_STDWIN |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2236 | ret = waskfile(prompt, buf, sizeof buf, new); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2237 | END_STDWIN |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2238 | if (!ret) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2239 | PyErr_SetNone(PyExc_KeyboardInterrupt); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2240 | return NULL; |
| 2241 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2242 | return PyString_FromString(buf); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2243 | } |
| 2244 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2245 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2246 | stdwin_askync(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2247 | PyObject *self; |
| 2248 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2249 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2250 | char *prompt; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2251 | int new, ret; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2252 | if (!PyArg_Parse(args, "(si)", &prompt, &new)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2253 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2254 | BGN_STDWIN |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2255 | ret = waskync(prompt, new); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2256 | END_STDWIN |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2257 | if (ret < 0) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2258 | PyErr_SetNone(PyExc_KeyboardInterrupt); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2259 | return NULL; |
| 2260 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2261 | return PyInt_FromLong((long)ret); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2262 | } |
| 2263 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2264 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2265 | stdwin_askstr(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2266 | PyObject *self; |
| 2267 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2268 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2269 | char *prompt, *dflt; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2270 | int ret; |
| 2271 | char buf[256]; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2272 | if (!PyArg_Parse(args, "(ss)", &prompt, &dflt)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2273 | return NULL; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2274 | strncpy(buf, dflt, sizeof buf); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2275 | buf[sizeof buf - 1] = '\0'; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2276 | BGN_STDWIN |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2277 | ret = waskstr(prompt, buf, sizeof buf); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2278 | END_STDWIN |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2279 | if (!ret) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2280 | PyErr_SetNone(PyExc_KeyboardInterrupt); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2281 | return NULL; |
| 2282 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2283 | return PyString_FromString(buf); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2286 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2287 | stdwin_message(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2288 | PyObject *self; |
| 2289 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2290 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2291 | char *msg; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2292 | if (!getstrarg(args, &msg)) |
| 2293 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2294 | BGN_STDWIN |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2295 | wmessage(msg); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2296 | END_STDWIN |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2297 | Py_INCREF(Py_None); |
| 2298 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2301 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2302 | stdwin_fleep(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2303 | PyObject *self; |
| 2304 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2305 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2306 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2307 | return NULL; |
| 2308 | wfleep(); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2309 | Py_INCREF(Py_None); |
| 2310 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2311 | } |
| 2312 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2313 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2314 | stdwin_setcutbuffer(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2315 | PyObject *self; |
| 2316 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2317 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2318 | int i, size; |
| 2319 | char *str; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2320 | if (!PyArg_Parse(args, "(is#)", &i, &str, &size)) |
Guido van Rossum | 124967c | 1990-11-06 15:17:35 +0000 | [diff] [blame] | 2321 | return NULL; |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2322 | wsetcutbuffer(i, str, size); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2323 | Py_INCREF(Py_None); |
| 2324 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2327 | static PyObject * |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2328 | stdwin_getactive(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2329 | PyObject *self; |
| 2330 | PyObject *args; |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2331 | { |
| 2332 | return window2object(wgetactive()); |
| 2333 | } |
| 2334 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2335 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2336 | stdwin_getcutbuffer(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2337 | PyObject *self; |
| 2338 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2339 | { |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2340 | int i; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2341 | char *str; |
Guido van Rossum | 01769f0 | 1990-10-30 13:39:00 +0000 | [diff] [blame] | 2342 | int len; |
Guido van Rossum | 124967c | 1990-11-06 15:17:35 +0000 | [diff] [blame] | 2343 | if (!getintarg(args, &i)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2344 | return NULL; |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2345 | str = wgetcutbuffer(i, &len); |
Guido van Rossum | 01769f0 | 1990-10-30 13:39:00 +0000 | [diff] [blame] | 2346 | if (str == NULL) { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2347 | str = ""; |
Guido van Rossum | 01769f0 | 1990-10-30 13:39:00 +0000 | [diff] [blame] | 2348 | len = 0; |
| 2349 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2350 | return PyString_FromStringAndSize(str, len); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2353 | static PyObject * |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2354 | stdwin_rotatecutbuffers(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2355 | PyObject *self; |
| 2356 | PyObject *args; |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2357 | { |
| 2358 | int i; |
| 2359 | if (!getintarg(args, &i)) |
| 2360 | return NULL; |
| 2361 | wrotatecutbuffers(i); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2362 | Py_INCREF(Py_None); |
| 2363 | return Py_None; |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2364 | } |
| 2365 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2366 | static PyObject * |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2367 | stdwin_getselection(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2368 | PyObject *self; |
| 2369 | PyObject *args; |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2370 | { |
| 2371 | int sel; |
| 2372 | char *data; |
| 2373 | int len; |
| 2374 | if (!getintarg(args, &sel)) |
| 2375 | return NULL; |
| 2376 | data = wgetselection(sel, &len); |
| 2377 | if (data == NULL) { |
| 2378 | data = ""; |
| 2379 | len = 0; |
| 2380 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2381 | return PyString_FromStringAndSize(data, len); |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2382 | } |
| 2383 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2384 | static PyObject * |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2385 | stdwin_resetselection(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2386 | PyObject *self; |
| 2387 | PyObject *args; |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2388 | { |
| 2389 | int sel; |
| 2390 | if (!getintarg(args, &sel)) |
| 2391 | return NULL; |
| 2392 | wresetselection(sel); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2393 | Py_INCREF(Py_None); |
| 2394 | return Py_None; |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2395 | } |
| 2396 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2397 | static PyObject * |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2398 | stdwin_fetchcolor(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2399 | PyObject *self; |
| 2400 | PyObject *args; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2401 | { |
Guido van Rossum | fc58e58 | 1992-01-27 16:45:55 +0000 | [diff] [blame] | 2402 | char *colorname; |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 2403 | COLOR color; |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2404 | if (!getstrarg(args, &colorname)) |
| 2405 | return NULL; |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 2406 | color = wfetchcolor(colorname); |
| 2407 | #ifdef BADCOLOR |
| 2408 | if (color == BADCOLOR) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2409 | PyErr_SetString(StdwinError, "color name not found"); |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 2410 | return NULL; |
| 2411 | } |
| 2412 | #endif |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2413 | return PyInt_FromLong((long)color); |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2416 | static PyObject * |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 2417 | stdwin_getscrsize(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2418 | PyObject *self; |
| 2419 | PyObject *args; |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 2420 | { |
| 2421 | int width, height; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2422 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 2423 | return NULL; |
| 2424 | wgetscrsize(&width, &height); |
| 2425 | return makepoint(width, height); |
| 2426 | } |
| 2427 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2428 | static PyObject * |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 2429 | stdwin_getscrmm(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2430 | PyObject *self; |
| 2431 | PyObject *args; |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 2432 | { |
| 2433 | int width, height; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2434 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 2435 | return NULL; |
| 2436 | wgetscrmm(&width, &height); |
| 2437 | return makepoint(width, height); |
| 2438 | } |
| 2439 | |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 2440 | #ifdef unix |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2441 | static PyObject * |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 2442 | stdwin_connectionnumber(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2443 | PyObject *self; |
| 2444 | PyObject *args; |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 2445 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2446 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 2447 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2448 | return PyInt_FromLong((long) wconnectionnumber()); |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 2449 | } |
| 2450 | #endif |
| 2451 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2452 | static PyObject * |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2453 | stdwin_listfontnames(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2454 | PyObject *self; |
| 2455 | PyObject *args; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2456 | { |
| 2457 | char *pattern; |
| 2458 | char **fontnames; |
| 2459 | int count; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2460 | PyObject *list; |
| 2461 | if (!PyArg_Parse(args, "z", &pattern)) |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2462 | return NULL; |
| 2463 | fontnames = wlistfontnames(pattern, &count); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2464 | list = PyList_New(count); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2465 | if (list != NULL) { |
| 2466 | int i; |
| 2467 | for (i = 0; i < count; i++) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2468 | PyObject *v = PyString_FromString(fontnames[i]); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2469 | if (v == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2470 | Py_DECREF(list); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2471 | list = NULL; |
| 2472 | break; |
| 2473 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2474 | PyList_SetItem(list, i, v); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2475 | } |
| 2476 | } |
| 2477 | return list; |
| 2478 | } |
| 2479 | |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 2480 | #ifdef HAVE_BITMAPS |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2481 | static PyObject * |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2482 | stdwin_newbitmap(self, args) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2483 | PyObject *self; |
| 2484 | PyObject *args; |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2485 | { |
| 2486 | int width, height; |
| 2487 | bitmapobject *bp; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2488 | if (!PyArg_Parse(args, "(ii)", &width, &height)) |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2489 | return NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2490 | return (PyObject *)newbitmapobject(width, height); |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2491 | } |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 2492 | #endif |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2493 | |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2494 | static PyMethodDef stdwin_methods[] = { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2495 | {"askfile", stdwin_askfile}, |
| 2496 | {"askstr", stdwin_askstr}, |
| 2497 | {"askync", stdwin_askync}, |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2498 | {"done", stdwin_done}, |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 2499 | {"fetchcolor", stdwin_fetchcolor}, |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 2500 | #ifdef unix |
| 2501 | {"fileno", stdwin_connectionnumber}, |
| 2502 | {"connectionnumber", stdwin_connectionnumber}, |
| 2503 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2504 | {"fleep", stdwin_fleep}, |
Guido van Rossum | 246b9d8 | 1991-06-03 10:55:14 +0000 | [diff] [blame] | 2505 | {"getactive", stdwin_getactive}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2506 | {"getcutbuffer", stdwin_getcutbuffer}, |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2507 | {"getdefscrollbars", stdwin_getdefscrollbars}, |
Guido van Rossum | 33f1770 | 1991-02-13 23:19:39 +0000 | [diff] [blame] | 2508 | {"getdefwinpos", stdwin_getdefwinpos}, |
| 2509 | {"getdefwinsize", stdwin_getdefwinsize}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2510 | {"getevent", stdwin_getevent}, |
Guido van Rossum | 541c8c0 | 1991-05-05 20:13:41 +0000 | [diff] [blame] | 2511 | {"getscrmm", stdwin_getscrmm}, |
| 2512 | {"getscrsize", stdwin_getscrsize}, |
Guido van Rossum | 2720106 | 1991-04-16 08:43:03 +0000 | [diff] [blame] | 2513 | {"getselection", stdwin_getselection}, |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2514 | {"listfontnames", stdwin_listfontnames}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2515 | {"menucreate", stdwin_menucreate}, |
| 2516 | {"message", stdwin_message}, |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 2517 | #ifdef HAVE_BITMAPS |
Guido van Rossum | bf80e54 | 1993-02-08 15:49:17 +0000 | [diff] [blame] | 2518 | {"newbitmap", stdwin_newbitmap}, |
Guido van Rossum | e906606 | 1993-07-29 13:14:32 +0000 | [diff] [blame] | 2519 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2520 | {"open", stdwin_open}, |
Guido van Rossum | e8e7cf4 | 1991-01-16 14:06:18 +0000 | [diff] [blame] | 2521 | {"pollevent", stdwin_pollevent}, |
Guido van Rossum | 5b10f45 | 1990-10-30 16:01:48 +0000 | [diff] [blame] | 2522 | {"resetselection", stdwin_resetselection}, |
| 2523 | {"rotatecutbuffers", stdwin_rotatecutbuffers}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2524 | {"setcutbuffer", stdwin_setcutbuffer}, |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2525 | {"setdefscrollbars", stdwin_setdefscrollbars}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2526 | {"setdefwinpos", stdwin_setdefwinpos}, |
| 2527 | {"setdefwinsize", stdwin_setdefwinsize}, |
| 2528 | |
| 2529 | /* Text measuring methods borrow code from drawing objects: */ |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2530 | {"baseline", (PyCFunction)drawing_baseline}, |
| 2531 | {"lineheight", (PyCFunction)drawing_lineheight}, |
| 2532 | {"textbreak", (PyCFunction)drawing_textbreak}, |
| 2533 | {"textwidth", (PyCFunction)drawing_textwidth}, |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2534 | |
| 2535 | /* Same for font setting methods: */ |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2536 | {"setfont", (PyCFunction)drawing_setfont}, |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2537 | |
| 2538 | /* Same for color setting/getting methods: */ |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2539 | {"getbgcolor", (PyCFunction)drawing_getbgcolor}, |
| 2540 | {"getfgcolor", (PyCFunction)drawing_getfgcolor}, |
| 2541 | {"setbgcolor", (PyCFunction)drawing_setbgcolor}, |
| 2542 | {"setfgcolor", (PyCFunction)drawing_setfgcolor}, |
Guido van Rossum | 0c2290b | 1991-04-03 19:12:14 +0000 | [diff] [blame] | 2543 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2544 | {NULL, NULL} /* sentinel */ |
| 2545 | }; |
| 2546 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2547 | #ifndef macintosh |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2548 | static int |
| 2549 | checkstringlist(args, ps, pn) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2550 | PyObject *args; |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2551 | char ***ps; |
| 2552 | int *pn; |
| 2553 | { |
| 2554 | int i, n; |
| 2555 | char **s; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2556 | if (!PyList_Check(args)) { |
| 2557 | PyErr_SetString(PyExc_TypeError, "list of strings expected"); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2558 | return 0; |
| 2559 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2560 | n = PyList_Size(args); |
| 2561 | s = PyMem_NEW(char *, n+1); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2562 | if (s == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2563 | PyErr_NoMemory(); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2564 | return 0; |
| 2565 | } |
| 2566 | for (i = 0; i < n; i++) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2567 | PyObject *item = PyList_GetItem(args, i); |
| 2568 | if (!PyString_Check(item)) { |
| 2569 | PyErr_SetString(PyExc_TypeError, |
| 2570 | "list of strings expected"); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2571 | return 0; |
| 2572 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2573 | s[i] = PyString_AsString(item); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2574 | } |
| 2575 | s[n] = NULL; /* In case caller wants a NULL-terminated list */ |
| 2576 | *ps = s; |
| 2577 | *pn = n; |
| 2578 | return 1; |
| 2579 | } |
| 2580 | |
| 2581 | static int |
| 2582 | putbackstringlist(list, s, n) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2583 | PyObject *list; |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2584 | char **s; |
| 2585 | int n; |
| 2586 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2587 | int oldsize = PyList_Size(list); |
| 2588 | PyObject *newlist; |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2589 | int i; |
| 2590 | if (n == oldsize) |
| 2591 | return 1; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2592 | newlist = PyList_New(n); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2593 | for (i = 0; i < n && newlist != NULL; i++) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2594 | PyObject *item = PyString_FromString(s[i]); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2595 | if (item == NULL) { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2596 | Py_DECREF(newlist); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2597 | newlist = NULL; |
| 2598 | } |
| 2599 | else |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2600 | PyList_SetItem(newlist, i, item); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2601 | } |
| 2602 | if (newlist == NULL) |
| 2603 | return 0; |
| 2604 | (*list->ob_type->tp_as_sequence->sq_ass_slice) |
| 2605 | (list, 0, oldsize, newlist); |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2606 | Py_DECREF(newlist); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2607 | return 1; |
| 2608 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2609 | #endif /* macintosh */ |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2610 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2611 | void |
| 2612 | initstdwin() |
| 2613 | { |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2614 | PyObject *m, *d; |
Guido van Rossum | bbf9434 | 1991-12-16 15:44:53 +0000 | [diff] [blame] | 2615 | static int inited = 0; |
| 2616 | |
Guido van Rossum | 2d14e21 | 1991-02-19 12:26:49 +0000 | [diff] [blame] | 2617 | if (!inited) { |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2618 | #ifdef macintosh |
| 2619 | winit(); |
Jack Jansen | d56c109 | 1995-01-27 14:44:16 +0000 | [diff] [blame] | 2620 | PyMac_DoYieldEnabled = 0; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2621 | #else |
Guido van Rossum | 39cb5ce | 1995-01-26 00:37:10 +0000 | [diff] [blame] | 2622 | char buf[1000]; |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2623 | int argc = 0; |
| 2624 | char **argv = NULL; |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2625 | PyObject *sys_argv = PySys_GetObject("argv"); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2626 | if (sys_argv != NULL) { |
| 2627 | if (!checkstringlist(sys_argv, &argv, &argc)) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2628 | PyErr_Clear(); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2629 | } |
Guido van Rossum | c45611d | 1993-11-17 22:58:56 +0000 | [diff] [blame] | 2630 | if (argc > 0) { |
| 2631 | /* If argv[0] has a ".py" suffix, remove the suffix */ |
| 2632 | char *p = strrchr(argv[0], '.'); |
| 2633 | if (p != NULL && strcmp(p, ".py") == 0) { |
| 2634 | int n = p - argv[0]; |
| 2635 | if (n >= sizeof(buf)) |
| 2636 | n = sizeof(buf)-1; |
| 2637 | strncpy(buf, argv[0], n); |
| 2638 | buf[n] = '\0'; |
| 2639 | argv[0] = buf; |
| 2640 | } |
| 2641 | } |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2642 | winitargs(&argc, &argv); |
| 2643 | if (argv != NULL) { |
| 2644 | if (!putbackstringlist(sys_argv, argv, argc)) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2645 | PyErr_Clear(); |
Guido van Rossum | cacd957 | 1993-10-18 11:44:47 +0000 | [diff] [blame] | 2646 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2647 | #endif |
Guido van Rossum | 2d14e21 | 1991-02-19 12:26:49 +0000 | [diff] [blame] | 2648 | inited = 1; |
| 2649 | } |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2650 | m = Py_InitModule("stdwin", stdwin_methods); |
| 2651 | d = PyModule_GetDict(m); |
Guido van Rossum | bbf9434 | 1991-12-16 15:44:53 +0000 | [diff] [blame] | 2652 | |
| 2653 | /* Initialize stdwin.error exception */ |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2654 | StdwinError = PyString_FromString("stdwin.error"); |
| 2655 | if (StdwinError == NULL || |
| 2656 | PyDict_SetItemString(d, "error", StdwinError) != 0) |
| 2657 | Py_FatalError("can't define stdwin.error"); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2658 | #ifdef WITH_THREAD |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2659 | StdwinLock = allocate_lock(); |
| 2660 | if (StdwinLock == NULL) |
Barry Warsaw | c2feec3 | 1996-12-12 22:48:20 +0000 | [diff] [blame] | 2661 | Py_FatalError("can't allocate stdwin lock"); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 2662 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2663 | } |