2 * This is a curses module for Python.
4 * Based on prior work by Lance Ellinghaus and Oliver Andrich
5 * Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse,
6 * Cathedral City, California Republic, United States of America.
8 * Version 1.5b1, heavily extended for ncurses by Oliver Andrich:
9 * Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany.
11 * Tidied for Python 1.6, and currently maintained by <amk@amk.ca>.
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this source file to use, copy, modify, merge, or publish it
15 * subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or in any new file that contains a substantial portion of
21 * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF
22 * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
23 * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES
24 * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
25 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE
27 * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL,
28 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
29 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR
30 * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
31 * PERFORMANCE OF THIS SOFTWARE.
38 A number of SysV or ncurses functions don't have wrappers yet; if you need
39 a given function, add it and send a patch. Here's a list of currently
40 unsupported functions:
42 addchnstr addchstr chgat color_set define_key
43 del_curterm delscreen dupwin inchnstr inchstr innstr keyok
44 mcprint mvaddchnstr mvaddchstr mvchgat mvcur mvinchnstr
45 mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
46 mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr newterm
47 resizeterm restartterm ripoffline scr_dump
48 scr_init scr_restore scr_set scrl set_curterm set_term setterm
49 tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
50 use_default_colors vidattr vidputs waddchnstr waddchstr wchgat
51 wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
54 slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
55 slk_attron slk_attrset slk_clear slk_color slk_init slk_label
56 slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
58 Menu extension (ncurses and probably SYSV):
59 current_item free_item free_menu item_count item_description
60 item_index item_init item_name item_opts item_opts_off
61 item_opts_on item_term item_userptr item_value item_visible
62 menu_back menu_driver menu_fore menu_format menu_grey
63 menu_init menu_items menu_mark menu_opts menu_opts_off
64 menu_opts_on menu_pad menu_pattern menu_request_by_name
65 menu_request_name menu_spacing menu_sub menu_term menu_userptr
66 menu_win new_item new_menu pos_menu_cursor post_menu
67 scale_menu set_current_item set_item_init set_item_opts
68 set_item_term set_item_userptr set_item_value set_menu_back
69 set_menu_fore set_menu_format set_menu_grey set_menu_init
70 set_menu_items set_menu_mark set_menu_opts set_menu_pad
71 set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
72 set_menu_userptr set_menu_win set_top_row top_row unpost_menu
74 Form extension (ncurses and probably SYSV):
75 current_field data_ahead data_behind dup_field
76 dynamic_fieldinfo field_arg field_back field_buffer
77 field_count field_fore field_index field_info field_init
78 field_just field_opts field_opts_off field_opts_on field_pad
79 field_status field_term field_type field_userptr form_driver
80 form_fields form_init form_opts form_opts_off form_opts_on
81 form_page form_request_by_name form_request_name form_sub
82 form_term form_userptr form_win free_field free_form
83 link_field link_fieldtype move_field new_field new_form
84 new_page pos_form_cursor post_form scale_form
85 set_current_field set_field_back set_field_buffer
86 set_field_fore set_field_init set_field_just set_field_opts
87 set_field_pad set_field_status set_field_term set_field_type
88 set_field_userptr set_fieldtype_arg set_fieldtype_choice
89 set_form_fields set_form_init set_form_opts set_form_page
90 set_form_sub set_form_term set_form_userptr set_form_win
91 set_max_field set_new_page unpost_form
98 char *PyCursesVersion
= "2.2";
105 #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
109 #define STRICT_SYSV_CURSES
112 #define CURSES_MODULE
113 #include "py_curses.h"
115 /* These prototypes are in <term.h>, but including this header
116 #defines many common symbols (such as "lines") which breaks the
117 curses module in other ways. So the code will just specify
118 explicit prototypes here. */
119 extern int setupterm(char *,int,int *);
124 #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
125 #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
126 typedef chtype attr_t
; /* No attr_t type is available */
130 #define STRICT_SYSV_CURSES
133 /* Definition of exception curses.error */
135 static PyObject
*PyCursesError
;
137 /* Tells whether setupterm() has been called to initialise terminfo. */
138 static int initialised_setupterm
= FALSE
;
140 /* Tells whether initscr() has been called to initialise curses. */
141 static int initialised
= FALSE
;
143 /* Tells whether start_color() has been called to initialise color usage. */
144 static int initialisedcolors
= FALSE
;
147 #define PyCursesSetupTermCalled \
148 if (initialised_setupterm != TRUE) { \
149 PyErr_SetString(PyCursesError, \
150 "must call (at least) setupterm() first"); \
153 #define PyCursesInitialised \
154 if (initialised != TRUE) { \
155 PyErr_SetString(PyCursesError, \
156 "must call initscr() first"); \
159 #define PyCursesInitialisedColor \
160 if (initialisedcolors != TRUE) { \
161 PyErr_SetString(PyCursesError, \
162 "must call start_color() first"); \
165 /* Utility Functions */
168 * Check the return code from a curses function and return None
169 * or raise an exception as appropriate. These are exported using the
174 PyCursesCheckERR(int code
, char *fname
)
181 PyErr_SetString(PyCursesError
, catchall_ERR
);
183 PyErr_Format(PyCursesError
, "%s() returned ERR", fname
);
190 PyCurses_ConvertToChtype(PyObject
*obj
, chtype
*ch
)
192 if (PyInt_Check(obj
)) {
193 *ch
= (chtype
) PyInt_AsLong(obj
);
194 } else if(PyString_Check(obj
)
195 && (PyString_Size(obj
) == 1)) {
196 *ch
= (chtype
) *PyString_AsString(obj
);
203 /* Function versions of the 3 functions for tested whether curses has been
204 initialised or not. */
206 static int func_PyCursesSetupTermCalled(void)
208 PyCursesSetupTermCalled
;
212 static int func_PyCursesInitialised(void)
218 static int func_PyCursesInitialisedColor(void)
220 PyCursesInitialisedColor
;
224 /*****************************************************************************
226 ******************************************************************************/
228 /* Definition of the window type */
230 PyTypeObject PyCursesWindow_Type
;
232 /* Function prototype macros for Window object
235 TYPE - parameter Type
236 ERGSTR - format string for construction of the return value
237 PARSESTR - format string for argument parsing
240 #define Window_NoArgNoReturnFunction(X) \
241 static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
242 { return PyCursesCheckERR(X(self->win), # X); }
244 #define Window_NoArgTrueFalseFunction(X) \
245 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
247 if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
248 else { Py_INCREF(Py_True); return Py_True; } }
250 #define Window_NoArgNoReturnVoidFunction(X) \
251 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
253 X(self->win); Py_INCREF(Py_None); return Py_None; }
255 #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
256 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
259 X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
261 #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
262 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
265 if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
266 X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
268 #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
269 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
272 if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
273 return PyCursesCheckERR(X(self->win, arg1), # X); }
275 #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
276 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
279 if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
280 return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
282 /* ------------- WINDOW routines --------------- */
284 Window_NoArgNoReturnFunction(untouchwin
)
285 Window_NoArgNoReturnFunction(touchwin
)
286 Window_NoArgNoReturnFunction(redrawwin
)
287 Window_NoArgNoReturnFunction(winsertln
)
288 Window_NoArgNoReturnFunction(werase
)
289 Window_NoArgNoReturnFunction(wdeleteln
)
291 Window_NoArgTrueFalseFunction(is_wintouched
)
293 Window_NoArgNoReturnVoidFunction(wsyncup
)
294 Window_NoArgNoReturnVoidFunction(wsyncdown
)
295 Window_NoArgNoReturnVoidFunction(wstandend
)
296 Window_NoArgNoReturnVoidFunction(wstandout
)
297 Window_NoArgNoReturnVoidFunction(wcursyncup
)
298 Window_NoArgNoReturnVoidFunction(wclrtoeol
)
299 Window_NoArgNoReturnVoidFunction(wclrtobot
)
300 Window_NoArgNoReturnVoidFunction(wclear
)
302 Window_OneArgNoReturnVoidFunction(idcok
, int, "i;True(1) or False(0)")
303 Window_OneArgNoReturnVoidFunction(immedok
, int, "i;True(1) or False(0)")
304 Window_OneArgNoReturnVoidFunction(wtimeout
, int, "i;delay")
306 Window_NoArg2TupleReturnFunction(getyx
, int, "ii")
307 Window_NoArg2TupleReturnFunction(getbegyx
, int, "ii")
308 Window_NoArg2TupleReturnFunction(getmaxyx
, int, "ii")
309 Window_NoArg2TupleReturnFunction(getparyx
, int, "ii")
311 Window_OneArgNoReturnFunction(wattron
, attr_t
, "l;attr")
312 Window_OneArgNoReturnFunction(wattroff
, attr_t
, "l;attr")
313 Window_OneArgNoReturnFunction(wattrset
, attr_t
, "l;attr")
314 Window_OneArgNoReturnFunction(clearok
, int, "i;True(1) or False(0)")
315 Window_OneArgNoReturnFunction(idlok
, int, "i;True(1) or False(0)")
316 #if defined(__NetBSD__)
317 Window_OneArgNoReturnVoidFunction(keypad
, int, "i;True(1) or False(0)")
319 Window_OneArgNoReturnFunction(keypad
, int, "i;True(1) or False(0)")
321 Window_OneArgNoReturnFunction(leaveok
, int, "i;True(1) or False(0)")
322 #if defined(__NetBSD__)
323 Window_OneArgNoReturnVoidFunction(nodelay
, int, "i;True(1) or False(0)")
325 Window_OneArgNoReturnFunction(nodelay
, int, "i;True(1) or False(0)")
327 Window_OneArgNoReturnFunction(notimeout
, int, "i;True(1) or False(0)")
328 Window_OneArgNoReturnFunction(scrollok
, int, "i;True(1) or False(0)")
329 Window_OneArgNoReturnFunction(winsdelln
, int, "i;nlines")
330 Window_OneArgNoReturnFunction(syncok
, int, "i;True(1) or False(0)")
332 Window_TwoArgNoReturnFunction(mvwin
, int, "ii;y,x")
333 Window_TwoArgNoReturnFunction(mvderwin
, int, "ii;y,x")
334 Window_TwoArgNoReturnFunction(wmove
, int, "ii;y,x")
335 #ifndef STRICT_SYSV_CURSES
336 Window_TwoArgNoReturnFunction(wresize
, int, "ii;lines,columns")
339 /* Allocation and deallocation of Window Objects */
342 PyCursesWindow_New(WINDOW
*win
)
344 PyCursesWindowObject
*wo
;
346 wo
= PyObject_NEW(PyCursesWindowObject
, &PyCursesWindow_Type
);
347 if (wo
== NULL
) return NULL
;
349 return (PyObject
*)wo
;
353 PyCursesWindow_Dealloc(PyCursesWindowObject
*wo
)
355 if (wo
->win
!= stdscr
) delwin(wo
->win
);
359 /* Addch, Addstr, Addnstr */
362 PyCursesWindow_AddCh(PyCursesWindowObject
*self
, PyObject
*args
)
364 int rtn
, x
, y
, use_xy
= FALSE
;
367 attr_t attr
= A_NORMAL
;
369 switch (PyTuple_Size(args
)) {
371 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
375 if (!PyArg_ParseTuple(args
, "Ol;ch or int,attr", &temp
, &attr
))
379 if (!PyArg_ParseTuple(args
,"iiO;y,x,ch or int", &y
, &x
, &temp
))
384 if (!PyArg_ParseTuple(args
,"iiOl;y,x,ch or int, attr",
385 &y
, &x
, &temp
, &attr
))
390 PyErr_SetString(PyExc_TypeError
, "addch requires 1 to 4 arguments");
394 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
395 PyErr_SetString(PyExc_TypeError
, "argument 1 or 3 must be a ch or an int");
400 rtn
= mvwaddch(self
->win
,y
,x
, ch
| attr
);
402 rtn
= waddch(self
->win
, ch
| attr
);
404 return PyCursesCheckERR(rtn
, "addch");
408 PyCursesWindow_AddStr(PyCursesWindowObject
*self
, PyObject
*args
)
413 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
414 int use_xy
= FALSE
, use_attr
= FALSE
;
416 switch (PyTuple_Size(args
)) {
418 if (!PyArg_ParseTuple(args
,"s;str", &str
))
422 if (!PyArg_ParseTuple(args
,"sl;str,attr", &str
, &attr
))
427 if (!PyArg_ParseTuple(args
,"iis;int,int,str", &y
, &x
, &str
))
432 if (!PyArg_ParseTuple(args
,"iisl;int,int,str,attr", &y
, &x
, &str
, &attr
))
434 use_xy
= use_attr
= TRUE
;
437 PyErr_SetString(PyExc_TypeError
, "addstr requires 1 to 4 arguments");
441 if (use_attr
== TRUE
) {
442 attr_old
= getattrs(self
->win
);
443 wattrset(self
->win
,attr
);
446 rtn
= mvwaddstr(self
->win
,y
,x
,str
);
448 rtn
= waddstr(self
->win
,str
);
449 if (use_attr
== TRUE
)
450 wattrset(self
->win
,attr_old
);
451 return PyCursesCheckERR(rtn
, "addstr");
455 PyCursesWindow_AddNStr(PyCursesWindowObject
*self
, PyObject
*args
)
459 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
460 int use_xy
= FALSE
, use_attr
= FALSE
;
462 switch (PyTuple_Size(args
)) {
464 if (!PyArg_ParseTuple(args
,"si;str,n", &str
, &n
))
468 if (!PyArg_ParseTuple(args
,"sil;str,n,attr", &str
, &n
, &attr
))
473 if (!PyArg_ParseTuple(args
,"iisi;y,x,str,n", &y
, &x
, &str
, &n
))
478 if (!PyArg_ParseTuple(args
,"iisil;y,x,str,n,attr", &y
, &x
, &str
, &n
, &attr
))
480 use_xy
= use_attr
= TRUE
;
483 PyErr_SetString(PyExc_TypeError
, "addnstr requires 2 to 5 arguments");
487 if (use_attr
== TRUE
) {
488 attr_old
= getattrs(self
->win
);
489 wattrset(self
->win
,attr
);
492 rtn
= mvwaddnstr(self
->win
,y
,x
,str
,n
);
494 rtn
= waddnstr(self
->win
,str
,n
);
495 if (use_attr
== TRUE
)
496 wattrset(self
->win
,attr_old
);
497 return PyCursesCheckERR(rtn
, "addnstr");
501 PyCursesWindow_Bkgd(PyCursesWindowObject
*self
, PyObject
*args
)
505 attr_t attr
= A_NORMAL
;
507 switch (PyTuple_Size(args
)) {
509 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
513 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &attr
))
517 PyErr_SetString(PyExc_TypeError
, "bkgd requires 1 or 2 arguments");
521 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
522 PyErr_SetString(PyExc_TypeError
, "argument 1 or 3 must be a ch or an int");
526 return PyCursesCheckERR(wbkgd(self
->win
, bkgd
| attr
), "bkgd");
530 PyCursesWindow_BkgdSet(PyCursesWindowObject
*self
, PyObject
*args
)
534 attr_t attr
= A_NORMAL
;
536 switch (PyTuple_Size(args
)) {
538 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
542 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &attr
))
546 PyErr_SetString(PyExc_TypeError
, "bkgdset requires 1 or 2 arguments");
550 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
551 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
555 wbkgdset(self
->win
, bkgd
| attr
);
556 return PyCursesCheckERR(0, "bkgdset");
560 PyCursesWindow_Border(PyCursesWindowObject
*self
, PyObject
*args
)
566 /* Clear the array of parameters */
572 if (!PyArg_ParseTuple(args
,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
573 &temp
[0], &temp
[1], &temp
[2], &temp
[3],
574 &temp
[4], &temp
[5], &temp
[6], &temp
[7]))
578 if (temp
[i
] != NULL
&& !PyCurses_ConvertToChtype(temp
[i
], &ch
[i
])) {
579 PyErr_Format(PyExc_TypeError
,
580 "argument %i must be a ch or an int", i
+1);
586 ch
[0], ch
[1], ch
[2], ch
[3],
587 ch
[4], ch
[5], ch
[6], ch
[7]);
593 PyCursesWindow_Box(PyCursesWindowObject
*self
, PyObject
*args
)
596 switch(PyTuple_Size(args
)){
599 if (!PyArg_ParseTuple(args
,"ll;vertint,horint", &ch1
, &ch2
))
602 box(self
->win
,ch1
,ch2
);
607 #if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
608 #define py_mvwdelch mvwdelch
610 int py_mvwdelch(WINDOW
*w
, int y
, int x
)
613 /* On HP/UX, mvwdelch already returns. On other systems,
614 we may well run into this return statement. */
621 PyCursesWindow_DelCh(PyCursesWindowObject
*self
, PyObject
*args
)
626 switch (PyTuple_Size(args
)) {
628 rtn
= wdelch(self
->win
);
631 if (!PyArg_ParseTuple(args
,"ii;y,x", &y
, &x
))
633 rtn
= py_mvwdelch(self
->win
,y
,x
);
636 PyErr_SetString(PyExc_TypeError
, "delch requires 0 or 2 arguments");
639 return PyCursesCheckERR(rtn
, "[mv]wdelch");
643 PyCursesWindow_DerWin(PyCursesWindowObject
*self
, PyObject
*args
)
646 int nlines
, ncols
, begin_y
, begin_x
;
650 switch (PyTuple_Size(args
)) {
652 if (!PyArg_ParseTuple(args
,"ii;begin_y,begin_x",&begin_y
,&begin_x
))
656 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
657 &nlines
,&ncols
,&begin_y
,&begin_x
))
661 PyErr_SetString(PyExc_TypeError
, "derwin requires 2 or 4 arguments");
665 win
= derwin(self
->win
,nlines
,ncols
,begin_y
,begin_x
);
668 PyErr_SetString(PyCursesError
, catchall_NULL
);
672 return (PyObject
*)PyCursesWindow_New(win
);
676 PyCursesWindow_EchoChar(PyCursesWindowObject
*self
, PyObject
*args
)
680 attr_t attr
= A_NORMAL
;
682 switch (PyTuple_Size(args
)) {
684 if (!PyArg_ParseTuple(args
,"O;ch or int", &temp
))
688 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &attr
))
692 PyErr_SetString(PyExc_TypeError
, "echochar requires 1 or 2 arguments");
698 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
699 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
703 #ifdef WINDOW_HAS_FLAGS
704 if (self
->win
->_flags
& _ISPAD
)
705 return PyCursesCheckERR(pechochar(self
->win
, ch
| attr
),
709 return PyCursesCheckERR(wechochar(self
->win
, ch
| attr
),
713 #ifdef NCURSES_MOUSE_VERSION
715 PyCursesWindow_Enclose(PyCursesWindowObject
*self
, PyObject
*args
)
718 if (!PyArg_ParseTuple(args
,"ii;y,x", &y
, &x
))
721 return PyInt_FromLong( wenclose(self
->win
,y
,x
) );
726 PyCursesWindow_GetBkgd(PyCursesWindowObject
*self
)
728 return PyInt_FromLong((long) getbkgd(self
->win
));
732 PyCursesWindow_GetCh(PyCursesWindowObject
*self
, PyObject
*args
)
737 switch (PyTuple_Size(args
)) {
739 Py_BEGIN_ALLOW_THREADS
740 rtn
= wgetch(self
->win
);
744 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
746 Py_BEGIN_ALLOW_THREADS
747 rtn
= mvwgetch(self
->win
,y
,x
);
751 PyErr_SetString(PyExc_TypeError
, "getch requires 0 or 2 arguments");
754 return PyInt_FromLong((long)rtn
);
758 PyCursesWindow_GetKey(PyCursesWindowObject
*self
, PyObject
*args
)
763 switch (PyTuple_Size(args
)) {
765 Py_BEGIN_ALLOW_THREADS
766 rtn
= wgetch(self
->win
);
770 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
772 Py_BEGIN_ALLOW_THREADS
773 rtn
= mvwgetch(self
->win
,y
,x
);
777 PyErr_SetString(PyExc_TypeError
, "getkey requires 0 or 2 arguments");
781 /* getch() returns ERR in nodelay mode */
782 PyErr_SetString(PyCursesError
, "no input");
785 return Py_BuildValue("c", rtn
);
787 #if defined(__NetBSD__)
788 return PyString_FromString(unctrl(rtn
));
790 return PyString_FromString((char *)keyname(rtn
));
795 PyCursesWindow_GetStr(PyCursesWindowObject
*self
, PyObject
*args
)
798 char rtn
[1024]; /* This should be big enough.. I hope */
801 switch (PyTuple_Size(args
)) {
803 Py_BEGIN_ALLOW_THREADS
804 rtn2
= wgetstr(self
->win
,rtn
);
808 if (!PyArg_ParseTuple(args
,"i;n", &n
))
810 Py_BEGIN_ALLOW_THREADS
811 rtn2
= wgetnstr(self
->win
,rtn
,n
);
815 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
817 Py_BEGIN_ALLOW_THREADS
818 rtn2
= mvwgetstr(self
->win
,y
,x
,rtn
);
822 if (!PyArg_ParseTuple(args
,"iii;y,x,n", &y
, &x
, &n
))
824 #ifdef STRICT_SYSV_CURSES
826 Py_BEGIN_ALLOW_THREADS
827 rtn2
= wmove(self
->win
,y
,x
)==ERR
? ERR
:
828 wgetnstr(self
->win
, rtn
, n
);
831 Py_BEGIN_ALLOW_THREADS
832 rtn2
= mvwgetnstr(self
->win
, y
, x
, rtn
, n
);
837 PyErr_SetString(PyExc_TypeError
, "getstr requires 0 to 2 arguments");
842 return PyString_FromString(rtn
);
846 PyCursesWindow_Hline(PyCursesWindowObject
*self
, PyObject
*args
)
850 int n
, x
, y
, code
= OK
;
851 attr_t attr
= A_NORMAL
;
853 switch (PyTuple_Size(args
)) {
855 if (!PyArg_ParseTuple(args
, "Oi;ch or int,n", &temp
, &n
))
859 if (!PyArg_ParseTuple(args
, "Oil;ch or int,n,attr", &temp
, &n
, &attr
))
863 if (!PyArg_ParseTuple(args
, "iiOi;y,x,ch or int,n", &y
, &x
, &temp
, &n
))
865 code
= wmove(self
->win
, y
, x
);
868 if (!PyArg_ParseTuple(args
, "iiOil; y,x,ch or int,n,attr",
869 &y
, &x
, &temp
, &n
, &attr
))
871 code
= wmove(self
->win
, y
, x
);
874 PyErr_SetString(PyExc_TypeError
, "hline requires 2 to 5 arguments");
879 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
880 PyErr_SetString(PyExc_TypeError
,
881 "argument 1 or 3 must be a ch or an int");
884 return PyCursesCheckERR(whline(self
->win
, ch
| attr
, n
), "hline");
886 return PyCursesCheckERR(code
, "wmove");
890 PyCursesWindow_InsCh(PyCursesWindowObject
*self
, PyObject
*args
)
892 int rtn
, x
, y
, use_xy
= FALSE
;
895 attr_t attr
= A_NORMAL
;
897 switch (PyTuple_Size(args
)) {
899 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
903 if (!PyArg_ParseTuple(args
, "Ol;ch or int,attr", &temp
, &attr
))
907 if (!PyArg_ParseTuple(args
,"iiO;y,x,ch or int", &y
, &x
, &temp
))
912 if (!PyArg_ParseTuple(args
,"iiOl;y,x,ch or int, attr", &y
, &x
, &temp
, &attr
))
917 PyErr_SetString(PyExc_TypeError
, "insch requires 1 or 4 arguments");
921 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
922 PyErr_SetString(PyExc_TypeError
,
923 "argument 1 or 3 must be a ch or an int");
928 rtn
= mvwinsch(self
->win
,y
,x
, ch
| attr
);
930 rtn
= winsch(self
->win
, ch
| attr
);
932 return PyCursesCheckERR(rtn
, "insch");
936 PyCursesWindow_InCh(PyCursesWindowObject
*self
, PyObject
*args
)
940 switch (PyTuple_Size(args
)) {
942 rtn
= winch(self
->win
);
945 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
947 rtn
= mvwinch(self
->win
,y
,x
);
950 PyErr_SetString(PyExc_TypeError
, "inch requires 0 or 2 arguments");
953 return PyInt_FromLong((long) rtn
);
957 PyCursesWindow_InStr(PyCursesWindowObject
*self
, PyObject
*args
)
960 char rtn
[1024]; /* This should be big enough.. I hope */
963 switch (PyTuple_Size(args
)) {
965 rtn2
= winstr(self
->win
,rtn
);
968 if (!PyArg_ParseTuple(args
,"i;n", &n
))
970 rtn2
= winnstr(self
->win
,rtn
,n
);
973 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
975 rtn2
= mvwinstr(self
->win
,y
,x
,rtn
);
978 if (!PyArg_ParseTuple(args
, "iii;y,x,n", &y
, &x
, &n
))
980 rtn2
= mvwinnstr(self
->win
, y
, x
, rtn
, n
);
983 PyErr_SetString(PyExc_TypeError
, "instr requires 0 or 3 arguments");
988 return PyString_FromString(rtn
);
992 PyCursesWindow_InsStr(PyCursesWindowObject
*self
, PyObject
*args
)
997 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
998 int use_xy
= FALSE
, use_attr
= FALSE
;
1000 switch (PyTuple_Size(args
)) {
1002 if (!PyArg_ParseTuple(args
,"s;str", &str
))
1006 if (!PyArg_ParseTuple(args
,"sl;str,attr", &str
, &attr
))
1011 if (!PyArg_ParseTuple(args
,"iis;y,x,str", &y
, &x
, &str
))
1016 if (!PyArg_ParseTuple(args
,"iisl;y,x,str,attr", &y
, &x
, &str
, &attr
))
1018 use_xy
= use_attr
= TRUE
;
1021 PyErr_SetString(PyExc_TypeError
, "insstr requires 1 to 4 arguments");
1025 if (use_attr
== TRUE
) {
1026 attr_old
= getattrs(self
->win
);
1027 wattrset(self
->win
,attr
);
1030 rtn
= mvwinsstr(self
->win
,y
,x
,str
);
1032 rtn
= winsstr(self
->win
,str
);
1033 if (use_attr
== TRUE
)
1034 wattrset(self
->win
,attr_old
);
1035 return PyCursesCheckERR(rtn
, "insstr");
1039 PyCursesWindow_InsNStr(PyCursesWindowObject
*self
, PyObject
*args
)
1043 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
1044 int use_xy
= FALSE
, use_attr
= FALSE
;
1046 switch (PyTuple_Size(args
)) {
1048 if (!PyArg_ParseTuple(args
,"si;str,n", &str
, &n
))
1052 if (!PyArg_ParseTuple(args
,"sil;str,n,attr", &str
, &n
, &attr
))
1057 if (!PyArg_ParseTuple(args
,"iisi;y,x,str,n", &y
, &x
, &str
, &n
))
1062 if (!PyArg_ParseTuple(args
,"iisil;y,x,str,n,attr", &y
, &x
, &str
, &n
, &attr
))
1064 use_xy
= use_attr
= TRUE
;
1067 PyErr_SetString(PyExc_TypeError
, "insnstr requires 2 to 5 arguments");
1071 if (use_attr
== TRUE
) {
1072 attr_old
= getattrs(self
->win
);
1073 wattrset(self
->win
,attr
);
1076 rtn
= mvwinsnstr(self
->win
,y
,x
,str
,n
);
1078 rtn
= winsnstr(self
->win
,str
,n
);
1079 if (use_attr
== TRUE
)
1080 wattrset(self
->win
,attr_old
);
1081 return PyCursesCheckERR(rtn
, "insnstr");
1085 PyCursesWindow_Is_LineTouched(PyCursesWindowObject
*self
, PyObject
*args
)
1088 if (!PyArg_ParseTuple(args
,"i;line", &line
))
1090 erg
= is_linetouched(self
->win
, line
);
1092 PyErr_SetString(PyExc_TypeError
,
1093 "is_linetouched: line number outside of boundaries");
1097 Py_INCREF(Py_False
);
1106 PyCursesWindow_NoOutRefresh(PyCursesWindowObject
*self
, PyObject
*args
)
1108 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1111 #ifndef WINDOW_HAS_FLAGS
1114 if (self
->win
->_flags
& _ISPAD
) {
1116 switch(PyTuple_Size(args
)) {
1118 if (!PyArg_ParseTuple(args
,
1120 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1121 &pminrow
, &pmincol
, &sminrow
,
1122 &smincol
, &smaxrow
, &smaxcol
))
1124 Py_BEGIN_ALLOW_THREADS
1125 rtn
= pnoutrefresh(self
->win
,
1126 pminrow
, pmincol
, sminrow
,
1127 smincol
, smaxrow
, smaxcol
);
1128 Py_END_ALLOW_THREADS
1129 return PyCursesCheckERR(rtn
, "pnoutrefresh");
1131 PyErr_SetString(PyCursesError
,
1132 "noutrefresh() called for a pad "
1133 "requires 6 arguments");
1137 if (!PyArg_ParseTuple(args
, ":noutrefresh"))
1140 Py_BEGIN_ALLOW_THREADS
1141 rtn
= wnoutrefresh(self
->win
);
1142 Py_END_ALLOW_THREADS
1143 return PyCursesCheckERR(rtn
, "wnoutrefresh");
1148 PyCursesWindow_Overlay(PyCursesWindowObject
*self
, PyObject
*args
)
1150 PyCursesWindowObject
*temp
;
1151 int use_copywin
= FALSE
;
1152 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1155 switch (PyTuple_Size(args
)) {
1157 if (!PyArg_ParseTuple(args
, "O!;window object",
1158 &PyCursesWindow_Type
, &temp
))
1162 if (!PyArg_ParseTuple(args
, "(O!iiiiii);window object, int, int, int, int, int, int",
1163 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1164 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1169 PyErr_SetString(PyExc_TypeError
,
1170 "overlay requires one or seven arguments");
1174 if (use_copywin
== TRUE
) {
1175 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1176 dminrow
, dmincol
, dmaxrow
, dmaxcol
, TRUE
);
1177 return PyCursesCheckERR(rtn
, "copywin");
1180 rtn
= overlay(self
->win
, temp
->win
);
1181 return PyCursesCheckERR(rtn
, "overlay");
1186 PyCursesWindow_Overwrite(PyCursesWindowObject
*self
, PyObject
*args
)
1188 PyCursesWindowObject
*temp
;
1189 int use_copywin
= FALSE
;
1190 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1193 switch (PyTuple_Size(args
)) {
1195 if (!PyArg_ParseTuple(args
, "O!;window object",
1196 &PyCursesWindow_Type
, &temp
))
1200 if (!PyArg_ParseTuple(args
, "(O!iiiiii);window object, int, int, int, int, int, int",
1201 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1202 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1207 PyErr_SetString(PyExc_TypeError
,
1208 "overwrite requires one or seven arguments");
1212 if (use_copywin
== TRUE
) {
1213 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1214 dminrow
, dmincol
, dmaxrow
, dmaxcol
, FALSE
);
1215 return PyCursesCheckERR(rtn
, "copywin");
1218 rtn
= overwrite(self
->win
, temp
->win
);
1219 return PyCursesCheckERR(rtn
, "overwrite");
1224 PyCursesWindow_PutWin(PyCursesWindowObject
*self
, PyObject
*args
)
1228 if (!PyArg_ParseTuple(args
, "O;fileobj", &temp
))
1230 if (!PyFile_Check(temp
)) {
1231 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1234 return PyCursesCheckERR(putwin(self
->win
, PyFile_AsFile(temp
)),
1239 PyCursesWindow_RedrawLine(PyCursesWindowObject
*self
, PyObject
*args
)
1242 if (!PyArg_ParseTuple(args
,"ii;beg,num", &beg
, &num
))
1244 return PyCursesCheckERR(wredrawln(self
->win
,beg
,num
), "redrawln");
1248 PyCursesWindow_Refresh(PyCursesWindowObject
*self
, PyObject
*args
)
1250 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1253 #ifndef WINDOW_HAS_FLAGS
1256 if (self
->win
->_flags
& _ISPAD
) {
1258 switch(PyTuple_Size(args
)) {
1260 if (!PyArg_ParseTuple(args
,
1262 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1263 &pminrow
, &pmincol
, &sminrow
,
1264 &smincol
, &smaxrow
, &smaxcol
))
1267 Py_BEGIN_ALLOW_THREADS
1268 rtn
= prefresh(self
->win
,
1269 pminrow
, pmincol
, sminrow
,
1270 smincol
, smaxrow
, smaxcol
);
1271 Py_END_ALLOW_THREADS
1272 return PyCursesCheckERR(rtn
, "prefresh");
1274 PyErr_SetString(PyCursesError
,
1275 "refresh() for a pad requires 6 arguments");
1279 if (!PyArg_ParseTuple(args
, ":refresh"))
1281 Py_BEGIN_ALLOW_THREADS
1282 rtn
= wrefresh(self
->win
);
1283 Py_END_ALLOW_THREADS
1284 return PyCursesCheckERR(rtn
, "prefresh");
1289 PyCursesWindow_SetScrollRegion(PyCursesWindowObject
*self
, PyObject
*args
)
1292 if (!PyArg_ParseTuple(args
,"ii;top, bottom",&y
,&x
))
1294 return PyCursesCheckERR(wsetscrreg(self
->win
,y
,x
), "wsetscrreg");
1298 PyCursesWindow_SubWin(PyCursesWindowObject
*self
, PyObject
*args
)
1301 int nlines
, ncols
, begin_y
, begin_x
;
1305 switch (PyTuple_Size(args
)) {
1307 if (!PyArg_ParseTuple(args
,"ii;begin_y,begin_x",&begin_y
,&begin_x
))
1311 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
1312 &nlines
,&ncols
,&begin_y
,&begin_x
))
1316 PyErr_SetString(PyExc_TypeError
, "subwin requires 2 or 4 arguments");
1320 /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
1321 #ifdef WINDOW_HAS_FLAGS
1322 if (self
->win
->_flags
& _ISPAD
)
1323 win
= subpad(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1326 win
= subwin(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1329 PyErr_SetString(PyCursesError
, catchall_NULL
);
1333 return (PyObject
*)PyCursesWindow_New(win
);
1337 PyCursesWindow_Scroll(PyCursesWindowObject
*self
, PyObject
*args
)
1340 switch(PyTuple_Size(args
)) {
1342 return PyCursesCheckERR(scroll(self
->win
), "scroll");
1344 if (!PyArg_ParseTuple(args
, "i;nlines", &nlines
))
1346 return PyCursesCheckERR(wscrl(self
->win
, nlines
), "scroll");
1348 PyErr_SetString(PyExc_TypeError
, "scroll requires 0 or 1 arguments");
1354 PyCursesWindow_TouchLine(PyCursesWindowObject
*self
, PyObject
*args
)
1357 switch (PyTuple_Size(args
)) {
1359 if (!PyArg_ParseTuple(args
,"ii;start,count",&st
,&cnt
))
1361 return PyCursesCheckERR(touchline(self
->win
,st
,cnt
), "touchline");
1363 if (!PyArg_ParseTuple(args
, "iii;start,count,val", &st
, &cnt
, &val
))
1365 return PyCursesCheckERR(wtouchln(self
->win
, st
, cnt
, val
), "touchline");
1367 PyErr_SetString(PyExc_TypeError
, "touchline requires 2 or 3 arguments");
1373 PyCursesWindow_Vline(PyCursesWindowObject
*self
, PyObject
*args
)
1377 int n
, x
, y
, code
= OK
;
1378 attr_t attr
= A_NORMAL
;
1380 switch (PyTuple_Size(args
)) {
1382 if (!PyArg_ParseTuple(args
, "Oi;ch or int,n", &temp
, &n
))
1386 if (!PyArg_ParseTuple(args
, "Oil;ch or int,n,attr", &temp
, &n
, &attr
))
1390 if (!PyArg_ParseTuple(args
, "iiOi;y,x,ch or int,n", &y
, &x
, &temp
, &n
))
1392 code
= wmove(self
->win
, y
, x
);
1395 if (!PyArg_ParseTuple(args
, "iiOil; y,x,ch or int,n,attr",
1396 &y
, &x
, &temp
, &n
, &attr
))
1398 code
= wmove(self
->win
, y
, x
);
1401 PyErr_SetString(PyExc_TypeError
, "vline requires 2 to 5 arguments");
1406 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
1407 PyErr_SetString(PyExc_TypeError
,
1408 "argument 1 or 3 must be a ch or an int");
1411 return PyCursesCheckERR(wvline(self
->win
, ch
| attr
, n
), "vline");
1413 return PyCursesCheckERR(code
, "wmove");
1416 static PyMethodDef PyCursesWindow_Methods
[] = {
1417 {"addch", (PyCFunction
)PyCursesWindow_AddCh
, METH_VARARGS
},
1418 {"addnstr", (PyCFunction
)PyCursesWindow_AddNStr
, METH_VARARGS
},
1419 {"addstr", (PyCFunction
)PyCursesWindow_AddStr
, METH_VARARGS
},
1420 {"attroff", (PyCFunction
)PyCursesWindow_wattroff
, METH_VARARGS
},
1421 {"attron", (PyCFunction
)PyCursesWindow_wattron
, METH_VARARGS
},
1422 {"attrset", (PyCFunction
)PyCursesWindow_wattrset
, METH_VARARGS
},
1423 {"bkgd", (PyCFunction
)PyCursesWindow_Bkgd
, METH_VARARGS
},
1424 {"bkgdset", (PyCFunction
)PyCursesWindow_BkgdSet
, METH_VARARGS
},
1425 {"border", (PyCFunction
)PyCursesWindow_Border
, METH_VARARGS
},
1426 {"box", (PyCFunction
)PyCursesWindow_Box
, METH_VARARGS
},
1427 {"clear", (PyCFunction
)PyCursesWindow_wclear
, METH_NOARGS
},
1428 {"clearok", (PyCFunction
)PyCursesWindow_clearok
, METH_VARARGS
},
1429 {"clrtobot", (PyCFunction
)PyCursesWindow_wclrtobot
, METH_NOARGS
},
1430 {"clrtoeol", (PyCFunction
)PyCursesWindow_wclrtoeol
, METH_NOARGS
},
1431 {"cursyncup", (PyCFunction
)PyCursesWindow_wcursyncup
, METH_NOARGS
},
1432 {"delch", (PyCFunction
)PyCursesWindow_DelCh
, METH_VARARGS
},
1433 {"deleteln", (PyCFunction
)PyCursesWindow_wdeleteln
, METH_NOARGS
},
1434 {"derwin", (PyCFunction
)PyCursesWindow_DerWin
, METH_VARARGS
},
1435 {"echochar", (PyCFunction
)PyCursesWindow_EchoChar
, METH_VARARGS
},
1436 #ifdef NCURSES_MOUSE_VERSION
1437 {"enclose", (PyCFunction
)PyCursesWindow_Enclose
, METH_VARARGS
},
1439 {"erase", (PyCFunction
)PyCursesWindow_werase
, METH_NOARGS
},
1440 {"getbegyx", (PyCFunction
)PyCursesWindow_getbegyx
, METH_NOARGS
},
1441 {"getbkgd", (PyCFunction
)PyCursesWindow_GetBkgd
, METH_NOARGS
},
1442 {"getch", (PyCFunction
)PyCursesWindow_GetCh
, METH_VARARGS
},
1443 {"getkey", (PyCFunction
)PyCursesWindow_GetKey
, METH_VARARGS
},
1444 {"getmaxyx", (PyCFunction
)PyCursesWindow_getmaxyx
, METH_NOARGS
},
1445 {"getparyx", (PyCFunction
)PyCursesWindow_getparyx
, METH_NOARGS
},
1446 {"getstr", (PyCFunction
)PyCursesWindow_GetStr
, METH_VARARGS
},
1447 {"getyx", (PyCFunction
)PyCursesWindow_getyx
, METH_NOARGS
},
1448 {"hline", (PyCFunction
)PyCursesWindow_Hline
, METH_VARARGS
},
1449 {"idcok", (PyCFunction
)PyCursesWindow_idcok
, METH_VARARGS
},
1450 {"idlok", (PyCFunction
)PyCursesWindow_idlok
, METH_VARARGS
},
1451 {"immedok", (PyCFunction
)PyCursesWindow_immedok
, METH_VARARGS
},
1452 {"inch", (PyCFunction
)PyCursesWindow_InCh
, METH_VARARGS
},
1453 {"insch", (PyCFunction
)PyCursesWindow_InsCh
, METH_VARARGS
},
1454 {"insdelln", (PyCFunction
)PyCursesWindow_winsdelln
, METH_VARARGS
},
1455 {"insertln", (PyCFunction
)PyCursesWindow_winsertln
, METH_NOARGS
},
1456 {"insnstr", (PyCFunction
)PyCursesWindow_InsNStr
, METH_VARARGS
},
1457 {"insstr", (PyCFunction
)PyCursesWindow_InsStr
, METH_VARARGS
},
1458 {"instr", (PyCFunction
)PyCursesWindow_InStr
, METH_VARARGS
},
1459 {"is_linetouched", (PyCFunction
)PyCursesWindow_Is_LineTouched
, METH_VARARGS
},
1460 {"is_wintouched", (PyCFunction
)PyCursesWindow_is_wintouched
, METH_NOARGS
},
1461 {"keypad", (PyCFunction
)PyCursesWindow_keypad
, METH_VARARGS
},
1462 {"leaveok", (PyCFunction
)PyCursesWindow_leaveok
, METH_VARARGS
},
1463 {"move", (PyCFunction
)PyCursesWindow_wmove
, METH_VARARGS
},
1464 {"mvderwin", (PyCFunction
)PyCursesWindow_mvderwin
, METH_VARARGS
},
1465 {"mvwin", (PyCFunction
)PyCursesWindow_mvwin
, METH_VARARGS
},
1466 {"nodelay", (PyCFunction
)PyCursesWindow_nodelay
, METH_VARARGS
},
1467 {"notimeout", (PyCFunction
)PyCursesWindow_notimeout
, METH_VARARGS
},
1468 {"noutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
, METH_VARARGS
},
1469 /* Backward compatibility alias -- remove in Python 2.3 */
1470 {"nooutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
, METH_VARARGS
},
1471 {"overlay", (PyCFunction
)PyCursesWindow_Overlay
, METH_VARARGS
},
1472 {"overwrite", (PyCFunction
)PyCursesWindow_Overwrite
,
1474 {"putwin", (PyCFunction
)PyCursesWindow_PutWin
, METH_VARARGS
},
1475 {"redrawln", (PyCFunction
)PyCursesWindow_RedrawLine
},
1476 {"redrawwin", (PyCFunction
)PyCursesWindow_redrawwin
, METH_NOARGS
},
1477 {"refresh", (PyCFunction
)PyCursesWindow_Refresh
, METH_VARARGS
},
1478 #ifndef STRICT_SYSV_CURSES
1479 {"resize", (PyCFunction
)PyCursesWindow_wresize
, METH_VARARGS
},
1481 {"scroll", (PyCFunction
)PyCursesWindow_Scroll
, METH_VARARGS
},
1482 {"scrollok", (PyCFunction
)PyCursesWindow_scrollok
, METH_VARARGS
},
1483 {"setscrreg", (PyCFunction
)PyCursesWindow_SetScrollRegion
, METH_VARARGS
},
1484 {"standend", (PyCFunction
)PyCursesWindow_wstandend
, METH_NOARGS
},
1485 {"standout", (PyCFunction
)PyCursesWindow_wstandout
, METH_NOARGS
},
1486 {"subpad", (PyCFunction
)PyCursesWindow_SubWin
, METH_VARARGS
},
1487 {"subwin", (PyCFunction
)PyCursesWindow_SubWin
, METH_VARARGS
},
1488 {"syncdown", (PyCFunction
)PyCursesWindow_wsyncdown
, METH_NOARGS
},
1489 {"syncok", (PyCFunction
)PyCursesWindow_syncok
, METH_VARARGS
},
1490 {"syncup", (PyCFunction
)PyCursesWindow_wsyncup
, METH_NOARGS
},
1491 {"timeout", (PyCFunction
)PyCursesWindow_wtimeout
, METH_VARARGS
},
1492 {"touchline", (PyCFunction
)PyCursesWindow_TouchLine
, METH_VARARGS
},
1493 {"touchwin", (PyCFunction
)PyCursesWindow_touchwin
, METH_NOARGS
},
1494 {"untouchwin", (PyCFunction
)PyCursesWindow_untouchwin
, METH_NOARGS
},
1495 {"vline", (PyCFunction
)PyCursesWindow_Vline
, METH_VARARGS
},
1496 {NULL
, NULL
} /* sentinel */
1500 PyCursesWindow_GetAttr(PyCursesWindowObject
*self
, char *name
)
1502 return Py_FindMethod(PyCursesWindow_Methods
, (PyObject
*)self
, name
);
1505 /* -------------------------------------------------------*/
1507 PyTypeObject PyCursesWindow_Type
= {
1508 PyObject_HEAD_INIT(NULL
)
1510 "_curses.curses window", /*tp_name*/
1511 sizeof(PyCursesWindowObject
), /*tp_basicsize*/
1514 (destructor
)PyCursesWindow_Dealloc
, /*tp_dealloc*/
1516 (getattrfunc
)PyCursesWindow_GetAttr
, /*tp_getattr*/
1517 (setattrfunc
)0, /*tp_setattr*/
1521 0, /*tp_as_sequence*/
1522 0, /*tp_as_mapping*/
1526 /*********************************************************************
1528 **********************************************************************/
1530 NoArgNoReturnFunction(beep
)
1531 NoArgNoReturnFunction(def_prog_mode
)
1532 NoArgNoReturnFunction(def_shell_mode
)
1533 NoArgNoReturnFunction(doupdate
)
1534 NoArgNoReturnFunction(endwin
)
1535 NoArgNoReturnFunction(flash
)
1536 NoArgNoReturnFunction(nocbreak
)
1537 NoArgNoReturnFunction(noecho
)
1538 NoArgNoReturnFunction(nonl
)
1539 NoArgNoReturnFunction(noraw
)
1540 NoArgNoReturnFunction(reset_prog_mode
)
1541 NoArgNoReturnFunction(reset_shell_mode
)
1542 NoArgNoReturnFunction(resetty
)
1543 NoArgNoReturnFunction(savetty
)
1545 NoArgOrFlagNoReturnFunction(cbreak
)
1546 NoArgOrFlagNoReturnFunction(echo
)
1547 NoArgOrFlagNoReturnFunction(nl
)
1548 NoArgOrFlagNoReturnFunction(raw
)
1550 NoArgReturnIntFunction(baudrate
)
1551 NoArgReturnIntFunction(termattrs
)
1553 NoArgReturnStringFunction(termname
)
1554 NoArgReturnStringFunction(longname
)
1556 NoArgTrueFalseFunction(can_change_color
)
1557 NoArgTrueFalseFunction(has_colors
)
1558 NoArgTrueFalseFunction(has_ic
)
1559 NoArgTrueFalseFunction(has_il
)
1560 NoArgTrueFalseFunction(isendwin
)
1561 NoArgNoReturnVoidFunction(filter
)
1562 NoArgNoReturnVoidFunction(flushinp
)
1563 NoArgNoReturnVoidFunction(noqiflush
)
1566 PyCurses_Color_Content(PyObject
*self
, PyObject
*args
)
1571 PyCursesInitialisedColor
1573 if (!PyArg_ParseTuple(args
, "h:color_content", &color
)) return NULL
;
1575 if (color_content(color
, &r
, &g
, &b
) != ERR
)
1576 return Py_BuildValue("(iii)", r
, g
, b
);
1578 PyErr_SetString(PyCursesError
,
1579 "Argument 1 was out of range. Check value of COLORS.");
1585 PyCurses_color_pair(PyObject
*self
, PyObject
*args
)
1590 PyCursesInitialisedColor
1592 if (!PyArg_ParseTuple(args
, "i:color_pair", &n
)) return NULL
;
1593 return PyInt_FromLong((long) (n
<< 8));
1597 PyCurses_Curs_Set(PyObject
*self
, PyObject
*args
)
1603 if (!PyArg_ParseTuple(args
, "i:curs_set", &vis
)) return NULL
;
1605 erg
= curs_set(vis
);
1606 if (erg
== ERR
) return PyCursesCheckERR(erg
, "curs_set");
1608 return PyInt_FromLong((long) erg
);
1612 PyCurses_Delay_Output(PyObject
*self
, PyObject
*args
)
1618 if (!PyArg_ParseTuple(args
, "i:delay_output", &ms
)) return NULL
;
1620 return PyCursesCheckERR(delay_output(ms
), "delay_output");
1624 PyCurses_EraseChar(PyObject
*self
)
1632 return PyString_FromStringAndSize(&ch
, 1);
1636 PyCurses_getsyx(PyObject
*self
)
1644 return Py_BuildValue("(ii)", y
, x
);
1647 #ifdef NCURSES_MOUSE_VERSION
1649 PyCurses_GetMouse(PyObject
*self
)
1656 rtn
= getmouse( &event
);
1658 PyErr_SetString(PyCursesError
, "getmouse() returned ERR");
1661 return Py_BuildValue("(hiiil)",
1663 event
.x
, event
.y
, event
.z
,
1664 (long) event
.bstate
);
1668 PyCurses_UngetMouse(PyObject
*self
, PyObject
*args
)
1673 if (!PyArg_ParseTuple(args
, "(hiiil)",
1675 &event
.x
, &event
.y
, &event
.z
,
1676 (int *) &event
.bstate
))
1679 return PyCursesCheckERR(ungetmouse(&event
), "ungetmouse");
1684 PyCurses_GetWin(PyCursesWindowObject
*self
, PyObject
*temp
)
1690 if (!PyFile_Check(temp
)) {
1691 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1695 win
= getwin(PyFile_AsFile(temp
));
1698 PyErr_SetString(PyCursesError
, catchall_NULL
);
1702 return PyCursesWindow_New(win
);
1706 PyCurses_HalfDelay(PyObject
*self
, PyObject
*args
)
1708 unsigned char tenths
;
1712 if (!PyArg_ParseTuple(args
, "b:halfdelay", &tenths
)) return NULL
;
1714 return PyCursesCheckERR(halfdelay(tenths
), "halfdelay");
1717 #ifndef STRICT_SYSV_CURSES
1719 static PyObject
* PyCurses_has_key(PyObject
*self
, PyObject
*args
)
1725 if (!PyArg_ParseTuple(args
,"i",&ch
)) return NULL
;
1727 if (has_key(ch
) == FALSE
) {
1728 Py_INCREF(Py_False
);
1734 #endif /* STRICT_SYSV_CURSES */
1737 PyCurses_Init_Color(PyObject
*self
, PyObject
*args
)
1739 short color
, r
, g
, b
;
1742 PyCursesInitialisedColor
1744 switch(PyTuple_Size(args
)) {
1746 if (!PyArg_ParseTuple(args
, "hhhh;color,r,g,b", &color
, &r
, &g
, &b
)) return NULL
;
1749 PyErr_SetString(PyExc_TypeError
, "init_color requires 4 arguments");
1753 return PyCursesCheckERR(init_color(color
, r
, g
, b
), "init_color");
1757 PyCurses_Init_Pair(PyObject
*self
, PyObject
*args
)
1762 PyCursesInitialisedColor
1764 if (PyTuple_Size(args
) != 3) {
1765 PyErr_SetString(PyExc_TypeError
, "init_pair requires 3 arguments");
1769 if (!PyArg_ParseTuple(args
, "hhh;pair, f, b", &pair
, &f
, &b
)) return NULL
;
1771 return PyCursesCheckERR(init_pair(pair
, f
, b
), "init_pair");
1774 static PyObject
*ModDict
;
1777 PyCurses_InitScr(PyObject
*self
)
1780 PyObject
*nlines
, *cols
;
1782 if (initialised
== TRUE
) {
1784 return (PyObject
*)PyCursesWindow_New(stdscr
);
1790 PyErr_SetString(PyCursesError
, catchall_NULL
);
1794 initialised
= initialised_setupterm
= TRUE
;
1796 /* This was moved from initcurses() because it core dumped on SGI,
1797 where they're not defined until you've called initscr() */
1798 #define SetDictInt(string,ch) \
1799 PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
1801 /* Here are some graphic symbols you can use */
1802 SetDictInt("ACS_ULCORNER", (ACS_ULCORNER
));
1803 SetDictInt("ACS_LLCORNER", (ACS_LLCORNER
));
1804 SetDictInt("ACS_URCORNER", (ACS_URCORNER
));
1805 SetDictInt("ACS_LRCORNER", (ACS_LRCORNER
));
1806 SetDictInt("ACS_LTEE", (ACS_LTEE
));
1807 SetDictInt("ACS_RTEE", (ACS_RTEE
));
1808 SetDictInt("ACS_BTEE", (ACS_BTEE
));
1809 SetDictInt("ACS_TTEE", (ACS_TTEE
));
1810 SetDictInt("ACS_HLINE", (ACS_HLINE
));
1811 SetDictInt("ACS_VLINE", (ACS_VLINE
));
1812 SetDictInt("ACS_PLUS", (ACS_PLUS
));
1813 #if !defined(__hpux) || defined(HAVE_NCURSES_H)
1814 /* On HP/UX 11, these are of type cchar_t, which is not an
1815 integral type. If this is a problem on more platforms, a
1816 configure test should be added to determine whether ACS_S1
1817 is of integral type. */
1818 SetDictInt("ACS_S1", (ACS_S1
));
1819 SetDictInt("ACS_S9", (ACS_S9
));
1820 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND
));
1821 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD
));
1822 SetDictInt("ACS_DEGREE", (ACS_DEGREE
));
1823 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS
));
1824 SetDictInt("ACS_BULLET", (ACS_BULLET
));
1825 SetDictInt("ACS_LARROW", (ACS_LARROW
));
1826 SetDictInt("ACS_RARROW", (ACS_RARROW
));
1827 SetDictInt("ACS_DARROW", (ACS_DARROW
));
1828 SetDictInt("ACS_UARROW", (ACS_UARROW
));
1829 SetDictInt("ACS_BOARD", (ACS_BOARD
));
1830 SetDictInt("ACS_LANTERN", (ACS_LANTERN
));
1831 SetDictInt("ACS_BLOCK", (ACS_BLOCK
));
1833 SetDictInt("ACS_BSSB", (ACS_ULCORNER
));
1834 SetDictInt("ACS_SSBB", (ACS_LLCORNER
));
1835 SetDictInt("ACS_BBSS", (ACS_URCORNER
));
1836 SetDictInt("ACS_SBBS", (ACS_LRCORNER
));
1837 SetDictInt("ACS_SBSS", (ACS_RTEE
));
1838 SetDictInt("ACS_SSSB", (ACS_LTEE
));
1839 SetDictInt("ACS_SSBS", (ACS_BTEE
));
1840 SetDictInt("ACS_BSSS", (ACS_TTEE
));
1841 SetDictInt("ACS_BSBS", (ACS_HLINE
));
1842 SetDictInt("ACS_SBSB", (ACS_VLINE
));
1843 SetDictInt("ACS_SSSS", (ACS_PLUS
));
1845 /* The following are never available with strict SYSV curses */
1847 SetDictInt("ACS_S3", (ACS_S3
));
1850 SetDictInt("ACS_S7", (ACS_S7
));
1853 SetDictInt("ACS_LEQUAL", (ACS_LEQUAL
));
1856 SetDictInt("ACS_GEQUAL", (ACS_GEQUAL
));
1859 SetDictInt("ACS_PI", (ACS_PI
));
1862 SetDictInt("ACS_NEQUAL", (ACS_NEQUAL
));
1865 SetDictInt("ACS_STERLING", (ACS_STERLING
));
1868 nlines
= PyInt_FromLong((long) LINES
);
1869 PyDict_SetItemString(ModDict
, "LINES", nlines
);
1871 cols
= PyInt_FromLong((long) COLS
);
1872 PyDict_SetItemString(ModDict
, "COLS", cols
);
1875 return (PyObject
*)PyCursesWindow_New(win
);
1879 PyCurses_setupterm(PyObject
* self
, PyObject
*args
, PyObject
* keywds
)
1883 char* termstr
= NULL
;
1885 static char *kwlist
[] = {"term", "fd", NULL
};
1887 if (!PyArg_ParseTupleAndKeywords(
1888 args
,keywds
,"|zi:setupterm",kwlist
,&termstr
,&fd
)) {
1893 PyObject
* sys_stdout
;
1895 sys_stdout
= PySys_GetObject("stdout");
1897 if (sys_stdout
== NULL
) {
1904 fd
= PyObject_AsFileDescriptor(sys_stdout
);
1911 if (setupterm(termstr
,fd
,&err
) == ERR
) {
1912 char* s
= "setupterm: unknown error";
1915 s
= "setupterm: could not find terminal";
1916 } else if (err
== -1) {
1917 s
= "setupterm: could not find terminfo database";
1920 PyErr_SetString(PyCursesError
,s
);
1924 initialised_setupterm
= TRUE
;
1931 PyCurses_IntrFlush(PyObject
*self
, PyObject
*args
)
1937 switch(PyTuple_Size(args
)) {
1939 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&ch
)) return NULL
;
1942 PyErr_SetString(PyExc_TypeError
, "intrflush requires 1 argument");
1946 return PyCursesCheckERR(intrflush(NULL
,ch
), "intrflush");
1949 #if !defined(__NetBSD__)
1951 PyCurses_KeyName(PyObject
*self
, PyObject
*args
)
1958 if (!PyArg_ParseTuple(args
,"i",&ch
)) return NULL
;
1961 PyErr_SetString(PyExc_ValueError
, "invalid key number");
1966 return PyString_FromString((knp
== NULL
) ? "" : (char *)knp
);
1971 PyCurses_KillChar(PyObject
*self
)
1977 return PyString_FromStringAndSize(&ch
, 1);
1981 PyCurses_Meta(PyObject
*self
, PyObject
*args
)
1987 switch(PyTuple_Size(args
)) {
1989 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&ch
)) return NULL
;
1992 PyErr_SetString(PyExc_TypeError
, "meta requires 1 argument");
1996 return PyCursesCheckERR(meta(stdscr
, ch
), "meta");
1999 #ifdef NCURSES_MOUSE_VERSION
2001 PyCurses_MouseInterval(PyObject
*self
, PyObject
*args
)
2006 if (!PyArg_ParseTuple(args
,"i;interval",&interval
))
2008 return PyCursesCheckERR(mouseinterval(interval
), "mouseinterval");
2012 PyCurses_MouseMask(PyObject
*self
, PyObject
*args
)
2015 mmask_t oldmask
, availmask
;
2018 if (!PyArg_ParseTuple(args
,"i;mousemask",&newmask
))
2020 availmask
= mousemask(newmask
, &oldmask
);
2021 return Py_BuildValue("(ll)", (long)availmask
, (long)oldmask
);
2026 PyCurses_Napms(PyObject
*self
, PyObject
*args
)
2031 if (!PyArg_ParseTuple(args
, "i;ms", &ms
)) return NULL
;
2033 return Py_BuildValue("i", napms(ms
));
2038 PyCurses_NewPad(PyObject
*self
, PyObject
*args
)
2045 if (!PyArg_ParseTuple(args
,"ii;nlines,ncols",&nlines
,&ncols
)) return NULL
;
2047 win
= newpad(nlines
, ncols
);
2050 PyErr_SetString(PyCursesError
, catchall_NULL
);
2054 return (PyObject
*)PyCursesWindow_New(win
);
2058 PyCurses_NewWindow(PyObject
*self
, PyObject
*args
)
2061 int nlines
, ncols
, begin_y
=0, begin_x
=0;
2065 switch (PyTuple_Size(args
)) {
2067 if (!PyArg_ParseTuple(args
,"ii;nlines,ncols",&nlines
,&ncols
))
2071 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
2072 &nlines
,&ncols
,&begin_y
,&begin_x
))
2076 PyErr_SetString(PyExc_TypeError
, "newwin requires 2 or 4 arguments");
2080 win
= newwin(nlines
,ncols
,begin_y
,begin_x
);
2082 PyErr_SetString(PyCursesError
, catchall_NULL
);
2086 return (PyObject
*)PyCursesWindow_New(win
);
2090 PyCurses_Pair_Content(PyObject
*self
, PyObject
*args
)
2095 PyCursesInitialisedColor
2097 switch(PyTuple_Size(args
)) {
2099 if (!PyArg_ParseTuple(args
, "h;pair", &pair
)) return NULL
;
2102 PyErr_SetString(PyExc_TypeError
, "pair_content requires 1 argument");
2106 if (!pair_content(pair
, &f
, &b
)) {
2107 PyErr_SetString(PyCursesError
,
2108 "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
2112 return Py_BuildValue("(ii)", f
, b
);
2116 PyCurses_pair_number(PyObject
*self
, PyObject
*args
)
2121 PyCursesInitialisedColor
2123 switch(PyTuple_Size(args
)) {
2125 if (!PyArg_ParseTuple(args
, "i;pairvalue", &n
)) return NULL
;
2128 PyErr_SetString(PyExc_TypeError
,
2129 "pair_number requires 1 argument");
2133 return PyInt_FromLong((long) ((n
& A_COLOR
) >> 8));
2137 PyCurses_Putp(PyObject
*self
, PyObject
*args
)
2141 if (!PyArg_ParseTuple(args
,"s;str", &str
)) return NULL
;
2142 return PyCursesCheckERR(putp(str
), "putp");
2146 PyCurses_QiFlush(PyObject
*self
, PyObject
*args
)
2152 switch(PyTuple_Size(args
)) {
2158 if (!PyArg_ParseTuple(args
, "i;True(1) or False(0)", &flag
)) return NULL
;
2159 if (flag
) qiflush();
2164 PyErr_SetString(PyExc_TypeError
, "qiflush requires 0 or 1 arguments");
2170 PyCurses_setsyx(PyObject
*self
, PyObject
*args
)
2176 if (PyTuple_Size(args
)!=2) {
2177 PyErr_SetString(PyExc_TypeError
, "setsyx requires 2 arguments");
2181 if (!PyArg_ParseTuple(args
, "ii;y, x", &y
, &x
)) return NULL
;
2190 PyCurses_Start_Color(PyObject
*self
)
2197 code
= start_color();
2199 initialisedcolors
= TRUE
;
2200 c
= PyInt_FromLong((long) COLORS
);
2201 PyDict_SetItemString(ModDict
, "COLORS", c
);
2203 cp
= PyInt_FromLong((long) COLOR_PAIRS
);
2204 PyDict_SetItemString(ModDict
, "COLOR_PAIRS", cp
);
2209 PyErr_SetString(PyCursesError
, "start_color() returned ERR");
2215 PyCurses_tigetflag(PyObject
*self
, PyObject
*args
)
2219 PyCursesSetupTermCalled
;
2221 if (!PyArg_ParseTuple(args
, "z", &capname
))
2224 return PyInt_FromLong( (long) tigetflag( capname
) );
2228 PyCurses_tigetnum(PyObject
*self
, PyObject
*args
)
2232 PyCursesSetupTermCalled
;
2234 if (!PyArg_ParseTuple(args
, "z", &capname
))
2237 return PyInt_FromLong( (long) tigetnum( capname
) );
2241 PyCurses_tigetstr(PyObject
*self
, PyObject
*args
)
2245 PyCursesSetupTermCalled
;
2247 if (!PyArg_ParseTuple(args
, "z", &capname
))
2250 capname
= tigetstr( capname
);
2251 if (capname
== 0 || capname
== (char*) -1) {
2255 return PyString_FromString( capname
);
2259 PyCurses_tparm(PyObject
*self
, PyObject
*args
)
2262 char* result
= NULL
;
2263 int i1
=0,i2
=0,i3
=0,i4
=0,i5
=0,i6
=0,i7
=0,i8
=0,i9
=0;
2265 PyCursesSetupTermCalled
;
2267 if (!PyArg_ParseTuple(args
, "s|iiiiiiiii:tparm",
2268 &fmt
, &i1
, &i2
, &i3
, &i4
,
2269 &i5
, &i6
, &i7
, &i8
, &i9
)) {
2273 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
,i9
);
2275 return PyString_FromString(result
);
2279 PyCurses_TypeAhead(PyObject
*self
, PyObject
*args
)
2285 if (!PyArg_ParseTuple(args
,"i;fd",&fd
)) return NULL
;
2287 PyCursesCheckERR(typeahead( fd
), "typeahead");
2293 PyCurses_UnCtrl(PyObject
*self
, PyObject
*args
)
2300 if (!PyArg_ParseTuple(args
,"O;ch or int",&temp
)) return NULL
;
2302 if (PyInt_Check(temp
))
2303 ch
= (chtype
) PyInt_AsLong(temp
);
2304 else if (PyString_Check(temp
))
2305 ch
= (chtype
) *PyString_AsString(temp
);
2307 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2311 return PyString_FromString(unctrl(ch
));
2315 PyCurses_UngetCh(PyObject
*self
, PyObject
*args
)
2322 if (!PyArg_ParseTuple(args
,"O;ch or int",&temp
)) return NULL
;
2324 if (PyInt_Check(temp
))
2325 ch
= (int) PyInt_AsLong(temp
);
2326 else if (PyString_Check(temp
))
2327 ch
= (int) *PyString_AsString(temp
);
2329 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2333 return PyCursesCheckERR(ungetch(ch
), "ungetch");
2337 PyCurses_Use_Env(PyObject
*self
, PyObject
*args
)
2343 switch(PyTuple_Size(args
)) {
2345 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&flag
))
2349 PyErr_SetString(PyExc_TypeError
, "use_env requires 1 argument");
2357 /* List of functions defined in the module */
2359 static PyMethodDef PyCurses_methods
[] = {
2360 {"baudrate", (PyCFunction
)PyCurses_baudrate
, METH_NOARGS
},
2361 {"beep", (PyCFunction
)PyCurses_beep
, METH_NOARGS
},
2362 {"can_change_color", (PyCFunction
)PyCurses_can_change_color
, METH_NOARGS
},
2363 {"cbreak", (PyCFunction
)PyCurses_cbreak
, METH_VARARGS
},
2364 {"color_content", (PyCFunction
)PyCurses_Color_Content
, METH_VARARGS
},
2365 {"color_pair", (PyCFunction
)PyCurses_color_pair
, METH_VARARGS
},
2366 {"curs_set", (PyCFunction
)PyCurses_Curs_Set
, METH_VARARGS
},
2367 {"def_prog_mode", (PyCFunction
)PyCurses_def_prog_mode
, METH_NOARGS
},
2368 {"def_shell_mode", (PyCFunction
)PyCurses_def_shell_mode
, METH_NOARGS
},
2369 {"delay_output", (PyCFunction
)PyCurses_Delay_Output
, METH_VARARGS
},
2370 {"doupdate", (PyCFunction
)PyCurses_doupdate
, METH_NOARGS
},
2371 {"echo", (PyCFunction
)PyCurses_echo
, METH_VARARGS
},
2372 {"endwin", (PyCFunction
)PyCurses_endwin
, METH_NOARGS
},
2373 {"erasechar", (PyCFunction
)PyCurses_EraseChar
, METH_NOARGS
},
2374 {"filter", (PyCFunction
)PyCurses_filter
, METH_NOARGS
},
2375 {"flash", (PyCFunction
)PyCurses_flash
, METH_NOARGS
},
2376 {"flushinp", (PyCFunction
)PyCurses_flushinp
, METH_NOARGS
},
2377 #ifdef NCURSES_MOUSE_VERSION
2378 {"getmouse", (PyCFunction
)PyCurses_GetMouse
, METH_NOARGS
},
2379 {"ungetmouse", (PyCFunction
)PyCurses_UngetMouse
, METH_VARARGS
},
2381 {"getsyx", (PyCFunction
)PyCurses_getsyx
, METH_NOARGS
},
2382 {"getwin", (PyCFunction
)PyCurses_GetWin
, METH_O
},
2383 {"has_colors", (PyCFunction
)PyCurses_has_colors
, METH_NOARGS
},
2384 {"has_ic", (PyCFunction
)PyCurses_has_ic
, METH_NOARGS
},
2385 {"has_il", (PyCFunction
)PyCurses_has_il
, METH_NOARGS
},
2386 #ifndef STRICT_SYSV_CURSES
2387 {"has_key", (PyCFunction
)PyCurses_has_key
, METH_VARARGS
},
2389 {"halfdelay", (PyCFunction
)PyCurses_HalfDelay
, METH_VARARGS
},
2390 {"init_color", (PyCFunction
)PyCurses_Init_Color
, METH_VARARGS
},
2391 {"init_pair", (PyCFunction
)PyCurses_Init_Pair
, METH_VARARGS
},
2392 {"initscr", (PyCFunction
)PyCurses_InitScr
, METH_NOARGS
},
2393 {"intrflush", (PyCFunction
)PyCurses_IntrFlush
, METH_VARARGS
},
2394 {"isendwin", (PyCFunction
)PyCurses_isendwin
, METH_NOARGS
},
2395 #if !defined(__NetBSD__)
2396 {"keyname", (PyCFunction
)PyCurses_KeyName
, METH_VARARGS
},
2398 {"killchar", (PyCFunction
)PyCurses_KillChar
, METH_NOARGS
},
2399 {"longname", (PyCFunction
)PyCurses_longname
, METH_NOARGS
},
2400 {"meta", (PyCFunction
)PyCurses_Meta
, METH_VARARGS
},
2401 #ifdef NCURSES_MOUSE_VERSION
2402 {"mouseinterval", (PyCFunction
)PyCurses_MouseInterval
, METH_VARARGS
},
2403 {"mousemask", (PyCFunction
)PyCurses_MouseMask
, METH_VARARGS
},
2405 {"napms", (PyCFunction
)PyCurses_Napms
, METH_VARARGS
},
2406 {"newpad", (PyCFunction
)PyCurses_NewPad
, METH_VARARGS
},
2407 {"newwin", (PyCFunction
)PyCurses_NewWindow
, METH_VARARGS
},
2408 {"nl", (PyCFunction
)PyCurses_nl
, METH_VARARGS
},
2409 {"nocbreak", (PyCFunction
)PyCurses_nocbreak
, METH_NOARGS
},
2410 {"noecho", (PyCFunction
)PyCurses_noecho
, METH_NOARGS
},
2411 {"nonl", (PyCFunction
)PyCurses_nonl
, METH_NOARGS
},
2412 {"noqiflush", (PyCFunction
)PyCurses_noqiflush
, METH_NOARGS
},
2413 {"noraw", (PyCFunction
)PyCurses_noraw
, METH_NOARGS
},
2414 {"pair_content", (PyCFunction
)PyCurses_Pair_Content
, METH_VARARGS
},
2415 {"pair_number", (PyCFunction
)PyCurses_pair_number
, METH_VARARGS
},
2416 {"putp", (PyCFunction
)PyCurses_Putp
, METH_VARARGS
},
2417 {"qiflush", (PyCFunction
)PyCurses_QiFlush
, METH_VARARGS
},
2418 {"raw", (PyCFunction
)PyCurses_raw
, METH_VARARGS
},
2419 {"reset_prog_mode", (PyCFunction
)PyCurses_reset_prog_mode
, METH_NOARGS
},
2420 {"reset_shell_mode", (PyCFunction
)PyCurses_reset_shell_mode
, METH_NOARGS
},
2421 {"resetty", (PyCFunction
)PyCurses_resetty
, METH_NOARGS
},
2422 {"savetty", (PyCFunction
)PyCurses_savetty
, METH_NOARGS
},
2423 {"setsyx", (PyCFunction
)PyCurses_setsyx
, METH_VARARGS
},
2424 {"setupterm", (PyCFunction
)PyCurses_setupterm
,
2425 METH_VARARGS
|METH_KEYWORDS
},
2426 {"start_color", (PyCFunction
)PyCurses_Start_Color
, METH_NOARGS
},
2427 {"termattrs", (PyCFunction
)PyCurses_termattrs
, METH_NOARGS
},
2428 {"termname", (PyCFunction
)PyCurses_termname
, METH_NOARGS
},
2429 {"tigetflag", (PyCFunction
)PyCurses_tigetflag
, METH_VARARGS
},
2430 {"tigetnum", (PyCFunction
)PyCurses_tigetnum
, METH_VARARGS
},
2431 {"tigetstr", (PyCFunction
)PyCurses_tigetstr
, METH_VARARGS
},
2432 {"tparm", (PyCFunction
)PyCurses_tparm
, METH_VARARGS
},
2433 {"typeahead", (PyCFunction
)PyCurses_TypeAhead
, METH_VARARGS
},
2434 {"unctrl", (PyCFunction
)PyCurses_UnCtrl
, METH_VARARGS
},
2435 {"ungetch", (PyCFunction
)PyCurses_UngetCh
, METH_VARARGS
},
2436 {"use_env", (PyCFunction
)PyCurses_Use_Env
, METH_VARARGS
},
2437 {NULL
, NULL
} /* sentinel */
2440 /* Initialization function for the module */
2445 PyObject
*m
, *d
, *v
, *c_api_object
;
2446 static void *PyCurses_API
[PyCurses_API_pointers
];
2448 /* Initialize object type */
2449 PyCursesWindow_Type
.ob_type
= &PyType_Type
;
2451 /* Initialize the C API pointer array */
2452 PyCurses_API
[0] = (void *)&PyCursesWindow_Type
;
2453 PyCurses_API
[1] = (void *)func_PyCursesSetupTermCalled
;
2454 PyCurses_API
[2] = (void *)func_PyCursesInitialised
;
2455 PyCurses_API
[3] = (void *)func_PyCursesInitialisedColor
;
2457 /* Create the module and add the functions */
2458 m
= Py_InitModule("_curses", PyCurses_methods
);
2460 /* Add some symbolic constants to the module */
2461 d
= PyModule_GetDict(m
);
2462 ModDict
= d
; /* For PyCurses_InitScr to use later */
2464 /* Add a CObject for the C API */
2465 c_api_object
= PyCObject_FromVoidPtr((void *)PyCurses_API
, NULL
);
2466 PyDict_SetItemString(d
, "_C_API", c_api_object
);
2467 Py_DECREF(c_api_object
);
2469 /* For exception curses.error */
2470 PyCursesError
= PyErr_NewException("_curses.error", NULL
, NULL
);
2471 PyDict_SetItemString(d
, "error", PyCursesError
);
2473 /* Make the version available */
2474 v
= PyString_FromString(PyCursesVersion
);
2475 PyDict_SetItemString(d
, "version", v
);
2476 PyDict_SetItemString(d
, "__version__", v
);
2479 SetDictInt("ERR", ERR
);
2480 SetDictInt("OK", OK
);
2482 /* Here are some attributes you can add to chars to print */
2484 SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES
);
2485 SetDictInt("A_NORMAL", A_NORMAL
);
2486 SetDictInt("A_STANDOUT", A_STANDOUT
);
2487 SetDictInt("A_UNDERLINE", A_UNDERLINE
);
2488 SetDictInt("A_REVERSE", A_REVERSE
);
2489 SetDictInt("A_BLINK", A_BLINK
);
2490 SetDictInt("A_DIM", A_DIM
);
2491 SetDictInt("A_BOLD", A_BOLD
);
2492 SetDictInt("A_ALTCHARSET", A_ALTCHARSET
);
2493 #if !defined(__NetBSD__)
2494 SetDictInt("A_INVIS", A_INVIS
);
2496 SetDictInt("A_PROTECT", A_PROTECT
);
2497 SetDictInt("A_CHARTEXT", A_CHARTEXT
);
2498 SetDictInt("A_COLOR", A_COLOR
);
2500 /* The following are never available with strict SYSV curses */
2502 SetDictInt("A_HORIZONTAL", A_HORIZONTAL
);
2505 SetDictInt("A_LEFT", A_LEFT
);
2508 SetDictInt("A_LOW", A_LOW
);
2511 SetDictInt("A_RIGHT", A_RIGHT
);
2514 SetDictInt("A_TOP", A_TOP
);
2517 SetDictInt("A_VERTICAL", A_VERTICAL
);
2520 SetDictInt("COLOR_BLACK", COLOR_BLACK
);
2521 SetDictInt("COLOR_RED", COLOR_RED
);
2522 SetDictInt("COLOR_GREEN", COLOR_GREEN
);
2523 SetDictInt("COLOR_YELLOW", COLOR_YELLOW
);
2524 SetDictInt("COLOR_BLUE", COLOR_BLUE
);
2525 SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA
);
2526 SetDictInt("COLOR_CYAN", COLOR_CYAN
);
2527 SetDictInt("COLOR_WHITE", COLOR_WHITE
);
2529 #ifdef NCURSES_MOUSE_VERSION
2530 /* Mouse-related constants */
2531 SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED
);
2532 SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED
);
2533 SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED
);
2534 SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED
);
2535 SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED
);
2537 SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED
);
2538 SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED
);
2539 SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED
);
2540 SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED
);
2541 SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED
);
2543 SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED
);
2544 SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED
);
2545 SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED
);
2546 SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED
);
2547 SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED
);
2549 SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED
);
2550 SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED
);
2551 SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED
);
2552 SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED
);
2553 SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED
);
2555 SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT
);
2556 SetDictInt("BUTTON_CTRL", BUTTON_CTRL
);
2557 SetDictInt("BUTTON_ALT", BUTTON_ALT
);
2559 SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS
);
2560 SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION
);
2562 /* Now set everything up for KEY_ variables */
2567 #if !defined(__NetBSD__)
2568 for (key
=KEY_MIN
;key
< KEY_MAX
; key
++) {
2569 key_n
= (char *)keyname(key
);
2570 if (key_n
== NULL
|| strcmp(key_n
,"UNKNOWN KEY")==0)
2572 if (strncmp(key_n
,"KEY_F(",6)==0) {
2574 key_n2
= malloc(strlen(key_n
)+1);
2578 if (*p1
!= '(' && *p1
!= ')') {
2587 PyDict_SetItemString(d
,key_n2
,PyInt_FromLong((long) key
));
2588 if (key_n2
!= key_n
)
2592 SetDictInt("KEY_MIN", KEY_MIN
);
2593 SetDictInt("KEY_MAX", KEY_MAX
);