Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * This is a curses implementation for Python. |
| 3 | * |
| 4 | * Based on a prior work by Lance Ellinghaus |
| 5 | * (version 1.2 of this module |
| 6 | * Copyright 1994 by Lance Ellinghouse, |
| 7 | * Cathedral City, California Republic, United States of America.) |
| 8 | * Updated, fixed and heavily extended by Oliver Andrich |
| 9 | * |
| 10 | * Copyright 1996,1997 by Oliver Andrich, |
| 11 | * Koblenz, Germany |
| 12 | * |
| 13 | * Permission is hereby granted, free of charge, to any person obtaining |
| 14 | * a copy of this source file to use, copy, modify, merge, or publish it |
| 15 | * subject to the following conditions: |
| 16 | * |
| 17 | * The above copyright notice and this permission notice shall be included |
| 18 | * in all copies or in any new file that contains a substantial portion of |
| 19 | * this file. |
| 20 | * |
| 21 | * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF |
| 22 | * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT |
| 23 | * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 24 | * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES |
| 25 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE |
| 27 | * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, |
| 28 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 29 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR |
| 30 | * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 31 | * PERFORMANCE OF THIS SOFTWARE. |
| 32 | */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 33 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 34 | /* CVS: $Id$ */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 35 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 36 | /* Release Number */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 37 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 38 | char *PyCursesVersion = "1.5b1"; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 39 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 40 | /* Includes */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 41 | |
Guido van Rossum | 602099a | 1994-09-14 13:32:22 +0000 | [diff] [blame] | 42 | #include "Python.h" |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 43 | #include <curses.h> |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 44 | |
| 45 | #ifdef __sgi__ |
| 46 | /* No attr_t type is available */ |
| 47 | typedef chtype attr_t; |
Guido van Rossum | 1266a01 | 1996-02-25 04:50:31 +0000 | [diff] [blame] | 48 | #endif |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 49 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 50 | /* Definition of exception curses.error */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 51 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 52 | static PyObject *PyCursesError; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 53 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 54 | /* general error messages */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 55 | static char *catchall_ERR = "curses function returned ERR"; |
| 56 | static char *catchall_NULL = "curses function returned NULL"; |
| 57 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 58 | /* Tells whether initscr() has been called to initialise curses. */ |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 59 | static int initialised = FALSE; |
| 60 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 61 | /* Tells whether start_color() has been called to initialise colorusage. */ |
| 62 | static int initialisedcolors = FALSE; |
| 63 | |
| 64 | /* Utility Macros */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 65 | #define ARG_COUNT(X) \ |
| 66 | (((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1)) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 67 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 68 | #define PyCursesInitialised \ |
| 69 | if (initialised != TRUE) { \ |
| 70 | PyErr_SetString(PyCursesError, \ |
| 71 | "must call initscr() first"); \ |
| 72 | return NULL; } |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 73 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 74 | #define PyCursesInitialisedColor \ |
| 75 | if (initialisedcolors != TRUE) { \ |
| 76 | PyErr_SetString(PyCursesError, \ |
| 77 | "must call start_color() first"); \ |
| 78 | return NULL; } |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 79 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 80 | /* Utility Functions */ |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 81 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 82 | /* |
| 83 | * Check the return code from a curses function and return None |
| 84 | * or raise an exception as appropriate. |
| 85 | */ |
| 86 | |
| 87 | static PyObject * |
| 88 | PyCursesCheckERR(code, fname) |
| 89 | int code; |
| 90 | char *fname; |
| 91 | { |
| 92 | char buf[100]; |
| 93 | |
| 94 | if (code != ERR) { |
| 95 | Py_INCREF(Py_None); |
| 96 | return Py_None; |
| 97 | } else { |
| 98 | if (fname == NULL) { |
| 99 | PyErr_SetString(PyCursesError, catchall_ERR); |
| 100 | } else { |
| 101 | strcpy(buf, fname); |
| 102 | strcat(buf, "() returned ERR"); |
| 103 | PyErr_SetString(PyCursesError, buf); |
| 104 | } |
| 105 | return NULL; |
| 106 | } |
| 107 | } |
| 108 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 109 | int |
| 110 | PyCurses_ConvertToChtype(obj, ch) |
| 111 | PyObject *obj; |
| 112 | chtype *ch; |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 113 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 114 | if (PyInt_Check(obj)) { |
| 115 | *ch = (chtype) PyInt_AsLong(obj); |
| 116 | } else if(PyString_Check(obj) & |
| 117 | (PyString_Size(obj) == 1)) { |
| 118 | *ch = (chtype) *PyString_AsString(obj); |
| 119 | } else { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 120 | return 0; |
| 121 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 122 | return 1; |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 125 | /***************************************************************************** |
| 126 | The Window Object |
| 127 | ******************************************************************************/ |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 128 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 129 | /* Definition of the window object and window type */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 130 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 131 | typedef struct { |
| 132 | PyObject_HEAD |
| 133 | WINDOW *win; |
| 134 | } PyCursesWindowObject; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 135 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 136 | PyTypeObject PyCursesWindow_Type; |
| 137 | |
| 138 | #define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type) |
| 139 | |
| 140 | /* Function Prototype Macros - They are ugly but very, very useful. ;-) |
| 141 | |
| 142 | X - function name |
| 143 | TYPE - parameter Type |
| 144 | ERGSTR - format string for construction of the return value |
| 145 | PARSESTR - format string for argument parsing |
| 146 | */ |
| 147 | |
| 148 | #define Window_NoArgNoReturnFunction(X) \ |
| 149 | static PyObject *PyCursesWindow_ ## X (self, arg) \ |
| 150 | PyCursesWindowObject * self; PyObject * arg; \ |
| 151 | { if (!PyArg_NoArgs(arg)) return NULL; \ |
| 152 | return PyCursesCheckERR(X(self->win), # X); } |
| 153 | |
| 154 | #define Window_NoArgTrueFalseFunction(X) \ |
| 155 | static PyObject * PyCursesWindow_ ## X (self,arg) \ |
| 156 | PyCursesWindowObject * self; PyObject * arg; \ |
| 157 | { \ |
| 158 | if (!PyArg_NoArgs(arg)) return NULL; \ |
| 159 | if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \ |
| 160 | else { Py_INCREF(Py_True); return Py_True; } } |
| 161 | |
| 162 | #define Window_NoArgNoReturnVoidFunction(X) \ |
| 163 | static PyObject * PyCursesWindow_ ## X (self,arg) \ |
| 164 | PyCursesWindowObject * self; \ |
| 165 | PyObject * arg; \ |
| 166 | { \ |
| 167 | if (!PyArg_NoArgs(arg)) return NULL; \ |
| 168 | X(self->win); Py_INCREF(Py_None); return Py_None; } |
| 169 | |
| 170 | #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \ |
| 171 | static PyObject * PyCursesWindow_ ## X (self, arg) \ |
| 172 | PyCursesWindowObject *self; \ |
| 173 | PyObject * arg; \ |
| 174 | { \ |
| 175 | TYPE arg1, arg2; \ |
| 176 | if (!PyArg_NoArgs(arg)) return NULL; \ |
| 177 | X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); } |
| 178 | |
| 179 | #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \ |
| 180 | static PyObject * PyCursesWindow_ ## X (self, arg) \ |
| 181 | PyCursesWindowObject *self; \ |
| 182 | PyObject * arg; \ |
| 183 | { \ |
| 184 | TYPE arg1; \ |
| 185 | if (!PyArg_Parse(arg, PARSESTR, &arg1)) return NULL; \ |
| 186 | X(self->win,arg1); Py_INCREF(Py_None); return Py_None; } |
| 187 | |
| 188 | #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \ |
| 189 | static PyObject * PyCursesWindow_ ## X (self, arg) \ |
| 190 | PyCursesWindowObject *self; \ |
| 191 | PyObject * arg; \ |
| 192 | { \ |
| 193 | TYPE arg1; \ |
| 194 | if (!PyArg_Parse(arg,PARSESTR, &arg1)) return NULL; \ |
| 195 | return PyCursesCheckERR(X(self->win, arg1), # X); } |
| 196 | |
| 197 | #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \ |
| 198 | static PyObject * PyCursesWindow_ ## X (self, arg) \ |
| 199 | PyCursesWindowObject *self; \ |
| 200 | PyObject * arg; \ |
| 201 | { \ |
| 202 | TYPE arg1, arg2; \ |
| 203 | if (!PyArg_Parse(arg,PARSESTR, &arg1, &arg2)) return NULL; \ |
| 204 | return PyCursesCheckERR(X(self->win, arg1, arg2), # X); } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 205 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 206 | /* ------------- WINDOW routines --------------- */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 207 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 208 | Window_NoArgNoReturnFunction(untouchwin) |
| 209 | Window_NoArgNoReturnFunction(touchwin) |
| 210 | Window_NoArgNoReturnFunction(redrawwin) |
| 211 | Window_NoArgNoReturnFunction(winsertln) |
| 212 | Window_NoArgNoReturnFunction(werase) |
| 213 | Window_NoArgNoReturnFunction(wdeleteln) |
| 214 | |
| 215 | Window_NoArgTrueFalseFunction(is_wintouched) |
| 216 | |
| 217 | Window_NoArgNoReturnVoidFunction(wsyncup) |
| 218 | Window_NoArgNoReturnVoidFunction(wsyncdown) |
| 219 | Window_NoArgNoReturnVoidFunction(wstandend) |
| 220 | Window_NoArgNoReturnVoidFunction(wstandout) |
| 221 | Window_NoArgNoReturnVoidFunction(wcursyncup) |
| 222 | Window_NoArgNoReturnVoidFunction(wclrtoeol) |
| 223 | Window_NoArgNoReturnVoidFunction(wclrtobot) |
| 224 | Window_NoArgNoReturnVoidFunction(wclear) |
| 225 | |
| 226 | Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)") |
| 227 | Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)") |
| 228 | |
| 229 | Window_NoArg2TupleReturnFunction(getyx, int, "(ii)") |
| 230 | Window_NoArg2TupleReturnFunction(getbegyx, int, "(ii)") |
| 231 | Window_NoArg2TupleReturnFunction(getmaxyx, int, "(ii)") |
| 232 | Window_NoArg2TupleReturnFunction(getparyx, int, "(ii)") |
| 233 | |
| 234 | Window_OneArgNoReturnFunction(wattron, attr_t, "l;attr") |
| 235 | Window_OneArgNoReturnFunction(wattroff, attr_t, "l;attr") |
| 236 | Window_OneArgNoReturnFunction(wattrset, attr_t, "l;attr") |
| 237 | Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)") |
| 238 | Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)") |
| 239 | Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)") |
| 240 | Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)") |
| 241 | Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)") |
| 242 | Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)") |
| 243 | Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)") |
| 244 | Window_OneArgNoReturnFunction(winsdelln, int, "i;cnt") |
| 245 | Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)") |
| 246 | |
| 247 | Window_TwoArgNoReturnFunction(mvwin, int, "(ii);y,x") |
| 248 | Window_TwoArgNoReturnFunction(mvderwin, int, "(ii);y,x") |
| 249 | Window_TwoArgNoReturnFunction(wmove, int, "(ii);y,x") |
| 250 | #ifndef __sgi__ |
| 251 | Window_TwoArgNoReturnFunction(wresize, int, "(ii);lines,columns") |
| 252 | #endif |
| 253 | |
| 254 | /* Allocation and Deallocation of Window Objects */ |
| 255 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 256 | static PyObject * |
| 257 | PyCursesWindow_New(win) |
| 258 | WINDOW *win; |
| 259 | { |
| 260 | PyCursesWindowObject *wo; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 261 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 262 | wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type); |
| 263 | if (wo == NULL) return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 264 | wo->win = win; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 265 | return (PyObject *)wo; |
| 266 | } |
| 267 | |
| 268 | static void |
| 269 | PyCursesWindow_Dealloc(wo) |
| 270 | PyCursesWindowObject *wo; |
| 271 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 272 | if (wo->win != stdscr) delwin(wo->win); |
| 273 | PyMem_DEL(wo); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 276 | /* Addch, Addstr, Addnstr */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 277 | |
| 278 | static PyObject * |
| 279 | PyCursesWindow_AddCh(self,arg) |
| 280 | PyCursesWindowObject *self; |
| 281 | PyObject * arg; |
| 282 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 283 | int rtn, x, y, use_xy = FALSE; |
| 284 | PyObject *temp; |
| 285 | chtype ch = 0; |
| 286 | attr_t attr = A_NORMAL; |
| 287 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 288 | switch (ARG_COUNT(arg)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 289 | case 1: |
| 290 | if (!PyArg_Parse(arg, "O;ch or int", &temp)) |
| 291 | return NULL; |
| 292 | break; |
| 293 | case 2: |
| 294 | if (!PyArg_Parse(arg, "(Ol);ch or int,attr", &temp, &attr)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 295 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 296 | break; |
| 297 | case 3: |
| 298 | if (!PyArg_Parse(arg,"(iiO);y,x,ch or int", &y, &x, &temp)) |
| 299 | return NULL; |
| 300 | use_xy = TRUE; |
| 301 | break; |
| 302 | case 4: |
| 303 | if (!PyArg_Parse(arg,"(iiOl);y,x,ch or int, attr", |
| 304 | &y, &x, &temp, &attr)) |
| 305 | return NULL; |
| 306 | use_xy = TRUE; |
| 307 | break; |
| 308 | default: |
| 309 | PyErr_SetString(PyExc_TypeError, "addch requires 1 or 4 arguments"); |
| 310 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 311 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 312 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 313 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 314 | PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int"); |
| 315 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 316 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 317 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 318 | if (use_xy == TRUE) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 319 | rtn = mvwaddch(self->win,y,x, ch | attr); |
| 320 | else { |
| 321 | rtn = waddch(self->win, ch | attr); |
| 322 | } |
| 323 | return PyCursesCheckERR(rtn, "addch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 327 | PyCursesWindow_AddStr(self,arg) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 328 | PyCursesWindowObject *self; |
| 329 | PyObject * arg; |
| 330 | { |
| 331 | int rtn; |
| 332 | int x, y; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 333 | char *str; |
| 334 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 335 | int use_xy = FALSE, use_attr = FALSE; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 336 | |
| 337 | switch (ARG_COUNT(arg)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 338 | case 1: |
| 339 | if (!PyArg_Parse(arg,"s;str", &str)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 340 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 341 | break; |
| 342 | case 2: |
| 343 | if (!PyArg_Parse(arg,"(sl);str,attr", &str, &attr)) |
| 344 | return NULL; |
| 345 | use_attr = TRUE; |
| 346 | break; |
| 347 | case 3: |
| 348 | if (!PyArg_Parse(arg,"(iis);int,int,str", &y, &x, &str)) |
| 349 | return NULL; |
| 350 | use_xy = TRUE; |
| 351 | break; |
| 352 | case 4: |
| 353 | if (!PyArg_Parse(arg,"(iisl);int,int,str,attr", &y, &x, &str, &attr)) |
| 354 | return NULL; |
| 355 | use_xy = use_attr = TRUE; |
| 356 | break; |
| 357 | default: |
| 358 | PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments"); |
| 359 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 360 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 361 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 362 | if (use_attr == TRUE) { |
| 363 | attr_old = getattrs(self->win); |
| 364 | wattrset(self->win,attr); |
| 365 | } |
| 366 | if (use_xy == TRUE) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 367 | rtn = mvwaddstr(self->win,y,x,str); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 368 | else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 369 | rtn = waddstr(self->win,str); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 370 | if (use_attr == TRUE) |
| 371 | wattrset(self->win,attr_old); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 372 | return PyCursesCheckERR(rtn, "addstr"); |
| 373 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 374 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 375 | static PyObject * |
| 376 | PyCursesWindow_AddNStr(self,arg) |
| 377 | PyCursesWindowObject *self; |
| 378 | PyObject * arg; |
| 379 | { |
| 380 | int rtn, x, y, n; |
| 381 | char *str; |
| 382 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 383 | int use_xy = FALSE, use_attr = FALSE; |
| 384 | |
| 385 | switch (ARG_COUNT(arg)) { |
| 386 | case 2: |
| 387 | if (!PyArg_Parse(arg,"(si);str,n", &str, &n)) |
| 388 | return NULL; |
| 389 | break; |
| 390 | case 3: |
| 391 | if (!PyArg_Parse(arg,"(sil);str,n,attr", &str, &n, &attr)) |
| 392 | return NULL; |
| 393 | use_attr = TRUE; |
| 394 | break; |
| 395 | case 4: |
| 396 | if (!PyArg_Parse(arg,"(iisi);y,x,str,n", &y, &x, &str, &n)) |
| 397 | return NULL; |
| 398 | use_xy = TRUE; |
| 399 | break; |
| 400 | case 5: |
| 401 | if (!PyArg_Parse(arg,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr)) |
| 402 | return NULL; |
| 403 | use_xy = use_attr = TRUE; |
| 404 | break; |
| 405 | default: |
| 406 | PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments"); |
| 407 | return NULL; |
| 408 | } |
| 409 | |
| 410 | if (use_attr == TRUE) { |
| 411 | attr_old = getattrs(self->win); |
| 412 | wattrset(self->win,attr); |
| 413 | } |
| 414 | if (use_xy == TRUE) |
| 415 | rtn = mvwaddnstr(self->win,y,x,str,n); |
| 416 | else |
| 417 | rtn = waddnstr(self->win,str,n); |
| 418 | if (use_attr == TRUE) |
| 419 | wattrset(self->win,attr_old); |
| 420 | return PyCursesCheckERR(rtn, "addnstr"); |
| 421 | } |
| 422 | |
| 423 | static PyObject * |
| 424 | PyCursesWindow_Bkgd(self,arg) |
| 425 | PyCursesWindowObject *self; |
| 426 | PyObject * arg; |
| 427 | { |
| 428 | PyObject *temp; |
| 429 | chtype bkgd; |
| 430 | attr_t attr = A_NORMAL; |
| 431 | |
| 432 | switch (ARG_COUNT(arg)) { |
| 433 | case 1: |
| 434 | if (!PyArg_Parse(arg, "O;ch or int", &temp)) |
| 435 | return NULL; |
| 436 | break; |
| 437 | case 2: |
| 438 | if (!PyArg_Parse(arg,"(Ol);ch or int,attr", &temp, &attr)) |
| 439 | return NULL; |
| 440 | break; |
| 441 | default: |
| 442 | PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments"); |
| 443 | return NULL; |
| 444 | } |
| 445 | |
| 446 | if (!PyCurses_ConvertToChtype(temp, &bkgd)) { |
| 447 | PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int"); |
| 448 | return NULL; |
| 449 | } |
| 450 | |
| 451 | return PyCursesCheckERR(wbkgd(self->win, bkgd | A_NORMAL), "bkgd"); |
| 452 | } |
| 453 | |
| 454 | static PyObject * |
| 455 | PyCursesWindow_BkgdSet(self,arg) |
| 456 | PyCursesWindowObject *self; |
| 457 | PyObject * arg; |
| 458 | { |
| 459 | PyObject *temp; |
| 460 | chtype bkgd; |
| 461 | attr_t attr = A_NORMAL; |
| 462 | |
| 463 | switch (ARG_COUNT(arg)) { |
| 464 | case 1: |
| 465 | if (!PyArg_Parse(arg, "O;ch or int", &temp)) |
| 466 | return NULL; |
| 467 | break; |
| 468 | case 2: |
| 469 | if (!PyArg_Parse(arg,"(Ol);ch or int,attr", &temp, &attr)) |
| 470 | return NULL; |
| 471 | break; |
| 472 | default: |
| 473 | PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments"); |
| 474 | return NULL; |
| 475 | } |
| 476 | |
| 477 | if (!PyCurses_ConvertToChtype(temp, &bkgd)) { |
| 478 | PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int"); |
| 479 | return NULL; |
| 480 | } |
| 481 | |
| 482 | wbkgdset(self->win, bkgd | attr); |
| 483 | return PyCursesCheckERR(0, "bkgdset"); |
| 484 | } |
| 485 | |
| 486 | static PyObject * |
| 487 | PyCursesWindow_Border(self, args) |
| 488 | PyCursesWindowObject *self; |
| 489 | PyObject *args; |
| 490 | { |
| 491 | chtype ls, rs, ts, bs, tl, tr, bl, br; |
| 492 | ls = rs = ts = bs = tl = tr = bl = br = 0; |
| 493 | if (!PyArg_Parse(args,"|llllllll;ls,rs,ts,bs,tl,tr,bl,br", |
| 494 | &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br)) |
| 495 | return NULL; |
| 496 | wborder(self->win, ls, rs, ts, bs, tl, tr, bl, br); |
| 497 | Py_INCREF(Py_None); |
| 498 | return Py_None; |
| 499 | } |
| 500 | |
| 501 | static PyObject * |
| 502 | PyCursesWindow_Box(self,arg) |
| 503 | PyCursesWindowObject *self; |
| 504 | PyObject * arg; |
| 505 | { |
| 506 | chtype ch1=0,ch2=0; |
| 507 | if (!PyArg_NoArgs(arg)) { |
| 508 | PyErr_Clear(); |
| 509 | if (!PyArg_Parse(arg,"(ll);vertint,horint", &ch1, &ch2)) |
| 510 | return NULL; |
| 511 | } |
| 512 | box(self->win,ch1,ch2); |
| 513 | Py_INCREF(Py_None); |
| 514 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static PyObject * |
| 518 | PyCursesWindow_DelCh(self,arg) |
| 519 | PyCursesWindowObject *self; |
| 520 | PyObject * arg; |
| 521 | { |
| 522 | int rtn; |
| 523 | int x, y; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 524 | |
| 525 | switch (ARG_COUNT(arg)) { |
| 526 | case 0: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 527 | rtn = wdelch(self->win); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 528 | break; |
| 529 | case 2: |
| 530 | if (!PyArg_Parse(arg,"(ii);y,x", &y, &x)) |
| 531 | return NULL; |
| 532 | rtn = mvwdelch(self->win,y,x); |
| 533 | break; |
| 534 | default: |
| 535 | PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments"); |
| 536 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 537 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 538 | return PyCursesCheckERR(rtn, "[mv]wdelch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 542 | PyCursesWindow_DerWin(self,arg) |
| 543 | PyCursesWindowObject *self; |
| 544 | PyObject * arg; |
| 545 | { |
| 546 | WINDOW *win; |
| 547 | int nlines, ncols, begin_y, begin_x; |
| 548 | |
| 549 | nlines = 0; |
| 550 | ncols = 0; |
| 551 | switch (ARG_COUNT(arg)) { |
| 552 | case 2: |
| 553 | if (!PyArg_Parse(arg,"(ii);begin_y,begin_x",&begin_y,&begin_x)) |
| 554 | return NULL; |
| 555 | break; |
| 556 | case 4: |
| 557 | if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x", |
| 558 | &nlines,&ncols,&begin_y,&begin_x)) |
| 559 | return NULL; |
| 560 | break; |
| 561 | default: |
| 562 | PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments"); |
| 563 | return NULL; |
| 564 | } |
| 565 | |
| 566 | win = derwin(self->win,nlines,ncols,begin_y,begin_x); |
| 567 | |
| 568 | if (win == NULL) { |
| 569 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 570 | return NULL; |
| 571 | } |
| 572 | |
| 573 | return (PyObject *)PyCursesWindow_New(win); |
| 574 | } |
| 575 | |
| 576 | static PyObject * |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 577 | PyCursesWindow_EchoChar(self,arg) |
| 578 | PyCursesWindowObject *self; |
| 579 | PyObject * arg; |
| 580 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 581 | PyObject *temp; |
| 582 | chtype ch; |
| 583 | attr_t attr = A_NORMAL; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 584 | |
| 585 | switch (ARG_COUNT(arg)) { |
| 586 | case 1: |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 587 | if (!PyArg_Parse(arg,"O;ch or int", &temp)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 588 | return NULL; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 589 | break; |
| 590 | case 2: |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 591 | if (!PyArg_Parse(arg,"(Ol);ch or int,attr", &temp, &attr)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 592 | return NULL; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 593 | break; |
| 594 | default: |
| 595 | PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 596 | |
| 597 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 598 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 599 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 600 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 601 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 602 | PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 603 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 604 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 605 | |
| 606 | if (self->win->_flags & _ISPAD) |
| 607 | return PyCursesCheckERR(pechochar(self->win, ch | attr), |
| 608 | "echochar"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 609 | else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 610 | return PyCursesCheckERR(wechochar(self->win, ch | attr), |
| 611 | "echochar"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 615 | PyCursesWindow_GetBkgd(self, arg) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 616 | PyCursesWindowObject *self; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 617 | PyObject *arg; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 618 | { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 619 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 620 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 621 | return PyInt_FromLong((long) getbkgd(self->win)); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | static PyObject * |
| 625 | PyCursesWindow_GetCh(self,arg) |
| 626 | PyCursesWindowObject *self; |
| 627 | PyObject * arg; |
| 628 | { |
| 629 | int x, y; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 630 | chtype rtn; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 631 | |
| 632 | switch (ARG_COUNT(arg)) { |
| 633 | case 0: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 634 | rtn = wgetch(self->win); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 635 | break; |
| 636 | case 2: |
| 637 | if (!PyArg_Parse(arg,"(ii);y,x",&y,&x)) |
| 638 | return NULL; |
| 639 | rtn = mvwgetch(self->win,y,x); |
| 640 | break; |
| 641 | default: |
| 642 | PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments"); |
| 643 | return NULL; |
| 644 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 645 | return PyInt_FromLong(rtn); |
| 646 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 647 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 648 | static PyObject * |
| 649 | PyCursesWindow_GetKey(self,arg) |
| 650 | PyCursesWindowObject *self; |
| 651 | PyObject * arg; |
| 652 | { |
| 653 | int x, y; |
| 654 | chtype rtn; |
| 655 | |
| 656 | switch (ARG_COUNT(arg)) { |
| 657 | case 0: |
| 658 | rtn = wgetch(self->win); |
| 659 | break; |
| 660 | case 2: |
| 661 | if (!PyArg_Parse(arg,"(ii);y,x",&y,&x)) |
| 662 | return NULL; |
| 663 | rtn = mvwgetch(self->win,y,x); |
| 664 | break; |
| 665 | default: |
| 666 | PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments"); |
| 667 | return NULL; |
| 668 | } |
| 669 | if (rtn<=255) |
| 670 | return Py_BuildValue("c", rtn); |
| 671 | else |
| 672 | return PyString_FromString((char *)keyname(rtn)); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | static PyObject * |
| 676 | PyCursesWindow_GetStr(self,arg) |
| 677 | PyCursesWindowObject *self; |
| 678 | PyObject * arg; |
| 679 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 680 | int x, y, n; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 681 | char rtn[1024]; /* This should be big enough.. I hope */ |
| 682 | int rtn2; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 683 | |
| 684 | switch (ARG_COUNT(arg)) { |
| 685 | case 0: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 686 | rtn2 = wgetstr(self->win,rtn); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 687 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 688 | case 1: |
| 689 | if (!PyArg_Parse(arg,"i;n", &n)) |
| 690 | return NULL; |
| 691 | rtn2 = wgetnstr(self->win,rtn,n); |
| 692 | break; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 693 | case 2: |
| 694 | if (!PyArg_Parse(arg,"(ii);y,x",&y,&x)) |
| 695 | return NULL; |
| 696 | rtn2 = mvwgetstr(self->win,y,x,rtn); |
| 697 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 698 | case 3: |
| 699 | if (!PyArg_Parse(arg,"(iii);y,x,n", &y, &x, &n)) |
| 700 | return NULL; |
| 701 | #ifdef __sgi__ |
| 702 | /* Untested */ |
| 703 | rtn2 = wmove(self->win,y,x)==ERR ? ERR : |
| 704 | wgetnstr(self->win, rtn, n); |
| 705 | #else |
| 706 | rtn2 = mvwgetnstr(self->win, y, x, rtn, n); |
| 707 | #endif |
| 708 | break; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 709 | default: |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 710 | PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 2 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 711 | return NULL; |
| 712 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 713 | if (rtn2 == ERR) |
| 714 | rtn[0] = 0; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 715 | return PyString_FromString(rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 719 | PyCursesWindow_Hline(self, args) |
| 720 | PyCursesWindowObject *self; |
| 721 | PyObject *args; |
| 722 | { |
| 723 | PyObject *temp; |
| 724 | chtype ch; |
| 725 | int n, x, y, code = OK; |
| 726 | attr_t attr = A_NORMAL; |
| 727 | |
| 728 | switch (ARG_COUNT(args)) { |
| 729 | case 2: |
| 730 | if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n)) |
| 731 | return NULL; |
| 732 | break; |
| 733 | case 3: |
| 734 | if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr)) |
| 735 | return NULL; |
| 736 | break; |
| 737 | case 4: |
| 738 | if (!PyArg_Parse(args, "(iiOi);y,x,ch o int,n", &y, &x, &temp, &n)) |
| 739 | return NULL; |
| 740 | code = wmove(self->win, y, x); |
| 741 | break; |
| 742 | case 5: |
| 743 | if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr", |
| 744 | &y, &x, &temp, &n, &attr)) |
| 745 | return NULL; |
| 746 | code = wmove(self->win, y, x); |
| 747 | default: |
| 748 | PyErr_SetString(PyExc_TypeError, "hline requires 2 or 5 arguments"); |
| 749 | return NULL; |
| 750 | } |
| 751 | |
| 752 | if (code != ERR) { |
| 753 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 754 | PyErr_SetString(PyExc_TypeError, |
| 755 | "argument 1 or 3 must be a ch or an int"); |
| 756 | return NULL; |
| 757 | } |
| 758 | return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline"); |
| 759 | } else |
| 760 | return PyCursesCheckERR(code, "wmove"); |
| 761 | } |
| 762 | |
| 763 | static PyObject * |
| 764 | PyCursesWindow_InsCh(self,arg) |
| 765 | PyCursesWindowObject *self; |
| 766 | PyObject * arg; |
| 767 | { |
| 768 | int rtn, x, y, use_xy = FALSE; |
| 769 | PyObject *temp; |
| 770 | chtype ch = 0; |
| 771 | attr_t attr = A_NORMAL; |
| 772 | |
| 773 | switch (ARG_COUNT(arg)) { |
| 774 | case 1: |
| 775 | if (!PyArg_Parse(arg, "O;ch or int", &temp)) |
| 776 | return NULL; |
| 777 | break; |
| 778 | case 2: |
| 779 | if (!PyArg_Parse(arg, "(Ol);ch or int,attr", &temp, &attr)) |
| 780 | return NULL; |
| 781 | break; |
| 782 | case 3: |
| 783 | if (!PyArg_Parse(arg,"(iiO);y,x,ch or int", &y, &x, &temp)) |
| 784 | return NULL; |
| 785 | use_xy = TRUE; |
| 786 | break; |
| 787 | case 4: |
| 788 | if (!PyArg_Parse(arg,"(iiOl);y,x,ch or int, attr", &y, &x, &temp, &attr)) |
| 789 | return NULL; |
| 790 | use_xy = TRUE; |
| 791 | break; |
| 792 | default: |
| 793 | PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments"); |
| 794 | return NULL; |
| 795 | } |
| 796 | |
| 797 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 798 | PyErr_SetString(PyExc_TypeError, |
| 799 | "argument 1 or 3 must be a ch or an int"); |
| 800 | return NULL; |
| 801 | } |
| 802 | |
| 803 | if (use_xy == TRUE) |
| 804 | rtn = mvwinsch(self->win,y,x, ch | attr); |
| 805 | else { |
| 806 | rtn = winsch(self->win, ch | attr); |
| 807 | } |
| 808 | return PyCursesCheckERR(rtn, "insch"); |
| 809 | } |
| 810 | |
| 811 | static PyObject * |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 812 | PyCursesWindow_InCh(self,arg) |
| 813 | PyCursesWindowObject *self; |
| 814 | PyObject * arg; |
| 815 | { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 816 | int x, y, rtn; |
| 817 | |
| 818 | switch (ARG_COUNT(arg)) { |
| 819 | case 0: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 820 | rtn = winch(self->win); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 821 | break; |
| 822 | case 2: |
| 823 | if (!PyArg_Parse(arg,"(ii);y,x",&y,&x)) |
| 824 | return NULL; |
| 825 | rtn = mvwinch(self->win,y,x); |
| 826 | break; |
| 827 | default: |
| 828 | PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments"); |
| 829 | return NULL; |
| 830 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 831 | return PyInt_FromLong((long) rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 835 | PyCursesWindow_InStr(self,arg) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 836 | PyCursesWindowObject *self; |
| 837 | PyObject * arg; |
| 838 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 839 | int x, y, n; |
| 840 | char rtn[1024]; /* This should be big enough.. I hope */ |
| 841 | int rtn2; |
| 842 | |
| 843 | switch (ARG_COUNT(arg)) { |
| 844 | case 0: |
| 845 | rtn2 = winstr(self->win,rtn); |
| 846 | break; |
| 847 | case 1: |
| 848 | if (!PyArg_Parse(arg,"i;n", &n)) |
| 849 | return NULL; |
| 850 | rtn2 = winnstr(self->win,rtn,n); |
| 851 | break; |
| 852 | case 2: |
| 853 | if (!PyArg_Parse(arg,"(ii);y,x",&y,&x)) |
| 854 | return NULL; |
| 855 | rtn2 = mvwinstr(self->win,y,x,rtn); |
| 856 | break; |
| 857 | case 3: |
| 858 | if (!PyArg_Parse(arg, "(iii);y,x,n", &y, &x, &n)) |
| 859 | return NULL; |
| 860 | rtn2 = mvwinnstr(self->win, y, x, rtn, n); |
| 861 | break; |
| 862 | default: |
| 863 | PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 864 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 865 | } |
| 866 | if (rtn2 == ERR) |
| 867 | rtn[0] = 0; |
| 868 | return PyString_FromString(rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 872 | PyCursesWindow_InsStr(self,arg) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 873 | PyCursesWindowObject *self; |
| 874 | PyObject * arg; |
| 875 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 876 | int rtn; |
| 877 | int x, y; |
| 878 | char *str; |
| 879 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 880 | int use_xy = FALSE, use_attr = FALSE; |
| 881 | |
| 882 | switch (ARG_COUNT(arg)) { |
| 883 | case 1: |
| 884 | if (!PyArg_Parse(arg,"s;str", &str)) |
| 885 | return NULL; |
| 886 | break; |
| 887 | case 2: |
| 888 | if (!PyArg_Parse(arg,"(sl);str,attr", &str, &attr)) |
| 889 | return NULL; |
| 890 | use_attr = TRUE; |
| 891 | break; |
| 892 | case 3: |
| 893 | if (!PyArg_Parse(arg,"(iis);y,x,str", &y, &x, &str)) |
| 894 | return NULL; |
| 895 | use_xy = TRUE; |
| 896 | break; |
| 897 | case 4: |
| 898 | if (!PyArg_Parse(arg,"(iisl);y,x,str,attr", &y, &x, &str, &attr)) |
| 899 | return NULL; |
| 900 | use_xy = use_attr = TRUE; |
| 901 | break; |
| 902 | default: |
| 903 | PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 904 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 905 | } |
| 906 | |
| 907 | if (use_attr == TRUE) { |
| 908 | attr_old = getattrs(self->win); |
| 909 | wattrset(self->win,attr); |
| 910 | } |
| 911 | if (use_xy == TRUE) |
| 912 | rtn = mvwinsstr(self->win,y,x,str); |
| 913 | else |
| 914 | rtn = winsstr(self->win,str); |
| 915 | if (use_attr == TRUE) |
| 916 | wattrset(self->win,attr_old); |
| 917 | return PyCursesCheckERR(rtn, "insstr"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 921 | PyCursesWindow_InsNStr(self,arg) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 922 | PyCursesWindowObject *self; |
| 923 | PyObject * arg; |
| 924 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 925 | int rtn, x, y, n; |
| 926 | char *str; |
| 927 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 928 | int use_xy = FALSE, use_attr = FALSE; |
| 929 | |
| 930 | switch (ARG_COUNT(arg)) { |
| 931 | case 2: |
| 932 | if (!PyArg_Parse(arg,"(si);str,n", &str, &n)) |
| 933 | return NULL; |
| 934 | break; |
| 935 | case 3: |
| 936 | if (!PyArg_Parse(arg,"(sil);str,n,attr", &str, &n, &attr)) |
| 937 | return NULL; |
| 938 | use_attr = TRUE; |
| 939 | break; |
| 940 | case 4: |
| 941 | if (!PyArg_Parse(arg,"(iisi);y,x,str,n", &y, &x, &str, &n)) |
| 942 | return NULL; |
| 943 | use_xy = TRUE; |
| 944 | break; |
| 945 | case 5: |
| 946 | if (!PyArg_Parse(arg,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr)) |
| 947 | return NULL; |
| 948 | use_xy = use_attr = TRUE; |
| 949 | break; |
| 950 | default: |
| 951 | PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 952 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 953 | } |
| 954 | |
| 955 | if (use_attr == TRUE) { |
| 956 | attr_old = getattrs(self->win); |
| 957 | wattrset(self->win,attr); |
| 958 | } |
| 959 | if (use_xy == TRUE) |
| 960 | rtn = mvwinsnstr(self->win,y,x,str,n); |
| 961 | else |
| 962 | rtn = winsnstr(self->win,str,n); |
| 963 | if (use_attr == TRUE) |
| 964 | wattrset(self->win,attr_old); |
| 965 | return PyCursesCheckERR(rtn, "insnstr"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 969 | PyCursesWindow_Is_LineTouched(self,arg) |
| 970 | PyCursesWindowObject * self; |
| 971 | PyObject * arg; |
| 972 | { |
| 973 | int line, erg; |
| 974 | if (!PyArg_Parse(arg,"i;line", &line)) |
| 975 | return NULL; |
| 976 | erg = is_linetouched(self->win, line); |
| 977 | if (erg == ERR) { |
| 978 | PyErr_SetString(PyExc_TypeError, |
| 979 | "is_linetouched: line number outside of boundaries"); |
| 980 | return NULL; |
| 981 | } else |
| 982 | if (erg == FALSE) { |
| 983 | Py_INCREF(Py_False); |
| 984 | return Py_False; |
| 985 | } else { |
| 986 | Py_INCREF(Py_True); |
| 987 | return Py_True; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | static PyObject * |
| 992 | PyCursesWindow_NoOutRefresh(self,arg) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 993 | PyCursesWindowObject *self; |
| 994 | PyObject * arg; |
| 995 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 996 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; |
| 997 | |
| 998 | if (self->win->_flags & _ISPAD) { |
| 999 | switch(ARG_COUNT(arg)) { |
| 1000 | case 6: |
| 1001 | if (!PyArg_Parse(arg, |
| 1002 | "(iiiiii);" \ |
| 1003 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", |
| 1004 | &pminrow, &pmincol, &sminrow, |
| 1005 | &smincol, &smaxrow, &smaxcol)) |
| 1006 | return NULL; |
| 1007 | return PyCursesCheckERR(pnoutrefresh(self->win, |
| 1008 | pminrow, pmincol, sminrow, |
| 1009 | smincol, smaxrow, smaxcol), |
| 1010 | "pnoutrefresh"); |
| 1011 | default: |
| 1012 | PyErr_SetString(PyCursesError, |
| 1013 | "noutrefresh was called for a pad;" \ |
| 1014 | "requires 6 arguments"); |
| 1015 | return NULL; |
| 1016 | } |
| 1017 | } else { |
| 1018 | if (!PyArg_NoArgs(arg)) |
| 1019 | return NULL; |
| 1020 | return PyCursesCheckERR(wnoutrefresh(self->win), "wnoutrefresh"); |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | static PyObject * |
| 1025 | PyCursesWindow_PutWin(self, arg) |
| 1026 | PyCursesWindowObject *self; |
| 1027 | PyObject *arg; |
| 1028 | { |
| 1029 | PyObject *temp; |
| 1030 | |
| 1031 | if (!PyArg_Parse(arg, "O;fileobj", &temp)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1032 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1033 | if (!PyFile_Check(temp)) { |
| 1034 | PyErr_SetString(PyExc_TypeError, "argument must be a file object"); |
| 1035 | return NULL; |
| 1036 | } |
| 1037 | return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)), |
| 1038 | "putwin"); |
| 1039 | } |
| 1040 | |
| 1041 | static PyObject * |
| 1042 | PyCursesWindow_RedrawLine(self,arg) |
| 1043 | PyCursesWindowObject *self; |
| 1044 | PyObject * arg; |
| 1045 | { |
| 1046 | int beg, num; |
| 1047 | if (!PyArg_Parse(arg,"(ii);beg,num", &beg, &num)) |
| 1048 | return NULL; |
| 1049 | return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln"); |
| 1050 | } |
| 1051 | |
| 1052 | static PyObject * |
| 1053 | PyCursesWindow_Refresh(self,arg) |
| 1054 | PyCursesWindowObject *self; |
| 1055 | PyObject * arg; |
| 1056 | { |
| 1057 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; |
| 1058 | |
| 1059 | if (self->win->_flags & _ISPAD) { |
| 1060 | switch(ARG_COUNT(arg)) { |
| 1061 | case 6: |
| 1062 | if (!PyArg_Parse(arg, |
| 1063 | "(iiiiii);" \ |
| 1064 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", |
| 1065 | &pminrow, &pmincol, &sminrow, |
| 1066 | &smincol, &smaxrow, &smaxcol)) |
| 1067 | return NULL; |
| 1068 | return PyCursesCheckERR(prefresh(self->win, |
| 1069 | pminrow, pmincol, sminrow, |
| 1070 | smincol, smaxrow, smaxcol), |
| 1071 | "prefresh"); |
| 1072 | default: |
| 1073 | PyErr_SetString(PyCursesError, |
| 1074 | "refresh was called for a pad; requires 6 arguments"); |
| 1075 | return NULL; |
| 1076 | } |
| 1077 | } else { |
| 1078 | if (!PyArg_NoArgs(arg)) |
| 1079 | return NULL; |
| 1080 | return PyCursesCheckERR(wrefresh(self->win), "wrefresh"); |
| 1081 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | static PyObject * |
| 1085 | PyCursesWindow_SetScrollRegion(self,arg) |
| 1086 | PyCursesWindowObject *self; |
| 1087 | PyObject * arg; |
| 1088 | { |
| 1089 | int x, y; |
| 1090 | if (!PyArg_Parse(arg,"(ii);top, bottom",&y,&x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1091 | return NULL; |
| 1092 | return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1096 | PyCursesWindow_SubWin(self,arg) |
| 1097 | PyCursesWindowObject *self; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1098 | PyObject * arg; |
| 1099 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1100 | WINDOW *win; |
| 1101 | int nlines, ncols, begin_y, begin_x; |
| 1102 | |
| 1103 | if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x", |
| 1104 | &nlines,&ncols,&begin_y,&begin_x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1105 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1106 | |
| 1107 | if (self->win->_flags & _ISPAD) |
| 1108 | win = subpad(self->win, nlines, ncols, begin_y, begin_x); |
| 1109 | else |
| 1110 | win = subwin(self->win,nlines,ncols,begin_y,begin_x); |
| 1111 | |
| 1112 | if (win == NULL) { |
| 1113 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1114 | return NULL; |
| 1115 | } |
| 1116 | |
| 1117 | return (PyObject *)PyCursesWindow_New(win); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1121 | PyCursesWindow_Scroll(self,arg) |
| 1122 | PyCursesWindowObject *self; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1123 | PyObject * arg; |
| 1124 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1125 | int lines; |
| 1126 | switch(ARG_COUNT(arg)) { |
| 1127 | case 0: |
| 1128 | return PyCursesCheckERR(scroll(self->win), "scroll"); |
| 1129 | break; |
| 1130 | case 1: |
| 1131 | if (!PyArg_Parse(arg, "i;lines", &lines)) |
| 1132 | return NULL; |
| 1133 | return PyCursesCheckERR(wscrl(self->win, lines), "scroll"); |
| 1134 | default: |
| 1135 | PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1136 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1137 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1141 | PyCursesWindow_TouchLine(self,arg) |
| 1142 | PyCursesWindowObject *self; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1143 | PyObject * arg; |
| 1144 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1145 | int st, cnt, val; |
| 1146 | switch (ARG_COUNT(arg)) { |
| 1147 | case 2: |
| 1148 | if (!PyArg_Parse(arg,"(ii);start,count",&st,&cnt)) |
| 1149 | return NULL; |
| 1150 | return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline"); |
| 1151 | break; |
| 1152 | case 3: |
| 1153 | if (!PyArg_Parse(arg, "(iii);start,count,val", &st, &cnt, &val)) |
| 1154 | return NULL; |
| 1155 | return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline"); |
| 1156 | default: |
| 1157 | PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1158 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | static PyObject * |
| 1163 | PyCursesWindow_Vline(self, args) |
| 1164 | PyCursesWindowObject *self; |
| 1165 | PyObject *args; |
| 1166 | { |
| 1167 | PyObject *temp; |
| 1168 | chtype ch; |
| 1169 | int n, x, y, code = OK; |
| 1170 | attr_t attr = A_NORMAL; |
| 1171 | |
| 1172 | switch (ARG_COUNT(args)) { |
| 1173 | case 2: |
| 1174 | if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n)) |
| 1175 | return NULL; |
| 1176 | break; |
| 1177 | case 3: |
| 1178 | if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr)) |
| 1179 | return NULL; |
| 1180 | break; |
| 1181 | case 4: |
| 1182 | if (!PyArg_Parse(args, "(iiOi);y,x,ch o int,n", &y, &x, &temp, &n)) |
| 1183 | return NULL; |
| 1184 | code = wmove(self->win, y, x); |
| 1185 | break; |
| 1186 | case 5: |
| 1187 | if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr", |
| 1188 | &y, &x, &temp, &n, &attr)) |
| 1189 | return NULL; |
| 1190 | code = wmove(self->win, y, x); |
| 1191 | default: |
| 1192 | PyErr_SetString(PyExc_TypeError, "vline requires 2 or 5 arguments"); |
| 1193 | return NULL; |
| 1194 | } |
| 1195 | |
| 1196 | if (code != ERR) { |
| 1197 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 1198 | PyErr_SetString(PyExc_TypeError, |
| 1199 | "argument 1 or 3 must be a ch or an int"); |
| 1200 | return NULL; |
| 1201 | } |
| 1202 | return PyCursesCheckERR(whline(self->win, ch | attr, n), "vline"); |
| 1203 | } else |
| 1204 | return PyCursesCheckERR(code, "wmove"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | static PyMethodDef PyCursesWindow_Methods[] = { |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1208 | {"addch", (PyCFunction)PyCursesWindow_AddCh}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1209 | {"addnstr", (PyCFunction)PyCursesWindow_AddNStr}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1210 | {"addstr", (PyCFunction)PyCursesWindow_AddStr}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1211 | {"attron", (PyCFunction)PyCursesWindow_wattron}, |
| 1212 | {"attr_on", (PyCFunction)PyCursesWindow_wattron}, |
| 1213 | {"attroff", (PyCFunction)PyCursesWindow_wattroff}, |
| 1214 | {"attr_off", (PyCFunction)PyCursesWindow_wattroff}, |
| 1215 | {"attrset", (PyCFunction)PyCursesWindow_wattrset}, |
| 1216 | {"attr_set", (PyCFunction)PyCursesWindow_wattrset}, |
| 1217 | {"bkgd", (PyCFunction)PyCursesWindow_Bkgd}, |
| 1218 | {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1219 | {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS}, |
| 1220 | {"box", (PyCFunction)PyCursesWindow_Box}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1221 | {"clear", (PyCFunction)PyCursesWindow_wclear}, |
| 1222 | {"clearok", (PyCFunction)PyCursesWindow_clearok}, |
| 1223 | {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot}, |
| 1224 | {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol}, |
| 1225 | {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup}, |
| 1226 | {"delch", (PyCFunction)PyCursesWindow_DelCh}, |
| 1227 | {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln}, |
| 1228 | {"derwin", (PyCFunction)PyCursesWindow_DerWin}, |
| 1229 | {"echochar", (PyCFunction)PyCursesWindow_EchoChar}, |
| 1230 | {"erase", (PyCFunction)PyCursesWindow_werase}, |
| 1231 | {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx}, |
| 1232 | {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1233 | {"getch", (PyCFunction)PyCursesWindow_GetCh}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1234 | {"getkey", (PyCFunction)PyCursesWindow_GetKey}, |
| 1235 | {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx}, |
| 1236 | {"getparyx", (PyCFunction)PyCursesWindow_getparyx}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1237 | {"getstr", (PyCFunction)PyCursesWindow_GetStr}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1238 | {"getyx", (PyCFunction)PyCursesWindow_getyx}, |
| 1239 | {"hline", (PyCFunction)PyCursesWindow_Hline}, |
| 1240 | {"idlok", (PyCFunction)PyCursesWindow_idlok}, |
| 1241 | {"idcok", (PyCFunction)PyCursesWindow_idcok}, |
| 1242 | {"immedok", (PyCFunction)PyCursesWindow_immedok}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1243 | {"inch", (PyCFunction)PyCursesWindow_InCh}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1244 | {"insch", (PyCFunction)PyCursesWindow_InsCh}, |
| 1245 | {"insdelln", (PyCFunction)PyCursesWindow_winsdelln}, |
| 1246 | {"insertln", (PyCFunction)PyCursesWindow_winsertln}, |
| 1247 | {"insnstr", (PyCFunction)PyCursesWindow_InsNStr}, |
| 1248 | {"insstr", (PyCFunction)PyCursesWindow_InsStr}, |
| 1249 | {"instr", (PyCFunction)PyCursesWindow_InStr}, |
| 1250 | {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched}, |
| 1251 | {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched}, |
| 1252 | {"keypad", (PyCFunction)PyCursesWindow_keypad}, |
| 1253 | {"leaveok", (PyCFunction)PyCursesWindow_leaveok}, |
| 1254 | {"move", (PyCFunction)PyCursesWindow_wmove}, |
| 1255 | {"mvwin", (PyCFunction)PyCursesWindow_mvwin}, |
| 1256 | {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin}, |
| 1257 | {"nodelay", (PyCFunction)PyCursesWindow_nodelay}, |
| 1258 | {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh}, |
| 1259 | {"notimeout", (PyCFunction)PyCursesWindow_notimeout}, |
| 1260 | {"putwin", (PyCFunction)PyCursesWindow_PutWin}, |
| 1261 | {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin}, |
| 1262 | {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine}, |
| 1263 | {"refresh", (PyCFunction)PyCursesWindow_Refresh}, |
| 1264 | #ifndef __sgi__ |
| 1265 | {"resize", (PyCFunction)PyCursesWindow_wresize}, |
| 1266 | #endif |
| 1267 | {"scroll", (PyCFunction)PyCursesWindow_Scroll}, |
| 1268 | {"scrollok", (PyCFunction)PyCursesWindow_scrollok}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1269 | {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1270 | {"standend", (PyCFunction)PyCursesWindow_wstandend}, |
| 1271 | {"standout", (PyCFunction)PyCursesWindow_wstandout}, |
| 1272 | {"subpad", (PyCFunction)PyCursesWindow_SubWin}, |
| 1273 | {"subwin", (PyCFunction)PyCursesWindow_SubWin}, |
| 1274 | {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown}, |
| 1275 | {"syncok", (PyCFunction)PyCursesWindow_syncok}, |
| 1276 | {"syncup", (PyCFunction)PyCursesWindow_wsyncup}, |
| 1277 | {"touchline", (PyCFunction)PyCursesWindow_TouchLine}, |
| 1278 | {"touchwin", (PyCFunction)PyCursesWindow_touchwin}, |
| 1279 | {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin}, |
| 1280 | {"vline", (PyCFunction)PyCursesWindow_Vline}, |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1281 | {NULL, NULL} /* sentinel */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1282 | }; |
| 1283 | |
| 1284 | static PyObject * |
| 1285 | PyCursesWindow_GetAttr(self, name) |
| 1286 | PyCursesWindowObject *self; |
| 1287 | char *name; |
| 1288 | { |
Guido van Rossum | a597dde | 1995-01-10 20:56:29 +0000 | [diff] [blame] | 1289 | return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1292 | /* -------------------------------------------------------*/ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1293 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1294 | PyTypeObject PyCursesWindow_Type = { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1295 | PyObject_HEAD_INIT(&PyType_Type) |
| 1296 | 0, /*ob_size*/ |
| 1297 | "curses window", /*tp_name*/ |
| 1298 | sizeof(PyCursesWindowObject), /*tp_basicsize*/ |
| 1299 | 0, /*tp_itemsize*/ |
| 1300 | /* methods */ |
| 1301 | (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/ |
| 1302 | 0, /*tp_print*/ |
| 1303 | (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/ |
| 1304 | (setattrfunc)0, /*tp_setattr*/ |
| 1305 | 0, /*tp_compare*/ |
| 1306 | 0, /*tp_repr*/ |
| 1307 | 0, /*tp_as_number*/ |
| 1308 | 0, /*tp_as_sequence*/ |
| 1309 | 0, /*tp_as_mapping*/ |
| 1310 | 0, /*tp_hash*/ |
| 1311 | }; |
| 1312 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1313 | /********************************************************************* |
| 1314 | Global Functions |
| 1315 | **********************************************************************/ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1316 | |
Guido van Rossum | e4485b0 | 1994-09-07 14:32:49 +0000 | [diff] [blame] | 1317 | static PyObject *ModDict; |
| 1318 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1319 | /* Function Prototype Macros - They are ugly but very, very useful. ;-) |
| 1320 | |
| 1321 | X - function name |
| 1322 | TYPE - parameter Type |
| 1323 | ERGSTR - format string for construction of the return value |
| 1324 | PARSESTR - format string for argument parsing |
| 1325 | */ |
| 1326 | |
| 1327 | #define NoArgNoReturnFunction(X) \ |
| 1328 | static PyObject *PyCurses_ ## X (self, arg) \ |
| 1329 | PyObject * self; \ |
| 1330 | PyObject * arg; \ |
| 1331 | { \ |
| 1332 | PyCursesInitialised \ |
| 1333 | if (!PyArg_NoArgs(arg)) return NULL; \ |
| 1334 | return PyCursesCheckERR(X(), # X); } |
| 1335 | |
| 1336 | #define NoArgOrFlagNoReturnFunction(X) \ |
| 1337 | static PyObject *PyCurses_ ## X (self, arg) \ |
| 1338 | PyObject * self; \ |
| 1339 | PyObject * arg; \ |
| 1340 | { \ |
| 1341 | int flag = 0; \ |
| 1342 | PyCursesInitialised \ |
| 1343 | switch(ARG_COUNT(arg)) { \ |
| 1344 | case 0: \ |
| 1345 | return PyCursesCheckERR(X(), # X); \ |
| 1346 | case 1: \ |
| 1347 | if (!PyArg_Parse(arg, "i;True(1) or False(0)", &flag)) return NULL; \ |
| 1348 | if (flag) return PyCursesCheckERR(X(), # X); \ |
| 1349 | else return PyCursesCheckERR(no ## X (), # X); \ |
| 1350 | default: \ |
| 1351 | PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 argument"); \ |
| 1352 | return NULL; } } |
| 1353 | |
| 1354 | #define NoArgReturnIntFunction(X) \ |
| 1355 | static PyObject *PyCurses_ ## X (self, arg) \ |
| 1356 | PyObject * self; \ |
| 1357 | PyObject * arg; \ |
| 1358 | { \ |
| 1359 | PyCursesInitialised \ |
| 1360 | if (!PyArg_NoArgs(arg)) return NULL; \ |
| 1361 | return PyInt_FromLong((long) X()); } |
| 1362 | |
| 1363 | |
| 1364 | #define NoArgReturnStringFunction(X) \ |
| 1365 | static PyObject *PyCurses_ ## X (self, arg) \ |
| 1366 | PyObject * self; \ |
| 1367 | PyObject * arg; \ |
| 1368 | { \ |
| 1369 | PyCursesInitialised \ |
| 1370 | if (!PyArg_NoArgs(arg)) return NULL; \ |
| 1371 | return PyString_FromString(X()); } |
| 1372 | |
| 1373 | #define NoArgTrueFalseFunction(X) \ |
| 1374 | static PyObject * PyCurses_ ## X (self,arg) \ |
| 1375 | PyObject * self; \ |
| 1376 | PyObject * arg; \ |
| 1377 | { \ |
| 1378 | PyCursesInitialised \ |
| 1379 | if (!PyArg_NoArgs(arg)) return NULL; \ |
| 1380 | if (X () == FALSE) { \ |
| 1381 | Py_INCREF(Py_False); \ |
| 1382 | return Py_False; \ |
| 1383 | } \ |
| 1384 | Py_INCREF(Py_True); \ |
| 1385 | return Py_True; } |
| 1386 | |
| 1387 | #define NoArgNoReturnVoidFunction(X) \ |
| 1388 | static PyObject * PyCurses_ ## X (self,arg) \ |
| 1389 | PyObject * self; \ |
| 1390 | PyObject * arg; \ |
| 1391 | { \ |
| 1392 | PyCursesInitialised \ |
| 1393 | if (!PyArg_NoArgs(arg)) return NULL; \ |
| 1394 | X(); \ |
| 1395 | Py_INCREF(Py_None); \ |
| 1396 | return Py_None; } |
| 1397 | |
| 1398 | NoArgNoReturnFunction(beep) |
| 1399 | NoArgNoReturnFunction(def_prog_mode) |
| 1400 | NoArgNoReturnFunction(def_shell_mode) |
| 1401 | NoArgNoReturnFunction(doupdate) |
| 1402 | NoArgNoReturnFunction(endwin) |
| 1403 | NoArgNoReturnFunction(flash) |
| 1404 | NoArgNoReturnFunction(nocbreak) |
| 1405 | NoArgNoReturnFunction(noecho) |
| 1406 | NoArgNoReturnFunction(nonl) |
| 1407 | NoArgNoReturnFunction(noraw) |
| 1408 | NoArgNoReturnFunction(reset_prog_mode) |
| 1409 | NoArgNoReturnFunction(reset_shell_mode) |
| 1410 | NoArgNoReturnFunction(resetty) |
| 1411 | NoArgNoReturnFunction(savetty) |
| 1412 | |
| 1413 | NoArgOrFlagNoReturnFunction(cbreak) |
| 1414 | NoArgOrFlagNoReturnFunction(echo) |
| 1415 | NoArgOrFlagNoReturnFunction(nl) |
| 1416 | NoArgOrFlagNoReturnFunction(raw) |
| 1417 | |
| 1418 | NoArgReturnIntFunction(baudrate) |
| 1419 | NoArgReturnIntFunction(termattrs) |
| 1420 | |
| 1421 | NoArgReturnStringFunction(termname) |
| 1422 | NoArgReturnStringFunction(longname) |
| 1423 | |
| 1424 | NoArgTrueFalseFunction(can_change_color) |
| 1425 | NoArgTrueFalseFunction(has_colors) |
| 1426 | NoArgTrueFalseFunction(has_ic) |
| 1427 | NoArgTrueFalseFunction(has_il) |
| 1428 | NoArgTrueFalseFunction(isendwin) |
| 1429 | |
| 1430 | NoArgNoReturnVoidFunction(filter) |
| 1431 | NoArgNoReturnVoidFunction(flushinp) |
| 1432 | NoArgNoReturnVoidFunction(noqiflush) |
| 1433 | |
| 1434 | static PyObject * |
| 1435 | PyCurses_Color_Content(self, arg) |
| 1436 | PyObject * self; |
| 1437 | PyObject * arg; |
| 1438 | { |
| 1439 | short color,r,g,b; |
| 1440 | |
| 1441 | PyCursesInitialised |
| 1442 | PyCursesInitialisedColor |
| 1443 | |
| 1444 | if (ARG_COUNT(arg) != 1) { |
| 1445 | PyErr_SetString(PyExc_TypeError, |
| 1446 | "color_content requires 1 argument"); |
| 1447 | return NULL; |
| 1448 | } |
| 1449 | |
| 1450 | if (!PyArg_Parse(arg, "h;color", &color)) return NULL; |
| 1451 | |
| 1452 | if (color_content(color, &r, &g, &b) != ERR) |
| 1453 | return Py_BuildValue("(iii)", r, g, b); |
| 1454 | else { |
| 1455 | PyErr_SetString(PyCursesError, |
| 1456 | "Argument 1 was out of range. Check value of COLORS."); |
| 1457 | return NULL; |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | static PyObject * |
| 1462 | PyCurses_COLOR_PAIR(self, arg) |
| 1463 | PyObject * self; |
| 1464 | PyObject * arg; |
| 1465 | { |
| 1466 | int n; |
| 1467 | |
| 1468 | PyCursesInitialised |
| 1469 | PyCursesInitialisedColor |
| 1470 | |
| 1471 | if (ARG_COUNT(arg)!=1) { |
| 1472 | PyErr_SetString(PyExc_TypeError, "COLOR_PAIR requires 1 argument"); |
| 1473 | return NULL; |
| 1474 | } |
| 1475 | if (!PyArg_Parse(arg, "i;number", &n)) return NULL; |
| 1476 | return PyInt_FromLong((long) (n << 8)); |
| 1477 | } |
| 1478 | |
| 1479 | static PyObject * |
| 1480 | PyCurses_Curs_Set(self, arg) |
| 1481 | PyObject * self; |
| 1482 | PyObject * arg; |
| 1483 | { |
| 1484 | int vis,erg; |
| 1485 | |
| 1486 | PyCursesInitialised |
| 1487 | |
| 1488 | if (ARG_COUNT(arg)==1) { |
| 1489 | PyErr_SetString(PyExc_TypeError, "curs_set requires 1 argument"); |
| 1490 | return NULL; |
| 1491 | } |
| 1492 | |
| 1493 | if (!PyArg_Parse(arg, "i;int", &vis)) return NULL; |
| 1494 | |
| 1495 | erg = curs_set(vis); |
| 1496 | if (erg == ERR) return PyCursesCheckERR(erg, "curs_set"); |
| 1497 | |
| 1498 | return PyInt_FromLong((long) erg); |
| 1499 | } |
| 1500 | |
| 1501 | static PyObject * |
| 1502 | PyCurses_Delay_Output(self,arg) |
| 1503 | PyObject * self; |
| 1504 | PyObject * arg; |
| 1505 | { |
| 1506 | int ms; |
| 1507 | |
| 1508 | PyCursesInitialised |
| 1509 | |
| 1510 | if (ARG_COUNT(arg)==1) { |
| 1511 | PyErr_SetString(PyExc_TypeError, "delay_output requires 1 argument"); |
| 1512 | return NULL; |
| 1513 | } |
| 1514 | if (!PyArg_Parse(arg, "i;ms", &ms)) return NULL; |
| 1515 | |
| 1516 | return PyCursesCheckERR(delay_output(ms), "delay_output"); |
| 1517 | } |
| 1518 | |
| 1519 | static PyObject * |
| 1520 | PyCurses_EraseChar(self,arg) |
| 1521 | PyObject * self; |
| 1522 | PyObject * arg; |
| 1523 | { |
| 1524 | char ch; |
| 1525 | |
| 1526 | PyCursesInitialised |
| 1527 | |
| 1528 | if (!PyArg_NoArgs(arg)) return NULL; |
| 1529 | |
| 1530 | ch = erasechar(); |
| 1531 | |
| 1532 | return PyString_FromString(&ch); |
| 1533 | } |
| 1534 | |
| 1535 | static PyObject * |
| 1536 | PyCurses_getsyx(self, arg) |
| 1537 | PyObject * self; |
| 1538 | PyObject * arg; |
| 1539 | { |
| 1540 | int x,y; |
| 1541 | |
| 1542 | PyCursesInitialised |
| 1543 | |
| 1544 | if (!PyArg_NoArgs(arg)) return NULL; |
| 1545 | |
| 1546 | getsyx(y, x); |
| 1547 | |
| 1548 | return Py_BuildValue("(ii)", y, x); |
| 1549 | } |
| 1550 | |
| 1551 | static PyObject * |
| 1552 | PyCurses_GetWin(self,arg) |
| 1553 | PyCursesWindowObject *self; |
| 1554 | PyObject * arg; |
| 1555 | { |
| 1556 | WINDOW *win; |
| 1557 | PyObject *temp; |
| 1558 | |
| 1559 | PyCursesInitialised |
| 1560 | |
| 1561 | if (!PyArg_Parse(arg, "O;fileobj", &temp)) return NULL; |
| 1562 | |
| 1563 | if (!PyFile_Check(temp)) { |
| 1564 | PyErr_SetString(PyExc_TypeError, "argument must be a file object"); |
| 1565 | return NULL; |
| 1566 | } |
| 1567 | |
| 1568 | win = getwin(PyFile_AsFile(temp)); |
| 1569 | |
| 1570 | if (win == NULL) { |
| 1571 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1572 | return NULL; |
| 1573 | } |
| 1574 | |
| 1575 | return PyCursesWindow_New(win); |
| 1576 | } |
| 1577 | |
| 1578 | static PyObject * |
| 1579 | PyCurses_HalfDelay(self,arg) |
| 1580 | PyObject * self; |
| 1581 | PyObject * arg; |
| 1582 | { |
| 1583 | unsigned char tenths; |
| 1584 | |
| 1585 | PyCursesInitialised |
| 1586 | |
| 1587 | switch(ARG_COUNT(arg)) { |
| 1588 | case 1: |
| 1589 | if (!PyArg_Parse(arg, "b;tenths", &tenths)) return NULL; |
| 1590 | break; |
| 1591 | default: |
| 1592 | PyErr_SetString(PyExc_TypeError, "halfdelay requires 1 argument"); |
| 1593 | return NULL; |
| 1594 | } |
| 1595 | |
| 1596 | return PyCursesCheckERR(halfdelay(tenths), "halfdelay"); |
| 1597 | } |
| 1598 | |
| 1599 | #ifndef __sgi__ |
| 1600 | /* No has_key! */ |
| 1601 | static PyObject * PyCurses_has_key(self,arg) |
| 1602 | PyObject * self; |
| 1603 | PyObject * arg; |
| 1604 | { |
| 1605 | int ch; |
| 1606 | |
| 1607 | PyCursesInitialised |
| 1608 | |
| 1609 | if (!PyArg_Parse(arg,"i",&ch)) return NULL; |
| 1610 | |
| 1611 | if (has_key(ch) == FALSE) { |
| 1612 | Py_INCREF(Py_False); |
| 1613 | return Py_False; |
| 1614 | } |
| 1615 | Py_INCREF(Py_True); |
| 1616 | return Py_True; |
| 1617 | } |
| 1618 | #endif |
| 1619 | |
| 1620 | static PyObject * |
| 1621 | PyCurses_Init_Color(self, arg) |
| 1622 | PyObject * self; |
| 1623 | PyObject * arg; |
| 1624 | { |
| 1625 | short color, r, g, b; |
| 1626 | |
| 1627 | PyCursesInitialised |
| 1628 | PyCursesInitialisedColor |
| 1629 | |
| 1630 | switch(ARG_COUNT(arg)) { |
| 1631 | case 4: |
| 1632 | if (!PyArg_Parse(arg, "(hhhh);color,r,g,b", &color, &r, &g, &b)) return NULL; |
| 1633 | break; |
| 1634 | default: |
| 1635 | PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments"); |
| 1636 | return NULL; |
| 1637 | } |
| 1638 | |
| 1639 | return PyCursesCheckERR(init_color(color, r, g, b), "init_color"); |
| 1640 | } |
| 1641 | |
| 1642 | static PyObject * |
| 1643 | PyCurses_Init_Pair(self, arg) |
| 1644 | PyObject * self; |
| 1645 | PyObject * arg; |
| 1646 | { |
| 1647 | short pair, f, b; |
| 1648 | |
| 1649 | PyCursesInitialised |
| 1650 | PyCursesInitialisedColor |
| 1651 | |
| 1652 | if (ARG_COUNT(arg) == 3) { |
| 1653 | PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments"); |
| 1654 | return NULL; |
| 1655 | } |
| 1656 | |
| 1657 | if (!PyArg_Parse(arg, "(hhh);pair, f, b", &pair, &f, &b)) return NULL; |
| 1658 | |
| 1659 | return PyCursesCheckERR(init_pair(pair, f, b), "init_pair"); |
| 1660 | } |
| 1661 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1662 | static PyObject * |
| 1663 | PyCurses_InitScr(self, args) |
| 1664 | PyObject * self; |
| 1665 | PyObject * args; |
| 1666 | { |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1667 | WINDOW *win; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1668 | PyObject *lines, *cols; |
| 1669 | |
| 1670 | if (!PyArg_NoArgs(args)) return NULL; |
| 1671 | |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1672 | if (initialised == TRUE) { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1673 | wrefresh(stdscr); |
| 1674 | return (PyObject *)PyCursesWindow_New(stdscr); |
| 1675 | } |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1676 | |
| 1677 | win = initscr(); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1678 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1679 | if (win == NULL) { |
| 1680 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1681 | return NULL; |
| 1682 | } |
| 1683 | |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1684 | initialised = TRUE; |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1685 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1686 | lines = PyInt_FromLong((long) LINES); |
| 1687 | PyDict_SetItemString(ModDict, "LINES", lines); |
| 1688 | Py_DECREF(lines); |
| 1689 | cols = PyInt_FromLong((long) COLS); |
| 1690 | PyDict_SetItemString(ModDict, "COLS", cols); |
| 1691 | Py_DECREF(cols); |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1692 | |
| 1693 | return (PyObject *)PyCursesWindow_New(win); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1696 | |
| 1697 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1698 | PyCurses_IntrFlush(self,arg) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1699 | PyObject * self; |
| 1700 | PyObject * arg; |
| 1701 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1702 | int ch; |
| 1703 | |
| 1704 | PyCursesInitialised |
| 1705 | |
| 1706 | switch(ARG_COUNT(arg)) { |
| 1707 | case 1: |
| 1708 | if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch)) return NULL; |
| 1709 | break; |
| 1710 | default: |
| 1711 | PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1712 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1713 | } |
| 1714 | |
| 1715 | return PyCursesCheckERR(intrflush(NULL,ch), "intrflush"); |
| 1716 | } |
| 1717 | |
| 1718 | static PyObject * |
| 1719 | PyCurses_KeyName(self,arg) |
| 1720 | PyObject * self; |
| 1721 | PyObject * arg; |
| 1722 | { |
| 1723 | const char *knp; |
| 1724 | int ch; |
| 1725 | |
| 1726 | PyCursesInitialised |
| 1727 | |
| 1728 | if (!PyArg_Parse(arg,"i",&ch)) return NULL; |
| 1729 | |
| 1730 | knp = keyname(ch); |
| 1731 | |
| 1732 | return PyString_FromString((knp == NULL) ? "" : (char *)knp); |
| 1733 | } |
| 1734 | |
| 1735 | static PyObject * |
| 1736 | PyCurses_KillChar(self,arg) |
| 1737 | PyObject * self; |
| 1738 | PyObject * arg; |
| 1739 | { |
| 1740 | char ch; |
| 1741 | |
| 1742 | if (!PyArg_NoArgs(arg)) return NULL; |
| 1743 | |
| 1744 | ch = killchar(); |
| 1745 | |
| 1746 | return PyString_FromString(&ch); |
| 1747 | } |
| 1748 | |
| 1749 | static PyObject * |
| 1750 | PyCurses_Meta(self,arg) |
| 1751 | PyObject * self; |
| 1752 | PyObject * arg; |
| 1753 | { |
| 1754 | int ch; |
| 1755 | |
| 1756 | PyCursesInitialised |
| 1757 | |
| 1758 | switch(ARG_COUNT(arg)) { |
| 1759 | case 1: |
| 1760 | if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch)) return NULL; |
| 1761 | break; |
| 1762 | default: |
| 1763 | PyErr_SetString(PyExc_TypeError, "meta requires 1 argument"); |
| 1764 | return NULL; |
| 1765 | } |
| 1766 | |
| 1767 | return PyCursesCheckERR(meta(stdscr, ch), "meta"); |
| 1768 | } |
| 1769 | |
| 1770 | static PyObject * |
| 1771 | PyCurses_NewPad(self,arg) |
| 1772 | PyObject * self; |
| 1773 | PyObject * arg; |
| 1774 | { |
| 1775 | WINDOW *win; |
| 1776 | int nlines, ncols; |
| 1777 | |
| 1778 | PyCursesInitialised |
| 1779 | |
| 1780 | if (!PyArg_Parse(arg,"(ii);nlines,ncols",&nlines,&ncols)) return NULL; |
| 1781 | |
| 1782 | win = newpad(nlines, ncols); |
| 1783 | |
| 1784 | if (win == NULL) { |
| 1785 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1786 | return NULL; |
| 1787 | } |
| 1788 | |
| 1789 | return (PyObject *)PyCursesWindow_New(win); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | static PyObject * |
| 1793 | PyCurses_NewWindow(self,arg) |
| 1794 | PyObject * self; |
| 1795 | PyObject * arg; |
| 1796 | { |
| 1797 | WINDOW *win; |
| 1798 | int nlines, ncols, begin_y, begin_x; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1799 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1800 | PyCursesInitialised |
| 1801 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1802 | switch (ARG_COUNT(arg)) { |
| 1803 | case 2: |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1804 | if (!PyArg_Parse(arg,"(ii);nlines,ncols",&nlines,&ncols)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1805 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1806 | win = newpad(nlines, ncols); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | case 4: |
| 1809 | if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x", |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1810 | &nlines,&ncols,&begin_y,&begin_x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1811 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1812 | win = newwin(nlines,ncols,begin_y,begin_x); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1813 | break; |
| 1814 | default: |
| 1815 | PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments"); |
| 1816 | return NULL; |
| 1817 | } |
| 1818 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1819 | if (win == NULL) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1820 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1821 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1822 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1823 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1824 | return (PyObject *)PyCursesWindow_New(win); |
| 1825 | } |
| 1826 | |
| 1827 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1828 | PyCurses_Pair_Content(self, arg) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1829 | PyObject * self; |
| 1830 | PyObject * arg; |
| 1831 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1832 | short pair,f,b; |
| 1833 | |
| 1834 | PyCursesInitialised |
| 1835 | PyCursesInitialisedColor |
| 1836 | |
| 1837 | switch(ARG_COUNT(arg)) { |
| 1838 | case 1: |
| 1839 | if (!PyArg_Parse(arg, "h;pair", &pair)) return NULL; |
| 1840 | break; |
| 1841 | default: |
| 1842 | PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1843 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1844 | } |
| 1845 | |
| 1846 | if (!pair_content(pair, &f, &b)) { |
| 1847 | PyErr_SetString(PyCursesError, |
| 1848 | "Argument 1 was out of range. (1..COLOR_PAIRS-1)"); |
| 1849 | return NULL; |
| 1850 | } |
| 1851 | |
| 1852 | return Py_BuildValue("(ii)", f, b); |
| 1853 | } |
| 1854 | |
| 1855 | static PyObject * |
| 1856 | PyCurses_PAIR_NUMBER(self, arg) |
| 1857 | PyObject * self; |
| 1858 | PyObject * arg; |
| 1859 | { |
| 1860 | int n; |
| 1861 | |
| 1862 | PyCursesInitialised |
| 1863 | PyCursesInitialisedColor |
| 1864 | |
| 1865 | switch(ARG_COUNT(arg)) { |
| 1866 | case 1: |
| 1867 | if (!PyArg_Parse(arg, "i;pairvalue", &n)) return NULL; |
| 1868 | break; |
| 1869 | default: |
| 1870 | PyErr_SetString(PyExc_TypeError, |
| 1871 | "PAIR_NUMBER requires 1 argument"); |
| 1872 | return NULL; |
| 1873 | } |
| 1874 | |
| 1875 | return PyInt_FromLong((long) ((n & A_COLOR) >> 8)); |
| 1876 | } |
| 1877 | |
| 1878 | static PyObject * |
| 1879 | PyCurses_Putp(self,arg) |
| 1880 | PyObject *self; |
| 1881 | PyObject *arg; |
| 1882 | { |
| 1883 | char *str; |
| 1884 | |
| 1885 | if (!PyArg_Parse(arg,"s;str", &str)) return NULL; |
| 1886 | return PyCursesCheckERR(putp(str), "putp"); |
| 1887 | } |
| 1888 | |
| 1889 | static PyObject * |
| 1890 | PyCurses_QiFlush(self, arg) |
| 1891 | PyObject * self; |
| 1892 | PyObject * arg; |
| 1893 | { |
| 1894 | int flag = 0; |
| 1895 | |
| 1896 | PyCursesInitialised |
| 1897 | |
| 1898 | switch(ARG_COUNT(arg)) { |
| 1899 | case 0: |
| 1900 | qiflush(); |
| 1901 | Py_INCREF(Py_None); |
| 1902 | return Py_None; |
| 1903 | case 1: |
| 1904 | if (!PyArg_Parse(arg, "i;True(1) or False(0)", &flag)) return NULL; |
| 1905 | if (flag) qiflush(); |
| 1906 | else noqiflush(); |
| 1907 | Py_INCREF(Py_None); |
| 1908 | return Py_None; |
| 1909 | default: |
| 1910 | PyErr_SetString(PyExc_TypeError, "nl requires 0 or 1 argument"); |
| 1911 | return NULL; |
| 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | static PyObject * |
| 1916 | PyCurses_setsyx(self, arg) |
| 1917 | PyObject * self; |
| 1918 | PyObject * arg; |
| 1919 | { |
| 1920 | int y,x; |
| 1921 | |
| 1922 | PyCursesInitialised |
| 1923 | |
| 1924 | if (ARG_COUNT(arg)!=3) { |
| 1925 | PyErr_SetString(PyExc_TypeError, "curs_set requires 3 argument"); |
| 1926 | return NULL; |
| 1927 | } |
| 1928 | |
| 1929 | if (!PyArg_Parse(arg, "(ii);y, x", &y, &x)) return NULL; |
| 1930 | |
| 1931 | setsyx(y,x); |
| 1932 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1933 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1934 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1938 | PyCurses_Start_Color(self,arg) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1939 | PyObject * self; |
| 1940 | PyObject * arg; |
| 1941 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1942 | int code; |
| 1943 | PyObject *c, *cp; |
| 1944 | |
| 1945 | PyCursesInitialised |
| 1946 | |
| 1947 | if (!PyArg_NoArgs(arg)) return NULL; |
| 1948 | |
| 1949 | code = start_color(); |
| 1950 | if (code != ERR) { |
| 1951 | initialisedcolors = TRUE; |
| 1952 | c = PyInt_FromLong((long) COLORS); |
| 1953 | PyDict_SetItemString(ModDict, "COLORS", c); |
| 1954 | Py_DECREF(c); |
| 1955 | cp = PyInt_FromLong((long) COLOR_PAIRS); |
| 1956 | PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp); |
| 1957 | Py_DECREF(cp); |
| 1958 | Py_INCREF(Py_None); |
| 1959 | return Py_None; |
| 1960 | } else { |
| 1961 | PyErr_SetString(PyCursesError, "start_color() returned ERR"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1962 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1963 | } |
| 1964 | } |
| 1965 | |
| 1966 | static PyObject * |
| 1967 | PyCurses_UnCtrl(self,arg) |
| 1968 | PyObject * self; |
| 1969 | PyObject * arg; |
| 1970 | { |
| 1971 | PyObject *temp; |
| 1972 | chtype ch; |
| 1973 | |
| 1974 | PyCursesInitialised |
| 1975 | |
| 1976 | if (!PyArg_Parse(arg,"O;ch or int",&temp)) return NULL; |
| 1977 | |
| 1978 | if (PyInt_Check(temp)) |
| 1979 | ch = (chtype) PyInt_AsLong(temp); |
| 1980 | else if (PyString_Check(temp)) |
| 1981 | ch = (chtype) *PyString_AsString(temp); |
| 1982 | else { |
| 1983 | PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int"); |
| 1984 | return NULL; |
| 1985 | } |
| 1986 | |
| 1987 | return PyString_FromString(unctrl(ch)); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | static PyObject * |
| 1991 | PyCurses_UngetCh(self,arg) |
| 1992 | PyObject * self; |
| 1993 | PyObject * arg; |
| 1994 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 1995 | PyObject *temp; |
| 1996 | chtype ch; |
| 1997 | |
| 1998 | PyCursesInitialised |
| 1999 | |
| 2000 | if (!PyArg_Parse(arg,"O;ch or int",&temp)) return NULL; |
| 2001 | |
| 2002 | if (PyInt_Check(temp)) |
| 2003 | ch = (chtype) PyInt_AsLong(temp); |
| 2004 | else if (PyString_Check(temp)) |
| 2005 | ch = (chtype) *PyString_AsString(temp); |
| 2006 | else { |
| 2007 | PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2008 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 2009 | } |
| 2010 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2011 | return PyCursesCheckERR(ungetch(ch), "ungetch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | static PyObject * |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 2015 | PyCurses_Use_Env(self,arg) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2016 | PyObject * self; |
| 2017 | PyObject * arg; |
| 2018 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 2019 | int flag; |
| 2020 | |
| 2021 | PyCursesInitialised |
| 2022 | |
| 2023 | switch(ARG_COUNT(arg)) { |
| 2024 | case 1: |
| 2025 | if (!PyArg_Parse(arg,"i;True(1), False(0)",&flag)) |
| 2026 | return NULL; |
| 2027 | break; |
| 2028 | default: |
| 2029 | PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2030 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 2031 | } |
| 2032 | use_env(flag); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2033 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2034 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2037 | /* List of functions defined in the module */ |
| 2038 | |
| 2039 | static PyMethodDef PyCurses_methods[] = { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 2040 | {"baudrate", (PyCFunction)PyCurses_baudrate}, |
| 2041 | {"beep", (PyCFunction)PyCurses_beep}, |
| 2042 | {"can_change_color", (PyCFunction)PyCurses_can_change_color}, |
| 2043 | {"cbreak", (PyCFunction)PyCurses_cbreak}, |
| 2044 | {"color_content", (PyCFunction)PyCurses_Color_Content}, |
| 2045 | {"COLOR_PAIR", (PyCFunction)PyCurses_COLOR_PAIR}, |
| 2046 | {"curs_set", (PyCFunction)PyCurses_Curs_Set}, |
| 2047 | {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode}, |
| 2048 | {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode}, |
| 2049 | {"delay_output", (PyCFunction)PyCurses_Delay_Output}, |
| 2050 | {"doupdate", (PyCFunction)PyCurses_doupdate}, |
| 2051 | {"echo", (PyCFunction)PyCurses_echo}, |
| 2052 | {"endwin", (PyCFunction)PyCurses_endwin}, |
| 2053 | {"erasechar", (PyCFunction)PyCurses_EraseChar}, |
| 2054 | {"filter", (PyCFunction)PyCurses_filter}, |
| 2055 | {"flash", (PyCFunction)PyCurses_flash}, |
| 2056 | {"flushinp", (PyCFunction)PyCurses_flushinp}, |
| 2057 | {"getsyx", (PyCFunction)PyCurses_getsyx}, |
| 2058 | {"getwin", (PyCFunction)PyCurses_GetWin}, |
| 2059 | {"has_colors", (PyCFunction)PyCurses_has_colors}, |
| 2060 | {"has_ic", (PyCFunction)PyCurses_has_ic}, |
| 2061 | {"has_il", (PyCFunction)PyCurses_has_il}, |
| 2062 | #ifndef __sgi__ |
| 2063 | {"has_key", (PyCFunction)PyCurses_has_key}, |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2064 | #endif |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 2065 | {"halfdelay", (PyCFunction)PyCurses_HalfDelay}, |
| 2066 | {"init_color", (PyCFunction)PyCurses_Init_Color}, |
| 2067 | {"init_pair", (PyCFunction)PyCurses_Init_Pair}, |
| 2068 | {"initscr", (PyCFunction)PyCurses_InitScr}, |
| 2069 | {"intrflush", (PyCFunction)PyCurses_IntrFlush}, |
| 2070 | {"isendwin", (PyCFunction)PyCurses_isendwin}, |
| 2071 | {"keyname", (PyCFunction)PyCurses_KeyName}, |
| 2072 | {"killchar", (PyCFunction)PyCurses_KillChar}, |
| 2073 | {"longname", (PyCFunction)PyCurses_longname}, |
| 2074 | {"meta", (PyCFunction)PyCurses_Meta}, |
| 2075 | {"newpad", (PyCFunction)PyCurses_NewPad}, |
| 2076 | {"newwin", (PyCFunction)PyCurses_NewWindow}, |
| 2077 | {"nl", (PyCFunction)PyCurses_nl}, |
| 2078 | {"nocbreak", (PyCFunction)PyCurses_nocbreak}, |
| 2079 | {"noecho", (PyCFunction)PyCurses_noecho}, |
| 2080 | {"nonl", (PyCFunction)PyCurses_nonl}, |
| 2081 | {"noqiflush", (PyCFunction)PyCurses_noqiflush}, |
| 2082 | {"noraw", (PyCFunction)PyCurses_noraw}, |
| 2083 | {"pair_content", (PyCFunction)PyCurses_Pair_Content}, |
| 2084 | {"PAIR_NUMBER", (PyCFunction)PyCurses_PAIR_NUMBER}, |
| 2085 | {"putp", (PyCFunction)PyCurses_Putp}, |
| 2086 | {"qiflush", (PyCFunction)PyCurses_QiFlush}, |
| 2087 | {"raw", (PyCFunction)PyCurses_raw}, |
| 2088 | {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode}, |
| 2089 | {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode}, |
| 2090 | {"setsyx", (PyCFunction)PyCurses_setsyx}, |
| 2091 | {"start_color", (PyCFunction)PyCurses_Start_Color}, |
| 2092 | {"termattrs", (PyCFunction)PyCurses_termattrs}, |
| 2093 | {"termname", (PyCFunction)PyCurses_termname}, |
| 2094 | {"unctrl", (PyCFunction)PyCurses_UnCtrl}, |
| 2095 | {"ungetch", (PyCFunction)PyCurses_UngetCh}, |
| 2096 | {"use_env", (PyCFunction)PyCurses_Use_Env}, |
| 2097 | {NULL, NULL} /* sentinel */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2098 | }; |
| 2099 | |
| 2100 | /* Initialization function for the module */ |
| 2101 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 2102 | void |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 2103 | initcurses() |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2104 | { |
Guido van Rossum | 8fbf82b | 1995-02-17 13:54:04 +0000 | [diff] [blame] | 2105 | PyObject *m, *d, *v; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2106 | |
| 2107 | /* Create the module and add the functions */ |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 2108 | m = Py_InitModule("curses", PyCurses_methods); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2109 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2110 | /* Add some symbolic constants to the module */ |
| 2111 | d = PyModule_GetDict(m); |
Guido van Rossum | e4485b0 | 1994-09-07 14:32:49 +0000 | [diff] [blame] | 2112 | ModDict = d; /* For PyCurses_InitScr */ |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 2113 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2114 | /* For exception curses.error */ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 2115 | PyCursesError = PyString_FromString("curses.error"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2116 | PyDict_SetItemString(d, "error", PyCursesError); |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 2117 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2118 | /* Make the version available */ |
Guido van Rossum | 8fbf82b | 1995-02-17 13:54:04 +0000 | [diff] [blame] | 2119 | v = PyString_FromString(PyCursesVersion); |
| 2120 | PyDict_SetItemString(d, "version", v); |
| 2121 | PyDict_SetItemString(d, "__version__", v); |
| 2122 | Py_DECREF(v); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2123 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2124 | /* Here are some attributes you can add to chars to print */ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 2125 | |
| 2126 | #define SetDictInt(string,ch) \ |
| 2127 | PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch))); |
| 2128 | |
| 2129 | #ifndef __sgi__ |
| 2130 | /* On IRIX 5.3, the ACS characters aren't available until initscr() has been called. */ |
| 2131 | SetDictInt("ACS_ULCORNER", (ACS_ULCORNER)); |
| 2132 | SetDictInt("ACS_LLCORNER", (ACS_LLCORNER)); |
| 2133 | SetDictInt("ACS_URCORNER", (ACS_URCORNER)); |
| 2134 | SetDictInt("ACS_LRCORNER", (ACS_LRCORNER)); |
| 2135 | SetDictInt("ACS_LTEE", (ACS_LTEE)); |
| 2136 | SetDictInt("ACS_RTEE", (ACS_RTEE)); |
| 2137 | SetDictInt("ACS_BTEE", (ACS_BTEE)); |
| 2138 | SetDictInt("ACS_TTEE", (ACS_TTEE)); |
| 2139 | SetDictInt("ACS_HLINE", (ACS_HLINE)); |
| 2140 | SetDictInt("ACS_VLINE", (ACS_VLINE)); |
| 2141 | SetDictInt("ACS_PLUS", (ACS_PLUS)); |
| 2142 | SetDictInt("ACS_S1", (ACS_S1)); |
| 2143 | SetDictInt("ACS_S9", (ACS_S9)); |
| 2144 | SetDictInt("ACS_DIAMOND", (ACS_DIAMOND)); |
| 2145 | SetDictInt("ACS_CKBOARD", (ACS_CKBOARD)); |
| 2146 | SetDictInt("ACS_DEGREE", (ACS_DEGREE)); |
| 2147 | SetDictInt("ACS_PLMINUS", (ACS_PLMINUS)); |
| 2148 | SetDictInt("ACS_BULLET", (ACS_BULLET)); |
| 2149 | SetDictInt("ACS_LARROW", (ACS_LARROW)); |
| 2150 | SetDictInt("ACS_RARROW", (ACS_RARROW)); |
| 2151 | SetDictInt("ACS_DARROW", (ACS_DARROW)); |
| 2152 | SetDictInt("ACS_UARROW", (ACS_UARROW)); |
| 2153 | SetDictInt("ACS_BOARD", (ACS_BOARD)); |
| 2154 | SetDictInt("ACS_LANTERN", (ACS_LANTERN)); |
| 2155 | SetDictInt("ACS_BLOCK", (ACS_BLOCK)); |
| 2156 | #ifndef __sgi__ |
| 2157 | /* The following are never available on IRIX 5.3 */ |
| 2158 | SetDictInt("ACS_S3", (ACS_S3)); |
| 2159 | SetDictInt("ACS_LEQUAL", (ACS_LEQUAL)); |
| 2160 | SetDictInt("ACS_GEQUAL", (ACS_GEQUAL)); |
| 2161 | SetDictInt("ACS_PI", (ACS_PI)); |
| 2162 | SetDictInt("ACS_NEQUAL", (ACS_NEQUAL)); |
| 2163 | SetDictInt("ACS_STERLING", (ACS_STERLING)); |
| 2164 | #endif |
| 2165 | SetDictInt("ACS_BSSB", (ACS_ULCORNER)); |
| 2166 | SetDictInt("ACS_SSBB", (ACS_LLCORNER)); |
| 2167 | SetDictInt("ACS_BBSS", (ACS_URCORNER)); |
| 2168 | SetDictInt("ACS_SBBS", (ACS_LRCORNER)); |
| 2169 | SetDictInt("ACS_SBSS", (ACS_RTEE)); |
| 2170 | SetDictInt("ACS_SSSB", (ACS_LTEE)); |
| 2171 | SetDictInt("ACS_SSBS", (ACS_BTEE)); |
| 2172 | SetDictInt("ACS_BSSS", (ACS_TTEE)); |
| 2173 | SetDictInt("ACS_BSBS", (ACS_HLINE)); |
| 2174 | SetDictInt("ACS_SBSB", (ACS_VLINE)); |
| 2175 | SetDictInt("ACS_SSSS", (ACS_PLUS)); |
| 2176 | #endif |
| 2177 | |
| 2178 | SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES); |
| 2179 | SetDictInt("A_NORMAL", A_NORMAL); |
| 2180 | SetDictInt("A_STANDOUT", A_STANDOUT); |
| 2181 | SetDictInt("A_UNDERLINE", A_UNDERLINE); |
| 2182 | SetDictInt("A_REVERSE", A_REVERSE); |
| 2183 | SetDictInt("A_BLINK", A_BLINK); |
| 2184 | SetDictInt("A_DIM", A_DIM); |
| 2185 | SetDictInt("A_BOLD", A_BOLD); |
| 2186 | SetDictInt("A_ALTCHARSET", A_ALTCHARSET); |
| 2187 | SetDictInt("A_INVIS", A_INVIS); |
| 2188 | SetDictInt("A_PROTECT", A_PROTECT); |
| 2189 | #ifndef __sgi__ |
| 2190 | SetDictInt("A_HORIZONTAL", A_HORIZONTAL); |
| 2191 | SetDictInt("A_LEFT", A_LEFT); |
| 2192 | SetDictInt("A_LOW", A_LOW); |
| 2193 | SetDictInt("A_RIGHT", A_RIGHT); |
| 2194 | SetDictInt("A_TOP", A_TOP); |
| 2195 | SetDictInt("A_VERTICAL", A_VERTICAL); |
| 2196 | #endif |
| 2197 | SetDictInt("A_CHARTEXT", A_CHARTEXT); |
| 2198 | SetDictInt("A_COLOR", A_COLOR); |
| 2199 | #ifndef __sgi__ |
| 2200 | SetDictInt("WA_ATTRIBUTES", WA_ATTRIBUTES); |
| 2201 | SetDictInt("WA_NORMAL", WA_NORMAL); |
| 2202 | SetDictInt("WA_STANDOUT", WA_STANDOUT); |
| 2203 | SetDictInt("WA_UNDERLINE", WA_UNDERLINE); |
| 2204 | SetDictInt("WA_REVERSE", WA_REVERSE); |
| 2205 | SetDictInt("WA_BLINK", WA_BLINK); |
| 2206 | SetDictInt("WA_DIM", WA_DIM); |
| 2207 | SetDictInt("WA_BOLD", WA_BOLD); |
| 2208 | SetDictInt("WA_ALTCHARSET", WA_ALTCHARSET); |
| 2209 | SetDictInt("WA_INVIS", WA_INVIS); |
| 2210 | SetDictInt("WA_PROTECT", WA_PROTECT); |
| 2211 | SetDictInt("WA_HORIZONTAL", WA_HORIZONTAL); |
| 2212 | SetDictInt("WA_LEFT", WA_LEFT); |
| 2213 | SetDictInt("WA_LOW", WA_LOW); |
| 2214 | SetDictInt("WA_RIGHT", WA_RIGHT); |
| 2215 | SetDictInt("WA_TOP", WA_TOP); |
| 2216 | SetDictInt("WA_VERTICAL", WA_VERTICAL); |
| 2217 | #endif |
| 2218 | SetDictInt("COLOR_BLACK", COLOR_BLACK); |
| 2219 | SetDictInt("COLOR_RED", COLOR_RED); |
| 2220 | SetDictInt("COLOR_GREEN", COLOR_GREEN); |
| 2221 | SetDictInt("COLOR_YELLOW", COLOR_YELLOW); |
| 2222 | SetDictInt("COLOR_BLUE", COLOR_BLUE); |
| 2223 | SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA); |
| 2224 | SetDictInt("COLOR_CYAN", COLOR_CYAN); |
| 2225 | SetDictInt("COLOR_WHITE", COLOR_WHITE); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2226 | |
| 2227 | /* Now set everything up for KEY_ variables */ |
| 2228 | { |
| 2229 | int key; |
| 2230 | char *key_n; |
| 2231 | char *key_n2; |
| 2232 | for (key=KEY_MIN;key < KEY_MAX; key++) { |
| 2233 | key_n = (char *)keyname(key); |
Guido van Rossum | f5c6d47 | 1995-02-07 15:38:32 +0000 | [diff] [blame] | 2234 | if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2235 | continue; |
| 2236 | if (strncmp(key_n,"KEY_F(",6)==0) { |
| 2237 | char *p1, *p2; |
| 2238 | key_n2 = malloc(strlen(key_n)+1); |
| 2239 | p1 = key_n; |
| 2240 | p2 = key_n2; |
| 2241 | while (*p1) { |
| 2242 | if (*p1 != '(' && *p1 != ')') { |
| 2243 | *p2 = *p1; |
| 2244 | p2++; |
| 2245 | } |
| 2246 | p1++; |
| 2247 | } |
| 2248 | *p2 = (char)0; |
| 2249 | } else |
| 2250 | key_n2 = key_n; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2251 | PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key)); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2252 | if (key_n2 != key_n) |
| 2253 | free(key_n2); |
| 2254 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2255 | SetDictInt("KEY_MIN", KEY_MIN); |
| 2256 | SetDictInt("KEY_MAX", KEY_MAX); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2257 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 2258 | |
| 2259 | /* Check for errors */ |
| 2260 | if (PyErr_Occurred()) |
| 2261 | Py_FatalError("can't initialize module curses"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2262 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame^] | 2263 | |
| 2264 | |