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