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