[2] | 1 | /*
|
---|
| 2 | * This is a curses module for Python.
|
---|
| 3 | *
|
---|
| 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.
|
---|
| 7 | *
|
---|
| 8 | * Version 1.5b1, heavily extended for ncurses by Oliver Andrich:
|
---|
| 9 | * Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany.
|
---|
| 10 | *
|
---|
| 11 | * Tidied for Python 1.6, and currently maintained by <amk@amk.ca>.
|
---|
| 12 | *
|
---|
| 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:
|
---|
| 16 | *
|
---|
| 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
|
---|
| 19 | * this file.
|
---|
| 20 | *
|
---|
| 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.
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | /*
|
---|
| 35 |
|
---|
[391] | 36 | A number of SysV or ncurses functions don't have wrappers yet; if you
|
---|
| 37 | need a given function, add it and send a patch. See
|
---|
| 38 | http://www.python.org/dev/patches/ for instructions on how to submit
|
---|
| 39 | patches to Python.
|
---|
[2] | 40 |
|
---|
[391] | 41 | Here's a list of currently unsupported functions:
|
---|
[2] | 42 |
|
---|
[391] | 43 | addchnstr addchstr color_set define_key
|
---|
| 44 | del_curterm delscreen dupwin inchnstr inchstr innstr keyok
|
---|
| 45 | mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr
|
---|
| 46 | mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr
|
---|
| 47 | mvwinchnstr mvwinchstr mvwinnstr newterm
|
---|
| 48 | restartterm ripoffline scr_dump
|
---|
| 49 | scr_init scr_restore scr_set scrl set_curterm set_term setterm
|
---|
| 50 | tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
|
---|
| 51 | vidattr vidputs waddchnstr waddchstr
|
---|
| 52 | wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
|
---|
[2] | 53 |
|
---|
[391] | 54 | Low-priority:
|
---|
| 55 | slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
|
---|
| 56 | slk_attron slk_attrset slk_clear slk_color slk_init slk_label
|
---|
| 57 | slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
|
---|
[2] | 58 |
|
---|
[391] | 59 | Menu extension (ncurses and probably SYSV):
|
---|
| 60 | current_item free_item free_menu item_count item_description
|
---|
| 61 | item_index item_init item_name item_opts item_opts_off
|
---|
| 62 | item_opts_on item_term item_userptr item_value item_visible
|
---|
| 63 | menu_back menu_driver menu_fore menu_format menu_grey
|
---|
| 64 | menu_init menu_items menu_mark menu_opts menu_opts_off
|
---|
| 65 | menu_opts_on menu_pad menu_pattern menu_request_by_name
|
---|
| 66 | menu_request_name menu_spacing menu_sub menu_term menu_userptr
|
---|
| 67 | menu_win new_item new_menu pos_menu_cursor post_menu
|
---|
| 68 | scale_menu set_current_item set_item_init set_item_opts
|
---|
| 69 | set_item_term set_item_userptr set_item_value set_menu_back
|
---|
| 70 | set_menu_fore set_menu_format set_menu_grey set_menu_init
|
---|
| 71 | set_menu_items set_menu_mark set_menu_opts set_menu_pad
|
---|
| 72 | set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
|
---|
| 73 | set_menu_userptr set_menu_win set_top_row top_row unpost_menu
|
---|
[2] | 74 |
|
---|
[391] | 75 | Form extension (ncurses and probably SYSV):
|
---|
| 76 | current_field data_ahead data_behind dup_field
|
---|
| 77 | dynamic_fieldinfo field_arg field_back field_buffer
|
---|
| 78 | field_count field_fore field_index field_info field_init
|
---|
| 79 | field_just field_opts field_opts_off field_opts_on field_pad
|
---|
| 80 | field_status field_term field_type field_userptr form_driver
|
---|
| 81 | form_fields form_init form_opts form_opts_off form_opts_on
|
---|
| 82 | form_page form_request_by_name form_request_name form_sub
|
---|
| 83 | form_term form_userptr form_win free_field free_form
|
---|
| 84 | link_field link_fieldtype move_field new_field new_form
|
---|
| 85 | new_page pos_form_cursor post_form scale_form
|
---|
| 86 | set_current_field set_field_back set_field_buffer
|
---|
| 87 | set_field_fore set_field_init set_field_just set_field_opts
|
---|
| 88 | set_field_pad set_field_status set_field_term set_field_type
|
---|
| 89 | set_field_userptr set_fieldtype_arg set_fieldtype_choice
|
---|
| 90 | set_form_fields set_form_init set_form_opts set_form_page
|
---|
| 91 | set_form_sub set_form_term set_form_userptr set_form_win
|
---|
| 92 | set_max_field set_new_page unpost_form
|
---|
[2] | 93 |
|
---|
| 94 |
|
---|
[391] | 95 | */
|
---|
[2] | 96 |
|
---|
| 97 | /* Release Number */
|
---|
| 98 |
|
---|
| 99 | char *PyCursesVersion = "2.2";
|
---|
| 100 |
|
---|
| 101 | /* Includes */
|
---|
| 102 |
|
---|
| 103 | #include "Python.h"
|
---|
| 104 |
|
---|
| 105 | #ifdef __osf__
|
---|
| 106 | #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
|
---|
| 107 | #endif
|
---|
| 108 |
|
---|
| 109 | #ifdef __hpux
|
---|
| 110 | #define STRICT_SYSV_CURSES
|
---|
| 111 | #endif
|
---|
| 112 |
|
---|
| 113 | #define CURSES_MODULE
|
---|
| 114 | #include "py_curses.h"
|
---|
| 115 |
|
---|
[391] | 116 | /* These prototypes are in <term.h>, but including this header
|
---|
| 117 | #defines many common symbols (such as "lines") which breaks the
|
---|
| 118 | curses module in other ways. So the code will just specify
|
---|
[2] | 119 | explicit prototypes here. */
|
---|
| 120 | extern int setupterm(char *,int,int *);
|
---|
| 121 | #ifdef __sgi
|
---|
| 122 | #include <term.h>
|
---|
| 123 | #endif
|
---|
| 124 |
|
---|
| 125 | #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
|
---|
| 126 | #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
|
---|
| 127 | typedef chtype attr_t; /* No attr_t type is available */
|
---|
| 128 | #endif
|
---|
| 129 |
|
---|
| 130 | #if defined(_AIX)
|
---|
| 131 | #define STRICT_SYSV_CURSES
|
---|
| 132 | #endif
|
---|
| 133 |
|
---|
| 134 | /* Definition of exception curses.error */
|
---|
| 135 |
|
---|
| 136 | static PyObject *PyCursesError;
|
---|
| 137 |
|
---|
| 138 | /* Tells whether setupterm() has been called to initialise terminfo. */
|
---|
| 139 | static int initialised_setupterm = FALSE;
|
---|
| 140 |
|
---|
| 141 | /* Tells whether initscr() has been called to initialise curses. */
|
---|
| 142 | static int initialised = FALSE;
|
---|
| 143 |
|
---|
| 144 | /* Tells whether start_color() has been called to initialise color usage. */
|
---|
| 145 | static int initialisedcolors = FALSE;
|
---|
| 146 |
|
---|
| 147 | /* Utility Macros */
|
---|
[391] | 148 | #define PyCursesSetupTermCalled \
|
---|
| 149 | if (initialised_setupterm != TRUE) { \
|
---|
| 150 | PyErr_SetString(PyCursesError, \
|
---|
| 151 | "must call (at least) setupterm() first"); \
|
---|
| 152 | return 0; }
|
---|
[2] | 153 |
|
---|
[391] | 154 | #define PyCursesInitialised \
|
---|
| 155 | if (initialised != TRUE) { \
|
---|
| 156 | PyErr_SetString(PyCursesError, \
|
---|
| 157 | "must call initscr() first"); \
|
---|
| 158 | return 0; }
|
---|
[2] | 159 |
|
---|
[391] | 160 | #define PyCursesInitialisedColor \
|
---|
| 161 | if (initialisedcolors != TRUE) { \
|
---|
| 162 | PyErr_SetString(PyCursesError, \
|
---|
| 163 | "must call start_color() first"); \
|
---|
| 164 | return 0; }
|
---|
[2] | 165 |
|
---|
| 166 | #ifndef MIN
|
---|
| 167 | #define MIN(x,y) ((x) < (y) ? (x) : (y))
|
---|
| 168 | #endif
|
---|
| 169 |
|
---|
| 170 | /* Utility Functions */
|
---|
| 171 |
|
---|
| 172 | /*
|
---|
[391] | 173 | * Check the return code from a curses function and return None
|
---|
[2] | 174 | * or raise an exception as appropriate. These are exported using the
|
---|
[391] | 175 | * capsule API.
|
---|
[2] | 176 | */
|
---|
| 177 |
|
---|
| 178 | static PyObject *
|
---|
| 179 | PyCursesCheckERR(int code, char *fname)
|
---|
| 180 | {
|
---|
[391] | 181 | if (code != ERR) {
|
---|
| 182 | Py_INCREF(Py_None);
|
---|
| 183 | return Py_None;
|
---|
[2] | 184 | } else {
|
---|
[391] | 185 | if (fname == NULL) {
|
---|
| 186 | PyErr_SetString(PyCursesError, catchall_ERR);
|
---|
| 187 | } else {
|
---|
| 188 | PyErr_Format(PyCursesError, "%s() returned ERR", fname);
|
---|
| 189 | }
|
---|
| 190 | return NULL;
|
---|
[2] | 191 | }
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[391] | 194 | static int
|
---|
[2] | 195 | PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
|
---|
| 196 | {
|
---|
[391] | 197 | if (PyInt_Check(obj)) {
|
---|
| 198 | *ch = (chtype) PyInt_AsLong(obj);
|
---|
| 199 | } else if(PyString_Check(obj)
|
---|
| 200 | && (PyString_Size(obj) == 1)) {
|
---|
| 201 | *ch = (chtype) *PyString_AsString(obj);
|
---|
| 202 | } else {
|
---|
| 203 | return 0;
|
---|
| 204 | }
|
---|
| 205 | return 1;
|
---|
[2] | 206 | }
|
---|
| 207 |
|
---|
[391] | 208 | /* Function versions of the 3 functions for testing whether curses has been
|
---|
[2] | 209 | initialised or not. */
|
---|
[391] | 210 |
|
---|
[2] | 211 | static int func_PyCursesSetupTermCalled(void)
|
---|
| 212 | {
|
---|
| 213 | PyCursesSetupTermCalled;
|
---|
| 214 | return 1;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | static int func_PyCursesInitialised(void)
|
---|
| 218 | {
|
---|
| 219 | PyCursesInitialised;
|
---|
| 220 | return 1;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | static int func_PyCursesInitialisedColor(void)
|
---|
| 224 | {
|
---|
| 225 | PyCursesInitialisedColor;
|
---|
| 226 | return 1;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | /*****************************************************************************
|
---|
| 230 | The Window Object
|
---|
| 231 | ******************************************************************************/
|
---|
| 232 |
|
---|
| 233 | /* Definition of the window type */
|
---|
| 234 |
|
---|
| 235 | PyTypeObject PyCursesWindow_Type;
|
---|
| 236 |
|
---|
| 237 | /* Function prototype macros for Window object
|
---|
| 238 |
|
---|
| 239 | X - function name
|
---|
| 240 | TYPE - parameter Type
|
---|
| 241 | ERGSTR - format string for construction of the return value
|
---|
| 242 | PARSESTR - format string for argument parsing
|
---|
[391] | 243 | */
|
---|
[2] | 244 |
|
---|
[391] | 245 | #define Window_NoArgNoReturnFunction(X) \
|
---|
| 246 | static PyObject *PyCursesWindow_ ## X \
|
---|
| 247 | (PyCursesWindowObject *self, PyObject *args) \
|
---|
| 248 | { return PyCursesCheckERR(X(self->win), # X); }
|
---|
[2] | 249 |
|
---|
[391] | 250 | #define Window_NoArgTrueFalseFunction(X) \
|
---|
| 251 | static PyObject * PyCursesWindow_ ## X \
|
---|
| 252 | (PyCursesWindowObject *self) \
|
---|
| 253 | { \
|
---|
| 254 | if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
|
---|
| 255 | else { Py_INCREF(Py_True); return Py_True; } }
|
---|
[2] | 256 |
|
---|
[391] | 257 | #define Window_NoArgNoReturnVoidFunction(X) \
|
---|
| 258 | static PyObject * PyCursesWindow_ ## X \
|
---|
| 259 | (PyCursesWindowObject *self) \
|
---|
| 260 | { \
|
---|
| 261 | X(self->win); Py_INCREF(Py_None); return Py_None; }
|
---|
[2] | 262 |
|
---|
[391] | 263 | #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
|
---|
| 264 | static PyObject * PyCursesWindow_ ## X \
|
---|
| 265 | (PyCursesWindowObject *self) \
|
---|
| 266 | { \
|
---|
| 267 | TYPE arg1, arg2; \
|
---|
| 268 | X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
|
---|
[2] | 269 |
|
---|
[391] | 270 | #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
|
---|
| 271 | static PyObject * PyCursesWindow_ ## X \
|
---|
| 272 | (PyCursesWindowObject *self, PyObject *args) \
|
---|
| 273 | { \
|
---|
| 274 | TYPE arg1; \
|
---|
| 275 | if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
|
---|
| 276 | X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
|
---|
[2] | 277 |
|
---|
[391] | 278 | #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
|
---|
| 279 | static PyObject * PyCursesWindow_ ## X \
|
---|
| 280 | (PyCursesWindowObject *self, PyObject *args) \
|
---|
| 281 | { \
|
---|
| 282 | TYPE arg1; \
|
---|
| 283 | if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
|
---|
| 284 | return PyCursesCheckERR(X(self->win, arg1), # X); }
|
---|
[2] | 285 |
|
---|
[391] | 286 | #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
|
---|
| 287 | static PyObject * PyCursesWindow_ ## X \
|
---|
| 288 | (PyCursesWindowObject *self, PyObject *args) \
|
---|
| 289 | { \
|
---|
| 290 | TYPE arg1, arg2; \
|
---|
| 291 | if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
|
---|
| 292 | return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
|
---|
[2] | 293 |
|
---|
| 294 | /* ------------- WINDOW routines --------------- */
|
---|
| 295 |
|
---|
| 296 | Window_NoArgNoReturnFunction(untouchwin)
|
---|
| 297 | Window_NoArgNoReturnFunction(touchwin)
|
---|
| 298 | Window_NoArgNoReturnFunction(redrawwin)
|
---|
| 299 | Window_NoArgNoReturnFunction(winsertln)
|
---|
| 300 | Window_NoArgNoReturnFunction(werase)
|
---|
| 301 | Window_NoArgNoReturnFunction(wdeleteln)
|
---|
| 302 |
|
---|
| 303 | Window_NoArgTrueFalseFunction(is_wintouched)
|
---|
| 304 |
|
---|
| 305 | Window_NoArgNoReturnVoidFunction(wsyncup)
|
---|
| 306 | Window_NoArgNoReturnVoidFunction(wsyncdown)
|
---|
| 307 | Window_NoArgNoReturnVoidFunction(wstandend)
|
---|
| 308 | Window_NoArgNoReturnVoidFunction(wstandout)
|
---|
| 309 | Window_NoArgNoReturnVoidFunction(wcursyncup)
|
---|
| 310 | Window_NoArgNoReturnVoidFunction(wclrtoeol)
|
---|
| 311 | Window_NoArgNoReturnVoidFunction(wclrtobot)
|
---|
| 312 | Window_NoArgNoReturnVoidFunction(wclear)
|
---|
| 313 |
|
---|
| 314 | Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")
|
---|
| 315 | Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
|
---|
| 316 | Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay")
|
---|
| 317 |
|
---|
| 318 | Window_NoArg2TupleReturnFunction(getyx, int, "ii")
|
---|
| 319 | Window_NoArg2TupleReturnFunction(getbegyx, int, "ii")
|
---|
| 320 | Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii")
|
---|
| 321 | Window_NoArg2TupleReturnFunction(getparyx, int, "ii")
|
---|
| 322 |
|
---|
| 323 | Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
|
---|
| 324 | Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
|
---|
| 325 | #if defined(__NetBSD__)
|
---|
| 326 | Window_OneArgNoReturnVoidFunction(keypad, int, "i;True(1) or False(0)")
|
---|
| 327 | #else
|
---|
| 328 | Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")
|
---|
| 329 | #endif
|
---|
| 330 | Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")
|
---|
| 331 | #if defined(__NetBSD__)
|
---|
| 332 | Window_OneArgNoReturnVoidFunction(nodelay, int, "i;True(1) or False(0)")
|
---|
| 333 | #else
|
---|
| 334 | Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
|
---|
| 335 | #endif
|
---|
| 336 | Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")
|
---|
| 337 | Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")
|
---|
| 338 | Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines")
|
---|
| 339 | Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
|
---|
| 340 |
|
---|
| 341 | Window_TwoArgNoReturnFunction(mvwin, int, "ii;y,x")
|
---|
| 342 | Window_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x")
|
---|
| 343 | Window_TwoArgNoReturnFunction(wmove, int, "ii;y,x")
|
---|
| 344 | #ifndef STRICT_SYSV_CURSES
|
---|
| 345 | Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns")
|
---|
| 346 | #endif
|
---|
| 347 |
|
---|
| 348 | /* Allocation and deallocation of Window Objects */
|
---|
| 349 |
|
---|
| 350 | static PyObject *
|
---|
| 351 | PyCursesWindow_New(WINDOW *win)
|
---|
| 352 | {
|
---|
[391] | 353 | PyCursesWindowObject *wo;
|
---|
[2] | 354 |
|
---|
[391] | 355 | wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
|
---|
| 356 | if (wo == NULL) return NULL;
|
---|
| 357 | wo->win = win;
|
---|
| 358 | return (PyObject *)wo;
|
---|
[2] | 359 | }
|
---|
| 360 |
|
---|
| 361 | static void
|
---|
| 362 | PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
|
---|
| 363 | {
|
---|
[391] | 364 | if (wo->win != stdscr) delwin(wo->win);
|
---|
| 365 | PyObject_DEL(wo);
|
---|
[2] | 366 | }
|
---|
| 367 |
|
---|
| 368 | /* Addch, Addstr, Addnstr */
|
---|
| 369 |
|
---|
| 370 | static PyObject *
|
---|
| 371 | PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args)
|
---|
| 372 | {
|
---|
[391] | 373 | int rtn, x, y, use_xy = FALSE;
|
---|
| 374 | PyObject *temp;
|
---|
| 375 | chtype ch = 0;
|
---|
| 376 | attr_t attr = A_NORMAL;
|
---|
| 377 | long lattr;
|
---|
[2] | 378 |
|
---|
[391] | 379 | switch (PyTuple_Size(args)) {
|
---|
| 380 | case 1:
|
---|
| 381 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
|
---|
| 382 | return NULL;
|
---|
| 383 | break;
|
---|
| 384 | case 2:
|
---|
| 385 | if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
|
---|
| 386 | return NULL;
|
---|
| 387 | attr = lattr;
|
---|
| 388 | break;
|
---|
| 389 | case 3:
|
---|
| 390 | if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
|
---|
| 391 | return NULL;
|
---|
| 392 | use_xy = TRUE;
|
---|
| 393 | break;
|
---|
| 394 | case 4:
|
---|
| 395 | if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr",
|
---|
| 396 | &y, &x, &temp, &lattr))
|
---|
| 397 | return NULL;
|
---|
| 398 | attr = lattr;
|
---|
| 399 | use_xy = TRUE;
|
---|
| 400 | break;
|
---|
| 401 | default:
|
---|
| 402 | PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
|
---|
| 403 | return NULL;
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | if (!PyCurses_ConvertToChtype(temp, &ch)) {
|
---|
| 407 | PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
|
---|
| 408 | return NULL;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | if (use_xy == TRUE)
|
---|
| 412 | rtn = mvwaddch(self->win,y,x, ch | attr);
|
---|
| 413 | else {
|
---|
| 414 | rtn = waddch(self->win, ch | attr);
|
---|
| 415 | }
|
---|
| 416 | return PyCursesCheckERR(rtn, "addch");
|
---|
[2] | 417 | }
|
---|
| 418 |
|
---|
| 419 | static PyObject *
|
---|
| 420 | PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args)
|
---|
| 421 | {
|
---|
[391] | 422 | int rtn;
|
---|
| 423 | int x, y;
|
---|
| 424 | char *str;
|
---|
| 425 | attr_t attr = A_NORMAL , attr_old = A_NORMAL;
|
---|
| 426 | long lattr;
|
---|
| 427 | int use_xy = FALSE, use_attr = FALSE;
|
---|
[2] | 428 |
|
---|
[391] | 429 | switch (PyTuple_Size(args)) {
|
---|
| 430 | case 1:
|
---|
| 431 | if (!PyArg_ParseTuple(args,"s;str", &str))
|
---|
| 432 | return NULL;
|
---|
| 433 | break;
|
---|
| 434 | case 2:
|
---|
| 435 | if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
|
---|
| 436 | return NULL;
|
---|
| 437 | attr = lattr;
|
---|
| 438 | use_attr = TRUE;
|
---|
| 439 | break;
|
---|
| 440 | case 3:
|
---|
| 441 | if (!PyArg_ParseTuple(args,"iis;int,int,str", &y, &x, &str))
|
---|
| 442 | return NULL;
|
---|
| 443 | use_xy = TRUE;
|
---|
| 444 | break;
|
---|
| 445 | case 4:
|
---|
| 446 | if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &lattr))
|
---|
| 447 | return NULL;
|
---|
| 448 | attr = lattr;
|
---|
| 449 | use_xy = use_attr = TRUE;
|
---|
| 450 | break;
|
---|
| 451 | default:
|
---|
| 452 | PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
|
---|
| 453 | return NULL;
|
---|
| 454 | }
|
---|
[2] | 455 |
|
---|
[391] | 456 | if (use_attr == TRUE) {
|
---|
| 457 | attr_old = getattrs(self->win);
|
---|
| 458 | (void)wattrset(self->win,attr);
|
---|
| 459 | }
|
---|
| 460 | if (use_xy == TRUE)
|
---|
| 461 | rtn = mvwaddstr(self->win,y,x,str);
|
---|
| 462 | else
|
---|
| 463 | rtn = waddstr(self->win,str);
|
---|
| 464 | if (use_attr == TRUE)
|
---|
| 465 | (void)wattrset(self->win,attr_old);
|
---|
| 466 | return PyCursesCheckERR(rtn, "addstr");
|
---|
[2] | 467 | }
|
---|
| 468 |
|
---|
| 469 | static PyObject *
|
---|
| 470 | PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args)
|
---|
| 471 | {
|
---|
[391] | 472 | int rtn, x, y, n;
|
---|
| 473 | char *str;
|
---|
| 474 | attr_t attr = A_NORMAL , attr_old = A_NORMAL;
|
---|
| 475 | long lattr;
|
---|
| 476 | int use_xy = FALSE, use_attr = FALSE;
|
---|
[2] | 477 |
|
---|
[391] | 478 | switch (PyTuple_Size(args)) {
|
---|
| 479 | case 2:
|
---|
| 480 | if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
|
---|
| 481 | return NULL;
|
---|
| 482 | break;
|
---|
| 483 | case 3:
|
---|
| 484 | if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
|
---|
| 485 | return NULL;
|
---|
| 486 | attr = lattr;
|
---|
| 487 | use_attr = TRUE;
|
---|
| 488 | break;
|
---|
| 489 | case 4:
|
---|
| 490 | if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
|
---|
| 491 | return NULL;
|
---|
| 492 | use_xy = TRUE;
|
---|
| 493 | break;
|
---|
| 494 | case 5:
|
---|
| 495 | if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
|
---|
| 496 | return NULL;
|
---|
| 497 | attr = lattr;
|
---|
| 498 | use_xy = use_attr = TRUE;
|
---|
| 499 | break;
|
---|
| 500 | default:
|
---|
| 501 | PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
|
---|
| 502 | return NULL;
|
---|
| 503 | }
|
---|
[2] | 504 |
|
---|
[391] | 505 | if (use_attr == TRUE) {
|
---|
| 506 | attr_old = getattrs(self->win);
|
---|
| 507 | (void)wattrset(self->win,attr);
|
---|
| 508 | }
|
---|
| 509 | if (use_xy == TRUE)
|
---|
| 510 | rtn = mvwaddnstr(self->win,y,x,str,n);
|
---|
| 511 | else
|
---|
| 512 | rtn = waddnstr(self->win,str,n);
|
---|
| 513 | if (use_attr == TRUE)
|
---|
| 514 | (void)wattrset(self->win,attr_old);
|
---|
| 515 | return PyCursesCheckERR(rtn, "addnstr");
|
---|
[2] | 516 | }
|
---|
| 517 |
|
---|
| 518 | static PyObject *
|
---|
| 519 | PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
|
---|
| 520 | {
|
---|
[391] | 521 | PyObject *temp;
|
---|
| 522 | chtype bkgd;
|
---|
| 523 | attr_t attr = A_NORMAL;
|
---|
| 524 | long lattr;
|
---|
[2] | 525 |
|
---|
[391] | 526 | switch (PyTuple_Size(args)) {
|
---|
[2] | 527 | case 1:
|
---|
[391] | 528 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
|
---|
| 529 | return NULL;
|
---|
| 530 | break;
|
---|
[2] | 531 | case 2:
|
---|
[391] | 532 | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
|
---|
| 533 | return NULL;
|
---|
| 534 | attr = lattr;
|
---|
| 535 | break;
|
---|
| 536 | default:
|
---|
| 537 | PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
|
---|
[2] | 538 | return NULL;
|
---|
[391] | 539 | }
|
---|
[2] | 540 |
|
---|
[391] | 541 | if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
|
---|
| 542 | PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
|
---|
| 543 | return NULL;
|
---|
| 544 | }
|
---|
[2] | 545 |
|
---|
[391] | 546 | return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
|
---|
[2] | 547 | }
|
---|
| 548 |
|
---|
| 549 | static PyObject *
|
---|
| 550 | PyCursesWindow_AttrOff(PyCursesWindowObject *self, PyObject *args)
|
---|
| 551 | {
|
---|
[391] | 552 | long lattr;
|
---|
| 553 | if (!PyArg_ParseTuple(args,"l;attr", &lattr))
|
---|
| 554 | return NULL;
|
---|
| 555 | return PyCursesCheckERR(wattroff(self->win, (attr_t)lattr), "attroff");
|
---|
[2] | 556 | }
|
---|
| 557 |
|
---|
| 558 | static PyObject *
|
---|
| 559 | PyCursesWindow_AttrOn(PyCursesWindowObject *self, PyObject *args)
|
---|
| 560 | {
|
---|
[391] | 561 | long lattr;
|
---|
| 562 | if (!PyArg_ParseTuple(args,"l;attr", &lattr))
|
---|
| 563 | return NULL;
|
---|
| 564 | return PyCursesCheckERR(wattron(self->win, (attr_t)lattr), "attron");
|
---|
[2] | 565 | }
|
---|
| 566 |
|
---|
| 567 | static PyObject *
|
---|
| 568 | PyCursesWindow_AttrSet(PyCursesWindowObject *self, PyObject *args)
|
---|
| 569 | {
|
---|
[391] | 570 | long lattr;
|
---|
| 571 | if (!PyArg_ParseTuple(args,"l;attr", &lattr))
|
---|
| 572 | return NULL;
|
---|
| 573 | return PyCursesCheckERR(wattrset(self->win, (attr_t)lattr), "attrset");
|
---|
[2] | 574 | }
|
---|
| 575 |
|
---|
| 576 | static PyObject *
|
---|
| 577 | PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
|
---|
| 578 | {
|
---|
[391] | 579 | PyObject *temp;
|
---|
| 580 | chtype bkgd;
|
---|
| 581 | attr_t attr = A_NORMAL;
|
---|
| 582 | long lattr;
|
---|
[2] | 583 |
|
---|
[391] | 584 | switch (PyTuple_Size(args)) {
|
---|
[2] | 585 | case 1:
|
---|
[391] | 586 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
|
---|
| 587 | return NULL;
|
---|
| 588 | break;
|
---|
[2] | 589 | case 2:
|
---|
[391] | 590 | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
|
---|
| 591 | return NULL;
|
---|
| 592 | attr = lattr;
|
---|
| 593 | break;
|
---|
| 594 | default:
|
---|
| 595 | PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
|
---|
[2] | 596 | return NULL;
|
---|
[391] | 597 | }
|
---|
[2] | 598 |
|
---|
[391] | 599 | if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
|
---|
| 600 | PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
|
---|
| 601 | return NULL;
|
---|
| 602 | }
|
---|
[2] | 603 |
|
---|
[391] | 604 | wbkgdset(self->win, bkgd | attr);
|
---|
| 605 | return PyCursesCheckERR(0, "bkgdset");
|
---|
[2] | 606 | }
|
---|
| 607 |
|
---|
| 608 | static PyObject *
|
---|
| 609 | PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args)
|
---|
| 610 | {
|
---|
[391] | 611 | PyObject *temp[8];
|
---|
| 612 | chtype ch[8];
|
---|
| 613 | int i;
|
---|
[2] | 614 |
|
---|
[391] | 615 | /* Clear the array of parameters */
|
---|
| 616 | for(i=0; i<8; i++) {
|
---|
| 617 | temp[i] = NULL;
|
---|
| 618 | ch[i] = 0;
|
---|
| 619 | }
|
---|
[2] | 620 |
|
---|
[391] | 621 | if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
|
---|
| 622 | &temp[0], &temp[1], &temp[2], &temp[3],
|
---|
| 623 | &temp[4], &temp[5], &temp[6], &temp[7]))
|
---|
| 624 | return NULL;
|
---|
| 625 |
|
---|
| 626 | for(i=0; i<8; i++) {
|
---|
| 627 | if (temp[i] != NULL && !PyCurses_ConvertToChtype(temp[i], &ch[i])) {
|
---|
| 628 | PyErr_Format(PyExc_TypeError,
|
---|
| 629 | "argument %i must be a ch or an int", i+1);
|
---|
| 630 | return NULL;
|
---|
| 631 | }
|
---|
| 632 | }
|
---|
| 633 |
|
---|
| 634 | wborder(self->win,
|
---|
| 635 | ch[0], ch[1], ch[2], ch[3],
|
---|
| 636 | ch[4], ch[5], ch[6], ch[7]);
|
---|
| 637 | Py_INCREF(Py_None);
|
---|
| 638 | return Py_None;
|
---|
[2] | 639 | }
|
---|
| 640 |
|
---|
| 641 | static PyObject *
|
---|
| 642 | PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args)
|
---|
| 643 | {
|
---|
[391] | 644 | chtype ch1=0,ch2=0;
|
---|
| 645 | switch(PyTuple_Size(args)){
|
---|
| 646 | case 0: break;
|
---|
| 647 | default:
|
---|
| 648 | if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2))
|
---|
| 649 | return NULL;
|
---|
| 650 | }
|
---|
| 651 | box(self->win,ch1,ch2);
|
---|
| 652 | Py_INCREF(Py_None);
|
---|
| 653 | return Py_None;
|
---|
[2] | 654 | }
|
---|
| 655 |
|
---|
| 656 | #if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
|
---|
| 657 | #define py_mvwdelch mvwdelch
|
---|
| 658 | #else
|
---|
| 659 | int py_mvwdelch(WINDOW *w, int y, int x)
|
---|
| 660 | {
|
---|
[391] | 661 | mvwdelch(w,y,x);
|
---|
| 662 | /* On HP/UX, mvwdelch already returns. On other systems,
|
---|
| 663 | we may well run into this return statement. */
|
---|
| 664 | return 0;
|
---|
[2] | 665 | }
|
---|
| 666 | #endif
|
---|
| 667 |
|
---|
| 668 | /* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */
|
---|
| 669 |
|
---|
| 670 | static PyObject *
|
---|
| 671 | PyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args)
|
---|
| 672 | {
|
---|
[391] | 673 | int rtn;
|
---|
| 674 | int x, y;
|
---|
| 675 | int num = -1;
|
---|
| 676 | short color;
|
---|
| 677 | attr_t attr = A_NORMAL;
|
---|
| 678 | long lattr;
|
---|
| 679 | int use_xy = FALSE;
|
---|
[2] | 680 |
|
---|
[391] | 681 | switch (PyTuple_Size(args)) {
|
---|
| 682 | case 1:
|
---|
| 683 | if (!PyArg_ParseTuple(args,"l;attr", &lattr))
|
---|
| 684 | return NULL;
|
---|
| 685 | attr = lattr;
|
---|
| 686 | break;
|
---|
| 687 | case 2:
|
---|
| 688 | if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr))
|
---|
| 689 | return NULL;
|
---|
| 690 | attr = lattr;
|
---|
| 691 | break;
|
---|
| 692 | case 3:
|
---|
| 693 | if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr))
|
---|
| 694 | return NULL;
|
---|
| 695 | attr = lattr;
|
---|
| 696 | use_xy = TRUE;
|
---|
| 697 | break;
|
---|
| 698 | case 4:
|
---|
| 699 | if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr))
|
---|
| 700 | return NULL;
|
---|
| 701 | attr = lattr;
|
---|
| 702 | use_xy = TRUE;
|
---|
| 703 | break;
|
---|
| 704 | default:
|
---|
| 705 | PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments");
|
---|
| 706 | return NULL;
|
---|
| 707 | }
|
---|
[2] | 708 |
|
---|
[391] | 709 | color = (short)((attr >> 8) & 0xff);
|
---|
| 710 | attr = attr - (color << 8);
|
---|
[2] | 711 |
|
---|
[391] | 712 | if (use_xy == TRUE) {
|
---|
| 713 | rtn = mvwchgat(self->win,y,x,num,attr,color,NULL);
|
---|
| 714 | touchline(self->win,y,1);
|
---|
| 715 | } else {
|
---|
| 716 | getyx(self->win,y,x);
|
---|
| 717 | rtn = wchgat(self->win,num,attr,color,NULL);
|
---|
| 718 | touchline(self->win,y,1);
|
---|
| 719 | }
|
---|
| 720 | return PyCursesCheckERR(rtn, "chgat");
|
---|
[2] | 721 | }
|
---|
| 722 |
|
---|
| 723 |
|
---|
| 724 | static PyObject *
|
---|
| 725 | PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args)
|
---|
| 726 | {
|
---|
[391] | 727 | int rtn;
|
---|
| 728 | int x, y;
|
---|
[2] | 729 |
|
---|
[391] | 730 | switch (PyTuple_Size(args)) {
|
---|
| 731 | case 0:
|
---|
| 732 | rtn = wdelch(self->win);
|
---|
| 733 | break;
|
---|
| 734 | case 2:
|
---|
| 735 | if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
|
---|
| 736 | return NULL;
|
---|
| 737 | rtn = py_mvwdelch(self->win,y,x);
|
---|
| 738 | break;
|
---|
| 739 | default:
|
---|
| 740 | PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
|
---|
| 741 | return NULL;
|
---|
| 742 | }
|
---|
| 743 | return PyCursesCheckERR(rtn, "[mv]wdelch");
|
---|
[2] | 744 | }
|
---|
| 745 |
|
---|
| 746 | static PyObject *
|
---|
| 747 | PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
|
---|
| 748 | {
|
---|
[391] | 749 | WINDOW *win;
|
---|
| 750 | int nlines, ncols, begin_y, begin_x;
|
---|
[2] | 751 |
|
---|
[391] | 752 | nlines = 0;
|
---|
| 753 | ncols = 0;
|
---|
| 754 | switch (PyTuple_Size(args)) {
|
---|
| 755 | case 2:
|
---|
| 756 | if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
|
---|
| 757 | return NULL;
|
---|
| 758 | break;
|
---|
| 759 | case 4:
|
---|
| 760 | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
|
---|
| 761 | &nlines,&ncols,&begin_y,&begin_x))
|
---|
| 762 | return NULL;
|
---|
| 763 | break;
|
---|
| 764 | default:
|
---|
| 765 | PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
|
---|
| 766 | return NULL;
|
---|
| 767 | }
|
---|
[2] | 768 |
|
---|
[391] | 769 | win = derwin(self->win,nlines,ncols,begin_y,begin_x);
|
---|
[2] | 770 |
|
---|
[391] | 771 | if (win == NULL) {
|
---|
| 772 | PyErr_SetString(PyCursesError, catchall_NULL);
|
---|
| 773 | return NULL;
|
---|
| 774 | }
|
---|
[2] | 775 |
|
---|
[391] | 776 | return (PyObject *)PyCursesWindow_New(win);
|
---|
[2] | 777 | }
|
---|
| 778 |
|
---|
| 779 | static PyObject *
|
---|
| 780 | PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
|
---|
| 781 | {
|
---|
[391] | 782 | PyObject *temp;
|
---|
| 783 | chtype ch;
|
---|
| 784 | attr_t attr = A_NORMAL;
|
---|
| 785 | long lattr;
|
---|
[2] | 786 |
|
---|
[391] | 787 | switch (PyTuple_Size(args)) {
|
---|
| 788 | case 1:
|
---|
| 789 | if (!PyArg_ParseTuple(args,"O;ch or int", &temp))
|
---|
| 790 | return NULL;
|
---|
| 791 | break;
|
---|
| 792 | case 2:
|
---|
| 793 | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
|
---|
| 794 | return NULL;
|
---|
| 795 | attr = lattr;
|
---|
| 796 | break;
|
---|
| 797 | default:
|
---|
| 798 | PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
|
---|
[2] | 799 |
|
---|
| 800 |
|
---|
[391] | 801 | return NULL;
|
---|
| 802 | }
|
---|
[2] | 803 |
|
---|
[391] | 804 | if (!PyCurses_ConvertToChtype(temp, &ch)) {
|
---|
| 805 | PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
|
---|
| 806 | return NULL;
|
---|
| 807 | }
|
---|
| 808 |
|
---|
[2] | 809 | #ifdef WINDOW_HAS_FLAGS
|
---|
[391] | 810 | if (self->win->_flags & _ISPAD)
|
---|
| 811 | return PyCursesCheckERR(pechochar(self->win, ch | attr),
|
---|
| 812 | "echochar");
|
---|
| 813 | else
|
---|
[2] | 814 | #endif
|
---|
[391] | 815 | return PyCursesCheckERR(wechochar(self->win, ch | attr),
|
---|
| 816 | "echochar");
|
---|
[2] | 817 | }
|
---|
| 818 |
|
---|
| 819 | #ifdef NCURSES_MOUSE_VERSION
|
---|
| 820 | static PyObject *
|
---|
| 821 | PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
|
---|
| 822 | {
|
---|
[391] | 823 | int x, y;
|
---|
| 824 | if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
|
---|
| 825 | return NULL;
|
---|
[2] | 826 |
|
---|
[391] | 827 | return PyInt_FromLong( wenclose(self->win,y,x) );
|
---|
[2] | 828 | }
|
---|
| 829 | #endif
|
---|
| 830 |
|
---|
| 831 | static PyObject *
|
---|
| 832 | PyCursesWindow_GetBkgd(PyCursesWindowObject *self)
|
---|
| 833 | {
|
---|
[391] | 834 | return PyInt_FromLong((long) getbkgd(self->win));
|
---|
[2] | 835 | }
|
---|
| 836 |
|
---|
| 837 | static PyObject *
|
---|
| 838 | PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args)
|
---|
| 839 | {
|
---|
[391] | 840 | int x, y;
|
---|
| 841 | int rtn;
|
---|
[2] | 842 |
|
---|
[391] | 843 | switch (PyTuple_Size(args)) {
|
---|
| 844 | case 0:
|
---|
| 845 | Py_BEGIN_ALLOW_THREADS
|
---|
| 846 | rtn = wgetch(self->win);
|
---|
| 847 | Py_END_ALLOW_THREADS
|
---|
| 848 | break;
|
---|
| 849 | case 2:
|
---|
| 850 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
|
---|
| 851 | return NULL;
|
---|
| 852 | Py_BEGIN_ALLOW_THREADS
|
---|
| 853 | rtn = mvwgetch(self->win,y,x);
|
---|
| 854 | Py_END_ALLOW_THREADS
|
---|
| 855 | break;
|
---|
| 856 | default:
|
---|
| 857 | PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
|
---|
| 858 | return NULL;
|
---|
| 859 | }
|
---|
| 860 | return PyInt_FromLong((long)rtn);
|
---|
[2] | 861 | }
|
---|
| 862 |
|
---|
| 863 | static PyObject *
|
---|
| 864 | PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
|
---|
| 865 | {
|
---|
[391] | 866 | int x, y;
|
---|
| 867 | int rtn;
|
---|
[2] | 868 |
|
---|
[391] | 869 | switch (PyTuple_Size(args)) {
|
---|
| 870 | case 0:
|
---|
| 871 | Py_BEGIN_ALLOW_THREADS
|
---|
| 872 | rtn = wgetch(self->win);
|
---|
| 873 | Py_END_ALLOW_THREADS
|
---|
| 874 | break;
|
---|
| 875 | case 2:
|
---|
| 876 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
|
---|
| 877 | return NULL;
|
---|
| 878 | Py_BEGIN_ALLOW_THREADS
|
---|
| 879 | rtn = mvwgetch(self->win,y,x);
|
---|
| 880 | Py_END_ALLOW_THREADS
|
---|
| 881 | break;
|
---|
| 882 | default:
|
---|
| 883 | PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
|
---|
| 884 | return NULL;
|
---|
| 885 | }
|
---|
| 886 | if (rtn == ERR) {
|
---|
| 887 | /* getch() returns ERR in nodelay mode */
|
---|
| 888 | PyErr_CheckSignals();
|
---|
| 889 | if (!PyErr_Occurred())
|
---|
| 890 | PyErr_SetString(PyCursesError, "no input");
|
---|
| 891 | return NULL;
|
---|
| 892 | } else if (rtn<=255) {
|
---|
| 893 | return Py_BuildValue("c", rtn);
|
---|
| 894 | } else {
|
---|
| 895 | const char *knp;
|
---|
[2] | 896 | #if defined(__NetBSD__)
|
---|
[391] | 897 | knp = unctrl(rtn);
|
---|
[2] | 898 | #else
|
---|
[391] | 899 | knp = keyname(rtn);
|
---|
[2] | 900 | #endif
|
---|
[391] | 901 | return PyString_FromString((knp == NULL) ? "" : knp);
|
---|
| 902 | }
|
---|
[2] | 903 | }
|
---|
| 904 |
|
---|
| 905 | static PyObject *
|
---|
| 906 | PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
|
---|
| 907 | {
|
---|
[391] | 908 | int x, y, n;
|
---|
| 909 | char rtn[1024]; /* This should be big enough.. I hope */
|
---|
| 910 | int rtn2;
|
---|
[2] | 911 |
|
---|
[391] | 912 | switch (PyTuple_Size(args)) {
|
---|
| 913 | case 0:
|
---|
| 914 | Py_BEGIN_ALLOW_THREADS
|
---|
| 915 | rtn2 = wgetnstr(self->win,rtn, 1023);
|
---|
| 916 | Py_END_ALLOW_THREADS
|
---|
| 917 | break;
|
---|
| 918 | case 1:
|
---|
| 919 | if (!PyArg_ParseTuple(args,"i;n", &n))
|
---|
| 920 | return NULL;
|
---|
| 921 | Py_BEGIN_ALLOW_THREADS
|
---|
| 922 | rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023));
|
---|
| 923 | Py_END_ALLOW_THREADS
|
---|
| 924 | break;
|
---|
| 925 | case 2:
|
---|
| 926 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
|
---|
| 927 | return NULL;
|
---|
| 928 | Py_BEGIN_ALLOW_THREADS
|
---|
[2] | 929 | #ifdef STRICT_SYSV_CURSES
|
---|
[391] | 930 | rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);
|
---|
[2] | 931 | #else
|
---|
[391] | 932 | rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023);
|
---|
[2] | 933 | #endif
|
---|
[391] | 934 | Py_END_ALLOW_THREADS
|
---|
| 935 | break;
|
---|
| 936 | case 3:
|
---|
| 937 | if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
|
---|
| 938 | return NULL;
|
---|
[2] | 939 | #ifdef STRICT_SYSV_CURSES
|
---|
[391] | 940 | Py_BEGIN_ALLOW_THREADS
|
---|
| 941 | rtn2 = wmove(self->win,y,x)==ERR ? ERR :
|
---|
| 942 | wgetnstr(self->win, rtn, MIN(n, 1023));
|
---|
| 943 | Py_END_ALLOW_THREADS
|
---|
[2] | 944 | #else
|
---|
[391] | 945 | Py_BEGIN_ALLOW_THREADS
|
---|
| 946 | rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023));
|
---|
| 947 | Py_END_ALLOW_THREADS
|
---|
[2] | 948 | #endif
|
---|
[391] | 949 | break;
|
---|
| 950 | default:
|
---|
| 951 | PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
|
---|
| 952 | return NULL;
|
---|
| 953 | }
|
---|
| 954 | if (rtn2 == ERR)
|
---|
| 955 | rtn[0] = 0;
|
---|
| 956 | return PyString_FromString(rtn);
|
---|
[2] | 957 | }
|
---|
| 958 |
|
---|
| 959 | static PyObject *
|
---|
| 960 | PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args)
|
---|
| 961 | {
|
---|
[391] | 962 | PyObject *temp;
|
---|
| 963 | chtype ch;
|
---|
| 964 | int n, x, y, code = OK;
|
---|
| 965 | attr_t attr = A_NORMAL;
|
---|
| 966 | long lattr;
|
---|
[2] | 967 |
|
---|
[391] | 968 | switch (PyTuple_Size(args)) {
|
---|
| 969 | case 2:
|
---|
| 970 | if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
|
---|
| 971 | return NULL;
|
---|
| 972 | break;
|
---|
| 973 | case 3:
|
---|
| 974 | if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
|
---|
| 975 | return NULL;
|
---|
| 976 | attr = lattr;
|
---|
| 977 | break;
|
---|
| 978 | case 4:
|
---|
| 979 | if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
|
---|
| 980 | return NULL;
|
---|
| 981 | code = wmove(self->win, y, x);
|
---|
| 982 | break;
|
---|
| 983 | case 5:
|
---|
| 984 | if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
|
---|
| 985 | &y, &x, &temp, &n, &lattr))
|
---|
| 986 | return NULL;
|
---|
| 987 | attr = lattr;
|
---|
| 988 | code = wmove(self->win, y, x);
|
---|
| 989 | break;
|
---|
| 990 | default:
|
---|
| 991 | PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments");
|
---|
| 992 | return NULL;
|
---|
| 993 | }
|
---|
[2] | 994 |
|
---|
[391] | 995 | if (code != ERR) {
|
---|
| 996 | if (!PyCurses_ConvertToChtype(temp, &ch)) {
|
---|
| 997 | PyErr_SetString(PyExc_TypeError,
|
---|
| 998 | "argument 1 or 3 must be a ch or an int");
|
---|
| 999 | return NULL;
|
---|
| 1000 | }
|
---|
| 1001 | return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
|
---|
| 1002 | } else
|
---|
| 1003 | return PyCursesCheckERR(code, "wmove");
|
---|
[2] | 1004 | }
|
---|
| 1005 |
|
---|
| 1006 | static PyObject *
|
---|
| 1007 | PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1008 | {
|
---|
[391] | 1009 | int rtn, x, y, use_xy = FALSE;
|
---|
| 1010 | PyObject *temp;
|
---|
| 1011 | chtype ch = 0;
|
---|
| 1012 | attr_t attr = A_NORMAL;
|
---|
| 1013 | long lattr;
|
---|
[2] | 1014 |
|
---|
[391] | 1015 | switch (PyTuple_Size(args)) {
|
---|
| 1016 | case 1:
|
---|
| 1017 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
|
---|
| 1018 | return NULL;
|
---|
| 1019 | break;
|
---|
| 1020 | case 2:
|
---|
| 1021 | if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
|
---|
| 1022 | return NULL;
|
---|
| 1023 | attr = lattr;
|
---|
| 1024 | break;
|
---|
| 1025 | case 3:
|
---|
| 1026 | if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
|
---|
| 1027 | return NULL;
|
---|
| 1028 | use_xy = TRUE;
|
---|
| 1029 | break;
|
---|
| 1030 | case 4:
|
---|
| 1031 | if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &lattr))
|
---|
| 1032 | return NULL;
|
---|
| 1033 | attr = lattr;
|
---|
| 1034 | use_xy = TRUE;
|
---|
| 1035 | break;
|
---|
| 1036 | default:
|
---|
| 1037 | PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
|
---|
| 1038 | return NULL;
|
---|
| 1039 | }
|
---|
| 1040 |
|
---|
| 1041 | if (!PyCurses_ConvertToChtype(temp, &ch)) {
|
---|
| 1042 | PyErr_SetString(PyExc_TypeError,
|
---|
| 1043 | "argument 1 or 3 must be a ch or an int");
|
---|
| 1044 | return NULL;
|
---|
| 1045 | }
|
---|
| 1046 |
|
---|
| 1047 | if (use_xy == TRUE)
|
---|
| 1048 | rtn = mvwinsch(self->win,y,x, ch | attr);
|
---|
| 1049 | else {
|
---|
| 1050 | rtn = winsch(self->win, ch | attr);
|
---|
| 1051 | }
|
---|
| 1052 | return PyCursesCheckERR(rtn, "insch");
|
---|
[2] | 1053 | }
|
---|
| 1054 |
|
---|
| 1055 | static PyObject *
|
---|
| 1056 | PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1057 | {
|
---|
[391] | 1058 | int x, y, rtn;
|
---|
[2] | 1059 |
|
---|
[391] | 1060 | switch (PyTuple_Size(args)) {
|
---|
| 1061 | case 0:
|
---|
| 1062 | rtn = winch(self->win);
|
---|
| 1063 | break;
|
---|
| 1064 | case 2:
|
---|
| 1065 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
|
---|
| 1066 | return NULL;
|
---|
| 1067 | rtn = mvwinch(self->win,y,x);
|
---|
| 1068 | break;
|
---|
| 1069 | default:
|
---|
| 1070 | PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
|
---|
| 1071 | return NULL;
|
---|
| 1072 | }
|
---|
| 1073 | return PyInt_FromLong((long) rtn);
|
---|
[2] | 1074 | }
|
---|
| 1075 |
|
---|
| 1076 | static PyObject *
|
---|
| 1077 | PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1078 | {
|
---|
[391] | 1079 | int x, y, n;
|
---|
| 1080 | char rtn[1024]; /* This should be big enough.. I hope */
|
---|
| 1081 | int rtn2;
|
---|
[2] | 1082 |
|
---|
[391] | 1083 | switch (PyTuple_Size(args)) {
|
---|
| 1084 | case 0:
|
---|
| 1085 | rtn2 = winnstr(self->win,rtn, 1023);
|
---|
| 1086 | break;
|
---|
| 1087 | case 1:
|
---|
| 1088 | if (!PyArg_ParseTuple(args,"i;n", &n))
|
---|
| 1089 | return NULL;
|
---|
| 1090 | rtn2 = winnstr(self->win,rtn,MIN(n,1023));
|
---|
| 1091 | break;
|
---|
| 1092 | case 2:
|
---|
| 1093 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
|
---|
| 1094 | return NULL;
|
---|
| 1095 | rtn2 = mvwinnstr(self->win,y,x,rtn,1023);
|
---|
| 1096 | break;
|
---|
| 1097 | case 3:
|
---|
| 1098 | if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
|
---|
| 1099 | return NULL;
|
---|
| 1100 | rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023));
|
---|
| 1101 | break;
|
---|
| 1102 | default:
|
---|
| 1103 | PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
|
---|
| 1104 | return NULL;
|
---|
| 1105 | }
|
---|
| 1106 | if (rtn2 == ERR)
|
---|
| 1107 | rtn[0] = 0;
|
---|
| 1108 | return PyString_FromString(rtn);
|
---|
[2] | 1109 | }
|
---|
| 1110 |
|
---|
| 1111 | static PyObject *
|
---|
| 1112 | PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1113 | {
|
---|
[391] | 1114 | int rtn;
|
---|
| 1115 | int x, y;
|
---|
| 1116 | char *str;
|
---|
| 1117 | attr_t attr = A_NORMAL , attr_old = A_NORMAL;
|
---|
| 1118 | long lattr;
|
---|
| 1119 | int use_xy = FALSE, use_attr = FALSE;
|
---|
[2] | 1120 |
|
---|
[391] | 1121 | switch (PyTuple_Size(args)) {
|
---|
| 1122 | case 1:
|
---|
| 1123 | if (!PyArg_ParseTuple(args,"s;str", &str))
|
---|
| 1124 | return NULL;
|
---|
| 1125 | break;
|
---|
| 1126 | case 2:
|
---|
| 1127 | if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
|
---|
| 1128 | return NULL;
|
---|
| 1129 | attr = lattr;
|
---|
| 1130 | use_attr = TRUE;
|
---|
| 1131 | break;
|
---|
| 1132 | case 3:
|
---|
| 1133 | if (!PyArg_ParseTuple(args,"iis;y,x,str", &y, &x, &str))
|
---|
| 1134 | return NULL;
|
---|
| 1135 | use_xy = TRUE;
|
---|
| 1136 | break;
|
---|
| 1137 | case 4:
|
---|
| 1138 | if (!PyArg_ParseTuple(args,"iisl;y,x,str,attr", &y, &x, &str, &lattr))
|
---|
| 1139 | return NULL;
|
---|
| 1140 | attr = lattr;
|
---|
| 1141 | use_xy = use_attr = TRUE;
|
---|
| 1142 | break;
|
---|
| 1143 | default:
|
---|
| 1144 | PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
|
---|
| 1145 | return NULL;
|
---|
| 1146 | }
|
---|
[2] | 1147 |
|
---|
[391] | 1148 | if (use_attr == TRUE) {
|
---|
| 1149 | attr_old = getattrs(self->win);
|
---|
| 1150 | (void)wattrset(self->win,attr);
|
---|
| 1151 | }
|
---|
| 1152 | if (use_xy == TRUE)
|
---|
| 1153 | rtn = mvwinsstr(self->win,y,x,str);
|
---|
| 1154 | else
|
---|
| 1155 | rtn = winsstr(self->win,str);
|
---|
| 1156 | if (use_attr == TRUE)
|
---|
| 1157 | (void)wattrset(self->win,attr_old);
|
---|
| 1158 | return PyCursesCheckERR(rtn, "insstr");
|
---|
[2] | 1159 | }
|
---|
| 1160 |
|
---|
| 1161 | static PyObject *
|
---|
| 1162 | PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1163 | {
|
---|
[391] | 1164 | int rtn, x, y, n;
|
---|
| 1165 | char *str;
|
---|
| 1166 | attr_t attr = A_NORMAL , attr_old = A_NORMAL;
|
---|
| 1167 | long lattr;
|
---|
| 1168 | int use_xy = FALSE, use_attr = FALSE;
|
---|
[2] | 1169 |
|
---|
[391] | 1170 | switch (PyTuple_Size(args)) {
|
---|
| 1171 | case 2:
|
---|
| 1172 | if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
|
---|
| 1173 | return NULL;
|
---|
| 1174 | break;
|
---|
| 1175 | case 3:
|
---|
| 1176 | if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
|
---|
| 1177 | return NULL;
|
---|
| 1178 | attr = lattr;
|
---|
| 1179 | use_attr = TRUE;
|
---|
| 1180 | break;
|
---|
| 1181 | case 4:
|
---|
| 1182 | if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
|
---|
| 1183 | return NULL;
|
---|
| 1184 | use_xy = TRUE;
|
---|
| 1185 | break;
|
---|
| 1186 | case 5:
|
---|
| 1187 | if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
|
---|
| 1188 | return NULL;
|
---|
| 1189 | attr = lattr;
|
---|
| 1190 | use_xy = use_attr = TRUE;
|
---|
| 1191 | break;
|
---|
| 1192 | default:
|
---|
| 1193 | PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
|
---|
| 1194 | return NULL;
|
---|
| 1195 | }
|
---|
[2] | 1196 |
|
---|
[391] | 1197 | if (use_attr == TRUE) {
|
---|
| 1198 | attr_old = getattrs(self->win);
|
---|
| 1199 | (void)wattrset(self->win,attr);
|
---|
| 1200 | }
|
---|
| 1201 | if (use_xy == TRUE)
|
---|
| 1202 | rtn = mvwinsnstr(self->win,y,x,str,n);
|
---|
| 1203 | else
|
---|
| 1204 | rtn = winsnstr(self->win,str,n);
|
---|
| 1205 | if (use_attr == TRUE)
|
---|
| 1206 | (void)wattrset(self->win,attr_old);
|
---|
| 1207 | return PyCursesCheckERR(rtn, "insnstr");
|
---|
[2] | 1208 | }
|
---|
| 1209 |
|
---|
| 1210 | static PyObject *
|
---|
| 1211 | PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1212 | {
|
---|
[391] | 1213 | int line, erg;
|
---|
| 1214 | if (!PyArg_ParseTuple(args,"i;line", &line))
|
---|
| 1215 | return NULL;
|
---|
| 1216 | erg = is_linetouched(self->win, line);
|
---|
| 1217 | if (erg == ERR) {
|
---|
| 1218 | PyErr_SetString(PyExc_TypeError,
|
---|
| 1219 | "is_linetouched: line number outside of boundaries");
|
---|
| 1220 | return NULL;
|
---|
| 1221 | } else
|
---|
| 1222 | if (erg == FALSE) {
|
---|
| 1223 | Py_INCREF(Py_False);
|
---|
| 1224 | return Py_False;
|
---|
| 1225 | } else {
|
---|
| 1226 | Py_INCREF(Py_True);
|
---|
| 1227 | return Py_True;
|
---|
| 1228 | }
|
---|
[2] | 1229 | }
|
---|
| 1230 |
|
---|
| 1231 | static PyObject *
|
---|
| 1232 | PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1233 | {
|
---|
[391] | 1234 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
|
---|
| 1235 | int rtn;
|
---|
[2] | 1236 |
|
---|
| 1237 | #ifndef WINDOW_HAS_FLAGS
|
---|
[391] | 1238 | if (0)
|
---|
[2] | 1239 | #else
|
---|
[391] | 1240 | if (self->win->_flags & _ISPAD)
|
---|
[2] | 1241 | #endif
|
---|
[391] | 1242 | {
|
---|
| 1243 | switch(PyTuple_Size(args)) {
|
---|
| 1244 | case 6:
|
---|
| 1245 | if (!PyArg_ParseTuple(args,
|
---|
| 1246 | "iiiiii;" \
|
---|
| 1247 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
|
---|
| 1248 | &pminrow, &pmincol, &sminrow,
|
---|
| 1249 | &smincol, &smaxrow, &smaxcol))
|
---|
| 1250 | return NULL;
|
---|
| 1251 | Py_BEGIN_ALLOW_THREADS
|
---|
| 1252 | rtn = pnoutrefresh(self->win,
|
---|
| 1253 | pminrow, pmincol, sminrow,
|
---|
| 1254 | smincol, smaxrow, smaxcol);
|
---|
| 1255 | Py_END_ALLOW_THREADS
|
---|
| 1256 | return PyCursesCheckERR(rtn, "pnoutrefresh");
|
---|
| 1257 | default:
|
---|
| 1258 | PyErr_SetString(PyCursesError,
|
---|
| 1259 | "noutrefresh() called for a pad "
|
---|
| 1260 | "requires 6 arguments");
|
---|
| 1261 | return NULL;
|
---|
| 1262 | }
|
---|
| 1263 | } else {
|
---|
| 1264 | if (!PyArg_ParseTuple(args, ":noutrefresh"))
|
---|
| 1265 | return NULL;
|
---|
[2] | 1266 |
|
---|
[391] | 1267 | Py_BEGIN_ALLOW_THREADS
|
---|
| 1268 | rtn = wnoutrefresh(self->win);
|
---|
| 1269 | Py_END_ALLOW_THREADS
|
---|
| 1270 | return PyCursesCheckERR(rtn, "wnoutrefresh");
|
---|
| 1271 | }
|
---|
[2] | 1272 | }
|
---|
| 1273 |
|
---|
| 1274 | static PyObject *
|
---|
| 1275 | PyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1276 | {
|
---|
| 1277 | PyCursesWindowObject *temp;
|
---|
| 1278 | int use_copywin = FALSE;
|
---|
| 1279 | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
|
---|
| 1280 | int rtn;
|
---|
[391] | 1281 |
|
---|
[2] | 1282 | switch (PyTuple_Size(args)) {
|
---|
| 1283 | case 1:
|
---|
[391] | 1284 | if (!PyArg_ParseTuple(args, "O!;window object",
|
---|
| 1285 | &PyCursesWindow_Type, &temp))
|
---|
| 1286 | return NULL;
|
---|
| 1287 | break;
|
---|
[2] | 1288 | case 7:
|
---|
[391] | 1289 | if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
|
---|
| 1290 | &PyCursesWindow_Type, &temp, &sminrow, &smincol,
|
---|
| 1291 | &dminrow, &dmincol, &dmaxrow, &dmaxcol))
|
---|
| 1292 | return NULL;
|
---|
| 1293 | use_copywin = TRUE;
|
---|
| 1294 | break;
|
---|
[2] | 1295 | default:
|
---|
[391] | 1296 | PyErr_SetString(PyExc_TypeError,
|
---|
| 1297 | "overlay requires one or seven arguments");
|
---|
| 1298 | return NULL;
|
---|
[2] | 1299 | }
|
---|
| 1300 |
|
---|
| 1301 | if (use_copywin == TRUE) {
|
---|
[391] | 1302 | rtn = copywin(self->win, temp->win, sminrow, smincol,
|
---|
| 1303 | dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
|
---|
| 1304 | return PyCursesCheckERR(rtn, "copywin");
|
---|
[2] | 1305 | }
|
---|
| 1306 | else {
|
---|
[391] | 1307 | rtn = overlay(self->win, temp->win);
|
---|
| 1308 | return PyCursesCheckERR(rtn, "overlay");
|
---|
[2] | 1309 | }
|
---|
| 1310 | }
|
---|
| 1311 |
|
---|
| 1312 | static PyObject *
|
---|
| 1313 | PyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1314 | {
|
---|
| 1315 | PyCursesWindowObject *temp;
|
---|
| 1316 | int use_copywin = FALSE;
|
---|
| 1317 | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
|
---|
| 1318 | int rtn;
|
---|
[391] | 1319 |
|
---|
[2] | 1320 | switch (PyTuple_Size(args)) {
|
---|
| 1321 | case 1:
|
---|
[391] | 1322 | if (!PyArg_ParseTuple(args, "O!;window object",
|
---|
| 1323 | &PyCursesWindow_Type, &temp))
|
---|
| 1324 | return NULL;
|
---|
| 1325 | break;
|
---|
[2] | 1326 | case 7:
|
---|
[391] | 1327 | if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
|
---|
| 1328 | &PyCursesWindow_Type, &temp, &sminrow, &smincol,
|
---|
| 1329 | &dminrow, &dmincol, &dmaxrow, &dmaxcol))
|
---|
| 1330 | return NULL;
|
---|
| 1331 | use_copywin = TRUE;
|
---|
| 1332 | break;
|
---|
[2] | 1333 | default:
|
---|
[391] | 1334 | PyErr_SetString(PyExc_TypeError,
|
---|
| 1335 | "overwrite requires one or seven arguments");
|
---|
| 1336 | return NULL;
|
---|
[2] | 1337 | }
|
---|
| 1338 |
|
---|
| 1339 | if (use_copywin == TRUE) {
|
---|
[391] | 1340 | rtn = copywin(self->win, temp->win, sminrow, smincol,
|
---|
| 1341 | dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
|
---|
[2] | 1342 | return PyCursesCheckERR(rtn, "copywin");
|
---|
| 1343 | }
|
---|
| 1344 | else {
|
---|
[391] | 1345 | rtn = overwrite(self->win, temp->win);
|
---|
| 1346 | return PyCursesCheckERR(rtn, "overwrite");
|
---|
[2] | 1347 | }
|
---|
| 1348 | }
|
---|
| 1349 |
|
---|
| 1350 | static PyObject *
|
---|
| 1351 | PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1352 | {
|
---|
[391] | 1353 | PyObject *temp;
|
---|
| 1354 |
|
---|
| 1355 | if (!PyArg_ParseTuple(args, "O;fileobj", &temp))
|
---|
| 1356 | return NULL;
|
---|
| 1357 | if (!PyFile_Check(temp)) {
|
---|
| 1358 | PyErr_SetString(PyExc_TypeError, "argument must be a file object");
|
---|
| 1359 | return NULL;
|
---|
| 1360 | }
|
---|
| 1361 | return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)),
|
---|
| 1362 | "putwin");
|
---|
[2] | 1363 | }
|
---|
| 1364 |
|
---|
| 1365 | static PyObject *
|
---|
| 1366 | PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1367 | {
|
---|
[391] | 1368 | int beg, num;
|
---|
| 1369 | if (!PyArg_ParseTuple(args, "ii;beg,num", &beg, &num))
|
---|
| 1370 | return NULL;
|
---|
| 1371 | return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
|
---|
[2] | 1372 | }
|
---|
| 1373 |
|
---|
| 1374 | static PyObject *
|
---|
| 1375 | PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1376 | {
|
---|
[391] | 1377 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
|
---|
| 1378 | int rtn;
|
---|
| 1379 |
|
---|
[2] | 1380 | #ifndef WINDOW_HAS_FLAGS
|
---|
[391] | 1381 | if (0)
|
---|
[2] | 1382 | #else
|
---|
[391] | 1383 | if (self->win->_flags & _ISPAD)
|
---|
[2] | 1384 | #endif
|
---|
[391] | 1385 | {
|
---|
| 1386 | switch(PyTuple_Size(args)) {
|
---|
| 1387 | case 6:
|
---|
| 1388 | if (!PyArg_ParseTuple(args,
|
---|
| 1389 | "iiiiii;" \
|
---|
| 1390 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
|
---|
| 1391 | &pminrow, &pmincol, &sminrow,
|
---|
| 1392 | &smincol, &smaxrow, &smaxcol))
|
---|
| 1393 | return NULL;
|
---|
[2] | 1394 |
|
---|
[391] | 1395 | Py_BEGIN_ALLOW_THREADS
|
---|
| 1396 | rtn = prefresh(self->win,
|
---|
| 1397 | pminrow, pmincol, sminrow,
|
---|
| 1398 | smincol, smaxrow, smaxcol);
|
---|
| 1399 | Py_END_ALLOW_THREADS
|
---|
| 1400 | return PyCursesCheckERR(rtn, "prefresh");
|
---|
| 1401 | default:
|
---|
| 1402 | PyErr_SetString(PyCursesError,
|
---|
| 1403 | "refresh() for a pad requires 6 arguments");
|
---|
| 1404 | return NULL;
|
---|
| 1405 | }
|
---|
| 1406 | } else {
|
---|
| 1407 | if (!PyArg_ParseTuple(args, ":refresh"))
|
---|
| 1408 | return NULL;
|
---|
| 1409 | Py_BEGIN_ALLOW_THREADS
|
---|
| 1410 | rtn = wrefresh(self->win);
|
---|
| 1411 | Py_END_ALLOW_THREADS
|
---|
| 1412 | return PyCursesCheckERR(rtn, "prefresh");
|
---|
| 1413 | }
|
---|
[2] | 1414 | }
|
---|
| 1415 |
|
---|
| 1416 | static PyObject *
|
---|
| 1417 | PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1418 | {
|
---|
[391] | 1419 | int x, y;
|
---|
| 1420 | if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x))
|
---|
| 1421 | return NULL;
|
---|
| 1422 | return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
|
---|
[2] | 1423 | }
|
---|
| 1424 |
|
---|
| 1425 | static PyObject *
|
---|
| 1426 | PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1427 | {
|
---|
[391] | 1428 | WINDOW *win;
|
---|
| 1429 | int nlines, ncols, begin_y, begin_x;
|
---|
[2] | 1430 |
|
---|
[391] | 1431 | nlines = 0;
|
---|
| 1432 | ncols = 0;
|
---|
| 1433 | switch (PyTuple_Size(args)) {
|
---|
| 1434 | case 2:
|
---|
| 1435 | if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
|
---|
| 1436 | return NULL;
|
---|
| 1437 | break;
|
---|
| 1438 | case 4:
|
---|
| 1439 | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
|
---|
| 1440 | &nlines,&ncols,&begin_y,&begin_x))
|
---|
| 1441 | return NULL;
|
---|
| 1442 | break;
|
---|
| 1443 | default:
|
---|
| 1444 | PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
|
---|
| 1445 | return NULL;
|
---|
| 1446 | }
|
---|
[2] | 1447 |
|
---|
[391] | 1448 | /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
|
---|
[2] | 1449 | #ifdef WINDOW_HAS_FLAGS
|
---|
[391] | 1450 | if (self->win->_flags & _ISPAD)
|
---|
| 1451 | win = subpad(self->win, nlines, ncols, begin_y, begin_x);
|
---|
| 1452 | else
|
---|
[2] | 1453 | #endif
|
---|
[391] | 1454 | win = subwin(self->win, nlines, ncols, begin_y, begin_x);
|
---|
[2] | 1455 |
|
---|
[391] | 1456 | if (win == NULL) {
|
---|
| 1457 | PyErr_SetString(PyCursesError, catchall_NULL);
|
---|
| 1458 | return NULL;
|
---|
| 1459 | }
|
---|
| 1460 |
|
---|
| 1461 | return (PyObject *)PyCursesWindow_New(win);
|
---|
[2] | 1462 | }
|
---|
| 1463 |
|
---|
| 1464 | static PyObject *
|
---|
| 1465 | PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1466 | {
|
---|
[391] | 1467 | int nlines;
|
---|
| 1468 | switch(PyTuple_Size(args)) {
|
---|
| 1469 | case 0:
|
---|
| 1470 | return PyCursesCheckERR(scroll(self->win), "scroll");
|
---|
| 1471 | case 1:
|
---|
| 1472 | if (!PyArg_ParseTuple(args, "i;nlines", &nlines))
|
---|
| 1473 | return NULL;
|
---|
| 1474 | return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
|
---|
| 1475 | default:
|
---|
| 1476 | PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
|
---|
| 1477 | return NULL;
|
---|
| 1478 | }
|
---|
[2] | 1479 | }
|
---|
| 1480 |
|
---|
| 1481 | static PyObject *
|
---|
| 1482 | PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1483 | {
|
---|
[391] | 1484 | int st, cnt, val;
|
---|
| 1485 | switch (PyTuple_Size(args)) {
|
---|
| 1486 | case 2:
|
---|
| 1487 | if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt))
|
---|
| 1488 | return NULL;
|
---|
| 1489 | return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
|
---|
| 1490 | case 3:
|
---|
| 1491 | if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val))
|
---|
| 1492 | return NULL;
|
---|
| 1493 | return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
|
---|
| 1494 | default:
|
---|
| 1495 | PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
|
---|
| 1496 | return NULL;
|
---|
| 1497 | }
|
---|
[2] | 1498 | }
|
---|
| 1499 |
|
---|
| 1500 | static PyObject *
|
---|
| 1501 | PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args)
|
---|
| 1502 | {
|
---|
[391] | 1503 | PyObject *temp;
|
---|
| 1504 | chtype ch;
|
---|
| 1505 | int n, x, y, code = OK;
|
---|
| 1506 | attr_t attr = A_NORMAL;
|
---|
| 1507 | long lattr;
|
---|
[2] | 1508 |
|
---|
[391] | 1509 | switch (PyTuple_Size(args)) {
|
---|
| 1510 | case 2:
|
---|
| 1511 | if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
|
---|
| 1512 | return NULL;
|
---|
| 1513 | break;
|
---|
| 1514 | case 3:
|
---|
| 1515 | if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
|
---|
| 1516 | return NULL;
|
---|
| 1517 | attr = lattr;
|
---|
| 1518 | break;
|
---|
| 1519 | case 4:
|
---|
| 1520 | if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
|
---|
| 1521 | return NULL;
|
---|
| 1522 | code = wmove(self->win, y, x);
|
---|
| 1523 | break;
|
---|
| 1524 | case 5:
|
---|
| 1525 | if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
|
---|
| 1526 | &y, &x, &temp, &n, &lattr))
|
---|
| 1527 | return NULL;
|
---|
| 1528 | attr = lattr;
|
---|
| 1529 | code = wmove(self->win, y, x);
|
---|
| 1530 | break;
|
---|
| 1531 | default:
|
---|
| 1532 | PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments");
|
---|
| 1533 | return NULL;
|
---|
| 1534 | }
|
---|
[2] | 1535 |
|
---|
[391] | 1536 | if (code != ERR) {
|
---|
| 1537 | if (!PyCurses_ConvertToChtype(temp, &ch)) {
|
---|
| 1538 | PyErr_SetString(PyExc_TypeError,
|
---|
| 1539 | "argument 1 or 3 must be a ch or an int");
|
---|
| 1540 | return NULL;
|
---|
| 1541 | }
|
---|
| 1542 | return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
|
---|
| 1543 | } else
|
---|
| 1544 | return PyCursesCheckERR(code, "wmove");
|
---|
[2] | 1545 | }
|
---|
| 1546 |
|
---|
| 1547 | static PyMethodDef PyCursesWindow_Methods[] = {
|
---|
[391] | 1548 | {"addch", (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS},
|
---|
| 1549 | {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS},
|
---|
| 1550 | {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS},
|
---|
| 1551 | {"attroff", (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS},
|
---|
| 1552 | {"attron", (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS},
|
---|
| 1553 | {"attrset", (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS},
|
---|
| 1554 | {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS},
|
---|
| 1555 | {"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS},
|
---|
| 1556 | {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS},
|
---|
| 1557 | {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
|
---|
| 1558 | {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS},
|
---|
| 1559 | {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS},
|
---|
| 1560 | {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS},
|
---|
| 1561 | {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS},
|
---|
| 1562 | {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS},
|
---|
| 1563 | {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS},
|
---|
| 1564 | {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS},
|
---|
| 1565 | {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS},
|
---|
| 1566 | {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS},
|
---|
| 1567 | {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS},
|
---|
[2] | 1568 | #ifdef NCURSES_MOUSE_VERSION
|
---|
[391] | 1569 | {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS},
|
---|
[2] | 1570 | #endif
|
---|
[391] | 1571 | {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS},
|
---|
| 1572 | {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},
|
---|
| 1573 | {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS},
|
---|
| 1574 | {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS},
|
---|
| 1575 | {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS},
|
---|
| 1576 | {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},
|
---|
| 1577 | {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},
|
---|
| 1578 | {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},
|
---|
| 1579 | {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS},
|
---|
| 1580 | {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS},
|
---|
| 1581 | {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS},
|
---|
| 1582 | {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS},
|
---|
| 1583 | {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS},
|
---|
| 1584 | {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS},
|
---|
| 1585 | {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS},
|
---|
| 1586 | {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS},
|
---|
| 1587 | {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS},
|
---|
| 1588 | {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS},
|
---|
| 1589 | {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS},
|
---|
| 1590 | {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS},
|
---|
| 1591 | {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS},
|
---|
| 1592 | {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS},
|
---|
| 1593 | {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS},
|
---|
| 1594 | {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS},
|
---|
| 1595 | {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS},
|
---|
| 1596 | {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS},
|
---|
| 1597 | {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS},
|
---|
| 1598 | {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS},
|
---|
| 1599 | {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS},
|
---|
| 1600 | {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
|
---|
| 1601 | /* Backward compatibility alias -- remove in Python 2.3 */
|
---|
| 1602 | {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
|
---|
| 1603 | {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS},
|
---|
| 1604 | {"overwrite", (PyCFunction)PyCursesWindow_Overwrite,
|
---|
| 1605 | METH_VARARGS},
|
---|
| 1606 | {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_VARARGS},
|
---|
| 1607 | {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS},
|
---|
| 1608 | {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS},
|
---|
| 1609 | {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS},
|
---|
[2] | 1610 | #ifndef STRICT_SYSV_CURSES
|
---|
[391] | 1611 | {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS},
|
---|
[2] | 1612 | #endif
|
---|
[391] | 1613 | {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS},
|
---|
| 1614 | {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS},
|
---|
| 1615 | {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS},
|
---|
| 1616 | {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS},
|
---|
| 1617 | {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS},
|
---|
| 1618 | {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
|
---|
| 1619 | {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
|
---|
| 1620 | {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS},
|
---|
| 1621 | {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS},
|
---|
| 1622 | {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS},
|
---|
| 1623 | {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS},
|
---|
| 1624 | {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS},
|
---|
| 1625 | {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS},
|
---|
| 1626 | {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS},
|
---|
| 1627 | {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS},
|
---|
| 1628 | {NULL, NULL} /* sentinel */
|
---|
[2] | 1629 | };
|
---|
| 1630 |
|
---|
| 1631 | static PyObject *
|
---|
| 1632 | PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name)
|
---|
| 1633 | {
|
---|
[391] | 1634 | return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
|
---|
[2] | 1635 | }
|
---|
| 1636 |
|
---|
| 1637 | /* -------------------------------------------------------*/
|
---|
| 1638 |
|
---|
| 1639 | PyTypeObject PyCursesWindow_Type = {
|
---|
[391] | 1640 | PyVarObject_HEAD_INIT(NULL, 0)
|
---|
| 1641 | "_curses.curses window", /*tp_name*/
|
---|
| 1642 | sizeof(PyCursesWindowObject), /*tp_basicsize*/
|
---|
| 1643 | 0, /*tp_itemsize*/
|
---|
| 1644 | /* methods */
|
---|
| 1645 | (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
|
---|
| 1646 | 0, /*tp_print*/
|
---|
| 1647 | (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
|
---|
| 1648 | (setattrfunc)0, /*tp_setattr*/
|
---|
| 1649 | 0, /*tp_compare*/
|
---|
| 1650 | 0, /*tp_repr*/
|
---|
| 1651 | 0, /*tp_as_number*/
|
---|
| 1652 | 0, /*tp_as_sequence*/
|
---|
| 1653 | 0, /*tp_as_mapping*/
|
---|
| 1654 | 0, /*tp_hash*/
|
---|
[2] | 1655 | };
|
---|
| 1656 |
|
---|
| 1657 | /*********************************************************************
|
---|
| 1658 | Global Functions
|
---|
| 1659 | **********************************************************************/
|
---|
| 1660 |
|
---|
| 1661 | NoArgNoReturnFunction(beep)
|
---|
| 1662 | NoArgNoReturnFunction(def_prog_mode)
|
---|
| 1663 | NoArgNoReturnFunction(def_shell_mode)
|
---|
| 1664 | NoArgNoReturnFunction(doupdate)
|
---|
| 1665 | NoArgNoReturnFunction(endwin)
|
---|
| 1666 | NoArgNoReturnFunction(flash)
|
---|
| 1667 | NoArgNoReturnFunction(nocbreak)
|
---|
| 1668 | NoArgNoReturnFunction(noecho)
|
---|
| 1669 | NoArgNoReturnFunction(nonl)
|
---|
| 1670 | NoArgNoReturnFunction(noraw)
|
---|
| 1671 | NoArgNoReturnFunction(reset_prog_mode)
|
---|
| 1672 | NoArgNoReturnFunction(reset_shell_mode)
|
---|
| 1673 | NoArgNoReturnFunction(resetty)
|
---|
| 1674 | NoArgNoReturnFunction(savetty)
|
---|
| 1675 |
|
---|
| 1676 | NoArgOrFlagNoReturnFunction(cbreak)
|
---|
| 1677 | NoArgOrFlagNoReturnFunction(echo)
|
---|
| 1678 | NoArgOrFlagNoReturnFunction(nl)
|
---|
| 1679 | NoArgOrFlagNoReturnFunction(raw)
|
---|
| 1680 |
|
---|
| 1681 | NoArgReturnIntFunction(baudrate)
|
---|
| 1682 | NoArgReturnIntFunction(termattrs)
|
---|
| 1683 |
|
---|
| 1684 | NoArgReturnStringFunction(termname)
|
---|
| 1685 | NoArgReturnStringFunction(longname)
|
---|
| 1686 |
|
---|
| 1687 | NoArgTrueFalseFunction(can_change_color)
|
---|
| 1688 | NoArgTrueFalseFunction(has_colors)
|
---|
| 1689 | NoArgTrueFalseFunction(has_ic)
|
---|
| 1690 | NoArgTrueFalseFunction(has_il)
|
---|
| 1691 | NoArgTrueFalseFunction(isendwin)
|
---|
| 1692 | NoArgNoReturnVoidFunction(flushinp)
|
---|
| 1693 | NoArgNoReturnVoidFunction(noqiflush)
|
---|
| 1694 |
|
---|
| 1695 | static PyObject *
|
---|
| 1696 | PyCurses_filter(PyObject *self)
|
---|
| 1697 | {
|
---|
[391] | 1698 | /* not checking for PyCursesInitialised here since filter() must
|
---|
| 1699 | be called before initscr() */
|
---|
| 1700 | filter();
|
---|
| 1701 | Py_INCREF(Py_None);
|
---|
| 1702 | return Py_None;
|
---|
[2] | 1703 | }
|
---|
| 1704 |
|
---|
| 1705 | static PyObject *
|
---|
| 1706 | PyCurses_Color_Content(PyObject *self, PyObject *args)
|
---|
| 1707 | {
|
---|
[391] | 1708 | short color,r,g,b;
|
---|
[2] | 1709 |
|
---|
[391] | 1710 | PyCursesInitialised;
|
---|
| 1711 | PyCursesInitialisedColor;
|
---|
[2] | 1712 |
|
---|
[391] | 1713 | if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL;
|
---|
[2] | 1714 |
|
---|
[391] | 1715 | if (color_content(color, &r, &g, &b) != ERR)
|
---|
| 1716 | return Py_BuildValue("(iii)", r, g, b);
|
---|
| 1717 | else {
|
---|
| 1718 | PyErr_SetString(PyCursesError,
|
---|
| 1719 | "Argument 1 was out of range. Check value of COLORS.");
|
---|
| 1720 | return NULL;
|
---|
| 1721 | }
|
---|
[2] | 1722 | }
|
---|
| 1723 |
|
---|
| 1724 | static PyObject *
|
---|
| 1725 | PyCurses_color_pair(PyObject *self, PyObject *args)
|
---|
| 1726 | {
|
---|
[391] | 1727 | int n;
|
---|
[2] | 1728 |
|
---|
[391] | 1729 | PyCursesInitialised;
|
---|
| 1730 | PyCursesInitialisedColor;
|
---|
[2] | 1731 |
|
---|
[391] | 1732 | if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL;
|
---|
| 1733 | return PyInt_FromLong((long) (n << 8));
|
---|
[2] | 1734 | }
|
---|
| 1735 |
|
---|
| 1736 | static PyObject *
|
---|
| 1737 | PyCurses_Curs_Set(PyObject *self, PyObject *args)
|
---|
| 1738 | {
|
---|
[391] | 1739 | int vis,erg;
|
---|
[2] | 1740 |
|
---|
[391] | 1741 | PyCursesInitialised;
|
---|
[2] | 1742 |
|
---|
[391] | 1743 | if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL;
|
---|
[2] | 1744 |
|
---|
[391] | 1745 | erg = curs_set(vis);
|
---|
| 1746 | if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
|
---|
[2] | 1747 |
|
---|
[391] | 1748 | return PyInt_FromLong((long) erg);
|
---|
[2] | 1749 | }
|
---|
| 1750 |
|
---|
| 1751 | static PyObject *
|
---|
| 1752 | PyCurses_Delay_Output(PyObject *self, PyObject *args)
|
---|
| 1753 | {
|
---|
[391] | 1754 | int ms;
|
---|
[2] | 1755 |
|
---|
[391] | 1756 | PyCursesInitialised;
|
---|
[2] | 1757 |
|
---|
[391] | 1758 | if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL;
|
---|
[2] | 1759 |
|
---|
[391] | 1760 | return PyCursesCheckERR(delay_output(ms), "delay_output");
|
---|
[2] | 1761 | }
|
---|
| 1762 |
|
---|
| 1763 | static PyObject *
|
---|
| 1764 | PyCurses_EraseChar(PyObject *self)
|
---|
| 1765 | {
|
---|
[391] | 1766 | char ch;
|
---|
[2] | 1767 |
|
---|
[391] | 1768 | PyCursesInitialised;
|
---|
[2] | 1769 |
|
---|
[391] | 1770 | ch = erasechar();
|
---|
[2] | 1771 |
|
---|
[391] | 1772 | return PyString_FromStringAndSize(&ch, 1);
|
---|
[2] | 1773 | }
|
---|
| 1774 |
|
---|
| 1775 | static PyObject *
|
---|
| 1776 | PyCurses_getsyx(PyObject *self)
|
---|
| 1777 | {
|
---|
[391] | 1778 | int x = 0;
|
---|
| 1779 | int y = 0;
|
---|
[2] | 1780 |
|
---|
[391] | 1781 | PyCursesInitialised;
|
---|
[2] | 1782 |
|
---|
[391] | 1783 | getsyx(y, x);
|
---|
[2] | 1784 |
|
---|
[391] | 1785 | return Py_BuildValue("(ii)", y, x);
|
---|
[2] | 1786 | }
|
---|
| 1787 |
|
---|
| 1788 | #ifdef NCURSES_MOUSE_VERSION
|
---|
| 1789 | static PyObject *
|
---|
| 1790 | PyCurses_GetMouse(PyObject *self)
|
---|
| 1791 | {
|
---|
[391] | 1792 | int rtn;
|
---|
| 1793 | MEVENT event;
|
---|
[2] | 1794 |
|
---|
[391] | 1795 | PyCursesInitialised;
|
---|
[2] | 1796 |
|
---|
[391] | 1797 | rtn = getmouse( &event );
|
---|
| 1798 | if (rtn == ERR) {
|
---|
| 1799 | PyErr_SetString(PyCursesError, "getmouse() returned ERR");
|
---|
| 1800 | return NULL;
|
---|
| 1801 | }
|
---|
| 1802 | return Py_BuildValue("(hiiil)",
|
---|
| 1803 | (short)event.id,
|
---|
| 1804 | event.x, event.y, event.z,
|
---|
| 1805 | (long) event.bstate);
|
---|
[2] | 1806 | }
|
---|
| 1807 |
|
---|
| 1808 | static PyObject *
|
---|
| 1809 | PyCurses_UngetMouse(PyObject *self, PyObject *args)
|
---|
| 1810 | {
|
---|
[391] | 1811 | MEVENT event;
|
---|
[2] | 1812 |
|
---|
[391] | 1813 | PyCursesInitialised;
|
---|
| 1814 | if (!PyArg_ParseTuple(args, "hiiil",
|
---|
| 1815 | &event.id,
|
---|
| 1816 | &event.x, &event.y, &event.z,
|
---|
| 1817 | (int *) &event.bstate))
|
---|
| 1818 | return NULL;
|
---|
[2] | 1819 |
|
---|
[391] | 1820 | return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
|
---|
[2] | 1821 | }
|
---|
| 1822 | #endif
|
---|
| 1823 |
|
---|
| 1824 | static PyObject *
|
---|
| 1825 | PyCurses_GetWin(PyCursesWindowObject *self, PyObject *temp)
|
---|
| 1826 | {
|
---|
[391] | 1827 | WINDOW *win;
|
---|
[2] | 1828 |
|
---|
[391] | 1829 | PyCursesInitialised;
|
---|
[2] | 1830 |
|
---|
[391] | 1831 | if (!PyFile_Check(temp)) {
|
---|
| 1832 | PyErr_SetString(PyExc_TypeError, "argument must be a file object");
|
---|
| 1833 | return NULL;
|
---|
| 1834 | }
|
---|
[2] | 1835 |
|
---|
[391] | 1836 | win = getwin(PyFile_AsFile(temp));
|
---|
[2] | 1837 |
|
---|
[391] | 1838 | if (win == NULL) {
|
---|
| 1839 | PyErr_SetString(PyCursesError, catchall_NULL);
|
---|
| 1840 | return NULL;
|
---|
| 1841 | }
|
---|
[2] | 1842 |
|
---|
[391] | 1843 | return PyCursesWindow_New(win);
|
---|
[2] | 1844 | }
|
---|
| 1845 |
|
---|
| 1846 | static PyObject *
|
---|
| 1847 | PyCurses_HalfDelay(PyObject *self, PyObject *args)
|
---|
| 1848 | {
|
---|
[391] | 1849 | unsigned char tenths;
|
---|
[2] | 1850 |
|
---|
[391] | 1851 | PyCursesInitialised;
|
---|
[2] | 1852 |
|
---|
[391] | 1853 | if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL;
|
---|
[2] | 1854 |
|
---|
[391] | 1855 | return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
|
---|
[2] | 1856 | }
|
---|
| 1857 |
|
---|
| 1858 | #ifndef STRICT_SYSV_CURSES
|
---|
[391] | 1859 | /* No has_key! */
|
---|
[2] | 1860 | static PyObject * PyCurses_has_key(PyObject *self, PyObject *args)
|
---|
| 1861 | {
|
---|
[391] | 1862 | int ch;
|
---|
[2] | 1863 |
|
---|
[391] | 1864 | PyCursesInitialised;
|
---|
[2] | 1865 |
|
---|
[391] | 1866 | if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
|
---|
[2] | 1867 |
|
---|
[391] | 1868 | if (has_key(ch) == FALSE) {
|
---|
| 1869 | Py_INCREF(Py_False);
|
---|
| 1870 | return Py_False;
|
---|
| 1871 | }
|
---|
| 1872 | Py_INCREF(Py_True);
|
---|
| 1873 | return Py_True;
|
---|
[2] | 1874 | }
|
---|
| 1875 | #endif /* STRICT_SYSV_CURSES */
|
---|
| 1876 |
|
---|
| 1877 | static PyObject *
|
---|
| 1878 | PyCurses_Init_Color(PyObject *self, PyObject *args)
|
---|
| 1879 | {
|
---|
[391] | 1880 | short color, r, g, b;
|
---|
[2] | 1881 |
|
---|
[391] | 1882 | PyCursesInitialised;
|
---|
| 1883 | PyCursesInitialisedColor;
|
---|
[2] | 1884 |
|
---|
[391] | 1885 | switch(PyTuple_Size(args)) {
|
---|
| 1886 | case 4:
|
---|
| 1887 | if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL;
|
---|
| 1888 | break;
|
---|
| 1889 | default:
|
---|
| 1890 | PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
|
---|
| 1891 | return NULL;
|
---|
| 1892 | }
|
---|
[2] | 1893 |
|
---|
[391] | 1894 | return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
|
---|
[2] | 1895 | }
|
---|
| 1896 |
|
---|
| 1897 | static PyObject *
|
---|
| 1898 | PyCurses_Init_Pair(PyObject *self, PyObject *args)
|
---|
| 1899 | {
|
---|
[391] | 1900 | short pair, f, b;
|
---|
[2] | 1901 |
|
---|
[391] | 1902 | PyCursesInitialised;
|
---|
| 1903 | PyCursesInitialisedColor;
|
---|
[2] | 1904 |
|
---|
[391] | 1905 | if (PyTuple_Size(args) != 3) {
|
---|
| 1906 | PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
|
---|
| 1907 | return NULL;
|
---|
| 1908 | }
|
---|
[2] | 1909 |
|
---|
[391] | 1910 | if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL;
|
---|
[2] | 1911 |
|
---|
[391] | 1912 | return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
|
---|
[2] | 1913 | }
|
---|
| 1914 |
|
---|
| 1915 | static PyObject *ModDict;
|
---|
| 1916 |
|
---|
[391] | 1917 | static PyObject *
|
---|
[2] | 1918 | PyCurses_InitScr(PyObject *self)
|
---|
| 1919 | {
|
---|
[391] | 1920 | WINDOW *win;
|
---|
[2] | 1921 |
|
---|
[391] | 1922 | if (initialised == TRUE) {
|
---|
| 1923 | wrefresh(stdscr);
|
---|
| 1924 | return (PyObject *)PyCursesWindow_New(stdscr);
|
---|
| 1925 | }
|
---|
[2] | 1926 |
|
---|
[391] | 1927 | win = initscr();
|
---|
[2] | 1928 |
|
---|
[391] | 1929 | if (win == NULL) {
|
---|
| 1930 | PyErr_SetString(PyCursesError, catchall_NULL);
|
---|
| 1931 | return NULL;
|
---|
| 1932 | }
|
---|
[2] | 1933 |
|
---|
[391] | 1934 | initialised = initialised_setupterm = TRUE;
|
---|
[2] | 1935 |
|
---|
| 1936 | /* This was moved from initcurses() because it core dumped on SGI,
|
---|
| 1937 | where they're not defined until you've called initscr() */
|
---|
[391] | 1938 | #define SetDictInt(string,ch) \
|
---|
| 1939 | do { \
|
---|
| 1940 | PyObject *o = PyInt_FromLong((long) (ch)); \
|
---|
| 1941 | if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \
|
---|
| 1942 | Py_DECREF(o); \
|
---|
| 1943 | } \
|
---|
[2] | 1944 | } while (0)
|
---|
| 1945 |
|
---|
[391] | 1946 | /* Here are some graphic symbols you can use */
|
---|
| 1947 | SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
|
---|
| 1948 | SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
|
---|
| 1949 | SetDictInt("ACS_URCORNER", (ACS_URCORNER));
|
---|
| 1950 | SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
|
---|
| 1951 | SetDictInt("ACS_LTEE", (ACS_LTEE));
|
---|
| 1952 | SetDictInt("ACS_RTEE", (ACS_RTEE));
|
---|
| 1953 | SetDictInt("ACS_BTEE", (ACS_BTEE));
|
---|
| 1954 | SetDictInt("ACS_TTEE", (ACS_TTEE));
|
---|
| 1955 | SetDictInt("ACS_HLINE", (ACS_HLINE));
|
---|
| 1956 | SetDictInt("ACS_VLINE", (ACS_VLINE));
|
---|
| 1957 | SetDictInt("ACS_PLUS", (ACS_PLUS));
|
---|
[2] | 1958 | #if !defined(__hpux) || defined(HAVE_NCURSES_H)
|
---|
[391] | 1959 | /* On HP/UX 11, these are of type cchar_t, which is not an
|
---|
| 1960 | integral type. If this is a problem on more platforms, a
|
---|
| 1961 | configure test should be added to determine whether ACS_S1
|
---|
| 1962 | is of integral type. */
|
---|
| 1963 | SetDictInt("ACS_S1", (ACS_S1));
|
---|
| 1964 | SetDictInt("ACS_S9", (ACS_S9));
|
---|
| 1965 | SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
|
---|
| 1966 | SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
|
---|
| 1967 | SetDictInt("ACS_DEGREE", (ACS_DEGREE));
|
---|
| 1968 | SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
|
---|
| 1969 | SetDictInt("ACS_BULLET", (ACS_BULLET));
|
---|
| 1970 | SetDictInt("ACS_LARROW", (ACS_LARROW));
|
---|
| 1971 | SetDictInt("ACS_RARROW", (ACS_RARROW));
|
---|
| 1972 | SetDictInt("ACS_DARROW", (ACS_DARROW));
|
---|
| 1973 | SetDictInt("ACS_UARROW", (ACS_UARROW));
|
---|
| 1974 | SetDictInt("ACS_BOARD", (ACS_BOARD));
|
---|
| 1975 | SetDictInt("ACS_LANTERN", (ACS_LANTERN));
|
---|
| 1976 | SetDictInt("ACS_BLOCK", (ACS_BLOCK));
|
---|
[2] | 1977 | #endif
|
---|
[391] | 1978 | SetDictInt("ACS_BSSB", (ACS_ULCORNER));
|
---|
| 1979 | SetDictInt("ACS_SSBB", (ACS_LLCORNER));
|
---|
| 1980 | SetDictInt("ACS_BBSS", (ACS_URCORNER));
|
---|
| 1981 | SetDictInt("ACS_SBBS", (ACS_LRCORNER));
|
---|
| 1982 | SetDictInt("ACS_SBSS", (ACS_RTEE));
|
---|
| 1983 | SetDictInt("ACS_SSSB", (ACS_LTEE));
|
---|
| 1984 | SetDictInt("ACS_SSBS", (ACS_BTEE));
|
---|
| 1985 | SetDictInt("ACS_BSSS", (ACS_TTEE));
|
---|
| 1986 | SetDictInt("ACS_BSBS", (ACS_HLINE));
|
---|
| 1987 | SetDictInt("ACS_SBSB", (ACS_VLINE));
|
---|
| 1988 | SetDictInt("ACS_SSSS", (ACS_PLUS));
|
---|
[2] | 1989 |
|
---|
[391] | 1990 | /* The following are never available with strict SYSV curses */
|
---|
[2] | 1991 | #ifdef ACS_S3
|
---|
[391] | 1992 | SetDictInt("ACS_S3", (ACS_S3));
|
---|
[2] | 1993 | #endif
|
---|
| 1994 | #ifdef ACS_S7
|
---|
[391] | 1995 | SetDictInt("ACS_S7", (ACS_S7));
|
---|
[2] | 1996 | #endif
|
---|
| 1997 | #ifdef ACS_LEQUAL
|
---|
[391] | 1998 | SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
|
---|
[2] | 1999 | #endif
|
---|
| 2000 | #ifdef ACS_GEQUAL
|
---|
[391] | 2001 | SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
|
---|
[2] | 2002 | #endif
|
---|
| 2003 | #ifdef ACS_PI
|
---|
[391] | 2004 | SetDictInt("ACS_PI", (ACS_PI));
|
---|
[2] | 2005 | #endif
|
---|
| 2006 | #ifdef ACS_NEQUAL
|
---|
[391] | 2007 | SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
|
---|
[2] | 2008 | #endif
|
---|
| 2009 | #ifdef ACS_STERLING
|
---|
[391] | 2010 | SetDictInt("ACS_STERLING", (ACS_STERLING));
|
---|
[2] | 2011 | #endif
|
---|
| 2012 |
|
---|
[391] | 2013 | SetDictInt("LINES", LINES);
|
---|
| 2014 | SetDictInt("COLS", COLS);
|
---|
[2] | 2015 |
|
---|
[391] | 2016 | return (PyObject *)PyCursesWindow_New(win);
|
---|
[2] | 2017 | }
|
---|
| 2018 |
|
---|
| 2019 | static PyObject *
|
---|
| 2020 | PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
|
---|
| 2021 | {
|
---|
[391] | 2022 | int fd = -1;
|
---|
| 2023 | int err;
|
---|
| 2024 | char* termstr = NULL;
|
---|
[2] | 2025 |
|
---|
[391] | 2026 | static char *kwlist[] = {"term", "fd", NULL};
|
---|
[2] | 2027 |
|
---|
[391] | 2028 | if (!PyArg_ParseTupleAndKeywords(
|
---|
| 2029 | args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) {
|
---|
| 2030 | return NULL;
|
---|
| 2031 | }
|
---|
[2] | 2032 |
|
---|
[391] | 2033 | if (fd == -1) {
|
---|
| 2034 | PyObject* sys_stdout;
|
---|
[2] | 2035 |
|
---|
[391] | 2036 | sys_stdout = PySys_GetObject("stdout");
|
---|
[2] | 2037 |
|
---|
[391] | 2038 | if (sys_stdout == NULL) {
|
---|
| 2039 | PyErr_SetString(
|
---|
| 2040 | PyCursesError,
|
---|
| 2041 | "lost sys.stdout");
|
---|
| 2042 | return NULL;
|
---|
| 2043 | }
|
---|
[2] | 2044 |
|
---|
[391] | 2045 | fd = PyObject_AsFileDescriptor(sys_stdout);
|
---|
[2] | 2046 |
|
---|
[391] | 2047 | if (fd == -1) {
|
---|
| 2048 | return NULL;
|
---|
| 2049 | }
|
---|
| 2050 | }
|
---|
[2] | 2051 |
|
---|
[391] | 2052 | if (!initialised_setupterm && setupterm(termstr,fd,&err) == ERR) {
|
---|
| 2053 | char* s = "setupterm: unknown error";
|
---|
[2] | 2054 |
|
---|
[391] | 2055 | if (err == 0) {
|
---|
| 2056 | s = "setupterm: could not find terminal";
|
---|
| 2057 | } else if (err == -1) {
|
---|
| 2058 | s = "setupterm: could not find terminfo database";
|
---|
| 2059 | }
|
---|
[2] | 2060 |
|
---|
[391] | 2061 | PyErr_SetString(PyCursesError,s);
|
---|
| 2062 | return NULL;
|
---|
| 2063 | }
|
---|
| 2064 |
|
---|
| 2065 | initialised_setupterm = TRUE;
|
---|
| 2066 |
|
---|
| 2067 | Py_INCREF(Py_None);
|
---|
| 2068 | return Py_None;
|
---|
[2] | 2069 | }
|
---|
| 2070 |
|
---|
| 2071 | static PyObject *
|
---|
| 2072 | PyCurses_IntrFlush(PyObject *self, PyObject *args)
|
---|
| 2073 | {
|
---|
[391] | 2074 | int ch;
|
---|
[2] | 2075 |
|
---|
[391] | 2076 | PyCursesInitialised;
|
---|
[2] | 2077 |
|
---|
[391] | 2078 | switch(PyTuple_Size(args)) {
|
---|
| 2079 | case 1:
|
---|
| 2080 | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
|
---|
| 2081 | break;
|
---|
| 2082 | default:
|
---|
| 2083 | PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
|
---|
| 2084 | return NULL;
|
---|
| 2085 | }
|
---|
[2] | 2086 |
|
---|
[391] | 2087 | return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
|
---|
[2] | 2088 | }
|
---|
| 2089 |
|
---|
| 2090 | #ifdef HAVE_CURSES_IS_TERM_RESIZED
|
---|
| 2091 | static PyObject *
|
---|
| 2092 | PyCurses_Is_Term_Resized(PyObject *self, PyObject *args)
|
---|
| 2093 | {
|
---|
[391] | 2094 | int lines;
|
---|
| 2095 | int columns;
|
---|
| 2096 | int result;
|
---|
[2] | 2097 |
|
---|
[391] | 2098 | PyCursesInitialised;
|
---|
[2] | 2099 |
|
---|
[391] | 2100 | if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns))
|
---|
| 2101 | return NULL;
|
---|
| 2102 | result = is_term_resized(lines, columns);
|
---|
| 2103 | if (result == TRUE) {
|
---|
| 2104 | Py_INCREF(Py_True);
|
---|
| 2105 | return Py_True;
|
---|
| 2106 | } else {
|
---|
| 2107 | Py_INCREF(Py_False);
|
---|
| 2108 | return Py_False;
|
---|
| 2109 | }
|
---|
[2] | 2110 | }
|
---|
| 2111 | #endif /* HAVE_CURSES_IS_TERM_RESIZED */
|
---|
| 2112 |
|
---|
| 2113 | #if !defined(__NetBSD__)
|
---|
| 2114 | static PyObject *
|
---|
| 2115 | PyCurses_KeyName(PyObject *self, PyObject *args)
|
---|
| 2116 | {
|
---|
[391] | 2117 | const char *knp;
|
---|
| 2118 | int ch;
|
---|
[2] | 2119 |
|
---|
[391] | 2120 | PyCursesInitialised;
|
---|
[2] | 2121 |
|
---|
[391] | 2122 | if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
|
---|
[2] | 2123 |
|
---|
[391] | 2124 | if (ch < 0) {
|
---|
| 2125 | PyErr_SetString(PyExc_ValueError, "invalid key number");
|
---|
| 2126 | return NULL;
|
---|
| 2127 | }
|
---|
| 2128 | knp = keyname(ch);
|
---|
[2] | 2129 |
|
---|
[391] | 2130 | return PyString_FromString((knp == NULL) ? "" : (char *)knp);
|
---|
[2] | 2131 | }
|
---|
| 2132 | #endif
|
---|
| 2133 |
|
---|
[391] | 2134 | static PyObject *
|
---|
| 2135 | PyCurses_KillChar(PyObject *self)
|
---|
| 2136 | {
|
---|
| 2137 | char ch;
|
---|
[2] | 2138 |
|
---|
[391] | 2139 | ch = killchar();
|
---|
[2] | 2140 |
|
---|
[391] | 2141 | return PyString_FromStringAndSize(&ch, 1);
|
---|
| 2142 | }
|
---|
[2] | 2143 |
|
---|
| 2144 | static PyObject *
|
---|
| 2145 | PyCurses_Meta(PyObject *self, PyObject *args)
|
---|
| 2146 | {
|
---|
[391] | 2147 | int ch;
|
---|
[2] | 2148 |
|
---|
[391] | 2149 | PyCursesInitialised;
|
---|
[2] | 2150 |
|
---|
[391] | 2151 | switch(PyTuple_Size(args)) {
|
---|
| 2152 | case 1:
|
---|
| 2153 | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
|
---|
| 2154 | break;
|
---|
| 2155 | default:
|
---|
| 2156 | PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
|
---|
| 2157 | return NULL;
|
---|
| 2158 | }
|
---|
[2] | 2159 |
|
---|
[391] | 2160 | return PyCursesCheckERR(meta(stdscr, ch), "meta");
|
---|
[2] | 2161 | }
|
---|
| 2162 |
|
---|
| 2163 | #ifdef NCURSES_MOUSE_VERSION
|
---|
| 2164 | static PyObject *
|
---|
| 2165 | PyCurses_MouseInterval(PyObject *self, PyObject *args)
|
---|
| 2166 | {
|
---|
[391] | 2167 | int interval;
|
---|
| 2168 | PyCursesInitialised;
|
---|
[2] | 2169 |
|
---|
[391] | 2170 | if (!PyArg_ParseTuple(args,"i;interval",&interval))
|
---|
| 2171 | return NULL;
|
---|
| 2172 | return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
|
---|
[2] | 2173 | }
|
---|
| 2174 |
|
---|
| 2175 | static PyObject *
|
---|
| 2176 | PyCurses_MouseMask(PyObject *self, PyObject *args)
|
---|
| 2177 | {
|
---|
[391] | 2178 | int newmask;
|
---|
| 2179 | mmask_t oldmask, availmask;
|
---|
[2] | 2180 |
|
---|
[391] | 2181 | PyCursesInitialised;
|
---|
| 2182 | if (!PyArg_ParseTuple(args,"i;mousemask",&newmask))
|
---|
| 2183 | return NULL;
|
---|
| 2184 | availmask = mousemask(newmask, &oldmask);
|
---|
| 2185 | return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
|
---|
[2] | 2186 | }
|
---|
| 2187 | #endif
|
---|
| 2188 |
|
---|
| 2189 | static PyObject *
|
---|
| 2190 | PyCurses_Napms(PyObject *self, PyObject *args)
|
---|
| 2191 | {
|
---|
| 2192 | int ms;
|
---|
| 2193 |
|
---|
[391] | 2194 | PyCursesInitialised;
|
---|
[2] | 2195 | if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL;
|
---|
| 2196 |
|
---|
| 2197 | return Py_BuildValue("i", napms(ms));
|
---|
| 2198 | }
|
---|
| 2199 |
|
---|
| 2200 |
|
---|
| 2201 | static PyObject *
|
---|
| 2202 | PyCurses_NewPad(PyObject *self, PyObject *args)
|
---|
| 2203 | {
|
---|
[391] | 2204 | WINDOW *win;
|
---|
| 2205 | int nlines, ncols;
|
---|
[2] | 2206 |
|
---|
[391] | 2207 | PyCursesInitialised;
|
---|
[2] | 2208 |
|
---|
[391] | 2209 | if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL;
|
---|
[2] | 2210 |
|
---|
[391] | 2211 | win = newpad(nlines, ncols);
|
---|
[2] | 2212 |
|
---|
[391] | 2213 | if (win == NULL) {
|
---|
| 2214 | PyErr_SetString(PyCursesError, catchall_NULL);
|
---|
| 2215 | return NULL;
|
---|
| 2216 | }
|
---|
| 2217 |
|
---|
| 2218 | return (PyObject *)PyCursesWindow_New(win);
|
---|
[2] | 2219 | }
|
---|
| 2220 |
|
---|
| 2221 | static PyObject *
|
---|
| 2222 | PyCurses_NewWindow(PyObject *self, PyObject *args)
|
---|
| 2223 | {
|
---|
[391] | 2224 | WINDOW *win;
|
---|
| 2225 | int nlines, ncols, begin_y=0, begin_x=0;
|
---|
[2] | 2226 |
|
---|
[391] | 2227 | PyCursesInitialised;
|
---|
[2] | 2228 |
|
---|
[391] | 2229 | switch (PyTuple_Size(args)) {
|
---|
| 2230 | case 2:
|
---|
| 2231 | if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols))
|
---|
| 2232 | return NULL;
|
---|
| 2233 | break;
|
---|
| 2234 | case 4:
|
---|
| 2235 | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
|
---|
| 2236 | &nlines,&ncols,&begin_y,&begin_x))
|
---|
| 2237 | return NULL;
|
---|
| 2238 | break;
|
---|
| 2239 | default:
|
---|
| 2240 | PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
|
---|
| 2241 | return NULL;
|
---|
| 2242 | }
|
---|
[2] | 2243 |
|
---|
[391] | 2244 | win = newwin(nlines,ncols,begin_y,begin_x);
|
---|
| 2245 | if (win == NULL) {
|
---|
| 2246 | PyErr_SetString(PyCursesError, catchall_NULL);
|
---|
| 2247 | return NULL;
|
---|
| 2248 | }
|
---|
[2] | 2249 |
|
---|
[391] | 2250 | return (PyObject *)PyCursesWindow_New(win);
|
---|
[2] | 2251 | }
|
---|
| 2252 |
|
---|
| 2253 | static PyObject *
|
---|
| 2254 | PyCurses_Pair_Content(PyObject *self, PyObject *args)
|
---|
| 2255 | {
|
---|
[391] | 2256 | short pair,f,b;
|
---|
[2] | 2257 |
|
---|
[391] | 2258 | PyCursesInitialised;
|
---|
| 2259 | PyCursesInitialisedColor;
|
---|
[2] | 2260 |
|
---|
[391] | 2261 | switch(PyTuple_Size(args)) {
|
---|
| 2262 | case 1:
|
---|
| 2263 | if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL;
|
---|
| 2264 | break;
|
---|
| 2265 | default:
|
---|
| 2266 | PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
|
---|
| 2267 | return NULL;
|
---|
| 2268 | }
|
---|
[2] | 2269 |
|
---|
[391] | 2270 | if (pair_content(pair, &f, &b)==ERR) {
|
---|
| 2271 | PyErr_SetString(PyCursesError,
|
---|
| 2272 | "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
|
---|
| 2273 | return NULL;
|
---|
| 2274 | }
|
---|
[2] | 2275 |
|
---|
[391] | 2276 | return Py_BuildValue("(ii)", f, b);
|
---|
[2] | 2277 | }
|
---|
| 2278 |
|
---|
| 2279 | static PyObject *
|
---|
| 2280 | PyCurses_pair_number(PyObject *self, PyObject *args)
|
---|
| 2281 | {
|
---|
[391] | 2282 | int n;
|
---|
[2] | 2283 |
|
---|
[391] | 2284 | PyCursesInitialised;
|
---|
| 2285 | PyCursesInitialisedColor;
|
---|
[2] | 2286 |
|
---|
[391] | 2287 | switch(PyTuple_Size(args)) {
|
---|
| 2288 | case 1:
|
---|
| 2289 | if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL;
|
---|
| 2290 | break;
|
---|
| 2291 | default:
|
---|
| 2292 | PyErr_SetString(PyExc_TypeError,
|
---|
| 2293 | "pair_number requires 1 argument");
|
---|
| 2294 | return NULL;
|
---|
| 2295 | }
|
---|
[2] | 2296 |
|
---|
[391] | 2297 | return PyInt_FromLong((long) ((n & A_COLOR) >> 8));
|
---|
[2] | 2298 | }
|
---|
| 2299 |
|
---|
| 2300 | static PyObject *
|
---|
| 2301 | PyCurses_Putp(PyObject *self, PyObject *args)
|
---|
| 2302 | {
|
---|
[391] | 2303 | char *str;
|
---|
[2] | 2304 |
|
---|
[391] | 2305 | if (!PyArg_ParseTuple(args,"s;str", &str)) return NULL;
|
---|
| 2306 | return PyCursesCheckERR(putp(str), "putp");
|
---|
[2] | 2307 | }
|
---|
| 2308 |
|
---|
| 2309 | static PyObject *
|
---|
| 2310 | PyCurses_QiFlush(PyObject *self, PyObject *args)
|
---|
| 2311 | {
|
---|
[391] | 2312 | int flag = 0;
|
---|
[2] | 2313 |
|
---|
[391] | 2314 | PyCursesInitialised;
|
---|
[2] | 2315 |
|
---|
[391] | 2316 | switch(PyTuple_Size(args)) {
|
---|
| 2317 | case 0:
|
---|
| 2318 | qiflush();
|
---|
| 2319 | Py_INCREF(Py_None);
|
---|
| 2320 | return Py_None;
|
---|
| 2321 | case 1:
|
---|
| 2322 | if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL;
|
---|
| 2323 | if (flag) qiflush();
|
---|
| 2324 | else noqiflush();
|
---|
| 2325 | Py_INCREF(Py_None);
|
---|
| 2326 | return Py_None;
|
---|
| 2327 | default:
|
---|
| 2328 | PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
|
---|
| 2329 | return NULL;
|
---|
| 2330 | }
|
---|
[2] | 2331 | }
|
---|
| 2332 |
|
---|
| 2333 | /* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
|
---|
| 2334 | * and _curses.COLS */
|
---|
| 2335 | #if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM)
|
---|
| 2336 | static int
|
---|
| 2337 | update_lines_cols(void)
|
---|
| 2338 | {
|
---|
[391] | 2339 | PyObject *o;
|
---|
| 2340 | PyObject *m = PyImport_ImportModuleNoBlock("curses");
|
---|
[2] | 2341 |
|
---|
[391] | 2342 | if (!m)
|
---|
| 2343 | return 0;
|
---|
[2] | 2344 |
|
---|
[391] | 2345 | o = PyInt_FromLong(LINES);
|
---|
| 2346 | if (!o) {
|
---|
| 2347 | Py_DECREF(m);
|
---|
| 2348 | return 0;
|
---|
| 2349 | }
|
---|
| 2350 | if (PyObject_SetAttrString(m, "LINES", o)) {
|
---|
| 2351 | Py_DECREF(m);
|
---|
| 2352 | Py_DECREF(o);
|
---|
| 2353 | return 0;
|
---|
| 2354 | }
|
---|
| 2355 | if (PyDict_SetItemString(ModDict, "LINES", o)) {
|
---|
| 2356 | Py_DECREF(m);
|
---|
| 2357 | Py_DECREF(o);
|
---|
| 2358 | return 0;
|
---|
| 2359 | }
|
---|
[2] | 2360 | Py_DECREF(o);
|
---|
[391] | 2361 | o = PyInt_FromLong(COLS);
|
---|
| 2362 | if (!o) {
|
---|
| 2363 | Py_DECREF(m);
|
---|
| 2364 | return 0;
|
---|
| 2365 | }
|
---|
| 2366 | if (PyObject_SetAttrString(m, "COLS", o)) {
|
---|
| 2367 | Py_DECREF(m);
|
---|
| 2368 | Py_DECREF(o);
|
---|
| 2369 | return 0;
|
---|
| 2370 | }
|
---|
| 2371 | if (PyDict_SetItemString(ModDict, "COLS", o)) {
|
---|
| 2372 | Py_DECREF(m);
|
---|
| 2373 | Py_DECREF(o);
|
---|
| 2374 | return 0;
|
---|
| 2375 | }
|
---|
[2] | 2376 | Py_DECREF(o);
|
---|
| 2377 | Py_DECREF(m);
|
---|
[391] | 2378 | return 1;
|
---|
[2] | 2379 | }
|
---|
| 2380 | #endif
|
---|
| 2381 |
|
---|
| 2382 | #ifdef HAVE_CURSES_RESIZETERM
|
---|
| 2383 | static PyObject *
|
---|
| 2384 | PyCurses_ResizeTerm(PyObject *self, PyObject *args)
|
---|
| 2385 | {
|
---|
[391] | 2386 | int lines;
|
---|
| 2387 | int columns;
|
---|
| 2388 | PyObject *result;
|
---|
[2] | 2389 |
|
---|
[391] | 2390 | PyCursesInitialised;
|
---|
[2] | 2391 |
|
---|
[391] | 2392 | if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns))
|
---|
| 2393 | return NULL;
|
---|
[2] | 2394 |
|
---|
[391] | 2395 | result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
|
---|
| 2396 | if (!result)
|
---|
| 2397 | return NULL;
|
---|
| 2398 | if (!update_lines_cols())
|
---|
| 2399 | return NULL;
|
---|
| 2400 | return result;
|
---|
[2] | 2401 | }
|
---|
| 2402 |
|
---|
| 2403 | #endif
|
---|
| 2404 |
|
---|
| 2405 | #ifdef HAVE_CURSES_RESIZE_TERM
|
---|
| 2406 | static PyObject *
|
---|
| 2407 | PyCurses_Resize_Term(PyObject *self, PyObject *args)
|
---|
| 2408 | {
|
---|
[391] | 2409 | int lines;
|
---|
| 2410 | int columns;
|
---|
[2] | 2411 |
|
---|
[391] | 2412 | PyObject *result;
|
---|
[2] | 2413 |
|
---|
[391] | 2414 | PyCursesInitialised;
|
---|
[2] | 2415 |
|
---|
[391] | 2416 | if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns))
|
---|
| 2417 | return NULL;
|
---|
[2] | 2418 |
|
---|
[391] | 2419 | result = PyCursesCheckERR(resize_term(lines, columns), "resize_term");
|
---|
| 2420 | if (!result)
|
---|
| 2421 | return NULL;
|
---|
| 2422 | if (!update_lines_cols())
|
---|
| 2423 | return NULL;
|
---|
| 2424 | return result;
|
---|
[2] | 2425 | }
|
---|
| 2426 | #endif /* HAVE_CURSES_RESIZE_TERM */
|
---|
| 2427 |
|
---|
| 2428 | static PyObject *
|
---|
| 2429 | PyCurses_setsyx(PyObject *self, PyObject *args)
|
---|
| 2430 | {
|
---|
[391] | 2431 | int y,x;
|
---|
[2] | 2432 |
|
---|
[391] | 2433 | PyCursesInitialised;
|
---|
[2] | 2434 |
|
---|
[391] | 2435 | if (PyTuple_Size(args)!=2) {
|
---|
| 2436 | PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
|
---|
| 2437 | return NULL;
|
---|
| 2438 | }
|
---|
[2] | 2439 |
|
---|
[391] | 2440 | if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL;
|
---|
[2] | 2441 |
|
---|
[391] | 2442 | setsyx(y,x);
|
---|
[2] | 2443 |
|
---|
[391] | 2444 | Py_INCREF(Py_None);
|
---|
| 2445 | return Py_None;
|
---|
[2] | 2446 | }
|
---|
| 2447 |
|
---|
| 2448 | static PyObject *
|
---|
| 2449 | PyCurses_Start_Color(PyObject *self)
|
---|
| 2450 | {
|
---|
[391] | 2451 | int code;
|
---|
| 2452 | PyObject *c, *cp;
|
---|
[2] | 2453 |
|
---|
[391] | 2454 | PyCursesInitialised;
|
---|
[2] | 2455 |
|
---|
[391] | 2456 | code = start_color();
|
---|
| 2457 | if (code != ERR) {
|
---|
| 2458 | initialisedcolors = TRUE;
|
---|
| 2459 | c = PyInt_FromLong((long) COLORS);
|
---|
| 2460 | PyDict_SetItemString(ModDict, "COLORS", c);
|
---|
| 2461 | Py_DECREF(c);
|
---|
| 2462 | cp = PyInt_FromLong((long) COLOR_PAIRS);
|
---|
| 2463 | PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
|
---|
| 2464 | Py_DECREF(cp);
|
---|
| 2465 | Py_INCREF(Py_None);
|
---|
| 2466 | return Py_None;
|
---|
| 2467 | } else {
|
---|
| 2468 | PyErr_SetString(PyCursesError, "start_color() returned ERR");
|
---|
| 2469 | return NULL;
|
---|
| 2470 | }
|
---|
[2] | 2471 | }
|
---|
| 2472 |
|
---|
| 2473 | static PyObject *
|
---|
| 2474 | PyCurses_tigetflag(PyObject *self, PyObject *args)
|
---|
| 2475 | {
|
---|
[391] | 2476 | char *capname;
|
---|
[2] | 2477 |
|
---|
[391] | 2478 | PyCursesSetupTermCalled;
|
---|
[2] | 2479 |
|
---|
[391] | 2480 | if (!PyArg_ParseTuple(args, "s", &capname))
|
---|
| 2481 | return NULL;
|
---|
| 2482 |
|
---|
| 2483 | return PyInt_FromLong( (long) tigetflag( capname ) );
|
---|
[2] | 2484 | }
|
---|
| 2485 |
|
---|
| 2486 | static PyObject *
|
---|
| 2487 | PyCurses_tigetnum(PyObject *self, PyObject *args)
|
---|
| 2488 | {
|
---|
[391] | 2489 | char *capname;
|
---|
[2] | 2490 |
|
---|
[391] | 2491 | PyCursesSetupTermCalled;
|
---|
[2] | 2492 |
|
---|
[391] | 2493 | if (!PyArg_ParseTuple(args, "s", &capname))
|
---|
| 2494 | return NULL;
|
---|
| 2495 |
|
---|
| 2496 | return PyInt_FromLong( (long) tigetnum( capname ) );
|
---|
[2] | 2497 | }
|
---|
| 2498 |
|
---|
| 2499 | static PyObject *
|
---|
| 2500 | PyCurses_tigetstr(PyObject *self, PyObject *args)
|
---|
| 2501 | {
|
---|
[391] | 2502 | char *capname;
|
---|
[2] | 2503 |
|
---|
[391] | 2504 | PyCursesSetupTermCalled;
|
---|
[2] | 2505 |
|
---|
[391] | 2506 | if (!PyArg_ParseTuple(args, "s", &capname))
|
---|
| 2507 | return NULL;
|
---|
| 2508 |
|
---|
| 2509 | capname = tigetstr( capname );
|
---|
| 2510 | if (capname == 0 || capname == (char*) -1) {
|
---|
| 2511 | Py_INCREF(Py_None);
|
---|
| 2512 | return Py_None;
|
---|
| 2513 | }
|
---|
| 2514 | return PyString_FromString( capname );
|
---|
[2] | 2515 | }
|
---|
| 2516 |
|
---|
| 2517 | static PyObject *
|
---|
| 2518 | PyCurses_tparm(PyObject *self, PyObject *args)
|
---|
| 2519 | {
|
---|
[391] | 2520 | char* fmt;
|
---|
| 2521 | char* result = NULL;
|
---|
| 2522 | int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0;
|
---|
[2] | 2523 |
|
---|
[391] | 2524 | PyCursesSetupTermCalled;
|
---|
[2] | 2525 |
|
---|
[391] | 2526 | if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
|
---|
| 2527 | &fmt, &i1, &i2, &i3, &i4,
|
---|
| 2528 | &i5, &i6, &i7, &i8, &i9)) {
|
---|
| 2529 | return NULL;
|
---|
| 2530 | }
|
---|
[2] | 2531 |
|
---|
[391] | 2532 | result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9);
|
---|
| 2533 | if (!result) {
|
---|
| 2534 | PyErr_SetString(PyCursesError, "tparm() returned NULL");
|
---|
| 2535 | return NULL;
|
---|
| 2536 | }
|
---|
[2] | 2537 |
|
---|
[391] | 2538 | return PyString_FromString(result);
|
---|
[2] | 2539 | }
|
---|
| 2540 |
|
---|
| 2541 | static PyObject *
|
---|
| 2542 | PyCurses_TypeAhead(PyObject *self, PyObject *args)
|
---|
| 2543 | {
|
---|
[391] | 2544 | int fd;
|
---|
[2] | 2545 |
|
---|
[391] | 2546 | PyCursesInitialised;
|
---|
[2] | 2547 |
|
---|
[391] | 2548 | if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL;
|
---|
[2] | 2549 |
|
---|
[391] | 2550 | return PyCursesCheckERR(typeahead( fd ), "typeahead");
|
---|
[2] | 2551 | }
|
---|
| 2552 |
|
---|
| 2553 | static PyObject *
|
---|
| 2554 | PyCurses_UnCtrl(PyObject *self, PyObject *args)
|
---|
| 2555 | {
|
---|
[391] | 2556 | PyObject *temp;
|
---|
| 2557 | chtype ch;
|
---|
[2] | 2558 |
|
---|
[391] | 2559 | PyCursesInitialised;
|
---|
[2] | 2560 |
|
---|
[391] | 2561 | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
|
---|
[2] | 2562 |
|
---|
[391] | 2563 | if (PyInt_Check(temp))
|
---|
| 2564 | ch = (chtype) PyInt_AsLong(temp);
|
---|
| 2565 | else if (PyString_Check(temp))
|
---|
| 2566 | ch = (chtype) *PyString_AsString(temp);
|
---|
| 2567 | else {
|
---|
| 2568 | PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
|
---|
| 2569 | return NULL;
|
---|
| 2570 | }
|
---|
[2] | 2571 |
|
---|
[391] | 2572 | return PyString_FromString(unctrl(ch));
|
---|
[2] | 2573 | }
|
---|
| 2574 |
|
---|
| 2575 | static PyObject *
|
---|
| 2576 | PyCurses_UngetCh(PyObject *self, PyObject *args)
|
---|
| 2577 | {
|
---|
[391] | 2578 | PyObject *temp;
|
---|
| 2579 | int ch;
|
---|
[2] | 2580 |
|
---|
[391] | 2581 | PyCursesInitialised;
|
---|
[2] | 2582 |
|
---|
[391] | 2583 | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
|
---|
[2] | 2584 |
|
---|
[391] | 2585 | if (PyInt_Check(temp))
|
---|
| 2586 | ch = (int) PyInt_AsLong(temp);
|
---|
| 2587 | else if (PyString_Check(temp))
|
---|
| 2588 | ch = (int) *PyString_AsString(temp);
|
---|
| 2589 | else {
|
---|
| 2590 | PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
|
---|
| 2591 | return NULL;
|
---|
| 2592 | }
|
---|
[2] | 2593 |
|
---|
[391] | 2594 | return PyCursesCheckERR(ungetch(ch), "ungetch");
|
---|
[2] | 2595 | }
|
---|
| 2596 |
|
---|
| 2597 | static PyObject *
|
---|
| 2598 | PyCurses_Use_Env(PyObject *self, PyObject *args)
|
---|
| 2599 | {
|
---|
[391] | 2600 | int flag;
|
---|
[2] | 2601 |
|
---|
[391] | 2602 | switch(PyTuple_Size(args)) {
|
---|
| 2603 | case 1:
|
---|
| 2604 | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag))
|
---|
| 2605 | return NULL;
|
---|
| 2606 | break;
|
---|
| 2607 | default:
|
---|
| 2608 | PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
|
---|
| 2609 | return NULL;
|
---|
| 2610 | }
|
---|
| 2611 | use_env(flag);
|
---|
| 2612 | Py_INCREF(Py_None);
|
---|
| 2613 | return Py_None;
|
---|
[2] | 2614 | }
|
---|
| 2615 |
|
---|
| 2616 | #ifndef STRICT_SYSV_CURSES
|
---|
| 2617 | static PyObject *
|
---|
| 2618 | PyCurses_Use_Default_Colors(PyObject *self)
|
---|
| 2619 | {
|
---|
[391] | 2620 | int code;
|
---|
[2] | 2621 |
|
---|
[391] | 2622 | PyCursesInitialised;
|
---|
| 2623 | PyCursesInitialisedColor;
|
---|
[2] | 2624 |
|
---|
[391] | 2625 | code = use_default_colors();
|
---|
| 2626 | if (code != ERR) {
|
---|
| 2627 | Py_INCREF(Py_None);
|
---|
| 2628 | return Py_None;
|
---|
| 2629 | } else {
|
---|
| 2630 | PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
|
---|
| 2631 | return NULL;
|
---|
| 2632 | }
|
---|
[2] | 2633 | }
|
---|
| 2634 | #endif /* STRICT_SYSV_CURSES */
|
---|
| 2635 |
|
---|
| 2636 | /* List of functions defined in the module */
|
---|
| 2637 |
|
---|
| 2638 | static PyMethodDef PyCurses_methods[] = {
|
---|
[391] | 2639 | {"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS},
|
---|
| 2640 | {"beep", (PyCFunction)PyCurses_beep, METH_NOARGS},
|
---|
| 2641 | {"can_change_color", (PyCFunction)PyCurses_can_change_color, METH_NOARGS},
|
---|
| 2642 | {"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS},
|
---|
| 2643 | {"color_content", (PyCFunction)PyCurses_Color_Content, METH_VARARGS},
|
---|
| 2644 | {"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS},
|
---|
| 2645 | {"curs_set", (PyCFunction)PyCurses_Curs_Set, METH_VARARGS},
|
---|
| 2646 | {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS},
|
---|
| 2647 | {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS},
|
---|
| 2648 | {"delay_output", (PyCFunction)PyCurses_Delay_Output, METH_VARARGS},
|
---|
| 2649 | {"doupdate", (PyCFunction)PyCurses_doupdate, METH_NOARGS},
|
---|
| 2650 | {"echo", (PyCFunction)PyCurses_echo, METH_VARARGS},
|
---|
| 2651 | {"endwin", (PyCFunction)PyCurses_endwin, METH_NOARGS},
|
---|
| 2652 | {"erasechar", (PyCFunction)PyCurses_EraseChar, METH_NOARGS},
|
---|
| 2653 | {"filter", (PyCFunction)PyCurses_filter, METH_NOARGS},
|
---|
| 2654 | {"flash", (PyCFunction)PyCurses_flash, METH_NOARGS},
|
---|
| 2655 | {"flushinp", (PyCFunction)PyCurses_flushinp, METH_NOARGS},
|
---|
[2] | 2656 | #ifdef NCURSES_MOUSE_VERSION
|
---|
[391] | 2657 | {"getmouse", (PyCFunction)PyCurses_GetMouse, METH_NOARGS},
|
---|
| 2658 | {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
|
---|
[2] | 2659 | #endif
|
---|
[391] | 2660 | {"getsyx", (PyCFunction)PyCurses_getsyx, METH_NOARGS},
|
---|
| 2661 | {"getwin", (PyCFunction)PyCurses_GetWin, METH_O},
|
---|
| 2662 | {"has_colors", (PyCFunction)PyCurses_has_colors, METH_NOARGS},
|
---|
| 2663 | {"has_ic", (PyCFunction)PyCurses_has_ic, METH_NOARGS},
|
---|
| 2664 | {"has_il", (PyCFunction)PyCurses_has_il, METH_NOARGS},
|
---|
[2] | 2665 | #ifndef STRICT_SYSV_CURSES
|
---|
[391] | 2666 | {"has_key", (PyCFunction)PyCurses_has_key, METH_VARARGS},
|
---|
[2] | 2667 | #endif
|
---|
[391] | 2668 | {"halfdelay", (PyCFunction)PyCurses_HalfDelay, METH_VARARGS},
|
---|
| 2669 | {"init_color", (PyCFunction)PyCurses_Init_Color, METH_VARARGS},
|
---|
| 2670 | {"init_pair", (PyCFunction)PyCurses_Init_Pair, METH_VARARGS},
|
---|
| 2671 | {"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS},
|
---|
| 2672 | {"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS},
|
---|
| 2673 | {"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS},
|
---|
[2] | 2674 | #ifdef HAVE_CURSES_IS_TERM_RESIZED
|
---|
[391] | 2675 | {"is_term_resized", (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS},
|
---|
[2] | 2676 | #endif
|
---|
| 2677 | #if !defined(__NetBSD__)
|
---|
[391] | 2678 | {"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS},
|
---|
[2] | 2679 | #endif
|
---|
[391] | 2680 | {"killchar", (PyCFunction)PyCurses_KillChar, METH_NOARGS},
|
---|
| 2681 | {"longname", (PyCFunction)PyCurses_longname, METH_NOARGS},
|
---|
| 2682 | {"meta", (PyCFunction)PyCurses_Meta, METH_VARARGS},
|
---|
[2] | 2683 | #ifdef NCURSES_MOUSE_VERSION
|
---|
[391] | 2684 | {"mouseinterval", (PyCFunction)PyCurses_MouseInterval, METH_VARARGS},
|
---|
| 2685 | {"mousemask", (PyCFunction)PyCurses_MouseMask, METH_VARARGS},
|
---|
[2] | 2686 | #endif
|
---|
[391] | 2687 | {"napms", (PyCFunction)PyCurses_Napms, METH_VARARGS},
|
---|
| 2688 | {"newpad", (PyCFunction)PyCurses_NewPad, METH_VARARGS},
|
---|
| 2689 | {"newwin", (PyCFunction)PyCurses_NewWindow, METH_VARARGS},
|
---|
| 2690 | {"nl", (PyCFunction)PyCurses_nl, METH_VARARGS},
|
---|
| 2691 | {"nocbreak", (PyCFunction)PyCurses_nocbreak, METH_NOARGS},
|
---|
| 2692 | {"noecho", (PyCFunction)PyCurses_noecho, METH_NOARGS},
|
---|
| 2693 | {"nonl", (PyCFunction)PyCurses_nonl, METH_NOARGS},
|
---|
| 2694 | {"noqiflush", (PyCFunction)PyCurses_noqiflush, METH_NOARGS},
|
---|
| 2695 | {"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS},
|
---|
| 2696 | {"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS},
|
---|
| 2697 | {"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS},
|
---|
| 2698 | {"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS},
|
---|
| 2699 | {"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS},
|
---|
| 2700 | {"raw", (PyCFunction)PyCurses_raw, METH_VARARGS},
|
---|
| 2701 | {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS},
|
---|
| 2702 | {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS},
|
---|
| 2703 | {"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS},
|
---|
[2] | 2704 | #ifdef HAVE_CURSES_RESIZETERM
|
---|
[391] | 2705 | {"resizeterm", (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS},
|
---|
[2] | 2706 | #endif
|
---|
| 2707 | #ifdef HAVE_CURSES_RESIZE_TERM
|
---|
[391] | 2708 | {"resize_term", (PyCFunction)PyCurses_Resize_Term, METH_VARARGS},
|
---|
[2] | 2709 | #endif
|
---|
[391] | 2710 | {"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS},
|
---|
| 2711 | {"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS},
|
---|
| 2712 | {"setupterm", (PyCFunction)PyCurses_setupterm,
|
---|
| 2713 | METH_VARARGS|METH_KEYWORDS},
|
---|
| 2714 | {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS},
|
---|
| 2715 | {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS},
|
---|
| 2716 | {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS},
|
---|
| 2717 | {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
|
---|
| 2718 | {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
|
---|
| 2719 | {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
|
---|
| 2720 | {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS},
|
---|
| 2721 | {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS},
|
---|
| 2722 | {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS},
|
---|
| 2723 | {"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS},
|
---|
| 2724 | {"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS},
|
---|
[2] | 2725 | #ifndef STRICT_SYSV_CURSES
|
---|
[391] | 2726 | {"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS},
|
---|
[2] | 2727 | #endif
|
---|
[391] | 2728 | {NULL, NULL} /* sentinel */
|
---|
[2] | 2729 | };
|
---|
| 2730 |
|
---|
| 2731 | /* Initialization function for the module */
|
---|
| 2732 |
|
---|
| 2733 | PyMODINIT_FUNC
|
---|
| 2734 | init_curses(void)
|
---|
| 2735 | {
|
---|
[391] | 2736 | PyObject *m, *d, *v, *c_api_object;
|
---|
| 2737 | static void *PyCurses_API[PyCurses_API_pointers];
|
---|
[2] | 2738 |
|
---|
[391] | 2739 | /* Initialize object type */
|
---|
| 2740 | Py_TYPE(&PyCursesWindow_Type) = &PyType_Type;
|
---|
[2] | 2741 |
|
---|
[391] | 2742 | /* Initialize the C API pointer array */
|
---|
| 2743 | PyCurses_API[0] = (void *)&PyCursesWindow_Type;
|
---|
| 2744 | PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
|
---|
| 2745 | PyCurses_API[2] = (void *)func_PyCursesInitialised;
|
---|
| 2746 | PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
|
---|
[2] | 2747 |
|
---|
[391] | 2748 | /* Create the module and add the functions */
|
---|
| 2749 | m = Py_InitModule("_curses", PyCurses_methods);
|
---|
| 2750 | if (m == NULL)
|
---|
| 2751 | return;
|
---|
[2] | 2752 |
|
---|
[391] | 2753 | /* Add some symbolic constants to the module */
|
---|
| 2754 | d = PyModule_GetDict(m);
|
---|
| 2755 | if (d == NULL)
|
---|
| 2756 | return;
|
---|
| 2757 | ModDict = d; /* For PyCurses_InitScr to use later */
|
---|
[2] | 2758 |
|
---|
[391] | 2759 | /* Add a capsule for the C API */
|
---|
| 2760 | c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, NULL);
|
---|
| 2761 | PyDict_SetItemString(d, "_C_API", c_api_object);
|
---|
| 2762 | Py_DECREF(c_api_object);
|
---|
[2] | 2763 |
|
---|
[391] | 2764 | /* For exception curses.error */
|
---|
| 2765 | PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
|
---|
| 2766 | PyDict_SetItemString(d, "error", PyCursesError);
|
---|
[2] | 2767 |
|
---|
[391] | 2768 | /* Make the version available */
|
---|
| 2769 | v = PyString_FromString(PyCursesVersion);
|
---|
| 2770 | PyDict_SetItemString(d, "version", v);
|
---|
| 2771 | PyDict_SetItemString(d, "__version__", v);
|
---|
| 2772 | Py_DECREF(v);
|
---|
[2] | 2773 |
|
---|
[391] | 2774 | SetDictInt("ERR", ERR);
|
---|
| 2775 | SetDictInt("OK", OK);
|
---|
[2] | 2776 |
|
---|
[391] | 2777 | /* Here are some attributes you can add to chars to print */
|
---|
| 2778 |
|
---|
| 2779 | SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
|
---|
| 2780 | SetDictInt("A_NORMAL", A_NORMAL);
|
---|
| 2781 | SetDictInt("A_STANDOUT", A_STANDOUT);
|
---|
| 2782 | SetDictInt("A_UNDERLINE", A_UNDERLINE);
|
---|
| 2783 | SetDictInt("A_REVERSE", A_REVERSE);
|
---|
| 2784 | SetDictInt("A_BLINK", A_BLINK);
|
---|
| 2785 | SetDictInt("A_DIM", A_DIM);
|
---|
| 2786 | SetDictInt("A_BOLD", A_BOLD);
|
---|
| 2787 | SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
|
---|
[2] | 2788 | #if !defined(__NetBSD__)
|
---|
[391] | 2789 | SetDictInt("A_INVIS", A_INVIS);
|
---|
[2] | 2790 | #endif
|
---|
[391] | 2791 | SetDictInt("A_PROTECT", A_PROTECT);
|
---|
| 2792 | SetDictInt("A_CHARTEXT", A_CHARTEXT);
|
---|
| 2793 | SetDictInt("A_COLOR", A_COLOR);
|
---|
[2] | 2794 |
|
---|
[391] | 2795 | /* The following are never available with strict SYSV curses */
|
---|
[2] | 2796 | #ifdef A_HORIZONTAL
|
---|
[391] | 2797 | SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
|
---|
[2] | 2798 | #endif
|
---|
| 2799 | #ifdef A_LEFT
|
---|
[391] | 2800 | SetDictInt("A_LEFT", A_LEFT);
|
---|
[2] | 2801 | #endif
|
---|
| 2802 | #ifdef A_LOW
|
---|
[391] | 2803 | SetDictInt("A_LOW", A_LOW);
|
---|
[2] | 2804 | #endif
|
---|
| 2805 | #ifdef A_RIGHT
|
---|
[391] | 2806 | SetDictInt("A_RIGHT", A_RIGHT);
|
---|
[2] | 2807 | #endif
|
---|
| 2808 | #ifdef A_TOP
|
---|
[391] | 2809 | SetDictInt("A_TOP", A_TOP);
|
---|
[2] | 2810 | #endif
|
---|
| 2811 | #ifdef A_VERTICAL
|
---|
[391] | 2812 | SetDictInt("A_VERTICAL", A_VERTICAL);
|
---|
[2] | 2813 | #endif
|
---|
| 2814 |
|
---|
[391] | 2815 | SetDictInt("COLOR_BLACK", COLOR_BLACK);
|
---|
| 2816 | SetDictInt("COLOR_RED", COLOR_RED);
|
---|
| 2817 | SetDictInt("COLOR_GREEN", COLOR_GREEN);
|
---|
| 2818 | SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
|
---|
| 2819 | SetDictInt("COLOR_BLUE", COLOR_BLUE);
|
---|
| 2820 | SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
|
---|
| 2821 | SetDictInt("COLOR_CYAN", COLOR_CYAN);
|
---|
| 2822 | SetDictInt("COLOR_WHITE", COLOR_WHITE);
|
---|
[2] | 2823 |
|
---|
| 2824 | #ifdef NCURSES_MOUSE_VERSION
|
---|
[391] | 2825 | /* Mouse-related constants */
|
---|
| 2826 | SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
|
---|
| 2827 | SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
|
---|
| 2828 | SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
|
---|
| 2829 | SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
|
---|
| 2830 | SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
|
---|
[2] | 2831 |
|
---|
[391] | 2832 | SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
|
---|
| 2833 | SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
|
---|
| 2834 | SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
|
---|
| 2835 | SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
|
---|
| 2836 | SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
|
---|
[2] | 2837 |
|
---|
[391] | 2838 | SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
|
---|
| 2839 | SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
|
---|
| 2840 | SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
|
---|
| 2841 | SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
|
---|
| 2842 | SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
|
---|
[2] | 2843 |
|
---|
[391] | 2844 | SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
|
---|
| 2845 | SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
|
---|
| 2846 | SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
|
---|
| 2847 | SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
|
---|
| 2848 | SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
|
---|
[2] | 2849 |
|
---|
[391] | 2850 | SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
|
---|
| 2851 | SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
|
---|
| 2852 | SetDictInt("BUTTON_ALT", BUTTON_ALT);
|
---|
[2] | 2853 |
|
---|
[391] | 2854 | SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
|
---|
| 2855 | SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
|
---|
[2] | 2856 | #endif
|
---|
[391] | 2857 | /* Now set everything up for KEY_ variables */
|
---|
| 2858 | {
|
---|
| 2859 | int key;
|
---|
| 2860 | char *key_n;
|
---|
| 2861 | char *key_n2;
|
---|
[2] | 2862 | #if !defined(__NetBSD__)
|
---|
[391] | 2863 | for (key=KEY_MIN;key < KEY_MAX; key++) {
|
---|
| 2864 | key_n = (char *)keyname(key);
|
---|
| 2865 | if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
|
---|
| 2866 | continue;
|
---|
| 2867 | if (strncmp(key_n,"KEY_F(",6)==0) {
|
---|
| 2868 | char *p1, *p2;
|
---|
| 2869 | key_n2 = malloc(strlen(key_n)+1);
|
---|
| 2870 | if (!key_n2) {
|
---|
| 2871 | PyErr_NoMemory();
|
---|
| 2872 | break;
|
---|
| 2873 | }
|
---|
| 2874 | p1 = key_n;
|
---|
| 2875 | p2 = key_n2;
|
---|
| 2876 | while (*p1) {
|
---|
| 2877 | if (*p1 != '(' && *p1 != ')') {
|
---|
| 2878 | *p2 = *p1;
|
---|
| 2879 | p2++;
|
---|
| 2880 | }
|
---|
| 2881 | p1++;
|
---|
| 2882 | }
|
---|
| 2883 | *p2 = (char)0;
|
---|
| 2884 | } else
|
---|
| 2885 | key_n2 = key_n;
|
---|
| 2886 | SetDictInt(key_n2,key);
|
---|
| 2887 | if (key_n2 != key_n)
|
---|
| 2888 | free(key_n2);
|
---|
| 2889 | }
|
---|
[2] | 2890 | #endif
|
---|
[391] | 2891 | SetDictInt("KEY_MIN", KEY_MIN);
|
---|
| 2892 | SetDictInt("KEY_MAX", KEY_MAX);
|
---|
| 2893 | }
|
---|
[2] | 2894 | }
|
---|