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