Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1994 by Lance Ellinghouse, |
| 3 | Cathedral City, California Republic, United States of America. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the name of Lance Ellinghouse |
| 12 | not be used in advertising or publicity pertaining to distribution |
| 13 | of the software without specific, written prior permission. |
| 14 | |
| 15 | LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL, |
| 18 | INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING |
| 19 | FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
| 21 | WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 25 | /****************************************************************** |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 26 | This is a curses implementation. I have tried to be as complete |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 27 | as possible. If there are functions you need that are not included, |
| 28 | please let me know and/or send me some diffs. |
| 29 | |
| 30 | There are 3 basic types exported by this module: |
| 31 | 1) Screen - This is not currently used |
| 32 | 2) Window - This is the basic type. This is equivalent to "WINDOW *". |
| 33 | 3) Pad - This is similar to Window, but works with Pads as defined |
| 34 | in curses. |
| 35 | |
| 36 | Most of the routines can be looked up using the curses man page. |
| 37 | |
| 38 | Here is a list of the currently supported methods and attributes |
| 39 | in the curses module: |
| 40 | |
| 41 | Return Value Func/Attr Description |
| 42 | -------------------------------------------------------------------------- |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 43 | StringObject version A string representing the current |
| 44 | version of this module. |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 45 | WindowObject initscr() This initializes the screen for use |
| 46 | None endwin() Closes down the screen and returns |
| 47 | things as they were before calling |
| 48 | initscr() |
| 49 | True/FalseObject isendwin() Has endwin() been called? |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 50 | None doupdate() Updates screen |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 51 | WindowObject newwin(nlines,ncols,begin_y,begin_x) |
| 52 | newwin(begin_y,begin_x) |
| 53 | newwin() creates and returns |
| 54 | a new window. |
| 55 | None beep() Beep the screen if possible |
| 56 | None flash() Flash the screen if possible |
| 57 | None ungetch(int) Push the int back so next getch() |
| 58 | will return it. |
| 59 | Note: argument is an INT, not a CHAR |
| 60 | None flushinp() Flush all input buffers |
| 61 | None cbreak() Enter cbreak mode |
| 62 | None nocbreak() Leave cbreak mode |
| 63 | None echo() Enter echo mode |
| 64 | None noecho() Leave echo mode |
| 65 | None nl() Enter nl mode |
| 66 | None nonl() Leave nl mode |
| 67 | None raw() Enter raw mode |
| 68 | None noraw() Leave raw mode |
| 69 | None intrflush(int) Set or reset interruptable flush |
| 70 | mode, int=1 if set, 0 if notset. |
| 71 | None meta(int) Allow 8 bit or 7 bit chars. |
| 72 | int=1 is 8 bit, int=0 is 7 bit |
| 73 | StringObject keyname(int) return the text representation |
| 74 | of a KEY_ value. (see below) |
| 75 | |
| 76 | Here is a list of the currently supported methods and attributes |
| 77 | in the WindowObject: |
| 78 | |
| 79 | Return Value Func/Attr Description |
| 80 | -------------------------------------------------------------------------- |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 81 | None refresh() Do refresh |
| 82 | None nooutrefresh() Mark for refresh but wait |
| 83 | None mvwin(new_y,new_x) Move Window |
| 84 | None move(new_y,new_x) Move Cursor |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 85 | WindowObject subwin(nlines,ncols,begin_y,begin_x) |
| 86 | subwin(begin_y,begin_x) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 87 | None addch(y,x,ch,attr) |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 88 | addch(y,x,ch) |
| 89 | addch(ch,attr) |
| 90 | addch(ch) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 91 | None insch(y,x,ch,attr) |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 92 | insch(y,x,ch) |
| 93 | insch(ch,attr) |
| 94 | insch(ch) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 95 | None delch(y,x) |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 96 | delch() |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 97 | None echochar(ch,attr) |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 98 | echochar(ch) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 99 | None addstr(y,x,str,attr) |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 100 | addstr(y,x,str) |
| 101 | addstr(str,attr) |
| 102 | addstr(str) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 103 | None attron(attr) |
| 104 | None attroff(attr) |
| 105 | None attrset(sttr) |
| 106 | None standend() |
| 107 | None standout() |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 108 | None border(ls,rs,ts,bs,tl,tr,bl,br) (accepts 0-8 INT args) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 109 | None box(vertch,horch) vertch and horch are INTS |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 110 | box() |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 111 | None hline(y,x,ch,n) |
| 112 | hline(ch,n) |
| 113 | None vline(y,x,ch,n) |
| 114 | vline(ch,n) |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 115 | None erase() |
| 116 | None deleteln() |
| 117 | None insertln() |
| 118 | (y,x) getyx() |
| 119 | (y,x) getbegyx() |
| 120 | (y,x) getmaxyx() |
| 121 | None clear() |
| 122 | None clrtobot() |
| 123 | None clrtoeol() |
| 124 | None scroll() |
Guido van Rossum | 716a89c | 1999-01-05 17:16:46 +0000 | [diff] [blame] | 125 | scroll(nlines) |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 126 | None touchwin() |
| 127 | None touchline(start,count) |
| 128 | IntObject getch(y,x) |
| 129 | getch() |
| 130 | StringObject getstr(y,x) |
| 131 | getstr() |
| 132 | IntObject inch(y,x) |
| 133 | inch() |
| 134 | None clearok(int) int=0 or int=1 |
| 135 | None idlok(int) int=0 or int=1 |
| 136 | None leaveok(int) int=0 or int=1 |
| 137 | None scrollok(int) int=0 or int=1 |
| 138 | None setscrreg(top,bottom) |
Guido van Rossum | 8fbf82b | 1995-02-17 13:54:04 +0000 | [diff] [blame] | 139 | None keypad(int) int=0 or int=1 |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 140 | None nodelay(int) int=0 or int=1 |
| 141 | None notimeout(int) int=0 or int=1 |
| 142 | ******************************************************************/ |
| 143 | |
| 144 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 145 | /* curses module */ |
| 146 | |
Guido van Rossum | 602099a | 1994-09-14 13:32:22 +0000 | [diff] [blame] | 147 | #include "Python.h" |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 148 | |
Guido van Rossum | 1266a01 | 1996-02-25 04:50:31 +0000 | [diff] [blame] | 149 | #ifdef HAVE_NCURSES_H |
| 150 | /* Now let's hope there aren't systems that have a broken ncurses.h */ |
| 151 | #include <ncurses.h> |
| 152 | #else |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 153 | #include <curses.h> |
Guido van Rossum | 1266a01 | 1996-02-25 04:50:31 +0000 | [diff] [blame] | 154 | #endif |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 155 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 156 | typedef struct { |
| 157 | PyObject_HEAD |
| 158 | SCREEN *scr; |
| 159 | } PyCursesScreenObject; |
| 160 | |
| 161 | typedef struct { |
| 162 | PyObject_HEAD |
| 163 | WINDOW *win; |
| 164 | WINDOW *parent; |
| 165 | } PyCursesWindowObject; |
| 166 | |
| 167 | typedef struct { |
| 168 | PyObject_HEAD |
| 169 | WINDOW *pad; |
| 170 | } PyCursesPadObject; |
| 171 | |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 172 | #if 0 |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 173 | staticforward PyTypeObject PyCursesScreen_Type; |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 174 | #endif |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 175 | staticforward PyTypeObject PyCursesWindow_Type; |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 176 | #if 0 |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 177 | staticforward PyTypeObject PyCursesPad_Type; |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 178 | #endif |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 179 | |
| 180 | #define PyCursesScreen_Check(v) ((v)->ob_type == &PyCursesScreen_Type) |
| 181 | #define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type) |
| 182 | #define PyCursesPad_Check(v) ((v)->ob_type == &PyCursesPad_Type) |
| 183 | |
| 184 | /* Defines */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 185 | static PyObject *PyCursesError; /* For exception curses.error */ |
| 186 | |
| 187 | /* Catch-all error messages */ |
| 188 | static char *catchall_ERR = "curses function returned ERR"; |
| 189 | static char *catchall_NULL = "curses function returned NULL"; |
| 190 | |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 191 | /* Tells whether initscr() has been called to initialise curses */ |
| 192 | static int initialised = FALSE; |
| 193 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 194 | #define ARG_COUNT(X) \ |
| 195 | (((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1)) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 196 | |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 197 | /****************************************************************** |
| 198 | |
| 199 | Change Log: |
| 200 | |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 201 | Version 1.2: 95/02/23 (Steve Clift) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 202 | Fixed several potential core-dumping bugs. |
| 203 | Reworked arg parsing where variable arg lists are used. |
| 204 | Generate exceptions when ERR or NULL is returned by curses functions. |
| 205 | Changed return types to match SysV Curses manual descriptions. |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 206 | Added keypad() to window method list. |
| 207 | Added border(), hline() and vline() window methods. |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 208 | |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 209 | Version 1.1: 94/08/31: |
| 210 | Minor fixes given by Guido. |
| 211 | Changed 'ncurses' to 'curses' |
| 212 | Changed '__version__' to 'version' |
| 213 | Added PyErr_Clear() where needed |
| 214 | Moved ACS_* attribute initialization to PyCurses_InitScr() to fix |
| 215 | crash on SGI |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 216 | |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 217 | Version 1.0: 94/08/30: |
| 218 | This is the first release of this software. |
| 219 | Released to the Internet via python-list@cwi.nl |
| 220 | |
| 221 | ******************************************************************/ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 222 | |
Guido van Rossum | d5f6c22 | 1998-10-07 14:48:53 +0000 | [diff] [blame] | 223 | static char *PyCursesVersion = "1.2"; |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 224 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 225 | /* |
| 226 | * Check the return code from a curses function and return None |
| 227 | * or raise an exception as appropriate. |
| 228 | */ |
| 229 | |
| 230 | static PyObject * |
| 231 | PyCursesCheckERR(code, fname) |
| 232 | int code; |
| 233 | char *fname; |
| 234 | { |
| 235 | char buf[100]; |
| 236 | |
| 237 | if (code != ERR) { |
| 238 | Py_INCREF(Py_None); |
| 239 | return Py_None; |
| 240 | } else { |
| 241 | if (fname == NULL) { |
| 242 | PyErr_SetString(PyCursesError, catchall_ERR); |
| 243 | } else { |
| 244 | strcpy(buf, fname); |
| 245 | strcat(buf, "() returned ERR"); |
| 246 | PyErr_SetString(PyCursesError, buf); |
| 247 | } |
| 248 | return NULL; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 253 | static int |
| 254 | PyCursesInitialised() |
| 255 | { |
| 256 | if (initialised == TRUE) |
| 257 | return 1; |
| 258 | else { |
| 259 | PyErr_SetString(PyCursesError, "must call initscr() first"); |
| 260 | return 0; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 265 | /* ------------- SCREEN routines --------------- */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 266 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 267 | #ifdef NOT_YET |
| 268 | static PyObject * |
| 269 | PyCursesScreen_New(arg) |
| 270 | PyObject * arg; |
| 271 | { |
| 272 | char *term_type; |
| 273 | PyFileObject *in_fo; |
| 274 | PyFileObject *out_fo; |
| 275 | PyCursesScreenObject *xp; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 276 | xp = PyObject_NEW(PyCursesScreenObject, &PyCursesScreen_Type); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 277 | if (xp == NULL) |
| 278 | return NULL; |
| 279 | return (PyObject *)xp; |
| 280 | } |
| 281 | #endif |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 282 | |
| 283 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 284 | /* ------------- WINDOW routines --------------- */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 285 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 286 | static PyObject * |
| 287 | PyCursesWindow_New(win) |
| 288 | WINDOW *win; |
| 289 | { |
| 290 | PyCursesWindowObject *wo; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 291 | |
| 292 | wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 293 | if (wo == NULL) |
| 294 | return NULL; |
| 295 | wo->win = win; |
| 296 | wo->parent = (WINDOW *)NULL; |
| 297 | return (PyObject *)wo; |
| 298 | } |
| 299 | |
| 300 | static void |
| 301 | PyCursesWindow_Dealloc(wo) |
| 302 | PyCursesWindowObject *wo; |
| 303 | { |
| 304 | if (wo->win != stdscr) |
| 305 | delwin(wo->win); |
| 306 | PyMem_DEL(wo); |
| 307 | } |
| 308 | |
| 309 | static PyObject * |
| 310 | PyCursesWindow_Refresh(self,arg) |
| 311 | PyCursesWindowObject *self; |
| 312 | PyObject * arg; |
| 313 | { |
| 314 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 315 | return NULL; |
| 316 | return PyCursesCheckERR(wrefresh(self->win), "wrefresh"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static PyObject * |
| 320 | PyCursesWindow_NoOutRefresh(self,arg) |
| 321 | PyCursesWindowObject *self; |
| 322 | PyObject * arg; |
| 323 | { |
| 324 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 325 | return NULL; |
| 326 | return PyCursesCheckERR(wnoutrefresh(self->win), "wnoutrefresh"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | static PyObject * |
| 330 | PyCursesWindow_MoveWin(self,arg) |
| 331 | PyCursesWindowObject *self; |
| 332 | PyObject * arg; |
| 333 | { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 334 | int x, y; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 335 | if (!PyArg_Parse(arg,"(ii);y,x", &y, &x)) |
| 336 | return NULL; |
| 337 | return PyCursesCheckERR(mvwin(self->win,y,x), "mvwin"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static PyObject * |
| 341 | PyCursesWindow_Move(self,arg) |
| 342 | PyCursesWindowObject *self; |
| 343 | PyObject * arg; |
| 344 | { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 345 | int x, y; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 346 | if (!PyArg_Parse(arg,"(ii);y,x", &y, &x)) |
| 347 | return NULL; |
| 348 | return PyCursesCheckERR(wmove(self->win,y,x), "wmove"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static PyObject * |
| 352 | PyCursesWindow_SubWin(self,arg) |
| 353 | PyCursesWindowObject *self; |
| 354 | PyObject * arg; |
| 355 | { |
| 356 | WINDOW *win; |
| 357 | PyCursesWindowObject *rtn_win; |
| 358 | int nlines, ncols, begin_y, begin_x; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 359 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 360 | nlines = 0; |
| 361 | ncols = 0; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 362 | switch (ARG_COUNT(arg)) { |
| 363 | case 2: |
| 364 | if (!PyArg_Parse(arg,"(ii);begin_y,begin_x",&begin_y,&begin_x)) |
| 365 | return NULL; |
| 366 | break; |
| 367 | case 4: |
| 368 | if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x", |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 369 | &nlines,&ncols,&begin_y,&begin_x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 370 | return NULL; |
| 371 | break; |
| 372 | default: |
| 373 | PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments"); |
| 374 | return NULL; |
| 375 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 376 | win = subwin(self->win,nlines,ncols,begin_y,begin_x); |
| 377 | if (win == NULL) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 378 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 379 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 380 | } |
| 381 | rtn_win = (PyCursesWindowObject *)PyCursesWindow_New(win); |
| 382 | rtn_win->parent = self->win; |
| 383 | return (PyObject *)rtn_win; |
| 384 | } |
| 385 | |
| 386 | static PyObject * |
| 387 | PyCursesWindow_AddCh(self,arg) |
| 388 | PyCursesWindowObject *self; |
| 389 | PyObject * arg; |
| 390 | { |
| 391 | int rtn; |
| 392 | int x, y; |
| 393 | int ch; |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 394 | int attr, attr_old = 0; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 395 | int use_xy = FALSE, use_attr = FALSE; |
| 396 | |
| 397 | switch (ARG_COUNT(arg)) { |
| 398 | case 1: |
| 399 | if (!PyArg_Parse(arg, "i;ch", &ch)) |
| 400 | return NULL; |
| 401 | break; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 402 | case 2: |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 403 | if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr)) |
| 404 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 405 | use_attr = TRUE; |
| 406 | break; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 407 | case 3: |
| 408 | if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch)) |
| 409 | return NULL; |
| 410 | use_xy = TRUE; |
| 411 | break; |
| 412 | case 4: |
| 413 | if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr)) |
| 414 | return NULL; |
| 415 | use_xy = use_attr = TRUE; |
| 416 | break; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 417 | default: |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 418 | PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments"); |
| 419 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 420 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 421 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 422 | if (use_attr == TRUE) { |
| 423 | attr_old = getattrs(self->win); |
| 424 | wattrset(self->win,attr); |
| 425 | } |
| 426 | if (use_xy == TRUE) |
| 427 | rtn = mvwaddch(self->win,y,x,ch); |
| 428 | else |
| 429 | rtn = waddch(self->win,ch); |
| 430 | if (use_attr == TRUE) |
| 431 | wattrset(self->win,attr_old); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 432 | |
| 433 | return PyCursesCheckERR(rtn, "[mv]waddch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static PyObject * |
| 437 | PyCursesWindow_InsCh(self,arg) |
| 438 | PyCursesWindowObject *self; |
| 439 | PyObject * arg; |
| 440 | { |
| 441 | int rtn; |
| 442 | int x, y; |
| 443 | int ch; |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 444 | int attr, attr_old = 0; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 445 | int use_xy = TRUE, use_attr = FALSE; |
| 446 | |
| 447 | switch (ARG_COUNT(arg)) { |
| 448 | case 1: |
| 449 | if (!PyArg_Parse(arg, "i;ch", &ch)) |
| 450 | return NULL; |
| 451 | break; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 452 | case 2: |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 453 | if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr)) |
| 454 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 455 | use_attr = TRUE; |
| 456 | break; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 457 | case 3: |
| 458 | if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch)) |
| 459 | return NULL; |
| 460 | use_xy = TRUE; |
| 461 | break; |
| 462 | case 4: |
| 463 | if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr)) |
| 464 | return NULL; |
| 465 | use_xy = use_attr = TRUE; |
| 466 | break; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 467 | default: |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 468 | PyErr_SetString(PyExc_TypeError, "insch requires 1 to 4 arguments"); |
| 469 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 470 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 471 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 472 | if (use_attr == TRUE) { |
| 473 | attr_old = getattrs(self->win); |
| 474 | wattrset(self->win,attr); |
| 475 | } |
| 476 | if (use_xy == TRUE) |
| 477 | rtn = mvwinsch(self->win,y,x,ch); |
| 478 | else |
| 479 | rtn = winsch(self->win,ch); |
| 480 | if (use_attr == TRUE) |
| 481 | wattrset(self->win,attr_old); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 482 | |
| 483 | return PyCursesCheckERR(rtn, "[mv]winsch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static PyObject * |
| 487 | PyCursesWindow_DelCh(self,arg) |
| 488 | PyCursesWindowObject *self; |
| 489 | PyObject * arg; |
| 490 | { |
| 491 | int rtn; |
| 492 | int x, y; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 493 | |
| 494 | switch (ARG_COUNT(arg)) { |
| 495 | case 0: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 496 | rtn = wdelch(self->win); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 497 | break; |
| 498 | case 2: |
| 499 | if (!PyArg_Parse(arg,"(ii);y,x", &y, &x)) |
| 500 | return NULL; |
| 501 | rtn = mvwdelch(self->win,y,x); |
| 502 | break; |
| 503 | default: |
| 504 | PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments"); |
| 505 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 506 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 507 | |
| 508 | return PyCursesCheckERR(rtn, "[mv]wdelch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static PyObject * |
| 512 | PyCursesWindow_EchoChar(self,arg) |
| 513 | PyCursesWindowObject *self; |
| 514 | PyObject * arg; |
| 515 | { |
| 516 | int rtn; |
| 517 | int ch; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 518 | int attr, attr_old; |
| 519 | |
| 520 | switch (ARG_COUNT(arg)) { |
| 521 | case 1: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 522 | if (!PyArg_Parse(arg,"i;ch", &ch)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 523 | return NULL; |
| 524 | rtn = wechochar(self->win,ch); |
| 525 | break; |
| 526 | case 2: |
| 527 | if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr)) |
| 528 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 529 | attr_old = getattrs(self->win); |
| 530 | wattrset(self->win,attr); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 531 | rtn = wechochar(self->win,ch); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 532 | wattrset(self->win,attr_old); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 533 | break; |
| 534 | default: |
| 535 | PyErr_SetString(PyExc_TypeError, "echochar requires 1 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 | |
| 539 | return PyCursesCheckERR(rtn, "wechochar"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static PyObject * |
| 543 | PyCursesWindow_AddStr(self,arg) |
| 544 | PyCursesWindowObject *self; |
| 545 | PyObject * arg; |
| 546 | { |
| 547 | int rtn; |
| 548 | int x, y; |
| 549 | char *str; |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 550 | int attr, attr_old = 0; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 551 | int use_xy = FALSE, use_attr = FALSE; |
| 552 | |
| 553 | switch (ARG_COUNT(arg)) { |
| 554 | case 1: |
| 555 | if (!PyArg_Parse(arg,"s;str", &str)) |
| 556 | return NULL; |
| 557 | break; |
| 558 | case 2: |
| 559 | if (!PyArg_Parse(arg,"(si);str,attr", &str, &attr)) |
| 560 | return NULL; |
| 561 | use_attr = TRUE; |
| 562 | break; |
| 563 | case 3: |
| 564 | if (!PyArg_Parse(arg,"(iis);y,x,str", &y, &x, &str)) |
| 565 | return NULL; |
| 566 | use_xy = TRUE; |
| 567 | break; |
| 568 | case 4: |
| 569 | if (!PyArg_Parse(arg,"(iisi);y,x,str,attr", &y, &x, &str, &attr)) |
| 570 | return NULL; |
| 571 | use_xy = use_attr = TRUE; |
| 572 | break; |
| 573 | default: |
| 574 | PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments"); |
| 575 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 576 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 577 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 578 | if (use_attr == TRUE) { |
| 579 | attr_old = getattrs(self->win); |
| 580 | wattrset(self->win,attr); |
| 581 | } |
| 582 | if (use_xy == TRUE) |
| 583 | rtn = mvwaddstr(self->win,y,x,str); |
| 584 | else |
| 585 | rtn = waddstr(self->win,str); |
| 586 | if (use_attr == TRUE) |
| 587 | wattrset(self->win,attr_old); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 588 | |
| 589 | return PyCursesCheckERR(rtn, "[mv]waddstr"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | static PyObject * |
| 593 | PyCursesWindow_AttrOn(self,arg) |
| 594 | PyCursesWindowObject *self; |
| 595 | PyObject * arg; |
| 596 | { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 597 | int ch; |
| 598 | if (!PyArg_Parse(arg,"i;attr", &ch)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 599 | return NULL; |
| 600 | wattron(self->win,ch); |
| 601 | Py_INCREF(Py_None); |
| 602 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | static PyObject * |
| 606 | PyCursesWindow_AttrOff(self,arg) |
| 607 | PyCursesWindowObject *self; |
| 608 | PyObject * arg; |
| 609 | { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 610 | int ch; |
| 611 | if (!PyArg_Parse(arg,"i;attr", &ch)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 612 | return NULL; |
| 613 | wattroff(self->win,ch); |
| 614 | Py_INCREF(Py_None); |
| 615 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | static PyObject * |
| 619 | PyCursesWindow_AttrSet(self,arg) |
| 620 | PyCursesWindowObject *self; |
| 621 | PyObject * arg; |
| 622 | { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 623 | int ch; |
| 624 | if (!PyArg_Parse(arg,"i;attr", &ch)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 625 | return NULL; |
| 626 | wattrset(self->win,ch); |
| 627 | Py_INCREF(Py_None); |
| 628 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | static PyObject * |
| 632 | PyCursesWindow_StandEnd(self,arg) |
| 633 | PyCursesWindowObject *self; |
| 634 | PyObject * arg; |
| 635 | { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 636 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 637 | return NULL; |
| 638 | wstandend(self->win); |
| 639 | Py_INCREF(Py_None); |
| 640 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | static PyObject * |
| 644 | PyCursesWindow_StandOut(self,arg) |
| 645 | PyCursesWindowObject *self; |
| 646 | PyObject * arg; |
| 647 | { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 648 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 649 | return NULL; |
| 650 | wstandout(self->win); |
| 651 | Py_INCREF(Py_None); |
| 652 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | static PyObject * |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 656 | PyCursesWindow_Border(self, args) |
| 657 | PyCursesWindowObject *self; |
| 658 | PyObject *args; |
| 659 | { |
| 660 | int ls, rs, ts, bs, tl, tr, bl, br; |
| 661 | ls = rs = ts = bs = tl = tr = bl = br = 0; |
| 662 | if (!PyArg_ParseTuple(args,"|iiiiiiii;ls,rs,ts,bs,tl,tr,bl,br", |
| 663 | &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br)) |
| 664 | return NULL; |
| 665 | wborder(self->win, ls, rs, ts, bs, tl, tr, bl, br); |
| 666 | Py_INCREF(Py_None); |
| 667 | return Py_None; |
| 668 | } |
| 669 | |
| 670 | static PyObject * |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 671 | PyCursesWindow_Box(self,arg) |
| 672 | PyCursesWindowObject *self; |
| 673 | PyObject * arg; |
| 674 | { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 675 | int ch1=0,ch2=0; |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 676 | if (!PyArg_NoArgs(arg)) { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 677 | PyErr_Clear(); |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 678 | if (!PyArg_Parse(arg,"(ii);vertch,horch", &ch1, &ch2)) |
| 679 | return NULL; |
| 680 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 681 | box(self->win,ch1,ch2); |
| 682 | Py_INCREF(Py_None); |
| 683 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | static PyObject * |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 687 | PyCursesWindow_Hline(self, args) |
| 688 | PyCursesWindowObject *self; |
| 689 | PyObject *args; |
| 690 | { |
| 691 | int ch, n, x, y, code = OK; |
| 692 | switch (ARG_COUNT(args)) { |
| 693 | case 2: |
| 694 | if (!PyArg_Parse(args, "(ii);ch,n", &ch, &n)) |
| 695 | return NULL; |
| 696 | break; |
| 697 | case 4: |
| 698 | if (!PyArg_Parse(args, "(iiii);y,x,ch,n", &y, &x, &ch, &n)) |
| 699 | return NULL; |
| 700 | code = wmove(self->win, y, x); |
| 701 | break; |
| 702 | default: |
| 703 | PyErr_SetString(PyExc_TypeError, "hline requires 2 or 4 arguments"); |
| 704 | return NULL; |
| 705 | } |
| 706 | if (code != ERR) |
| 707 | whline(self->win, ch, n); |
| 708 | return PyCursesCheckERR(code, "wmove"); |
| 709 | } |
| 710 | |
| 711 | static PyObject * |
| 712 | PyCursesWindow_Vline(self, args) |
| 713 | PyCursesWindowObject *self; |
| 714 | PyObject *args; |
| 715 | { |
| 716 | int ch, n, x, y, code = OK; |
| 717 | switch (ARG_COUNT(args)) { |
| 718 | case 2: |
| 719 | if (!PyArg_Parse(args, "(ii);ch,n", &ch, &n)) |
| 720 | return NULL; |
| 721 | break; |
| 722 | case 4: |
| 723 | if (!PyArg_Parse(args, "(iiii);y,x,ch,n", &y, &x, &ch, &n)) |
| 724 | return NULL; |
| 725 | code = wmove(self->win, y, x); |
| 726 | break; |
| 727 | default: |
| 728 | PyErr_SetString(PyExc_TypeError, "vline requires 2 or 4 arguments"); |
| 729 | return NULL; |
| 730 | } |
| 731 | if (code != ERR) |
| 732 | wvline(self->win, ch, n); |
| 733 | return PyCursesCheckERR(code, "wmove"); |
| 734 | } |
| 735 | |
| 736 | static PyObject * |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 737 | PyCursesWindow_Erase(self,arg) |
| 738 | PyCursesWindowObject *self; |
| 739 | PyObject * arg; |
| 740 | { |
| 741 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 742 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 743 | werase(self->win); |
| 744 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 745 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | static PyObject * |
| 749 | PyCursesWindow_DeleteLine(self,arg) |
| 750 | PyCursesWindowObject *self; |
| 751 | PyObject * arg; |
| 752 | { |
| 753 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 754 | return NULL; |
| 755 | return PyCursesCheckERR(wdeleteln(self->win), "wdeleteln"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | static PyObject * |
| 759 | PyCursesWindow_InsertLine(self,arg) |
| 760 | PyCursesWindowObject *self; |
| 761 | PyObject * arg; |
| 762 | { |
| 763 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 764 | return NULL; |
| 765 | return PyCursesCheckERR(winsertln(self->win), "winsertln"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | static PyObject * |
| 769 | PyCursesWindow_GetYX(self,arg) |
| 770 | PyCursesWindowObject *self; |
| 771 | PyObject * arg; |
| 772 | { |
| 773 | int x, y; |
| 774 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 775 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 776 | getyx(self->win,y,x); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 777 | return Py_BuildValue("(ii)", y, x); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | static PyObject * |
| 781 | PyCursesWindow_GetBegYX(self,arg) |
| 782 | PyCursesWindowObject *self; |
| 783 | PyObject * arg; |
| 784 | { |
| 785 | int x, y; |
| 786 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 787 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 788 | getbegyx(self->win,y,x); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 789 | return Py_BuildValue("(ii)", y, x); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | static PyObject * |
| 793 | PyCursesWindow_GetMaxYX(self,arg) |
| 794 | PyCursesWindowObject *self; |
| 795 | PyObject * arg; |
| 796 | { |
| 797 | int x, y; |
| 798 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 799 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 800 | getmaxyx(self->win,y,x); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 801 | return Py_BuildValue("(ii)", y, x); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | static PyObject * |
| 805 | PyCursesWindow_Clear(self,arg) |
| 806 | PyCursesWindowObject *self; |
| 807 | PyObject * arg; |
| 808 | { |
| 809 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 810 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 811 | wclear(self->win); |
| 812 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 813 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | static PyObject * |
| 817 | PyCursesWindow_ClearToBottom(self,arg) |
| 818 | PyCursesWindowObject *self; |
| 819 | PyObject * arg; |
| 820 | { |
| 821 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 822 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 823 | wclrtobot(self->win); |
| 824 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 825 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | static PyObject * |
| 829 | PyCursesWindow_ClearToEOL(self,arg) |
| 830 | PyCursesWindowObject *self; |
| 831 | PyObject * arg; |
| 832 | { |
| 833 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 834 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 835 | wclrtoeol(self->win); |
| 836 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 837 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | static PyObject * |
| 841 | PyCursesWindow_Scroll(self,arg) |
| 842 | PyCursesWindowObject *self; |
| 843 | PyObject * arg; |
| 844 | { |
Guido van Rossum | 716a89c | 1999-01-05 17:16:46 +0000 | [diff] [blame] | 845 | int nlines; |
| 846 | int use_nlines = FALSE; |
| 847 | switch (ARG_COUNT(arg)) { |
| 848 | case 0: |
| 849 | break; |
| 850 | case 1: |
| 851 | if (!PyArg_Parse(arg, "i;nlines", &nlines)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 852 | return NULL; |
Guido van Rossum | 716a89c | 1999-01-05 17:16:46 +0000 | [diff] [blame] | 853 | use_nlines = TRUE; |
| 854 | break; |
| 855 | default: |
| 856 | PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments"); |
| 857 | return NULL; |
| 858 | } |
| 859 | if (use_nlines) |
| 860 | return PyCursesCheckERR(wscrl(self->win, nlines), "scroll"); |
| 861 | else |
| 862 | return PyCursesCheckERR(scroll(self->win), "scroll"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | static PyObject * |
| 866 | PyCursesWindow_TouchWin(self,arg) |
| 867 | PyCursesWindowObject *self; |
| 868 | PyObject * arg; |
| 869 | { |
| 870 | if (!PyArg_NoArgs(arg)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 871 | return NULL; |
| 872 | return PyCursesCheckERR(touchwin(self->win), "touchwin"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | static PyObject * |
| 876 | PyCursesWindow_TouchLine(self,arg) |
| 877 | PyCursesWindowObject *self; |
| 878 | PyObject * arg; |
| 879 | { |
| 880 | int st, cnt; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 881 | if (!PyArg_Parse(arg,"(ii);start,count",&st,&cnt)) |
| 882 | return NULL; |
| 883 | return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static PyObject * |
| 887 | PyCursesWindow_GetCh(self,arg) |
| 888 | PyCursesWindowObject *self; |
| 889 | PyObject * arg; |
| 890 | { |
| 891 | int x, y; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 892 | int rtn; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 893 | |
| 894 | switch (ARG_COUNT(arg)) { |
| 895 | case 0: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 896 | rtn = wgetch(self->win); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 897 | break; |
| 898 | case 2: |
| 899 | if (!PyArg_Parse(arg,"(ii);y,x",&y,&x)) |
| 900 | return NULL; |
| 901 | rtn = mvwgetch(self->win,y,x); |
| 902 | break; |
| 903 | default: |
| 904 | PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments"); |
| 905 | return NULL; |
| 906 | } |
| 907 | |
| 908 | return PyInt_FromLong((long) rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static PyObject * |
| 912 | PyCursesWindow_GetStr(self,arg) |
| 913 | PyCursesWindowObject *self; |
| 914 | PyObject * arg; |
| 915 | { |
| 916 | int x, y; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 917 | char rtn[1024]; /* This should be big enough.. I hope */ |
| 918 | int rtn2; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 919 | |
| 920 | switch (ARG_COUNT(arg)) { |
| 921 | case 0: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 922 | rtn2 = wgetstr(self->win,rtn); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 923 | break; |
| 924 | case 2: |
| 925 | if (!PyArg_Parse(arg,"(ii);y,x",&y,&x)) |
| 926 | return NULL; |
| 927 | rtn2 = mvwgetstr(self->win,y,x,rtn); |
| 928 | break; |
| 929 | default: |
| 930 | PyErr_SetString(PyExc_TypeError, "getstr requires 0 or 2 arguments"); |
| 931 | return NULL; |
| 932 | } |
| 933 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 934 | if (rtn2 == ERR) |
| 935 | rtn[0] = 0; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 936 | return PyString_FromString(rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | static PyObject * |
| 940 | PyCursesWindow_InCh(self,arg) |
| 941 | PyCursesWindowObject *self; |
| 942 | PyObject * arg; |
| 943 | { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 944 | int x, y, rtn; |
| 945 | |
| 946 | switch (ARG_COUNT(arg)) { |
| 947 | case 0: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 948 | rtn = winch(self->win); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 949 | break; |
| 950 | case 2: |
| 951 | if (!PyArg_Parse(arg,"(ii);y,x",&y,&x)) |
| 952 | return NULL; |
| 953 | rtn = mvwinch(self->win,y,x); |
| 954 | break; |
| 955 | default: |
| 956 | PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments"); |
| 957 | return NULL; |
| 958 | } |
| 959 | |
| 960 | return PyInt_FromLong((long) rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | static PyObject * |
| 964 | PyCursesWindow_ClearOk(self,arg) |
| 965 | PyCursesWindowObject *self; |
| 966 | PyObject * arg; |
| 967 | { |
| 968 | int val; |
| 969 | if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 970 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 971 | clearok(self->win,val); |
| 972 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 973 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | static PyObject * |
| 977 | PyCursesWindow_IdlOk(self,arg) |
| 978 | PyCursesWindowObject *self; |
| 979 | PyObject * arg; |
| 980 | { |
| 981 | int val; |
| 982 | if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 983 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 984 | idlok(self->win,val); |
| 985 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 986 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | static PyObject * |
| 990 | PyCursesWindow_LeaveOk(self,arg) |
| 991 | PyCursesWindowObject *self; |
| 992 | PyObject * arg; |
| 993 | { |
| 994 | int val; |
| 995 | if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 996 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 997 | leaveok(self->win,val); |
| 998 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 999 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | static PyObject * |
| 1003 | PyCursesWindow_ScrollOk(self,arg) |
| 1004 | PyCursesWindowObject *self; |
| 1005 | PyObject * arg; |
| 1006 | { |
| 1007 | int val; |
| 1008 | if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1009 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1010 | scrollok(self->win,val); |
| 1011 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1012 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | static PyObject * |
| 1016 | PyCursesWindow_SetScrollRegion(self,arg) |
| 1017 | PyCursesWindowObject *self; |
| 1018 | PyObject * arg; |
| 1019 | { |
| 1020 | int x, y; |
| 1021 | if (!PyArg_Parse(arg,"(ii);top, bottom",&y,&x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1022 | return NULL; |
| 1023 | return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | static PyObject * |
| 1027 | PyCursesWindow_KeyPad(self,arg) |
| 1028 | PyCursesWindowObject * self; |
| 1029 | PyObject * arg; |
| 1030 | { |
| 1031 | int ch; |
| 1032 | if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1033 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1034 | keypad(self->win,ch); |
| 1035 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1036 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | static PyObject * |
| 1040 | PyCursesWindow_NoDelay(self,arg) |
| 1041 | PyCursesWindowObject * self; |
| 1042 | PyObject * arg; |
| 1043 | { |
| 1044 | int ch; |
| 1045 | if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1046 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1047 | nodelay(self->win,ch); |
| 1048 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1049 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | static PyObject * |
| 1053 | PyCursesWindow_NoTimeout(self,arg) |
| 1054 | PyCursesWindowObject * self; |
| 1055 | PyObject * arg; |
| 1056 | { |
| 1057 | int ch; |
| 1058 | if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1059 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1060 | notimeout(self->win,ch); |
| 1061 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1062 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | static PyMethodDef PyCursesWindow_Methods[] = { |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1066 | {"refresh", (PyCFunction)PyCursesWindow_Refresh}, |
| 1067 | {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh}, |
| 1068 | {"mvwin", (PyCFunction)PyCursesWindow_MoveWin}, |
| 1069 | {"move", (PyCFunction)PyCursesWindow_Move}, |
| 1070 | {"subwin", (PyCFunction)PyCursesWindow_SubWin}, |
| 1071 | {"addch", (PyCFunction)PyCursesWindow_AddCh}, |
| 1072 | {"insch", (PyCFunction)PyCursesWindow_InsCh}, |
| 1073 | {"delch", (PyCFunction)PyCursesWindow_DelCh}, |
| 1074 | {"echochar", (PyCFunction)PyCursesWindow_EchoChar}, |
| 1075 | {"addstr", (PyCFunction)PyCursesWindow_AddStr}, |
| 1076 | {"attron", (PyCFunction)PyCursesWindow_AttrOn}, |
| 1077 | {"attroff", (PyCFunction)PyCursesWindow_AttrOff}, |
| 1078 | {"attrset", (PyCFunction)PyCursesWindow_AttrSet}, |
| 1079 | {"standend", (PyCFunction)PyCursesWindow_StandEnd}, |
| 1080 | {"standout", (PyCFunction)PyCursesWindow_StandOut}, |
| 1081 | {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS}, |
| 1082 | {"box", (PyCFunction)PyCursesWindow_Box}, |
| 1083 | {"hline", (PyCFunction)PyCursesWindow_Hline}, |
| 1084 | {"vline", (PyCFunction)PyCursesWindow_Vline}, |
| 1085 | {"erase", (PyCFunction)PyCursesWindow_Erase}, |
| 1086 | {"deleteln", (PyCFunction)PyCursesWindow_DeleteLine}, |
| 1087 | {"insertln", (PyCFunction)PyCursesWindow_InsertLine}, |
| 1088 | {"getyx", (PyCFunction)PyCursesWindow_GetYX}, |
| 1089 | {"getbegyx", (PyCFunction)PyCursesWindow_GetBegYX}, |
| 1090 | {"getmaxyx", (PyCFunction)PyCursesWindow_GetMaxYX}, |
| 1091 | {"clear", (PyCFunction)PyCursesWindow_Clear}, |
| 1092 | {"clrtobot", (PyCFunction)PyCursesWindow_ClearToBottom}, |
| 1093 | {"clrtoeol", (PyCFunction)PyCursesWindow_ClearToEOL}, |
| 1094 | {"scroll", (PyCFunction)PyCursesWindow_Scroll}, |
| 1095 | {"touchwin", (PyCFunction)PyCursesWindow_TouchWin}, |
| 1096 | {"touchline", (PyCFunction)PyCursesWindow_TouchLine}, |
| 1097 | {"getch", (PyCFunction)PyCursesWindow_GetCh}, |
| 1098 | {"getstr", (PyCFunction)PyCursesWindow_GetStr}, |
| 1099 | {"inch", (PyCFunction)PyCursesWindow_InCh}, |
| 1100 | {"clearok", (PyCFunction)PyCursesWindow_ClearOk}, |
| 1101 | {"idlok", (PyCFunction)PyCursesWindow_IdlOk}, |
| 1102 | {"leaveok", (PyCFunction)PyCursesWindow_LeaveOk}, |
| 1103 | {"scrollok", (PyCFunction)PyCursesWindow_ScrollOk}, |
| 1104 | {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion}, |
| 1105 | {"keypad", (PyCFunction)PyCursesWindow_KeyPad}, |
| 1106 | {"nodelay", (PyCFunction)PyCursesWindow_NoDelay}, |
| 1107 | {"notimeout", (PyCFunction)PyCursesWindow_NoTimeout}, |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1108 | {NULL, NULL} /* sentinel */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1109 | }; |
| 1110 | |
| 1111 | static PyObject * |
| 1112 | PyCursesWindow_GetAttr(self, name) |
| 1113 | PyCursesWindowObject *self; |
| 1114 | char *name; |
| 1115 | { |
Guido van Rossum | a597dde | 1995-01-10 20:56:29 +0000 | [diff] [blame] | 1116 | return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1119 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1120 | /* --------------- PAD routines ---------------- */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1121 | |
| 1122 | #ifdef NOT_YET |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1123 | static PyObject * |
| 1124 | PyCursesPad_New(pad) |
| 1125 | WINDOW *pad; |
| 1126 | { |
| 1127 | PyCursesPadObject *po; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1128 | po = PyObject_NEW(PyCursesPadObject, &PyCursesPad_Type); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1129 | if (po == NULL) |
| 1130 | return NULL; |
| 1131 | po->pad = pad; |
| 1132 | return (PyObject *)po; |
| 1133 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1134 | #endif |
| 1135 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1136 | |
| 1137 | /* -------------------------------------------------------*/ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1138 | |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 1139 | #if 0 |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1140 | static PyTypeObject PyCursesScreen_Type = { |
| 1141 | PyObject_HEAD_INIT(&PyType_Type) |
| 1142 | 0, /*ob_size*/ |
| 1143 | "curses screen", /*tp_name*/ |
| 1144 | sizeof(PyCursesScreenObject), /*tp_basicsize*/ |
| 1145 | 0, /*tp_itemsize*/ |
| 1146 | /* methods */ |
| 1147 | (destructor)0 /*PyCursesScreen_Dealloc*/, /*tp_dealloc*/ |
| 1148 | 0, /*tp_print*/ |
| 1149 | (getattrfunc)0, /*tp_getattr*/ |
| 1150 | (setattrfunc)0, /*tp_setattr*/ |
| 1151 | 0, /*tp_compare*/ |
| 1152 | 0, /*tp_repr*/ |
| 1153 | 0, /*tp_as_number*/ |
| 1154 | 0, /*tp_as_sequence*/ |
| 1155 | 0, /*tp_as_mapping*/ |
| 1156 | 0, /*tp_hash*/ |
| 1157 | }; |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 1158 | #endif |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1159 | |
| 1160 | static PyTypeObject PyCursesWindow_Type = { |
| 1161 | PyObject_HEAD_INIT(&PyType_Type) |
| 1162 | 0, /*ob_size*/ |
| 1163 | "curses window", /*tp_name*/ |
| 1164 | sizeof(PyCursesWindowObject), /*tp_basicsize*/ |
| 1165 | 0, /*tp_itemsize*/ |
| 1166 | /* methods */ |
| 1167 | (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/ |
| 1168 | 0, /*tp_print*/ |
| 1169 | (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/ |
| 1170 | (setattrfunc)0, /*tp_setattr*/ |
| 1171 | 0, /*tp_compare*/ |
| 1172 | 0, /*tp_repr*/ |
| 1173 | 0, /*tp_as_number*/ |
| 1174 | 0, /*tp_as_sequence*/ |
| 1175 | 0, /*tp_as_mapping*/ |
| 1176 | 0, /*tp_hash*/ |
| 1177 | }; |
| 1178 | |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 1179 | #if 0 |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1180 | static PyTypeObject PyCursesPad_Type = { |
| 1181 | PyObject_HEAD_INIT(&PyType_Type) |
| 1182 | 0, /*ob_size*/ |
| 1183 | "curses pad", /*tp_name*/ |
| 1184 | sizeof(PyCursesPadObject), /*tp_basicsize*/ |
| 1185 | 0, /*tp_itemsize*/ |
| 1186 | /* methods */ |
| 1187 | (destructor)0 /*PyCursesPad_Dealloc*/, /*tp_dealloc*/ |
| 1188 | 0, /*tp_print*/ |
| 1189 | (getattrfunc)0, /*tp_getattr*/ |
| 1190 | (setattrfunc)0, /*tp_setattr*/ |
| 1191 | 0, /*tp_compare*/ |
| 1192 | 0, /*tp_repr*/ |
| 1193 | 0, /*tp_as_number*/ |
| 1194 | 0, /*tp_as_sequence*/ |
| 1195 | 0, /*tp_as_mapping*/ |
| 1196 | 0, /*tp_hash*/ |
| 1197 | }; |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 1198 | #endif |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1199 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1200 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1201 | /* -------------------------------------------------------*/ |
| 1202 | |
Guido van Rossum | e4485b0 | 1994-09-07 14:32:49 +0000 | [diff] [blame] | 1203 | static PyObject *ModDict; |
| 1204 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1205 | static PyObject * |
| 1206 | PyCurses_InitScr(self, args) |
| 1207 | PyObject * self; |
| 1208 | PyObject * args; |
| 1209 | { |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1210 | WINDOW *win; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1211 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1212 | return NULL; |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1213 | if (initialised == TRUE) { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1214 | wrefresh(stdscr); |
| 1215 | return (PyObject *)PyCursesWindow_New(stdscr); |
| 1216 | } |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1217 | |
| 1218 | win = initscr(); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1219 | if (win == NULL) { |
| 1220 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1221 | return NULL; |
| 1222 | } |
| 1223 | |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1224 | initialised = TRUE; |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1225 | |
| 1226 | /* This was moved from initcurses() because core dumped on SGI */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1227 | /* Also, they are probably not defined until you've called initscr() */ |
| 1228 | #define SetDictInt(string,ch) \ |
| 1229 | PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch))); |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1230 | |
| 1231 | /* Here are some graphic symbols you can use */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1232 | SetDictInt("ACS_ULCORNER",(ACS_ULCORNER)); |
| 1233 | SetDictInt("ACS_ULCORNER",(ACS_ULCORNER)); |
| 1234 | SetDictInt("ACS_LLCORNER",(ACS_LLCORNER)); |
| 1235 | SetDictInt("ACS_URCORNER",(ACS_URCORNER)); |
| 1236 | SetDictInt("ACS_LRCORNER",(ACS_LRCORNER)); |
| 1237 | SetDictInt("ACS_RTEE", (ACS_RTEE)); |
| 1238 | SetDictInt("ACS_LTEE", (ACS_LTEE)); |
| 1239 | SetDictInt("ACS_BTEE", (ACS_BTEE)); |
| 1240 | SetDictInt("ACS_TTEE", (ACS_TTEE)); |
| 1241 | SetDictInt("ACS_HLINE", (ACS_HLINE)); |
| 1242 | SetDictInt("ACS_VLINE", (ACS_VLINE)); |
| 1243 | SetDictInt("ACS_PLUS", (ACS_PLUS)); |
| 1244 | SetDictInt("ACS_S1", (ACS_S1)); |
| 1245 | SetDictInt("ACS_S9", (ACS_S9)); |
| 1246 | SetDictInt("ACS_DIAMOND", (ACS_DIAMOND)); |
| 1247 | SetDictInt("ACS_CKBOARD", (ACS_CKBOARD)); |
| 1248 | SetDictInt("ACS_DEGREE", (ACS_DEGREE)); |
| 1249 | SetDictInt("ACS_PLMINUS", (ACS_PLMINUS)); |
| 1250 | SetDictInt("ACS_BULLET", (ACS_BULLET)); |
Guido van Rossum | 1184789 | 1998-12-23 04:45:04 +0000 | [diff] [blame] | 1251 | SetDictInt("ACS_LARROW", (ACS_LARROW)); |
| 1252 | SetDictInt("ACS_RARROW", (ACS_RARROW)); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1253 | SetDictInt("ACS_DARROW", (ACS_DARROW)); |
| 1254 | SetDictInt("ACS_UARROW", (ACS_UARROW)); |
| 1255 | SetDictInt("ACS_BOARD", (ACS_BOARD)); |
| 1256 | SetDictInt("ACS_LANTERN", (ACS_LANTERN)); |
| 1257 | SetDictInt("ACS_BLOCK", (ACS_BLOCK)); |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1258 | |
| 1259 | return (PyObject *)PyCursesWindow_New(win); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | static PyObject * |
| 1263 | PyCurses_EndWin(self, args) |
| 1264 | PyObject * self; |
| 1265 | PyObject * args; |
| 1266 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1267 | if (!PyArg_NoArgs(args) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1268 | return NULL; |
| 1269 | return PyCursesCheckERR(endwin(), "endwin"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | static PyObject * |
| 1273 | PyCurses_IsEndWin(self, args) |
| 1274 | PyObject * self; |
| 1275 | PyObject * args; |
| 1276 | { |
| 1277 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1278 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1279 | if (isendwin() == FALSE) { |
| 1280 | Py_INCREF(Py_False); |
| 1281 | return Py_False; |
| 1282 | } |
| 1283 | Py_INCREF(Py_True); |
| 1284 | return Py_True; |
| 1285 | } |
| 1286 | |
| 1287 | static PyObject * |
| 1288 | PyCurses_DoUpdate(self,arg) |
| 1289 | PyObject * self; |
| 1290 | PyObject * arg; |
| 1291 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1292 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1293 | return NULL; |
| 1294 | return PyCursesCheckERR(doupdate(), "doupdate"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | static PyObject * |
| 1298 | PyCurses_NewWindow(self,arg) |
| 1299 | PyObject * self; |
| 1300 | PyObject * arg; |
| 1301 | { |
| 1302 | WINDOW *win; |
| 1303 | int nlines, ncols, begin_y, begin_x; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1304 | |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1305 | if (!PyCursesInitialised()) |
| 1306 | return NULL; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1307 | nlines = ncols = 0; |
| 1308 | switch (ARG_COUNT(arg)) { |
| 1309 | case 2: |
| 1310 | if (!PyArg_Parse(arg,"(ii);begin)_y,begin_x",&begin_y,&begin_x)) |
| 1311 | return NULL; |
| 1312 | break; |
| 1313 | case 4: |
| 1314 | if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x", |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1315 | &nlines,&ncols,&begin_y,&begin_x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1316 | return NULL; |
| 1317 | break; |
| 1318 | default: |
| 1319 | PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments"); |
| 1320 | return NULL; |
| 1321 | } |
| 1322 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1323 | win = newwin(nlines,ncols,begin_y,begin_x); |
| 1324 | if (win == NULL) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1325 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1326 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1327 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1328 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1329 | return (PyObject *)PyCursesWindow_New(win); |
| 1330 | } |
| 1331 | |
| 1332 | static PyObject * |
| 1333 | PyCurses_Beep(self,arg) |
| 1334 | PyObject * self; |
| 1335 | PyObject * arg; |
| 1336 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1337 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1338 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1339 | beep(); |
| 1340 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1341 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | static PyObject * |
| 1345 | PyCurses_Flash(self,arg) |
| 1346 | PyObject * self; |
| 1347 | PyObject * arg; |
| 1348 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1349 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1350 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1351 | flash(); |
| 1352 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1353 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | static PyObject * |
| 1357 | PyCurses_UngetCh(self,arg) |
| 1358 | PyObject * self; |
| 1359 | PyObject * arg; |
| 1360 | { |
| 1361 | int ch; |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1362 | if (!PyArg_Parse(arg,"i;integer",&ch) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1363 | return NULL; |
| 1364 | return PyCursesCheckERR(ungetch(ch), "ungetch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | static PyObject * |
| 1368 | PyCurses_FlushInp(self,arg) |
| 1369 | PyObject * self; |
| 1370 | PyObject * arg; |
| 1371 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1372 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1373 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1374 | flushinp(); |
| 1375 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1376 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | static PyObject * |
| 1380 | PyCurses_CBreak(self,arg) |
| 1381 | PyObject * self; |
| 1382 | PyObject * arg; |
| 1383 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1384 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1385 | return NULL; |
| 1386 | return PyCursesCheckERR(cbreak(), "cbreak"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | static PyObject * |
| 1390 | PyCurses_NoCBreak(self,arg) |
| 1391 | PyObject * self; |
| 1392 | PyObject * arg; |
| 1393 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1394 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1395 | return NULL; |
| 1396 | return PyCursesCheckERR(nocbreak(), "nocbreak"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | static PyObject * |
| 1400 | PyCurses_Echo(self,arg) |
| 1401 | PyObject * self; |
| 1402 | PyObject * arg; |
| 1403 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1404 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1405 | return NULL; |
| 1406 | return PyCursesCheckERR(echo(), "echo"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | static PyObject * |
| 1410 | PyCurses_NoEcho(self,arg) |
| 1411 | PyObject * self; |
| 1412 | PyObject * arg; |
| 1413 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1414 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1415 | return NULL; |
| 1416 | return PyCursesCheckERR(noecho(), "noecho"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | static PyObject * |
| 1420 | PyCurses_Nl(self,arg) |
| 1421 | PyObject * self; |
| 1422 | PyObject * arg; |
| 1423 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1424 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1425 | return NULL; |
| 1426 | return PyCursesCheckERR(nl(), "nl"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | static PyObject * |
| 1430 | PyCurses_NoNl(self,arg) |
| 1431 | PyObject * self; |
| 1432 | PyObject * arg; |
| 1433 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1434 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1435 | return NULL; |
| 1436 | return PyCursesCheckERR(nonl(), "nonl"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | static PyObject * |
| 1440 | PyCurses_Raw(self,arg) |
| 1441 | PyObject * self; |
| 1442 | PyObject * arg; |
| 1443 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1444 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1445 | return NULL; |
| 1446 | return PyCursesCheckERR(raw(), "raw"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | static PyObject * |
| 1450 | PyCurses_NoRaw(self,arg) |
| 1451 | PyObject * self; |
| 1452 | PyObject * arg; |
| 1453 | { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1454 | if (!PyArg_NoArgs(arg) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1455 | return NULL; |
| 1456 | return PyCursesCheckERR(noraw(), "noraw"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | static PyObject * |
| 1460 | PyCurses_IntrFlush(self,arg) |
| 1461 | PyObject * self; |
| 1462 | PyObject * arg; |
| 1463 | { |
| 1464 | int ch; |
| 1465 | if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1466 | return NULL; |
| 1467 | return PyCursesCheckERR(intrflush(NULL,ch), "intrflush"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | static PyObject * |
| 1471 | PyCurses_Meta(self,arg) |
| 1472 | PyObject * self; |
| 1473 | PyObject * arg; |
| 1474 | { |
| 1475 | int ch; |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1476 | if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch) || !PyCursesInitialised()) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1477 | return NULL; |
| 1478 | return PyCursesCheckERR(meta(stdscr, ch), "meta"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | static PyObject * |
| 1482 | PyCurses_KeyName(self,arg) |
| 1483 | PyObject * self; |
| 1484 | PyObject * arg; |
| 1485 | { |
Guido van Rossum | db4a629 | 1997-05-09 02:17:12 +0000 | [diff] [blame] | 1486 | const char *knp; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1487 | int ch; |
| 1488 | if (!PyArg_Parse(arg,"i",&ch)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1489 | return NULL; |
| 1490 | knp = keyname(ch); |
| 1491 | return PyString_FromString((knp == NULL) ? "" : knp); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | #ifdef NOT_YET |
| 1495 | static PyObject * |
| 1496 | PyCurses_NewTerm(self, args) |
| 1497 | PyObject * self; |
| 1498 | PyObject * args; |
| 1499 | { |
| 1500 | } |
| 1501 | |
| 1502 | static PyObject * |
| 1503 | PyCurses_SetTerm(self, args) |
| 1504 | PyObject * self; |
| 1505 | PyObject * args; |
| 1506 | { |
| 1507 | } |
| 1508 | #endif |
| 1509 | |
| 1510 | /* List of functions defined in the module */ |
| 1511 | |
| 1512 | static PyMethodDef PyCurses_methods[] = { |
| 1513 | {"initscr", (PyCFunction)PyCurses_InitScr}, |
| 1514 | {"endwin", (PyCFunction)PyCurses_EndWin}, |
| 1515 | {"isendwin", (PyCFunction)PyCurses_IsEndWin}, |
| 1516 | {"doupdate", (PyCFunction)PyCurses_DoUpdate}, |
| 1517 | {"newwin", (PyCFunction)PyCurses_NewWindow}, |
| 1518 | {"beep", (PyCFunction)PyCurses_Beep}, |
| 1519 | {"flash", (PyCFunction)PyCurses_Flash}, |
| 1520 | {"ungetch", (PyCFunction)PyCurses_UngetCh}, |
| 1521 | {"flushinp", (PyCFunction)PyCurses_FlushInp}, |
| 1522 | {"cbreak", (PyCFunction)PyCurses_CBreak}, |
| 1523 | {"nocbreak", (PyCFunction)PyCurses_NoCBreak}, |
| 1524 | {"echo", (PyCFunction)PyCurses_Echo}, |
| 1525 | {"noecho", (PyCFunction)PyCurses_NoEcho}, |
| 1526 | {"nl", (PyCFunction)PyCurses_Nl}, |
| 1527 | {"nonl", (PyCFunction)PyCurses_NoNl}, |
| 1528 | {"raw", (PyCFunction)PyCurses_Raw}, |
| 1529 | {"noraw", (PyCFunction)PyCurses_NoRaw}, |
| 1530 | {"intrflush", (PyCFunction)PyCurses_IntrFlush}, |
| 1531 | {"meta", (PyCFunction)PyCurses_Meta}, |
| 1532 | {"keyname", (PyCFunction)PyCurses_KeyName}, |
| 1533 | #ifdef NOT_YET |
| 1534 | {"newterm", (PyCFunction)PyCurses_NewTerm}, |
| 1535 | {"set_term", (PyCFunction)PyCurses_SetTerm}, |
| 1536 | #endif |
| 1537 | {NULL, NULL} /* sentinel */ |
| 1538 | }; |
| 1539 | |
| 1540 | /* Initialization function for the module */ |
| 1541 | |
Guido van Rossum | 3886bb6 | 1998-12-04 18:50:17 +0000 | [diff] [blame] | 1542 | DL_EXPORT(void) |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1543 | initcurses() |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1544 | { |
Guido van Rossum | 8fbf82b | 1995-02-17 13:54:04 +0000 | [diff] [blame] | 1545 | PyObject *m, *d, *v; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1546 | |
| 1547 | /* Create the module and add the functions */ |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1548 | m = Py_InitModule("curses", PyCurses_methods); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1549 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1550 | /* Add some symbolic constants to the module */ |
| 1551 | d = PyModule_GetDict(m); |
Guido van Rossum | e4485b0 | 1994-09-07 14:32:49 +0000 | [diff] [blame] | 1552 | ModDict = d; /* For PyCurses_InitScr */ |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 1553 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1554 | /* For exception curses.error */ |
Guido van Rossum | 0cb96de | 1997-10-01 04:29:29 +0000 | [diff] [blame] | 1555 | PyCursesError = PyErr_NewException("curses.error", NULL, NULL); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1556 | PyDict_SetItemString(d, "error", PyCursesError); |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 1557 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1558 | /* Make the version available */ |
Guido van Rossum | 8fbf82b | 1995-02-17 13:54:04 +0000 | [diff] [blame] | 1559 | v = PyString_FromString(PyCursesVersion); |
| 1560 | PyDict_SetItemString(d, "version", v); |
| 1561 | PyDict_SetItemString(d, "__version__", v); |
| 1562 | Py_DECREF(v); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1563 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1564 | /* Here are some attributes you can add to chars to print */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1565 | SetDictInt("A_NORMAL", A_NORMAL); |
| 1566 | SetDictInt("A_STANDOUT", A_STANDOUT); |
| 1567 | SetDictInt("A_UNDERLINE", A_UNDERLINE); |
| 1568 | SetDictInt("A_REVERSE", A_REVERSE); |
| 1569 | SetDictInt("A_BLINK", A_BLINK); |
| 1570 | SetDictInt("A_DIM", A_DIM); |
| 1571 | SetDictInt("A_BOLD", A_BOLD); |
| 1572 | SetDictInt("A_ALTCHARSET", A_ALTCHARSET); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1573 | |
| 1574 | /* Now set everything up for KEY_ variables */ |
| 1575 | { |
| 1576 | int key; |
| 1577 | char *key_n; |
| 1578 | char *key_n2; |
| 1579 | for (key=KEY_MIN;key < KEY_MAX; key++) { |
| 1580 | key_n = (char *)keyname(key); |
Guido van Rossum | f5c6d47 | 1995-02-07 15:38:32 +0000 | [diff] [blame] | 1581 | if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1582 | continue; |
| 1583 | if (strncmp(key_n,"KEY_F(",6)==0) { |
| 1584 | char *p1, *p2; |
| 1585 | key_n2 = malloc(strlen(key_n)+1); |
| 1586 | p1 = key_n; |
| 1587 | p2 = key_n2; |
| 1588 | while (*p1) { |
| 1589 | if (*p1 != '(' && *p1 != ')') { |
| 1590 | *p2 = *p1; |
| 1591 | p2++; |
| 1592 | } |
| 1593 | p1++; |
| 1594 | } |
| 1595 | *p2 = (char)0; |
| 1596 | } else |
| 1597 | key_n2 = key_n; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1598 | PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key)); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1599 | if (key_n2 != key_n) |
| 1600 | free(key_n2); |
| 1601 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1602 | SetDictInt("KEY_MIN", KEY_MIN); |
| 1603 | SetDictInt("KEY_MAX", KEY_MAX); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1604 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1605 | } |