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
12 * <akuchlin@mems-exchange.org>.
14 * Permission is hereby granted, free of charge, to any person obtaining
15 * a copy of this source file to use, copy, modify, merge, or publish it
16 * subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or in any new file that contains a substantial portion of
22 * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF
23 * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
24 * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES
25 * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
26 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE
28 * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL,
29 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
30 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR
31 * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
32 * PERFORMANCE OF THIS SOFTWARE.
39 A number of SysV or ncurses functions don't have wrappers yet; if you need
40 a given function, add it and send a patch. Here's a list of currently
41 unsupported functions:
43 addchnstr addchstr chgat color_set define_key
44 del_curterm delscreen dupwin inchnstr inchstr innstr keyok
45 mcprint mvaddchnstr mvaddchstr mvchgat mvcur mvinchnstr
46 mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
47 mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr newterm
48 resizeterm restartterm ripoffline scr_dump
49 scr_init scr_restore scr_set scrl set_curterm set_term setterm
50 tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
51 use_default_colors vidattr vidputs waddchnstr waddchstr wchgat
52 wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
55 slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
56 slk_attron slk_attrset slk_clear slk_color slk_init slk_label
57 slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
59 Menu extension (ncurses and probably SYSV):
60 current_item free_item free_menu item_count item_description
61 item_index item_init item_name item_opts item_opts_off
62 item_opts_on item_term item_userptr item_value item_visible
63 menu_back menu_driver menu_fore menu_format menu_grey
64 menu_init menu_items menu_mark menu_opts menu_opts_off
65 menu_opts_on menu_pad menu_pattern menu_request_by_name
66 menu_request_name menu_spacing menu_sub menu_term menu_userptr
67 menu_win new_item new_menu pos_menu_cursor post_menu
68 scale_menu set_current_item set_item_init set_item_opts
69 set_item_term set_item_userptr set_item_value set_menu_back
70 set_menu_fore set_menu_format set_menu_grey set_menu_init
71 set_menu_items set_menu_mark set_menu_opts set_menu_pad
72 set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
73 set_menu_userptr set_menu_win set_top_row top_row unpost_menu
75 Form extension (ncurses and probably SYSV):
76 current_field data_ahead data_behind dup_field
77 dynamic_fieldinfo field_arg field_back field_buffer
78 field_count field_fore field_index field_info field_init
79 field_just field_opts field_opts_off field_opts_on field_pad
80 field_status field_term field_type field_userptr form_driver
81 form_fields form_init form_opts form_opts_off form_opts_on
82 form_page form_request_by_name form_request_name form_sub
83 form_term form_userptr form_win free_field free_form
84 link_field link_fieldtype move_field new_field new_form
85 new_page pos_form_cursor post_form scale_form
86 set_current_field set_field_back set_field_buffer
87 set_field_fore set_field_init set_field_just set_field_opts
88 set_field_pad set_field_status set_field_term set_field_type
89 set_field_userptr set_fieldtype_arg set_fieldtype_choice
90 set_form_fields set_form_init set_form_opts set_form_page
91 set_form_sub set_form_term set_form_userptr set_form_win
92 set_max_field set_new_page unpost_form
99 char *PyCursesVersion
= "2.2";
106 #define _XOPEN_SOURCE_EXTENDED /* Define macro for OSF/1 */
107 #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
111 #define _XOPEN_SOURCE_EXTENDED
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))
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"); \
168 /* Utility Functions */
171 * Check the return code from a curses function and return None
172 * or raise an exception as appropriate. These are exported using the
177 PyCursesCheckERR(int code
, char *fname
)
184 PyErr_SetString(PyCursesError
, catchall_ERR
);
186 PyErr_Format(PyCursesError
, "%s() returned ERR", fname
);
193 PyCurses_ConvertToChtype(PyObject
*obj
, chtype
*ch
)
195 if (PyInt_Check(obj
)) {
196 *ch
= (chtype
) PyInt_AsLong(obj
);
197 } else if(PyString_Check(obj
)
198 && (PyString_Size(obj
) == 1)) {
199 *ch
= (chtype
) *PyString_AsString(obj
);
206 /* Function versions of the 3 functions for tested whether curses has been
207 initialised or not. */
209 static int func_PyCursesSetupTermCalled(void)
211 PyCursesSetupTermCalled
;
215 static int func_PyCursesInitialised(void)
221 static int func_PyCursesInitialisedColor(void)
223 PyCursesInitialisedColor
;
227 /*****************************************************************************
229 ******************************************************************************/
231 /* Definition of the window type */
233 PyTypeObject PyCursesWindow_Type
;
235 /* Function prototype macros for Window object
238 TYPE - parameter Type
239 ERGSTR - format string for construction of the return value
240 PARSESTR - format string for argument parsing
243 #define Window_NoArgNoReturnFunction(X) \
244 static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
245 { if (!PyArg_NoArgs(args)) return NULL; \
246 return PyCursesCheckERR(X(self->win), # X); }
248 #define Window_NoArgTrueFalseFunction(X) \
249 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
251 if (!PyArg_NoArgs(args)) return NULL; \
252 if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
253 else { Py_INCREF(Py_True); return Py_True; } }
255 #define Window_NoArgNoReturnVoidFunction(X) \
256 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
258 if (!PyArg_NoArgs(args)) return NULL; \
259 X(self->win); Py_INCREF(Py_None); return Py_None; }
261 #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
262 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
265 if (!PyArg_NoArgs(args)) return NULL; \
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_Parse(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_Parse(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_Parse(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(wattron
, attr_t
, "l;attr")
319 Window_OneArgNoReturnFunction(wattroff
, attr_t
, "l;attr")
320 Window_OneArgNoReturnFunction(wattrset
, attr_t
, "l;attr")
321 Window_OneArgNoReturnFunction(clearok
, int, "i;True(1) or False(0)")
322 Window_OneArgNoReturnFunction(idlok
, int, "i;True(1) or False(0)")
323 #if defined(__NetBSD__)
324 Window_OneArgNoReturnVoidFunction(keypad
, int, "i;True(1) or False(0)")
326 Window_OneArgNoReturnFunction(keypad
, int, "i;True(1) or False(0)")
328 Window_OneArgNoReturnFunction(leaveok
, int, "i;True(1) or False(0)")
329 #if defined(__NetBSD__)
330 Window_OneArgNoReturnVoidFunction(nodelay
, int, "i;True(1) or False(0)")
332 Window_OneArgNoReturnFunction(nodelay
, int, "i;True(1) or False(0)")
334 Window_OneArgNoReturnFunction(notimeout
, int, "i;True(1) or False(0)")
335 Window_OneArgNoReturnFunction(scrollok
, int, "i;True(1) or False(0)")
336 Window_OneArgNoReturnFunction(winsdelln
, int, "i;nlines")
337 Window_OneArgNoReturnFunction(syncok
, int, "i;True(1) or False(0)")
339 Window_TwoArgNoReturnFunction(mvwin
, int, "(ii);y,x")
340 Window_TwoArgNoReturnFunction(mvderwin
, int, "(ii);y,x")
341 Window_TwoArgNoReturnFunction(wmove
, int, "(ii);y,x")
342 #ifndef STRICT_SYSV_CURSES
343 Window_TwoArgNoReturnFunction(wresize
, int, "(ii);lines,columns")
346 /* Allocation and deallocation of Window Objects */
349 PyCursesWindow_New(WINDOW
*win
)
351 PyCursesWindowObject
*wo
;
353 wo
= PyObject_NEW(PyCursesWindowObject
, &PyCursesWindow_Type
);
354 if (wo
== NULL
) return NULL
;
356 return (PyObject
*)wo
;
360 PyCursesWindow_Dealloc(PyCursesWindowObject
*wo
)
362 if (wo
->win
!= stdscr
) delwin(wo
->win
);
366 /* Addch, Addstr, Addnstr */
369 PyCursesWindow_AddCh(PyCursesWindowObject
*self
, PyObject
*args
)
371 int rtn
, x
, y
, use_xy
= FALSE
;
374 attr_t attr
= A_NORMAL
;
376 switch (ARG_COUNT(args
)) {
378 if (!PyArg_Parse(args
, "O;ch or int", &temp
))
382 if (!PyArg_Parse(args
, "(Ol);ch or int,attr", &temp
, &attr
))
386 if (!PyArg_Parse(args
,"(iiO);y,x,ch or int", &y
, &x
, &temp
))
391 if (!PyArg_Parse(args
,"(iiOl);y,x,ch or int, attr",
392 &y
, &x
, &temp
, &attr
))
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
;
421 int use_xy
= FALSE
, use_attr
= FALSE
;
423 switch (ARG_COUNT(args
)) {
425 if (!PyArg_Parse(args
,"s;str", &str
))
429 if (!PyArg_Parse(args
,"(sl);str,attr", &str
, &attr
))
434 if (!PyArg_Parse(args
,"(iis);int,int,str", &y
, &x
, &str
))
439 if (!PyArg_Parse(args
,"(iisl);int,int,str,attr", &y
, &x
, &str
, &attr
))
441 use_xy
= use_attr
= TRUE
;
444 PyErr_SetString(PyExc_TypeError
, "addstr requires 1 to 4 arguments");
448 if (use_attr
== TRUE
) {
449 attr_old
= getattrs(self
->win
);
450 wattrset(self
->win
,attr
);
453 rtn
= mvwaddstr(self
->win
,y
,x
,str
);
455 rtn
= waddstr(self
->win
,str
);
456 if (use_attr
== TRUE
)
457 wattrset(self
->win
,attr_old
);
458 return PyCursesCheckERR(rtn
, "addstr");
462 PyCursesWindow_AddNStr(PyCursesWindowObject
*self
, PyObject
*args
)
466 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
467 int use_xy
= FALSE
, use_attr
= FALSE
;
469 switch (ARG_COUNT(args
)) {
471 if (!PyArg_Parse(args
,"(si);str,n", &str
, &n
))
475 if (!PyArg_Parse(args
,"(sil);str,n,attr", &str
, &n
, &attr
))
480 if (!PyArg_Parse(args
,"(iisi);y,x,str,n", &y
, &x
, &str
, &n
))
485 if (!PyArg_Parse(args
,"(iisil);y,x,str,n,attr", &y
, &x
, &str
, &n
, &attr
))
487 use_xy
= use_attr
= TRUE
;
490 PyErr_SetString(PyExc_TypeError
, "addnstr requires 2 to 5 arguments");
494 if (use_attr
== TRUE
) {
495 attr_old
= getattrs(self
->win
);
496 wattrset(self
->win
,attr
);
499 rtn
= mvwaddnstr(self
->win
,y
,x
,str
,n
);
501 rtn
= waddnstr(self
->win
,str
,n
);
502 if (use_attr
== TRUE
)
503 wattrset(self
->win
,attr_old
);
504 return PyCursesCheckERR(rtn
, "addnstr");
508 PyCursesWindow_Bkgd(PyCursesWindowObject
*self
, PyObject
*args
)
512 attr_t attr
= A_NORMAL
;
514 switch (ARG_COUNT(args
)) {
516 if (!PyArg_Parse(args
, "O;ch or int", &temp
))
520 if (!PyArg_Parse(args
,"(Ol);ch or int,attr", &temp
, &attr
))
524 PyErr_SetString(PyExc_TypeError
, "bkgd requires 1 or 2 arguments");
528 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
529 PyErr_SetString(PyExc_TypeError
, "argument 1 or 3 must be a ch or an int");
533 return PyCursesCheckERR(wbkgd(self
->win
, bkgd
| attr
), "bkgd");
537 PyCursesWindow_BkgdSet(PyCursesWindowObject
*self
, PyObject
*args
)
541 attr_t attr
= A_NORMAL
;
543 switch (ARG_COUNT(args
)) {
545 if (!PyArg_Parse(args
, "O;ch or int", &temp
))
549 if (!PyArg_Parse(args
,"(Ol);ch or int,attr", &temp
, &attr
))
553 PyErr_SetString(PyExc_TypeError
, "bkgdset requires 1 or 2 arguments");
557 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
558 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
562 wbkgdset(self
->win
, bkgd
| attr
);
563 return PyCursesCheckERR(0, "bkgdset");
567 PyCursesWindow_Border(PyCursesWindowObject
*self
, PyObject
*args
)
573 /* Clear the array of parameters */
579 if (!PyArg_ParseTuple(args
,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
580 &temp
[0], &temp
[1], &temp
[2], &temp
[3],
581 &temp
[4], &temp
[5], &temp
[6], &temp
[7]))
585 if (temp
[i
] != NULL
&& !PyCurses_ConvertToChtype(temp
[i
], &ch
[i
])) {
586 PyErr_Format(PyExc_TypeError
,
587 "argument %i must be a ch or an int", i
+1);
593 ch
[0], ch
[1], ch
[2], ch
[3],
594 ch
[4], ch
[5], ch
[6], ch
[7]);
600 PyCursesWindow_Box(PyCursesWindowObject
*self
, PyObject
*args
)
603 if (!PyArg_NoArgs(args
)) {
605 if (!PyArg_Parse(args
,"(ll);vertint,horint", &ch1
, &ch2
))
608 box(self
->win
,ch1
,ch2
);
613 #if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
614 #define py_mvwdelch mvwdelch
616 int py_mvwdelch(WINDOW
*w
, int y
, int x
)
619 /* On HP/UX, mvwdelch already returns. On other systems,
620 we may well run into this return statement. */
627 PyCursesWindow_DelCh(PyCursesWindowObject
*self
, PyObject
*args
)
632 switch (ARG_COUNT(args
)) {
634 rtn
= wdelch(self
->win
);
637 if (!PyArg_Parse(args
,"(ii);y,x", &y
, &x
))
639 rtn
= py_mvwdelch(self
->win
,y
,x
);
642 PyErr_SetString(PyExc_TypeError
, "delch requires 0 or 2 arguments");
645 return PyCursesCheckERR(rtn
, "[mv]wdelch");
649 PyCursesWindow_DerWin(PyCursesWindowObject
*self
, PyObject
*args
)
652 int nlines
, ncols
, begin_y
, begin_x
;
656 switch (ARG_COUNT(args
)) {
658 if (!PyArg_Parse(args
,"(ii);begin_y,begin_x",&begin_y
,&begin_x
))
662 if (!PyArg_Parse(args
, "(iiii);nlines,ncols,begin_y,begin_x",
663 &nlines
,&ncols
,&begin_y
,&begin_x
))
667 PyErr_SetString(PyExc_TypeError
, "derwin requires 2 or 4 arguments");
671 win
= derwin(self
->win
,nlines
,ncols
,begin_y
,begin_x
);
674 PyErr_SetString(PyCursesError
, catchall_NULL
);
678 return (PyObject
*)PyCursesWindow_New(win
);
682 PyCursesWindow_EchoChar(PyCursesWindowObject
*self
, PyObject
*args
)
686 attr_t attr
= A_NORMAL
;
688 switch (ARG_COUNT(args
)) {
690 if (!PyArg_Parse(args
,"O;ch or int", &temp
))
694 if (!PyArg_Parse(args
,"(Ol);ch or int,attr", &temp
, &attr
))
698 PyErr_SetString(PyExc_TypeError
, "echochar requires 1 or 2 arguments");
704 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
705 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
709 #ifdef WINDOW_HAS_FLAGS
710 if (self
->win
->_flags
& _ISPAD
)
711 return PyCursesCheckERR(pechochar(self
->win
, ch
| attr
),
715 return PyCursesCheckERR(wechochar(self
->win
, ch
| attr
),
719 #ifdef NCURSES_MOUSE_VERSION
721 PyCursesWindow_Enclose(PyCursesWindowObject
*self
, PyObject
*args
)
724 if (!PyArg_Parse(args
,"(ii);y,x", &y
, &x
))
727 return PyInt_FromLong( wenclose(self
->win
,y
,x
) );
732 PyCursesWindow_GetBkgd(PyCursesWindowObject
*self
, PyObject
*args
)
734 if (!PyArg_NoArgs(args
))
736 return PyInt_FromLong((long) getbkgd(self
->win
));
740 PyCursesWindow_GetCh(PyCursesWindowObject
*self
, PyObject
*args
)
745 switch (ARG_COUNT(args
)) {
747 Py_BEGIN_ALLOW_THREADS
748 rtn
= wgetch(self
->win
);
752 if (!PyArg_Parse(args
,"(ii);y,x",&y
,&x
))
754 Py_BEGIN_ALLOW_THREADS
755 rtn
= mvwgetch(self
->win
,y
,x
);
759 PyErr_SetString(PyExc_TypeError
, "getch requires 0 or 2 arguments");
762 return PyInt_FromLong((long)rtn
);
766 PyCursesWindow_GetKey(PyCursesWindowObject
*self
, PyObject
*args
)
771 switch (ARG_COUNT(args
)) {
773 Py_BEGIN_ALLOW_THREADS
774 rtn
= wgetch(self
->win
);
778 if (!PyArg_Parse(args
,"(ii);y,x",&y
,&x
))
780 Py_BEGIN_ALLOW_THREADS
781 rtn
= mvwgetch(self
->win
,y
,x
);
785 PyErr_SetString(PyExc_TypeError
, "getkey requires 0 or 2 arguments");
789 return Py_BuildValue("c", rtn
);
791 #if defined(__NetBSD__)
792 return PyString_FromString(unctrl(rtn
));
794 return PyString_FromString((char *)keyname(rtn
));
799 PyCursesWindow_GetStr(PyCursesWindowObject
*self
, PyObject
*args
)
802 char rtn
[1024]; /* This should be big enough.. I hope */
805 switch (ARG_COUNT(args
)) {
807 Py_BEGIN_ALLOW_THREADS
808 rtn2
= wgetstr(self
->win
,rtn
);
812 if (!PyArg_Parse(args
,"i;n", &n
))
814 Py_BEGIN_ALLOW_THREADS
815 rtn2
= wgetnstr(self
->win
,rtn
,n
);
819 if (!PyArg_Parse(args
,"(ii);y,x",&y
,&x
))
821 Py_BEGIN_ALLOW_THREADS
822 rtn2
= mvwgetstr(self
->win
,y
,x
,rtn
);
826 if (!PyArg_Parse(args
,"(iii);y,x,n", &y
, &x
, &n
))
828 #ifdef STRICT_SYSV_CURSES
830 Py_BEGIN_ALLOW_THREADS
831 rtn2
= wmove(self
->win
,y
,x
)==ERR
? ERR
:
832 wgetnstr(self
->win
, rtn
, n
);
835 Py_BEGIN_ALLOW_THREADS
836 rtn2
= mvwgetnstr(self
->win
, y
, x
, rtn
, n
);
841 PyErr_SetString(PyExc_TypeError
, "getstr requires 0 to 2 arguments");
846 return PyString_FromString(rtn
);
850 PyCursesWindow_Hline(PyCursesWindowObject
*self
, PyObject
*args
)
854 int n
, x
, y
, code
= OK
;
855 attr_t attr
= A_NORMAL
;
857 switch (ARG_COUNT(args
)) {
859 if (!PyArg_Parse(args
, "(Oi);ch or int,n", &temp
, &n
))
863 if (!PyArg_Parse(args
, "(Oil);ch or int,n,attr", &temp
, &n
, &attr
))
867 if (!PyArg_Parse(args
, "(iiOi);y,x,ch or int,n", &y
, &x
, &temp
, &n
))
869 code
= wmove(self
->win
, y
, x
);
872 if (!PyArg_Parse(args
, "(iiOil); y,x,ch or int,n,attr",
873 &y
, &x
, &temp
, &n
, &attr
))
875 code
= wmove(self
->win
, y
, x
);
878 PyErr_SetString(PyExc_TypeError
, "hline requires 2 to 5 arguments");
883 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
884 PyErr_SetString(PyExc_TypeError
,
885 "argument 1 or 3 must be a ch or an int");
888 return PyCursesCheckERR(whline(self
->win
, ch
| attr
, n
), "hline");
890 return PyCursesCheckERR(code
, "wmove");
894 PyCursesWindow_InsCh(PyCursesWindowObject
*self
, PyObject
*args
)
896 int rtn
, x
, y
, use_xy
= FALSE
;
899 attr_t attr
= A_NORMAL
;
901 switch (ARG_COUNT(args
)) {
903 if (!PyArg_Parse(args
, "O;ch or int", &temp
))
907 if (!PyArg_Parse(args
, "(Ol);ch or int,attr", &temp
, &attr
))
911 if (!PyArg_Parse(args
,"(iiO);y,x,ch or int", &y
, &x
, &temp
))
916 if (!PyArg_Parse(args
,"(iiOl);y,x,ch or int, attr", &y
, &x
, &temp
, &attr
))
921 PyErr_SetString(PyExc_TypeError
, "insch requires 1 or 4 arguments");
925 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
926 PyErr_SetString(PyExc_TypeError
,
927 "argument 1 or 3 must be a ch or an int");
932 rtn
= mvwinsch(self
->win
,y
,x
, ch
| attr
);
934 rtn
= winsch(self
->win
, ch
| attr
);
936 return PyCursesCheckERR(rtn
, "insch");
940 PyCursesWindow_InCh(PyCursesWindowObject
*self
, PyObject
*args
)
944 switch (ARG_COUNT(args
)) {
946 rtn
= winch(self
->win
);
949 if (!PyArg_Parse(args
,"(ii);y,x",&y
,&x
))
951 rtn
= mvwinch(self
->win
,y
,x
);
954 PyErr_SetString(PyExc_TypeError
, "inch requires 0 or 2 arguments");
957 return PyInt_FromLong((long) rtn
);
961 PyCursesWindow_InStr(PyCursesWindowObject
*self
, PyObject
*args
)
964 char rtn
[1024]; /* This should be big enough.. I hope */
967 switch (ARG_COUNT(args
)) {
969 rtn2
= winstr(self
->win
,rtn
);
972 if (!PyArg_Parse(args
,"i;n", &n
))
974 rtn2
= winnstr(self
->win
,rtn
,n
);
977 if (!PyArg_Parse(args
,"(ii);y,x",&y
,&x
))
979 rtn2
= mvwinstr(self
->win
,y
,x
,rtn
);
982 if (!PyArg_Parse(args
, "(iii);y,x,n", &y
, &x
, &n
))
984 rtn2
= mvwinnstr(self
->win
, y
, x
, rtn
, n
);
987 PyErr_SetString(PyExc_TypeError
, "instr requires 0 or 3 arguments");
992 return PyString_FromString(rtn
);
996 PyCursesWindow_InsStr(PyCursesWindowObject
*self
, PyObject
*args
)
1001 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
1002 int use_xy
= FALSE
, use_attr
= FALSE
;
1004 switch (ARG_COUNT(args
)) {
1006 if (!PyArg_Parse(args
,"s;str", &str
))
1010 if (!PyArg_Parse(args
,"(sl);str,attr", &str
, &attr
))
1015 if (!PyArg_Parse(args
,"(iis);y,x,str", &y
, &x
, &str
))
1020 if (!PyArg_Parse(args
,"(iisl);y,x,str,attr", &y
, &x
, &str
, &attr
))
1022 use_xy
= use_attr
= TRUE
;
1025 PyErr_SetString(PyExc_TypeError
, "insstr requires 1 to 4 arguments");
1029 if (use_attr
== TRUE
) {
1030 attr_old
= getattrs(self
->win
);
1031 wattrset(self
->win
,attr
);
1034 rtn
= mvwinsstr(self
->win
,y
,x
,str
);
1036 rtn
= winsstr(self
->win
,str
);
1037 if (use_attr
== TRUE
)
1038 wattrset(self
->win
,attr_old
);
1039 return PyCursesCheckERR(rtn
, "insstr");
1043 PyCursesWindow_InsNStr(PyCursesWindowObject
*self
, PyObject
*args
)
1047 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
1048 int use_xy
= FALSE
, use_attr
= FALSE
;
1050 switch (ARG_COUNT(args
)) {
1052 if (!PyArg_Parse(args
,"(si);str,n", &str
, &n
))
1056 if (!PyArg_Parse(args
,"(sil);str,n,attr", &str
, &n
, &attr
))
1061 if (!PyArg_Parse(args
,"(iisi);y,x,str,n", &y
, &x
, &str
, &n
))
1066 if (!PyArg_Parse(args
,"(iisil);y,x,str,n,attr", &y
, &x
, &str
, &n
, &attr
))
1068 use_xy
= use_attr
= TRUE
;
1071 PyErr_SetString(PyExc_TypeError
, "insnstr requires 2 to 5 arguments");
1075 if (use_attr
== TRUE
) {
1076 attr_old
= getattrs(self
->win
);
1077 wattrset(self
->win
,attr
);
1080 rtn
= mvwinsnstr(self
->win
,y
,x
,str
,n
);
1082 rtn
= winsnstr(self
->win
,str
,n
);
1083 if (use_attr
== TRUE
)
1084 wattrset(self
->win
,attr_old
);
1085 return PyCursesCheckERR(rtn
, "insnstr");
1089 PyCursesWindow_Is_LineTouched(PyCursesWindowObject
*self
, PyObject
*args
)
1092 if (!PyArg_Parse(args
,"i;line", &line
))
1094 erg
= is_linetouched(self
->win
, line
);
1096 PyErr_SetString(PyExc_TypeError
,
1097 "is_linetouched: line number outside of boundaries");
1101 Py_INCREF(Py_False
);
1110 PyCursesWindow_NoOutRefresh(PyCursesWindowObject
*self
, PyObject
*args
)
1112 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1115 #ifndef WINDOW_HAS_FLAGS
1118 if (self
->win
->_flags
& _ISPAD
) {
1120 switch(ARG_COUNT(args
)) {
1122 if (!PyArg_Parse(args
,
1124 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1125 &pminrow
, &pmincol
, &sminrow
,
1126 &smincol
, &smaxrow
, &smaxcol
))
1128 Py_BEGIN_ALLOW_THREADS
1129 rtn
= pnoutrefresh(self
->win
,
1130 pminrow
, pmincol
, sminrow
,
1131 smincol
, smaxrow
, smaxcol
);
1132 Py_END_ALLOW_THREADS
1133 return PyCursesCheckERR(rtn
, "pnoutrefresh");
1135 PyErr_SetString(PyCursesError
,
1136 "noutrefresh() called for a pad "
1137 "requires 6 arguments");
1141 if (!PyArg_NoArgs(args
))
1144 Py_BEGIN_ALLOW_THREADS
1145 rtn
= wnoutrefresh(self
->win
);
1146 Py_END_ALLOW_THREADS
1147 return PyCursesCheckERR(rtn
, "wnoutrefresh");
1152 PyCursesWindow_Overlay(PyCursesWindowObject
*self
, PyObject
*args
)
1154 PyCursesWindowObject
*temp
;
1155 int use_copywin
= FALSE
;
1156 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1159 switch (ARG_COUNT(args
)) {
1161 if (!PyArg_ParseTuple(args
, "O!;window object",
1162 &PyCursesWindow_Type
, &temp
))
1166 if (!PyArg_ParseTuple(args
, "(O!iiiiii);window object, int, int, int, int, int, int",
1167 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1168 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1173 PyErr_SetString(PyExc_TypeError
,
1174 "overlay requires one or seven arguments");
1178 if (use_copywin
== TRUE
) {
1179 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1180 dminrow
, dmincol
, dmaxrow
, dmaxcol
, TRUE
);
1181 return PyCursesCheckERR(rtn
, "copywin");
1184 rtn
= overlay(self
->win
, temp
->win
);
1185 return PyCursesCheckERR(rtn
, "overlay");
1190 PyCursesWindow_Overwrite(PyCursesWindowObject
*self
, PyObject
*args
)
1192 PyCursesWindowObject
*temp
;
1193 int use_copywin
= FALSE
;
1194 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1197 switch (ARG_COUNT(args
)) {
1199 if (!PyArg_ParseTuple(args
, "O!;window object",
1200 &PyCursesWindow_Type
, &temp
))
1204 if (!PyArg_ParseTuple(args
, "(O!iiiiii);window object, int, int, int, int, int, int",
1205 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1206 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1211 PyErr_SetString(PyExc_TypeError
,
1212 "overwrite requires one or seven arguments");
1216 if (use_copywin
== TRUE
) {
1217 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1218 dminrow
, dmincol
, dmaxrow
, dmaxcol
, FALSE
);
1219 return PyCursesCheckERR(rtn
, "copywin");
1222 rtn
= overwrite(self
->win
, temp
->win
);
1223 return PyCursesCheckERR(rtn
, "overwrite");
1228 PyCursesWindow_PutWin(PyCursesWindowObject
*self
, PyObject
*args
)
1232 if (!PyArg_Parse(args
, "O;fileobj", &temp
))
1234 if (!PyFile_Check(temp
)) {
1235 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1238 return PyCursesCheckERR(putwin(self
->win
, PyFile_AsFile(temp
)),
1243 PyCursesWindow_RedrawLine(PyCursesWindowObject
*self
, PyObject
*args
)
1246 if (!PyArg_Parse(args
,"(ii);beg,num", &beg
, &num
))
1248 return PyCursesCheckERR(wredrawln(self
->win
,beg
,num
), "redrawln");
1252 PyCursesWindow_Refresh(PyCursesWindowObject
*self
, PyObject
*args
)
1254 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1257 #ifndef WINDOW_HAS_FLAGS
1260 if (self
->win
->_flags
& _ISPAD
) {
1262 switch(ARG_COUNT(args
)) {
1264 if (!PyArg_Parse(args
,
1266 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1267 &pminrow
, &pmincol
, &sminrow
,
1268 &smincol
, &smaxrow
, &smaxcol
))
1271 Py_BEGIN_ALLOW_THREADS
1272 rtn
= prefresh(self
->win
,
1273 pminrow
, pmincol
, sminrow
,
1274 smincol
, smaxrow
, smaxcol
);
1275 Py_END_ALLOW_THREADS
1276 return PyCursesCheckERR(rtn
, "prefresh");
1278 PyErr_SetString(PyCursesError
,
1279 "refresh() for a pad requires 6 arguments");
1283 if (!PyArg_NoArgs(args
))
1285 Py_BEGIN_ALLOW_THREADS
1286 rtn
= wrefresh(self
->win
);
1287 Py_END_ALLOW_THREADS
1288 return PyCursesCheckERR(rtn
, "prefresh");
1293 PyCursesWindow_SetScrollRegion(PyCursesWindowObject
*self
, PyObject
*args
)
1296 if (!PyArg_Parse(args
,"(ii);top, bottom",&y
,&x
))
1298 return PyCursesCheckERR(wsetscrreg(self
->win
,y
,x
), "wsetscrreg");
1302 PyCursesWindow_SubWin(PyCursesWindowObject
*self
, PyObject
*args
)
1305 int nlines
, ncols
, begin_y
, begin_x
;
1309 switch (ARG_COUNT(args
)) {
1311 if (!PyArg_Parse(args
,"(ii);begin_y,begin_x",&begin_y
,&begin_x
))
1315 if (!PyArg_Parse(args
, "(iiii);nlines,ncols,begin_y,begin_x",
1316 &nlines
,&ncols
,&begin_y
,&begin_x
))
1320 PyErr_SetString(PyExc_TypeError
, "subwin requires 2 or 4 arguments");
1324 /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
1325 #ifdef WINDOW_HAS_FLAGS
1326 if (self
->win
->_flags
& _ISPAD
)
1327 win
= subpad(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1330 win
= subwin(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1333 PyErr_SetString(PyCursesError
, catchall_NULL
);
1337 return (PyObject
*)PyCursesWindow_New(win
);
1341 PyCursesWindow_Scroll(PyCursesWindowObject
*self
, PyObject
*args
)
1344 switch(ARG_COUNT(args
)) {
1346 return PyCursesCheckERR(scroll(self
->win
), "scroll");
1348 if (!PyArg_Parse(args
, "i;nlines", &nlines
))
1350 return PyCursesCheckERR(wscrl(self
->win
, nlines
), "scroll");
1352 PyErr_SetString(PyExc_TypeError
, "scroll requires 0 or 1 arguments");
1358 PyCursesWindow_TouchLine(PyCursesWindowObject
*self
, PyObject
*args
)
1361 switch (ARG_COUNT(args
)) {
1363 if (!PyArg_Parse(args
,"(ii);start,count",&st
,&cnt
))
1365 return PyCursesCheckERR(touchline(self
->win
,st
,cnt
), "touchline");
1367 if (!PyArg_Parse(args
, "(iii);start,count,val", &st
, &cnt
, &val
))
1369 return PyCursesCheckERR(wtouchln(self
->win
, st
, cnt
, val
), "touchline");
1371 PyErr_SetString(PyExc_TypeError
, "touchline requires 2 or 3 arguments");
1377 PyCursesWindow_Vline(PyCursesWindowObject
*self
, PyObject
*args
)
1381 int n
, x
, y
, code
= OK
;
1382 attr_t attr
= A_NORMAL
;
1384 switch (ARG_COUNT(args
)) {
1386 if (!PyArg_Parse(args
, "(Oi);ch or int,n", &temp
, &n
))
1390 if (!PyArg_Parse(args
, "(Oil);ch or int,n,attr", &temp
, &n
, &attr
))
1394 if (!PyArg_Parse(args
, "(iiOi);y,x,ch or int,n", &y
, &x
, &temp
, &n
))
1396 code
= wmove(self
->win
, y
, x
);
1399 if (!PyArg_Parse(args
, "(iiOil); y,x,ch or int,n,attr",
1400 &y
, &x
, &temp
, &n
, &attr
))
1402 code
= wmove(self
->win
, y
, x
);
1405 PyErr_SetString(PyExc_TypeError
, "vline requires 2 to 5 arguments");
1410 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
1411 PyErr_SetString(PyExc_TypeError
,
1412 "argument 1 or 3 must be a ch or an int");
1415 return PyCursesCheckERR(wvline(self
->win
, ch
| attr
, n
), "vline");
1417 return PyCursesCheckERR(code
, "wmove");
1420 static PyMethodDef PyCursesWindow_Methods
[] = {
1421 {"addch", (PyCFunction
)PyCursesWindow_AddCh
},
1422 {"addnstr", (PyCFunction
)PyCursesWindow_AddNStr
},
1423 {"addstr", (PyCFunction
)PyCursesWindow_AddStr
},
1424 {"attroff", (PyCFunction
)PyCursesWindow_wattroff
},
1425 {"attron", (PyCFunction
)PyCursesWindow_wattron
},
1426 {"attrset", (PyCFunction
)PyCursesWindow_wattrset
},
1427 {"bkgd", (PyCFunction
)PyCursesWindow_Bkgd
},
1428 {"bkgdset", (PyCFunction
)PyCursesWindow_BkgdSet
},
1429 {"border", (PyCFunction
)PyCursesWindow_Border
, METH_VARARGS
},
1430 {"box", (PyCFunction
)PyCursesWindow_Box
},
1431 {"clear", (PyCFunction
)PyCursesWindow_wclear
},
1432 {"clearok", (PyCFunction
)PyCursesWindow_clearok
},
1433 {"clrtobot", (PyCFunction
)PyCursesWindow_wclrtobot
},
1434 {"clrtoeol", (PyCFunction
)PyCursesWindow_wclrtoeol
},
1435 {"cursyncup", (PyCFunction
)PyCursesWindow_wcursyncup
},
1436 {"delch", (PyCFunction
)PyCursesWindow_DelCh
},
1437 {"deleteln", (PyCFunction
)PyCursesWindow_wdeleteln
},
1438 {"derwin", (PyCFunction
)PyCursesWindow_DerWin
},
1439 {"echochar", (PyCFunction
)PyCursesWindow_EchoChar
},
1440 #ifdef NCURSES_MOUSE_VERSION
1441 {"enclose", (PyCFunction
)PyCursesWindow_Enclose
},
1443 {"erase", (PyCFunction
)PyCursesWindow_werase
},
1444 {"getbegyx", (PyCFunction
)PyCursesWindow_getbegyx
},
1445 {"getbkgd", (PyCFunction
)PyCursesWindow_GetBkgd
},
1446 {"getch", (PyCFunction
)PyCursesWindow_GetCh
},
1447 {"getkey", (PyCFunction
)PyCursesWindow_GetKey
},
1448 {"getmaxyx", (PyCFunction
)PyCursesWindow_getmaxyx
},
1449 {"getparyx", (PyCFunction
)PyCursesWindow_getparyx
},
1450 {"getstr", (PyCFunction
)PyCursesWindow_GetStr
},
1451 {"getyx", (PyCFunction
)PyCursesWindow_getyx
},
1452 {"hline", (PyCFunction
)PyCursesWindow_Hline
},
1453 {"idcok", (PyCFunction
)PyCursesWindow_idcok
},
1454 {"idlok", (PyCFunction
)PyCursesWindow_idlok
},
1455 {"immedok", (PyCFunction
)PyCursesWindow_immedok
},
1456 {"inch", (PyCFunction
)PyCursesWindow_InCh
},
1457 {"insch", (PyCFunction
)PyCursesWindow_InsCh
},
1458 {"insdelln", (PyCFunction
)PyCursesWindow_winsdelln
},
1459 {"insertln", (PyCFunction
)PyCursesWindow_winsertln
},
1460 {"insnstr", (PyCFunction
)PyCursesWindow_InsNStr
},
1461 {"insstr", (PyCFunction
)PyCursesWindow_InsStr
},
1462 {"instr", (PyCFunction
)PyCursesWindow_InStr
},
1463 {"is_linetouched", (PyCFunction
)PyCursesWindow_Is_LineTouched
},
1464 {"is_wintouched", (PyCFunction
)PyCursesWindow_is_wintouched
},
1465 {"keypad", (PyCFunction
)PyCursesWindow_keypad
},
1466 {"leaveok", (PyCFunction
)PyCursesWindow_leaveok
},
1467 {"move", (PyCFunction
)PyCursesWindow_wmove
},
1468 {"mvderwin", (PyCFunction
)PyCursesWindow_mvderwin
},
1469 {"mvwin", (PyCFunction
)PyCursesWindow_mvwin
},
1470 {"nodelay", (PyCFunction
)PyCursesWindow_nodelay
},
1471 {"notimeout", (PyCFunction
)PyCursesWindow_notimeout
},
1472 {"noutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
},
1473 /* Backward compatibility alias -- remove in Python 2.1 */
1474 {"nooutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
},
1475 {"overlay", (PyCFunction
)PyCursesWindow_Overlay
, METH_VARARGS
},
1476 {"overwrite", (PyCFunction
)PyCursesWindow_Overwrite
,
1478 {"putwin", (PyCFunction
)PyCursesWindow_PutWin
},
1479 {"redrawln", (PyCFunction
)PyCursesWindow_RedrawLine
},
1480 {"redrawwin", (PyCFunction
)PyCursesWindow_redrawwin
},
1481 {"refresh", (PyCFunction
)PyCursesWindow_Refresh
},
1482 #ifndef STRICT_SYSV_CURSES
1483 {"resize", (PyCFunction
)PyCursesWindow_wresize
},
1485 {"scroll", (PyCFunction
)PyCursesWindow_Scroll
},
1486 {"scrollok", (PyCFunction
)PyCursesWindow_scrollok
},
1487 {"setscrreg", (PyCFunction
)PyCursesWindow_SetScrollRegion
},
1488 {"standend", (PyCFunction
)PyCursesWindow_wstandend
},
1489 {"standout", (PyCFunction
)PyCursesWindow_wstandout
},
1490 {"subpad", (PyCFunction
)PyCursesWindow_SubWin
},
1491 {"subwin", (PyCFunction
)PyCursesWindow_SubWin
},
1492 {"syncdown", (PyCFunction
)PyCursesWindow_wsyncdown
},
1493 {"syncok", (PyCFunction
)PyCursesWindow_syncok
},
1494 {"syncup", (PyCFunction
)PyCursesWindow_wsyncup
},
1495 {"timeout", (PyCFunction
)PyCursesWindow_wtimeout
},
1496 {"touchline", (PyCFunction
)PyCursesWindow_TouchLine
},
1497 {"touchwin", (PyCFunction
)PyCursesWindow_touchwin
},
1498 {"untouchwin", (PyCFunction
)PyCursesWindow_untouchwin
},
1499 {"vline", (PyCFunction
)PyCursesWindow_Vline
},
1500 {NULL
, NULL
} /* sentinel */
1504 PyCursesWindow_GetAttr(PyCursesWindowObject
*self
, char *name
)
1506 return Py_FindMethod(PyCursesWindow_Methods
, (PyObject
*)self
, name
);
1509 /* -------------------------------------------------------*/
1511 PyTypeObject PyCursesWindow_Type
= {
1512 PyObject_HEAD_INIT(NULL
)
1514 "_curses.curses window", /*tp_name*/
1515 sizeof(PyCursesWindowObject
), /*tp_basicsize*/
1518 (destructor
)PyCursesWindow_Dealloc
, /*tp_dealloc*/
1520 (getattrfunc
)PyCursesWindow_GetAttr
, /*tp_getattr*/
1521 (setattrfunc
)0, /*tp_setattr*/
1525 0, /*tp_as_sequence*/
1526 0, /*tp_as_mapping*/
1530 /*********************************************************************
1532 **********************************************************************/
1534 NoArgNoReturnFunction(beep
)
1535 NoArgNoReturnFunction(def_prog_mode
)
1536 NoArgNoReturnFunction(def_shell_mode
)
1537 NoArgNoReturnFunction(doupdate
)
1538 NoArgNoReturnFunction(endwin
)
1539 NoArgNoReturnFunction(flash
)
1540 NoArgNoReturnFunction(nocbreak
)
1541 NoArgNoReturnFunction(noecho
)
1542 NoArgNoReturnFunction(nonl
)
1543 NoArgNoReturnFunction(noraw
)
1544 NoArgNoReturnFunction(reset_prog_mode
)
1545 NoArgNoReturnFunction(reset_shell_mode
)
1546 NoArgNoReturnFunction(resetty
)
1547 NoArgNoReturnFunction(savetty
)
1549 NoArgOrFlagNoReturnFunction(cbreak
)
1550 NoArgOrFlagNoReturnFunction(echo
)
1551 NoArgOrFlagNoReturnFunction(nl
)
1552 NoArgOrFlagNoReturnFunction(raw
)
1554 NoArgReturnIntFunction(baudrate
)
1555 NoArgReturnIntFunction(termattrs
)
1557 NoArgReturnStringFunction(termname
)
1558 NoArgReturnStringFunction(longname
)
1560 NoArgTrueFalseFunction(can_change_color
)
1561 NoArgTrueFalseFunction(has_colors
)
1562 NoArgTrueFalseFunction(has_ic
)
1563 NoArgTrueFalseFunction(has_il
)
1564 NoArgTrueFalseFunction(isendwin
)
1565 NoArgNoReturnVoidFunction(filter
)
1566 NoArgNoReturnVoidFunction(flushinp
)
1567 NoArgNoReturnVoidFunction(noqiflush
)
1570 PyCurses_Color_Content(PyObject
*self
, PyObject
*args
)
1575 PyCursesInitialisedColor
1577 if (ARG_COUNT(args
) != 1) {
1578 PyErr_SetString(PyExc_TypeError
,
1579 "color_content requires 1 argument");
1583 if (!PyArg_Parse(args
, "h;color", &color
)) return NULL
;
1585 if (color_content(color
, &r
, &g
, &b
) != ERR
)
1586 return Py_BuildValue("(iii)", r
, g
, b
);
1588 PyErr_SetString(PyCursesError
,
1589 "Argument 1 was out of range. Check value of COLORS.");
1595 PyCurses_color_pair(PyObject
*self
, PyObject
*args
)
1600 PyCursesInitialisedColor
1602 if (ARG_COUNT(args
) != 1) {
1603 PyErr_SetString(PyExc_TypeError
, "color_pair requires 1 argument");
1606 if (!PyArg_Parse(args
, "i;number", &n
)) return NULL
;
1607 return PyInt_FromLong((long) (n
<< 8));
1611 PyCurses_Curs_Set(PyObject
*self
, PyObject
*args
)
1617 if (ARG_COUNT(args
)!=1) {
1618 PyErr_SetString(PyExc_TypeError
, "curs_set requires 1 argument");
1622 if (!PyArg_Parse(args
, "i;int", &vis
)) return NULL
;
1624 erg
= curs_set(vis
);
1625 if (erg
== ERR
) return PyCursesCheckERR(erg
, "curs_set");
1627 return PyInt_FromLong((long) erg
);
1631 PyCurses_Delay_Output(PyObject
*self
, PyObject
*args
)
1637 if (ARG_COUNT(args
) != 1) {
1638 PyErr_SetString(PyExc_TypeError
, "delay_output requires 1 argument");
1641 if (!PyArg_Parse(args
, "i;ms", &ms
)) return NULL
;
1643 return PyCursesCheckERR(delay_output(ms
), "delay_output");
1647 PyCurses_EraseChar(PyObject
*self
, PyObject
*args
)
1653 if (!PyArg_NoArgs(args
)) return NULL
;
1657 return PyString_FromStringAndSize(&ch
, 1);
1661 PyCurses_getsyx(PyObject
*self
, PyObject
*args
)
1667 if (!PyArg_NoArgs(args
)) return NULL
;
1671 return Py_BuildValue("(ii)", y
, x
);
1674 #ifdef NCURSES_MOUSE_VERSION
1676 PyCurses_GetMouse(PyObject
*self
, PyObject
*args
)
1682 if (!PyArg_NoArgs(args
)) return NULL
;
1684 rtn
= getmouse( &event
);
1686 PyErr_SetString(PyCursesError
, "getmouse() returned ERR");
1689 return Py_BuildValue("(hiiil)",
1691 event
.x
, event
.y
, event
.z
,
1692 (long) event
.bstate
);
1696 PyCurses_UngetMouse(PyObject
*self
, PyObject
*args
)
1701 if (!PyArg_ParseTuple(args
, "(hiiil)",
1703 &event
.x
, &event
.y
, &event
.z
,
1704 (int *) &event
.bstate
))
1707 return PyCursesCheckERR(ungetmouse(&event
), "ungetmouse");
1712 PyCurses_GetWin(PyCursesWindowObject
*self
, PyObject
*args
)
1719 if (!PyArg_Parse(args
, "O;fileobj", &temp
)) return NULL
;
1721 if (!PyFile_Check(temp
)) {
1722 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1726 win
= getwin(PyFile_AsFile(temp
));
1729 PyErr_SetString(PyCursesError
, catchall_NULL
);
1733 return PyCursesWindow_New(win
);
1737 PyCurses_HalfDelay(PyObject
*self
, PyObject
*args
)
1739 unsigned char tenths
;
1743 switch(ARG_COUNT(args
)) {
1745 if (!PyArg_Parse(args
, "b;tenths", &tenths
)) return NULL
;
1748 PyErr_SetString(PyExc_TypeError
, "halfdelay requires 1 argument");
1752 return PyCursesCheckERR(halfdelay(tenths
), "halfdelay");
1755 #ifndef STRICT_SYSV_CURSES
1757 static PyObject
* PyCurses_has_key(PyObject
*self
, PyObject
*args
)
1763 if (!PyArg_Parse(args
,"i",&ch
)) return NULL
;
1765 if (has_key(ch
) == FALSE
) {
1766 Py_INCREF(Py_False
);
1772 #endif /* STRICT_SYSV_CURSES */
1775 PyCurses_Init_Color(PyObject
*self
, PyObject
*args
)
1777 short color
, r
, g
, b
;
1780 PyCursesInitialisedColor
1782 switch(ARG_COUNT(args
)) {
1784 if (!PyArg_Parse(args
, "(hhhh);color,r,g,b", &color
, &r
, &g
, &b
)) return NULL
;
1787 PyErr_SetString(PyExc_TypeError
, "init_color requires 4 arguments");
1791 return PyCursesCheckERR(init_color(color
, r
, g
, b
), "init_color");
1795 PyCurses_Init_Pair(PyObject
*self
, PyObject
*args
)
1800 PyCursesInitialisedColor
1802 if (ARG_COUNT(args
) != 3) {
1803 PyErr_SetString(PyExc_TypeError
, "init_pair requires 3 arguments");
1807 if (!PyArg_Parse(args
, "(hhh);pair, f, b", &pair
, &f
, &b
)) return NULL
;
1809 return PyCursesCheckERR(init_pair(pair
, f
, b
), "init_pair");
1812 static PyObject
*ModDict
;
1815 PyCurses_InitScr(PyObject
*self
, PyObject
*args
)
1818 PyObject
*nlines
, *cols
;
1820 if (!PyArg_NoArgs(args
)) return NULL
;
1822 if (initialised
== TRUE
) {
1824 return (PyObject
*)PyCursesWindow_New(stdscr
);
1830 PyErr_SetString(PyCursesError
, catchall_NULL
);
1834 initialised
= initialised_setupterm
= TRUE
;
1836 /* This was moved from initcurses() because it core dumped on SGI,
1837 where they're not defined until you've called initscr() */
1838 #define SetDictInt(string,ch) \
1839 PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
1841 /* Here are some graphic symbols you can use */
1842 SetDictInt("ACS_ULCORNER", (ACS_ULCORNER
));
1843 SetDictInt("ACS_LLCORNER", (ACS_LLCORNER
));
1844 SetDictInt("ACS_URCORNER", (ACS_URCORNER
));
1845 SetDictInt("ACS_LRCORNER", (ACS_LRCORNER
));
1846 SetDictInt("ACS_LTEE", (ACS_LTEE
));
1847 SetDictInt("ACS_RTEE", (ACS_RTEE
));
1848 SetDictInt("ACS_BTEE", (ACS_BTEE
));
1849 SetDictInt("ACS_TTEE", (ACS_TTEE
));
1850 SetDictInt("ACS_HLINE", (ACS_HLINE
));
1851 SetDictInt("ACS_VLINE", (ACS_VLINE
));
1852 SetDictInt("ACS_PLUS", (ACS_PLUS
));
1853 #if !defined(__hpux) || defined(HAVE_NCURSES_H)
1854 /* On HP/UX 11, these are of type cchar_t, which is not an
1855 integral type. If this is a problem on more platforms, a
1856 configure test should be added to determine whether ACS_S1
1857 is of integral type. */
1858 SetDictInt("ACS_S1", (ACS_S1
));
1859 SetDictInt("ACS_S9", (ACS_S9
));
1860 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND
));
1861 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD
));
1862 SetDictInt("ACS_DEGREE", (ACS_DEGREE
));
1863 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS
));
1864 SetDictInt("ACS_BULLET", (ACS_BULLET
));
1865 SetDictInt("ACS_LARROW", (ACS_LARROW
));
1866 SetDictInt("ACS_RARROW", (ACS_RARROW
));
1867 SetDictInt("ACS_DARROW", (ACS_DARROW
));
1868 SetDictInt("ACS_UARROW", (ACS_UARROW
));
1869 SetDictInt("ACS_BOARD", (ACS_BOARD
));
1870 SetDictInt("ACS_LANTERN", (ACS_LANTERN
));
1871 SetDictInt("ACS_BLOCK", (ACS_BLOCK
));
1873 SetDictInt("ACS_BSSB", (ACS_ULCORNER
));
1874 SetDictInt("ACS_SSBB", (ACS_LLCORNER
));
1875 SetDictInt("ACS_BBSS", (ACS_URCORNER
));
1876 SetDictInt("ACS_SBBS", (ACS_LRCORNER
));
1877 SetDictInt("ACS_SBSS", (ACS_RTEE
));
1878 SetDictInt("ACS_SSSB", (ACS_LTEE
));
1879 SetDictInt("ACS_SSBS", (ACS_BTEE
));
1880 SetDictInt("ACS_BSSS", (ACS_TTEE
));
1881 SetDictInt("ACS_BSBS", (ACS_HLINE
));
1882 SetDictInt("ACS_SBSB", (ACS_VLINE
));
1883 SetDictInt("ACS_SSSS", (ACS_PLUS
));
1885 /* The following are never available with strict SYSV curses */
1887 SetDictInt("ACS_S3", (ACS_S3
));
1890 SetDictInt("ACS_S7", (ACS_S7
));
1893 SetDictInt("ACS_LEQUAL", (ACS_LEQUAL
));
1896 SetDictInt("ACS_GEQUAL", (ACS_GEQUAL
));
1899 SetDictInt("ACS_PI", (ACS_PI
));
1902 SetDictInt("ACS_NEQUAL", (ACS_NEQUAL
));
1905 SetDictInt("ACS_STERLING", (ACS_STERLING
));
1908 nlines
= PyInt_FromLong((long) LINES
);
1909 PyDict_SetItemString(ModDict
, "LINES", nlines
);
1911 cols
= PyInt_FromLong((long) COLS
);
1912 PyDict_SetItemString(ModDict
, "COLS", cols
);
1915 return (PyObject
*)PyCursesWindow_New(win
);
1919 PyCurses_setupterm(PyObject
* self
, PyObject
*args
, PyObject
* keywds
)
1923 char* termstr
= NULL
;
1925 static char *kwlist
[] = {"term", "fd", NULL
};
1927 if (!PyArg_ParseTupleAndKeywords(
1928 args
,keywds
,"|zi:setupterm",kwlist
,&termstr
,&fd
)) {
1933 PyObject
* sys_stdout
;
1935 sys_stdout
= PySys_GetObject("stdout");
1937 if (sys_stdout
== NULL
) {
1944 fd
= PyObject_AsFileDescriptor(sys_stdout
);
1951 if (setupterm(termstr
,fd
,&err
) == ERR
) {
1952 char* s
= "setupterm: unknown error";
1955 s
= "setupterm: could not find terminal";
1956 } else if (err
== -1) {
1957 s
= "setupterm: could not find terminfo database";
1960 PyErr_SetString(PyCursesError
,s
);
1964 initialised_setupterm
= TRUE
;
1971 PyCurses_IntrFlush(PyObject
*self
, PyObject
*args
)
1977 switch(ARG_COUNT(args
)) {
1979 if (!PyArg_Parse(args
,"i;True(1), False(0)",&ch
)) return NULL
;
1982 PyErr_SetString(PyExc_TypeError
, "intrflush requires 1 argument");
1986 return PyCursesCheckERR(intrflush(NULL
,ch
), "intrflush");
1989 #if !defined(__NetBSD__)
1991 PyCurses_KeyName(PyObject
*self
, PyObject
*args
)
1998 if (!PyArg_Parse(args
,"i",&ch
)) return NULL
;
2002 return PyString_FromString((knp
== NULL
) ? "" : (char *)knp
);
2007 PyCurses_KillChar(PyObject
*self
, PyObject
*args
)
2011 if (!PyArg_NoArgs(args
)) return NULL
;
2015 return PyString_FromStringAndSize(&ch
, 1);
2019 PyCurses_Meta(PyObject
*self
, PyObject
*args
)
2025 switch(ARG_COUNT(args
)) {
2027 if (!PyArg_Parse(args
,"i;True(1), False(0)",&ch
)) return NULL
;
2030 PyErr_SetString(PyExc_TypeError
, "meta requires 1 argument");
2034 return PyCursesCheckERR(meta(stdscr
, ch
), "meta");
2037 #ifdef NCURSES_MOUSE_VERSION
2039 PyCurses_MouseInterval(PyObject
*self
, PyObject
*args
)
2044 if (!PyArg_Parse(args
,"i;interval",&interval
))
2046 return PyCursesCheckERR(mouseinterval(interval
), "mouseinterval");
2050 PyCurses_MouseMask(PyObject
*self
, PyObject
*args
)
2053 mmask_t oldmask
, availmask
;
2056 if (!PyArg_Parse(args
,"i;mousemask",&newmask
))
2058 availmask
= mousemask(newmask
, &oldmask
);
2059 return Py_BuildValue("(ll)", (long)availmask
, (long)oldmask
);
2064 PyCurses_Napms(PyObject
*self
, PyObject
*args
)
2069 if (!PyArg_Parse(args
, "i;ms", &ms
)) return NULL
;
2071 return Py_BuildValue("i", napms(ms
));
2076 PyCurses_NewPad(PyObject
*self
, PyObject
*args
)
2083 if (!PyArg_Parse(args
,"(ii);nlines,ncols",&nlines
,&ncols
)) return NULL
;
2085 win
= newpad(nlines
, ncols
);
2088 PyErr_SetString(PyCursesError
, catchall_NULL
);
2092 return (PyObject
*)PyCursesWindow_New(win
);
2096 PyCurses_NewWindow(PyObject
*self
, PyObject
*args
)
2099 int nlines
, ncols
, begin_y
=0, begin_x
=0;
2103 switch (ARG_COUNT(args
)) {
2105 if (!PyArg_Parse(args
,"(ii);nlines,ncols",&nlines
,&ncols
))
2109 if (!PyArg_Parse(args
, "(iiii);nlines,ncols,begin_y,begin_x",
2110 &nlines
,&ncols
,&begin_y
,&begin_x
))
2114 PyErr_SetString(PyExc_TypeError
, "newwin requires 2 or 4 arguments");
2118 win
= newwin(nlines
,ncols
,begin_y
,begin_x
);
2120 PyErr_SetString(PyCursesError
, catchall_NULL
);
2124 return (PyObject
*)PyCursesWindow_New(win
);
2128 PyCurses_Pair_Content(PyObject
*self
, PyObject
*args
)
2133 PyCursesInitialisedColor
2135 switch(ARG_COUNT(args
)) {
2137 if (!PyArg_Parse(args
, "h;pair", &pair
)) return NULL
;
2140 PyErr_SetString(PyExc_TypeError
, "pair_content requires 1 argument");
2144 if (!pair_content(pair
, &f
, &b
)) {
2145 PyErr_SetString(PyCursesError
,
2146 "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
2150 return Py_BuildValue("(ii)", f
, b
);
2154 PyCurses_pair_number(PyObject
*self
, PyObject
*args
)
2159 PyCursesInitialisedColor
2161 switch(ARG_COUNT(args
)) {
2163 if (!PyArg_Parse(args
, "i;pairvalue", &n
)) return NULL
;
2166 PyErr_SetString(PyExc_TypeError
,
2167 "pair_number requires 1 argument");
2171 return PyInt_FromLong((long) ((n
& A_COLOR
) >> 8));
2175 PyCurses_Putp(PyObject
*self
, PyObject
*args
)
2179 if (!PyArg_Parse(args
,"s;str", &str
)) return NULL
;
2180 return PyCursesCheckERR(putp(str
), "putp");
2184 PyCurses_QiFlush(PyObject
*self
, PyObject
*args
)
2190 switch(ARG_COUNT(args
)) {
2196 if (!PyArg_Parse(args
, "i;True(1) or False(0)", &flag
)) return NULL
;
2197 if (flag
) qiflush();
2202 PyErr_SetString(PyExc_TypeError
, "qiflush requires 0 or 1 arguments");
2208 PyCurses_setsyx(PyObject
*self
, PyObject
*args
)
2214 if (ARG_COUNT(args
)!=2) {
2215 PyErr_SetString(PyExc_TypeError
, "setsyx requires 2 arguments");
2219 if (!PyArg_Parse(args
, "(ii);y, x", &y
, &x
)) return NULL
;
2228 PyCurses_Start_Color(PyObject
*self
, PyObject
*args
)
2235 if (!PyArg_NoArgs(args
)) return NULL
;
2237 code
= start_color();
2239 initialisedcolors
= TRUE
;
2240 c
= PyInt_FromLong((long) COLORS
);
2241 PyDict_SetItemString(ModDict
, "COLORS", c
);
2243 cp
= PyInt_FromLong((long) COLOR_PAIRS
);
2244 PyDict_SetItemString(ModDict
, "COLOR_PAIRS", cp
);
2249 PyErr_SetString(PyCursesError
, "start_color() returned ERR");
2255 PyCurses_tigetflag(PyObject
*self
, PyObject
*args
)
2259 PyCursesSetupTermCalled
;
2261 if (!PyArg_ParseTuple(args
, "z", &capname
))
2264 return PyInt_FromLong( (long) tigetflag( capname
) );
2268 PyCurses_tigetnum(PyObject
*self
, PyObject
*args
)
2272 PyCursesSetupTermCalled
;
2274 if (!PyArg_ParseTuple(args
, "z", &capname
))
2277 return PyInt_FromLong( (long) tigetnum( capname
) );
2281 PyCurses_tigetstr(PyObject
*self
, PyObject
*args
)
2285 PyCursesSetupTermCalled
;
2287 if (!PyArg_ParseTuple(args
, "z", &capname
))
2290 capname
= tigetstr( capname
);
2291 if (capname
== 0 || capname
== (char*) -1) {
2295 return PyString_FromString( capname
);
2299 PyCurses_tparm(PyObject
*self
, PyObject
*args
)
2302 char* result
= NULL
;
2303 int i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
,i9
;
2305 PyCursesSetupTermCalled
;
2307 if (!PyArg_ParseTuple(args
, "s|iiiiiiiii:tparm",
2308 &fmt
, &i1
, &i2
, &i3
, &i4
,
2309 &i5
, &i6
, &i7
, &i8
, &i9
)) {
2313 #if defined(__hpux) || defined(_AIX)
2314 /* tparm is declared with 10 arguments on a few platforms
2315 (HP-UX, AIX). If this proves to be a problem on other
2316 platforms as well, perhaps an autoconf test should be
2317 added to determine whether tparm can be called with a
2318 variable number of arguments. Perhaps the other arguments
2319 should be initialized in this case also. */
2320 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
,i9
);
2322 switch (PyTuple_GET_SIZE(args
)) {
2324 result
= tparm(fmt
);
2327 result
= tparm(fmt
,i1
);
2330 result
= tparm(fmt
,i1
,i2
);
2333 result
= tparm(fmt
,i1
,i2
,i3
);
2336 result
= tparm(fmt
,i1
,i2
,i3
,i4
);
2339 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
);
2342 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
);
2345 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
);
2348 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
);
2351 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
,i9
);
2354 #endif /* defined(__hpux) || defined(_AIX) */
2355 return PyString_FromString(result
);
2359 PyCurses_TypeAhead(PyObject
*self
, PyObject
*args
)
2365 if (!PyArg_Parse(args
,"i;fd",&fd
)) return NULL
;
2367 PyCursesCheckERR(typeahead( fd
), "typeahead");
2373 PyCurses_UnCtrl(PyObject
*self
, PyObject
*args
)
2380 if (!PyArg_Parse(args
,"O;ch or int",&temp
)) return NULL
;
2382 if (PyInt_Check(temp
))
2383 ch
= (chtype
) PyInt_AsLong(temp
);
2384 else if (PyString_Check(temp
))
2385 ch
= (chtype
) *PyString_AsString(temp
);
2387 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2391 return PyString_FromString(unctrl(ch
));
2395 PyCurses_UngetCh(PyObject
*self
, PyObject
*args
)
2402 if (!PyArg_Parse(args
,"O;ch or int",&temp
)) return NULL
;
2404 if (PyInt_Check(temp
))
2405 ch
= (chtype
) PyInt_AsLong(temp
);
2406 else if (PyString_Check(temp
))
2407 ch
= (chtype
) *PyString_AsString(temp
);
2409 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2413 return PyCursesCheckERR(ungetch(ch
), "ungetch");
2417 PyCurses_Use_Env(PyObject
*self
, PyObject
*args
)
2423 switch(ARG_COUNT(args
)) {
2425 if (!PyArg_Parse(args
,"i;True(1), False(0)",&flag
))
2429 PyErr_SetString(PyExc_TypeError
, "use_env requires 1 argument");
2437 /* List of functions defined in the module */
2439 static PyMethodDef PyCurses_methods
[] = {
2440 {"baudrate", (PyCFunction
)PyCurses_baudrate
},
2441 {"beep", (PyCFunction
)PyCurses_beep
},
2442 {"can_change_color", (PyCFunction
)PyCurses_can_change_color
},
2443 {"cbreak", (PyCFunction
)PyCurses_cbreak
},
2444 {"color_content", (PyCFunction
)PyCurses_Color_Content
},
2445 {"color_pair", (PyCFunction
)PyCurses_color_pair
},
2446 {"curs_set", (PyCFunction
)PyCurses_Curs_Set
},
2447 {"def_prog_mode", (PyCFunction
)PyCurses_def_prog_mode
},
2448 {"def_shell_mode", (PyCFunction
)PyCurses_def_shell_mode
},
2449 {"delay_output", (PyCFunction
)PyCurses_Delay_Output
},
2450 {"doupdate", (PyCFunction
)PyCurses_doupdate
},
2451 {"echo", (PyCFunction
)PyCurses_echo
},
2452 {"endwin", (PyCFunction
)PyCurses_endwin
},
2453 {"erasechar", (PyCFunction
)PyCurses_EraseChar
},
2454 {"filter", (PyCFunction
)PyCurses_filter
},
2455 {"flash", (PyCFunction
)PyCurses_flash
},
2456 {"flushinp", (PyCFunction
)PyCurses_flushinp
},
2457 #ifdef NCURSES_MOUSE_VERSION
2458 {"getmouse", (PyCFunction
)PyCurses_GetMouse
},
2459 {"ungetmouse", (PyCFunction
)PyCurses_UngetMouse
, METH_VARARGS
},
2461 {"getsyx", (PyCFunction
)PyCurses_getsyx
},
2462 {"getwin", (PyCFunction
)PyCurses_GetWin
},
2463 {"has_colors", (PyCFunction
)PyCurses_has_colors
},
2464 {"has_ic", (PyCFunction
)PyCurses_has_ic
},
2465 {"has_il", (PyCFunction
)PyCurses_has_il
},
2466 #ifndef STRICT_SYSV_CURSES
2467 {"has_key", (PyCFunction
)PyCurses_has_key
},
2469 {"halfdelay", (PyCFunction
)PyCurses_HalfDelay
},
2470 {"init_color", (PyCFunction
)PyCurses_Init_Color
},
2471 {"init_pair", (PyCFunction
)PyCurses_Init_Pair
},
2472 {"initscr", (PyCFunction
)PyCurses_InitScr
},
2473 {"intrflush", (PyCFunction
)PyCurses_IntrFlush
},
2474 {"isendwin", (PyCFunction
)PyCurses_isendwin
},
2475 #if !defined(__NetBSD__)
2476 {"keyname", (PyCFunction
)PyCurses_KeyName
},
2478 {"killchar", (PyCFunction
)PyCurses_KillChar
},
2479 {"longname", (PyCFunction
)PyCurses_longname
},
2480 {"meta", (PyCFunction
)PyCurses_Meta
},
2481 #ifdef NCURSES_MOUSE_VERSION
2482 {"mouseinterval", (PyCFunction
)PyCurses_MouseInterval
},
2483 {"mousemask", (PyCFunction
)PyCurses_MouseMask
},
2485 {"napms", (PyCFunction
)PyCurses_Napms
},
2486 {"newpad", (PyCFunction
)PyCurses_NewPad
},
2487 {"newwin", (PyCFunction
)PyCurses_NewWindow
},
2488 {"nl", (PyCFunction
)PyCurses_nl
},
2489 {"nocbreak", (PyCFunction
)PyCurses_nocbreak
},
2490 {"noecho", (PyCFunction
)PyCurses_noecho
},
2491 {"nonl", (PyCFunction
)PyCurses_nonl
},
2492 {"noqiflush", (PyCFunction
)PyCurses_noqiflush
},
2493 {"noraw", (PyCFunction
)PyCurses_noraw
},
2494 {"pair_content", (PyCFunction
)PyCurses_Pair_Content
},
2495 {"pair_number", (PyCFunction
)PyCurses_pair_number
},
2496 {"putp", (PyCFunction
)PyCurses_Putp
},
2497 {"qiflush", (PyCFunction
)PyCurses_QiFlush
},
2498 {"raw", (PyCFunction
)PyCurses_raw
},
2499 {"reset_prog_mode", (PyCFunction
)PyCurses_reset_prog_mode
},
2500 {"reset_shell_mode", (PyCFunction
)PyCurses_reset_shell_mode
},
2501 {"resetty", (PyCFunction
)PyCurses_resetty
},
2502 {"savetty", (PyCFunction
)PyCurses_savetty
},
2503 {"setsyx", (PyCFunction
)PyCurses_setsyx
},
2504 {"setupterm", (PyCFunction
)PyCurses_setupterm
,
2505 METH_VARARGS
|METH_KEYWORDS
},
2506 {"start_color", (PyCFunction
)PyCurses_Start_Color
},
2507 {"termattrs", (PyCFunction
)PyCurses_termattrs
},
2508 {"termname", (PyCFunction
)PyCurses_termname
},
2509 {"tigetflag", (PyCFunction
)PyCurses_tigetflag
, METH_VARARGS
},
2510 {"tigetnum", (PyCFunction
)PyCurses_tigetnum
, METH_VARARGS
},
2511 {"tigetstr", (PyCFunction
)PyCurses_tigetstr
, METH_VARARGS
},
2512 {"tparm", (PyCFunction
)PyCurses_tparm
, METH_VARARGS
},
2513 {"typeahead", (PyCFunction
)PyCurses_TypeAhead
},
2514 {"unctrl", (PyCFunction
)PyCurses_UnCtrl
},
2515 {"ungetch", (PyCFunction
)PyCurses_UngetCh
},
2516 {"use_env", (PyCFunction
)PyCurses_Use_Env
},
2517 {NULL
, NULL
} /* sentinel */
2520 /* Initialization function for the module */
2525 PyObject
*m
, *d
, *v
, *c_api_object
;
2526 static void *PyCurses_API
[PyCurses_API_pointers
];
2528 /* Initialize object type */
2529 PyCursesWindow_Type
.ob_type
= &PyType_Type
;
2531 /* Initialize the C API pointer array */
2532 PyCurses_API
[0] = (void *)&PyCursesWindow_Type
;
2533 PyCurses_API
[1] = (void *)func_PyCursesSetupTermCalled
;
2534 PyCurses_API
[2] = (void *)func_PyCursesInitialised
;
2535 PyCurses_API
[3] = (void *)func_PyCursesInitialisedColor
;
2537 /* Create the module and add the functions */
2538 m
= Py_InitModule("_curses", PyCurses_methods
);
2540 /* Add some symbolic constants to the module */
2541 d
= PyModule_GetDict(m
);
2542 ModDict
= d
; /* For PyCurses_InitScr to use later */
2544 /* Add a CObject for the C API */
2545 c_api_object
= PyCObject_FromVoidPtr((void *)PyCurses_API
, NULL
);
2546 PyDict_SetItemString(d
, "_C_API", c_api_object
);
2547 Py_DECREF(c_api_object
);
2549 /* For exception curses.error */
2550 PyCursesError
= PyErr_NewException("_curses.error", NULL
, NULL
);
2551 PyDict_SetItemString(d
, "error", PyCursesError
);
2553 /* Make the version available */
2554 v
= PyString_FromString(PyCursesVersion
);
2555 PyDict_SetItemString(d
, "version", v
);
2556 PyDict_SetItemString(d
, "__version__", v
);
2559 SetDictInt("ERR", ERR
);
2560 SetDictInt("OK", OK
);
2562 /* Here are some attributes you can add to chars to print */
2564 SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES
);
2565 SetDictInt("A_NORMAL", A_NORMAL
);
2566 SetDictInt("A_STANDOUT", A_STANDOUT
);
2567 SetDictInt("A_UNDERLINE", A_UNDERLINE
);
2568 SetDictInt("A_REVERSE", A_REVERSE
);
2569 SetDictInt("A_BLINK", A_BLINK
);
2570 SetDictInt("A_DIM", A_DIM
);
2571 SetDictInt("A_BOLD", A_BOLD
);
2572 SetDictInt("A_ALTCHARSET", A_ALTCHARSET
);
2573 #if !defined(__NetBSD__)
2574 SetDictInt("A_INVIS", A_INVIS
);
2576 SetDictInt("A_PROTECT", A_PROTECT
);
2577 SetDictInt("A_CHARTEXT", A_CHARTEXT
);
2578 SetDictInt("A_COLOR", A_COLOR
);
2580 /* The following are never available with strict SYSV curses */
2582 SetDictInt("A_HORIZONTAL", A_HORIZONTAL
);
2585 SetDictInt("A_LEFT", A_LEFT
);
2588 SetDictInt("A_LOW", A_LOW
);
2591 SetDictInt("A_RIGHT", A_RIGHT
);
2594 SetDictInt("A_TOP", A_TOP
);
2597 SetDictInt("A_VERTICAL", A_VERTICAL
);
2600 SetDictInt("COLOR_BLACK", COLOR_BLACK
);
2601 SetDictInt("COLOR_RED", COLOR_RED
);
2602 SetDictInt("COLOR_GREEN", COLOR_GREEN
);
2603 SetDictInt("COLOR_YELLOW", COLOR_YELLOW
);
2604 SetDictInt("COLOR_BLUE", COLOR_BLUE
);
2605 SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA
);
2606 SetDictInt("COLOR_CYAN", COLOR_CYAN
);
2607 SetDictInt("COLOR_WHITE", COLOR_WHITE
);
2609 #ifdef NCURSES_MOUSE_VERSION
2610 /* Mouse-related constants */
2611 SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED
);
2612 SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED
);
2613 SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED
);
2614 SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED
);
2615 SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED
);
2617 SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED
);
2618 SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED
);
2619 SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED
);
2620 SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED
);
2621 SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED
);
2623 SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED
);
2624 SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED
);
2625 SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED
);
2626 SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED
);
2627 SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED
);
2629 SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED
);
2630 SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED
);
2631 SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED
);
2632 SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED
);
2633 SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED
);
2635 SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT
);
2636 SetDictInt("BUTTON_CTRL", BUTTON_CTRL
);
2637 SetDictInt("BUTTON_ALT", BUTTON_ALT
);
2639 SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS
);
2640 SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION
);
2642 /* Now set everything up for KEY_ variables */
2647 #if !defined(__NetBSD__)
2648 for (key
=KEY_MIN
;key
< KEY_MAX
; key
++) {
2649 key_n
= (char *)keyname(key
);
2650 if (key_n
== NULL
|| strcmp(key_n
,"UNKNOWN KEY")==0)
2652 if (strncmp(key_n
,"KEY_F(",6)==0) {
2654 key_n2
= malloc(strlen(key_n
)+1);
2658 if (*p1
!= '(' && *p1
!= ')') {
2667 PyDict_SetItemString(d
,key_n2
,PyInt_FromLong((long) key
));
2668 if (key_n2
!= key_n
)
2672 SetDictInt("KEY_MIN", KEY_MIN
);
2673 SetDictInt("KEY_MAX", KEY_MAX
);