blob: 935f6c8a8e678338fb807acbea951bc7e02681c2 [file] [log] [blame]
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001/*
2 * This is a curses implementation for Python.
3 *
4 * Based on a prior work by Lance Ellinghaus
5 * (version 1.2 of this module
6 * Copyright 1994 by Lance Ellinghouse,
7 * Cathedral City, California Republic, United States of America.)
8 * Updated, fixed and heavily extended by Oliver Andrich
9 *
10 * Copyright 1996,1997 by Oliver Andrich,
11 * Koblenz, Germany
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this source file to use, copy, modify, merge, or publish it
15 * subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or in any new file that contains a substantial portion of
19 * this file.
20 *
21 * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF
22 * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
23 * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES
24 * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
25 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE
27 * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL,
28 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
29 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR
30 * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
31 * PERFORMANCE OF THIS SOFTWARE.
32 */
Guido van Rossumf6971e21994-08-30 12:25:20 +000033
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000034/* CVS: $Id$ */
Guido van Rossumf6971e21994-08-30 12:25:20 +000035
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000036/* Release Number */
Guido van Rossumf6971e21994-08-30 12:25:20 +000037
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000038char *PyCursesVersion = "1.5b1";
Guido van Rossumf6971e21994-08-30 12:25:20 +000039
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000040/* Includes */
Guido van Rossumf6971e21994-08-30 12:25:20 +000041
Guido van Rossum602099a1994-09-14 13:32:22 +000042#include "Python.h"
Guido van Rossumf6971e21994-08-30 12:25:20 +000043#include <curses.h>
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000044
45#ifdef __sgi__
46 /* No attr_t type is available */
47typedef chtype attr_t;
Guido van Rossum1266a011996-02-25 04:50:31 +000048#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +000049
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000050/* Definition of exception curses.error */
Guido van Rossumf6971e21994-08-30 12:25:20 +000051
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000052static PyObject *PyCursesError;
Guido van Rossumf6971e21994-08-30 12:25:20 +000053
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000054/* general error messages */
Guido van Rossum85738471995-02-17 13:50:17 +000055static char *catchall_ERR = "curses function returned ERR";
56static char *catchall_NULL = "curses function returned NULL";
57
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000058/* Tells whether initscr() has been called to initialise curses. */
Guido van Rossum585c6dc1995-02-24 13:45:43 +000059static int initialised = FALSE;
60
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000061/* Tells whether start_color() has been called to initialise colorusage. */
62static int initialisedcolors = FALSE;
63
64/* Utility Macros */
Guido van Rossum85738471995-02-17 13:50:17 +000065#define ARG_COUNT(X) \
66 (((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
Guido van Rossumf6971e21994-08-30 12:25:20 +000067
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000068#define PyCursesInitialised \
69 if (initialised != TRUE) { \
70 PyErr_SetString(PyCursesError, \
71 "must call initscr() first"); \
72 return NULL; }
Guido van Rossumfbea2f31994-08-31 22:05:27 +000073
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000074#define PyCursesInitialisedColor \
75 if (initialisedcolors != TRUE) { \
76 PyErr_SetString(PyCursesError, \
77 "must call start_color() first"); \
78 return NULL; }
Guido van Rossumfbea2f31994-08-31 22:05:27 +000079
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000080/* Utility Functions */
Guido van Rossumfbea2f31994-08-31 22:05:27 +000081
Guido van Rossum85738471995-02-17 13:50:17 +000082/*
83 * Check the return code from a curses function and return None
84 * or raise an exception as appropriate.
85 */
86
87static PyObject *
88PyCursesCheckERR(code, fname)
89 int code;
90 char *fname;
91{
92 char buf[100];
93
94 if (code != ERR) {
95 Py_INCREF(Py_None);
96 return Py_None;
97 } else {
98 if (fname == NULL) {
99 PyErr_SetString(PyCursesError, catchall_ERR);
100 } else {
101 strcpy(buf, fname);
102 strcat(buf, "() returned ERR");
103 PyErr_SetString(PyCursesError, buf);
104 }
105 return NULL;
106 }
107}
108
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000109int
110PyCurses_ConvertToChtype(obj, ch)
111 PyObject *obj;
112 chtype *ch;
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000113{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000114 if (PyInt_Check(obj)) {
115 *ch = (chtype) PyInt_AsLong(obj);
116 } else if(PyString_Check(obj) &
117 (PyString_Size(obj) == 1)) {
118 *ch = (chtype) *PyString_AsString(obj);
119 } else {
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000120 return 0;
121 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000122 return 1;
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000123}
124
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000125/*****************************************************************************
126 The Window Object
127******************************************************************************/
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000128
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000129/* Definition of the window object and window type */
Guido van Rossum85738471995-02-17 13:50:17 +0000130
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000131typedef struct {
132 PyObject_HEAD
133 WINDOW *win;
134} PyCursesWindowObject;
Guido van Rossum85738471995-02-17 13:50:17 +0000135
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000136PyTypeObject PyCursesWindow_Type;
137
138#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
139
140/* Function Prototype Macros - They are ugly but very, very useful. ;-)
141
142 X - function name
143 TYPE - parameter Type
144 ERGSTR - format string for construction of the return value
145 PARSESTR - format string for argument parsing
146 */
147
148#define Window_NoArgNoReturnFunction(X) \
149static PyObject *PyCursesWindow_ ## X (self, arg) \
150 PyCursesWindowObject * self; PyObject * arg; \
151{ if (!PyArg_NoArgs(arg)) return NULL; \
152 return PyCursesCheckERR(X(self->win), # X); }
153
154#define Window_NoArgTrueFalseFunction(X) \
155static PyObject * PyCursesWindow_ ## X (self,arg) \
156 PyCursesWindowObject * self; PyObject * arg; \
157{ \
158 if (!PyArg_NoArgs(arg)) return NULL; \
159 if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
160 else { Py_INCREF(Py_True); return Py_True; } }
161
162#define Window_NoArgNoReturnVoidFunction(X) \
163static PyObject * PyCursesWindow_ ## X (self,arg) \
164 PyCursesWindowObject * self; \
165 PyObject * arg; \
166{ \
167 if (!PyArg_NoArgs(arg)) return NULL; \
168 X(self->win); Py_INCREF(Py_None); return Py_None; }
169
170#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
171static PyObject * PyCursesWindow_ ## X (self, arg) \
172 PyCursesWindowObject *self; \
173 PyObject * arg; \
174{ \
175 TYPE arg1, arg2; \
176 if (!PyArg_NoArgs(arg)) return NULL; \
177 X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
178
179#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
180static PyObject * PyCursesWindow_ ## X (self, arg) \
181 PyCursesWindowObject *self; \
182 PyObject * arg; \
183{ \
184 TYPE arg1; \
185 if (!PyArg_Parse(arg, PARSESTR, &arg1)) return NULL; \
186 X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
187
188#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
189static PyObject * PyCursesWindow_ ## X (self, arg) \
190 PyCursesWindowObject *self; \
191 PyObject * arg; \
192{ \
193 TYPE arg1; \
194 if (!PyArg_Parse(arg,PARSESTR, &arg1)) return NULL; \
195 return PyCursesCheckERR(X(self->win, arg1), # X); }
196
197#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
198static PyObject * PyCursesWindow_ ## X (self, arg) \
199 PyCursesWindowObject *self; \
200 PyObject * arg; \
201{ \
202 TYPE arg1, arg2; \
203 if (!PyArg_Parse(arg,PARSESTR, &arg1, &arg2)) return NULL; \
204 return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
Guido van Rossum85738471995-02-17 13:50:17 +0000205
Guido van Rossumf6971e21994-08-30 12:25:20 +0000206/* ------------- WINDOW routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000207
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000208Window_NoArgNoReturnFunction(untouchwin)
209Window_NoArgNoReturnFunction(touchwin)
210Window_NoArgNoReturnFunction(redrawwin)
211Window_NoArgNoReturnFunction(winsertln)
212Window_NoArgNoReturnFunction(werase)
213Window_NoArgNoReturnFunction(wdeleteln)
214
215Window_NoArgTrueFalseFunction(is_wintouched)
216
217Window_NoArgNoReturnVoidFunction(wsyncup)
218Window_NoArgNoReturnVoidFunction(wsyncdown)
219Window_NoArgNoReturnVoidFunction(wstandend)
220Window_NoArgNoReturnVoidFunction(wstandout)
221Window_NoArgNoReturnVoidFunction(wcursyncup)
222Window_NoArgNoReturnVoidFunction(wclrtoeol)
223Window_NoArgNoReturnVoidFunction(wclrtobot)
224Window_NoArgNoReturnVoidFunction(wclear)
225
226Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")
227Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
228
229Window_NoArg2TupleReturnFunction(getyx, int, "(ii)")
230Window_NoArg2TupleReturnFunction(getbegyx, int, "(ii)")
231Window_NoArg2TupleReturnFunction(getmaxyx, int, "(ii)")
232Window_NoArg2TupleReturnFunction(getparyx, int, "(ii)")
233
234Window_OneArgNoReturnFunction(wattron, attr_t, "l;attr")
235Window_OneArgNoReturnFunction(wattroff, attr_t, "l;attr")
236Window_OneArgNoReturnFunction(wattrset, attr_t, "l;attr")
237Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
238Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
239Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")
240Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")
241Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
242Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")
243Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")
244Window_OneArgNoReturnFunction(winsdelln, int, "i;cnt")
245Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
246
247Window_TwoArgNoReturnFunction(mvwin, int, "(ii);y,x")
248Window_TwoArgNoReturnFunction(mvderwin, int, "(ii);y,x")
249Window_TwoArgNoReturnFunction(wmove, int, "(ii);y,x")
250#ifndef __sgi__
251Window_TwoArgNoReturnFunction(wresize, int, "(ii);lines,columns")
252#endif
253
254/* Allocation and Deallocation of Window Objects */
255
Guido van Rossumf6971e21994-08-30 12:25:20 +0000256static PyObject *
257PyCursesWindow_New(win)
258 WINDOW *win;
259{
260 PyCursesWindowObject *wo;
Guido van Rossum85738471995-02-17 13:50:17 +0000261
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000262 wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
263 if (wo == NULL) return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000264 wo->win = win;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000265 return (PyObject *)wo;
266}
267
268static void
269PyCursesWindow_Dealloc(wo)
270 PyCursesWindowObject *wo;
271{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000272 if (wo->win != stdscr) delwin(wo->win);
273 PyMem_DEL(wo);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000274}
275
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000276/* Addch, Addstr, Addnstr */
Guido van Rossumf6971e21994-08-30 12:25:20 +0000277
278static PyObject *
279PyCursesWindow_AddCh(self,arg)
280 PyCursesWindowObject *self;
281 PyObject * arg;
282{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000283 int rtn, x, y, use_xy = FALSE;
284 PyObject *temp;
285 chtype ch = 0;
286 attr_t attr = A_NORMAL;
287
Guido van Rossum85738471995-02-17 13:50:17 +0000288 switch (ARG_COUNT(arg)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000289 case 1:
290 if (!PyArg_Parse(arg, "O;ch or int", &temp))
291 return NULL;
292 break;
293 case 2:
294 if (!PyArg_Parse(arg, "(Ol);ch or int,attr", &temp, &attr))
Guido van Rossum85738471995-02-17 13:50:17 +0000295 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000296 break;
297 case 3:
298 if (!PyArg_Parse(arg,"(iiO);y,x,ch or int", &y, &x, &temp))
299 return NULL;
300 use_xy = TRUE;
301 break;
302 case 4:
303 if (!PyArg_Parse(arg,"(iiOl);y,x,ch or int, attr",
304 &y, &x, &temp, &attr))
305 return NULL;
306 use_xy = TRUE;
307 break;
308 default:
309 PyErr_SetString(PyExc_TypeError, "addch requires 1 or 4 arguments");
310 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000311 }
Guido van Rossum85738471995-02-17 13:50:17 +0000312
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000313 if (!PyCurses_ConvertToChtype(temp, &ch)) {
314 PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
315 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000316 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000317
Guido van Rossumf6971e21994-08-30 12:25:20 +0000318 if (use_xy == TRUE)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000319 rtn = mvwaddch(self->win,y,x, ch | attr);
320 else {
321 rtn = waddch(self->win, ch | attr);
322 }
323 return PyCursesCheckERR(rtn, "addch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000324}
325
326static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000327PyCursesWindow_AddStr(self,arg)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000328 PyCursesWindowObject *self;
329 PyObject * arg;
330{
331 int rtn;
332 int x, y;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000333 char *str;
334 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
335 int use_xy = FALSE, use_attr = FALSE;
Guido van Rossum85738471995-02-17 13:50:17 +0000336
337 switch (ARG_COUNT(arg)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000338 case 1:
339 if (!PyArg_Parse(arg,"s;str", &str))
Guido van Rossum85738471995-02-17 13:50:17 +0000340 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000341 break;
342 case 2:
343 if (!PyArg_Parse(arg,"(sl);str,attr", &str, &attr))
344 return NULL;
345 use_attr = TRUE;
346 break;
347 case 3:
348 if (!PyArg_Parse(arg,"(iis);int,int,str", &y, &x, &str))
349 return NULL;
350 use_xy = TRUE;
351 break;
352 case 4:
353 if (!PyArg_Parse(arg,"(iisl);int,int,str,attr", &y, &x, &str, &attr))
354 return NULL;
355 use_xy = use_attr = TRUE;
356 break;
357 default:
358 PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
359 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000360 }
Guido van Rossum85738471995-02-17 13:50:17 +0000361
Guido van Rossumf6971e21994-08-30 12:25:20 +0000362 if (use_attr == TRUE) {
363 attr_old = getattrs(self->win);
364 wattrset(self->win,attr);
365 }
366 if (use_xy == TRUE)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000367 rtn = mvwaddstr(self->win,y,x,str);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000368 else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000369 rtn = waddstr(self->win,str);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000370 if (use_attr == TRUE)
371 wattrset(self->win,attr_old);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000372 return PyCursesCheckERR(rtn, "addstr");
373}
Guido van Rossum85738471995-02-17 13:50:17 +0000374
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000375static PyObject *
376PyCursesWindow_AddNStr(self,arg)
377 PyCursesWindowObject *self;
378 PyObject * arg;
379{
380 int rtn, x, y, n;
381 char *str;
382 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
383 int use_xy = FALSE, use_attr = FALSE;
384
385 switch (ARG_COUNT(arg)) {
386 case 2:
387 if (!PyArg_Parse(arg,"(si);str,n", &str, &n))
388 return NULL;
389 break;
390 case 3:
391 if (!PyArg_Parse(arg,"(sil);str,n,attr", &str, &n, &attr))
392 return NULL;
393 use_attr = TRUE;
394 break;
395 case 4:
396 if (!PyArg_Parse(arg,"(iisi);y,x,str,n", &y, &x, &str, &n))
397 return NULL;
398 use_xy = TRUE;
399 break;
400 case 5:
401 if (!PyArg_Parse(arg,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr))
402 return NULL;
403 use_xy = use_attr = TRUE;
404 break;
405 default:
406 PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
407 return NULL;
408 }
409
410 if (use_attr == TRUE) {
411 attr_old = getattrs(self->win);
412 wattrset(self->win,attr);
413 }
414 if (use_xy == TRUE)
415 rtn = mvwaddnstr(self->win,y,x,str,n);
416 else
417 rtn = waddnstr(self->win,str,n);
418 if (use_attr == TRUE)
419 wattrset(self->win,attr_old);
420 return PyCursesCheckERR(rtn, "addnstr");
421}
422
423static PyObject *
424PyCursesWindow_Bkgd(self,arg)
425 PyCursesWindowObject *self;
426 PyObject * arg;
427{
428 PyObject *temp;
429 chtype bkgd;
430 attr_t attr = A_NORMAL;
431
432 switch (ARG_COUNT(arg)) {
433 case 1:
434 if (!PyArg_Parse(arg, "O;ch or int", &temp))
435 return NULL;
436 break;
437 case 2:
438 if (!PyArg_Parse(arg,"(Ol);ch or int,attr", &temp, &attr))
439 return NULL;
440 break;
441 default:
442 PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
443 return NULL;
444 }
445
446 if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
447 PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
448 return NULL;
449 }
450
451 return PyCursesCheckERR(wbkgd(self->win, bkgd | A_NORMAL), "bkgd");
452}
453
454static PyObject *
455PyCursesWindow_BkgdSet(self,arg)
456 PyCursesWindowObject *self;
457 PyObject * arg;
458{
459 PyObject *temp;
460 chtype bkgd;
461 attr_t attr = A_NORMAL;
462
463 switch (ARG_COUNT(arg)) {
464 case 1:
465 if (!PyArg_Parse(arg, "O;ch or int", &temp))
466 return NULL;
467 break;
468 case 2:
469 if (!PyArg_Parse(arg,"(Ol);ch or int,attr", &temp, &attr))
470 return NULL;
471 break;
472 default:
473 PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
474 return NULL;
475 }
476
477 if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
478 PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
479 return NULL;
480 }
481
482 wbkgdset(self->win, bkgd | attr);
483 return PyCursesCheckERR(0, "bkgdset");
484}
485
486static PyObject *
487PyCursesWindow_Border(self, args)
488 PyCursesWindowObject *self;
489 PyObject *args;
490{
491 chtype ls, rs, ts, bs, tl, tr, bl, br;
492 ls = rs = ts = bs = tl = tr = bl = br = 0;
493 if (!PyArg_Parse(args,"|llllllll;ls,rs,ts,bs,tl,tr,bl,br",
494 &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br))
495 return NULL;
496 wborder(self->win, ls, rs, ts, bs, tl, tr, bl, br);
497 Py_INCREF(Py_None);
498 return Py_None;
499}
500
501static PyObject *
502PyCursesWindow_Box(self,arg)
503 PyCursesWindowObject *self;
504 PyObject * arg;
505{
506 chtype ch1=0,ch2=0;
507 if (!PyArg_NoArgs(arg)) {
508 PyErr_Clear();
509 if (!PyArg_Parse(arg,"(ll);vertint,horint", &ch1, &ch2))
510 return NULL;
511 }
512 box(self->win,ch1,ch2);
513 Py_INCREF(Py_None);
514 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000515}
516
517static PyObject *
518PyCursesWindow_DelCh(self,arg)
519 PyCursesWindowObject *self;
520 PyObject * arg;
521{
522 int rtn;
523 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000524
525 switch (ARG_COUNT(arg)) {
526 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000527 rtn = wdelch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000528 break;
529 case 2:
530 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
531 return NULL;
532 rtn = mvwdelch(self->win,y,x);
533 break;
534 default:
535 PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
536 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000537 }
Guido van Rossum85738471995-02-17 13:50:17 +0000538 return PyCursesCheckERR(rtn, "[mv]wdelch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000539}
540
541static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000542PyCursesWindow_DerWin(self,arg)
543 PyCursesWindowObject *self;
544 PyObject * arg;
545{
546 WINDOW *win;
547 int nlines, ncols, begin_y, begin_x;
548
549 nlines = 0;
550 ncols = 0;
551 switch (ARG_COUNT(arg)) {
552 case 2:
553 if (!PyArg_Parse(arg,"(ii);begin_y,begin_x",&begin_y,&begin_x))
554 return NULL;
555 break;
556 case 4:
557 if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x",
558 &nlines,&ncols,&begin_y,&begin_x))
559 return NULL;
560 break;
561 default:
562 PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
563 return NULL;
564 }
565
566 win = derwin(self->win,nlines,ncols,begin_y,begin_x);
567
568 if (win == NULL) {
569 PyErr_SetString(PyCursesError, catchall_NULL);
570 return NULL;
571 }
572
573 return (PyObject *)PyCursesWindow_New(win);
574}
575
576static PyObject *
Guido van Rossumf6971e21994-08-30 12:25:20 +0000577PyCursesWindow_EchoChar(self,arg)
578 PyCursesWindowObject *self;
579 PyObject * arg;
580{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000581 PyObject *temp;
582 chtype ch;
583 attr_t attr = A_NORMAL;
Guido van Rossum85738471995-02-17 13:50:17 +0000584
585 switch (ARG_COUNT(arg)) {
586 case 1:
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000587 if (!PyArg_Parse(arg,"O;ch or int", &temp))
Guido van Rossum85738471995-02-17 13:50:17 +0000588 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +0000589 break;
590 case 2:
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000591 if (!PyArg_Parse(arg,"(Ol);ch or int,attr", &temp, &attr))
Guido van Rossum85738471995-02-17 13:50:17 +0000592 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +0000593 break;
594 default:
595 PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000596
597
Guido van Rossum85738471995-02-17 13:50:17 +0000598 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000599 }
Guido van Rossum85738471995-02-17 13:50:17 +0000600
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000601 if (!PyCurses_ConvertToChtype(temp, &ch)) {
602 PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
Guido van Rossum85738471995-02-17 13:50:17 +0000603 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000604 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000605
606 if (self->win->_flags & _ISPAD)
607 return PyCursesCheckERR(pechochar(self->win, ch | attr),
608 "echochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000609 else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000610 return PyCursesCheckERR(wechochar(self->win, ch | attr),
611 "echochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000612}
613
614static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000615PyCursesWindow_GetBkgd(self, arg)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000616 PyCursesWindowObject *self;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000617 PyObject *arg;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000618{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000619 if (!PyArg_NoArgs(arg))
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000620 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000621 return PyInt_FromLong((long) getbkgd(self->win));
Guido van Rossumf6971e21994-08-30 12:25:20 +0000622}
623
624static PyObject *
625PyCursesWindow_GetCh(self,arg)
626 PyCursesWindowObject *self;
627 PyObject * arg;
628{
629 int x, y;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000630 chtype rtn;
Guido van Rossum85738471995-02-17 13:50:17 +0000631
632 switch (ARG_COUNT(arg)) {
633 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000634 rtn = wgetch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000635 break;
636 case 2:
637 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
638 return NULL;
639 rtn = mvwgetch(self->win,y,x);
640 break;
641 default:
642 PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
643 return NULL;
644 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000645 return PyInt_FromLong(rtn);
646}
Guido van Rossum85738471995-02-17 13:50:17 +0000647
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000648static PyObject *
649PyCursesWindow_GetKey(self,arg)
650 PyCursesWindowObject *self;
651 PyObject * arg;
652{
653 int x, y;
654 chtype rtn;
655
656 switch (ARG_COUNT(arg)) {
657 case 0:
658 rtn = wgetch(self->win);
659 break;
660 case 2:
661 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
662 return NULL;
663 rtn = mvwgetch(self->win,y,x);
664 break;
665 default:
666 PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
667 return NULL;
668 }
669 if (rtn<=255)
670 return Py_BuildValue("c", rtn);
671 else
672 return PyString_FromString((char *)keyname(rtn));
Guido van Rossumf6971e21994-08-30 12:25:20 +0000673}
674
675static PyObject *
676PyCursesWindow_GetStr(self,arg)
677 PyCursesWindowObject *self;
678 PyObject * arg;
679{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000680 int x, y, n;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000681 char rtn[1024]; /* This should be big enough.. I hope */
682 int rtn2;
Guido van Rossum85738471995-02-17 13:50:17 +0000683
684 switch (ARG_COUNT(arg)) {
685 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000686 rtn2 = wgetstr(self->win,rtn);
Guido van Rossum85738471995-02-17 13:50:17 +0000687 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000688 case 1:
689 if (!PyArg_Parse(arg,"i;n", &n))
690 return NULL;
691 rtn2 = wgetnstr(self->win,rtn,n);
692 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000693 case 2:
694 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
695 return NULL;
696 rtn2 = mvwgetstr(self->win,y,x,rtn);
697 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000698 case 3:
699 if (!PyArg_Parse(arg,"(iii);y,x,n", &y, &x, &n))
700 return NULL;
701#ifdef __sgi__
702 /* Untested */
703 rtn2 = wmove(self->win,y,x)==ERR ? ERR :
704 wgetnstr(self->win, rtn, n);
705#else
706 rtn2 = mvwgetnstr(self->win, y, x, rtn, n);
707#endif
708 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000709 default:
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000710 PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 2 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000711 return NULL;
712 }
Guido van Rossumf6971e21994-08-30 12:25:20 +0000713 if (rtn2 == ERR)
714 rtn[0] = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000715 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000716}
717
718static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000719PyCursesWindow_Hline(self, args)
720 PyCursesWindowObject *self;
721 PyObject *args;
722{
723 PyObject *temp;
724 chtype ch;
725 int n, x, y, code = OK;
726 attr_t attr = A_NORMAL;
727
728 switch (ARG_COUNT(args)) {
729 case 2:
730 if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n))
731 return NULL;
732 break;
733 case 3:
734 if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr))
735 return NULL;
736 break;
737 case 4:
738 if (!PyArg_Parse(args, "(iiOi);y,x,ch o int,n", &y, &x, &temp, &n))
739 return NULL;
740 code = wmove(self->win, y, x);
741 break;
742 case 5:
743 if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr",
744 &y, &x, &temp, &n, &attr))
745 return NULL;
746 code = wmove(self->win, y, x);
747 default:
748 PyErr_SetString(PyExc_TypeError, "hline requires 2 or 5 arguments");
749 return NULL;
750 }
751
752 if (code != ERR) {
753 if (!PyCurses_ConvertToChtype(temp, &ch)) {
754 PyErr_SetString(PyExc_TypeError,
755 "argument 1 or 3 must be a ch or an int");
756 return NULL;
757 }
758 return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
759 } else
760 return PyCursesCheckERR(code, "wmove");
761}
762
763static PyObject *
764PyCursesWindow_InsCh(self,arg)
765 PyCursesWindowObject *self;
766 PyObject * arg;
767{
768 int rtn, x, y, use_xy = FALSE;
769 PyObject *temp;
770 chtype ch = 0;
771 attr_t attr = A_NORMAL;
772
773 switch (ARG_COUNT(arg)) {
774 case 1:
775 if (!PyArg_Parse(arg, "O;ch or int", &temp))
776 return NULL;
777 break;
778 case 2:
779 if (!PyArg_Parse(arg, "(Ol);ch or int,attr", &temp, &attr))
780 return NULL;
781 break;
782 case 3:
783 if (!PyArg_Parse(arg,"(iiO);y,x,ch or int", &y, &x, &temp))
784 return NULL;
785 use_xy = TRUE;
786 break;
787 case 4:
788 if (!PyArg_Parse(arg,"(iiOl);y,x,ch or int, attr", &y, &x, &temp, &attr))
789 return NULL;
790 use_xy = TRUE;
791 break;
792 default:
793 PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
794 return NULL;
795 }
796
797 if (!PyCurses_ConvertToChtype(temp, &ch)) {
798 PyErr_SetString(PyExc_TypeError,
799 "argument 1 or 3 must be a ch or an int");
800 return NULL;
801 }
802
803 if (use_xy == TRUE)
804 rtn = mvwinsch(self->win,y,x, ch | attr);
805 else {
806 rtn = winsch(self->win, ch | attr);
807 }
808 return PyCursesCheckERR(rtn, "insch");
809}
810
811static PyObject *
Guido van Rossumf6971e21994-08-30 12:25:20 +0000812PyCursesWindow_InCh(self,arg)
813 PyCursesWindowObject *self;
814 PyObject * arg;
815{
Guido van Rossum85738471995-02-17 13:50:17 +0000816 int x, y, rtn;
817
818 switch (ARG_COUNT(arg)) {
819 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000820 rtn = winch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000821 break;
822 case 2:
823 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
824 return NULL;
825 rtn = mvwinch(self->win,y,x);
826 break;
827 default:
828 PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
829 return NULL;
830 }
Guido van Rossum85738471995-02-17 13:50:17 +0000831 return PyInt_FromLong((long) rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000832}
833
834static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000835PyCursesWindow_InStr(self,arg)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000836 PyCursesWindowObject *self;
837 PyObject * arg;
838{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000839 int x, y, n;
840 char rtn[1024]; /* This should be big enough.. I hope */
841 int rtn2;
842
843 switch (ARG_COUNT(arg)) {
844 case 0:
845 rtn2 = winstr(self->win,rtn);
846 break;
847 case 1:
848 if (!PyArg_Parse(arg,"i;n", &n))
849 return NULL;
850 rtn2 = winnstr(self->win,rtn,n);
851 break;
852 case 2:
853 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
854 return NULL;
855 rtn2 = mvwinstr(self->win,y,x,rtn);
856 break;
857 case 3:
858 if (!PyArg_Parse(arg, "(iii);y,x,n", &y, &x, &n))
859 return NULL;
860 rtn2 = mvwinnstr(self->win, y, x, rtn, n);
861 break;
862 default:
863 PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000864 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000865 }
866 if (rtn2 == ERR)
867 rtn[0] = 0;
868 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000869}
870
871static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000872PyCursesWindow_InsStr(self,arg)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000873 PyCursesWindowObject *self;
874 PyObject * arg;
875{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000876 int rtn;
877 int x, y;
878 char *str;
879 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
880 int use_xy = FALSE, use_attr = FALSE;
881
882 switch (ARG_COUNT(arg)) {
883 case 1:
884 if (!PyArg_Parse(arg,"s;str", &str))
885 return NULL;
886 break;
887 case 2:
888 if (!PyArg_Parse(arg,"(sl);str,attr", &str, &attr))
889 return NULL;
890 use_attr = TRUE;
891 break;
892 case 3:
893 if (!PyArg_Parse(arg,"(iis);y,x,str", &y, &x, &str))
894 return NULL;
895 use_xy = TRUE;
896 break;
897 case 4:
898 if (!PyArg_Parse(arg,"(iisl);y,x,str,attr", &y, &x, &str, &attr))
899 return NULL;
900 use_xy = use_attr = TRUE;
901 break;
902 default:
903 PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000904 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000905 }
906
907 if (use_attr == TRUE) {
908 attr_old = getattrs(self->win);
909 wattrset(self->win,attr);
910 }
911 if (use_xy == TRUE)
912 rtn = mvwinsstr(self->win,y,x,str);
913 else
914 rtn = winsstr(self->win,str);
915 if (use_attr == TRUE)
916 wattrset(self->win,attr_old);
917 return PyCursesCheckERR(rtn, "insstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000918}
919
920static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000921PyCursesWindow_InsNStr(self,arg)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000922 PyCursesWindowObject *self;
923 PyObject * arg;
924{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000925 int rtn, x, y, n;
926 char *str;
927 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
928 int use_xy = FALSE, use_attr = FALSE;
929
930 switch (ARG_COUNT(arg)) {
931 case 2:
932 if (!PyArg_Parse(arg,"(si);str,n", &str, &n))
933 return NULL;
934 break;
935 case 3:
936 if (!PyArg_Parse(arg,"(sil);str,n,attr", &str, &n, &attr))
937 return NULL;
938 use_attr = TRUE;
939 break;
940 case 4:
941 if (!PyArg_Parse(arg,"(iisi);y,x,str,n", &y, &x, &str, &n))
942 return NULL;
943 use_xy = TRUE;
944 break;
945 case 5:
946 if (!PyArg_Parse(arg,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr))
947 return NULL;
948 use_xy = use_attr = TRUE;
949 break;
950 default:
951 PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000952 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000953 }
954
955 if (use_attr == TRUE) {
956 attr_old = getattrs(self->win);
957 wattrset(self->win,attr);
958 }
959 if (use_xy == TRUE)
960 rtn = mvwinsnstr(self->win,y,x,str,n);
961 else
962 rtn = winsnstr(self->win,str,n);
963 if (use_attr == TRUE)
964 wattrset(self->win,attr_old);
965 return PyCursesCheckERR(rtn, "insnstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000966}
967
968static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000969PyCursesWindow_Is_LineTouched(self,arg)
970 PyCursesWindowObject * self;
971 PyObject * arg;
972{
973 int line, erg;
974 if (!PyArg_Parse(arg,"i;line", &line))
975 return NULL;
976 erg = is_linetouched(self->win, line);
977 if (erg == ERR) {
978 PyErr_SetString(PyExc_TypeError,
979 "is_linetouched: line number outside of boundaries");
980 return NULL;
981 } else
982 if (erg == FALSE) {
983 Py_INCREF(Py_False);
984 return Py_False;
985 } else {
986 Py_INCREF(Py_True);
987 return Py_True;
988 }
989}
990
991static PyObject *
992PyCursesWindow_NoOutRefresh(self,arg)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000993 PyCursesWindowObject *self;
994 PyObject * arg;
995{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000996 int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
997
998 if (self->win->_flags & _ISPAD) {
999 switch(ARG_COUNT(arg)) {
1000 case 6:
1001 if (!PyArg_Parse(arg,
1002 "(iiiiii);" \
1003 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1004 &pminrow, &pmincol, &sminrow,
1005 &smincol, &smaxrow, &smaxcol))
1006 return NULL;
1007 return PyCursesCheckERR(pnoutrefresh(self->win,
1008 pminrow, pmincol, sminrow,
1009 smincol, smaxrow, smaxcol),
1010 "pnoutrefresh");
1011 default:
1012 PyErr_SetString(PyCursesError,
1013 "noutrefresh was called for a pad;" \
1014 "requires 6 arguments");
1015 return NULL;
1016 }
1017 } else {
1018 if (!PyArg_NoArgs(arg))
1019 return NULL;
1020 return PyCursesCheckERR(wnoutrefresh(self->win), "wnoutrefresh");
1021 }
1022}
1023
1024static PyObject *
1025PyCursesWindow_PutWin(self, arg)
1026 PyCursesWindowObject *self;
1027 PyObject *arg;
1028{
1029 PyObject *temp;
1030
1031 if (!PyArg_Parse(arg, "O;fileobj", &temp))
Guido van Rossum85738471995-02-17 13:50:17 +00001032 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001033 if (!PyFile_Check(temp)) {
1034 PyErr_SetString(PyExc_TypeError, "argument must be a file object");
1035 return NULL;
1036 }
1037 return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)),
1038 "putwin");
1039}
1040
1041static PyObject *
1042PyCursesWindow_RedrawLine(self,arg)
1043 PyCursesWindowObject *self;
1044 PyObject * arg;
1045{
1046 int beg, num;
1047 if (!PyArg_Parse(arg,"(ii);beg,num", &beg, &num))
1048 return NULL;
1049 return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
1050}
1051
1052static PyObject *
1053PyCursesWindow_Refresh(self,arg)
1054 PyCursesWindowObject *self;
1055 PyObject * arg;
1056{
1057 int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
1058
1059 if (self->win->_flags & _ISPAD) {
1060 switch(ARG_COUNT(arg)) {
1061 case 6:
1062 if (!PyArg_Parse(arg,
1063 "(iiiiii);" \
1064 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1065 &pminrow, &pmincol, &sminrow,
1066 &smincol, &smaxrow, &smaxcol))
1067 return NULL;
1068 return PyCursesCheckERR(prefresh(self->win,
1069 pminrow, pmincol, sminrow,
1070 smincol, smaxrow, smaxcol),
1071 "prefresh");
1072 default:
1073 PyErr_SetString(PyCursesError,
1074 "refresh was called for a pad; requires 6 arguments");
1075 return NULL;
1076 }
1077 } else {
1078 if (!PyArg_NoArgs(arg))
1079 return NULL;
1080 return PyCursesCheckERR(wrefresh(self->win), "wrefresh");
1081 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001082}
1083
1084static PyObject *
1085PyCursesWindow_SetScrollRegion(self,arg)
1086 PyCursesWindowObject *self;
1087 PyObject * arg;
1088{
1089 int x, y;
1090 if (!PyArg_Parse(arg,"(ii);top, bottom",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +00001091 return NULL;
1092 return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001093}
1094
1095static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001096PyCursesWindow_SubWin(self,arg)
1097 PyCursesWindowObject *self;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001098 PyObject * arg;
1099{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001100 WINDOW *win;
1101 int nlines, ncols, begin_y, begin_x;
1102
1103 if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x",
1104 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +00001105 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001106
1107 if (self->win->_flags & _ISPAD)
1108 win = subpad(self->win, nlines, ncols, begin_y, begin_x);
1109 else
1110 win = subwin(self->win,nlines,ncols,begin_y,begin_x);
1111
1112 if (win == NULL) {
1113 PyErr_SetString(PyCursesError, catchall_NULL);
1114 return NULL;
1115 }
1116
1117 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001118}
1119
1120static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001121PyCursesWindow_Scroll(self,arg)
1122 PyCursesWindowObject *self;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001123 PyObject * arg;
1124{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001125 int lines;
1126 switch(ARG_COUNT(arg)) {
1127 case 0:
1128 return PyCursesCheckERR(scroll(self->win), "scroll");
1129 break;
1130 case 1:
1131 if (!PyArg_Parse(arg, "i;lines", &lines))
1132 return NULL;
1133 return PyCursesCheckERR(wscrl(self->win, lines), "scroll");
1134 default:
1135 PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001136 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001137 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001138}
1139
1140static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001141PyCursesWindow_TouchLine(self,arg)
1142 PyCursesWindowObject *self;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001143 PyObject * arg;
1144{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001145 int st, cnt, val;
1146 switch (ARG_COUNT(arg)) {
1147 case 2:
1148 if (!PyArg_Parse(arg,"(ii);start,count",&st,&cnt))
1149 return NULL;
1150 return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
1151 break;
1152 case 3:
1153 if (!PyArg_Parse(arg, "(iii);start,count,val", &st, &cnt, &val))
1154 return NULL;
1155 return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
1156 default:
1157 PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001158 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001159 }
1160}
1161
1162static PyObject *
1163PyCursesWindow_Vline(self, args)
1164 PyCursesWindowObject *self;
1165 PyObject *args;
1166{
1167 PyObject *temp;
1168 chtype ch;
1169 int n, x, y, code = OK;
1170 attr_t attr = A_NORMAL;
1171
1172 switch (ARG_COUNT(args)) {
1173 case 2:
1174 if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n))
1175 return NULL;
1176 break;
1177 case 3:
1178 if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr))
1179 return NULL;
1180 break;
1181 case 4:
1182 if (!PyArg_Parse(args, "(iiOi);y,x,ch o int,n", &y, &x, &temp, &n))
1183 return NULL;
1184 code = wmove(self->win, y, x);
1185 break;
1186 case 5:
1187 if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr",
1188 &y, &x, &temp, &n, &attr))
1189 return NULL;
1190 code = wmove(self->win, y, x);
1191 default:
1192 PyErr_SetString(PyExc_TypeError, "vline requires 2 or 5 arguments");
1193 return NULL;
1194 }
1195
1196 if (code != ERR) {
1197 if (!PyCurses_ConvertToChtype(temp, &ch)) {
1198 PyErr_SetString(PyExc_TypeError,
1199 "argument 1 or 3 must be a ch or an int");
1200 return NULL;
1201 }
1202 return PyCursesCheckERR(whline(self->win, ch | attr, n), "vline");
1203 } else
1204 return PyCursesCheckERR(code, "wmove");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001205}
1206
1207static PyMethodDef PyCursesWindow_Methods[] = {
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001208 {"addch", (PyCFunction)PyCursesWindow_AddCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001209 {"addnstr", (PyCFunction)PyCursesWindow_AddNStr},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001210 {"addstr", (PyCFunction)PyCursesWindow_AddStr},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001211 {"attron", (PyCFunction)PyCursesWindow_wattron},
1212 {"attr_on", (PyCFunction)PyCursesWindow_wattron},
1213 {"attroff", (PyCFunction)PyCursesWindow_wattroff},
1214 {"attr_off", (PyCFunction)PyCursesWindow_wattroff},
1215 {"attrset", (PyCFunction)PyCursesWindow_wattrset},
1216 {"attr_set", (PyCFunction)PyCursesWindow_wattrset},
1217 {"bkgd", (PyCFunction)PyCursesWindow_Bkgd},
1218 {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001219 {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
1220 {"box", (PyCFunction)PyCursesWindow_Box},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001221 {"clear", (PyCFunction)PyCursesWindow_wclear},
1222 {"clearok", (PyCFunction)PyCursesWindow_clearok},
1223 {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot},
1224 {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol},
1225 {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup},
1226 {"delch", (PyCFunction)PyCursesWindow_DelCh},
1227 {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln},
1228 {"derwin", (PyCFunction)PyCursesWindow_DerWin},
1229 {"echochar", (PyCFunction)PyCursesWindow_EchoChar},
1230 {"erase", (PyCFunction)PyCursesWindow_werase},
1231 {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx},
1232 {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001233 {"getch", (PyCFunction)PyCursesWindow_GetCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001234 {"getkey", (PyCFunction)PyCursesWindow_GetKey},
1235 {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx},
1236 {"getparyx", (PyCFunction)PyCursesWindow_getparyx},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001237 {"getstr", (PyCFunction)PyCursesWindow_GetStr},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001238 {"getyx", (PyCFunction)PyCursesWindow_getyx},
1239 {"hline", (PyCFunction)PyCursesWindow_Hline},
1240 {"idlok", (PyCFunction)PyCursesWindow_idlok},
1241 {"idcok", (PyCFunction)PyCursesWindow_idcok},
1242 {"immedok", (PyCFunction)PyCursesWindow_immedok},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001243 {"inch", (PyCFunction)PyCursesWindow_InCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001244 {"insch", (PyCFunction)PyCursesWindow_InsCh},
1245 {"insdelln", (PyCFunction)PyCursesWindow_winsdelln},
1246 {"insertln", (PyCFunction)PyCursesWindow_winsertln},
1247 {"insnstr", (PyCFunction)PyCursesWindow_InsNStr},
1248 {"insstr", (PyCFunction)PyCursesWindow_InsStr},
1249 {"instr", (PyCFunction)PyCursesWindow_InStr},
1250 {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched},
1251 {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched},
1252 {"keypad", (PyCFunction)PyCursesWindow_keypad},
1253 {"leaveok", (PyCFunction)PyCursesWindow_leaveok},
1254 {"move", (PyCFunction)PyCursesWindow_wmove},
1255 {"mvwin", (PyCFunction)PyCursesWindow_mvwin},
1256 {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin},
1257 {"nodelay", (PyCFunction)PyCursesWindow_nodelay},
1258 {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
1259 {"notimeout", (PyCFunction)PyCursesWindow_notimeout},
1260 {"putwin", (PyCFunction)PyCursesWindow_PutWin},
1261 {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin},
1262 {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine},
1263 {"refresh", (PyCFunction)PyCursesWindow_Refresh},
1264#ifndef __sgi__
1265 {"resize", (PyCFunction)PyCursesWindow_wresize},
1266#endif
1267 {"scroll", (PyCFunction)PyCursesWindow_Scroll},
1268 {"scrollok", (PyCFunction)PyCursesWindow_scrollok},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001269 {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001270 {"standend", (PyCFunction)PyCursesWindow_wstandend},
1271 {"standout", (PyCFunction)PyCursesWindow_wstandout},
1272 {"subpad", (PyCFunction)PyCursesWindow_SubWin},
1273 {"subwin", (PyCFunction)PyCursesWindow_SubWin},
1274 {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown},
1275 {"syncok", (PyCFunction)PyCursesWindow_syncok},
1276 {"syncup", (PyCFunction)PyCursesWindow_wsyncup},
1277 {"touchline", (PyCFunction)PyCursesWindow_TouchLine},
1278 {"touchwin", (PyCFunction)PyCursesWindow_touchwin},
1279 {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin},
1280 {"vline", (PyCFunction)PyCursesWindow_Vline},
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001281 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00001282};
1283
1284static PyObject *
1285PyCursesWindow_GetAttr(self, name)
1286 PyCursesWindowObject *self;
1287 char *name;
1288{
Guido van Rossuma597dde1995-01-10 20:56:29 +00001289 return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001290}
1291
Guido van Rossumf6971e21994-08-30 12:25:20 +00001292/* -------------------------------------------------------*/
Guido van Rossum85738471995-02-17 13:50:17 +00001293
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001294PyTypeObject PyCursesWindow_Type = {
Guido van Rossumf6971e21994-08-30 12:25:20 +00001295 PyObject_HEAD_INIT(&PyType_Type)
1296 0, /*ob_size*/
1297 "curses window", /*tp_name*/
1298 sizeof(PyCursesWindowObject), /*tp_basicsize*/
1299 0, /*tp_itemsize*/
1300 /* methods */
1301 (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
1302 0, /*tp_print*/
1303 (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
1304 (setattrfunc)0, /*tp_setattr*/
1305 0, /*tp_compare*/
1306 0, /*tp_repr*/
1307 0, /*tp_as_number*/
1308 0, /*tp_as_sequence*/
1309 0, /*tp_as_mapping*/
1310 0, /*tp_hash*/
1311};
1312
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001313/*********************************************************************
1314 Global Functions
1315**********************************************************************/
Guido van Rossumf6971e21994-08-30 12:25:20 +00001316
Guido van Rossume4485b01994-09-07 14:32:49 +00001317static PyObject *ModDict;
1318
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001319/* Function Prototype Macros - They are ugly but very, very useful. ;-)
1320
1321 X - function name
1322 TYPE - parameter Type
1323 ERGSTR - format string for construction of the return value
1324 PARSESTR - format string for argument parsing
1325 */
1326
1327#define NoArgNoReturnFunction(X) \
1328static PyObject *PyCurses_ ## X (self, arg) \
1329 PyObject * self; \
1330 PyObject * arg; \
1331{ \
1332 PyCursesInitialised \
1333 if (!PyArg_NoArgs(arg)) return NULL; \
1334 return PyCursesCheckERR(X(), # X); }
1335
1336#define NoArgOrFlagNoReturnFunction(X) \
1337static PyObject *PyCurses_ ## X (self, arg) \
1338 PyObject * self; \
1339 PyObject * arg; \
1340{ \
1341 int flag = 0; \
1342 PyCursesInitialised \
1343 switch(ARG_COUNT(arg)) { \
1344 case 0: \
1345 return PyCursesCheckERR(X(), # X); \
1346 case 1: \
1347 if (!PyArg_Parse(arg, "i;True(1) or False(0)", &flag)) return NULL; \
1348 if (flag) return PyCursesCheckERR(X(), # X); \
1349 else return PyCursesCheckERR(no ## X (), # X); \
1350 default: \
1351 PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 argument"); \
1352 return NULL; } }
1353
1354#define NoArgReturnIntFunction(X) \
1355static PyObject *PyCurses_ ## X (self, arg) \
1356 PyObject * self; \
1357 PyObject * arg; \
1358{ \
1359 PyCursesInitialised \
1360 if (!PyArg_NoArgs(arg)) return NULL; \
1361 return PyInt_FromLong((long) X()); }
1362
1363
1364#define NoArgReturnStringFunction(X) \
1365static PyObject *PyCurses_ ## X (self, arg) \
1366 PyObject * self; \
1367 PyObject * arg; \
1368{ \
1369 PyCursesInitialised \
1370 if (!PyArg_NoArgs(arg)) return NULL; \
1371 return PyString_FromString(X()); }
1372
1373#define NoArgTrueFalseFunction(X) \
1374static PyObject * PyCurses_ ## X (self,arg) \
1375 PyObject * self; \
1376 PyObject * arg; \
1377{ \
1378 PyCursesInitialised \
1379 if (!PyArg_NoArgs(arg)) return NULL; \
1380 if (X () == FALSE) { \
1381 Py_INCREF(Py_False); \
1382 return Py_False; \
1383 } \
1384 Py_INCREF(Py_True); \
1385 return Py_True; }
1386
1387#define NoArgNoReturnVoidFunction(X) \
1388static PyObject * PyCurses_ ## X (self,arg) \
1389 PyObject * self; \
1390 PyObject * arg; \
1391{ \
1392 PyCursesInitialised \
1393 if (!PyArg_NoArgs(arg)) return NULL; \
1394 X(); \
1395 Py_INCREF(Py_None); \
1396 return Py_None; }
1397
1398NoArgNoReturnFunction(beep)
1399NoArgNoReturnFunction(def_prog_mode)
1400NoArgNoReturnFunction(def_shell_mode)
1401NoArgNoReturnFunction(doupdate)
1402NoArgNoReturnFunction(endwin)
1403NoArgNoReturnFunction(flash)
1404NoArgNoReturnFunction(nocbreak)
1405NoArgNoReturnFunction(noecho)
1406NoArgNoReturnFunction(nonl)
1407NoArgNoReturnFunction(noraw)
1408NoArgNoReturnFunction(reset_prog_mode)
1409NoArgNoReturnFunction(reset_shell_mode)
1410NoArgNoReturnFunction(resetty)
1411NoArgNoReturnFunction(savetty)
1412
1413NoArgOrFlagNoReturnFunction(cbreak)
1414NoArgOrFlagNoReturnFunction(echo)
1415NoArgOrFlagNoReturnFunction(nl)
1416NoArgOrFlagNoReturnFunction(raw)
1417
1418NoArgReturnIntFunction(baudrate)
1419NoArgReturnIntFunction(termattrs)
1420
1421NoArgReturnStringFunction(termname)
1422NoArgReturnStringFunction(longname)
1423
1424NoArgTrueFalseFunction(can_change_color)
1425NoArgTrueFalseFunction(has_colors)
1426NoArgTrueFalseFunction(has_ic)
1427NoArgTrueFalseFunction(has_il)
1428NoArgTrueFalseFunction(isendwin)
1429
1430NoArgNoReturnVoidFunction(filter)
1431NoArgNoReturnVoidFunction(flushinp)
1432NoArgNoReturnVoidFunction(noqiflush)
1433
1434static PyObject *
1435PyCurses_Color_Content(self, arg)
1436 PyObject * self;
1437 PyObject * arg;
1438{
1439 short color,r,g,b;
1440
1441 PyCursesInitialised
1442 PyCursesInitialisedColor
1443
1444 if (ARG_COUNT(arg) != 1) {
1445 PyErr_SetString(PyExc_TypeError,
1446 "color_content requires 1 argument");
1447 return NULL;
1448 }
1449
1450 if (!PyArg_Parse(arg, "h;color", &color)) return NULL;
1451
1452 if (color_content(color, &r, &g, &b) != ERR)
1453 return Py_BuildValue("(iii)", r, g, b);
1454 else {
1455 PyErr_SetString(PyCursesError,
1456 "Argument 1 was out of range. Check value of COLORS.");
1457 return NULL;
1458 }
1459}
1460
1461static PyObject *
1462PyCurses_COLOR_PAIR(self, arg)
1463 PyObject * self;
1464 PyObject * arg;
1465{
1466 int n;
1467
1468 PyCursesInitialised
1469 PyCursesInitialisedColor
1470
1471 if (ARG_COUNT(arg)!=1) {
1472 PyErr_SetString(PyExc_TypeError, "COLOR_PAIR requires 1 argument");
1473 return NULL;
1474 }
1475 if (!PyArg_Parse(arg, "i;number", &n)) return NULL;
1476 return PyInt_FromLong((long) (n << 8));
1477}
1478
1479static PyObject *
1480PyCurses_Curs_Set(self, arg)
1481 PyObject * self;
1482 PyObject * arg;
1483{
1484 int vis,erg;
1485
1486 PyCursesInitialised
1487
1488 if (ARG_COUNT(arg)==1) {
1489 PyErr_SetString(PyExc_TypeError, "curs_set requires 1 argument");
1490 return NULL;
1491 }
1492
1493 if (!PyArg_Parse(arg, "i;int", &vis)) return NULL;
1494
1495 erg = curs_set(vis);
1496 if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
1497
1498 return PyInt_FromLong((long) erg);
1499}
1500
1501static PyObject *
1502PyCurses_Delay_Output(self,arg)
1503 PyObject * self;
1504 PyObject * arg;
1505{
1506 int ms;
1507
1508 PyCursesInitialised
1509
1510 if (ARG_COUNT(arg)==1) {
1511 PyErr_SetString(PyExc_TypeError, "delay_output requires 1 argument");
1512 return NULL;
1513 }
1514 if (!PyArg_Parse(arg, "i;ms", &ms)) return NULL;
1515
1516 return PyCursesCheckERR(delay_output(ms), "delay_output");
1517}
1518
1519static PyObject *
1520PyCurses_EraseChar(self,arg)
1521 PyObject * self;
1522 PyObject * arg;
1523{
1524 char ch;
1525
1526 PyCursesInitialised
1527
1528 if (!PyArg_NoArgs(arg)) return NULL;
1529
1530 ch = erasechar();
1531
1532 return PyString_FromString(&ch);
1533}
1534
1535static PyObject *
1536PyCurses_getsyx(self, arg)
1537 PyObject * self;
1538 PyObject * arg;
1539{
1540 int x,y;
1541
1542 PyCursesInitialised
1543
1544 if (!PyArg_NoArgs(arg)) return NULL;
1545
1546 getsyx(y, x);
1547
1548 return Py_BuildValue("(ii)", y, x);
1549}
1550
1551static PyObject *
1552PyCurses_GetWin(self,arg)
1553 PyCursesWindowObject *self;
1554 PyObject * arg;
1555{
1556 WINDOW *win;
1557 PyObject *temp;
1558
1559 PyCursesInitialised
1560
1561 if (!PyArg_Parse(arg, "O;fileobj", &temp)) return NULL;
1562
1563 if (!PyFile_Check(temp)) {
1564 PyErr_SetString(PyExc_TypeError, "argument must be a file object");
1565 return NULL;
1566 }
1567
1568 win = getwin(PyFile_AsFile(temp));
1569
1570 if (win == NULL) {
1571 PyErr_SetString(PyCursesError, catchall_NULL);
1572 return NULL;
1573 }
1574
1575 return PyCursesWindow_New(win);
1576}
1577
1578static PyObject *
1579PyCurses_HalfDelay(self,arg)
1580 PyObject * self;
1581 PyObject * arg;
1582{
1583 unsigned char tenths;
1584
1585 PyCursesInitialised
1586
1587 switch(ARG_COUNT(arg)) {
1588 case 1:
1589 if (!PyArg_Parse(arg, "b;tenths", &tenths)) return NULL;
1590 break;
1591 default:
1592 PyErr_SetString(PyExc_TypeError, "halfdelay requires 1 argument");
1593 return NULL;
1594 }
1595
1596 return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
1597}
1598
1599#ifndef __sgi__
1600 /* No has_key! */
1601static PyObject * PyCurses_has_key(self,arg)
1602 PyObject * self;
1603 PyObject * arg;
1604{
1605 int ch;
1606
1607 PyCursesInitialised
1608
1609 if (!PyArg_Parse(arg,"i",&ch)) return NULL;
1610
1611 if (has_key(ch) == FALSE) {
1612 Py_INCREF(Py_False);
1613 return Py_False;
1614 }
1615 Py_INCREF(Py_True);
1616 return Py_True;
1617}
1618#endif
1619
1620static PyObject *
1621PyCurses_Init_Color(self, arg)
1622 PyObject * self;
1623 PyObject * arg;
1624{
1625 short color, r, g, b;
1626
1627 PyCursesInitialised
1628 PyCursesInitialisedColor
1629
1630 switch(ARG_COUNT(arg)) {
1631 case 4:
1632 if (!PyArg_Parse(arg, "(hhhh);color,r,g,b", &color, &r, &g, &b)) return NULL;
1633 break;
1634 default:
1635 PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
1636 return NULL;
1637 }
1638
1639 return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
1640}
1641
1642static PyObject *
1643PyCurses_Init_Pair(self, arg)
1644 PyObject * self;
1645 PyObject * arg;
1646{
1647 short pair, f, b;
1648
1649 PyCursesInitialised
1650 PyCursesInitialisedColor
1651
1652 if (ARG_COUNT(arg) == 3) {
1653 PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
1654 return NULL;
1655 }
1656
1657 if (!PyArg_Parse(arg, "(hhh);pair, f, b", &pair, &f, &b)) return NULL;
1658
1659 return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
1660}
1661
Guido van Rossumf6971e21994-08-30 12:25:20 +00001662static PyObject *
1663PyCurses_InitScr(self, args)
1664 PyObject * self;
1665 PyObject * args;
1666{
Guido van Rossum56bf2351994-08-31 22:06:24 +00001667 WINDOW *win;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001668 PyObject *lines, *cols;
1669
1670 if (!PyArg_NoArgs(args)) return NULL;
1671
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001672 if (initialised == TRUE) {
Guido van Rossumf6971e21994-08-30 12:25:20 +00001673 wrefresh(stdscr);
1674 return (PyObject *)PyCursesWindow_New(stdscr);
1675 }
Guido van Rossum56bf2351994-08-31 22:06:24 +00001676
1677 win = initscr();
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001678
Guido van Rossum85738471995-02-17 13:50:17 +00001679 if (win == NULL) {
1680 PyErr_SetString(PyCursesError, catchall_NULL);
1681 return NULL;
1682 }
1683
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001684 initialised = TRUE;
Guido van Rossum56bf2351994-08-31 22:06:24 +00001685
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001686 lines = PyInt_FromLong((long) LINES);
1687 PyDict_SetItemString(ModDict, "LINES", lines);
1688 Py_DECREF(lines);
1689 cols = PyInt_FromLong((long) COLS);
1690 PyDict_SetItemString(ModDict, "COLS", cols);
1691 Py_DECREF(cols);
Guido van Rossum56bf2351994-08-31 22:06:24 +00001692
1693 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001694}
1695
Guido van Rossumf6971e21994-08-30 12:25:20 +00001696
1697static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001698PyCurses_IntrFlush(self,arg)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001699 PyObject * self;
1700 PyObject * arg;
1701{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001702 int ch;
1703
1704 PyCursesInitialised
1705
1706 switch(ARG_COUNT(arg)) {
1707 case 1:
1708 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch)) return NULL;
1709 break;
1710 default:
1711 PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00001712 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001713 }
1714
1715 return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
1716}
1717
1718static PyObject *
1719PyCurses_KeyName(self,arg)
1720 PyObject * self;
1721 PyObject * arg;
1722{
1723 const char *knp;
1724 int ch;
1725
1726 PyCursesInitialised
1727
1728 if (!PyArg_Parse(arg,"i",&ch)) return NULL;
1729
1730 knp = keyname(ch);
1731
1732 return PyString_FromString((knp == NULL) ? "" : (char *)knp);
1733}
1734
1735static PyObject *
1736PyCurses_KillChar(self,arg)
1737PyObject * self;
1738PyObject * arg;
1739{
1740 char ch;
1741
1742 if (!PyArg_NoArgs(arg)) return NULL;
1743
1744 ch = killchar();
1745
1746 return PyString_FromString(&ch);
1747}
1748
1749static PyObject *
1750PyCurses_Meta(self,arg)
1751 PyObject * self;
1752 PyObject * arg;
1753{
1754 int ch;
1755
1756 PyCursesInitialised
1757
1758 switch(ARG_COUNT(arg)) {
1759 case 1:
1760 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch)) return NULL;
1761 break;
1762 default:
1763 PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
1764 return NULL;
1765 }
1766
1767 return PyCursesCheckERR(meta(stdscr, ch), "meta");
1768}
1769
1770static PyObject *
1771PyCurses_NewPad(self,arg)
1772 PyObject * self;
1773 PyObject * arg;
1774{
1775 WINDOW *win;
1776 int nlines, ncols;
1777
1778 PyCursesInitialised
1779
1780 if (!PyArg_Parse(arg,"(ii);nlines,ncols",&nlines,&ncols)) return NULL;
1781
1782 win = newpad(nlines, ncols);
1783
1784 if (win == NULL) {
1785 PyErr_SetString(PyCursesError, catchall_NULL);
1786 return NULL;
1787 }
1788
1789 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001790}
1791
1792static PyObject *
1793PyCurses_NewWindow(self,arg)
1794 PyObject * self;
1795 PyObject * arg;
1796{
1797 WINDOW *win;
1798 int nlines, ncols, begin_y, begin_x;
Guido van Rossum85738471995-02-17 13:50:17 +00001799
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001800 PyCursesInitialised
1801
Guido van Rossum85738471995-02-17 13:50:17 +00001802 switch (ARG_COUNT(arg)) {
1803 case 2:
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001804 if (!PyArg_Parse(arg,"(ii);nlines,ncols",&nlines,&ncols))
Guido van Rossum85738471995-02-17 13:50:17 +00001805 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001806 win = newpad(nlines, ncols);
Guido van Rossum85738471995-02-17 13:50:17 +00001807 break;
1808 case 4:
1809 if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x",
Guido van Rossumf6971e21994-08-30 12:25:20 +00001810 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +00001811 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001812 win = newwin(nlines,ncols,begin_y,begin_x);
Guido van Rossum85738471995-02-17 13:50:17 +00001813 break;
1814 default:
1815 PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
1816 return NULL;
1817 }
1818
Guido van Rossumf6971e21994-08-30 12:25:20 +00001819 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +00001820 PyErr_SetString(PyCursesError, catchall_NULL);
1821 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001822 }
Guido van Rossum85738471995-02-17 13:50:17 +00001823
Guido van Rossumf6971e21994-08-30 12:25:20 +00001824 return (PyObject *)PyCursesWindow_New(win);
1825}
1826
1827static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001828PyCurses_Pair_Content(self, arg)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001829 PyObject * self;
1830 PyObject * arg;
1831{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001832 short pair,f,b;
1833
1834 PyCursesInitialised
1835 PyCursesInitialisedColor
1836
1837 switch(ARG_COUNT(arg)) {
1838 case 1:
1839 if (!PyArg_Parse(arg, "h;pair", &pair)) return NULL;
1840 break;
1841 default:
1842 PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00001843 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001844 }
1845
1846 if (!pair_content(pair, &f, &b)) {
1847 PyErr_SetString(PyCursesError,
1848 "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
1849 return NULL;
1850 }
1851
1852 return Py_BuildValue("(ii)", f, b);
1853}
1854
1855static PyObject *
1856PyCurses_PAIR_NUMBER(self, arg)
1857 PyObject * self;
1858 PyObject * arg;
1859{
1860 int n;
1861
1862 PyCursesInitialised
1863 PyCursesInitialisedColor
1864
1865 switch(ARG_COUNT(arg)) {
1866 case 1:
1867 if (!PyArg_Parse(arg, "i;pairvalue", &n)) return NULL;
1868 break;
1869 default:
1870 PyErr_SetString(PyExc_TypeError,
1871 "PAIR_NUMBER requires 1 argument");
1872 return NULL;
1873 }
1874
1875 return PyInt_FromLong((long) ((n & A_COLOR) >> 8));
1876}
1877
1878static PyObject *
1879PyCurses_Putp(self,arg)
1880 PyObject *self;
1881 PyObject *arg;
1882{
1883 char *str;
1884
1885 if (!PyArg_Parse(arg,"s;str", &str)) return NULL;
1886 return PyCursesCheckERR(putp(str), "putp");
1887}
1888
1889static PyObject *
1890PyCurses_QiFlush(self, arg)
1891 PyObject * self;
1892 PyObject * arg;
1893{
1894 int flag = 0;
1895
1896 PyCursesInitialised
1897
1898 switch(ARG_COUNT(arg)) {
1899 case 0:
1900 qiflush();
1901 Py_INCREF(Py_None);
1902 return Py_None;
1903 case 1:
1904 if (!PyArg_Parse(arg, "i;True(1) or False(0)", &flag)) return NULL;
1905 if (flag) qiflush();
1906 else noqiflush();
1907 Py_INCREF(Py_None);
1908 return Py_None;
1909 default:
1910 PyErr_SetString(PyExc_TypeError, "nl requires 0 or 1 argument");
1911 return NULL;
1912 }
1913}
1914
1915static PyObject *
1916PyCurses_setsyx(self, arg)
1917 PyObject * self;
1918 PyObject * arg;
1919{
1920 int y,x;
1921
1922 PyCursesInitialised
1923
1924 if (ARG_COUNT(arg)!=3) {
1925 PyErr_SetString(PyExc_TypeError, "curs_set requires 3 argument");
1926 return NULL;
1927 }
1928
1929 if (!PyArg_Parse(arg, "(ii);y, x", &y, &x)) return NULL;
1930
1931 setsyx(y,x);
1932
Guido van Rossumf6971e21994-08-30 12:25:20 +00001933 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001934 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001935}
1936
1937static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001938PyCurses_Start_Color(self,arg)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001939 PyObject * self;
1940 PyObject * arg;
1941{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001942 int code;
1943 PyObject *c, *cp;
1944
1945 PyCursesInitialised
1946
1947 if (!PyArg_NoArgs(arg)) return NULL;
1948
1949 code = start_color();
1950 if (code != ERR) {
1951 initialisedcolors = TRUE;
1952 c = PyInt_FromLong((long) COLORS);
1953 PyDict_SetItemString(ModDict, "COLORS", c);
1954 Py_DECREF(c);
1955 cp = PyInt_FromLong((long) COLOR_PAIRS);
1956 PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
1957 Py_DECREF(cp);
1958 Py_INCREF(Py_None);
1959 return Py_None;
1960 } else {
1961 PyErr_SetString(PyCursesError, "start_color() returned ERR");
Guido van Rossum85738471995-02-17 13:50:17 +00001962 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001963 }
1964}
1965
1966static PyObject *
1967PyCurses_UnCtrl(self,arg)
1968 PyObject * self;
1969 PyObject * arg;
1970{
1971 PyObject *temp;
1972 chtype ch;
1973
1974 PyCursesInitialised
1975
1976 if (!PyArg_Parse(arg,"O;ch or int",&temp)) return NULL;
1977
1978 if (PyInt_Check(temp))
1979 ch = (chtype) PyInt_AsLong(temp);
1980 else if (PyString_Check(temp))
1981 ch = (chtype) *PyString_AsString(temp);
1982 else {
1983 PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
1984 return NULL;
1985 }
1986
1987 return PyString_FromString(unctrl(ch));
Guido van Rossumf6971e21994-08-30 12:25:20 +00001988}
1989
1990static PyObject *
1991PyCurses_UngetCh(self,arg)
1992 PyObject * self;
1993 PyObject * arg;
1994{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001995 PyObject *temp;
1996 chtype ch;
1997
1998 PyCursesInitialised
1999
2000 if (!PyArg_Parse(arg,"O;ch or int",&temp)) return NULL;
2001
2002 if (PyInt_Check(temp))
2003 ch = (chtype) PyInt_AsLong(temp);
2004 else if (PyString_Check(temp))
2005 ch = (chtype) *PyString_AsString(temp);
2006 else {
2007 PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
Guido van Rossum85738471995-02-17 13:50:17 +00002008 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002009 }
2010
Guido van Rossum85738471995-02-17 13:50:17 +00002011 return PyCursesCheckERR(ungetch(ch), "ungetch");
Guido van Rossumf6971e21994-08-30 12:25:20 +00002012}
2013
2014static PyObject *
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002015PyCurses_Use_Env(self,arg)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002016 PyObject * self;
2017 PyObject * arg;
2018{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002019 int flag;
2020
2021 PyCursesInitialised
2022
2023 switch(ARG_COUNT(arg)) {
2024 case 1:
2025 if (!PyArg_Parse(arg,"i;True(1), False(0)",&flag))
2026 return NULL;
2027 break;
2028 default:
2029 PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00002030 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002031 }
2032 use_env(flag);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002033 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00002034 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002035}
2036
Guido van Rossumf6971e21994-08-30 12:25:20 +00002037/* List of functions defined in the module */
2038
2039static PyMethodDef PyCurses_methods[] = {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002040 {"baudrate", (PyCFunction)PyCurses_baudrate},
2041 {"beep", (PyCFunction)PyCurses_beep},
2042 {"can_change_color", (PyCFunction)PyCurses_can_change_color},
2043 {"cbreak", (PyCFunction)PyCurses_cbreak},
2044 {"color_content", (PyCFunction)PyCurses_Color_Content},
2045 {"COLOR_PAIR", (PyCFunction)PyCurses_COLOR_PAIR},
2046 {"curs_set", (PyCFunction)PyCurses_Curs_Set},
2047 {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode},
2048 {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode},
2049 {"delay_output", (PyCFunction)PyCurses_Delay_Output},
2050 {"doupdate", (PyCFunction)PyCurses_doupdate},
2051 {"echo", (PyCFunction)PyCurses_echo},
2052 {"endwin", (PyCFunction)PyCurses_endwin},
2053 {"erasechar", (PyCFunction)PyCurses_EraseChar},
2054 {"filter", (PyCFunction)PyCurses_filter},
2055 {"flash", (PyCFunction)PyCurses_flash},
2056 {"flushinp", (PyCFunction)PyCurses_flushinp},
2057 {"getsyx", (PyCFunction)PyCurses_getsyx},
2058 {"getwin", (PyCFunction)PyCurses_GetWin},
2059 {"has_colors", (PyCFunction)PyCurses_has_colors},
2060 {"has_ic", (PyCFunction)PyCurses_has_ic},
2061 {"has_il", (PyCFunction)PyCurses_has_il},
2062#ifndef __sgi__
2063 {"has_key", (PyCFunction)PyCurses_has_key},
Guido van Rossumf6971e21994-08-30 12:25:20 +00002064#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002065 {"halfdelay", (PyCFunction)PyCurses_HalfDelay},
2066 {"init_color", (PyCFunction)PyCurses_Init_Color},
2067 {"init_pair", (PyCFunction)PyCurses_Init_Pair},
2068 {"initscr", (PyCFunction)PyCurses_InitScr},
2069 {"intrflush", (PyCFunction)PyCurses_IntrFlush},
2070 {"isendwin", (PyCFunction)PyCurses_isendwin},
2071 {"keyname", (PyCFunction)PyCurses_KeyName},
2072 {"killchar", (PyCFunction)PyCurses_KillChar},
2073 {"longname", (PyCFunction)PyCurses_longname},
2074 {"meta", (PyCFunction)PyCurses_Meta},
2075 {"newpad", (PyCFunction)PyCurses_NewPad},
2076 {"newwin", (PyCFunction)PyCurses_NewWindow},
2077 {"nl", (PyCFunction)PyCurses_nl},
2078 {"nocbreak", (PyCFunction)PyCurses_nocbreak},
2079 {"noecho", (PyCFunction)PyCurses_noecho},
2080 {"nonl", (PyCFunction)PyCurses_nonl},
2081 {"noqiflush", (PyCFunction)PyCurses_noqiflush},
2082 {"noraw", (PyCFunction)PyCurses_noraw},
2083 {"pair_content", (PyCFunction)PyCurses_Pair_Content},
2084 {"PAIR_NUMBER", (PyCFunction)PyCurses_PAIR_NUMBER},
2085 {"putp", (PyCFunction)PyCurses_Putp},
2086 {"qiflush", (PyCFunction)PyCurses_QiFlush},
2087 {"raw", (PyCFunction)PyCurses_raw},
2088 {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode},
2089 {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode},
2090 {"setsyx", (PyCFunction)PyCurses_setsyx},
2091 {"start_color", (PyCFunction)PyCurses_Start_Color},
2092 {"termattrs", (PyCFunction)PyCurses_termattrs},
2093 {"termname", (PyCFunction)PyCurses_termname},
2094 {"unctrl", (PyCFunction)PyCurses_UnCtrl},
2095 {"ungetch", (PyCFunction)PyCurses_UngetCh},
2096 {"use_env", (PyCFunction)PyCurses_Use_Env},
2097 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00002098};
2099
2100/* Initialization function for the module */
2101
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002102void
Guido van Rossum56bf2351994-08-31 22:06:24 +00002103initcurses()
Guido van Rossumf6971e21994-08-30 12:25:20 +00002104{
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00002105 PyObject *m, *d, *v;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002106
2107 /* Create the module and add the functions */
Guido van Rossum56bf2351994-08-31 22:06:24 +00002108 m = Py_InitModule("curses", PyCurses_methods);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002109
Guido van Rossumf6971e21994-08-30 12:25:20 +00002110 /* Add some symbolic constants to the module */
2111 d = PyModule_GetDict(m);
Guido van Rossume4485b01994-09-07 14:32:49 +00002112 ModDict = d; /* For PyCurses_InitScr */
Guido van Rossumfbea2f31994-08-31 22:05:27 +00002113
Guido van Rossum85738471995-02-17 13:50:17 +00002114 /* For exception curses.error */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002115 PyCursesError = PyString_FromString("curses.error");
Guido van Rossum85738471995-02-17 13:50:17 +00002116 PyDict_SetItemString(d, "error", PyCursesError);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00002117
Guido van Rossum85738471995-02-17 13:50:17 +00002118 /* Make the version available */
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00002119 v = PyString_FromString(PyCursesVersion);
2120 PyDict_SetItemString(d, "version", v);
2121 PyDict_SetItemString(d, "__version__", v);
2122 Py_DECREF(v);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002123
Guido van Rossumf6971e21994-08-30 12:25:20 +00002124 /* Here are some attributes you can add to chars to print */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002125
2126#define SetDictInt(string,ch) \
2127 PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
2128
2129#ifndef __sgi__
2130 /* On IRIX 5.3, the ACS characters aren't available until initscr() has been called. */
2131 SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
2132 SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
2133 SetDictInt("ACS_URCORNER", (ACS_URCORNER));
2134 SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
2135 SetDictInt("ACS_LTEE", (ACS_LTEE));
2136 SetDictInt("ACS_RTEE", (ACS_RTEE));
2137 SetDictInt("ACS_BTEE", (ACS_BTEE));
2138 SetDictInt("ACS_TTEE", (ACS_TTEE));
2139 SetDictInt("ACS_HLINE", (ACS_HLINE));
2140 SetDictInt("ACS_VLINE", (ACS_VLINE));
2141 SetDictInt("ACS_PLUS", (ACS_PLUS));
2142 SetDictInt("ACS_S1", (ACS_S1));
2143 SetDictInt("ACS_S9", (ACS_S9));
2144 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
2145 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
2146 SetDictInt("ACS_DEGREE", (ACS_DEGREE));
2147 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
2148 SetDictInt("ACS_BULLET", (ACS_BULLET));
2149 SetDictInt("ACS_LARROW", (ACS_LARROW));
2150 SetDictInt("ACS_RARROW", (ACS_RARROW));
2151 SetDictInt("ACS_DARROW", (ACS_DARROW));
2152 SetDictInt("ACS_UARROW", (ACS_UARROW));
2153 SetDictInt("ACS_BOARD", (ACS_BOARD));
2154 SetDictInt("ACS_LANTERN", (ACS_LANTERN));
2155 SetDictInt("ACS_BLOCK", (ACS_BLOCK));
2156#ifndef __sgi__
2157 /* The following are never available on IRIX 5.3 */
2158 SetDictInt("ACS_S3", (ACS_S3));
2159 SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
2160 SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
2161 SetDictInt("ACS_PI", (ACS_PI));
2162 SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
2163 SetDictInt("ACS_STERLING", (ACS_STERLING));
2164#endif
2165 SetDictInt("ACS_BSSB", (ACS_ULCORNER));
2166 SetDictInt("ACS_SSBB", (ACS_LLCORNER));
2167 SetDictInt("ACS_BBSS", (ACS_URCORNER));
2168 SetDictInt("ACS_SBBS", (ACS_LRCORNER));
2169 SetDictInt("ACS_SBSS", (ACS_RTEE));
2170 SetDictInt("ACS_SSSB", (ACS_LTEE));
2171 SetDictInt("ACS_SSBS", (ACS_BTEE));
2172 SetDictInt("ACS_BSSS", (ACS_TTEE));
2173 SetDictInt("ACS_BSBS", (ACS_HLINE));
2174 SetDictInt("ACS_SBSB", (ACS_VLINE));
2175 SetDictInt("ACS_SSSS", (ACS_PLUS));
2176#endif
2177
2178 SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
2179 SetDictInt("A_NORMAL", A_NORMAL);
2180 SetDictInt("A_STANDOUT", A_STANDOUT);
2181 SetDictInt("A_UNDERLINE", A_UNDERLINE);
2182 SetDictInt("A_REVERSE", A_REVERSE);
2183 SetDictInt("A_BLINK", A_BLINK);
2184 SetDictInt("A_DIM", A_DIM);
2185 SetDictInt("A_BOLD", A_BOLD);
2186 SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
2187 SetDictInt("A_INVIS", A_INVIS);
2188 SetDictInt("A_PROTECT", A_PROTECT);
2189#ifndef __sgi__
2190 SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
2191 SetDictInt("A_LEFT", A_LEFT);
2192 SetDictInt("A_LOW", A_LOW);
2193 SetDictInt("A_RIGHT", A_RIGHT);
2194 SetDictInt("A_TOP", A_TOP);
2195 SetDictInt("A_VERTICAL", A_VERTICAL);
2196#endif
2197 SetDictInt("A_CHARTEXT", A_CHARTEXT);
2198 SetDictInt("A_COLOR", A_COLOR);
2199#ifndef __sgi__
2200 SetDictInt("WA_ATTRIBUTES", WA_ATTRIBUTES);
2201 SetDictInt("WA_NORMAL", WA_NORMAL);
2202 SetDictInt("WA_STANDOUT", WA_STANDOUT);
2203 SetDictInt("WA_UNDERLINE", WA_UNDERLINE);
2204 SetDictInt("WA_REVERSE", WA_REVERSE);
2205 SetDictInt("WA_BLINK", WA_BLINK);
2206 SetDictInt("WA_DIM", WA_DIM);
2207 SetDictInt("WA_BOLD", WA_BOLD);
2208 SetDictInt("WA_ALTCHARSET", WA_ALTCHARSET);
2209 SetDictInt("WA_INVIS", WA_INVIS);
2210 SetDictInt("WA_PROTECT", WA_PROTECT);
2211 SetDictInt("WA_HORIZONTAL", WA_HORIZONTAL);
2212 SetDictInt("WA_LEFT", WA_LEFT);
2213 SetDictInt("WA_LOW", WA_LOW);
2214 SetDictInt("WA_RIGHT", WA_RIGHT);
2215 SetDictInt("WA_TOP", WA_TOP);
2216 SetDictInt("WA_VERTICAL", WA_VERTICAL);
2217#endif
2218 SetDictInt("COLOR_BLACK", COLOR_BLACK);
2219 SetDictInt("COLOR_RED", COLOR_RED);
2220 SetDictInt("COLOR_GREEN", COLOR_GREEN);
2221 SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
2222 SetDictInt("COLOR_BLUE", COLOR_BLUE);
2223 SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
2224 SetDictInt("COLOR_CYAN", COLOR_CYAN);
2225 SetDictInt("COLOR_WHITE", COLOR_WHITE);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002226
2227 /* Now set everything up for KEY_ variables */
2228 {
2229 int key;
2230 char *key_n;
2231 char *key_n2;
2232 for (key=KEY_MIN;key < KEY_MAX; key++) {
2233 key_n = (char *)keyname(key);
Guido van Rossumf5c6d471995-02-07 15:38:32 +00002234 if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002235 continue;
2236 if (strncmp(key_n,"KEY_F(",6)==0) {
2237 char *p1, *p2;
2238 key_n2 = malloc(strlen(key_n)+1);
2239 p1 = key_n;
2240 p2 = key_n2;
2241 while (*p1) {
2242 if (*p1 != '(' && *p1 != ')') {
2243 *p2 = *p1;
2244 p2++;
2245 }
2246 p1++;
2247 }
2248 *p2 = (char)0;
2249 } else
2250 key_n2 = key_n;
Guido van Rossum85738471995-02-17 13:50:17 +00002251 PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
Guido van Rossumf6971e21994-08-30 12:25:20 +00002252 if (key_n2 != key_n)
2253 free(key_n2);
2254 }
Guido van Rossum85738471995-02-17 13:50:17 +00002255 SetDictInt("KEY_MIN", KEY_MIN);
2256 SetDictInt("KEY_MAX", KEY_MAX);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002257 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002258
2259 /* Check for errors */
2260 if (PyErr_Occurred())
2261 Py_FatalError("can't initialize module curses");
Guido van Rossumf6971e21994-08-30 12:25:20 +00002262}
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002263
2264