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