blob: e57e80216469c443f97e5af859d199bce2bfbd54 [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
148#include <curses.h>
149
Guido van Rossumf6971e21994-08-30 12:25:20 +0000150typedef struct {
151 PyObject_HEAD
152 SCREEN *scr;
153} PyCursesScreenObject;
154
155typedef struct {
156 PyObject_HEAD
157 WINDOW *win;
158 WINDOW *parent;
159} PyCursesWindowObject;
160
161typedef struct {
162 PyObject_HEAD
163 WINDOW *pad;
164} PyCursesPadObject;
165
166staticforward PyTypeObject PyCursesScreen_Type;
167staticforward PyTypeObject PyCursesWindow_Type;
168staticforward PyTypeObject PyCursesPad_Type;
169
170#define PyCursesScreen_Check(v) ((v)->ob_type == &PyCursesScreen_Type)
171#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
172#define PyCursesPad_Check(v) ((v)->ob_type == &PyCursesPad_Type)
173
174/* Defines */
Guido van Rossum85738471995-02-17 13:50:17 +0000175static PyObject *PyCursesError; /* For exception curses.error */
176
177/* Catch-all error messages */
178static char *catchall_ERR = "curses function returned ERR";
179static char *catchall_NULL = "curses function returned NULL";
180
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000181/* Tells whether initscr() has been called to initialise curses */
182static int initialised = FALSE;
183
Guido van Rossum85738471995-02-17 13:50:17 +0000184#define ARG_COUNT(X) \
185 (((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
Guido van Rossumf6971e21994-08-30 12:25:20 +0000186
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000187/******************************************************************
188
189Change Log:
190
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000191Version 1.2: 95/02/23 (Steve Clift)
Guido van Rossum85738471995-02-17 13:50:17 +0000192 Fixed several potential core-dumping bugs.
193 Reworked arg parsing where variable arg lists are used.
194 Generate exceptions when ERR or NULL is returned by curses functions.
195 Changed return types to match SysV Curses manual descriptions.
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000196 Added keypad() to window method list.
197 Added border(), hline() and vline() window methods.
Guido van Rossum85738471995-02-17 13:50:17 +0000198
Guido van Rossum56bf2351994-08-31 22:06:24 +0000199Version 1.1: 94/08/31:
200 Minor fixes given by Guido.
201 Changed 'ncurses' to 'curses'
202 Changed '__version__' to 'version'
203 Added PyErr_Clear() where needed
204 Moved ACS_* attribute initialization to PyCurses_InitScr() to fix
205 crash on SGI
Guido van Rossum85738471995-02-17 13:50:17 +0000206
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000207Version 1.0: 94/08/30:
208 This is the first release of this software.
209 Released to the Internet via python-list@cwi.nl
210
211******************************************************************/
Guido van Rossum85738471995-02-17 13:50:17 +0000212
Guido van Rossum8fbf82b1995-02-17 13:54:04 +0000213char *PyCursesVersion = "1.2";
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000214
Guido van Rossum85738471995-02-17 13:50:17 +0000215/*
216 * Check the return code from a curses function and return None
217 * or raise an exception as appropriate.
218 */
219
220static PyObject *
221PyCursesCheckERR(code, fname)
222 int code;
223 char *fname;
224{
225 char buf[100];
226
227 if (code != ERR) {
228 Py_INCREF(Py_None);
229 return Py_None;
230 } else {
231 if (fname == NULL) {
232 PyErr_SetString(PyCursesError, catchall_ERR);
233 } else {
234 strcpy(buf, fname);
235 strcat(buf, "() returned ERR");
236 PyErr_SetString(PyCursesError, buf);
237 }
238 return NULL;
239 }
240}
241
242
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000243static int
244PyCursesInitialised()
245{
246 if (initialised == TRUE)
247 return 1;
248 else {
249 PyErr_SetString(PyCursesError, "must call initscr() first");
250 return 0;
251 }
252}
253
254
Guido van Rossumf6971e21994-08-30 12:25:20 +0000255/* ------------- SCREEN routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000256
Guido van Rossumf6971e21994-08-30 12:25:20 +0000257#ifdef NOT_YET
258static PyObject *
259PyCursesScreen_New(arg)
260 PyObject * arg;
261{
262 char *term_type;
263 PyFileObject *in_fo;
264 PyFileObject *out_fo;
265 PyCursesScreenObject *xp;
Guido van Rossum85738471995-02-17 13:50:17 +0000266 xp = PyObject_NEW(PyCursesScreenObject, &PyCursesScreen_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000267 if (xp == NULL)
268 return NULL;
269 return (PyObject *)xp;
270}
271#endif
Guido van Rossum85738471995-02-17 13:50:17 +0000272
273
Guido van Rossumf6971e21994-08-30 12:25:20 +0000274/* ------------- WINDOW routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000275
Guido van Rossumf6971e21994-08-30 12:25:20 +0000276static PyObject *
277PyCursesWindow_New(win)
278 WINDOW *win;
279{
280 PyCursesWindowObject *wo;
Guido van Rossum85738471995-02-17 13:50:17 +0000281
282 wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000283 if (wo == NULL)
284 return NULL;
285 wo->win = win;
286 wo->parent = (WINDOW *)NULL;
287 return (PyObject *)wo;
288}
289
290static void
291PyCursesWindow_Dealloc(wo)
292 PyCursesWindowObject *wo;
293{
294 if (wo->win != stdscr)
295 delwin(wo->win);
296 PyMem_DEL(wo);
297}
298
299static PyObject *
300PyCursesWindow_Refresh(self,arg)
301 PyCursesWindowObject *self;
302 PyObject * arg;
303{
304 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000305 return NULL;
306 return PyCursesCheckERR(wrefresh(self->win), "wrefresh");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000307}
308
309static PyObject *
310PyCursesWindow_NoOutRefresh(self,arg)
311 PyCursesWindowObject *self;
312 PyObject * arg;
313{
314 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000315 return NULL;
316 return PyCursesCheckERR(wnoutrefresh(self->win), "wnoutrefresh");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000317}
318
319static PyObject *
320PyCursesWindow_MoveWin(self,arg)
321 PyCursesWindowObject *self;
322 PyObject * arg;
323{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000324 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000325 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
326 return NULL;
327 return PyCursesCheckERR(mvwin(self->win,y,x), "mvwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000328}
329
330static PyObject *
331PyCursesWindow_Move(self,arg)
332 PyCursesWindowObject *self;
333 PyObject * arg;
334{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000335 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000336 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
337 return NULL;
338 return PyCursesCheckERR(wmove(self->win,y,x), "wmove");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000339}
340
341static PyObject *
342PyCursesWindow_SubWin(self,arg)
343 PyCursesWindowObject *self;
344 PyObject * arg;
345{
346 WINDOW *win;
347 PyCursesWindowObject *rtn_win;
348 int nlines, ncols, begin_y, begin_x;
Guido van Rossum85738471995-02-17 13:50:17 +0000349
Guido van Rossumf6971e21994-08-30 12:25:20 +0000350 nlines = 0;
351 ncols = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000352 switch (ARG_COUNT(arg)) {
353 case 2:
354 if (!PyArg_Parse(arg,"(ii);begin_y,begin_x",&begin_y,&begin_x))
355 return NULL;
356 break;
357 case 4:
358 if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x",
Guido van Rossumf6971e21994-08-30 12:25:20 +0000359 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +0000360 return NULL;
361 break;
362 default:
363 PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
364 return NULL;
365 }
Guido van Rossumf6971e21994-08-30 12:25:20 +0000366 win = subwin(self->win,nlines,ncols,begin_y,begin_x);
367 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +0000368 PyErr_SetString(PyCursesError, catchall_NULL);
369 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000370 }
371 rtn_win = (PyCursesWindowObject *)PyCursesWindow_New(win);
372 rtn_win->parent = self->win;
373 return (PyObject *)rtn_win;
374}
375
376static PyObject *
377PyCursesWindow_AddCh(self,arg)
378 PyCursesWindowObject *self;
379 PyObject * arg;
380{
381 int rtn;
382 int x, y;
383 int ch;
Guido van Rossum85738471995-02-17 13:50:17 +0000384 int attr, attr_old;
385 int use_xy = FALSE, use_attr = FALSE;
386
387 switch (ARG_COUNT(arg)) {
388 case 1:
389 if (!PyArg_Parse(arg, "i;ch", &ch))
390 return NULL;
391 break;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000392 case 2:
Guido van Rossum85738471995-02-17 13:50:17 +0000393 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
394 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000395 use_attr = TRUE;
396 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000397 case 3:
398 if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch))
399 return NULL;
400 use_xy = TRUE;
401 break;
402 case 4:
403 if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr))
404 return NULL;
405 use_xy = use_attr = TRUE;
406 break;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000407 default:
Guido van Rossum85738471995-02-17 13:50:17 +0000408 PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
409 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000410 }
Guido van Rossum85738471995-02-17 13:50:17 +0000411
Guido van Rossumf6971e21994-08-30 12:25:20 +0000412 if (use_attr == TRUE) {
413 attr_old = getattrs(self->win);
414 wattrset(self->win,attr);
415 }
416 if (use_xy == TRUE)
417 rtn = mvwaddch(self->win,y,x,ch);
418 else
419 rtn = waddch(self->win,ch);
420 if (use_attr == TRUE)
421 wattrset(self->win,attr_old);
Guido van Rossum85738471995-02-17 13:50:17 +0000422
423 return PyCursesCheckERR(rtn, "[mv]waddch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000424}
425
426static PyObject *
427PyCursesWindow_InsCh(self,arg)
428 PyCursesWindowObject *self;
429 PyObject * arg;
430{
431 int rtn;
432 int x, y;
433 int ch;
Guido van Rossum85738471995-02-17 13:50:17 +0000434 int attr, attr_old;
435 int use_xy = TRUE, use_attr = FALSE;
436
437 switch (ARG_COUNT(arg)) {
438 case 1:
439 if (!PyArg_Parse(arg, "i;ch", &ch))
440 return NULL;
441 break;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000442 case 2:
Guido van Rossum85738471995-02-17 13:50:17 +0000443 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
444 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000445 use_attr = TRUE;
446 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000447 case 3:
448 if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch))
449 return NULL;
450 use_xy = TRUE;
451 break;
452 case 4:
453 if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr))
454 return NULL;
455 use_xy = use_attr = TRUE;
456 break;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000457 default:
Guido van Rossum85738471995-02-17 13:50:17 +0000458 PyErr_SetString(PyExc_TypeError, "insch requires 1 to 4 arguments");
459 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000460 }
Guido van Rossum85738471995-02-17 13:50:17 +0000461
Guido van Rossumf6971e21994-08-30 12:25:20 +0000462 if (use_attr == TRUE) {
463 attr_old = getattrs(self->win);
464 wattrset(self->win,attr);
465 }
466 if (use_xy == TRUE)
467 rtn = mvwinsch(self->win,y,x,ch);
468 else
469 rtn = winsch(self->win,ch);
470 if (use_attr == TRUE)
471 wattrset(self->win,attr_old);
Guido van Rossum85738471995-02-17 13:50:17 +0000472
473 return PyCursesCheckERR(rtn, "[mv]winsch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000474}
475
476static PyObject *
477PyCursesWindow_DelCh(self,arg)
478 PyCursesWindowObject *self;
479 PyObject * arg;
480{
481 int rtn;
482 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000483
484 switch (ARG_COUNT(arg)) {
485 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000486 rtn = wdelch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000487 break;
488 case 2:
489 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
490 return NULL;
491 rtn = mvwdelch(self->win,y,x);
492 break;
493 default:
494 PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
495 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000496 }
Guido van Rossum85738471995-02-17 13:50:17 +0000497
498 return PyCursesCheckERR(rtn, "[mv]wdelch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000499}
500
501static PyObject *
502PyCursesWindow_EchoChar(self,arg)
503 PyCursesWindowObject *self;
504 PyObject * arg;
505{
506 int rtn;
507 int ch;
Guido van Rossum85738471995-02-17 13:50:17 +0000508 int attr, attr_old;
509
510 switch (ARG_COUNT(arg)) {
511 case 1:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000512 if (!PyArg_Parse(arg,"i;ch", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000513 return NULL;
514 rtn = wechochar(self->win,ch);
515 break;
516 case 2:
517 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
518 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000519 attr_old = getattrs(self->win);
520 wattrset(self->win,attr);
Guido van Rossum85738471995-02-17 13:50:17 +0000521 rtn = wechochar(self->win,ch);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000522 wattrset(self->win,attr_old);
Guido van Rossum85738471995-02-17 13:50:17 +0000523 break;
524 default:
525 PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
526 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000527 }
Guido van Rossum85738471995-02-17 13:50:17 +0000528
529 return PyCursesCheckERR(rtn, "wechochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000530}
531
532static PyObject *
533PyCursesWindow_AddStr(self,arg)
534 PyCursesWindowObject *self;
535 PyObject * arg;
536{
537 int rtn;
538 int x, y;
539 char *str;
Guido van Rossum85738471995-02-17 13:50:17 +0000540 int attr, attr_old;
541 int use_xy = FALSE, use_attr = FALSE;
542
543 switch (ARG_COUNT(arg)) {
544 case 1:
545 if (!PyArg_Parse(arg,"s;str", &str))
546 return NULL;
547 break;
548 case 2:
549 if (!PyArg_Parse(arg,"(si);str,attr", &str, &attr))
550 return NULL;
551 use_attr = TRUE;
552 break;
553 case 3:
554 if (!PyArg_Parse(arg,"(iis);y,x,str", &y, &x, &str))
555 return NULL;
556 use_xy = TRUE;
557 break;
558 case 4:
559 if (!PyArg_Parse(arg,"(iisi);y,x,str,attr", &y, &x, &str, &attr))
560 return NULL;
561 use_xy = use_attr = TRUE;
562 break;
563 default:
564 PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
565 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000566 }
Guido van Rossum85738471995-02-17 13:50:17 +0000567
Guido van Rossumf6971e21994-08-30 12:25:20 +0000568 if (use_attr == TRUE) {
569 attr_old = getattrs(self->win);
570 wattrset(self->win,attr);
571 }
572 if (use_xy == TRUE)
573 rtn = mvwaddstr(self->win,y,x,str);
574 else
575 rtn = waddstr(self->win,str);
576 if (use_attr == TRUE)
577 wattrset(self->win,attr_old);
Guido van Rossum85738471995-02-17 13:50:17 +0000578
579 return PyCursesCheckERR(rtn, "[mv]waddstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000580}
581
582static PyObject *
583PyCursesWindow_AttrOn(self,arg)
584 PyCursesWindowObject *self;
585 PyObject * arg;
586{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000587 int ch;
588 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000589 return NULL;
590 wattron(self->win,ch);
591 Py_INCREF(Py_None);
592 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000593}
594
595static PyObject *
596PyCursesWindow_AttrOff(self,arg)
597 PyCursesWindowObject *self;
598 PyObject * arg;
599{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000600 int ch;
601 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000602 return NULL;
603 wattroff(self->win,ch);
604 Py_INCREF(Py_None);
605 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000606}
607
608static PyObject *
609PyCursesWindow_AttrSet(self,arg)
610 PyCursesWindowObject *self;
611 PyObject * arg;
612{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000613 int ch;
614 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000615 return NULL;
616 wattrset(self->win,ch);
617 Py_INCREF(Py_None);
618 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000619}
620
621static PyObject *
622PyCursesWindow_StandEnd(self,arg)
623 PyCursesWindowObject *self;
624 PyObject * arg;
625{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000626 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000627 return NULL;
628 wstandend(self->win);
629 Py_INCREF(Py_None);
630 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000631}
632
633static PyObject *
634PyCursesWindow_StandOut(self,arg)
635 PyCursesWindowObject *self;
636 PyObject * arg;
637{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000638 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000639 return NULL;
640 wstandout(self->win);
641 Py_INCREF(Py_None);
642 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000643}
644
645static PyObject *
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000646PyCursesWindow_Border(self, args)
647 PyCursesWindowObject *self;
648 PyObject *args;
649{
650 int ls, rs, ts, bs, tl, tr, bl, br;
651 ls = rs = ts = bs = tl = tr = bl = br = 0;
652 if (!PyArg_ParseTuple(args,"|iiiiiiii;ls,rs,ts,bs,tl,tr,bl,br",
653 &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br))
654 return NULL;
655 wborder(self->win, ls, rs, ts, bs, tl, tr, bl, br);
656 Py_INCREF(Py_None);
657 return Py_None;
658}
659
660static PyObject *
Guido van Rossumf6971e21994-08-30 12:25:20 +0000661PyCursesWindow_Box(self,arg)
662 PyCursesWindowObject *self;
663 PyObject * arg;
664{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000665 int ch1=0,ch2=0;
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000666 if (!PyArg_NoArgs(arg)) {
Guido van Rossumf6971e21994-08-30 12:25:20 +0000667 PyErr_Clear();
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000668 if (!PyArg_Parse(arg,"(ii);vertch,horch", &ch1, &ch2))
669 return NULL;
670 }
Guido van Rossum85738471995-02-17 13:50:17 +0000671 box(self->win,ch1,ch2);
672 Py_INCREF(Py_None);
673 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000674}
675
676static PyObject *
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000677PyCursesWindow_Hline(self, args)
678 PyCursesWindowObject *self;
679 PyObject *args;
680{
681 int ch, n, x, y, code = OK;
682 switch (ARG_COUNT(args)) {
683 case 2:
684 if (!PyArg_Parse(args, "(ii);ch,n", &ch, &n))
685 return NULL;
686 break;
687 case 4:
688 if (!PyArg_Parse(args, "(iiii);y,x,ch,n", &y, &x, &ch, &n))
689 return NULL;
690 code = wmove(self->win, y, x);
691 break;
692 default:
693 PyErr_SetString(PyExc_TypeError, "hline requires 2 or 4 arguments");
694 return NULL;
695 }
696 if (code != ERR)
697 whline(self->win, ch, n);
698 return PyCursesCheckERR(code, "wmove");
699}
700
701static PyObject *
702PyCursesWindow_Vline(self, args)
703 PyCursesWindowObject *self;
704 PyObject *args;
705{
706 int ch, n, x, y, code = OK;
707 switch (ARG_COUNT(args)) {
708 case 2:
709 if (!PyArg_Parse(args, "(ii);ch,n", &ch, &n))
710 return NULL;
711 break;
712 case 4:
713 if (!PyArg_Parse(args, "(iiii);y,x,ch,n", &y, &x, &ch, &n))
714 return NULL;
715 code = wmove(self->win, y, x);
716 break;
717 default:
718 PyErr_SetString(PyExc_TypeError, "vline requires 2 or 4 arguments");
719 return NULL;
720 }
721 if (code != ERR)
722 wvline(self->win, ch, n);
723 return PyCursesCheckERR(code, "wmove");
724}
725
726static PyObject *
Guido van Rossumf6971e21994-08-30 12:25:20 +0000727PyCursesWindow_Erase(self,arg)
728 PyCursesWindowObject *self;
729 PyObject * arg;
730{
731 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000732 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000733 werase(self->win);
734 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000735 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000736}
737
738static PyObject *
739PyCursesWindow_DeleteLine(self,arg)
740 PyCursesWindowObject *self;
741 PyObject * arg;
742{
743 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000744 return NULL;
745 return PyCursesCheckERR(wdeleteln(self->win), "wdeleteln");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000746}
747
748static PyObject *
749PyCursesWindow_InsertLine(self,arg)
750 PyCursesWindowObject *self;
751 PyObject * arg;
752{
753 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000754 return NULL;
755 return PyCursesCheckERR(winsertln(self->win), "winsertln");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000756}
757
758static PyObject *
759PyCursesWindow_GetYX(self,arg)
760 PyCursesWindowObject *self;
761 PyObject * arg;
762{
763 int x, y;
764 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000765 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000766 getyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000767 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000768}
769
770static PyObject *
771PyCursesWindow_GetBegYX(self,arg)
772 PyCursesWindowObject *self;
773 PyObject * arg;
774{
775 int x, y;
776 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000777 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000778 getbegyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000779 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000780}
781
782static PyObject *
783PyCursesWindow_GetMaxYX(self,arg)
784 PyCursesWindowObject *self;
785 PyObject * arg;
786{
787 int x, y;
788 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000789 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000790 getmaxyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000791 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000792}
793
794static PyObject *
795PyCursesWindow_Clear(self,arg)
796 PyCursesWindowObject *self;
797 PyObject * arg;
798{
799 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000800 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000801 wclear(self->win);
802 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000803 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000804}
805
806static PyObject *
807PyCursesWindow_ClearToBottom(self,arg)
808 PyCursesWindowObject *self;
809 PyObject * arg;
810{
811 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000812 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000813 wclrtobot(self->win);
814 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000815 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000816}
817
818static PyObject *
819PyCursesWindow_ClearToEOL(self,arg)
820 PyCursesWindowObject *self;
821 PyObject * arg;
822{
823 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000824 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000825 wclrtoeol(self->win);
826 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000827 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000828}
829
830static PyObject *
831PyCursesWindow_Scroll(self,arg)
832 PyCursesWindowObject *self;
833 PyObject * arg;
834{
835 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000836 return NULL;
837 return PyCursesCheckERR(scroll(self->win), "scroll");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000838}
839
840static PyObject *
841PyCursesWindow_TouchWin(self,arg)
842 PyCursesWindowObject *self;
843 PyObject * arg;
844{
845 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000846 return NULL;
847 return PyCursesCheckERR(touchwin(self->win), "touchwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000848}
849
850static PyObject *
851PyCursesWindow_TouchLine(self,arg)
852 PyCursesWindowObject *self;
853 PyObject * arg;
854{
855 int st, cnt;
Guido van Rossum85738471995-02-17 13:50:17 +0000856 if (!PyArg_Parse(arg,"(ii);start,count",&st,&cnt))
857 return NULL;
858 return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000859}
860
861static PyObject *
862PyCursesWindow_GetCh(self,arg)
863 PyCursesWindowObject *self;
864 PyObject * arg;
865{
866 int x, y;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000867 int rtn;
Guido van Rossum85738471995-02-17 13:50:17 +0000868
869 switch (ARG_COUNT(arg)) {
870 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000871 rtn = wgetch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000872 break;
873 case 2:
874 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
875 return NULL;
876 rtn = mvwgetch(self->win,y,x);
877 break;
878 default:
879 PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
880 return NULL;
881 }
882
883 return PyInt_FromLong((long) rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000884}
885
886static PyObject *
887PyCursesWindow_GetStr(self,arg)
888 PyCursesWindowObject *self;
889 PyObject * arg;
890{
891 int x, y;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000892 char rtn[1024]; /* This should be big enough.. I hope */
893 int rtn2;
Guido van Rossum85738471995-02-17 13:50:17 +0000894
895 switch (ARG_COUNT(arg)) {
896 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000897 rtn2 = wgetstr(self->win,rtn);
Guido van Rossum85738471995-02-17 13:50:17 +0000898 break;
899 case 2:
900 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
901 return NULL;
902 rtn2 = mvwgetstr(self->win,y,x,rtn);
903 break;
904 default:
905 PyErr_SetString(PyExc_TypeError, "getstr requires 0 or 2 arguments");
906 return NULL;
907 }
908
Guido van Rossumf6971e21994-08-30 12:25:20 +0000909 if (rtn2 == ERR)
910 rtn[0] = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000911 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000912}
913
914static PyObject *
915PyCursesWindow_InCh(self,arg)
916 PyCursesWindowObject *self;
917 PyObject * arg;
918{
Guido van Rossum85738471995-02-17 13:50:17 +0000919 int x, y, rtn;
920
921 switch (ARG_COUNT(arg)) {
922 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000923 rtn = winch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000924 break;
925 case 2:
926 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
927 return NULL;
928 rtn = mvwinch(self->win,y,x);
929 break;
930 default:
931 PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
932 return NULL;
933 }
934
935 return PyInt_FromLong((long) rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000936}
937
938static PyObject *
939PyCursesWindow_ClearOk(self,arg)
940 PyCursesWindowObject *self;
941 PyObject * arg;
942{
943 int val;
944 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +0000945 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000946 clearok(self->win,val);
947 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000948 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000949}
950
951static PyObject *
952PyCursesWindow_IdlOk(self,arg)
953 PyCursesWindowObject *self;
954 PyObject * arg;
955{
956 int val;
957 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +0000958 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000959 idlok(self->win,val);
960 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000961 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000962}
963
964static PyObject *
965PyCursesWindow_LeaveOk(self,arg)
966 PyCursesWindowObject *self;
967 PyObject * arg;
968{
969 int val;
970 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +0000971 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000972 leaveok(self->win,val);
973 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000974 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000975}
976
977static PyObject *
978PyCursesWindow_ScrollOk(self,arg)
979 PyCursesWindowObject *self;
980 PyObject * arg;
981{
982 int val;
983 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +0000984 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000985 scrollok(self->win,val);
986 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000987 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000988}
989
990static PyObject *
991PyCursesWindow_SetScrollRegion(self,arg)
992 PyCursesWindowObject *self;
993 PyObject * arg;
994{
995 int x, y;
996 if (!PyArg_Parse(arg,"(ii);top, bottom",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000997 return NULL;
998 return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000999}
1000
1001static PyObject *
1002PyCursesWindow_KeyPad(self,arg)
1003 PyCursesWindowObject * self;
1004 PyObject * arg;
1005{
1006 int ch;
1007 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001008 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001009 keypad(self->win,ch);
1010 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001011 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001012}
1013
1014static PyObject *
1015PyCursesWindow_NoDelay(self,arg)
1016 PyCursesWindowObject * self;
1017 PyObject * arg;
1018{
1019 int ch;
1020 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001021 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001022 nodelay(self->win,ch);
1023 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001024 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001025}
1026
1027static PyObject *
1028PyCursesWindow_NoTimeout(self,arg)
1029 PyCursesWindowObject * self;
1030 PyObject * arg;
1031{
1032 int ch;
1033 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001034 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001035 notimeout(self->win,ch);
1036 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001037 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001038}
1039
1040static PyMethodDef PyCursesWindow_Methods[] = {
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001041 {"refresh", (PyCFunction)PyCursesWindow_Refresh},
1042 {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
1043 {"mvwin", (PyCFunction)PyCursesWindow_MoveWin},
1044 {"move", (PyCFunction)PyCursesWindow_Move},
1045 {"subwin", (PyCFunction)PyCursesWindow_SubWin},
1046 {"addch", (PyCFunction)PyCursesWindow_AddCh},
1047 {"insch", (PyCFunction)PyCursesWindow_InsCh},
1048 {"delch", (PyCFunction)PyCursesWindow_DelCh},
1049 {"echochar", (PyCFunction)PyCursesWindow_EchoChar},
1050 {"addstr", (PyCFunction)PyCursesWindow_AddStr},
1051 {"attron", (PyCFunction)PyCursesWindow_AttrOn},
1052 {"attroff", (PyCFunction)PyCursesWindow_AttrOff},
1053 {"attrset", (PyCFunction)PyCursesWindow_AttrSet},
1054 {"standend", (PyCFunction)PyCursesWindow_StandEnd},
1055 {"standout", (PyCFunction)PyCursesWindow_StandOut},
1056 {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
1057 {"box", (PyCFunction)PyCursesWindow_Box},
1058 {"hline", (PyCFunction)PyCursesWindow_Hline},
1059 {"vline", (PyCFunction)PyCursesWindow_Vline},
1060 {"erase", (PyCFunction)PyCursesWindow_Erase},
1061 {"deleteln", (PyCFunction)PyCursesWindow_DeleteLine},
1062 {"insertln", (PyCFunction)PyCursesWindow_InsertLine},
1063 {"getyx", (PyCFunction)PyCursesWindow_GetYX},
1064 {"getbegyx", (PyCFunction)PyCursesWindow_GetBegYX},
1065 {"getmaxyx", (PyCFunction)PyCursesWindow_GetMaxYX},
1066 {"clear", (PyCFunction)PyCursesWindow_Clear},
1067 {"clrtobot", (PyCFunction)PyCursesWindow_ClearToBottom},
1068 {"clrtoeol", (PyCFunction)PyCursesWindow_ClearToEOL},
1069 {"scroll", (PyCFunction)PyCursesWindow_Scroll},
1070 {"touchwin", (PyCFunction)PyCursesWindow_TouchWin},
1071 {"touchline", (PyCFunction)PyCursesWindow_TouchLine},
1072 {"getch", (PyCFunction)PyCursesWindow_GetCh},
1073 {"getstr", (PyCFunction)PyCursesWindow_GetStr},
1074 {"inch", (PyCFunction)PyCursesWindow_InCh},
1075 {"clearok", (PyCFunction)PyCursesWindow_ClearOk},
1076 {"idlok", (PyCFunction)PyCursesWindow_IdlOk},
1077 {"leaveok", (PyCFunction)PyCursesWindow_LeaveOk},
1078 {"scrollok", (PyCFunction)PyCursesWindow_ScrollOk},
1079 {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion},
1080 {"keypad", (PyCFunction)PyCursesWindow_KeyPad},
1081 {"nodelay", (PyCFunction)PyCursesWindow_NoDelay},
1082 {"notimeout", (PyCFunction)PyCursesWindow_NoTimeout},
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001083 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00001084};
1085
1086static PyObject *
1087PyCursesWindow_GetAttr(self, name)
1088 PyCursesWindowObject *self;
1089 char *name;
1090{
Guido van Rossuma597dde1995-01-10 20:56:29 +00001091 return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001092}
1093
Guido van Rossum85738471995-02-17 13:50:17 +00001094
Guido van Rossumf6971e21994-08-30 12:25:20 +00001095/* --------------- PAD routines ---------------- */
Guido van Rossum85738471995-02-17 13:50:17 +00001096
1097#ifdef NOT_YET
Guido van Rossumf6971e21994-08-30 12:25:20 +00001098static PyObject *
1099PyCursesPad_New(pad)
1100 WINDOW *pad;
1101{
1102 PyCursesPadObject *po;
Guido van Rossum85738471995-02-17 13:50:17 +00001103 po = PyObject_NEW(PyCursesPadObject, &PyCursesPad_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001104 if (po == NULL)
1105 return NULL;
1106 po->pad = pad;
1107 return (PyObject *)po;
1108}
Guido van Rossum85738471995-02-17 13:50:17 +00001109#endif
1110
Guido van Rossumf6971e21994-08-30 12:25:20 +00001111
1112/* -------------------------------------------------------*/
Guido van Rossum85738471995-02-17 13:50:17 +00001113
Guido van Rossumf6971e21994-08-30 12:25:20 +00001114static PyTypeObject PyCursesScreen_Type = {
1115 PyObject_HEAD_INIT(&PyType_Type)
1116 0, /*ob_size*/
1117 "curses screen", /*tp_name*/
1118 sizeof(PyCursesScreenObject), /*tp_basicsize*/
1119 0, /*tp_itemsize*/
1120 /* methods */
1121 (destructor)0 /*PyCursesScreen_Dealloc*/, /*tp_dealloc*/
1122 0, /*tp_print*/
1123 (getattrfunc)0, /*tp_getattr*/
1124 (setattrfunc)0, /*tp_setattr*/
1125 0, /*tp_compare*/
1126 0, /*tp_repr*/
1127 0, /*tp_as_number*/
1128 0, /*tp_as_sequence*/
1129 0, /*tp_as_mapping*/
1130 0, /*tp_hash*/
1131};
1132
1133static PyTypeObject PyCursesWindow_Type = {
1134 PyObject_HEAD_INIT(&PyType_Type)
1135 0, /*ob_size*/
1136 "curses window", /*tp_name*/
1137 sizeof(PyCursesWindowObject), /*tp_basicsize*/
1138 0, /*tp_itemsize*/
1139 /* methods */
1140 (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
1141 0, /*tp_print*/
1142 (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
1143 (setattrfunc)0, /*tp_setattr*/
1144 0, /*tp_compare*/
1145 0, /*tp_repr*/
1146 0, /*tp_as_number*/
1147 0, /*tp_as_sequence*/
1148 0, /*tp_as_mapping*/
1149 0, /*tp_hash*/
1150};
1151
1152static PyTypeObject PyCursesPad_Type = {
1153 PyObject_HEAD_INIT(&PyType_Type)
1154 0, /*ob_size*/
1155 "curses pad", /*tp_name*/
1156 sizeof(PyCursesPadObject), /*tp_basicsize*/
1157 0, /*tp_itemsize*/
1158 /* methods */
1159 (destructor)0 /*PyCursesPad_Dealloc*/, /*tp_dealloc*/
1160 0, /*tp_print*/
1161 (getattrfunc)0, /*tp_getattr*/
1162 (setattrfunc)0, /*tp_setattr*/
1163 0, /*tp_compare*/
1164 0, /*tp_repr*/
1165 0, /*tp_as_number*/
1166 0, /*tp_as_sequence*/
1167 0, /*tp_as_mapping*/
1168 0, /*tp_hash*/
1169};
1170
Guido van Rossum85738471995-02-17 13:50:17 +00001171
Guido van Rossumf6971e21994-08-30 12:25:20 +00001172/* -------------------------------------------------------*/
1173
Guido van Rossume4485b01994-09-07 14:32:49 +00001174static PyObject *ModDict;
1175
Guido van Rossumf6971e21994-08-30 12:25:20 +00001176static PyObject *
1177PyCurses_InitScr(self, args)
1178 PyObject * self;
1179 PyObject * args;
1180{
Guido van Rossum56bf2351994-08-31 22:06:24 +00001181 WINDOW *win;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001182 if (!PyArg_NoArgs(args))
Guido van Rossum85738471995-02-17 13:50:17 +00001183 return NULL;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001184 if (initialised == TRUE) {
Guido van Rossumf6971e21994-08-30 12:25:20 +00001185 wrefresh(stdscr);
1186 return (PyObject *)PyCursesWindow_New(stdscr);
1187 }
Guido van Rossum56bf2351994-08-31 22:06:24 +00001188
1189 win = initscr();
Guido van Rossum85738471995-02-17 13:50:17 +00001190 if (win == NULL) {
1191 PyErr_SetString(PyCursesError, catchall_NULL);
1192 return NULL;
1193 }
1194
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001195 initialised = TRUE;
Guido van Rossum56bf2351994-08-31 22:06:24 +00001196
1197/* This was moved from initcurses() because core dumped on SGI */
Guido van Rossum85738471995-02-17 13:50:17 +00001198/* Also, they are probably not defined until you've called initscr() */
1199#define SetDictInt(string,ch) \
1200 PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
Guido van Rossum56bf2351994-08-31 22:06:24 +00001201
1202 /* Here are some graphic symbols you can use */
Guido van Rossum85738471995-02-17 13:50:17 +00001203 SetDictInt("ACS_ULCORNER",(ACS_ULCORNER));
1204 SetDictInt("ACS_ULCORNER",(ACS_ULCORNER));
1205 SetDictInt("ACS_LLCORNER",(ACS_LLCORNER));
1206 SetDictInt("ACS_URCORNER",(ACS_URCORNER));
1207 SetDictInt("ACS_LRCORNER",(ACS_LRCORNER));
1208 SetDictInt("ACS_RTEE", (ACS_RTEE));
1209 SetDictInt("ACS_LTEE", (ACS_LTEE));
1210 SetDictInt("ACS_BTEE", (ACS_BTEE));
1211 SetDictInt("ACS_TTEE", (ACS_TTEE));
1212 SetDictInt("ACS_HLINE", (ACS_HLINE));
1213 SetDictInt("ACS_VLINE", (ACS_VLINE));
1214 SetDictInt("ACS_PLUS", (ACS_PLUS));
1215 SetDictInt("ACS_S1", (ACS_S1));
1216 SetDictInt("ACS_S9", (ACS_S9));
1217 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
1218 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
1219 SetDictInt("ACS_DEGREE", (ACS_DEGREE));
1220 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
1221 SetDictInt("ACS_BULLET", (ACS_BULLET));
1222 SetDictInt("ACS_LARROW", (ACS_RARROW));
1223 SetDictInt("ACS_DARROW", (ACS_DARROW));
1224 SetDictInt("ACS_UARROW", (ACS_UARROW));
1225 SetDictInt("ACS_BOARD", (ACS_BOARD));
1226 SetDictInt("ACS_LANTERN", (ACS_LANTERN));
1227 SetDictInt("ACS_BLOCK", (ACS_BLOCK));
Guido van Rossum56bf2351994-08-31 22:06:24 +00001228
1229 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001230}
1231
1232static PyObject *
1233PyCurses_EndWin(self, args)
1234 PyObject * self;
1235 PyObject * args;
1236{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001237 if (!PyArg_NoArgs(args) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001238 return NULL;
1239 return PyCursesCheckERR(endwin(), "endwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001240}
1241
1242static PyObject *
1243PyCurses_IsEndWin(self, args)
1244 PyObject * self;
1245 PyObject * args;
1246{
1247 if (!PyArg_NoArgs(args))
Guido van Rossum85738471995-02-17 13:50:17 +00001248 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001249 if (isendwin() == FALSE) {
1250 Py_INCREF(Py_False);
1251 return Py_False;
1252 }
1253 Py_INCREF(Py_True);
1254 return Py_True;
1255}
1256
1257static PyObject *
1258PyCurses_DoUpdate(self,arg)
1259 PyObject * self;
1260 PyObject * arg;
1261{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001262 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001263 return NULL;
1264 return PyCursesCheckERR(doupdate(), "doupdate");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001265}
1266
1267static PyObject *
1268PyCurses_NewWindow(self,arg)
1269 PyObject * self;
1270 PyObject * arg;
1271{
1272 WINDOW *win;
1273 int nlines, ncols, begin_y, begin_x;
Guido van Rossum85738471995-02-17 13:50:17 +00001274
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001275 if (!PyCursesInitialised())
1276 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +00001277 nlines = ncols = 0;
1278 switch (ARG_COUNT(arg)) {
1279 case 2:
1280 if (!PyArg_Parse(arg,"(ii);begin)_y,begin_x",&begin_y,&begin_x))
1281 return NULL;
1282 break;
1283 case 4:
1284 if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x",
Guido van Rossumf6971e21994-08-30 12:25:20 +00001285 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +00001286 return NULL;
1287 break;
1288 default:
1289 PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
1290 return NULL;
1291 }
1292
Guido van Rossumf6971e21994-08-30 12:25:20 +00001293 win = newwin(nlines,ncols,begin_y,begin_x);
1294 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +00001295 PyErr_SetString(PyCursesError, catchall_NULL);
1296 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001297 }
Guido van Rossum85738471995-02-17 13:50:17 +00001298
Guido van Rossumf6971e21994-08-30 12:25:20 +00001299 return (PyObject *)PyCursesWindow_New(win);
1300}
1301
1302static PyObject *
1303PyCurses_Beep(self,arg)
1304 PyObject * self;
1305 PyObject * arg;
1306{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001307 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001308 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001309 beep();
1310 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001311 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001312}
1313
1314static PyObject *
1315PyCurses_Flash(self,arg)
1316 PyObject * self;
1317 PyObject * arg;
1318{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001319 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001320 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001321 flash();
1322 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001323 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001324}
1325
1326static PyObject *
1327PyCurses_UngetCh(self,arg)
1328 PyObject * self;
1329 PyObject * arg;
1330{
1331 int ch;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001332 if (!PyArg_Parse(arg,"i;integer",&ch) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001333 return NULL;
1334 return PyCursesCheckERR(ungetch(ch), "ungetch");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001335}
1336
1337static PyObject *
1338PyCurses_FlushInp(self,arg)
1339 PyObject * self;
1340 PyObject * arg;
1341{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001342 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001343 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001344 flushinp();
1345 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001346 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001347}
1348
1349static PyObject *
1350PyCurses_CBreak(self,arg)
1351 PyObject * self;
1352 PyObject * arg;
1353{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001354 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001355 return NULL;
1356 return PyCursesCheckERR(cbreak(), "cbreak");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001357}
1358
1359static PyObject *
1360PyCurses_NoCBreak(self,arg)
1361 PyObject * self;
1362 PyObject * arg;
1363{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001364 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001365 return NULL;
1366 return PyCursesCheckERR(nocbreak(), "nocbreak");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001367}
1368
1369static PyObject *
1370PyCurses_Echo(self,arg)
1371 PyObject * self;
1372 PyObject * arg;
1373{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001374 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001375 return NULL;
1376 return PyCursesCheckERR(echo(), "echo");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001377}
1378
1379static PyObject *
1380PyCurses_NoEcho(self,arg)
1381 PyObject * self;
1382 PyObject * arg;
1383{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001384 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001385 return NULL;
1386 return PyCursesCheckERR(noecho(), "noecho");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001387}
1388
1389static PyObject *
1390PyCurses_Nl(self,arg)
1391 PyObject * self;
1392 PyObject * arg;
1393{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001394 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001395 return NULL;
1396 return PyCursesCheckERR(nl(), "nl");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001397}
1398
1399static PyObject *
1400PyCurses_NoNl(self,arg)
1401 PyObject * self;
1402 PyObject * arg;
1403{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001404 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001405 return NULL;
1406 return PyCursesCheckERR(nonl(), "nonl");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001407}
1408
1409static PyObject *
1410PyCurses_Raw(self,arg)
1411 PyObject * self;
1412 PyObject * arg;
1413{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001414 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001415 return NULL;
1416 return PyCursesCheckERR(raw(), "raw");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001417}
1418
1419static PyObject *
1420PyCurses_NoRaw(self,arg)
1421 PyObject * self;
1422 PyObject * arg;
1423{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001424 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001425 return NULL;
1426 return PyCursesCheckERR(noraw(), "noraw");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001427}
1428
1429static PyObject *
1430PyCurses_IntrFlush(self,arg)
1431 PyObject * self;
1432 PyObject * arg;
1433{
1434 int ch;
1435 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001436 return NULL;
1437 return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001438}
1439
1440static PyObject *
1441PyCurses_Meta(self,arg)
1442 PyObject * self;
1443 PyObject * arg;
1444{
1445 int ch;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001446 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001447 return NULL;
1448 return PyCursesCheckERR(meta(stdscr, ch), "meta");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001449}
1450
1451static PyObject *
1452PyCurses_KeyName(self,arg)
1453 PyObject * self;
1454 PyObject * arg;
1455{
Guido van Rossum85738471995-02-17 13:50:17 +00001456 char *knp;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001457 int ch;
1458 if (!PyArg_Parse(arg,"i",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001459 return NULL;
1460 knp = keyname(ch);
1461 return PyString_FromString((knp == NULL) ? "" : knp);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001462}
1463
1464#ifdef NOT_YET
1465static PyObject *
1466PyCurses_NewTerm(self, args)
1467 PyObject * self;
1468 PyObject * args;
1469{
1470}
1471
1472static PyObject *
1473PyCurses_SetTerm(self, args)
1474 PyObject * self;
1475 PyObject * args;
1476{
1477}
1478#endif
1479
1480/* List of functions defined in the module */
1481
1482static PyMethodDef PyCurses_methods[] = {
1483 {"initscr", (PyCFunction)PyCurses_InitScr},
1484 {"endwin", (PyCFunction)PyCurses_EndWin},
1485 {"isendwin", (PyCFunction)PyCurses_IsEndWin},
1486 {"doupdate", (PyCFunction)PyCurses_DoUpdate},
1487 {"newwin", (PyCFunction)PyCurses_NewWindow},
1488 {"beep", (PyCFunction)PyCurses_Beep},
1489 {"flash", (PyCFunction)PyCurses_Flash},
1490 {"ungetch", (PyCFunction)PyCurses_UngetCh},
1491 {"flushinp", (PyCFunction)PyCurses_FlushInp},
1492 {"cbreak", (PyCFunction)PyCurses_CBreak},
1493 {"nocbreak", (PyCFunction)PyCurses_NoCBreak},
1494 {"echo", (PyCFunction)PyCurses_Echo},
1495 {"noecho", (PyCFunction)PyCurses_NoEcho},
1496 {"nl", (PyCFunction)PyCurses_Nl},
1497 {"nonl", (PyCFunction)PyCurses_NoNl},
1498 {"raw", (PyCFunction)PyCurses_Raw},
1499 {"noraw", (PyCFunction)PyCurses_NoRaw},
1500 {"intrflush", (PyCFunction)PyCurses_IntrFlush},
1501 {"meta", (PyCFunction)PyCurses_Meta},
1502 {"keyname", (PyCFunction)PyCurses_KeyName},
1503#ifdef NOT_YET
1504 {"newterm", (PyCFunction)PyCurses_NewTerm},
1505 {"set_term", (PyCFunction)PyCurses_SetTerm},
1506#endif
1507 {NULL, NULL} /* sentinel */
1508};
1509
1510/* Initialization function for the module */
1511
1512void
Guido van Rossum56bf2351994-08-31 22:06:24 +00001513initcurses()
Guido van Rossumf6971e21994-08-30 12:25:20 +00001514{
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00001515 PyObject *m, *d, *v;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001516
1517 /* Create the module and add the functions */
Guido van Rossum56bf2351994-08-31 22:06:24 +00001518 m = Py_InitModule("curses", PyCurses_methods);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001519
Guido van Rossumf6971e21994-08-30 12:25:20 +00001520 /* Add some symbolic constants to the module */
1521 d = PyModule_GetDict(m);
Guido van Rossume4485b01994-09-07 14:32:49 +00001522 ModDict = d; /* For PyCurses_InitScr */
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001523
Guido van Rossum85738471995-02-17 13:50:17 +00001524 /* For exception curses.error */
1525 PyCursesError = PyString_FromString("curses.error");
1526 PyDict_SetItemString(d, "error", PyCursesError);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001527
Guido van Rossum85738471995-02-17 13:50:17 +00001528 /* Make the version available */
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00001529 v = PyString_FromString(PyCursesVersion);
1530 PyDict_SetItemString(d, "version", v);
1531 PyDict_SetItemString(d, "__version__", v);
1532 Py_DECREF(v);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001533
Guido van Rossumf6971e21994-08-30 12:25:20 +00001534 /* Here are some attributes you can add to chars to print */
Guido van Rossum85738471995-02-17 13:50:17 +00001535 SetDictInt("A_NORMAL", A_NORMAL);
1536 SetDictInt("A_STANDOUT", A_STANDOUT);
1537 SetDictInt("A_UNDERLINE", A_UNDERLINE);
1538 SetDictInt("A_REVERSE", A_REVERSE);
1539 SetDictInt("A_BLINK", A_BLINK);
1540 SetDictInt("A_DIM", A_DIM);
1541 SetDictInt("A_BOLD", A_BOLD);
1542 SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001543
1544 /* Now set everything up for KEY_ variables */
1545 {
1546 int key;
1547 char *key_n;
1548 char *key_n2;
1549 for (key=KEY_MIN;key < KEY_MAX; key++) {
1550 key_n = (char *)keyname(key);
Guido van Rossumf5c6d471995-02-07 15:38:32 +00001551 if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001552 continue;
1553 if (strncmp(key_n,"KEY_F(",6)==0) {
1554 char *p1, *p2;
1555 key_n2 = malloc(strlen(key_n)+1);
1556 p1 = key_n;
1557 p2 = key_n2;
1558 while (*p1) {
1559 if (*p1 != '(' && *p1 != ')') {
1560 *p2 = *p1;
1561 p2++;
1562 }
1563 p1++;
1564 }
1565 *p2 = (char)0;
1566 } else
1567 key_n2 = key_n;
Guido van Rossum85738471995-02-17 13:50:17 +00001568 PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
Guido van Rossumf6971e21994-08-30 12:25:20 +00001569 if (key_n2 != key_n)
1570 free(key_n2);
1571 }
Guido van Rossum85738471995-02-17 13:50:17 +00001572 SetDictInt("KEY_MIN", KEY_MIN);
1573 SetDictInt("KEY_MAX", KEY_MAX);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001574 }
1575
1576 /* Check for errors */
1577 if (PyErr_Occurred())
Guido van Rossum85738471995-02-17 13:50:17 +00001578 Py_FatalError("can't initialize module curses");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001579}