2 * This is a curses module for Python.
4 * Based on prior work by Lance Ellinghaus and Oliver Andrich
5 * Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse,
6 * Cathedral City, California Republic, United States of America.
8 * Version 1.5b1, heavily extended for ncurses by Oliver Andrich:
9 * Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany.
11 * Tidied for Python 1.6, and currently maintained by <amk@amk.ca>.
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this source file to use, copy, modify, merge, or publish it
15 * subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or in any new file that contains a substantial portion of
21 * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF
22 * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
23 * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES
24 * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
25 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE
27 * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL,
28 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
29 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR
30 * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
31 * PERFORMANCE OF THIS SOFTWARE.
38 A number of SysV or ncurses functions don't have wrappers yet; if you
39 need a given function, add it and send a patch. See
40 http://www.python.org/dev/patches/ for instructions on how to submit
43 Here's a list of currently unsupported functions:
45 addchnstr addchstr color_set define_key
46 del_curterm delscreen dupwin inchnstr inchstr innstr keyok
47 mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr
48 mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr
49 mvwinchnstr mvwinchstr mvwinnstr newterm
50 restartterm ripoffline scr_dump
51 scr_init scr_restore scr_set scrl set_curterm set_term setterm
52 tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
53 vidattr vidputs waddchnstr waddchstr
54 wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
57 slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
58 slk_attron slk_attrset slk_clear slk_color slk_init slk_label
59 slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
61 Menu extension (ncurses and probably SYSV):
62 current_item free_item free_menu item_count item_description
63 item_index item_init item_name item_opts item_opts_off
64 item_opts_on item_term item_userptr item_value item_visible
65 menu_back menu_driver menu_fore menu_format menu_grey
66 menu_init menu_items menu_mark menu_opts menu_opts_off
67 menu_opts_on menu_pad menu_pattern menu_request_by_name
68 menu_request_name menu_spacing menu_sub menu_term menu_userptr
69 menu_win new_item new_menu pos_menu_cursor post_menu
70 scale_menu set_current_item set_item_init set_item_opts
71 set_item_term set_item_userptr set_item_value set_menu_back
72 set_menu_fore set_menu_format set_menu_grey set_menu_init
73 set_menu_items set_menu_mark set_menu_opts set_menu_pad
74 set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
75 set_menu_userptr set_menu_win set_top_row top_row unpost_menu
77 Form extension (ncurses and probably SYSV):
78 current_field data_ahead data_behind dup_field
79 dynamic_fieldinfo field_arg field_back field_buffer
80 field_count field_fore field_index field_info field_init
81 field_just field_opts field_opts_off field_opts_on field_pad
82 field_status field_term field_type field_userptr form_driver
83 form_fields form_init form_opts form_opts_off form_opts_on
84 form_page form_request_by_name form_request_name form_sub
85 form_term form_userptr form_win free_field free_form
86 link_field link_fieldtype move_field new_field new_form
87 new_page pos_form_cursor post_form scale_form
88 set_current_field set_field_back set_field_buffer
89 set_field_fore set_field_init set_field_just set_field_opts
90 set_field_pad set_field_status set_field_term set_field_type
91 set_field_userptr set_fieldtype_arg set_fieldtype_choice
92 set_form_fields set_form_init set_form_opts set_form_page
93 set_form_sub set_form_term set_form_userptr set_form_win
94 set_max_field set_new_page unpost_form
101 char *PyCursesVersion
= "2.2";
108 #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
112 #define STRICT_SYSV_CURSES
115 #define CURSES_MODULE
116 #include "py_curses.h"
118 /* These prototypes are in <term.h>, but including this header
119 #defines many common symbols (such as "lines") which breaks the
120 curses module in other ways. So the code will just specify
121 explicit prototypes here. */
122 extern int setupterm(char *,int,int *);
127 #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
128 #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
129 typedef chtype attr_t
; /* No attr_t type is available */
133 #define STRICT_SYSV_CURSES
136 /* Definition of exception curses.error */
138 static PyObject
*PyCursesError
;
140 /* Tells whether setupterm() has been called to initialise terminfo. */
141 static int initialised_setupterm
= FALSE
;
143 /* Tells whether initscr() has been called to initialise curses. */
144 static int initialised
= FALSE
;
146 /* Tells whether start_color() has been called to initialise color usage. */
147 static int initialisedcolors
= FALSE
;
150 #define PyCursesSetupTermCalled \
151 if (initialised_setupterm != TRUE) { \
152 PyErr_SetString(PyCursesError, \
153 "must call (at least) setupterm() first"); \
156 #define PyCursesInitialised \
157 if (initialised != TRUE) { \
158 PyErr_SetString(PyCursesError, \
159 "must call initscr() first"); \
162 #define PyCursesInitialisedColor \
163 if (initialisedcolors != TRUE) { \
164 PyErr_SetString(PyCursesError, \
165 "must call start_color() first"); \
169 #define MIN(x,y) ((x) < (y) ? (x) : (y))
172 /* Utility Functions */
175 * Check the return code from a curses function and return None
176 * or raise an exception as appropriate. These are exported using the
181 PyCursesCheckERR(int code
, char *fname
)
188 PyErr_SetString(PyCursesError
, catchall_ERR
);
190 PyErr_Format(PyCursesError
, "%s() returned ERR", fname
);
197 PyCurses_ConvertToChtype(PyObject
*obj
, chtype
*ch
)
199 if (PyInt_Check(obj
)) {
200 *ch
= (chtype
) PyInt_AsLong(obj
);
201 } else if(PyString_Check(obj
)
202 && (PyString_Size(obj
) == 1)) {
203 *ch
= (chtype
) *PyString_AsString(obj
);
210 /* Function versions of the 3 functions for tested whether curses has been
211 initialised or not. */
213 static int func_PyCursesSetupTermCalled(void)
215 PyCursesSetupTermCalled
;
219 static int func_PyCursesInitialised(void)
225 static int func_PyCursesInitialisedColor(void)
227 PyCursesInitialisedColor
;
231 /*****************************************************************************
233 ******************************************************************************/
235 /* Definition of the window type */
237 PyTypeObject PyCursesWindow_Type
;
239 /* Function prototype macros for Window object
242 TYPE - parameter Type
243 ERGSTR - format string for construction of the return value
244 PARSESTR - format string for argument parsing
247 #define Window_NoArgNoReturnFunction(X) \
248 static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
249 { return PyCursesCheckERR(X(self->win), # X); }
251 #define Window_NoArgTrueFalseFunction(X) \
252 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
254 if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
255 else { Py_INCREF(Py_True); return Py_True; } }
257 #define Window_NoArgNoReturnVoidFunction(X) \
258 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
260 X(self->win); Py_INCREF(Py_None); return Py_None; }
262 #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
263 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
266 X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
268 #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
269 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
272 if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
273 X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
275 #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
276 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
279 if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
280 return PyCursesCheckERR(X(self->win, arg1), # X); }
282 #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
283 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
286 if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
287 return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
289 /* ------------- WINDOW routines --------------- */
291 Window_NoArgNoReturnFunction(untouchwin
)
292 Window_NoArgNoReturnFunction(touchwin
)
293 Window_NoArgNoReturnFunction(redrawwin
)
294 Window_NoArgNoReturnFunction(winsertln
)
295 Window_NoArgNoReturnFunction(werase
)
296 Window_NoArgNoReturnFunction(wdeleteln
)
298 Window_NoArgTrueFalseFunction(is_wintouched
)
300 Window_NoArgNoReturnVoidFunction(wsyncup
)
301 Window_NoArgNoReturnVoidFunction(wsyncdown
)
302 Window_NoArgNoReturnVoidFunction(wstandend
)
303 Window_NoArgNoReturnVoidFunction(wstandout
)
304 Window_NoArgNoReturnVoidFunction(wcursyncup
)
305 Window_NoArgNoReturnVoidFunction(wclrtoeol
)
306 Window_NoArgNoReturnVoidFunction(wclrtobot
)
307 Window_NoArgNoReturnVoidFunction(wclear
)
309 Window_OneArgNoReturnVoidFunction(idcok
, int, "i;True(1) or False(0)")
310 Window_OneArgNoReturnVoidFunction(immedok
, int, "i;True(1) or False(0)")
311 Window_OneArgNoReturnVoidFunction(wtimeout
, int, "i;delay")
313 Window_NoArg2TupleReturnFunction(getyx
, int, "ii")
314 Window_NoArg2TupleReturnFunction(getbegyx
, int, "ii")
315 Window_NoArg2TupleReturnFunction(getmaxyx
, int, "ii")
316 Window_NoArg2TupleReturnFunction(getparyx
, int, "ii")
318 Window_OneArgNoReturnFunction(wattron
, attr_t
, "l;attr")
319 Window_OneArgNoReturnFunction(wattroff
, attr_t
, "l;attr")
320 Window_OneArgNoReturnFunction(wattrset
, attr_t
, "l;attr")
321 Window_OneArgNoReturnFunction(clearok
, int, "i;True(1) or False(0)")
322 Window_OneArgNoReturnFunction(idlok
, int, "i;True(1) or False(0)")
323 #if defined(__NetBSD__)
324 Window_OneArgNoReturnVoidFunction(keypad
, int, "i;True(1) or False(0)")
326 Window_OneArgNoReturnFunction(keypad
, int, "i;True(1) or False(0)")
328 Window_OneArgNoReturnFunction(leaveok
, int, "i;True(1) or False(0)")
329 #if defined(__NetBSD__)
330 Window_OneArgNoReturnVoidFunction(nodelay
, int, "i;True(1) or False(0)")
332 Window_OneArgNoReturnFunction(nodelay
, int, "i;True(1) or False(0)")
334 Window_OneArgNoReturnFunction(notimeout
, int, "i;True(1) or False(0)")
335 Window_OneArgNoReturnFunction(scrollok
, int, "i;True(1) or False(0)")
336 Window_OneArgNoReturnFunction(winsdelln
, int, "i;nlines")
337 Window_OneArgNoReturnFunction(syncok
, int, "i;True(1) or False(0)")
339 Window_TwoArgNoReturnFunction(mvwin
, int, "ii;y,x")
340 Window_TwoArgNoReturnFunction(mvderwin
, int, "ii;y,x")
341 Window_TwoArgNoReturnFunction(wmove
, int, "ii;y,x")
342 #ifndef STRICT_SYSV_CURSES
343 Window_TwoArgNoReturnFunction(wresize
, int, "ii;lines,columns")
346 /* Allocation and deallocation of Window Objects */
349 PyCursesWindow_New(WINDOW
*win
)
351 PyCursesWindowObject
*wo
;
353 wo
= PyObject_NEW(PyCursesWindowObject
, &PyCursesWindow_Type
);
354 if (wo
== NULL
) return NULL
;
356 return (PyObject
*)wo
;
360 PyCursesWindow_Dealloc(PyCursesWindowObject
*wo
)
362 if (wo
->win
!= stdscr
) delwin(wo
->win
);
366 /* Addch, Addstr, Addnstr */
369 PyCursesWindow_AddCh(PyCursesWindowObject
*self
, PyObject
*args
)
371 int rtn
, x
, y
, use_xy
= FALSE
;
374 attr_t attr
= A_NORMAL
;
376 switch (PyTuple_Size(args
)) {
378 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
382 if (!PyArg_ParseTuple(args
, "Ol;ch or int,attr", &temp
, &attr
))
386 if (!PyArg_ParseTuple(args
,"iiO;y,x,ch or int", &y
, &x
, &temp
))
391 if (!PyArg_ParseTuple(args
,"iiOl;y,x,ch or int, attr",
392 &y
, &x
, &temp
, &attr
))
397 PyErr_SetString(PyExc_TypeError
, "addch requires 1 to 4 arguments");
401 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
402 PyErr_SetString(PyExc_TypeError
, "argument 1 or 3 must be a ch or an int");
407 rtn
= mvwaddch(self
->win
,y
,x
, ch
| attr
);
409 rtn
= waddch(self
->win
, ch
| attr
);
411 return PyCursesCheckERR(rtn
, "addch");
415 PyCursesWindow_AddStr(PyCursesWindowObject
*self
, PyObject
*args
)
420 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
421 int use_xy
= FALSE
, use_attr
= FALSE
;
423 switch (PyTuple_Size(args
)) {
425 if (!PyArg_ParseTuple(args
,"s;str", &str
))
429 if (!PyArg_ParseTuple(args
,"sl;str,attr", &str
, &attr
))
434 if (!PyArg_ParseTuple(args
,"iis;int,int,str", &y
, &x
, &str
))
439 if (!PyArg_ParseTuple(args
,"iisl;int,int,str,attr", &y
, &x
, &str
, &attr
))
441 use_xy
= use_attr
= TRUE
;
444 PyErr_SetString(PyExc_TypeError
, "addstr requires 1 to 4 arguments");
448 if (use_attr
== TRUE
) {
449 attr_old
= getattrs(self
->win
);
450 wattrset(self
->win
,attr
);
453 rtn
= mvwaddstr(self
->win
,y
,x
,str
);
455 rtn
= waddstr(self
->win
,str
);
456 if (use_attr
== TRUE
)
457 wattrset(self
->win
,attr_old
);
458 return PyCursesCheckERR(rtn
, "addstr");
462 PyCursesWindow_AddNStr(PyCursesWindowObject
*self
, PyObject
*args
)
466 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
467 int use_xy
= FALSE
, use_attr
= FALSE
;
469 switch (PyTuple_Size(args
)) {
471 if (!PyArg_ParseTuple(args
,"si;str,n", &str
, &n
))
475 if (!PyArg_ParseTuple(args
,"sil;str,n,attr", &str
, &n
, &attr
))
480 if (!PyArg_ParseTuple(args
,"iisi;y,x,str,n", &y
, &x
, &str
, &n
))
485 if (!PyArg_ParseTuple(args
,"iisil;y,x,str,n,attr", &y
, &x
, &str
, &n
, &attr
))
487 use_xy
= use_attr
= TRUE
;
490 PyErr_SetString(PyExc_TypeError
, "addnstr requires 2 to 5 arguments");
494 if (use_attr
== TRUE
) {
495 attr_old
= getattrs(self
->win
);
496 wattrset(self
->win
,attr
);
499 rtn
= mvwaddnstr(self
->win
,y
,x
,str
,n
);
501 rtn
= waddnstr(self
->win
,str
,n
);
502 if (use_attr
== TRUE
)
503 wattrset(self
->win
,attr_old
);
504 return PyCursesCheckERR(rtn
, "addnstr");
508 PyCursesWindow_Bkgd(PyCursesWindowObject
*self
, PyObject
*args
)
512 attr_t attr
= A_NORMAL
;
514 switch (PyTuple_Size(args
)) {
516 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
520 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &attr
))
524 PyErr_SetString(PyExc_TypeError
, "bkgd requires 1 or 2 arguments");
528 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
529 PyErr_SetString(PyExc_TypeError
, "argument 1 or 3 must be a ch or an int");
533 return PyCursesCheckERR(wbkgd(self
->win
, bkgd
| attr
), "bkgd");
537 PyCursesWindow_BkgdSet(PyCursesWindowObject
*self
, PyObject
*args
)
541 attr_t attr
= A_NORMAL
;
543 switch (PyTuple_Size(args
)) {
545 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
549 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &attr
))
553 PyErr_SetString(PyExc_TypeError
, "bkgdset requires 1 or 2 arguments");
557 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
558 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
562 wbkgdset(self
->win
, bkgd
| attr
);
563 return PyCursesCheckERR(0, "bkgdset");
567 PyCursesWindow_Border(PyCursesWindowObject
*self
, PyObject
*args
)
573 /* Clear the array of parameters */
579 if (!PyArg_ParseTuple(args
,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
580 &temp
[0], &temp
[1], &temp
[2], &temp
[3],
581 &temp
[4], &temp
[5], &temp
[6], &temp
[7]))
585 if (temp
[i
] != NULL
&& !PyCurses_ConvertToChtype(temp
[i
], &ch
[i
])) {
586 PyErr_Format(PyExc_TypeError
,
587 "argument %i must be a ch or an int", i
+1);
593 ch
[0], ch
[1], ch
[2], ch
[3],
594 ch
[4], ch
[5], ch
[6], ch
[7]);
600 PyCursesWindow_Box(PyCursesWindowObject
*self
, PyObject
*args
)
603 switch(PyTuple_Size(args
)){
606 if (!PyArg_ParseTuple(args
,"ll;vertint,horint", &ch1
, &ch2
))
609 box(self
->win
,ch1
,ch2
);
614 #if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
615 #define py_mvwdelch mvwdelch
617 int py_mvwdelch(WINDOW
*w
, int y
, int x
)
620 /* On HP/UX, mvwdelch already returns. On other systems,
621 we may well run into this return statement. */
626 /* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */
629 PyCursesWindow_ChgAt(PyCursesWindowObject
*self
, PyObject
*args
)
635 attr_t attr
= A_NORMAL
;
638 switch (PyTuple_Size(args
)) {
640 if (!PyArg_ParseTuple(args
,"l;attr", &attr
))
644 if (!PyArg_ParseTuple(args
,"il;n,attr", &num
, &attr
))
648 if (!PyArg_ParseTuple(args
,"iil;int,int,attr", &y
, &x
, &attr
))
653 if (!PyArg_ParseTuple(args
,"iiil;int,int,n,attr", &y
, &x
, &num
, &attr
))
658 PyErr_SetString(PyExc_TypeError
, "chgat requires 1 to 4 arguments");
662 color
= (short)((attr
>> 8) & 0xff);
663 attr
= attr
- (color
<< 8);
665 if (use_xy
== TRUE
) {
666 rtn
= mvwchgat(self
->win
,y
,x
,num
,attr
,color
,NULL
);
667 touchline(self
->win
,y
,1);
669 getyx(self
->win
,y
,x
);
670 rtn
= wchgat(self
->win
,num
,attr
,color
,NULL
);
671 touchline(self
->win
,y
,1);
673 return PyCursesCheckERR(rtn
, "chgat");
678 PyCursesWindow_DelCh(PyCursesWindowObject
*self
, PyObject
*args
)
683 switch (PyTuple_Size(args
)) {
685 rtn
= wdelch(self
->win
);
688 if (!PyArg_ParseTuple(args
,"ii;y,x", &y
, &x
))
690 rtn
= py_mvwdelch(self
->win
,y
,x
);
693 PyErr_SetString(PyExc_TypeError
, "delch requires 0 or 2 arguments");
696 return PyCursesCheckERR(rtn
, "[mv]wdelch");
700 PyCursesWindow_DerWin(PyCursesWindowObject
*self
, PyObject
*args
)
703 int nlines
, ncols
, begin_y
, begin_x
;
707 switch (PyTuple_Size(args
)) {
709 if (!PyArg_ParseTuple(args
,"ii;begin_y,begin_x",&begin_y
,&begin_x
))
713 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
714 &nlines
,&ncols
,&begin_y
,&begin_x
))
718 PyErr_SetString(PyExc_TypeError
, "derwin requires 2 or 4 arguments");
722 win
= derwin(self
->win
,nlines
,ncols
,begin_y
,begin_x
);
725 PyErr_SetString(PyCursesError
, catchall_NULL
);
729 return (PyObject
*)PyCursesWindow_New(win
);
733 PyCursesWindow_EchoChar(PyCursesWindowObject
*self
, PyObject
*args
)
737 attr_t attr
= A_NORMAL
;
739 switch (PyTuple_Size(args
)) {
741 if (!PyArg_ParseTuple(args
,"O;ch or int", &temp
))
745 if (!PyArg_ParseTuple(args
,"Ol;ch or int,attr", &temp
, &attr
))
749 PyErr_SetString(PyExc_TypeError
, "echochar requires 1 or 2 arguments");
755 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
756 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
760 #ifdef WINDOW_HAS_FLAGS
761 if (self
->win
->_flags
& _ISPAD
)
762 return PyCursesCheckERR(pechochar(self
->win
, ch
| attr
),
766 return PyCursesCheckERR(wechochar(self
->win
, ch
| attr
),
770 #ifdef NCURSES_MOUSE_VERSION
772 PyCursesWindow_Enclose(PyCursesWindowObject
*self
, PyObject
*args
)
775 if (!PyArg_ParseTuple(args
,"ii;y,x", &y
, &x
))
778 return PyInt_FromLong( wenclose(self
->win
,y
,x
) );
783 PyCursesWindow_GetBkgd(PyCursesWindowObject
*self
)
785 return PyInt_FromLong((long) getbkgd(self
->win
));
789 PyCursesWindow_GetCh(PyCursesWindowObject
*self
, PyObject
*args
)
794 switch (PyTuple_Size(args
)) {
796 Py_BEGIN_ALLOW_THREADS
797 rtn
= wgetch(self
->win
);
801 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
803 Py_BEGIN_ALLOW_THREADS
804 rtn
= mvwgetch(self
->win
,y
,x
);
808 PyErr_SetString(PyExc_TypeError
, "getch requires 0 or 2 arguments");
811 return PyInt_FromLong((long)rtn
);
815 PyCursesWindow_GetKey(PyCursesWindowObject
*self
, PyObject
*args
)
820 switch (PyTuple_Size(args
)) {
822 Py_BEGIN_ALLOW_THREADS
823 rtn
= wgetch(self
->win
);
827 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
829 Py_BEGIN_ALLOW_THREADS
830 rtn
= mvwgetch(self
->win
,y
,x
);
834 PyErr_SetString(PyExc_TypeError
, "getkey requires 0 or 2 arguments");
838 /* getch() returns ERR in nodelay mode */
839 PyErr_SetString(PyCursesError
, "no input");
842 return Py_BuildValue("c", rtn
);
844 #if defined(__NetBSD__)
845 return PyString_FromString(unctrl(rtn
));
847 return PyString_FromString((char *)keyname(rtn
));
852 PyCursesWindow_GetStr(PyCursesWindowObject
*self
, PyObject
*args
)
855 char rtn
[1024]; /* This should be big enough.. I hope */
858 switch (PyTuple_Size(args
)) {
860 Py_BEGIN_ALLOW_THREADS
861 rtn2
= wgetnstr(self
->win
,rtn
, 1023);
865 if (!PyArg_ParseTuple(args
,"i;n", &n
))
867 Py_BEGIN_ALLOW_THREADS
868 rtn2
= wgetnstr(self
->win
,rtn
,MIN(n
, 1023));
872 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
874 Py_BEGIN_ALLOW_THREADS
875 #ifdef STRICT_SYSV_CURSES
876 rtn2
= wmove(self
->win
,y
,x
)==ERR
? ERR
: wgetnstr(self
->win
, rtn
, 1023);
878 rtn2
= mvwgetnstr(self
->win
,y
,x
,rtn
, 1023);
883 if (!PyArg_ParseTuple(args
,"iii;y,x,n", &y
, &x
, &n
))
885 #ifdef STRICT_SYSV_CURSES
886 Py_BEGIN_ALLOW_THREADS
887 rtn2
= wmove(self
->win
,y
,x
)==ERR
? ERR
:
888 wgetnstr(self
->win
, rtn
, MIN(n
, 1023));
891 Py_BEGIN_ALLOW_THREADS
892 rtn2
= mvwgetnstr(self
->win
, y
, x
, rtn
, MIN(n
, 1023));
897 PyErr_SetString(PyExc_TypeError
, "getstr requires 0 to 3 arguments");
902 return PyString_FromString(rtn
);
906 PyCursesWindow_Hline(PyCursesWindowObject
*self
, PyObject
*args
)
910 int n
, x
, y
, code
= OK
;
911 attr_t attr
= A_NORMAL
;
913 switch (PyTuple_Size(args
)) {
915 if (!PyArg_ParseTuple(args
, "Oi;ch or int,n", &temp
, &n
))
919 if (!PyArg_ParseTuple(args
, "Oil;ch or int,n,attr", &temp
, &n
, &attr
))
923 if (!PyArg_ParseTuple(args
, "iiOi;y,x,ch or int,n", &y
, &x
, &temp
, &n
))
925 code
= wmove(self
->win
, y
, x
);
928 if (!PyArg_ParseTuple(args
, "iiOil; y,x,ch or int,n,attr",
929 &y
, &x
, &temp
, &n
, &attr
))
931 code
= wmove(self
->win
, y
, x
);
934 PyErr_SetString(PyExc_TypeError
, "hline requires 2 to 5 arguments");
939 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
940 PyErr_SetString(PyExc_TypeError
,
941 "argument 1 or 3 must be a ch or an int");
944 return PyCursesCheckERR(whline(self
->win
, ch
| attr
, n
), "hline");
946 return PyCursesCheckERR(code
, "wmove");
950 PyCursesWindow_InsCh(PyCursesWindowObject
*self
, PyObject
*args
)
952 int rtn
, x
, y
, use_xy
= FALSE
;
955 attr_t attr
= A_NORMAL
;
957 switch (PyTuple_Size(args
)) {
959 if (!PyArg_ParseTuple(args
, "O;ch or int", &temp
))
963 if (!PyArg_ParseTuple(args
, "Ol;ch or int,attr", &temp
, &attr
))
967 if (!PyArg_ParseTuple(args
,"iiO;y,x,ch or int", &y
, &x
, &temp
))
972 if (!PyArg_ParseTuple(args
,"iiOl;y,x,ch or int, attr", &y
, &x
, &temp
, &attr
))
977 PyErr_SetString(PyExc_TypeError
, "insch requires 1 or 4 arguments");
981 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
982 PyErr_SetString(PyExc_TypeError
,
983 "argument 1 or 3 must be a ch or an int");
988 rtn
= mvwinsch(self
->win
,y
,x
, ch
| attr
);
990 rtn
= winsch(self
->win
, ch
| attr
);
992 return PyCursesCheckERR(rtn
, "insch");
996 PyCursesWindow_InCh(PyCursesWindowObject
*self
, PyObject
*args
)
1000 switch (PyTuple_Size(args
)) {
1002 rtn
= winch(self
->win
);
1005 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
1007 rtn
= mvwinch(self
->win
,y
,x
);
1010 PyErr_SetString(PyExc_TypeError
, "inch requires 0 or 2 arguments");
1013 return PyInt_FromLong((long) rtn
);
1017 PyCursesWindow_InStr(PyCursesWindowObject
*self
, PyObject
*args
)
1020 char rtn
[1024]; /* This should be big enough.. I hope */
1023 switch (PyTuple_Size(args
)) {
1025 rtn2
= winnstr(self
->win
,rtn
, 1023);
1028 if (!PyArg_ParseTuple(args
,"i;n", &n
))
1030 rtn2
= winnstr(self
->win
,rtn
,MIN(n
,1023));
1033 if (!PyArg_ParseTuple(args
,"ii;y,x",&y
,&x
))
1035 rtn2
= mvwinnstr(self
->win
,y
,x
,rtn
,1023);
1038 if (!PyArg_ParseTuple(args
, "iii;y,x,n", &y
, &x
, &n
))
1040 rtn2
= mvwinnstr(self
->win
, y
, x
, rtn
, MIN(n
,1023));
1043 PyErr_SetString(PyExc_TypeError
, "instr requires 0 or 3 arguments");
1048 return PyString_FromString(rtn
);
1052 PyCursesWindow_InsStr(PyCursesWindowObject
*self
, PyObject
*args
)
1057 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
1058 int use_xy
= FALSE
, use_attr
= FALSE
;
1060 switch (PyTuple_Size(args
)) {
1062 if (!PyArg_ParseTuple(args
,"s;str", &str
))
1066 if (!PyArg_ParseTuple(args
,"sl;str,attr", &str
, &attr
))
1071 if (!PyArg_ParseTuple(args
,"iis;y,x,str", &y
, &x
, &str
))
1076 if (!PyArg_ParseTuple(args
,"iisl;y,x,str,attr", &y
, &x
, &str
, &attr
))
1078 use_xy
= use_attr
= TRUE
;
1081 PyErr_SetString(PyExc_TypeError
, "insstr requires 1 to 4 arguments");
1085 if (use_attr
== TRUE
) {
1086 attr_old
= getattrs(self
->win
);
1087 wattrset(self
->win
,attr
);
1090 rtn
= mvwinsstr(self
->win
,y
,x
,str
);
1092 rtn
= winsstr(self
->win
,str
);
1093 if (use_attr
== TRUE
)
1094 wattrset(self
->win
,attr_old
);
1095 return PyCursesCheckERR(rtn
, "insstr");
1099 PyCursesWindow_InsNStr(PyCursesWindowObject
*self
, PyObject
*args
)
1103 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
1104 int use_xy
= FALSE
, use_attr
= FALSE
;
1106 switch (PyTuple_Size(args
)) {
1108 if (!PyArg_ParseTuple(args
,"si;str,n", &str
, &n
))
1112 if (!PyArg_ParseTuple(args
,"sil;str,n,attr", &str
, &n
, &attr
))
1117 if (!PyArg_ParseTuple(args
,"iisi;y,x,str,n", &y
, &x
, &str
, &n
))
1122 if (!PyArg_ParseTuple(args
,"iisil;y,x,str,n,attr", &y
, &x
, &str
, &n
, &attr
))
1124 use_xy
= use_attr
= TRUE
;
1127 PyErr_SetString(PyExc_TypeError
, "insnstr requires 2 to 5 arguments");
1131 if (use_attr
== TRUE
) {
1132 attr_old
= getattrs(self
->win
);
1133 wattrset(self
->win
,attr
);
1136 rtn
= mvwinsnstr(self
->win
,y
,x
,str
,n
);
1138 rtn
= winsnstr(self
->win
,str
,n
);
1139 if (use_attr
== TRUE
)
1140 wattrset(self
->win
,attr_old
);
1141 return PyCursesCheckERR(rtn
, "insnstr");
1145 PyCursesWindow_Is_LineTouched(PyCursesWindowObject
*self
, PyObject
*args
)
1148 if (!PyArg_ParseTuple(args
,"i;line", &line
))
1150 erg
= is_linetouched(self
->win
, line
);
1152 PyErr_SetString(PyExc_TypeError
,
1153 "is_linetouched: line number outside of boundaries");
1157 Py_INCREF(Py_False
);
1166 PyCursesWindow_NoOutRefresh(PyCursesWindowObject
*self
, PyObject
*args
)
1168 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1171 #ifndef WINDOW_HAS_FLAGS
1174 if (self
->win
->_flags
& _ISPAD
) {
1176 switch(PyTuple_Size(args
)) {
1178 if (!PyArg_ParseTuple(args
,
1180 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1181 &pminrow
, &pmincol
, &sminrow
,
1182 &smincol
, &smaxrow
, &smaxcol
))
1184 Py_BEGIN_ALLOW_THREADS
1185 rtn
= pnoutrefresh(self
->win
,
1186 pminrow
, pmincol
, sminrow
,
1187 smincol
, smaxrow
, smaxcol
);
1188 Py_END_ALLOW_THREADS
1189 return PyCursesCheckERR(rtn
, "pnoutrefresh");
1191 PyErr_SetString(PyCursesError
,
1192 "noutrefresh() called for a pad "
1193 "requires 6 arguments");
1197 if (!PyArg_ParseTuple(args
, ":noutrefresh"))
1200 Py_BEGIN_ALLOW_THREADS
1201 rtn
= wnoutrefresh(self
->win
);
1202 Py_END_ALLOW_THREADS
1203 return PyCursesCheckERR(rtn
, "wnoutrefresh");
1208 PyCursesWindow_Overlay(PyCursesWindowObject
*self
, PyObject
*args
)
1210 PyCursesWindowObject
*temp
;
1211 int use_copywin
= FALSE
;
1212 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1215 switch (PyTuple_Size(args
)) {
1217 if (!PyArg_ParseTuple(args
, "O!;window object",
1218 &PyCursesWindow_Type
, &temp
))
1222 if (!PyArg_ParseTuple(args
, "O!iiiiii;window object, int, int, int, int, int, int",
1223 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1224 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1229 PyErr_SetString(PyExc_TypeError
,
1230 "overlay requires one or seven arguments");
1234 if (use_copywin
== TRUE
) {
1235 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1236 dminrow
, dmincol
, dmaxrow
, dmaxcol
, TRUE
);
1237 return PyCursesCheckERR(rtn
, "copywin");
1240 rtn
= overlay(self
->win
, temp
->win
);
1241 return PyCursesCheckERR(rtn
, "overlay");
1246 PyCursesWindow_Overwrite(PyCursesWindowObject
*self
, PyObject
*args
)
1248 PyCursesWindowObject
*temp
;
1249 int use_copywin
= FALSE
;
1250 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1253 switch (PyTuple_Size(args
)) {
1255 if (!PyArg_ParseTuple(args
, "O!;window object",
1256 &PyCursesWindow_Type
, &temp
))
1260 if (!PyArg_ParseTuple(args
, "O!iiiiii;window object, int, int, int, int, int, int",
1261 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1262 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1267 PyErr_SetString(PyExc_TypeError
,
1268 "overwrite requires one or seven arguments");
1272 if (use_copywin
== TRUE
) {
1273 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1274 dminrow
, dmincol
, dmaxrow
, dmaxcol
, FALSE
);
1275 return PyCursesCheckERR(rtn
, "copywin");
1278 rtn
= overwrite(self
->win
, temp
->win
);
1279 return PyCursesCheckERR(rtn
, "overwrite");
1284 PyCursesWindow_PutWin(PyCursesWindowObject
*self
, PyObject
*args
)
1288 if (!PyArg_ParseTuple(args
, "O;fileobj", &temp
))
1290 if (!PyFile_Check(temp
)) {
1291 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1294 return PyCursesCheckERR(putwin(self
->win
, PyFile_AsFile(temp
)),
1299 PyCursesWindow_RedrawLine(PyCursesWindowObject
*self
, PyObject
*args
)
1302 if (!PyArg_ParseTuple(args
, "ii;beg,num", &beg
, &num
))
1304 return PyCursesCheckERR(wredrawln(self
->win
,beg
,num
), "redrawln");
1308 PyCursesWindow_Refresh(PyCursesWindowObject
*self
, PyObject
*args
)
1310 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1313 #ifndef WINDOW_HAS_FLAGS
1316 if (self
->win
->_flags
& _ISPAD
) {
1318 switch(PyTuple_Size(args
)) {
1320 if (!PyArg_ParseTuple(args
,
1322 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1323 &pminrow
, &pmincol
, &sminrow
,
1324 &smincol
, &smaxrow
, &smaxcol
))
1327 Py_BEGIN_ALLOW_THREADS
1328 rtn
= prefresh(self
->win
,
1329 pminrow
, pmincol
, sminrow
,
1330 smincol
, smaxrow
, smaxcol
);
1331 Py_END_ALLOW_THREADS
1332 return PyCursesCheckERR(rtn
, "prefresh");
1334 PyErr_SetString(PyCursesError
,
1335 "refresh() for a pad requires 6 arguments");
1339 if (!PyArg_ParseTuple(args
, ":refresh"))
1341 Py_BEGIN_ALLOW_THREADS
1342 rtn
= wrefresh(self
->win
);
1343 Py_END_ALLOW_THREADS
1344 return PyCursesCheckERR(rtn
, "prefresh");
1349 PyCursesWindow_SetScrollRegion(PyCursesWindowObject
*self
, PyObject
*args
)
1352 if (!PyArg_ParseTuple(args
,"ii;top, bottom",&y
,&x
))
1354 return PyCursesCheckERR(wsetscrreg(self
->win
,y
,x
), "wsetscrreg");
1358 PyCursesWindow_SubWin(PyCursesWindowObject
*self
, PyObject
*args
)
1361 int nlines
, ncols
, begin_y
, begin_x
;
1365 switch (PyTuple_Size(args
)) {
1367 if (!PyArg_ParseTuple(args
,"ii;begin_y,begin_x",&begin_y
,&begin_x
))
1371 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
1372 &nlines
,&ncols
,&begin_y
,&begin_x
))
1376 PyErr_SetString(PyExc_TypeError
, "subwin requires 2 or 4 arguments");
1380 /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
1381 #ifdef WINDOW_HAS_FLAGS
1382 if (self
->win
->_flags
& _ISPAD
)
1383 win
= subpad(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1386 win
= subwin(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1389 PyErr_SetString(PyCursesError
, catchall_NULL
);
1393 return (PyObject
*)PyCursesWindow_New(win
);
1397 PyCursesWindow_Scroll(PyCursesWindowObject
*self
, PyObject
*args
)
1400 switch(PyTuple_Size(args
)) {
1402 return PyCursesCheckERR(scroll(self
->win
), "scroll");
1404 if (!PyArg_ParseTuple(args
, "i;nlines", &nlines
))
1406 return PyCursesCheckERR(wscrl(self
->win
, nlines
), "scroll");
1408 PyErr_SetString(PyExc_TypeError
, "scroll requires 0 or 1 arguments");
1414 PyCursesWindow_TouchLine(PyCursesWindowObject
*self
, PyObject
*args
)
1417 switch (PyTuple_Size(args
)) {
1419 if (!PyArg_ParseTuple(args
,"ii;start,count",&st
,&cnt
))
1421 return PyCursesCheckERR(touchline(self
->win
,st
,cnt
), "touchline");
1423 if (!PyArg_ParseTuple(args
, "iii;start,count,val", &st
, &cnt
, &val
))
1425 return PyCursesCheckERR(wtouchln(self
->win
, st
, cnt
, val
), "touchline");
1427 PyErr_SetString(PyExc_TypeError
, "touchline requires 2 or 3 arguments");
1433 PyCursesWindow_Vline(PyCursesWindowObject
*self
, PyObject
*args
)
1437 int n
, x
, y
, code
= OK
;
1438 attr_t attr
= A_NORMAL
;
1440 switch (PyTuple_Size(args
)) {
1442 if (!PyArg_ParseTuple(args
, "Oi;ch or int,n", &temp
, &n
))
1446 if (!PyArg_ParseTuple(args
, "Oil;ch or int,n,attr", &temp
, &n
, &attr
))
1450 if (!PyArg_ParseTuple(args
, "iiOi;y,x,ch or int,n", &y
, &x
, &temp
, &n
))
1452 code
= wmove(self
->win
, y
, x
);
1455 if (!PyArg_ParseTuple(args
, "iiOil; y,x,ch or int,n,attr",
1456 &y
, &x
, &temp
, &n
, &attr
))
1458 code
= wmove(self
->win
, y
, x
);
1461 PyErr_SetString(PyExc_TypeError
, "vline requires 2 to 5 arguments");
1466 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
1467 PyErr_SetString(PyExc_TypeError
,
1468 "argument 1 or 3 must be a ch or an int");
1471 return PyCursesCheckERR(wvline(self
->win
, ch
| attr
, n
), "vline");
1473 return PyCursesCheckERR(code
, "wmove");
1476 static PyMethodDef PyCursesWindow_Methods
[] = {
1477 {"addch", (PyCFunction
)PyCursesWindow_AddCh
, METH_VARARGS
},
1478 {"addnstr", (PyCFunction
)PyCursesWindow_AddNStr
, METH_VARARGS
},
1479 {"addstr", (PyCFunction
)PyCursesWindow_AddStr
, METH_VARARGS
},
1480 {"attroff", (PyCFunction
)PyCursesWindow_wattroff
, METH_VARARGS
},
1481 {"attron", (PyCFunction
)PyCursesWindow_wattron
, METH_VARARGS
},
1482 {"attrset", (PyCFunction
)PyCursesWindow_wattrset
, METH_VARARGS
},
1483 {"bkgd", (PyCFunction
)PyCursesWindow_Bkgd
, METH_VARARGS
},
1484 {"chgat", (PyCFunction
)PyCursesWindow_ChgAt
, METH_VARARGS
},
1485 {"bkgdset", (PyCFunction
)PyCursesWindow_BkgdSet
, METH_VARARGS
},
1486 {"border", (PyCFunction
)PyCursesWindow_Border
, METH_VARARGS
},
1487 {"box", (PyCFunction
)PyCursesWindow_Box
, METH_VARARGS
},
1488 {"clear", (PyCFunction
)PyCursesWindow_wclear
, METH_NOARGS
},
1489 {"clearok", (PyCFunction
)PyCursesWindow_clearok
, METH_VARARGS
},
1490 {"clrtobot", (PyCFunction
)PyCursesWindow_wclrtobot
, METH_NOARGS
},
1491 {"clrtoeol", (PyCFunction
)PyCursesWindow_wclrtoeol
, METH_NOARGS
},
1492 {"cursyncup", (PyCFunction
)PyCursesWindow_wcursyncup
, METH_NOARGS
},
1493 {"delch", (PyCFunction
)PyCursesWindow_DelCh
, METH_VARARGS
},
1494 {"deleteln", (PyCFunction
)PyCursesWindow_wdeleteln
, METH_NOARGS
},
1495 {"derwin", (PyCFunction
)PyCursesWindow_DerWin
, METH_VARARGS
},
1496 {"echochar", (PyCFunction
)PyCursesWindow_EchoChar
, METH_VARARGS
},
1497 #ifdef NCURSES_MOUSE_VERSION
1498 {"enclose", (PyCFunction
)PyCursesWindow_Enclose
, METH_VARARGS
},
1500 {"erase", (PyCFunction
)PyCursesWindow_werase
, METH_NOARGS
},
1501 {"getbegyx", (PyCFunction
)PyCursesWindow_getbegyx
, METH_NOARGS
},
1502 {"getbkgd", (PyCFunction
)PyCursesWindow_GetBkgd
, METH_NOARGS
},
1503 {"getch", (PyCFunction
)PyCursesWindow_GetCh
, METH_VARARGS
},
1504 {"getkey", (PyCFunction
)PyCursesWindow_GetKey
, METH_VARARGS
},
1505 {"getmaxyx", (PyCFunction
)PyCursesWindow_getmaxyx
, METH_NOARGS
},
1506 {"getparyx", (PyCFunction
)PyCursesWindow_getparyx
, METH_NOARGS
},
1507 {"getstr", (PyCFunction
)PyCursesWindow_GetStr
, METH_VARARGS
},
1508 {"getyx", (PyCFunction
)PyCursesWindow_getyx
, METH_NOARGS
},
1509 {"hline", (PyCFunction
)PyCursesWindow_Hline
, METH_VARARGS
},
1510 {"idcok", (PyCFunction
)PyCursesWindow_idcok
, METH_VARARGS
},
1511 {"idlok", (PyCFunction
)PyCursesWindow_idlok
, METH_VARARGS
},
1512 {"immedok", (PyCFunction
)PyCursesWindow_immedok
, METH_VARARGS
},
1513 {"inch", (PyCFunction
)PyCursesWindow_InCh
, METH_VARARGS
},
1514 {"insch", (PyCFunction
)PyCursesWindow_InsCh
, METH_VARARGS
},
1515 {"insdelln", (PyCFunction
)PyCursesWindow_winsdelln
, METH_VARARGS
},
1516 {"insertln", (PyCFunction
)PyCursesWindow_winsertln
, METH_NOARGS
},
1517 {"insnstr", (PyCFunction
)PyCursesWindow_InsNStr
, METH_VARARGS
},
1518 {"insstr", (PyCFunction
)PyCursesWindow_InsStr
, METH_VARARGS
},
1519 {"instr", (PyCFunction
)PyCursesWindow_InStr
, METH_VARARGS
},
1520 {"is_linetouched", (PyCFunction
)PyCursesWindow_Is_LineTouched
, METH_VARARGS
},
1521 {"is_wintouched", (PyCFunction
)PyCursesWindow_is_wintouched
, METH_NOARGS
},
1522 {"keypad", (PyCFunction
)PyCursesWindow_keypad
, METH_VARARGS
},
1523 {"leaveok", (PyCFunction
)PyCursesWindow_leaveok
, METH_VARARGS
},
1524 {"move", (PyCFunction
)PyCursesWindow_wmove
, METH_VARARGS
},
1525 {"mvderwin", (PyCFunction
)PyCursesWindow_mvderwin
, METH_VARARGS
},
1526 {"mvwin", (PyCFunction
)PyCursesWindow_mvwin
, METH_VARARGS
},
1527 {"nodelay", (PyCFunction
)PyCursesWindow_nodelay
, METH_VARARGS
},
1528 {"notimeout", (PyCFunction
)PyCursesWindow_notimeout
, METH_VARARGS
},
1529 {"noutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
, METH_VARARGS
},
1530 /* Backward compatibility alias -- remove in Python 2.3 */
1531 {"nooutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
, METH_VARARGS
},
1532 {"overlay", (PyCFunction
)PyCursesWindow_Overlay
, METH_VARARGS
},
1533 {"overwrite", (PyCFunction
)PyCursesWindow_Overwrite
,
1535 {"putwin", (PyCFunction
)PyCursesWindow_PutWin
, METH_VARARGS
},
1536 {"redrawln", (PyCFunction
)PyCursesWindow_RedrawLine
, METH_VARARGS
},
1537 {"redrawwin", (PyCFunction
)PyCursesWindow_redrawwin
, METH_NOARGS
},
1538 {"refresh", (PyCFunction
)PyCursesWindow_Refresh
, METH_VARARGS
},
1539 #ifndef STRICT_SYSV_CURSES
1540 {"resize", (PyCFunction
)PyCursesWindow_wresize
, METH_VARARGS
},
1542 {"scroll", (PyCFunction
)PyCursesWindow_Scroll
, METH_VARARGS
},
1543 {"scrollok", (PyCFunction
)PyCursesWindow_scrollok
, METH_VARARGS
},
1544 {"setscrreg", (PyCFunction
)PyCursesWindow_SetScrollRegion
, METH_VARARGS
},
1545 {"standend", (PyCFunction
)PyCursesWindow_wstandend
, METH_NOARGS
},
1546 {"standout", (PyCFunction
)PyCursesWindow_wstandout
, METH_NOARGS
},
1547 {"subpad", (PyCFunction
)PyCursesWindow_SubWin
, METH_VARARGS
},
1548 {"subwin", (PyCFunction
)PyCursesWindow_SubWin
, METH_VARARGS
},
1549 {"syncdown", (PyCFunction
)PyCursesWindow_wsyncdown
, METH_NOARGS
},
1550 {"syncok", (PyCFunction
)PyCursesWindow_syncok
, METH_VARARGS
},
1551 {"syncup", (PyCFunction
)PyCursesWindow_wsyncup
, METH_NOARGS
},
1552 {"timeout", (PyCFunction
)PyCursesWindow_wtimeout
, METH_VARARGS
},
1553 {"touchline", (PyCFunction
)PyCursesWindow_TouchLine
, METH_VARARGS
},
1554 {"touchwin", (PyCFunction
)PyCursesWindow_touchwin
, METH_NOARGS
},
1555 {"untouchwin", (PyCFunction
)PyCursesWindow_untouchwin
, METH_NOARGS
},
1556 {"vline", (PyCFunction
)PyCursesWindow_Vline
, METH_VARARGS
},
1557 {NULL
, NULL
} /* sentinel */
1561 PyCursesWindow_GetAttr(PyCursesWindowObject
*self
, char *name
)
1563 return Py_FindMethod(PyCursesWindow_Methods
, (PyObject
*)self
, name
);
1566 /* -------------------------------------------------------*/
1568 PyTypeObject PyCursesWindow_Type
= {
1569 PyVarObject_HEAD_INIT(NULL
, 0)
1570 "_curses.curses window", /*tp_name*/
1571 sizeof(PyCursesWindowObject
), /*tp_basicsize*/
1574 (destructor
)PyCursesWindow_Dealloc
, /*tp_dealloc*/
1576 (getattrfunc
)PyCursesWindow_GetAttr
, /*tp_getattr*/
1577 (setattrfunc
)0, /*tp_setattr*/
1581 0, /*tp_as_sequence*/
1582 0, /*tp_as_mapping*/
1586 /*********************************************************************
1588 **********************************************************************/
1590 NoArgNoReturnFunction(beep
)
1591 NoArgNoReturnFunction(def_prog_mode
)
1592 NoArgNoReturnFunction(def_shell_mode
)
1593 NoArgNoReturnFunction(doupdate
)
1594 NoArgNoReturnFunction(endwin
)
1595 NoArgNoReturnFunction(flash
)
1596 NoArgNoReturnFunction(nocbreak
)
1597 NoArgNoReturnFunction(noecho
)
1598 NoArgNoReturnFunction(nonl
)
1599 NoArgNoReturnFunction(noraw
)
1600 NoArgNoReturnFunction(reset_prog_mode
)
1601 NoArgNoReturnFunction(reset_shell_mode
)
1602 NoArgNoReturnFunction(resetty
)
1603 NoArgNoReturnFunction(savetty
)
1605 NoArgOrFlagNoReturnFunction(cbreak
)
1606 NoArgOrFlagNoReturnFunction(echo
)
1607 NoArgOrFlagNoReturnFunction(nl
)
1608 NoArgOrFlagNoReturnFunction(raw
)
1610 NoArgReturnIntFunction(baudrate
)
1611 NoArgReturnIntFunction(termattrs
)
1613 NoArgReturnStringFunction(termname
)
1614 NoArgReturnStringFunction(longname
)
1616 NoArgTrueFalseFunction(can_change_color
)
1617 NoArgTrueFalseFunction(has_colors
)
1618 NoArgTrueFalseFunction(has_ic
)
1619 NoArgTrueFalseFunction(has_il
)
1620 NoArgTrueFalseFunction(isendwin
)
1621 NoArgNoReturnVoidFunction(filter
)
1622 NoArgNoReturnVoidFunction(flushinp
)
1623 NoArgNoReturnVoidFunction(noqiflush
)
1626 PyCurses_Color_Content(PyObject
*self
, PyObject
*args
)
1631 PyCursesInitialisedColor
1633 if (!PyArg_ParseTuple(args
, "h:color_content", &color
)) return NULL
;
1635 if (color_content(color
, &r
, &g
, &b
) != ERR
)
1636 return Py_BuildValue("(iii)", r
, g
, b
);
1638 PyErr_SetString(PyCursesError
,
1639 "Argument 1 was out of range. Check value of COLORS.");
1645 PyCurses_color_pair(PyObject
*self
, PyObject
*args
)
1650 PyCursesInitialisedColor
1652 if (!PyArg_ParseTuple(args
, "i:color_pair", &n
)) return NULL
;
1653 return PyInt_FromLong((long) (n
<< 8));
1657 PyCurses_Curs_Set(PyObject
*self
, PyObject
*args
)
1663 if (!PyArg_ParseTuple(args
, "i:curs_set", &vis
)) return NULL
;
1665 erg
= curs_set(vis
);
1666 if (erg
== ERR
) return PyCursesCheckERR(erg
, "curs_set");
1668 return PyInt_FromLong((long) erg
);
1672 PyCurses_Delay_Output(PyObject
*self
, PyObject
*args
)
1678 if (!PyArg_ParseTuple(args
, "i:delay_output", &ms
)) return NULL
;
1680 return PyCursesCheckERR(delay_output(ms
), "delay_output");
1684 PyCurses_EraseChar(PyObject
*self
)
1692 return PyString_FromStringAndSize(&ch
, 1);
1696 PyCurses_getsyx(PyObject
*self
)
1704 return Py_BuildValue("(ii)", y
, x
);
1707 #ifdef NCURSES_MOUSE_VERSION
1709 PyCurses_GetMouse(PyObject
*self
)
1716 rtn
= getmouse( &event
);
1718 PyErr_SetString(PyCursesError
, "getmouse() returned ERR");
1721 return Py_BuildValue("(hiiil)",
1723 event
.x
, event
.y
, event
.z
,
1724 (long) event
.bstate
);
1728 PyCurses_UngetMouse(PyObject
*self
, PyObject
*args
)
1733 if (!PyArg_ParseTuple(args
, "hiiil",
1735 &event
.x
, &event
.y
, &event
.z
,
1736 (int *) &event
.bstate
))
1739 return PyCursesCheckERR(ungetmouse(&event
), "ungetmouse");
1744 PyCurses_GetWin(PyCursesWindowObject
*self
, PyObject
*temp
)
1750 if (!PyFile_Check(temp
)) {
1751 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1755 win
= getwin(PyFile_AsFile(temp
));
1758 PyErr_SetString(PyCursesError
, catchall_NULL
);
1762 return PyCursesWindow_New(win
);
1766 PyCurses_HalfDelay(PyObject
*self
, PyObject
*args
)
1768 unsigned char tenths
;
1772 if (!PyArg_ParseTuple(args
, "b:halfdelay", &tenths
)) return NULL
;
1774 return PyCursesCheckERR(halfdelay(tenths
), "halfdelay");
1777 #ifndef STRICT_SYSV_CURSES
1779 static PyObject
* PyCurses_has_key(PyObject
*self
, PyObject
*args
)
1785 if (!PyArg_ParseTuple(args
,"i",&ch
)) return NULL
;
1787 if (has_key(ch
) == FALSE
) {
1788 Py_INCREF(Py_False
);
1794 #endif /* STRICT_SYSV_CURSES */
1797 PyCurses_Init_Color(PyObject
*self
, PyObject
*args
)
1799 short color
, r
, g
, b
;
1802 PyCursesInitialisedColor
1804 switch(PyTuple_Size(args
)) {
1806 if (!PyArg_ParseTuple(args
, "hhhh;color,r,g,b", &color
, &r
, &g
, &b
)) return NULL
;
1809 PyErr_SetString(PyExc_TypeError
, "init_color requires 4 arguments");
1813 return PyCursesCheckERR(init_color(color
, r
, g
, b
), "init_color");
1817 PyCurses_Init_Pair(PyObject
*self
, PyObject
*args
)
1822 PyCursesInitialisedColor
1824 if (PyTuple_Size(args
) != 3) {
1825 PyErr_SetString(PyExc_TypeError
, "init_pair requires 3 arguments");
1829 if (!PyArg_ParseTuple(args
, "hhh;pair, f, b", &pair
, &f
, &b
)) return NULL
;
1831 return PyCursesCheckERR(init_pair(pair
, f
, b
), "init_pair");
1834 static PyObject
*ModDict
;
1837 PyCurses_InitScr(PyObject
*self
)
1841 if (initialised
== TRUE
) {
1843 return (PyObject
*)PyCursesWindow_New(stdscr
);
1849 PyErr_SetString(PyCursesError
, catchall_NULL
);
1853 initialised
= initialised_setupterm
= TRUE
;
1855 /* This was moved from initcurses() because it core dumped on SGI,
1856 where they're not defined until you've called initscr() */
1857 #define SetDictInt(string,ch) \
1859 PyObject *o = PyInt_FromLong((long) (ch)); \
1860 if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \
1865 /* Here are some graphic symbols you can use */
1866 SetDictInt("ACS_ULCORNER", (ACS_ULCORNER
));
1867 SetDictInt("ACS_LLCORNER", (ACS_LLCORNER
));
1868 SetDictInt("ACS_URCORNER", (ACS_URCORNER
));
1869 SetDictInt("ACS_LRCORNER", (ACS_LRCORNER
));
1870 SetDictInt("ACS_LTEE", (ACS_LTEE
));
1871 SetDictInt("ACS_RTEE", (ACS_RTEE
));
1872 SetDictInt("ACS_BTEE", (ACS_BTEE
));
1873 SetDictInt("ACS_TTEE", (ACS_TTEE
));
1874 SetDictInt("ACS_HLINE", (ACS_HLINE
));
1875 SetDictInt("ACS_VLINE", (ACS_VLINE
));
1876 SetDictInt("ACS_PLUS", (ACS_PLUS
));
1877 #if !defined(__hpux) || defined(HAVE_NCURSES_H)
1878 /* On HP/UX 11, these are of type cchar_t, which is not an
1879 integral type. If this is a problem on more platforms, a
1880 configure test should be added to determine whether ACS_S1
1881 is of integral type. */
1882 SetDictInt("ACS_S1", (ACS_S1
));
1883 SetDictInt("ACS_S9", (ACS_S9
));
1884 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND
));
1885 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD
));
1886 SetDictInt("ACS_DEGREE", (ACS_DEGREE
));
1887 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS
));
1888 SetDictInt("ACS_BULLET", (ACS_BULLET
));
1889 SetDictInt("ACS_LARROW", (ACS_LARROW
));
1890 SetDictInt("ACS_RARROW", (ACS_RARROW
));
1891 SetDictInt("ACS_DARROW", (ACS_DARROW
));
1892 SetDictInt("ACS_UARROW", (ACS_UARROW
));
1893 SetDictInt("ACS_BOARD", (ACS_BOARD
));
1894 SetDictInt("ACS_LANTERN", (ACS_LANTERN
));
1895 SetDictInt("ACS_BLOCK", (ACS_BLOCK
));
1897 SetDictInt("ACS_BSSB", (ACS_ULCORNER
));
1898 SetDictInt("ACS_SSBB", (ACS_LLCORNER
));
1899 SetDictInt("ACS_BBSS", (ACS_URCORNER
));
1900 SetDictInt("ACS_SBBS", (ACS_LRCORNER
));
1901 SetDictInt("ACS_SBSS", (ACS_RTEE
));
1902 SetDictInt("ACS_SSSB", (ACS_LTEE
));
1903 SetDictInt("ACS_SSBS", (ACS_BTEE
));
1904 SetDictInt("ACS_BSSS", (ACS_TTEE
));
1905 SetDictInt("ACS_BSBS", (ACS_HLINE
));
1906 SetDictInt("ACS_SBSB", (ACS_VLINE
));
1907 SetDictInt("ACS_SSSS", (ACS_PLUS
));
1909 /* The following are never available with strict SYSV curses */
1911 SetDictInt("ACS_S3", (ACS_S3
));
1914 SetDictInt("ACS_S7", (ACS_S7
));
1917 SetDictInt("ACS_LEQUAL", (ACS_LEQUAL
));
1920 SetDictInt("ACS_GEQUAL", (ACS_GEQUAL
));
1923 SetDictInt("ACS_PI", (ACS_PI
));
1926 SetDictInt("ACS_NEQUAL", (ACS_NEQUAL
));
1929 SetDictInt("ACS_STERLING", (ACS_STERLING
));
1932 SetDictInt("LINES", LINES
);
1933 SetDictInt("COLS", COLS
);
1935 return (PyObject
*)PyCursesWindow_New(win
);
1939 PyCurses_setupterm(PyObject
* self
, PyObject
*args
, PyObject
* keywds
)
1943 char* termstr
= NULL
;
1945 static char *kwlist
[] = {"term", "fd", NULL
};
1947 if (!PyArg_ParseTupleAndKeywords(
1948 args
, keywds
, "|zi:setupterm", kwlist
, &termstr
, &fd
)) {
1953 PyObject
* sys_stdout
;
1955 sys_stdout
= PySys_GetObject("stdout");
1957 if (sys_stdout
== NULL
) {
1964 fd
= PyObject_AsFileDescriptor(sys_stdout
);
1971 if (setupterm(termstr
,fd
,&err
) == ERR
) {
1972 char* s
= "setupterm: unknown error";
1975 s
= "setupterm: could not find terminal";
1976 } else if (err
== -1) {
1977 s
= "setupterm: could not find terminfo database";
1980 PyErr_SetString(PyCursesError
,s
);
1984 initialised_setupterm
= TRUE
;
1991 PyCurses_IntrFlush(PyObject
*self
, PyObject
*args
)
1997 switch(PyTuple_Size(args
)) {
1999 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&ch
)) return NULL
;
2002 PyErr_SetString(PyExc_TypeError
, "intrflush requires 1 argument");
2006 return PyCursesCheckERR(intrflush(NULL
,ch
), "intrflush");
2009 #ifdef HAVE_CURSES_IS_TERM_RESIZED
2011 PyCurses_Is_Term_Resized(PyObject
*self
, PyObject
*args
)
2019 if (!PyArg_ParseTuple(args
,"ii:is_term_resized", &lines
, &columns
))
2021 result
= is_term_resized(lines
, columns
);
2022 if (result
== TRUE
) {
2026 Py_INCREF(Py_False
);
2030 #endif /* HAVE_CURSES_IS_TERM_RESIZED */
2032 #if !defined(__NetBSD__)
2034 PyCurses_KeyName(PyObject
*self
, PyObject
*args
)
2041 if (!PyArg_ParseTuple(args
,"i",&ch
)) return NULL
;
2044 PyErr_SetString(PyExc_ValueError
, "invalid key number");
2049 return PyString_FromString((knp
== NULL
) ? "" : (char *)knp
);
2054 PyCurses_KillChar(PyObject
*self
)
2060 return PyString_FromStringAndSize(&ch
, 1);
2064 PyCurses_Meta(PyObject
*self
, PyObject
*args
)
2070 switch(PyTuple_Size(args
)) {
2072 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&ch
)) return NULL
;
2075 PyErr_SetString(PyExc_TypeError
, "meta requires 1 argument");
2079 return PyCursesCheckERR(meta(stdscr
, ch
), "meta");
2082 #ifdef NCURSES_MOUSE_VERSION
2084 PyCurses_MouseInterval(PyObject
*self
, PyObject
*args
)
2089 if (!PyArg_ParseTuple(args
,"i;interval",&interval
))
2091 return PyCursesCheckERR(mouseinterval(interval
), "mouseinterval");
2095 PyCurses_MouseMask(PyObject
*self
, PyObject
*args
)
2098 mmask_t oldmask
, availmask
;
2101 if (!PyArg_ParseTuple(args
,"i;mousemask",&newmask
))
2103 availmask
= mousemask(newmask
, &oldmask
);
2104 return Py_BuildValue("(ll)", (long)availmask
, (long)oldmask
);
2109 PyCurses_Napms(PyObject
*self
, PyObject
*args
)
2114 if (!PyArg_ParseTuple(args
, "i;ms", &ms
)) return NULL
;
2116 return Py_BuildValue("i", napms(ms
));
2121 PyCurses_NewPad(PyObject
*self
, PyObject
*args
)
2128 if (!PyArg_ParseTuple(args
,"ii;nlines,ncols",&nlines
,&ncols
)) return NULL
;
2130 win
= newpad(nlines
, ncols
);
2133 PyErr_SetString(PyCursesError
, catchall_NULL
);
2137 return (PyObject
*)PyCursesWindow_New(win
);
2141 PyCurses_NewWindow(PyObject
*self
, PyObject
*args
)
2144 int nlines
, ncols
, begin_y
=0, begin_x
=0;
2148 switch (PyTuple_Size(args
)) {
2150 if (!PyArg_ParseTuple(args
,"ii;nlines,ncols",&nlines
,&ncols
))
2154 if (!PyArg_ParseTuple(args
, "iiii;nlines,ncols,begin_y,begin_x",
2155 &nlines
,&ncols
,&begin_y
,&begin_x
))
2159 PyErr_SetString(PyExc_TypeError
, "newwin requires 2 or 4 arguments");
2163 win
= newwin(nlines
,ncols
,begin_y
,begin_x
);
2165 PyErr_SetString(PyCursesError
, catchall_NULL
);
2169 return (PyObject
*)PyCursesWindow_New(win
);
2173 PyCurses_Pair_Content(PyObject
*self
, PyObject
*args
)
2178 PyCursesInitialisedColor
2180 switch(PyTuple_Size(args
)) {
2182 if (!PyArg_ParseTuple(args
, "h;pair", &pair
)) return NULL
;
2185 PyErr_SetString(PyExc_TypeError
, "pair_content requires 1 argument");
2189 if (pair_content(pair
, &f
, &b
)==ERR
) {
2190 PyErr_SetString(PyCursesError
,
2191 "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
2195 return Py_BuildValue("(ii)", f
, b
);
2199 PyCurses_pair_number(PyObject
*self
, PyObject
*args
)
2204 PyCursesInitialisedColor
2206 switch(PyTuple_Size(args
)) {
2208 if (!PyArg_ParseTuple(args
, "i;pairvalue", &n
)) return NULL
;
2211 PyErr_SetString(PyExc_TypeError
,
2212 "pair_number requires 1 argument");
2216 return PyInt_FromLong((long) ((n
& A_COLOR
) >> 8));
2220 PyCurses_Putp(PyObject
*self
, PyObject
*args
)
2224 if (!PyArg_ParseTuple(args
,"s;str", &str
)) return NULL
;
2225 return PyCursesCheckERR(putp(str
), "putp");
2229 PyCurses_QiFlush(PyObject
*self
, PyObject
*args
)
2235 switch(PyTuple_Size(args
)) {
2241 if (!PyArg_ParseTuple(args
, "i;True(1) or False(0)", &flag
)) return NULL
;
2242 if (flag
) qiflush();
2247 PyErr_SetString(PyExc_TypeError
, "qiflush requires 0 or 1 arguments");
2252 /* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
2253 * and _curses.COLS */
2255 update_lines_cols(void)
2258 PyObject
*m
= PyImport_ImportModuleNoBlock("curses");
2263 o
= PyInt_FromLong(LINES
);
2268 if (PyObject_SetAttrString(m
, "LINES", o
)) {
2273 if (PyDict_SetItemString(ModDict
, "LINES", o
)) {
2279 o
= PyInt_FromLong(COLS
);
2284 if (PyObject_SetAttrString(m
, "COLS", o
)) {
2289 if (PyDict_SetItemString(ModDict
, "COLS", o
)) {
2299 #ifdef HAVE_CURSES_RESIZETERM
2301 PyCurses_ResizeTerm(PyObject
*self
, PyObject
*args
)
2309 if (!PyArg_ParseTuple(args
,"ii:resizeterm", &lines
, &columns
))
2312 result
= PyCursesCheckERR(resizeterm(lines
, columns
), "resizeterm");
2315 if (!update_lines_cols())
2322 #ifdef HAVE_CURSES_RESIZE_TERM
2324 PyCurses_Resize_Term(PyObject
*self
, PyObject
*args
)
2333 if (!PyArg_ParseTuple(args
,"ii:resize_term", &lines
, &columns
))
2336 result
= PyCursesCheckERR(resize_term(lines
, columns
), "resize_term");
2339 if (!update_lines_cols())
2343 #endif /* HAVE_CURSES_RESIZE_TERM */
2346 PyCurses_setsyx(PyObject
*self
, PyObject
*args
)
2352 if (PyTuple_Size(args
)!=2) {
2353 PyErr_SetString(PyExc_TypeError
, "setsyx requires 2 arguments");
2357 if (!PyArg_ParseTuple(args
, "ii;y, x", &y
, &x
)) return NULL
;
2366 PyCurses_Start_Color(PyObject
*self
)
2373 code
= start_color();
2375 initialisedcolors
= TRUE
;
2376 c
= PyInt_FromLong((long) COLORS
);
2377 PyDict_SetItemString(ModDict
, "COLORS", c
);
2379 cp
= PyInt_FromLong((long) COLOR_PAIRS
);
2380 PyDict_SetItemString(ModDict
, "COLOR_PAIRS", cp
);
2385 PyErr_SetString(PyCursesError
, "start_color() returned ERR");
2391 PyCurses_tigetflag(PyObject
*self
, PyObject
*args
)
2395 PyCursesSetupTermCalled
;
2397 if (!PyArg_ParseTuple(args
, "z", &capname
))
2400 return PyInt_FromLong( (long) tigetflag( capname
) );
2404 PyCurses_tigetnum(PyObject
*self
, PyObject
*args
)
2408 PyCursesSetupTermCalled
;
2410 if (!PyArg_ParseTuple(args
, "z", &capname
))
2413 return PyInt_FromLong( (long) tigetnum( capname
) );
2417 PyCurses_tigetstr(PyObject
*self
, PyObject
*args
)
2421 PyCursesSetupTermCalled
;
2423 if (!PyArg_ParseTuple(args
, "z", &capname
))
2426 capname
= tigetstr( capname
);
2427 if (capname
== 0 || capname
== (char*) -1) {
2431 return PyString_FromString( capname
);
2435 PyCurses_tparm(PyObject
*self
, PyObject
*args
)
2438 char* result
= NULL
;
2439 int i1
=0,i2
=0,i3
=0,i4
=0,i5
=0,i6
=0,i7
=0,i8
=0,i9
=0;
2441 PyCursesSetupTermCalled
;
2443 if (!PyArg_ParseTuple(args
, "s|iiiiiiiii:tparm",
2444 &fmt
, &i1
, &i2
, &i3
, &i4
,
2445 &i5
, &i6
, &i7
, &i8
, &i9
)) {
2449 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
,i9
);
2451 PyErr_SetString(PyCursesError
, "tparm() returned NULL");
2455 return PyString_FromString(result
);
2459 PyCurses_TypeAhead(PyObject
*self
, PyObject
*args
)
2465 if (!PyArg_ParseTuple(args
,"i;fd",&fd
)) return NULL
;
2467 return PyCursesCheckERR(typeahead( fd
), "typeahead");
2471 PyCurses_UnCtrl(PyObject
*self
, PyObject
*args
)
2478 if (!PyArg_ParseTuple(args
,"O;ch or int",&temp
)) return NULL
;
2480 if (PyInt_Check(temp
))
2481 ch
= (chtype
) PyInt_AsLong(temp
);
2482 else if (PyString_Check(temp
))
2483 ch
= (chtype
) *PyString_AsString(temp
);
2485 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2489 return PyString_FromString(unctrl(ch
));
2493 PyCurses_UngetCh(PyObject
*self
, PyObject
*args
)
2500 if (!PyArg_ParseTuple(args
,"O;ch or int",&temp
)) return NULL
;
2502 if (PyInt_Check(temp
))
2503 ch
= (int) PyInt_AsLong(temp
);
2504 else if (PyString_Check(temp
))
2505 ch
= (int) *PyString_AsString(temp
);
2507 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2511 return PyCursesCheckERR(ungetch(ch
), "ungetch");
2515 PyCurses_Use_Env(PyObject
*self
, PyObject
*args
)
2521 switch(PyTuple_Size(args
)) {
2523 if (!PyArg_ParseTuple(args
,"i;True(1), False(0)",&flag
))
2527 PyErr_SetString(PyExc_TypeError
, "use_env requires 1 argument");
2535 #ifndef STRICT_SYSV_CURSES
2537 PyCurses_Use_Default_Colors(PyObject
*self
)
2542 PyCursesInitialisedColor
2544 code
= use_default_colors();
2549 PyErr_SetString(PyCursesError
, "use_default_colors() returned ERR");
2553 #endif /* STRICT_SYSV_CURSES */
2555 /* List of functions defined in the module */
2557 static PyMethodDef PyCurses_methods
[] = {
2558 {"baudrate", (PyCFunction
)PyCurses_baudrate
, METH_NOARGS
},
2559 {"beep", (PyCFunction
)PyCurses_beep
, METH_NOARGS
},
2560 {"can_change_color", (PyCFunction
)PyCurses_can_change_color
, METH_NOARGS
},
2561 {"cbreak", (PyCFunction
)PyCurses_cbreak
, METH_VARARGS
},
2562 {"color_content", (PyCFunction
)PyCurses_Color_Content
, METH_VARARGS
},
2563 {"color_pair", (PyCFunction
)PyCurses_color_pair
, METH_VARARGS
},
2564 {"curs_set", (PyCFunction
)PyCurses_Curs_Set
, METH_VARARGS
},
2565 {"def_prog_mode", (PyCFunction
)PyCurses_def_prog_mode
, METH_NOARGS
},
2566 {"def_shell_mode", (PyCFunction
)PyCurses_def_shell_mode
, METH_NOARGS
},
2567 {"delay_output", (PyCFunction
)PyCurses_Delay_Output
, METH_VARARGS
},
2568 {"doupdate", (PyCFunction
)PyCurses_doupdate
, METH_NOARGS
},
2569 {"echo", (PyCFunction
)PyCurses_echo
, METH_VARARGS
},
2570 {"endwin", (PyCFunction
)PyCurses_endwin
, METH_NOARGS
},
2571 {"erasechar", (PyCFunction
)PyCurses_EraseChar
, METH_NOARGS
},
2572 {"filter", (PyCFunction
)PyCurses_filter
, METH_NOARGS
},
2573 {"flash", (PyCFunction
)PyCurses_flash
, METH_NOARGS
},
2574 {"flushinp", (PyCFunction
)PyCurses_flushinp
, METH_NOARGS
},
2575 #ifdef NCURSES_MOUSE_VERSION
2576 {"getmouse", (PyCFunction
)PyCurses_GetMouse
, METH_NOARGS
},
2577 {"ungetmouse", (PyCFunction
)PyCurses_UngetMouse
, METH_VARARGS
},
2579 {"getsyx", (PyCFunction
)PyCurses_getsyx
, METH_NOARGS
},
2580 {"getwin", (PyCFunction
)PyCurses_GetWin
, METH_O
},
2581 {"has_colors", (PyCFunction
)PyCurses_has_colors
, METH_NOARGS
},
2582 {"has_ic", (PyCFunction
)PyCurses_has_ic
, METH_NOARGS
},
2583 {"has_il", (PyCFunction
)PyCurses_has_il
, METH_NOARGS
},
2584 #ifndef STRICT_SYSV_CURSES
2585 {"has_key", (PyCFunction
)PyCurses_has_key
, METH_VARARGS
},
2587 {"halfdelay", (PyCFunction
)PyCurses_HalfDelay
, METH_VARARGS
},
2588 {"init_color", (PyCFunction
)PyCurses_Init_Color
, METH_VARARGS
},
2589 {"init_pair", (PyCFunction
)PyCurses_Init_Pair
, METH_VARARGS
},
2590 {"initscr", (PyCFunction
)PyCurses_InitScr
, METH_NOARGS
},
2591 {"intrflush", (PyCFunction
)PyCurses_IntrFlush
, METH_VARARGS
},
2592 {"isendwin", (PyCFunction
)PyCurses_isendwin
, METH_NOARGS
},
2593 #ifdef HAVE_CURSES_IS_TERM_RESIZED
2594 {"is_term_resized", (PyCFunction
)PyCurses_Is_Term_Resized
, METH_VARARGS
},
2596 #if !defined(__NetBSD__)
2597 {"keyname", (PyCFunction
)PyCurses_KeyName
, METH_VARARGS
},
2599 {"killchar", (PyCFunction
)PyCurses_KillChar
, METH_NOARGS
},
2600 {"longname", (PyCFunction
)PyCurses_longname
, METH_NOARGS
},
2601 {"meta", (PyCFunction
)PyCurses_Meta
, METH_VARARGS
},
2602 #ifdef NCURSES_MOUSE_VERSION
2603 {"mouseinterval", (PyCFunction
)PyCurses_MouseInterval
, METH_VARARGS
},
2604 {"mousemask", (PyCFunction
)PyCurses_MouseMask
, METH_VARARGS
},
2606 {"napms", (PyCFunction
)PyCurses_Napms
, METH_VARARGS
},
2607 {"newpad", (PyCFunction
)PyCurses_NewPad
, METH_VARARGS
},
2608 {"newwin", (PyCFunction
)PyCurses_NewWindow
, METH_VARARGS
},
2609 {"nl", (PyCFunction
)PyCurses_nl
, METH_VARARGS
},
2610 {"nocbreak", (PyCFunction
)PyCurses_nocbreak
, METH_NOARGS
},
2611 {"noecho", (PyCFunction
)PyCurses_noecho
, METH_NOARGS
},
2612 {"nonl", (PyCFunction
)PyCurses_nonl
, METH_NOARGS
},
2613 {"noqiflush", (PyCFunction
)PyCurses_noqiflush
, METH_NOARGS
},
2614 {"noraw", (PyCFunction
)PyCurses_noraw
, METH_NOARGS
},
2615 {"pair_content", (PyCFunction
)PyCurses_Pair_Content
, METH_VARARGS
},
2616 {"pair_number", (PyCFunction
)PyCurses_pair_number
, METH_VARARGS
},
2617 {"putp", (PyCFunction
)PyCurses_Putp
, METH_VARARGS
},
2618 {"qiflush", (PyCFunction
)PyCurses_QiFlush
, METH_VARARGS
},
2619 {"raw", (PyCFunction
)PyCurses_raw
, METH_VARARGS
},
2620 {"reset_prog_mode", (PyCFunction
)PyCurses_reset_prog_mode
, METH_NOARGS
},
2621 {"reset_shell_mode", (PyCFunction
)PyCurses_reset_shell_mode
, METH_NOARGS
},
2622 {"resetty", (PyCFunction
)PyCurses_resetty
, METH_NOARGS
},
2623 #ifdef HAVE_CURSES_RESIZETERM
2624 {"resizeterm", (PyCFunction
)PyCurses_ResizeTerm
, METH_VARARGS
},
2626 #ifdef HAVE_CURSES_RESIZE_TERM
2627 {"resize_term", (PyCFunction
)PyCurses_Resize_Term
, METH_VARARGS
},
2629 {"savetty", (PyCFunction
)PyCurses_savetty
, METH_NOARGS
},
2630 {"setsyx", (PyCFunction
)PyCurses_setsyx
, METH_VARARGS
},
2631 {"setupterm", (PyCFunction
)PyCurses_setupterm
,
2632 METH_VARARGS
|METH_KEYWORDS
},
2633 {"start_color", (PyCFunction
)PyCurses_Start_Color
, METH_NOARGS
},
2634 {"termattrs", (PyCFunction
)PyCurses_termattrs
, METH_NOARGS
},
2635 {"termname", (PyCFunction
)PyCurses_termname
, METH_NOARGS
},
2636 {"tigetflag", (PyCFunction
)PyCurses_tigetflag
, METH_VARARGS
},
2637 {"tigetnum", (PyCFunction
)PyCurses_tigetnum
, METH_VARARGS
},
2638 {"tigetstr", (PyCFunction
)PyCurses_tigetstr
, METH_VARARGS
},
2639 {"tparm", (PyCFunction
)PyCurses_tparm
, METH_VARARGS
},
2640 {"typeahead", (PyCFunction
)PyCurses_TypeAhead
, METH_VARARGS
},
2641 {"unctrl", (PyCFunction
)PyCurses_UnCtrl
, METH_VARARGS
},
2642 {"ungetch", (PyCFunction
)PyCurses_UngetCh
, METH_VARARGS
},
2643 {"use_env", (PyCFunction
)PyCurses_Use_Env
, METH_VARARGS
},
2644 #ifndef STRICT_SYSV_CURSES
2645 {"use_default_colors", (PyCFunction
)PyCurses_Use_Default_Colors
, METH_NOARGS
},
2647 {NULL
, NULL
} /* sentinel */
2650 /* Initialization function for the module */
2655 PyObject
*m
, *d
, *v
, *c_api_object
;
2656 static void *PyCurses_API
[PyCurses_API_pointers
];
2658 /* Initialize object type */
2659 Py_TYPE(&PyCursesWindow_Type
) = &PyType_Type
;
2661 /* Initialize the C API pointer array */
2662 PyCurses_API
[0] = (void *)&PyCursesWindow_Type
;
2663 PyCurses_API
[1] = (void *)func_PyCursesSetupTermCalled
;
2664 PyCurses_API
[2] = (void *)func_PyCursesInitialised
;
2665 PyCurses_API
[3] = (void *)func_PyCursesInitialisedColor
;
2667 /* Create the module and add the functions */
2668 m
= Py_InitModule("_curses", PyCurses_methods
);
2672 /* Add some symbolic constants to the module */
2673 d
= PyModule_GetDict(m
);
2676 ModDict
= d
; /* For PyCurses_InitScr to use later */
2678 /* Add a CObject for the C API */
2679 c_api_object
= PyCObject_FromVoidPtr((void *)PyCurses_API
, NULL
);
2680 PyDict_SetItemString(d
, "_C_API", c_api_object
);
2681 Py_DECREF(c_api_object
);
2683 /* For exception curses.error */
2684 PyCursesError
= PyErr_NewException("_curses.error", NULL
, NULL
);
2685 PyDict_SetItemString(d
, "error", PyCursesError
);
2687 /* Make the version available */
2688 v
= PyString_FromString(PyCursesVersion
);
2689 PyDict_SetItemString(d
, "version", v
);
2690 PyDict_SetItemString(d
, "__version__", v
);
2693 SetDictInt("ERR", ERR
);
2694 SetDictInt("OK", OK
);
2696 /* Here are some attributes you can add to chars to print */
2698 SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES
);
2699 SetDictInt("A_NORMAL", A_NORMAL
);
2700 SetDictInt("A_STANDOUT", A_STANDOUT
);
2701 SetDictInt("A_UNDERLINE", A_UNDERLINE
);
2702 SetDictInt("A_REVERSE", A_REVERSE
);
2703 SetDictInt("A_BLINK", A_BLINK
);
2704 SetDictInt("A_DIM", A_DIM
);
2705 SetDictInt("A_BOLD", A_BOLD
);
2706 SetDictInt("A_ALTCHARSET", A_ALTCHARSET
);
2707 #if !defined(__NetBSD__)
2708 SetDictInt("A_INVIS", A_INVIS
);
2710 SetDictInt("A_PROTECT", A_PROTECT
);
2711 SetDictInt("A_CHARTEXT", A_CHARTEXT
);
2712 SetDictInt("A_COLOR", A_COLOR
);
2714 /* The following are never available with strict SYSV curses */
2716 SetDictInt("A_HORIZONTAL", A_HORIZONTAL
);
2719 SetDictInt("A_LEFT", A_LEFT
);
2722 SetDictInt("A_LOW", A_LOW
);
2725 SetDictInt("A_RIGHT", A_RIGHT
);
2728 SetDictInt("A_TOP", A_TOP
);
2731 SetDictInt("A_VERTICAL", A_VERTICAL
);
2734 SetDictInt("COLOR_BLACK", COLOR_BLACK
);
2735 SetDictInt("COLOR_RED", COLOR_RED
);
2736 SetDictInt("COLOR_GREEN", COLOR_GREEN
);
2737 SetDictInt("COLOR_YELLOW", COLOR_YELLOW
);
2738 SetDictInt("COLOR_BLUE", COLOR_BLUE
);
2739 SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA
);
2740 SetDictInt("COLOR_CYAN", COLOR_CYAN
);
2741 SetDictInt("COLOR_WHITE", COLOR_WHITE
);
2743 #ifdef NCURSES_MOUSE_VERSION
2744 /* Mouse-related constants */
2745 SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED
);
2746 SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED
);
2747 SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED
);
2748 SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED
);
2749 SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED
);
2751 SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED
);
2752 SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED
);
2753 SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED
);
2754 SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED
);
2755 SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED
);
2757 SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED
);
2758 SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED
);
2759 SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED
);
2760 SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED
);
2761 SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED
);
2763 SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED
);
2764 SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED
);
2765 SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED
);
2766 SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED
);
2767 SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED
);
2769 SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT
);
2770 SetDictInt("BUTTON_CTRL", BUTTON_CTRL
);
2771 SetDictInt("BUTTON_ALT", BUTTON_ALT
);
2773 SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS
);
2774 SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION
);
2776 /* Now set everything up for KEY_ variables */
2781 #if !defined(__NetBSD__)
2782 for (key
=KEY_MIN
;key
< KEY_MAX
; key
++) {
2783 key_n
= (char *)keyname(key
);
2784 if (key_n
== NULL
|| strcmp(key_n
,"UNKNOWN KEY")==0)
2786 if (strncmp(key_n
,"KEY_F(",6)==0) {
2788 key_n2
= malloc(strlen(key_n
)+1);
2796 if (*p1
!= '(' && *p1
!= ')') {
2805 SetDictInt(key_n2
,key
);
2806 if (key_n2
!= key_n
)
2810 SetDictInt("KEY_MIN", KEY_MIN
);
2811 SetDictInt("KEY_MAX", KEY_MAX
);