blob: 1920ee0e8bc883011e4d7b0a22e7761cfe6c4a75 [file] [log] [blame]
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001/*
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002 * This is a curses module for Python.
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00003 *
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00004 * Based on prior work by Lance Ellinghaus and Oliver Andrich
5 * Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse,
6 * Cathedral City, California Republic, United States of America.
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00007 *
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00008 * Version 1.5b1, heavily extended for ncurses by Oliver Andrich:
9 * Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany.
10 *
11 * Tidied for Python 1.6, and currently maintained by AMK (amk1@bigfoot.com)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000012 *
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. Kuchlingfb6bbf52000-07-27 11:58:01 +000036/*
37
38A number of SysV or ncurses functions don't have wrappers yet; if you need
39a given function, add it and send a patch. Here's a list of currently
40unsupported functions:
41
42 addchnstr addchstr chgat color_set copywin define_key
43 del_curterm delscreen dupwin inchnstr inchstr innstr keyok
44 mcprint mvaddchnstr mvaddchstr mvchgat mvcur mvinchnstr
45 mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
46 mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr napms newterm
47 overlay overwrite resetty resizeterm restartterm ripoffline
48 savetty scr_dump scr_init scr_restore scr_set scrl set_curterm
49 set_term setterm setupterm tgetent tgetflag tgetnum tgetstr
50 tgoto timeout tparm tputs tputs typeahead use_default_colors
51 vidattr vidputs waddchnstr waddchstr wchgat wcolor_set
52 winchnstr winchstr winnstr wmouse_trafo wredrawln wscrl
53 wtimeout
54
55Low-priority:
56 slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
57 slk_attron slk_attrset slk_clear slk_color slk_init slk_label
58 slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
59
60 */
61
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000062/* Release Number */
Guido van Rossumf6971e21994-08-30 12:25:20 +000063
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +000064char *PyCursesVersion = "1.6";
Guido van Rossumf6971e21994-08-30 12:25:20 +000065
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000066/* Includes */
Guido van Rossumf6971e21994-08-30 12:25:20 +000067
Guido van Rossum602099a1994-09-14 13:32:22 +000068#include "Python.h"
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000069
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +000070#ifdef __osf__
71#define _XOPEN_SOURCE_EXTENDED /* Define macro for OSF/1 */
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +000072#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +000073#endif
74
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +000075#ifdef HAVE_NCURSES_H
76#include <ncurses.h>
77#else
78#include <curses.h>
79#endif
80
81#if defined(__sgi__) || defined(__sun__)
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +000082#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +000083typedef chtype attr_t; /* No attr_t type is available */
Guido van Rossum1266a011996-02-25 04:50:31 +000084#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +000085
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000086/* Definition of exception curses.error */
Guido van Rossumf6971e21994-08-30 12:25:20 +000087
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000088static PyObject *PyCursesError;
Guido van Rossumf6971e21994-08-30 12:25:20 +000089
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000090/* general error messages */
Guido van Rossum85738471995-02-17 13:50:17 +000091static char *catchall_ERR = "curses function returned ERR";
92static char *catchall_NULL = "curses function returned NULL";
93
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000094/* Tells whether initscr() has been called to initialise curses. */
Guido van Rossum585c6dc1995-02-24 13:45:43 +000095static int initialised = FALSE;
96
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000097/* Tells whether start_color() has been called to initialise colorusage. */
98static int initialisedcolors = FALSE;
99
100/* Utility Macros */
Guido van Rossum85738471995-02-17 13:50:17 +0000101#define ARG_COUNT(X) \
102 (((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
Guido van Rossumf6971e21994-08-30 12:25:20 +0000103
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000104#define PyCursesInitialised \
105 if (initialised != TRUE) { \
106 PyErr_SetString(PyCursesError, \
107 "must call initscr() first"); \
108 return NULL; }
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000109
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000110#define PyCursesInitialisedColor \
111 if (initialisedcolors != TRUE) { \
112 PyErr_SetString(PyCursesError, \
113 "must call start_color() first"); \
114 return NULL; }
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000115
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000116/* Utility Functions */
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000117
Guido van Rossum85738471995-02-17 13:50:17 +0000118/*
119 * Check the return code from a curses function and return None
120 * or raise an exception as appropriate.
121 */
122
123static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000124PyCursesCheckERR(int code, char *fname)
Guido van Rossum85738471995-02-17 13:50:17 +0000125{
Guido van Rossum85738471995-02-17 13:50:17 +0000126 if (code != ERR) {
127 Py_INCREF(Py_None);
128 return Py_None;
129 } else {
130 if (fname == NULL) {
131 PyErr_SetString(PyCursesError, catchall_ERR);
132 } else {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000133 PyErr_Format(PyCursesError, "%s() returned ERR", fname);
Guido van Rossum85738471995-02-17 13:50:17 +0000134 }
135 return NULL;
136 }
137}
138
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000139static int
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000140PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000141{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000142 if (PyInt_Check(obj)) {
143 *ch = (chtype) PyInt_AsLong(obj);
144 } else if(PyString_Check(obj) &
145 (PyString_Size(obj) == 1)) {
146 *ch = (chtype) *PyString_AsString(obj);
147 } else {
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000148 return 0;
149 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000150 return 1;
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000151}
152
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000153/*****************************************************************************
154 The Window Object
155******************************************************************************/
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000156
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000157/* Definition of the window object and window type */
Guido van Rossum85738471995-02-17 13:50:17 +0000158
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000159typedef struct {
160 PyObject_HEAD
161 WINDOW *win;
162} PyCursesWindowObject;
Guido van Rossum85738471995-02-17 13:50:17 +0000163
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000164PyTypeObject PyCursesWindow_Type;
165
166#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
167
168/* Function Prototype Macros - They are ugly but very, very useful. ;-)
169
170 X - function name
171 TYPE - parameter Type
172 ERGSTR - format string for construction of the return value
173 PARSESTR - format string for argument parsing
174 */
175
176#define Window_NoArgNoReturnFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000177static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
178{ if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000179 return PyCursesCheckERR(X(self->win), # X); }
180
181#define Window_NoArgTrueFalseFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000182static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000183{ \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000184 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000185 if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
186 else { Py_INCREF(Py_True); return Py_True; } }
187
188#define Window_NoArgNoReturnVoidFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000189static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000190{ \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000191 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000192 X(self->win); Py_INCREF(Py_None); return Py_None; }
193
194#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000195static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000196{ \
197 TYPE arg1, arg2; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000198 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000199 X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
200
201#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000202static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000203{ \
204 TYPE arg1; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000205 if (!PyArg_Parse(args, PARSESTR, &arg1)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000206 X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
207
208#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000209static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000210{ \
211 TYPE arg1; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000212 if (!PyArg_Parse(args,PARSESTR, &arg1)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000213 return PyCursesCheckERR(X(self->win, arg1), # X); }
214
215#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000216static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000217{ \
218 TYPE arg1, arg2; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000219 if (!PyArg_Parse(args,PARSESTR, &arg1, &arg2)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000220 return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
Guido van Rossum85738471995-02-17 13:50:17 +0000221
Guido van Rossumf6971e21994-08-30 12:25:20 +0000222/* ------------- WINDOW routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000223
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000224Window_NoArgNoReturnFunction(untouchwin)
225Window_NoArgNoReturnFunction(touchwin)
226Window_NoArgNoReturnFunction(redrawwin)
227Window_NoArgNoReturnFunction(winsertln)
228Window_NoArgNoReturnFunction(werase)
229Window_NoArgNoReturnFunction(wdeleteln)
230
231Window_NoArgTrueFalseFunction(is_wintouched)
232
233Window_NoArgNoReturnVoidFunction(wsyncup)
234Window_NoArgNoReturnVoidFunction(wsyncdown)
235Window_NoArgNoReturnVoidFunction(wstandend)
236Window_NoArgNoReturnVoidFunction(wstandout)
237Window_NoArgNoReturnVoidFunction(wcursyncup)
238Window_NoArgNoReturnVoidFunction(wclrtoeol)
239Window_NoArgNoReturnVoidFunction(wclrtobot)
240Window_NoArgNoReturnVoidFunction(wclear)
241
242Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")
243Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +0000244Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay")
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000245
246Window_NoArg2TupleReturnFunction(getyx, int, "(ii)")
247Window_NoArg2TupleReturnFunction(getbegyx, int, "(ii)")
248Window_NoArg2TupleReturnFunction(getmaxyx, int, "(ii)")
249Window_NoArg2TupleReturnFunction(getparyx, int, "(ii)")
250
251Window_OneArgNoReturnFunction(wattron, attr_t, "l;attr")
252Window_OneArgNoReturnFunction(wattroff, attr_t, "l;attr")
253Window_OneArgNoReturnFunction(wattrset, attr_t, "l;attr")
254Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
255Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
256Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")
257Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")
258Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
259Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")
260Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000261Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines")
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000262Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
263
264Window_TwoArgNoReturnFunction(mvwin, int, "(ii);y,x")
265Window_TwoArgNoReturnFunction(mvderwin, int, "(ii);y,x")
266Window_TwoArgNoReturnFunction(wmove, int, "(ii);y,x")
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000267#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000268Window_TwoArgNoReturnFunction(wresize, int, "(ii);lines,columns")
269#endif
270
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000271/* Allocation and deallocation of Window Objects */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000272
Guido van Rossumf6971e21994-08-30 12:25:20 +0000273static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000274PyCursesWindow_New(WINDOW *win)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000275{
276 PyCursesWindowObject *wo;
Guido van Rossum85738471995-02-17 13:50:17 +0000277
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000278 wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
279 if (wo == NULL) return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000280 wo->win = win;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000281 return (PyObject *)wo;
282}
283
284static void
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000285PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000286{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000287 if (wo->win != stdscr) delwin(wo->win);
288 PyMem_DEL(wo);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000289}
290
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000291/* Addch, Addstr, Addnstr */
Guido van Rossumf6971e21994-08-30 12:25:20 +0000292
293static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000294PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000295{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000296 int rtn, x, y, use_xy = FALSE;
297 PyObject *temp;
298 chtype ch = 0;
299 attr_t attr = A_NORMAL;
300
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000301 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000302 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000303 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000304 return NULL;
305 break;
306 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000307 if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr))
Guido van Rossum85738471995-02-17 13:50:17 +0000308 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000309 break;
310 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000311 if (!PyArg_Parse(args,"(iiO);y,x,ch or int", &y, &x, &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000312 return NULL;
313 use_xy = TRUE;
314 break;
315 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000316 if (!PyArg_Parse(args,"(iiOl);y,x,ch or int, attr",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000317 &y, &x, &temp, &attr))
318 return NULL;
319 use_xy = TRUE;
320 break;
321 default:
322 PyErr_SetString(PyExc_TypeError, "addch requires 1 or 4 arguments");
323 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000324 }
Guido van Rossum85738471995-02-17 13:50:17 +0000325
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000326 if (!PyCurses_ConvertToChtype(temp, &ch)) {
327 PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
328 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000329 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000330
Guido van Rossumf6971e21994-08-30 12:25:20 +0000331 if (use_xy == TRUE)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000332 rtn = mvwaddch(self->win,y,x, ch | attr);
333 else {
334 rtn = waddch(self->win, ch | attr);
335 }
336 return PyCursesCheckERR(rtn, "addch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000337}
338
339static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000340PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000341{
342 int rtn;
343 int x, y;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000344 char *str;
345 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
346 int use_xy = FALSE, use_attr = FALSE;
Guido van Rossum85738471995-02-17 13:50:17 +0000347
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000348 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000349 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000350 if (!PyArg_Parse(args,"s;str", &str))
Guido van Rossum85738471995-02-17 13:50:17 +0000351 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000352 break;
353 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000354 if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000355 return NULL;
356 use_attr = TRUE;
357 break;
358 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000359 if (!PyArg_Parse(args,"(iis);int,int,str", &y, &x, &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000360 return NULL;
361 use_xy = TRUE;
362 break;
363 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000364 if (!PyArg_Parse(args,"(iisl);int,int,str,attr", &y, &x, &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000365 return NULL;
366 use_xy = use_attr = TRUE;
367 break;
368 default:
369 PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
370 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000371 }
Guido van Rossum85738471995-02-17 13:50:17 +0000372
Guido van Rossumf6971e21994-08-30 12:25:20 +0000373 if (use_attr == TRUE) {
374 attr_old = getattrs(self->win);
375 wattrset(self->win,attr);
376 }
377 if (use_xy == TRUE)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000378 rtn = mvwaddstr(self->win,y,x,str);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000379 else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000380 rtn = waddstr(self->win,str);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000381 if (use_attr == TRUE)
382 wattrset(self->win,attr_old);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000383 return PyCursesCheckERR(rtn, "addstr");
384}
Guido van Rossum85738471995-02-17 13:50:17 +0000385
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000386static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000387PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000388{
389 int rtn, x, y, n;
390 char *str;
391 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
392 int use_xy = FALSE, use_attr = FALSE;
393
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000394 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000395 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000396 if (!PyArg_Parse(args,"(si);str,n", &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000397 return NULL;
398 break;
399 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000400 if (!PyArg_Parse(args,"(sil);str,n,attr", &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000401 return NULL;
402 use_attr = TRUE;
403 break;
404 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000405 if (!PyArg_Parse(args,"(iisi);y,x,str,n", &y, &x, &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000406 return NULL;
407 use_xy = TRUE;
408 break;
409 case 5:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000410 if (!PyArg_Parse(args,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000411 return NULL;
412 use_xy = use_attr = TRUE;
413 break;
414 default:
415 PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
416 return NULL;
417 }
418
419 if (use_attr == TRUE) {
420 attr_old = getattrs(self->win);
421 wattrset(self->win,attr);
422 }
423 if (use_xy == TRUE)
424 rtn = mvwaddnstr(self->win,y,x,str,n);
425 else
426 rtn = waddnstr(self->win,str,n);
427 if (use_attr == TRUE)
428 wattrset(self->win,attr_old);
429 return PyCursesCheckERR(rtn, "addnstr");
430}
431
432static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000433PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000434{
435 PyObject *temp;
436 chtype bkgd;
437 attr_t attr = A_NORMAL;
438
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000439 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000440 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000441 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000442 return NULL;
443 break;
444 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000445 if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000446 return NULL;
447 break;
448 default:
449 PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
450 return NULL;
451 }
452
453 if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
454 PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
455 return NULL;
456 }
457
458 return PyCursesCheckERR(wbkgd(self->win, bkgd | A_NORMAL), "bkgd");
459}
460
461static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000462PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000463{
464 PyObject *temp;
465 chtype bkgd;
466 attr_t attr = A_NORMAL;
467
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000468 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000469 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000470 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000471 return NULL;
472 break;
473 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000474 if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000475 return NULL;
476 break;
477 default:
478 PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
479 return NULL;
480 }
481
482 if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000483 PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000484 return NULL;
485 }
486
487 wbkgdset(self->win, bkgd | attr);
488 return PyCursesCheckERR(0, "bkgdset");
489}
490
491static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000492PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000493{
494 chtype ls, rs, ts, bs, tl, tr, bl, br;
495 ls = rs = ts = bs = tl = tr = bl = br = 0;
496 if (!PyArg_Parse(args,"|llllllll;ls,rs,ts,bs,tl,tr,bl,br",
497 &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br))
498 return NULL;
499 wborder(self->win, ls, rs, ts, bs, tl, tr, bl, br);
500 Py_INCREF(Py_None);
501 return Py_None;
502}
503
504static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000505PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000506{
507 chtype ch1=0,ch2=0;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000508 if (!PyArg_NoArgs(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000509 PyErr_Clear();
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000510 if (!PyArg_Parse(args,"(ll);vertint,horint", &ch1, &ch2))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000511 return NULL;
512 }
513 box(self->win,ch1,ch2);
514 Py_INCREF(Py_None);
515 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000516}
517
518static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000519PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000520{
521 int rtn;
522 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000523
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000524 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000525 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000526 rtn = wdelch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000527 break;
528 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000529 if (!PyArg_Parse(args,"(ii);y,x", &y, &x))
Guido van Rossum85738471995-02-17 13:50:17 +0000530 return NULL;
531 rtn = mvwdelch(self->win,y,x);
532 break;
533 default:
534 PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
535 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000536 }
Guido van Rossum85738471995-02-17 13:50:17 +0000537 return PyCursesCheckERR(rtn, "[mv]wdelch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000538}
539
540static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000541PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000542{
543 WINDOW *win;
544 int nlines, ncols, begin_y, begin_x;
545
546 nlines = 0;
547 ncols = 0;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000548 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000549 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000550 if (!PyArg_Parse(args,"(ii);begin_y,begin_x",&begin_y,&begin_x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000551 return NULL;
552 break;
553 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000554 if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000555 &nlines,&ncols,&begin_y,&begin_x))
556 return NULL;
557 break;
558 default:
559 PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
560 return NULL;
561 }
562
563 win = derwin(self->win,nlines,ncols,begin_y,begin_x);
564
565 if (win == NULL) {
566 PyErr_SetString(PyCursesError, catchall_NULL);
567 return NULL;
568 }
569
570 return (PyObject *)PyCursesWindow_New(win);
571}
572
573static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000574PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000575{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000576 PyObject *temp;
577 chtype ch;
578 attr_t attr = A_NORMAL;
Guido van Rossum85738471995-02-17 13:50:17 +0000579
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000580 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000581 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000582 if (!PyArg_Parse(args,"O;ch or int", &temp))
Guido van Rossum85738471995-02-17 13:50:17 +0000583 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +0000584 break;
585 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000586 if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
Guido van Rossum85738471995-02-17 13:50:17 +0000587 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +0000588 break;
589 default:
590 PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000591
592
Guido van Rossum85738471995-02-17 13:50:17 +0000593 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000594 }
Guido van Rossum85738471995-02-17 13:50:17 +0000595
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000596 if (!PyCurses_ConvertToChtype(temp, &ch)) {
597 PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
Guido van Rossum85738471995-02-17 13:50:17 +0000598 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000599 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000600
601 if (self->win->_flags & _ISPAD)
602 return PyCursesCheckERR(pechochar(self->win, ch | attr),
603 "echochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000604 else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000605 return PyCursesCheckERR(wechochar(self->win, ch | attr),
606 "echochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000607}
608
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000609#ifdef NCURSES_MOUSE_VERSION
610static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000611PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000612{
613 int x, y;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000614 if (!PyArg_Parse(args,"(ii);y,x", &y, &x))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000615 return NULL;
616
617 return PyInt_FromLong( wenclose(self->win,y,x) );
618}
619#endif
620
Guido van Rossumf6971e21994-08-30 12:25:20 +0000621static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000622PyCursesWindow_GetBkgd(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000623{
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000624 if (!PyArg_NoArgs(args))
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000625 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000626 return PyInt_FromLong((long) getbkgd(self->win));
Guido van Rossumf6971e21994-08-30 12:25:20 +0000627}
628
629static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000630PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000631{
632 int x, y;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000633 chtype rtn;
Guido van Rossum85738471995-02-17 13:50:17 +0000634
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000635 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000636 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000637 Py_BEGIN_ALLOW_THREADS
Guido van Rossumf6971e21994-08-30 12:25:20 +0000638 rtn = wgetch(self->win);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000639 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000640 break;
641 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000642 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000643 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000644 Py_BEGIN_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000645 rtn = mvwgetch(self->win,y,x);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000646 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000647 break;
648 default:
649 PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
650 return NULL;
651 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000652 return PyInt_FromLong(rtn);
653}
Guido van Rossum85738471995-02-17 13:50:17 +0000654
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000655static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000656PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000657{
658 int x, y;
659 chtype rtn;
660
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000661 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000662 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000663 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000664 rtn = wgetch(self->win);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000665 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000666 break;
667 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000668 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000669 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000670 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000671 rtn = mvwgetch(self->win,y,x);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000672 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000673 break;
674 default:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000675 PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000676 return NULL;
677 }
678 if (rtn<=255)
679 return Py_BuildValue("c", rtn);
680 else
681 return PyString_FromString((char *)keyname(rtn));
Guido van Rossumf6971e21994-08-30 12:25:20 +0000682}
683
684static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000685PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000686{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000687 int x, y, n;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000688 char rtn[1024]; /* This should be big enough.. I hope */
689 int rtn2;
Guido van Rossum85738471995-02-17 13:50:17 +0000690
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000691 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000692 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000693 Py_BEGIN_ALLOW_THREADS
Guido van Rossumf6971e21994-08-30 12:25:20 +0000694 rtn2 = wgetstr(self->win,rtn);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000695 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000696 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000697 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000698 if (!PyArg_Parse(args,"i;n", &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000699 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000700 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000701 rtn2 = wgetnstr(self->win,rtn,n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000702 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000703 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000704 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000705 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000706 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000707 Py_BEGIN_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000708 rtn2 = mvwgetstr(self->win,y,x,rtn);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000709 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000710 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000711 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000712 if (!PyArg_Parse(args,"(iii);y,x,n", &y, &x, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000713 return NULL;
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000714#ifdef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000715 /* Untested */
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000716 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000717 rtn2 = wmove(self->win,y,x)==ERR ? ERR :
718 wgetnstr(self->win, rtn, n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000719 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000720#else
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000721 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000722 rtn2 = mvwgetnstr(self->win, y, x, rtn, n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000723 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000724#endif
725 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000726 default:
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000727 PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 2 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000728 return NULL;
729 }
Guido van Rossumf6971e21994-08-30 12:25:20 +0000730 if (rtn2 == ERR)
731 rtn[0] = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000732 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000733}
734
735static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000736PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000737{
738 PyObject *temp;
739 chtype ch;
740 int n, x, y, code = OK;
741 attr_t attr = A_NORMAL;
742
743 switch (ARG_COUNT(args)) {
744 case 2:
745 if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n))
746 return NULL;
747 break;
748 case 3:
749 if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr))
750 return NULL;
751 break;
752 case 4:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000753 if (!PyArg_Parse(args, "(iiOi);y,x,ch or int,n", &y, &x, &temp, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000754 return NULL;
755 code = wmove(self->win, y, x);
756 break;
757 case 5:
758 if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr",
759 &y, &x, &temp, &n, &attr))
760 return NULL;
761 code = wmove(self->win, y, x);
762 default:
763 PyErr_SetString(PyExc_TypeError, "hline requires 2 or 5 arguments");
764 return NULL;
765 }
766
767 if (code != ERR) {
768 if (!PyCurses_ConvertToChtype(temp, &ch)) {
769 PyErr_SetString(PyExc_TypeError,
770 "argument 1 or 3 must be a ch or an int");
771 return NULL;
772 }
773 return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
774 } else
775 return PyCursesCheckERR(code, "wmove");
776}
777
778static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000779PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000780{
781 int rtn, x, y, use_xy = FALSE;
782 PyObject *temp;
783 chtype ch = 0;
784 attr_t attr = A_NORMAL;
785
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000786 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000787 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000788 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000789 return NULL;
790 break;
791 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000792 if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000793 return NULL;
794 break;
795 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000796 if (!PyArg_Parse(args,"(iiO);y,x,ch or int", &y, &x, &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000797 return NULL;
798 use_xy = TRUE;
799 break;
800 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000801 if (!PyArg_Parse(args,"(iiOl);y,x,ch or int, attr", &y, &x, &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000802 return NULL;
803 use_xy = TRUE;
804 break;
805 default:
806 PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
807 return NULL;
808 }
809
810 if (!PyCurses_ConvertToChtype(temp, &ch)) {
811 PyErr_SetString(PyExc_TypeError,
812 "argument 1 or 3 must be a ch or an int");
813 return NULL;
814 }
815
816 if (use_xy == TRUE)
817 rtn = mvwinsch(self->win,y,x, ch | attr);
818 else {
819 rtn = winsch(self->win, ch | attr);
820 }
821 return PyCursesCheckERR(rtn, "insch");
822}
823
824static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000825PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000826{
Guido van Rossum85738471995-02-17 13:50:17 +0000827 int x, y, rtn;
828
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000829 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000830 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000831 rtn = winch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000832 break;
833 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000834 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000835 return NULL;
836 rtn = mvwinch(self->win,y,x);
837 break;
838 default:
839 PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
840 return NULL;
841 }
Guido van Rossum85738471995-02-17 13:50:17 +0000842 return PyInt_FromLong((long) rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000843}
844
845static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000846PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000847{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000848 int x, y, n;
849 char rtn[1024]; /* This should be big enough.. I hope */
850 int rtn2;
851
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000852 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000853 case 0:
854 rtn2 = winstr(self->win,rtn);
855 break;
856 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000857 if (!PyArg_Parse(args,"i;n", &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000858 return NULL;
859 rtn2 = winnstr(self->win,rtn,n);
860 break;
861 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000862 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000863 return NULL;
864 rtn2 = mvwinstr(self->win,y,x,rtn);
865 break;
866 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000867 if (!PyArg_Parse(args, "(iii);y,x,n", &y, &x, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000868 return NULL;
869 rtn2 = mvwinnstr(self->win, y, x, rtn, n);
870 break;
871 default:
872 PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000873 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000874 }
875 if (rtn2 == ERR)
876 rtn[0] = 0;
877 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000878}
879
880static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000881PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000882{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000883 int rtn;
884 int x, y;
885 char *str;
886 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
887 int use_xy = FALSE, use_attr = FALSE;
888
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000889 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000890 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000891 if (!PyArg_Parse(args,"s;str", &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000892 return NULL;
893 break;
894 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000895 if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000896 return NULL;
897 use_attr = TRUE;
898 break;
899 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000900 if (!PyArg_Parse(args,"(iis);y,x,str", &y, &x, &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000901 return NULL;
902 use_xy = TRUE;
903 break;
904 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000905 if (!PyArg_Parse(args,"(iisl);y,x,str,attr", &y, &x, &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000906 return NULL;
907 use_xy = use_attr = TRUE;
908 break;
909 default:
910 PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000911 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000912 }
913
914 if (use_attr == TRUE) {
915 attr_old = getattrs(self->win);
916 wattrset(self->win,attr);
917 }
918 if (use_xy == TRUE)
919 rtn = mvwinsstr(self->win,y,x,str);
920 else
921 rtn = winsstr(self->win,str);
922 if (use_attr == TRUE)
923 wattrset(self->win,attr_old);
924 return PyCursesCheckERR(rtn, "insstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000925}
926
927static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000928PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000929{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000930 int rtn, x, y, n;
931 char *str;
932 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
933 int use_xy = FALSE, use_attr = FALSE;
934
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000935 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000936 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000937 if (!PyArg_Parse(args,"(si);str,n", &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000938 return NULL;
939 break;
940 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000941 if (!PyArg_Parse(args,"(sil);str,n,attr", &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000942 return NULL;
943 use_attr = TRUE;
944 break;
945 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000946 if (!PyArg_Parse(args,"(iisi);y,x,str,n", &y, &x, &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000947 return NULL;
948 use_xy = TRUE;
949 break;
950 case 5:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000951 if (!PyArg_Parse(args,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000952 return NULL;
953 use_xy = use_attr = TRUE;
954 break;
955 default:
956 PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000957 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000958 }
959
960 if (use_attr == TRUE) {
961 attr_old = getattrs(self->win);
962 wattrset(self->win,attr);
963 }
964 if (use_xy == TRUE)
965 rtn = mvwinsnstr(self->win,y,x,str,n);
966 else
967 rtn = winsnstr(self->win,str,n);
968 if (use_attr == TRUE)
969 wattrset(self->win,attr_old);
970 return PyCursesCheckERR(rtn, "insnstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000971}
972
973static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000974PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000975{
976 int line, erg;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000977 if (!PyArg_Parse(args,"i;line", &line))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000978 return NULL;
979 erg = is_linetouched(self->win, line);
980 if (erg == ERR) {
981 PyErr_SetString(PyExc_TypeError,
982 "is_linetouched: line number outside of boundaries");
983 return NULL;
984 } else
985 if (erg == FALSE) {
986 Py_INCREF(Py_False);
987 return Py_False;
988 } else {
989 Py_INCREF(Py_True);
990 return Py_True;
991 }
992}
993
994static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000995PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000996{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000997 int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000998 int rtn;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000999
1000 if (self->win->_flags & _ISPAD) {
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001001 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001002 case 6:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001003 if (!PyArg_Parse(args,
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001004 "(iiiiii);" \
1005 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1006 &pminrow, &pmincol, &sminrow,
1007 &smincol, &smaxrow, &smaxcol))
1008 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001009 Py_BEGIN_ALLOW_THREADS
1010 rtn = pnoutrefresh(self->win,
1011 pminrow, pmincol, sminrow,
Andrew M. Kuchlingb6e46872000-06-27 15:01:10 +00001012 smincol, smaxrow, smaxcol);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001013 Py_END_ALLOW_THREADS
1014 return PyCursesCheckERR(rtn, "pnoutrefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001015 default:
1016 PyErr_SetString(PyCursesError,
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001017 "noutrefresh() called for a pad "
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001018 "requires 6 arguments");
1019 return NULL;
1020 }
1021 } else {
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001022 if (!PyArg_NoArgs(args))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001023 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001024
1025 Py_BEGIN_ALLOW_THREADS
1026 rtn = wnoutrefresh(self->win);
1027 Py_END_ALLOW_THREADS
1028 return PyCursesCheckERR(rtn, "wnoutrefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001029 }
1030}
1031
1032static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001033PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001034{
1035 PyObject *temp;
1036
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001037 if (!PyArg_Parse(args, "O;fileobj", &temp))
Guido van Rossum85738471995-02-17 13:50:17 +00001038 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001039 if (!PyFile_Check(temp)) {
1040 PyErr_SetString(PyExc_TypeError, "argument must be a file object");
1041 return NULL;
1042 }
1043 return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)),
1044 "putwin");
1045}
1046
1047static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001048PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001049{
1050 int beg, num;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001051 if (!PyArg_Parse(args,"(ii);beg,num", &beg, &num))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001052 return NULL;
1053 return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
1054}
1055
1056static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001057PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001058{
1059 int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001060 int rtn;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001061
1062 if (self->win->_flags & _ISPAD) {
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001063 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001064 case 6:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001065 if (!PyArg_Parse(args,
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001066 "(iiiiii);" \
1067 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1068 &pminrow, &pmincol, &sminrow,
1069 &smincol, &smaxrow, &smaxcol))
1070 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001071
1072 Py_BEGIN_ALLOW_THREADS
1073 rtn = prefresh(self->win,
1074 pminrow, pmincol, sminrow,
Andrew M. Kuchlingb6e46872000-06-27 15:01:10 +00001075 smincol, smaxrow, smaxcol);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001076 Py_END_ALLOW_THREADS
1077 return PyCursesCheckERR(rtn, "prefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001078 default:
1079 PyErr_SetString(PyCursesError,
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001080 "refresh() for a pad requires 6 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001081 return NULL;
1082 }
1083 } else {
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001084 if (!PyArg_NoArgs(args))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001085 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001086 Py_BEGIN_ALLOW_THREADS
1087 rtn = wrefresh(self->win);
1088 Py_END_ALLOW_THREADS
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001089 return PyCursesCheckERR(rtn, "prefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001090 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001091}
1092
1093static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001094PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001095{
1096 int x, y;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001097 if (!PyArg_Parse(args,"(ii);top, bottom",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +00001098 return NULL;
1099 return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001100}
1101
1102static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001103PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001104{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001105 WINDOW *win;
1106 int nlines, ncols, begin_y, begin_x;
1107
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001108 nlines = 0;
1109 ncols = 0;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001110 switch (ARG_COUNT(args)) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001111 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001112 if (!PyArg_Parse(args,"(ii);begin_y,begin_x",&begin_y,&begin_x))
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001113 return NULL;
1114 break;
1115 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001116 if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001117 &nlines,&ncols,&begin_y,&begin_x))
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001118 return NULL;
1119 break;
1120 default:
1121 PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001122 return NULL;
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001123 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001124
Andrew M. Kuchling8353f622000-07-26 18:36:27 +00001125 /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001126 if (self->win->_flags & _ISPAD)
1127 win = subpad(self->win, nlines, ncols, begin_y, begin_x);
1128 else
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001129 win = subwin(self->win, nlines, ncols, begin_y, begin_x);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001130
1131 if (win == NULL) {
1132 PyErr_SetString(PyCursesError, catchall_NULL);
1133 return NULL;
1134 }
1135
1136 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001137}
1138
1139static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001140PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001141{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001142 int lines;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001143 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001144 case 0:
1145 return PyCursesCheckERR(scroll(self->win), "scroll");
1146 break;
1147 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001148 if (!PyArg_Parse(args, "i;lines", &lines))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001149 return NULL;
1150 return PyCursesCheckERR(wscrl(self->win, lines), "scroll");
1151 default:
1152 PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001153 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001154 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001155}
1156
1157static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001158PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001159{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001160 int st, cnt, val;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001161 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001162 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001163 if (!PyArg_Parse(args,"(ii);start,count",&st,&cnt))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001164 return NULL;
1165 return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
1166 break;
1167 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001168 if (!PyArg_Parse(args, "(iii);start,count,val", &st, &cnt, &val))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001169 return NULL;
1170 return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
1171 default:
1172 PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001173 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001174 }
1175}
1176
1177static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001178PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001179{
1180 PyObject *temp;
1181 chtype ch;
1182 int n, x, y, code = OK;
1183 attr_t attr = A_NORMAL;
1184
1185 switch (ARG_COUNT(args)) {
1186 case 2:
1187 if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n))
1188 return NULL;
1189 break;
1190 case 3:
1191 if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr))
1192 return NULL;
1193 break;
1194 case 4:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001195 if (!PyArg_Parse(args, "(iiOi);y,x,ch or int,n", &y, &x, &temp, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001196 return NULL;
1197 code = wmove(self->win, y, x);
1198 break;
1199 case 5:
1200 if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr",
1201 &y, &x, &temp, &n, &attr))
1202 return NULL;
1203 code = wmove(self->win, y, x);
1204 default:
1205 PyErr_SetString(PyExc_TypeError, "vline requires 2 or 5 arguments");
1206 return NULL;
1207 }
1208
1209 if (code != ERR) {
1210 if (!PyCurses_ConvertToChtype(temp, &ch)) {
1211 PyErr_SetString(PyExc_TypeError,
1212 "argument 1 or 3 must be a ch or an int");
1213 return NULL;
1214 }
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001215 return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001216 } else
1217 return PyCursesCheckERR(code, "wmove");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001218}
1219
1220static PyMethodDef PyCursesWindow_Methods[] = {
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001221 {"addch", (PyCFunction)PyCursesWindow_AddCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001222 {"addnstr", (PyCFunction)PyCursesWindow_AddNStr},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001223 {"addstr", (PyCFunction)PyCursesWindow_AddStr},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001224 {"attroff", (PyCFunction)PyCursesWindow_wattroff},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001225 {"attron", (PyCFunction)PyCursesWindow_wattron},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001226 {"attrset", (PyCFunction)PyCursesWindow_wattrset},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001227 {"bkgd", (PyCFunction)PyCursesWindow_Bkgd},
1228 {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001229 {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
1230 {"box", (PyCFunction)PyCursesWindow_Box},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001231 {"clear", (PyCFunction)PyCursesWindow_wclear},
1232 {"clearok", (PyCFunction)PyCursesWindow_clearok},
1233 {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot},
1234 {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol},
1235 {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup},
1236 {"delch", (PyCFunction)PyCursesWindow_DelCh},
1237 {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln},
1238 {"derwin", (PyCFunction)PyCursesWindow_DerWin},
1239 {"echochar", (PyCFunction)PyCursesWindow_EchoChar},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001240#ifdef NCURSES_MOUSE_VERSION
1241 {"enclose", (PyCFunction)PyCursesWindow_Enclose},
1242#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001243 {"erase", (PyCFunction)PyCursesWindow_werase},
1244 {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx},
1245 {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001246 {"getch", (PyCFunction)PyCursesWindow_GetCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001247 {"getkey", (PyCFunction)PyCursesWindow_GetKey},
1248 {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx},
1249 {"getparyx", (PyCFunction)PyCursesWindow_getparyx},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001250 {"getstr", (PyCFunction)PyCursesWindow_GetStr},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001251 {"getyx", (PyCFunction)PyCursesWindow_getyx},
1252 {"hline", (PyCFunction)PyCursesWindow_Hline},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001253 {"idcok", (PyCFunction)PyCursesWindow_idcok},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001254 {"idlok", (PyCFunction)PyCursesWindow_idlok},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001255 {"immedok", (PyCFunction)PyCursesWindow_immedok},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001256 {"inch", (PyCFunction)PyCursesWindow_InCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001257 {"insch", (PyCFunction)PyCursesWindow_InsCh},
1258 {"insdelln", (PyCFunction)PyCursesWindow_winsdelln},
1259 {"insertln", (PyCFunction)PyCursesWindow_winsertln},
1260 {"insnstr", (PyCFunction)PyCursesWindow_InsNStr},
1261 {"insstr", (PyCFunction)PyCursesWindow_InsStr},
1262 {"instr", (PyCFunction)PyCursesWindow_InStr},
1263 {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched},
1264 {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched},
1265 {"keypad", (PyCFunction)PyCursesWindow_keypad},
1266 {"leaveok", (PyCFunction)PyCursesWindow_leaveok},
1267 {"move", (PyCFunction)PyCursesWindow_wmove},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001268 {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001269 {"mvwin", (PyCFunction)PyCursesWindow_mvwin},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001270 {"nodelay", (PyCFunction)PyCursesWindow_nodelay},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001271 {"notimeout", (PyCFunction)PyCursesWindow_notimeout},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001272 {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
Andrew M. Kuchlinga98e92b2000-08-20 23:37:02 +00001273 /* Backward compatibility alias -- remove in Python 2.1 */
1274 {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001275 {"putwin", (PyCFunction)PyCursesWindow_PutWin},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001276 {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001277 {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001278 {"refresh", (PyCFunction)PyCursesWindow_Refresh},
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +00001279#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001280 {"resize", (PyCFunction)PyCursesWindow_wresize},
1281#endif
1282 {"scroll", (PyCFunction)PyCursesWindow_Scroll},
1283 {"scrollok", (PyCFunction)PyCursesWindow_scrollok},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001284 {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001285 {"standend", (PyCFunction)PyCursesWindow_wstandend},
1286 {"standout", (PyCFunction)PyCursesWindow_wstandout},
1287 {"subpad", (PyCFunction)PyCursesWindow_SubWin},
1288 {"subwin", (PyCFunction)PyCursesWindow_SubWin},
1289 {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown},
1290 {"syncok", (PyCFunction)PyCursesWindow_syncok},
1291 {"syncup", (PyCFunction)PyCursesWindow_wsyncup},
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00001292 {"timeout", (PyCFunction)PyCursesWindow_wtimeout},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001293 {"touchline", (PyCFunction)PyCursesWindow_TouchLine},
1294 {"touchwin", (PyCFunction)PyCursesWindow_touchwin},
1295 {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin},
1296 {"vline", (PyCFunction)PyCursesWindow_Vline},
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001297 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00001298};
1299
1300static PyObject *
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00001301PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001302{
Guido van Rossuma597dde1995-01-10 20:56:29 +00001303 return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001304}
1305
Guido van Rossumf6971e21994-08-30 12:25:20 +00001306/* -------------------------------------------------------*/
Guido van Rossum85738471995-02-17 13:50:17 +00001307
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001308PyTypeObject PyCursesWindow_Type = {
Guido van Rossumf6971e21994-08-30 12:25:20 +00001309 PyObject_HEAD_INIT(&PyType_Type)
1310 0, /*ob_size*/
1311 "curses window", /*tp_name*/
1312 sizeof(PyCursesWindowObject), /*tp_basicsize*/
1313 0, /*tp_itemsize*/
1314 /* methods */
1315 (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
1316 0, /*tp_print*/
1317 (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
1318 (setattrfunc)0, /*tp_setattr*/
1319 0, /*tp_compare*/
1320 0, /*tp_repr*/
1321 0, /*tp_as_number*/
1322 0, /*tp_as_sequence*/
1323 0, /*tp_as_mapping*/
1324 0, /*tp_hash*/
1325};
1326
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001327/*********************************************************************
1328 Global Functions
1329**********************************************************************/
Guido van Rossumf6971e21994-08-30 12:25:20 +00001330
Guido van Rossume4485b01994-09-07 14:32:49 +00001331static PyObject *ModDict;
1332
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001333/* Function Prototype Macros - They are ugly but very, very useful. ;-)
1334
1335 X - function name
1336 TYPE - parameter Type
1337 ERGSTR - format string for construction of the return value
1338 PARSESTR - format string for argument parsing
1339 */
1340
1341#define NoArgNoReturnFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001342static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001343{ \
1344 PyCursesInitialised \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001345 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001346 return PyCursesCheckERR(X(), # X); }
1347
1348#define NoArgOrFlagNoReturnFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001349static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001350{ \
1351 int flag = 0; \
1352 PyCursesInitialised \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001353 switch(ARG_COUNT(args)) { \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001354 case 0: \
1355 return PyCursesCheckERR(X(), # X); \
1356 case 1: \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001357 if (!PyArg_Parse(args, "i;True(1) or False(0)", &flag)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001358 if (flag) return PyCursesCheckERR(X(), # X); \
1359 else return PyCursesCheckERR(no ## X (), # X); \
1360 default: \
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001361 PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001362 return NULL; } }
1363
1364#define NoArgReturnIntFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001365static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001366{ \
1367 PyCursesInitialised \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001368 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001369 return PyInt_FromLong((long) X()); }
1370
1371
1372#define NoArgReturnStringFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001373static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001374{ \
1375 PyCursesInitialised \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001376 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001377 return PyString_FromString(X()); }
1378
1379#define NoArgTrueFalseFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001380static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001381{ \
1382 PyCursesInitialised \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001383 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001384 if (X () == FALSE) { \
1385 Py_INCREF(Py_False); \
1386 return Py_False; \
1387 } \
1388 Py_INCREF(Py_True); \
1389 return Py_True; }
1390
1391#define NoArgNoReturnVoidFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001392static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001393{ \
1394 PyCursesInitialised \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001395 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001396 X(); \
1397 Py_INCREF(Py_None); \
1398 return Py_None; }
1399
1400NoArgNoReturnFunction(beep)
1401NoArgNoReturnFunction(def_prog_mode)
1402NoArgNoReturnFunction(def_shell_mode)
1403NoArgNoReturnFunction(doupdate)
1404NoArgNoReturnFunction(endwin)
1405NoArgNoReturnFunction(flash)
1406NoArgNoReturnFunction(nocbreak)
1407NoArgNoReturnFunction(noecho)
1408NoArgNoReturnFunction(nonl)
1409NoArgNoReturnFunction(noraw)
1410NoArgNoReturnFunction(reset_prog_mode)
1411NoArgNoReturnFunction(reset_shell_mode)
1412NoArgNoReturnFunction(resetty)
1413NoArgNoReturnFunction(savetty)
1414
1415NoArgOrFlagNoReturnFunction(cbreak)
1416NoArgOrFlagNoReturnFunction(echo)
1417NoArgOrFlagNoReturnFunction(nl)
1418NoArgOrFlagNoReturnFunction(raw)
1419
1420NoArgReturnIntFunction(baudrate)
1421NoArgReturnIntFunction(termattrs)
1422
1423NoArgReturnStringFunction(termname)
1424NoArgReturnStringFunction(longname)
1425
1426NoArgTrueFalseFunction(can_change_color)
1427NoArgTrueFalseFunction(has_colors)
1428NoArgTrueFalseFunction(has_ic)
1429NoArgTrueFalseFunction(has_il)
1430NoArgTrueFalseFunction(isendwin)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001431NoArgNoReturnVoidFunction(filter)
1432NoArgNoReturnVoidFunction(flushinp)
1433NoArgNoReturnVoidFunction(noqiflush)
1434
1435static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001436PyCurses_Color_Content(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001437{
1438 short color,r,g,b;
1439
1440 PyCursesInitialised
1441 PyCursesInitialisedColor
1442
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001443 if (ARG_COUNT(args) != 1) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001444 PyErr_SetString(PyExc_TypeError,
1445 "color_content requires 1 argument");
1446 return NULL;
1447 }
1448
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001449 if (!PyArg_Parse(args, "h;color", &color)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001450
1451 if (color_content(color, &r, &g, &b) != ERR)
1452 return Py_BuildValue("(iii)", r, g, b);
1453 else {
1454 PyErr_SetString(PyCursesError,
1455 "Argument 1 was out of range. Check value of COLORS.");
1456 return NULL;
1457 }
1458}
1459
1460static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001461PyCurses_color_pair(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001462{
1463 int n;
1464
1465 PyCursesInitialised
1466 PyCursesInitialisedColor
1467
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001468 if (ARG_COUNT(args) != 1) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001469 PyErr_SetString(PyExc_TypeError, "color_pair requires 1 argument");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001470 return NULL;
1471 }
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001472 if (!PyArg_Parse(args, "i;number", &n)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001473 return PyInt_FromLong((long) (n << 8));
1474}
1475
1476static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001477PyCurses_Curs_Set(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001478{
1479 int vis,erg;
1480
1481 PyCursesInitialised
1482
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001483 if (ARG_COUNT(args)!=1) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001484 PyErr_SetString(PyExc_TypeError, "curs_set requires 1 argument");
1485 return NULL;
1486 }
1487
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001488 if (!PyArg_Parse(args, "i;int", &vis)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001489
1490 erg = curs_set(vis);
1491 if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
1492
1493 return PyInt_FromLong((long) erg);
1494}
1495
1496static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001497PyCurses_Delay_Output(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001498{
1499 int ms;
1500
1501 PyCursesInitialised
1502
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001503 if (ARG_COUNT(args) != 1) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001504 PyErr_SetString(PyExc_TypeError, "delay_output requires 1 argument");
1505 return NULL;
1506 }
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001507 if (!PyArg_Parse(args, "i;ms", &ms)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001508
1509 return PyCursesCheckERR(delay_output(ms), "delay_output");
1510}
1511
1512static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001513PyCurses_EraseChar(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001514{
1515 char ch;
1516
1517 PyCursesInitialised
1518
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001519 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001520
1521 ch = erasechar();
1522
1523 return PyString_FromString(&ch);
1524}
1525
1526static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001527PyCurses_getsyx(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001528{
1529 int x,y;
1530
1531 PyCursesInitialised
1532
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001533 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001534
1535 getsyx(y, x);
1536
1537 return Py_BuildValue("(ii)", y, x);
1538}
1539
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001540#ifdef NCURSES_MOUSE_VERSION
1541static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001542PyCurses_GetMouse(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001543{
1544 int rtn;
1545 MEVENT event;
1546
1547 PyCursesInitialised
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001548 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001549
1550 rtn = getmouse( &event );
1551 if (rtn == ERR) {
1552 PyErr_SetString(PyCursesError, "getmouse() returned ERR");
1553 return NULL;
1554 }
1555 return Py_BuildValue("(hiiil)",
1556 (short)event.id,
1557 event.x, event.y, event.z,
1558 (long) event.bstate);
1559}
1560
1561static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001562PyCurses_UngetMouse(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001563{
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001564 MEVENT event;
1565
1566 PyCursesInitialised
1567 if (!PyArg_ParseTuple(args, "(hiiil)",
1568 &event.id,
1569 &event.x, &event.y, &event.z,
1570 (int *) &event.bstate))
1571 return NULL;
1572
1573 return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
1574}
1575#endif
1576
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001577static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001578PyCurses_GetWin(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001579{
1580 WINDOW *win;
1581 PyObject *temp;
1582
1583 PyCursesInitialised
1584
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001585 if (!PyArg_Parse(args, "O;fileobj", &temp)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001586
1587 if (!PyFile_Check(temp)) {
1588 PyErr_SetString(PyExc_TypeError, "argument must be a file object");
1589 return NULL;
1590 }
1591
1592 win = getwin(PyFile_AsFile(temp));
1593
1594 if (win == NULL) {
1595 PyErr_SetString(PyCursesError, catchall_NULL);
1596 return NULL;
1597 }
1598
1599 return PyCursesWindow_New(win);
1600}
1601
1602static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001603PyCurses_HalfDelay(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001604{
1605 unsigned char tenths;
1606
1607 PyCursesInitialised
1608
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001609 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001610 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001611 if (!PyArg_Parse(args, "b;tenths", &tenths)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001612 break;
1613 default:
1614 PyErr_SetString(PyExc_TypeError, "halfdelay requires 1 argument");
1615 return NULL;
1616 }
1617
1618 return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
1619}
1620
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00001621#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001622 /* No has_key! */
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001623static PyObject * PyCurses_has_key(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001624{
1625 int ch;
1626
1627 PyCursesInitialised
1628
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001629 if (!PyArg_Parse(args,"i",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001630
1631 if (has_key(ch) == FALSE) {
1632 Py_INCREF(Py_False);
1633 return Py_False;
1634 }
1635 Py_INCREF(Py_True);
1636 return Py_True;
1637}
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00001638#endif /* STRICT_SYSV_CURSES */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001639
1640static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001641PyCurses_Init_Color(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001642{
1643 short color, r, g, b;
1644
1645 PyCursesInitialised
1646 PyCursesInitialisedColor
1647
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001648 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001649 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001650 if (!PyArg_Parse(args, "(hhhh);color,r,g,b", &color, &r, &g, &b)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001651 break;
1652 default:
1653 PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
1654 return NULL;
1655 }
1656
1657 return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
1658}
1659
1660static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001661PyCurses_Init_Pair(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001662{
1663 short pair, f, b;
1664
1665 PyCursesInitialised
1666 PyCursesInitialisedColor
1667
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001668 if (ARG_COUNT(args) != 3) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001669 PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
1670 return NULL;
1671 }
1672
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001673 if (!PyArg_Parse(args, "(hhh);pair, f, b", &pair, &f, &b)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001674
1675 return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
1676}
1677
Guido van Rossumf6971e21994-08-30 12:25:20 +00001678static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001679PyCurses_InitScr(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001680{
Guido van Rossum56bf2351994-08-31 22:06:24 +00001681 WINDOW *win;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001682 PyObject *lines, *cols;
1683
1684 if (!PyArg_NoArgs(args)) return NULL;
1685
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001686 if (initialised == TRUE) {
Guido van Rossumf6971e21994-08-30 12:25:20 +00001687 wrefresh(stdscr);
1688 return (PyObject *)PyCursesWindow_New(stdscr);
1689 }
Guido van Rossum56bf2351994-08-31 22:06:24 +00001690
1691 win = initscr();
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001692
Guido van Rossum85738471995-02-17 13:50:17 +00001693 if (win == NULL) {
1694 PyErr_SetString(PyCursesError, catchall_NULL);
1695 return NULL;
1696 }
1697
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001698 initialised = TRUE;
Guido van Rossum56bf2351994-08-31 22:06:24 +00001699
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001700/* This was moved from initcurses() because it core dumped on SGI,
1701 where they're not defined until you've called initscr() */
1702#define SetDictInt(string,ch) \
1703 PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
1704
1705 /* Here are some graphic symbols you can use */
1706 SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
1707 SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
1708 SetDictInt("ACS_URCORNER", (ACS_URCORNER));
1709 SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
1710 SetDictInt("ACS_LTEE", (ACS_LTEE));
1711 SetDictInt("ACS_RTEE", (ACS_RTEE));
1712 SetDictInt("ACS_BTEE", (ACS_BTEE));
1713 SetDictInt("ACS_TTEE", (ACS_TTEE));
1714 SetDictInt("ACS_HLINE", (ACS_HLINE));
1715 SetDictInt("ACS_VLINE", (ACS_VLINE));
1716 SetDictInt("ACS_PLUS", (ACS_PLUS));
1717 SetDictInt("ACS_S1", (ACS_S1));
1718 SetDictInt("ACS_S9", (ACS_S9));
1719 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
1720 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
1721 SetDictInt("ACS_DEGREE", (ACS_DEGREE));
1722 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
1723 SetDictInt("ACS_BULLET", (ACS_BULLET));
1724 SetDictInt("ACS_LARROW", (ACS_LARROW));
1725 SetDictInt("ACS_RARROW", (ACS_RARROW));
1726 SetDictInt("ACS_DARROW", (ACS_DARROW));
1727 SetDictInt("ACS_UARROW", (ACS_UARROW));
1728 SetDictInt("ACS_BOARD", (ACS_BOARD));
1729 SetDictInt("ACS_LANTERN", (ACS_LANTERN));
1730 SetDictInt("ACS_BLOCK", (ACS_BLOCK));
1731 SetDictInt("ACS_BSSB", (ACS_ULCORNER));
1732 SetDictInt("ACS_SSBB", (ACS_LLCORNER));
1733 SetDictInt("ACS_BBSS", (ACS_URCORNER));
1734 SetDictInt("ACS_SBBS", (ACS_LRCORNER));
1735 SetDictInt("ACS_SBSS", (ACS_RTEE));
1736 SetDictInt("ACS_SSSB", (ACS_LTEE));
1737 SetDictInt("ACS_SSBS", (ACS_BTEE));
1738 SetDictInt("ACS_BSSS", (ACS_TTEE));
1739 SetDictInt("ACS_BSBS", (ACS_HLINE));
1740 SetDictInt("ACS_SBSB", (ACS_VLINE));
1741 SetDictInt("ACS_SSSS", (ACS_PLUS));
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +00001742#ifndef STRICT_SYSV_CURSES
1743 /* The following are never available with strict SYSV curses */
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001744 SetDictInt("ACS_S3", (ACS_S3));
1745 SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
1746 SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
1747 SetDictInt("ACS_PI", (ACS_PI));
1748 SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
1749 SetDictInt("ACS_STERLING", (ACS_STERLING));
1750#endif
1751
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001752 lines = PyInt_FromLong((long) LINES);
1753 PyDict_SetItemString(ModDict, "LINES", lines);
1754 Py_DECREF(lines);
1755 cols = PyInt_FromLong((long) COLS);
1756 PyDict_SetItemString(ModDict, "COLS", cols);
1757 Py_DECREF(cols);
Guido van Rossum56bf2351994-08-31 22:06:24 +00001758
1759 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001760}
1761
Guido van Rossumf6971e21994-08-30 12:25:20 +00001762
1763static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001764PyCurses_IntrFlush(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001765{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001766 int ch;
1767
1768 PyCursesInitialised
1769
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001770 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001771 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001772 if (!PyArg_Parse(args,"i;True(1), False(0)",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001773 break;
1774 default:
1775 PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00001776 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001777 }
1778
1779 return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
1780}
1781
1782static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001783PyCurses_KeyName(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001784{
1785 const char *knp;
1786 int ch;
1787
1788 PyCursesInitialised
1789
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001790 if (!PyArg_Parse(args,"i",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001791
1792 knp = keyname(ch);
1793
1794 return PyString_FromString((knp == NULL) ? "" : (char *)knp);
1795}
1796
1797static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001798PyCurses_KillChar(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001799{
1800 char ch;
1801
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001802 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001803
1804 ch = killchar();
1805
1806 return PyString_FromString(&ch);
1807}
1808
1809static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001810PyCurses_Meta(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001811{
1812 int ch;
1813
1814 PyCursesInitialised
1815
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001816 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001817 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001818 if (!PyArg_Parse(args,"i;True(1), False(0)",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001819 break;
1820 default:
1821 PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
1822 return NULL;
1823 }
1824
1825 return PyCursesCheckERR(meta(stdscr, ch), "meta");
1826}
1827
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001828#ifdef NCURSES_MOUSE_VERSION
1829static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001830PyCurses_MouseInterval(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001831{
1832 int interval;
1833 PyCursesInitialised
1834
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001835 if (!PyArg_Parse(args,"i;interval",&interval))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001836 return NULL;
1837 return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
1838}
1839
1840static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001841PyCurses_MouseMask(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001842{
Andrew M. Kuchling1a104002000-07-06 18:14:03 +00001843 int newmask;
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001844 mmask_t oldmask, availmask;
1845
1846 PyCursesInitialised
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001847 if (!PyArg_Parse(args,"i;mousemask",&newmask))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001848 return NULL;
1849 availmask = mousemask(newmask, &oldmask);
1850 return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
1851}
1852#endif
1853
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001854static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001855PyCurses_NewPad(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001856{
1857 WINDOW *win;
1858 int nlines, ncols;
1859
1860 PyCursesInitialised
1861
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001862 if (!PyArg_Parse(args,"(ii);nlines,ncols",&nlines,&ncols)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001863
1864 win = newpad(nlines, ncols);
1865
1866 if (win == NULL) {
1867 PyErr_SetString(PyCursesError, catchall_NULL);
1868 return NULL;
1869 }
1870
1871 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001872}
1873
1874static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001875PyCurses_NewWindow(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001876{
1877 WINDOW *win;
1878 int nlines, ncols, begin_y, begin_x;
Guido van Rossum85738471995-02-17 13:50:17 +00001879
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001880 PyCursesInitialised
1881
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001882 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +00001883 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001884 if (!PyArg_Parse(args,"(ii);nlines,ncols",&nlines,&ncols))
Guido van Rossum85738471995-02-17 13:50:17 +00001885 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001886 win = newpad(nlines, ncols);
Guido van Rossum85738471995-02-17 13:50:17 +00001887 break;
1888 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001889 if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
Guido van Rossumf6971e21994-08-30 12:25:20 +00001890 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +00001891 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001892 win = newwin(nlines,ncols,begin_y,begin_x);
Guido van Rossum85738471995-02-17 13:50:17 +00001893 break;
1894 default:
1895 PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
1896 return NULL;
1897 }
1898
Guido van Rossumf6971e21994-08-30 12:25:20 +00001899 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +00001900 PyErr_SetString(PyCursesError, catchall_NULL);
1901 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001902 }
Guido van Rossum85738471995-02-17 13:50:17 +00001903
Guido van Rossumf6971e21994-08-30 12:25:20 +00001904 return (PyObject *)PyCursesWindow_New(win);
1905}
1906
1907static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001908PyCurses_Pair_Content(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001909{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001910 short pair,f,b;
1911
1912 PyCursesInitialised
1913 PyCursesInitialisedColor
1914
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001915 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001916 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001917 if (!PyArg_Parse(args, "h;pair", &pair)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001918 break;
1919 default:
1920 PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00001921 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001922 }
1923
1924 if (!pair_content(pair, &f, &b)) {
1925 PyErr_SetString(PyCursesError,
1926 "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
1927 return NULL;
1928 }
1929
1930 return Py_BuildValue("(ii)", f, b);
1931}
1932
1933static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001934PyCurses_pair_number(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001935{
1936 int n;
1937
1938 PyCursesInitialised
1939 PyCursesInitialisedColor
1940
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001941 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001942 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001943 if (!PyArg_Parse(args, "i;pairvalue", &n)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001944 break;
1945 default:
1946 PyErr_SetString(PyExc_TypeError,
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001947 "pair_number requires 1 argument");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001948 return NULL;
1949 }
1950
1951 return PyInt_FromLong((long) ((n & A_COLOR) >> 8));
1952}
1953
1954static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001955PyCurses_Putp(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001956{
1957 char *str;
1958
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001959 if (!PyArg_Parse(args,"s;str", &str)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001960 return PyCursesCheckERR(putp(str), "putp");
1961}
1962
1963static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001964PyCurses_QiFlush(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001965{
1966 int flag = 0;
1967
1968 PyCursesInitialised
1969
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001970 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001971 case 0:
1972 qiflush();
1973 Py_INCREF(Py_None);
1974 return Py_None;
1975 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001976 if (!PyArg_Parse(args, "i;True(1) or False(0)", &flag)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001977 if (flag) qiflush();
1978 else noqiflush();
1979 Py_INCREF(Py_None);
1980 return Py_None;
1981 default:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001982 PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001983 return NULL;
1984 }
1985}
1986
1987static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001988PyCurses_setsyx(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001989{
1990 int y,x;
1991
1992 PyCursesInitialised
1993
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001994 if (ARG_COUNT(args)!=2) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001995 PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001996 return NULL;
1997 }
1998
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001999 if (!PyArg_Parse(args, "(ii);y, x", &y, &x)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002000
2001 setsyx(y,x);
2002
Guido van Rossumf6971e21994-08-30 12:25:20 +00002003 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00002004 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002005}
2006
2007static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002008PyCurses_Start_Color(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002009{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002010 int code;
2011 PyObject *c, *cp;
2012
2013 PyCursesInitialised
2014
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002015 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002016
2017 code = start_color();
2018 if (code != ERR) {
2019 initialisedcolors = TRUE;
2020 c = PyInt_FromLong((long) COLORS);
2021 PyDict_SetItemString(ModDict, "COLORS", c);
2022 Py_DECREF(c);
2023 cp = PyInt_FromLong((long) COLOR_PAIRS);
2024 PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
2025 Py_DECREF(cp);
2026 Py_INCREF(Py_None);
2027 return Py_None;
2028 } else {
2029 PyErr_SetString(PyCursesError, "start_color() returned ERR");
Guido van Rossum85738471995-02-17 13:50:17 +00002030 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002031 }
2032}
2033
2034static PyObject *
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002035PyCurses_tigetflag(PyObject *self, PyObject *args)
2036{
2037 char *capname;
2038
2039 PyCursesInitialised;
2040
2041 if (!PyArg_ParseTuple(args, "z", &capname))
2042 return NULL;
2043
2044 return PyInt_FromLong( (long) tigetflag( capname ) );
2045}
2046
2047static PyObject *
2048PyCurses_tigetnum(PyObject *self, PyObject *args)
2049{
2050 char *capname;
2051
2052 PyCursesInitialised;
2053
2054 if (!PyArg_ParseTuple(args, "z", &capname))
2055 return NULL;
2056
2057 return PyInt_FromLong( (long) tigetnum( capname ) );
2058}
2059
2060static PyObject *
2061PyCurses_tigetstr(PyObject *self, PyObject *args)
2062{
2063 char *capname;
2064
2065 PyCursesInitialised;
2066
2067 if (!PyArg_ParseTuple(args, "z", &capname))
2068 return NULL;
2069
2070 capname = tigetstr( capname );
2071 if (capname == 0 || capname == (char*) -1) {
2072 Py_INCREF(Py_None);
2073 return Py_None;
2074 }
2075 return PyString_FromString( capname );
2076}
2077
2078static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002079PyCurses_TypeAhead(PyObject *self, PyObject *args)
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002080{
Andrew M. Kuchling1a104002000-07-06 18:14:03 +00002081 int fd;
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002082
2083 PyCursesInitialised
2084
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002085 if (!PyArg_Parse(args,"i;fd",&fd)) return NULL;
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002086
2087 PyCursesCheckERR(typeahead( fd ), "typeahead");
2088 Py_INCREF(Py_None);
2089 return Py_None;
2090}
2091
2092static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002093PyCurses_UnCtrl(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002094{
2095 PyObject *temp;
2096 chtype ch;
2097
2098 PyCursesInitialised
2099
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002100 if (!PyArg_Parse(args,"O;ch or int",&temp)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002101
2102 if (PyInt_Check(temp))
2103 ch = (chtype) PyInt_AsLong(temp);
2104 else if (PyString_Check(temp))
2105 ch = (chtype) *PyString_AsString(temp);
2106 else {
2107 PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
2108 return NULL;
2109 }
2110
2111 return PyString_FromString(unctrl(ch));
Guido van Rossumf6971e21994-08-30 12:25:20 +00002112}
2113
2114static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002115PyCurses_UngetCh(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002116{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002117 PyObject *temp;
2118 chtype ch;
2119
2120 PyCursesInitialised
2121
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002122 if (!PyArg_Parse(args,"O;ch or int",&temp)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002123
2124 if (PyInt_Check(temp))
2125 ch = (chtype) PyInt_AsLong(temp);
2126 else if (PyString_Check(temp))
2127 ch = (chtype) *PyString_AsString(temp);
2128 else {
2129 PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
Guido van Rossum85738471995-02-17 13:50:17 +00002130 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002131 }
2132
Guido van Rossum85738471995-02-17 13:50:17 +00002133 return PyCursesCheckERR(ungetch(ch), "ungetch");
Guido van Rossumf6971e21994-08-30 12:25:20 +00002134}
2135
2136static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002137PyCurses_Use_Env(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002138{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002139 int flag;
2140
2141 PyCursesInitialised
2142
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002143 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002144 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002145 if (!PyArg_Parse(args,"i;True(1), False(0)",&flag))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002146 return NULL;
2147 break;
2148 default:
2149 PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00002150 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002151 }
2152 use_env(flag);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002153 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00002154 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002155}
2156
Guido van Rossumf6971e21994-08-30 12:25:20 +00002157/* List of functions defined in the module */
2158
2159static PyMethodDef PyCurses_methods[] = {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002160 {"baudrate", (PyCFunction)PyCurses_baudrate},
2161 {"beep", (PyCFunction)PyCurses_beep},
2162 {"can_change_color", (PyCFunction)PyCurses_can_change_color},
2163 {"cbreak", (PyCFunction)PyCurses_cbreak},
2164 {"color_content", (PyCFunction)PyCurses_Color_Content},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002165 {"color_pair", (PyCFunction)PyCurses_color_pair},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002166 {"curs_set", (PyCFunction)PyCurses_Curs_Set},
2167 {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode},
2168 {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode},
2169 {"delay_output", (PyCFunction)PyCurses_Delay_Output},
2170 {"doupdate", (PyCFunction)PyCurses_doupdate},
2171 {"echo", (PyCFunction)PyCurses_echo},
2172 {"endwin", (PyCFunction)PyCurses_endwin},
2173 {"erasechar", (PyCFunction)PyCurses_EraseChar},
2174 {"filter", (PyCFunction)PyCurses_filter},
2175 {"flash", (PyCFunction)PyCurses_flash},
2176 {"flushinp", (PyCFunction)PyCurses_flushinp},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002177#ifdef NCURSES_MOUSE_VERSION
2178 {"getmouse", (PyCFunction)PyCurses_GetMouse},
2179 {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
2180#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002181 {"getsyx", (PyCFunction)PyCurses_getsyx},
2182 {"getwin", (PyCFunction)PyCurses_GetWin},
2183 {"has_colors", (PyCFunction)PyCurses_has_colors},
2184 {"has_ic", (PyCFunction)PyCurses_has_ic},
2185 {"has_il", (PyCFunction)PyCurses_has_il},
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00002186#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002187 {"has_key", (PyCFunction)PyCurses_has_key},
Guido van Rossumf6971e21994-08-30 12:25:20 +00002188#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002189 {"halfdelay", (PyCFunction)PyCurses_HalfDelay},
2190 {"init_color", (PyCFunction)PyCurses_Init_Color},
2191 {"init_pair", (PyCFunction)PyCurses_Init_Pair},
2192 {"initscr", (PyCFunction)PyCurses_InitScr},
2193 {"intrflush", (PyCFunction)PyCurses_IntrFlush},
2194 {"isendwin", (PyCFunction)PyCurses_isendwin},
2195 {"keyname", (PyCFunction)PyCurses_KeyName},
2196 {"killchar", (PyCFunction)PyCurses_KillChar},
2197 {"longname", (PyCFunction)PyCurses_longname},
2198 {"meta", (PyCFunction)PyCurses_Meta},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002199#ifdef NCURSES_MOUSE_VERSION
2200 {"mouseinterval", (PyCFunction)PyCurses_MouseInterval},
2201 {"mousemask", (PyCFunction)PyCurses_MouseMask},
2202#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002203 {"newpad", (PyCFunction)PyCurses_NewPad},
2204 {"newwin", (PyCFunction)PyCurses_NewWindow},
2205 {"nl", (PyCFunction)PyCurses_nl},
2206 {"nocbreak", (PyCFunction)PyCurses_nocbreak},
2207 {"noecho", (PyCFunction)PyCurses_noecho},
2208 {"nonl", (PyCFunction)PyCurses_nonl},
2209 {"noqiflush", (PyCFunction)PyCurses_noqiflush},
2210 {"noraw", (PyCFunction)PyCurses_noraw},
2211 {"pair_content", (PyCFunction)PyCurses_Pair_Content},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002212 {"pair_number", (PyCFunction)PyCurses_pair_number},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002213 {"putp", (PyCFunction)PyCurses_Putp},
2214 {"qiflush", (PyCFunction)PyCurses_QiFlush},
2215 {"raw", (PyCFunction)PyCurses_raw},
2216 {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode},
2217 {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode},
Andrew M. Kuchling1a104002000-07-06 18:14:03 +00002218 {"resetty", (PyCFunction)PyCurses_resetty},
2219 {"savetty", (PyCFunction)PyCurses_savetty},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002220 {"setsyx", (PyCFunction)PyCurses_setsyx},
2221 {"start_color", (PyCFunction)PyCurses_Start_Color},
2222 {"termattrs", (PyCFunction)PyCurses_termattrs},
2223 {"termname", (PyCFunction)PyCurses_termname},
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002224 {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
2225 {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
2226 {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002227 {"typeahead", (PyCFunction)PyCurses_TypeAhead},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002228 {"unctrl", (PyCFunction)PyCurses_UnCtrl},
2229 {"ungetch", (PyCFunction)PyCurses_UngetCh},
2230 {"use_env", (PyCFunction)PyCurses_Use_Env},
2231 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00002232};
2233
2234/* Initialization function for the module */
2235
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002236void
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00002237init_curses(void)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002238{
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00002239 PyObject *m, *d, *v;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002240
2241 /* Create the module and add the functions */
Andrew M. Kuchlingb7f198e2000-06-10 23:12:32 +00002242 m = Py_InitModule("_curses", PyCurses_methods);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002243
Guido van Rossumf6971e21994-08-30 12:25:20 +00002244 /* Add some symbolic constants to the module */
2245 d = PyModule_GetDict(m);
Guido van Rossume4485b01994-09-07 14:32:49 +00002246 ModDict = d; /* For PyCurses_InitScr */
Guido van Rossumfbea2f31994-08-31 22:05:27 +00002247
Guido van Rossum85738471995-02-17 13:50:17 +00002248 /* For exception curses.error */
Fred Drake589c35b2000-07-06 19:38:49 +00002249 PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
Guido van Rossum85738471995-02-17 13:50:17 +00002250 PyDict_SetItemString(d, "error", PyCursesError);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00002251
Guido van Rossum85738471995-02-17 13:50:17 +00002252 /* Make the version available */
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00002253 v = PyString_FromString(PyCursesVersion);
2254 PyDict_SetItemString(d, "version", v);
2255 PyDict_SetItemString(d, "__version__", v);
2256 Py_DECREF(v);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002257
Guido van Rossumf6971e21994-08-30 12:25:20 +00002258 /* Here are some attributes you can add to chars to print */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002259
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002260 SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002261 SetDictInt("A_NORMAL", A_NORMAL);
2262 SetDictInt("A_STANDOUT", A_STANDOUT);
2263 SetDictInt("A_UNDERLINE", A_UNDERLINE);
2264 SetDictInt("A_REVERSE", A_REVERSE);
2265 SetDictInt("A_BLINK", A_BLINK);
2266 SetDictInt("A_DIM", A_DIM);
2267 SetDictInt("A_BOLD", A_BOLD);
2268 SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002269 SetDictInt("A_INVIS", A_INVIS);
2270 SetDictInt("A_PROTECT", A_PROTECT);
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002271 SetDictInt("A_CHARTEXT", A_CHARTEXT);
2272 SetDictInt("A_COLOR", A_COLOR);
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +00002273#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002274 SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
2275 SetDictInt("A_LEFT", A_LEFT);
2276 SetDictInt("A_LOW", A_LOW);
2277 SetDictInt("A_RIGHT", A_RIGHT);
2278 SetDictInt("A_TOP", A_TOP);
2279 SetDictInt("A_VERTICAL", A_VERTICAL);
2280#endif
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002281
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002282 SetDictInt("COLOR_BLACK", COLOR_BLACK);
2283 SetDictInt("COLOR_RED", COLOR_RED);
2284 SetDictInt("COLOR_GREEN", COLOR_GREEN);
2285 SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
2286 SetDictInt("COLOR_BLUE", COLOR_BLUE);
2287 SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
2288 SetDictInt("COLOR_CYAN", COLOR_CYAN);
2289 SetDictInt("COLOR_WHITE", COLOR_WHITE);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002290
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002291#ifdef NCURSES_MOUSE_VERSION
2292 /* Mouse-related constants */
2293 SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
2294 SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
2295 SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
2296 SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
2297 SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
2298
2299 SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
2300 SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
2301 SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
2302 SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
2303 SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
2304
2305 SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
2306 SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
2307 SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
2308 SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
2309 SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
2310
2311 SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
2312 SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
2313 SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
2314 SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
2315 SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
2316
2317 SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
2318 SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
2319 SetDictInt("BUTTON_ALT", BUTTON_ALT);
2320
2321 SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
2322 SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
2323#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +00002324 /* Now set everything up for KEY_ variables */
2325 {
2326 int key;
2327 char *key_n;
2328 char *key_n2;
2329 for (key=KEY_MIN;key < KEY_MAX; key++) {
2330 key_n = (char *)keyname(key);
Guido van Rossumf5c6d471995-02-07 15:38:32 +00002331 if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002332 continue;
2333 if (strncmp(key_n,"KEY_F(",6)==0) {
2334 char *p1, *p2;
2335 key_n2 = malloc(strlen(key_n)+1);
2336 p1 = key_n;
2337 p2 = key_n2;
2338 while (*p1) {
2339 if (*p1 != '(' && *p1 != ')') {
2340 *p2 = *p1;
2341 p2++;
2342 }
2343 p1++;
2344 }
2345 *p2 = (char)0;
2346 } else
2347 key_n2 = key_n;
Guido van Rossum85738471995-02-17 13:50:17 +00002348 PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
Guido van Rossumf6971e21994-08-30 12:25:20 +00002349 if (key_n2 != key_n)
2350 free(key_n2);
2351 }
Guido van Rossum85738471995-02-17 13:50:17 +00002352 SetDictInt("KEY_MIN", KEY_MIN);
2353 SetDictInt("KEY_MAX", KEY_MAX);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002354 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00002355}