blob: 5a7a642691dcd758de507e69cbc6b730d8db998f [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 *
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +000011 * Tidied for Python 1.6, and currently maintained by
12 * <akuchlin@mems-exchange.org>.
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000013 *
14 * Permission is hereby granted, free of charge, to any person obtaining
15 * a copy of this source file to use, copy, modify, merge, or publish it
16 * subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or in any new file that contains a substantial portion of
20 * this file.
21 *
22 * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF
23 * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
24 * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES
25 * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
26 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE
28 * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL,
29 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
30 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR
31 * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
32 * PERFORMANCE OF THIS SOFTWARE.
33 */
Guido van Rossumf6971e21994-08-30 12:25:20 +000034
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000035/* CVS: $Id$ */
Guido van Rossumf6971e21994-08-30 12:25:20 +000036
Andrew M. Kuchlingfb6bbf52000-07-27 11:58:01 +000037/*
38
39A number of SysV or ncurses functions don't have wrappers yet; if you need
40a given function, add it and send a patch. Here's a list of currently
41unsupported functions:
42
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +000043 addchnstr addchstr chgat color_set define_key
Andrew M. Kuchlingfb6bbf52000-07-27 11:58:01 +000044 del_curterm delscreen dupwin inchnstr inchstr innstr keyok
45 mcprint mvaddchnstr mvaddchstr mvchgat mvcur mvinchnstr
46 mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +000047 mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr newterm
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +000048 resizeterm restartterm ripoffline scr_dump
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +000049 scr_init scr_restore scr_set scrl set_curterm set_term setterm
50 tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
51 use_default_colors vidattr vidputs waddchnstr waddchstr wchgat
52 wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
Andrew M. Kuchlingfb6bbf52000-07-27 11:58:01 +000053
54Low-priority:
55 slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
56 slk_attron slk_attrset slk_clear slk_color slk_init slk_label
57 slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
58
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +000059Menu extension (ncurses and probably SYSV):
60 current_item free_item free_menu item_count item_description
61 item_index item_init item_name item_opts item_opts_off
62 item_opts_on item_term item_userptr item_value item_visible
63 menu_back menu_driver menu_fore menu_format menu_grey
64 menu_init menu_items menu_mark menu_opts menu_opts_off
65 menu_opts_on menu_pad menu_pattern menu_request_by_name
66 menu_request_name menu_spacing menu_sub menu_term menu_userptr
67 menu_win new_item new_menu pos_menu_cursor post_menu
68 scale_menu set_current_item set_item_init set_item_opts
69 set_item_term set_item_userptr set_item_value set_menu_back
70 set_menu_fore set_menu_format set_menu_grey set_menu_init
71 set_menu_items set_menu_mark set_menu_opts set_menu_pad
72 set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
73 set_menu_userptr set_menu_win set_top_row top_row unpost_menu
74
75Form extension (ncurses and probably SYSV):
76 current_field data_ahead data_behind dup_field
77 dynamic_fieldinfo field_arg field_back field_buffer
78 field_count field_fore field_index field_info field_init
79 field_just field_opts field_opts_off field_opts_on field_pad
80 field_status field_term field_type field_userptr form_driver
81 form_fields form_init form_opts form_opts_off form_opts_on
82 form_page form_request_by_name form_request_name form_sub
83 form_term form_userptr form_win free_field free_form
84 link_field link_fieldtype move_field new_field new_form
85 new_page pos_form_cursor post_form scale_form
86 set_current_field set_field_back set_field_buffer
87 set_field_fore set_field_init set_field_just set_field_opts
88 set_field_pad set_field_status set_field_term set_field_type
89 set_field_userptr set_fieldtype_arg set_fieldtype_choice
90 set_form_fields set_form_init set_form_opts set_form_page
91 set_form_sub set_form_term set_form_userptr set_form_win
92 set_max_field set_new_page unpost_form
93
94
Andrew M. Kuchlingfb6bbf52000-07-27 11:58:01 +000095 */
96
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000097/* Release Number */
Guido van Rossumf6971e21994-08-30 12:25:20 +000098
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +000099char *PyCursesVersion = "2.2";
Guido van Rossumf6971e21994-08-30 12:25:20 +0000100
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000101/* Includes */
Guido van Rossumf6971e21994-08-30 12:25:20 +0000102
Guido van Rossum602099a1994-09-14 13:32:22 +0000103#include "Python.h"
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000104
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000105#ifdef __osf__
106#define _XOPEN_SOURCE_EXTENDED /* Define macro for OSF/1 */
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +0000107#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000108#endif
109
Martin v. Löwiseb9b1032001-10-24 17:10:49 +0000110#ifdef __hpux
111#define _XOPEN_SOURCE_EXTENDED
112#define STRICT_SYSV_CURSES
113#endif
114
Guido van Rossum858ca0f2001-04-10 19:53:37 +0000115#define CURSES_MODULE
116#include "py_curses.h"
117
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000118/* These prototypes are in <term.h>, but including this header
119 #defines many common symbols (such as "lines") which breaks the
120 curses module in other ways. So the code will just specify
121 explicit prototypes here. */
122extern int setupterm(char *,int,int *);
Fred Drake0368bc42001-07-19 20:48:32 +0000123#ifdef __sgi
124#include <term.h>
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +0000125#endif
126
Martin v. Löwiseb9b1032001-10-24 17:10:49 +0000127#if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun))
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +0000128#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000129typedef chtype attr_t; /* No attr_t type is available */
Guido van Rossum1266a011996-02-25 04:50:31 +0000130#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000131
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000132#if defined(_AIX)
133#define STRICT_SYSV_CURSES
134#endif
135
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000136/* Definition of exception curses.error */
Guido van Rossumf6971e21994-08-30 12:25:20 +0000137
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000138static PyObject *PyCursesError;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000139
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000140/* Tells whether setupterm() has been called to initialise terminfo. */
141static int initialised_setupterm = FALSE;
142
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000143/* Tells whether initscr() has been called to initialise curses. */
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000144static int initialised = FALSE;
145
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000146/* Tells whether start_color() has been called to initialise color usage. */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000147static int initialisedcolors = FALSE;
148
149/* Utility Macros */
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000150#define PyCursesSetupTermCalled \
151 if (initialised_setupterm != TRUE) { \
152 PyErr_SetString(PyCursesError, \
153 "must call (at least) setupterm() first"); \
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000154 return 0; }
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000155
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000156#define PyCursesInitialised \
157 if (initialised != TRUE) { \
158 PyErr_SetString(PyCursesError, \
159 "must call initscr() 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#define PyCursesInitialisedColor \
163 if (initialisedcolors != TRUE) { \
164 PyErr_SetString(PyCursesError, \
165 "must call start_color() first"); \
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000166 return 0; }
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000167
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000168/* Utility Functions */
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000169
Guido van Rossum85738471995-02-17 13:50:17 +0000170/*
171 * Check the return code from a curses function and return None
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000172 * or raise an exception as appropriate. These are exported using the
173 * CObject API.
Guido van Rossum85738471995-02-17 13:50:17 +0000174 */
175
176static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000177PyCursesCheckERR(int code, char *fname)
Guido van Rossum85738471995-02-17 13:50:17 +0000178{
Guido van Rossum85738471995-02-17 13:50:17 +0000179 if (code != ERR) {
180 Py_INCREF(Py_None);
181 return Py_None;
182 } else {
183 if (fname == NULL) {
184 PyErr_SetString(PyCursesError, catchall_ERR);
185 } else {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000186 PyErr_Format(PyCursesError, "%s() returned ERR", fname);
Guido van Rossum85738471995-02-17 13:50:17 +0000187 }
188 return NULL;
189 }
190}
191
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000192static int
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000193PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000194{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000195 if (PyInt_Check(obj)) {
196 *ch = (chtype) PyInt_AsLong(obj);
Martin v. Löwisbfdf4ec2001-06-23 19:58:46 +0000197 } else if(PyString_Check(obj)
198 && (PyString_Size(obj) == 1)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000199 *ch = (chtype) *PyString_AsString(obj);
200 } else {
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000201 return 0;
202 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000203 return 1;
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000204}
205
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000206/* Function versions of the 3 functions for tested whether curses has been
207 initialised or not. */
208
209static int func_PyCursesSetupTermCalled(void)
210{
211 PyCursesSetupTermCalled;
212 return 1;
213}
214
215static int func_PyCursesInitialised(void)
216{
217 PyCursesInitialised;
218 return 1;
219}
220
221static int func_PyCursesInitialisedColor(void)
222{
223 PyCursesInitialisedColor;
224 return 1;
225}
226
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000227/*****************************************************************************
228 The Window Object
229******************************************************************************/
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000230
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000231/* Definition of the window type */
Guido van Rossum85738471995-02-17 13:50:17 +0000232
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000233PyTypeObject PyCursesWindow_Type;
234
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000235/* Function prototype macros for Window object
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000236
237 X - function name
238 TYPE - parameter Type
239 ERGSTR - format string for construction of the return value
240 PARSESTR - format string for argument parsing
241 */
242
243#define Window_NoArgNoReturnFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000244static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
245{ if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000246 return PyCursesCheckERR(X(self->win), # X); }
247
248#define Window_NoArgTrueFalseFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000249static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000250{ \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000251 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000252 if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
253 else { Py_INCREF(Py_True); return Py_True; } }
254
255#define Window_NoArgNoReturnVoidFunction(X) \
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{ \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000258 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000259 X(self->win); Py_INCREF(Py_None); return Py_None; }
260
261#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000262static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000263{ \
264 TYPE arg1, arg2; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000265 if (!PyArg_NoArgs(args)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000266 X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
267
268#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000269static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000270{ \
271 TYPE arg1; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000272 if (!PyArg_Parse(args, PARSESTR, &arg1)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000273 X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
274
275#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000276static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000277{ \
278 TYPE arg1; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000279 if (!PyArg_Parse(args,PARSESTR, &arg1)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000280 return PyCursesCheckERR(X(self->win, arg1), # X); }
281
282#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000283static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000284{ \
285 TYPE arg1, arg2; \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000286 if (!PyArg_Parse(args,PARSESTR, &arg1, &arg2)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000287 return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
Guido van Rossum85738471995-02-17 13:50:17 +0000288
Guido van Rossumf6971e21994-08-30 12:25:20 +0000289/* ------------- WINDOW routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000290
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000291Window_NoArgNoReturnFunction(untouchwin)
292Window_NoArgNoReturnFunction(touchwin)
293Window_NoArgNoReturnFunction(redrawwin)
294Window_NoArgNoReturnFunction(winsertln)
295Window_NoArgNoReturnFunction(werase)
296Window_NoArgNoReturnFunction(wdeleteln)
297
298Window_NoArgTrueFalseFunction(is_wintouched)
299
300Window_NoArgNoReturnVoidFunction(wsyncup)
301Window_NoArgNoReturnVoidFunction(wsyncdown)
302Window_NoArgNoReturnVoidFunction(wstandend)
303Window_NoArgNoReturnVoidFunction(wstandout)
304Window_NoArgNoReturnVoidFunction(wcursyncup)
305Window_NoArgNoReturnVoidFunction(wclrtoeol)
306Window_NoArgNoReturnVoidFunction(wclrtobot)
307Window_NoArgNoReturnVoidFunction(wclear)
308
309Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")
310Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +0000311Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay")
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000312
313Window_NoArg2TupleReturnFunction(getyx, int, "(ii)")
314Window_NoArg2TupleReturnFunction(getbegyx, int, "(ii)")
315Window_NoArg2TupleReturnFunction(getmaxyx, int, "(ii)")
316Window_NoArg2TupleReturnFunction(getparyx, int, "(ii)")
317
318Window_OneArgNoReturnFunction(wattron, attr_t, "l;attr")
319Window_OneArgNoReturnFunction(wattroff, attr_t, "l;attr")
320Window_OneArgNoReturnFunction(wattrset, attr_t, "l;attr")
321Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
322Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000323#if defined(__NetBSD__)
324Window_OneArgNoReturnVoidFunction(keypad, int, "i;True(1) or False(0)")
325#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000326Window_OneArgNoReturnFunction(keypad, 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(leaveok, int, "i;True(1) or False(0)")
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000329#if defined(__NetBSD__)
330Window_OneArgNoReturnVoidFunction(nodelay, int, "i;True(1) or False(0)")
331#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000332Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000333#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000334Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")
335Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000336Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines")
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000337Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
338
339Window_TwoArgNoReturnFunction(mvwin, int, "(ii);y,x")
340Window_TwoArgNoReturnFunction(mvderwin, int, "(ii);y,x")
341Window_TwoArgNoReturnFunction(wmove, int, "(ii);y,x")
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000342#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000343Window_TwoArgNoReturnFunction(wresize, int, "(ii);lines,columns")
344#endif
345
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000346/* Allocation and deallocation of Window Objects */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000347
Guido van Rossumf6971e21994-08-30 12:25:20 +0000348static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000349PyCursesWindow_New(WINDOW *win)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000350{
351 PyCursesWindowObject *wo;
Guido van Rossum85738471995-02-17 13:50:17 +0000352
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000353 wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
354 if (wo == NULL) return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000355 wo->win = win;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000356 return (PyObject *)wo;
357}
358
359static void
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000360PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000361{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000362 if (wo->win != stdscr) delwin(wo->win);
363 PyMem_DEL(wo);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000364}
365
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000366/* Addch, Addstr, Addnstr */
Guido van Rossumf6971e21994-08-30 12:25:20 +0000367
368static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000369PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000370{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000371 int rtn, x, y, use_xy = FALSE;
372 PyObject *temp;
373 chtype ch = 0;
374 attr_t attr = A_NORMAL;
375
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000376 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000377 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000378 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000379 return NULL;
380 break;
381 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000382 if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr))
Guido van Rossum85738471995-02-17 13:50:17 +0000383 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000384 break;
385 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000386 if (!PyArg_Parse(args,"(iiO);y,x,ch or int", &y, &x, &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000387 return NULL;
388 use_xy = TRUE;
389 break;
390 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000391 if (!PyArg_Parse(args,"(iiOl);y,x,ch or int, attr",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000392 &y, &x, &temp, &attr))
393 return NULL;
394 use_xy = TRUE;
395 break;
396 default:
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +0000397 PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000398 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000399 }
Guido van Rossum85738471995-02-17 13:50:17 +0000400
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000401 if (!PyCurses_ConvertToChtype(temp, &ch)) {
402 PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
403 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000404 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000405
Guido van Rossumf6971e21994-08-30 12:25:20 +0000406 if (use_xy == TRUE)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000407 rtn = mvwaddch(self->win,y,x, ch | attr);
408 else {
409 rtn = waddch(self->win, ch | attr);
410 }
411 return PyCursesCheckERR(rtn, "addch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000412}
413
414static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000415PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000416{
417 int rtn;
418 int x, y;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000419 char *str;
420 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
421 int use_xy = FALSE, use_attr = FALSE;
Guido van Rossum85738471995-02-17 13:50:17 +0000422
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000423 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000424 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000425 if (!PyArg_Parse(args,"s;str", &str))
Guido van Rossum85738471995-02-17 13:50:17 +0000426 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000427 break;
428 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000429 if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000430 return NULL;
431 use_attr = TRUE;
432 break;
433 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000434 if (!PyArg_Parse(args,"(iis);int,int,str", &y, &x, &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000435 return NULL;
436 use_xy = TRUE;
437 break;
438 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000439 if (!PyArg_Parse(args,"(iisl);int,int,str,attr", &y, &x, &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000440 return NULL;
441 use_xy = use_attr = TRUE;
442 break;
443 default:
444 PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
445 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000446 }
Guido van Rossum85738471995-02-17 13:50:17 +0000447
Guido van Rossumf6971e21994-08-30 12:25:20 +0000448 if (use_attr == TRUE) {
449 attr_old = getattrs(self->win);
450 wattrset(self->win,attr);
451 }
452 if (use_xy == TRUE)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000453 rtn = mvwaddstr(self->win,y,x,str);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000454 else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000455 rtn = waddstr(self->win,str);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000456 if (use_attr == TRUE)
457 wattrset(self->win,attr_old);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000458 return PyCursesCheckERR(rtn, "addstr");
459}
Guido van Rossum85738471995-02-17 13:50:17 +0000460
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000461static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000462PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000463{
464 int rtn, x, y, n;
465 char *str;
466 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
467 int use_xy = FALSE, use_attr = FALSE;
468
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000469 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000470 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000471 if (!PyArg_Parse(args,"(si);str,n", &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000472 return NULL;
473 break;
474 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000475 if (!PyArg_Parse(args,"(sil);str,n,attr", &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000476 return NULL;
477 use_attr = TRUE;
478 break;
479 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000480 if (!PyArg_Parse(args,"(iisi);y,x,str,n", &y, &x, &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000481 return NULL;
482 use_xy = TRUE;
483 break;
484 case 5:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000485 if (!PyArg_Parse(args,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000486 return NULL;
487 use_xy = use_attr = TRUE;
488 break;
489 default:
490 PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
491 return NULL;
492 }
493
494 if (use_attr == TRUE) {
495 attr_old = getattrs(self->win);
496 wattrset(self->win,attr);
497 }
498 if (use_xy == TRUE)
499 rtn = mvwaddnstr(self->win,y,x,str,n);
500 else
501 rtn = waddnstr(self->win,str,n);
502 if (use_attr == TRUE)
503 wattrset(self->win,attr_old);
504 return PyCursesCheckERR(rtn, "addnstr");
505}
506
507static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000508PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000509{
510 PyObject *temp;
511 chtype bkgd;
512 attr_t attr = A_NORMAL;
513
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000514 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000515 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000516 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000517 return NULL;
518 break;
519 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000520 if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000521 return NULL;
522 break;
523 default:
524 PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
525 return NULL;
526 }
527
528 if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
529 PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
530 return NULL;
531 }
532
Andrew M. Kuchling4a596e32001-09-04 19:34:32 +0000533 return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000534}
535
536static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000537PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000538{
539 PyObject *temp;
540 chtype bkgd;
541 attr_t attr = A_NORMAL;
542
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000543 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000544 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000545 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000546 return NULL;
547 break;
548 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000549 if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000550 return NULL;
551 break;
552 default:
553 PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
554 return NULL;
555 }
556
557 if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000558 PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000559 return NULL;
560 }
561
562 wbkgdset(self->win, bkgd | attr);
563 return PyCursesCheckERR(0, "bkgdset");
564}
565
566static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000567PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000568{
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +0000569 PyObject *temp[8];
570 chtype ch[8];
571 int i;
572
573 /* Clear the array of parameters */
574 for(i=0; i<8; i++) {
575 temp[i] = NULL;
576 ch[i] = 0;
577 }
578
579 if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
580 &temp[0], &temp[1], &temp[2], &temp[3],
581 &temp[4], &temp[5], &temp[6], &temp[7]))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000582 return NULL;
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +0000583
584 for(i=0; i<8; i++) {
585 if (temp[i] != NULL && !PyCurses_ConvertToChtype(temp[i], &ch[i])) {
586 PyErr_Format(PyExc_TypeError,
587 "argument %i must be a ch or an int", i+1);
588 return NULL;
589 }
590 }
591
592 wborder(self->win,
593 ch[0], ch[1], ch[2], ch[3],
594 ch[4], ch[5], ch[6], ch[7]);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000595 Py_INCREF(Py_None);
596 return Py_None;
597}
598
599static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000600PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000601{
602 chtype ch1=0,ch2=0;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000603 if (!PyArg_NoArgs(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000604 PyErr_Clear();
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000605 if (!PyArg_Parse(args,"(ll);vertint,horint", &ch1, &ch2))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000606 return NULL;
607 }
608 box(self->win,ch1,ch2);
609 Py_INCREF(Py_None);
610 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000611}
612
Martin v. Löwiseb9b1032001-10-24 17:10:49 +0000613#if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
614#define py_mvwdelch mvwdelch
615#else
616int py_mvwdelch(WINDOW *w, int y, int x)
617{
618 mvwdelch(w,y,x);
619 /* On HP/UX, mvwdelch already returns. On other systems,
620 we may well run into this return statement. */
621 return 0;
622}
623#endif
624
625
Guido van Rossumf6971e21994-08-30 12:25:20 +0000626static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000627PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000628{
629 int rtn;
630 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000631
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000632 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000633 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000634 rtn = wdelch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000635 break;
636 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000637 if (!PyArg_Parse(args,"(ii);y,x", &y, &x))
Guido van Rossum85738471995-02-17 13:50:17 +0000638 return NULL;
Martin v. Löwiseb9b1032001-10-24 17:10:49 +0000639 rtn = py_mvwdelch(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000640 break;
641 default:
642 PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
643 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000644 }
Guido van Rossum85738471995-02-17 13:50:17 +0000645 return PyCursesCheckERR(rtn, "[mv]wdelch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000646}
647
648static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000649PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000650{
651 WINDOW *win;
652 int nlines, ncols, begin_y, begin_x;
653
654 nlines = 0;
655 ncols = 0;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000656 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000657 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000658 if (!PyArg_Parse(args,"(ii);begin_y,begin_x",&begin_y,&begin_x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000659 return NULL;
660 break;
661 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000662 if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000663 &nlines,&ncols,&begin_y,&begin_x))
664 return NULL;
665 break;
666 default:
667 PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
668 return NULL;
669 }
670
671 win = derwin(self->win,nlines,ncols,begin_y,begin_x);
672
673 if (win == NULL) {
674 PyErr_SetString(PyCursesError, catchall_NULL);
675 return NULL;
676 }
677
678 return (PyObject *)PyCursesWindow_New(win);
679}
680
681static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000682PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000683{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000684 PyObject *temp;
685 chtype ch;
686 attr_t attr = A_NORMAL;
Guido van Rossum85738471995-02-17 13:50:17 +0000687
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000688 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000689 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000690 if (!PyArg_Parse(args,"O;ch or int", &temp))
Guido van Rossum85738471995-02-17 13:50:17 +0000691 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +0000692 break;
693 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000694 if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
Guido van Rossum85738471995-02-17 13:50:17 +0000695 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +0000696 break;
697 default:
698 PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000699
700
Guido van Rossum85738471995-02-17 13:50:17 +0000701 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000702 }
Guido van Rossum85738471995-02-17 13:50:17 +0000703
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000704 if (!PyCurses_ConvertToChtype(temp, &ch)) {
705 PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
Guido van Rossum85738471995-02-17 13:50:17 +0000706 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000707 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000708
Martin v. Löwiseb9b1032001-10-24 17:10:49 +0000709#ifdef WINDOW_HAS_FLAGS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000710 if (self->win->_flags & _ISPAD)
711 return PyCursesCheckERR(pechochar(self->win, ch | attr),
712 "echochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000713 else
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000714#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000715 return PyCursesCheckERR(wechochar(self->win, ch | attr),
716 "echochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000717}
718
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000719#ifdef NCURSES_MOUSE_VERSION
720static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000721PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000722{
723 int x, y;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000724 if (!PyArg_Parse(args,"(ii);y,x", &y, &x))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000725 return NULL;
726
727 return PyInt_FromLong( wenclose(self->win,y,x) );
728}
729#endif
730
Guido van Rossumf6971e21994-08-30 12:25:20 +0000731static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000732PyCursesWindow_GetBkgd(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000733{
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000734 if (!PyArg_NoArgs(args))
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000735 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000736 return PyInt_FromLong((long) getbkgd(self->win));
Guido van Rossumf6971e21994-08-30 12:25:20 +0000737}
738
739static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000740PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000741{
742 int x, y;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000743 chtype rtn;
Guido van Rossum85738471995-02-17 13:50:17 +0000744
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000745 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000746 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000747 Py_BEGIN_ALLOW_THREADS
Guido van Rossumf6971e21994-08-30 12:25:20 +0000748 rtn = wgetch(self->win);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000749 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000750 break;
751 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000752 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000753 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000754 Py_BEGIN_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000755 rtn = mvwgetch(self->win,y,x);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000756 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000757 break;
758 default:
759 PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
760 return NULL;
761 }
Fred Drake0368bc42001-07-19 20:48:32 +0000762 return PyInt_FromLong((long)rtn);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000763}
Guido van Rossum85738471995-02-17 13:50:17 +0000764
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000765static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000766PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000767{
768 int x, y;
769 chtype rtn;
770
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000771 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000772 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000773 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000774 rtn = wgetch(self->win);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000775 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000776 break;
777 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000778 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000779 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000780 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000781 rtn = mvwgetch(self->win,y,x);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000782 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000783 break;
784 default:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000785 PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000786 return NULL;
787 }
788 if (rtn<=255)
789 return Py_BuildValue("c", rtn);
790 else
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000791#if defined(__NetBSD__)
792 return PyString_FromString(unctrl(rtn));
793#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000794 return PyString_FromString((char *)keyname(rtn));
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000795#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000796}
797
798static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000799PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000800{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000801 int x, y, n;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000802 char rtn[1024]; /* This should be big enough.. I hope */
803 int rtn2;
Guido van Rossum85738471995-02-17 13:50:17 +0000804
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000805 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000806 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000807 Py_BEGIN_ALLOW_THREADS
Guido van Rossumf6971e21994-08-30 12:25:20 +0000808 rtn2 = wgetstr(self->win,rtn);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000809 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000810 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000811 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000812 if (!PyArg_Parse(args,"i;n", &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000813 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000814 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000815 rtn2 = wgetnstr(self->win,rtn,n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000816 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000817 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000818 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000819 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000820 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000821 Py_BEGIN_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000822 rtn2 = mvwgetstr(self->win,y,x,rtn);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000823 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000824 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000825 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000826 if (!PyArg_Parse(args,"(iii);y,x,n", &y, &x, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000827 return NULL;
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000828#ifdef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000829 /* Untested */
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000830 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000831 rtn2 = wmove(self->win,y,x)==ERR ? ERR :
832 wgetnstr(self->win, rtn, n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000833 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000834#else
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000835 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000836 rtn2 = mvwgetnstr(self->win, y, x, rtn, n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000837 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000838#endif
839 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000840 default:
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000841 PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 2 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000842 return NULL;
843 }
Guido van Rossumf6971e21994-08-30 12:25:20 +0000844 if (rtn2 == ERR)
845 rtn[0] = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000846 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000847}
848
849static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000850PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000851{
852 PyObject *temp;
853 chtype ch;
854 int n, x, y, code = OK;
855 attr_t attr = A_NORMAL;
856
857 switch (ARG_COUNT(args)) {
858 case 2:
859 if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n))
860 return NULL;
861 break;
862 case 3:
863 if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr))
864 return NULL;
865 break;
866 case 4:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000867 if (!PyArg_Parse(args, "(iiOi);y,x,ch or int,n", &y, &x, &temp, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000868 return NULL;
869 code = wmove(self->win, y, x);
870 break;
871 case 5:
872 if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr",
873 &y, &x, &temp, &n, &attr))
874 return NULL;
875 code = wmove(self->win, y, x);
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +0000876 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000877 default:
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +0000878 PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000879 return NULL;
880 }
881
882 if (code != ERR) {
883 if (!PyCurses_ConvertToChtype(temp, &ch)) {
884 PyErr_SetString(PyExc_TypeError,
885 "argument 1 or 3 must be a ch or an int");
886 return NULL;
887 }
888 return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
889 } else
890 return PyCursesCheckERR(code, "wmove");
891}
892
893static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000894PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000895{
896 int rtn, x, y, use_xy = FALSE;
897 PyObject *temp;
898 chtype ch = 0;
899 attr_t attr = A_NORMAL;
900
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000901 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000902 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000903 if (!PyArg_Parse(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000904 return NULL;
905 break;
906 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000907 if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000908 return NULL;
909 break;
910 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000911 if (!PyArg_Parse(args,"(iiO);y,x,ch or int", &y, &x, &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000912 return NULL;
913 use_xy = TRUE;
914 break;
915 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000916 if (!PyArg_Parse(args,"(iiOl);y,x,ch or int, attr", &y, &x, &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000917 return NULL;
918 use_xy = TRUE;
919 break;
920 default:
921 PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
922 return NULL;
923 }
924
925 if (!PyCurses_ConvertToChtype(temp, &ch)) {
926 PyErr_SetString(PyExc_TypeError,
927 "argument 1 or 3 must be a ch or an int");
928 return NULL;
929 }
930
931 if (use_xy == TRUE)
932 rtn = mvwinsch(self->win,y,x, ch | attr);
933 else {
934 rtn = winsch(self->win, ch | attr);
935 }
936 return PyCursesCheckERR(rtn, "insch");
937}
938
939static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000940PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000941{
Guido van Rossum85738471995-02-17 13:50:17 +0000942 int x, y, rtn;
943
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000944 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000945 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000946 rtn = winch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000947 break;
948 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000949 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000950 return NULL;
951 rtn = mvwinch(self->win,y,x);
952 break;
953 default:
954 PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
955 return NULL;
956 }
Guido van Rossum85738471995-02-17 13:50:17 +0000957 return PyInt_FromLong((long) rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000958}
959
960static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000961PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000962{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000963 int x, y, n;
964 char rtn[1024]; /* This should be big enough.. I hope */
965 int rtn2;
966
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000967 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000968 case 0:
969 rtn2 = winstr(self->win,rtn);
970 break;
971 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000972 if (!PyArg_Parse(args,"i;n", &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000973 return NULL;
974 rtn2 = winnstr(self->win,rtn,n);
975 break;
976 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000977 if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000978 return NULL;
979 rtn2 = mvwinstr(self->win,y,x,rtn);
980 break;
981 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000982 if (!PyArg_Parse(args, "(iii);y,x,n", &y, &x, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000983 return NULL;
984 rtn2 = mvwinnstr(self->win, y, x, rtn, n);
985 break;
986 default:
987 PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000988 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000989 }
990 if (rtn2 == ERR)
991 rtn[0] = 0;
992 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000993}
994
995static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000996PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000997{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000998 int rtn;
999 int x, y;
1000 char *str;
1001 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
1002 int use_xy = FALSE, use_attr = FALSE;
1003
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001004 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001005 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001006 if (!PyArg_Parse(args,"s;str", &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001007 return NULL;
1008 break;
1009 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001010 if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001011 return NULL;
1012 use_attr = TRUE;
1013 break;
1014 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001015 if (!PyArg_Parse(args,"(iis);y,x,str", &y, &x, &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001016 return NULL;
1017 use_xy = TRUE;
1018 break;
1019 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001020 if (!PyArg_Parse(args,"(iisl);y,x,str,attr", &y, &x, &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001021 return NULL;
1022 use_xy = use_attr = TRUE;
1023 break;
1024 default:
1025 PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001026 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001027 }
1028
1029 if (use_attr == TRUE) {
1030 attr_old = getattrs(self->win);
1031 wattrset(self->win,attr);
1032 }
1033 if (use_xy == TRUE)
1034 rtn = mvwinsstr(self->win,y,x,str);
1035 else
1036 rtn = winsstr(self->win,str);
1037 if (use_attr == TRUE)
1038 wattrset(self->win,attr_old);
1039 return PyCursesCheckERR(rtn, "insstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001040}
1041
1042static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001043PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001044{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001045 int rtn, x, y, n;
1046 char *str;
1047 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
1048 int use_xy = FALSE, use_attr = FALSE;
1049
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001050 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001051 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001052 if (!PyArg_Parse(args,"(si);str,n", &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001053 return NULL;
1054 break;
1055 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001056 if (!PyArg_Parse(args,"(sil);str,n,attr", &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001057 return NULL;
1058 use_attr = TRUE;
1059 break;
1060 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001061 if (!PyArg_Parse(args,"(iisi);y,x,str,n", &y, &x, &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001062 return NULL;
1063 use_xy = TRUE;
1064 break;
1065 case 5:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001066 if (!PyArg_Parse(args,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001067 return NULL;
1068 use_xy = use_attr = TRUE;
1069 break;
1070 default:
1071 PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001072 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001073 }
1074
1075 if (use_attr == TRUE) {
1076 attr_old = getattrs(self->win);
1077 wattrset(self->win,attr);
1078 }
1079 if (use_xy == TRUE)
1080 rtn = mvwinsnstr(self->win,y,x,str,n);
1081 else
1082 rtn = winsnstr(self->win,str,n);
1083 if (use_attr == TRUE)
1084 wattrset(self->win,attr_old);
1085 return PyCursesCheckERR(rtn, "insnstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001086}
1087
1088static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001089PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001090{
1091 int line, erg;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001092 if (!PyArg_Parse(args,"i;line", &line))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001093 return NULL;
1094 erg = is_linetouched(self->win, line);
1095 if (erg == ERR) {
1096 PyErr_SetString(PyExc_TypeError,
1097 "is_linetouched: line number outside of boundaries");
1098 return NULL;
1099 } else
1100 if (erg == FALSE) {
1101 Py_INCREF(Py_False);
1102 return Py_False;
1103 } else {
1104 Py_INCREF(Py_True);
1105 return Py_True;
1106 }
1107}
1108
1109static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001110PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001111{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001112 int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001113 int rtn;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001114
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00001115#ifndef WINDOW_HAS_FLAGS
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001116 if (0) {
1117#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001118 if (self->win->_flags & _ISPAD) {
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001119#endif
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001120 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001121 case 6:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001122 if (!PyArg_Parse(args,
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001123 "(iiiiii);" \
1124 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1125 &pminrow, &pmincol, &sminrow,
1126 &smincol, &smaxrow, &smaxcol))
1127 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001128 Py_BEGIN_ALLOW_THREADS
1129 rtn = pnoutrefresh(self->win,
1130 pminrow, pmincol, sminrow,
Andrew M. Kuchlingb6e46872000-06-27 15:01:10 +00001131 smincol, smaxrow, smaxcol);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001132 Py_END_ALLOW_THREADS
1133 return PyCursesCheckERR(rtn, "pnoutrefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001134 default:
1135 PyErr_SetString(PyCursesError,
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001136 "noutrefresh() called for a pad "
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001137 "requires 6 arguments");
1138 return NULL;
1139 }
1140 } else {
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001141 if (!PyArg_NoArgs(args))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001142 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001143
1144 Py_BEGIN_ALLOW_THREADS
1145 rtn = wnoutrefresh(self->win);
1146 Py_END_ALLOW_THREADS
1147 return PyCursesCheckERR(rtn, "wnoutrefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001148 }
1149}
1150
1151static PyObject *
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +00001152PyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args)
1153{
1154 PyCursesWindowObject *temp;
1155 int use_copywin = FALSE;
1156 int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
1157 int rtn;
1158
1159 switch (ARG_COUNT(args)) {
1160 case 1:
1161 if (!PyArg_ParseTuple(args, "O!;window object",
1162 &PyCursesWindow_Type, &temp))
1163 return NULL;
1164 break;
1165 case 7:
1166 if (!PyArg_ParseTuple(args, "(O!iiiiii);window object, int, int, int, int, int, int",
1167 &PyCursesWindow_Type, &temp, &sminrow, &smincol,
1168 &dminrow, &dmincol, &dmaxrow, &dmaxcol))
1169 return NULL;
1170 use_copywin = TRUE;
1171 break;
1172 default:
1173 PyErr_SetString(PyExc_TypeError,
1174 "overlay requires one or seven arguments");
1175 return NULL;
1176 }
1177
1178 if (use_copywin == TRUE) {
1179 rtn = copywin(self->win, temp->win, sminrow, smincol,
1180 dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
1181 return PyCursesCheckERR(rtn, "copywin");
1182 }
1183 else {
1184 rtn = overlay(self->win, temp->win);
1185 return PyCursesCheckERR(rtn, "overlay");
1186 }
1187}
1188
1189static PyObject *
1190PyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args)
1191{
1192 PyCursesWindowObject *temp;
1193 int use_copywin = FALSE;
1194 int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
1195 int rtn;
1196
1197 switch (ARG_COUNT(args)) {
1198 case 1:
1199 if (!PyArg_ParseTuple(args, "O!;window object",
1200 &PyCursesWindow_Type, &temp))
1201 return NULL;
1202 break;
1203 case 7:
1204 if (!PyArg_ParseTuple(args, "(O!iiiiii);window object, int, int, int, int, int, int",
1205 &PyCursesWindow_Type, &temp, &sminrow, &smincol,
1206 &dminrow, &dmincol, &dmaxrow, &dmaxcol))
1207 return NULL;
1208 use_copywin = TRUE;
1209 break;
1210 default:
1211 PyErr_SetString(PyExc_TypeError,
1212 "overwrite requires one or seven arguments");
1213 return NULL;
1214 }
1215
1216 if (use_copywin == TRUE) {
1217 rtn = copywin(self->win, temp->win, sminrow, smincol,
1218 dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
1219 return PyCursesCheckERR(rtn, "copywin");
1220 }
1221 else {
1222 rtn = overwrite(self->win, temp->win);
1223 return PyCursesCheckERR(rtn, "overwrite");
1224 }
1225}
1226
1227static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001228PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001229{
1230 PyObject *temp;
1231
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001232 if (!PyArg_Parse(args, "O;fileobj", &temp))
Guido van Rossum85738471995-02-17 13:50:17 +00001233 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001234 if (!PyFile_Check(temp)) {
1235 PyErr_SetString(PyExc_TypeError, "argument must be a file object");
1236 return NULL;
1237 }
1238 return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)),
1239 "putwin");
1240}
1241
1242static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001243PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001244{
1245 int beg, num;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001246 if (!PyArg_Parse(args,"(ii);beg,num", &beg, &num))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001247 return NULL;
1248 return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
1249}
1250
1251static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001252PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001253{
1254 int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001255 int rtn;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001256
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00001257#ifndef WINDOW_HAS_FLAGS
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001258 if (0) {
1259#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001260 if (self->win->_flags & _ISPAD) {
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001261#endif
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001262 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001263 case 6:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001264 if (!PyArg_Parse(args,
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001265 "(iiiiii);" \
1266 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1267 &pminrow, &pmincol, &sminrow,
1268 &smincol, &smaxrow, &smaxcol))
1269 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001270
1271 Py_BEGIN_ALLOW_THREADS
1272 rtn = prefresh(self->win,
1273 pminrow, pmincol, sminrow,
Andrew M. Kuchlingb6e46872000-06-27 15:01:10 +00001274 smincol, smaxrow, smaxcol);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001275 Py_END_ALLOW_THREADS
1276 return PyCursesCheckERR(rtn, "prefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001277 default:
1278 PyErr_SetString(PyCursesError,
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001279 "refresh() for a pad requires 6 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001280 return NULL;
1281 }
1282 } else {
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001283 if (!PyArg_NoArgs(args))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001284 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001285 Py_BEGIN_ALLOW_THREADS
1286 rtn = wrefresh(self->win);
1287 Py_END_ALLOW_THREADS
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001288 return PyCursesCheckERR(rtn, "prefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001289 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001290}
1291
1292static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001293PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001294{
1295 int x, y;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001296 if (!PyArg_Parse(args,"(ii);top, bottom",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +00001297 return NULL;
1298 return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001299}
1300
1301static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001302PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001303{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001304 WINDOW *win;
1305 int nlines, ncols, begin_y, begin_x;
1306
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001307 nlines = 0;
1308 ncols = 0;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001309 switch (ARG_COUNT(args)) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001310 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001311 if (!PyArg_Parse(args,"(ii);begin_y,begin_x",&begin_y,&begin_x))
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001312 return NULL;
1313 break;
1314 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001315 if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001316 &nlines,&ncols,&begin_y,&begin_x))
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001317 return NULL;
1318 break;
1319 default:
1320 PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001321 return NULL;
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001322 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001323
Andrew M. Kuchling8353f622000-07-26 18:36:27 +00001324 /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00001325#ifdef WINDOW_HAS_FLAGS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001326 if (self->win->_flags & _ISPAD)
1327 win = subpad(self->win, nlines, ncols, begin_y, begin_x);
1328 else
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001329#endif
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001330 win = subwin(self->win, nlines, ncols, begin_y, begin_x);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001331
1332 if (win == NULL) {
1333 PyErr_SetString(PyCursesError, catchall_NULL);
1334 return NULL;
1335 }
1336
1337 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001338}
1339
1340static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001341PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001342{
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001343 int nlines;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001344 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001345 case 0:
1346 return PyCursesCheckERR(scroll(self->win), "scroll");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001347 case 1:
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001348 if (!PyArg_Parse(args, "i;nlines", &nlines))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001349 return NULL;
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001350 return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001351 default:
1352 PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001353 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001354 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001355}
1356
1357static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001358PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001359{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001360 int st, cnt, val;
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001361 switch (ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001362 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001363 if (!PyArg_Parse(args,"(ii);start,count",&st,&cnt))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001364 return NULL;
1365 return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001366 case 3:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001367 if (!PyArg_Parse(args, "(iii);start,count,val", &st, &cnt, &val))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001368 return NULL;
1369 return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
1370 default:
1371 PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001372 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001373 }
1374}
1375
1376static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001377PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001378{
1379 PyObject *temp;
1380 chtype ch;
1381 int n, x, y, code = OK;
1382 attr_t attr = A_NORMAL;
1383
1384 switch (ARG_COUNT(args)) {
1385 case 2:
1386 if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n))
1387 return NULL;
1388 break;
1389 case 3:
1390 if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr))
1391 return NULL;
1392 break;
1393 case 4:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001394 if (!PyArg_Parse(args, "(iiOi);y,x,ch or int,n", &y, &x, &temp, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001395 return NULL;
1396 code = wmove(self->win, y, x);
1397 break;
1398 case 5:
1399 if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr",
1400 &y, &x, &temp, &n, &attr))
1401 return NULL;
1402 code = wmove(self->win, y, x);
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00001403 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001404 default:
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00001405 PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001406 return NULL;
1407 }
1408
1409 if (code != ERR) {
1410 if (!PyCurses_ConvertToChtype(temp, &ch)) {
1411 PyErr_SetString(PyExc_TypeError,
1412 "argument 1 or 3 must be a ch or an int");
1413 return NULL;
1414 }
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001415 return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001416 } else
1417 return PyCursesCheckERR(code, "wmove");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001418}
1419
1420static PyMethodDef PyCursesWindow_Methods[] = {
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001421 {"addch", (PyCFunction)PyCursesWindow_AddCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001422 {"addnstr", (PyCFunction)PyCursesWindow_AddNStr},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001423 {"addstr", (PyCFunction)PyCursesWindow_AddStr},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001424 {"attroff", (PyCFunction)PyCursesWindow_wattroff},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001425 {"attron", (PyCFunction)PyCursesWindow_wattron},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001426 {"attrset", (PyCFunction)PyCursesWindow_wattrset},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001427 {"bkgd", (PyCFunction)PyCursesWindow_Bkgd},
1428 {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001429 {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
1430 {"box", (PyCFunction)PyCursesWindow_Box},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001431 {"clear", (PyCFunction)PyCursesWindow_wclear},
1432 {"clearok", (PyCFunction)PyCursesWindow_clearok},
1433 {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot},
1434 {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol},
1435 {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup},
1436 {"delch", (PyCFunction)PyCursesWindow_DelCh},
1437 {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln},
1438 {"derwin", (PyCFunction)PyCursesWindow_DerWin},
1439 {"echochar", (PyCFunction)PyCursesWindow_EchoChar},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001440#ifdef NCURSES_MOUSE_VERSION
1441 {"enclose", (PyCFunction)PyCursesWindow_Enclose},
1442#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001443 {"erase", (PyCFunction)PyCursesWindow_werase},
1444 {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx},
1445 {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001446 {"getch", (PyCFunction)PyCursesWindow_GetCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001447 {"getkey", (PyCFunction)PyCursesWindow_GetKey},
1448 {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx},
1449 {"getparyx", (PyCFunction)PyCursesWindow_getparyx},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001450 {"getstr", (PyCFunction)PyCursesWindow_GetStr},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001451 {"getyx", (PyCFunction)PyCursesWindow_getyx},
1452 {"hline", (PyCFunction)PyCursesWindow_Hline},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001453 {"idcok", (PyCFunction)PyCursesWindow_idcok},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001454 {"idlok", (PyCFunction)PyCursesWindow_idlok},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001455 {"immedok", (PyCFunction)PyCursesWindow_immedok},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001456 {"inch", (PyCFunction)PyCursesWindow_InCh},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001457 {"insch", (PyCFunction)PyCursesWindow_InsCh},
1458 {"insdelln", (PyCFunction)PyCursesWindow_winsdelln},
1459 {"insertln", (PyCFunction)PyCursesWindow_winsertln},
1460 {"insnstr", (PyCFunction)PyCursesWindow_InsNStr},
1461 {"insstr", (PyCFunction)PyCursesWindow_InsStr},
1462 {"instr", (PyCFunction)PyCursesWindow_InStr},
1463 {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched},
1464 {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched},
1465 {"keypad", (PyCFunction)PyCursesWindow_keypad},
1466 {"leaveok", (PyCFunction)PyCursesWindow_leaveok},
1467 {"move", (PyCFunction)PyCursesWindow_wmove},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001468 {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001469 {"mvwin", (PyCFunction)PyCursesWindow_mvwin},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001470 {"nodelay", (PyCFunction)PyCursesWindow_nodelay},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001471 {"notimeout", (PyCFunction)PyCursesWindow_notimeout},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001472 {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
Andrew M. Kuchlinga98e92b2000-08-20 23:37:02 +00001473 /* Backward compatibility alias -- remove in Python 2.1 */
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +00001474 {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00001475 {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS},
1476 {"overwrite", (PyCFunction)PyCursesWindow_Overwrite,
1477 METH_VARARGS},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001478 {"putwin", (PyCFunction)PyCursesWindow_PutWin},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001479 {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001480 {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001481 {"refresh", (PyCFunction)PyCursesWindow_Refresh},
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +00001482#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001483 {"resize", (PyCFunction)PyCursesWindow_wresize},
1484#endif
1485 {"scroll", (PyCFunction)PyCursesWindow_Scroll},
1486 {"scrollok", (PyCFunction)PyCursesWindow_scrollok},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001487 {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001488 {"standend", (PyCFunction)PyCursesWindow_wstandend},
1489 {"standout", (PyCFunction)PyCursesWindow_wstandout},
1490 {"subpad", (PyCFunction)PyCursesWindow_SubWin},
1491 {"subwin", (PyCFunction)PyCursesWindow_SubWin},
1492 {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown},
1493 {"syncok", (PyCFunction)PyCursesWindow_syncok},
1494 {"syncup", (PyCFunction)PyCursesWindow_wsyncup},
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00001495 {"timeout", (PyCFunction)PyCursesWindow_wtimeout},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001496 {"touchline", (PyCFunction)PyCursesWindow_TouchLine},
1497 {"touchwin", (PyCFunction)PyCursesWindow_touchwin},
1498 {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin},
1499 {"vline", (PyCFunction)PyCursesWindow_Vline},
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00001500 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00001501};
1502
1503static PyObject *
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00001504PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001505{
Guido van Rossuma597dde1995-01-10 20:56:29 +00001506 return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001507}
1508
Guido van Rossumf6971e21994-08-30 12:25:20 +00001509/* -------------------------------------------------------*/
Guido van Rossum85738471995-02-17 13:50:17 +00001510
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001511PyTypeObject PyCursesWindow_Type = {
Guido van Rossum6915c4d2001-01-19 00:28:08 +00001512 PyObject_HEAD_INIT(NULL)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001513 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +00001514 "_curses.curses window", /*tp_name*/
Guido van Rossumf6971e21994-08-30 12:25:20 +00001515 sizeof(PyCursesWindowObject), /*tp_basicsize*/
1516 0, /*tp_itemsize*/
1517 /* methods */
1518 (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
1519 0, /*tp_print*/
1520 (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
1521 (setattrfunc)0, /*tp_setattr*/
1522 0, /*tp_compare*/
1523 0, /*tp_repr*/
1524 0, /*tp_as_number*/
1525 0, /*tp_as_sequence*/
1526 0, /*tp_as_mapping*/
1527 0, /*tp_hash*/
1528};
1529
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001530/*********************************************************************
1531 Global Functions
1532**********************************************************************/
Guido van Rossumf6971e21994-08-30 12:25:20 +00001533
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001534NoArgNoReturnFunction(beep)
1535NoArgNoReturnFunction(def_prog_mode)
1536NoArgNoReturnFunction(def_shell_mode)
1537NoArgNoReturnFunction(doupdate)
1538NoArgNoReturnFunction(endwin)
1539NoArgNoReturnFunction(flash)
1540NoArgNoReturnFunction(nocbreak)
1541NoArgNoReturnFunction(noecho)
1542NoArgNoReturnFunction(nonl)
1543NoArgNoReturnFunction(noraw)
1544NoArgNoReturnFunction(reset_prog_mode)
1545NoArgNoReturnFunction(reset_shell_mode)
1546NoArgNoReturnFunction(resetty)
1547NoArgNoReturnFunction(savetty)
1548
1549NoArgOrFlagNoReturnFunction(cbreak)
1550NoArgOrFlagNoReturnFunction(echo)
1551NoArgOrFlagNoReturnFunction(nl)
1552NoArgOrFlagNoReturnFunction(raw)
1553
1554NoArgReturnIntFunction(baudrate)
1555NoArgReturnIntFunction(termattrs)
1556
1557NoArgReturnStringFunction(termname)
1558NoArgReturnStringFunction(longname)
1559
1560NoArgTrueFalseFunction(can_change_color)
1561NoArgTrueFalseFunction(has_colors)
1562NoArgTrueFalseFunction(has_ic)
1563NoArgTrueFalseFunction(has_il)
1564NoArgTrueFalseFunction(isendwin)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001565NoArgNoReturnVoidFunction(filter)
1566NoArgNoReturnVoidFunction(flushinp)
1567NoArgNoReturnVoidFunction(noqiflush)
1568
1569static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001570PyCurses_Color_Content(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001571{
1572 short color,r,g,b;
1573
1574 PyCursesInitialised
1575 PyCursesInitialisedColor
1576
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001577 if (ARG_COUNT(args) != 1) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001578 PyErr_SetString(PyExc_TypeError,
1579 "color_content requires 1 argument");
1580 return NULL;
1581 }
1582
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001583 if (!PyArg_Parse(args, "h;color", &color)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001584
1585 if (color_content(color, &r, &g, &b) != ERR)
1586 return Py_BuildValue("(iii)", r, g, b);
1587 else {
1588 PyErr_SetString(PyCursesError,
1589 "Argument 1 was out of range. Check value of COLORS.");
1590 return NULL;
1591 }
1592}
1593
1594static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001595PyCurses_color_pair(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001596{
1597 int n;
1598
1599 PyCursesInitialised
1600 PyCursesInitialisedColor
1601
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001602 if (ARG_COUNT(args) != 1) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001603 PyErr_SetString(PyExc_TypeError, "color_pair requires 1 argument");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001604 return NULL;
1605 }
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001606 if (!PyArg_Parse(args, "i;number", &n)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001607 return PyInt_FromLong((long) (n << 8));
1608}
1609
1610static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001611PyCurses_Curs_Set(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001612{
1613 int vis,erg;
1614
1615 PyCursesInitialised
1616
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001617 if (ARG_COUNT(args)!=1) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001618 PyErr_SetString(PyExc_TypeError, "curs_set requires 1 argument");
1619 return NULL;
1620 }
1621
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001622 if (!PyArg_Parse(args, "i;int", &vis)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001623
1624 erg = curs_set(vis);
1625 if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
1626
1627 return PyInt_FromLong((long) erg);
1628}
1629
1630static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001631PyCurses_Delay_Output(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001632{
1633 int ms;
1634
1635 PyCursesInitialised
1636
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001637 if (ARG_COUNT(args) != 1) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001638 PyErr_SetString(PyExc_TypeError, "delay_output requires 1 argument");
1639 return NULL;
1640 }
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001641 if (!PyArg_Parse(args, "i;ms", &ms)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001642
1643 return PyCursesCheckERR(delay_output(ms), "delay_output");
1644}
1645
1646static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001647PyCurses_EraseChar(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001648{
1649 char ch;
1650
1651 PyCursesInitialised
1652
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001653 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001654
1655 ch = erasechar();
1656
Martin v. Löwis43f2dc62001-11-11 14:49:15 +00001657 return PyString_FromStringAndSize(&ch, 1);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001658}
1659
1660static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001661PyCurses_getsyx(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001662{
1663 int x,y;
1664
1665 PyCursesInitialised
1666
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001667 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001668
1669 getsyx(y, x);
1670
1671 return Py_BuildValue("(ii)", y, x);
1672}
1673
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001674#ifdef NCURSES_MOUSE_VERSION
1675static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001676PyCurses_GetMouse(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001677{
1678 int rtn;
1679 MEVENT event;
1680
1681 PyCursesInitialised
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001682 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001683
1684 rtn = getmouse( &event );
1685 if (rtn == ERR) {
1686 PyErr_SetString(PyCursesError, "getmouse() returned ERR");
1687 return NULL;
1688 }
1689 return Py_BuildValue("(hiiil)",
1690 (short)event.id,
1691 event.x, event.y, event.z,
1692 (long) event.bstate);
1693}
1694
1695static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001696PyCurses_UngetMouse(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001697{
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001698 MEVENT event;
1699
1700 PyCursesInitialised
1701 if (!PyArg_ParseTuple(args, "(hiiil)",
1702 &event.id,
1703 &event.x, &event.y, &event.z,
1704 (int *) &event.bstate))
1705 return NULL;
1706
1707 return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
1708}
1709#endif
1710
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001711static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001712PyCurses_GetWin(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001713{
1714 WINDOW *win;
1715 PyObject *temp;
1716
1717 PyCursesInitialised
1718
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001719 if (!PyArg_Parse(args, "O;fileobj", &temp)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001720
1721 if (!PyFile_Check(temp)) {
1722 PyErr_SetString(PyExc_TypeError, "argument must be a file object");
1723 return NULL;
1724 }
1725
1726 win = getwin(PyFile_AsFile(temp));
1727
1728 if (win == NULL) {
1729 PyErr_SetString(PyCursesError, catchall_NULL);
1730 return NULL;
1731 }
1732
1733 return PyCursesWindow_New(win);
1734}
1735
1736static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001737PyCurses_HalfDelay(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001738{
1739 unsigned char tenths;
1740
1741 PyCursesInitialised
1742
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001743 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001744 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001745 if (!PyArg_Parse(args, "b;tenths", &tenths)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001746 break;
1747 default:
1748 PyErr_SetString(PyExc_TypeError, "halfdelay requires 1 argument");
1749 return NULL;
1750 }
1751
1752 return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
1753}
1754
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00001755#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001756 /* No has_key! */
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001757static PyObject * PyCurses_has_key(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001758{
1759 int ch;
1760
1761 PyCursesInitialised
1762
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001763 if (!PyArg_Parse(args,"i",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001764
1765 if (has_key(ch) == FALSE) {
1766 Py_INCREF(Py_False);
1767 return Py_False;
1768 }
1769 Py_INCREF(Py_True);
1770 return Py_True;
1771}
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00001772#endif /* STRICT_SYSV_CURSES */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001773
1774static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001775PyCurses_Init_Color(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001776{
1777 short color, r, g, b;
1778
1779 PyCursesInitialised
1780 PyCursesInitialisedColor
1781
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001782 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001783 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001784 if (!PyArg_Parse(args, "(hhhh);color,r,g,b", &color, &r, &g, &b)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001785 break;
1786 default:
1787 PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
1788 return NULL;
1789 }
1790
1791 return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
1792}
1793
1794static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001795PyCurses_Init_Pair(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001796{
1797 short pair, f, b;
1798
1799 PyCursesInitialised
1800 PyCursesInitialisedColor
1801
Andrew M. Kuchling4463acb2000-07-24 23:54:49 +00001802 if (ARG_COUNT(args) != 3) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001803 PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
1804 return NULL;
1805 }
1806
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001807 if (!PyArg_Parse(args, "(hhh);pair, f, b", &pair, &f, &b)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001808
1809 return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
1810}
1811
Andrew M. Kuchling32552682000-12-22 21:52:27 +00001812static PyObject *ModDict;
1813
Guido van Rossumf6971e21994-08-30 12:25:20 +00001814static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001815PyCurses_InitScr(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001816{
Guido van Rossum56bf2351994-08-31 22:06:24 +00001817 WINDOW *win;
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001818 PyObject *nlines, *cols;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001819
1820 if (!PyArg_NoArgs(args)) return NULL;
1821
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001822 if (initialised == TRUE) {
Guido van Rossumf6971e21994-08-30 12:25:20 +00001823 wrefresh(stdscr);
1824 return (PyObject *)PyCursesWindow_New(stdscr);
1825 }
Guido van Rossum56bf2351994-08-31 22:06:24 +00001826
1827 win = initscr();
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001828
Guido van Rossum85738471995-02-17 13:50:17 +00001829 if (win == NULL) {
1830 PyErr_SetString(PyCursesError, catchall_NULL);
1831 return NULL;
1832 }
1833
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00001834 initialised = initialised_setupterm = TRUE;
Guido van Rossum56bf2351994-08-31 22:06:24 +00001835
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001836/* This was moved from initcurses() because it core dumped on SGI,
1837 where they're not defined until you've called initscr() */
1838#define SetDictInt(string,ch) \
1839 PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
1840
1841 /* Here are some graphic symbols you can use */
1842 SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
1843 SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
1844 SetDictInt("ACS_URCORNER", (ACS_URCORNER));
1845 SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
1846 SetDictInt("ACS_LTEE", (ACS_LTEE));
1847 SetDictInt("ACS_RTEE", (ACS_RTEE));
1848 SetDictInt("ACS_BTEE", (ACS_BTEE));
1849 SetDictInt("ACS_TTEE", (ACS_TTEE));
1850 SetDictInt("ACS_HLINE", (ACS_HLINE));
1851 SetDictInt("ACS_VLINE", (ACS_VLINE));
1852 SetDictInt("ACS_PLUS", (ACS_PLUS));
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00001853#if !defined(__hpux) || defined(HAVE_NCURSES_H)
1854 /* On HP/UX 11, these are of type cchar_t, which is not an
1855 integral type. If this is a problem on more platforms, a
1856 configure test should be added to determine whether ACS_S1
1857 is of integral type. */
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001858 SetDictInt("ACS_S1", (ACS_S1));
1859 SetDictInt("ACS_S9", (ACS_S9));
1860 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
1861 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
1862 SetDictInt("ACS_DEGREE", (ACS_DEGREE));
1863 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
1864 SetDictInt("ACS_BULLET", (ACS_BULLET));
1865 SetDictInt("ACS_LARROW", (ACS_LARROW));
1866 SetDictInt("ACS_RARROW", (ACS_RARROW));
1867 SetDictInt("ACS_DARROW", (ACS_DARROW));
1868 SetDictInt("ACS_UARROW", (ACS_UARROW));
1869 SetDictInt("ACS_BOARD", (ACS_BOARD));
1870 SetDictInt("ACS_LANTERN", (ACS_LANTERN));
1871 SetDictInt("ACS_BLOCK", (ACS_BLOCK));
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00001872#endif
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001873 SetDictInt("ACS_BSSB", (ACS_ULCORNER));
1874 SetDictInt("ACS_SSBB", (ACS_LLCORNER));
1875 SetDictInt("ACS_BBSS", (ACS_URCORNER));
1876 SetDictInt("ACS_SBBS", (ACS_LRCORNER));
1877 SetDictInt("ACS_SBSS", (ACS_RTEE));
1878 SetDictInt("ACS_SSSB", (ACS_LTEE));
1879 SetDictInt("ACS_SSBS", (ACS_BTEE));
1880 SetDictInt("ACS_BSSS", (ACS_TTEE));
1881 SetDictInt("ACS_BSBS", (ACS_HLINE));
1882 SetDictInt("ACS_SBSB", (ACS_VLINE));
1883 SetDictInt("ACS_SSSS", (ACS_PLUS));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001884
1885 /* The following are never available with strict SYSV curses */
1886#ifdef ACS_S3
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001887 SetDictInt("ACS_S3", (ACS_S3));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001888#endif
1889#ifdef ACS_S7
1890 SetDictInt("ACS_S7", (ACS_S7));
1891#endif
1892#ifdef ACS_LEQUAL
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001893 SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001894#endif
1895#ifdef ACS_GEQUAL
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001896 SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001897#endif
1898#ifdef ACS_PI
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001899 SetDictInt("ACS_PI", (ACS_PI));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001900#endif
1901#ifdef ACS_NEQUAL
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001902 SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001903#endif
1904#ifdef ACS_STERLING
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001905 SetDictInt("ACS_STERLING", (ACS_STERLING));
1906#endif
1907
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001908 nlines = PyInt_FromLong((long) LINES);
1909 PyDict_SetItemString(ModDict, "LINES", nlines);
1910 Py_DECREF(nlines);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001911 cols = PyInt_FromLong((long) COLS);
1912 PyDict_SetItemString(ModDict, "COLS", cols);
1913 Py_DECREF(cols);
Guido van Rossum56bf2351994-08-31 22:06:24 +00001914
1915 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001916}
1917
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00001918static PyObject *
1919PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
1920{
1921 int fd = -1;
1922 int err;
1923 char* termstr = NULL;
1924
1925 static char *kwlist[] = {"term", "fd", NULL};
1926
1927 if (!PyArg_ParseTupleAndKeywords(
1928 args,keywds,"|zi:setupterm",kwlist,&termstr,&fd)) {
1929 return NULL;
1930 }
1931
1932 if (fd == -1) {
1933 PyObject* sys_stdout;
1934
1935 sys_stdout = PySys_GetObject("stdout");
1936
1937 if (sys_stdout == NULL) {
1938 PyErr_SetString(
1939 PyCursesError,
1940 "lost sys.stdout");
1941 return NULL;
1942 }
1943
1944 fd = PyObject_AsFileDescriptor(sys_stdout);
1945
1946 if (fd == -1) {
1947 return NULL;
1948 }
1949 }
1950
1951 if (setupterm(termstr,fd,&err) == ERR) {
1952 char* s = "setupterm: unknown error";
1953
1954 if (err == 0) {
1955 s = "setupterm: could not find terminal";
1956 } else if (err == -1) {
1957 s = "setupterm: could not find terminfo database";
1958 }
1959
1960 PyErr_SetString(PyCursesError,s);
1961 return NULL;
1962 }
1963
1964 initialised_setupterm = TRUE;
1965
1966 Py_INCREF(Py_None);
1967 return Py_None;
1968}
Guido van Rossumf6971e21994-08-30 12:25:20 +00001969
1970static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001971PyCurses_IntrFlush(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001972{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001973 int ch;
1974
1975 PyCursesInitialised
1976
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001977 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001978 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001979 if (!PyArg_Parse(args,"i;True(1), False(0)",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001980 break;
1981 default:
1982 PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00001983 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001984 }
1985
1986 return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
1987}
1988
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001989#if !defined(__NetBSD__)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001990static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001991PyCurses_KeyName(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001992{
1993 const char *knp;
1994 int ch;
1995
1996 PyCursesInitialised
1997
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001998 if (!PyArg_Parse(args,"i",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001999
2000 knp = keyname(ch);
2001
2002 return PyString_FromString((knp == NULL) ? "" : (char *)knp);
2003}
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002004#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002005
2006static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002007PyCurses_KillChar(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002008{
2009 char ch;
2010
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002011 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002012
2013 ch = killchar();
2014
Martin v. Löwis43f2dc62001-11-11 14:49:15 +00002015 return PyString_FromStringAndSize(&ch, 1);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002016}
2017
2018static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002019PyCurses_Meta(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002020{
2021 int ch;
2022
2023 PyCursesInitialised
2024
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002025 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002026 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002027 if (!PyArg_Parse(args,"i;True(1), False(0)",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002028 break;
2029 default:
2030 PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
2031 return NULL;
2032 }
2033
2034 return PyCursesCheckERR(meta(stdscr, ch), "meta");
2035}
2036
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002037#ifdef NCURSES_MOUSE_VERSION
2038static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002039PyCurses_MouseInterval(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002040{
2041 int interval;
2042 PyCursesInitialised
2043
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002044 if (!PyArg_Parse(args,"i;interval",&interval))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002045 return NULL;
2046 return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
2047}
2048
2049static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002050PyCurses_MouseMask(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002051{
Andrew M. Kuchling1a104002000-07-06 18:14:03 +00002052 int newmask;
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002053 mmask_t oldmask, availmask;
2054
2055 PyCursesInitialised
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002056 if (!PyArg_Parse(args,"i;mousemask",&newmask))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002057 return NULL;
2058 availmask = mousemask(newmask, &oldmask);
2059 return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
2060}
2061#endif
2062
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002063static PyObject *
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +00002064PyCurses_Napms(PyObject *self, PyObject *args)
2065{
2066 int ms;
2067
2068 PyCursesInitialised
2069 if (!PyArg_Parse(args, "i;ms", &ms)) return NULL;
2070
2071 return Py_BuildValue("i", napms(ms));
2072}
2073
2074
2075static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002076PyCurses_NewPad(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002077{
2078 WINDOW *win;
2079 int nlines, ncols;
2080
2081 PyCursesInitialised
2082
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002083 if (!PyArg_Parse(args,"(ii);nlines,ncols",&nlines,&ncols)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002084
2085 win = newpad(nlines, ncols);
2086
2087 if (win == NULL) {
2088 PyErr_SetString(PyCursesError, catchall_NULL);
2089 return NULL;
2090 }
2091
2092 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002093}
2094
2095static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002096PyCurses_NewWindow(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002097{
2098 WINDOW *win;
Andrew M. Kuchling5a76c442001-07-14 20:38:30 +00002099 int nlines, ncols, begin_y=0, begin_x=0;
Guido van Rossum85738471995-02-17 13:50:17 +00002100
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002101 PyCursesInitialised
2102
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002103 switch (ARG_COUNT(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +00002104 case 2:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002105 if (!PyArg_Parse(args,"(ii);nlines,ncols",&nlines,&ncols))
Guido van Rossum85738471995-02-17 13:50:17 +00002106 return NULL;
2107 break;
2108 case 4:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002109 if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
Guido van Rossumf6971e21994-08-30 12:25:20 +00002110 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +00002111 return NULL;
2112 break;
2113 default:
2114 PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
2115 return NULL;
2116 }
2117
Andrew M. Kuchling5a76c442001-07-14 20:38:30 +00002118 win = newwin(nlines,ncols,begin_y,begin_x);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002119 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +00002120 PyErr_SetString(PyCursesError, catchall_NULL);
2121 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002122 }
Guido van Rossum85738471995-02-17 13:50:17 +00002123
Guido van Rossumf6971e21994-08-30 12:25:20 +00002124 return (PyObject *)PyCursesWindow_New(win);
2125}
2126
2127static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002128PyCurses_Pair_Content(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002129{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002130 short pair,f,b;
2131
2132 PyCursesInitialised
2133 PyCursesInitialisedColor
2134
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002135 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002136 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002137 if (!PyArg_Parse(args, "h;pair", &pair)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002138 break;
2139 default:
2140 PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00002141 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002142 }
2143
2144 if (!pair_content(pair, &f, &b)) {
2145 PyErr_SetString(PyCursesError,
2146 "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
2147 return NULL;
2148 }
2149
2150 return Py_BuildValue("(ii)", f, b);
2151}
2152
2153static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002154PyCurses_pair_number(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002155{
2156 int n;
2157
2158 PyCursesInitialised
2159 PyCursesInitialisedColor
2160
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002161 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002162 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002163 if (!PyArg_Parse(args, "i;pairvalue", &n)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002164 break;
2165 default:
2166 PyErr_SetString(PyExc_TypeError,
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002167 "pair_number requires 1 argument");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002168 return NULL;
2169 }
2170
2171 return PyInt_FromLong((long) ((n & A_COLOR) >> 8));
2172}
2173
2174static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002175PyCurses_Putp(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002176{
2177 char *str;
2178
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002179 if (!PyArg_Parse(args,"s;str", &str)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002180 return PyCursesCheckERR(putp(str), "putp");
2181}
2182
2183static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002184PyCurses_QiFlush(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002185{
2186 int flag = 0;
2187
2188 PyCursesInitialised
2189
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002190 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002191 case 0:
2192 qiflush();
2193 Py_INCREF(Py_None);
2194 return Py_None;
2195 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002196 if (!PyArg_Parse(args, "i;True(1) or False(0)", &flag)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002197 if (flag) qiflush();
2198 else noqiflush();
2199 Py_INCREF(Py_None);
2200 return Py_None;
2201 default:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002202 PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002203 return NULL;
2204 }
2205}
2206
2207static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002208PyCurses_setsyx(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002209{
2210 int y,x;
2211
2212 PyCursesInitialised
2213
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002214 if (ARG_COUNT(args)!=2) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002215 PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002216 return NULL;
2217 }
2218
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002219 if (!PyArg_Parse(args, "(ii);y, x", &y, &x)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002220
2221 setsyx(y,x);
2222
Guido van Rossumf6971e21994-08-30 12:25:20 +00002223 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00002224 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002225}
2226
2227static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002228PyCurses_Start_Color(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002229{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002230 int code;
2231 PyObject *c, *cp;
2232
2233 PyCursesInitialised
2234
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002235 if (!PyArg_NoArgs(args)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002236
2237 code = start_color();
2238 if (code != ERR) {
2239 initialisedcolors = TRUE;
2240 c = PyInt_FromLong((long) COLORS);
2241 PyDict_SetItemString(ModDict, "COLORS", c);
2242 Py_DECREF(c);
2243 cp = PyInt_FromLong((long) COLOR_PAIRS);
2244 PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
2245 Py_DECREF(cp);
2246 Py_INCREF(Py_None);
2247 return Py_None;
2248 } else {
2249 PyErr_SetString(PyCursesError, "start_color() returned ERR");
Guido van Rossum85738471995-02-17 13:50:17 +00002250 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002251 }
2252}
2253
2254static PyObject *
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002255PyCurses_tigetflag(PyObject *self, PyObject *args)
2256{
2257 char *capname;
2258
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002259 PyCursesSetupTermCalled;
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002260
2261 if (!PyArg_ParseTuple(args, "z", &capname))
2262 return NULL;
2263
2264 return PyInt_FromLong( (long) tigetflag( capname ) );
2265}
2266
2267static PyObject *
2268PyCurses_tigetnum(PyObject *self, PyObject *args)
2269{
2270 char *capname;
2271
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002272 PyCursesSetupTermCalled;
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002273
2274 if (!PyArg_ParseTuple(args, "z", &capname))
2275 return NULL;
2276
2277 return PyInt_FromLong( (long) tigetnum( capname ) );
2278}
2279
2280static PyObject *
2281PyCurses_tigetstr(PyObject *self, PyObject *args)
2282{
2283 char *capname;
2284
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002285 PyCursesSetupTermCalled;
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002286
2287 if (!PyArg_ParseTuple(args, "z", &capname))
2288 return NULL;
2289
2290 capname = tigetstr( capname );
2291 if (capname == 0 || capname == (char*) -1) {
2292 Py_INCREF(Py_None);
2293 return Py_None;
2294 }
2295 return PyString_FromString( capname );
2296}
2297
2298static PyObject *
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002299PyCurses_tparm(PyObject *self, PyObject *args)
2300{
2301 char* fmt;
2302 char* result = NULL;
2303 int i1,i2,i3,i4,i5,i6,i7,i8,i9;
2304
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002305 PyCursesSetupTermCalled;
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002306
2307 if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
2308 &fmt, &i1, &i2, &i3, &i4,
2309 &i5, &i6, &i7, &i8, &i9)) {
2310 return NULL;
2311 }
2312
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00002313#ifdef __hpux
2314 /* tparm is declared with 10 arguments on HP/UX 11.
2315 If this is a problem on other platforms as well,
2316 an autoconf test should be added to determine
2317 whether tparm can be called with a variable number
2318 of arguments. Perhaps the other arguments should
2319 be initialized in this case also. */
2320 result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9);
2321#else
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002322 switch (PyTuple_GET_SIZE(args)) {
2323 case 1:
2324 result = tparm(fmt);
2325 break;
2326 case 2:
2327 result = tparm(fmt,i1);
2328 break;
2329 case 3:
2330 result = tparm(fmt,i1,i2);
2331 break;
2332 case 4:
2333 result = tparm(fmt,i1,i2,i3);
2334 break;
2335 case 5:
2336 result = tparm(fmt,i1,i2,i3,i4);
2337 break;
2338 case 6:
2339 result = tparm(fmt,i1,i2,i3,i4,i5);
2340 break;
2341 case 7:
2342 result = tparm(fmt,i1,i2,i3,i4,i5,i6);
2343 break;
2344 case 8:
2345 result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7);
2346 break;
2347 case 9:
2348 result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8);
2349 break;
2350 case 10:
2351 result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9);
2352 break;
2353 }
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00002354#endif /* __hpux */
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002355 return PyString_FromString(result);
2356}
2357
2358static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002359PyCurses_TypeAhead(PyObject *self, PyObject *args)
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002360{
Andrew M. Kuchling1a104002000-07-06 18:14:03 +00002361 int fd;
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002362
2363 PyCursesInitialised
2364
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002365 if (!PyArg_Parse(args,"i;fd",&fd)) return NULL;
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002366
2367 PyCursesCheckERR(typeahead( fd ), "typeahead");
2368 Py_INCREF(Py_None);
2369 return Py_None;
2370}
2371
2372static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002373PyCurses_UnCtrl(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002374{
2375 PyObject *temp;
2376 chtype ch;
2377
2378 PyCursesInitialised
2379
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002380 if (!PyArg_Parse(args,"O;ch or int",&temp)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002381
2382 if (PyInt_Check(temp))
2383 ch = (chtype) PyInt_AsLong(temp);
2384 else if (PyString_Check(temp))
2385 ch = (chtype) *PyString_AsString(temp);
2386 else {
2387 PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
2388 return NULL;
2389 }
2390
2391 return PyString_FromString(unctrl(ch));
Guido van Rossumf6971e21994-08-30 12:25:20 +00002392}
2393
2394static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002395PyCurses_UngetCh(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002396{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002397 PyObject *temp;
2398 chtype ch;
2399
2400 PyCursesInitialised
2401
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002402 if (!PyArg_Parse(args,"O;ch or int",&temp)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002403
2404 if (PyInt_Check(temp))
2405 ch = (chtype) PyInt_AsLong(temp);
2406 else if (PyString_Check(temp))
2407 ch = (chtype) *PyString_AsString(temp);
2408 else {
2409 PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
Guido van Rossum85738471995-02-17 13:50:17 +00002410 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002411 }
2412
Guido van Rossum85738471995-02-17 13:50:17 +00002413 return PyCursesCheckERR(ungetch(ch), "ungetch");
Guido van Rossumf6971e21994-08-30 12:25:20 +00002414}
2415
2416static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002417PyCurses_Use_Env(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002418{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002419 int flag;
2420
2421 PyCursesInitialised
2422
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002423 switch(ARG_COUNT(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002424 case 1:
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002425 if (!PyArg_Parse(args,"i;True(1), False(0)",&flag))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002426 return NULL;
2427 break;
2428 default:
2429 PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00002430 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002431 }
2432 use_env(flag);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002433 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00002434 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002435}
2436
Guido van Rossumf6971e21994-08-30 12:25:20 +00002437/* List of functions defined in the module */
2438
2439static PyMethodDef PyCurses_methods[] = {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002440 {"baudrate", (PyCFunction)PyCurses_baudrate},
2441 {"beep", (PyCFunction)PyCurses_beep},
2442 {"can_change_color", (PyCFunction)PyCurses_can_change_color},
2443 {"cbreak", (PyCFunction)PyCurses_cbreak},
2444 {"color_content", (PyCFunction)PyCurses_Color_Content},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002445 {"color_pair", (PyCFunction)PyCurses_color_pair},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002446 {"curs_set", (PyCFunction)PyCurses_Curs_Set},
2447 {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode},
2448 {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode},
2449 {"delay_output", (PyCFunction)PyCurses_Delay_Output},
2450 {"doupdate", (PyCFunction)PyCurses_doupdate},
2451 {"echo", (PyCFunction)PyCurses_echo},
2452 {"endwin", (PyCFunction)PyCurses_endwin},
2453 {"erasechar", (PyCFunction)PyCurses_EraseChar},
2454 {"filter", (PyCFunction)PyCurses_filter},
2455 {"flash", (PyCFunction)PyCurses_flash},
2456 {"flushinp", (PyCFunction)PyCurses_flushinp},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002457#ifdef NCURSES_MOUSE_VERSION
2458 {"getmouse", (PyCFunction)PyCurses_GetMouse},
2459 {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
2460#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002461 {"getsyx", (PyCFunction)PyCurses_getsyx},
2462 {"getwin", (PyCFunction)PyCurses_GetWin},
2463 {"has_colors", (PyCFunction)PyCurses_has_colors},
2464 {"has_ic", (PyCFunction)PyCurses_has_ic},
2465 {"has_il", (PyCFunction)PyCurses_has_il},
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00002466#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002467 {"has_key", (PyCFunction)PyCurses_has_key},
Guido van Rossumf6971e21994-08-30 12:25:20 +00002468#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002469 {"halfdelay", (PyCFunction)PyCurses_HalfDelay},
2470 {"init_color", (PyCFunction)PyCurses_Init_Color},
2471 {"init_pair", (PyCFunction)PyCurses_Init_Pair},
2472 {"initscr", (PyCFunction)PyCurses_InitScr},
2473 {"intrflush", (PyCFunction)PyCurses_IntrFlush},
2474 {"isendwin", (PyCFunction)PyCurses_isendwin},
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002475#if !defined(__NetBSD__)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002476 {"keyname", (PyCFunction)PyCurses_KeyName},
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002477#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002478 {"killchar", (PyCFunction)PyCurses_KillChar},
2479 {"longname", (PyCFunction)PyCurses_longname},
2480 {"meta", (PyCFunction)PyCurses_Meta},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002481#ifdef NCURSES_MOUSE_VERSION
2482 {"mouseinterval", (PyCFunction)PyCurses_MouseInterval},
2483 {"mousemask", (PyCFunction)PyCurses_MouseMask},
2484#endif
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +00002485 {"napms", (PyCFunction)PyCurses_Napms},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002486 {"newpad", (PyCFunction)PyCurses_NewPad},
2487 {"newwin", (PyCFunction)PyCurses_NewWindow},
2488 {"nl", (PyCFunction)PyCurses_nl},
2489 {"nocbreak", (PyCFunction)PyCurses_nocbreak},
2490 {"noecho", (PyCFunction)PyCurses_noecho},
2491 {"nonl", (PyCFunction)PyCurses_nonl},
2492 {"noqiflush", (PyCFunction)PyCurses_noqiflush},
2493 {"noraw", (PyCFunction)PyCurses_noraw},
2494 {"pair_content", (PyCFunction)PyCurses_Pair_Content},
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002495 {"pair_number", (PyCFunction)PyCurses_pair_number},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002496 {"putp", (PyCFunction)PyCurses_Putp},
2497 {"qiflush", (PyCFunction)PyCurses_QiFlush},
2498 {"raw", (PyCFunction)PyCurses_raw},
2499 {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode},
2500 {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode},
Andrew M. Kuchling1a104002000-07-06 18:14:03 +00002501 {"resetty", (PyCFunction)PyCurses_resetty},
2502 {"savetty", (PyCFunction)PyCurses_savetty},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002503 {"setsyx", (PyCFunction)PyCurses_setsyx},
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00002504 {"setupterm", (PyCFunction)PyCurses_setupterm,
2505 METH_VARARGS|METH_KEYWORDS},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002506 {"start_color", (PyCFunction)PyCurses_Start_Color},
2507 {"termattrs", (PyCFunction)PyCurses_termattrs},
2508 {"termname", (PyCFunction)PyCurses_termname},
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002509 {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
2510 {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
2511 {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002512 {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS},
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002513 {"typeahead", (PyCFunction)PyCurses_TypeAhead},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002514 {"unctrl", (PyCFunction)PyCurses_UnCtrl},
2515 {"ungetch", (PyCFunction)PyCurses_UngetCh},
2516 {"use_env", (PyCFunction)PyCurses_Use_Env},
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00002517 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00002518};
2519
2520/* Initialization function for the module */
2521
Guido van Rossum6915c4d2001-01-19 00:28:08 +00002522DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00002523init_curses(void)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002524{
Andrew M. Kuchling32552682000-12-22 21:52:27 +00002525 PyObject *m, *d, *v, *c_api_object;
2526 static void *PyCurses_API[PyCurses_API_pointers];
2527
Guido van Rossum6915c4d2001-01-19 00:28:08 +00002528 /* Initialize object type */
2529 PyCursesWindow_Type.ob_type = &PyType_Type;
2530
Andrew M. Kuchling32552682000-12-22 21:52:27 +00002531 /* Initialize the C API pointer array */
2532 PyCurses_API[0] = (void *)&PyCursesWindow_Type;
2533 PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
2534 PyCurses_API[2] = (void *)func_PyCursesInitialised;
2535 PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002536
2537 /* Create the module and add the functions */
Andrew M. Kuchlingb7f198e2000-06-10 23:12:32 +00002538 m = Py_InitModule("_curses", PyCurses_methods);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002539
Guido van Rossumf6971e21994-08-30 12:25:20 +00002540 /* Add some symbolic constants to the module */
2541 d = PyModule_GetDict(m);
Andrew M. Kuchling32552682000-12-22 21:52:27 +00002542 ModDict = d; /* For PyCurses_InitScr to use later */
2543
2544 /* Add a CObject for the C API */
2545 c_api_object = PyCObject_FromVoidPtr((void *)PyCurses_API, NULL);
2546 PyDict_SetItemString(d, "_C_API", c_api_object);
Martin v. Löwis00ff10c2001-11-11 14:24:05 +00002547 Py_DECREF(c_api_object);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00002548
Guido van Rossum85738471995-02-17 13:50:17 +00002549 /* For exception curses.error */
Fred Drake589c35b2000-07-06 19:38:49 +00002550 PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
Guido van Rossum85738471995-02-17 13:50:17 +00002551 PyDict_SetItemString(d, "error", PyCursesError);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00002552
Guido van Rossum85738471995-02-17 13:50:17 +00002553 /* Make the version available */
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00002554 v = PyString_FromString(PyCursesVersion);
2555 PyDict_SetItemString(d, "version", v);
2556 PyDict_SetItemString(d, "__version__", v);
2557 Py_DECREF(v);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002558
Andrew M. Kuchlingcaefb372000-12-26 15:57:01 +00002559 SetDictInt("ERR", ERR);
2560 SetDictInt("OK", OK);
2561
Guido van Rossumf6971e21994-08-30 12:25:20 +00002562 /* Here are some attributes you can add to chars to print */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002563
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002564 SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002565 SetDictInt("A_NORMAL", A_NORMAL);
2566 SetDictInt("A_STANDOUT", A_STANDOUT);
2567 SetDictInt("A_UNDERLINE", A_UNDERLINE);
2568 SetDictInt("A_REVERSE", A_REVERSE);
2569 SetDictInt("A_BLINK", A_BLINK);
2570 SetDictInt("A_DIM", A_DIM);
2571 SetDictInt("A_BOLD", A_BOLD);
2572 SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002573#if !defined(__NetBSD__)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002574 SetDictInt("A_INVIS", A_INVIS);
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002575#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002576 SetDictInt("A_PROTECT", A_PROTECT);
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002577 SetDictInt("A_CHARTEXT", A_CHARTEXT);
2578 SetDictInt("A_COLOR", A_COLOR);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002579
2580 /* The following are never available with strict SYSV curses */
2581#ifdef A_HORIZONTAL
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002582 SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002583#endif
2584#ifdef A_LEFT
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002585 SetDictInt("A_LEFT", A_LEFT);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002586#endif
2587#ifdef A_LOW
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002588 SetDictInt("A_LOW", A_LOW);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002589#endif
2590#ifdef A_RIGHT
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002591 SetDictInt("A_RIGHT", A_RIGHT);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002592#endif
2593#ifdef A_TOP
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002594 SetDictInt("A_TOP", A_TOP);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002595#endif
2596#ifdef A_VERTICAL
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002597 SetDictInt("A_VERTICAL", A_VERTICAL);
2598#endif
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002599
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002600 SetDictInt("COLOR_BLACK", COLOR_BLACK);
2601 SetDictInt("COLOR_RED", COLOR_RED);
2602 SetDictInt("COLOR_GREEN", COLOR_GREEN);
2603 SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
2604 SetDictInt("COLOR_BLUE", COLOR_BLUE);
2605 SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
2606 SetDictInt("COLOR_CYAN", COLOR_CYAN);
2607 SetDictInt("COLOR_WHITE", COLOR_WHITE);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002608
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002609#ifdef NCURSES_MOUSE_VERSION
2610 /* Mouse-related constants */
2611 SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
2612 SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
2613 SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
2614 SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
2615 SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
2616
2617 SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
2618 SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
2619 SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
2620 SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
2621 SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
2622
2623 SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
2624 SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
2625 SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
2626 SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
2627 SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
2628
2629 SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
2630 SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
2631 SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
2632 SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
2633 SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
2634
2635 SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
2636 SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
2637 SetDictInt("BUTTON_ALT", BUTTON_ALT);
2638
2639 SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
2640 SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
2641#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +00002642 /* Now set everything up for KEY_ variables */
2643 {
2644 int key;
2645 char *key_n;
2646 char *key_n2;
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002647#if !defined(__NetBSD__)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002648 for (key=KEY_MIN;key < KEY_MAX; key++) {
2649 key_n = (char *)keyname(key);
Guido van Rossumf5c6d471995-02-07 15:38:32 +00002650 if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002651 continue;
2652 if (strncmp(key_n,"KEY_F(",6)==0) {
2653 char *p1, *p2;
2654 key_n2 = malloc(strlen(key_n)+1);
2655 p1 = key_n;
2656 p2 = key_n2;
2657 while (*p1) {
2658 if (*p1 != '(' && *p1 != ')') {
2659 *p2 = *p1;
2660 p2++;
2661 }
2662 p1++;
2663 }
2664 *p2 = (char)0;
2665 } else
2666 key_n2 = key_n;
Guido van Rossum85738471995-02-17 13:50:17 +00002667 PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
Guido van Rossumf6971e21994-08-30 12:25:20 +00002668 if (key_n2 != key_n)
2669 free(key_n2);
2670 }
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002671#endif
Guido van Rossum85738471995-02-17 13:50:17 +00002672 SetDictInt("KEY_MIN", KEY_MIN);
2673 SetDictInt("KEY_MAX", KEY_MAX);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002674 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00002675}