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