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