blob: 51f4c388fe6e046bcbcf20d541164f23d7777054 [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. Kuchling3adefcc2002-10-30 21:08:34 +000011 * Tidied for Python 1.6, and currently maintained by <amk@amk.ca>.
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000012 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this source file to use, copy, modify, merge, or publish it
15 * subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or in any new file that contains a substantial portion of
19 * this file.
20 *
21 * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF
22 * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
23 * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES
24 * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
25 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE
27 * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL,
28 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
29 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR
30 * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
31 * PERFORMANCE OF THIS SOFTWARE.
32 */
Guido van Rossumf6971e21994-08-30 12:25:20 +000033
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000034/* CVS: $Id$ */
Guido van Rossumf6971e21994-08-30 12:25:20 +000035
Andrew M. Kuchlingfb6bbf52000-07-27 11:58:01 +000036/*
37
38A number of SysV or ncurses functions don't have wrappers yet; if you need
39a given function, add it and send a patch. Here's a list of currently
40unsupported functions:
41
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +000042 addchnstr addchstr chgat color_set define_key
Andrew M. Kuchlingfb6bbf52000-07-27 11:58:01 +000043 del_curterm delscreen dupwin inchnstr inchstr innstr keyok
44 mcprint mvaddchnstr mvaddchstr mvchgat mvcur mvinchnstr
45 mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +000046 mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr newterm
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +000047 resizeterm restartterm ripoffline scr_dump
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +000048 scr_init scr_restore scr_set scrl set_curterm set_term setterm
49 tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
Andrew M. Kuchling69f31eb2003-08-13 23:11:04 +000050 vidattr vidputs waddchnstr waddchstr wchgat
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +000051 wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
Andrew M. Kuchlingfb6bbf52000-07-27 11:58:01 +000052
53Low-priority:
54 slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
55 slk_attron slk_attrset slk_clear slk_color slk_init slk_label
56 slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
57
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +000058Menu extension (ncurses and probably SYSV):
59 current_item free_item free_menu item_count item_description
60 item_index item_init item_name item_opts item_opts_off
61 item_opts_on item_term item_userptr item_value item_visible
62 menu_back menu_driver menu_fore menu_format menu_grey
63 menu_init menu_items menu_mark menu_opts menu_opts_off
64 menu_opts_on menu_pad menu_pattern menu_request_by_name
65 menu_request_name menu_spacing menu_sub menu_term menu_userptr
66 menu_win new_item new_menu pos_menu_cursor post_menu
67 scale_menu set_current_item set_item_init set_item_opts
68 set_item_term set_item_userptr set_item_value set_menu_back
69 set_menu_fore set_menu_format set_menu_grey set_menu_init
70 set_menu_items set_menu_mark set_menu_opts set_menu_pad
71 set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
72 set_menu_userptr set_menu_win set_top_row top_row unpost_menu
73
74Form extension (ncurses and probably SYSV):
75 current_field data_ahead data_behind dup_field
76 dynamic_fieldinfo field_arg field_back field_buffer
77 field_count field_fore field_index field_info field_init
78 field_just field_opts field_opts_off field_opts_on field_pad
79 field_status field_term field_type field_userptr form_driver
80 form_fields form_init form_opts form_opts_off form_opts_on
81 form_page form_request_by_name form_request_name form_sub
82 form_term form_userptr form_win free_field free_form
83 link_field link_fieldtype move_field new_field new_form
84 new_page pos_form_cursor post_form scale_form
85 set_current_field set_field_back set_field_buffer
86 set_field_fore set_field_init set_field_just set_field_opts
87 set_field_pad set_field_status set_field_term set_field_type
88 set_field_userptr set_fieldtype_arg set_fieldtype_choice
89 set_form_fields set_form_init set_form_opts set_form_page
90 set_form_sub set_form_term set_form_userptr set_form_win
91 set_max_field set_new_page unpost_form
92
93
Andrew M. Kuchlingfb6bbf52000-07-27 11:58:01 +000094 */
95
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +000096/* Release Number */
Guido van Rossumf6971e21994-08-30 12:25:20 +000097
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +000098char *PyCursesVersion = "2.2";
Guido van Rossumf6971e21994-08-30 12:25:20 +000099
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000100/* Includes */
Guido van Rossumf6971e21994-08-30 12:25:20 +0000101
Guido van Rossum602099a1994-09-14 13:32:22 +0000102#include "Python.h"
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000103
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000104#ifdef __osf__
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +0000105#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000106#endif
107
Martin v. Löwiseb9b1032001-10-24 17:10:49 +0000108#ifdef __hpux
Martin v. Löwiseb9b1032001-10-24 17:10:49 +0000109#define STRICT_SYSV_CURSES
110#endif
111
Guido van Rossum858ca0f2001-04-10 19:53:37 +0000112#define CURSES_MODULE
113#include "py_curses.h"
114
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000115/* These prototypes are in <term.h>, but including this header
116 #defines many common symbols (such as "lines") which breaks the
117 curses module in other ways. So the code will just specify
118 explicit prototypes here. */
119extern int setupterm(char *,int,int *);
Fred Drake0368bc42001-07-19 20:48:32 +0000120#ifdef __sgi
121#include <term.h>
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +0000122#endif
123
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000124#if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +0000125#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000126typedef chtype attr_t; /* No attr_t type is available */
Guido van Rossum1266a011996-02-25 04:50:31 +0000127#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000128
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000129#if defined(_AIX)
130#define STRICT_SYSV_CURSES
131#endif
132
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000133/* Definition of exception curses.error */
Guido van Rossumf6971e21994-08-30 12:25:20 +0000134
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000135static PyObject *PyCursesError;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000136
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000137/* Tells whether setupterm() has been called to initialise terminfo. */
138static int initialised_setupterm = FALSE;
139
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000140/* Tells whether initscr() has been called to initialise curses. */
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000141static int initialised = FALSE;
142
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000143/* Tells whether start_color() has been called to initialise color usage. */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000144static int initialisedcolors = FALSE;
145
146/* Utility Macros */
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000147#define PyCursesSetupTermCalled \
148 if (initialised_setupterm != TRUE) { \
149 PyErr_SetString(PyCursesError, \
150 "must call (at least) setupterm() first"); \
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000151 return 0; }
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +0000152
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000153#define PyCursesInitialised \
154 if (initialised != TRUE) { \
155 PyErr_SetString(PyCursesError, \
156 "must call initscr() first"); \
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000157 return 0; }
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000158
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000159#define PyCursesInitialisedColor \
160 if (initialisedcolors != TRUE) { \
161 PyErr_SetString(PyCursesError, \
162 "must call start_color() first"); \
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000163 return 0; }
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000164
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000165/* Utility Functions */
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000166
Guido van Rossum85738471995-02-17 13:50:17 +0000167/*
168 * Check the return code from a curses function and return None
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000169 * or raise an exception as appropriate. These are exported using the
170 * CObject API.
Guido van Rossum85738471995-02-17 13:50:17 +0000171 */
172
173static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000174PyCursesCheckERR(int code, char *fname)
Guido van Rossum85738471995-02-17 13:50:17 +0000175{
Guido van Rossum85738471995-02-17 13:50:17 +0000176 if (code != ERR) {
177 Py_INCREF(Py_None);
178 return Py_None;
179 } else {
180 if (fname == NULL) {
181 PyErr_SetString(PyCursesError, catchall_ERR);
182 } else {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000183 PyErr_Format(PyCursesError, "%s() returned ERR", fname);
Guido van Rossum85738471995-02-17 13:50:17 +0000184 }
185 return NULL;
186 }
187}
188
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000189static int
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000190PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000191{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000192 if (PyInt_Check(obj)) {
193 *ch = (chtype) PyInt_AsLong(obj);
Martin v. Löwisbfdf4ec2001-06-23 19:58:46 +0000194 } else if(PyString_Check(obj)
195 && (PyString_Size(obj) == 1)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000196 *ch = (chtype) *PyString_AsString(obj);
197 } else {
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000198 return 0;
199 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000200 return 1;
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000201}
202
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000203/* Function versions of the 3 functions for tested whether curses has been
204 initialised or not. */
205
206static int func_PyCursesSetupTermCalled(void)
207{
208 PyCursesSetupTermCalled;
209 return 1;
210}
211
212static int func_PyCursesInitialised(void)
213{
214 PyCursesInitialised;
215 return 1;
216}
217
218static int func_PyCursesInitialisedColor(void)
219{
220 PyCursesInitialisedColor;
221 return 1;
222}
223
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000224/*****************************************************************************
225 The Window Object
226******************************************************************************/
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000227
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000228/* Definition of the window type */
Guido van Rossum85738471995-02-17 13:50:17 +0000229
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000230PyTypeObject PyCursesWindow_Type;
231
Andrew M. Kuchling32552682000-12-22 21:52:27 +0000232/* Function prototype macros for Window object
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000233
234 X - function name
235 TYPE - parameter Type
236 ERGSTR - format string for construction of the return value
237 PARSESTR - format string for argument parsing
238 */
239
240#define Window_NoArgNoReturnFunction(X) \
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000241static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000242{ return PyCursesCheckERR(X(self->win), # X); }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000243
244#define Window_NoArgTrueFalseFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000245static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000246{ \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000247 if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
248 else { Py_INCREF(Py_True); return Py_True; } }
249
250#define Window_NoArgNoReturnVoidFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000251static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000252{ \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000253 X(self->win); Py_INCREF(Py_None); return Py_None; }
254
255#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000256static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000257{ \
258 TYPE arg1, arg2; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000259 X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
260
261#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
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; \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000265 if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000266 X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
267
268#define Window_OneArgNoReturnFunction(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; \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000272 if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000273 return PyCursesCheckERR(X(self->win, arg1), # X); }
274
275#define Window_TwoArgNoReturnFunction(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, arg2; \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000279 if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000280 return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
Guido van Rossum85738471995-02-17 13:50:17 +0000281
Guido van Rossumf6971e21994-08-30 12:25:20 +0000282/* ------------- WINDOW routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000283
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000284Window_NoArgNoReturnFunction(untouchwin)
285Window_NoArgNoReturnFunction(touchwin)
286Window_NoArgNoReturnFunction(redrawwin)
287Window_NoArgNoReturnFunction(winsertln)
288Window_NoArgNoReturnFunction(werase)
289Window_NoArgNoReturnFunction(wdeleteln)
290
291Window_NoArgTrueFalseFunction(is_wintouched)
292
293Window_NoArgNoReturnVoidFunction(wsyncup)
294Window_NoArgNoReturnVoidFunction(wsyncdown)
295Window_NoArgNoReturnVoidFunction(wstandend)
296Window_NoArgNoReturnVoidFunction(wstandout)
297Window_NoArgNoReturnVoidFunction(wcursyncup)
298Window_NoArgNoReturnVoidFunction(wclrtoeol)
299Window_NoArgNoReturnVoidFunction(wclrtobot)
300Window_NoArgNoReturnVoidFunction(wclear)
301
302Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")
303Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +0000304Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay")
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000305
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000306Window_NoArg2TupleReturnFunction(getyx, int, "ii")
307Window_NoArg2TupleReturnFunction(getbegyx, int, "ii")
308Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii")
309Window_NoArg2TupleReturnFunction(getparyx, int, "ii")
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000310
311Window_OneArgNoReturnFunction(wattron, attr_t, "l;attr")
312Window_OneArgNoReturnFunction(wattroff, attr_t, "l;attr")
313Window_OneArgNoReturnFunction(wattrset, attr_t, "l;attr")
314Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
315Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000316#if defined(__NetBSD__)
317Window_OneArgNoReturnVoidFunction(keypad, int, "i;True(1) or False(0)")
318#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000319Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000320#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000321Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000322#if defined(__NetBSD__)
323Window_OneArgNoReturnVoidFunction(nodelay, int, "i;True(1) or False(0)")
324#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000325Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000326#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000327Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")
328Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000329Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines")
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000330Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
331
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000332Window_TwoArgNoReturnFunction(mvwin, int, "ii;y,x")
333Window_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x")
334Window_TwoArgNoReturnFunction(wmove, int, "ii;y,x")
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000335#ifndef STRICT_SYSV_CURSES
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000336Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns")
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000337#endif
338
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000339/* Allocation and deallocation of Window Objects */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000340
Guido van Rossumf6971e21994-08-30 12:25:20 +0000341static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000342PyCursesWindow_New(WINDOW *win)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000343{
344 PyCursesWindowObject *wo;
Guido van Rossum85738471995-02-17 13:50:17 +0000345
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000346 wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
347 if (wo == NULL) return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000348 wo->win = win;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000349 return (PyObject *)wo;
350}
351
352static void
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000353PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000354{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000355 if (wo->win != stdscr) delwin(wo->win);
Michael W. Hudson67fb0c32002-01-30 15:39:28 +0000356 PyObject_DEL(wo);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000357}
358
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000359/* Addch, Addstr, Addnstr */
Guido van Rossumf6971e21994-08-30 12:25:20 +0000360
361static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000362PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000363{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000364 int rtn, x, y, use_xy = FALSE;
365 PyObject *temp;
366 chtype ch = 0;
367 attr_t attr = A_NORMAL;
368
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000369 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000370 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000371 if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000372 return NULL;
373 break;
374 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000375 if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &attr))
Guido van Rossum85738471995-02-17 13:50:17 +0000376 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000377 break;
378 case 3:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000379 if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000380 return NULL;
381 use_xy = TRUE;
382 break;
383 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000384 if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000385 &y, &x, &temp, &attr))
386 return NULL;
387 use_xy = TRUE;
388 break;
389 default:
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +0000390 PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000391 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000392 }
Guido van Rossum85738471995-02-17 13:50:17 +0000393
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000394 if (!PyCurses_ConvertToChtype(temp, &ch)) {
395 PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
396 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000397 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000398
Guido van Rossumf6971e21994-08-30 12:25:20 +0000399 if (use_xy == TRUE)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000400 rtn = mvwaddch(self->win,y,x, ch | attr);
401 else {
402 rtn = waddch(self->win, ch | attr);
403 }
404 return PyCursesCheckERR(rtn, "addch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000405}
406
407static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000408PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000409{
410 int rtn;
411 int x, y;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000412 char *str;
413 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
414 int use_xy = FALSE, use_attr = FALSE;
Guido van Rossum85738471995-02-17 13:50:17 +0000415
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000416 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000417 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000418 if (!PyArg_ParseTuple(args,"s;str", &str))
Guido van Rossum85738471995-02-17 13:50:17 +0000419 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000420 break;
421 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000422 if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000423 return NULL;
424 use_attr = TRUE;
425 break;
426 case 3:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000427 if (!PyArg_ParseTuple(args,"iis;int,int,str", &y, &x, &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000428 return NULL;
429 use_xy = TRUE;
430 break;
431 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000432 if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000433 return NULL;
434 use_xy = use_attr = TRUE;
435 break;
436 default:
437 PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
438 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000439 }
Guido van Rossum85738471995-02-17 13:50:17 +0000440
Guido van Rossumf6971e21994-08-30 12:25:20 +0000441 if (use_attr == TRUE) {
442 attr_old = getattrs(self->win);
443 wattrset(self->win,attr);
444 }
445 if (use_xy == TRUE)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000446 rtn = mvwaddstr(self->win,y,x,str);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000447 else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000448 rtn = waddstr(self->win,str);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000449 if (use_attr == TRUE)
450 wattrset(self->win,attr_old);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000451 return PyCursesCheckERR(rtn, "addstr");
452}
Guido van Rossum85738471995-02-17 13:50:17 +0000453
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000454static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000455PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000456{
457 int rtn, x, y, n;
458 char *str;
459 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
460 int use_xy = FALSE, use_attr = FALSE;
461
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000462 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000463 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000464 if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000465 return NULL;
466 break;
467 case 3:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000468 if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000469 return NULL;
470 use_attr = TRUE;
471 break;
472 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000473 if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000474 return NULL;
475 use_xy = TRUE;
476 break;
477 case 5:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000478 if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000479 return NULL;
480 use_xy = use_attr = TRUE;
481 break;
482 default:
483 PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
484 return NULL;
485 }
486
487 if (use_attr == TRUE) {
488 attr_old = getattrs(self->win);
489 wattrset(self->win,attr);
490 }
491 if (use_xy == TRUE)
492 rtn = mvwaddnstr(self->win,y,x,str,n);
493 else
494 rtn = waddnstr(self->win,str,n);
495 if (use_attr == TRUE)
496 wattrset(self->win,attr_old);
497 return PyCursesCheckERR(rtn, "addnstr");
498}
499
500static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000501PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000502{
503 PyObject *temp;
504 chtype bkgd;
505 attr_t attr = A_NORMAL;
506
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000507 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000508 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000509 if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000510 return NULL;
511 break;
512 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000513 if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000514 return NULL;
515 break;
516 default:
517 PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
518 return NULL;
519 }
520
521 if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
522 PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
523 return NULL;
524 }
525
Andrew M. Kuchling4a596e32001-09-04 19:34:32 +0000526 return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000527}
528
529static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000530PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000531{
532 PyObject *temp;
533 chtype bkgd;
534 attr_t attr = A_NORMAL;
535
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000536 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000537 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000538 if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000539 return NULL;
540 break;
541 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000542 if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000543 return NULL;
544 break;
545 default:
546 PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
547 return NULL;
548 }
549
550 if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000551 PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000552 return NULL;
553 }
554
555 wbkgdset(self->win, bkgd | attr);
556 return PyCursesCheckERR(0, "bkgdset");
557}
558
559static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000560PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000561{
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +0000562 PyObject *temp[8];
563 chtype ch[8];
564 int i;
565
566 /* Clear the array of parameters */
567 for(i=0; i<8; i++) {
568 temp[i] = NULL;
569 ch[i] = 0;
570 }
571
572 if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
573 &temp[0], &temp[1], &temp[2], &temp[3],
574 &temp[4], &temp[5], &temp[6], &temp[7]))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000575 return NULL;
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +0000576
577 for(i=0; i<8; i++) {
578 if (temp[i] != NULL && !PyCurses_ConvertToChtype(temp[i], &ch[i])) {
579 PyErr_Format(PyExc_TypeError,
580 "argument %i must be a ch or an int", i+1);
581 return NULL;
582 }
583 }
584
585 wborder(self->win,
586 ch[0], ch[1], ch[2], ch[3],
587 ch[4], ch[5], ch[6], ch[7]);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000588 Py_INCREF(Py_None);
589 return Py_None;
590}
591
592static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000593PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000594{
595 chtype ch1=0,ch2=0;
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000596 switch(PyTuple_Size(args)){
597 case 0: break;
598 default:
599 if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000600 return NULL;
601 }
602 box(self->win,ch1,ch2);
603 Py_INCREF(Py_None);
604 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000605}
606
Martin v. Löwiseb9b1032001-10-24 17:10:49 +0000607#if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
608#define py_mvwdelch mvwdelch
609#else
610int py_mvwdelch(WINDOW *w, int y, int x)
611{
612 mvwdelch(w,y,x);
613 /* On HP/UX, mvwdelch already returns. On other systems,
614 we may well run into this return statement. */
615 return 0;
616}
617#endif
618
619
Guido van Rossumf6971e21994-08-30 12:25:20 +0000620static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000621PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000622{
623 int rtn;
624 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000625
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000626 switch (PyTuple_Size(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000627 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000628 rtn = wdelch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000629 break;
630 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000631 if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
Guido van Rossum85738471995-02-17 13:50:17 +0000632 return NULL;
Martin v. Löwiseb9b1032001-10-24 17:10:49 +0000633 rtn = py_mvwdelch(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000634 break;
635 default:
636 PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
637 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000638 }
Guido van Rossum85738471995-02-17 13:50:17 +0000639 return PyCursesCheckERR(rtn, "[mv]wdelch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000640}
641
642static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000643PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000644{
645 WINDOW *win;
646 int nlines, ncols, begin_y, begin_x;
647
648 nlines = 0;
649 ncols = 0;
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000650 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000651 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000652 if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000653 return NULL;
654 break;
655 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000656 if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000657 &nlines,&ncols,&begin_y,&begin_x))
658 return NULL;
659 break;
660 default:
661 PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
662 return NULL;
663 }
664
665 win = derwin(self->win,nlines,ncols,begin_y,begin_x);
666
667 if (win == NULL) {
668 PyErr_SetString(PyCursesError, catchall_NULL);
669 return NULL;
670 }
671
672 return (PyObject *)PyCursesWindow_New(win);
673}
674
675static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000676PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000677{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000678 PyObject *temp;
679 chtype ch;
680 attr_t attr = A_NORMAL;
Guido van Rossum85738471995-02-17 13:50:17 +0000681
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000682 switch (PyTuple_Size(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000683 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000684 if (!PyArg_ParseTuple(args,"O;ch or int", &temp))
Guido van Rossum85738471995-02-17 13:50:17 +0000685 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +0000686 break;
687 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000688 if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr))
Guido van Rossum85738471995-02-17 13:50:17 +0000689 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +0000690 break;
691 default:
692 PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000693
694
Guido van Rossum85738471995-02-17 13:50:17 +0000695 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000696 }
Guido van Rossum85738471995-02-17 13:50:17 +0000697
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000698 if (!PyCurses_ConvertToChtype(temp, &ch)) {
699 PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
Guido van Rossum85738471995-02-17 13:50:17 +0000700 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000701 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000702
Martin v. Löwiseb9b1032001-10-24 17:10:49 +0000703#ifdef WINDOW_HAS_FLAGS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000704 if (self->win->_flags & _ISPAD)
705 return PyCursesCheckERR(pechochar(self->win, ch | attr),
706 "echochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000707 else
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000708#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000709 return PyCursesCheckERR(wechochar(self->win, ch | attr),
710 "echochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000711}
712
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000713#ifdef NCURSES_MOUSE_VERSION
714static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000715PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000716{
717 int x, y;
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000718 if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +0000719 return NULL;
720
721 return PyInt_FromLong( wenclose(self->win,y,x) );
722}
723#endif
724
Guido van Rossumf6971e21994-08-30 12:25:20 +0000725static PyObject *
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000726PyCursesWindow_GetBkgd(PyCursesWindowObject *self)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000727{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000728 return PyInt_FromLong((long) getbkgd(self->win));
Guido van Rossumf6971e21994-08-30 12:25:20 +0000729}
730
731static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000732PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000733{
734 int x, y;
Andrew M. Kuchling7e23f002002-11-06 14:15:36 +0000735 int rtn;
Guido van Rossum85738471995-02-17 13:50:17 +0000736
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000737 switch (PyTuple_Size(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000738 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000739 Py_BEGIN_ALLOW_THREADS
Guido van Rossumf6971e21994-08-30 12:25:20 +0000740 rtn = wgetch(self->win);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000741 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000742 break;
743 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000744 if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000745 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000746 Py_BEGIN_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000747 rtn = mvwgetch(self->win,y,x);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000748 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000749 break;
750 default:
751 PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
752 return NULL;
753 }
Fred Drake0368bc42001-07-19 20:48:32 +0000754 return PyInt_FromLong((long)rtn);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000755}
Guido van Rossum85738471995-02-17 13:50:17 +0000756
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000757static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000758PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000759{
760 int x, y;
Andrew M. Kuchling7e23f002002-11-06 14:15:36 +0000761 int rtn;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000762
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000763 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000764 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000765 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000766 rtn = wgetch(self->win);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000767 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000768 break;
769 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000770 if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000771 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000772 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000773 rtn = mvwgetch(self->win,y,x);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000774 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000775 break;
776 default:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +0000777 PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000778 return NULL;
779 }
Andrew M. Kuchling7e23f002002-11-06 14:15:36 +0000780 if (rtn == ERR) {
781 /* getch() returns ERR in nodelay mode */
782 PyErr_SetString(PyCursesError, "no input");
783 return NULL;
784 } else if (rtn<=255)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000785 return Py_BuildValue("c", rtn);
786 else
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000787#if defined(__NetBSD__)
788 return PyString_FromString(unctrl(rtn));
789#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000790 return PyString_FromString((char *)keyname(rtn));
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +0000791#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000792}
793
794static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000795PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000796{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000797 int x, y, n;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000798 char rtn[1024]; /* This should be big enough.. I hope */
799 int rtn2;
Guido van Rossum85738471995-02-17 13:50:17 +0000800
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000801 switch (PyTuple_Size(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000802 case 0:
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000803 Py_BEGIN_ALLOW_THREADS
Guido van Rossumf6971e21994-08-30 12:25:20 +0000804 rtn2 = wgetstr(self->win,rtn);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000805 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000806 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000807 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000808 if (!PyArg_ParseTuple(args,"i;n", &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000809 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000810 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000811 rtn2 = wgetnstr(self->win,rtn,n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000812 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000813 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000814 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000815 if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000816 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000817 Py_BEGIN_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000818 rtn2 = mvwgetstr(self->win,y,x,rtn);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000819 Py_END_ALLOW_THREADS
Guido van Rossum85738471995-02-17 13:50:17 +0000820 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000821 case 3:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000822 if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000823 return NULL;
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +0000824#ifdef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000825 /* Untested */
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000826 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000827 rtn2 = wmove(self->win,y,x)==ERR ? ERR :
828 wgetnstr(self->win, rtn, n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000829 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000830#else
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000831 Py_BEGIN_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000832 rtn2 = mvwgetnstr(self->win, y, x, rtn, n);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +0000833 Py_END_ALLOW_THREADS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000834#endif
835 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000836 default:
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000837 PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 2 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000838 return NULL;
839 }
Guido van Rossumf6971e21994-08-30 12:25:20 +0000840 if (rtn2 == ERR)
841 rtn[0] = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000842 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000843}
844
845static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000846PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000847{
848 PyObject *temp;
849 chtype ch;
850 int n, x, y, code = OK;
851 attr_t attr = A_NORMAL;
852
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000853 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000854 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000855 if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000856 return NULL;
857 break;
858 case 3:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000859 if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000860 return NULL;
861 break;
862 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000863 if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000864 return NULL;
865 code = wmove(self->win, y, x);
866 break;
867 case 5:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000868 if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000869 &y, &x, &temp, &n, &attr))
870 return NULL;
871 code = wmove(self->win, y, x);
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +0000872 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000873 default:
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +0000874 PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000875 return NULL;
876 }
877
878 if (code != ERR) {
879 if (!PyCurses_ConvertToChtype(temp, &ch)) {
880 PyErr_SetString(PyExc_TypeError,
881 "argument 1 or 3 must be a ch or an int");
882 return NULL;
883 }
884 return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
885 } else
886 return PyCursesCheckERR(code, "wmove");
887}
888
889static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000890PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000891{
892 int rtn, x, y, use_xy = FALSE;
893 PyObject *temp;
894 chtype ch = 0;
895 attr_t attr = A_NORMAL;
896
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000897 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000898 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000899 if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000900 return NULL;
901 break;
902 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000903 if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000904 return NULL;
905 break;
906 case 3:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000907 if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000908 return NULL;
909 use_xy = TRUE;
910 break;
911 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000912 if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000913 return NULL;
914 use_xy = TRUE;
915 break;
916 default:
917 PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
918 return NULL;
919 }
920
921 if (!PyCurses_ConvertToChtype(temp, &ch)) {
922 PyErr_SetString(PyExc_TypeError,
923 "argument 1 or 3 must be a ch or an int");
924 return NULL;
925 }
926
927 if (use_xy == TRUE)
928 rtn = mvwinsch(self->win,y,x, ch | attr);
929 else {
930 rtn = winsch(self->win, ch | attr);
931 }
932 return PyCursesCheckERR(rtn, "insch");
933}
934
935static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000936PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000937{
Guido van Rossum85738471995-02-17 13:50:17 +0000938 int x, y, rtn;
939
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000940 switch (PyTuple_Size(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +0000941 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000942 rtn = winch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000943 break;
944 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000945 if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +0000946 return NULL;
947 rtn = mvwinch(self->win,y,x);
948 break;
949 default:
950 PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
951 return NULL;
952 }
Guido van Rossum85738471995-02-17 13:50:17 +0000953 return PyInt_FromLong((long) rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000954}
955
956static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000957PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000958{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000959 int x, y, n;
960 char rtn[1024]; /* This should be big enough.. I hope */
961 int rtn2;
962
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000963 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000964 case 0:
965 rtn2 = winstr(self->win,rtn);
966 break;
967 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000968 if (!PyArg_ParseTuple(args,"i;n", &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000969 return NULL;
970 rtn2 = winnstr(self->win,rtn,n);
971 break;
972 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000973 if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000974 return NULL;
975 rtn2 = mvwinstr(self->win,y,x,rtn);
976 break;
977 case 3:
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000978 if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000979 return NULL;
980 rtn2 = mvwinnstr(self->win, y, x, rtn, n);
981 break;
982 default:
983 PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +0000984 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000985 }
986 if (rtn2 == ERR)
987 rtn[0] = 0;
988 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000989}
990
991static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +0000992PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +0000993{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +0000994 int rtn;
995 int x, y;
996 char *str;
997 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
998 int use_xy = FALSE, use_attr = FALSE;
999
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001000 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001001 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001002 if (!PyArg_ParseTuple(args,"s;str", &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001003 return NULL;
1004 break;
1005 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001006 if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001007 return NULL;
1008 use_attr = TRUE;
1009 break;
1010 case 3:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001011 if (!PyArg_ParseTuple(args,"iis;y,x,str", &y, &x, &str))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001012 return NULL;
1013 use_xy = TRUE;
1014 break;
1015 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001016 if (!PyArg_ParseTuple(args,"iisl;y,x,str,attr", &y, &x, &str, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001017 return NULL;
1018 use_xy = use_attr = TRUE;
1019 break;
1020 default:
1021 PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001022 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001023 }
1024
1025 if (use_attr == TRUE) {
1026 attr_old = getattrs(self->win);
1027 wattrset(self->win,attr);
1028 }
1029 if (use_xy == TRUE)
1030 rtn = mvwinsstr(self->win,y,x,str);
1031 else
1032 rtn = winsstr(self->win,str);
1033 if (use_attr == TRUE)
1034 wattrset(self->win,attr_old);
1035 return PyCursesCheckERR(rtn, "insstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001036}
1037
1038static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001039PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001040{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001041 int rtn, x, y, n;
1042 char *str;
1043 attr_t attr = A_NORMAL , attr_old = A_NORMAL;
1044 int use_xy = FALSE, use_attr = FALSE;
1045
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001046 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001047 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001048 if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001049 return NULL;
1050 break;
1051 case 3:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001052 if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001053 return NULL;
1054 use_attr = TRUE;
1055 break;
1056 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001057 if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001058 return NULL;
1059 use_xy = TRUE;
1060 break;
1061 case 5:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001062 if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001063 return NULL;
1064 use_xy = use_attr = TRUE;
1065 break;
1066 default:
1067 PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001068 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001069 }
1070
1071 if (use_attr == TRUE) {
1072 attr_old = getattrs(self->win);
1073 wattrset(self->win,attr);
1074 }
1075 if (use_xy == TRUE)
1076 rtn = mvwinsnstr(self->win,y,x,str,n);
1077 else
1078 rtn = winsnstr(self->win,str,n);
1079 if (use_attr == TRUE)
1080 wattrset(self->win,attr_old);
1081 return PyCursesCheckERR(rtn, "insnstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001082}
1083
1084static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001085PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001086{
1087 int line, erg;
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001088 if (!PyArg_ParseTuple(args,"i;line", &line))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001089 return NULL;
1090 erg = is_linetouched(self->win, line);
1091 if (erg == ERR) {
1092 PyErr_SetString(PyExc_TypeError,
1093 "is_linetouched: line number outside of boundaries");
1094 return NULL;
1095 } else
1096 if (erg == FALSE) {
1097 Py_INCREF(Py_False);
1098 return Py_False;
1099 } else {
1100 Py_INCREF(Py_True);
1101 return Py_True;
1102 }
1103}
1104
1105static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001106PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001107{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001108 int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001109 int rtn;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001110
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00001111#ifndef WINDOW_HAS_FLAGS
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001112 if (0) {
1113#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001114 if (self->win->_flags & _ISPAD) {
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001115#endif
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001116 switch(PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001117 case 6:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001118 if (!PyArg_ParseTuple(args,
1119 "iiiiii;" \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001120 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1121 &pminrow, &pmincol, &sminrow,
1122 &smincol, &smaxrow, &smaxcol))
1123 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001124 Py_BEGIN_ALLOW_THREADS
1125 rtn = pnoutrefresh(self->win,
1126 pminrow, pmincol, sminrow,
Andrew M. Kuchlingb6e46872000-06-27 15:01:10 +00001127 smincol, smaxrow, smaxcol);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001128 Py_END_ALLOW_THREADS
1129 return PyCursesCheckERR(rtn, "pnoutrefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001130 default:
1131 PyErr_SetString(PyCursesError,
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001132 "noutrefresh() called for a pad "
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001133 "requires 6 arguments");
1134 return NULL;
1135 }
1136 } else {
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001137 if (!PyArg_ParseTuple(args, ":noutrefresh"))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001138 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001139
1140 Py_BEGIN_ALLOW_THREADS
1141 rtn = wnoutrefresh(self->win);
1142 Py_END_ALLOW_THREADS
1143 return PyCursesCheckERR(rtn, "wnoutrefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001144 }
1145}
1146
1147static PyObject *
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +00001148PyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args)
1149{
1150 PyCursesWindowObject *temp;
1151 int use_copywin = FALSE;
1152 int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
1153 int rtn;
1154
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001155 switch (PyTuple_Size(args)) {
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +00001156 case 1:
1157 if (!PyArg_ParseTuple(args, "O!;window object",
1158 &PyCursesWindow_Type, &temp))
1159 return NULL;
1160 break;
1161 case 7:
1162 if (!PyArg_ParseTuple(args, "(O!iiiiii);window object, int, int, int, int, int, int",
1163 &PyCursesWindow_Type, &temp, &sminrow, &smincol,
1164 &dminrow, &dmincol, &dmaxrow, &dmaxcol))
1165 return NULL;
1166 use_copywin = TRUE;
1167 break;
1168 default:
1169 PyErr_SetString(PyExc_TypeError,
1170 "overlay requires one or seven arguments");
1171 return NULL;
1172 }
1173
1174 if (use_copywin == TRUE) {
1175 rtn = copywin(self->win, temp->win, sminrow, smincol,
1176 dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
1177 return PyCursesCheckERR(rtn, "copywin");
1178 }
1179 else {
1180 rtn = overlay(self->win, temp->win);
1181 return PyCursesCheckERR(rtn, "overlay");
1182 }
1183}
1184
1185static PyObject *
1186PyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args)
1187{
1188 PyCursesWindowObject *temp;
1189 int use_copywin = FALSE;
1190 int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
1191 int rtn;
1192
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001193 switch (PyTuple_Size(args)) {
Andrew M. Kuchling9de6ffa2000-12-21 16:22:22 +00001194 case 1:
1195 if (!PyArg_ParseTuple(args, "O!;window object",
1196 &PyCursesWindow_Type, &temp))
1197 return NULL;
1198 break;
1199 case 7:
1200 if (!PyArg_ParseTuple(args, "(O!iiiiii);window object, int, int, int, int, int, int",
1201 &PyCursesWindow_Type, &temp, &sminrow, &smincol,
1202 &dminrow, &dmincol, &dmaxrow, &dmaxcol))
1203 return NULL;
1204 use_copywin = TRUE;
1205 break;
1206 default:
1207 PyErr_SetString(PyExc_TypeError,
1208 "overwrite requires one or seven arguments");
1209 return NULL;
1210 }
1211
1212 if (use_copywin == TRUE) {
1213 rtn = copywin(self->win, temp->win, sminrow, smincol,
1214 dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
1215 return PyCursesCheckERR(rtn, "copywin");
1216 }
1217 else {
1218 rtn = overwrite(self->win, temp->win);
1219 return PyCursesCheckERR(rtn, "overwrite");
1220 }
1221}
1222
1223static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001224PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001225{
1226 PyObject *temp;
1227
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001228 if (!PyArg_ParseTuple(args, "O;fileobj", &temp))
Guido van Rossum85738471995-02-17 13:50:17 +00001229 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001230 if (!PyFile_Check(temp)) {
1231 PyErr_SetString(PyExc_TypeError, "argument must be a file object");
1232 return NULL;
1233 }
1234 return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)),
1235 "putwin");
1236}
1237
1238static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001239PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001240{
1241 int beg, num;
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001242 if (!PyArg_ParseTuple(args,"ii;beg,num", &beg, &num))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001243 return NULL;
1244 return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
1245}
1246
1247static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001248PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001249{
1250 int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001251 int rtn;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001252
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00001253#ifndef WINDOW_HAS_FLAGS
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001254 if (0) {
1255#else
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001256 if (self->win->_flags & _ISPAD) {
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001257#endif
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001258 switch(PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001259 case 6:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001260 if (!PyArg_ParseTuple(args,
1261 "iiiiii;" \
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001262 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1263 &pminrow, &pmincol, &sminrow,
1264 &smincol, &smaxrow, &smaxcol))
1265 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001266
1267 Py_BEGIN_ALLOW_THREADS
1268 rtn = prefresh(self->win,
1269 pminrow, pmincol, sminrow,
Andrew M. Kuchlingb6e46872000-06-27 15:01:10 +00001270 smincol, smaxrow, smaxcol);
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001271 Py_END_ALLOW_THREADS
1272 return PyCursesCheckERR(rtn, "prefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001273 default:
1274 PyErr_SetString(PyCursesError,
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001275 "refresh() for a pad requires 6 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001276 return NULL;
1277 }
1278 } else {
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001279 if (!PyArg_ParseTuple(args, ":refresh"))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001280 return NULL;
Andrew M. Kuchlingf4195722000-06-23 01:36:21 +00001281 Py_BEGIN_ALLOW_THREADS
1282 rtn = wrefresh(self->win);
1283 Py_END_ALLOW_THREADS
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001284 return PyCursesCheckERR(rtn, "prefresh");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001285 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001286}
1287
1288static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001289PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001290{
1291 int x, y;
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001292 if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +00001293 return NULL;
1294 return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001295}
1296
1297static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001298PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001299{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001300 WINDOW *win;
1301 int nlines, ncols, begin_y, begin_x;
1302
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001303 nlines = 0;
1304 ncols = 0;
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001305 switch (PyTuple_Size(args)) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001306 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001307 if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001308 return NULL;
1309 break;
1310 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001311 if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001312 &nlines,&ncols,&begin_y,&begin_x))
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001313 return NULL;
1314 break;
1315 default:
1316 PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001317 return NULL;
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001318 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001319
Andrew M. Kuchling8353f622000-07-26 18:36:27 +00001320 /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00001321#ifdef WINDOW_HAS_FLAGS
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001322 if (self->win->_flags & _ISPAD)
1323 win = subpad(self->win, nlines, ncols, begin_y, begin_x);
1324 else
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001325#endif
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001326 win = subwin(self->win, nlines, ncols, begin_y, begin_x);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001327
1328 if (win == NULL) {
1329 PyErr_SetString(PyCursesError, catchall_NULL);
1330 return NULL;
1331 }
1332
1333 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001334}
1335
1336static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001337PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001338{
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001339 int nlines;
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001340 switch(PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001341 case 0:
1342 return PyCursesCheckERR(scroll(self->win), "scroll");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001343 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001344 if (!PyArg_ParseTuple(args, "i;nlines", &nlines))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001345 return NULL;
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001346 return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001347 default:
1348 PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001349 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001350 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001351}
1352
1353static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001354PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001355{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001356 int st, cnt, val;
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001357 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001358 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001359 if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001360 return NULL;
1361 return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001362 case 3:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001363 if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001364 return NULL;
1365 return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
1366 default:
1367 PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
Guido van Rossum85738471995-02-17 13:50:17 +00001368 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001369 }
1370}
1371
1372static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001373PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001374{
1375 PyObject *temp;
1376 chtype ch;
1377 int n, x, y, code = OK;
1378 attr_t attr = A_NORMAL;
1379
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001380 switch (PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001381 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001382 if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001383 return NULL;
1384 break;
1385 case 3:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001386 if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &attr))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001387 return NULL;
1388 break;
1389 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001390 if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001391 return NULL;
1392 code = wmove(self->win, y, x);
1393 break;
1394 case 5:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001395 if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001396 &y, &x, &temp, &n, &attr))
1397 return NULL;
1398 code = wmove(self->win, y, x);
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00001399 break;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001400 default:
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00001401 PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001402 return NULL;
1403 }
1404
1405 if (code != ERR) {
1406 if (!PyCurses_ConvertToChtype(temp, &ch)) {
1407 PyErr_SetString(PyExc_TypeError,
1408 "argument 1 or 3 must be a ch or an int");
1409 return NULL;
1410 }
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001411 return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001412 } else
1413 return PyCursesCheckERR(code, "wmove");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001414}
1415
1416static PyMethodDef PyCursesWindow_Methods[] = {
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001417 {"addch", (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS},
1418 {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS},
1419 {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS},
1420 {"attroff", (PyCFunction)PyCursesWindow_wattroff, METH_VARARGS},
1421 {"attron", (PyCFunction)PyCursesWindow_wattron, METH_VARARGS},
1422 {"attrset", (PyCFunction)PyCursesWindow_wattrset, METH_VARARGS},
1423 {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS},
1424 {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS},
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001425 {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001426 {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS},
1427 {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS},
1428 {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS},
1429 {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS},
1430 {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS},
1431 {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS},
1432 {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS},
1433 {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS},
1434 {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS},
1435 {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001436#ifdef NCURSES_MOUSE_VERSION
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001437 {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001438#endif
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001439 {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS},
1440 {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},
1441 {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS},
1442 {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS},
1443 {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS},
1444 {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},
1445 {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},
1446 {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},
1447 {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS},
1448 {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS},
1449 {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS},
1450 {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS},
1451 {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS},
1452 {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS},
1453 {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS},
1454 {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS},
1455 {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS},
1456 {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS},
1457 {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS},
1458 {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS},
1459 {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS},
1460 {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS},
1461 {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS},
1462 {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS},
1463 {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS},
1464 {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS},
1465 {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS},
1466 {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS},
1467 {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS},
1468 {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
1469 /* Backward compatibility alias -- remove in Python 2.3 */
1470 {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00001471 {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS},
1472 {"overwrite", (PyCFunction)PyCursesWindow_Overwrite,
1473 METH_VARARGS},
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001474 {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_VARARGS},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001475 {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine},
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001476 {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS},
1477 {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS},
Andrew M. Kuchlinga1e4b052000-06-27 21:49:47 +00001478#ifndef STRICT_SYSV_CURSES
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001479 {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS},
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001480#endif
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001481 {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS},
1482 {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS},
1483 {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS},
1484 {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS},
1485 {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS},
1486 {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
1487 {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
1488 {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS},
1489 {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS},
1490 {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS},
1491 {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS},
1492 {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS},
1493 {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS},
1494 {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS},
1495 {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS},
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00001496 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00001497};
1498
1499static PyObject *
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00001500PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001501{
Guido van Rossuma597dde1995-01-10 20:56:29 +00001502 return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001503}
1504
Guido van Rossumf6971e21994-08-30 12:25:20 +00001505/* -------------------------------------------------------*/
Guido van Rossum85738471995-02-17 13:50:17 +00001506
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001507PyTypeObject PyCursesWindow_Type = {
Guido van Rossum6915c4d2001-01-19 00:28:08 +00001508 PyObject_HEAD_INIT(NULL)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001509 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +00001510 "_curses.curses window", /*tp_name*/
Guido van Rossumf6971e21994-08-30 12:25:20 +00001511 sizeof(PyCursesWindowObject), /*tp_basicsize*/
1512 0, /*tp_itemsize*/
1513 /* methods */
1514 (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
1515 0, /*tp_print*/
1516 (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
1517 (setattrfunc)0, /*tp_setattr*/
1518 0, /*tp_compare*/
1519 0, /*tp_repr*/
1520 0, /*tp_as_number*/
1521 0, /*tp_as_sequence*/
1522 0, /*tp_as_mapping*/
1523 0, /*tp_hash*/
1524};
1525
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001526/*********************************************************************
1527 Global Functions
1528**********************************************************************/
Guido van Rossumf6971e21994-08-30 12:25:20 +00001529
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001530NoArgNoReturnFunction(beep)
1531NoArgNoReturnFunction(def_prog_mode)
1532NoArgNoReturnFunction(def_shell_mode)
1533NoArgNoReturnFunction(doupdate)
1534NoArgNoReturnFunction(endwin)
1535NoArgNoReturnFunction(flash)
1536NoArgNoReturnFunction(nocbreak)
1537NoArgNoReturnFunction(noecho)
1538NoArgNoReturnFunction(nonl)
1539NoArgNoReturnFunction(noraw)
1540NoArgNoReturnFunction(reset_prog_mode)
1541NoArgNoReturnFunction(reset_shell_mode)
1542NoArgNoReturnFunction(resetty)
1543NoArgNoReturnFunction(savetty)
1544
1545NoArgOrFlagNoReturnFunction(cbreak)
1546NoArgOrFlagNoReturnFunction(echo)
1547NoArgOrFlagNoReturnFunction(nl)
1548NoArgOrFlagNoReturnFunction(raw)
1549
1550NoArgReturnIntFunction(baudrate)
1551NoArgReturnIntFunction(termattrs)
1552
1553NoArgReturnStringFunction(termname)
1554NoArgReturnStringFunction(longname)
1555
1556NoArgTrueFalseFunction(can_change_color)
1557NoArgTrueFalseFunction(has_colors)
1558NoArgTrueFalseFunction(has_ic)
1559NoArgTrueFalseFunction(has_il)
1560NoArgTrueFalseFunction(isendwin)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001561NoArgNoReturnVoidFunction(filter)
1562NoArgNoReturnVoidFunction(flushinp)
1563NoArgNoReturnVoidFunction(noqiflush)
1564
1565static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001566PyCurses_Color_Content(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001567{
1568 short color,r,g,b;
1569
1570 PyCursesInitialised
1571 PyCursesInitialisedColor
1572
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001573 if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001574
1575 if (color_content(color, &r, &g, &b) != ERR)
1576 return Py_BuildValue("(iii)", r, g, b);
1577 else {
1578 PyErr_SetString(PyCursesError,
1579 "Argument 1 was out of range. Check value of COLORS.");
1580 return NULL;
1581 }
1582}
1583
1584static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001585PyCurses_color_pair(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001586{
1587 int n;
1588
1589 PyCursesInitialised
1590 PyCursesInitialisedColor
1591
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001592 if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001593 return PyInt_FromLong((long) (n << 8));
1594}
1595
1596static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001597PyCurses_Curs_Set(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001598{
1599 int vis,erg;
1600
1601 PyCursesInitialised
1602
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001603 if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001604
1605 erg = curs_set(vis);
1606 if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
1607
1608 return PyInt_FromLong((long) erg);
1609}
1610
1611static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001612PyCurses_Delay_Output(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001613{
1614 int ms;
1615
1616 PyCursesInitialised
1617
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001618 if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001619
1620 return PyCursesCheckERR(delay_output(ms), "delay_output");
1621}
1622
1623static PyObject *
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001624PyCurses_EraseChar(PyObject *self)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001625{
1626 char ch;
1627
1628 PyCursesInitialised
1629
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001630 ch = erasechar();
1631
Martin v. Löwis43f2dc62001-11-11 14:49:15 +00001632 return PyString_FromStringAndSize(&ch, 1);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001633}
1634
1635static PyObject *
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001636PyCurses_getsyx(PyObject *self)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001637{
1638 int x,y;
1639
1640 PyCursesInitialised
1641
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001642 getsyx(y, x);
1643
1644 return Py_BuildValue("(ii)", y, x);
1645}
1646
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001647#ifdef NCURSES_MOUSE_VERSION
1648static PyObject *
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001649PyCurses_GetMouse(PyObject *self)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001650{
1651 int rtn;
1652 MEVENT event;
1653
1654 PyCursesInitialised
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001655
1656 rtn = getmouse( &event );
1657 if (rtn == ERR) {
1658 PyErr_SetString(PyCursesError, "getmouse() returned ERR");
1659 return NULL;
1660 }
1661 return Py_BuildValue("(hiiil)",
1662 (short)event.id,
1663 event.x, event.y, event.z,
1664 (long) event.bstate);
1665}
1666
1667static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001668PyCurses_UngetMouse(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001669{
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001670 MEVENT event;
1671
1672 PyCursesInitialised
1673 if (!PyArg_ParseTuple(args, "(hiiil)",
1674 &event.id,
1675 &event.x, &event.y, &event.z,
1676 (int *) &event.bstate))
1677 return NULL;
1678
1679 return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
1680}
1681#endif
1682
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001683static PyObject *
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001684PyCurses_GetWin(PyCursesWindowObject *self, PyObject *temp)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001685{
1686 WINDOW *win;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001687
1688 PyCursesInitialised
1689
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001690 if (!PyFile_Check(temp)) {
1691 PyErr_SetString(PyExc_TypeError, "argument must be a file object");
1692 return NULL;
1693 }
1694
1695 win = getwin(PyFile_AsFile(temp));
1696
1697 if (win == NULL) {
1698 PyErr_SetString(PyCursesError, catchall_NULL);
1699 return NULL;
1700 }
1701
1702 return PyCursesWindow_New(win);
1703}
1704
1705static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001706PyCurses_HalfDelay(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001707{
1708 unsigned char tenths;
1709
1710 PyCursesInitialised
1711
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001712 if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001713
1714 return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
1715}
1716
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00001717#ifndef STRICT_SYSV_CURSES
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001718 /* No has_key! */
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001719static PyObject * PyCurses_has_key(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001720{
1721 int ch;
1722
1723 PyCursesInitialised
1724
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001725 if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001726
1727 if (has_key(ch) == FALSE) {
1728 Py_INCREF(Py_False);
1729 return Py_False;
1730 }
1731 Py_INCREF(Py_True);
1732 return Py_True;
1733}
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00001734#endif /* STRICT_SYSV_CURSES */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001735
1736static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001737PyCurses_Init_Color(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001738{
1739 short color, r, g, b;
1740
1741 PyCursesInitialised
1742 PyCursesInitialisedColor
1743
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001744 switch(PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001745 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001746 if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001747 break;
1748 default:
1749 PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
1750 return NULL;
1751 }
1752
1753 return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
1754}
1755
1756static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001757PyCurses_Init_Pair(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001758{
1759 short pair, f, b;
1760
1761 PyCursesInitialised
1762 PyCursesInitialisedColor
1763
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001764 if (PyTuple_Size(args) != 3) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001765 PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
1766 return NULL;
1767 }
1768
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001769 if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001770
1771 return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
1772}
1773
Andrew M. Kuchling32552682000-12-22 21:52:27 +00001774static PyObject *ModDict;
1775
Guido van Rossumf6971e21994-08-30 12:25:20 +00001776static PyObject *
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001777PyCurses_InitScr(PyObject *self)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001778{
Guido van Rossum56bf2351994-08-31 22:06:24 +00001779 WINDOW *win;
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001780 PyObject *nlines, *cols;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001781
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001782 if (initialised == TRUE) {
Guido van Rossumf6971e21994-08-30 12:25:20 +00001783 wrefresh(stdscr);
1784 return (PyObject *)PyCursesWindow_New(stdscr);
1785 }
Guido van Rossum56bf2351994-08-31 22:06:24 +00001786
1787 win = initscr();
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001788
Guido van Rossum85738471995-02-17 13:50:17 +00001789 if (win == NULL) {
1790 PyErr_SetString(PyCursesError, catchall_NULL);
1791 return NULL;
1792 }
1793
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00001794 initialised = initialised_setupterm = TRUE;
Guido van Rossum56bf2351994-08-31 22:06:24 +00001795
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001796/* This was moved from initcurses() because it core dumped on SGI,
1797 where they're not defined until you've called initscr() */
1798#define SetDictInt(string,ch) \
1799 PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
1800
1801 /* Here are some graphic symbols you can use */
1802 SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
1803 SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
1804 SetDictInt("ACS_URCORNER", (ACS_URCORNER));
1805 SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
1806 SetDictInt("ACS_LTEE", (ACS_LTEE));
1807 SetDictInt("ACS_RTEE", (ACS_RTEE));
1808 SetDictInt("ACS_BTEE", (ACS_BTEE));
1809 SetDictInt("ACS_TTEE", (ACS_TTEE));
1810 SetDictInt("ACS_HLINE", (ACS_HLINE));
1811 SetDictInt("ACS_VLINE", (ACS_VLINE));
1812 SetDictInt("ACS_PLUS", (ACS_PLUS));
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00001813#if !defined(__hpux) || defined(HAVE_NCURSES_H)
1814 /* On HP/UX 11, these are of type cchar_t, which is not an
1815 integral type. If this is a problem on more platforms, a
1816 configure test should be added to determine whether ACS_S1
1817 is of integral type. */
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001818 SetDictInt("ACS_S1", (ACS_S1));
1819 SetDictInt("ACS_S9", (ACS_S9));
1820 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
1821 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
1822 SetDictInt("ACS_DEGREE", (ACS_DEGREE));
1823 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
1824 SetDictInt("ACS_BULLET", (ACS_BULLET));
1825 SetDictInt("ACS_LARROW", (ACS_LARROW));
1826 SetDictInt("ACS_RARROW", (ACS_RARROW));
1827 SetDictInt("ACS_DARROW", (ACS_DARROW));
1828 SetDictInt("ACS_UARROW", (ACS_UARROW));
1829 SetDictInt("ACS_BOARD", (ACS_BOARD));
1830 SetDictInt("ACS_LANTERN", (ACS_LANTERN));
1831 SetDictInt("ACS_BLOCK", (ACS_BLOCK));
Martin v. Löwiseb9b1032001-10-24 17:10:49 +00001832#endif
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001833 SetDictInt("ACS_BSSB", (ACS_ULCORNER));
1834 SetDictInt("ACS_SSBB", (ACS_LLCORNER));
1835 SetDictInt("ACS_BBSS", (ACS_URCORNER));
1836 SetDictInt("ACS_SBBS", (ACS_LRCORNER));
1837 SetDictInt("ACS_SBSS", (ACS_RTEE));
1838 SetDictInt("ACS_SSSB", (ACS_LTEE));
1839 SetDictInt("ACS_SSBS", (ACS_BTEE));
1840 SetDictInt("ACS_BSSS", (ACS_TTEE));
1841 SetDictInt("ACS_BSBS", (ACS_HLINE));
1842 SetDictInt("ACS_SBSB", (ACS_VLINE));
1843 SetDictInt("ACS_SSSS", (ACS_PLUS));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001844
1845 /* The following are never available with strict SYSV curses */
1846#ifdef ACS_S3
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001847 SetDictInt("ACS_S3", (ACS_S3));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001848#endif
1849#ifdef ACS_S7
1850 SetDictInt("ACS_S7", (ACS_S7));
1851#endif
1852#ifdef ACS_LEQUAL
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001853 SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001854#endif
1855#ifdef ACS_GEQUAL
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001856 SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001857#endif
1858#ifdef ACS_PI
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001859 SetDictInt("ACS_PI", (ACS_PI));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001860#endif
1861#ifdef ACS_NEQUAL
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001862 SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00001863#endif
1864#ifdef ACS_STERLING
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00001865 SetDictInt("ACS_STERLING", (ACS_STERLING));
1866#endif
1867
Andrew M. Kuchlinge1c43522001-01-29 20:31:29 +00001868 nlines = PyInt_FromLong((long) LINES);
1869 PyDict_SetItemString(ModDict, "LINES", nlines);
1870 Py_DECREF(nlines);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001871 cols = PyInt_FromLong((long) COLS);
1872 PyDict_SetItemString(ModDict, "COLS", cols);
1873 Py_DECREF(cols);
Guido van Rossum56bf2351994-08-31 22:06:24 +00001874
1875 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001876}
1877
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00001878static PyObject *
1879PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
1880{
1881 int fd = -1;
1882 int err;
1883 char* termstr = NULL;
1884
1885 static char *kwlist[] = {"term", "fd", NULL};
1886
1887 if (!PyArg_ParseTupleAndKeywords(
1888 args,keywds,"|zi:setupterm",kwlist,&termstr,&fd)) {
1889 return NULL;
1890 }
1891
1892 if (fd == -1) {
1893 PyObject* sys_stdout;
1894
1895 sys_stdout = PySys_GetObject("stdout");
1896
1897 if (sys_stdout == NULL) {
1898 PyErr_SetString(
1899 PyCursesError,
1900 "lost sys.stdout");
1901 return NULL;
1902 }
1903
1904 fd = PyObject_AsFileDescriptor(sys_stdout);
1905
1906 if (fd == -1) {
1907 return NULL;
1908 }
1909 }
1910
1911 if (setupterm(termstr,fd,&err) == ERR) {
1912 char* s = "setupterm: unknown error";
1913
1914 if (err == 0) {
1915 s = "setupterm: could not find terminal";
1916 } else if (err == -1) {
1917 s = "setupterm: could not find terminfo database";
1918 }
1919
1920 PyErr_SetString(PyCursesError,s);
1921 return NULL;
1922 }
1923
1924 initialised_setupterm = TRUE;
1925
1926 Py_INCREF(Py_None);
1927 return Py_None;
1928}
Guido van Rossumf6971e21994-08-30 12:25:20 +00001929
1930static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001931PyCurses_IntrFlush(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001932{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001933 int ch;
1934
1935 PyCursesInitialised
1936
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001937 switch(PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001938 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001939 if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001940 break;
1941 default:
1942 PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00001943 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001944 }
1945
1946 return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
1947}
1948
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001949#if !defined(__NetBSD__)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001950static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001951PyCurses_KeyName(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001952{
1953 const char *knp;
1954 int ch;
1955
1956 PyCursesInitialised
1957
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001958 if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001959
Andrew M. Kuchling7e23f002002-11-06 14:15:36 +00001960 if (ch < 0) {
1961 PyErr_SetString(PyExc_ValueError, "invalid key number");
1962 return NULL;
1963 }
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001964 knp = keyname(ch);
1965
1966 return PyString_FromString((knp == NULL) ? "" : (char *)knp);
1967}
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00001968#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001969
1970static PyObject *
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001971PyCurses_KillChar(PyObject *self)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001972{
1973 char ch;
1974
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001975 ch = killchar();
1976
Martin v. Löwis43f2dc62001-11-11 14:49:15 +00001977 return PyString_FromStringAndSize(&ch, 1);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001978}
1979
1980static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00001981PyCurses_Meta(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001982{
1983 int ch;
1984
1985 PyCursesInitialised
1986
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001987 switch(PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001988 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00001989 if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00001990 break;
1991 default:
1992 PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
1993 return NULL;
1994 }
1995
1996 return PyCursesCheckERR(meta(stdscr, ch), "meta");
1997}
1998
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00001999#ifdef NCURSES_MOUSE_VERSION
2000static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002001PyCurses_MouseInterval(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002002{
2003 int interval;
2004 PyCursesInitialised
2005
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002006 if (!PyArg_ParseTuple(args,"i;interval",&interval))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002007 return NULL;
2008 return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
2009}
2010
2011static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002012PyCurses_MouseMask(PyObject *self, PyObject *args)
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002013{
Andrew M. Kuchling1a104002000-07-06 18:14:03 +00002014 int newmask;
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002015 mmask_t oldmask, availmask;
2016
2017 PyCursesInitialised
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002018 if (!PyArg_ParseTuple(args,"i;mousemask",&newmask))
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002019 return NULL;
2020 availmask = mousemask(newmask, &oldmask);
2021 return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
2022}
2023#endif
2024
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002025static PyObject *
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +00002026PyCurses_Napms(PyObject *self, PyObject *args)
2027{
2028 int ms;
2029
2030 PyCursesInitialised
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002031 if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL;
Andrew M. Kuchling2824d7f2000-12-15 00:44:02 +00002032
2033 return Py_BuildValue("i", napms(ms));
2034}
2035
2036
2037static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002038PyCurses_NewPad(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002039{
2040 WINDOW *win;
2041 int nlines, ncols;
2042
2043 PyCursesInitialised
2044
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002045 if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002046
2047 win = newpad(nlines, ncols);
2048
2049 if (win == NULL) {
2050 PyErr_SetString(PyCursesError, catchall_NULL);
2051 return NULL;
2052 }
2053
2054 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002055}
2056
2057static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002058PyCurses_NewWindow(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002059{
2060 WINDOW *win;
Andrew M. Kuchling5a76c442001-07-14 20:38:30 +00002061 int nlines, ncols, begin_y=0, begin_x=0;
Guido van Rossum85738471995-02-17 13:50:17 +00002062
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002063 PyCursesInitialised
2064
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002065 switch (PyTuple_Size(args)) {
Guido van Rossum85738471995-02-17 13:50:17 +00002066 case 2:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002067 if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols))
Guido van Rossum85738471995-02-17 13:50:17 +00002068 return NULL;
2069 break;
2070 case 4:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002071 if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
Guido van Rossumf6971e21994-08-30 12:25:20 +00002072 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +00002073 return NULL;
2074 break;
2075 default:
2076 PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
2077 return NULL;
2078 }
2079
Andrew M. Kuchling5a76c442001-07-14 20:38:30 +00002080 win = newwin(nlines,ncols,begin_y,begin_x);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002081 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +00002082 PyErr_SetString(PyCursesError, catchall_NULL);
2083 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002084 }
Guido van Rossum85738471995-02-17 13:50:17 +00002085
Guido van Rossumf6971e21994-08-30 12:25:20 +00002086 return (PyObject *)PyCursesWindow_New(win);
2087}
2088
2089static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002090PyCurses_Pair_Content(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002091{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002092 short pair,f,b;
2093
2094 PyCursesInitialised
2095 PyCursesInitialisedColor
2096
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002097 switch(PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002098 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002099 if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002100 break;
2101 default:
2102 PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00002103 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002104 }
2105
2106 if (!pair_content(pair, &f, &b)) {
2107 PyErr_SetString(PyCursesError,
2108 "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
2109 return NULL;
2110 }
2111
2112 return Py_BuildValue("(ii)", f, b);
2113}
2114
2115static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002116PyCurses_pair_number(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002117{
2118 int n;
2119
2120 PyCursesInitialised
2121 PyCursesInitialisedColor
2122
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002123 switch(PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002124 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002125 if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002126 break;
2127 default:
2128 PyErr_SetString(PyExc_TypeError,
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002129 "pair_number requires 1 argument");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002130 return NULL;
2131 }
2132
2133 return PyInt_FromLong((long) ((n & A_COLOR) >> 8));
2134}
2135
2136static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002137PyCurses_Putp(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002138{
2139 char *str;
2140
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002141 if (!PyArg_ParseTuple(args,"s;str", &str)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002142 return PyCursesCheckERR(putp(str), "putp");
2143}
2144
2145static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002146PyCurses_QiFlush(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002147{
2148 int flag = 0;
2149
2150 PyCursesInitialised
2151
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002152 switch(PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002153 case 0:
2154 qiflush();
2155 Py_INCREF(Py_None);
2156 return Py_None;
2157 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002158 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002159 if (flag) qiflush();
2160 else noqiflush();
2161 Py_INCREF(Py_None);
2162 return Py_None;
2163 default:
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002164 PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002165 return NULL;
2166 }
2167}
2168
2169static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002170PyCurses_setsyx(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002171{
2172 int y,x;
2173
2174 PyCursesInitialised
2175
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002176 if (PyTuple_Size(args)!=2) {
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002177 PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002178 return NULL;
2179 }
2180
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002181 if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002182
2183 setsyx(y,x);
2184
Guido van Rossumf6971e21994-08-30 12:25:20 +00002185 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00002186 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002187}
2188
2189static PyObject *
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002190PyCurses_Start_Color(PyObject *self)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002191{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002192 int code;
2193 PyObject *c, *cp;
2194
2195 PyCursesInitialised
2196
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002197 code = start_color();
2198 if (code != ERR) {
2199 initialisedcolors = TRUE;
2200 c = PyInt_FromLong((long) COLORS);
2201 PyDict_SetItemString(ModDict, "COLORS", c);
2202 Py_DECREF(c);
2203 cp = PyInt_FromLong((long) COLOR_PAIRS);
2204 PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
2205 Py_DECREF(cp);
2206 Py_INCREF(Py_None);
2207 return Py_None;
2208 } else {
2209 PyErr_SetString(PyCursesError, "start_color() returned ERR");
Guido van Rossum85738471995-02-17 13:50:17 +00002210 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002211 }
2212}
2213
2214static PyObject *
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002215PyCurses_tigetflag(PyObject *self, PyObject *args)
2216{
2217 char *capname;
2218
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002219 PyCursesSetupTermCalled;
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002220
2221 if (!PyArg_ParseTuple(args, "z", &capname))
2222 return NULL;
2223
2224 return PyInt_FromLong( (long) tigetflag( capname ) );
2225}
2226
2227static PyObject *
2228PyCurses_tigetnum(PyObject *self, PyObject *args)
2229{
2230 char *capname;
2231
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002232 PyCursesSetupTermCalled;
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002233
2234 if (!PyArg_ParseTuple(args, "z", &capname))
2235 return NULL;
2236
2237 return PyInt_FromLong( (long) tigetnum( capname ) );
2238}
2239
2240static PyObject *
2241PyCurses_tigetstr(PyObject *self, PyObject *args)
2242{
2243 char *capname;
2244
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002245 PyCursesSetupTermCalled;
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002246
2247 if (!PyArg_ParseTuple(args, "z", &capname))
2248 return NULL;
2249
2250 capname = tigetstr( capname );
2251 if (capname == 0 || capname == (char*) -1) {
2252 Py_INCREF(Py_None);
2253 return Py_None;
2254 }
2255 return PyString_FromString( capname );
2256}
2257
2258static PyObject *
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002259PyCurses_tparm(PyObject *self, PyObject *args)
2260{
2261 char* fmt;
2262 char* result = NULL;
Michael W. Hudson21007982002-11-21 14:17:51 +00002263 int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0;
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002264
Andrew M. Kuchling26cc66f2000-11-18 17:45:59 +00002265 PyCursesSetupTermCalled;
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002266
2267 if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
2268 &fmt, &i1, &i2, &i3, &i4,
2269 &i5, &i6, &i7, &i8, &i9)) {
2270 return NULL;
2271 }
Michael W. Hudson21007982002-11-21 14:17:51 +00002272
Michael W. Hudson8f514602002-01-16 15:18:09 +00002273 result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9);
Michael W. Hudson21007982002-11-21 14:17:51 +00002274
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002275 return PyString_FromString(result);
2276}
2277
2278static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002279PyCurses_TypeAhead(PyObject *self, PyObject *args)
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002280{
Andrew M. Kuchling1a104002000-07-06 18:14:03 +00002281 int fd;
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002282
2283 PyCursesInitialised
2284
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002285 if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL;
Andrew M. Kuchling97311bb2000-06-21 01:41:48 +00002286
2287 PyCursesCheckERR(typeahead( fd ), "typeahead");
2288 Py_INCREF(Py_None);
2289 return Py_None;
2290}
2291
2292static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002293PyCurses_UnCtrl(PyObject *self, PyObject *args)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002294{
2295 PyObject *temp;
2296 chtype ch;
2297
2298 PyCursesInitialised
2299
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002300 if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002301
2302 if (PyInt_Check(temp))
2303 ch = (chtype) PyInt_AsLong(temp);
2304 else if (PyString_Check(temp))
2305 ch = (chtype) *PyString_AsString(temp);
2306 else {
2307 PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
2308 return NULL;
2309 }
2310
2311 return PyString_FromString(unctrl(ch));
Guido van Rossumf6971e21994-08-30 12:25:20 +00002312}
2313
2314static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002315PyCurses_UngetCh(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002316{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002317 PyObject *temp;
Andrew M. Kuchling7e23f002002-11-06 14:15:36 +00002318 int ch;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002319
2320 PyCursesInitialised
2321
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002322 if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002323
2324 if (PyInt_Check(temp))
Andrew M. Kuchling7e23f002002-11-06 14:15:36 +00002325 ch = (int) PyInt_AsLong(temp);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002326 else if (PyString_Check(temp))
Andrew M. Kuchling7e23f002002-11-06 14:15:36 +00002327 ch = (int) *PyString_AsString(temp);
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002328 else {
2329 PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
Guido van Rossum85738471995-02-17 13:50:17 +00002330 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002331 }
2332
Guido van Rossum85738471995-02-17 13:50:17 +00002333 return PyCursesCheckERR(ungetch(ch), "ungetch");
Guido van Rossumf6971e21994-08-30 12:25:20 +00002334}
2335
2336static PyObject *
Andrew M. Kuchlingad9b1f82000-07-09 14:35:00 +00002337PyCurses_Use_Env(PyObject *self, PyObject *args)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002338{
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002339 int flag;
2340
2341 PyCursesInitialised
2342
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002343 switch(PyTuple_Size(args)) {
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002344 case 1:
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002345 if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag))
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002346 return NULL;
2347 break;
2348 default:
2349 PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
Guido van Rossum85738471995-02-17 13:50:17 +00002350 return NULL;
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002351 }
2352 use_env(flag);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002353 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00002354 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002355}
2356
Andrew M. Kuchling69f31eb2003-08-13 23:11:04 +00002357#ifndef STRICT_SYSV_CURSES
2358static PyObject *
2359PyCurses_Use_Default_Colors(PyObject *self)
2360{
2361 int code;
2362
2363 PyCursesInitialised
2364 PyCursesInitialisedColor
2365
2366 code = use_default_colors();
2367 if (code != ERR) {
2368 Py_INCREF(Py_None);
2369 return Py_None;
2370 } else {
2371 PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
2372 return NULL;
2373 }
2374}
2375#endif /* STRICT_SYSV_CURSES */
2376
Guido van Rossumf6971e21994-08-30 12:25:20 +00002377/* List of functions defined in the module */
2378
2379static PyMethodDef PyCurses_methods[] = {
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002380 {"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS},
2381 {"beep", (PyCFunction)PyCurses_beep, METH_NOARGS},
2382 {"can_change_color", (PyCFunction)PyCurses_can_change_color, METH_NOARGS},
2383 {"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS},
2384 {"color_content", (PyCFunction)PyCurses_Color_Content, METH_VARARGS},
2385 {"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS},
2386 {"curs_set", (PyCFunction)PyCurses_Curs_Set, METH_VARARGS},
2387 {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS},
2388 {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS},
2389 {"delay_output", (PyCFunction)PyCurses_Delay_Output, METH_VARARGS},
2390 {"doupdate", (PyCFunction)PyCurses_doupdate, METH_NOARGS},
2391 {"echo", (PyCFunction)PyCurses_echo, METH_VARARGS},
2392 {"endwin", (PyCFunction)PyCurses_endwin, METH_NOARGS},
2393 {"erasechar", (PyCFunction)PyCurses_EraseChar, METH_NOARGS},
2394 {"filter", (PyCFunction)PyCurses_filter, METH_NOARGS},
2395 {"flash", (PyCFunction)PyCurses_flash, METH_NOARGS},
2396 {"flushinp", (PyCFunction)PyCurses_flushinp, METH_NOARGS},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002397#ifdef NCURSES_MOUSE_VERSION
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002398 {"getmouse", (PyCFunction)PyCurses_GetMouse, METH_NOARGS},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002399 {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
2400#endif
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002401 {"getsyx", (PyCFunction)PyCurses_getsyx, METH_NOARGS},
2402 {"getwin", (PyCFunction)PyCurses_GetWin, METH_O},
2403 {"has_colors", (PyCFunction)PyCurses_has_colors, METH_NOARGS},
2404 {"has_ic", (PyCFunction)PyCurses_has_ic, METH_NOARGS},
2405 {"has_il", (PyCFunction)PyCurses_has_il, METH_NOARGS},
Andrew M. Kuchlingbf680262000-07-25 12:37:41 +00002406#ifndef STRICT_SYSV_CURSES
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002407 {"has_key", (PyCFunction)PyCurses_has_key, METH_VARARGS},
Guido van Rossumf6971e21994-08-30 12:25:20 +00002408#endif
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002409 {"halfdelay", (PyCFunction)PyCurses_HalfDelay, METH_VARARGS},
2410 {"init_color", (PyCFunction)PyCurses_Init_Color, METH_VARARGS},
2411 {"init_pair", (PyCFunction)PyCurses_Init_Pair, METH_VARARGS},
2412 {"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS},
2413 {"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS},
2414 {"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS},
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002415#if !defined(__NetBSD__)
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002416 {"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS},
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002417#endif
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002418 {"killchar", (PyCFunction)PyCurses_KillChar, METH_NOARGS},
2419 {"longname", (PyCFunction)PyCurses_longname, METH_NOARGS},
2420 {"meta", (PyCFunction)PyCurses_Meta, METH_VARARGS},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002421#ifdef NCURSES_MOUSE_VERSION
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002422 {"mouseinterval", (PyCFunction)PyCurses_MouseInterval, METH_VARARGS},
2423 {"mousemask", (PyCFunction)PyCurses_MouseMask, METH_VARARGS},
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002424#endif
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002425 {"napms", (PyCFunction)PyCurses_Napms, METH_VARARGS},
2426 {"newpad", (PyCFunction)PyCurses_NewPad, METH_VARARGS},
2427 {"newwin", (PyCFunction)PyCurses_NewWindow, METH_VARARGS},
2428 {"nl", (PyCFunction)PyCurses_nl, METH_VARARGS},
2429 {"nocbreak", (PyCFunction)PyCurses_nocbreak, METH_NOARGS},
2430 {"noecho", (PyCFunction)PyCurses_noecho, METH_NOARGS},
2431 {"nonl", (PyCFunction)PyCurses_nonl, METH_NOARGS},
2432 {"noqiflush", (PyCFunction)PyCurses_noqiflush, METH_NOARGS},
2433 {"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS},
2434 {"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS},
2435 {"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS},
2436 {"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS},
2437 {"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS},
2438 {"raw", (PyCFunction)PyCurses_raw, METH_VARARGS},
2439 {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS},
2440 {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS},
2441 {"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS},
2442 {"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS},
2443 {"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS},
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00002444 {"setupterm", (PyCFunction)PyCurses_setupterm,
2445 METH_VARARGS|METH_KEYWORDS},
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002446 {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS},
2447 {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS},
2448 {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS},
Andrew M. Kuchling70e89c12000-07-26 02:57:20 +00002449 {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
2450 {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
2451 {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
Andrew M. Kuchlingf16e0ed2000-11-07 03:35:24 +00002452 {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS},
Martin v. Löwisc0e16712002-01-17 23:08:27 +00002453 {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS},
2454 {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS},
2455 {"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS},
2456 {"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS},
Andrew M. Kuchling69f31eb2003-08-13 23:11:04 +00002457#ifndef STRICT_SYSV_CURSES
2458 {"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS},
2459#endif
Andrew M. Kuchling16e65a02001-10-20 16:05:52 +00002460 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00002461};
2462
2463/* Initialization function for the module */
2464
Mark Hammondfe51c6d2002-08-02 02:27:13 +00002465PyMODINIT_FUNC
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00002466init_curses(void)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002467{
Andrew M. Kuchling32552682000-12-22 21:52:27 +00002468 PyObject *m, *d, *v, *c_api_object;
2469 static void *PyCurses_API[PyCurses_API_pointers];
2470
Guido van Rossum6915c4d2001-01-19 00:28:08 +00002471 /* Initialize object type */
2472 PyCursesWindow_Type.ob_type = &PyType_Type;
2473
Andrew M. Kuchling32552682000-12-22 21:52:27 +00002474 /* Initialize the C API pointer array */
2475 PyCurses_API[0] = (void *)&PyCursesWindow_Type;
2476 PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
2477 PyCurses_API[2] = (void *)func_PyCursesInitialised;
2478 PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
Guido van Rossumf6971e21994-08-30 12:25:20 +00002479
2480 /* Create the module and add the functions */
Andrew M. Kuchlingb7f198e2000-06-10 23:12:32 +00002481 m = Py_InitModule("_curses", PyCurses_methods);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002482
Guido van Rossumf6971e21994-08-30 12:25:20 +00002483 /* Add some symbolic constants to the module */
2484 d = PyModule_GetDict(m);
Andrew M. Kuchling32552682000-12-22 21:52:27 +00002485 ModDict = d; /* For PyCurses_InitScr to use later */
2486
2487 /* Add a CObject for the C API */
2488 c_api_object = PyCObject_FromVoidPtr((void *)PyCurses_API, NULL);
2489 PyDict_SetItemString(d, "_C_API", c_api_object);
Martin v. Löwis00ff10c2001-11-11 14:24:05 +00002490 Py_DECREF(c_api_object);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00002491
Guido van Rossum85738471995-02-17 13:50:17 +00002492 /* For exception curses.error */
Fred Drake589c35b2000-07-06 19:38:49 +00002493 PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
Guido van Rossum85738471995-02-17 13:50:17 +00002494 PyDict_SetItemString(d, "error", PyCursesError);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00002495
Guido van Rossum85738471995-02-17 13:50:17 +00002496 /* Make the version available */
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00002497 v = PyString_FromString(PyCursesVersion);
2498 PyDict_SetItemString(d, "version", v);
2499 PyDict_SetItemString(d, "__version__", v);
2500 Py_DECREF(v);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002501
Andrew M. Kuchlingcaefb372000-12-26 15:57:01 +00002502 SetDictInt("ERR", ERR);
2503 SetDictInt("OK", OK);
2504
Guido van Rossumf6971e21994-08-30 12:25:20 +00002505 /* Here are some attributes you can add to chars to print */
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002506
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002507 SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002508 SetDictInt("A_NORMAL", A_NORMAL);
2509 SetDictInt("A_STANDOUT", A_STANDOUT);
2510 SetDictInt("A_UNDERLINE", A_UNDERLINE);
2511 SetDictInt("A_REVERSE", A_REVERSE);
2512 SetDictInt("A_BLINK", A_BLINK);
2513 SetDictInt("A_DIM", A_DIM);
2514 SetDictInt("A_BOLD", A_BOLD);
2515 SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002516#if !defined(__NetBSD__)
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002517 SetDictInt("A_INVIS", A_INVIS);
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002518#endif
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002519 SetDictInt("A_PROTECT", A_PROTECT);
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002520 SetDictInt("A_CHARTEXT", A_CHARTEXT);
2521 SetDictInt("A_COLOR", A_COLOR);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002522
2523 /* The following are never available with strict SYSV curses */
2524#ifdef A_HORIZONTAL
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002525 SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002526#endif
2527#ifdef A_LEFT
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002528 SetDictInt("A_LEFT", A_LEFT);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002529#endif
2530#ifdef A_LOW
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002531 SetDictInt("A_LOW", A_LOW);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002532#endif
2533#ifdef A_RIGHT
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002534 SetDictInt("A_RIGHT", A_RIGHT);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002535#endif
2536#ifdef A_TOP
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002537 SetDictInt("A_TOP", A_TOP);
Andrew M. Kuchlinge7d36162000-11-01 19:59:12 +00002538#endif
2539#ifdef A_VERTICAL
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002540 SetDictInt("A_VERTICAL", A_VERTICAL);
2541#endif
Andrew M. Kuchling03e644b2000-05-23 16:24:54 +00002542
Andrew M. Kuchling22b88ce2000-05-23 16:18:03 +00002543 SetDictInt("COLOR_BLACK", COLOR_BLACK);
2544 SetDictInt("COLOR_RED", COLOR_RED);
2545 SetDictInt("COLOR_GREEN", COLOR_GREEN);
2546 SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
2547 SetDictInt("COLOR_BLUE", COLOR_BLUE);
2548 SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
2549 SetDictInt("COLOR_CYAN", COLOR_CYAN);
2550 SetDictInt("COLOR_WHITE", COLOR_WHITE);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002551
Andrew M. Kuchling8e9d23b2000-06-27 03:10:38 +00002552#ifdef NCURSES_MOUSE_VERSION
2553 /* Mouse-related constants */
2554 SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
2555 SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
2556 SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
2557 SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
2558 SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
2559
2560 SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
2561 SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
2562 SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
2563 SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
2564 SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
2565
2566 SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
2567 SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
2568 SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
2569 SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
2570 SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
2571
2572 SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
2573 SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
2574 SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
2575 SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
2576 SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
2577
2578 SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
2579 SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
2580 SetDictInt("BUTTON_ALT", BUTTON_ALT);
2581
2582 SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
2583 SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
2584#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +00002585 /* Now set everything up for KEY_ variables */
2586 {
2587 int key;
2588 char *key_n;
2589 char *key_n2;
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002590#if !defined(__NetBSD__)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002591 for (key=KEY_MIN;key < KEY_MAX; key++) {
2592 key_n = (char *)keyname(key);
Guido van Rossumf5c6d471995-02-07 15:38:32 +00002593 if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
Guido van Rossumf6971e21994-08-30 12:25:20 +00002594 continue;
2595 if (strncmp(key_n,"KEY_F(",6)==0) {
2596 char *p1, *p2;
2597 key_n2 = malloc(strlen(key_n)+1);
2598 p1 = key_n;
2599 p2 = key_n2;
2600 while (*p1) {
2601 if (*p1 != '(' && *p1 != ')') {
2602 *p2 = *p1;
2603 p2++;
2604 }
2605 p1++;
2606 }
2607 *p2 = (char)0;
2608 } else
2609 key_n2 = key_n;
Guido van Rossum85738471995-02-17 13:50:17 +00002610 PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
Guido van Rossumf6971e21994-08-30 12:25:20 +00002611 if (key_n2 != key_n)
2612 free(key_n2);
2613 }
Andrew M. Kuchling2d339f92001-01-29 20:47:59 +00002614#endif
Guido van Rossum85738471995-02-17 13:50:17 +00002615 SetDictInt("KEY_MIN", KEY_MIN);
2616 SetDictInt("KEY_MAX", KEY_MAX);
Guido van Rossumf6971e21994-08-30 12:25:20 +00002617 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00002618}