Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1 | /* |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2 | * This is a curses module for Python. |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 3 | * |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 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. |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 7 | * |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 8 | * Version 1.5b1, heavily extended for ncurses by Oliver Andrich: |
| 9 | * Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany. |
| 10 | * |
Andrew M. Kuchling | 3adefcc | 2002-10-30 21:08:34 +0000 | [diff] [blame] | 11 | * Tidied for Python 1.6, and currently maintained by <amk@amk.ca>. |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 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 | */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 33 | |
Andrew M. Kuchling | fb6bbf5 | 2000-07-27 11:58:01 +0000 | [diff] [blame] | 34 | /* |
| 35 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 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. |
Andrew M. Kuchling | fb6bbf5 | 2000-07-27 11:58:01 +0000 | [diff] [blame] | 40 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 41 | Here's a list of currently unsupported functions: |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 42 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 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 |
Andrew M. Kuchling | fb6bbf5 | 2000-07-27 11:58:01 +0000 | [diff] [blame] | 53 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 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 |
Andrew M. Kuchling | fb6bbf5 | 2000-07-27 11:58:01 +0000 | [diff] [blame] | 58 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 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 |
Andrew M. Kuchling | 2824d7f | 2000-12-15 00:44:02 +0000 | [diff] [blame] | 74 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 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 |
Andrew M. Kuchling | 2824d7f | 2000-12-15 00:44:02 +0000 | [diff] [blame] | 93 | |
| 94 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 95 | */ |
Andrew M. Kuchling | fb6bbf5 | 2000-07-27 11:58:01 +0000 | [diff] [blame] | 96 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 97 | /* Release Number */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 98 | |
Andrew M. Kuchling | 16e65a0 | 2001-10-20 16:05:52 +0000 | [diff] [blame] | 99 | char *PyCursesVersion = "2.2"; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 100 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 101 | /* Includes */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 102 | |
Mark Dickinson | e047cfa | 2010-05-11 17:57:09 +0000 | [diff] [blame] | 103 | #define PY_SSIZE_T_CLEAN |
| 104 | |
Guido van Rossum | 602099a | 1994-09-14 13:32:22 +0000 | [diff] [blame] | 105 | #include "Python.h" |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 106 | |
Benjamin Peterson | b173f78 | 2009-05-05 22:31:58 +0000 | [diff] [blame] | 107 | |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 108 | #ifdef __hpux |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 109 | #define STRICT_SYSV_CURSES |
| 110 | #endif |
| 111 | |
Guido van Rossum | 858ca0f | 2001-04-10 19:53:37 +0000 | [diff] [blame] | 112 | #define CURSES_MODULE |
| 113 | #include "py_curses.h" |
| 114 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 115 | /* These prototypes are in <term.h>, but including this header |
| 116 | #defines many common symbols (such as "lines") which breaks the |
| 117 | curses module in other ways. So the code will just specify |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 118 | explicit prototypes here. */ |
| 119 | extern int setupterm(char *,int,int *); |
Fred Drake | 0368bc4 | 2001-07-19 20:48:32 +0000 | [diff] [blame] | 120 | #ifdef __sgi |
| 121 | #include <term.h> |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 122 | #endif |
| 123 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 124 | #ifdef HAVE_LANGINFO_H |
| 125 | #include <langinfo.h> |
| 126 | #endif |
| 127 | |
Martin v. Löwis | 21ee409 | 2002-09-30 16:19:48 +0000 | [diff] [blame] | 128 | #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5)) |
Andrew M. Kuchling | bf68026 | 2000-07-25 12:37:41 +0000 | [diff] [blame] | 129 | #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 130 | typedef chtype attr_t; /* No attr_t type is available */ |
Guido van Rossum | 1266a01 | 1996-02-25 04:50:31 +0000 | [diff] [blame] | 131 | #endif |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 132 | |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 133 | #if defined(_AIX) |
| 134 | #define STRICT_SYSV_CURSES |
| 135 | #endif |
| 136 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 137 | /* Definition of exception curses.error */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 138 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 139 | static PyObject *PyCursesError; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 140 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 141 | /* Tells whether setupterm() has been called to initialise terminfo. */ |
| 142 | static int initialised_setupterm = FALSE; |
| 143 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 144 | /* Tells whether initscr() has been called to initialise curses. */ |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 145 | static int initialised = FALSE; |
| 146 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 147 | /* Tells whether start_color() has been called to initialise color usage. */ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 148 | static int initialisedcolors = FALSE; |
| 149 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 150 | static char *screen_encoding = NULL; |
| 151 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 152 | /* Utility Macros */ |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 153 | #define PyCursesSetupTermCalled \ |
| 154 | if (initialised_setupterm != TRUE) { \ |
| 155 | PyErr_SetString(PyCursesError, \ |
| 156 | "must call (at least) setupterm() first"); \ |
| 157 | return 0; } |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 158 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 159 | #define PyCursesInitialised \ |
| 160 | if (initialised != TRUE) { \ |
| 161 | PyErr_SetString(PyCursesError, \ |
| 162 | "must call initscr() first"); \ |
| 163 | return 0; } |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 164 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 165 | #define PyCursesInitialisedColor \ |
| 166 | if (initialisedcolors != TRUE) { \ |
| 167 | PyErr_SetString(PyCursesError, \ |
| 168 | "must call start_color() first"); \ |
| 169 | return 0; } |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 170 | |
Andrew M. Kuchling | 52a14c3 | 2005-06-09 17:53:27 +0000 | [diff] [blame] | 171 | #ifndef MIN |
| 172 | #define MIN(x,y) ((x) < (y) ? (x) : (y)) |
| 173 | #endif |
| 174 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 175 | /* Utility Functions */ |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 176 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 177 | /* |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 178 | * Check the return code from a curses function and return None |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 179 | * or raise an exception as appropriate. These are exported using the |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 180 | * capsule API. |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 181 | */ |
| 182 | |
| 183 | static PyObject * |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 184 | PyCursesCheckERR(int code, const char *fname) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 185 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 186 | if (code != ERR) { |
| 187 | Py_INCREF(Py_None); |
| 188 | return Py_None; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 189 | } else { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 190 | if (fname == NULL) { |
| 191 | PyErr_SetString(PyCursesError, catchall_ERR); |
| 192 | } else { |
| 193 | PyErr_Format(PyCursesError, "%s() returned ERR", fname); |
| 194 | } |
| 195 | return NULL; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 196 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 199 | /* Convert an object to a byte (an integer of type chtype): |
| 200 | |
| 201 | - int |
| 202 | - bytes of length 1 |
| 203 | - str of length 1 |
| 204 | |
| 205 | Return 1 on success, 0 on error (invalid type or integer overflow). */ |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 206 | static int |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 207 | PyCurses_ConvertToChtype(PyCursesWindowObject *win, PyObject *obj, chtype *ch) |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 208 | { |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 209 | long value; |
| 210 | if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) { |
| 211 | value = (unsigned char)PyBytes_AsString(obj)[0]; |
| 212 | } |
| 213 | else if (PyUnicode_Check(obj)) { |
| 214 | if (PyUnicode_GetLength(obj) != 1) { |
| 215 | PyErr_Format(PyExc_TypeError, |
| 216 | "expect bytes or str of length 1, or int, " |
| 217 | "got a str of length %zi", |
| 218 | PyUnicode_GET_LENGTH(obj)); |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 219 | return 0; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 220 | } |
| 221 | value = PyUnicode_READ_CHAR(obj, 0); |
| 222 | if (128 < value) { |
| 223 | PyObject *bytes; |
| 224 | const char *encoding; |
| 225 | if (win) |
| 226 | encoding = win->encoding; |
| 227 | else |
| 228 | encoding = screen_encoding; |
| 229 | bytes = PyUnicode_AsEncodedObject(obj, encoding, NULL); |
| 230 | if (bytes == NULL) |
| 231 | return 0; |
| 232 | if (PyBytes_GET_SIZE(bytes) == 1) |
| 233 | value = (unsigned char)PyBytes_AS_STRING(bytes)[0]; |
| 234 | else |
| 235 | value = -1; |
| 236 | Py_DECREF(bytes); |
| 237 | if (value < 0) |
| 238 | goto overflow; |
| 239 | } |
| 240 | } |
| 241 | else if (PyLong_CheckExact(obj)) { |
| 242 | int long_overflow; |
| 243 | value = PyLong_AsLongAndOverflow(obj, &long_overflow); |
| 244 | if (long_overflow) |
| 245 | goto overflow; |
| 246 | } |
| 247 | else { |
| 248 | PyErr_Format(PyExc_TypeError, |
| 249 | "expect bytes or str of length 1, or int, got %s", |
| 250 | Py_TYPE(obj)->tp_name); |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 251 | return 0; |
| 252 | } |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 253 | *ch = (chtype)value; |
| 254 | if ((long)*ch != value) |
| 255 | goto overflow; |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 256 | return 1; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 257 | |
| 258 | overflow: |
| 259 | PyErr_SetString(PyExc_OverflowError, |
| 260 | "byte doesn't fit in chtype"); |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | /* Convert an object to a byte (chtype) or a character (cchar_t): |
| 265 | |
| 266 | - int |
| 267 | - bytes of length 1 |
| 268 | - str of length 1 |
| 269 | |
| 270 | Return: |
| 271 | |
| 272 | - 2 if obj is a character (written into *wch) |
| 273 | - 1 if obj is a byte (written into *ch) |
| 274 | - 0 on error: raise an exception */ |
| 275 | static int |
| 276 | PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj, |
| 277 | chtype *ch |
| 278 | #ifdef HAVE_NCURSESW |
| 279 | , cchar_t *wch |
| 280 | #endif |
| 281 | ) |
| 282 | { |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 283 | long value; |
| 284 | #ifdef HAVE_NCURSESW |
| 285 | wchar_t buffer[2]; |
| 286 | #endif |
| 287 | |
| 288 | if (PyUnicode_Check(obj)) { |
| 289 | #ifdef HAVE_NCURSESW |
| 290 | if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) { |
| 291 | PyErr_Format(PyExc_TypeError, |
| 292 | "expect bytes or str of length 1, or int, " |
| 293 | "got a str of length %zi", |
| 294 | PyUnicode_GET_LENGTH(obj)); |
| 295 | return 0; |
| 296 | } |
| 297 | memset(wch->chars, 0, sizeof(wch->chars)); |
| 298 | wch->chars[0] = buffer[0]; |
| 299 | return 2; |
| 300 | #else |
| 301 | return PyCurses_ConvertToChtype(win, obj, ch); |
| 302 | #endif |
| 303 | } |
| 304 | else if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) { |
| 305 | value = (unsigned char)PyBytes_AsString(obj)[0]; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 306 | } |
| 307 | else if (PyLong_CheckExact(obj)) { |
| 308 | int overflow; |
| 309 | value = PyLong_AsLongAndOverflow(obj, &overflow); |
| 310 | if (overflow) { |
| 311 | PyErr_SetString(PyExc_OverflowError, |
| 312 | "int doesn't fit in long"); |
| 313 | return 0; |
| 314 | } |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 315 | } |
| 316 | else { |
| 317 | PyErr_Format(PyExc_TypeError, |
| 318 | "expect bytes or str of length 1, or int, got %s", |
| 319 | Py_TYPE(obj)->tp_name); |
| 320 | return 0; |
| 321 | } |
Victor Stinner | 9f16e44 | 2012-09-01 15:00:34 +0200 | [diff] [blame] | 322 | |
| 323 | *ch = (chtype)value; |
| 324 | if ((long)*ch != value) { |
| 325 | PyErr_Format(PyExc_OverflowError, |
| 326 | "byte doesn't fit in chtype"); |
| 327 | return 0; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 328 | } |
Victor Stinner | 9f16e44 | 2012-09-01 15:00:34 +0200 | [diff] [blame] | 329 | return 1; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /* Convert an object to a byte string (char*) or a wide character string |
| 333 | (wchar_t*). Return: |
| 334 | |
| 335 | - 2 if obj is a character string (written into *wch) |
| 336 | - 1 if obj is a byte string (written into *bytes) |
| 337 | - 0 on error: raise an exception */ |
| 338 | static int |
| 339 | PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj, |
| 340 | PyObject **bytes, wchar_t **wstr) |
| 341 | { |
| 342 | if (PyUnicode_Check(obj)) { |
| 343 | #ifdef HAVE_NCURSESW |
| 344 | assert (wstr != NULL); |
| 345 | *wstr = PyUnicode_AsWideCharString(obj, NULL); |
| 346 | if (*wstr == NULL) |
| 347 | return 0; |
| 348 | return 2; |
| 349 | #else |
| 350 | assert (wstr == NULL); |
| 351 | *bytes = PyUnicode_AsEncodedObject(obj, win->encoding, NULL); |
| 352 | if (*bytes == NULL) |
| 353 | return 0; |
| 354 | return 1; |
| 355 | #endif |
| 356 | } |
| 357 | else if (PyBytes_Check(obj)) { |
| 358 | Py_INCREF(obj); |
| 359 | *bytes = obj; |
| 360 | return 1; |
| 361 | } |
| 362 | |
| 363 | PyErr_Format(PyExc_TypeError, "expect bytes or str, got %s", |
| 364 | Py_TYPE(obj)->tp_name); |
| 365 | return 0; |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Benjamin Peterson | 21896a3 | 2010-03-21 22:03:03 +0000 | [diff] [blame] | 368 | /* Function versions of the 3 functions for testing whether curses has been |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 369 | initialised or not. */ |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 370 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 371 | static int func_PyCursesSetupTermCalled(void) |
| 372 | { |
| 373 | PyCursesSetupTermCalled; |
| 374 | return 1; |
| 375 | } |
| 376 | |
| 377 | static int func_PyCursesInitialised(void) |
| 378 | { |
| 379 | PyCursesInitialised; |
| 380 | return 1; |
| 381 | } |
| 382 | |
| 383 | static int func_PyCursesInitialisedColor(void) |
| 384 | { |
| 385 | PyCursesInitialisedColor; |
| 386 | return 1; |
| 387 | } |
| 388 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 389 | /***************************************************************************** |
| 390 | The Window Object |
| 391 | ******************************************************************************/ |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 392 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 393 | /* Definition of the window type */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 394 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 395 | PyTypeObject PyCursesWindow_Type; |
| 396 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 397 | /* Function prototype macros for Window object |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 398 | |
| 399 | X - function name |
| 400 | TYPE - parameter Type |
| 401 | ERGSTR - format string for construction of the return value |
| 402 | PARSESTR - format string for argument parsing |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 403 | */ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 404 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 405 | #define Window_NoArgNoReturnFunction(X) \ |
| 406 | static PyObject *PyCursesWindow_ ## X \ |
| 407 | (PyCursesWindowObject *self, PyObject *args) \ |
| 408 | { return PyCursesCheckERR(X(self->win), # X); } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 409 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 410 | #define Window_NoArgTrueFalseFunction(X) \ |
| 411 | static PyObject * PyCursesWindow_ ## X \ |
| 412 | (PyCursesWindowObject *self) \ |
| 413 | { \ |
| 414 | if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \ |
| 415 | else { Py_INCREF(Py_True); return Py_True; } } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 416 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 417 | #define Window_NoArgNoReturnVoidFunction(X) \ |
| 418 | static PyObject * PyCursesWindow_ ## X \ |
| 419 | (PyCursesWindowObject *self) \ |
| 420 | { \ |
| 421 | X(self->win); Py_INCREF(Py_None); return Py_None; } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 422 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 423 | #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \ |
| 424 | static PyObject * PyCursesWindow_ ## X \ |
| 425 | (PyCursesWindowObject *self) \ |
| 426 | { \ |
| 427 | TYPE arg1, arg2; \ |
| 428 | X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 429 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 430 | #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \ |
| 431 | static PyObject * PyCursesWindow_ ## X \ |
| 432 | (PyCursesWindowObject *self, PyObject *args) \ |
| 433 | { \ |
| 434 | TYPE arg1; \ |
| 435 | if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \ |
| 436 | X(self->win,arg1); Py_INCREF(Py_None); return Py_None; } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 437 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 438 | #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \ |
| 439 | static PyObject * PyCursesWindow_ ## X \ |
| 440 | (PyCursesWindowObject *self, PyObject *args) \ |
| 441 | { \ |
| 442 | TYPE arg1; \ |
| 443 | if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \ |
| 444 | return PyCursesCheckERR(X(self->win, arg1), # X); } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 445 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 446 | #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \ |
| 447 | static PyObject * PyCursesWindow_ ## X \ |
| 448 | (PyCursesWindowObject *self, PyObject *args) \ |
| 449 | { \ |
| 450 | TYPE arg1, arg2; \ |
| 451 | if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \ |
| 452 | return PyCursesCheckERR(X(self->win, arg1, arg2), # X); } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 453 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 454 | /* ------------- WINDOW routines --------------- */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 455 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 456 | Window_NoArgNoReturnFunction(untouchwin) |
| 457 | Window_NoArgNoReturnFunction(touchwin) |
| 458 | Window_NoArgNoReturnFunction(redrawwin) |
| 459 | Window_NoArgNoReturnFunction(winsertln) |
| 460 | Window_NoArgNoReturnFunction(werase) |
| 461 | Window_NoArgNoReturnFunction(wdeleteln) |
| 462 | |
| 463 | Window_NoArgTrueFalseFunction(is_wintouched) |
| 464 | |
| 465 | Window_NoArgNoReturnVoidFunction(wsyncup) |
| 466 | Window_NoArgNoReturnVoidFunction(wsyncdown) |
| 467 | Window_NoArgNoReturnVoidFunction(wstandend) |
| 468 | Window_NoArgNoReturnVoidFunction(wstandout) |
| 469 | Window_NoArgNoReturnVoidFunction(wcursyncup) |
| 470 | Window_NoArgNoReturnVoidFunction(wclrtoeol) |
| 471 | Window_NoArgNoReturnVoidFunction(wclrtobot) |
| 472 | Window_NoArgNoReturnVoidFunction(wclear) |
| 473 | |
| 474 | Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)") |
| 475 | Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 476 | Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay") |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 477 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 478 | Window_NoArg2TupleReturnFunction(getyx, int, "ii") |
| 479 | Window_NoArg2TupleReturnFunction(getbegyx, int, "ii") |
| 480 | Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii") |
| 481 | Window_NoArg2TupleReturnFunction(getparyx, int, "ii") |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 482 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 483 | Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)") |
| 484 | Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 485 | #if defined(__NetBSD__) |
| 486 | Window_OneArgNoReturnVoidFunction(keypad, int, "i;True(1) or False(0)") |
| 487 | #else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 488 | Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 489 | #endif |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 490 | Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 491 | #if defined(__NetBSD__) |
| 492 | Window_OneArgNoReturnVoidFunction(nodelay, int, "i;True(1) or False(0)") |
| 493 | #else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 494 | Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 495 | #endif |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 496 | Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)") |
| 497 | Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 498 | Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines") |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 499 | Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)") |
| 500 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 501 | Window_TwoArgNoReturnFunction(mvwin, int, "ii;y,x") |
| 502 | Window_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x") |
| 503 | Window_TwoArgNoReturnFunction(wmove, int, "ii;y,x") |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 504 | #ifndef STRICT_SYSV_CURSES |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 505 | Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns") |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 506 | #endif |
| 507 | |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 508 | /* Allocation and deallocation of Window Objects */ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 509 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 510 | static PyObject * |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 511 | PyCursesWindow_New(WINDOW *win, const char *encoding) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 512 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 513 | PyCursesWindowObject *wo; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 514 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 515 | if (encoding == NULL) { |
| 516 | #if defined(MS_WINDOWS) |
| 517 | char *buffer[100]; |
| 518 | UINT cp; |
| 519 | cp = GetConsoleOutputCP(); |
| 520 | if (cp != 0) { |
| 521 | PyOS_snprintf(buffer, sizeof(buffer), "cp%u", cp); |
| 522 | encoding = buffer; |
| 523 | } |
| 524 | #elif defined(CODESET) |
| 525 | const char *codeset = nl_langinfo(CODESET); |
| 526 | if (codeset != NULL && codeset[0] != 0) |
| 527 | encoding = codeset; |
| 528 | #endif |
| 529 | if (encoding == NULL) |
| 530 | encoding = "utf-8"; |
| 531 | } |
| 532 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 533 | wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type); |
| 534 | if (wo == NULL) return NULL; |
| 535 | wo->win = win; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 536 | wo->encoding = strdup(encoding); |
| 537 | if (wo->encoding == NULL) { |
| 538 | Py_DECREF(wo); |
| 539 | PyErr_NoMemory(); |
| 540 | return NULL; |
| 541 | } |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 542 | return (PyObject *)wo; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | static void |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 546 | PyCursesWindow_Dealloc(PyCursesWindowObject *wo) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 547 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 548 | if (wo->win != stdscr) delwin(wo->win); |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 549 | if (wo->encoding != NULL) |
| 550 | free(wo->encoding); |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 551 | PyObject_DEL(wo); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 554 | /* Addch, Addstr, Addnstr */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 555 | |
| 556 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 557 | PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 558 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 559 | int rtn, x, y, use_xy = FALSE; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 560 | PyObject *chobj; |
| 561 | int type; |
| 562 | chtype ch; |
| 563 | #ifdef HAVE_NCURSESW |
| 564 | cchar_t wch; |
| 565 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 566 | attr_t attr = A_NORMAL; |
| 567 | long lattr; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 568 | const char *funcname; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 569 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 570 | switch (PyTuple_Size(args)) { |
| 571 | case 1: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 572 | if (!PyArg_ParseTuple(args, "O;ch or int", &chobj)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 573 | return NULL; |
| 574 | break; |
| 575 | case 2: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 576 | if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &chobj, &lattr)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 577 | return NULL; |
| 578 | attr = lattr; |
| 579 | break; |
| 580 | case 3: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 581 | if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &chobj)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 582 | return NULL; |
| 583 | use_xy = TRUE; |
| 584 | break; |
| 585 | case 4: |
| 586 | if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 587 | &y, &x, &chobj, &lattr)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 588 | return NULL; |
| 589 | attr = lattr; |
| 590 | use_xy = TRUE; |
| 591 | break; |
| 592 | default: |
| 593 | PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments"); |
| 594 | return NULL; |
| 595 | } |
| 596 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 597 | #ifdef HAVE_NCURSESW |
| 598 | type = PyCurses_ConvertToCchar_t(self, chobj, &ch, &wch); |
| 599 | if (type == 2) { |
| 600 | funcname = "add_wch"; |
| 601 | wch.attr = attr; |
| 602 | if (use_xy == TRUE) |
| 603 | rtn = mvwadd_wch(self->win,y,x, &wch); |
| 604 | else { |
| 605 | rtn = wadd_wch(self->win, &wch); |
| 606 | } |
| 607 | } |
| 608 | else |
| 609 | #else |
| 610 | type = PyCurses_ConvertToCchar_t(self, chobj, &ch); |
| 611 | #endif |
| 612 | if (type == 1) { |
| 613 | funcname = "addch"; |
| 614 | if (use_xy == TRUE) |
| 615 | rtn = mvwaddch(self->win,y,x, ch | attr); |
| 616 | else { |
| 617 | rtn = waddch(self->win, ch | attr); |
| 618 | } |
| 619 | } |
| 620 | else { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 621 | return NULL; |
| 622 | } |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 623 | return PyCursesCheckERR(rtn, funcname); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 627 | PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 628 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 629 | int rtn; |
| 630 | int x, y; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 631 | int strtype; |
Benjamin Peterson | 5e54519 | 2012-03-14 18:21:35 -0500 | [diff] [blame] | 632 | PyObject *strobj, *bytesobj = NULL; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 633 | #ifdef HAVE_NCURSESW |
| 634 | wchar_t *wstr = NULL; |
| 635 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 636 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 637 | long lattr; |
| 638 | int use_xy = FALSE, use_attr = FALSE; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 639 | const char *funcname; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 640 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 641 | switch (PyTuple_Size(args)) { |
| 642 | case 1: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 643 | if (!PyArg_ParseTuple(args,"O;str", &strobj)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 644 | return NULL; |
| 645 | break; |
| 646 | case 2: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 647 | if (!PyArg_ParseTuple(args,"Ol;str,attr", &strobj, &lattr)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 648 | return NULL; |
| 649 | attr = lattr; |
| 650 | use_attr = TRUE; |
| 651 | break; |
| 652 | case 3: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 653 | if (!PyArg_ParseTuple(args,"iiO;int,int,str", &y, &x, &strobj)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 654 | return NULL; |
| 655 | use_xy = TRUE; |
| 656 | break; |
| 657 | case 4: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 658 | if (!PyArg_ParseTuple(args,"iiOl;int,int,str,attr", &y, &x, &strobj, &lattr)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 659 | return NULL; |
| 660 | attr = lattr; |
| 661 | use_xy = use_attr = TRUE; |
| 662 | break; |
| 663 | default: |
| 664 | PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments"); |
| 665 | return NULL; |
| 666 | } |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 667 | #ifdef HAVE_NCURSESW |
| 668 | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); |
| 669 | #else |
| 670 | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); |
| 671 | #endif |
| 672 | if (strtype == 0) |
| 673 | return NULL; |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 674 | if (use_attr == TRUE) { |
| 675 | attr_old = getattrs(self->win); |
| 676 | (void)wattrset(self->win,attr); |
| 677 | } |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 678 | #ifdef HAVE_NCURSESW |
| 679 | if (strtype == 2) { |
| 680 | funcname = "addwstr"; |
| 681 | if (use_xy == TRUE) |
| 682 | rtn = mvwaddwstr(self->win,y,x,wstr); |
| 683 | else |
| 684 | rtn = waddwstr(self->win,wstr); |
| 685 | PyMem_Free(wstr); |
| 686 | } |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 687 | else |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 688 | #endif |
| 689 | { |
| 690 | char *str = PyBytes_AS_STRING(bytesobj); |
| 691 | funcname = "addstr"; |
| 692 | if (use_xy == TRUE) |
| 693 | rtn = mvwaddstr(self->win,y,x,str); |
| 694 | else |
| 695 | rtn = waddstr(self->win,str); |
| 696 | Py_DECREF(bytesobj); |
| 697 | } |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 698 | if (use_attr == TRUE) |
| 699 | (void)wattrset(self->win,attr_old); |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 700 | return PyCursesCheckERR(rtn, funcname); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 701 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 702 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 703 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 704 | PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 705 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 706 | int rtn, x, y, n; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 707 | int strtype; |
Benjamin Peterson | 5e54519 | 2012-03-14 18:21:35 -0500 | [diff] [blame] | 708 | PyObject *strobj, *bytesobj = NULL; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 709 | #ifdef HAVE_NCURSESW |
| 710 | wchar_t *wstr = NULL; |
| 711 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 712 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 713 | long lattr; |
| 714 | int use_xy = FALSE, use_attr = FALSE; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 715 | const char *funcname; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 716 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 717 | switch (PyTuple_Size(args)) { |
| 718 | case 2: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 719 | if (!PyArg_ParseTuple(args,"Oi;str,n", &strobj, &n)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 720 | return NULL; |
| 721 | break; |
| 722 | case 3: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 723 | if (!PyArg_ParseTuple(args,"Oil;str,n,attr", &strobj, &n, &lattr)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 724 | return NULL; |
| 725 | attr = lattr; |
| 726 | use_attr = TRUE; |
| 727 | break; |
| 728 | case 4: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 729 | if (!PyArg_ParseTuple(args,"iiOi;y,x,str,n", &y, &x, &strobj, &n)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 730 | return NULL; |
| 731 | use_xy = TRUE; |
| 732 | break; |
| 733 | case 5: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 734 | if (!PyArg_ParseTuple(args,"iiOil;y,x,str,n,attr", &y, &x, &strobj, &n, &lattr)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 735 | return NULL; |
| 736 | attr = lattr; |
| 737 | use_xy = use_attr = TRUE; |
| 738 | break; |
| 739 | default: |
| 740 | PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments"); |
| 741 | return NULL; |
| 742 | } |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 743 | #ifdef HAVE_NCURSESW |
| 744 | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); |
| 745 | #else |
| 746 | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); |
| 747 | #endif |
| 748 | if (strtype == 0) |
| 749 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 750 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 751 | if (use_attr == TRUE) { |
| 752 | attr_old = getattrs(self->win); |
| 753 | (void)wattrset(self->win,attr); |
| 754 | } |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 755 | #ifdef HAVE_NCURSESW |
| 756 | if (strtype == 2) { |
| 757 | funcname = "addnwstr"; |
| 758 | if (use_xy == TRUE) |
| 759 | rtn = mvwaddnwstr(self->win,y,x,wstr,n); |
| 760 | else |
| 761 | rtn = waddnwstr(self->win,wstr,n); |
| 762 | PyMem_Free(wstr); |
| 763 | } |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 764 | else |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 765 | #endif |
| 766 | { |
| 767 | char *str = PyBytes_AS_STRING(bytesobj); |
| 768 | funcname = "addnstr"; |
| 769 | if (use_xy == TRUE) |
| 770 | rtn = mvwaddnstr(self->win,y,x,str,n); |
| 771 | else |
| 772 | rtn = waddnstr(self->win,str,n); |
| 773 | Py_DECREF(bytesobj); |
| 774 | } |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 775 | if (use_attr == TRUE) |
| 776 | (void)wattrset(self->win,attr_old); |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 777 | return PyCursesCheckERR(rtn, funcname); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 781 | PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 782 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 783 | PyObject *temp; |
| 784 | chtype bkgd; |
| 785 | attr_t attr = A_NORMAL; |
| 786 | long lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 787 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 788 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 789 | case 1: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 790 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) |
| 791 | return NULL; |
| 792 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 793 | case 2: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 794 | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) |
| 795 | return NULL; |
| 796 | attr = lattr; |
| 797 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 798 | default: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 799 | PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments"); |
| 800 | return NULL; |
| 801 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 802 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 803 | if (!PyCurses_ConvertToChtype(self, temp, &bkgd)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 804 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 805 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 806 | return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | static PyObject * |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 810 | PyCursesWindow_AttrOff(PyCursesWindowObject *self, PyObject *args) |
| 811 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 812 | long lattr; |
| 813 | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) |
| 814 | return NULL; |
| 815 | return PyCursesCheckERR(wattroff(self->win, (attr_t)lattr), "attroff"); |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | static PyObject * |
| 819 | PyCursesWindow_AttrOn(PyCursesWindowObject *self, PyObject *args) |
| 820 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 821 | long lattr; |
| 822 | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) |
| 823 | return NULL; |
| 824 | return PyCursesCheckERR(wattron(self->win, (attr_t)lattr), "attron"); |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | static PyObject * |
| 828 | PyCursesWindow_AttrSet(PyCursesWindowObject *self, PyObject *args) |
| 829 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 830 | long lattr; |
| 831 | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) |
| 832 | return NULL; |
| 833 | return PyCursesCheckERR(wattrset(self->win, (attr_t)lattr), "attrset"); |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 837 | PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 838 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 839 | PyObject *temp; |
| 840 | chtype bkgd; |
| 841 | attr_t attr = A_NORMAL; |
| 842 | long lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 843 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 844 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 845 | case 1: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 846 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) |
| 847 | return NULL; |
| 848 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 849 | case 2: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 850 | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) |
| 851 | return NULL; |
| 852 | attr = lattr; |
| 853 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 854 | default: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 855 | PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments"); |
| 856 | return NULL; |
| 857 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 858 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 859 | if (!PyCurses_ConvertToChtype(self, temp, &bkgd)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 860 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 861 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 862 | wbkgdset(self->win, bkgd | attr); |
| 863 | return PyCursesCheckERR(0, "bkgdset"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 867 | PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 868 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 869 | PyObject *temp[8]; |
| 870 | chtype ch[8]; |
| 871 | int i; |
Andrew M. Kuchling | 16e65a0 | 2001-10-20 16:05:52 +0000 | [diff] [blame] | 872 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 873 | /* Clear the array of parameters */ |
| 874 | for(i=0; i<8; i++) { |
| 875 | temp[i] = NULL; |
| 876 | ch[i] = 0; |
| 877 | } |
Andrew M. Kuchling | 16e65a0 | 2001-10-20 16:05:52 +0000 | [diff] [blame] | 878 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 879 | if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br", |
| 880 | &temp[0], &temp[1], &temp[2], &temp[3], |
| 881 | &temp[4], &temp[5], &temp[6], &temp[7])) |
| 882 | return NULL; |
| 883 | |
| 884 | for(i=0; i<8; i++) { |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 885 | if (temp[i] != NULL && !PyCurses_ConvertToChtype(self, temp[i], &ch[i])) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 886 | return NULL; |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | wborder(self->win, |
| 890 | ch[0], ch[1], ch[2], ch[3], |
| 891 | ch[4], ch[5], ch[6], ch[7]); |
| 892 | Py_INCREF(Py_None); |
| 893 | return Py_None; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 897 | PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 898 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 899 | chtype ch1=0,ch2=0; |
| 900 | switch(PyTuple_Size(args)){ |
| 901 | case 0: break; |
| 902 | default: |
| 903 | if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2)) |
| 904 | return NULL; |
| 905 | } |
| 906 | box(self->win,ch1,ch2); |
| 907 | Py_INCREF(Py_None); |
| 908 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 911 | #if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION) |
| 912 | #define py_mvwdelch mvwdelch |
| 913 | #else |
| 914 | int py_mvwdelch(WINDOW *w, int y, int x) |
| 915 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 916 | mvwdelch(w,y,x); |
| 917 | /* On HP/UX, mvwdelch already returns. On other systems, |
| 918 | we may well run into this return statement. */ |
| 919 | return 0; |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 920 | } |
| 921 | #endif |
| 922 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 923 | /* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */ |
| 924 | |
| 925 | static PyObject * |
| 926 | PyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args) |
| 927 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 928 | int rtn; |
| 929 | int x, y; |
| 930 | int num = -1; |
| 931 | short color; |
| 932 | attr_t attr = A_NORMAL; |
| 933 | long lattr; |
| 934 | int use_xy = FALSE; |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 935 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 936 | switch (PyTuple_Size(args)) { |
| 937 | case 1: |
| 938 | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) |
| 939 | return NULL; |
| 940 | attr = lattr; |
| 941 | break; |
| 942 | case 2: |
| 943 | if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr)) |
| 944 | return NULL; |
| 945 | attr = lattr; |
| 946 | break; |
| 947 | case 3: |
| 948 | if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr)) |
| 949 | return NULL; |
| 950 | attr = lattr; |
| 951 | use_xy = TRUE; |
| 952 | break; |
| 953 | case 4: |
| 954 | if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr)) |
| 955 | return NULL; |
| 956 | attr = lattr; |
| 957 | use_xy = TRUE; |
| 958 | break; |
| 959 | default: |
| 960 | PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments"); |
| 961 | return NULL; |
| 962 | } |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 963 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 964 | color = (short)((attr >> 8) & 0xff); |
| 965 | attr = attr - (color << 8); |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 966 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 967 | if (use_xy == TRUE) { |
| 968 | rtn = mvwchgat(self->win,y,x,num,attr,color,NULL); |
| 969 | touchline(self->win,y,1); |
| 970 | } else { |
| 971 | getyx(self->win,y,x); |
| 972 | rtn = wchgat(self->win,num,attr,color,NULL); |
| 973 | touchline(self->win,y,1); |
| 974 | } |
| 975 | return PyCursesCheckERR(rtn, "chgat"); |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 978 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 979 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 980 | PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 981 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 982 | int rtn; |
| 983 | int x, y; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 984 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 985 | switch (PyTuple_Size(args)) { |
| 986 | case 0: |
| 987 | rtn = wdelch(self->win); |
| 988 | break; |
| 989 | case 2: |
| 990 | if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x)) |
| 991 | return NULL; |
| 992 | rtn = py_mvwdelch(self->win,y,x); |
| 993 | break; |
| 994 | default: |
| 995 | PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments"); |
| 996 | return NULL; |
| 997 | } |
| 998 | return PyCursesCheckERR(rtn, "[mv]wdelch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1002 | PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1003 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1004 | WINDOW *win; |
| 1005 | int nlines, ncols, begin_y, begin_x; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1006 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1007 | nlines = 0; |
| 1008 | ncols = 0; |
| 1009 | switch (PyTuple_Size(args)) { |
| 1010 | case 2: |
| 1011 | if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x)) |
| 1012 | return NULL; |
| 1013 | break; |
| 1014 | case 4: |
| 1015 | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", |
| 1016 | &nlines,&ncols,&begin_y,&begin_x)) |
| 1017 | return NULL; |
| 1018 | break; |
| 1019 | default: |
| 1020 | PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments"); |
| 1021 | return NULL; |
| 1022 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1023 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1024 | win = derwin(self->win,nlines,ncols,begin_y,begin_x); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1025 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1026 | if (win == NULL) { |
| 1027 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1028 | return NULL; |
| 1029 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1030 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1031 | return (PyObject *)PyCursesWindow_New(win, NULL); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1035 | PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1036 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1037 | PyObject *temp; |
| 1038 | chtype ch; |
| 1039 | attr_t attr = A_NORMAL; |
| 1040 | long lattr; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1041 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1042 | switch (PyTuple_Size(args)) { |
| 1043 | case 1: |
| 1044 | if (!PyArg_ParseTuple(args,"O;ch or int", &temp)) |
| 1045 | return NULL; |
| 1046 | break; |
| 1047 | case 2: |
| 1048 | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) |
| 1049 | return NULL; |
| 1050 | attr = lattr; |
| 1051 | break; |
| 1052 | default: |
| 1053 | PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1054 | |
| 1055 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1056 | return NULL; |
| 1057 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1058 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1059 | if (!PyCurses_ConvertToChtype(self, temp, &ch)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1060 | return NULL; |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1061 | |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 1062 | #ifdef WINDOW_HAS_FLAGS |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1063 | if (self->win->_flags & _ISPAD) |
| 1064 | return PyCursesCheckERR(pechochar(self->win, ch | attr), |
| 1065 | "echochar"); |
| 1066 | else |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1067 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1068 | return PyCursesCheckERR(wechochar(self->win, ch | attr), |
| 1069 | "echochar"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1072 | #ifdef NCURSES_MOUSE_VERSION |
| 1073 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1074 | PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1075 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1076 | int x, y; |
| 1077 | if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x)) |
| 1078 | return NULL; |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1079 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1080 | return PyLong_FromLong( wenclose(self->win,y,x) ); |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1081 | } |
| 1082 | #endif |
| 1083 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1084 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1085 | PyCursesWindow_GetBkgd(PyCursesWindowObject *self) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1086 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1087 | return PyLong_FromLong((long) getbkgd(self->win)); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1091 | PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1092 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1093 | int x, y; |
| 1094 | int rtn; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1095 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1096 | switch (PyTuple_Size(args)) { |
| 1097 | case 0: |
| 1098 | Py_BEGIN_ALLOW_THREADS |
| 1099 | rtn = wgetch(self->win); |
| 1100 | Py_END_ALLOW_THREADS |
| 1101 | break; |
| 1102 | case 2: |
| 1103 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
| 1104 | return NULL; |
| 1105 | Py_BEGIN_ALLOW_THREADS |
| 1106 | rtn = mvwgetch(self->win,y,x); |
| 1107 | Py_END_ALLOW_THREADS |
| 1108 | break; |
| 1109 | default: |
| 1110 | PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments"); |
| 1111 | return NULL; |
| 1112 | } |
| 1113 | return PyLong_FromLong((long)rtn); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1114 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1115 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1116 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1117 | PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1118 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1119 | int x, y; |
| 1120 | int rtn; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1121 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1122 | switch (PyTuple_Size(args)) { |
| 1123 | case 0: |
| 1124 | Py_BEGIN_ALLOW_THREADS |
| 1125 | rtn = wgetch(self->win); |
| 1126 | Py_END_ALLOW_THREADS |
| 1127 | break; |
| 1128 | case 2: |
| 1129 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
| 1130 | return NULL; |
| 1131 | Py_BEGIN_ALLOW_THREADS |
| 1132 | rtn = mvwgetch(self->win,y,x); |
| 1133 | Py_END_ALLOW_THREADS |
| 1134 | break; |
| 1135 | default: |
| 1136 | PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments"); |
| 1137 | return NULL; |
| 1138 | } |
| 1139 | if (rtn == ERR) { |
| 1140 | /* getch() returns ERR in nodelay mode */ |
| 1141 | PyErr_SetString(PyCursesError, "no input"); |
| 1142 | return NULL; |
| 1143 | } else if (rtn<=255) { |
| 1144 | return Py_BuildValue("C", rtn); |
| 1145 | } else { |
| 1146 | const char *knp; |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1147 | #if defined(__NetBSD__) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1148 | knp = unctrl(rtn); |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1149 | #else |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1150 | knp = keyname(rtn); |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1151 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1152 | return PyUnicode_FromString((knp == NULL) ? "" : knp); |
| 1153 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
Nadeem Vawda | 9e2e990 | 2011-07-31 15:01:11 +0200 | [diff] [blame] | 1156 | #ifdef HAVE_NCURSESW |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1157 | static PyObject * |
Victor Stinner | a7878b7 | 2011-07-14 23:07:44 +0200 | [diff] [blame] | 1158 | PyCursesWindow_Get_WCh(PyCursesWindowObject *self, PyObject *args) |
| 1159 | { |
| 1160 | int x, y; |
| 1161 | int ct; |
| 1162 | wint_t rtn; |
| 1163 | |
| 1164 | switch (PyTuple_Size(args)) { |
| 1165 | case 0: |
| 1166 | Py_BEGIN_ALLOW_THREADS |
| 1167 | ct = wget_wch(self->win,&rtn); |
| 1168 | Py_END_ALLOW_THREADS |
| 1169 | break; |
| 1170 | case 2: |
| 1171 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
| 1172 | return NULL; |
| 1173 | Py_BEGIN_ALLOW_THREADS |
| 1174 | ct = mvwget_wch(self->win,y,x,&rtn); |
| 1175 | Py_END_ALLOW_THREADS |
| 1176 | break; |
| 1177 | default: |
| 1178 | PyErr_SetString(PyExc_TypeError, "get_wch requires 0 or 2 arguments"); |
| 1179 | return NULL; |
| 1180 | } |
| 1181 | if (ct == ERR) { |
| 1182 | /* get_wch() returns ERR in nodelay mode */ |
| 1183 | PyErr_SetString(PyCursesError, "no input"); |
| 1184 | return NULL; |
| 1185 | } |
Victor Stinner | 1d39cde | 2012-08-29 01:40:57 +0200 | [diff] [blame] | 1186 | if (ct == KEY_CODE_YES) |
| 1187 | return PyLong_FromLong(rtn); |
| 1188 | else |
| 1189 | return PyUnicode_FromOrdinal(rtn); |
Victor Stinner | a7878b7 | 2011-07-14 23:07:44 +0200 | [diff] [blame] | 1190 | } |
Nadeem Vawda | 9e2e990 | 2011-07-31 15:01:11 +0200 | [diff] [blame] | 1191 | #endif |
Victor Stinner | a7878b7 | 2011-07-14 23:07:44 +0200 | [diff] [blame] | 1192 | |
| 1193 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1194 | PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1195 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1196 | int x, y, n; |
| 1197 | char rtn[1024]; /* This should be big enough.. I hope */ |
| 1198 | int rtn2; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1199 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1200 | switch (PyTuple_Size(args)) { |
| 1201 | case 0: |
| 1202 | Py_BEGIN_ALLOW_THREADS |
| 1203 | rtn2 = wgetnstr(self->win,rtn, 1023); |
| 1204 | Py_END_ALLOW_THREADS |
| 1205 | break; |
| 1206 | case 1: |
| 1207 | if (!PyArg_ParseTuple(args,"i;n", &n)) |
| 1208 | return NULL; |
| 1209 | Py_BEGIN_ALLOW_THREADS |
| 1210 | rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023)); |
| 1211 | Py_END_ALLOW_THREADS |
| 1212 | break; |
| 1213 | case 2: |
| 1214 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
| 1215 | return NULL; |
| 1216 | Py_BEGIN_ALLOW_THREADS |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1217 | #ifdef STRICT_SYSV_CURSES |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1218 | rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023); |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1219 | #else |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1220 | rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023); |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1221 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1222 | Py_END_ALLOW_THREADS |
| 1223 | break; |
| 1224 | case 3: |
| 1225 | if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n)) |
| 1226 | return NULL; |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 1227 | #ifdef STRICT_SYSV_CURSES |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1228 | Py_BEGIN_ALLOW_THREADS |
| 1229 | rtn2 = wmove(self->win,y,x)==ERR ? ERR : |
| 1230 | wgetnstr(self->win, rtn, MIN(n, 1023)); |
| 1231 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1232 | #else |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1233 | Py_BEGIN_ALLOW_THREADS |
| 1234 | rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023)); |
| 1235 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1236 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1237 | break; |
| 1238 | default: |
| 1239 | PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments"); |
| 1240 | return NULL; |
| 1241 | } |
| 1242 | if (rtn2 == ERR) |
| 1243 | rtn[0] = 0; |
| 1244 | return PyBytes_FromString(rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1248 | PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1249 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1250 | PyObject *temp; |
| 1251 | chtype ch; |
| 1252 | int n, x, y, code = OK; |
| 1253 | attr_t attr = A_NORMAL; |
| 1254 | long lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1255 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1256 | switch (PyTuple_Size(args)) { |
| 1257 | case 2: |
| 1258 | if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n)) |
| 1259 | return NULL; |
| 1260 | break; |
| 1261 | case 3: |
| 1262 | if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr)) |
| 1263 | return NULL; |
| 1264 | attr = lattr; |
| 1265 | break; |
| 1266 | case 4: |
| 1267 | if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n)) |
| 1268 | return NULL; |
| 1269 | code = wmove(self->win, y, x); |
| 1270 | break; |
| 1271 | case 5: |
| 1272 | if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", |
| 1273 | &y, &x, &temp, &n, &lattr)) |
| 1274 | return NULL; |
| 1275 | attr = lattr; |
| 1276 | code = wmove(self->win, y, x); |
| 1277 | break; |
| 1278 | default: |
| 1279 | PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments"); |
| 1280 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1281 | } |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1282 | |
| 1283 | if (code != ERR) { |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1284 | if (!PyCurses_ConvertToChtype(self, temp, &ch)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1285 | return NULL; |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1286 | return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline"); |
| 1287 | } else |
| 1288 | return PyCursesCheckERR(code, "wmove"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1292 | PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1293 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1294 | int rtn, x, y, use_xy = FALSE; |
| 1295 | PyObject *temp; |
| 1296 | chtype ch = 0; |
| 1297 | attr_t attr = A_NORMAL; |
| 1298 | long lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1299 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1300 | switch (PyTuple_Size(args)) { |
| 1301 | case 1: |
| 1302 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) |
| 1303 | return NULL; |
| 1304 | break; |
| 1305 | case 2: |
| 1306 | if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr)) |
| 1307 | return NULL; |
| 1308 | attr = lattr; |
| 1309 | break; |
| 1310 | case 3: |
| 1311 | if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp)) |
| 1312 | return NULL; |
| 1313 | use_xy = TRUE; |
| 1314 | break; |
| 1315 | case 4: |
| 1316 | if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &lattr)) |
| 1317 | return NULL; |
| 1318 | attr = lattr; |
| 1319 | use_xy = TRUE; |
| 1320 | break; |
| 1321 | default: |
| 1322 | PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments"); |
| 1323 | return NULL; |
| 1324 | } |
| 1325 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1326 | if (!PyCurses_ConvertToChtype(self, temp, &ch)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1327 | return NULL; |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1328 | |
| 1329 | if (use_xy == TRUE) |
| 1330 | rtn = mvwinsch(self->win,y,x, ch | attr); |
| 1331 | else { |
| 1332 | rtn = winsch(self->win, ch | attr); |
| 1333 | } |
| 1334 | return PyCursesCheckERR(rtn, "insch"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1338 | PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1339 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1340 | int x, y, rtn; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1341 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1342 | switch (PyTuple_Size(args)) { |
| 1343 | case 0: |
| 1344 | rtn = winch(self->win); |
| 1345 | break; |
| 1346 | case 2: |
| 1347 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
| 1348 | return NULL; |
| 1349 | rtn = mvwinch(self->win,y,x); |
| 1350 | break; |
| 1351 | default: |
| 1352 | PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments"); |
| 1353 | return NULL; |
| 1354 | } |
| 1355 | return PyLong_FromLong((long) rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1359 | PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1360 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1361 | int x, y, n; |
| 1362 | char rtn[1024]; /* This should be big enough.. I hope */ |
| 1363 | int rtn2; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1364 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1365 | switch (PyTuple_Size(args)) { |
| 1366 | case 0: |
| 1367 | rtn2 = winnstr(self->win,rtn, 1023); |
| 1368 | break; |
| 1369 | case 1: |
| 1370 | if (!PyArg_ParseTuple(args,"i;n", &n)) |
| 1371 | return NULL; |
| 1372 | rtn2 = winnstr(self->win,rtn,MIN(n,1023)); |
| 1373 | break; |
| 1374 | case 2: |
| 1375 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
| 1376 | return NULL; |
| 1377 | rtn2 = mvwinnstr(self->win,y,x,rtn,1023); |
| 1378 | break; |
| 1379 | case 3: |
| 1380 | if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n)) |
| 1381 | return NULL; |
| 1382 | rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023)); |
| 1383 | break; |
| 1384 | default: |
| 1385 | PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments"); |
| 1386 | return NULL; |
| 1387 | } |
| 1388 | if (rtn2 == ERR) |
| 1389 | rtn[0] = 0; |
| 1390 | return PyBytes_FromString(rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1394 | PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1395 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1396 | int rtn; |
| 1397 | int x, y; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1398 | int strtype; |
Benjamin Peterson | 5e54519 | 2012-03-14 18:21:35 -0500 | [diff] [blame] | 1399 | PyObject *strobj, *bytesobj = NULL; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1400 | #ifdef HAVE_NCURSESW |
| 1401 | wchar_t *wstr = NULL; |
| 1402 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1403 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 1404 | long lattr; |
| 1405 | int use_xy = FALSE, use_attr = FALSE; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1406 | const char *funcname; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1407 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1408 | switch (PyTuple_Size(args)) { |
| 1409 | case 1: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1410 | if (!PyArg_ParseTuple(args,"O;str", &strobj)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1411 | return NULL; |
| 1412 | break; |
| 1413 | case 2: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1414 | if (!PyArg_ParseTuple(args,"Ol;str,attr", &strobj, &lattr)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1415 | return NULL; |
| 1416 | attr = lattr; |
| 1417 | use_attr = TRUE; |
| 1418 | break; |
| 1419 | case 3: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1420 | if (!PyArg_ParseTuple(args,"iiO;y,x,str", &y, &x, &strobj)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1421 | return NULL; |
| 1422 | use_xy = TRUE; |
| 1423 | break; |
| 1424 | case 4: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1425 | if (!PyArg_ParseTuple(args,"iiOl;y,x,str,attr", &y, &x, &strobj, &lattr)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1426 | return NULL; |
| 1427 | attr = lattr; |
| 1428 | use_xy = use_attr = TRUE; |
| 1429 | break; |
| 1430 | default: |
| 1431 | PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments"); |
| 1432 | return NULL; |
| 1433 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1434 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1435 | #ifdef HAVE_NCURSESW |
| 1436 | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); |
| 1437 | #else |
| 1438 | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); |
| 1439 | #endif |
| 1440 | if (strtype == 0) |
| 1441 | return NULL; |
| 1442 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1443 | if (use_attr == TRUE) { |
| 1444 | attr_old = getattrs(self->win); |
| 1445 | (void)wattrset(self->win,attr); |
| 1446 | } |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1447 | #ifdef HAVE_NCURSESW |
| 1448 | if (strtype == 2) { |
| 1449 | funcname = "inswstr"; |
| 1450 | if (use_xy == TRUE) |
| 1451 | rtn = mvwins_wstr(self->win,y,x,wstr); |
| 1452 | else |
| 1453 | rtn = wins_wstr(self->win,wstr); |
| 1454 | PyMem_Free(wstr); |
| 1455 | } |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1456 | else |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1457 | #endif |
| 1458 | { |
| 1459 | char *str = PyBytes_AS_STRING(bytesobj); |
| 1460 | funcname = "insstr"; |
| 1461 | if (use_xy == TRUE) |
| 1462 | rtn = mvwinsstr(self->win,y,x,str); |
| 1463 | else |
| 1464 | rtn = winsstr(self->win,str); |
| 1465 | Py_DECREF(bytesobj); |
| 1466 | } |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1467 | if (use_attr == TRUE) |
| 1468 | (void)wattrset(self->win,attr_old); |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1469 | return PyCursesCheckERR(rtn, funcname); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1473 | PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1474 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1475 | int rtn, x, y, n; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1476 | int strtype; |
Benjamin Peterson | 5e54519 | 2012-03-14 18:21:35 -0500 | [diff] [blame] | 1477 | PyObject *strobj, *bytesobj = NULL; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1478 | #ifdef HAVE_NCURSESW |
| 1479 | wchar_t *wstr = NULL; |
| 1480 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1481 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 1482 | long lattr; |
| 1483 | int use_xy = FALSE, use_attr = FALSE; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1484 | const char *funcname; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1485 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1486 | switch (PyTuple_Size(args)) { |
| 1487 | case 2: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1488 | if (!PyArg_ParseTuple(args,"Oi;str,n", &strobj, &n)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1489 | return NULL; |
| 1490 | break; |
| 1491 | case 3: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1492 | if (!PyArg_ParseTuple(args,"Oil;str,n,attr", &strobj, &n, &lattr)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1493 | return NULL; |
| 1494 | attr = lattr; |
| 1495 | use_attr = TRUE; |
| 1496 | break; |
| 1497 | case 4: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1498 | if (!PyArg_ParseTuple(args,"iiOi;y,x,str,n", &y, &x, &strobj, &n)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1499 | return NULL; |
| 1500 | use_xy = TRUE; |
| 1501 | break; |
| 1502 | case 5: |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1503 | if (!PyArg_ParseTuple(args,"iiOil;y,x,str,n,attr", &y, &x, &strobj, &n, &lattr)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1504 | return NULL; |
| 1505 | attr = lattr; |
| 1506 | use_xy = use_attr = TRUE; |
| 1507 | break; |
| 1508 | default: |
| 1509 | PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments"); |
| 1510 | return NULL; |
| 1511 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1512 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1513 | #ifdef HAVE_NCURSESW |
| 1514 | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); |
| 1515 | #else |
| 1516 | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); |
| 1517 | #endif |
| 1518 | if (strtype == 0) |
| 1519 | return NULL; |
| 1520 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1521 | if (use_attr == TRUE) { |
| 1522 | attr_old = getattrs(self->win); |
| 1523 | (void)wattrset(self->win,attr); |
| 1524 | } |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1525 | #ifdef HAVE_NCURSESW |
| 1526 | if (strtype == 2) { |
| 1527 | funcname = "insn_wstr"; |
| 1528 | if (use_xy == TRUE) |
| 1529 | rtn = mvwins_nwstr(self->win,y,x,wstr,n); |
| 1530 | else |
| 1531 | rtn = wins_nwstr(self->win,wstr,n); |
| 1532 | PyMem_Free(wstr); |
| 1533 | } |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1534 | else |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1535 | #endif |
| 1536 | { |
| 1537 | char *str = PyBytes_AS_STRING(bytesobj); |
| 1538 | funcname = "insnstr"; |
| 1539 | if (use_xy == TRUE) |
| 1540 | rtn = mvwinsnstr(self->win,y,x,str,n); |
| 1541 | else |
| 1542 | rtn = winsnstr(self->win,str,n); |
| 1543 | Py_DECREF(bytesobj); |
| 1544 | } |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1545 | if (use_attr == TRUE) |
| 1546 | (void)wattrset(self->win,attr_old); |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1547 | return PyCursesCheckERR(rtn, funcname); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1551 | PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1552 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1553 | int line, erg; |
| 1554 | if (!PyArg_ParseTuple(args,"i;line", &line)) |
| 1555 | return NULL; |
| 1556 | erg = is_linetouched(self->win, line); |
| 1557 | if (erg == ERR) { |
| 1558 | PyErr_SetString(PyExc_TypeError, |
| 1559 | "is_linetouched: line number outside of boundaries"); |
| 1560 | return NULL; |
| 1561 | } else |
| 1562 | if (erg == FALSE) { |
| 1563 | Py_INCREF(Py_False); |
| 1564 | return Py_False; |
| 1565 | } else { |
| 1566 | Py_INCREF(Py_True); |
| 1567 | return Py_True; |
| 1568 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1572 | PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1573 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1574 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; |
| 1575 | int rtn; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1576 | |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 1577 | #ifndef WINDOW_HAS_FLAGS |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1578 | if (0) |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1579 | #else |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1580 | if (self->win->_flags & _ISPAD) |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1581 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1582 | { |
| 1583 | switch(PyTuple_Size(args)) { |
| 1584 | case 6: |
| 1585 | if (!PyArg_ParseTuple(args, |
| 1586 | "iiiiii;" \ |
| 1587 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", |
| 1588 | &pminrow, &pmincol, &sminrow, |
| 1589 | &smincol, &smaxrow, &smaxcol)) |
| 1590 | return NULL; |
| 1591 | Py_BEGIN_ALLOW_THREADS |
| 1592 | rtn = pnoutrefresh(self->win, |
| 1593 | pminrow, pmincol, sminrow, |
| 1594 | smincol, smaxrow, smaxcol); |
| 1595 | Py_END_ALLOW_THREADS |
| 1596 | return PyCursesCheckERR(rtn, "pnoutrefresh"); |
| 1597 | default: |
| 1598 | PyErr_SetString(PyCursesError, |
| 1599 | "noutrefresh() called for a pad " |
| 1600 | "requires 6 arguments"); |
| 1601 | return NULL; |
| 1602 | } |
| 1603 | } else { |
| 1604 | if (!PyArg_ParseTuple(args, ":noutrefresh")) |
| 1605 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1606 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1607 | Py_BEGIN_ALLOW_THREADS |
| 1608 | rtn = wnoutrefresh(self->win); |
| 1609 | Py_END_ALLOW_THREADS |
| 1610 | return PyCursesCheckERR(rtn, "wnoutrefresh"); |
| 1611 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | static PyObject * |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1615 | PyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args) |
| 1616 | { |
| 1617 | PyCursesWindowObject *temp; |
| 1618 | int use_copywin = FALSE; |
| 1619 | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; |
| 1620 | int rtn; |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1621 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1622 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1623 | case 1: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1624 | if (!PyArg_ParseTuple(args, "O!;window object", |
| 1625 | &PyCursesWindow_Type, &temp)) |
| 1626 | return NULL; |
| 1627 | break; |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1628 | case 7: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1629 | if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", |
| 1630 | &PyCursesWindow_Type, &temp, &sminrow, &smincol, |
| 1631 | &dminrow, &dmincol, &dmaxrow, &dmaxcol)) |
| 1632 | return NULL; |
| 1633 | use_copywin = TRUE; |
| 1634 | break; |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1635 | default: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1636 | PyErr_SetString(PyExc_TypeError, |
| 1637 | "overlay requires one or seven arguments"); |
| 1638 | return NULL; |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | if (use_copywin == TRUE) { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1642 | rtn = copywin(self->win, temp->win, sminrow, smincol, |
| 1643 | dminrow, dmincol, dmaxrow, dmaxcol, TRUE); |
| 1644 | return PyCursesCheckERR(rtn, "copywin"); |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1645 | } |
| 1646 | else { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1647 | rtn = overlay(self->win, temp->win); |
| 1648 | return PyCursesCheckERR(rtn, "overlay"); |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | static PyObject * |
| 1653 | PyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args) |
| 1654 | { |
| 1655 | PyCursesWindowObject *temp; |
| 1656 | int use_copywin = FALSE; |
| 1657 | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; |
| 1658 | int rtn; |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1659 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1660 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1661 | case 1: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1662 | if (!PyArg_ParseTuple(args, "O!;window object", |
| 1663 | &PyCursesWindow_Type, &temp)) |
| 1664 | return NULL; |
| 1665 | break; |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1666 | case 7: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1667 | if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", |
| 1668 | &PyCursesWindow_Type, &temp, &sminrow, &smincol, |
| 1669 | &dminrow, &dmincol, &dmaxrow, &dmaxcol)) |
| 1670 | return NULL; |
| 1671 | use_copywin = TRUE; |
| 1672 | break; |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1673 | default: |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1674 | PyErr_SetString(PyExc_TypeError, |
| 1675 | "overwrite requires one or seven arguments"); |
| 1676 | return NULL; |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | if (use_copywin == TRUE) { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1680 | rtn = copywin(self->win, temp->win, sminrow, smincol, |
| 1681 | dminrow, dmincol, dmaxrow, dmaxcol, FALSE); |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1682 | return PyCursesCheckERR(rtn, "copywin"); |
| 1683 | } |
| 1684 | else { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1685 | rtn = overwrite(self->win, temp->win); |
| 1686 | return PyCursesCheckERR(rtn, "overwrite"); |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | static PyObject * |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1691 | PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *stream) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1692 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1693 | /* We have to simulate this by writing to a temporary FILE*, |
| 1694 | then reading back, then writing to the argument stream. */ |
| 1695 | char fn[100]; |
| 1696 | int fd; |
| 1697 | FILE *fp; |
| 1698 | PyObject *res; |
Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame] | 1699 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1700 | strcpy(fn, "/tmp/py.curses.putwin.XXXXXX"); |
| 1701 | fd = mkstemp(fn); |
| 1702 | if (fd < 0) |
| 1703 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
| 1704 | fp = fdopen(fd, "wb+"); |
| 1705 | if (fp == NULL) { |
| 1706 | close(fd); |
| 1707 | remove(fn); |
| 1708 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
| 1709 | } |
| 1710 | res = PyCursesCheckERR(putwin(self->win, fp), "putwin"); |
| 1711 | if (res == NULL) { |
| 1712 | fclose(fp); |
| 1713 | remove(fn); |
| 1714 | return res; |
| 1715 | } |
| 1716 | fseek(fp, 0, 0); |
| 1717 | while (1) { |
| 1718 | char buf[BUFSIZ]; |
| 1719 | Py_ssize_t n = fread(buf, 1, BUFSIZ, fp); |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 1720 | _Py_IDENTIFIER(write); |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 1721 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1722 | if (n <= 0) |
| 1723 | break; |
| 1724 | Py_DECREF(res); |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 1725 | res = _PyObject_CallMethodId(stream, &PyId_write, "y#", buf, n); |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1726 | if (res == NULL) |
| 1727 | break; |
| 1728 | } |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1729 | fclose(fp); |
Guido van Rossum | 150b7d7 | 2007-08-30 23:34:01 +0000 | [diff] [blame] | 1730 | remove(fn); |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1731 | return res; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1735 | PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1736 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1737 | int beg, num; |
| 1738 | if (!PyArg_ParseTuple(args, "ii;beg,num", &beg, &num)) |
| 1739 | return NULL; |
| 1740 | return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1744 | PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1745 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1746 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; |
| 1747 | int rtn; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1748 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1749 | #ifndef WINDOW_HAS_FLAGS |
| 1750 | if (0) |
| 1751 | #else |
| 1752 | if (self->win->_flags & _ISPAD) |
| 1753 | #endif |
| 1754 | { |
| 1755 | switch(PyTuple_Size(args)) { |
| 1756 | case 6: |
| 1757 | if (!PyArg_ParseTuple(args, |
| 1758 | "iiiiii;" \ |
| 1759 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", |
| 1760 | &pminrow, &pmincol, &sminrow, |
| 1761 | &smincol, &smaxrow, &smaxcol)) |
| 1762 | return NULL; |
| 1763 | |
| 1764 | Py_BEGIN_ALLOW_THREADS |
| 1765 | rtn = prefresh(self->win, |
| 1766 | pminrow, pmincol, sminrow, |
| 1767 | smincol, smaxrow, smaxcol); |
| 1768 | Py_END_ALLOW_THREADS |
| 1769 | return PyCursesCheckERR(rtn, "prefresh"); |
| 1770 | default: |
| 1771 | PyErr_SetString(PyCursesError, |
| 1772 | "refresh() for a pad requires 6 arguments"); |
| 1773 | return NULL; |
| 1774 | } |
| 1775 | } else { |
| 1776 | if (!PyArg_ParseTuple(args, ":refresh")) |
| 1777 | return NULL; |
| 1778 | Py_BEGIN_ALLOW_THREADS |
| 1779 | rtn = wrefresh(self->win); |
| 1780 | Py_END_ALLOW_THREADS |
| 1781 | return PyCursesCheckERR(rtn, "prefresh"); |
| 1782 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1786 | PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1787 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1788 | int x, y; |
| 1789 | if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x)) |
| 1790 | return NULL; |
| 1791 | return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1795 | PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1796 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1797 | WINDOW *win; |
| 1798 | int nlines, ncols, begin_y, begin_x; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1799 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1800 | nlines = 0; |
| 1801 | ncols = 0; |
| 1802 | switch (PyTuple_Size(args)) { |
| 1803 | case 2: |
| 1804 | if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x)) |
| 1805 | return NULL; |
| 1806 | break; |
| 1807 | case 4: |
| 1808 | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", |
| 1809 | &nlines,&ncols,&begin_y,&begin_x)) |
| 1810 | return NULL; |
| 1811 | break; |
| 1812 | default: |
| 1813 | PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments"); |
| 1814 | return NULL; |
| 1815 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1816 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1817 | /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */ |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 1818 | #ifdef WINDOW_HAS_FLAGS |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1819 | if (self->win->_flags & _ISPAD) |
| 1820 | win = subpad(self->win, nlines, ncols, begin_y, begin_x); |
| 1821 | else |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1822 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1823 | win = subwin(self->win, nlines, ncols, begin_y, begin_x); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1824 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1825 | if (win == NULL) { |
| 1826 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1827 | return NULL; |
| 1828 | } |
| 1829 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1830 | return (PyObject *)PyCursesWindow_New(win, self->encoding); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1834 | PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1835 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1836 | int nlines; |
| 1837 | switch(PyTuple_Size(args)) { |
| 1838 | case 0: |
| 1839 | return PyCursesCheckERR(scroll(self->win), "scroll"); |
| 1840 | case 1: |
| 1841 | if (!PyArg_ParseTuple(args, "i;nlines", &nlines)) |
| 1842 | return NULL; |
| 1843 | return PyCursesCheckERR(wscrl(self->win, nlines), "scroll"); |
| 1844 | default: |
| 1845 | PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments"); |
| 1846 | return NULL; |
| 1847 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1851 | PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1852 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1853 | int st, cnt, val; |
| 1854 | switch (PyTuple_Size(args)) { |
| 1855 | case 2: |
| 1856 | if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt)) |
| 1857 | return NULL; |
| 1858 | return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline"); |
| 1859 | case 3: |
| 1860 | if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val)) |
| 1861 | return NULL; |
| 1862 | return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline"); |
| 1863 | default: |
| 1864 | PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments"); |
| 1865 | return NULL; |
| 1866 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1870 | PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1871 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1872 | PyObject *temp; |
| 1873 | chtype ch; |
| 1874 | int n, x, y, code = OK; |
| 1875 | attr_t attr = A_NORMAL; |
| 1876 | long lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1877 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1878 | switch (PyTuple_Size(args)) { |
| 1879 | case 2: |
| 1880 | if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n)) |
| 1881 | return NULL; |
| 1882 | break; |
| 1883 | case 3: |
| 1884 | if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr)) |
| 1885 | return NULL; |
| 1886 | attr = lattr; |
| 1887 | break; |
| 1888 | case 4: |
| 1889 | if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n)) |
| 1890 | return NULL; |
| 1891 | code = wmove(self->win, y, x); |
| 1892 | break; |
| 1893 | case 5: |
| 1894 | if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", |
| 1895 | &y, &x, &temp, &n, &lattr)) |
| 1896 | return NULL; |
| 1897 | attr = lattr; |
| 1898 | code = wmove(self->win, y, x); |
| 1899 | break; |
| 1900 | default: |
| 1901 | PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments"); |
| 1902 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1903 | } |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1904 | |
| 1905 | if (code != ERR) { |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1906 | if (!PyCurses_ConvertToChtype(self, temp, &ch)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1907 | return NULL; |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1908 | return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline"); |
| 1909 | } else |
| 1910 | return PyCursesCheckERR(code, "wmove"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1913 | static PyObject * |
| 1914 | PyCursesWindow_get_encoding(PyCursesWindowObject *self, void *closure) |
| 1915 | { |
| 1916 | return PyUnicode_FromString(self->encoding); |
| 1917 | } |
| 1918 | |
| 1919 | static int |
| 1920 | PyCursesWindow_set_encoding(PyCursesWindowObject *self, PyObject *value) |
| 1921 | { |
| 1922 | PyObject *ascii; |
| 1923 | char *encoding; |
| 1924 | |
| 1925 | /* It is illegal to del win.encoding */ |
| 1926 | if (value == NULL) { |
| 1927 | PyErr_SetString(PyExc_TypeError, |
| 1928 | "encoding may not be deleted"); |
| 1929 | return -1; |
| 1930 | } |
| 1931 | |
| 1932 | if (!PyUnicode_Check(value)) { |
| 1933 | PyErr_SetString(PyExc_TypeError, |
| 1934 | "setting encoding to a non-string"); |
| 1935 | return -1; |
| 1936 | } |
| 1937 | ascii = PyUnicode_AsASCIIString(value); |
| 1938 | if (ascii == NULL) |
| 1939 | return -1; |
| 1940 | encoding = strdup(PyBytes_AS_STRING(ascii)); |
Ross Lagerwall | 2dabaf6 | 2012-09-07 08:34:23 +0200 | [diff] [blame] | 1941 | Py_DECREF(ascii); |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1942 | if (encoding == NULL) { |
| 1943 | PyErr_NoMemory(); |
| 1944 | return -1; |
| 1945 | } |
| 1946 | free(self->encoding); |
| 1947 | self->encoding = encoding; |
| 1948 | return 0; |
| 1949 | } |
| 1950 | |
| 1951 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1952 | static PyMethodDef PyCursesWindow_Methods[] = { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1953 | {"addch", (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS}, |
| 1954 | {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS}, |
| 1955 | {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS}, |
| 1956 | {"attroff", (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS}, |
| 1957 | {"attron", (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS}, |
| 1958 | {"attrset", (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS}, |
| 1959 | {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS}, |
| 1960 | {"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS}, |
| 1961 | {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS}, |
| 1962 | {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS}, |
| 1963 | {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS}, |
| 1964 | {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS}, |
| 1965 | {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS}, |
| 1966 | {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS}, |
| 1967 | {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS}, |
| 1968 | {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS}, |
| 1969 | {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS}, |
| 1970 | {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS}, |
| 1971 | {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS}, |
| 1972 | {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1973 | #ifdef NCURSES_MOUSE_VERSION |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1974 | {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1975 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1976 | {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS}, |
| 1977 | {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS}, |
| 1978 | {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS}, |
| 1979 | {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS}, |
| 1980 | {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS}, |
Nadeem Vawda | 9e2e990 | 2011-07-31 15:01:11 +0200 | [diff] [blame] | 1981 | #ifdef HAVE_NCURSESW |
Victor Stinner | a7878b7 | 2011-07-14 23:07:44 +0200 | [diff] [blame] | 1982 | {"get_wch", (PyCFunction)PyCursesWindow_Get_WCh, METH_VARARGS}, |
Nadeem Vawda | 9e2e990 | 2011-07-31 15:01:11 +0200 | [diff] [blame] | 1983 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 1984 | {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS}, |
| 1985 | {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS}, |
| 1986 | {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS}, |
| 1987 | {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS}, |
| 1988 | {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS}, |
| 1989 | {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS}, |
| 1990 | {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS}, |
| 1991 | {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS}, |
| 1992 | {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS}, |
| 1993 | {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS}, |
| 1994 | {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS}, |
| 1995 | {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS}, |
| 1996 | {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS}, |
| 1997 | {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS}, |
| 1998 | {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS}, |
| 1999 | {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS}, |
| 2000 | {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS}, |
| 2001 | {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS}, |
| 2002 | {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS}, |
| 2003 | {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS}, |
| 2004 | {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS}, |
| 2005 | {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS}, |
| 2006 | {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS}, |
| 2007 | {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS}, |
| 2008 | {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, |
| 2009 | /* Backward compatibility alias -- remove in Python 2.3 */ |
| 2010 | {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, |
| 2011 | {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS}, |
| 2012 | {"overwrite", (PyCFunction)PyCursesWindow_Overwrite, |
| 2013 | METH_VARARGS}, |
| 2014 | {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_O}, |
| 2015 | {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS}, |
| 2016 | {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS}, |
| 2017 | {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS}, |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 2018 | #ifndef STRICT_SYSV_CURSES |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2019 | {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2020 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2021 | {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS}, |
| 2022 | {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS}, |
| 2023 | {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS}, |
| 2024 | {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS}, |
| 2025 | {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS}, |
| 2026 | {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, |
| 2027 | {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, |
| 2028 | {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS}, |
| 2029 | {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS}, |
| 2030 | {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS}, |
| 2031 | {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS}, |
| 2032 | {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS}, |
| 2033 | {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS}, |
| 2034 | {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS}, |
| 2035 | {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS}, |
| 2036 | {NULL, NULL} /* sentinel */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2037 | }; |
| 2038 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 2039 | static PyGetSetDef PyCursesWindow_getsets[] = { |
| 2040 | {"encoding", |
| 2041 | (getter)PyCursesWindow_get_encoding, |
| 2042 | (setter)PyCursesWindow_set_encoding, |
Ronald Oussoren | 2a7fe03 | 2012-01-17 16:53:20 +0100 | [diff] [blame] | 2043 | "the typecode character used to create the array"}, |
| 2044 | {NULL, NULL, NULL, NULL } /* sentinel */ |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 2045 | }; |
| 2046 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2047 | /* -------------------------------------------------------*/ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2048 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2049 | PyTypeObject PyCursesWindow_Type = { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2050 | PyVarObject_HEAD_INIT(NULL, 0) |
| 2051 | "_curses.curses window", /*tp_name*/ |
| 2052 | sizeof(PyCursesWindowObject), /*tp_basicsize*/ |
| 2053 | 0, /*tp_itemsize*/ |
| 2054 | /* methods */ |
| 2055 | (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/ |
| 2056 | 0, /*tp_print*/ |
| 2057 | (getattrfunc)0, /*tp_getattr*/ |
| 2058 | (setattrfunc)0, /*tp_setattr*/ |
| 2059 | 0, /*tp_reserved*/ |
| 2060 | 0, /*tp_repr*/ |
| 2061 | 0, /*tp_as_number*/ |
| 2062 | 0, /*tp_as_sequence*/ |
| 2063 | 0, /*tp_as_mapping*/ |
| 2064 | 0, /*tp_hash*/ |
| 2065 | 0, /*tp_call*/ |
| 2066 | 0, /*tp_str*/ |
| 2067 | 0, /*tp_getattro*/ |
| 2068 | 0, /*tp_setattro*/ |
| 2069 | 0, /*tp_as_buffer*/ |
| 2070 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 2071 | 0, /*tp_doc*/ |
| 2072 | 0, /*tp_traverse*/ |
| 2073 | 0, /*tp_clear*/ |
| 2074 | 0, /*tp_richcompare*/ |
| 2075 | 0, /*tp_weaklistoffset*/ |
| 2076 | 0, /*tp_iter*/ |
| 2077 | 0, /*tp_iternext*/ |
| 2078 | PyCursesWindow_Methods, /*tp_methods*/ |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 2079 | 0, /* tp_members */ |
| 2080 | PyCursesWindow_getsets, /* tp_getset */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2081 | }; |
| 2082 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2083 | /********************************************************************* |
| 2084 | Global Functions |
| 2085 | **********************************************************************/ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2086 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2087 | NoArgNoReturnFunction(beep) |
| 2088 | NoArgNoReturnFunction(def_prog_mode) |
| 2089 | NoArgNoReturnFunction(def_shell_mode) |
| 2090 | NoArgNoReturnFunction(doupdate) |
| 2091 | NoArgNoReturnFunction(endwin) |
| 2092 | NoArgNoReturnFunction(flash) |
| 2093 | NoArgNoReturnFunction(nocbreak) |
| 2094 | NoArgNoReturnFunction(noecho) |
| 2095 | NoArgNoReturnFunction(nonl) |
| 2096 | NoArgNoReturnFunction(noraw) |
| 2097 | NoArgNoReturnFunction(reset_prog_mode) |
| 2098 | NoArgNoReturnFunction(reset_shell_mode) |
| 2099 | NoArgNoReturnFunction(resetty) |
| 2100 | NoArgNoReturnFunction(savetty) |
| 2101 | |
| 2102 | NoArgOrFlagNoReturnFunction(cbreak) |
| 2103 | NoArgOrFlagNoReturnFunction(echo) |
| 2104 | NoArgOrFlagNoReturnFunction(nl) |
| 2105 | NoArgOrFlagNoReturnFunction(raw) |
| 2106 | |
| 2107 | NoArgReturnIntFunction(baudrate) |
| 2108 | NoArgReturnIntFunction(termattrs) |
| 2109 | |
| 2110 | NoArgReturnStringFunction(termname) |
| 2111 | NoArgReturnStringFunction(longname) |
| 2112 | |
| 2113 | NoArgTrueFalseFunction(can_change_color) |
| 2114 | NoArgTrueFalseFunction(has_colors) |
| 2115 | NoArgTrueFalseFunction(has_ic) |
| 2116 | NoArgTrueFalseFunction(has_il) |
| 2117 | NoArgTrueFalseFunction(isendwin) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2118 | NoArgNoReturnVoidFunction(flushinp) |
| 2119 | NoArgNoReturnVoidFunction(noqiflush) |
| 2120 | |
| 2121 | static PyObject * |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 2122 | PyCurses_filter(PyObject *self) |
| 2123 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2124 | /* not checking for PyCursesInitialised here since filter() must |
| 2125 | be called before initscr() */ |
| 2126 | filter(); |
| 2127 | Py_INCREF(Py_None); |
| 2128 | return Py_None; |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2132 | PyCurses_Color_Content(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2133 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2134 | short color,r,g,b; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2135 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2136 | PyCursesInitialised; |
| 2137 | PyCursesInitialisedColor; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2138 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2139 | if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2140 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2141 | if (color_content(color, &r, &g, &b) != ERR) |
| 2142 | return Py_BuildValue("(iii)", r, g, b); |
| 2143 | else { |
| 2144 | PyErr_SetString(PyCursesError, |
| 2145 | "Argument 1 was out of range. Check value of COLORS."); |
| 2146 | return NULL; |
| 2147 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2151 | PyCurses_color_pair(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2152 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2153 | int n; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2154 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2155 | PyCursesInitialised; |
| 2156 | PyCursesInitialisedColor; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2157 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2158 | if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL; |
| 2159 | return PyLong_FromLong((long) (n << 8)); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2163 | PyCurses_Curs_Set(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2164 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2165 | int vis,erg; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2166 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2167 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2168 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2169 | if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2170 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2171 | erg = curs_set(vis); |
| 2172 | if (erg == ERR) return PyCursesCheckERR(erg, "curs_set"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2173 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2174 | return PyLong_FromLong((long) erg); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2178 | PyCurses_Delay_Output(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2179 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2180 | int ms; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2181 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2182 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2183 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2184 | if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2185 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2186 | return PyCursesCheckERR(delay_output(ms), "delay_output"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2190 | PyCurses_EraseChar(PyObject *self) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2191 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2192 | char ch; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2193 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2194 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2195 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2196 | ch = erasechar(); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2197 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2198 | return PyBytes_FromStringAndSize(&ch, 1); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2202 | PyCurses_getsyx(PyObject *self) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2203 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2204 | int x = 0; |
| 2205 | int y = 0; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2206 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2207 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2208 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2209 | getsyx(y, x); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2210 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2211 | return Py_BuildValue("(ii)", y, x); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2214 | #ifdef NCURSES_MOUSE_VERSION |
| 2215 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2216 | PyCurses_GetMouse(PyObject *self) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2217 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2218 | int rtn; |
| 2219 | MEVENT event; |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2220 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2221 | PyCursesInitialised; |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2222 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2223 | rtn = getmouse( &event ); |
| 2224 | if (rtn == ERR) { |
| 2225 | PyErr_SetString(PyCursesError, "getmouse() returned ERR"); |
| 2226 | return NULL; |
| 2227 | } |
| 2228 | return Py_BuildValue("(hiiil)", |
| 2229 | (short)event.id, |
| 2230 | event.x, event.y, event.z, |
| 2231 | (long) event.bstate); |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2235 | PyCurses_UngetMouse(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2236 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2237 | MEVENT event; |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2238 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2239 | PyCursesInitialised; |
| 2240 | if (!PyArg_ParseTuple(args, "hiiil", |
| 2241 | &event.id, |
| 2242 | &event.x, &event.y, &event.z, |
| 2243 | (int *) &event.bstate)) |
| 2244 | return NULL; |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2245 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2246 | return PyCursesCheckERR(ungetmouse(&event), "ungetmouse"); |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2247 | } |
| 2248 | #endif |
| 2249 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2250 | static PyObject * |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 2251 | PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2252 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2253 | char fn[100]; |
| 2254 | int fd; |
| 2255 | FILE *fp; |
| 2256 | PyObject *data; |
| 2257 | size_t datalen; |
| 2258 | WINDOW *win; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2259 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2260 | PyCursesInitialised; |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 2261 | _Py_IDENTIFIER(read); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2262 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2263 | strcpy(fn, "/tmp/py.curses.getwin.XXXXXX"); |
| 2264 | fd = mkstemp(fn); |
| 2265 | if (fd < 0) |
| 2266 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
| 2267 | fp = fdopen(fd, "wb+"); |
| 2268 | if (fp == NULL) { |
| 2269 | close(fd); |
| 2270 | remove(fn); |
| 2271 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
| 2272 | } |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 2273 | data = _PyObject_CallMethodId(stream, &PyId_read, ""); |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2274 | if (data == NULL) { |
| 2275 | fclose(fp); |
| 2276 | remove(fn); |
| 2277 | return NULL; |
| 2278 | } |
| 2279 | if (!PyBytes_Check(data)) { |
| 2280 | PyErr_Format(PyExc_TypeError, |
| 2281 | "f.read() returned %.100s instead of bytes", |
| 2282 | data->ob_type->tp_name); |
| 2283 | Py_DECREF(data); |
| 2284 | fclose(fp); |
| 2285 | remove(fn); |
| 2286 | return NULL; |
| 2287 | } |
| 2288 | datalen = PyBytes_GET_SIZE(data); |
| 2289 | if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) { |
| 2290 | Py_DECREF(data); |
| 2291 | fclose(fp); |
| 2292 | remove(fn); |
| 2293 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
| 2294 | } |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 2295 | Py_DECREF(data); |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2296 | fseek(fp, 0, 0); |
| 2297 | win = getwin(fp); |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 2298 | fclose(fp); |
Guido van Rossum | 150b7d7 | 2007-08-30 23:34:01 +0000 | [diff] [blame] | 2299 | remove(fn); |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2300 | if (win == NULL) { |
| 2301 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 2302 | return NULL; |
| 2303 | } |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 2304 | return PyCursesWindow_New(win, NULL); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2308 | PyCurses_HalfDelay(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2309 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2310 | unsigned char tenths; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2311 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2312 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2313 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2314 | if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2315 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2316 | return PyCursesCheckERR(halfdelay(tenths), "halfdelay"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2317 | } |
| 2318 | |
Andrew M. Kuchling | bf68026 | 2000-07-25 12:37:41 +0000 | [diff] [blame] | 2319 | #ifndef STRICT_SYSV_CURSES |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2320 | /* No has_key! */ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2321 | static PyObject * PyCurses_has_key(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2322 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2323 | int ch; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2324 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2325 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2326 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2327 | if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2328 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2329 | if (has_key(ch) == FALSE) { |
| 2330 | Py_INCREF(Py_False); |
| 2331 | return Py_False; |
| 2332 | } |
| 2333 | Py_INCREF(Py_True); |
| 2334 | return Py_True; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2335 | } |
Andrew M. Kuchling | bf68026 | 2000-07-25 12:37:41 +0000 | [diff] [blame] | 2336 | #endif /* STRICT_SYSV_CURSES */ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2337 | |
| 2338 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2339 | PyCurses_Init_Color(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2340 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2341 | short color, r, g, b; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2342 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2343 | PyCursesInitialised; |
| 2344 | PyCursesInitialisedColor; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2345 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2346 | switch(PyTuple_Size(args)) { |
| 2347 | case 4: |
| 2348 | if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL; |
| 2349 | break; |
| 2350 | default: |
| 2351 | PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments"); |
| 2352 | return NULL; |
| 2353 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2354 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2355 | return PyCursesCheckERR(init_color(color, r, g, b), "init_color"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2359 | PyCurses_Init_Pair(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2360 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2361 | short pair, f, b; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2362 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2363 | PyCursesInitialised; |
| 2364 | PyCursesInitialisedColor; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2365 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2366 | if (PyTuple_Size(args) != 3) { |
| 2367 | PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments"); |
| 2368 | return NULL; |
| 2369 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2370 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2371 | if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2372 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2373 | return PyCursesCheckERR(init_pair(pair, f, b), "init_pair"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 2376 | static PyObject *ModDict; |
| 2377 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2378 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2379 | PyCurses_InitScr(PyObject *self) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2380 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2381 | WINDOW *win; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 2382 | PyCursesWindowObject *winobj; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2383 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2384 | if (initialised == TRUE) { |
| 2385 | wrefresh(stdscr); |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 2386 | return (PyObject *)PyCursesWindow_New(stdscr, NULL); |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2387 | } |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 2388 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2389 | win = initscr(); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2390 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2391 | if (win == NULL) { |
| 2392 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 2393 | return NULL; |
| 2394 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2395 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2396 | initialised = initialised_setupterm = TRUE; |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 2397 | |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2398 | /* This was moved from initcurses() because it core dumped on SGI, |
| 2399 | where they're not defined until you've called initscr() */ |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2400 | #define SetDictInt(string,ch) \ |
| 2401 | do { \ |
| 2402 | PyObject *o = PyLong_FromLong((long) (ch)); \ |
| 2403 | if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \ |
| 2404 | Py_DECREF(o); \ |
| 2405 | } \ |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 2406 | } while (0) |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2407 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2408 | /* Here are some graphic symbols you can use */ |
| 2409 | SetDictInt("ACS_ULCORNER", (ACS_ULCORNER)); |
| 2410 | SetDictInt("ACS_LLCORNER", (ACS_LLCORNER)); |
| 2411 | SetDictInt("ACS_URCORNER", (ACS_URCORNER)); |
| 2412 | SetDictInt("ACS_LRCORNER", (ACS_LRCORNER)); |
| 2413 | SetDictInt("ACS_LTEE", (ACS_LTEE)); |
| 2414 | SetDictInt("ACS_RTEE", (ACS_RTEE)); |
| 2415 | SetDictInt("ACS_BTEE", (ACS_BTEE)); |
| 2416 | SetDictInt("ACS_TTEE", (ACS_TTEE)); |
| 2417 | SetDictInt("ACS_HLINE", (ACS_HLINE)); |
| 2418 | SetDictInt("ACS_VLINE", (ACS_VLINE)); |
| 2419 | SetDictInt("ACS_PLUS", (ACS_PLUS)); |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 2420 | #if !defined(__hpux) || defined(HAVE_NCURSES_H) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2421 | /* On HP/UX 11, these are of type cchar_t, which is not an |
| 2422 | integral type. If this is a problem on more platforms, a |
| 2423 | configure test should be added to determine whether ACS_S1 |
| 2424 | is of integral type. */ |
| 2425 | SetDictInt("ACS_S1", (ACS_S1)); |
| 2426 | SetDictInt("ACS_S9", (ACS_S9)); |
| 2427 | SetDictInt("ACS_DIAMOND", (ACS_DIAMOND)); |
| 2428 | SetDictInt("ACS_CKBOARD", (ACS_CKBOARD)); |
| 2429 | SetDictInt("ACS_DEGREE", (ACS_DEGREE)); |
| 2430 | SetDictInt("ACS_PLMINUS", (ACS_PLMINUS)); |
| 2431 | SetDictInt("ACS_BULLET", (ACS_BULLET)); |
| 2432 | SetDictInt("ACS_LARROW", (ACS_LARROW)); |
| 2433 | SetDictInt("ACS_RARROW", (ACS_RARROW)); |
| 2434 | SetDictInt("ACS_DARROW", (ACS_DARROW)); |
| 2435 | SetDictInt("ACS_UARROW", (ACS_UARROW)); |
| 2436 | SetDictInt("ACS_BOARD", (ACS_BOARD)); |
| 2437 | SetDictInt("ACS_LANTERN", (ACS_LANTERN)); |
| 2438 | SetDictInt("ACS_BLOCK", (ACS_BLOCK)); |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 2439 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2440 | SetDictInt("ACS_BSSB", (ACS_ULCORNER)); |
| 2441 | SetDictInt("ACS_SSBB", (ACS_LLCORNER)); |
| 2442 | SetDictInt("ACS_BBSS", (ACS_URCORNER)); |
| 2443 | SetDictInt("ACS_SBBS", (ACS_LRCORNER)); |
| 2444 | SetDictInt("ACS_SBSS", (ACS_RTEE)); |
| 2445 | SetDictInt("ACS_SSSB", (ACS_LTEE)); |
| 2446 | SetDictInt("ACS_SSBS", (ACS_BTEE)); |
| 2447 | SetDictInt("ACS_BSSS", (ACS_TTEE)); |
| 2448 | SetDictInt("ACS_BSBS", (ACS_HLINE)); |
| 2449 | SetDictInt("ACS_SBSB", (ACS_VLINE)); |
| 2450 | SetDictInt("ACS_SSSS", (ACS_PLUS)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2451 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2452 | /* The following are never available with strict SYSV curses */ |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2453 | #ifdef ACS_S3 |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2454 | SetDictInt("ACS_S3", (ACS_S3)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2455 | #endif |
| 2456 | #ifdef ACS_S7 |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2457 | SetDictInt("ACS_S7", (ACS_S7)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2458 | #endif |
| 2459 | #ifdef ACS_LEQUAL |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2460 | SetDictInt("ACS_LEQUAL", (ACS_LEQUAL)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2461 | #endif |
| 2462 | #ifdef ACS_GEQUAL |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2463 | SetDictInt("ACS_GEQUAL", (ACS_GEQUAL)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2464 | #endif |
| 2465 | #ifdef ACS_PI |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2466 | SetDictInt("ACS_PI", (ACS_PI)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2467 | #endif |
| 2468 | #ifdef ACS_NEQUAL |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2469 | SetDictInt("ACS_NEQUAL", (ACS_NEQUAL)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2470 | #endif |
| 2471 | #ifdef ACS_STERLING |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2472 | SetDictInt("ACS_STERLING", (ACS_STERLING)); |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2473 | #endif |
| 2474 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2475 | SetDictInt("LINES", LINES); |
| 2476 | SetDictInt("COLS", COLS); |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 2477 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 2478 | winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL); |
| 2479 | screen_encoding = winobj->encoding; |
| 2480 | return (PyObject *)winobj; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2481 | } |
| 2482 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2483 | static PyObject * |
| 2484 | PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds) |
| 2485 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2486 | int fd = -1; |
| 2487 | int err; |
| 2488 | char* termstr = NULL; |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2489 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2490 | static char *kwlist[] = {"term", "fd", NULL}; |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2491 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2492 | if (!PyArg_ParseTupleAndKeywords( |
| 2493 | args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) { |
| 2494 | return NULL; |
| 2495 | } |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2496 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2497 | if (fd == -1) { |
| 2498 | PyObject* sys_stdout; |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2499 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2500 | sys_stdout = PySys_GetObject("stdout"); |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2501 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2502 | if (sys_stdout == NULL || sys_stdout == Py_None) { |
| 2503 | PyErr_SetString( |
| 2504 | PyCursesError, |
| 2505 | "lost sys.stdout"); |
| 2506 | return NULL; |
| 2507 | } |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2508 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2509 | fd = PyObject_AsFileDescriptor(sys_stdout); |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2510 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2511 | if (fd == -1) { |
| 2512 | return NULL; |
| 2513 | } |
| 2514 | } |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2515 | |
Matthias Klose | 635edd1 | 2010-07-30 21:40:57 +0000 | [diff] [blame] | 2516 | if (!initialised_setupterm && setupterm(termstr,fd,&err) == ERR) { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2517 | char* s = "setupterm: unknown error"; |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2518 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2519 | if (err == 0) { |
| 2520 | s = "setupterm: could not find terminal"; |
| 2521 | } else if (err == -1) { |
| 2522 | s = "setupterm: could not find terminfo database"; |
| 2523 | } |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2524 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2525 | PyErr_SetString(PyCursesError,s); |
| 2526 | return NULL; |
| 2527 | } |
| 2528 | |
| 2529 | initialised_setupterm = TRUE; |
| 2530 | |
| 2531 | Py_INCREF(Py_None); |
| 2532 | return Py_None; |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2533 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2534 | |
| 2535 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2536 | PyCurses_IntrFlush(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2537 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2538 | int ch; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2539 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2540 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2541 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2542 | switch(PyTuple_Size(args)) { |
| 2543 | case 1: |
| 2544 | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL; |
| 2545 | break; |
| 2546 | default: |
| 2547 | PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument"); |
| 2548 | return NULL; |
| 2549 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2550 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2551 | return PyCursesCheckERR(intrflush(NULL,ch), "intrflush"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2554 | #ifdef HAVE_CURSES_IS_TERM_RESIZED |
| 2555 | static PyObject * |
| 2556 | PyCurses_Is_Term_Resized(PyObject *self, PyObject *args) |
| 2557 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2558 | int lines; |
| 2559 | int columns; |
| 2560 | int result; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2561 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2562 | PyCursesInitialised; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2563 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2564 | if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns)) |
| 2565 | return NULL; |
| 2566 | result = is_term_resized(lines, columns); |
| 2567 | if (result == TRUE) { |
| 2568 | Py_INCREF(Py_True); |
| 2569 | return Py_True; |
| 2570 | } else { |
| 2571 | Py_INCREF(Py_False); |
| 2572 | return Py_False; |
| 2573 | } |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2574 | } |
| 2575 | #endif /* HAVE_CURSES_IS_TERM_RESIZED */ |
| 2576 | |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 2577 | #if !defined(__NetBSD__) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2578 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2579 | PyCurses_KeyName(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2580 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2581 | const char *knp; |
| 2582 | int ch; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2583 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2584 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2585 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2586 | if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2587 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2588 | if (ch < 0) { |
| 2589 | PyErr_SetString(PyExc_ValueError, "invalid key number"); |
| 2590 | return NULL; |
| 2591 | } |
| 2592 | knp = keyname(ch); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2593 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2594 | return PyBytes_FromString((knp == NULL) ? "" : (char *)knp); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2595 | } |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 2596 | #endif |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2597 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2598 | static PyObject * |
| 2599 | PyCurses_KillChar(PyObject *self) |
| 2600 | { |
| 2601 | char ch; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2602 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2603 | ch = killchar(); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2604 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2605 | return PyBytes_FromStringAndSize(&ch, 1); |
| 2606 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2607 | |
| 2608 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2609 | PyCurses_Meta(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2610 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2611 | int ch; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2612 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2613 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2614 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2615 | switch(PyTuple_Size(args)) { |
| 2616 | case 1: |
| 2617 | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL; |
| 2618 | break; |
| 2619 | default: |
| 2620 | PyErr_SetString(PyExc_TypeError, "meta requires 1 argument"); |
| 2621 | return NULL; |
| 2622 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2623 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2624 | return PyCursesCheckERR(meta(stdscr, ch), "meta"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2627 | #ifdef NCURSES_MOUSE_VERSION |
| 2628 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2629 | PyCurses_MouseInterval(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2630 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2631 | int interval; |
| 2632 | PyCursesInitialised; |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2633 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2634 | if (!PyArg_ParseTuple(args,"i;interval",&interval)) |
| 2635 | return NULL; |
| 2636 | return PyCursesCheckERR(mouseinterval(interval), "mouseinterval"); |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2640 | PyCurses_MouseMask(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2641 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2642 | int newmask; |
| 2643 | mmask_t oldmask, availmask; |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2644 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2645 | PyCursesInitialised; |
| 2646 | if (!PyArg_ParseTuple(args,"i;mousemask",&newmask)) |
| 2647 | return NULL; |
| 2648 | availmask = mousemask(newmask, &oldmask); |
| 2649 | return Py_BuildValue("(ll)", (long)availmask, (long)oldmask); |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2650 | } |
| 2651 | #endif |
| 2652 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2653 | static PyObject * |
Andrew M. Kuchling | 2824d7f | 2000-12-15 00:44:02 +0000 | [diff] [blame] | 2654 | PyCurses_Napms(PyObject *self, PyObject *args) |
| 2655 | { |
| 2656 | int ms; |
| 2657 | |
Andrew M. Kuchling | 2b14676 | 2010-05-10 23:30:25 +0000 | [diff] [blame] | 2658 | PyCursesInitialised; |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2659 | if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL; |
Andrew M. Kuchling | 2824d7f | 2000-12-15 00:44:02 +0000 | [diff] [blame] | 2660 | |
| 2661 | return Py_BuildValue("i", napms(ms)); |
| 2662 | } |
| 2663 | |
| 2664 | |
| 2665 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2666 | PyCurses_NewPad(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2667 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2668 | WINDOW *win; |
| 2669 | int nlines, ncols; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2670 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2671 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2672 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2673 | if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2674 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2675 | win = newpad(nlines, ncols); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2676 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2677 | if (win == NULL) { |
| 2678 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 2679 | return NULL; |
| 2680 | } |
| 2681 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 2682 | return (PyObject *)PyCursesWindow_New(win, NULL); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2686 | PyCurses_NewWindow(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2687 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2688 | WINDOW *win; |
| 2689 | int nlines, ncols, begin_y=0, begin_x=0; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2690 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2691 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2692 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2693 | switch (PyTuple_Size(args)) { |
| 2694 | case 2: |
| 2695 | if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) |
| 2696 | return NULL; |
| 2697 | break; |
| 2698 | case 4: |
| 2699 | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", |
| 2700 | &nlines,&ncols,&begin_y,&begin_x)) |
| 2701 | return NULL; |
| 2702 | break; |
| 2703 | default: |
| 2704 | PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments"); |
| 2705 | return NULL; |
| 2706 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2707 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2708 | win = newwin(nlines,ncols,begin_y,begin_x); |
| 2709 | if (win == NULL) { |
| 2710 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 2711 | return NULL; |
| 2712 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2713 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 2714 | return (PyObject *)PyCursesWindow_New(win, NULL); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2718 | PyCurses_Pair_Content(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2719 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2720 | short pair,f,b; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2721 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2722 | PyCursesInitialised; |
| 2723 | PyCursesInitialisedColor; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2724 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2725 | switch(PyTuple_Size(args)) { |
| 2726 | case 1: |
| 2727 | if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL; |
| 2728 | break; |
| 2729 | default: |
| 2730 | PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument"); |
| 2731 | return NULL; |
| 2732 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2733 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2734 | if (pair_content(pair, &f, &b)==ERR) { |
| 2735 | PyErr_SetString(PyCursesError, |
| 2736 | "Argument 1 was out of range. (1..COLOR_PAIRS-1)"); |
| 2737 | return NULL; |
| 2738 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2739 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2740 | return Py_BuildValue("(ii)", f, b); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2744 | PyCurses_pair_number(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2745 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2746 | int n; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2747 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2748 | PyCursesInitialised; |
| 2749 | PyCursesInitialisedColor; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2750 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2751 | switch(PyTuple_Size(args)) { |
| 2752 | case 1: |
| 2753 | if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL; |
| 2754 | break; |
| 2755 | default: |
| 2756 | PyErr_SetString(PyExc_TypeError, |
| 2757 | "pair_number requires 1 argument"); |
| 2758 | return NULL; |
| 2759 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2760 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2761 | return PyLong_FromLong((long) ((n & A_COLOR) >> 8)); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2765 | PyCurses_Putp(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2766 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2767 | char *str; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2768 | |
Victor Stinner | b3bc7e7 | 2011-11-03 20:35:40 +0100 | [diff] [blame] | 2769 | if (!PyArg_ParseTuple(args,"y;str", &str)) |
| 2770 | return NULL; |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2771 | return PyCursesCheckERR(putp(str), "putp"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2775 | PyCurses_QiFlush(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2776 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2777 | int flag = 0; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2778 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2779 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2780 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2781 | switch(PyTuple_Size(args)) { |
| 2782 | case 0: |
| 2783 | qiflush(); |
| 2784 | Py_INCREF(Py_None); |
| 2785 | return Py_None; |
| 2786 | case 1: |
| 2787 | if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; |
| 2788 | if (flag) qiflush(); |
| 2789 | else noqiflush(); |
| 2790 | Py_INCREF(Py_None); |
| 2791 | return Py_None; |
| 2792 | default: |
| 2793 | PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments"); |
| 2794 | return NULL; |
| 2795 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2796 | } |
| 2797 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2798 | /* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES |
| 2799 | * and _curses.COLS */ |
Benjamin Peterson | fea6a94 | 2008-07-02 16:11:42 +0000 | [diff] [blame] | 2800 | #if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2801 | static int |
| 2802 | update_lines_cols(void) |
| 2803 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2804 | PyObject *o; |
| 2805 | PyObject *m = PyImport_ImportModuleNoBlock("curses"); |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2806 | _Py_IDENTIFIER(LINES); |
| 2807 | _Py_IDENTIFIER(COLS); |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2808 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2809 | if (!m) |
| 2810 | return 0; |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2811 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2812 | o = PyLong_FromLong(LINES); |
| 2813 | if (!o) { |
| 2814 | Py_DECREF(m); |
| 2815 | return 0; |
| 2816 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2817 | if (_PyObject_SetAttrId(m, &PyId_LINES, o)) { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2818 | Py_DECREF(m); |
| 2819 | Py_DECREF(o); |
| 2820 | return 0; |
| 2821 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2822 | /* PyId_LINES.object will be initialized here. */ |
| 2823 | if (PyDict_SetItem(ModDict, PyId_LINES.object, o)) { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2824 | Py_DECREF(m); |
| 2825 | Py_DECREF(o); |
| 2826 | return 0; |
| 2827 | } |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2828 | Py_DECREF(o); |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2829 | o = PyLong_FromLong(COLS); |
| 2830 | if (!o) { |
| 2831 | Py_DECREF(m); |
| 2832 | return 0; |
| 2833 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2834 | if (_PyObject_SetAttrId(m, &PyId_COLS, o)) { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2835 | Py_DECREF(m); |
| 2836 | Py_DECREF(o); |
| 2837 | return 0; |
| 2838 | } |
Martin v. Löwis | 1c67dd9 | 2011-10-14 15:16:45 +0200 | [diff] [blame] | 2839 | if (PyDict_SetItem(ModDict, PyId_COLS.object, o)) { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2840 | Py_DECREF(m); |
| 2841 | Py_DECREF(o); |
| 2842 | return 0; |
| 2843 | } |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2844 | Py_DECREF(o); |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2845 | Py_DECREF(m); |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2846 | return 1; |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2847 | } |
Benjamin Peterson | fea6a94 | 2008-07-02 16:11:42 +0000 | [diff] [blame] | 2848 | #endif |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2849 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2850 | #ifdef HAVE_CURSES_RESIZETERM |
| 2851 | static PyObject * |
| 2852 | PyCurses_ResizeTerm(PyObject *self, PyObject *args) |
| 2853 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2854 | int lines; |
| 2855 | int columns; |
| 2856 | PyObject *result; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2857 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2858 | PyCursesInitialised; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2859 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2860 | if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns)) |
| 2861 | return NULL; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2862 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2863 | result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm"); |
| 2864 | if (!result) |
| 2865 | return NULL; |
| 2866 | if (!update_lines_cols()) |
| 2867 | return NULL; |
| 2868 | return result; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | #endif |
| 2872 | |
| 2873 | #ifdef HAVE_CURSES_RESIZE_TERM |
| 2874 | static PyObject * |
| 2875 | PyCurses_Resize_Term(PyObject *self, PyObject *args) |
| 2876 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2877 | int lines; |
| 2878 | int columns; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2879 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2880 | PyObject *result; |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2881 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2882 | PyCursesInitialised; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2883 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2884 | if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns)) |
| 2885 | return NULL; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2886 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2887 | result = PyCursesCheckERR(resize_term(lines, columns), "resize_term"); |
| 2888 | if (!result) |
| 2889 | return NULL; |
| 2890 | if (!update_lines_cols()) |
| 2891 | return NULL; |
| 2892 | return result; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2893 | } |
| 2894 | #endif /* HAVE_CURSES_RESIZE_TERM */ |
| 2895 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2896 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2897 | PyCurses_setsyx(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2898 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2899 | int y,x; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2900 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2901 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2902 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2903 | if (PyTuple_Size(args)!=2) { |
| 2904 | PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments"); |
| 2905 | return NULL; |
| 2906 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2907 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2908 | if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2909 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2910 | setsyx(y,x); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2911 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2912 | Py_INCREF(Py_None); |
| 2913 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2914 | } |
| 2915 | |
| 2916 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2917 | PyCurses_Start_Color(PyObject *self) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2918 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2919 | int code; |
| 2920 | PyObject *c, *cp; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2921 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2922 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2923 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2924 | code = start_color(); |
| 2925 | if (code != ERR) { |
| 2926 | initialisedcolors = TRUE; |
| 2927 | c = PyLong_FromLong((long) COLORS); |
| 2928 | PyDict_SetItemString(ModDict, "COLORS", c); |
| 2929 | Py_DECREF(c); |
| 2930 | cp = PyLong_FromLong((long) COLOR_PAIRS); |
| 2931 | PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp); |
| 2932 | Py_DECREF(cp); |
| 2933 | Py_INCREF(Py_None); |
| 2934 | return Py_None; |
| 2935 | } else { |
| 2936 | PyErr_SetString(PyCursesError, "start_color() returned ERR"); |
| 2937 | return NULL; |
| 2938 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | static PyObject * |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2942 | PyCurses_tigetflag(PyObject *self, PyObject *args) |
| 2943 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2944 | char *capname; |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2945 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2946 | PyCursesSetupTermCalled; |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2947 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2948 | if (!PyArg_ParseTuple(args, "s", &capname)) |
| 2949 | return NULL; |
| 2950 | |
| 2951 | return PyLong_FromLong( (long) tigetflag( capname ) ); |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | static PyObject * |
| 2955 | PyCurses_tigetnum(PyObject *self, PyObject *args) |
| 2956 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2957 | char *capname; |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2958 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2959 | PyCursesSetupTermCalled; |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2960 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2961 | if (!PyArg_ParseTuple(args, "s", &capname)) |
| 2962 | return NULL; |
| 2963 | |
| 2964 | return PyLong_FromLong( (long) tigetnum( capname ) ); |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | static PyObject * |
| 2968 | PyCurses_tigetstr(PyObject *self, PyObject *args) |
| 2969 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2970 | char *capname; |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2971 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2972 | PyCursesSetupTermCalled; |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2973 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2974 | if (!PyArg_ParseTuple(args, "s", &capname)) |
| 2975 | return NULL; |
| 2976 | |
| 2977 | capname = tigetstr( capname ); |
| 2978 | if (capname == 0 || capname == (char*) -1) { |
| 2979 | Py_INCREF(Py_None); |
| 2980 | return Py_None; |
| 2981 | } |
| 2982 | return PyBytes_FromString( capname ); |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | static PyObject * |
Andrew M. Kuchling | f16e0ed | 2000-11-07 03:35:24 +0000 | [diff] [blame] | 2986 | PyCurses_tparm(PyObject *self, PyObject *args) |
| 2987 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2988 | char* fmt; |
| 2989 | char* result = NULL; |
| 2990 | int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0; |
Andrew M. Kuchling | f16e0ed | 2000-11-07 03:35:24 +0000 | [diff] [blame] | 2991 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2992 | PyCursesSetupTermCalled; |
Andrew M. Kuchling | f16e0ed | 2000-11-07 03:35:24 +0000 | [diff] [blame] | 2993 | |
Victor Stinner | 2662133 | 2011-11-02 23:45:29 +0100 | [diff] [blame] | 2994 | if (!PyArg_ParseTuple(args, "y|iiiiiiiii:tparm", |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 2995 | &fmt, &i1, &i2, &i3, &i4, |
| 2996 | &i5, &i6, &i7, &i8, &i9)) { |
| 2997 | return NULL; |
| 2998 | } |
Michael W. Hudson | 2100798 | 2002-11-21 14:17:51 +0000 | [diff] [blame] | 2999 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3000 | result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9); |
| 3001 | if (!result) { |
| 3002 | PyErr_SetString(PyCursesError, "tparm() returned NULL"); |
| 3003 | return NULL; |
| 3004 | } |
Michael W. Hudson | 2100798 | 2002-11-21 14:17:51 +0000 | [diff] [blame] | 3005 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3006 | return PyBytes_FromString(result); |
Andrew M. Kuchling | f16e0ed | 2000-11-07 03:35:24 +0000 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 3010 | PyCurses_TypeAhead(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 3011 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3012 | int fd; |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 3013 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3014 | PyCursesInitialised; |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 3015 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3016 | if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL; |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 3017 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3018 | return PyCursesCheckERR(typeahead( fd ), "typeahead"); |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 3022 | PyCurses_UnCtrl(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 3023 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3024 | PyObject *temp; |
| 3025 | chtype ch; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 3026 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3027 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 3028 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3029 | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 3030 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 3031 | if (!PyCurses_ConvertToChtype(NULL, temp, &ch)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3032 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 3033 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3034 | return PyBytes_FromString(unctrl(ch)); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 3038 | PyCurses_UngetCh(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3039 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3040 | PyObject *temp; |
| 3041 | chtype ch; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 3042 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3043 | PyCursesInitialised; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 3044 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 3045 | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3046 | return NULL; |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 3047 | |
| 3048 | if (!PyCurses_ConvertToChtype(NULL, temp, &ch)) |
| 3049 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 3050 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3051 | return PyCursesCheckERR(ungetch(ch), "ungetch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3052 | } |
| 3053 | |
Victor Stinner | 71e44cb | 2011-09-06 01:53:03 +0200 | [diff] [blame] | 3054 | #ifdef HAVE_NCURSESW |
| 3055 | /* Convert an object to a character (wchar_t): |
| 3056 | |
| 3057 | - int |
| 3058 | - str of length 1 |
| 3059 | |
| 3060 | Return 1 on success, 0 on error. */ |
| 3061 | static int |
| 3062 | PyCurses_ConvertToWchar_t(PyObject *obj, |
| 3063 | wchar_t *wch) |
| 3064 | { |
| 3065 | if (PyUnicode_Check(obj)) { |
| 3066 | wchar_t buffer[2]; |
| 3067 | if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) { |
| 3068 | PyErr_Format(PyExc_TypeError, |
| 3069 | "expect bytes or str of length 1, or int, " |
| 3070 | "got a str of length %zi", |
Victor Stinner | c4f281e | 2011-10-11 22:11:42 +0200 | [diff] [blame] | 3071 | PyUnicode_GET_LENGTH(obj)); |
Victor Stinner | 71e44cb | 2011-09-06 01:53:03 +0200 | [diff] [blame] | 3072 | return 0; |
| 3073 | } |
| 3074 | *wch = buffer[0]; |
| 3075 | return 2; |
| 3076 | } |
| 3077 | else if (PyLong_CheckExact(obj)) { |
| 3078 | long value; |
| 3079 | int overflow; |
| 3080 | value = PyLong_AsLongAndOverflow(obj, &overflow); |
| 3081 | if (overflow) { |
| 3082 | PyErr_SetString(PyExc_OverflowError, |
| 3083 | "int doesn't fit in long"); |
| 3084 | return 0; |
| 3085 | } |
| 3086 | *wch = (wchar_t)value; |
| 3087 | if ((long)*wch != value) { |
| 3088 | PyErr_Format(PyExc_OverflowError, |
| 3089 | "character doesn't fit in wchar_t"); |
| 3090 | return 0; |
| 3091 | } |
| 3092 | return 1; |
| 3093 | } |
| 3094 | else { |
| 3095 | PyErr_Format(PyExc_TypeError, |
| 3096 | "expect bytes or str of length 1, or int, got %s", |
| 3097 | Py_TYPE(obj)->tp_name); |
| 3098 | return 0; |
| 3099 | } |
| 3100 | } |
| 3101 | |
| 3102 | static PyObject * |
| 3103 | PyCurses_Unget_Wch(PyObject *self, PyObject *args) |
| 3104 | { |
| 3105 | PyObject *obj; |
| 3106 | wchar_t wch; |
| 3107 | |
| 3108 | PyCursesInitialised; |
| 3109 | |
| 3110 | if (!PyArg_ParseTuple(args,"O", &obj)) |
| 3111 | return NULL; |
| 3112 | |
| 3113 | if (!PyCurses_ConvertToWchar_t(obj, &wch)) |
| 3114 | return NULL; |
| 3115 | return PyCursesCheckERR(unget_wch(wch), "unget_wch"); |
| 3116 | } |
| 3117 | #endif |
| 3118 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3119 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 3120 | PyCurses_Use_Env(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3121 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3122 | int flag; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 3123 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3124 | switch(PyTuple_Size(args)) { |
| 3125 | case 1: |
| 3126 | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag)) |
| 3127 | return NULL; |
| 3128 | break; |
| 3129 | default: |
| 3130 | PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument"); |
| 3131 | return NULL; |
| 3132 | } |
| 3133 | use_env(flag); |
| 3134 | Py_INCREF(Py_None); |
| 3135 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3136 | } |
| 3137 | |
Andrew M. Kuchling | 69f31eb | 2003-08-13 23:11:04 +0000 | [diff] [blame] | 3138 | #ifndef STRICT_SYSV_CURSES |
| 3139 | static PyObject * |
| 3140 | PyCurses_Use_Default_Colors(PyObject *self) |
| 3141 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3142 | int code; |
Andrew M. Kuchling | 69f31eb | 2003-08-13 23:11:04 +0000 | [diff] [blame] | 3143 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3144 | PyCursesInitialised; |
| 3145 | PyCursesInitialisedColor; |
Andrew M. Kuchling | 69f31eb | 2003-08-13 23:11:04 +0000 | [diff] [blame] | 3146 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3147 | code = use_default_colors(); |
| 3148 | if (code != ERR) { |
| 3149 | Py_INCREF(Py_None); |
| 3150 | return Py_None; |
| 3151 | } else { |
| 3152 | PyErr_SetString(PyCursesError, "use_default_colors() returned ERR"); |
| 3153 | return NULL; |
| 3154 | } |
Andrew M. Kuchling | 69f31eb | 2003-08-13 23:11:04 +0000 | [diff] [blame] | 3155 | } |
| 3156 | #endif /* STRICT_SYSV_CURSES */ |
| 3157 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3158 | /* List of functions defined in the module */ |
| 3159 | |
| 3160 | static PyMethodDef PyCurses_methods[] = { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3161 | {"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS}, |
| 3162 | {"beep", (PyCFunction)PyCurses_beep, METH_NOARGS}, |
| 3163 | {"can_change_color", (PyCFunction)PyCurses_can_change_color, METH_NOARGS}, |
| 3164 | {"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS}, |
| 3165 | {"color_content", (PyCFunction)PyCurses_Color_Content, METH_VARARGS}, |
| 3166 | {"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS}, |
| 3167 | {"curs_set", (PyCFunction)PyCurses_Curs_Set, METH_VARARGS}, |
| 3168 | {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS}, |
| 3169 | {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS}, |
| 3170 | {"delay_output", (PyCFunction)PyCurses_Delay_Output, METH_VARARGS}, |
| 3171 | {"doupdate", (PyCFunction)PyCurses_doupdate, METH_NOARGS}, |
| 3172 | {"echo", (PyCFunction)PyCurses_echo, METH_VARARGS}, |
| 3173 | {"endwin", (PyCFunction)PyCurses_endwin, METH_NOARGS}, |
| 3174 | {"erasechar", (PyCFunction)PyCurses_EraseChar, METH_NOARGS}, |
| 3175 | {"filter", (PyCFunction)PyCurses_filter, METH_NOARGS}, |
| 3176 | {"flash", (PyCFunction)PyCurses_flash, METH_NOARGS}, |
| 3177 | {"flushinp", (PyCFunction)PyCurses_flushinp, METH_NOARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 3178 | #ifdef NCURSES_MOUSE_VERSION |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3179 | {"getmouse", (PyCFunction)PyCurses_GetMouse, METH_NOARGS}, |
| 3180 | {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 3181 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3182 | {"getsyx", (PyCFunction)PyCurses_getsyx, METH_NOARGS}, |
| 3183 | {"getwin", (PyCFunction)PyCurses_GetWin, METH_O}, |
| 3184 | {"has_colors", (PyCFunction)PyCurses_has_colors, METH_NOARGS}, |
| 3185 | {"has_ic", (PyCFunction)PyCurses_has_ic, METH_NOARGS}, |
| 3186 | {"has_il", (PyCFunction)PyCurses_has_il, METH_NOARGS}, |
Andrew M. Kuchling | bf68026 | 2000-07-25 12:37:41 +0000 | [diff] [blame] | 3187 | #ifndef STRICT_SYSV_CURSES |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3188 | {"has_key", (PyCFunction)PyCurses_has_key, METH_VARARGS}, |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3189 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3190 | {"halfdelay", (PyCFunction)PyCurses_HalfDelay, METH_VARARGS}, |
| 3191 | {"init_color", (PyCFunction)PyCurses_Init_Color, METH_VARARGS}, |
| 3192 | {"init_pair", (PyCFunction)PyCurses_Init_Pair, METH_VARARGS}, |
| 3193 | {"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS}, |
| 3194 | {"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS}, |
| 3195 | {"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS}, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 3196 | #ifdef HAVE_CURSES_IS_TERM_RESIZED |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3197 | {"is_term_resized", (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS}, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 3198 | #endif |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 3199 | #if !defined(__NetBSD__) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3200 | {"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS}, |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 3201 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3202 | {"killchar", (PyCFunction)PyCurses_KillChar, METH_NOARGS}, |
| 3203 | {"longname", (PyCFunction)PyCurses_longname, METH_NOARGS}, |
| 3204 | {"meta", (PyCFunction)PyCurses_Meta, METH_VARARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 3205 | #ifdef NCURSES_MOUSE_VERSION |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3206 | {"mouseinterval", (PyCFunction)PyCurses_MouseInterval, METH_VARARGS}, |
| 3207 | {"mousemask", (PyCFunction)PyCurses_MouseMask, METH_VARARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 3208 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3209 | {"napms", (PyCFunction)PyCurses_Napms, METH_VARARGS}, |
| 3210 | {"newpad", (PyCFunction)PyCurses_NewPad, METH_VARARGS}, |
| 3211 | {"newwin", (PyCFunction)PyCurses_NewWindow, METH_VARARGS}, |
| 3212 | {"nl", (PyCFunction)PyCurses_nl, METH_VARARGS}, |
| 3213 | {"nocbreak", (PyCFunction)PyCurses_nocbreak, METH_NOARGS}, |
| 3214 | {"noecho", (PyCFunction)PyCurses_noecho, METH_NOARGS}, |
| 3215 | {"nonl", (PyCFunction)PyCurses_nonl, METH_NOARGS}, |
| 3216 | {"noqiflush", (PyCFunction)PyCurses_noqiflush, METH_NOARGS}, |
| 3217 | {"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS}, |
| 3218 | {"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS}, |
| 3219 | {"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS}, |
| 3220 | {"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS}, |
| 3221 | {"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS}, |
| 3222 | {"raw", (PyCFunction)PyCurses_raw, METH_VARARGS}, |
| 3223 | {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS}, |
| 3224 | {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS}, |
| 3225 | {"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS}, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 3226 | #ifdef HAVE_CURSES_RESIZETERM |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3227 | {"resizeterm", (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS}, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 3228 | #endif |
| 3229 | #ifdef HAVE_CURSES_RESIZE_TERM |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3230 | {"resize_term", (PyCFunction)PyCurses_Resize_Term, METH_VARARGS}, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 3231 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3232 | {"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS}, |
| 3233 | {"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS}, |
| 3234 | {"setupterm", (PyCFunction)PyCurses_setupterm, |
| 3235 | METH_VARARGS|METH_KEYWORDS}, |
| 3236 | {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS}, |
| 3237 | {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS}, |
| 3238 | {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS}, |
| 3239 | {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS}, |
| 3240 | {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS}, |
| 3241 | {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS}, |
| 3242 | {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS}, |
| 3243 | {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS}, |
| 3244 | {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS}, |
| 3245 | {"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS}, |
Victor Stinner | 71e44cb | 2011-09-06 01:53:03 +0200 | [diff] [blame] | 3246 | #ifdef HAVE_NCURSESW |
| 3247 | {"unget_wch", (PyCFunction)PyCurses_Unget_Wch, METH_VARARGS}, |
| 3248 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3249 | {"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS}, |
Andrew M. Kuchling | 69f31eb | 2003-08-13 23:11:04 +0000 | [diff] [blame] | 3250 | #ifndef STRICT_SYSV_CURSES |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3251 | {"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS}, |
Andrew M. Kuchling | 69f31eb | 2003-08-13 23:11:04 +0000 | [diff] [blame] | 3252 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3253 | {NULL, NULL} /* sentinel */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3254 | }; |
| 3255 | |
| 3256 | /* Initialization function for the module */ |
| 3257 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 3258 | |
| 3259 | static struct PyModuleDef _cursesmodule = { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3260 | PyModuleDef_HEAD_INIT, |
| 3261 | "_curses", |
| 3262 | NULL, |
| 3263 | -1, |
| 3264 | PyCurses_methods, |
| 3265 | NULL, |
| 3266 | NULL, |
| 3267 | NULL, |
| 3268 | NULL |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 3269 | }; |
| 3270 | |
Mark Hammond | fe51c6d | 2002-08-02 02:27:13 +0000 | [diff] [blame] | 3271 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 3272 | PyInit__curses(void) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3273 | { |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3274 | PyObject *m, *d, *v, *c_api_object; |
| 3275 | static void *PyCurses_API[PyCurses_API_pointers]; |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 3276 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3277 | /* Initialize object type */ |
| 3278 | if (PyType_Ready(&PyCursesWindow_Type) < 0) |
| 3279 | return NULL; |
Guido van Rossum | 6915c4d | 2001-01-19 00:28:08 +0000 | [diff] [blame] | 3280 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3281 | /* Initialize the C API pointer array */ |
| 3282 | PyCurses_API[0] = (void *)&PyCursesWindow_Type; |
| 3283 | PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled; |
| 3284 | PyCurses_API[2] = (void *)func_PyCursesInitialised; |
| 3285 | PyCurses_API[3] = (void *)func_PyCursesInitialisedColor; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3286 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3287 | /* Create the module and add the functions */ |
| 3288 | m = PyModule_Create(&_cursesmodule); |
| 3289 | if (m == NULL) |
| 3290 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3291 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3292 | /* Add some symbolic constants to the module */ |
| 3293 | d = PyModule_GetDict(m); |
| 3294 | if (d == NULL) |
| 3295 | return NULL; |
| 3296 | ModDict = d; /* For PyCurses_InitScr to use later */ |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 3297 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3298 | /* Add a capsule for the C API */ |
| 3299 | c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, NULL); |
| 3300 | PyDict_SetItemString(d, "_C_API", c_api_object); |
| 3301 | Py_DECREF(c_api_object); |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 3302 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3303 | /* For exception curses.error */ |
| 3304 | PyCursesError = PyErr_NewException("_curses.error", NULL, NULL); |
| 3305 | PyDict_SetItemString(d, "error", PyCursesError); |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 3306 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3307 | /* Make the version available */ |
| 3308 | v = PyBytes_FromString(PyCursesVersion); |
| 3309 | PyDict_SetItemString(d, "version", v); |
| 3310 | PyDict_SetItemString(d, "__version__", v); |
| 3311 | Py_DECREF(v); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3312 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3313 | SetDictInt("ERR", ERR); |
| 3314 | SetDictInt("OK", OK); |
Andrew M. Kuchling | caefb37 | 2000-12-26 15:57:01 +0000 | [diff] [blame] | 3315 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3316 | /* Here are some attributes you can add to chars to print */ |
| 3317 | |
| 3318 | SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES); |
| 3319 | SetDictInt("A_NORMAL", A_NORMAL); |
| 3320 | SetDictInt("A_STANDOUT", A_STANDOUT); |
| 3321 | SetDictInt("A_UNDERLINE", A_UNDERLINE); |
| 3322 | SetDictInt("A_REVERSE", A_REVERSE); |
| 3323 | SetDictInt("A_BLINK", A_BLINK); |
| 3324 | SetDictInt("A_DIM", A_DIM); |
| 3325 | SetDictInt("A_BOLD", A_BOLD); |
| 3326 | SetDictInt("A_ALTCHARSET", A_ALTCHARSET); |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 3327 | #if !defined(__NetBSD__) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3328 | SetDictInt("A_INVIS", A_INVIS); |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 3329 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3330 | SetDictInt("A_PROTECT", A_PROTECT); |
| 3331 | SetDictInt("A_CHARTEXT", A_CHARTEXT); |
| 3332 | SetDictInt("A_COLOR", A_COLOR); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 3333 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3334 | /* The following are never available with strict SYSV curses */ |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 3335 | #ifdef A_HORIZONTAL |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3336 | SetDictInt("A_HORIZONTAL", A_HORIZONTAL); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 3337 | #endif |
| 3338 | #ifdef A_LEFT |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3339 | SetDictInt("A_LEFT", A_LEFT); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 3340 | #endif |
| 3341 | #ifdef A_LOW |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3342 | SetDictInt("A_LOW", A_LOW); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 3343 | #endif |
| 3344 | #ifdef A_RIGHT |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3345 | SetDictInt("A_RIGHT", A_RIGHT); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 3346 | #endif |
| 3347 | #ifdef A_TOP |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3348 | SetDictInt("A_TOP", A_TOP); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 3349 | #endif |
| 3350 | #ifdef A_VERTICAL |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3351 | SetDictInt("A_VERTICAL", A_VERTICAL); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 3352 | #endif |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 3353 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3354 | SetDictInt("COLOR_BLACK", COLOR_BLACK); |
| 3355 | SetDictInt("COLOR_RED", COLOR_RED); |
| 3356 | SetDictInt("COLOR_GREEN", COLOR_GREEN); |
| 3357 | SetDictInt("COLOR_YELLOW", COLOR_YELLOW); |
| 3358 | SetDictInt("COLOR_BLUE", COLOR_BLUE); |
| 3359 | SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA); |
| 3360 | SetDictInt("COLOR_CYAN", COLOR_CYAN); |
| 3361 | SetDictInt("COLOR_WHITE", COLOR_WHITE); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3362 | |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 3363 | #ifdef NCURSES_MOUSE_VERSION |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3364 | /* Mouse-related constants */ |
| 3365 | SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED); |
| 3366 | SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED); |
| 3367 | SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED); |
| 3368 | SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED); |
| 3369 | SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED); |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 3370 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3371 | SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED); |
| 3372 | SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED); |
| 3373 | SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED); |
| 3374 | SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED); |
| 3375 | SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED); |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 3376 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3377 | SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED); |
| 3378 | SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED); |
| 3379 | SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED); |
| 3380 | SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED); |
| 3381 | SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED); |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 3382 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3383 | SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED); |
| 3384 | SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED); |
| 3385 | SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED); |
| 3386 | SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED); |
| 3387 | SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED); |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 3388 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3389 | SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT); |
| 3390 | SetDictInt("BUTTON_CTRL", BUTTON_CTRL); |
| 3391 | SetDictInt("BUTTON_ALT", BUTTON_ALT); |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 3392 | |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3393 | SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS); |
| 3394 | SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION); |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 3395 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3396 | /* Now set everything up for KEY_ variables */ |
| 3397 | { |
| 3398 | int key; |
| 3399 | char *key_n; |
| 3400 | char *key_n2; |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 3401 | #if !defined(__NetBSD__) |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3402 | for (key=KEY_MIN;key < KEY_MAX; key++) { |
| 3403 | key_n = (char *)keyname(key); |
| 3404 | if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0) |
| 3405 | continue; |
| 3406 | if (strncmp(key_n,"KEY_F(",6)==0) { |
| 3407 | char *p1, *p2; |
| 3408 | key_n2 = malloc(strlen(key_n)+1); |
| 3409 | if (!key_n2) { |
| 3410 | PyErr_NoMemory(); |
| 3411 | break; |
| 3412 | } |
| 3413 | p1 = key_n; |
| 3414 | p2 = key_n2; |
| 3415 | while (*p1) { |
| 3416 | if (*p1 != '(' && *p1 != ')') { |
| 3417 | *p2 = *p1; |
| 3418 | p2++; |
| 3419 | } |
| 3420 | p1++; |
| 3421 | } |
| 3422 | *p2 = (char)0; |
| 3423 | } else |
| 3424 | key_n2 = key_n; |
| 3425 | SetDictInt(key_n2,key); |
| 3426 | if (key_n2 != key_n) |
| 3427 | free(key_n2); |
| 3428 | } |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 3429 | #endif |
Victor Stinner | 26486ea | 2010-05-15 22:23:53 +0000 | [diff] [blame] | 3430 | SetDictInt("KEY_MIN", KEY_MIN); |
| 3431 | SetDictInt("KEY_MAX", KEY_MAX); |
| 3432 | } |
| 3433 | return m; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 3434 | } |