2 * This is a curses module for Python.
4 * 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.
8 * Version 1.5b1, heavily extended for ncurses by Oliver Andrich:
9 * Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany.
11 * Tidied for Python 1.6, and currently maintained by <amk@amk.ca>.
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:
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
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.
38 A number of SysV or ncurses functions don't have wrappers yet; if you
39 need a given function, add it and send a patch. See
40 http://www.python.org/dev/patches/ for instructions on how to submit
43 Here's a list of currently unsupported functions:
45 addchnstr addchstr color_set define_key
46 del_curterm delscreen dupwin inchnstr inchstr innstr keyok
47 mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr
48 mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr
49 mvwinchnstr mvwinchstr mvwinnstr newterm
50 restartterm ripoffline scr_dump
51 scr_init scr_restore scr_set scrl set_curterm set_term setterm
52 tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
53 vidattr vidputs waddchnstr waddchstr
54 wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
57 slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
58 slk_attron slk_attrset slk_clear slk_color slk_init slk_label
59 slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
61 Menu extension (ncurses and probably SYSV):
62 current_item free_item free_menu item_count item_description
63 item_index item_init item_name item_opts item_opts_off
64 item_opts_on item_term item_userptr item_value item_visible
65 menu_back menu_driver menu_fore menu_format menu_grey
66 menu_init menu_items menu_mark menu_opts menu_opts_off
67 menu_opts_on menu_pad menu_pattern menu_request_by_name
68 menu_request_name menu_spacing menu_sub menu_term menu_userptr
69 menu_win new_item new_menu pos_menu_cursor post_menu
70 scale_menu set_current_item set_item_init set_item_opts
71 set_item_term set_item_userptr set_item_value set_menu_back
72 set_menu_fore set_menu_format set_menu_grey set_menu_init
73 set_menu_items set_menu_mark set_menu_opts set_menu_pad
74 set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
75 set_menu_userptr set_menu_win set_top_row top_row unpost_menu
77 Form extension (ncurses and probably SYSV):
78 current_field data_ahead data_behind dup_field
79 dynamic_fieldinfo field_arg field_back field_buffer
80 field_count field_fore field_index field_info field_init
81 field_just field_opts field_opts_off field_opts_on field_pad
82 field_status field_term field_type field_userptr form_driver
83 form_fields form_init form_opts form_opts_off form_opts_on
84 form_page form_request_by_name form_request_name form_sub
85 form_term form_userptr form_win free_field free_form
86 link_field link_fieldtype move_field new_field new_form
87 new_page pos_form_cursor post_form scale_form
88 set_current_field set_field_back set_field_buffer
89 set_field_fore set_field_init set_field_just set_field_opts
90 set_field_pad set_field_status set_field_term set_field_type
91 set_field_userptr set_fieldtype_arg set_fieldtype_choice
92 set_form_fields set_form_init set_form_opts set_form_page
93 set_form_sub set_form_term set_form_userptr set_form_win
94 set_max_field set_new_page unpost_form
101 char *PyCursesVersion
= "2.2";
108 #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
112 #define STRICT_SYSV_CURSES
115 #define CURSES_MODULE
116 #include "py_curses.h"
118 /* These prototypes are in <term.h>, but including this header
119 #defines many common symbols (such as "lines") which breaks the
120 curses module in other ways. So the code will just specify
121 explicit prototypes here. */
122 extern int setupterm(char *,int,int *);
127 #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
128 #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
129 typedef chtype attr_t
; /* No attr_t type is available */
133 #define STRICT_SYSV_CURSES
136 /* Definition of exception curses.error */
138 static PyObject
*PyCursesError
;
140 /* Tells whether setupterm() has been called to initialise terminfo. */
141 static int initialised_setupterm
= FALSE
;
143 /* Tells whether initscr() has been called to initialise curses. */
144 static int initialised
= FALSE
;
146 /* Tells whether start_color() has been called to initialise color usage. */
147 static int initialisedcolors
= FALSE
;
150 #define PyCursesSetupTermCalled \
151 if (initialised_setupterm != TRUE) { \
152 PyErr_SetString(PyCursesError, \
153 "must call (at least) setupterm() first"); \
156 #define PyCursesInitialised \
157 if (initialised != TRUE) { \
158 PyErr_SetString(PyCursesError, \
159 "must call initscr() first"); \
162 #define PyCursesInitialisedColor \
163 if (initialisedcolors != TRUE) { \
164 PyErr_SetString(PyCursesError, \
165 "must call start_color() first"); \
169 #define MIN(x,y) ((x) < (y) ? (x) : (y))
172 /* Utility Functions */
175 * Check the return code from a curses function and return None
176 * or raise an exception as appropriate. These are exported using the
181 PyCursesCheckERR(int code
, char *fname
)
188 PyErr_SetString(PyCursesError
, catchall_ERR
);
190 PyErr_Format(PyCursesError
, "%s() returned ERR", fname
);
197 PyCurses_ConvertToChtype(PyObject
*obj
, chtype
*ch
)
199 if (PyInt_Check(obj
)) {
200 *ch
= (chtype
) PyInt_AsLong(obj
);
201 } else if(PyString_Check(obj
)
202 && (PyString_Size(obj
) == 1)) {
203 *ch
= (chtype
) *PyString_AsString(obj
);
210 /* Function versions of the 3 functions for tested whether curses has been
211 initialised or not. */
213 static int func_PyCursesSetupTermCalled(void)
215 PyCursesSetupTermCalled
;
219 static int func_PyCursesInitialised(void)
225 static int func_PyCursesInitialisedColor(void)
227 PyCursesInitialisedColor
;
231 /*****************************************************************************
233 ******************************************************************************/
235 /* Definition of the window type */
237 PyTypeObject PyCursesWindow_Type
;
239 /* Function prototype macros for Window object
242 TYPE - parameter Type
243 ERGSTR - format string for construction of the return value
244 PARSESTR - format string for argument parsing
247 #define Window_NoArgNoReturnFunction(X) \
248 static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
249 { return PyCursesCheckERR(X(self->win), # X); }
251 #define Window_NoArgTrueFalseFunction(X) \
252 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
254 if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
255 else { Py_INCREF(Py_True); return Py_True; } }
257 #define Window_NoArgNoReturnVoidFunction(X) \
258 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
260 X(self->win); Py_INCREF(Py_None); return Py_None; }
262 #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
263 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
266 X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
268 #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
269 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
272 if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
273 X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
275 #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
276 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
279 if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
280 return PyCursesCheckERR(X(self->win, arg1), # X); }
282 #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
283 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
286 if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
287 return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
289 /* ------------- WINDOW routines --------------- */
291 Window_NoArgNoReturnFunction(untouchwin
)
292 Window_NoArgNoReturnFunction(touchwin
)
293 Window_NoArgNoReturnFunction(redrawwin
)
294 Window_NoArgNoReturnFunction(winsertln
)
295 Window_NoArgNoReturnFunction(werase
)
296 Window_NoArgNoReturnFunction(wdeleteln
)
298 Window_NoArgTrueFalseFunction(is_wintouched
)
300 Window_NoArgNoReturnVoidFunction(wsyncup
)
301 Window_NoArgNoReturnVoidFunction(wsyncdown
)
302 Window_NoArgNoReturnVoidFunction(wstandend
)
303 Window_NoArgNoReturnVoidFunction(wstandout
)
304 Window_NoArgNoReturnVoidFunction(wcursyncup
)
305 Window_NoArgNoReturnVoidFunction(wclrtoeol
)
306 Window_NoArgNoReturnVoidFunction(wclrtobot
)
307 Window_NoArgNoReturnVoidFunction(wclear
)
309 Window_OneArgNoReturnVoidFunction(idcok
, int, "i;True(1) or False(0)")
310 Window_OneArgNoReturnVoidFunction(immedok
, int, "i;True(1) or False(0)")
311 Window_OneArgNoReturnVoidFunction(wtimeout
, int, "i;delay")
313 Window_NoArg2TupleReturnFunction(getyx
, int, "ii")
314 Window_NoArg2TupleReturnFunction(getbegyx
, int, "ii")
315 Window_NoArg2TupleReturnFunction(getmaxyx
, int, "ii")
316 Window_NoArg2TupleReturnFunction(getparyx
, int, "ii")
318 Window_OneArgNoReturnFunction(clearok
, int, "i;True(1) or False(0)")
319 Window_OneArgNoReturnFunction(idlok
, int, "i;True(1) or False(0)")
320 #if defined(__NetBSD__)
321 Window_OneArgNoReturnVoidFunction(keypad
, int, "i;True(1) or False(0)")
323 Window_OneArgNoReturnFunction(keypad
, int, "i;True(1) or False(0)")
325 Window_OneArgNoReturnFunction(leaveok
, int, "i;True(1) or False(0)")
326 #if defined(__NetBSD__)
327 Window_OneArgNoReturnVoidFunction(nodelay
, int, "i;True(1) or False(0)")
329 Window_OneArgNoReturnFunction(nodelay
, int, "i;True(1) or False(0)")
331 Window_OneArgNoReturnFunction(notimeout
, int, "i;True(1) or False(0)")
332 Window_OneArgNoReturnFunction(scrollok
, int, "i;True(1) or False(0)")
333 Window_OneArgNoReturnFunction(winsdelln
, int, "i;nlines")
334 Window_OneArgNoReturnFunction(syncok
, int, "i;True(1) or False(0)")
336 Window_TwoArgNoReturnFunction(mvwin
, int, "ii;y,x")
337 Window_TwoArgNoReturnFunction(mvderwin
, int, "ii;y,x")
338 Window_TwoArgNoReturnFunction(wmove
, int, "ii;y,x")
339 #ifndef STRICT_SYSV_CURSES
340 Window_TwoArgNoReturnFunction(wresize
, int, "ii;lines,columns")
343 /* Allocation and deallocation of Window Objects */
346 PyCursesWindow_New(WINDOW
*win
)
348 PyCursesWindowObject
*wo
;
350 wo
= PyObject_NEW(PyCursesWindowObject
, &PyCursesWindow_Type
);
351 if (wo
== NULL
) return NULL
;
353 return (PyObject
*)wo
;
357 PyCursesWindow_Dealloc(PyCursesWindowObject
*wo
)
359 if (wo
->win
!= stdscr
) delwin(wo
->win
);
363 /* Addch, Addstr, Addnstr */
366 PyCursesWindow_AddCh(PyCursesWindowObject
*self
, PyObject
*args
)
368 int rtn
, x
, y
, use_xy
= FALSE
;
371 attr_t attr
= A_NORMAL
;
374 switch (PyTuple_Size(args
)) {
376 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
380 if (!PyArg_ParseTuple(args
, "Ol;ch or int,attr", &temp
, &lattr
))
385 if (!PyArg_ParseTuple(args
,"iiO;y,x,ch or int", &y
, &x
, &temp
))
390 if (!PyArg_ParseTuple(args
,"iiOl;y,x,ch or int, attr",
391 &y
, &x
, &temp
, &lattr
))
397 PyErr_SetString(PyExc_TypeError
, "addch requires 1 to 4 arguments");
401 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
402 PyErr_SetString(PyExc_TypeError
, "argument 1 or 3 must be a ch or an int");
407 rtn
= mvwaddch(self
->win
,y
,x
, ch
| attr
);
409 rtn
= waddch(self
->win
, ch
| attr
);
411 return PyCursesCheckERR(rtn
, "addch");
415 PyCursesWindow_AddStr(PyCursesWindowObject
*self
, PyObject
*args
)
420 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
422 int use_xy
= FALSE
, use_attr
= FALSE
;
424 switch (PyTuple_Size(args
)) {
426 if (!PyArg_ParseTuple(args
,"s;str", &str
))
430 if (!PyArg_ParseTuple(args
,"sl;str,attr", &str
, &lattr
))
436 if (!PyArg_ParseTuple(args
,"iis;int,int,str", &y
, &x
, &str
))
441 if (!PyArg_ParseTuple(args
,"iisl;int,int,str,attr", &y
, &x
, &str
, &lattr
))
444 use_xy
= use_attr
= TRUE
;
447 PyErr_SetString(PyExc_TypeError
, "addstr requires 1 to 4 arguments");
451 if (use_attr
== TRUE
) {
452 attr_old
= getattrs(self
->win
);
453 wattrset(self
->win
,attr
);
456 rtn
= mvwaddstr(self
->win
,y
,x
,str
);
458 rtn
= waddstr(self
->win
,str
);
459 if (use_attr
== TRUE
)
460 wattrset(self
->win
,attr_old
);
461 return PyCursesCheckERR(rtn
, "addstr");
465 PyCursesWindow_AddNStr(PyCursesWindowObject
*self
, PyObject
*args
)
469 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
471 int use_xy
= FALSE
, use_attr
= FALSE
;
473 switch (PyTuple_Size(args
)) {
475 if (!PyArg_ParseTuple(args
,"si;str,n", &str
, &n
))
479 if (!PyArg_ParseTuple(args
,"sil;str,n,attr", &str
, &n
, &lattr
))
485 if (!PyArg_ParseTuple(args
,"iisi;y,x,str,n", &y
, &x
, &str
, &n
))
490 if (!PyArg_ParseTuple(args
,"iisil;y,x,str,n,attr", &y
, &x
, &str
, &n
, &lattr
))
493 use_xy
= use_attr
= TRUE
;
496 PyErr_SetString(PyExc_TypeError
, "addnstr requires 2 to 5 arguments");
500 if (use_attr
== TRUE
) {
501 attr_old
= getattrs(self
->win
);
502 wattrset(self
->win
,attr
);
505 rtn
= mvwaddnstr(self
->win
,y
,x
,str
,n
);
507 rtn
= waddnstr(self
->win
,str
,n
);
508 if (use_attr
== TRUE
)
509 wattrset(self
->win
,attr_old
);
510 return PyCursesCheckERR(rtn
, "addnstr");
514 PyCursesWindow_Bkgd(PyCursesWindowObject
*self
, PyObject
*args
)
518 attr_t attr
= A_NORMAL
;
521 switch (PyTuple_Size(args
)) {
523 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
527 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &lattr
))
532 PyErr_SetString(PyExc_TypeError
, "bkgd requires 1 or 2 arguments");
536 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
537 PyErr_SetString(PyExc_TypeError
, "argument 1 or 3 must be a ch or an int");
541 return PyCursesCheckERR(wbkgd(self
->win
, bkgd
| attr
), "bkgd");
545 PyCursesWindow_AttrOff(PyCursesWindowObject
*self
, PyObject
*args
)
548 if (!PyArg_ParseTuple(args
,"l;attr", &lattr
))
550 return PyCursesCheckERR(wattroff(self
->win
, (attr_t
)lattr
), "attroff");
554 PyCursesWindow_AttrOn(PyCursesWindowObject
*self
, PyObject
*args
)
557 if (!PyArg_ParseTuple(args
,"l;attr", &lattr
))
559 return PyCursesCheckERR(wattron(self
->win
, (attr_t
)lattr
), "attron");
563 PyCursesWindow_AttrSet(PyCursesWindowObject
*self
, PyObject
*args
)
566 if (!PyArg_ParseTuple(args
,"l;attr", &lattr
))
568 return PyCursesCheckERR(wattrset(self
->win
, (attr_t
)lattr
), "attrset");
572 PyCursesWindow_BkgdSet(PyCursesWindowObject
*self
, PyObject
*args
)
576 attr_t attr
= A_NORMAL
;
579 switch (PyTuple_Size(args
)) {
581 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
585 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &lattr
))
590 PyErr_SetString(PyExc_TypeError
, "bkgdset requires 1 or 2 arguments");
594 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
595 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
599 wbkgdset(self
->win
, bkgd
| attr
);
600 return PyCursesCheckERR(0, "bkgdset");
604 PyCursesWindow_Border(PyCursesWindowObject
*self
, PyObject
*args
)
610 /* Clear the array of parameters */
616 if (!PyArg_ParseTuple(args
,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
617 &temp
[0], &temp
[1], &temp
[2], &temp
[3],
618 &temp
[4], &temp
[5], &temp
[6], &temp
[7]))
622 if (temp
[i
] != NULL
&& !PyCurses_ConvertToChtype(temp
[i
], &ch
[i
])) {
623 PyErr_Format(PyExc_TypeError
,
624 "argument %i must be a ch or an int", i
+1);
630 ch
[0], ch
[1], ch
[2], ch
[3],
631 ch
[4], ch
[5], ch
[6], ch
[7]);
637 PyCursesWindow_Box(PyCursesWindowObject
*self
, PyObject
*args
)
640 switch(PyTuple_Size(args
)){
643 if (!PyArg_ParseTuple(args
,"ll;vertint,horint", &ch1
, &ch2
))
646 box(self
->win
,ch1
,ch2
);
651 #if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
652 #define py_mvwdelch mvwdelch
654 int py_mvwdelch(WINDOW
*w
, int y
, int x
)
657 /* On HP/UX, mvwdelch already returns. On other systems,
658 we may well run into this return statement. */
663 /* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */
666 PyCursesWindow_ChgAt(PyCursesWindowObject
*self
, PyObject
*args
)
672 attr_t attr
= A_NORMAL
;
676 switch (PyTuple_Size(args
)) {
678 if (!PyArg_ParseTuple(args
,"l;attr", &lattr
))
683 if (!PyArg_ParseTuple(args
,"il;n,attr", &num
, &lattr
))
688 if (!PyArg_ParseTuple(args
,"iil;int,int,attr", &y
, &x
, &lattr
))
694 if (!PyArg_ParseTuple(args
,"iiil;int,int,n,attr", &y
, &x
, &num
, &lattr
))
700 PyErr_SetString(PyExc_TypeError
, "chgat requires 1 to 4 arguments");
704 color
= (short)((attr
>> 8) & 0xff);
705 attr
= attr
- (color
<< 8);
707 if (use_xy
== TRUE
) {
708 rtn
= mvwchgat(self
->win
,y
,x
,num
,attr
,color
,NULL
);
709 touchline(self
->win
,y
,1);
711 getyx(self
->win
,y
,x
);
712 rtn
= wchgat(self
->win
,num
,attr
,color
,NULL
);
713 touchline(self
->win
,y
,1);
715 return PyCursesCheckERR(rtn
, "chgat");
720 PyCursesWindow_DelCh(PyCursesWindowObject
*self
, PyObject
*args
)
725 switch (PyTuple_Size(args
)) {
727 rtn
= wdelch(self
->win
);
730 if (!PyArg_ParseTuple(args
,"ii;y,x", &y
, &x
))
732 rtn
= py_mvwdelch(self
->win
,y
,x
);
735 PyErr_SetString(PyExc_TypeError
, "delch requires 0 or 2 arguments");
738 return PyCursesCheckERR(rtn
, "[mv]wdelch");
742 PyCursesWindow_DerWin(PyCursesWindowObject
*self
, PyObject
*args
)
745 int nlines
, ncols
, begin_y
, begin_x
;
749 switch (PyTuple_Size(args
)) {
751 if (!PyArg_ParseTuple(args
,"ii;begin_y,begin_x",&begin_y
,&begin_x
))
755 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
756 &nlines
,&ncols
,&begin_y
,&begin_x
))
760 PyErr_SetString(PyExc_TypeError
, "derwin requires 2 or 4 arguments");
764 win
= derwin(self
->win
,nlines
,ncols
,begin_y
,begin_x
);
767 PyErr_SetString(PyCursesError
, catchall_NULL
);
771 return (PyObject
*)PyCursesWindow_New(win
);
775 PyCursesWindow_EchoChar(PyCursesWindowObject
*self
, PyObject
*args
)
779 attr_t attr
= A_NORMAL
;
782 switch (PyTuple_Size(args
)) {
784 if (!PyArg_ParseTuple(args
,"O;ch or int", &temp
))
788 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &lattr
))
793 PyErr_SetString(PyExc_TypeError
, "echochar requires 1 or 2 arguments");
799 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
800 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
804 #ifdef WINDOW_HAS_FLAGS
805 if (self
->win
->_flags
& _ISPAD
)
806 return PyCursesCheckERR(pechochar(self
->win
, ch
| attr
),
810 return PyCursesCheckERR(wechochar(self
->win
, ch
| attr
),
814 #ifdef NCURSES_MOUSE_VERSION
816 PyCursesWindow_Enclose(PyCursesWindowObject
*self
, PyObject
*args
)
819 if (!PyArg_ParseTuple(args
,"ii;y,x", &y
, &x
))
822 return PyInt_FromLong( wenclose(self
->win
,y
,x
) );
827 PyCursesWindow_GetBkgd(PyCursesWindowObject
*self
)
829 return PyInt_FromLong((long) getbkgd(self
->win
));
833 PyCursesWindow_GetCh(PyCursesWindowObject
*self
, PyObject
*args
)
838 switch (PyTuple_Size(args
)) {
840 Py_BEGIN_ALLOW_THREADS
841 rtn
= wgetch(self
->win
);
845 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
847 Py_BEGIN_ALLOW_THREADS
848 rtn
= mvwgetch(self
->win
,y
,x
);
852 PyErr_SetString(PyExc_TypeError
, "getch requires 0 or 2 arguments");
855 return PyInt_FromLong((long)rtn
);
859 PyCursesWindow_GetKey(PyCursesWindowObject
*self
, PyObject
*args
)
864 switch (PyTuple_Size(args
)) {
866 Py_BEGIN_ALLOW_THREADS
867 rtn
= wgetch(self
->win
);
871 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
873 Py_BEGIN_ALLOW_THREADS
874 rtn
= mvwgetch(self
->win
,y
,x
);
878 PyErr_SetString(PyExc_TypeError
, "getkey requires 0 or 2 arguments");
882 /* getch() returns ERR in nodelay mode */
883 PyErr_SetString(PyCursesError
, "no input");
885 } else if (rtn
<=255) {
886 return Py_BuildValue("c", rtn
);
889 #if defined(__NetBSD__)
894 return PyString_FromString((knp
== NULL
) ? "" : knp
);
899 PyCursesWindow_GetStr(PyCursesWindowObject
*self
, PyObject
*args
)
902 char rtn
[1024]; /* This should be big enough.. I hope */
905 switch (PyTuple_Size(args
)) {
907 Py_BEGIN_ALLOW_THREADS
908 rtn2
= wgetnstr(self
->win
,rtn
, 1023);
912 if (!PyArg_ParseTuple(args
,"i;n", &n
))
914 Py_BEGIN_ALLOW_THREADS
915 rtn2
= wgetnstr(self
->win
,rtn
,MIN(n
, 1023));
919 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
921 Py_BEGIN_ALLOW_THREADS
922 #ifdef STRICT_SYSV_CURSES
923 rtn2
= wmove(self
->win
,y
,x
)==ERR
? ERR
: wgetnstr(self
->win
, rtn
, 1023);
925 rtn2
= mvwgetnstr(self
->win
,y
,x
,rtn
, 1023);
930 if (!PyArg_ParseTuple(args
,"iii;y,x,n", &y
, &x
, &n
))
932 #ifdef STRICT_SYSV_CURSES
933 Py_BEGIN_ALLOW_THREADS
934 rtn2
= wmove(self
->win
,y
,x
)==ERR
? ERR
:
935 wgetnstr(self
->win
, rtn
, MIN(n
, 1023));
938 Py_BEGIN_ALLOW_THREADS
939 rtn2
= mvwgetnstr(self
->win
, y
, x
, rtn
, MIN(n
, 1023));
944 PyErr_SetString(PyExc_TypeError
, "getstr requires 0 to 3 arguments");
949 return PyString_FromString(rtn
);
953 PyCursesWindow_Hline(PyCursesWindowObject
*self
, PyObject
*args
)
957 int n
, x
, y
, code
= OK
;
958 attr_t attr
= A_NORMAL
;
961 switch (PyTuple_Size(args
)) {
963 if (!PyArg_ParseTuple(args
, "Oi;ch or int,n", &temp
, &n
))
967 if (!PyArg_ParseTuple(args
, "Oil;ch or int,n,attr", &temp
, &n
, &lattr
))
972 if (!PyArg_ParseTuple(args
, "iiOi;y,x,ch or int,n", &y
, &x
, &temp
, &n
))
974 code
= wmove(self
->win
, y
, x
);
977 if (!PyArg_ParseTuple(args
, "iiOil; y,x,ch or int,n,attr",
978 &y
, &x
, &temp
, &n
, &lattr
))
981 code
= wmove(self
->win
, y
, x
);
984 PyErr_SetString(PyExc_TypeError
, "hline requires 2 to 5 arguments");
989 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
990 PyErr_SetString(PyExc_TypeError
,
991 "argument 1 or 3 must be a ch or an int");
994 return PyCursesCheckERR(whline(self
->win
, ch
| attr
, n
), "hline");
996 return PyCursesCheckERR(code
, "wmove");
1000 PyCursesWindow_InsCh(PyCursesWindowObject
*self
, PyObject
*args
)
1002 int rtn
, x
, y
, use_xy
= FALSE
;
1005 attr_t attr
= A_NORMAL
;
1008 switch (PyTuple_Size(args
)) {
1010 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
1014 if (!PyArg_ParseTuple(args
, "Ol;ch or int,attr", &temp
, &lattr
))
1019 if (!PyArg_ParseTuple(args
,"iiO;y,x,ch or int", &y
, &x
, &temp
))
1024 if (!PyArg_ParseTuple(args
,"iiOl;y,x,ch or int, attr", &y
, &x
, &temp
, &lattr
))
1030 PyErr_SetString(PyExc_TypeError
, "insch requires 1 or 4 arguments");
1034 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
1035 PyErr_SetString(PyExc_TypeError
,
1036 "argument 1 or 3 must be a ch or an int");
1041 rtn
= mvwinsch(self
->win
,y
,x
, ch
| attr
);
1043 rtn
= winsch(self
->win
, ch
| attr
);
1045 return PyCursesCheckERR(rtn
, "insch");
1049 PyCursesWindow_InCh(PyCursesWindowObject
*self
, PyObject
*args
)
1053 switch (PyTuple_Size(args
)) {
1055 rtn
= winch(self
->win
);
1058 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
1060 rtn
= mvwinch(self
->win
,y
,x
);
1063 PyErr_SetString(PyExc_TypeError
, "inch requires 0 or 2 arguments");
1066 return PyInt_FromLong((long) rtn
);
1070 PyCursesWindow_InStr(PyCursesWindowObject
*self
, PyObject
*args
)
1073 char rtn
[1024]; /* This should be big enough.. I hope */
1076 switch (PyTuple_Size(args
)) {
1078 rtn2
= winnstr(self
->win
,rtn
, 1023);
1081 if (!PyArg_ParseTuple(args
,"i;n", &n
))
1083 rtn2
= winnstr(self
->win
,rtn
,MIN(n
,1023));
1086 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
1088 rtn2
= mvwinnstr(self
->win
,y
,x
,rtn
,1023);
1091 if (!PyArg_ParseTuple(args
, "iii;y,x,n", &y
, &x
, &n
))
1093 rtn2
= mvwinnstr(self
->win
, y
, x
, rtn
, MIN(n
,1023));
1096 PyErr_SetString(PyExc_TypeError
, "instr requires 0 or 3 arguments");
1101 return PyString_FromString(rtn
);
1105 PyCursesWindow_InsStr(PyCursesWindowObject
*self
, PyObject
*args
)
1110 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
1112 int use_xy
= FALSE
, use_attr
= FALSE
;
1114 switch (PyTuple_Size(args
)) {
1116 if (!PyArg_ParseTuple(args
,"s;str", &str
))
1120 if (!PyArg_ParseTuple(args
,"sl;str,attr", &str
, &lattr
))
1126 if (!PyArg_ParseTuple(args
,"iis;y,x,str", &y
, &x
, &str
))
1131 if (!PyArg_ParseTuple(args
,"iisl;y,x,str,attr", &y
, &x
, &str
, &lattr
))
1134 use_xy
= use_attr
= TRUE
;
1137 PyErr_SetString(PyExc_TypeError
, "insstr requires 1 to 4 arguments");
1141 if (use_attr
== TRUE
) {
1142 attr_old
= getattrs(self
->win
);
1143 wattrset(self
->win
,attr
);
1146 rtn
= mvwinsstr(self
->win
,y
,x
,str
);
1148 rtn
= winsstr(self
->win
,str
);
1149 if (use_attr
== TRUE
)
1150 wattrset(self
->win
,attr_old
);
1151 return PyCursesCheckERR(rtn
, "insstr");
1155 PyCursesWindow_InsNStr(PyCursesWindowObject
*self
, PyObject
*args
)
1159 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
1161 int use_xy
= FALSE
, use_attr
= FALSE
;
1163 switch (PyTuple_Size(args
)) {
1165 if (!PyArg_ParseTuple(args
,"si;str,n", &str
, &n
))
1169 if (!PyArg_ParseTuple(args
,"sil;str,n,attr", &str
, &n
, &lattr
))
1175 if (!PyArg_ParseTuple(args
,"iisi;y,x,str,n", &y
, &x
, &str
, &n
))
1180 if (!PyArg_ParseTuple(args
,"iisil;y,x,str,n,attr", &y
, &x
, &str
, &n
, &lattr
))
1183 use_xy
= use_attr
= TRUE
;
1186 PyErr_SetString(PyExc_TypeError
, "insnstr requires 2 to 5 arguments");
1190 if (use_attr
== TRUE
) {
1191 attr_old
= getattrs(self
->win
);
1192 wattrset(self
->win
,attr
);
1195 rtn
= mvwinsnstr(self
->win
,y
,x
,str
,n
);
1197 rtn
= winsnstr(self
->win
,str
,n
);
1198 if (use_attr
== TRUE
)
1199 wattrset(self
->win
,attr_old
);
1200 return PyCursesCheckERR(rtn
, "insnstr");
1204 PyCursesWindow_Is_LineTouched(PyCursesWindowObject
*self
, PyObject
*args
)
1207 if (!PyArg_ParseTuple(args
,"i;line", &line
))
1209 erg
= is_linetouched(self
->win
, line
);
1211 PyErr_SetString(PyExc_TypeError
,
1212 "is_linetouched: line number outside of boundaries");
1216 Py_INCREF(Py_False
);
1225 PyCursesWindow_NoOutRefresh(PyCursesWindowObject
*self
, PyObject
*args
)
1227 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1230 #ifndef WINDOW_HAS_FLAGS
1233 if (self
->win
->_flags
& _ISPAD
) {
1235 switch(PyTuple_Size(args
)) {
1237 if (!PyArg_ParseTuple(args
,
1239 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1240 &pminrow
, &pmincol
, &sminrow
,
1241 &smincol
, &smaxrow
, &smaxcol
))
1243 Py_BEGIN_ALLOW_THREADS
1244 rtn
= pnoutrefresh(self
->win
,
1245 pminrow
, pmincol
, sminrow
,
1246 smincol
, smaxrow
, smaxcol
);
1247 Py_END_ALLOW_THREADS
1248 return PyCursesCheckERR(rtn
, "pnoutrefresh");
1250 PyErr_SetString(PyCursesError
,
1251 "noutrefresh() called for a pad "
1252 "requires 6 arguments");
1256 if (!PyArg_ParseTuple(args
, ":noutrefresh"))
1259 Py_BEGIN_ALLOW_THREADS
1260 rtn
= wnoutrefresh(self
->win
);
1261 Py_END_ALLOW_THREADS
1262 return PyCursesCheckERR(rtn
, "wnoutrefresh");
1267 PyCursesWindow_Overlay(PyCursesWindowObject
*self
, PyObject
*args
)
1269 PyCursesWindowObject
*temp
;
1270 int use_copywin
= FALSE
;
1271 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1274 switch (PyTuple_Size(args
)) {
1276 if (!PyArg_ParseTuple(args
, "O!;window object",
1277 &PyCursesWindow_Type
, &temp
))
1281 if (!PyArg_ParseTuple(args
, "O!iiiiii;window object, int, int, int, int, int, int",
1282 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1283 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1288 PyErr_SetString(PyExc_TypeError
,
1289 "overlay requires one or seven arguments");
1293 if (use_copywin
== TRUE
) {
1294 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1295 dminrow
, dmincol
, dmaxrow
, dmaxcol
, TRUE
);
1296 return PyCursesCheckERR(rtn
, "copywin");
1299 rtn
= overlay(self
->win
, temp
->win
);
1300 return PyCursesCheckERR(rtn
, "overlay");
1305 PyCursesWindow_Overwrite(PyCursesWindowObject
*self
, PyObject
*args
)
1307 PyCursesWindowObject
*temp
;
1308 int use_copywin
= FALSE
;
1309 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1312 switch (PyTuple_Size(args
)) {
1314 if (!PyArg_ParseTuple(args
, "O!;window object",
1315 &PyCursesWindow_Type
, &temp
))
1319 if (!PyArg_ParseTuple(args
, "O!iiiiii;window object, int, int, int, int, int, int",
1320 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1321 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1326 PyErr_SetString(PyExc_TypeError
,
1327 "overwrite requires one or seven arguments");
1331 if (use_copywin
== TRUE
) {
1332 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1333 dminrow
, dmincol
, dmaxrow
, dmaxcol
, FALSE
);
1334 return PyCursesCheckERR(rtn
, "copywin");
1337 rtn
= overwrite(self
->win
, temp
->win
);
1338 return PyCursesCheckERR(rtn
, "overwrite");
1343 PyCursesWindow_PutWin(PyCursesWindowObject
*self
, PyObject
*args
)
1347 if (!PyArg_ParseTuple(args
, "O;fileobj", &temp
))
1349 if (!PyFile_Check(temp
)) {
1350 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1353 return PyCursesCheckERR(putwin(self
->win
, PyFile_AsFile(temp
)),
1358 PyCursesWindow_RedrawLine(PyCursesWindowObject
*self
, PyObject
*args
)
1361 if (!PyArg_ParseTuple(args
, "ii;beg,num", &beg
, &num
))
1363 return PyCursesCheckERR(wredrawln(self
->win
,beg
,num
), "redrawln");
1367 PyCursesWindow_Refresh(PyCursesWindowObject
*self
, PyObject
*args
)
1369 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1372 #ifndef WINDOW_HAS_FLAGS
1375 if (self
->win
->_flags
& _ISPAD
) {
1377 switch(PyTuple_Size(args
)) {
1379 if (!PyArg_ParseTuple(args
,
1381 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1382 &pminrow
, &pmincol
, &sminrow
,
1383 &smincol
, &smaxrow
, &smaxcol
))
1386 Py_BEGIN_ALLOW_THREADS
1387 rtn
= prefresh(self
->win
,
1388 pminrow
, pmincol
, sminrow
,
1389 smincol
, smaxrow
, smaxcol
);
1390 Py_END_ALLOW_THREADS
1391 return PyCursesCheckERR(rtn
, "prefresh");
1393 PyErr_SetString(PyCursesError
,
1394 "refresh() for a pad requires 6 arguments");
1398 if (!PyArg_ParseTuple(args
, ":refresh"))
1400 Py_BEGIN_ALLOW_THREADS
1401 rtn
= wrefresh(self
->win
);
1402 Py_END_ALLOW_THREADS
1403 return PyCursesCheckERR(rtn
, "prefresh");
1408 PyCursesWindow_SetScrollRegion(PyCursesWindowObject
*self
, PyObject
*args
)
1411 if (!PyArg_ParseTuple(args
,"ii;top, bottom",&y
,&x
))
1413 return PyCursesCheckERR(wsetscrreg(self
->win
,y
,x
), "wsetscrreg");
1417 PyCursesWindow_SubWin(PyCursesWindowObject
*self
, PyObject
*args
)
1420 int nlines
, ncols
, begin_y
, begin_x
;
1424 switch (PyTuple_Size(args
)) {
1426 if (!PyArg_ParseTuple(args
,"ii;begin_y,begin_x",&begin_y
,&begin_x
))
1430 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
1431 &nlines
,&ncols
,&begin_y
,&begin_x
))
1435 PyErr_SetString(PyExc_TypeError
, "subwin requires 2 or 4 arguments");
1439 /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
1440 #ifdef WINDOW_HAS_FLAGS
1441 if (self
->win
->_flags
& _ISPAD
)
1442 win
= subpad(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1445 win
= subwin(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1448 PyErr_SetString(PyCursesError
, catchall_NULL
);
1452 return (PyObject
*)PyCursesWindow_New(win
);
1456 PyCursesWindow_Scroll(PyCursesWindowObject
*self
, PyObject
*args
)
1459 switch(PyTuple_Size(args
)) {
1461 return PyCursesCheckERR(scroll(self
->win
), "scroll");
1463 if (!PyArg_ParseTuple(args
, "i;nlines", &nlines
))
1465 return PyCursesCheckERR(wscrl(self
->win
, nlines
), "scroll");
1467 PyErr_SetString(PyExc_TypeError
, "scroll requires 0 or 1 arguments");
1473 PyCursesWindow_TouchLine(PyCursesWindowObject
*self
, PyObject
*args
)
1476 switch (PyTuple_Size(args
)) {
1478 if (!PyArg_ParseTuple(args
,"ii;start,count",&st
,&cnt
))
1480 return PyCursesCheckERR(touchline(self
->win
,st
,cnt
), "touchline");
1482 if (!PyArg_ParseTuple(args
, "iii;start,count,val", &st
, &cnt
, &val
))
1484 return PyCursesCheckERR(wtouchln(self
->win
, st
, cnt
, val
), "touchline");
1486 PyErr_SetString(PyExc_TypeError
, "touchline requires 2 or 3 arguments");
1492 PyCursesWindow_Vline(PyCursesWindowObject
*self
, PyObject
*args
)
1496 int n
, x
, y
, code
= OK
;
1497 attr_t attr
= A_NORMAL
;
1500 switch (PyTuple_Size(args
)) {
1502 if (!PyArg_ParseTuple(args
, "Oi;ch or int,n", &temp
, &n
))
1506 if (!PyArg_ParseTuple(args
, "Oil;ch or int,n,attr", &temp
, &n
, &lattr
))
1511 if (!PyArg_ParseTuple(args
, "iiOi;y,x,ch or int,n", &y
, &x
, &temp
, &n
))
1513 code
= wmove(self
->win
, y
, x
);
1516 if (!PyArg_ParseTuple(args
, "iiOil; y,x,ch or int,n,attr",
1517 &y
, &x
, &temp
, &n
, &lattr
))
1520 code
= wmove(self
->win
, y
, x
);
1523 PyErr_SetString(PyExc_TypeError
, "vline requires 2 to 5 arguments");
1528 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
1529 PyErr_SetString(PyExc_TypeError
,
1530 "argument 1 or 3 must be a ch or an int");
1533 return PyCursesCheckERR(wvline(self
->win
, ch
| attr
, n
), "vline");
1535 return PyCursesCheckERR(code
, "wmove");
1538 static PyMethodDef PyCursesWindow_Methods
[] = {
1539 {"addch", (PyCFunction
)PyCursesWindow_AddCh
, METH_VARARGS
},
1540 {"addnstr", (PyCFunction
)PyCursesWindow_AddNStr
, METH_VARARGS
},
1541 {"addstr", (PyCFunction
)PyCursesWindow_AddStr
, METH_VARARGS
},
1542 {"attroff", (PyCFunction
)PyCursesWindow_AttrOff
, METH_VARARGS
},
1543 {"attron", (PyCFunction
)PyCursesWindow_AttrOn
, METH_VARARGS
},
1544 {"attrset", (PyCFunction
)PyCursesWindow_AttrSet
, METH_VARARGS
},
1545 {"bkgd", (PyCFunction
)PyCursesWindow_Bkgd
, METH_VARARGS
},
1546 {"chgat", (PyCFunction
)PyCursesWindow_ChgAt
, METH_VARARGS
},
1547 {"bkgdset", (PyCFunction
)PyCursesWindow_BkgdSet
, METH_VARARGS
},
1548 {"border", (PyCFunction
)PyCursesWindow_Border
, METH_VARARGS
},
1549 {"box", (PyCFunction
)PyCursesWindow_Box
, METH_VARARGS
},
1550 {"clear", (PyCFunction
)PyCursesWindow_wclear
, METH_NOARGS
},
1551 {"clearok", (PyCFunction
)PyCursesWindow_clearok
, METH_VARARGS
},
1552 {"clrtobot", (PyCFunction
)PyCursesWindow_wclrtobot
, METH_NOARGS
},
1553 {"clrtoeol", (PyCFunction
)PyCursesWindow_wclrtoeol
, METH_NOARGS
},
1554 {"cursyncup", (PyCFunction
)PyCursesWindow_wcursyncup
, METH_NOARGS
},
1555 {"delch", (PyCFunction
)PyCursesWindow_DelCh
, METH_VARARGS
},
1556 {"deleteln", (PyCFunction
)PyCursesWindow_wdeleteln
, METH_NOARGS
},
1557 {"derwin", (PyCFunction
)PyCursesWindow_DerWin
, METH_VARARGS
},
1558 {"echochar", (PyCFunction
)PyCursesWindow_EchoChar
, METH_VARARGS
},
1559 #ifdef NCURSES_MOUSE_VERSION
1560 {"enclose", (PyCFunction
)PyCursesWindow_Enclose
, METH_VARARGS
},
1562 {"erase", (PyCFunction
)PyCursesWindow_werase
, METH_NOARGS
},
1563 {"getbegyx", (PyCFunction
)PyCursesWindow_getbegyx
, METH_NOARGS
},
1564 {"getbkgd", (PyCFunction
)PyCursesWindow_GetBkgd
, METH_NOARGS
},
1565 {"getch", (PyCFunction
)PyCursesWindow_GetCh
, METH_VARARGS
},
1566 {"getkey", (PyCFunction
)PyCursesWindow_GetKey
, METH_VARARGS
},
1567 {"getmaxyx", (PyCFunction
)PyCursesWindow_getmaxyx
, METH_NOARGS
},
1568 {"getparyx", (PyCFunction
)PyCursesWindow_getparyx
, METH_NOARGS
},
1569 {"getstr", (PyCFunction
)PyCursesWindow_GetStr
, METH_VARARGS
},
1570 {"getyx", (PyCFunction
)PyCursesWindow_getyx
, METH_NOARGS
},
1571 {"hline", (PyCFunction
)PyCursesWindow_Hline
, METH_VARARGS
},
1572 {"idcok", (PyCFunction
)PyCursesWindow_idcok
, METH_VARARGS
},
1573 {"idlok", (PyCFunction
)PyCursesWindow_idlok
, METH_VARARGS
},
1574 {"immedok", (PyCFunction
)PyCursesWindow_immedok
, METH_VARARGS
},
1575 {"inch", (PyCFunction
)PyCursesWindow_InCh
, METH_VARARGS
},
1576 {"insch", (PyCFunction
)PyCursesWindow_InsCh
, METH_VARARGS
},
1577 {"insdelln", (PyCFunction
)PyCursesWindow_winsdelln
, METH_VARARGS
},
1578 {"insertln", (PyCFunction
)PyCursesWindow_winsertln
, METH_NOARGS
},
1579 {"insnstr", (PyCFunction
)PyCursesWindow_InsNStr
, METH_VARARGS
},
1580 {"insstr", (PyCFunction
)PyCursesWindow_InsStr
, METH_VARARGS
},
1581 {"instr", (PyCFunction
)PyCursesWindow_InStr
, METH_VARARGS
},
1582 {"is_linetouched", (PyCFunction
)PyCursesWindow_Is_LineTouched
, METH_VARARGS
},
1583 {"is_wintouched", (PyCFunction
)PyCursesWindow_is_wintouched
, METH_NOARGS
},
1584 {"keypad", (PyCFunction
)PyCursesWindow_keypad
, METH_VARARGS
},
1585 {"leaveok", (PyCFunction
)PyCursesWindow_leaveok
, METH_VARARGS
},
1586 {"move", (PyCFunction
)PyCursesWindow_wmove
, METH_VARARGS
},
1587 {"mvderwin", (PyCFunction
)PyCursesWindow_mvderwin
, METH_VARARGS
},
1588 {"mvwin", (PyCFunction
)PyCursesWindow_mvwin
, METH_VARARGS
},
1589 {"nodelay", (PyCFunction
)PyCursesWindow_nodelay
, METH_VARARGS
},
1590 {"notimeout", (PyCFunction
)PyCursesWindow_notimeout
, METH_VARARGS
},
1591 {"noutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
, METH_VARARGS
},
1592 /* Backward compatibility alias -- remove in Python 2.3 */
1593 {"nooutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
, METH_VARARGS
},
1594 {"overlay", (PyCFunction
)PyCursesWindow_Overlay
, METH_VARARGS
},
1595 {"overwrite", (PyCFunction
)PyCursesWindow_Overwrite
,
1597 {"putwin", (PyCFunction
)PyCursesWindow_PutWin
, METH_VARARGS
},
1598 {"redrawln", (PyCFunction
)PyCursesWindow_RedrawLine
, METH_VARARGS
},
1599 {"redrawwin", (PyCFunction
)PyCursesWindow_redrawwin
, METH_NOARGS
},
1600 {"refresh", (PyCFunction
)PyCursesWindow_Refresh
, METH_VARARGS
},
1601 #ifndef STRICT_SYSV_CURSES
1602 {"resize", (PyCFunction
)PyCursesWindow_wresize
, METH_VARARGS
},
1604 {"scroll", (PyCFunction
)PyCursesWindow_Scroll
, METH_VARARGS
},
1605 {"scrollok", (PyCFunction
)PyCursesWindow_scrollok
, METH_VARARGS
},
1606 {"setscrreg", (PyCFunction
)PyCursesWindow_SetScrollRegion
, METH_VARARGS
},
1607 {"standend", (PyCFunction
)PyCursesWindow_wstandend
, METH_NOARGS
},
1608 {"standout", (PyCFunction
)PyCursesWindow_wstandout
, METH_NOARGS
},
1609 {"subpad", (PyCFunction
)PyCursesWindow_SubWin
, METH_VARARGS
},
1610 {"subwin", (PyCFunction
)PyCursesWindow_SubWin
, METH_VARARGS
},
1611 {"syncdown", (PyCFunction
)PyCursesWindow_wsyncdown
, METH_NOARGS
},
1612 {"syncok", (PyCFunction
)PyCursesWindow_syncok
, METH_VARARGS
},
1613 {"syncup", (PyCFunction
)PyCursesWindow_wsyncup
, METH_NOARGS
},
1614 {"timeout", (PyCFunction
)PyCursesWindow_wtimeout
, METH_VARARGS
},
1615 {"touchline", (PyCFunction
)PyCursesWindow_TouchLine
, METH_VARARGS
},
1616 {"touchwin", (PyCFunction
)PyCursesWindow_touchwin
, METH_NOARGS
},
1617 {"untouchwin", (PyCFunction
)PyCursesWindow_untouchwin
, METH_NOARGS
},
1618 {"vline", (PyCFunction
)PyCursesWindow_Vline
, METH_VARARGS
},
1619 {NULL
, NULL
} /* sentinel */
1623 PyCursesWindow_GetAttr(PyCursesWindowObject
*self
, char *name
)
1625 return Py_FindMethod(PyCursesWindow_Methods
, (PyObject
*)self
, name
);
1628 /* -------------------------------------------------------*/
1630 PyTypeObject PyCursesWindow_Type
= {
1631 PyVarObject_HEAD_INIT(NULL
, 0)
1632 "_curses.curses window", /*tp_name*/
1633 sizeof(PyCursesWindowObject
), /*tp_basicsize*/
1636 (destructor
)PyCursesWindow_Dealloc
, /*tp_dealloc*/
1638 (getattrfunc
)PyCursesWindow_GetAttr
, /*tp_getattr*/
1639 (setattrfunc
)0, /*tp_setattr*/
1643 0, /*tp_as_sequence*/
1644 0, /*tp_as_mapping*/
1648 /*********************************************************************
1650 **********************************************************************/
1652 NoArgNoReturnFunction(beep
)
1653 NoArgNoReturnFunction(def_prog_mode
)
1654 NoArgNoReturnFunction(def_shell_mode
)
1655 NoArgNoReturnFunction(doupdate
)
1656 NoArgNoReturnFunction(endwin
)
1657 NoArgNoReturnFunction(flash
)
1658 NoArgNoReturnFunction(nocbreak
)
1659 NoArgNoReturnFunction(noecho
)
1660 NoArgNoReturnFunction(nonl
)
1661 NoArgNoReturnFunction(noraw
)
1662 NoArgNoReturnFunction(reset_prog_mode
)
1663 NoArgNoReturnFunction(reset_shell_mode
)
1664 NoArgNoReturnFunction(resetty
)
1665 NoArgNoReturnFunction(savetty
)
1667 NoArgOrFlagNoReturnFunction(cbreak
)
1668 NoArgOrFlagNoReturnFunction(echo
)
1669 NoArgOrFlagNoReturnFunction(nl
)
1670 NoArgOrFlagNoReturnFunction(raw
)
1672 NoArgReturnIntFunction(baudrate
)
1673 NoArgReturnIntFunction(termattrs
)
1675 NoArgReturnStringFunction(termname
)
1676 NoArgReturnStringFunction(longname
)
1678 NoArgTrueFalseFunction(can_change_color
)
1679 NoArgTrueFalseFunction(has_colors
)
1680 NoArgTrueFalseFunction(has_ic
)
1681 NoArgTrueFalseFunction(has_il
)
1682 NoArgTrueFalseFunction(isendwin
)
1683 NoArgNoReturnVoidFunction(flushinp
)
1684 NoArgNoReturnVoidFunction(noqiflush
)
1687 PyCurses_filter(PyObject
*self
)
1689 /* not checking for PyCursesInitialised here since filter() must
1690 be called before initscr() */
1697 PyCurses_Color_Content(PyObject
*self
, PyObject
*args
)
1702 PyCursesInitialisedColor
1704 if (!PyArg_ParseTuple(args
, "h:color_content", &color
)) return NULL
;
1706 if (color_content(color
, &r
, &g
, &b
) != ERR
)
1707 return Py_BuildValue("(iii)", r
, g
, b
);
1709 PyErr_SetString(PyCursesError
,
1710 "Argument 1 was out of range. Check value of COLORS.");
1716 PyCurses_color_pair(PyObject
*self
, PyObject
*args
)
1721 PyCursesInitialisedColor
1723 if (!PyArg_ParseTuple(args
, "i:color_pair", &n
)) return NULL
;
1724 return PyInt_FromLong((long) (n
<< 8));
1728 PyCurses_Curs_Set(PyObject
*self
, PyObject
*args
)
1734 if (!PyArg_ParseTuple(args
, "i:curs_set", &vis
)) return NULL
;
1736 erg
= curs_set(vis
);
1737 if (erg
== ERR
) return PyCursesCheckERR(erg
, "curs_set");
1739 return PyInt_FromLong((long) erg
);
1743 PyCurses_Delay_Output(PyObject
*self
, PyObject
*args
)
1749 if (!PyArg_ParseTuple(args
, "i:delay_output", &ms
)) return NULL
;
1751 return PyCursesCheckERR(delay_output(ms
), "delay_output");
1755 PyCurses_EraseChar(PyObject
*self
)
1763 return PyString_FromStringAndSize(&ch
, 1);
1767 PyCurses_getsyx(PyObject
*self
)
1776 return Py_BuildValue("(ii)", y
, x
);
1779 #ifdef NCURSES_MOUSE_VERSION
1781 PyCurses_GetMouse(PyObject
*self
)
1788 rtn
= getmouse( &event
);
1790 PyErr_SetString(PyCursesError
, "getmouse() returned ERR");
1793 return Py_BuildValue("(hiiil)",
1795 event
.x
, event
.y
, event
.z
,
1796 (long) event
.bstate
);
1800 PyCurses_UngetMouse(PyObject
*self
, PyObject
*args
)
1805 if (!PyArg_ParseTuple(args
, "hiiil",
1807 &event
.x
, &event
.y
, &event
.z
,
1808 (int *) &event
.bstate
))
1811 return PyCursesCheckERR(ungetmouse(&event
), "ungetmouse");
1816 PyCurses_GetWin(PyCursesWindowObject
*self
, PyObject
*temp
)
1822 if (!PyFile_Check(temp
)) {
1823 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1827 win
= getwin(PyFile_AsFile(temp
));
1830 PyErr_SetString(PyCursesError
, catchall_NULL
);
1834 return PyCursesWindow_New(win
);
1838 PyCurses_HalfDelay(PyObject
*self
, PyObject
*args
)
1840 unsigned char tenths
;
1844 if (!PyArg_ParseTuple(args
, "b:halfdelay", &tenths
)) return NULL
;
1846 return PyCursesCheckERR(halfdelay(tenths
), "halfdelay");
1849 #ifndef STRICT_SYSV_CURSES
1851 static PyObject
* PyCurses_has_key(PyObject
*self
, PyObject
*args
)
1857 if (!PyArg_ParseTuple(args
,"i",&ch
)) return NULL
;
1859 if (has_key(ch
) == FALSE
) {
1860 Py_INCREF(Py_False
);
1866 #endif /* STRICT_SYSV_CURSES */
1869 PyCurses_Init_Color(PyObject
*self
, PyObject
*args
)
1871 short color
, r
, g
, b
;
1874 PyCursesInitialisedColor
1876 switch(PyTuple_Size(args
)) {
1878 if (!PyArg_ParseTuple(args
, "hhhh;color,r,g,b", &color
, &r
, &g
, &b
)) return NULL
;
1881 PyErr_SetString(PyExc_TypeError
, "init_color requires 4 arguments");
1885 return PyCursesCheckERR(init_color(color
, r
, g
, b
), "init_color");
1889 PyCurses_Init_Pair(PyObject
*self
, PyObject
*args
)
1894 PyCursesInitialisedColor
1896 if (PyTuple_Size(args
) != 3) {
1897 PyErr_SetString(PyExc_TypeError
, "init_pair requires 3 arguments");
1901 if (!PyArg_ParseTuple(args
, "hhh;pair, f, b", &pair
, &f
, &b
)) return NULL
;
1903 return PyCursesCheckERR(init_pair(pair
, f
, b
), "init_pair");
1906 static PyObject
*ModDict
;
1909 PyCurses_InitScr(PyObject
*self
)
1913 if (initialised
== TRUE
) {
1915 return (PyObject
*)PyCursesWindow_New(stdscr
);
1921 PyErr_SetString(PyCursesError
, catchall_NULL
);
1925 initialised
= initialised_setupterm
= TRUE
;
1927 /* This was moved from initcurses() because it core dumped on SGI,
1928 where they're not defined until you've called initscr() */
1929 #define SetDictInt(string,ch) \
1931 PyObject *o = PyInt_FromLong((long) (ch)); \
1932 if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \
1937 /* Here are some graphic symbols you can use */
1938 SetDictInt("ACS_ULCORNER", (ACS_ULCORNER
));
1939 SetDictInt("ACS_LLCORNER", (ACS_LLCORNER
));
1940 SetDictInt("ACS_URCORNER", (ACS_URCORNER
));
1941 SetDictInt("ACS_LRCORNER", (ACS_LRCORNER
));
1942 SetDictInt("ACS_LTEE", (ACS_LTEE
));
1943 SetDictInt("ACS_RTEE", (ACS_RTEE
));
1944 SetDictInt("ACS_BTEE", (ACS_BTEE
));
1945 SetDictInt("ACS_TTEE", (ACS_TTEE
));
1946 SetDictInt("ACS_HLINE", (ACS_HLINE
));
1947 SetDictInt("ACS_VLINE", (ACS_VLINE
));
1948 SetDictInt("ACS_PLUS", (ACS_PLUS
));
1949 #if !defined(__hpux) || defined(HAVE_NCURSES_H)
1950 /* On HP/UX 11, these are of type cchar_t, which is not an
1951 integral type. If this is a problem on more platforms, a
1952 configure test should be added to determine whether ACS_S1
1953 is of integral type. */
1954 SetDictInt("ACS_S1", (ACS_S1
));
1955 SetDictInt("ACS_S9", (ACS_S9
));
1956 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND
));
1957 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD
));
1958 SetDictInt("ACS_DEGREE", (ACS_DEGREE
));
1959 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS
));
1960 SetDictInt("ACS_BULLET", (ACS_BULLET
));
1961 SetDictInt("ACS_LARROW", (ACS_LARROW
));
1962 SetDictInt("ACS_RARROW", (ACS_RARROW
));
1963 SetDictInt("ACS_DARROW", (ACS_DARROW
));
1964 SetDictInt("ACS_UARROW", (ACS_UARROW
));
1965 SetDictInt("ACS_BOARD", (ACS_BOARD
));
1966 SetDictInt("ACS_LANTERN", (ACS_LANTERN
));
1967 SetDictInt("ACS_BLOCK", (ACS_BLOCK
));
1969 SetDictInt("ACS_BSSB", (ACS_ULCORNER
));
1970 SetDictInt("ACS_SSBB", (ACS_LLCORNER
));
1971 SetDictInt("ACS_BBSS", (ACS_URCORNER
));
1972 SetDictInt("ACS_SBBS", (ACS_LRCORNER
));
1973 SetDictInt("ACS_SBSS", (ACS_RTEE
));
1974 SetDictInt("ACS_SSSB", (ACS_LTEE
));
1975 SetDictInt("ACS_SSBS", (ACS_BTEE
));
1976 SetDictInt("ACS_BSSS", (ACS_TTEE
));
1977 SetDictInt("ACS_BSBS", (ACS_HLINE
));
1978 SetDictInt("ACS_SBSB", (ACS_VLINE
));
1979 SetDictInt("ACS_SSSS", (ACS_PLUS
));
1981 /* The following are never available with strict SYSV curses */
1983 SetDictInt("ACS_S3", (ACS_S3
));
1986 SetDictInt("ACS_S7", (ACS_S7
));
1989 SetDictInt("ACS_LEQUAL", (ACS_LEQUAL
));
1992 SetDictInt("ACS_GEQUAL", (ACS_GEQUAL
));
1995 SetDictInt("ACS_PI", (ACS_PI
));
1998 SetDictInt("ACS_NEQUAL", (ACS_NEQUAL
));
2001 SetDictInt("ACS_STERLING", (ACS_STERLING
));
2004 SetDictInt("LINES", LINES
);
2005 SetDictInt("COLS", COLS
);
2007 return (PyObject
*)PyCursesWindow_New(win
);
2011 PyCurses_setupterm(PyObject
* self
, PyObject
*args
, PyObject
* keywds
)
2015 char* termstr
= NULL
;
2017 static char *kwlist
[] = {"term", "fd", NULL
};
2019 if (!PyArg_ParseTupleAndKeywords(
2020 args
, keywds
, "|zi:setupterm", kwlist
, &termstr
, &fd
)) {
2025 PyObject
* sys_stdout
;
2027 sys_stdout
= PySys_GetObject("stdout");
2029 if (sys_stdout
== NULL
) {
2036 fd
= PyObject_AsFileDescriptor(sys_stdout
);
2043 if (setupterm(termstr
,fd
,&err
) == ERR
) {
2044 char* s
= "setupterm: unknown error";
2047 s
= "setupterm: could not find terminal";
2048 } else if (err
== -1) {
2049 s
= "setupterm: could not find terminfo database";
2052 PyErr_SetString(PyCursesError
,s
);
2056 initialised_setupterm
= TRUE
;
2063 PyCurses_IntrFlush(PyObject
*self
, PyObject
*args
)
2069 switch(PyTuple_Size(args
)) {
2071 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&ch
)) return NULL
;
2074 PyErr_SetString(PyExc_TypeError
, "intrflush requires 1 argument");
2078 return PyCursesCheckERR(intrflush(NULL
,ch
), "intrflush");
2081 #ifdef HAVE_CURSES_IS_TERM_RESIZED
2083 PyCurses_Is_Term_Resized(PyObject
*self
, PyObject
*args
)
2091 if (!PyArg_ParseTuple(args
,"ii:is_term_resized", &lines
, &columns
))
2093 result
= is_term_resized(lines
, columns
);
2094 if (result
== TRUE
) {
2098 Py_INCREF(Py_False
);
2102 #endif /* HAVE_CURSES_IS_TERM_RESIZED */
2104 #if !defined(__NetBSD__)
2106 PyCurses_KeyName(PyObject
*self
, PyObject
*args
)
2113 if (!PyArg_ParseTuple(args
,"i",&ch
)) return NULL
;
2116 PyErr_SetString(PyExc_ValueError
, "invalid key number");
2121 return PyString_FromString((knp
== NULL
) ? "" : (char *)knp
);
2126 PyCurses_KillChar(PyObject
*self
)
2132 return PyString_FromStringAndSize(&ch
, 1);
2136 PyCurses_Meta(PyObject
*self
, PyObject
*args
)
2142 switch(PyTuple_Size(args
)) {
2144 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&ch
)) return NULL
;
2147 PyErr_SetString(PyExc_TypeError
, "meta requires 1 argument");
2151 return PyCursesCheckERR(meta(stdscr
, ch
), "meta");
2154 #ifdef NCURSES_MOUSE_VERSION
2156 PyCurses_MouseInterval(PyObject
*self
, PyObject
*args
)
2161 if (!PyArg_ParseTuple(args
,"i;interval",&interval
))
2163 return PyCursesCheckERR(mouseinterval(interval
), "mouseinterval");
2167 PyCurses_MouseMask(PyObject
*self
, PyObject
*args
)
2170 mmask_t oldmask
, availmask
;
2173 if (!PyArg_ParseTuple(args
,"i;mousemask",&newmask
))
2175 availmask
= mousemask(newmask
, &oldmask
);
2176 return Py_BuildValue("(ll)", (long)availmask
, (long)oldmask
);
2181 PyCurses_Napms(PyObject
*self
, PyObject
*args
)
2186 if (!PyArg_ParseTuple(args
, "i;ms", &ms
)) return NULL
;
2188 return Py_BuildValue("i", napms(ms
));
2193 PyCurses_NewPad(PyObject
*self
, PyObject
*args
)
2200 if (!PyArg_ParseTuple(args
,"ii;nlines,ncols",&nlines
,&ncols
)) return NULL
;
2202 win
= newpad(nlines
, ncols
);
2205 PyErr_SetString(PyCursesError
, catchall_NULL
);
2209 return (PyObject
*)PyCursesWindow_New(win
);
2213 PyCurses_NewWindow(PyObject
*self
, PyObject
*args
)
2216 int nlines
, ncols
, begin_y
=0, begin_x
=0;
2220 switch (PyTuple_Size(args
)) {
2222 if (!PyArg_ParseTuple(args
,"ii;nlines,ncols",&nlines
,&ncols
))
2226 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
2227 &nlines
,&ncols
,&begin_y
,&begin_x
))
2231 PyErr_SetString(PyExc_TypeError
, "newwin requires 2 or 4 arguments");
2235 win
= newwin(nlines
,ncols
,begin_y
,begin_x
);
2237 PyErr_SetString(PyCursesError
, catchall_NULL
);
2241 return (PyObject
*)PyCursesWindow_New(win
);
2245 PyCurses_Pair_Content(PyObject
*self
, PyObject
*args
)
2250 PyCursesInitialisedColor
2252 switch(PyTuple_Size(args
)) {
2254 if (!PyArg_ParseTuple(args
, "h;pair", &pair
)) return NULL
;
2257 PyErr_SetString(PyExc_TypeError
, "pair_content requires 1 argument");
2261 if (pair_content(pair
, &f
, &b
)==ERR
) {
2262 PyErr_SetString(PyCursesError
,
2263 "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
2267 return Py_BuildValue("(ii)", f
, b
);
2271 PyCurses_pair_number(PyObject
*self
, PyObject
*args
)
2276 PyCursesInitialisedColor
2278 switch(PyTuple_Size(args
)) {
2280 if (!PyArg_ParseTuple(args
, "i;pairvalue", &n
)) return NULL
;
2283 PyErr_SetString(PyExc_TypeError
,
2284 "pair_number requires 1 argument");
2288 return PyInt_FromLong((long) ((n
& A_COLOR
) >> 8));
2292 PyCurses_Putp(PyObject
*self
, PyObject
*args
)
2296 if (!PyArg_ParseTuple(args
,"s;str", &str
)) return NULL
;
2297 return PyCursesCheckERR(putp(str
), "putp");
2301 PyCurses_QiFlush(PyObject
*self
, PyObject
*args
)
2307 switch(PyTuple_Size(args
)) {
2313 if (!PyArg_ParseTuple(args
, "i;True(1) or False(0)", &flag
)) return NULL
;
2314 if (flag
) qiflush();
2319 PyErr_SetString(PyExc_TypeError
, "qiflush requires 0 or 1 arguments");
2324 /* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
2325 * and _curses.COLS */
2326 #if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM)
2328 update_lines_cols(void)
2331 PyObject
*m
= PyImport_ImportModuleNoBlock("curses");
2336 o
= PyInt_FromLong(LINES
);
2341 if (PyObject_SetAttrString(m
, "LINES", o
)) {
2346 if (PyDict_SetItemString(ModDict
, "LINES", o
)) {
2352 o
= PyInt_FromLong(COLS
);
2357 if (PyObject_SetAttrString(m
, "COLS", o
)) {
2362 if (PyDict_SetItemString(ModDict
, "COLS", o
)) {
2373 #ifdef HAVE_CURSES_RESIZETERM
2375 PyCurses_ResizeTerm(PyObject
*self
, PyObject
*args
)
2383 if (!PyArg_ParseTuple(args
,"ii:resizeterm", &lines
, &columns
))
2386 result
= PyCursesCheckERR(resizeterm(lines
, columns
), "resizeterm");
2389 if (!update_lines_cols())
2396 #ifdef HAVE_CURSES_RESIZE_TERM
2398 PyCurses_Resize_Term(PyObject
*self
, PyObject
*args
)
2407 if (!PyArg_ParseTuple(args
,"ii:resize_term", &lines
, &columns
))
2410 result
= PyCursesCheckERR(resize_term(lines
, columns
), "resize_term");
2413 if (!update_lines_cols())
2417 #endif /* HAVE_CURSES_RESIZE_TERM */
2420 PyCurses_setsyx(PyObject
*self
, PyObject
*args
)
2426 if (PyTuple_Size(args
)!=2) {
2427 PyErr_SetString(PyExc_TypeError
, "setsyx requires 2 arguments");
2431 if (!PyArg_ParseTuple(args
, "ii;y, x", &y
, &x
)) return NULL
;
2440 PyCurses_Start_Color(PyObject
*self
)
2447 code
= start_color();
2449 initialisedcolors
= TRUE
;
2450 c
= PyInt_FromLong((long) COLORS
);
2451 PyDict_SetItemString(ModDict
, "COLORS", c
);
2453 cp
= PyInt_FromLong((long) COLOR_PAIRS
);
2454 PyDict_SetItemString(ModDict
, "COLOR_PAIRS", cp
);
2459 PyErr_SetString(PyCursesError
, "start_color() returned ERR");
2465 PyCurses_tigetflag(PyObject
*self
, PyObject
*args
)
2469 PyCursesSetupTermCalled
;
2471 if (!PyArg_ParseTuple(args
, "z", &capname
))
2474 return PyInt_FromLong( (long) tigetflag( capname
) );
2478 PyCurses_tigetnum(PyObject
*self
, PyObject
*args
)
2482 PyCursesSetupTermCalled
;
2484 if (!PyArg_ParseTuple(args
, "z", &capname
))
2487 return PyInt_FromLong( (long) tigetnum( capname
) );
2491 PyCurses_tigetstr(PyObject
*self
, PyObject
*args
)
2495 PyCursesSetupTermCalled
;
2497 if (!PyArg_ParseTuple(args
, "z", &capname
))
2500 capname
= tigetstr( capname
);
2501 if (capname
== 0 || capname
== (char*) -1) {
2505 return PyString_FromString( capname
);
2509 PyCurses_tparm(PyObject
*self
, PyObject
*args
)
2512 char* result
= NULL
;
2513 int i1
=0,i2
=0,i3
=0,i4
=0,i5
=0,i6
=0,i7
=0,i8
=0,i9
=0;
2515 PyCursesSetupTermCalled
;
2517 if (!PyArg_ParseTuple(args
, "s|iiiiiiiii:tparm",
2518 &fmt
, &i1
, &i2
, &i3
, &i4
,
2519 &i5
, &i6
, &i7
, &i8
, &i9
)) {
2523 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
,i9
);
2525 PyErr_SetString(PyCursesError
, "tparm() returned NULL");
2529 return PyString_FromString(result
);
2533 PyCurses_TypeAhead(PyObject
*self
, PyObject
*args
)
2539 if (!PyArg_ParseTuple(args
,"i;fd",&fd
)) return NULL
;
2541 return PyCursesCheckERR(typeahead( fd
), "typeahead");
2545 PyCurses_UnCtrl(PyObject
*self
, PyObject
*args
)
2552 if (!PyArg_ParseTuple(args
,"O;ch or int",&temp
)) return NULL
;
2554 if (PyInt_Check(temp
))
2555 ch
= (chtype
) PyInt_AsLong(temp
);
2556 else if (PyString_Check(temp
))
2557 ch
= (chtype
) *PyString_AsString(temp
);
2559 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2563 return PyString_FromString(unctrl(ch
));
2567 PyCurses_UngetCh(PyObject
*self
, PyObject
*args
)
2574 if (!PyArg_ParseTuple(args
,"O;ch or int",&temp
)) return NULL
;
2576 if (PyInt_Check(temp
))
2577 ch
= (int) PyInt_AsLong(temp
);
2578 else if (PyString_Check(temp
))
2579 ch
= (int) *PyString_AsString(temp
);
2581 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2585 return PyCursesCheckERR(ungetch(ch
), "ungetch");
2589 PyCurses_Use_Env(PyObject
*self
, PyObject
*args
)
2595 switch(PyTuple_Size(args
)) {
2597 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&flag
))
2601 PyErr_SetString(PyExc_TypeError
, "use_env requires 1 argument");
2609 #ifndef STRICT_SYSV_CURSES
2611 PyCurses_Use_Default_Colors(PyObject
*self
)
2616 PyCursesInitialisedColor
2618 code
= use_default_colors();
2623 PyErr_SetString(PyCursesError
, "use_default_colors() returned ERR");
2627 #endif /* STRICT_SYSV_CURSES */
2629 /* List of functions defined in the module */
2631 static PyMethodDef PyCurses_methods
[] = {
2632 {"baudrate", (PyCFunction
)PyCurses_baudrate
, METH_NOARGS
},
2633 {"beep", (PyCFunction
)PyCurses_beep
, METH_NOARGS
},
2634 {"can_change_color", (PyCFunction
)PyCurses_can_change_color
, METH_NOARGS
},
2635 {"cbreak", (PyCFunction
)PyCurses_cbreak
, METH_VARARGS
},
2636 {"color_content", (PyCFunction
)PyCurses_Color_Content
, METH_VARARGS
},
2637 {"color_pair", (PyCFunction
)PyCurses_color_pair
, METH_VARARGS
},
2638 {"curs_set", (PyCFunction
)PyCurses_Curs_Set
, METH_VARARGS
},
2639 {"def_prog_mode", (PyCFunction
)PyCurses_def_prog_mode
, METH_NOARGS
},
2640 {"def_shell_mode", (PyCFunction
)PyCurses_def_shell_mode
, METH_NOARGS
},
2641 {"delay_output", (PyCFunction
)PyCurses_Delay_Output
, METH_VARARGS
},
2642 {"doupdate", (PyCFunction
)PyCurses_doupdate
, METH_NOARGS
},
2643 {"echo", (PyCFunction
)PyCurses_echo
, METH_VARARGS
},
2644 {"endwin", (PyCFunction
)PyCurses_endwin
, METH_NOARGS
},
2645 {"erasechar", (PyCFunction
)PyCurses_EraseChar
, METH_NOARGS
},
2646 {"filter", (PyCFunction
)PyCurses_filter
, METH_NOARGS
},
2647 {"flash", (PyCFunction
)PyCurses_flash
, METH_NOARGS
},
2648 {"flushinp", (PyCFunction
)PyCurses_flushinp
, METH_NOARGS
},
2649 #ifdef NCURSES_MOUSE_VERSION
2650 {"getmouse", (PyCFunction
)PyCurses_GetMouse
, METH_NOARGS
},
2651 {"ungetmouse", (PyCFunction
)PyCurses_UngetMouse
, METH_VARARGS
},
2653 {"getsyx", (PyCFunction
)PyCurses_getsyx
, METH_NOARGS
},
2654 {"getwin", (PyCFunction
)PyCurses_GetWin
, METH_O
},
2655 {"has_colors", (PyCFunction
)PyCurses_has_colors
, METH_NOARGS
},
2656 {"has_ic", (PyCFunction
)PyCurses_has_ic
, METH_NOARGS
},
2657 {"has_il", (PyCFunction
)PyCurses_has_il
, METH_NOARGS
},
2658 #ifndef STRICT_SYSV_CURSES
2659 {"has_key", (PyCFunction
)PyCurses_has_key
, METH_VARARGS
},
2661 {"halfdelay", (PyCFunction
)PyCurses_HalfDelay
, METH_VARARGS
},
2662 {"init_color", (PyCFunction
)PyCurses_Init_Color
, METH_VARARGS
},
2663 {"init_pair", (PyCFunction
)PyCurses_Init_Pair
, METH_VARARGS
},
2664 {"initscr", (PyCFunction
)PyCurses_InitScr
, METH_NOARGS
},
2665 {"intrflush", (PyCFunction
)PyCurses_IntrFlush
, METH_VARARGS
},
2666 {"isendwin", (PyCFunction
)PyCurses_isendwin
, METH_NOARGS
},
2667 #ifdef HAVE_CURSES_IS_TERM_RESIZED
2668 {"is_term_resized", (PyCFunction
)PyCurses_Is_Term_Resized
, METH_VARARGS
},
2670 #if !defined(__NetBSD__)
2671 {"keyname", (PyCFunction
)PyCurses_KeyName
, METH_VARARGS
},
2673 {"killchar", (PyCFunction
)PyCurses_KillChar
, METH_NOARGS
},
2674 {"longname", (PyCFunction
)PyCurses_longname
, METH_NOARGS
},
2675 {"meta", (PyCFunction
)PyCurses_Meta
, METH_VARARGS
},
2676 #ifdef NCURSES_MOUSE_VERSION
2677 {"mouseinterval", (PyCFunction
)PyCurses_MouseInterval
, METH_VARARGS
},
2678 {"mousemask", (PyCFunction
)PyCurses_MouseMask
, METH_VARARGS
},
2680 {"napms", (PyCFunction
)PyCurses_Napms
, METH_VARARGS
},
2681 {"newpad", (PyCFunction
)PyCurses_NewPad
, METH_VARARGS
},
2682 {"newwin", (PyCFunction
)PyCurses_NewWindow
, METH_VARARGS
},
2683 {"nl", (PyCFunction
)PyCurses_nl
, METH_VARARGS
},
2684 {"nocbreak", (PyCFunction
)PyCurses_nocbreak
, METH_NOARGS
},
2685 {"noecho", (PyCFunction
)PyCurses_noecho
, METH_NOARGS
},
2686 {"nonl", (PyCFunction
)PyCurses_nonl
, METH_NOARGS
},
2687 {"noqiflush", (PyCFunction
)PyCurses_noqiflush
, METH_NOARGS
},
2688 {"noraw", (PyCFunction
)PyCurses_noraw
, METH_NOARGS
},
2689 {"pair_content", (PyCFunction
)PyCurses_Pair_Content
, METH_VARARGS
},
2690 {"pair_number", (PyCFunction
)PyCurses_pair_number
, METH_VARARGS
},
2691 {"putp", (PyCFunction
)PyCurses_Putp
, METH_VARARGS
},
2692 {"qiflush", (PyCFunction
)PyCurses_QiFlush
, METH_VARARGS
},
2693 {"raw", (PyCFunction
)PyCurses_raw
, METH_VARARGS
},
2694 {"reset_prog_mode", (PyCFunction
)PyCurses_reset_prog_mode
, METH_NOARGS
},
2695 {"reset_shell_mode", (PyCFunction
)PyCurses_reset_shell_mode
, METH_NOARGS
},
2696 {"resetty", (PyCFunction
)PyCurses_resetty
, METH_NOARGS
},
2697 #ifdef HAVE_CURSES_RESIZETERM
2698 {"resizeterm", (PyCFunction
)PyCurses_ResizeTerm
, METH_VARARGS
},
2700 #ifdef HAVE_CURSES_RESIZE_TERM
2701 {"resize_term", (PyCFunction
)PyCurses_Resize_Term
, METH_VARARGS
},
2703 {"savetty", (PyCFunction
)PyCurses_savetty
, METH_NOARGS
},
2704 {"setsyx", (PyCFunction
)PyCurses_setsyx
, METH_VARARGS
},
2705 {"setupterm", (PyCFunction
)PyCurses_setupterm
,
2706 METH_VARARGS
|METH_KEYWORDS
},
2707 {"start_color", (PyCFunction
)PyCurses_Start_Color
, METH_NOARGS
},
2708 {"termattrs", (PyCFunction
)PyCurses_termattrs
, METH_NOARGS
},
2709 {"termname", (PyCFunction
)PyCurses_termname
, METH_NOARGS
},
2710 {"tigetflag", (PyCFunction
)PyCurses_tigetflag
, METH_VARARGS
},
2711 {"tigetnum", (PyCFunction
)PyCurses_tigetnum
, METH_VARARGS
},
2712 {"tigetstr", (PyCFunction
)PyCurses_tigetstr
, METH_VARARGS
},
2713 {"tparm", (PyCFunction
)PyCurses_tparm
, METH_VARARGS
},
2714 {"typeahead", (PyCFunction
)PyCurses_TypeAhead
, METH_VARARGS
},
2715 {"unctrl", (PyCFunction
)PyCurses_UnCtrl
, METH_VARARGS
},
2716 {"ungetch", (PyCFunction
)PyCurses_UngetCh
, METH_VARARGS
},
2717 {"use_env", (PyCFunction
)PyCurses_Use_Env
, METH_VARARGS
},
2718 #ifndef STRICT_SYSV_CURSES
2719 {"use_default_colors", (PyCFunction
)PyCurses_Use_Default_Colors
, METH_NOARGS
},
2721 {NULL
, NULL
} /* sentinel */
2724 /* Initialization function for the module */
2729 PyObject
*m
, *d
, *v
, *c_api_object
;
2730 static void *PyCurses_API
[PyCurses_API_pointers
];
2732 /* Initialize object type */
2733 Py_TYPE(&PyCursesWindow_Type
) = &PyType_Type
;
2735 /* Initialize the C API pointer array */
2736 PyCurses_API
[0] = (void *)&PyCursesWindow_Type
;
2737 PyCurses_API
[1] = (void *)func_PyCursesSetupTermCalled
;
2738 PyCurses_API
[2] = (void *)func_PyCursesInitialised
;
2739 PyCurses_API
[3] = (void *)func_PyCursesInitialisedColor
;
2741 /* Create the module and add the functions */
2742 m
= Py_InitModule("_curses", PyCurses_methods
);
2746 /* Add some symbolic constants to the module */
2747 d
= PyModule_GetDict(m
);
2750 ModDict
= d
; /* For PyCurses_InitScr to use later */
2752 /* Add a CObject for the C API */
2753 c_api_object
= PyCObject_FromVoidPtr((void *)PyCurses_API
, NULL
);
2754 PyDict_SetItemString(d
, "_C_API", c_api_object
);
2755 Py_DECREF(c_api_object
);
2757 /* For exception curses.error */
2758 PyCursesError
= PyErr_NewException("_curses.error", NULL
, NULL
);
2759 PyDict_SetItemString(d
, "error", PyCursesError
);
2761 /* Make the version available */
2762 v
= PyString_FromString(PyCursesVersion
);
2763 PyDict_SetItemString(d
, "version", v
);
2764 PyDict_SetItemString(d
, "__version__", v
);
2767 SetDictInt("ERR", ERR
);
2768 SetDictInt("OK", OK
);
2770 /* Here are some attributes you can add to chars to print */
2772 SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES
);
2773 SetDictInt("A_NORMAL", A_NORMAL
);
2774 SetDictInt("A_STANDOUT", A_STANDOUT
);
2775 SetDictInt("A_UNDERLINE", A_UNDERLINE
);
2776 SetDictInt("A_REVERSE", A_REVERSE
);
2777 SetDictInt("A_BLINK", A_BLINK
);
2778 SetDictInt("A_DIM", A_DIM
);
2779 SetDictInt("A_BOLD", A_BOLD
);
2780 SetDictInt("A_ALTCHARSET", A_ALTCHARSET
);
2781 #if !defined(__NetBSD__)
2782 SetDictInt("A_INVIS", A_INVIS
);
2784 SetDictInt("A_PROTECT", A_PROTECT
);
2785 SetDictInt("A_CHARTEXT", A_CHARTEXT
);
2786 SetDictInt("A_COLOR", A_COLOR
);
2788 /* The following are never available with strict SYSV curses */
2790 SetDictInt("A_HORIZONTAL", A_HORIZONTAL
);
2793 SetDictInt("A_LEFT", A_LEFT
);
2796 SetDictInt("A_LOW", A_LOW
);
2799 SetDictInt("A_RIGHT", A_RIGHT
);
2802 SetDictInt("A_TOP", A_TOP
);
2805 SetDictInt("A_VERTICAL", A_VERTICAL
);
2808 SetDictInt("COLOR_BLACK", COLOR_BLACK
);
2809 SetDictInt("COLOR_RED", COLOR_RED
);
2810 SetDictInt("COLOR_GREEN", COLOR_GREEN
);
2811 SetDictInt("COLOR_YELLOW", COLOR_YELLOW
);
2812 SetDictInt("COLOR_BLUE", COLOR_BLUE
);
2813 SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA
);
2814 SetDictInt("COLOR_CYAN", COLOR_CYAN
);
2815 SetDictInt("COLOR_WHITE", COLOR_WHITE
);
2817 #ifdef NCURSES_MOUSE_VERSION
2818 /* Mouse-related constants */
2819 SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED
);
2820 SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED
);
2821 SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED
);
2822 SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED
);
2823 SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED
);
2825 SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED
);
2826 SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED
);
2827 SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED
);
2828 SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED
);
2829 SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED
);
2831 SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED
);
2832 SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED
);
2833 SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED
);
2834 SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED
);
2835 SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED
);
2837 SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED
);
2838 SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED
);
2839 SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED
);
2840 SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED
);
2841 SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED
);
2843 SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT
);
2844 SetDictInt("BUTTON_CTRL", BUTTON_CTRL
);
2845 SetDictInt("BUTTON_ALT", BUTTON_ALT
);
2847 SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS
);
2848 SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION
);
2850 /* Now set everything up for KEY_ variables */
2855 #if !defined(__NetBSD__)
2856 for (key
=KEY_MIN
;key
< KEY_MAX
; key
++) {
2857 key_n
= (char *)keyname(key
);
2858 if (key_n
== NULL
|| strcmp(key_n
,"UNKNOWN KEY")==0)
2860 if (strncmp(key_n
,"KEY_F(",6)==0) {
2862 key_n2
= malloc(strlen(key_n
)+1);
2870 if (*p1
!= '(' && *p1
!= ')') {
2879 SetDictInt(key_n2
,key
);
2880 if (key_n2
!= key_n
)
2884 SetDictInt("KEY_MIN", KEY_MIN
);
2885 SetDictInt("KEY_MAX", KEY_MAX
);