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