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) || 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"); \
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 { return PyCursesCheckERR(X(self->win), # X); }
247 #define Window_NoArgTrueFalseFunction(X) \
248 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
250 if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
251 else { Py_INCREF(Py_True); return Py_True; } }
253 #define Window_NoArgNoReturnVoidFunction(X) \
254 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
256 X(self->win); Py_INCREF(Py_None); return Py_None; }
258 #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
259 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
262 X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
264 #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
265 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
268 if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
269 X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
271 #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
272 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
275 if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
276 return PyCursesCheckERR(X(self->win, arg1), # X); }
278 #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
279 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
282 if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
283 return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
285 /* ------------- WINDOW routines --------------- */
287 Window_NoArgNoReturnFunction(untouchwin
)
288 Window_NoArgNoReturnFunction(touchwin
)
289 Window_NoArgNoReturnFunction(redrawwin
)
290 Window_NoArgNoReturnFunction(winsertln
)
291 Window_NoArgNoReturnFunction(werase
)
292 Window_NoArgNoReturnFunction(wdeleteln
)
294 Window_NoArgTrueFalseFunction(is_wintouched
)
296 Window_NoArgNoReturnVoidFunction(wsyncup
)
297 Window_NoArgNoReturnVoidFunction(wsyncdown
)
298 Window_NoArgNoReturnVoidFunction(wstandend
)
299 Window_NoArgNoReturnVoidFunction(wstandout
)
300 Window_NoArgNoReturnVoidFunction(wcursyncup
)
301 Window_NoArgNoReturnVoidFunction(wclrtoeol
)
302 Window_NoArgNoReturnVoidFunction(wclrtobot
)
303 Window_NoArgNoReturnVoidFunction(wclear
)
305 Window_OneArgNoReturnVoidFunction(idcok
, int, "i;True(1) or False(0)")
306 Window_OneArgNoReturnVoidFunction(immedok
, int, "i;True(1) or False(0)")
307 Window_OneArgNoReturnVoidFunction(wtimeout
, int, "i;delay")
309 Window_NoArg2TupleReturnFunction(getyx
, int, "ii")
310 Window_NoArg2TupleReturnFunction(getbegyx
, int, "ii")
311 Window_NoArg2TupleReturnFunction(getmaxyx
, int, "ii")
312 Window_NoArg2TupleReturnFunction(getparyx
, int, "ii")
314 Window_OneArgNoReturnFunction(wattron
, attr_t
, "l;attr")
315 Window_OneArgNoReturnFunction(wattroff
, attr_t
, "l;attr")
316 Window_OneArgNoReturnFunction(wattrset
, attr_t
, "l;attr")
317 Window_OneArgNoReturnFunction(clearok
, int, "i;True(1) or False(0)")
318 Window_OneArgNoReturnFunction(idlok
, int, "i;True(1) or False(0)")
319 #if defined(__NetBSD__)
320 Window_OneArgNoReturnVoidFunction(keypad
, int, "i;True(1) or False(0)")
322 Window_OneArgNoReturnFunction(keypad
, int, "i;True(1) or False(0)")
324 Window_OneArgNoReturnFunction(leaveok
, int, "i;True(1) or False(0)")
325 #if defined(__NetBSD__)
326 Window_OneArgNoReturnVoidFunction(nodelay
, int, "i;True(1) or False(0)")
328 Window_OneArgNoReturnFunction(nodelay
, int, "i;True(1) or False(0)")
330 Window_OneArgNoReturnFunction(notimeout
, int, "i;True(1) or False(0)")
331 Window_OneArgNoReturnFunction(scrollok
, int, "i;True(1) or False(0)")
332 Window_OneArgNoReturnFunction(winsdelln
, int, "i;nlines")
333 Window_OneArgNoReturnFunction(syncok
, int, "i;True(1) or False(0)")
335 Window_TwoArgNoReturnFunction(mvwin
, int, "ii;y,x")
336 Window_TwoArgNoReturnFunction(mvderwin
, int, "ii;y,x")
337 Window_TwoArgNoReturnFunction(wmove
, int, "ii;y,x")
338 #ifndef STRICT_SYSV_CURSES
339 Window_TwoArgNoReturnFunction(wresize
, int, "ii;lines,columns")
342 /* Allocation and deallocation of Window Objects */
345 PyCursesWindow_New(WINDOW
*win
)
347 PyCursesWindowObject
*wo
;
349 wo
= PyObject_NEW(PyCursesWindowObject
, &PyCursesWindow_Type
);
350 if (wo
== NULL
) return NULL
;
352 return (PyObject
*)wo
;
356 PyCursesWindow_Dealloc(PyCursesWindowObject
*wo
)
358 if (wo
->win
!= stdscr
) delwin(wo
->win
);
362 /* Addch, Addstr, Addnstr */
365 PyCursesWindow_AddCh(PyCursesWindowObject
*self
, PyObject
*args
)
367 int rtn
, x
, y
, use_xy
= FALSE
;
370 attr_t attr
= A_NORMAL
;
372 switch (PyTuple_Size(args
)) {
374 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
378 if (!PyArg_ParseTuple(args
, "Ol;ch or int,attr", &temp
, &attr
))
382 if (!PyArg_ParseTuple(args
,"iiO;y,x,ch or int", &y
, &x
, &temp
))
387 if (!PyArg_ParseTuple(args
,"iiOl;y,x,ch or int, attr",
388 &y
, &x
, &temp
, &attr
))
393 PyErr_SetString(PyExc_TypeError
, "addch requires 1 to 4 arguments");
397 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
398 PyErr_SetString(PyExc_TypeError
, "argument 1 or 3 must be a ch or an int");
403 rtn
= mvwaddch(self
->win
,y
,x
, ch
| attr
);
405 rtn
= waddch(self
->win
, ch
| attr
);
407 return PyCursesCheckERR(rtn
, "addch");
411 PyCursesWindow_AddStr(PyCursesWindowObject
*self
, PyObject
*args
)
416 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
417 int use_xy
= FALSE
, use_attr
= FALSE
;
419 switch (PyTuple_Size(args
)) {
421 if (!PyArg_ParseTuple(args
,"s;str", &str
))
425 if (!PyArg_ParseTuple(args
,"sl;str,attr", &str
, &attr
))
430 if (!PyArg_ParseTuple(args
,"iis;int,int,str", &y
, &x
, &str
))
435 if (!PyArg_ParseTuple(args
,"iisl;int,int,str,attr", &y
, &x
, &str
, &attr
))
437 use_xy
= use_attr
= TRUE
;
440 PyErr_SetString(PyExc_TypeError
, "addstr requires 1 to 4 arguments");
444 if (use_attr
== TRUE
) {
445 attr_old
= getattrs(self
->win
);
446 wattrset(self
->win
,attr
);
449 rtn
= mvwaddstr(self
->win
,y
,x
,str
);
451 rtn
= waddstr(self
->win
,str
);
452 if (use_attr
== TRUE
)
453 wattrset(self
->win
,attr_old
);
454 return PyCursesCheckERR(rtn
, "addstr");
458 PyCursesWindow_AddNStr(PyCursesWindowObject
*self
, PyObject
*args
)
462 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
463 int use_xy
= FALSE
, use_attr
= FALSE
;
465 switch (PyTuple_Size(args
)) {
467 if (!PyArg_ParseTuple(args
,"si;str,n", &str
, &n
))
471 if (!PyArg_ParseTuple(args
,"sil;str,n,attr", &str
, &n
, &attr
))
476 if (!PyArg_ParseTuple(args
,"iisi;y,x,str,n", &y
, &x
, &str
, &n
))
481 if (!PyArg_ParseTuple(args
,"iisil;y,x,str,n,attr", &y
, &x
, &str
, &n
, &attr
))
483 use_xy
= use_attr
= TRUE
;
486 PyErr_SetString(PyExc_TypeError
, "addnstr requires 2 to 5 arguments");
490 if (use_attr
== TRUE
) {
491 attr_old
= getattrs(self
->win
);
492 wattrset(self
->win
,attr
);
495 rtn
= mvwaddnstr(self
->win
,y
,x
,str
,n
);
497 rtn
= waddnstr(self
->win
,str
,n
);
498 if (use_attr
== TRUE
)
499 wattrset(self
->win
,attr_old
);
500 return PyCursesCheckERR(rtn
, "addnstr");
504 PyCursesWindow_Bkgd(PyCursesWindowObject
*self
, PyObject
*args
)
508 attr_t attr
= A_NORMAL
;
510 switch (PyTuple_Size(args
)) {
512 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
516 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &attr
))
520 PyErr_SetString(PyExc_TypeError
, "bkgd requires 1 or 2 arguments");
524 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
525 PyErr_SetString(PyExc_TypeError
, "argument 1 or 3 must be a ch or an int");
529 return PyCursesCheckERR(wbkgd(self
->win
, bkgd
| attr
), "bkgd");
533 PyCursesWindow_BkgdSet(PyCursesWindowObject
*self
, PyObject
*args
)
537 attr_t attr
= A_NORMAL
;
539 switch (PyTuple_Size(args
)) {
541 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
545 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &attr
))
549 PyErr_SetString(PyExc_TypeError
, "bkgdset requires 1 or 2 arguments");
553 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
554 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
558 wbkgdset(self
->win
, bkgd
| attr
);
559 return PyCursesCheckERR(0, "bkgdset");
563 PyCursesWindow_Border(PyCursesWindowObject
*self
, PyObject
*args
)
569 /* Clear the array of parameters */
575 if (!PyArg_ParseTuple(args
,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
576 &temp
[0], &temp
[1], &temp
[2], &temp
[3],
577 &temp
[4], &temp
[5], &temp
[6], &temp
[7]))
581 if (temp
[i
] != NULL
&& !PyCurses_ConvertToChtype(temp
[i
], &ch
[i
])) {
582 PyErr_Format(PyExc_TypeError
,
583 "argument %i must be a ch or an int", i
+1);
589 ch
[0], ch
[1], ch
[2], ch
[3],
590 ch
[4], ch
[5], ch
[6], ch
[7]);
596 PyCursesWindow_Box(PyCursesWindowObject
*self
, PyObject
*args
)
599 switch(PyTuple_Size(args
)){
602 if (!PyArg_ParseTuple(args
,"ll;vertint,horint", &ch1
, &ch2
))
605 box(self
->win
,ch1
,ch2
);
610 #if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
611 #define py_mvwdelch mvwdelch
613 int py_mvwdelch(WINDOW
*w
, int y
, int x
)
616 /* On HP/UX, mvwdelch already returns. On other systems,
617 we may well run into this return statement. */
624 PyCursesWindow_DelCh(PyCursesWindowObject
*self
, PyObject
*args
)
629 switch (PyTuple_Size(args
)) {
631 rtn
= wdelch(self
->win
);
634 if (!PyArg_ParseTuple(args
,"ii;y,x", &y
, &x
))
636 rtn
= py_mvwdelch(self
->win
,y
,x
);
639 PyErr_SetString(PyExc_TypeError
, "delch requires 0 or 2 arguments");
642 return PyCursesCheckERR(rtn
, "[mv]wdelch");
646 PyCursesWindow_DerWin(PyCursesWindowObject
*self
, PyObject
*args
)
649 int nlines
, ncols
, begin_y
, begin_x
;
653 switch (PyTuple_Size(args
)) {
655 if (!PyArg_ParseTuple(args
,"ii;begin_y,begin_x",&begin_y
,&begin_x
))
659 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
660 &nlines
,&ncols
,&begin_y
,&begin_x
))
664 PyErr_SetString(PyExc_TypeError
, "derwin requires 2 or 4 arguments");
668 win
= derwin(self
->win
,nlines
,ncols
,begin_y
,begin_x
);
671 PyErr_SetString(PyCursesError
, catchall_NULL
);
675 return (PyObject
*)PyCursesWindow_New(win
);
679 PyCursesWindow_EchoChar(PyCursesWindowObject
*self
, PyObject
*args
)
683 attr_t attr
= A_NORMAL
;
685 switch (PyTuple_Size(args
)) {
687 if (!PyArg_ParseTuple(args
,"O;ch or int", &temp
))
691 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &attr
))
695 PyErr_SetString(PyExc_TypeError
, "echochar requires 1 or 2 arguments");
701 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
702 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
706 #ifdef WINDOW_HAS_FLAGS
707 if (self
->win
->_flags
& _ISPAD
)
708 return PyCursesCheckERR(pechochar(self
->win
, ch
| attr
),
712 return PyCursesCheckERR(wechochar(self
->win
, ch
| attr
),
716 #ifdef NCURSES_MOUSE_VERSION
718 PyCursesWindow_Enclose(PyCursesWindowObject
*self
, PyObject
*args
)
721 if (!PyArg_ParseTuple(args
,"ii;y,x", &y
, &x
))
724 return PyInt_FromLong( wenclose(self
->win
,y
,x
) );
729 PyCursesWindow_GetBkgd(PyCursesWindowObject
*self
)
731 return PyInt_FromLong((long) getbkgd(self
->win
));
735 PyCursesWindow_GetCh(PyCursesWindowObject
*self
, PyObject
*args
)
740 switch (PyTuple_Size(args
)) {
742 Py_BEGIN_ALLOW_THREADS
743 rtn
= wgetch(self
->win
);
747 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
749 Py_BEGIN_ALLOW_THREADS
750 rtn
= mvwgetch(self
->win
,y
,x
);
754 PyErr_SetString(PyExc_TypeError
, "getch requires 0 or 2 arguments");
757 return PyInt_FromLong((long)rtn
);
761 PyCursesWindow_GetKey(PyCursesWindowObject
*self
, PyObject
*args
)
766 switch (PyTuple_Size(args
)) {
768 Py_BEGIN_ALLOW_THREADS
769 rtn
= wgetch(self
->win
);
773 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
775 Py_BEGIN_ALLOW_THREADS
776 rtn
= mvwgetch(self
->win
,y
,x
);
780 PyErr_SetString(PyExc_TypeError
, "getkey requires 0 or 2 arguments");
784 return Py_BuildValue("c", rtn
);
786 #if defined(__NetBSD__)
787 return PyString_FromString(unctrl(rtn
));
789 return PyString_FromString((char *)keyname(rtn
));
794 PyCursesWindow_GetStr(PyCursesWindowObject
*self
, PyObject
*args
)
797 char rtn
[1024]; /* This should be big enough.. I hope */
800 switch (PyTuple_Size(args
)) {
802 Py_BEGIN_ALLOW_THREADS
803 rtn2
= wgetstr(self
->win
,rtn
);
807 if (!PyArg_ParseTuple(args
,"i;n", &n
))
809 Py_BEGIN_ALLOW_THREADS
810 rtn2
= wgetnstr(self
->win
,rtn
,n
);
814 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
816 Py_BEGIN_ALLOW_THREADS
817 rtn2
= mvwgetstr(self
->win
,y
,x
,rtn
);
821 if (!PyArg_ParseTuple(args
,"iii;y,x,n", &y
, &x
, &n
))
823 #ifdef STRICT_SYSV_CURSES
825 Py_BEGIN_ALLOW_THREADS
826 rtn2
= wmove(self
->win
,y
,x
)==ERR
? ERR
:
827 wgetnstr(self
->win
, rtn
, n
);
830 Py_BEGIN_ALLOW_THREADS
831 rtn2
= mvwgetnstr(self
->win
, y
, x
, rtn
, n
);
836 PyErr_SetString(PyExc_TypeError
, "getstr requires 0 to 2 arguments");
841 return PyString_FromString(rtn
);
845 PyCursesWindow_Hline(PyCursesWindowObject
*self
, PyObject
*args
)
849 int n
, x
, y
, code
= OK
;
850 attr_t attr
= A_NORMAL
;
852 switch (PyTuple_Size(args
)) {
854 if (!PyArg_ParseTuple(args
, "Oi;ch or int,n", &temp
, &n
))
858 if (!PyArg_ParseTuple(args
, "Oil;ch or int,n,attr", &temp
, &n
, &attr
))
862 if (!PyArg_ParseTuple(args
, "iiOi;y,x,ch or int,n", &y
, &x
, &temp
, &n
))
864 code
= wmove(self
->win
, y
, x
);
867 if (!PyArg_ParseTuple(args
, "iiOil; y,x,ch or int,n,attr",
868 &y
, &x
, &temp
, &n
, &attr
))
870 code
= wmove(self
->win
, y
, x
);
873 PyErr_SetString(PyExc_TypeError
, "hline requires 2 to 5 arguments");
878 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
879 PyErr_SetString(PyExc_TypeError
,
880 "argument 1 or 3 must be a ch or an int");
883 return PyCursesCheckERR(whline(self
->win
, ch
| attr
, n
), "hline");
885 return PyCursesCheckERR(code
, "wmove");
889 PyCursesWindow_InsCh(PyCursesWindowObject
*self
, PyObject
*args
)
891 int rtn
, x
, y
, use_xy
= FALSE
;
894 attr_t attr
= A_NORMAL
;
896 switch (PyTuple_Size(args
)) {
898 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
902 if (!PyArg_ParseTuple(args
, "Ol;ch or int,attr", &temp
, &attr
))
906 if (!PyArg_ParseTuple(args
,"iiO;y,x,ch or int", &y
, &x
, &temp
))
911 if (!PyArg_ParseTuple(args
,"iiOl;y,x,ch or int, attr", &y
, &x
, &temp
, &attr
))
916 PyErr_SetString(PyExc_TypeError
, "insch requires 1 or 4 arguments");
920 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
921 PyErr_SetString(PyExc_TypeError
,
922 "argument 1 or 3 must be a ch or an int");
927 rtn
= mvwinsch(self
->win
,y
,x
, ch
| attr
);
929 rtn
= winsch(self
->win
, ch
| attr
);
931 return PyCursesCheckERR(rtn
, "insch");
935 PyCursesWindow_InCh(PyCursesWindowObject
*self
, PyObject
*args
)
939 switch (PyTuple_Size(args
)) {
941 rtn
= winch(self
->win
);
944 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
946 rtn
= mvwinch(self
->win
,y
,x
);
949 PyErr_SetString(PyExc_TypeError
, "inch requires 0 or 2 arguments");
952 return PyInt_FromLong((long) rtn
);
956 PyCursesWindow_InStr(PyCursesWindowObject
*self
, PyObject
*args
)
959 char rtn
[1024]; /* This should be big enough.. I hope */
962 switch (PyTuple_Size(args
)) {
964 rtn2
= winstr(self
->win
,rtn
);
967 if (!PyArg_ParseTuple(args
,"i;n", &n
))
969 rtn2
= winnstr(self
->win
,rtn
,n
);
972 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
974 rtn2
= mvwinstr(self
->win
,y
,x
,rtn
);
977 if (!PyArg_ParseTuple(args
, "iii;y,x,n", &y
, &x
, &n
))
979 rtn2
= mvwinnstr(self
->win
, y
, x
, rtn
, n
);
982 PyErr_SetString(PyExc_TypeError
, "instr requires 0 or 3 arguments");
987 return PyString_FromString(rtn
);
991 PyCursesWindow_InsStr(PyCursesWindowObject
*self
, PyObject
*args
)
996 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
997 int use_xy
= FALSE
, use_attr
= FALSE
;
999 switch (PyTuple_Size(args
)) {
1001 if (!PyArg_ParseTuple(args
,"s;str", &str
))
1005 if (!PyArg_ParseTuple(args
,"sl;str,attr", &str
, &attr
))
1010 if (!PyArg_ParseTuple(args
,"iis;y,x,str", &y
, &x
, &str
))
1015 if (!PyArg_ParseTuple(args
,"iisl;y,x,str,attr", &y
, &x
, &str
, &attr
))
1017 use_xy
= use_attr
= TRUE
;
1020 PyErr_SetString(PyExc_TypeError
, "insstr requires 1 to 4 arguments");
1024 if (use_attr
== TRUE
) {
1025 attr_old
= getattrs(self
->win
);
1026 wattrset(self
->win
,attr
);
1029 rtn
= mvwinsstr(self
->win
,y
,x
,str
);
1031 rtn
= winsstr(self
->win
,str
);
1032 if (use_attr
== TRUE
)
1033 wattrset(self
->win
,attr_old
);
1034 return PyCursesCheckERR(rtn
, "insstr");
1038 PyCursesWindow_InsNStr(PyCursesWindowObject
*self
, PyObject
*args
)
1042 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
1043 int use_xy
= FALSE
, use_attr
= FALSE
;
1045 switch (PyTuple_Size(args
)) {
1047 if (!PyArg_ParseTuple(args
,"si;str,n", &str
, &n
))
1051 if (!PyArg_ParseTuple(args
,"sil;str,n,attr", &str
, &n
, &attr
))
1056 if (!PyArg_ParseTuple(args
,"iisi;y,x,str,n", &y
, &x
, &str
, &n
))
1061 if (!PyArg_ParseTuple(args
,"iisil;y,x,str,n,attr", &y
, &x
, &str
, &n
, &attr
))
1063 use_xy
= use_attr
= TRUE
;
1066 PyErr_SetString(PyExc_TypeError
, "insnstr requires 2 to 5 arguments");
1070 if (use_attr
== TRUE
) {
1071 attr_old
= getattrs(self
->win
);
1072 wattrset(self
->win
,attr
);
1075 rtn
= mvwinsnstr(self
->win
,y
,x
,str
,n
);
1077 rtn
= winsnstr(self
->win
,str
,n
);
1078 if (use_attr
== TRUE
)
1079 wattrset(self
->win
,attr_old
);
1080 return PyCursesCheckERR(rtn
, "insnstr");
1084 PyCursesWindow_Is_LineTouched(PyCursesWindowObject
*self
, PyObject
*args
)
1087 if (!PyArg_ParseTuple(args
,"i;line", &line
))
1089 erg
= is_linetouched(self
->win
, line
);
1091 PyErr_SetString(PyExc_TypeError
,
1092 "is_linetouched: line number outside of boundaries");
1096 Py_INCREF(Py_False
);
1105 PyCursesWindow_NoOutRefresh(PyCursesWindowObject
*self
, PyObject
*args
)
1107 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1110 #ifndef WINDOW_HAS_FLAGS
1113 if (self
->win
->_flags
& _ISPAD
) {
1115 switch(PyTuple_Size(args
)) {
1117 if (!PyArg_ParseTuple(args
,
1119 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1120 &pminrow
, &pmincol
, &sminrow
,
1121 &smincol
, &smaxrow
, &smaxcol
))
1123 Py_BEGIN_ALLOW_THREADS
1124 rtn
= pnoutrefresh(self
->win
,
1125 pminrow
, pmincol
, sminrow
,
1126 smincol
, smaxrow
, smaxcol
);
1127 Py_END_ALLOW_THREADS
1128 return PyCursesCheckERR(rtn
, "pnoutrefresh");
1130 PyErr_SetString(PyCursesError
,
1131 "noutrefresh() called for a pad "
1132 "requires 6 arguments");
1136 if (!PyArg_ParseTuple(args
, ":noutrefresh"))
1139 Py_BEGIN_ALLOW_THREADS
1140 rtn
= wnoutrefresh(self
->win
);
1141 Py_END_ALLOW_THREADS
1142 return PyCursesCheckERR(rtn
, "wnoutrefresh");
1147 PyCursesWindow_Overlay(PyCursesWindowObject
*self
, PyObject
*args
)
1149 PyCursesWindowObject
*temp
;
1150 int use_copywin
= FALSE
;
1151 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1154 switch (PyTuple_Size(args
)) {
1156 if (!PyArg_ParseTuple(args
, "O!;window object",
1157 &PyCursesWindow_Type
, &temp
))
1161 if (!PyArg_ParseTuple(args
, "(O!iiiiii);window object, int, int, int, int, int, int",
1162 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1163 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1168 PyErr_SetString(PyExc_TypeError
,
1169 "overlay requires one or seven arguments");
1173 if (use_copywin
== TRUE
) {
1174 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1175 dminrow
, dmincol
, dmaxrow
, dmaxcol
, TRUE
);
1176 return PyCursesCheckERR(rtn
, "copywin");
1179 rtn
= overlay(self
->win
, temp
->win
);
1180 return PyCursesCheckERR(rtn
, "overlay");
1185 PyCursesWindow_Overwrite(PyCursesWindowObject
*self
, PyObject
*args
)
1187 PyCursesWindowObject
*temp
;
1188 int use_copywin
= FALSE
;
1189 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1192 switch (PyTuple_Size(args
)) {
1194 if (!PyArg_ParseTuple(args
, "O!;window object",
1195 &PyCursesWindow_Type
, &temp
))
1199 if (!PyArg_ParseTuple(args
, "(O!iiiiii);window object, int, int, int, int, int, int",
1200 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1201 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1206 PyErr_SetString(PyExc_TypeError
,
1207 "overwrite requires one or seven arguments");
1211 if (use_copywin
== TRUE
) {
1212 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1213 dminrow
, dmincol
, dmaxrow
, dmaxcol
, FALSE
);
1214 return PyCursesCheckERR(rtn
, "copywin");
1217 rtn
= overwrite(self
->win
, temp
->win
);
1218 return PyCursesCheckERR(rtn
, "overwrite");
1223 PyCursesWindow_PutWin(PyCursesWindowObject
*self
, PyObject
*args
)
1227 if (!PyArg_ParseTuple(args
, "O;fileobj", &temp
))
1229 if (!PyFile_Check(temp
)) {
1230 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1233 return PyCursesCheckERR(putwin(self
->win
, PyFile_AsFile(temp
)),
1238 PyCursesWindow_RedrawLine(PyCursesWindowObject
*self
, PyObject
*args
)
1241 if (!PyArg_ParseTuple(args
,"ii;beg,num", &beg
, &num
))
1243 return PyCursesCheckERR(wredrawln(self
->win
,beg
,num
), "redrawln");
1247 PyCursesWindow_Refresh(PyCursesWindowObject
*self
, PyObject
*args
)
1249 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1252 #ifndef WINDOW_HAS_FLAGS
1255 if (self
->win
->_flags
& _ISPAD
) {
1257 switch(PyTuple_Size(args
)) {
1259 if (!PyArg_ParseTuple(args
,
1261 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1262 &pminrow
, &pmincol
, &sminrow
,
1263 &smincol
, &smaxrow
, &smaxcol
))
1266 Py_BEGIN_ALLOW_THREADS
1267 rtn
= prefresh(self
->win
,
1268 pminrow
, pmincol
, sminrow
,
1269 smincol
, smaxrow
, smaxcol
);
1270 Py_END_ALLOW_THREADS
1271 return PyCursesCheckERR(rtn
, "prefresh");
1273 PyErr_SetString(PyCursesError
,
1274 "refresh() for a pad requires 6 arguments");
1278 if (!PyArg_ParseTuple(args
, ":refresh"))
1280 Py_BEGIN_ALLOW_THREADS
1281 rtn
= wrefresh(self
->win
);
1282 Py_END_ALLOW_THREADS
1283 return PyCursesCheckERR(rtn
, "prefresh");
1288 PyCursesWindow_SetScrollRegion(PyCursesWindowObject
*self
, PyObject
*args
)
1291 if (!PyArg_ParseTuple(args
,"ii;top, bottom",&y
,&x
))
1293 return PyCursesCheckERR(wsetscrreg(self
->win
,y
,x
), "wsetscrreg");
1297 PyCursesWindow_SubWin(PyCursesWindowObject
*self
, PyObject
*args
)
1300 int nlines
, ncols
, begin_y
, begin_x
;
1304 switch (PyTuple_Size(args
)) {
1306 if (!PyArg_ParseTuple(args
,"ii;begin_y,begin_x",&begin_y
,&begin_x
))
1310 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
1311 &nlines
,&ncols
,&begin_y
,&begin_x
))
1315 PyErr_SetString(PyExc_TypeError
, "subwin requires 2 or 4 arguments");
1319 /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
1320 #ifdef WINDOW_HAS_FLAGS
1321 if (self
->win
->_flags
& _ISPAD
)
1322 win
= subpad(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1325 win
= subwin(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1328 PyErr_SetString(PyCursesError
, catchall_NULL
);
1332 return (PyObject
*)PyCursesWindow_New(win
);
1336 PyCursesWindow_Scroll(PyCursesWindowObject
*self
, PyObject
*args
)
1339 switch(PyTuple_Size(args
)) {
1341 return PyCursesCheckERR(scroll(self
->win
), "scroll");
1343 if (!PyArg_ParseTuple(args
, "i;nlines", &nlines
))
1345 return PyCursesCheckERR(wscrl(self
->win
, nlines
), "scroll");
1347 PyErr_SetString(PyExc_TypeError
, "scroll requires 0 or 1 arguments");
1353 PyCursesWindow_TouchLine(PyCursesWindowObject
*self
, PyObject
*args
)
1356 switch (PyTuple_Size(args
)) {
1358 if (!PyArg_ParseTuple(args
,"ii;start,count",&st
,&cnt
))
1360 return PyCursesCheckERR(touchline(self
->win
,st
,cnt
), "touchline");
1362 if (!PyArg_ParseTuple(args
, "iii;start,count,val", &st
, &cnt
, &val
))
1364 return PyCursesCheckERR(wtouchln(self
->win
, st
, cnt
, val
), "touchline");
1366 PyErr_SetString(PyExc_TypeError
, "touchline requires 2 or 3 arguments");
1372 PyCursesWindow_Vline(PyCursesWindowObject
*self
, PyObject
*args
)
1376 int n
, x
, y
, code
= OK
;
1377 attr_t attr
= A_NORMAL
;
1379 switch (PyTuple_Size(args
)) {
1381 if (!PyArg_ParseTuple(args
, "Oi;ch or int,n", &temp
, &n
))
1385 if (!PyArg_ParseTuple(args
, "Oil;ch or int,n,attr", &temp
, &n
, &attr
))
1389 if (!PyArg_ParseTuple(args
, "iiOi;y,x,ch or int,n", &y
, &x
, &temp
, &n
))
1391 code
= wmove(self
->win
, y
, x
);
1394 if (!PyArg_ParseTuple(args
, "iiOil; y,x,ch or int,n,attr",
1395 &y
, &x
, &temp
, &n
, &attr
))
1397 code
= wmove(self
->win
, y
, x
);
1400 PyErr_SetString(PyExc_TypeError
, "vline requires 2 to 5 arguments");
1405 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
1406 PyErr_SetString(PyExc_TypeError
,
1407 "argument 1 or 3 must be a ch or an int");
1410 return PyCursesCheckERR(wvline(self
->win
, ch
| attr
, n
), "vline");
1412 return PyCursesCheckERR(code
, "wmove");
1415 static PyMethodDef PyCursesWindow_Methods
[] = {
1416 {"addch", (PyCFunction
)PyCursesWindow_AddCh
, METH_VARARGS
},
1417 {"addnstr", (PyCFunction
)PyCursesWindow_AddNStr
, METH_VARARGS
},
1418 {"addstr", (PyCFunction
)PyCursesWindow_AddStr
, METH_VARARGS
},
1419 {"attroff", (PyCFunction
)PyCursesWindow_wattroff
, METH_VARARGS
},
1420 {"attron", (PyCFunction
)PyCursesWindow_wattron
, METH_VARARGS
},
1421 {"attrset", (PyCFunction
)PyCursesWindow_wattrset
, METH_VARARGS
},
1422 {"bkgd", (PyCFunction
)PyCursesWindow_Bkgd
, METH_VARARGS
},
1423 {"bkgdset", (PyCFunction
)PyCursesWindow_BkgdSet
, METH_VARARGS
},
1424 {"border", (PyCFunction
)PyCursesWindow_Border
, METH_VARARGS
},
1425 {"box", (PyCFunction
)PyCursesWindow_Box
, METH_VARARGS
},
1426 {"clear", (PyCFunction
)PyCursesWindow_wclear
, METH_NOARGS
},
1427 {"clearok", (PyCFunction
)PyCursesWindow_clearok
, METH_VARARGS
},
1428 {"clrtobot", (PyCFunction
)PyCursesWindow_wclrtobot
, METH_NOARGS
},
1429 {"clrtoeol", (PyCFunction
)PyCursesWindow_wclrtoeol
, METH_NOARGS
},
1430 {"cursyncup", (PyCFunction
)PyCursesWindow_wcursyncup
, METH_NOARGS
},
1431 {"delch", (PyCFunction
)PyCursesWindow_DelCh
, METH_VARARGS
},
1432 {"deleteln", (PyCFunction
)PyCursesWindow_wdeleteln
, METH_NOARGS
},
1433 {"derwin", (PyCFunction
)PyCursesWindow_DerWin
, METH_VARARGS
},
1434 {"echochar", (PyCFunction
)PyCursesWindow_EchoChar
, METH_VARARGS
},
1435 #ifdef NCURSES_MOUSE_VERSION
1436 {"enclose", (PyCFunction
)PyCursesWindow_Enclose
, METH_VARARGS
},
1438 {"erase", (PyCFunction
)PyCursesWindow_werase
, METH_NOARGS
},
1439 {"getbegyx", (PyCFunction
)PyCursesWindow_getbegyx
, METH_NOARGS
},
1440 {"getbkgd", (PyCFunction
)PyCursesWindow_GetBkgd
, METH_NOARGS
},
1441 {"getch", (PyCFunction
)PyCursesWindow_GetCh
, METH_VARARGS
},
1442 {"getkey", (PyCFunction
)PyCursesWindow_GetKey
, METH_VARARGS
},
1443 {"getmaxyx", (PyCFunction
)PyCursesWindow_getmaxyx
, METH_NOARGS
},
1444 {"getparyx", (PyCFunction
)PyCursesWindow_getparyx
, METH_NOARGS
},
1445 {"getstr", (PyCFunction
)PyCursesWindow_GetStr
, METH_VARARGS
},
1446 {"getyx", (PyCFunction
)PyCursesWindow_getyx
, METH_NOARGS
},
1447 {"hline", (PyCFunction
)PyCursesWindow_Hline
, METH_VARARGS
},
1448 {"idcok", (PyCFunction
)PyCursesWindow_idcok
, METH_VARARGS
},
1449 {"idlok", (PyCFunction
)PyCursesWindow_idlok
, METH_VARARGS
},
1450 {"immedok", (PyCFunction
)PyCursesWindow_immedok
, METH_VARARGS
},
1451 {"inch", (PyCFunction
)PyCursesWindow_InCh
, METH_VARARGS
},
1452 {"insch", (PyCFunction
)PyCursesWindow_InsCh
, METH_VARARGS
},
1453 {"insdelln", (PyCFunction
)PyCursesWindow_winsdelln
, METH_VARARGS
},
1454 {"insertln", (PyCFunction
)PyCursesWindow_winsertln
, METH_NOARGS
},
1455 {"insnstr", (PyCFunction
)PyCursesWindow_InsNStr
, METH_VARARGS
},
1456 {"insstr", (PyCFunction
)PyCursesWindow_InsStr
, METH_VARARGS
},
1457 {"instr", (PyCFunction
)PyCursesWindow_InStr
, METH_VARARGS
},
1458 {"is_linetouched", (PyCFunction
)PyCursesWindow_Is_LineTouched
, METH_VARARGS
},
1459 {"is_wintouched", (PyCFunction
)PyCursesWindow_is_wintouched
, METH_NOARGS
},
1460 {"keypad", (PyCFunction
)PyCursesWindow_keypad
, METH_VARARGS
},
1461 {"leaveok", (PyCFunction
)PyCursesWindow_leaveok
, METH_VARARGS
},
1462 {"move", (PyCFunction
)PyCursesWindow_wmove
, METH_VARARGS
},
1463 {"mvderwin", (PyCFunction
)PyCursesWindow_mvderwin
, METH_VARARGS
},
1464 {"mvwin", (PyCFunction
)PyCursesWindow_mvwin
, METH_VARARGS
},
1465 {"nodelay", (PyCFunction
)PyCursesWindow_nodelay
, METH_VARARGS
},
1466 {"notimeout", (PyCFunction
)PyCursesWindow_notimeout
, METH_VARARGS
},
1467 {"noutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
, METH_VARARGS
},
1468 /* Backward compatibility alias -- remove in Python 2.3 */
1469 {"nooutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
, METH_VARARGS
},
1470 {"overlay", (PyCFunction
)PyCursesWindow_Overlay
, METH_VARARGS
},
1471 {"overwrite", (PyCFunction
)PyCursesWindow_Overwrite
,
1473 {"putwin", (PyCFunction
)PyCursesWindow_PutWin
, METH_VARARGS
},
1474 {"redrawln", (PyCFunction
)PyCursesWindow_RedrawLine
},
1475 {"redrawwin", (PyCFunction
)PyCursesWindow_redrawwin
, METH_NOARGS
},
1476 {"refresh", (PyCFunction
)PyCursesWindow_Refresh
, METH_VARARGS
},
1477 #ifndef STRICT_SYSV_CURSES
1478 {"resize", (PyCFunction
)PyCursesWindow_wresize
, METH_VARARGS
},
1480 {"scroll", (PyCFunction
)PyCursesWindow_Scroll
, METH_VARARGS
},
1481 {"scrollok", (PyCFunction
)PyCursesWindow_scrollok
, METH_VARARGS
},
1482 {"setscrreg", (PyCFunction
)PyCursesWindow_SetScrollRegion
, METH_VARARGS
},
1483 {"standend", (PyCFunction
)PyCursesWindow_wstandend
, METH_NOARGS
},
1484 {"standout", (PyCFunction
)PyCursesWindow_wstandout
, METH_NOARGS
},
1485 {"subpad", (PyCFunction
)PyCursesWindow_SubWin
, METH_VARARGS
},
1486 {"subwin", (PyCFunction
)PyCursesWindow_SubWin
, METH_VARARGS
},
1487 {"syncdown", (PyCFunction
)PyCursesWindow_wsyncdown
, METH_NOARGS
},
1488 {"syncok", (PyCFunction
)PyCursesWindow_syncok
, METH_VARARGS
},
1489 {"syncup", (PyCFunction
)PyCursesWindow_wsyncup
, METH_NOARGS
},
1490 {"timeout", (PyCFunction
)PyCursesWindow_wtimeout
, METH_VARARGS
},
1491 {"touchline", (PyCFunction
)PyCursesWindow_TouchLine
, METH_VARARGS
},
1492 {"touchwin", (PyCFunction
)PyCursesWindow_touchwin
, METH_NOARGS
},
1493 {"untouchwin", (PyCFunction
)PyCursesWindow_untouchwin
, METH_NOARGS
},
1494 {"vline", (PyCFunction
)PyCursesWindow_Vline
, METH_VARARGS
},
1495 {NULL
, NULL
} /* sentinel */
1499 PyCursesWindow_GetAttr(PyCursesWindowObject
*self
, char *name
)
1501 return Py_FindMethod(PyCursesWindow_Methods
, (PyObject
*)self
, name
);
1504 /* -------------------------------------------------------*/
1506 PyTypeObject PyCursesWindow_Type
= {
1507 PyObject_HEAD_INIT(NULL
)
1509 "_curses.curses window", /*tp_name*/
1510 sizeof(PyCursesWindowObject
), /*tp_basicsize*/
1513 (destructor
)PyCursesWindow_Dealloc
, /*tp_dealloc*/
1515 (getattrfunc
)PyCursesWindow_GetAttr
, /*tp_getattr*/
1516 (setattrfunc
)0, /*tp_setattr*/
1520 0, /*tp_as_sequence*/
1521 0, /*tp_as_mapping*/
1525 /*********************************************************************
1527 **********************************************************************/
1529 NoArgNoReturnFunction(beep
)
1530 NoArgNoReturnFunction(def_prog_mode
)
1531 NoArgNoReturnFunction(def_shell_mode
)
1532 NoArgNoReturnFunction(doupdate
)
1533 NoArgNoReturnFunction(endwin
)
1534 NoArgNoReturnFunction(flash
)
1535 NoArgNoReturnFunction(nocbreak
)
1536 NoArgNoReturnFunction(noecho
)
1537 NoArgNoReturnFunction(nonl
)
1538 NoArgNoReturnFunction(noraw
)
1539 NoArgNoReturnFunction(reset_prog_mode
)
1540 NoArgNoReturnFunction(reset_shell_mode
)
1541 NoArgNoReturnFunction(resetty
)
1542 NoArgNoReturnFunction(savetty
)
1544 NoArgOrFlagNoReturnFunction(cbreak
)
1545 NoArgOrFlagNoReturnFunction(echo
)
1546 NoArgOrFlagNoReturnFunction(nl
)
1547 NoArgOrFlagNoReturnFunction(raw
)
1549 NoArgReturnIntFunction(baudrate
)
1550 NoArgReturnIntFunction(termattrs
)
1552 NoArgReturnStringFunction(termname
)
1553 NoArgReturnStringFunction(longname
)
1555 NoArgTrueFalseFunction(can_change_color
)
1556 NoArgTrueFalseFunction(has_colors
)
1557 NoArgTrueFalseFunction(has_ic
)
1558 NoArgTrueFalseFunction(has_il
)
1559 NoArgTrueFalseFunction(isendwin
)
1560 NoArgNoReturnVoidFunction(filter
)
1561 NoArgNoReturnVoidFunction(flushinp
)
1562 NoArgNoReturnVoidFunction(noqiflush
)
1565 PyCurses_Color_Content(PyObject
*self
, PyObject
*args
)
1570 PyCursesInitialisedColor
1572 if (!PyArg_ParseTuple(args
, "h:color_content", &color
)) return NULL
;
1574 if (color_content(color
, &r
, &g
, &b
) != ERR
)
1575 return Py_BuildValue("(iii)", r
, g
, b
);
1577 PyErr_SetString(PyCursesError
,
1578 "Argument 1 was out of range. Check value of COLORS.");
1584 PyCurses_color_pair(PyObject
*self
, PyObject
*args
)
1589 PyCursesInitialisedColor
1591 if (!PyArg_ParseTuple(args
, "i:color_pair", &n
)) return NULL
;
1592 return PyInt_FromLong((long) (n
<< 8));
1596 PyCurses_Curs_Set(PyObject
*self
, PyObject
*args
)
1602 if (!PyArg_ParseTuple(args
, "i:curs_set", &vis
)) return NULL
;
1604 erg
= curs_set(vis
);
1605 if (erg
== ERR
) return PyCursesCheckERR(erg
, "curs_set");
1607 return PyInt_FromLong((long) erg
);
1611 PyCurses_Delay_Output(PyObject
*self
, PyObject
*args
)
1617 if (!PyArg_ParseTuple(args
, "i:delay_output", &ms
)) return NULL
;
1619 return PyCursesCheckERR(delay_output(ms
), "delay_output");
1623 PyCurses_EraseChar(PyObject
*self
)
1631 return PyString_FromStringAndSize(&ch
, 1);
1635 PyCurses_getsyx(PyObject
*self
)
1643 return Py_BuildValue("(ii)", y
, x
);
1646 #ifdef NCURSES_MOUSE_VERSION
1648 PyCurses_GetMouse(PyObject
*self
)
1655 rtn
= getmouse( &event
);
1657 PyErr_SetString(PyCursesError
, "getmouse() returned ERR");
1660 return Py_BuildValue("(hiiil)",
1662 event
.x
, event
.y
, event
.z
,
1663 (long) event
.bstate
);
1667 PyCurses_UngetMouse(PyObject
*self
, PyObject
*args
)
1672 if (!PyArg_ParseTuple(args
, "(hiiil)",
1674 &event
.x
, &event
.y
, &event
.z
,
1675 (int *) &event
.bstate
))
1678 return PyCursesCheckERR(ungetmouse(&event
), "ungetmouse");
1683 PyCurses_GetWin(PyCursesWindowObject
*self
, PyObject
*temp
)
1689 if (!PyFile_Check(temp
)) {
1690 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1694 win
= getwin(PyFile_AsFile(temp
));
1697 PyErr_SetString(PyCursesError
, catchall_NULL
);
1701 return PyCursesWindow_New(win
);
1705 PyCurses_HalfDelay(PyObject
*self
, PyObject
*args
)
1707 unsigned char tenths
;
1711 if (!PyArg_ParseTuple(args
, "b:halfdelay", &tenths
)) return NULL
;
1713 return PyCursesCheckERR(halfdelay(tenths
), "halfdelay");
1716 #ifndef STRICT_SYSV_CURSES
1718 static PyObject
* PyCurses_has_key(PyObject
*self
, PyObject
*args
)
1724 if (!PyArg_ParseTuple(args
,"i",&ch
)) return NULL
;
1726 if (has_key(ch
) == FALSE
) {
1727 Py_INCREF(Py_False
);
1733 #endif /* STRICT_SYSV_CURSES */
1736 PyCurses_Init_Color(PyObject
*self
, PyObject
*args
)
1738 short color
, r
, g
, b
;
1741 PyCursesInitialisedColor
1743 switch(PyTuple_Size(args
)) {
1745 if (!PyArg_ParseTuple(args
, "hhhh;color,r,g,b", &color
, &r
, &g
, &b
)) return NULL
;
1748 PyErr_SetString(PyExc_TypeError
, "init_color requires 4 arguments");
1752 return PyCursesCheckERR(init_color(color
, r
, g
, b
), "init_color");
1756 PyCurses_Init_Pair(PyObject
*self
, PyObject
*args
)
1761 PyCursesInitialisedColor
1763 if (PyTuple_Size(args
) != 3) {
1764 PyErr_SetString(PyExc_TypeError
, "init_pair requires 3 arguments");
1768 if (!PyArg_ParseTuple(args
, "hhh;pair, f, b", &pair
, &f
, &b
)) return NULL
;
1770 return PyCursesCheckERR(init_pair(pair
, f
, b
), "init_pair");
1773 static PyObject
*ModDict
;
1776 PyCurses_InitScr(PyObject
*self
)
1779 PyObject
*nlines
, *cols
;
1781 if (initialised
== TRUE
) {
1783 return (PyObject
*)PyCursesWindow_New(stdscr
);
1789 PyErr_SetString(PyCursesError
, catchall_NULL
);
1793 initialised
= initialised_setupterm
= TRUE
;
1795 /* This was moved from initcurses() because it core dumped on SGI,
1796 where they're not defined until you've called initscr() */
1797 #define SetDictInt(string,ch) \
1798 PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
1800 /* Here are some graphic symbols you can use */
1801 SetDictInt("ACS_ULCORNER", (ACS_ULCORNER
));
1802 SetDictInt("ACS_LLCORNER", (ACS_LLCORNER
));
1803 SetDictInt("ACS_URCORNER", (ACS_URCORNER
));
1804 SetDictInt("ACS_LRCORNER", (ACS_LRCORNER
));
1805 SetDictInt("ACS_LTEE", (ACS_LTEE
));
1806 SetDictInt("ACS_RTEE", (ACS_RTEE
));
1807 SetDictInt("ACS_BTEE", (ACS_BTEE
));
1808 SetDictInt("ACS_TTEE", (ACS_TTEE
));
1809 SetDictInt("ACS_HLINE", (ACS_HLINE
));
1810 SetDictInt("ACS_VLINE", (ACS_VLINE
));
1811 SetDictInt("ACS_PLUS", (ACS_PLUS
));
1812 #if !defined(__hpux) || defined(HAVE_NCURSES_H)
1813 /* On HP/UX 11, these are of type cchar_t, which is not an
1814 integral type. If this is a problem on more platforms, a
1815 configure test should be added to determine whether ACS_S1
1816 is of integral type. */
1817 SetDictInt("ACS_S1", (ACS_S1
));
1818 SetDictInt("ACS_S9", (ACS_S9
));
1819 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND
));
1820 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD
));
1821 SetDictInt("ACS_DEGREE", (ACS_DEGREE
));
1822 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS
));
1823 SetDictInt("ACS_BULLET", (ACS_BULLET
));
1824 SetDictInt("ACS_LARROW", (ACS_LARROW
));
1825 SetDictInt("ACS_RARROW", (ACS_RARROW
));
1826 SetDictInt("ACS_DARROW", (ACS_DARROW
));
1827 SetDictInt("ACS_UARROW", (ACS_UARROW
));
1828 SetDictInt("ACS_BOARD", (ACS_BOARD
));
1829 SetDictInt("ACS_LANTERN", (ACS_LANTERN
));
1830 SetDictInt("ACS_BLOCK", (ACS_BLOCK
));
1832 SetDictInt("ACS_BSSB", (ACS_ULCORNER
));
1833 SetDictInt("ACS_SSBB", (ACS_LLCORNER
));
1834 SetDictInt("ACS_BBSS", (ACS_URCORNER
));
1835 SetDictInt("ACS_SBBS", (ACS_LRCORNER
));
1836 SetDictInt("ACS_SBSS", (ACS_RTEE
));
1837 SetDictInt("ACS_SSSB", (ACS_LTEE
));
1838 SetDictInt("ACS_SSBS", (ACS_BTEE
));
1839 SetDictInt("ACS_BSSS", (ACS_TTEE
));
1840 SetDictInt("ACS_BSBS", (ACS_HLINE
));
1841 SetDictInt("ACS_SBSB", (ACS_VLINE
));
1842 SetDictInt("ACS_SSSS", (ACS_PLUS
));
1844 /* The following are never available with strict SYSV curses */
1846 SetDictInt("ACS_S3", (ACS_S3
));
1849 SetDictInt("ACS_S7", (ACS_S7
));
1852 SetDictInt("ACS_LEQUAL", (ACS_LEQUAL
));
1855 SetDictInt("ACS_GEQUAL", (ACS_GEQUAL
));
1858 SetDictInt("ACS_PI", (ACS_PI
));
1861 SetDictInt("ACS_NEQUAL", (ACS_NEQUAL
));
1864 SetDictInt("ACS_STERLING", (ACS_STERLING
));
1867 nlines
= PyInt_FromLong((long) LINES
);
1868 PyDict_SetItemString(ModDict
, "LINES", nlines
);
1870 cols
= PyInt_FromLong((long) COLS
);
1871 PyDict_SetItemString(ModDict
, "COLS", cols
);
1874 return (PyObject
*)PyCursesWindow_New(win
);
1878 PyCurses_setupterm(PyObject
* self
, PyObject
*args
, PyObject
* keywds
)
1882 char* termstr
= NULL
;
1884 static char *kwlist
[] = {"term", "fd", NULL
};
1886 if (!PyArg_ParseTupleAndKeywords(
1887 args
,keywds
,"|zi:setupterm",kwlist
,&termstr
,&fd
)) {
1892 PyObject
* sys_stdout
;
1894 sys_stdout
= PySys_GetObject("stdout");
1896 if (sys_stdout
== NULL
) {
1903 fd
= PyObject_AsFileDescriptor(sys_stdout
);
1910 if (setupterm(termstr
,fd
,&err
) == ERR
) {
1911 char* s
= "setupterm: unknown error";
1914 s
= "setupterm: could not find terminal";
1915 } else if (err
== -1) {
1916 s
= "setupterm: could not find terminfo database";
1919 PyErr_SetString(PyCursesError
,s
);
1923 initialised_setupterm
= TRUE
;
1930 PyCurses_IntrFlush(PyObject
*self
, PyObject
*args
)
1936 switch(PyTuple_Size(args
)) {
1938 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&ch
)) return NULL
;
1941 PyErr_SetString(PyExc_TypeError
, "intrflush requires 1 argument");
1945 return PyCursesCheckERR(intrflush(NULL
,ch
), "intrflush");
1948 #if !defined(__NetBSD__)
1950 PyCurses_KeyName(PyObject
*self
, PyObject
*args
)
1957 if (!PyArg_ParseTuple(args
,"i",&ch
)) return NULL
;
1961 return PyString_FromString((knp
== NULL
) ? "" : (char *)knp
);
1966 PyCurses_KillChar(PyObject
*self
)
1972 return PyString_FromStringAndSize(&ch
, 1);
1976 PyCurses_Meta(PyObject
*self
, PyObject
*args
)
1982 switch(PyTuple_Size(args
)) {
1984 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&ch
)) return NULL
;
1987 PyErr_SetString(PyExc_TypeError
, "meta requires 1 argument");
1991 return PyCursesCheckERR(meta(stdscr
, ch
), "meta");
1994 #ifdef NCURSES_MOUSE_VERSION
1996 PyCurses_MouseInterval(PyObject
*self
, PyObject
*args
)
2001 if (!PyArg_ParseTuple(args
,"i;interval",&interval
))
2003 return PyCursesCheckERR(mouseinterval(interval
), "mouseinterval");
2007 PyCurses_MouseMask(PyObject
*self
, PyObject
*args
)
2010 mmask_t oldmask
, availmask
;
2013 if (!PyArg_ParseTuple(args
,"i;mousemask",&newmask
))
2015 availmask
= mousemask(newmask
, &oldmask
);
2016 return Py_BuildValue("(ll)", (long)availmask
, (long)oldmask
);
2021 PyCurses_Napms(PyObject
*self
, PyObject
*args
)
2026 if (!PyArg_ParseTuple(args
, "i;ms", &ms
)) return NULL
;
2028 return Py_BuildValue("i", napms(ms
));
2033 PyCurses_NewPad(PyObject
*self
, PyObject
*args
)
2040 if (!PyArg_ParseTuple(args
,"ii;nlines,ncols",&nlines
,&ncols
)) return NULL
;
2042 win
= newpad(nlines
, ncols
);
2045 PyErr_SetString(PyCursesError
, catchall_NULL
);
2049 return (PyObject
*)PyCursesWindow_New(win
);
2053 PyCurses_NewWindow(PyObject
*self
, PyObject
*args
)
2056 int nlines
, ncols
, begin_y
=0, begin_x
=0;
2060 switch (PyTuple_Size(args
)) {
2062 if (!PyArg_ParseTuple(args
,"ii;nlines,ncols",&nlines
,&ncols
))
2066 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
2067 &nlines
,&ncols
,&begin_y
,&begin_x
))
2071 PyErr_SetString(PyExc_TypeError
, "newwin requires 2 or 4 arguments");
2075 win
= newwin(nlines
,ncols
,begin_y
,begin_x
);
2077 PyErr_SetString(PyCursesError
, catchall_NULL
);
2081 return (PyObject
*)PyCursesWindow_New(win
);
2085 PyCurses_Pair_Content(PyObject
*self
, PyObject
*args
)
2090 PyCursesInitialisedColor
2092 switch(PyTuple_Size(args
)) {
2094 if (!PyArg_ParseTuple(args
, "h;pair", &pair
)) return NULL
;
2097 PyErr_SetString(PyExc_TypeError
, "pair_content requires 1 argument");
2101 if (!pair_content(pair
, &f
, &b
)) {
2102 PyErr_SetString(PyCursesError
,
2103 "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
2107 return Py_BuildValue("(ii)", f
, b
);
2111 PyCurses_pair_number(PyObject
*self
, PyObject
*args
)
2116 PyCursesInitialisedColor
2118 switch(PyTuple_Size(args
)) {
2120 if (!PyArg_ParseTuple(args
, "i;pairvalue", &n
)) return NULL
;
2123 PyErr_SetString(PyExc_TypeError
,
2124 "pair_number requires 1 argument");
2128 return PyInt_FromLong((long) ((n
& A_COLOR
) >> 8));
2132 PyCurses_Putp(PyObject
*self
, PyObject
*args
)
2136 if (!PyArg_ParseTuple(args
,"s;str", &str
)) return NULL
;
2137 return PyCursesCheckERR(putp(str
), "putp");
2141 PyCurses_QiFlush(PyObject
*self
, PyObject
*args
)
2147 switch(PyTuple_Size(args
)) {
2153 if (!PyArg_ParseTuple(args
, "i;True(1) or False(0)", &flag
)) return NULL
;
2154 if (flag
) qiflush();
2159 PyErr_SetString(PyExc_TypeError
, "qiflush requires 0 or 1 arguments");
2165 PyCurses_setsyx(PyObject
*self
, PyObject
*args
)
2171 if (PyTuple_Size(args
)!=2) {
2172 PyErr_SetString(PyExc_TypeError
, "setsyx requires 2 arguments");
2176 if (!PyArg_ParseTuple(args
, "ii;y, x", &y
, &x
)) return NULL
;
2185 PyCurses_Start_Color(PyObject
*self
)
2192 code
= start_color();
2194 initialisedcolors
= TRUE
;
2195 c
= PyInt_FromLong((long) COLORS
);
2196 PyDict_SetItemString(ModDict
, "COLORS", c
);
2198 cp
= PyInt_FromLong((long) COLOR_PAIRS
);
2199 PyDict_SetItemString(ModDict
, "COLOR_PAIRS", cp
);
2204 PyErr_SetString(PyCursesError
, "start_color() returned ERR");
2210 PyCurses_tigetflag(PyObject
*self
, PyObject
*args
)
2214 PyCursesSetupTermCalled
;
2216 if (!PyArg_ParseTuple(args
, "z", &capname
))
2219 return PyInt_FromLong( (long) tigetflag( capname
) );
2223 PyCurses_tigetnum(PyObject
*self
, PyObject
*args
)
2227 PyCursesSetupTermCalled
;
2229 if (!PyArg_ParseTuple(args
, "z", &capname
))
2232 return PyInt_FromLong( (long) tigetnum( capname
) );
2236 PyCurses_tigetstr(PyObject
*self
, PyObject
*args
)
2240 PyCursesSetupTermCalled
;
2242 if (!PyArg_ParseTuple(args
, "z", &capname
))
2245 capname
= tigetstr( capname
);
2246 if (capname
== 0 || capname
== (char*) -1) {
2250 return PyString_FromString( capname
);
2254 PyCurses_tparm(PyObject
*self
, PyObject
*args
)
2257 char* result
= NULL
;
2258 int i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
,i9
;
2260 PyCursesSetupTermCalled
;
2262 if (!PyArg_ParseTuple(args
, "s|iiiiiiiii:tparm",
2263 &fmt
, &i1
, &i2
, &i3
, &i4
,
2264 &i5
, &i6
, &i7
, &i8
, &i9
)) {
2268 #if defined(__hpux) || defined(_AIX)
2269 /* tparm is declared with 10 arguments on a few platforms
2270 (HP-UX, AIX). If this proves to be a problem on other
2271 platforms as well, perhaps an autoconf test should be
2272 added to determine whether tparm can be called with a
2273 variable number of arguments. Perhaps the other arguments
2274 should be initialized in this case also. */
2275 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
,i9
);
2277 switch (PyTuple_GET_SIZE(args
)) {
2279 result
= tparm(fmt
);
2282 result
= tparm(fmt
,i1
);
2285 result
= tparm(fmt
,i1
,i2
);
2288 result
= tparm(fmt
,i1
,i2
,i3
);
2291 result
= tparm(fmt
,i1
,i2
,i3
,i4
);
2294 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
);
2297 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
);
2300 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
);
2303 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
);
2306 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
,i9
);
2309 #endif /* defined(__hpux) || defined(_AIX) */
2310 return PyString_FromString(result
);
2314 PyCurses_TypeAhead(PyObject
*self
, PyObject
*args
)
2320 if (!PyArg_ParseTuple(args
,"i;fd",&fd
)) return NULL
;
2322 PyCursesCheckERR(typeahead( fd
), "typeahead");
2328 PyCurses_UnCtrl(PyObject
*self
, PyObject
*args
)
2335 if (!PyArg_ParseTuple(args
,"O;ch or int",&temp
)) return NULL
;
2337 if (PyInt_Check(temp
))
2338 ch
= (chtype
) PyInt_AsLong(temp
);
2339 else if (PyString_Check(temp
))
2340 ch
= (chtype
) *PyString_AsString(temp
);
2342 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2346 return PyString_FromString(unctrl(ch
));
2350 PyCurses_UngetCh(PyObject
*self
, PyObject
*args
)
2357 if (!PyArg_ParseTuple(args
,"O;ch or int",&temp
)) return NULL
;
2359 if (PyInt_Check(temp
))
2360 ch
= (chtype
) PyInt_AsLong(temp
);
2361 else if (PyString_Check(temp
))
2362 ch
= (chtype
) *PyString_AsString(temp
);
2364 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2368 return PyCursesCheckERR(ungetch(ch
), "ungetch");
2372 PyCurses_Use_Env(PyObject
*self
, PyObject
*args
)
2378 switch(PyTuple_Size(args
)) {
2380 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&flag
))
2384 PyErr_SetString(PyExc_TypeError
, "use_env requires 1 argument");
2392 /* List of functions defined in the module */
2394 static PyMethodDef PyCurses_methods
[] = {
2395 {"baudrate", (PyCFunction
)PyCurses_baudrate
, METH_NOARGS
},
2396 {"beep", (PyCFunction
)PyCurses_beep
, METH_NOARGS
},
2397 {"can_change_color", (PyCFunction
)PyCurses_can_change_color
, METH_NOARGS
},
2398 {"cbreak", (PyCFunction
)PyCurses_cbreak
, METH_VARARGS
},
2399 {"color_content", (PyCFunction
)PyCurses_Color_Content
, METH_VARARGS
},
2400 {"color_pair", (PyCFunction
)PyCurses_color_pair
, METH_VARARGS
},
2401 {"curs_set", (PyCFunction
)PyCurses_Curs_Set
, METH_VARARGS
},
2402 {"def_prog_mode", (PyCFunction
)PyCurses_def_prog_mode
, METH_NOARGS
},
2403 {"def_shell_mode", (PyCFunction
)PyCurses_def_shell_mode
, METH_NOARGS
},
2404 {"delay_output", (PyCFunction
)PyCurses_Delay_Output
, METH_VARARGS
},
2405 {"doupdate", (PyCFunction
)PyCurses_doupdate
, METH_NOARGS
},
2406 {"echo", (PyCFunction
)PyCurses_echo
, METH_VARARGS
},
2407 {"endwin", (PyCFunction
)PyCurses_endwin
, METH_NOARGS
},
2408 {"erasechar", (PyCFunction
)PyCurses_EraseChar
, METH_NOARGS
},
2409 {"filter", (PyCFunction
)PyCurses_filter
, METH_NOARGS
},
2410 {"flash", (PyCFunction
)PyCurses_flash
, METH_NOARGS
},
2411 {"flushinp", (PyCFunction
)PyCurses_flushinp
, METH_NOARGS
},
2412 #ifdef NCURSES_MOUSE_VERSION
2413 {"getmouse", (PyCFunction
)PyCurses_GetMouse
, METH_NOARGS
},
2414 {"ungetmouse", (PyCFunction
)PyCurses_UngetMouse
, METH_VARARGS
},
2416 {"getsyx", (PyCFunction
)PyCurses_getsyx
, METH_NOARGS
},
2417 {"getwin", (PyCFunction
)PyCurses_GetWin
, METH_O
},
2418 {"has_colors", (PyCFunction
)PyCurses_has_colors
, METH_NOARGS
},
2419 {"has_ic", (PyCFunction
)PyCurses_has_ic
, METH_NOARGS
},
2420 {"has_il", (PyCFunction
)PyCurses_has_il
, METH_NOARGS
},
2421 #ifndef STRICT_SYSV_CURSES
2422 {"has_key", (PyCFunction
)PyCurses_has_key
, METH_VARARGS
},
2424 {"halfdelay", (PyCFunction
)PyCurses_HalfDelay
, METH_VARARGS
},
2425 {"init_color", (PyCFunction
)PyCurses_Init_Color
, METH_VARARGS
},
2426 {"init_pair", (PyCFunction
)PyCurses_Init_Pair
, METH_VARARGS
},
2427 {"initscr", (PyCFunction
)PyCurses_InitScr
, METH_NOARGS
},
2428 {"intrflush", (PyCFunction
)PyCurses_IntrFlush
, METH_VARARGS
},
2429 {"isendwin", (PyCFunction
)PyCurses_isendwin
, METH_NOARGS
},
2430 #if !defined(__NetBSD__)
2431 {"keyname", (PyCFunction
)PyCurses_KeyName
, METH_VARARGS
},
2433 {"killchar", (PyCFunction
)PyCurses_KillChar
, METH_NOARGS
},
2434 {"longname", (PyCFunction
)PyCurses_longname
, METH_NOARGS
},
2435 {"meta", (PyCFunction
)PyCurses_Meta
, METH_VARARGS
},
2436 #ifdef NCURSES_MOUSE_VERSION
2437 {"mouseinterval", (PyCFunction
)PyCurses_MouseInterval
, METH_VARARGS
},
2438 {"mousemask", (PyCFunction
)PyCurses_MouseMask
, METH_VARARGS
},
2440 {"napms", (PyCFunction
)PyCurses_Napms
, METH_VARARGS
},
2441 {"newpad", (PyCFunction
)PyCurses_NewPad
, METH_VARARGS
},
2442 {"newwin", (PyCFunction
)PyCurses_NewWindow
, METH_VARARGS
},
2443 {"nl", (PyCFunction
)PyCurses_nl
, METH_VARARGS
},
2444 {"nocbreak", (PyCFunction
)PyCurses_nocbreak
, METH_NOARGS
},
2445 {"noecho", (PyCFunction
)PyCurses_noecho
, METH_NOARGS
},
2446 {"nonl", (PyCFunction
)PyCurses_nonl
, METH_NOARGS
},
2447 {"noqiflush", (PyCFunction
)PyCurses_noqiflush
, METH_NOARGS
},
2448 {"noraw", (PyCFunction
)PyCurses_noraw
, METH_NOARGS
},
2449 {"pair_content", (PyCFunction
)PyCurses_Pair_Content
, METH_VARARGS
},
2450 {"pair_number", (PyCFunction
)PyCurses_pair_number
, METH_VARARGS
},
2451 {"putp", (PyCFunction
)PyCurses_Putp
, METH_VARARGS
},
2452 {"qiflush", (PyCFunction
)PyCurses_QiFlush
, METH_VARARGS
},
2453 {"raw", (PyCFunction
)PyCurses_raw
, METH_VARARGS
},
2454 {"reset_prog_mode", (PyCFunction
)PyCurses_reset_prog_mode
, METH_NOARGS
},
2455 {"reset_shell_mode", (PyCFunction
)PyCurses_reset_shell_mode
, METH_NOARGS
},
2456 {"resetty", (PyCFunction
)PyCurses_resetty
, METH_NOARGS
},
2457 {"savetty", (PyCFunction
)PyCurses_savetty
, METH_NOARGS
},
2458 {"setsyx", (PyCFunction
)PyCurses_setsyx
, METH_VARARGS
},
2459 {"setupterm", (PyCFunction
)PyCurses_setupterm
,
2460 METH_VARARGS
|METH_KEYWORDS
},
2461 {"start_color", (PyCFunction
)PyCurses_Start_Color
, METH_NOARGS
},
2462 {"termattrs", (PyCFunction
)PyCurses_termattrs
, METH_NOARGS
},
2463 {"termname", (PyCFunction
)PyCurses_termname
, METH_NOARGS
},
2464 {"tigetflag", (PyCFunction
)PyCurses_tigetflag
, METH_VARARGS
},
2465 {"tigetnum", (PyCFunction
)PyCurses_tigetnum
, METH_VARARGS
},
2466 {"tigetstr", (PyCFunction
)PyCurses_tigetstr
, METH_VARARGS
},
2467 {"tparm", (PyCFunction
)PyCurses_tparm
, METH_VARARGS
},
2468 {"typeahead", (PyCFunction
)PyCurses_TypeAhead
, METH_VARARGS
},
2469 {"unctrl", (PyCFunction
)PyCurses_UnCtrl
, METH_VARARGS
},
2470 {"ungetch", (PyCFunction
)PyCurses_UngetCh
, METH_VARARGS
},
2471 {"use_env", (PyCFunction
)PyCurses_Use_Env
, METH_VARARGS
},
2472 {NULL
, NULL
} /* sentinel */
2475 /* Initialization function for the module */
2480 PyObject
*m
, *d
, *v
, *c_api_object
;
2481 static void *PyCurses_API
[PyCurses_API_pointers
];
2483 /* Initialize object type */
2484 PyCursesWindow_Type
.ob_type
= &PyType_Type
;
2486 /* Initialize the C API pointer array */
2487 PyCurses_API
[0] = (void *)&PyCursesWindow_Type
;
2488 PyCurses_API
[1] = (void *)func_PyCursesSetupTermCalled
;
2489 PyCurses_API
[2] = (void *)func_PyCursesInitialised
;
2490 PyCurses_API
[3] = (void *)func_PyCursesInitialisedColor
;
2492 /* Create the module and add the functions */
2493 m
= Py_InitModule("_curses", PyCurses_methods
);
2495 /* Add some symbolic constants to the module */
2496 d
= PyModule_GetDict(m
);
2497 ModDict
= d
; /* For PyCurses_InitScr to use later */
2499 /* Add a CObject for the C API */
2500 c_api_object
= PyCObject_FromVoidPtr((void *)PyCurses_API
, NULL
);
2501 PyDict_SetItemString(d
, "_C_API", c_api_object
);
2502 Py_DECREF(c_api_object
);
2504 /* For exception curses.error */
2505 PyCursesError
= PyErr_NewException("_curses.error", NULL
, NULL
);
2506 PyDict_SetItemString(d
, "error", PyCursesError
);
2508 /* Make the version available */
2509 v
= PyString_FromString(PyCursesVersion
);
2510 PyDict_SetItemString(d
, "version", v
);
2511 PyDict_SetItemString(d
, "__version__", v
);
2514 SetDictInt("ERR", ERR
);
2515 SetDictInt("OK", OK
);
2517 /* Here are some attributes you can add to chars to print */
2519 SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES
);
2520 SetDictInt("A_NORMAL", A_NORMAL
);
2521 SetDictInt("A_STANDOUT", A_STANDOUT
);
2522 SetDictInt("A_UNDERLINE", A_UNDERLINE
);
2523 SetDictInt("A_REVERSE", A_REVERSE
);
2524 SetDictInt("A_BLINK", A_BLINK
);
2525 SetDictInt("A_DIM", A_DIM
);
2526 SetDictInt("A_BOLD", A_BOLD
);
2527 SetDictInt("A_ALTCHARSET", A_ALTCHARSET
);
2528 #if !defined(__NetBSD__)
2529 SetDictInt("A_INVIS", A_INVIS
);
2531 SetDictInt("A_PROTECT", A_PROTECT
);
2532 SetDictInt("A_CHARTEXT", A_CHARTEXT
);
2533 SetDictInt("A_COLOR", A_COLOR
);
2535 /* The following are never available with strict SYSV curses */
2537 SetDictInt("A_HORIZONTAL", A_HORIZONTAL
);
2540 SetDictInt("A_LEFT", A_LEFT
);
2543 SetDictInt("A_LOW", A_LOW
);
2546 SetDictInt("A_RIGHT", A_RIGHT
);
2549 SetDictInt("A_TOP", A_TOP
);
2552 SetDictInt("A_VERTICAL", A_VERTICAL
);
2555 SetDictInt("COLOR_BLACK", COLOR_BLACK
);
2556 SetDictInt("COLOR_RED", COLOR_RED
);
2557 SetDictInt("COLOR_GREEN", COLOR_GREEN
);
2558 SetDictInt("COLOR_YELLOW", COLOR_YELLOW
);
2559 SetDictInt("COLOR_BLUE", COLOR_BLUE
);
2560 SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA
);
2561 SetDictInt("COLOR_CYAN", COLOR_CYAN
);
2562 SetDictInt("COLOR_WHITE", COLOR_WHITE
);
2564 #ifdef NCURSES_MOUSE_VERSION
2565 /* Mouse-related constants */
2566 SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED
);
2567 SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED
);
2568 SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED
);
2569 SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED
);
2570 SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED
);
2572 SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED
);
2573 SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED
);
2574 SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED
);
2575 SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED
);
2576 SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED
);
2578 SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED
);
2579 SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED
);
2580 SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED
);
2581 SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED
);
2582 SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED
);
2584 SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED
);
2585 SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED
);
2586 SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED
);
2587 SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED
);
2588 SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED
);
2590 SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT
);
2591 SetDictInt("BUTTON_CTRL", BUTTON_CTRL
);
2592 SetDictInt("BUTTON_ALT", BUTTON_ALT
);
2594 SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS
);
2595 SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION
);
2597 /* Now set everything up for KEY_ variables */
2602 #if !defined(__NetBSD__)
2603 for (key
=KEY_MIN
;key
< KEY_MAX
; key
++) {
2604 key_n
= (char *)keyname(key
);
2605 if (key_n
== NULL
|| strcmp(key_n
,"UNKNOWN KEY")==0)
2607 if (strncmp(key_n
,"KEY_F(",6)==0) {
2609 key_n2
= malloc(strlen(key_n
)+1);
2613 if (*p1
!= '(' && *p1
!= ')') {
2622 PyDict_SetItemString(d
,key_n2
,PyInt_FromLong((long) key
));
2623 if (key_n2
!= key_n
)
2627 SetDictInt("KEY_MIN", KEY_MIN
);
2628 SetDictInt("KEY_MAX", KEY_MAX
);