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 (amk1@bigfoot.com)
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.1";
103 #define CURSES_MODULE
104 #include "py_curses.h"
107 #define _XOPEN_SOURCE_EXTENDED /* Define macro for OSF/1 */
108 #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
111 /* These prototypes are in <term.h>, but including this header
112 #defines many common symbols (such as "lines") which breaks the
113 curses module in other ways. So the code will just specify
114 explicit prototypes here. */
115 extern int setupterm(char *,int,int *);
117 extern char *tigetstr(char *);
118 extern char *tparm(char *instring
, ...);
121 #if defined(sgi) || defined(__sun__)
122 #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
123 typedef chtype attr_t
; /* No attr_t type is available */
127 #define STRICT_SYSV_CURSES
130 /* Definition of exception curses.error */
132 static PyObject
*PyCursesError
;
134 /* Tells whether setupterm() has been called to initialise terminfo. */
135 static int initialised_setupterm
= FALSE
;
137 /* Tells whether initscr() has been called to initialise curses. */
138 static int initialised
= FALSE
;
140 /* Tells whether start_color() has been called to initialise color usage. */
141 static int initialisedcolors
= FALSE
;
144 #define PyCursesSetupTermCalled \
145 if (initialised_setupterm != TRUE) { \
146 PyErr_SetString(PyCursesError, \
147 "must call (at least) setupterm() first"); \
150 #define PyCursesInitialised \
151 if (initialised != TRUE) { \
152 PyErr_SetString(PyCursesError, \
153 "must call initscr() first"); \
156 #define PyCursesInitialisedColor \
157 if (initialisedcolors != TRUE) { \
158 PyErr_SetString(PyCursesError, \
159 "must call start_color() first"); \
162 /* Utility Functions */
165 * Check the return code from a curses function and return None
166 * or raise an exception as appropriate. These are exported using the
171 PyCursesCheckERR(int code
, char *fname
)
178 PyErr_SetString(PyCursesError
, catchall_ERR
);
180 PyErr_Format(PyCursesError
, "%s() returned ERR", fname
);
187 PyCurses_ConvertToChtype(PyObject
*obj
, chtype
*ch
)
189 if (PyInt_Check(obj
)) {
190 *ch
= (chtype
) PyInt_AsLong(obj
);
191 } else if(PyString_Check(obj
) &
192 (PyString_Size(obj
) == 1)) {
193 *ch
= (chtype
) *PyString_AsString(obj
);
200 /* Function versions of the 3 functions for tested whether curses has been
201 initialised or not. */
203 static int func_PyCursesSetupTermCalled(void)
205 PyCursesSetupTermCalled
;
209 static int func_PyCursesInitialised(void)
215 static int func_PyCursesInitialisedColor(void)
217 PyCursesInitialisedColor
;
221 /*****************************************************************************
223 ******************************************************************************/
225 /* Definition of the window type */
227 PyTypeObject PyCursesWindow_Type
;
229 /* Function prototype macros for Window object
232 TYPE - parameter Type
233 ERGSTR - format string for construction of the return value
234 PARSESTR - format string for argument parsing
237 #define Window_NoArgNoReturnFunction(X) \
238 static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
239 { if (!PyArg_NoArgs(args)) return NULL; \
240 return PyCursesCheckERR(X(self->win), # X); }
242 #define Window_NoArgTrueFalseFunction(X) \
243 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
245 if (!PyArg_NoArgs(args)) return NULL; \
246 if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
247 else { Py_INCREF(Py_True); return Py_True; } }
249 #define Window_NoArgNoReturnVoidFunction(X) \
250 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
252 if (!PyArg_NoArgs(args)) return NULL; \
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, PyObject *args) \
259 if (!PyArg_NoArgs(args)) return NULL; \
260 X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
262 #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
263 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
266 if (!PyArg_Parse(args, PARSESTR, &arg1)) return NULL; \
267 X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
269 #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
270 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
273 if (!PyArg_Parse(args,PARSESTR, &arg1)) return NULL; \
274 return PyCursesCheckERR(X(self->win, arg1), # X); }
276 #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
277 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
280 if (!PyArg_Parse(args,PARSESTR, &arg1, &arg2)) return NULL; \
281 return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
283 /* ------------- WINDOW routines --------------- */
285 Window_NoArgNoReturnFunction(untouchwin
)
286 Window_NoArgNoReturnFunction(touchwin
)
287 Window_NoArgNoReturnFunction(redrawwin
)
288 Window_NoArgNoReturnFunction(winsertln
)
289 Window_NoArgNoReturnFunction(werase
)
290 Window_NoArgNoReturnFunction(wdeleteln
)
292 Window_NoArgTrueFalseFunction(is_wintouched
)
294 Window_NoArgNoReturnVoidFunction(wsyncup
)
295 Window_NoArgNoReturnVoidFunction(wsyncdown
)
296 Window_NoArgNoReturnVoidFunction(wstandend
)
297 Window_NoArgNoReturnVoidFunction(wstandout
)
298 Window_NoArgNoReturnVoidFunction(wcursyncup
)
299 Window_NoArgNoReturnVoidFunction(wclrtoeol
)
300 Window_NoArgNoReturnVoidFunction(wclrtobot
)
301 Window_NoArgNoReturnVoidFunction(wclear
)
303 Window_OneArgNoReturnVoidFunction(idcok
, int, "i;True(1) or False(0)")
304 Window_OneArgNoReturnVoidFunction(immedok
, int, "i;True(1) or False(0)")
305 Window_OneArgNoReturnVoidFunction(wtimeout
, int, "i;delay")
307 Window_NoArg2TupleReturnFunction(getyx
, int, "(ii)")
308 Window_NoArg2TupleReturnFunction(getbegyx
, int, "(ii)")
309 Window_NoArg2TupleReturnFunction(getmaxyx
, int, "(ii)")
310 Window_NoArg2TupleReturnFunction(getparyx
, int, "(ii)")
312 Window_OneArgNoReturnFunction(wattron
, attr_t
, "l;attr")
313 Window_OneArgNoReturnFunction(wattroff
, attr_t
, "l;attr")
314 Window_OneArgNoReturnFunction(wattrset
, attr_t
, "l;attr")
315 Window_OneArgNoReturnFunction(clearok
, int, "i;True(1) or False(0)")
316 Window_OneArgNoReturnFunction(idlok
, int, "i;True(1) or False(0)")
317 #if defined(__NetBSD__)
318 Window_OneArgNoReturnVoidFunction(keypad
, int, "i;True(1) or False(0)")
320 Window_OneArgNoReturnFunction(keypad
, int, "i;True(1) or False(0)")
322 Window_OneArgNoReturnFunction(leaveok
, int, "i;True(1) or False(0)")
323 #if defined(__NetBSD__)
324 Window_OneArgNoReturnVoidFunction(nodelay
, int, "i;True(1) or False(0)")
326 Window_OneArgNoReturnFunction(nodelay
, int, "i;True(1) or False(0)")
328 Window_OneArgNoReturnFunction(notimeout
, int, "i;True(1) or False(0)")
329 Window_OneArgNoReturnFunction(scrollok
, int, "i;True(1) or False(0)")
330 Window_OneArgNoReturnFunction(winsdelln
, int, "i;nlines")
331 Window_OneArgNoReturnFunction(syncok
, int, "i;True(1) or False(0)")
333 Window_TwoArgNoReturnFunction(mvwin
, int, "(ii);y,x")
334 Window_TwoArgNoReturnFunction(mvderwin
, int, "(ii);y,x")
335 Window_TwoArgNoReturnFunction(wmove
, int, "(ii);y,x")
336 #ifndef STRICT_SYSV_CURSES
337 Window_TwoArgNoReturnFunction(wresize
, int, "(ii);lines,columns")
340 /* Allocation and deallocation of Window Objects */
343 PyCursesWindow_New(WINDOW
*win
)
345 PyCursesWindowObject
*wo
;
347 wo
= PyObject_NEW(PyCursesWindowObject
, &PyCursesWindow_Type
);
348 if (wo
== NULL
) return NULL
;
350 return (PyObject
*)wo
;
354 PyCursesWindow_Dealloc(PyCursesWindowObject
*wo
)
356 if (wo
->win
!= stdscr
) delwin(wo
->win
);
360 /* Addch, Addstr, Addnstr */
363 PyCursesWindow_AddCh(PyCursesWindowObject
*self
, PyObject
*args
)
365 int rtn
, x
, y
, use_xy
= FALSE
;
368 attr_t attr
= A_NORMAL
;
370 switch (ARG_COUNT(args
)) {
372 if (!PyArg_Parse(args
, "O;ch or int", &temp
))
376 if (!PyArg_Parse(args
, "(Ol);ch or int,attr", &temp
, &attr
))
380 if (!PyArg_Parse(args
,"(iiO);y,x,ch or int", &y
, &x
, &temp
))
385 if (!PyArg_Parse(args
,"(iiOl);y,x,ch or int, attr",
386 &y
, &x
, &temp
, &attr
))
391 PyErr_SetString(PyExc_TypeError
, "addch requires 1 or 4 arguments");
395 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
396 PyErr_SetString(PyExc_TypeError
, "argument 1 or 3 must be a ch or an int");
401 rtn
= mvwaddch(self
->win
,y
,x
, ch
| attr
);
403 rtn
= waddch(self
->win
, ch
| attr
);
405 return PyCursesCheckERR(rtn
, "addch");
409 PyCursesWindow_AddStr(PyCursesWindowObject
*self
, PyObject
*args
)
414 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
415 int use_xy
= FALSE
, use_attr
= FALSE
;
417 switch (ARG_COUNT(args
)) {
419 if (!PyArg_Parse(args
,"s;str", &str
))
423 if (!PyArg_Parse(args
,"(sl);str,attr", &str
, &attr
))
428 if (!PyArg_Parse(args
,"(iis);int,int,str", &y
, &x
, &str
))
433 if (!PyArg_Parse(args
,"(iisl);int,int,str,attr", &y
, &x
, &str
, &attr
))
435 use_xy
= use_attr
= TRUE
;
438 PyErr_SetString(PyExc_TypeError
, "addstr requires 1 to 4 arguments");
442 if (use_attr
== TRUE
) {
443 attr_old
= getattrs(self
->win
);
444 wattrset(self
->win
,attr
);
447 rtn
= mvwaddstr(self
->win
,y
,x
,str
);
449 rtn
= waddstr(self
->win
,str
);
450 if (use_attr
== TRUE
)
451 wattrset(self
->win
,attr_old
);
452 return PyCursesCheckERR(rtn
, "addstr");
456 PyCursesWindow_AddNStr(PyCursesWindowObject
*self
, PyObject
*args
)
460 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
461 int use_xy
= FALSE
, use_attr
= FALSE
;
463 switch (ARG_COUNT(args
)) {
465 if (!PyArg_Parse(args
,"(si);str,n", &str
, &n
))
469 if (!PyArg_Parse(args
,"(sil);str,n,attr", &str
, &n
, &attr
))
474 if (!PyArg_Parse(args
,"(iisi);y,x,str,n", &y
, &x
, &str
, &n
))
479 if (!PyArg_Parse(args
,"(iisil);y,x,str,n,attr", &y
, &x
, &str
, &n
, &attr
))
481 use_xy
= use_attr
= TRUE
;
484 PyErr_SetString(PyExc_TypeError
, "addnstr requires 2 to 5 arguments");
488 if (use_attr
== TRUE
) {
489 attr_old
= getattrs(self
->win
);
490 wattrset(self
->win
,attr
);
493 rtn
= mvwaddnstr(self
->win
,y
,x
,str
,n
);
495 rtn
= waddnstr(self
->win
,str
,n
);
496 if (use_attr
== TRUE
)
497 wattrset(self
->win
,attr_old
);
498 return PyCursesCheckERR(rtn
, "addnstr");
502 PyCursesWindow_Bkgd(PyCursesWindowObject
*self
, PyObject
*args
)
506 attr_t attr
= A_NORMAL
;
508 switch (ARG_COUNT(args
)) {
510 if (!PyArg_Parse(args
, "O;ch or int", &temp
))
514 if (!PyArg_Parse(args
,"(Ol);ch or int,attr", &temp
, &attr
))
518 PyErr_SetString(PyExc_TypeError
, "bkgd requires 1 or 2 arguments");
522 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
523 PyErr_SetString(PyExc_TypeError
, "argument 1 or 3 must be a ch or an int");
527 return PyCursesCheckERR(wbkgd(self
->win
, bkgd
| A_NORMAL
), "bkgd");
531 PyCursesWindow_BkgdSet(PyCursesWindowObject
*self
, PyObject
*args
)
535 attr_t attr
= A_NORMAL
;
537 switch (ARG_COUNT(args
)) {
539 if (!PyArg_Parse(args
, "O;ch or int", &temp
))
543 if (!PyArg_Parse(args
,"(Ol);ch or int,attr", &temp
, &attr
))
547 PyErr_SetString(PyExc_TypeError
, "bkgdset requires 1 or 2 arguments");
551 if (!PyCurses_ConvertToChtype(temp
, &bkgd
)) {
552 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
556 wbkgdset(self
->win
, bkgd
| attr
);
557 return PyCursesCheckERR(0, "bkgdset");
561 PyCursesWindow_Border(PyCursesWindowObject
*self
, PyObject
*args
)
563 chtype ls
, rs
, ts
, bs
, tl
, tr
, bl
, br
;
564 ls
= rs
= ts
= bs
= tl
= tr
= bl
= br
= 0;
565 if (!PyArg_Parse(args
,"|llllllll;ls,rs,ts,bs,tl,tr,bl,br",
566 &ls
, &rs
, &ts
, &bs
, &tl
, &tr
, &bl
, &br
))
568 wborder(self
->win
, ls
, rs
, ts
, bs
, tl
, tr
, bl
, br
);
574 PyCursesWindow_Box(PyCursesWindowObject
*self
, PyObject
*args
)
577 if (!PyArg_NoArgs(args
)) {
579 if (!PyArg_Parse(args
,"(ll);vertint,horint", &ch1
, &ch2
))
582 box(self
->win
,ch1
,ch2
);
588 PyCursesWindow_DelCh(PyCursesWindowObject
*self
, PyObject
*args
)
593 switch (ARG_COUNT(args
)) {
595 rtn
= wdelch(self
->win
);
598 if (!PyArg_Parse(args
,"(ii);y,x", &y
, &x
))
600 rtn
= mvwdelch(self
->win
,y
,x
);
603 PyErr_SetString(PyExc_TypeError
, "delch requires 0 or 2 arguments");
606 return PyCursesCheckERR(rtn
, "[mv]wdelch");
610 PyCursesWindow_DerWin(PyCursesWindowObject
*self
, PyObject
*args
)
613 int nlines
, ncols
, begin_y
, begin_x
;
617 switch (ARG_COUNT(args
)) {
619 if (!PyArg_Parse(args
,"(ii);begin_y,begin_x",&begin_y
,&begin_x
))
623 if (!PyArg_Parse(args
, "(iiii);nlines,ncols,begin_y,begin_x",
624 &nlines
,&ncols
,&begin_y
,&begin_x
))
628 PyErr_SetString(PyExc_TypeError
, "derwin requires 2 or 4 arguments");
632 win
= derwin(self
->win
,nlines
,ncols
,begin_y
,begin_x
);
635 PyErr_SetString(PyCursesError
, catchall_NULL
);
639 return (PyObject
*)PyCursesWindow_New(win
);
643 PyCursesWindow_EchoChar(PyCursesWindowObject
*self
, PyObject
*args
)
647 attr_t attr
= A_NORMAL
;
649 switch (ARG_COUNT(args
)) {
651 if (!PyArg_Parse(args
,"O;ch or int", &temp
))
655 if (!PyArg_Parse(args
,"(Ol);ch or int,attr", &temp
, &attr
))
659 PyErr_SetString(PyExc_TypeError
, "echochar requires 1 or 2 arguments");
665 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
666 PyErr_SetString(PyExc_TypeError
, "argument 1 must be a ch or an int");
670 #if !defined(__NetBSD__)
671 if (self
->win
->_flags
& _ISPAD
)
672 return PyCursesCheckERR(pechochar(self
->win
, ch
| attr
),
676 return PyCursesCheckERR(wechochar(self
->win
, ch
| attr
),
680 #ifdef NCURSES_MOUSE_VERSION
682 PyCursesWindow_Enclose(PyCursesWindowObject
*self
, PyObject
*args
)
685 if (!PyArg_Parse(args
,"(ii);y,x", &y
, &x
))
688 return PyInt_FromLong( wenclose(self
->win
,y
,x
) );
693 PyCursesWindow_GetBkgd(PyCursesWindowObject
*self
, PyObject
*args
)
695 if (!PyArg_NoArgs(args
))
697 return PyInt_FromLong((long) getbkgd(self
->win
));
701 PyCursesWindow_GetCh(PyCursesWindowObject
*self
, PyObject
*args
)
706 switch (ARG_COUNT(args
)) {
708 Py_BEGIN_ALLOW_THREADS
709 rtn
= wgetch(self
->win
);
713 if (!PyArg_Parse(args
,"(ii);y,x",&y
,&x
))
715 Py_BEGIN_ALLOW_THREADS
716 rtn
= mvwgetch(self
->win
,y
,x
);
720 PyErr_SetString(PyExc_TypeError
, "getch requires 0 or 2 arguments");
723 return PyInt_FromLong(rtn
);
727 PyCursesWindow_GetKey(PyCursesWindowObject
*self
, PyObject
*args
)
732 switch (ARG_COUNT(args
)) {
734 Py_BEGIN_ALLOW_THREADS
735 rtn
= wgetch(self
->win
);
739 if (!PyArg_Parse(args
,"(ii);y,x",&y
,&x
))
741 Py_BEGIN_ALLOW_THREADS
742 rtn
= mvwgetch(self
->win
,y
,x
);
746 PyErr_SetString(PyExc_TypeError
, "getkey requires 0 or 2 arguments");
750 return Py_BuildValue("c", rtn
);
752 #if defined(__NetBSD__)
753 return PyString_FromString(unctrl(rtn
));
755 return PyString_FromString((char *)keyname(rtn
));
760 PyCursesWindow_GetStr(PyCursesWindowObject
*self
, PyObject
*args
)
763 char rtn
[1024]; /* This should be big enough.. I hope */
766 switch (ARG_COUNT(args
)) {
768 Py_BEGIN_ALLOW_THREADS
769 rtn2
= wgetstr(self
->win
,rtn
);
773 if (!PyArg_Parse(args
,"i;n", &n
))
775 Py_BEGIN_ALLOW_THREADS
776 rtn2
= wgetnstr(self
->win
,rtn
,n
);
780 if (!PyArg_Parse(args
,"(ii);y,x",&y
,&x
))
782 Py_BEGIN_ALLOW_THREADS
783 rtn2
= mvwgetstr(self
->win
,y
,x
,rtn
);
787 if (!PyArg_Parse(args
,"(iii);y,x,n", &y
, &x
, &n
))
789 #ifdef STRICT_SYSV_CURSES
791 Py_BEGIN_ALLOW_THREADS
792 rtn2
= wmove(self
->win
,y
,x
)==ERR
? ERR
:
793 wgetnstr(self
->win
, rtn
, n
);
796 Py_BEGIN_ALLOW_THREADS
797 rtn2
= mvwgetnstr(self
->win
, y
, x
, rtn
, n
);
802 PyErr_SetString(PyExc_TypeError
, "getstr requires 0 to 2 arguments");
807 return PyString_FromString(rtn
);
811 PyCursesWindow_Hline(PyCursesWindowObject
*self
, PyObject
*args
)
815 int n
, x
, y
, code
= OK
;
816 attr_t attr
= A_NORMAL
;
818 switch (ARG_COUNT(args
)) {
820 if (!PyArg_Parse(args
, "(Oi);ch or int,n", &temp
, &n
))
824 if (!PyArg_Parse(args
, "(Oil);ch or int,n,attr", &temp
, &n
, &attr
))
828 if (!PyArg_Parse(args
, "(iiOi);y,x,ch or int,n", &y
, &x
, &temp
, &n
))
830 code
= wmove(self
->win
, y
, x
);
833 if (!PyArg_Parse(args
, "(iiOil); y,x,ch or int,n,attr",
834 &y
, &x
, &temp
, &n
, &attr
))
836 code
= wmove(self
->win
, y
, x
);
838 PyErr_SetString(PyExc_TypeError
, "hline requires 2 or 5 arguments");
843 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
844 PyErr_SetString(PyExc_TypeError
,
845 "argument 1 or 3 must be a ch or an int");
848 return PyCursesCheckERR(whline(self
->win
, ch
| attr
, n
), "hline");
850 return PyCursesCheckERR(code
, "wmove");
854 PyCursesWindow_InsCh(PyCursesWindowObject
*self
, PyObject
*args
)
856 int rtn
, x
, y
, use_xy
= FALSE
;
859 attr_t attr
= A_NORMAL
;
861 switch (ARG_COUNT(args
)) {
863 if (!PyArg_Parse(args
, "O;ch or int", &temp
))
867 if (!PyArg_Parse(args
, "(Ol);ch or int,attr", &temp
, &attr
))
871 if (!PyArg_Parse(args
,"(iiO);y,x,ch or int", &y
, &x
, &temp
))
876 if (!PyArg_Parse(args
,"(iiOl);y,x,ch or int, attr", &y
, &x
, &temp
, &attr
))
881 PyErr_SetString(PyExc_TypeError
, "insch requires 1 or 4 arguments");
885 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
886 PyErr_SetString(PyExc_TypeError
,
887 "argument 1 or 3 must be a ch or an int");
892 rtn
= mvwinsch(self
->win
,y
,x
, ch
| attr
);
894 rtn
= winsch(self
->win
, ch
| attr
);
896 return PyCursesCheckERR(rtn
, "insch");
900 PyCursesWindow_InCh(PyCursesWindowObject
*self
, PyObject
*args
)
904 switch (ARG_COUNT(args
)) {
906 rtn
= winch(self
->win
);
909 if (!PyArg_Parse(args
,"(ii);y,x",&y
,&x
))
911 rtn
= mvwinch(self
->win
,y
,x
);
914 PyErr_SetString(PyExc_TypeError
, "inch requires 0 or 2 arguments");
917 return PyInt_FromLong((long) rtn
);
921 PyCursesWindow_InStr(PyCursesWindowObject
*self
, PyObject
*args
)
924 char rtn
[1024]; /* This should be big enough.. I hope */
927 switch (ARG_COUNT(args
)) {
929 rtn2
= winstr(self
->win
,rtn
);
932 if (!PyArg_Parse(args
,"i;n", &n
))
934 rtn2
= winnstr(self
->win
,rtn
,n
);
937 if (!PyArg_Parse(args
,"(ii);y,x",&y
,&x
))
939 rtn2
= mvwinstr(self
->win
,y
,x
,rtn
);
942 if (!PyArg_Parse(args
, "(iii);y,x,n", &y
, &x
, &n
))
944 rtn2
= mvwinnstr(self
->win
, y
, x
, rtn
, n
);
947 PyErr_SetString(PyExc_TypeError
, "instr requires 0 or 3 arguments");
952 return PyString_FromString(rtn
);
956 PyCursesWindow_InsStr(PyCursesWindowObject
*self
, PyObject
*args
)
961 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
962 int use_xy
= FALSE
, use_attr
= FALSE
;
964 switch (ARG_COUNT(args
)) {
966 if (!PyArg_Parse(args
,"s;str", &str
))
970 if (!PyArg_Parse(args
,"(sl);str,attr", &str
, &attr
))
975 if (!PyArg_Parse(args
,"(iis);y,x,str", &y
, &x
, &str
))
980 if (!PyArg_Parse(args
,"(iisl);y,x,str,attr", &y
, &x
, &str
, &attr
))
982 use_xy
= use_attr
= TRUE
;
985 PyErr_SetString(PyExc_TypeError
, "insstr requires 1 to 4 arguments");
989 if (use_attr
== TRUE
) {
990 attr_old
= getattrs(self
->win
);
991 wattrset(self
->win
,attr
);
994 rtn
= mvwinsstr(self
->win
,y
,x
,str
);
996 rtn
= winsstr(self
->win
,str
);
997 if (use_attr
== TRUE
)
998 wattrset(self
->win
,attr_old
);
999 return PyCursesCheckERR(rtn
, "insstr");
1003 PyCursesWindow_InsNStr(PyCursesWindowObject
*self
, PyObject
*args
)
1007 attr_t attr
= A_NORMAL
, attr_old
= A_NORMAL
;
1008 int use_xy
= FALSE
, use_attr
= FALSE
;
1010 switch (ARG_COUNT(args
)) {
1012 if (!PyArg_Parse(args
,"(si);str,n", &str
, &n
))
1016 if (!PyArg_Parse(args
,"(sil);str,n,attr", &str
, &n
, &attr
))
1021 if (!PyArg_Parse(args
,"(iisi);y,x,str,n", &y
, &x
, &str
, &n
))
1026 if (!PyArg_Parse(args
,"(iisil);y,x,str,n,attr", &y
, &x
, &str
, &n
, &attr
))
1028 use_xy
= use_attr
= TRUE
;
1031 PyErr_SetString(PyExc_TypeError
, "insnstr requires 2 to 5 arguments");
1035 if (use_attr
== TRUE
) {
1036 attr_old
= getattrs(self
->win
);
1037 wattrset(self
->win
,attr
);
1040 rtn
= mvwinsnstr(self
->win
,y
,x
,str
,n
);
1042 rtn
= winsnstr(self
->win
,str
,n
);
1043 if (use_attr
== TRUE
)
1044 wattrset(self
->win
,attr_old
);
1045 return PyCursesCheckERR(rtn
, "insnstr");
1049 PyCursesWindow_Is_LineTouched(PyCursesWindowObject
*self
, PyObject
*args
)
1052 if (!PyArg_Parse(args
,"i;line", &line
))
1054 erg
= is_linetouched(self
->win
, line
);
1056 PyErr_SetString(PyExc_TypeError
,
1057 "is_linetouched: line number outside of boundaries");
1061 Py_INCREF(Py_False
);
1070 PyCursesWindow_NoOutRefresh(PyCursesWindowObject
*self
, PyObject
*args
)
1072 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1075 #if defined(__NetBSD__)
1078 if (self
->win
->_flags
& _ISPAD
) {
1080 switch(ARG_COUNT(args
)) {
1082 if (!PyArg_Parse(args
,
1084 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1085 &pminrow
, &pmincol
, &sminrow
,
1086 &smincol
, &smaxrow
, &smaxcol
))
1088 Py_BEGIN_ALLOW_THREADS
1089 rtn
= pnoutrefresh(self
->win
,
1090 pminrow
, pmincol
, sminrow
,
1091 smincol
, smaxrow
, smaxcol
);
1092 Py_END_ALLOW_THREADS
1093 return PyCursesCheckERR(rtn
, "pnoutrefresh");
1095 PyErr_SetString(PyCursesError
,
1096 "noutrefresh() called for a pad "
1097 "requires 6 arguments");
1101 if (!PyArg_NoArgs(args
))
1104 Py_BEGIN_ALLOW_THREADS
1105 rtn
= wnoutrefresh(self
->win
);
1106 Py_END_ALLOW_THREADS
1107 return PyCursesCheckERR(rtn
, "wnoutrefresh");
1112 PyCursesWindow_Overlay(PyCursesWindowObject
*self
, PyObject
*args
)
1114 PyCursesWindowObject
*temp
;
1115 int use_copywin
= FALSE
;
1116 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1119 switch (ARG_COUNT(args
)) {
1121 if (!PyArg_ParseTuple(args
, "O!;window object",
1122 &PyCursesWindow_Type
, &temp
))
1126 if (!PyArg_ParseTuple(args
, "(O!iiiiii);window object, int, int, int, int, int, int",
1127 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1128 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1133 PyErr_SetString(PyExc_TypeError
,
1134 "overlay requires one or seven arguments");
1138 if (use_copywin
== TRUE
) {
1139 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1140 dminrow
, dmincol
, dmaxrow
, dmaxcol
, TRUE
);
1141 return PyCursesCheckERR(rtn
, "copywin");
1144 rtn
= overlay(self
->win
, temp
->win
);
1145 return PyCursesCheckERR(rtn
, "overlay");
1150 PyCursesWindow_Overwrite(PyCursesWindowObject
*self
, PyObject
*args
)
1152 PyCursesWindowObject
*temp
;
1153 int use_copywin
= FALSE
;
1154 int sminrow
, smincol
, dminrow
, dmincol
, dmaxrow
, dmaxcol
;
1157 switch (ARG_COUNT(args
)) {
1159 if (!PyArg_ParseTuple(args
, "O!;window object",
1160 &PyCursesWindow_Type
, &temp
))
1164 if (!PyArg_ParseTuple(args
, "(O!iiiiii);window object, int, int, int, int, int, int",
1165 &PyCursesWindow_Type
, &temp
, &sminrow
, &smincol
,
1166 &dminrow
, &dmincol
, &dmaxrow
, &dmaxcol
))
1171 PyErr_SetString(PyExc_TypeError
,
1172 "overwrite requires one or seven arguments");
1176 if (use_copywin
== TRUE
) {
1177 rtn
= copywin(self
->win
, temp
->win
, sminrow
, smincol
,
1178 dminrow
, dmincol
, dmaxrow
, dmaxcol
, FALSE
);
1179 return PyCursesCheckERR(rtn
, "copywin");
1182 rtn
= overwrite(self
->win
, temp
->win
);
1183 return PyCursesCheckERR(rtn
, "overwrite");
1188 PyCursesWindow_PutWin(PyCursesWindowObject
*self
, PyObject
*args
)
1192 if (!PyArg_Parse(args
, "O;fileobj", &temp
))
1194 if (!PyFile_Check(temp
)) {
1195 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1198 return PyCursesCheckERR(putwin(self
->win
, PyFile_AsFile(temp
)),
1203 PyCursesWindow_RedrawLine(PyCursesWindowObject
*self
, PyObject
*args
)
1206 if (!PyArg_Parse(args
,"(ii);beg,num", &beg
, &num
))
1208 return PyCursesCheckERR(wredrawln(self
->win
,beg
,num
), "redrawln");
1212 PyCursesWindow_Refresh(PyCursesWindowObject
*self
, PyObject
*args
)
1214 int pminrow
,pmincol
,sminrow
,smincol
,smaxrow
,smaxcol
;
1217 #if defined(__NetBSD__)
1220 if (self
->win
->_flags
& _ISPAD
) {
1222 switch(ARG_COUNT(args
)) {
1224 if (!PyArg_Parse(args
,
1226 "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1227 &pminrow
, &pmincol
, &sminrow
,
1228 &smincol
, &smaxrow
, &smaxcol
))
1231 Py_BEGIN_ALLOW_THREADS
1232 rtn
= prefresh(self
->win
,
1233 pminrow
, pmincol
, sminrow
,
1234 smincol
, smaxrow
, smaxcol
);
1235 Py_END_ALLOW_THREADS
1236 return PyCursesCheckERR(rtn
, "prefresh");
1238 PyErr_SetString(PyCursesError
,
1239 "refresh() for a pad requires 6 arguments");
1243 if (!PyArg_NoArgs(args
))
1245 Py_BEGIN_ALLOW_THREADS
1246 rtn
= wrefresh(self
->win
);
1247 Py_END_ALLOW_THREADS
1248 return PyCursesCheckERR(rtn
, "prefresh");
1253 PyCursesWindow_SetScrollRegion(PyCursesWindowObject
*self
, PyObject
*args
)
1256 if (!PyArg_Parse(args
,"(ii);top, bottom",&y
,&x
))
1258 return PyCursesCheckERR(wsetscrreg(self
->win
,y
,x
), "wsetscrreg");
1262 PyCursesWindow_SubWin(PyCursesWindowObject
*self
, PyObject
*args
)
1265 int nlines
, ncols
, begin_y
, begin_x
;
1269 switch (ARG_COUNT(args
)) {
1271 if (!PyArg_Parse(args
,"(ii);begin_y,begin_x",&begin_y
,&begin_x
))
1275 if (!PyArg_Parse(args
, "(iiii);nlines,ncols,begin_y,begin_x",
1276 &nlines
,&ncols
,&begin_y
,&begin_x
))
1280 PyErr_SetString(PyExc_TypeError
, "subwin requires 2 or 4 arguments");
1284 /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
1285 #if !defined(__NetBSD__)
1286 if (self
->win
->_flags
& _ISPAD
)
1287 win
= subpad(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1290 win
= subwin(self
->win
, nlines
, ncols
, begin_y
, begin_x
);
1293 PyErr_SetString(PyCursesError
, catchall_NULL
);
1297 return (PyObject
*)PyCursesWindow_New(win
);
1301 PyCursesWindow_Scroll(PyCursesWindowObject
*self
, PyObject
*args
)
1304 switch(ARG_COUNT(args
)) {
1306 return PyCursesCheckERR(scroll(self
->win
), "scroll");
1309 if (!PyArg_Parse(args
, "i;nlines", &nlines
))
1311 return PyCursesCheckERR(wscrl(self
->win
, nlines
), "scroll");
1313 PyErr_SetString(PyExc_TypeError
, "scroll requires 0 or 1 arguments");
1319 PyCursesWindow_TouchLine(PyCursesWindowObject
*self
, PyObject
*args
)
1322 switch (ARG_COUNT(args
)) {
1324 if (!PyArg_Parse(args
,"(ii);start,count",&st
,&cnt
))
1326 return PyCursesCheckERR(touchline(self
->win
,st
,cnt
), "touchline");
1329 if (!PyArg_Parse(args
, "(iii);start,count,val", &st
, &cnt
, &val
))
1331 return PyCursesCheckERR(wtouchln(self
->win
, st
, cnt
, val
), "touchline");
1333 PyErr_SetString(PyExc_TypeError
, "touchline requires 2 or 3 arguments");
1339 PyCursesWindow_Vline(PyCursesWindowObject
*self
, PyObject
*args
)
1343 int n
, x
, y
, code
= OK
;
1344 attr_t attr
= A_NORMAL
;
1346 switch (ARG_COUNT(args
)) {
1348 if (!PyArg_Parse(args
, "(Oi);ch or int,n", &temp
, &n
))
1352 if (!PyArg_Parse(args
, "(Oil);ch or int,n,attr", &temp
, &n
, &attr
))
1356 if (!PyArg_Parse(args
, "(iiOi);y,x,ch or int,n", &y
, &x
, &temp
, &n
))
1358 code
= wmove(self
->win
, y
, x
);
1361 if (!PyArg_Parse(args
, "(iiOil); y,x,ch or int,n,attr",
1362 &y
, &x
, &temp
, &n
, &attr
))
1364 code
= wmove(self
->win
, y
, x
);
1366 PyErr_SetString(PyExc_TypeError
, "vline requires 2 or 5 arguments");
1371 if (!PyCurses_ConvertToChtype(temp
, &ch
)) {
1372 PyErr_SetString(PyExc_TypeError
,
1373 "argument 1 or 3 must be a ch or an int");
1376 return PyCursesCheckERR(wvline(self
->win
, ch
| attr
, n
), "vline");
1378 return PyCursesCheckERR(code
, "wmove");
1381 static PyMethodDef PyCursesWindow_Methods
[] = {
1382 {"addch", (PyCFunction
)PyCursesWindow_AddCh
},
1383 {"addnstr", (PyCFunction
)PyCursesWindow_AddNStr
},
1384 {"addstr", (PyCFunction
)PyCursesWindow_AddStr
},
1385 {"attroff", (PyCFunction
)PyCursesWindow_wattroff
},
1386 {"attron", (PyCFunction
)PyCursesWindow_wattron
},
1387 {"attrset", (PyCFunction
)PyCursesWindow_wattrset
},
1388 {"bkgd", (PyCFunction
)PyCursesWindow_Bkgd
},
1389 {"bkgdset", (PyCFunction
)PyCursesWindow_BkgdSet
},
1390 {"border", (PyCFunction
)PyCursesWindow_Border
, METH_VARARGS
},
1391 {"box", (PyCFunction
)PyCursesWindow_Box
},
1392 {"clear", (PyCFunction
)PyCursesWindow_wclear
},
1393 {"clearok", (PyCFunction
)PyCursesWindow_clearok
},
1394 {"clrtobot", (PyCFunction
)PyCursesWindow_wclrtobot
},
1395 {"clrtoeol", (PyCFunction
)PyCursesWindow_wclrtoeol
},
1396 {"cursyncup", (PyCFunction
)PyCursesWindow_wcursyncup
},
1397 {"delch", (PyCFunction
)PyCursesWindow_DelCh
},
1398 {"deleteln", (PyCFunction
)PyCursesWindow_wdeleteln
},
1399 {"derwin", (PyCFunction
)PyCursesWindow_DerWin
},
1400 {"echochar", (PyCFunction
)PyCursesWindow_EchoChar
},
1401 #ifdef NCURSES_MOUSE_VERSION
1402 {"enclose", (PyCFunction
)PyCursesWindow_Enclose
},
1404 {"erase", (PyCFunction
)PyCursesWindow_werase
},
1405 {"getbegyx", (PyCFunction
)PyCursesWindow_getbegyx
},
1406 {"getbkgd", (PyCFunction
)PyCursesWindow_GetBkgd
},
1407 {"getch", (PyCFunction
)PyCursesWindow_GetCh
},
1408 {"getkey", (PyCFunction
)PyCursesWindow_GetKey
},
1409 {"getmaxyx", (PyCFunction
)PyCursesWindow_getmaxyx
},
1410 {"getparyx", (PyCFunction
)PyCursesWindow_getparyx
},
1411 {"getstr", (PyCFunction
)PyCursesWindow_GetStr
},
1412 {"getyx", (PyCFunction
)PyCursesWindow_getyx
},
1413 {"hline", (PyCFunction
)PyCursesWindow_Hline
},
1414 {"idcok", (PyCFunction
)PyCursesWindow_idcok
},
1415 {"idlok", (PyCFunction
)PyCursesWindow_idlok
},
1416 {"immedok", (PyCFunction
)PyCursesWindow_immedok
},
1417 {"inch", (PyCFunction
)PyCursesWindow_InCh
},
1418 {"insch", (PyCFunction
)PyCursesWindow_InsCh
},
1419 {"insdelln", (PyCFunction
)PyCursesWindow_winsdelln
},
1420 {"insertln", (PyCFunction
)PyCursesWindow_winsertln
},
1421 {"insnstr", (PyCFunction
)PyCursesWindow_InsNStr
},
1422 {"insstr", (PyCFunction
)PyCursesWindow_InsStr
},
1423 {"instr", (PyCFunction
)PyCursesWindow_InStr
},
1424 {"is_linetouched", (PyCFunction
)PyCursesWindow_Is_LineTouched
},
1425 {"is_wintouched", (PyCFunction
)PyCursesWindow_is_wintouched
},
1426 {"keypad", (PyCFunction
)PyCursesWindow_keypad
},
1427 {"leaveok", (PyCFunction
)PyCursesWindow_leaveok
},
1428 {"move", (PyCFunction
)PyCursesWindow_wmove
},
1429 {"mvderwin", (PyCFunction
)PyCursesWindow_mvderwin
},
1430 {"mvwin", (PyCFunction
)PyCursesWindow_mvwin
},
1431 {"nodelay", (PyCFunction
)PyCursesWindow_nodelay
},
1432 {"notimeout", (PyCFunction
)PyCursesWindow_notimeout
},
1433 {"noutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
},
1434 /* Backward compatibility alias -- remove in Python 2.1 */
1435 {"nooutrefresh", (PyCFunction
)PyCursesWindow_NoOutRefresh
},
1436 {"overlay", (PyCFunction
)PyCursesWindow_Overlay
, METH_VARARGS
},
1437 {"overwrite", (PyCFunction
)PyCursesWindow_Overwrite
, METH_VARARGS
},
1438 {"putwin", (PyCFunction
)PyCursesWindow_PutWin
},
1439 {"redrawln", (PyCFunction
)PyCursesWindow_RedrawLine
},
1440 {"redrawwin", (PyCFunction
)PyCursesWindow_redrawwin
},
1441 {"refresh", (PyCFunction
)PyCursesWindow_Refresh
},
1442 #ifndef STRICT_SYSV_CURSES
1443 {"resize", (PyCFunction
)PyCursesWindow_wresize
},
1445 {"scroll", (PyCFunction
)PyCursesWindow_Scroll
},
1446 {"scrollok", (PyCFunction
)PyCursesWindow_scrollok
},
1447 {"setscrreg", (PyCFunction
)PyCursesWindow_SetScrollRegion
},
1448 {"standend", (PyCFunction
)PyCursesWindow_wstandend
},
1449 {"standout", (PyCFunction
)PyCursesWindow_wstandout
},
1450 {"subpad", (PyCFunction
)PyCursesWindow_SubWin
},
1451 {"subwin", (PyCFunction
)PyCursesWindow_SubWin
},
1452 {"syncdown", (PyCFunction
)PyCursesWindow_wsyncdown
},
1453 {"syncok", (PyCFunction
)PyCursesWindow_syncok
},
1454 {"syncup", (PyCFunction
)PyCursesWindow_wsyncup
},
1455 {"timeout", (PyCFunction
)PyCursesWindow_wtimeout
},
1456 {"touchline", (PyCFunction
)PyCursesWindow_TouchLine
},
1457 {"touchwin", (PyCFunction
)PyCursesWindow_touchwin
},
1458 {"untouchwin", (PyCFunction
)PyCursesWindow_untouchwin
},
1459 {"vline", (PyCFunction
)PyCursesWindow_Vline
},
1460 {NULL
, NULL
} /* sentinel */
1464 PyCursesWindow_GetAttr(PyCursesWindowObject
*self
, char *name
)
1466 return Py_FindMethod(PyCursesWindow_Methods
, (PyObject
*)self
, name
);
1469 /* -------------------------------------------------------*/
1471 PyTypeObject PyCursesWindow_Type
= {
1472 PyObject_HEAD_INIT(NULL
)
1474 "curses window", /*tp_name*/
1475 sizeof(PyCursesWindowObject
), /*tp_basicsize*/
1478 (destructor
)PyCursesWindow_Dealloc
, /*tp_dealloc*/
1480 (getattrfunc
)PyCursesWindow_GetAttr
, /*tp_getattr*/
1481 (setattrfunc
)0, /*tp_setattr*/
1485 0, /*tp_as_sequence*/
1486 0, /*tp_as_mapping*/
1490 /*********************************************************************
1492 **********************************************************************/
1494 NoArgNoReturnFunction(beep
)
1495 NoArgNoReturnFunction(def_prog_mode
)
1496 NoArgNoReturnFunction(def_shell_mode
)
1497 NoArgNoReturnFunction(doupdate
)
1498 NoArgNoReturnFunction(endwin
)
1499 NoArgNoReturnFunction(flash
)
1500 NoArgNoReturnFunction(nocbreak
)
1501 NoArgNoReturnFunction(noecho
)
1502 NoArgNoReturnFunction(nonl
)
1503 NoArgNoReturnFunction(noraw
)
1504 NoArgNoReturnFunction(reset_prog_mode
)
1505 NoArgNoReturnFunction(reset_shell_mode
)
1506 NoArgNoReturnFunction(resetty
)
1507 NoArgNoReturnFunction(savetty
)
1509 NoArgOrFlagNoReturnFunction(cbreak
)
1510 NoArgOrFlagNoReturnFunction(echo
)
1511 NoArgOrFlagNoReturnFunction(nl
)
1512 NoArgOrFlagNoReturnFunction(raw
)
1514 NoArgReturnIntFunction(baudrate
)
1515 NoArgReturnIntFunction(termattrs
)
1517 NoArgReturnStringFunction(termname
)
1518 NoArgReturnStringFunction(longname
)
1520 NoArgTrueFalseFunction(can_change_color
)
1521 NoArgTrueFalseFunction(has_colors
)
1522 NoArgTrueFalseFunction(has_ic
)
1523 NoArgTrueFalseFunction(has_il
)
1524 NoArgTrueFalseFunction(isendwin
)
1525 NoArgNoReturnVoidFunction(filter
)
1526 NoArgNoReturnVoidFunction(flushinp
)
1527 NoArgNoReturnVoidFunction(noqiflush
)
1530 PyCurses_Color_Content(PyObject
*self
, PyObject
*args
)
1535 PyCursesInitialisedColor
1537 if (ARG_COUNT(args
) != 1) {
1538 PyErr_SetString(PyExc_TypeError
,
1539 "color_content requires 1 argument");
1543 if (!PyArg_Parse(args
, "h;color", &color
)) return NULL
;
1545 if (color_content(color
, &r
, &g
, &b
) != ERR
)
1546 return Py_BuildValue("(iii)", r
, g
, b
);
1548 PyErr_SetString(PyCursesError
,
1549 "Argument 1 was out of range. Check value of COLORS.");
1555 PyCurses_color_pair(PyObject
*self
, PyObject
*args
)
1560 PyCursesInitialisedColor
1562 if (ARG_COUNT(args
) != 1) {
1563 PyErr_SetString(PyExc_TypeError
, "color_pair requires 1 argument");
1566 if (!PyArg_Parse(args
, "i;number", &n
)) return NULL
;
1567 return PyInt_FromLong((long) (n
<< 8));
1571 PyCurses_Curs_Set(PyObject
*self
, PyObject
*args
)
1577 if (ARG_COUNT(args
)!=1) {
1578 PyErr_SetString(PyExc_TypeError
, "curs_set requires 1 argument");
1582 if (!PyArg_Parse(args
, "i;int", &vis
)) return NULL
;
1584 erg
= curs_set(vis
);
1585 if (erg
== ERR
) return PyCursesCheckERR(erg
, "curs_set");
1587 return PyInt_FromLong((long) erg
);
1591 PyCurses_Delay_Output(PyObject
*self
, PyObject
*args
)
1597 if (ARG_COUNT(args
) != 1) {
1598 PyErr_SetString(PyExc_TypeError
, "delay_output requires 1 argument");
1601 if (!PyArg_Parse(args
, "i;ms", &ms
)) return NULL
;
1603 return PyCursesCheckERR(delay_output(ms
), "delay_output");
1607 PyCurses_EraseChar(PyObject
*self
, PyObject
*args
)
1613 if (!PyArg_NoArgs(args
)) return NULL
;
1617 return PyString_FromString(&ch
);
1621 PyCurses_getsyx(PyObject
*self
, PyObject
*args
)
1627 if (!PyArg_NoArgs(args
)) return NULL
;
1631 return Py_BuildValue("(ii)", y
, x
);
1634 #ifdef NCURSES_MOUSE_VERSION
1636 PyCurses_GetMouse(PyObject
*self
, PyObject
*args
)
1642 if (!PyArg_NoArgs(args
)) return NULL
;
1644 rtn
= getmouse( &event
);
1646 PyErr_SetString(PyCursesError
, "getmouse() returned ERR");
1649 return Py_BuildValue("(hiiil)",
1651 event
.x
, event
.y
, event
.z
,
1652 (long) event
.bstate
);
1656 PyCurses_UngetMouse(PyObject
*self
, PyObject
*args
)
1661 if (!PyArg_ParseTuple(args
, "(hiiil)",
1663 &event
.x
, &event
.y
, &event
.z
,
1664 (int *) &event
.bstate
))
1667 return PyCursesCheckERR(ungetmouse(&event
), "ungetmouse");
1672 PyCurses_GetWin(PyCursesWindowObject
*self
, PyObject
*args
)
1679 if (!PyArg_Parse(args
, "O;fileobj", &temp
)) return NULL
;
1681 if (!PyFile_Check(temp
)) {
1682 PyErr_SetString(PyExc_TypeError
, "argument must be a file object");
1686 win
= getwin(PyFile_AsFile(temp
));
1689 PyErr_SetString(PyCursesError
, catchall_NULL
);
1693 return PyCursesWindow_New(win
);
1697 PyCurses_HalfDelay(PyObject
*self
, PyObject
*args
)
1699 unsigned char tenths
;
1703 switch(ARG_COUNT(args
)) {
1705 if (!PyArg_Parse(args
, "b;tenths", &tenths
)) return NULL
;
1708 PyErr_SetString(PyExc_TypeError
, "halfdelay requires 1 argument");
1712 return PyCursesCheckERR(halfdelay(tenths
), "halfdelay");
1715 #ifndef STRICT_SYSV_CURSES
1717 static PyObject
* PyCurses_has_key(PyObject
*self
, PyObject
*args
)
1723 if (!PyArg_Parse(args
,"i",&ch
)) return NULL
;
1725 if (has_key(ch
) == FALSE
) {
1726 Py_INCREF(Py_False
);
1732 #endif /* STRICT_SYSV_CURSES */
1735 PyCurses_Init_Color(PyObject
*self
, PyObject
*args
)
1737 short color
, r
, g
, b
;
1740 PyCursesInitialisedColor
1742 switch(ARG_COUNT(args
)) {
1744 if (!PyArg_Parse(args
, "(hhhh);color,r,g,b", &color
, &r
, &g
, &b
)) return NULL
;
1747 PyErr_SetString(PyExc_TypeError
, "init_color requires 4 arguments");
1751 return PyCursesCheckERR(init_color(color
, r
, g
, b
), "init_color");
1755 PyCurses_Init_Pair(PyObject
*self
, PyObject
*args
)
1760 PyCursesInitialisedColor
1762 if (ARG_COUNT(args
) != 3) {
1763 PyErr_SetString(PyExc_TypeError
, "init_pair requires 3 arguments");
1767 if (!PyArg_Parse(args
, "(hhh);pair, f, b", &pair
, &f
, &b
)) return NULL
;
1769 return PyCursesCheckERR(init_pair(pair
, f
, b
), "init_pair");
1772 static PyObject
*ModDict
;
1775 PyCurses_InitScr(PyObject
*self
, PyObject
*args
)
1778 PyObject
*nlines
, *cols
;
1780 if (!PyArg_NoArgs(args
)) return NULL
;
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 SetDictInt("ACS_S1", (ACS_S1
));
1814 SetDictInt("ACS_S9", (ACS_S9
));
1815 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND
));
1816 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD
));
1817 SetDictInt("ACS_DEGREE", (ACS_DEGREE
));
1818 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS
));
1819 SetDictInt("ACS_BULLET", (ACS_BULLET
));
1820 SetDictInt("ACS_LARROW", (ACS_LARROW
));
1821 SetDictInt("ACS_RARROW", (ACS_RARROW
));
1822 SetDictInt("ACS_DARROW", (ACS_DARROW
));
1823 SetDictInt("ACS_UARROW", (ACS_UARROW
));
1824 SetDictInt("ACS_BOARD", (ACS_BOARD
));
1825 SetDictInt("ACS_LANTERN", (ACS_LANTERN
));
1826 SetDictInt("ACS_BLOCK", (ACS_BLOCK
));
1827 SetDictInt("ACS_BSSB", (ACS_ULCORNER
));
1828 SetDictInt("ACS_SSBB", (ACS_LLCORNER
));
1829 SetDictInt("ACS_BBSS", (ACS_URCORNER
));
1830 SetDictInt("ACS_SBBS", (ACS_LRCORNER
));
1831 SetDictInt("ACS_SBSS", (ACS_RTEE
));
1832 SetDictInt("ACS_SSSB", (ACS_LTEE
));
1833 SetDictInt("ACS_SSBS", (ACS_BTEE
));
1834 SetDictInt("ACS_BSSS", (ACS_TTEE
));
1835 SetDictInt("ACS_BSBS", (ACS_HLINE
));
1836 SetDictInt("ACS_SBSB", (ACS_VLINE
));
1837 SetDictInt("ACS_SSSS", (ACS_PLUS
));
1839 /* The following are never available with strict SYSV curses */
1841 SetDictInt("ACS_S3", (ACS_S3
));
1844 SetDictInt("ACS_S7", (ACS_S7
));
1847 SetDictInt("ACS_LEQUAL", (ACS_LEQUAL
));
1850 SetDictInt("ACS_GEQUAL", (ACS_GEQUAL
));
1853 SetDictInt("ACS_PI", (ACS_PI
));
1856 SetDictInt("ACS_NEQUAL", (ACS_NEQUAL
));
1859 SetDictInt("ACS_STERLING", (ACS_STERLING
));
1862 nlines
= PyInt_FromLong((long) LINES
);
1863 PyDict_SetItemString(ModDict
, "LINES", nlines
);
1865 cols
= PyInt_FromLong((long) COLS
);
1866 PyDict_SetItemString(ModDict
, "COLS", cols
);
1869 return (PyObject
*)PyCursesWindow_New(win
);
1873 PyCurses_setupterm(PyObject
* self
, PyObject
*args
, PyObject
* keywds
)
1877 char* termstr
= NULL
;
1879 static char *kwlist
[] = {"term", "fd", NULL
};
1881 if (!PyArg_ParseTupleAndKeywords(
1882 args
,keywds
,"|zi:setupterm",kwlist
,&termstr
,&fd
)) {
1887 PyObject
* sys_stdout
;
1889 sys_stdout
= PySys_GetObject("stdout");
1891 if (sys_stdout
== NULL
) {
1898 fd
= PyObject_AsFileDescriptor(sys_stdout
);
1905 if (setupterm(termstr
,fd
,&err
) == ERR
) {
1906 char* s
= "setupterm: unknown error";
1909 s
= "setupterm: could not find terminal";
1910 } else if (err
== -1) {
1911 s
= "setupterm: could not find terminfo database";
1914 PyErr_SetString(PyCursesError
,s
);
1918 initialised_setupterm
= TRUE
;
1925 PyCurses_IntrFlush(PyObject
*self
, PyObject
*args
)
1931 switch(ARG_COUNT(args
)) {
1933 if (!PyArg_Parse(args
,"i;True(1), False(0)",&ch
)) return NULL
;
1936 PyErr_SetString(PyExc_TypeError
, "intrflush requires 1 argument");
1940 return PyCursesCheckERR(intrflush(NULL
,ch
), "intrflush");
1943 #if !defined(__NetBSD__)
1945 PyCurses_KeyName(PyObject
*self
, PyObject
*args
)
1952 if (!PyArg_Parse(args
,"i",&ch
)) return NULL
;
1956 return PyString_FromString((knp
== NULL
) ? "" : (char *)knp
);
1961 PyCurses_KillChar(PyObject
*self
, PyObject
*args
)
1965 if (!PyArg_NoArgs(args
)) return NULL
;
1969 return PyString_FromString(&ch
);
1973 PyCurses_Meta(PyObject
*self
, PyObject
*args
)
1979 switch(ARG_COUNT(args
)) {
1981 if (!PyArg_Parse(args
,"i;True(1), False(0)",&ch
)) return NULL
;
1984 PyErr_SetString(PyExc_TypeError
, "meta requires 1 argument");
1988 return PyCursesCheckERR(meta(stdscr
, ch
), "meta");
1991 #ifdef NCURSES_MOUSE_VERSION
1993 PyCurses_MouseInterval(PyObject
*self
, PyObject
*args
)
1998 if (!PyArg_Parse(args
,"i;interval",&interval
))
2000 return PyCursesCheckERR(mouseinterval(interval
), "mouseinterval");
2004 PyCurses_MouseMask(PyObject
*self
, PyObject
*args
)
2007 mmask_t oldmask
, availmask
;
2010 if (!PyArg_Parse(args
,"i;mousemask",&newmask
))
2012 availmask
= mousemask(newmask
, &oldmask
);
2013 return Py_BuildValue("(ll)", (long)availmask
, (long)oldmask
);
2018 PyCurses_Napms(PyObject
*self
, PyObject
*args
)
2023 if (!PyArg_Parse(args
, "i;ms", &ms
)) return NULL
;
2025 return Py_BuildValue("i", napms(ms
));
2030 PyCurses_NewPad(PyObject
*self
, PyObject
*args
)
2037 if (!PyArg_Parse(args
,"(ii);nlines,ncols",&nlines
,&ncols
)) return NULL
;
2039 win
= newpad(nlines
, ncols
);
2042 PyErr_SetString(PyCursesError
, catchall_NULL
);
2046 return (PyObject
*)PyCursesWindow_New(win
);
2050 PyCurses_NewWindow(PyObject
*self
, PyObject
*args
)
2053 int nlines
, ncols
, begin_y
, begin_x
;
2057 switch (ARG_COUNT(args
)) {
2059 if (!PyArg_Parse(args
,"(ii);nlines,ncols",&nlines
,&ncols
))
2061 win
= newpad(nlines
, ncols
);
2064 if (!PyArg_Parse(args
, "(iiii);nlines,ncols,begin_y,begin_x",
2065 &nlines
,&ncols
,&begin_y
,&begin_x
))
2067 win
= newwin(nlines
,ncols
,begin_y
,begin_x
);
2070 PyErr_SetString(PyExc_TypeError
, "newwin requires 2 or 4 arguments");
2075 PyErr_SetString(PyCursesError
, catchall_NULL
);
2079 return (PyObject
*)PyCursesWindow_New(win
);
2083 PyCurses_Pair_Content(PyObject
*self
, PyObject
*args
)
2088 PyCursesInitialisedColor
2090 switch(ARG_COUNT(args
)) {
2092 if (!PyArg_Parse(args
, "h;pair", &pair
)) return NULL
;
2095 PyErr_SetString(PyExc_TypeError
, "pair_content requires 1 argument");
2099 if (!pair_content(pair
, &f
, &b
)) {
2100 PyErr_SetString(PyCursesError
,
2101 "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
2105 return Py_BuildValue("(ii)", f
, b
);
2109 PyCurses_pair_number(PyObject
*self
, PyObject
*args
)
2114 PyCursesInitialisedColor
2116 switch(ARG_COUNT(args
)) {
2118 if (!PyArg_Parse(args
, "i;pairvalue", &n
)) return NULL
;
2121 PyErr_SetString(PyExc_TypeError
,
2122 "pair_number requires 1 argument");
2126 return PyInt_FromLong((long) ((n
& A_COLOR
) >> 8));
2130 PyCurses_Putp(PyObject
*self
, PyObject
*args
)
2134 if (!PyArg_Parse(args
,"s;str", &str
)) return NULL
;
2135 return PyCursesCheckERR(putp(str
), "putp");
2139 PyCurses_QiFlush(PyObject
*self
, PyObject
*args
)
2145 switch(ARG_COUNT(args
)) {
2151 if (!PyArg_Parse(args
, "i;True(1) or False(0)", &flag
)) return NULL
;
2152 if (flag
) qiflush();
2157 PyErr_SetString(PyExc_TypeError
, "qiflush requires 0 or 1 arguments");
2163 PyCurses_setsyx(PyObject
*self
, PyObject
*args
)
2169 if (ARG_COUNT(args
)!=2) {
2170 PyErr_SetString(PyExc_TypeError
, "setsyx requires 2 arguments");
2174 if (!PyArg_Parse(args
, "(ii);y, x", &y
, &x
)) return NULL
;
2183 PyCurses_Start_Color(PyObject
*self
, PyObject
*args
)
2190 if (!PyArg_NoArgs(args
)) return NULL
;
2192 code
= start_color();
2194 initialisedcolors
= TRUE
;
2195 c
= PyInt_FromLong((long) COLORS
);
2196 PyDict_SetItemString(ModDict
, "COLORS", c
);
2198 cp
= PyInt_FromLong((long) COLOR_PAIRS
);
2199 PyDict_SetItemString(ModDict
, "COLOR_PAIRS", cp
);
2204 PyErr_SetString(PyCursesError
, "start_color() returned ERR");
2210 PyCurses_tigetflag(PyObject
*self
, PyObject
*args
)
2214 PyCursesSetupTermCalled
;
2216 if (!PyArg_ParseTuple(args
, "z", &capname
))
2219 return PyInt_FromLong( (long) tigetflag( capname
) );
2223 PyCurses_tigetnum(PyObject
*self
, PyObject
*args
)
2227 PyCursesSetupTermCalled
;
2229 if (!PyArg_ParseTuple(args
, "z", &capname
))
2232 return PyInt_FromLong( (long) tigetnum( capname
) );
2236 PyCurses_tigetstr(PyObject
*self
, PyObject
*args
)
2240 PyCursesSetupTermCalled
;
2242 if (!PyArg_ParseTuple(args
, "z", &capname
))
2245 capname
= tigetstr( capname
);
2246 if (capname
== 0 || capname
== (char*) -1) {
2250 return PyString_FromString( capname
);
2254 PyCurses_tparm(PyObject
*self
, PyObject
*args
)
2257 char* result
= NULL
;
2258 int i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
,i9
;
2260 PyCursesSetupTermCalled
;
2262 if (!PyArg_ParseTuple(args
, "s|iiiiiiiii:tparm",
2263 &fmt
, &i1
, &i2
, &i3
, &i4
,
2264 &i5
, &i6
, &i7
, &i8
, &i9
)) {
2268 switch (PyTuple_GET_SIZE(args
)) {
2270 result
= tparm(fmt
);
2273 result
= tparm(fmt
,i1
);
2276 result
= tparm(fmt
,i1
,i2
);
2279 result
= tparm(fmt
,i1
,i2
,i3
);
2282 result
= tparm(fmt
,i1
,i2
,i3
,i4
);
2285 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
);
2288 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
);
2291 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
);
2294 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
);
2297 result
= tparm(fmt
,i1
,i2
,i3
,i4
,i5
,i6
,i7
,i8
,i9
);
2301 return PyString_FromString(result
);
2305 PyCurses_TypeAhead(PyObject
*self
, PyObject
*args
)
2311 if (!PyArg_Parse(args
,"i;fd",&fd
)) return NULL
;
2313 PyCursesCheckERR(typeahead( fd
), "typeahead");
2319 PyCurses_UnCtrl(PyObject
*self
, PyObject
*args
)
2326 if (!PyArg_Parse(args
,"O;ch or int",&temp
)) return NULL
;
2328 if (PyInt_Check(temp
))
2329 ch
= (chtype
) PyInt_AsLong(temp
);
2330 else if (PyString_Check(temp
))
2331 ch
= (chtype
) *PyString_AsString(temp
);
2333 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2337 return PyString_FromString(unctrl(ch
));
2341 PyCurses_UngetCh(PyObject
*self
, PyObject
*args
)
2348 if (!PyArg_Parse(args
,"O;ch or int",&temp
)) return NULL
;
2350 if (PyInt_Check(temp
))
2351 ch
= (chtype
) PyInt_AsLong(temp
);
2352 else if (PyString_Check(temp
))
2353 ch
= (chtype
) *PyString_AsString(temp
);
2355 PyErr_SetString(PyExc_TypeError
, "argument must be a ch or an int");
2359 return PyCursesCheckERR(ungetch(ch
), "ungetch");
2363 PyCurses_Use_Env(PyObject
*self
, PyObject
*args
)
2369 switch(ARG_COUNT(args
)) {
2371 if (!PyArg_Parse(args
,"i;True(1), False(0)",&flag
))
2375 PyErr_SetString(PyExc_TypeError
, "use_env requires 1 argument");
2383 /* List of functions defined in the module */
2385 static PyMethodDef PyCurses_methods
[] = {
2386 {"baudrate", (PyCFunction
)PyCurses_baudrate
},
2387 {"beep", (PyCFunction
)PyCurses_beep
},
2388 {"can_change_color", (PyCFunction
)PyCurses_can_change_color
},
2389 {"cbreak", (PyCFunction
)PyCurses_cbreak
},
2390 {"color_content", (PyCFunction
)PyCurses_Color_Content
},
2391 {"color_pair", (PyCFunction
)PyCurses_color_pair
},
2392 {"curs_set", (PyCFunction
)PyCurses_Curs_Set
},
2393 {"def_prog_mode", (PyCFunction
)PyCurses_def_prog_mode
},
2394 {"def_shell_mode", (PyCFunction
)PyCurses_def_shell_mode
},
2395 {"delay_output", (PyCFunction
)PyCurses_Delay_Output
},
2396 {"doupdate", (PyCFunction
)PyCurses_doupdate
},
2397 {"echo", (PyCFunction
)PyCurses_echo
},
2398 {"endwin", (PyCFunction
)PyCurses_endwin
},
2399 {"erasechar", (PyCFunction
)PyCurses_EraseChar
},
2400 {"filter", (PyCFunction
)PyCurses_filter
},
2401 {"flash", (PyCFunction
)PyCurses_flash
},
2402 {"flushinp", (PyCFunction
)PyCurses_flushinp
},
2403 #ifdef NCURSES_MOUSE_VERSION
2404 {"getmouse", (PyCFunction
)PyCurses_GetMouse
},
2405 {"ungetmouse", (PyCFunction
)PyCurses_UngetMouse
, METH_VARARGS
},
2407 {"getsyx", (PyCFunction
)PyCurses_getsyx
},
2408 {"getwin", (PyCFunction
)PyCurses_GetWin
},
2409 {"has_colors", (PyCFunction
)PyCurses_has_colors
},
2410 {"has_ic", (PyCFunction
)PyCurses_has_ic
},
2411 {"has_il", (PyCFunction
)PyCurses_has_il
},
2412 #ifndef STRICT_SYSV_CURSES
2413 {"has_key", (PyCFunction
)PyCurses_has_key
},
2415 {"halfdelay", (PyCFunction
)PyCurses_HalfDelay
},
2416 {"init_color", (PyCFunction
)PyCurses_Init_Color
},
2417 {"init_pair", (PyCFunction
)PyCurses_Init_Pair
},
2418 {"initscr", (PyCFunction
)PyCurses_InitScr
},
2419 {"intrflush", (PyCFunction
)PyCurses_IntrFlush
},
2420 {"isendwin", (PyCFunction
)PyCurses_isendwin
},
2421 #if !defined(__NetBSD__)
2422 {"keyname", (PyCFunction
)PyCurses_KeyName
},
2424 {"killchar", (PyCFunction
)PyCurses_KillChar
},
2425 {"longname", (PyCFunction
)PyCurses_longname
},
2426 {"meta", (PyCFunction
)PyCurses_Meta
},
2427 #ifdef NCURSES_MOUSE_VERSION
2428 {"mouseinterval", (PyCFunction
)PyCurses_MouseInterval
},
2429 {"mousemask", (PyCFunction
)PyCurses_MouseMask
},
2431 {"napms", (PyCFunction
)PyCurses_Napms
},
2432 {"newpad", (PyCFunction
)PyCurses_NewPad
},
2433 {"newwin", (PyCFunction
)PyCurses_NewWindow
},
2434 {"nl", (PyCFunction
)PyCurses_nl
},
2435 {"nocbreak", (PyCFunction
)PyCurses_nocbreak
},
2436 {"noecho", (PyCFunction
)PyCurses_noecho
},
2437 {"nonl", (PyCFunction
)PyCurses_nonl
},
2438 {"noqiflush", (PyCFunction
)PyCurses_noqiflush
},
2439 {"noraw", (PyCFunction
)PyCurses_noraw
},
2440 {"pair_content", (PyCFunction
)PyCurses_Pair_Content
},
2441 {"pair_number", (PyCFunction
)PyCurses_pair_number
},
2442 {"putp", (PyCFunction
)PyCurses_Putp
},
2443 {"qiflush", (PyCFunction
)PyCurses_QiFlush
},
2444 {"raw", (PyCFunction
)PyCurses_raw
},
2445 {"reset_prog_mode", (PyCFunction
)PyCurses_reset_prog_mode
},
2446 {"reset_shell_mode", (PyCFunction
)PyCurses_reset_shell_mode
},
2447 {"resetty", (PyCFunction
)PyCurses_resetty
},
2448 {"savetty", (PyCFunction
)PyCurses_savetty
},
2449 {"setsyx", (PyCFunction
)PyCurses_setsyx
},
2450 {"setupterm", (PyCFunction
)PyCurses_setupterm
, METH_VARARGS
|METH_KEYWORDS
},
2451 {"start_color", (PyCFunction
)PyCurses_Start_Color
},
2452 {"termattrs", (PyCFunction
)PyCurses_termattrs
},
2453 {"termname", (PyCFunction
)PyCurses_termname
},
2454 {"tigetflag", (PyCFunction
)PyCurses_tigetflag
, METH_VARARGS
},
2455 {"tigetnum", (PyCFunction
)PyCurses_tigetnum
, METH_VARARGS
},
2456 {"tigetstr", (PyCFunction
)PyCurses_tigetstr
, METH_VARARGS
},
2457 {"tparm", (PyCFunction
)PyCurses_tparm
, METH_VARARGS
},
2458 {"typeahead", (PyCFunction
)PyCurses_TypeAhead
},
2459 {"unctrl", (PyCFunction
)PyCurses_UnCtrl
},
2460 {"ungetch", (PyCFunction
)PyCurses_UngetCh
},
2461 {"use_env", (PyCFunction
)PyCurses_Use_Env
},
2462 {NULL
, NULL
} /* sentinel */
2465 /* Initialization function for the module */
2470 PyObject
*m
, *d
, *v
, *c_api_object
;
2471 static void *PyCurses_API
[PyCurses_API_pointers
];
2473 /* Initialize object type */
2474 PyCursesWindow_Type
.ob_type
= &PyType_Type
;
2476 /* Initialize the C API pointer array */
2477 PyCurses_API
[0] = (void *)&PyCursesWindow_Type
;
2478 PyCurses_API
[1] = (void *)func_PyCursesSetupTermCalled
;
2479 PyCurses_API
[2] = (void *)func_PyCursesInitialised
;
2480 PyCurses_API
[3] = (void *)func_PyCursesInitialisedColor
;
2482 /* Create the module and add the functions */
2483 m
= Py_InitModule("_curses", PyCurses_methods
);
2485 /* Add some symbolic constants to the module */
2486 d
= PyModule_GetDict(m
);
2487 ModDict
= d
; /* For PyCurses_InitScr to use later */
2489 /* Add a CObject for the C API */
2490 c_api_object
= PyCObject_FromVoidPtr((void *)PyCurses_API
, NULL
);
2491 PyDict_SetItemString(d
, "_C_API", c_api_object
);
2493 /* For exception curses.error */
2494 PyCursesError
= PyErr_NewException("_curses.error", NULL
, NULL
);
2495 PyDict_SetItemString(d
, "error", PyCursesError
);
2497 /* Make the version available */
2498 v
= PyString_FromString(PyCursesVersion
);
2499 PyDict_SetItemString(d
, "version", v
);
2500 PyDict_SetItemString(d
, "__version__", v
);
2503 SetDictInt("ERR", ERR
);
2504 SetDictInt("OK", OK
);
2506 /* Here are some attributes you can add to chars to print */
2508 SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES
);
2509 SetDictInt("A_NORMAL", A_NORMAL
);
2510 SetDictInt("A_STANDOUT", A_STANDOUT
);
2511 SetDictInt("A_UNDERLINE", A_UNDERLINE
);
2512 SetDictInt("A_REVERSE", A_REVERSE
);
2513 SetDictInt("A_BLINK", A_BLINK
);
2514 SetDictInt("A_DIM", A_DIM
);
2515 SetDictInt("A_BOLD", A_BOLD
);
2516 SetDictInt("A_ALTCHARSET", A_ALTCHARSET
);
2517 #if !defined(__NetBSD__)
2518 SetDictInt("A_INVIS", A_INVIS
);
2520 SetDictInt("A_PROTECT", A_PROTECT
);
2521 SetDictInt("A_CHARTEXT", A_CHARTEXT
);
2522 SetDictInt("A_COLOR", A_COLOR
);
2524 /* The following are never available with strict SYSV curses */
2526 SetDictInt("A_HORIZONTAL", A_HORIZONTAL
);
2529 SetDictInt("A_LEFT", A_LEFT
);
2532 SetDictInt("A_LOW", A_LOW
);
2535 SetDictInt("A_RIGHT", A_RIGHT
);
2538 SetDictInt("A_TOP", A_TOP
);
2541 SetDictInt("A_VERTICAL", A_VERTICAL
);
2544 SetDictInt("COLOR_BLACK", COLOR_BLACK
);
2545 SetDictInt("COLOR_RED", COLOR_RED
);
2546 SetDictInt("COLOR_GREEN", COLOR_GREEN
);
2547 SetDictInt("COLOR_YELLOW", COLOR_YELLOW
);
2548 SetDictInt("COLOR_BLUE", COLOR_BLUE
);
2549 SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA
);
2550 SetDictInt("COLOR_CYAN", COLOR_CYAN
);
2551 SetDictInt("COLOR_WHITE", COLOR_WHITE
);
2553 #ifdef NCURSES_MOUSE_VERSION
2554 /* Mouse-related constants */
2555 SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED
);
2556 SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED
);
2557 SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED
);
2558 SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED
);
2559 SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED
);
2561 SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED
);
2562 SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED
);
2563 SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED
);
2564 SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED
);
2565 SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED
);
2567 SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED
);
2568 SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED
);
2569 SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED
);
2570 SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED
);
2571 SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED
);
2573 SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED
);
2574 SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED
);
2575 SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED
);
2576 SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED
);
2577 SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED
);
2579 SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT
);
2580 SetDictInt("BUTTON_CTRL", BUTTON_CTRL
);
2581 SetDictInt("BUTTON_ALT", BUTTON_ALT
);
2583 SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS
);
2584 SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION
);
2586 /* Now set everything up for KEY_ variables */
2591 #if !defined(__NetBSD__)
2592 for (key
=KEY_MIN
;key
< KEY_MAX
; key
++) {
2593 key_n
= (char *)keyname(key
);
2594 if (key_n
== NULL
|| strcmp(key_n
,"UNKNOWN KEY")==0)
2596 if (strncmp(key_n
,"KEY_F(",6)==0) {
2598 key_n2
= malloc(strlen(key_n
)+1);
2602 if (*p1
!= '(' && *p1
!= ')') {
2611 PyDict_SetItemString(d
,key_n2
,PyInt_FromLong((long) key
));
2612 if (key_n2
!= key_n
)
2616 SetDictInt("KEY_MIN", KEY_MIN
);
2617 SetDictInt("KEY_MAX", KEY_MAX
);