blob: 25a18a5a624d8bf75be28506ac0b203de2c0fd81 [file] [log] [blame]
Guido van Rossumf6971e21994-08-30 12:25:20 +00001/***********************************************************
2Copyright 1994 by Lance Ellinghouse,
3Cathedral City, California Republic, United States of America.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the name of Lance Ellinghouse
12not be used in advertising or publicity pertaining to distribution
13of the software without specific, written prior permission.
14
15LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL,
18INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
19FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossumfbea2f31994-08-31 22:05:27 +000025/******************************************************************
Guido van Rossum56bf2351994-08-31 22:06:24 +000026This is a curses implementation. I have tried to be as complete
Guido van Rossumfbea2f31994-08-31 22:05:27 +000027as possible. If there are functions you need that are not included,
28please let me know and/or send me some diffs.
29
30There 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
36Most of the routines can be looked up using the curses man page.
37
38Here is a list of the currently supported methods and attributes
39in the curses module:
40
41Return Value Func/Attr Description
42--------------------------------------------------------------------------
Guido van Rossum85738471995-02-17 13:50:17 +000043StringObject version A string representing the current
44 version of this module.
Guido van Rossumfbea2f31994-08-31 22:05:27 +000045WindowObject initscr() This initializes the screen for use
46None endwin() Closes down the screen and returns
47 things as they were before calling
48 initscr()
49True/FalseObject isendwin() Has endwin() been called?
Guido van Rossum85738471995-02-17 13:50:17 +000050None doupdate() Updates screen
Guido van Rossumfbea2f31994-08-31 22:05:27 +000051WindowObject newwin(nlines,ncols,begin_y,begin_x)
52 newwin(begin_y,begin_x)
53 newwin() creates and returns
54 a new window.
55None beep() Beep the screen if possible
56None flash() Flash the screen if possible
57None ungetch(int) Push the int back so next getch()
58 will return it.
59 Note: argument is an INT, not a CHAR
60None flushinp() Flush all input buffers
61None cbreak() Enter cbreak mode
62None nocbreak() Leave cbreak mode
63None echo() Enter echo mode
64None noecho() Leave echo mode
65None nl() Enter nl mode
66None nonl() Leave nl mode
67None raw() Enter raw mode
68None noraw() Leave raw mode
69None intrflush(int) Set or reset interruptable flush
70 mode, int=1 if set, 0 if notset.
71None meta(int) Allow 8 bit or 7 bit chars.
72 int=1 is 8 bit, int=0 is 7 bit
73StringObject keyname(int) return the text representation
74 of a KEY_ value. (see below)
75
76Here is a list of the currently supported methods and attributes
77in the WindowObject:
78
79Return Value Func/Attr Description
80--------------------------------------------------------------------------
Guido van Rossum85738471995-02-17 13:50:17 +000081None refresh() Do refresh
82None nooutrefresh() Mark for refresh but wait
83None mvwin(new_y,new_x) Move Window
84None move(new_y,new_x) Move Cursor
Guido van Rossumfbea2f31994-08-31 22:05:27 +000085WindowObject subwin(nlines,ncols,begin_y,begin_x)
86 subwin(begin_y,begin_x)
Guido van Rossum85738471995-02-17 13:50:17 +000087None addch(y,x,ch,attr)
Guido van Rossumfbea2f31994-08-31 22:05:27 +000088 addch(y,x,ch)
89 addch(ch,attr)
90 addch(ch)
Guido van Rossum85738471995-02-17 13:50:17 +000091None insch(y,x,ch,attr)
Guido van Rossumfbea2f31994-08-31 22:05:27 +000092 insch(y,x,ch)
93 insch(ch,attr)
94 insch(ch)
Guido van Rossum85738471995-02-17 13:50:17 +000095None delch(y,x)
Guido van Rossumfbea2f31994-08-31 22:05:27 +000096 delch()
Guido van Rossum85738471995-02-17 13:50:17 +000097None echochar(ch,attr)
Guido van Rossumfbea2f31994-08-31 22:05:27 +000098 echochar(ch)
Guido van Rossum85738471995-02-17 13:50:17 +000099None addstr(y,x,str,attr)
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000100 addstr(y,x,str)
101 addstr(str,attr)
102 addstr(str)
Guido van Rossum85738471995-02-17 13:50:17 +0000103None attron(attr)
104None attroff(attr)
105None attrset(sttr)
106None standend()
107None standout()
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000108None border(ls,rs,ts,bs,tl,tr,bl,br) (accepts 0-8 INT args)
Guido van Rossum85738471995-02-17 13:50:17 +0000109None box(vertch,horch) vertch and horch are INTS
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000110 box()
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000111None hline(y,x,ch,n)
112 hline(ch,n)
113None vline(y,x,ch,n)
114 vline(ch,n)
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000115None erase()
116None deleteln()
117None insertln()
118(y,x) getyx()
119(y,x) getbegyx()
120(y,x) getmaxyx()
121None clear()
122None clrtobot()
123None clrtoeol()
124None scroll()
125None touchwin()
126None touchline(start,count)
127IntObject getch(y,x)
128 getch()
129StringObject getstr(y,x)
130 getstr()
131IntObject inch(y,x)
132 inch()
133None clearok(int) int=0 or int=1
134None idlok(int) int=0 or int=1
135None leaveok(int) int=0 or int=1
136None scrollok(int) int=0 or int=1
137None setscrreg(top,bottom)
Guido van Rossum8fbf82b1995-02-17 13:54:04 +0000138None keypad(int) int=0 or int=1
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000139None nodelay(int) int=0 or int=1
140None notimeout(int) int=0 or int=1
141******************************************************************/
142
143
Guido van Rossumf6971e21994-08-30 12:25:20 +0000144/* curses module */
145
Guido van Rossum602099a1994-09-14 13:32:22 +0000146#include "Python.h"
Guido van Rossumf6971e21994-08-30 12:25:20 +0000147
Guido van Rossum1266a011996-02-25 04:50:31 +0000148#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 Rossumf6971e21994-08-30 12:25:20 +0000152#include <curses.h>
Guido van Rossum1266a011996-02-25 04:50:31 +0000153#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000154
Guido van Rossumf6971e21994-08-30 12:25:20 +0000155typedef struct {
156 PyObject_HEAD
157 SCREEN *scr;
158} PyCursesScreenObject;
159
160typedef struct {
161 PyObject_HEAD
162 WINDOW *win;
163 WINDOW *parent;
164} PyCursesWindowObject;
165
166typedef struct {
167 PyObject_HEAD
168 WINDOW *pad;
169} PyCursesPadObject;
170
171staticforward PyTypeObject PyCursesScreen_Type;
172staticforward PyTypeObject PyCursesWindow_Type;
173staticforward 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 Rossum85738471995-02-17 13:50:17 +0000180static PyObject *PyCursesError; /* For exception curses.error */
181
182/* Catch-all error messages */
183static char *catchall_ERR = "curses function returned ERR";
184static char *catchall_NULL = "curses function returned NULL";
185
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000186/* Tells whether initscr() has been called to initialise curses */
187static int initialised = FALSE;
188
Guido van Rossum85738471995-02-17 13:50:17 +0000189#define ARG_COUNT(X) \
190 (((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
Guido van Rossumf6971e21994-08-30 12:25:20 +0000191
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000192/******************************************************************
193
194Change Log:
195
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000196Version 1.2: 95/02/23 (Steve Clift)
Guido van Rossum85738471995-02-17 13:50:17 +0000197 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 Rossum585c6dc1995-02-24 13:45:43 +0000201 Added keypad() to window method list.
202 Added border(), hline() and vline() window methods.
Guido van Rossum85738471995-02-17 13:50:17 +0000203
Guido van Rossum56bf2351994-08-31 22:06:24 +0000204Version 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 Rossum85738471995-02-17 13:50:17 +0000211
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000212Version 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 Rossum85738471995-02-17 13:50:17 +0000217
Guido van Rossum8fbf82b1995-02-17 13:54:04 +0000218char *PyCursesVersion = "1.2";
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000219
Guido van Rossum85738471995-02-17 13:50:17 +0000220/*
221 * Check the return code from a curses function and return None
222 * or raise an exception as appropriate.
223 */
224
225static PyObject *
226PyCursesCheckERR(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 Rossum585c6dc1995-02-24 13:45:43 +0000248static int
249PyCursesInitialised()
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 Rossumf6971e21994-08-30 12:25:20 +0000260/* ------------- SCREEN routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000261
Guido van Rossumf6971e21994-08-30 12:25:20 +0000262#ifdef NOT_YET
263static PyObject *
264PyCursesScreen_New(arg)
265 PyObject * arg;
266{
267 char *term_type;
268 PyFileObject *in_fo;
269 PyFileObject *out_fo;
270 PyCursesScreenObject *xp;
Guido van Rossum85738471995-02-17 13:50:17 +0000271 xp = PyObject_NEW(PyCursesScreenObject, &PyCursesScreen_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000272 if (xp == NULL)
273 return NULL;
274 return (PyObject *)xp;
275}
276#endif
Guido van Rossum85738471995-02-17 13:50:17 +0000277
278
Guido van Rossumf6971e21994-08-30 12:25:20 +0000279/* ------------- WINDOW routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000280
Guido van Rossumf6971e21994-08-30 12:25:20 +0000281static PyObject *
282PyCursesWindow_New(win)
283 WINDOW *win;
284{
285 PyCursesWindowObject *wo;
Guido van Rossum85738471995-02-17 13:50:17 +0000286
287 wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000288 if (wo == NULL)
289 return NULL;
290 wo->win = win;
291 wo->parent = (WINDOW *)NULL;
292 return (PyObject *)wo;
293}
294
295static void
296PyCursesWindow_Dealloc(wo)
297 PyCursesWindowObject *wo;
298{
299 if (wo->win != stdscr)
300 delwin(wo->win);
301 PyMem_DEL(wo);
302}
303
304static PyObject *
305PyCursesWindow_Refresh(self,arg)
306 PyCursesWindowObject *self;
307 PyObject * arg;
308{
309 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000310 return NULL;
311 return PyCursesCheckERR(wrefresh(self->win), "wrefresh");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000312}
313
314static PyObject *
315PyCursesWindow_NoOutRefresh(self,arg)
316 PyCursesWindowObject *self;
317 PyObject * arg;
318{
319 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000320 return NULL;
321 return PyCursesCheckERR(wnoutrefresh(self->win), "wnoutrefresh");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000322}
323
324static PyObject *
325PyCursesWindow_MoveWin(self,arg)
326 PyCursesWindowObject *self;
327 PyObject * arg;
328{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000329 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000330 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
331 return NULL;
332 return PyCursesCheckERR(mvwin(self->win,y,x), "mvwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000333}
334
335static PyObject *
336PyCursesWindow_Move(self,arg)
337 PyCursesWindowObject *self;
338 PyObject * arg;
339{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000340 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000341 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
342 return NULL;
343 return PyCursesCheckERR(wmove(self->win,y,x), "wmove");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000344}
345
346static PyObject *
347PyCursesWindow_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 Rossum85738471995-02-17 13:50:17 +0000354
Guido van Rossumf6971e21994-08-30 12:25:20 +0000355 nlines = 0;
356 ncols = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000357 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 Rossumf6971e21994-08-30 12:25:20 +0000364 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +0000365 return NULL;
366 break;
367 default:
368 PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
369 return NULL;
370 }
Guido van Rossumf6971e21994-08-30 12:25:20 +0000371 win = subwin(self->win,nlines,ncols,begin_y,begin_x);
372 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +0000373 PyErr_SetString(PyCursesError, catchall_NULL);
374 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000375 }
376 rtn_win = (PyCursesWindowObject *)PyCursesWindow_New(win);
377 rtn_win->parent = self->win;
378 return (PyObject *)rtn_win;
379}
380
381static PyObject *
382PyCursesWindow_AddCh(self,arg)
383 PyCursesWindowObject *self;
384 PyObject * arg;
385{
386 int rtn;
387 int x, y;
388 int ch;
Guido van Rossum85738471995-02-17 13:50:17 +0000389 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 Rossumf6971e21994-08-30 12:25:20 +0000397 case 2:
Guido van Rossum85738471995-02-17 13:50:17 +0000398 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
399 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000400 use_attr = TRUE;
401 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000402 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 Rossumf6971e21994-08-30 12:25:20 +0000412 default:
Guido van Rossum85738471995-02-17 13:50:17 +0000413 PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
414 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000415 }
Guido van Rossum85738471995-02-17 13:50:17 +0000416
Guido van Rossumf6971e21994-08-30 12:25:20 +0000417 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 Rossum85738471995-02-17 13:50:17 +0000427
428 return PyCursesCheckERR(rtn, "[mv]waddch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000429}
430
431static PyObject *
432PyCursesWindow_InsCh(self,arg)
433 PyCursesWindowObject *self;
434 PyObject * arg;
435{
436 int rtn;
437 int x, y;
438 int ch;
Guido van Rossum85738471995-02-17 13:50:17 +0000439 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 Rossumf6971e21994-08-30 12:25:20 +0000447 case 2:
Guido van Rossum85738471995-02-17 13:50:17 +0000448 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
449 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000450 use_attr = TRUE;
451 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000452 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 Rossumf6971e21994-08-30 12:25:20 +0000462 default:
Guido van Rossum85738471995-02-17 13:50:17 +0000463 PyErr_SetString(PyExc_TypeError, "insch requires 1 to 4 arguments");
464 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000465 }
Guido van Rossum85738471995-02-17 13:50:17 +0000466
Guido van Rossumf6971e21994-08-30 12:25:20 +0000467 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 Rossum85738471995-02-17 13:50:17 +0000477
478 return PyCursesCheckERR(rtn, "[mv]winsch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000479}
480
481static PyObject *
482PyCursesWindow_DelCh(self,arg)
483 PyCursesWindowObject *self;
484 PyObject * arg;
485{
486 int rtn;
487 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000488
489 switch (ARG_COUNT(arg)) {
490 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000491 rtn = wdelch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000492 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 Rossumf6971e21994-08-30 12:25:20 +0000501 }
Guido van Rossum85738471995-02-17 13:50:17 +0000502
503 return PyCursesCheckERR(rtn, "[mv]wdelch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000504}
505
506static PyObject *
507PyCursesWindow_EchoChar(self,arg)
508 PyCursesWindowObject *self;
509 PyObject * arg;
510{
511 int rtn;
512 int ch;
Guido van Rossum85738471995-02-17 13:50:17 +0000513 int attr, attr_old;
514
515 switch (ARG_COUNT(arg)) {
516 case 1:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000517 if (!PyArg_Parse(arg,"i;ch", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000518 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 Rossumf6971e21994-08-30 12:25:20 +0000524 attr_old = getattrs(self->win);
525 wattrset(self->win,attr);
Guido van Rossum85738471995-02-17 13:50:17 +0000526 rtn = wechochar(self->win,ch);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000527 wattrset(self->win,attr_old);
Guido van Rossum85738471995-02-17 13:50:17 +0000528 break;
529 default:
530 PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
531 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000532 }
Guido van Rossum85738471995-02-17 13:50:17 +0000533
534 return PyCursesCheckERR(rtn, "wechochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000535}
536
537static PyObject *
538PyCursesWindow_AddStr(self,arg)
539 PyCursesWindowObject *self;
540 PyObject * arg;
541{
542 int rtn;
543 int x, y;
544 char *str;
Guido van Rossum85738471995-02-17 13:50:17 +0000545 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 Rossumf6971e21994-08-30 12:25:20 +0000571 }
Guido van Rossum85738471995-02-17 13:50:17 +0000572
Guido van Rossumf6971e21994-08-30 12:25:20 +0000573 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 Rossum85738471995-02-17 13:50:17 +0000583
584 return PyCursesCheckERR(rtn, "[mv]waddstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000585}
586
587static PyObject *
588PyCursesWindow_AttrOn(self,arg)
589 PyCursesWindowObject *self;
590 PyObject * arg;
591{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000592 int ch;
593 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000594 return NULL;
595 wattron(self->win,ch);
596 Py_INCREF(Py_None);
597 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000598}
599
600static PyObject *
601PyCursesWindow_AttrOff(self,arg)
602 PyCursesWindowObject *self;
603 PyObject * arg;
604{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000605 int ch;
606 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000607 return NULL;
608 wattroff(self->win,ch);
609 Py_INCREF(Py_None);
610 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000611}
612
613static PyObject *
614PyCursesWindow_AttrSet(self,arg)
615 PyCursesWindowObject *self;
616 PyObject * arg;
617{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000618 int ch;
619 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000620 return NULL;
621 wattrset(self->win,ch);
622 Py_INCREF(Py_None);
623 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000624}
625
626static PyObject *
627PyCursesWindow_StandEnd(self,arg)
628 PyCursesWindowObject *self;
629 PyObject * arg;
630{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000631 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000632 return NULL;
633 wstandend(self->win);
634 Py_INCREF(Py_None);
635 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000636}
637
638static PyObject *
639PyCursesWindow_StandOut(self,arg)
640 PyCursesWindowObject *self;
641 PyObject * arg;
642{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000643 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000644 return NULL;
645 wstandout(self->win);
646 Py_INCREF(Py_None);
647 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000648}
649
650static PyObject *
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000651PyCursesWindow_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
665static PyObject *
Guido van Rossumf6971e21994-08-30 12:25:20 +0000666PyCursesWindow_Box(self,arg)
667 PyCursesWindowObject *self;
668 PyObject * arg;
669{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000670 int ch1=0,ch2=0;
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000671 if (!PyArg_NoArgs(arg)) {
Guido van Rossumf6971e21994-08-30 12:25:20 +0000672 PyErr_Clear();
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000673 if (!PyArg_Parse(arg,"(ii);vertch,horch", &ch1, &ch2))
674 return NULL;
675 }
Guido van Rossum85738471995-02-17 13:50:17 +0000676 box(self->win,ch1,ch2);
677 Py_INCREF(Py_None);
678 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000679}
680
681static PyObject *
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000682PyCursesWindow_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
706static PyObject *
707PyCursesWindow_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
731static PyObject *
Guido van Rossumf6971e21994-08-30 12:25:20 +0000732PyCursesWindow_Erase(self,arg)
733 PyCursesWindowObject *self;
734 PyObject * arg;
735{
736 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000737 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000738 werase(self->win);
739 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000740 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000741}
742
743static PyObject *
744PyCursesWindow_DeleteLine(self,arg)
745 PyCursesWindowObject *self;
746 PyObject * arg;
747{
748 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000749 return NULL;
750 return PyCursesCheckERR(wdeleteln(self->win), "wdeleteln");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000751}
752
753static PyObject *
754PyCursesWindow_InsertLine(self,arg)
755 PyCursesWindowObject *self;
756 PyObject * arg;
757{
758 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000759 return NULL;
760 return PyCursesCheckERR(winsertln(self->win), "winsertln");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000761}
762
763static PyObject *
764PyCursesWindow_GetYX(self,arg)
765 PyCursesWindowObject *self;
766 PyObject * arg;
767{
768 int x, y;
769 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000770 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000771 getyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000772 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000773}
774
775static PyObject *
776PyCursesWindow_GetBegYX(self,arg)
777 PyCursesWindowObject *self;
778 PyObject * arg;
779{
780 int x, y;
781 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000782 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000783 getbegyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000784 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000785}
786
787static PyObject *
788PyCursesWindow_GetMaxYX(self,arg)
789 PyCursesWindowObject *self;
790 PyObject * arg;
791{
792 int x, y;
793 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000794 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000795 getmaxyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000796 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000797}
798
799static PyObject *
800PyCursesWindow_Clear(self,arg)
801 PyCursesWindowObject *self;
802 PyObject * arg;
803{
804 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000805 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000806 wclear(self->win);
807 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000808 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000809}
810
811static PyObject *
812PyCursesWindow_ClearToBottom(self,arg)
813 PyCursesWindowObject *self;
814 PyObject * arg;
815{
816 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000817 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000818 wclrtobot(self->win);
819 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000820 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000821}
822
823static PyObject *
824PyCursesWindow_ClearToEOL(self,arg)
825 PyCursesWindowObject *self;
826 PyObject * arg;
827{
828 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000829 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000830 wclrtoeol(self->win);
831 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000832 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000833}
834
835static PyObject *
836PyCursesWindow_Scroll(self,arg)
837 PyCursesWindowObject *self;
838 PyObject * arg;
839{
840 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000841 return NULL;
842 return PyCursesCheckERR(scroll(self->win), "scroll");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000843}
844
845static PyObject *
846PyCursesWindow_TouchWin(self,arg)
847 PyCursesWindowObject *self;
848 PyObject * arg;
849{
850 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000851 return NULL;
852 return PyCursesCheckERR(touchwin(self->win), "touchwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000853}
854
855static PyObject *
856PyCursesWindow_TouchLine(self,arg)
857 PyCursesWindowObject *self;
858 PyObject * arg;
859{
860 int st, cnt;
Guido van Rossum85738471995-02-17 13:50:17 +0000861 if (!PyArg_Parse(arg,"(ii);start,count",&st,&cnt))
862 return NULL;
863 return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000864}
865
866static PyObject *
867PyCursesWindow_GetCh(self,arg)
868 PyCursesWindowObject *self;
869 PyObject * arg;
870{
871 int x, y;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000872 int rtn;
Guido van Rossum85738471995-02-17 13:50:17 +0000873
874 switch (ARG_COUNT(arg)) {
875 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000876 rtn = wgetch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000877 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 Rossumf6971e21994-08-30 12:25:20 +0000889}
890
891static PyObject *
892PyCursesWindow_GetStr(self,arg)
893 PyCursesWindowObject *self;
894 PyObject * arg;
895{
896 int x, y;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000897 char rtn[1024]; /* This should be big enough.. I hope */
898 int rtn2;
Guido van Rossum85738471995-02-17 13:50:17 +0000899
900 switch (ARG_COUNT(arg)) {
901 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000902 rtn2 = wgetstr(self->win,rtn);
Guido van Rossum85738471995-02-17 13:50:17 +0000903 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 Rossumf6971e21994-08-30 12:25:20 +0000914 if (rtn2 == ERR)
915 rtn[0] = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000916 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000917}
918
919static PyObject *
920PyCursesWindow_InCh(self,arg)
921 PyCursesWindowObject *self;
922 PyObject * arg;
923{
Guido van Rossum85738471995-02-17 13:50:17 +0000924 int x, y, rtn;
925
926 switch (ARG_COUNT(arg)) {
927 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000928 rtn = winch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000929 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 Rossumf6971e21994-08-30 12:25:20 +0000941}
942
943static PyObject *
944PyCursesWindow_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 Rossum85738471995-02-17 13:50:17 +0000950 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000951 clearok(self->win,val);
952 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000953 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000954}
955
956static PyObject *
957PyCursesWindow_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 Rossum85738471995-02-17 13:50:17 +0000963 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000964 idlok(self->win,val);
965 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000966 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000967}
968
969static PyObject *
970PyCursesWindow_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 Rossum85738471995-02-17 13:50:17 +0000976 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000977 leaveok(self->win,val);
978 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000979 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000980}
981
982static PyObject *
983PyCursesWindow_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 Rossum85738471995-02-17 13:50:17 +0000989 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000990 scrollok(self->win,val);
991 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000992 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000993}
994
995static PyObject *
996PyCursesWindow_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 Rossum85738471995-02-17 13:50:17 +00001002 return NULL;
1003 return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001004}
1005
1006static PyObject *
1007PyCursesWindow_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 Rossum85738471995-02-17 13:50:17 +00001013 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001014 keypad(self->win,ch);
1015 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001016 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001017}
1018
1019static PyObject *
1020PyCursesWindow_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 Rossum85738471995-02-17 13:50:17 +00001026 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001027 nodelay(self->win,ch);
1028 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001029 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001030}
1031
1032static PyObject *
1033PyCursesWindow_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 Rossum85738471995-02-17 13:50:17 +00001039 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001040 notimeout(self->win,ch);
1041 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001042 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001043}
1044
1045static PyMethodDef PyCursesWindow_Methods[] = {
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001046 {"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 Rossum585c6dc1995-02-24 13:45:43 +00001088 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00001089};
1090
1091static PyObject *
1092PyCursesWindow_GetAttr(self, name)
1093 PyCursesWindowObject *self;
1094 char *name;
1095{
Guido van Rossuma597dde1995-01-10 20:56:29 +00001096 return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001097}
1098
Guido van Rossum85738471995-02-17 13:50:17 +00001099
Guido van Rossumf6971e21994-08-30 12:25:20 +00001100/* --------------- PAD routines ---------------- */
Guido van Rossum85738471995-02-17 13:50:17 +00001101
1102#ifdef NOT_YET
Guido van Rossumf6971e21994-08-30 12:25:20 +00001103static PyObject *
1104PyCursesPad_New(pad)
1105 WINDOW *pad;
1106{
1107 PyCursesPadObject *po;
Guido van Rossum85738471995-02-17 13:50:17 +00001108 po = PyObject_NEW(PyCursesPadObject, &PyCursesPad_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001109 if (po == NULL)
1110 return NULL;
1111 po->pad = pad;
1112 return (PyObject *)po;
1113}
Guido van Rossum85738471995-02-17 13:50:17 +00001114#endif
1115
Guido van Rossumf6971e21994-08-30 12:25:20 +00001116
1117/* -------------------------------------------------------*/
Guido van Rossum85738471995-02-17 13:50:17 +00001118
Guido van Rossumf6971e21994-08-30 12:25:20 +00001119static 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
1138static 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
1157static 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 Rossum85738471995-02-17 13:50:17 +00001176
Guido van Rossumf6971e21994-08-30 12:25:20 +00001177/* -------------------------------------------------------*/
1178
Guido van Rossume4485b01994-09-07 14:32:49 +00001179static PyObject *ModDict;
1180
Guido van Rossumf6971e21994-08-30 12:25:20 +00001181static PyObject *
1182PyCurses_InitScr(self, args)
1183 PyObject * self;
1184 PyObject * args;
1185{
Guido van Rossum56bf2351994-08-31 22:06:24 +00001186 WINDOW *win;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001187 if (!PyArg_NoArgs(args))
Guido van Rossum85738471995-02-17 13:50:17 +00001188 return NULL;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001189 if (initialised == TRUE) {
Guido van Rossumf6971e21994-08-30 12:25:20 +00001190 wrefresh(stdscr);
1191 return (PyObject *)PyCursesWindow_New(stdscr);
1192 }
Guido van Rossum56bf2351994-08-31 22:06:24 +00001193
1194 win = initscr();
Guido van Rossum85738471995-02-17 13:50:17 +00001195 if (win == NULL) {
1196 PyErr_SetString(PyCursesError, catchall_NULL);
1197 return NULL;
1198 }
1199
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001200 initialised = TRUE;
Guido van Rossum56bf2351994-08-31 22:06:24 +00001201
1202/* This was moved from initcurses() because core dumped on SGI */
Guido van Rossum85738471995-02-17 13:50:17 +00001203/* 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 Rossum56bf2351994-08-31 22:06:24 +00001206
1207 /* Here are some graphic symbols you can use */
Guido van Rossum85738471995-02-17 13:50:17 +00001208 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 Rossum56bf2351994-08-31 22:06:24 +00001233
1234 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001235}
1236
1237static PyObject *
1238PyCurses_EndWin(self, args)
1239 PyObject * self;
1240 PyObject * args;
1241{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001242 if (!PyArg_NoArgs(args) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001243 return NULL;
1244 return PyCursesCheckERR(endwin(), "endwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001245}
1246
1247static PyObject *
1248PyCurses_IsEndWin(self, args)
1249 PyObject * self;
1250 PyObject * args;
1251{
1252 if (!PyArg_NoArgs(args))
Guido van Rossum85738471995-02-17 13:50:17 +00001253 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001254 if (isendwin() == FALSE) {
1255 Py_INCREF(Py_False);
1256 return Py_False;
1257 }
1258 Py_INCREF(Py_True);
1259 return Py_True;
1260}
1261
1262static PyObject *
1263PyCurses_DoUpdate(self,arg)
1264 PyObject * self;
1265 PyObject * arg;
1266{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001267 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001268 return NULL;
1269 return PyCursesCheckERR(doupdate(), "doupdate");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001270}
1271
1272static PyObject *
1273PyCurses_NewWindow(self,arg)
1274 PyObject * self;
1275 PyObject * arg;
1276{
1277 WINDOW *win;
1278 int nlines, ncols, begin_y, begin_x;
Guido van Rossum85738471995-02-17 13:50:17 +00001279
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001280 if (!PyCursesInitialised())
1281 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +00001282 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 Rossumf6971e21994-08-30 12:25:20 +00001290 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +00001291 return NULL;
1292 break;
1293 default:
1294 PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
1295 return NULL;
1296 }
1297
Guido van Rossumf6971e21994-08-30 12:25:20 +00001298 win = newwin(nlines,ncols,begin_y,begin_x);
1299 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +00001300 PyErr_SetString(PyCursesError, catchall_NULL);
1301 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001302 }
Guido van Rossum85738471995-02-17 13:50:17 +00001303
Guido van Rossumf6971e21994-08-30 12:25:20 +00001304 return (PyObject *)PyCursesWindow_New(win);
1305}
1306
1307static PyObject *
1308PyCurses_Beep(self,arg)
1309 PyObject * self;
1310 PyObject * arg;
1311{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001312 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001313 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001314 beep();
1315 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001316 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001317}
1318
1319static PyObject *
1320PyCurses_Flash(self,arg)
1321 PyObject * self;
1322 PyObject * arg;
1323{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001324 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001325 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001326 flash();
1327 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001328 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001329}
1330
1331static PyObject *
1332PyCurses_UngetCh(self,arg)
1333 PyObject * self;
1334 PyObject * arg;
1335{
1336 int ch;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001337 if (!PyArg_Parse(arg,"i;integer",&ch) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001338 return NULL;
1339 return PyCursesCheckERR(ungetch(ch), "ungetch");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001340}
1341
1342static PyObject *
1343PyCurses_FlushInp(self,arg)
1344 PyObject * self;
1345 PyObject * arg;
1346{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001347 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001348 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001349 flushinp();
1350 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001351 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001352}
1353
1354static PyObject *
1355PyCurses_CBreak(self,arg)
1356 PyObject * self;
1357 PyObject * arg;
1358{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001359 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001360 return NULL;
1361 return PyCursesCheckERR(cbreak(), "cbreak");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001362}
1363
1364static PyObject *
1365PyCurses_NoCBreak(self,arg)
1366 PyObject * self;
1367 PyObject * arg;
1368{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001369 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001370 return NULL;
1371 return PyCursesCheckERR(nocbreak(), "nocbreak");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001372}
1373
1374static PyObject *
1375PyCurses_Echo(self,arg)
1376 PyObject * self;
1377 PyObject * arg;
1378{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001379 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001380 return NULL;
1381 return PyCursesCheckERR(echo(), "echo");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001382}
1383
1384static PyObject *
1385PyCurses_NoEcho(self,arg)
1386 PyObject * self;
1387 PyObject * arg;
1388{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001389 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001390 return NULL;
1391 return PyCursesCheckERR(noecho(), "noecho");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001392}
1393
1394static PyObject *
1395PyCurses_Nl(self,arg)
1396 PyObject * self;
1397 PyObject * arg;
1398{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001399 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001400 return NULL;
1401 return PyCursesCheckERR(nl(), "nl");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001402}
1403
1404static PyObject *
1405PyCurses_NoNl(self,arg)
1406 PyObject * self;
1407 PyObject * arg;
1408{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001409 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001410 return NULL;
1411 return PyCursesCheckERR(nonl(), "nonl");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001412}
1413
1414static PyObject *
1415PyCurses_Raw(self,arg)
1416 PyObject * self;
1417 PyObject * arg;
1418{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001419 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001420 return NULL;
1421 return PyCursesCheckERR(raw(), "raw");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001422}
1423
1424static PyObject *
1425PyCurses_NoRaw(self,arg)
1426 PyObject * self;
1427 PyObject * arg;
1428{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001429 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001430 return NULL;
1431 return PyCursesCheckERR(noraw(), "noraw");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001432}
1433
1434static PyObject *
1435PyCurses_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 Rossum85738471995-02-17 13:50:17 +00001441 return NULL;
1442 return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001443}
1444
1445static PyObject *
1446PyCurses_Meta(self,arg)
1447 PyObject * self;
1448 PyObject * arg;
1449{
1450 int ch;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001451 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001452 return NULL;
1453 return PyCursesCheckERR(meta(stdscr, ch), "meta");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001454}
1455
1456static PyObject *
1457PyCurses_KeyName(self,arg)
1458 PyObject * self;
1459 PyObject * arg;
1460{
Guido van Rossum85738471995-02-17 13:50:17 +00001461 char *knp;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001462 int ch;
1463 if (!PyArg_Parse(arg,"i",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001464 return NULL;
1465 knp = keyname(ch);
1466 return PyString_FromString((knp == NULL) ? "" : knp);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001467}
1468
1469#ifdef NOT_YET
1470static PyObject *
1471PyCurses_NewTerm(self, args)
1472 PyObject * self;
1473 PyObject * args;
1474{
1475}
1476
1477static PyObject *
1478PyCurses_SetTerm(self, args)
1479 PyObject * self;
1480 PyObject * args;
1481{
1482}
1483#endif
1484
1485/* List of functions defined in the module */
1486
1487static 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
1517void
Guido van Rossum56bf2351994-08-31 22:06:24 +00001518initcurses()
Guido van Rossumf6971e21994-08-30 12:25:20 +00001519{
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00001520 PyObject *m, *d, *v;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001521
1522 /* Create the module and add the functions */
Guido van Rossum56bf2351994-08-31 22:06:24 +00001523 m = Py_InitModule("curses", PyCurses_methods);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001524
Guido van Rossumf6971e21994-08-30 12:25:20 +00001525 /* Add some symbolic constants to the module */
1526 d = PyModule_GetDict(m);
Guido van Rossume4485b01994-09-07 14:32:49 +00001527 ModDict = d; /* For PyCurses_InitScr */
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001528
Guido van Rossum85738471995-02-17 13:50:17 +00001529 /* For exception curses.error */
1530 PyCursesError = PyString_FromString("curses.error");
1531 PyDict_SetItemString(d, "error", PyCursesError);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001532
Guido van Rossum85738471995-02-17 13:50:17 +00001533 /* Make the version available */
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00001534 v = PyString_FromString(PyCursesVersion);
1535 PyDict_SetItemString(d, "version", v);
1536 PyDict_SetItemString(d, "__version__", v);
1537 Py_DECREF(v);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001538
Guido van Rossumf6971e21994-08-30 12:25:20 +00001539 /* Here are some attributes you can add to chars to print */
Guido van Rossum85738471995-02-17 13:50:17 +00001540 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 Rossumf6971e21994-08-30 12:25:20 +00001548
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 Rossumf5c6d471995-02-07 15:38:32 +00001556 if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001557 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 Rossum85738471995-02-17 13:50:17 +00001573 PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
Guido van Rossumf6971e21994-08-30 12:25:20 +00001574 if (key_n2 != key_n)
1575 free(key_n2);
1576 }
Guido van Rossum85738471995-02-17 13:50:17 +00001577 SetDictInt("KEY_MIN", KEY_MIN);
1578 SetDictInt("KEY_MAX", KEY_MAX);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001579 }
1580
1581 /* Check for errors */
1582 if (PyErr_Occurred())
Guido van Rossum85738471995-02-17 13:50:17 +00001583 Py_FatalError("can't initialize module curses");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001584}