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