blob: aa0b4f08ce20d501741f8aa6cc07f7116d55270a [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
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +000042 addchnstr addchstr chgat color_set define_key
Andrew M. Kuchlingfb6bbf52000-07-27 11:58:01 +000043 del_curterm delscreen dupwin inchnstr inchstr innstr keyok
44 mcprint mvaddchnstr mvaddchstr mvchgat mvcur mvinchnstr
45 mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +000046 mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr newterm
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +000047 resizeterm restartterm ripoffline scr_dump
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +000048 scr_init scr_restore scr_set scrl set_curterm set_term setterm
49 tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
50 use_default_colors vidattr vidputs waddchnstr waddchstr wchgat
51 wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
Andrew M. Kuchlingfb6bbf52000-07-27 11:58:01 +000052
53Low-priority:
54 slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
55 slk_attron slk_attrset slk_clear slk_color slk_init slk_label
56 slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
57
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +000058Menu extension (ncurses and probably SYSV):
59 current_item free_item free_menu item_count item_description
60 item_index item_init item_name item_opts item_opts_off
61 item_opts_on item_term item_userptr item_value item_visible
62 menu_back menu_driver menu_fore menu_format menu_grey
63 menu_init menu_items menu_mark menu_opts menu_opts_off
64 menu_opts_on menu_pad menu_pattern menu_request_by_name
65 menu_request_name menu_spacing menu_sub menu_term menu_userptr
66 menu_win new_item new_menu pos_menu_cursor post_menu
67 scale_menu set_current_item set_item_init set_item_opts
68 set_item_term set_item_userptr set_item_value set_menu_back
69 set_menu_fore set_menu_format set_menu_grey set_menu_init
70 set_menu_items set_menu_mark set_menu_opts set_menu_pad
71 set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
72 set_menu_userptr set_menu_win set_top_row top_row unpost_menu
73
74Form extension (ncurses and probably SYSV):
75 current_field data_ahead data_behind dup_field
76 dynamic_fieldinfo field_arg field_back field_buffer
77 field_count field_fore field_index field_info field_init
78 field_just field_opts field_opts_off field_opts_on field_pad
79 field_status field_term field_type field_userptr form_driver
80 form_fields form_init form_opts form_opts_off form_opts_on
81 form_page form_request_by_name form_request_name form_sub
82 form_term form_userptr form_win free_field free_form
83 link_field link_fieldtype move_field new_field new_form
84 new_page pos_form_cursor post_form scale_form
85 set_current_field set_field_back set_field_buffer
86 set_field_fore set_field_init set_field_just set_field_opts
87 set_field_pad set_field_status set_field_term set_field_type
88 set_field_userptr set_fieldtype_arg set_fieldtype_choice
89 set_form_fields set_form_init set_form_opts set_form_page
90 set_form_sub set_form_term set_form_userptr set_form_win
91 set_max_field set_new_page unpost_form
92
93
Andrew M. Kuchlingfb6bbf52000-07-27 11:58:01 +000094 */
95
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000096/* Release Number */
Guido van Rossumf6971e21994-08-30 12:25:20 +000097
Andrew M. Kuchling32552682000-12-22 21:52:27 +000098char *PyCursesVersion = "2.1";
Guido van Rossumf6971e21994-08-30 12:25:20 +000099
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000100/* Includes */
Guido van Rossumf6971e21994-08-30 12:25:20 +0000101
Guido van Rossum602099a1994-09-14 13:32:22 +0000102#include "Python.h"
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000103#define CURSES_MODULE
104#include "py_curses.h"
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000105
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000106#ifdef __osf__
107#define _XOPEN_SOURCE_EXTENDED /* Define macro for OSF/1 */
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +0000108#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000109#endif
110
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000111/* These prototypes are in <term.h>, but including this header
112 #defines many common symbols (such as "lines") which breaks the
113 curses module in other ways. So the code will just specify
114 explicit prototypes here. */
115extern int setupterm(char *,int,int *);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +0000116#ifdef sgi
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +0000117extern char *tigetstr(char *);
Andrew M. Kuchling399b8af2001-01-28 18:10:23 +0000118extern char *tparm(char *instring, ...);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +0000119#endif
120
121#if defined(sgi) || defined(__sun__)
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +0000122#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000123typedef chtype attr_t; /* No attr_t type is available */
Guido van Rossum1266a011996-02-25 04:50:31 +0000124#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000125
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000126#if defined(_AIX)
127#define STRICT_SYSV_CURSES
128#endif
129
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000130/* Definition of exception curses.error */
Guido van Rossumf6971e21994-08-30 12:25:20 +0000131
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000132static PyObject *PyCursesError;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000133
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000134/* Tells whether setupterm() has been called to initialise terminfo. */
135static int initialised_setupterm = FALSE;
136
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000137/* Tells whether initscr() has been called to initialise curses. */
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000138static int initialised = FALSE;
139
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000140/* Tells whether start_color() has been called to initialise color usage. */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000141static int initialisedcolors = FALSE;
142
143/* Utility Macros */
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000144#define PyCursesSetupTermCalled \
145 if (initialised_setupterm != TRUE) { \
146 PyErr_SetString(PyCursesError, \
147 "must call (at least) setupterm() first"); \
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000148 return 0; }
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000149
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000150#define PyCursesInitialised \
151 if (initialised != TRUE) { \
152 PyErr_SetString(PyCursesError, \
153 "must call initscr() first"); \
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000154 return 0; }
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000155
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000156#define PyCursesInitialisedColor \
157 if (initialisedcolors != TRUE) { \
158 PyErr_SetString(PyCursesError, \
159 "must call start_color() first"); \
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000160 return 0; }
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000161
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000162/* Utility Functions */
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000163
Guido van Rossum85738471995-02-17 13:50:17 +0000164/*
165 * Check the return code from a curses function and return None
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000166 * or raise an exception as appropriate. These are exported using the
167 * CObject API.
Guido van Rossum85738471995-02-17 13:50:17 +0000168 */
169
170static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000171PyCursesCheckERR(int code, char *fname)
Guido van Rossum85738471995-02-17 13:50:17 +0000172{
Guido van Rossum85738471995-02-17 13:50:17 +0000173 if (code != ERR) {
174 Py_INCREF(Py_None);
175 return Py_None;
176 } else {
177 if (fname == NULL) {
178 PyErr_SetString(PyCursesError, catchall_ERR);
179 } else {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000180 PyErr_Format(PyCursesError, "%s() returned ERR", fname);
Guido van Rossum85738471995-02-17 13:50:17 +0000181 }
182 return NULL;
183 }
184}
185
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000186static int
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000187PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000188{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000189 if (PyInt_Check(obj)) {
190 *ch = (chtype) PyInt_AsLong(obj);
191 } else if(PyString_Check(obj) &
192 (PyString_Size(obj) == 1)) {
193 *ch = (chtype) *PyString_AsString(obj);
194 } else {
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000195 return 0;
196 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000197 return 1;
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000198}
199
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000200/* Function versions of the 3 functions for tested whether curses has been
201 initialised or not. */
202
203static int func_PyCursesSetupTermCalled(void)
204{
205 PyCursesSetupTermCalled;
206 return 1;
207}
208
209static int func_PyCursesInitialised(void)
210{
211 PyCursesInitialised;
212 return 1;
213}
214
215static int func_PyCursesInitialisedColor(void)
216{
217 PyCursesInitialisedColor;
218 return 1;
219}
220
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000221/*****************************************************************************
222 The Window Object
223******************************************************************************/
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000224
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000225/* Definition of the window type */
Guido van Rossum85738471995-02-17 13:50:17 +0000226
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000227PyTypeObject PyCursesWindow_Type;
228
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000229/* Function prototype macros for Window object
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000230
231 X - function name
232 TYPE - parameter Type
233 ERGSTR - format string for construction of the return value
234 PARSESTR - format string for argument parsing
235 */
236
237#define Window_NoArgNoReturnFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000238static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
239{ if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000240 return PyCursesCheckERR(X(self->win), # X); }
241
242#define Window_NoArgTrueFalseFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000243static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000244{ \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000245 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000246 if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
247 else { Py_INCREF(Py_True); return Py_True; } }
248
249#define Window_NoArgNoReturnVoidFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000250static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000251{ \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000252 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000253 X(self->win); Py_INCREF(Py_None); return Py_None; }
254
255#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000256static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000257{ \
258 TYPE arg1, arg2; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000259 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000260 X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
261
262#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000263static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000264{ \
265 TYPE arg1; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000266 if (!PyArg_Parse(args, PARSESTR, &arg1)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000267 X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
268
269#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000270static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000271{ \
272 TYPE arg1; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000273 if (!PyArg_Parse(args,PARSESTR, &arg1)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000274 return PyCursesCheckERR(X(self->win, arg1), # X); }
275
276#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000277static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000278{ \
279 TYPE arg1, arg2; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000280 if (!PyArg_Parse(args,PARSESTR, &arg1, &arg2)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000281 return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
Guido van Rossum85738471995-02-17 13:50:17 +0000282
Guido van Rossumf6971e21994-08-30 12:25:20 +0000283/* ------------- WINDOW routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000284
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000285Window_NoArgNoReturnFunction(untouchwin)
286Window_NoArgNoReturnFunction(touchwin)
287Window_NoArgNoReturnFunction(redrawwin)
288Window_NoArgNoReturnFunction(winsertln)
289Window_NoArgNoReturnFunction(werase)
290Window_NoArgNoReturnFunction(wdeleteln)
291
292Window_NoArgTrueFalseFunction(is_wintouched)
293
294Window_NoArgNoReturnVoidFunction(wsyncup)
295Window_NoArgNoReturnVoidFunction(wsyncdown)
296Window_NoArgNoReturnVoidFunction(wstandend)
297Window_NoArgNoReturnVoidFunction(wstandout)
298Window_NoArgNoReturnVoidFunction(wcursyncup)
299Window_NoArgNoReturnVoidFunction(wclrtoeol)
300Window_NoArgNoReturnVoidFunction(wclrtobot)
301Window_NoArgNoReturnVoidFunction(wclear)
302
303Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")
304Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +0000305Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay")
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000306
307Window_NoArg2TupleReturnFunction(getyx, int, "(ii)")
308Window_NoArg2TupleReturnFunction(getbegyx, int, "(ii)")
309Window_NoArg2TupleReturnFunction(getmaxyx, int, "(ii)")
310Window_NoArg2TupleReturnFunction(getparyx, int, "(ii)")
311
312Window_OneArgNoReturnFunction(wattron, attr_t, "l;attr")
313Window_OneArgNoReturnFunction(wattroff, attr_t, "l;attr")
314Window_OneArgNoReturnFunction(wattrset, attr_t, "l;attr")
315Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
316Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000317#if defined(__NetBSD__)
318Window_OneArgNoReturnVoidFunction(keypad, int, "i;True(1) or False(0)")
319#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000320Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000321#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000322Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000323#if defined(__NetBSD__)
324Window_OneArgNoReturnVoidFunction(nodelay, int, "i;True(1) or False(0)")
325#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000326Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000327#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000328Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")
329Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000330Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines")
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000331Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
332
333Window_TwoArgNoReturnFunction(mvwin, int, "(ii);y,x")
334Window_TwoArgNoReturnFunction(mvderwin, int, "(ii);y,x")
335Window_TwoArgNoReturnFunction(wmove, int, "(ii);y,x")
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000336#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000337Window_TwoArgNoReturnFunction(wresize, int, "(ii);lines,columns")
338#endif
339
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000340/* Allocation and deallocation of Window Objects */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000341
Guido van Rossumf6971e21994-08-30 12:25:20 +0000342static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000343PyCursesWindow_New(WINDOW *win)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000344{
345 PyCursesWindowObject *wo;
Guido van Rossum85738471995-02-17 13:50:17 +0000346
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000347 wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
348 if (wo == NULL) return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000349 wo->win = win;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000350 return (PyObject *)wo;
351}
352
353static void
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000354PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000355{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000356 if (wo->win != stdscr) delwin(wo->win);
357 PyMem_DEL(wo);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000358}
359
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000360/* Addch, Addstr, Addnstr */
Guido van Rossumf6971e21994-08-30 12:25:20 +0000361
362static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000363PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000364{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000365 int rtn, x, y, use_xy = FALSE;
366 PyObject *temp;
367 chtype ch = 0;
368 attr_t attr = A_NORMAL;
369
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000370 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000371 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000372 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000373 return NULL;
374 break;
375 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000376 if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr))
Guido van Rossum85738471995-02-17 13:50:17 +0000377 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000378 break;
379 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000380 if (!PyArg_Parse(args,"(iiO);y,x,ch or int", &y, &x, &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000381 return NULL;
382 use_xy = TRUE;
383 break;
384 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000385 if (!PyArg_Parse(args,"(iiOl);y,x,ch or int, attr",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000386 &y, &x, &temp, &attr))
387 return NULL;
388 use_xy = TRUE;
389 break;
390 default:
391 PyErr_SetString(PyExc_TypeError, "addch requires 1 or 4 arguments");
392 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000393 }
Guido van Rossum85738471995-02-17 13:50:17 +0000394
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000395 if (!PyCurses_ConvertToChtype(temp, &ch)) {
396 PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
397 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000398 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000399
Guido van Rossumf6971e21994-08-30 12:25:20 +0000400 if (use_xy == TRUE)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000401 rtn = mvwaddch(self->win,y,x, ch | attr);
402 else {
403 rtn = waddch(self->win, ch | attr);
404 }
405 return PyCursesCheckERR(rtn, "addch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000406}
407
408static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000409PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000410{
411 int rtn;
412 int x, y;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000413 char *str;
414 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
415 int use_xy = FALSE, use_attr = FALSE;
Guido van Rossum85738471995-02-17 13:50:17 +0000416
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000417 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000418 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000419 if (!PyArg_Parse(args,"s;str", &str))
Guido van Rossum85738471995-02-17 13:50:17 +0000420 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000421 break;
422 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000423 if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000424 return NULL;
425 use_attr = TRUE;
426 break;
427 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000428 if (!PyArg_Parse(args,"(iis);int,int,str", &y, &x, &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000429 return NULL;
430 use_xy = TRUE;
431 break;
432 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000433 if (!PyArg_Parse(args,"(iisl);int,int,str,attr", &y, &x, &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000434 return NULL;
435 use_xy = use_attr = TRUE;
436 break;
437 default:
438 PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
439 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000440 }
Guido van Rossum85738471995-02-17 13:50:17 +0000441
Guido van Rossumf6971e21994-08-30 12:25:20 +0000442 if (use_attr == TRUE) {
443 attr_old = getattrs(self->win);
444 wattrset(self->win,attr);
445 }
446 if (use_xy == TRUE)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000447 rtn = mvwaddstr(self->win,y,x,str);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000448 else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000449 rtn = waddstr(self->win,str);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000450 if (use_attr == TRUE)
451 wattrset(self->win,attr_old);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000452 return PyCursesCheckERR(rtn, "addstr");
453}
Guido van Rossum85738471995-02-17 13:50:17 +0000454
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000455static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000456PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000457{
458 int rtn, x, y, n;
459 char *str;
460 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
461 int use_xy = FALSE, use_attr = FALSE;
462
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000463 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000464 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000465 if (!PyArg_Parse(args,"(si);str,n", &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000466 return NULL;
467 break;
468 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000469 if (!PyArg_Parse(args,"(sil);str,n,attr", &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000470 return NULL;
471 use_attr = TRUE;
472 break;
473 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000474 if (!PyArg_Parse(args,"(iisi);y,x,str,n", &y, &x, &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000475 return NULL;
476 use_xy = TRUE;
477 break;
478 case 5:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000479 if (!PyArg_Parse(args,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000480 return NULL;
481 use_xy = use_attr = TRUE;
482 break;
483 default:
484 PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
485 return NULL;
486 }
487
488 if (use_attr == TRUE) {
489 attr_old = getattrs(self->win);
490 wattrset(self->win,attr);
491 }
492 if (use_xy == TRUE)
493 rtn = mvwaddnstr(self->win,y,x,str,n);
494 else
495 rtn = waddnstr(self->win,str,n);
496 if (use_attr == TRUE)
497 wattrset(self->win,attr_old);
498 return PyCursesCheckERR(rtn, "addnstr");
499}
500
501static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000502PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000503{
504 PyObject *temp;
505 chtype bkgd;
506 attr_t attr = A_NORMAL;
507
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000508 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000509 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000510 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000511 return NULL;
512 break;
513 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000514 if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000515 return NULL;
516 break;
517 default:
518 PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
519 return NULL;
520 }
521
522 if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
523 PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
524 return NULL;
525 }
526
527 return PyCursesCheckERR(wbkgd(self->win, bkgd | A_NORMAL), "bkgd");
528}
529
530static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000531PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000532{
533 PyObject *temp;
534 chtype bkgd;
535 attr_t attr = A_NORMAL;
536
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000537 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000538 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000539 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000540 return NULL;
541 break;
542 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000543 if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000544 return NULL;
545 break;
546 default:
547 PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
548 return NULL;
549 }
550
551 if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000552 PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000553 return NULL;
554 }
555
556 wbkgdset(self->win, bkgd | attr);
557 return PyCursesCheckERR(0, "bkgdset");
558}
559
560static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000561PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000562{
563 chtype ls, rs, ts, bs, tl, tr, bl, br;
564 ls = rs = ts = bs = tl = tr = bl = br = 0;
565 if (!PyArg_Parse(args,"|llllllll;ls,rs,ts,bs,tl,tr,bl,br",
566 &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br))
567 return NULL;
568 wborder(self->win, ls, rs, ts, bs, tl, tr, bl, br);
569 Py_INCREF(Py_None);
570 return Py_None;
571}
572
573static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000574PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000575{
576 chtype ch1=0,ch2=0;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000577 if (!PyArg_NoArgs(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000578 PyErr_Clear();
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000579 if (!PyArg_Parse(args,"(ll);vertint,horint", &ch1, &ch2))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000580 return NULL;
581 }
582 box(self->win,ch1,ch2);
583 Py_INCREF(Py_None);
584 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000585}
586
587static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000588PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000589{
590 int rtn;
591 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000592
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000593 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000594 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000595 rtn = wdelch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000596 break;
597 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000598 if (!PyArg_Parse(args,"(ii);y,x", &y, &x))
Guido van Rossum85738471995-02-17 13:50:17 +0000599 return NULL;
600 rtn = mvwdelch(self->win,y,x);
601 break;
602 default:
603 PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
604 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000605 }
Guido van Rossum85738471995-02-17 13:50:17 +0000606 return PyCursesCheckERR(rtn, "[mv]wdelch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000607}
608
609static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000610PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000611{
612 WINDOW *win;
613 int nlines, ncols, begin_y, begin_x;
614
615 nlines = 0;
616 ncols = 0;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000617 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000618 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000619 if (!PyArg_Parse(args,"(ii);begin_y,begin_x",&begin_y,&begin_x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000620 return NULL;
621 break;
622 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000623 if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000624 &nlines,&ncols,&begin_y,&begin_x))
625 return NULL;
626 break;
627 default:
628 PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
629 return NULL;
630 }
631
632 win = derwin(self->win,nlines,ncols,begin_y,begin_x);
633
634 if (win == NULL) {
635 PyErr_SetString(PyCursesError, catchall_NULL);
636 return NULL;
637 }
638
639 return (PyObject *)PyCursesWindow_New(win);
640}
641
642static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000643PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000644{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000645 PyObject *temp;
646 chtype ch;
647 attr_t attr = A_NORMAL;
Guido van Rossum85738471995-02-17 13:50:17 +0000648
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000649 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000650 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000651 if (!PyArg_Parse(args,"O;ch or int", &temp))
Guido van Rossum85738471995-02-17 13:50:17 +0000652 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +0000653 break;
654 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000655 if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
Guido van Rossum85738471995-02-17 13:50:17 +0000656 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +0000657 break;
658 default:
659 PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000660
661
Guido van Rossum85738471995-02-17 13:50:17 +0000662 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000663 }
Guido van Rossum85738471995-02-17 13:50:17 +0000664
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000665 if (!PyCurses_ConvertToChtype(temp, &ch)) {
666 PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
Guido van Rossum85738471995-02-17 13:50:17 +0000667 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000668 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000669
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000670#if !defined(__NetBSD__)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000671 if (self->win->_flags & _ISPAD)
672 return PyCursesCheckERR(pechochar(self->win, ch | attr),
673 "echochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000674 else
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000675#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000676 return PyCursesCheckERR(wechochar(self->win, ch | attr),
677 "echochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000678}
679
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000680#ifdef NCURSES_MOUSE_VERSION
681static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000682PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000683{
684 int x, y;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000685 if (!PyArg_Parse(args,"(ii);y,x", &y, &x))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000686 return NULL;
687
688 return PyInt_FromLong( wenclose(self->win,y,x) );
689}
690#endif
691
Guido van Rossumf6971e21994-08-30 12:25:20 +0000692static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000693PyCursesWindow_GetBkgd(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000694{
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000695 if (!PyArg_NoArgs(args))
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000696 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000697 return PyInt_FromLong((long) getbkgd(self->win));
Guido van Rossumf6971e21994-08-30 12:25:20 +0000698}
699
700static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000701PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000702{
703 int x, y;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000704 chtype rtn;
Guido van Rossum85738471995-02-17 13:50:17 +0000705
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000706 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000707 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000708 Py_BEGIN_ALLOW_THREADS
Guido van Rossumf6971e21994-08-30 12:25:20 +0000709 rtn = wgetch(self->win);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000710 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000711 break;
712 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000713 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000714 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000715 Py_BEGIN_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000716 rtn = mvwgetch(self->win,y,x);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000717 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000718 break;
719 default:
720 PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
721 return NULL;
722 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000723 return PyInt_FromLong(rtn);
724}
Guido van Rossum85738471995-02-17 13:50:17 +0000725
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000726static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000727PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000728{
729 int x, y;
730 chtype rtn;
731
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000732 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000733 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000734 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000735 rtn = wgetch(self->win);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000736 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000737 break;
738 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000739 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000740 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000741 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000742 rtn = mvwgetch(self->win,y,x);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000743 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000744 break;
745 default:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000746 PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000747 return NULL;
748 }
749 if (rtn<=255)
750 return Py_BuildValue("c", rtn);
751 else
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000752#if defined(__NetBSD__)
753 return PyString_FromString(unctrl(rtn));
754#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000755 return PyString_FromString((char *)keyname(rtn));
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000756#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000757}
758
759static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000760PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000761{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000762 int x, y, n;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000763 char rtn[1024]; /* This should be big enough.. I hope */
764 int rtn2;
Guido van Rossum85738471995-02-17 13:50:17 +0000765
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000766 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000767 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000768 Py_BEGIN_ALLOW_THREADS
Guido van Rossumf6971e21994-08-30 12:25:20 +0000769 rtn2 = wgetstr(self->win,rtn);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000770 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000771 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000772 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000773 if (!PyArg_Parse(args,"i;n", &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000774 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000775 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000776 rtn2 = wgetnstr(self->win,rtn,n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000777 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000778 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000779 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000780 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000781 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000782 Py_BEGIN_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000783 rtn2 = mvwgetstr(self->win,y,x,rtn);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000784 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000785 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000786 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000787 if (!PyArg_Parse(args,"(iii);y,x,n", &y, &x, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000788 return NULL;
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000789#ifdef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000790 /* Untested */
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000791 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000792 rtn2 = wmove(self->win,y,x)==ERR ? ERR :
793 wgetnstr(self->win, rtn, n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000794 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000795#else
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000796 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000797 rtn2 = mvwgetnstr(self->win, y, x, rtn, n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000798 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000799#endif
800 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000801 default:
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000802 PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 2 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000803 return NULL;
804 }
Guido van Rossumf6971e21994-08-30 12:25:20 +0000805 if (rtn2 == ERR)
806 rtn[0] = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000807 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000808}
809
810static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000811PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000812{
813 PyObject *temp;
814 chtype ch;
815 int n, x, y, code = OK;
816 attr_t attr = A_NORMAL;
817
818 switch (ARG_COUNT(args)) {
819 case 2:
820 if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n))
821 return NULL;
822 break;
823 case 3:
824 if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr))
825 return NULL;
826 break;
827 case 4:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000828 if (!PyArg_Parse(args, "(iiOi);y,x,ch or int,n", &y, &x, &temp, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000829 return NULL;
830 code = wmove(self->win, y, x);
831 break;
832 case 5:
833 if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr",
834 &y, &x, &temp, &n, &attr))
835 return NULL;
836 code = wmove(self->win, y, x);
837 default:
838 PyErr_SetString(PyExc_TypeError, "hline requires 2 or 5 arguments");
839 return NULL;
840 }
841
842 if (code != ERR) {
843 if (!PyCurses_ConvertToChtype(temp, &ch)) {
844 PyErr_SetString(PyExc_TypeError,
845 "argument 1 or 3 must be a ch or an int");
846 return NULL;
847 }
848 return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
849 } else
850 return PyCursesCheckERR(code, "wmove");
851}
852
853static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000854PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000855{
856 int rtn, x, y, use_xy = FALSE;
857 PyObject *temp;
858 chtype ch = 0;
859 attr_t attr = A_NORMAL;
860
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000861 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000862 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000863 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000864 return NULL;
865 break;
866 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000867 if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000868 return NULL;
869 break;
870 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000871 if (!PyArg_Parse(args,"(iiO);y,x,ch or int", &y, &x, &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000872 return NULL;
873 use_xy = TRUE;
874 break;
875 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000876 if (!PyArg_Parse(args,"(iiOl);y,x,ch or int, attr", &y, &x, &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000877 return NULL;
878 use_xy = TRUE;
879 break;
880 default:
881 PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
882 return NULL;
883 }
884
885 if (!PyCurses_ConvertToChtype(temp, &ch)) {
886 PyErr_SetString(PyExc_TypeError,
887 "argument 1 or 3 must be a ch or an int");
888 return NULL;
889 }
890
891 if (use_xy == TRUE)
892 rtn = mvwinsch(self->win,y,x, ch | attr);
893 else {
894 rtn = winsch(self->win, ch | attr);
895 }
896 return PyCursesCheckERR(rtn, "insch");
897}
898
899static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000900PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000901{
Guido van Rossum85738471995-02-17 13:50:17 +0000902 int x, y, rtn;
903
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000904 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000905 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000906 rtn = winch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000907 break;
908 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000909 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000910 return NULL;
911 rtn = mvwinch(self->win,y,x);
912 break;
913 default:
914 PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
915 return NULL;
916 }
Guido van Rossum85738471995-02-17 13:50:17 +0000917 return PyInt_FromLong((long) rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000918}
919
920static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000921PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000922{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000923 int x, y, n;
924 char rtn[1024]; /* This should be big enough.. I hope */
925 int rtn2;
926
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000927 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000928 case 0:
929 rtn2 = winstr(self->win,rtn);
930 break;
931 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000932 if (!PyArg_Parse(args,"i;n", &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000933 return NULL;
934 rtn2 = winnstr(self->win,rtn,n);
935 break;
936 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000937 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000938 return NULL;
939 rtn2 = mvwinstr(self->win,y,x,rtn);
940 break;
941 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000942 if (!PyArg_Parse(args, "(iii);y,x,n", &y, &x, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000943 return NULL;
944 rtn2 = mvwinnstr(self->win, y, x, rtn, n);
945 break;
946 default:
947 PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000948 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000949 }
950 if (rtn2 == ERR)
951 rtn[0] = 0;
952 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000953}
954
955static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000956PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000957{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000958 int rtn;
959 int x, y;
960 char *str;
961 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
962 int use_xy = FALSE, use_attr = FALSE;
963
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000964 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000965 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000966 if (!PyArg_Parse(args,"s;str", &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000967 return NULL;
968 break;
969 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000970 if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000971 return NULL;
972 use_attr = TRUE;
973 break;
974 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000975 if (!PyArg_Parse(args,"(iis);y,x,str", &y, &x, &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000976 return NULL;
977 use_xy = TRUE;
978 break;
979 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000980 if (!PyArg_Parse(args,"(iisl);y,x,str,attr", &y, &x, &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000981 return NULL;
982 use_xy = use_attr = TRUE;
983 break;
984 default:
985 PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000986 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000987 }
988
989 if (use_attr == TRUE) {
990 attr_old = getattrs(self->win);
991 wattrset(self->win,attr);
992 }
993 if (use_xy == TRUE)
994 rtn = mvwinsstr(self->win,y,x,str);
995 else
996 rtn = winsstr(self->win,str);
997 if (use_attr == TRUE)
998 wattrset(self->win,attr_old);
999 return PyCursesCheckERR(rtn, "insstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001000}
1001
1002static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001003PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001004{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001005 int rtn, x, y, n;
1006 char *str;
1007 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
1008 int use_xy = FALSE, use_attr = FALSE;
1009
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001010 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001011 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001012 if (!PyArg_Parse(args,"(si);str,n", &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001013 return NULL;
1014 break;
1015 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001016 if (!PyArg_Parse(args,"(sil);str,n,attr", &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001017 return NULL;
1018 use_attr = TRUE;
1019 break;
1020 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001021 if (!PyArg_Parse(args,"(iisi);y,x,str,n", &y, &x, &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001022 return NULL;
1023 use_xy = TRUE;
1024 break;
1025 case 5:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001026 if (!PyArg_Parse(args,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001027 return NULL;
1028 use_xy = use_attr = TRUE;
1029 break;
1030 default:
1031 PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001032 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001033 }
1034
1035 if (use_attr == TRUE) {
1036 attr_old = getattrs(self->win);
1037 wattrset(self->win,attr);
1038 }
1039 if (use_xy == TRUE)
1040 rtn = mvwinsnstr(self->win,y,x,str,n);
1041 else
1042 rtn = winsnstr(self->win,str,n);
1043 if (use_attr == TRUE)
1044 wattrset(self->win,attr_old);
1045 return PyCursesCheckERR(rtn, "insnstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001046}
1047
1048static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001049PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001050{
1051 int line, erg;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001052 if (!PyArg_Parse(args,"i;line", &line))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001053 return NULL;
1054 erg = is_linetouched(self->win, line);
1055 if (erg == ERR) {
1056 PyErr_SetString(PyExc_TypeError,
1057 "is_linetouched: line number outside of boundaries");
1058 return NULL;
1059 } else
1060 if (erg == FALSE) {
1061 Py_INCREF(Py_False);
1062 return Py_False;
1063 } else {
1064 Py_INCREF(Py_True);
1065 return Py_True;
1066 }
1067}
1068
1069static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001070PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001071{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001072 int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001073 int rtn;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001074
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001075#if defined(__NetBSD__)
1076 if (0) {
1077#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001078 if (self->win->_flags & _ISPAD) {
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001079#endif
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001080 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001081 case 6:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001082 if (!PyArg_Parse(args,
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001083 "(iiiiii);" \
1084 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1085 &pminrow, &pmincol, &sminrow,
1086 &smincol, &smaxrow, &smaxcol))
1087 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001088 Py_BEGIN_ALLOW_THREADS
1089 rtn = pnoutrefresh(self->win,
1090 pminrow, pmincol, sminrow,
Andrew M. Kuchlingb6e46872000-06-27 15:01:10 +00001091 smincol, smaxrow, smaxcol);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001092 Py_END_ALLOW_THREADS
1093 return PyCursesCheckERR(rtn, "pnoutrefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001094 default:
1095 PyErr_SetString(PyCursesError,
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001096 "noutrefresh() called for a pad "
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001097 "requires 6 arguments");
1098 return NULL;
1099 }
1100 } else {
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001101 if (!PyArg_NoArgs(args))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001102 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001103
1104 Py_BEGIN_ALLOW_THREADS
1105 rtn = wnoutrefresh(self->win);
1106 Py_END_ALLOW_THREADS
1107 return PyCursesCheckERR(rtn, "wnoutrefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001108 }
1109}
1110
1111static PyObject *
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +00001112PyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args)
1113{
1114 PyCursesWindowObject *temp;
1115 int use_copywin = FALSE;
1116 int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
1117 int rtn;
1118
1119 switch (ARG_COUNT(args)) {
1120 case 1:
1121 if (!PyArg_ParseTuple(args, "O!;window object",
1122 &PyCursesWindow_Type, &temp))
1123 return NULL;
1124 break;
1125 case 7:
1126 if (!PyArg_ParseTuple(args, "(O!iiiiii);window object, int, int, int, int, int, int",
1127 &PyCursesWindow_Type, &temp, &sminrow, &smincol,
1128 &dminrow, &dmincol, &dmaxrow, &dmaxcol))
1129 return NULL;
1130 use_copywin = TRUE;
1131 break;
1132 default:
1133 PyErr_SetString(PyExc_TypeError,
1134 "overlay requires one or seven arguments");
1135 return NULL;
1136 }
1137
1138 if (use_copywin == TRUE) {
1139 rtn = copywin(self->win, temp->win, sminrow, smincol,
1140 dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
1141 return PyCursesCheckERR(rtn, "copywin");
1142 }
1143 else {
1144 rtn = overlay(self->win, temp->win);
1145 return PyCursesCheckERR(rtn, "overlay");
1146 }
1147}
1148
1149static PyObject *
1150PyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args)
1151{
1152 PyCursesWindowObject *temp;
1153 int use_copywin = FALSE;
1154 int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
1155 int rtn;
1156
1157 switch (ARG_COUNT(args)) {
1158 case 1:
1159 if (!PyArg_ParseTuple(args, "O!;window object",
1160 &PyCursesWindow_Type, &temp))
1161 return NULL;
1162 break;
1163 case 7:
1164 if (!PyArg_ParseTuple(args, "(O!iiiiii);window object, int, int, int, int, int, int",
1165 &PyCursesWindow_Type, &temp, &sminrow, &smincol,
1166 &dminrow, &dmincol, &dmaxrow, &dmaxcol))
1167 return NULL;
1168 use_copywin = TRUE;
1169 break;
1170 default:
1171 PyErr_SetString(PyExc_TypeError,
1172 "overwrite requires one or seven arguments");
1173 return NULL;
1174 }
1175
1176 if (use_copywin == TRUE) {
1177 rtn = copywin(self->win, temp->win, sminrow, smincol,
1178 dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
1179 return PyCursesCheckERR(rtn, "copywin");
1180 }
1181 else {
1182 rtn = overwrite(self->win, temp->win);
1183 return PyCursesCheckERR(rtn, "overwrite");
1184 }
1185}
1186
1187static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001188PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001189{
1190 PyObject *temp;
1191
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001192 if (!PyArg_Parse(args, "O;fileobj", &temp))
Guido van Rossum85738471995-02-17 13:50:17 +00001193 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001194 if (!PyFile_Check(temp)) {
1195 PyErr_SetString(PyExc_TypeError, "argument must be a file object");
1196 return NULL;
1197 }
1198 return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)),
1199 "putwin");
1200}
1201
1202static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001203PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001204{
1205 int beg, num;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001206 if (!PyArg_Parse(args,"(ii);beg,num", &beg, &num))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001207 return NULL;
1208 return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
1209}
1210
1211static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001212PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001213{
1214 int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001215 int rtn;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001216
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001217#if defined(__NetBSD__)
1218 if (0) {
1219#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001220 if (self->win->_flags & _ISPAD) {
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001221#endif
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001222 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001223 case 6:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001224 if (!PyArg_Parse(args,
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001225 "(iiiiii);" \
1226 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1227 &pminrow, &pmincol, &sminrow,
1228 &smincol, &smaxrow, &smaxcol))
1229 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001230
1231 Py_BEGIN_ALLOW_THREADS
1232 rtn = prefresh(self->win,
1233 pminrow, pmincol, sminrow,
Andrew M. Kuchlingb6e46872000-06-27 15:01:10 +00001234 smincol, smaxrow, smaxcol);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001235 Py_END_ALLOW_THREADS
1236 return PyCursesCheckERR(rtn, "prefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001237 default:
1238 PyErr_SetString(PyCursesError,
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001239 "refresh() for a pad requires 6 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001240 return NULL;
1241 }
1242 } else {
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001243 if (!PyArg_NoArgs(args))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001244 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001245 Py_BEGIN_ALLOW_THREADS
1246 rtn = wrefresh(self->win);
1247 Py_END_ALLOW_THREADS
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001248 return PyCursesCheckERR(rtn, "prefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001249 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001250}
1251
1252static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001253PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001254{
1255 int x, y;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001256 if (!PyArg_Parse(args,"(ii);top, bottom",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +00001257 return NULL;
1258 return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001259}
1260
1261static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001262PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001263{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001264 WINDOW *win;
1265 int nlines, ncols, begin_y, begin_x;
1266
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001267 nlines = 0;
1268 ncols = 0;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001269 switch (ARG_COUNT(args)) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001270 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001271 if (!PyArg_Parse(args,"(ii);begin_y,begin_x",&begin_y,&begin_x))
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001272 return NULL;
1273 break;
1274 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001275 if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001276 &nlines,&ncols,&begin_y,&begin_x))
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001277 return NULL;
1278 break;
1279 default:
1280 PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001281 return NULL;
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001282 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001283
Andrew M. Kuchling8353f622000-07-26 18:36:27 +00001284 /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001285#if !defined(__NetBSD__)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001286 if (self->win->_flags & _ISPAD)
1287 win = subpad(self->win, nlines, ncols, begin_y, begin_x);
1288 else
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001289#endif
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001290 win = subwin(self->win, nlines, ncols, begin_y, begin_x);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001291
1292 if (win == NULL) {
1293 PyErr_SetString(PyCursesError, catchall_NULL);
1294 return NULL;
1295 }
1296
1297 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001298}
1299
1300static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001301PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001302{
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001303 int nlines;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001304 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001305 case 0:
1306 return PyCursesCheckERR(scroll(self->win), "scroll");
1307 break;
1308 case 1:
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001309 if (!PyArg_Parse(args, "i;nlines", &nlines))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001310 return NULL;
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001311 return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001312 default:
1313 PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001314 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001315 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001316}
1317
1318static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001319PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001320{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001321 int st, cnt, val;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001322 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001323 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001324 if (!PyArg_Parse(args,"(ii);start,count",&st,&cnt))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001325 return NULL;
1326 return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
1327 break;
1328 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001329 if (!PyArg_Parse(args, "(iii);start,count,val", &st, &cnt, &val))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001330 return NULL;
1331 return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
1332 default:
1333 PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001334 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001335 }
1336}
1337
1338static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001339PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001340{
1341 PyObject *temp;
1342 chtype ch;
1343 int n, x, y, code = OK;
1344 attr_t attr = A_NORMAL;
1345
1346 switch (ARG_COUNT(args)) {
1347 case 2:
1348 if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n))
1349 return NULL;
1350 break;
1351 case 3:
1352 if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr))
1353 return NULL;
1354 break;
1355 case 4:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001356 if (!PyArg_Parse(args, "(iiOi);y,x,ch or int,n", &y, &x, &temp, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001357 return NULL;
1358 code = wmove(self->win, y, x);
1359 break;
1360 case 5:
1361 if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr",
1362 &y, &x, &temp, &n, &attr))
1363 return NULL;
1364 code = wmove(self->win, y, x);
1365 default:
1366 PyErr_SetString(PyExc_TypeError, "vline requires 2 or 5 arguments");
1367 return NULL;
1368 }
1369
1370 if (code != ERR) {
1371 if (!PyCurses_ConvertToChtype(temp, &ch)) {
1372 PyErr_SetString(PyExc_TypeError,
1373 "argument 1 or 3 must be a ch or an int");
1374 return NULL;
1375 }
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001376 return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001377 } else
1378 return PyCursesCheckERR(code, "wmove");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001379}
1380
1381static PyMethodDef PyCursesWindow_Methods[] = {
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001382 {"addch", (PyCFunction)PyCursesWindow_AddCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001383 {"addnstr", (PyCFunction)PyCursesWindow_AddNStr},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001384 {"addstr", (PyCFunction)PyCursesWindow_AddStr},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001385 {"attroff", (PyCFunction)PyCursesWindow_wattroff},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001386 {"attron", (PyCFunction)PyCursesWindow_wattron},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001387 {"attrset", (PyCFunction)PyCursesWindow_wattrset},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001388 {"bkgd", (PyCFunction)PyCursesWindow_Bkgd},
1389 {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001390 {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
1391 {"box", (PyCFunction)PyCursesWindow_Box},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001392 {"clear", (PyCFunction)PyCursesWindow_wclear},
1393 {"clearok", (PyCFunction)PyCursesWindow_clearok},
1394 {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot},
1395 {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol},
1396 {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup},
1397 {"delch", (PyCFunction)PyCursesWindow_DelCh},
1398 {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln},
1399 {"derwin", (PyCFunction)PyCursesWindow_DerWin},
1400 {"echochar", (PyCFunction)PyCursesWindow_EchoChar},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001401#ifdef NCURSES_MOUSE_VERSION
1402 {"enclose", (PyCFunction)PyCursesWindow_Enclose},
1403#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001404 {"erase", (PyCFunction)PyCursesWindow_werase},
1405 {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx},
1406 {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001407 {"getch", (PyCFunction)PyCursesWindow_GetCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001408 {"getkey", (PyCFunction)PyCursesWindow_GetKey},
1409 {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx},
1410 {"getparyx", (PyCFunction)PyCursesWindow_getparyx},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001411 {"getstr", (PyCFunction)PyCursesWindow_GetStr},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001412 {"getyx", (PyCFunction)PyCursesWindow_getyx},
1413 {"hline", (PyCFunction)PyCursesWindow_Hline},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001414 {"idcok", (PyCFunction)PyCursesWindow_idcok},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001415 {"idlok", (PyCFunction)PyCursesWindow_idlok},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001416 {"immedok", (PyCFunction)PyCursesWindow_immedok},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001417 {"inch", (PyCFunction)PyCursesWindow_InCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001418 {"insch", (PyCFunction)PyCursesWindow_InsCh},
1419 {"insdelln", (PyCFunction)PyCursesWindow_winsdelln},
1420 {"insertln", (PyCFunction)PyCursesWindow_winsertln},
1421 {"insnstr", (PyCFunction)PyCursesWindow_InsNStr},
1422 {"insstr", (PyCFunction)PyCursesWindow_InsStr},
1423 {"instr", (PyCFunction)PyCursesWindow_InStr},
1424 {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched},
1425 {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched},
1426 {"keypad", (PyCFunction)PyCursesWindow_keypad},
1427 {"leaveok", (PyCFunction)PyCursesWindow_leaveok},
1428 {"move", (PyCFunction)PyCursesWindow_wmove},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001429 {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001430 {"mvwin", (PyCFunction)PyCursesWindow_mvwin},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001431 {"nodelay", (PyCFunction)PyCursesWindow_nodelay},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001432 {"notimeout", (PyCFunction)PyCursesWindow_notimeout},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001433 {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
Andrew M. Kuchlinga98e92b2000-08-20 23:37:02 +00001434 /* Backward compatibility alias -- remove in Python 2.1 */
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +00001435 {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
1436 {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS},
1437 {"overwrite", (PyCFunction)PyCursesWindow_Overwrite, METH_VARARGS},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001438 {"putwin", (PyCFunction)PyCursesWindow_PutWin},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001439 {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001440 {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001441 {"refresh", (PyCFunction)PyCursesWindow_Refresh},
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +00001442#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001443 {"resize", (PyCFunction)PyCursesWindow_wresize},
1444#endif
1445 {"scroll", (PyCFunction)PyCursesWindow_Scroll},
1446 {"scrollok", (PyCFunction)PyCursesWindow_scrollok},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001447 {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001448 {"standend", (PyCFunction)PyCursesWindow_wstandend},
1449 {"standout", (PyCFunction)PyCursesWindow_wstandout},
1450 {"subpad", (PyCFunction)PyCursesWindow_SubWin},
1451 {"subwin", (PyCFunction)PyCursesWindow_SubWin},
1452 {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown},
1453 {"syncok", (PyCFunction)PyCursesWindow_syncok},
1454 {"syncup", (PyCFunction)PyCursesWindow_wsyncup},
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00001455 {"timeout", (PyCFunction)PyCursesWindow_wtimeout},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001456 {"touchline", (PyCFunction)PyCursesWindow_TouchLine},
1457 {"touchwin", (PyCFunction)PyCursesWindow_touchwin},
1458 {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin},
1459 {"vline", (PyCFunction)PyCursesWindow_Vline},
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001460 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00001461};
1462
1463static PyObject *
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00001464PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001465{
Guido van Rossuma597dde1995-01-10 20:56:29 +00001466 return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001467}
1468
Guido van Rossumf6971e21994-08-30 12:25:20 +00001469/* -------------------------------------------------------*/
Guido van Rossum85738471995-02-17 13:50:17 +00001470
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001471PyTypeObject PyCursesWindow_Type = {
Guido van Rossum6915c4d2001-01-19 00:28:08 +00001472 PyObject_HEAD_INIT(NULL)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001473 0, /*ob_size*/
1474 "curses window", /*tp_name*/
1475 sizeof(PyCursesWindowObject), /*tp_basicsize*/
1476 0, /*tp_itemsize*/
1477 /* methods */
1478 (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
1479 0, /*tp_print*/
1480 (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
1481 (setattrfunc)0, /*tp_setattr*/
1482 0, /*tp_compare*/
1483 0, /*tp_repr*/
1484 0, /*tp_as_number*/
1485 0, /*tp_as_sequence*/
1486 0, /*tp_as_mapping*/
1487 0, /*tp_hash*/
1488};
1489
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001490/*********************************************************************
1491 Global Functions
1492**********************************************************************/
Guido van Rossumf6971e21994-08-30 12:25:20 +00001493
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001494NoArgNoReturnFunction(beep)
1495NoArgNoReturnFunction(def_prog_mode)
1496NoArgNoReturnFunction(def_shell_mode)
1497NoArgNoReturnFunction(doupdate)
1498NoArgNoReturnFunction(endwin)
1499NoArgNoReturnFunction(flash)
1500NoArgNoReturnFunction(nocbreak)
1501NoArgNoReturnFunction(noecho)
1502NoArgNoReturnFunction(nonl)
1503NoArgNoReturnFunction(noraw)
1504NoArgNoReturnFunction(reset_prog_mode)
1505NoArgNoReturnFunction(reset_shell_mode)
1506NoArgNoReturnFunction(resetty)
1507NoArgNoReturnFunction(savetty)
1508
1509NoArgOrFlagNoReturnFunction(cbreak)
1510NoArgOrFlagNoReturnFunction(echo)
1511NoArgOrFlagNoReturnFunction(nl)
1512NoArgOrFlagNoReturnFunction(raw)
1513
1514NoArgReturnIntFunction(baudrate)
1515NoArgReturnIntFunction(termattrs)
1516
1517NoArgReturnStringFunction(termname)
1518NoArgReturnStringFunction(longname)
1519
1520NoArgTrueFalseFunction(can_change_color)
1521NoArgTrueFalseFunction(has_colors)
1522NoArgTrueFalseFunction(has_ic)
1523NoArgTrueFalseFunction(has_il)
1524NoArgTrueFalseFunction(isendwin)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001525NoArgNoReturnVoidFunction(filter)
1526NoArgNoReturnVoidFunction(flushinp)
1527NoArgNoReturnVoidFunction(noqiflush)
1528
1529static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001530PyCurses_Color_Content(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001531{
1532 short color,r,g,b;
1533
1534 PyCursesInitialised
1535 PyCursesInitialisedColor
1536
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001537 if (ARG_COUNT(args) != 1) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001538 PyErr_SetString(PyExc_TypeError,
1539 "color_content requires 1 argument");
1540 return NULL;
1541 }
1542
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001543 if (!PyArg_Parse(args, "h;color", &color)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001544
1545 if (color_content(color, &r, &g, &b) != ERR)
1546 return Py_BuildValue("(iii)", r, g, b);
1547 else {
1548 PyErr_SetString(PyCursesError,
1549 "Argument 1 was out of range. Check value of COLORS.");
1550 return NULL;
1551 }
1552}
1553
1554static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001555PyCurses_color_pair(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001556{
1557 int n;
1558
1559 PyCursesInitialised
1560 PyCursesInitialisedColor
1561
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001562 if (ARG_COUNT(args) != 1) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001563 PyErr_SetString(PyExc_TypeError, "color_pair requires 1 argument");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001564 return NULL;
1565 }
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001566 if (!PyArg_Parse(args, "i;number", &n)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001567 return PyInt_FromLong((long) (n << 8));
1568}
1569
1570static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001571PyCurses_Curs_Set(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001572{
1573 int vis,erg;
1574
1575 PyCursesInitialised
1576
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001577 if (ARG_COUNT(args)!=1) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001578 PyErr_SetString(PyExc_TypeError, "curs_set requires 1 argument");
1579 return NULL;
1580 }
1581
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001582 if (!PyArg_Parse(args, "i;int", &vis)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001583
1584 erg = curs_set(vis);
1585 if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
1586
1587 return PyInt_FromLong((long) erg);
1588}
1589
1590static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001591PyCurses_Delay_Output(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001592{
1593 int ms;
1594
1595 PyCursesInitialised
1596
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001597 if (ARG_COUNT(args) != 1) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001598 PyErr_SetString(PyExc_TypeError, "delay_output requires 1 argument");
1599 return NULL;
1600 }
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001601 if (!PyArg_Parse(args, "i;ms", &ms)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001602
1603 return PyCursesCheckERR(delay_output(ms), "delay_output");
1604}
1605
1606static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001607PyCurses_EraseChar(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001608{
1609 char ch;
1610
1611 PyCursesInitialised
1612
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001613 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001614
1615 ch = erasechar();
1616
1617 return PyString_FromString(&ch);
1618}
1619
1620static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001621PyCurses_getsyx(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001622{
1623 int x,y;
1624
1625 PyCursesInitialised
1626
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001627 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001628
1629 getsyx(y, x);
1630
1631 return Py_BuildValue("(ii)", y, x);
1632}
1633
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001634#ifdef NCURSES_MOUSE_VERSION
1635static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001636PyCurses_GetMouse(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001637{
1638 int rtn;
1639 MEVENT event;
1640
1641 PyCursesInitialised
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001642 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001643
1644 rtn = getmouse( &event );
1645 if (rtn == ERR) {
1646 PyErr_SetString(PyCursesError, "getmouse() returned ERR");
1647 return NULL;
1648 }
1649 return Py_BuildValue("(hiiil)",
1650 (short)event.id,
1651 event.x, event.y, event.z,
1652 (long) event.bstate);
1653}
1654
1655static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001656PyCurses_UngetMouse(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001657{
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001658 MEVENT event;
1659
1660 PyCursesInitialised
1661 if (!PyArg_ParseTuple(args, "(hiiil)",
1662 &event.id,
1663 &event.x, &event.y, &event.z,
1664 (int *) &event.bstate))
1665 return NULL;
1666
1667 return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
1668}
1669#endif
1670
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001671static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001672PyCurses_GetWin(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001673{
1674 WINDOW *win;
1675 PyObject *temp;
1676
1677 PyCursesInitialised
1678
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001679 if (!PyArg_Parse(args, "O;fileobj", &temp)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001680
1681 if (!PyFile_Check(temp)) {
1682 PyErr_SetString(PyExc_TypeError, "argument must be a file object");
1683 return NULL;
1684 }
1685
1686 win = getwin(PyFile_AsFile(temp));
1687
1688 if (win == NULL) {
1689 PyErr_SetString(PyCursesError, catchall_NULL);
1690 return NULL;
1691 }
1692
1693 return PyCursesWindow_New(win);
1694}
1695
1696static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001697PyCurses_HalfDelay(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001698{
1699 unsigned char tenths;
1700
1701 PyCursesInitialised
1702
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001703 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001704 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001705 if (!PyArg_Parse(args, "b;tenths", &tenths)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001706 break;
1707 default:
1708 PyErr_SetString(PyExc_TypeError, "halfdelay requires 1 argument");
1709 return NULL;
1710 }
1711
1712 return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
1713}
1714
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00001715#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001716 /* No has_key! */
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001717static PyObject * PyCurses_has_key(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001718{
1719 int ch;
1720
1721 PyCursesInitialised
1722
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001723 if (!PyArg_Parse(args,"i",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001724
1725 if (has_key(ch) == FALSE) {
1726 Py_INCREF(Py_False);
1727 return Py_False;
1728 }
1729 Py_INCREF(Py_True);
1730 return Py_True;
1731}
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00001732#endif /* STRICT_SYSV_CURSES */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001733
1734static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001735PyCurses_Init_Color(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001736{
1737 short color, r, g, b;
1738
1739 PyCursesInitialised
1740 PyCursesInitialisedColor
1741
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001742 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001743 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001744 if (!PyArg_Parse(args, "(hhhh);color,r,g,b", &color, &r, &g, &b)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001745 break;
1746 default:
1747 PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
1748 return NULL;
1749 }
1750
1751 return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
1752}
1753
1754static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001755PyCurses_Init_Pair(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001756{
1757 short pair, f, b;
1758
1759 PyCursesInitialised
1760 PyCursesInitialisedColor
1761
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001762 if (ARG_COUNT(args) != 3) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001763 PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
1764 return NULL;
1765 }
1766
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001767 if (!PyArg_Parse(args, "(hhh);pair, f, b", &pair, &f, &b)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001768
1769 return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
1770}
1771
Andrew M. Kuchling32552682000-12-22 21:52:27 +00001772static PyObject *ModDict;
1773
Guido van Rossumf6971e21994-08-30 12:25:20 +00001774static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001775PyCurses_InitScr(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001776{
Guido van Rossum56bf2351994-08-31 22:06:24 +00001777 WINDOW *win;
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001778 PyObject *nlines, *cols;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001779
1780 if (!PyArg_NoArgs(args)) return NULL;
1781
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001782 if (initialised == TRUE) {
Guido van Rossumf6971e21994-08-30 12:25:20 +00001783 wrefresh(stdscr);
1784 return (PyObject *)PyCursesWindow_New(stdscr);
1785 }
Guido van Rossum56bf2351994-08-31 22:06:24 +00001786
1787 win = initscr();
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001788
Guido van Rossum85738471995-02-17 13:50:17 +00001789 if (win == NULL) {
1790 PyErr_SetString(PyCursesError, catchall_NULL);
1791 return NULL;
1792 }
1793
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00001794 initialised = initialised_setupterm = TRUE;
Guido van Rossum56bf2351994-08-31 22:06:24 +00001795
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001796/* This was moved from initcurses() because it core dumped on SGI,
1797 where they're not defined until you've called initscr() */
1798#define SetDictInt(string,ch) \
1799 PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
1800
1801 /* Here are some graphic symbols you can use */
1802 SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
1803 SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
1804 SetDictInt("ACS_URCORNER", (ACS_URCORNER));
1805 SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
1806 SetDictInt("ACS_LTEE", (ACS_LTEE));
1807 SetDictInt("ACS_RTEE", (ACS_RTEE));
1808 SetDictInt("ACS_BTEE", (ACS_BTEE));
1809 SetDictInt("ACS_TTEE", (ACS_TTEE));
1810 SetDictInt("ACS_HLINE", (ACS_HLINE));
1811 SetDictInt("ACS_VLINE", (ACS_VLINE));
1812 SetDictInt("ACS_PLUS", (ACS_PLUS));
1813 SetDictInt("ACS_S1", (ACS_S1));
1814 SetDictInt("ACS_S9", (ACS_S9));
1815 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
1816 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
1817 SetDictInt("ACS_DEGREE", (ACS_DEGREE));
1818 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
1819 SetDictInt("ACS_BULLET", (ACS_BULLET));
1820 SetDictInt("ACS_LARROW", (ACS_LARROW));
1821 SetDictInt("ACS_RARROW", (ACS_RARROW));
1822 SetDictInt("ACS_DARROW", (ACS_DARROW));
1823 SetDictInt("ACS_UARROW", (ACS_UARROW));
1824 SetDictInt("ACS_BOARD", (ACS_BOARD));
1825 SetDictInt("ACS_LANTERN", (ACS_LANTERN));
1826 SetDictInt("ACS_BLOCK", (ACS_BLOCK));
1827 SetDictInt("ACS_BSSB", (ACS_ULCORNER));
1828 SetDictInt("ACS_SSBB", (ACS_LLCORNER));
1829 SetDictInt("ACS_BBSS", (ACS_URCORNER));
1830 SetDictInt("ACS_SBBS", (ACS_LRCORNER));
1831 SetDictInt("ACS_SBSS", (ACS_RTEE));
1832 SetDictInt("ACS_SSSB", (ACS_LTEE));
1833 SetDictInt("ACS_SSBS", (ACS_BTEE));
1834 SetDictInt("ACS_BSSS", (ACS_TTEE));
1835 SetDictInt("ACS_BSBS", (ACS_HLINE));
1836 SetDictInt("ACS_SBSB", (ACS_VLINE));
1837 SetDictInt("ACS_SSSS", (ACS_PLUS));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001838
1839 /* The following are never available with strict SYSV curses */
1840#ifdef ACS_S3
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001841 SetDictInt("ACS_S3", (ACS_S3));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001842#endif
1843#ifdef ACS_S7
1844 SetDictInt("ACS_S7", (ACS_S7));
1845#endif
1846#ifdef ACS_LEQUAL
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001847 SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001848#endif
1849#ifdef ACS_GEQUAL
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001850 SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001851#endif
1852#ifdef ACS_PI
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001853 SetDictInt("ACS_PI", (ACS_PI));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001854#endif
1855#ifdef ACS_NEQUAL
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001856 SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001857#endif
1858#ifdef ACS_STERLING
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001859 SetDictInt("ACS_STERLING", (ACS_STERLING));
1860#endif
1861
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001862 nlines = PyInt_FromLong((long) LINES);
1863 PyDict_SetItemString(ModDict, "LINES", nlines);
1864 Py_DECREF(nlines);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001865 cols = PyInt_FromLong((long) COLS);
1866 PyDict_SetItemString(ModDict, "COLS", cols);
1867 Py_DECREF(cols);
Guido van Rossum56bf2351994-08-31 22:06:24 +00001868
1869 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001870}
1871
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00001872static PyObject *
1873PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
1874{
1875 int fd = -1;
1876 int err;
1877 char* termstr = NULL;
1878
1879 static char *kwlist[] = {"term", "fd", NULL};
1880
1881 if (!PyArg_ParseTupleAndKeywords(
1882 args,keywds,"|zi:setupterm",kwlist,&termstr,&fd)) {
1883 return NULL;
1884 }
1885
1886 if (fd == -1) {
1887 PyObject* sys_stdout;
1888
1889 sys_stdout = PySys_GetObject("stdout");
1890
1891 if (sys_stdout == NULL) {
1892 PyErr_SetString(
1893 PyCursesError,
1894 "lost sys.stdout");
1895 return NULL;
1896 }
1897
1898 fd = PyObject_AsFileDescriptor(sys_stdout);
1899
1900 if (fd == -1) {
1901 return NULL;
1902 }
1903 }
1904
1905 if (setupterm(termstr,fd,&err) == ERR) {
1906 char* s = "setupterm: unknown error";
1907
1908 if (err == 0) {
1909 s = "setupterm: could not find terminal";
1910 } else if (err == -1) {
1911 s = "setupterm: could not find terminfo database";
1912 }
1913
1914 PyErr_SetString(PyCursesError,s);
1915 return NULL;
1916 }
1917
1918 initialised_setupterm = TRUE;
1919
1920 Py_INCREF(Py_None);
1921 return Py_None;
1922}
Guido van Rossumf6971e21994-08-30 12:25:20 +00001923
1924static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001925PyCurses_IntrFlush(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001926{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001927 int ch;
1928
1929 PyCursesInitialised
1930
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001931 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001932 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001933 if (!PyArg_Parse(args,"i;True(1), False(0)",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001934 break;
1935 default:
1936 PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00001937 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001938 }
1939
1940 return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
1941}
1942
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001943#if !defined(__NetBSD__)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001944static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001945PyCurses_KeyName(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001946{
1947 const char *knp;
1948 int ch;
1949
1950 PyCursesInitialised
1951
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001952 if (!PyArg_Parse(args,"i",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001953
1954 knp = keyname(ch);
1955
1956 return PyString_FromString((knp == NULL) ? "" : (char *)knp);
1957}
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001958#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001959
1960static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001961PyCurses_KillChar(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001962{
1963 char ch;
1964
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001965 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001966
1967 ch = killchar();
1968
1969 return PyString_FromString(&ch);
1970}
1971
1972static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001973PyCurses_Meta(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001974{
1975 int ch;
1976
1977 PyCursesInitialised
1978
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001979 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001980 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001981 if (!PyArg_Parse(args,"i;True(1), False(0)",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001982 break;
1983 default:
1984 PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
1985 return NULL;
1986 }
1987
1988 return PyCursesCheckERR(meta(stdscr, ch), "meta");
1989}
1990
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001991#ifdef NCURSES_MOUSE_VERSION
1992static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001993PyCurses_MouseInterval(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001994{
1995 int interval;
1996 PyCursesInitialised
1997
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001998 if (!PyArg_Parse(args,"i;interval",&interval))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001999 return NULL;
2000 return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
2001}
2002
2003static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002004PyCurses_MouseMask(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002005{
Andrew M. Kuchling1a104002000-07-06 18:14:03 +00002006 int newmask;
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002007 mmask_t oldmask, availmask;
2008
2009 PyCursesInitialised
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002010 if (!PyArg_Parse(args,"i;mousemask",&newmask))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002011 return NULL;
2012 availmask = mousemask(newmask, &oldmask);
2013 return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
2014}
2015#endif
2016
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002017static PyObject *
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +00002018PyCurses_Napms(PyObject *self, PyObject *args)
2019{
2020 int ms;
2021
2022 PyCursesInitialised
2023 if (!PyArg_Parse(args, "i;ms", &ms)) return NULL;
2024
2025 return Py_BuildValue("i", napms(ms));
2026}
2027
2028
2029static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002030PyCurses_NewPad(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002031{
2032 WINDOW *win;
2033 int nlines, ncols;
2034
2035 PyCursesInitialised
2036
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002037 if (!PyArg_Parse(args,"(ii);nlines,ncols",&nlines,&ncols)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002038
2039 win = newpad(nlines, ncols);
2040
2041 if (win == NULL) {
2042 PyErr_SetString(PyCursesError, catchall_NULL);
2043 return NULL;
2044 }
2045
2046 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002047}
2048
2049static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002050PyCurses_NewWindow(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002051{
2052 WINDOW *win;
2053 int nlines, ncols, begin_y, begin_x;
Guido van Rossum85738471995-02-17 13:50:17 +00002054
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002055 PyCursesInitialised
2056
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002057 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +00002058 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002059 if (!PyArg_Parse(args,"(ii);nlines,ncols",&nlines,&ncols))
Guido van Rossum85738471995-02-17 13:50:17 +00002060 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002061 win = newpad(nlines, ncols);
Guido van Rossum85738471995-02-17 13:50:17 +00002062 break;
2063 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002064 if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
Guido van Rossumf6971e21994-08-30 12:25:20 +00002065 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +00002066 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002067 win = newwin(nlines,ncols,begin_y,begin_x);
Guido van Rossum85738471995-02-17 13:50:17 +00002068 break;
2069 default:
2070 PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
2071 return NULL;
2072 }
2073
Guido van Rossumf6971e21994-08-30 12:25:20 +00002074 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +00002075 PyErr_SetString(PyCursesError, catchall_NULL);
2076 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002077 }
Guido van Rossum85738471995-02-17 13:50:17 +00002078
Guido van Rossumf6971e21994-08-30 12:25:20 +00002079 return (PyObject *)PyCursesWindow_New(win);
2080}
2081
2082static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002083PyCurses_Pair_Content(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002084{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002085 short pair,f,b;
2086
2087 PyCursesInitialised
2088 PyCursesInitialisedColor
2089
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002090 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002091 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002092 if (!PyArg_Parse(args, "h;pair", &pair)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002093 break;
2094 default:
2095 PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00002096 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002097 }
2098
2099 if (!pair_content(pair, &f, &b)) {
2100 PyErr_SetString(PyCursesError,
2101 "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
2102 return NULL;
2103 }
2104
2105 return Py_BuildValue("(ii)", f, b);
2106}
2107
2108static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002109PyCurses_pair_number(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002110{
2111 int n;
2112
2113 PyCursesInitialised
2114 PyCursesInitialisedColor
2115
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002116 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002117 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002118 if (!PyArg_Parse(args, "i;pairvalue", &n)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002119 break;
2120 default:
2121 PyErr_SetString(PyExc_TypeError,
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002122 "pair_number requires 1 argument");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002123 return NULL;
2124 }
2125
2126 return PyInt_FromLong((long) ((n & A_COLOR) >> 8));
2127}
2128
2129static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002130PyCurses_Putp(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002131{
2132 char *str;
2133
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002134 if (!PyArg_Parse(args,"s;str", &str)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002135 return PyCursesCheckERR(putp(str), "putp");
2136}
2137
2138static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002139PyCurses_QiFlush(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002140{
2141 int flag = 0;
2142
2143 PyCursesInitialised
2144
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002145 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002146 case 0:
2147 qiflush();
2148 Py_INCREF(Py_None);
2149 return Py_None;
2150 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002151 if (!PyArg_Parse(args, "i;True(1) or False(0)", &flag)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002152 if (flag) qiflush();
2153 else noqiflush();
2154 Py_INCREF(Py_None);
2155 return Py_None;
2156 default:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002157 PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002158 return NULL;
2159 }
2160}
2161
2162static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002163PyCurses_setsyx(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002164{
2165 int y,x;
2166
2167 PyCursesInitialised
2168
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002169 if (ARG_COUNT(args)!=2) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002170 PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002171 return NULL;
2172 }
2173
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002174 if (!PyArg_Parse(args, "(ii);y, x", &y, &x)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002175
2176 setsyx(y,x);
2177
Guido van Rossumf6971e21994-08-30 12:25:20 +00002178 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00002179 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002180}
2181
2182static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002183PyCurses_Start_Color(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002184{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002185 int code;
2186 PyObject *c, *cp;
2187
2188 PyCursesInitialised
2189
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002190 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002191
2192 code = start_color();
2193 if (code != ERR) {
2194 initialisedcolors = TRUE;
2195 c = PyInt_FromLong((long) COLORS);
2196 PyDict_SetItemString(ModDict, "COLORS", c);
2197 Py_DECREF(c);
2198 cp = PyInt_FromLong((long) COLOR_PAIRS);
2199 PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
2200 Py_DECREF(cp);
2201 Py_INCREF(Py_None);
2202 return Py_None;
2203 } else {
2204 PyErr_SetString(PyCursesError, "start_color() returned ERR");
Guido van Rossum85738471995-02-17 13:50:17 +00002205 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002206 }
2207}
2208
2209static PyObject *
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002210PyCurses_tigetflag(PyObject *self, PyObject *args)
2211{
2212 char *capname;
2213
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002214 PyCursesSetupTermCalled;
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002215
2216 if (!PyArg_ParseTuple(args, "z", &capname))
2217 return NULL;
2218
2219 return PyInt_FromLong( (long) tigetflag( capname ) );
2220}
2221
2222static PyObject *
2223PyCurses_tigetnum(PyObject *self, PyObject *args)
2224{
2225 char *capname;
2226
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002227 PyCursesSetupTermCalled;
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002228
2229 if (!PyArg_ParseTuple(args, "z", &capname))
2230 return NULL;
2231
2232 return PyInt_FromLong( (long) tigetnum( capname ) );
2233}
2234
2235static PyObject *
2236PyCurses_tigetstr(PyObject *self, PyObject *args)
2237{
2238 char *capname;
2239
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002240 PyCursesSetupTermCalled;
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002241
2242 if (!PyArg_ParseTuple(args, "z", &capname))
2243 return NULL;
2244
2245 capname = tigetstr( capname );
2246 if (capname == 0 || capname == (char*) -1) {
2247 Py_INCREF(Py_None);
2248 return Py_None;
2249 }
2250 return PyString_FromString( capname );
2251}
2252
2253static PyObject *
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002254PyCurses_tparm(PyObject *self, PyObject *args)
2255{
2256 char* fmt;
2257 char* result = NULL;
2258 int i1,i2,i3,i4,i5,i6,i7,i8,i9;
2259
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002260 PyCursesSetupTermCalled;
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002261
2262 if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
2263 &fmt, &i1, &i2, &i3, &i4,
2264 &i5, &i6, &i7, &i8, &i9)) {
2265 return NULL;
2266 }
2267
2268 switch (PyTuple_GET_SIZE(args)) {
2269 case 1:
2270 result = tparm(fmt);
2271 break;
2272 case 2:
2273 result = tparm(fmt,i1);
2274 break;
2275 case 3:
2276 result = tparm(fmt,i1,i2);
2277 break;
2278 case 4:
2279 result = tparm(fmt,i1,i2,i3);
2280 break;
2281 case 5:
2282 result = tparm(fmt,i1,i2,i3,i4);
2283 break;
2284 case 6:
2285 result = tparm(fmt,i1,i2,i3,i4,i5);
2286 break;
2287 case 7:
2288 result = tparm(fmt,i1,i2,i3,i4,i5,i6);
2289 break;
2290 case 8:
2291 result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7);
2292 break;
2293 case 9:
2294 result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8);
2295 break;
2296 case 10:
2297 result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9);
2298 break;
2299 }
2300
2301 return PyString_FromString(result);
2302}
2303
2304static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002305PyCurses_TypeAhead(PyObject *self, PyObject *args)
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002306{
Andrew M. Kuchling1a104002000-07-06 18:14:03 +00002307 int fd;
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002308
2309 PyCursesInitialised
2310
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002311 if (!PyArg_Parse(args,"i;fd",&fd)) return NULL;
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002312
2313 PyCursesCheckERR(typeahead( fd ), "typeahead");
2314 Py_INCREF(Py_None);
2315 return Py_None;
2316}
2317
2318static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002319PyCurses_UnCtrl(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002320{
2321 PyObject *temp;
2322 chtype ch;
2323
2324 PyCursesInitialised
2325
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002326 if (!PyArg_Parse(args,"O;ch or int",&temp)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002327
2328 if (PyInt_Check(temp))
2329 ch = (chtype) PyInt_AsLong(temp);
2330 else if (PyString_Check(temp))
2331 ch = (chtype) *PyString_AsString(temp);
2332 else {
2333 PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
2334 return NULL;
2335 }
2336
2337 return PyString_FromString(unctrl(ch));
Guido van Rossumf6971e21994-08-30 12:25:20 +00002338}
2339
2340static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002341PyCurses_UngetCh(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002342{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002343 PyObject *temp;
2344 chtype ch;
2345
2346 PyCursesInitialised
2347
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002348 if (!PyArg_Parse(args,"O;ch or int",&temp)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002349
2350 if (PyInt_Check(temp))
2351 ch = (chtype) PyInt_AsLong(temp);
2352 else if (PyString_Check(temp))
2353 ch = (chtype) *PyString_AsString(temp);
2354 else {
2355 PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
Guido van Rossum85738471995-02-17 13:50:17 +00002356 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002357 }
2358
Guido van Rossum85738471995-02-17 13:50:17 +00002359 return PyCursesCheckERR(ungetch(ch), "ungetch");
Guido van Rossumf6971e21994-08-30 12:25:20 +00002360}
2361
2362static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002363PyCurses_Use_Env(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002364{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002365 int flag;
2366
2367 PyCursesInitialised
2368
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002369 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002370 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002371 if (!PyArg_Parse(args,"i;True(1), False(0)",&flag))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002372 return NULL;
2373 break;
2374 default:
2375 PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00002376 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002377 }
2378 use_env(flag);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002379 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00002380 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002381}
2382
Guido van Rossumf6971e21994-08-30 12:25:20 +00002383/* List of functions defined in the module */
2384
2385static PyMethodDef PyCurses_methods[] = {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002386 {"baudrate", (PyCFunction)PyCurses_baudrate},
2387 {"beep", (PyCFunction)PyCurses_beep},
2388 {"can_change_color", (PyCFunction)PyCurses_can_change_color},
2389 {"cbreak", (PyCFunction)PyCurses_cbreak},
2390 {"color_content", (PyCFunction)PyCurses_Color_Content},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002391 {"color_pair", (PyCFunction)PyCurses_color_pair},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002392 {"curs_set", (PyCFunction)PyCurses_Curs_Set},
2393 {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode},
2394 {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode},
2395 {"delay_output", (PyCFunction)PyCurses_Delay_Output},
2396 {"doupdate", (PyCFunction)PyCurses_doupdate},
2397 {"echo", (PyCFunction)PyCurses_echo},
2398 {"endwin", (PyCFunction)PyCurses_endwin},
2399 {"erasechar", (PyCFunction)PyCurses_EraseChar},
2400 {"filter", (PyCFunction)PyCurses_filter},
2401 {"flash", (PyCFunction)PyCurses_flash},
2402 {"flushinp", (PyCFunction)PyCurses_flushinp},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002403#ifdef NCURSES_MOUSE_VERSION
2404 {"getmouse", (PyCFunction)PyCurses_GetMouse},
2405 {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
2406#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002407 {"getsyx", (PyCFunction)PyCurses_getsyx},
2408 {"getwin", (PyCFunction)PyCurses_GetWin},
2409 {"has_colors", (PyCFunction)PyCurses_has_colors},
2410 {"has_ic", (PyCFunction)PyCurses_has_ic},
2411 {"has_il", (PyCFunction)PyCurses_has_il},
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00002412#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002413 {"has_key", (PyCFunction)PyCurses_has_key},
Guido van Rossumf6971e21994-08-30 12:25:20 +00002414#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002415 {"halfdelay", (PyCFunction)PyCurses_HalfDelay},
2416 {"init_color", (PyCFunction)PyCurses_Init_Color},
2417 {"init_pair", (PyCFunction)PyCurses_Init_Pair},
2418 {"initscr", (PyCFunction)PyCurses_InitScr},
2419 {"intrflush", (PyCFunction)PyCurses_IntrFlush},
2420 {"isendwin", (PyCFunction)PyCurses_isendwin},
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002421#if !defined(__NetBSD__)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002422 {"keyname", (PyCFunction)PyCurses_KeyName},
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002423#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002424 {"killchar", (PyCFunction)PyCurses_KillChar},
2425 {"longname", (PyCFunction)PyCurses_longname},
2426 {"meta", (PyCFunction)PyCurses_Meta},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002427#ifdef NCURSES_MOUSE_VERSION
2428 {"mouseinterval", (PyCFunction)PyCurses_MouseInterval},
2429 {"mousemask", (PyCFunction)PyCurses_MouseMask},
2430#endif
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +00002431 {"napms", (PyCFunction)PyCurses_Napms},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002432 {"newpad", (PyCFunction)PyCurses_NewPad},
2433 {"newwin", (PyCFunction)PyCurses_NewWindow},
2434 {"nl", (PyCFunction)PyCurses_nl},
2435 {"nocbreak", (PyCFunction)PyCurses_nocbreak},
2436 {"noecho", (PyCFunction)PyCurses_noecho},
2437 {"nonl", (PyCFunction)PyCurses_nonl},
2438 {"noqiflush", (PyCFunction)PyCurses_noqiflush},
2439 {"noraw", (PyCFunction)PyCurses_noraw},
2440 {"pair_content", (PyCFunction)PyCurses_Pair_Content},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002441 {"pair_number", (PyCFunction)PyCurses_pair_number},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002442 {"putp", (PyCFunction)PyCurses_Putp},
2443 {"qiflush", (PyCFunction)PyCurses_QiFlush},
2444 {"raw", (PyCFunction)PyCurses_raw},
2445 {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode},
2446 {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode},
Andrew M. Kuchling1a104002000-07-06 18:14:03 +00002447 {"resetty", (PyCFunction)PyCurses_resetty},
2448 {"savetty", (PyCFunction)PyCurses_savetty},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002449 {"setsyx", (PyCFunction)PyCurses_setsyx},
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002450 {"setupterm", (PyCFunction)PyCurses_setupterm, METH_VARARGS|METH_KEYWORDS},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002451 {"start_color", (PyCFunction)PyCurses_Start_Color},
2452 {"termattrs", (PyCFunction)PyCurses_termattrs},
2453 {"termname", (PyCFunction)PyCurses_termname},
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002454 {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
2455 {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
2456 {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002457 {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS},
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002458 {"typeahead", (PyCFunction)PyCurses_TypeAhead},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002459 {"unctrl", (PyCFunction)PyCurses_UnCtrl},
2460 {"ungetch", (PyCFunction)PyCurses_UngetCh},
2461 {"use_env", (PyCFunction)PyCurses_Use_Env},
2462 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00002463};
2464
2465/* Initialization function for the module */
2466
Guido van Rossum6915c4d2001-01-19 00:28:08 +00002467DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00002468init_curses(void)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002469{
Andrew M. Kuchling32552682000-12-22 21:52:27 +00002470 PyObject *m, *d, *v, *c_api_object;
2471 static void *PyCurses_API[PyCurses_API_pointers];
2472
Guido van Rossum6915c4d2001-01-19 00:28:08 +00002473 /* Initialize object type */
2474 PyCursesWindow_Type.ob_type = &PyType_Type;
2475
Andrew M. Kuchling32552682000-12-22 21:52:27 +00002476 /* Initialize the C API pointer array */
2477 PyCurses_API[0] = (void *)&PyCursesWindow_Type;
2478 PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
2479 PyCurses_API[2] = (void *)func_PyCursesInitialised;
2480 PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002481
2482 /* Create the module and add the functions */
Andrew M. Kuchlingb7f198e2000-06-10 23:12:32 +00002483 m = Py_InitModule("_curses", PyCurses_methods);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002484
Guido van Rossumf6971e21994-08-30 12:25:20 +00002485 /* Add some symbolic constants to the module */
2486 d = PyModule_GetDict(m);
Andrew M. Kuchling32552682000-12-22 21:52:27 +00002487 ModDict = d; /* For PyCurses_InitScr to use later */
2488
2489 /* Add a CObject for the C API */
2490 c_api_object = PyCObject_FromVoidPtr((void *)PyCurses_API, NULL);
2491 PyDict_SetItemString(d, "_C_API", c_api_object);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00002492
Guido van Rossum85738471995-02-17 13:50:17 +00002493 /* For exception curses.error */
Fred Drake589c35b2000-07-06 19:38:49 +00002494 PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
Guido van Rossum85738471995-02-17 13:50:17 +00002495 PyDict_SetItemString(d, "error", PyCursesError);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00002496
Guido van Rossum85738471995-02-17 13:50:17 +00002497 /* Make the version available */
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00002498 v = PyString_FromString(PyCursesVersion);
2499 PyDict_SetItemString(d, "version", v);
2500 PyDict_SetItemString(d, "__version__", v);
2501 Py_DECREF(v);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002502
Andrew M. Kuchlingcaefb372000-12-26 15:57:01 +00002503 SetDictInt("ERR", ERR);
2504 SetDictInt("OK", OK);
2505
Guido van Rossumf6971e21994-08-30 12:25:20 +00002506 /* Here are some attributes you can add to chars to print */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002507
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002508 SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002509 SetDictInt("A_NORMAL", A_NORMAL);
2510 SetDictInt("A_STANDOUT", A_STANDOUT);
2511 SetDictInt("A_UNDERLINE", A_UNDERLINE);
2512 SetDictInt("A_REVERSE", A_REVERSE);
2513 SetDictInt("A_BLINK", A_BLINK);
2514 SetDictInt("A_DIM", A_DIM);
2515 SetDictInt("A_BOLD", A_BOLD);
2516 SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002517#if !defined(__NetBSD__)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002518 SetDictInt("A_INVIS", A_INVIS);
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002519#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002520 SetDictInt("A_PROTECT", A_PROTECT);
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002521 SetDictInt("A_CHARTEXT", A_CHARTEXT);
2522 SetDictInt("A_COLOR", A_COLOR);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002523
2524 /* The following are never available with strict SYSV curses */
2525#ifdef A_HORIZONTAL
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002526 SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002527#endif
2528#ifdef A_LEFT
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002529 SetDictInt("A_LEFT", A_LEFT);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002530#endif
2531#ifdef A_LOW
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002532 SetDictInt("A_LOW", A_LOW);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002533#endif
2534#ifdef A_RIGHT
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002535 SetDictInt("A_RIGHT", A_RIGHT);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002536#endif
2537#ifdef A_TOP
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002538 SetDictInt("A_TOP", A_TOP);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002539#endif
2540#ifdef A_VERTICAL
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002541 SetDictInt("A_VERTICAL", A_VERTICAL);
2542#endif
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002543
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002544 SetDictInt("COLOR_BLACK", COLOR_BLACK);
2545 SetDictInt("COLOR_RED", COLOR_RED);
2546 SetDictInt("COLOR_GREEN", COLOR_GREEN);
2547 SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
2548 SetDictInt("COLOR_BLUE", COLOR_BLUE);
2549 SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
2550 SetDictInt("COLOR_CYAN", COLOR_CYAN);
2551 SetDictInt("COLOR_WHITE", COLOR_WHITE);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002552
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002553#ifdef NCURSES_MOUSE_VERSION
2554 /* Mouse-related constants */
2555 SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
2556 SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
2557 SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
2558 SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
2559 SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
2560
2561 SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
2562 SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
2563 SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
2564 SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
2565 SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
2566
2567 SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
2568 SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
2569 SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
2570 SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
2571 SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
2572
2573 SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
2574 SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
2575 SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
2576 SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
2577 SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
2578
2579 SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
2580 SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
2581 SetDictInt("BUTTON_ALT", BUTTON_ALT);
2582
2583 SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
2584 SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
2585#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +00002586 /* Now set everything up for KEY_ variables */
2587 {
2588 int key;
2589 char *key_n;
2590 char *key_n2;
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002591#if !defined(__NetBSD__)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002592 for (key=KEY_MIN;key < KEY_MAX; key++) {
2593 key_n = (char *)keyname(key);
Guido van Rossumf5c6d471995-02-07 15:38:32 +00002594 if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002595 continue;
2596 if (strncmp(key_n,"KEY_F(",6)==0) {
2597 char *p1, *p2;
2598 key_n2 = malloc(strlen(key_n)+1);
2599 p1 = key_n;
2600 p2 = key_n2;
2601 while (*p1) {
2602 if (*p1 != '(' && *p1 != ')') {
2603 *p2 = *p1;
2604 p2++;
2605 }
2606 p1++;
2607 }
2608 *p2 = (char)0;
2609 } else
2610 key_n2 = key_n;
Guido van Rossum85738471995-02-17 13:50:17 +00002611 PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
Guido van Rossumf6971e21994-08-30 12:25:20 +00002612 if (key_n2 != key_n)
2613 free(key_n2);
2614 }
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002615#endif
Guido van Rossum85738471995-02-17 13:50:17 +00002616 SetDictInt("KEY_MIN", KEY_MIN);
2617 SetDictInt("KEY_MAX", KEY_MAX);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002618 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00002619}