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; |
| 893 | } else if (rtn<=255) |
Benjamin Peterson | a921fb0 | 2009-04-03 22:18:11 +0000 | [diff] [blame] | 894 | return Py_BuildValue("C", rtn); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 895 | else |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 896 | #if defined(__NetBSD__) |
Neal Norwitz | 9af3ae4 | 2007-08-24 00:06:36 +0000 | [diff] [blame] | 897 | return PyUnicode_FromString(unctrl(rtn)); |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 898 | #else |
Neal Norwitz | 9af3ae4 | 2007-08-24 00:06:36 +0000 | [diff] [blame] | 899 | return PyUnicode_FromString((const char *)keyname(rtn)); |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 900 | #endif |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 904 | PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 905 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 906 | int x, y, n; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 907 | char rtn[1024]; /* This should be big enough.. I hope */ |
| 908 | int rtn2; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 909 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 910 | switch (PyTuple_Size(args)) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 911 | case 0: |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 912 | Py_BEGIN_ALLOW_THREADS |
Andrew M. Kuchling | 52a14c3 | 2005-06-09 17:53:27 +0000 | [diff] [blame] | 913 | rtn2 = wgetnstr(self->win,rtn, 1023); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 914 | Py_END_ALLOW_THREADS |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 915 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 916 | case 1: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 917 | if (!PyArg_ParseTuple(args,"i;n", &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 918 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 919 | Py_BEGIN_ALLOW_THREADS |
Andrew M. Kuchling | 52a14c3 | 2005-06-09 17:53:27 +0000 | [diff] [blame] | 920 | rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023)); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 921 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 922 | break; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 923 | case 2: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 924 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 925 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 926 | Py_BEGIN_ALLOW_THREADS |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 927 | #ifdef STRICT_SYSV_CURSES |
| 928 | rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023); |
| 929 | #else |
Andrew M. Kuchling | 52a14c3 | 2005-06-09 17:53:27 +0000 | [diff] [blame] | 930 | rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023); |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 931 | #endif |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 932 | Py_END_ALLOW_THREADS |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 933 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 934 | case 3: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 935 | if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 936 | return NULL; |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 937 | #ifdef STRICT_SYSV_CURSES |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 938 | Py_BEGIN_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 939 | rtn2 = wmove(self->win,y,x)==ERR ? ERR : |
Andrew M. Kuchling | 52a14c3 | 2005-06-09 17:53:27 +0000 | [diff] [blame] | 940 | wgetnstr(self->win, rtn, MIN(n, 1023)); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 941 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 942 | #else |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 943 | Py_BEGIN_ALLOW_THREADS |
Andrew M. Kuchling | 52a14c3 | 2005-06-09 17:53:27 +0000 | [diff] [blame] | 944 | rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023)); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 945 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 946 | #endif |
| 947 | break; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 948 | default: |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 949 | PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 950 | return NULL; |
| 951 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 952 | if (rtn2 == ERR) |
| 953 | rtn[0] = 0; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 954 | return PyBytes_FromString(rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 958 | PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 959 | { |
| 960 | PyObject *temp; |
| 961 | chtype ch; |
| 962 | int n, x, y, code = OK; |
| 963 | attr_t attr = A_NORMAL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 964 | long lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 965 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 966 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 967 | case 2: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 968 | if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 969 | return NULL; |
| 970 | break; |
| 971 | case 3: |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 972 | 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] | 973 | return NULL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 974 | attr = lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 975 | break; |
| 976 | case 4: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 977 | 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] | 978 | return NULL; |
| 979 | code = wmove(self->win, y, x); |
| 980 | break; |
| 981 | case 5: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 982 | if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 983 | &y, &x, &temp, &n, &lattr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 984 | return NULL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 985 | attr = lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 986 | code = wmove(self->win, y, x); |
Andrew M. Kuchling | 16e65a0 | 2001-10-20 16:05:52 +0000 | [diff] [blame] | 987 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 988 | default: |
Andrew M. Kuchling | 16e65a0 | 2001-10-20 16:05:52 +0000 | [diff] [blame] | 989 | PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 990 | return NULL; |
| 991 | } |
| 992 | |
| 993 | if (code != ERR) { |
| 994 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 995 | PyErr_SetString(PyExc_TypeError, |
| 996 | "argument 1 or 3 must be a ch or an int"); |
| 997 | return NULL; |
| 998 | } |
| 999 | return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline"); |
| 1000 | } else |
| 1001 | return PyCursesCheckERR(code, "wmove"); |
| 1002 | } |
| 1003 | |
| 1004 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1005 | PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1006 | { |
| 1007 | int rtn, x, y, use_xy = FALSE; |
| 1008 | PyObject *temp; |
| 1009 | chtype ch = 0; |
| 1010 | attr_t attr = A_NORMAL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1011 | long lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1012 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1013 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1014 | case 1: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1015 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1016 | return NULL; |
| 1017 | break; |
| 1018 | case 2: |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1019 | if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1020 | return NULL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1021 | attr = lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1022 | break; |
| 1023 | case 3: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1024 | 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] | 1025 | return NULL; |
| 1026 | use_xy = TRUE; |
| 1027 | break; |
| 1028 | case 4: |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1029 | 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] | 1030 | return NULL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1031 | attr = lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1032 | use_xy = TRUE; |
| 1033 | break; |
| 1034 | default: |
| 1035 | PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments"); |
| 1036 | return NULL; |
| 1037 | } |
| 1038 | |
| 1039 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 1040 | PyErr_SetString(PyExc_TypeError, |
| 1041 | "argument 1 or 3 must be a ch or an int"); |
| 1042 | return NULL; |
| 1043 | } |
| 1044 | |
| 1045 | if (use_xy == TRUE) |
| 1046 | rtn = mvwinsch(self->win,y,x, ch | attr); |
| 1047 | else { |
| 1048 | rtn = winsch(self->win, ch | attr); |
| 1049 | } |
| 1050 | return PyCursesCheckERR(rtn, "insch"); |
| 1051 | } |
| 1052 | |
| 1053 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1054 | PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1055 | { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1056 | int x, y, rtn; |
| 1057 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1058 | switch (PyTuple_Size(args)) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1059 | case 0: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1060 | rtn = winch(self->win); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1061 | break; |
| 1062 | case 2: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1063 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1064 | return NULL; |
| 1065 | rtn = mvwinch(self->win,y,x); |
| 1066 | break; |
| 1067 | default: |
| 1068 | PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments"); |
| 1069 | return NULL; |
| 1070 | } |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1071 | return PyLong_FromLong((long) rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1075 | PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1076 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1077 | int x, y, n; |
| 1078 | char rtn[1024]; /* This should be big enough.. I hope */ |
| 1079 | int rtn2; |
| 1080 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1081 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1082 | case 0: |
Andrew M. Kuchling | 52a14c3 | 2005-06-09 17:53:27 +0000 | [diff] [blame] | 1083 | rtn2 = winnstr(self->win,rtn, 1023); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1084 | break; |
| 1085 | case 1: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1086 | if (!PyArg_ParseTuple(args,"i;n", &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1087 | return NULL; |
Andrew M. Kuchling | 52a14c3 | 2005-06-09 17:53:27 +0000 | [diff] [blame] | 1088 | rtn2 = winnstr(self->win,rtn,MIN(n,1023)); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1089 | break; |
| 1090 | case 2: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1091 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1092 | return NULL; |
Andrew M. Kuchling | 52a14c3 | 2005-06-09 17:53:27 +0000 | [diff] [blame] | 1093 | rtn2 = mvwinnstr(self->win,y,x,rtn,1023); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1094 | break; |
| 1095 | case 3: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1096 | if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1097 | return NULL; |
Andrew M. Kuchling | 52a14c3 | 2005-06-09 17:53:27 +0000 | [diff] [blame] | 1098 | rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023)); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1099 | break; |
| 1100 | default: |
| 1101 | PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1102 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1103 | } |
| 1104 | if (rtn2 == ERR) |
| 1105 | rtn[0] = 0; |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 1106 | return PyBytes_FromString(rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1110 | PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1111 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1112 | int rtn; |
| 1113 | int x, y; |
| 1114 | char *str; |
| 1115 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1116 | long lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1117 | int use_xy = FALSE, use_attr = FALSE; |
| 1118 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1119 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1120 | case 1: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1121 | if (!PyArg_ParseTuple(args,"s;str", &str)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1122 | return NULL; |
| 1123 | break; |
| 1124 | case 2: |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1125 | if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1126 | return NULL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1127 | attr = lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1128 | use_attr = TRUE; |
| 1129 | break; |
| 1130 | case 3: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1131 | if (!PyArg_ParseTuple(args,"iis;y,x,str", &y, &x, &str)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1132 | return NULL; |
| 1133 | use_xy = TRUE; |
| 1134 | break; |
| 1135 | case 4: |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1136 | 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] | 1137 | return NULL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1138 | attr = lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1139 | use_xy = use_attr = TRUE; |
| 1140 | break; |
| 1141 | default: |
| 1142 | PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1143 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | if (use_attr == TRUE) { |
| 1147 | attr_old = getattrs(self->win); |
| 1148 | wattrset(self->win,attr); |
| 1149 | } |
| 1150 | if (use_xy == TRUE) |
| 1151 | rtn = mvwinsstr(self->win,y,x,str); |
| 1152 | else |
| 1153 | rtn = winsstr(self->win,str); |
| 1154 | if (use_attr == TRUE) |
| 1155 | wattrset(self->win,attr_old); |
| 1156 | return PyCursesCheckERR(rtn, "insstr"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1160 | PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1161 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1162 | int rtn, x, y, n; |
| 1163 | char *str; |
| 1164 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1165 | long lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1166 | int use_xy = FALSE, use_attr = FALSE; |
| 1167 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1168 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1169 | case 2: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1170 | if (!PyArg_ParseTuple(args,"si;str,n", &str, &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1171 | return NULL; |
| 1172 | break; |
| 1173 | case 3: |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1174 | if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1175 | return NULL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1176 | attr = lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1177 | use_attr = TRUE; |
| 1178 | break; |
| 1179 | case 4: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1180 | 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] | 1181 | return NULL; |
| 1182 | use_xy = TRUE; |
| 1183 | break; |
| 1184 | case 5: |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1185 | 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] | 1186 | return NULL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1187 | attr = lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1188 | use_xy = use_attr = TRUE; |
| 1189 | break; |
| 1190 | default: |
| 1191 | PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1192 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | if (use_attr == TRUE) { |
| 1196 | attr_old = getattrs(self->win); |
| 1197 | wattrset(self->win,attr); |
| 1198 | } |
| 1199 | if (use_xy == TRUE) |
| 1200 | rtn = mvwinsnstr(self->win,y,x,str,n); |
| 1201 | else |
| 1202 | rtn = winsnstr(self->win,str,n); |
| 1203 | if (use_attr == TRUE) |
| 1204 | wattrset(self->win,attr_old); |
| 1205 | return PyCursesCheckERR(rtn, "insnstr"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1209 | PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1210 | { |
| 1211 | int line, erg; |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1212 | if (!PyArg_ParseTuple(args,"i;line", &line)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1213 | return NULL; |
| 1214 | erg = is_linetouched(self->win, line); |
| 1215 | if (erg == ERR) { |
| 1216 | PyErr_SetString(PyExc_TypeError, |
| 1217 | "is_linetouched: line number outside of boundaries"); |
| 1218 | return NULL; |
| 1219 | } else |
| 1220 | if (erg == FALSE) { |
| 1221 | Py_INCREF(Py_False); |
| 1222 | return Py_False; |
| 1223 | } else { |
| 1224 | Py_INCREF(Py_True); |
| 1225 | return Py_True; |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1230 | PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1231 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1232 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1233 | int rtn; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1234 | |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 1235 | #ifndef WINDOW_HAS_FLAGS |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1236 | if (0) { |
| 1237 | #else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1238 | if (self->win->_flags & _ISPAD) { |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1239 | #endif |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1240 | switch(PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1241 | case 6: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1242 | if (!PyArg_ParseTuple(args, |
| 1243 | "iiiiii;" \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1244 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", |
| 1245 | &pminrow, &pmincol, &sminrow, |
| 1246 | &smincol, &smaxrow, &smaxcol)) |
| 1247 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1248 | Py_BEGIN_ALLOW_THREADS |
| 1249 | rtn = pnoutrefresh(self->win, |
| 1250 | pminrow, pmincol, sminrow, |
Andrew M. Kuchling | b6e4687 | 2000-06-27 15:01:10 +0000 | [diff] [blame] | 1251 | smincol, smaxrow, smaxcol); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1252 | Py_END_ALLOW_THREADS |
| 1253 | return PyCursesCheckERR(rtn, "pnoutrefresh"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1254 | default: |
| 1255 | PyErr_SetString(PyCursesError, |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1256 | "noutrefresh() called for a pad " |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1257 | "requires 6 arguments"); |
| 1258 | return NULL; |
| 1259 | } |
| 1260 | } else { |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1261 | if (!PyArg_ParseTuple(args, ":noutrefresh")) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1262 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1263 | |
| 1264 | Py_BEGIN_ALLOW_THREADS |
| 1265 | rtn = wnoutrefresh(self->win); |
| 1266 | Py_END_ALLOW_THREADS |
| 1267 | return PyCursesCheckERR(rtn, "wnoutrefresh"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | static PyObject * |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1272 | PyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args) |
| 1273 | { |
| 1274 | PyCursesWindowObject *temp; |
| 1275 | int use_copywin = FALSE; |
| 1276 | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; |
| 1277 | int rtn; |
| 1278 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1279 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1280 | case 1: |
| 1281 | if (!PyArg_ParseTuple(args, "O!;window object", |
| 1282 | &PyCursesWindow_Type, &temp)) |
| 1283 | return NULL; |
| 1284 | break; |
| 1285 | case 7: |
Neal Norwitz | 88bbd73 | 2006-01-10 07:05:44 +0000 | [diff] [blame] | 1286 | 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] | 1287 | &PyCursesWindow_Type, &temp, &sminrow, &smincol, |
| 1288 | &dminrow, &dmincol, &dmaxrow, &dmaxcol)) |
| 1289 | return NULL; |
| 1290 | use_copywin = TRUE; |
| 1291 | break; |
| 1292 | default: |
| 1293 | PyErr_SetString(PyExc_TypeError, |
| 1294 | "overlay requires one or seven arguments"); |
| 1295 | return NULL; |
| 1296 | } |
| 1297 | |
| 1298 | if (use_copywin == TRUE) { |
| 1299 | rtn = copywin(self->win, temp->win, sminrow, smincol, |
| 1300 | dminrow, dmincol, dmaxrow, dmaxcol, TRUE); |
| 1301 | return PyCursesCheckERR(rtn, "copywin"); |
| 1302 | } |
| 1303 | else { |
| 1304 | rtn = overlay(self->win, temp->win); |
| 1305 | return PyCursesCheckERR(rtn, "overlay"); |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | static PyObject * |
| 1310 | PyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args) |
| 1311 | { |
| 1312 | PyCursesWindowObject *temp; |
| 1313 | int use_copywin = FALSE; |
| 1314 | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; |
| 1315 | int rtn; |
| 1316 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1317 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1318 | case 1: |
| 1319 | if (!PyArg_ParseTuple(args, "O!;window object", |
| 1320 | &PyCursesWindow_Type, &temp)) |
| 1321 | return NULL; |
| 1322 | break; |
| 1323 | case 7: |
Neal Norwitz | 88bbd73 | 2006-01-10 07:05:44 +0000 | [diff] [blame] | 1324 | 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] | 1325 | &PyCursesWindow_Type, &temp, &sminrow, &smincol, |
| 1326 | &dminrow, &dmincol, &dmaxrow, &dmaxcol)) |
| 1327 | return NULL; |
| 1328 | use_copywin = TRUE; |
| 1329 | break; |
| 1330 | default: |
| 1331 | PyErr_SetString(PyExc_TypeError, |
| 1332 | "overwrite requires one or seven arguments"); |
| 1333 | return NULL; |
| 1334 | } |
| 1335 | |
| 1336 | if (use_copywin == TRUE) { |
| 1337 | rtn = copywin(self->win, temp->win, sminrow, smincol, |
| 1338 | dminrow, dmincol, dmaxrow, dmaxcol, FALSE); |
| 1339 | return PyCursesCheckERR(rtn, "copywin"); |
| 1340 | } |
| 1341 | else { |
| 1342 | rtn = overwrite(self->win, temp->win); |
| 1343 | return PyCursesCheckERR(rtn, "overwrite"); |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | static PyObject * |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1348 | PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *stream) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1349 | { |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1350 | /* We have to simulate this by writing to a temporary FILE*, |
| 1351 | then reading back, then writing to the argument stream. */ |
| 1352 | char fn[100]; |
| 1353 | int fd; |
| 1354 | FILE *fp; |
| 1355 | PyObject *res; |
Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame] | 1356 | |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1357 | strcpy(fn, "/tmp/py.curses.putwin.XXXXXX"); |
| 1358 | fd = mkstemp(fn); |
| 1359 | if (fd < 0) |
| 1360 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
| 1361 | fp = fdopen(fd, "wb+"); |
| 1362 | if (fp == NULL) { |
| 1363 | close(fd); |
Guido van Rossum | 150b7d7 | 2007-08-30 23:34:01 +0000 | [diff] [blame] | 1364 | remove(fn); |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1365 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
| 1366 | } |
| 1367 | res = PyCursesCheckERR(putwin(self->win, fp), "putwin"); |
| 1368 | if (res == NULL) { |
| 1369 | fclose(fp); |
Guido van Rossum | 150b7d7 | 2007-08-30 23:34:01 +0000 | [diff] [blame] | 1370 | remove(fn); |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1371 | return res; |
| 1372 | } |
| 1373 | fseek(fp, 0, 0); |
| 1374 | while (1) { |
| 1375 | char buf[BUFSIZ]; |
| 1376 | int n = fread(buf, 1, BUFSIZ, fp); |
| 1377 | if (n <= 0) |
| 1378 | break; |
| 1379 | Py_DECREF(res); |
| 1380 | res = PyObject_CallMethod(stream, "write", "y#", buf, n); |
| 1381 | if (res == NULL) |
| 1382 | break; |
| 1383 | } |
| 1384 | fclose(fp); |
| 1385 | remove(fn); |
| 1386 | return res; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1390 | PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1391 | { |
| 1392 | int beg, num; |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1393 | if (!PyArg_ParseTuple(args, "ii;beg,num", &beg, &num)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1394 | return NULL; |
| 1395 | return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln"); |
| 1396 | } |
| 1397 | |
| 1398 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1399 | PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1400 | { |
| 1401 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1402 | int rtn; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1403 | |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 1404 | #ifndef WINDOW_HAS_FLAGS |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1405 | if (0) { |
| 1406 | #else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1407 | if (self->win->_flags & _ISPAD) { |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1408 | #endif |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1409 | switch(PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1410 | case 6: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1411 | if (!PyArg_ParseTuple(args, |
| 1412 | "iiiiii;" \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1413 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", |
| 1414 | &pminrow, &pmincol, &sminrow, |
| 1415 | &smincol, &smaxrow, &smaxcol)) |
| 1416 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1417 | |
| 1418 | Py_BEGIN_ALLOW_THREADS |
| 1419 | rtn = prefresh(self->win, |
| 1420 | pminrow, pmincol, sminrow, |
Andrew M. Kuchling | b6e4687 | 2000-06-27 15:01:10 +0000 | [diff] [blame] | 1421 | smincol, smaxrow, smaxcol); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1422 | Py_END_ALLOW_THREADS |
| 1423 | return PyCursesCheckERR(rtn, "prefresh"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1424 | default: |
| 1425 | PyErr_SetString(PyCursesError, |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1426 | "refresh() for a pad requires 6 arguments"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1427 | return NULL; |
| 1428 | } |
| 1429 | } else { |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1430 | if (!PyArg_ParseTuple(args, ":refresh")) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1431 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1432 | Py_BEGIN_ALLOW_THREADS |
| 1433 | rtn = wrefresh(self->win); |
| 1434 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1435 | return PyCursesCheckERR(rtn, "prefresh"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1436 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1440 | PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1441 | { |
| 1442 | int x, y; |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1443 | if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1444 | return NULL; |
| 1445 | return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1449 | PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1450 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1451 | WINDOW *win; |
| 1452 | int nlines, ncols, begin_y, begin_x; |
| 1453 | |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1454 | nlines = 0; |
| 1455 | ncols = 0; |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1456 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1457 | case 2: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1458 | 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] | 1459 | return NULL; |
| 1460 | break; |
| 1461 | case 4: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1462 | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1463 | &nlines,&ncols,&begin_y,&begin_x)) |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1464 | return NULL; |
| 1465 | break; |
| 1466 | default: |
| 1467 | PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1468 | return NULL; |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1469 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1470 | |
Andrew M. Kuchling | 8353f62 | 2000-07-26 18:36:27 +0000 | [diff] [blame] | 1471 | /* 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] | 1472 | #ifdef WINDOW_HAS_FLAGS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1473 | if (self->win->_flags & _ISPAD) |
| 1474 | win = subpad(self->win, nlines, ncols, begin_y, begin_x); |
| 1475 | else |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1476 | #endif |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1477 | win = subwin(self->win, nlines, ncols, begin_y, begin_x); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1478 | |
| 1479 | if (win == NULL) { |
| 1480 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1481 | return NULL; |
| 1482 | } |
| 1483 | |
| 1484 | return (PyObject *)PyCursesWindow_New(win); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1488 | PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1489 | { |
Andrew M. Kuchling | e1c4352 | 2001-01-29 20:31:29 +0000 | [diff] [blame] | 1490 | int nlines; |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1491 | switch(PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1492 | case 0: |
| 1493 | return PyCursesCheckERR(scroll(self->win), "scroll"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1494 | case 1: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1495 | if (!PyArg_ParseTuple(args, "i;nlines", &nlines)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1496 | return NULL; |
Andrew M. Kuchling | e1c4352 | 2001-01-29 20:31:29 +0000 | [diff] [blame] | 1497 | return PyCursesCheckERR(wscrl(self->win, nlines), "scroll"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1498 | default: |
| 1499 | PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1500 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1501 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1505 | PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1506 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1507 | int st, cnt, val; |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1508 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1509 | case 2: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1510 | if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1511 | return NULL; |
| 1512 | return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1513 | case 3: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1514 | if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1515 | return NULL; |
| 1516 | return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline"); |
| 1517 | default: |
| 1518 | PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1519 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1524 | PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1525 | { |
| 1526 | PyObject *temp; |
| 1527 | chtype ch; |
| 1528 | int n, x, y, code = OK; |
| 1529 | attr_t attr = A_NORMAL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1530 | long lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1531 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1532 | switch (PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1533 | case 2: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1534 | if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1535 | return NULL; |
| 1536 | break; |
| 1537 | case 3: |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1538 | 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] | 1539 | return NULL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1540 | attr = lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1541 | break; |
| 1542 | case 4: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1543 | 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] | 1544 | return NULL; |
| 1545 | code = wmove(self->win, y, x); |
| 1546 | break; |
| 1547 | case 5: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1548 | if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1549 | &y, &x, &temp, &n, &lattr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1550 | return NULL; |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1551 | attr = lattr; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1552 | code = wmove(self->win, y, x); |
Andrew M. Kuchling | 16e65a0 | 2001-10-20 16:05:52 +0000 | [diff] [blame] | 1553 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1554 | default: |
Andrew M. Kuchling | 16e65a0 | 2001-10-20 16:05:52 +0000 | [diff] [blame] | 1555 | PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1556 | return NULL; |
| 1557 | } |
| 1558 | |
| 1559 | if (code != ERR) { |
| 1560 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 1561 | PyErr_SetString(PyExc_TypeError, |
| 1562 | "argument 1 or 3 must be a ch or an int"); |
| 1563 | return NULL; |
| 1564 | } |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1565 | return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1566 | } else |
| 1567 | return PyCursesCheckERR(code, "wmove"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | static PyMethodDef PyCursesWindow_Methods[] = { |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1571 | {"addch", (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS}, |
| 1572 | {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS}, |
| 1573 | {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS}, |
Christian Heimes | 2380ac7 | 2008-01-09 00:17:24 +0000 | [diff] [blame] | 1574 | {"attroff", (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS}, |
| 1575 | {"attron", (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS}, |
| 1576 | {"attrset", (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS}, |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1577 | {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS}, |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 1578 | {"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS}, |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1579 | {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1580 | {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS}, |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1581 | {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS}, |
| 1582 | {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS}, |
| 1583 | {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS}, |
| 1584 | {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS}, |
| 1585 | {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS}, |
| 1586 | {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS}, |
| 1587 | {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS}, |
| 1588 | {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS}, |
| 1589 | {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS}, |
| 1590 | {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1591 | #ifdef NCURSES_MOUSE_VERSION |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1592 | {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1593 | #endif |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1594 | {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS}, |
| 1595 | {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS}, |
| 1596 | {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS}, |
| 1597 | {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS}, |
| 1598 | {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS}, |
| 1599 | {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS}, |
| 1600 | {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS}, |
| 1601 | {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS}, |
| 1602 | {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS}, |
| 1603 | {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS}, |
| 1604 | {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS}, |
| 1605 | {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS}, |
| 1606 | {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS}, |
| 1607 | {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS}, |
| 1608 | {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS}, |
| 1609 | {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS}, |
| 1610 | {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS}, |
| 1611 | {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS}, |
| 1612 | {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS}, |
| 1613 | {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS}, |
| 1614 | {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS}, |
| 1615 | {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS}, |
| 1616 | {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS}, |
| 1617 | {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS}, |
| 1618 | {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS}, |
| 1619 | {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS}, |
| 1620 | {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS}, |
| 1621 | {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS}, |
| 1622 | {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS}, |
| 1623 | {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, |
| 1624 | /* Backward compatibility alias -- remove in Python 2.3 */ |
| 1625 | {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, |
Andrew M. Kuchling | 16e65a0 | 2001-10-20 16:05:52 +0000 | [diff] [blame] | 1626 | {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS}, |
| 1627 | {"overwrite", (PyCFunction)PyCursesWindow_Overwrite, |
| 1628 | METH_VARARGS}, |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1629 | {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_O}, |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 1630 | {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS}, |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1631 | {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS}, |
| 1632 | {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS}, |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 1633 | #ifndef STRICT_SYSV_CURSES |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1634 | {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1635 | #endif |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1636 | {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS}, |
| 1637 | {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS}, |
| 1638 | {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS}, |
| 1639 | {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS}, |
| 1640 | {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS}, |
| 1641 | {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, |
| 1642 | {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, |
| 1643 | {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS}, |
| 1644 | {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS}, |
| 1645 | {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS}, |
| 1646 | {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS}, |
| 1647 | {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS}, |
| 1648 | {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS}, |
| 1649 | {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS}, |
| 1650 | {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS}, |
Andrew M. Kuchling | 16e65a0 | 2001-10-20 16:05:52 +0000 | [diff] [blame] | 1651 | {NULL, NULL} /* sentinel */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1652 | }; |
| 1653 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1654 | /* -------------------------------------------------------*/ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1655 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1656 | PyTypeObject PyCursesWindow_Type = { |
Martin v. Löwis | 9f2e346 | 2007-07-21 17:22:18 +0000 | [diff] [blame] | 1657 | PyVarObject_HEAD_INIT(NULL, 0) |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 1658 | "_curses.curses window", /*tp_name*/ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1659 | sizeof(PyCursesWindowObject), /*tp_basicsize*/ |
| 1660 | 0, /*tp_itemsize*/ |
| 1661 | /* methods */ |
| 1662 | (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/ |
| 1663 | 0, /*tp_print*/ |
Amaury Forgeot d'Arc | 1f900f1 | 2008-07-02 22:38:47 +0000 | [diff] [blame] | 1664 | (getattrfunc)0, /*tp_getattr*/ |
| 1665 | (setattrfunc)0, /*tp_setattr*/ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame] | 1666 | 0, /*tp_reserved*/ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1667 | 0, /*tp_repr*/ |
| 1668 | 0, /*tp_as_number*/ |
| 1669 | 0, /*tp_as_sequence*/ |
| 1670 | 0, /*tp_as_mapping*/ |
| 1671 | 0, /*tp_hash*/ |
Amaury Forgeot d'Arc | 1f900f1 | 2008-07-02 22:38:47 +0000 | [diff] [blame] | 1672 | 0, /*tp_call*/ |
| 1673 | 0, /*tp_str*/ |
| 1674 | 0, /*tp_getattro*/ |
| 1675 | 0, /*tp_setattro*/ |
| 1676 | 0, /*tp_as_buffer*/ |
| 1677 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1678 | 0, /*tp_doc*/ |
| 1679 | 0, /*tp_traverse*/ |
| 1680 | 0, /*tp_clear*/ |
| 1681 | 0, /*tp_richcompare*/ |
| 1682 | 0, /*tp_weaklistoffset*/ |
| 1683 | 0, /*tp_iter*/ |
| 1684 | 0, /*tp_iternext*/ |
| 1685 | PyCursesWindow_Methods, /*tp_methods*/ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1686 | }; |
| 1687 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1688 | /********************************************************************* |
| 1689 | Global Functions |
| 1690 | **********************************************************************/ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1691 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1692 | NoArgNoReturnFunction(beep) |
| 1693 | NoArgNoReturnFunction(def_prog_mode) |
| 1694 | NoArgNoReturnFunction(def_shell_mode) |
| 1695 | NoArgNoReturnFunction(doupdate) |
| 1696 | NoArgNoReturnFunction(endwin) |
| 1697 | NoArgNoReturnFunction(flash) |
| 1698 | NoArgNoReturnFunction(nocbreak) |
| 1699 | NoArgNoReturnFunction(noecho) |
| 1700 | NoArgNoReturnFunction(nonl) |
| 1701 | NoArgNoReturnFunction(noraw) |
| 1702 | NoArgNoReturnFunction(reset_prog_mode) |
| 1703 | NoArgNoReturnFunction(reset_shell_mode) |
| 1704 | NoArgNoReturnFunction(resetty) |
| 1705 | NoArgNoReturnFunction(savetty) |
| 1706 | |
| 1707 | NoArgOrFlagNoReturnFunction(cbreak) |
| 1708 | NoArgOrFlagNoReturnFunction(echo) |
| 1709 | NoArgOrFlagNoReturnFunction(nl) |
| 1710 | NoArgOrFlagNoReturnFunction(raw) |
| 1711 | |
| 1712 | NoArgReturnIntFunction(baudrate) |
| 1713 | NoArgReturnIntFunction(termattrs) |
| 1714 | |
| 1715 | NoArgReturnStringFunction(termname) |
| 1716 | NoArgReturnStringFunction(longname) |
| 1717 | |
| 1718 | NoArgTrueFalseFunction(can_change_color) |
| 1719 | NoArgTrueFalseFunction(has_colors) |
| 1720 | NoArgTrueFalseFunction(has_ic) |
| 1721 | NoArgTrueFalseFunction(has_il) |
| 1722 | NoArgTrueFalseFunction(isendwin) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1723 | NoArgNoReturnVoidFunction(flushinp) |
| 1724 | NoArgNoReturnVoidFunction(noqiflush) |
| 1725 | |
| 1726 | static PyObject * |
Christian Heimes | af98da1 | 2008-01-27 15:18:18 +0000 | [diff] [blame] | 1727 | PyCurses_filter(PyObject *self) |
| 1728 | { |
| 1729 | /* not checking for PyCursesInitialised here since filter() must |
| 1730 | be called before initscr() */ |
| 1731 | filter(); |
| 1732 | Py_INCREF(Py_None); |
| 1733 | return Py_None; |
| 1734 | } |
| 1735 | |
| 1736 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1737 | PyCurses_Color_Content(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1738 | { |
| 1739 | short color,r,g,b; |
| 1740 | |
| 1741 | PyCursesInitialised |
| 1742 | PyCursesInitialisedColor |
| 1743 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1744 | if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1745 | |
| 1746 | if (color_content(color, &r, &g, &b) != ERR) |
| 1747 | return Py_BuildValue("(iii)", r, g, b); |
| 1748 | else { |
| 1749 | PyErr_SetString(PyCursesError, |
| 1750 | "Argument 1 was out of range. Check value of COLORS."); |
| 1751 | return NULL; |
| 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1756 | PyCurses_color_pair(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1757 | { |
| 1758 | int n; |
| 1759 | |
| 1760 | PyCursesInitialised |
| 1761 | PyCursesInitialisedColor |
| 1762 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1763 | if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL; |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1764 | return PyLong_FromLong((long) (n << 8)); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1768 | PyCurses_Curs_Set(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1769 | { |
| 1770 | int vis,erg; |
| 1771 | |
| 1772 | PyCursesInitialised |
| 1773 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1774 | if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1775 | |
| 1776 | erg = curs_set(vis); |
| 1777 | if (erg == ERR) return PyCursesCheckERR(erg, "curs_set"); |
| 1778 | |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1779 | return PyLong_FromLong((long) erg); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1783 | PyCurses_Delay_Output(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1784 | { |
| 1785 | int ms; |
| 1786 | |
| 1787 | PyCursesInitialised |
| 1788 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1789 | if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1790 | |
| 1791 | return PyCursesCheckERR(delay_output(ms), "delay_output"); |
| 1792 | } |
| 1793 | |
| 1794 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1795 | PyCurses_EraseChar(PyObject *self) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1796 | { |
| 1797 | char ch; |
| 1798 | |
| 1799 | PyCursesInitialised |
| 1800 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1801 | ch = erasechar(); |
| 1802 | |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 1803 | return PyBytes_FromStringAndSize(&ch, 1); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1807 | PyCurses_getsyx(PyObject *self) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1808 | { |
Alexandre Vassalotti | cf7128c | 2009-07-17 08:31:44 +0000 | [diff] [blame] | 1809 | int x = 0; |
| 1810 | int y = 0; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1811 | |
| 1812 | PyCursesInitialised |
| 1813 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1814 | getsyx(y, x); |
| 1815 | |
| 1816 | return Py_BuildValue("(ii)", y, x); |
| 1817 | } |
| 1818 | |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1819 | #ifdef NCURSES_MOUSE_VERSION |
| 1820 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1821 | PyCurses_GetMouse(PyObject *self) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1822 | { |
| 1823 | int rtn; |
| 1824 | MEVENT event; |
| 1825 | |
| 1826 | PyCursesInitialised |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1827 | |
| 1828 | rtn = getmouse( &event ); |
| 1829 | if (rtn == ERR) { |
| 1830 | PyErr_SetString(PyCursesError, "getmouse() returned ERR"); |
| 1831 | return NULL; |
| 1832 | } |
| 1833 | return Py_BuildValue("(hiiil)", |
| 1834 | (short)event.id, |
| 1835 | event.x, event.y, event.z, |
| 1836 | (long) event.bstate); |
| 1837 | } |
| 1838 | |
| 1839 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1840 | PyCurses_UngetMouse(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1841 | { |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1842 | MEVENT event; |
| 1843 | |
| 1844 | PyCursesInitialised |
Neal Norwitz | 88bbd73 | 2006-01-10 07:05:44 +0000 | [diff] [blame] | 1845 | if (!PyArg_ParseTuple(args, "hiiil", |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1846 | &event.id, |
| 1847 | &event.x, &event.y, &event.z, |
| 1848 | (int *) &event.bstate)) |
| 1849 | return NULL; |
| 1850 | |
| 1851 | return PyCursesCheckERR(ungetmouse(&event), "ungetmouse"); |
| 1852 | } |
| 1853 | #endif |
| 1854 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1855 | static PyObject * |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1856 | PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1857 | { |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1858 | char fn[100]; |
| 1859 | int fd; |
| 1860 | FILE *fp; |
| 1861 | PyObject *data; |
Matthias Klose | 7e1b8fa | 2008-11-26 17:22:04 +0000 | [diff] [blame] | 1862 | size_t datalen; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1863 | WINDOW *win; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1864 | |
| 1865 | PyCursesInitialised |
| 1866 | |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1867 | strcpy(fn, "/tmp/py.curses.getwin.XXXXXX"); |
| 1868 | fd = mkstemp(fn); |
| 1869 | if (fd < 0) |
| 1870 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
| 1871 | fp = fdopen(fd, "wb+"); |
| 1872 | if (fp == NULL) { |
| 1873 | close(fd); |
Guido van Rossum | 150b7d7 | 2007-08-30 23:34:01 +0000 | [diff] [blame] | 1874 | remove(fn); |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1875 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
| 1876 | } |
| 1877 | data = PyObject_CallMethod(stream, "read", ""); |
| 1878 | if (data == NULL) { |
| 1879 | fclose(fp); |
Guido van Rossum | 150b7d7 | 2007-08-30 23:34:01 +0000 | [diff] [blame] | 1880 | remove(fn); |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1881 | return NULL; |
| 1882 | } |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 1883 | if (!PyBytes_Check(data)) { |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1884 | PyErr_Format(PyExc_TypeError, |
| 1885 | "f.read() returned %.100s instead of bytes", |
| 1886 | data->ob_type->tp_name); |
| 1887 | Py_DECREF(data); |
| 1888 | fclose(fp); |
Guido van Rossum | 150b7d7 | 2007-08-30 23:34:01 +0000 | [diff] [blame] | 1889 | remove(fn); |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1890 | return NULL; |
| 1891 | } |
Matthias Klose | 7e1b8fa | 2008-11-26 17:22:04 +0000 | [diff] [blame] | 1892 | datalen = PyBytes_GET_SIZE(data); |
| 1893 | if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) { |
| 1894 | Py_DECREF(data); |
| 1895 | fclose(fp); |
| 1896 | remove(fn); |
| 1897 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
| 1898 | } |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 1899 | Py_DECREF(data); |
| 1900 | fseek(fp, 0, 0); |
| 1901 | win = getwin(fp); |
| 1902 | fclose(fp); |
Guido van Rossum | 150b7d7 | 2007-08-30 23:34:01 +0000 | [diff] [blame] | 1903 | remove(fn); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1904 | if (win == NULL) { |
| 1905 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1906 | return NULL; |
| 1907 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1908 | return PyCursesWindow_New(win); |
| 1909 | } |
| 1910 | |
| 1911 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1912 | PyCurses_HalfDelay(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1913 | { |
| 1914 | unsigned char tenths; |
| 1915 | |
| 1916 | PyCursesInitialised |
| 1917 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1918 | if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1919 | |
| 1920 | return PyCursesCheckERR(halfdelay(tenths), "halfdelay"); |
| 1921 | } |
| 1922 | |
Andrew M. Kuchling | bf68026 | 2000-07-25 12:37:41 +0000 | [diff] [blame] | 1923 | #ifndef STRICT_SYSV_CURSES |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1924 | /* No has_key! */ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1925 | static PyObject * PyCurses_has_key(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1926 | { |
| 1927 | int ch; |
| 1928 | |
| 1929 | PyCursesInitialised |
| 1930 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1931 | if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1932 | |
| 1933 | if (has_key(ch) == FALSE) { |
| 1934 | Py_INCREF(Py_False); |
| 1935 | return Py_False; |
| 1936 | } |
| 1937 | Py_INCREF(Py_True); |
| 1938 | return Py_True; |
| 1939 | } |
Andrew M. Kuchling | bf68026 | 2000-07-25 12:37:41 +0000 | [diff] [blame] | 1940 | #endif /* STRICT_SYSV_CURSES */ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1941 | |
| 1942 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1943 | PyCurses_Init_Color(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1944 | { |
| 1945 | short color, r, g, b; |
| 1946 | |
| 1947 | PyCursesInitialised |
| 1948 | PyCursesInitialisedColor |
| 1949 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1950 | switch(PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1951 | case 4: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1952 | 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] | 1953 | break; |
| 1954 | default: |
| 1955 | PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments"); |
| 1956 | return NULL; |
| 1957 | } |
| 1958 | |
| 1959 | return PyCursesCheckERR(init_color(color, r, g, b), "init_color"); |
| 1960 | } |
| 1961 | |
| 1962 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1963 | PyCurses_Init_Pair(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1964 | { |
| 1965 | short pair, f, b; |
| 1966 | |
| 1967 | PyCursesInitialised |
| 1968 | PyCursesInitialisedColor |
| 1969 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1970 | if (PyTuple_Size(args) != 3) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1971 | PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments"); |
| 1972 | return NULL; |
| 1973 | } |
| 1974 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1975 | 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] | 1976 | |
| 1977 | return PyCursesCheckERR(init_pair(pair, f, b), "init_pair"); |
| 1978 | } |
| 1979 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 1980 | static PyObject *ModDict; |
| 1981 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1982 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 1983 | PyCurses_InitScr(PyObject *self) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1984 | { |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1985 | WINDOW *win; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1986 | |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1987 | if (initialised == TRUE) { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1988 | wrefresh(stdscr); |
| 1989 | return (PyObject *)PyCursesWindow_New(stdscr); |
| 1990 | } |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1991 | |
| 1992 | win = initscr(); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1993 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1994 | if (win == NULL) { |
| 1995 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1996 | return NULL; |
| 1997 | } |
| 1998 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 1999 | initialised = initialised_setupterm = TRUE; |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 2000 | |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2001 | /* This was moved from initcurses() because it core dumped on SGI, |
| 2002 | where they're not defined until you've called initscr() */ |
| 2003 | #define SetDictInt(string,ch) \ |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 2004 | do { \ |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 2005 | PyObject *o = PyLong_FromLong((long) (ch)); \ |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 2006 | if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \ |
| 2007 | Py_DECREF(o); \ |
| 2008 | } \ |
| 2009 | } while (0) |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2010 | |
| 2011 | /* Here are some graphic symbols you can use */ |
| 2012 | SetDictInt("ACS_ULCORNER", (ACS_ULCORNER)); |
| 2013 | SetDictInt("ACS_LLCORNER", (ACS_LLCORNER)); |
| 2014 | SetDictInt("ACS_URCORNER", (ACS_URCORNER)); |
| 2015 | SetDictInt("ACS_LRCORNER", (ACS_LRCORNER)); |
| 2016 | SetDictInt("ACS_LTEE", (ACS_LTEE)); |
| 2017 | SetDictInt("ACS_RTEE", (ACS_RTEE)); |
| 2018 | SetDictInt("ACS_BTEE", (ACS_BTEE)); |
| 2019 | SetDictInt("ACS_TTEE", (ACS_TTEE)); |
| 2020 | SetDictInt("ACS_HLINE", (ACS_HLINE)); |
| 2021 | SetDictInt("ACS_VLINE", (ACS_VLINE)); |
| 2022 | SetDictInt("ACS_PLUS", (ACS_PLUS)); |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 2023 | #if !defined(__hpux) || defined(HAVE_NCURSES_H) |
| 2024 | /* On HP/UX 11, these are of type cchar_t, which is not an |
| 2025 | integral type. If this is a problem on more platforms, a |
| 2026 | configure test should be added to determine whether ACS_S1 |
| 2027 | is of integral type. */ |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2028 | SetDictInt("ACS_S1", (ACS_S1)); |
| 2029 | SetDictInt("ACS_S9", (ACS_S9)); |
| 2030 | SetDictInt("ACS_DIAMOND", (ACS_DIAMOND)); |
| 2031 | SetDictInt("ACS_CKBOARD", (ACS_CKBOARD)); |
| 2032 | SetDictInt("ACS_DEGREE", (ACS_DEGREE)); |
| 2033 | SetDictInt("ACS_PLMINUS", (ACS_PLMINUS)); |
| 2034 | SetDictInt("ACS_BULLET", (ACS_BULLET)); |
| 2035 | SetDictInt("ACS_LARROW", (ACS_LARROW)); |
| 2036 | SetDictInt("ACS_RARROW", (ACS_RARROW)); |
| 2037 | SetDictInt("ACS_DARROW", (ACS_DARROW)); |
| 2038 | SetDictInt("ACS_UARROW", (ACS_UARROW)); |
| 2039 | SetDictInt("ACS_BOARD", (ACS_BOARD)); |
| 2040 | SetDictInt("ACS_LANTERN", (ACS_LANTERN)); |
| 2041 | SetDictInt("ACS_BLOCK", (ACS_BLOCK)); |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 2042 | #endif |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2043 | SetDictInt("ACS_BSSB", (ACS_ULCORNER)); |
| 2044 | SetDictInt("ACS_SSBB", (ACS_LLCORNER)); |
| 2045 | SetDictInt("ACS_BBSS", (ACS_URCORNER)); |
| 2046 | SetDictInt("ACS_SBBS", (ACS_LRCORNER)); |
| 2047 | SetDictInt("ACS_SBSS", (ACS_RTEE)); |
| 2048 | SetDictInt("ACS_SSSB", (ACS_LTEE)); |
| 2049 | SetDictInt("ACS_SSBS", (ACS_BTEE)); |
| 2050 | SetDictInt("ACS_BSSS", (ACS_TTEE)); |
| 2051 | SetDictInt("ACS_BSBS", (ACS_HLINE)); |
| 2052 | SetDictInt("ACS_SBSB", (ACS_VLINE)); |
| 2053 | SetDictInt("ACS_SSSS", (ACS_PLUS)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2054 | |
| 2055 | /* The following are never available with strict SYSV curses */ |
| 2056 | #ifdef ACS_S3 |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2057 | SetDictInt("ACS_S3", (ACS_S3)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2058 | #endif |
| 2059 | #ifdef ACS_S7 |
| 2060 | SetDictInt("ACS_S7", (ACS_S7)); |
| 2061 | #endif |
| 2062 | #ifdef ACS_LEQUAL |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2063 | SetDictInt("ACS_LEQUAL", (ACS_LEQUAL)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2064 | #endif |
| 2065 | #ifdef ACS_GEQUAL |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2066 | SetDictInt("ACS_GEQUAL", (ACS_GEQUAL)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2067 | #endif |
| 2068 | #ifdef ACS_PI |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2069 | SetDictInt("ACS_PI", (ACS_PI)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2070 | #endif |
| 2071 | #ifdef ACS_NEQUAL |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2072 | SetDictInt("ACS_NEQUAL", (ACS_NEQUAL)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2073 | #endif |
| 2074 | #ifdef ACS_STERLING |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2075 | SetDictInt("ACS_STERLING", (ACS_STERLING)); |
| 2076 | #endif |
| 2077 | |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 2078 | SetDictInt("LINES", LINES); |
| 2079 | SetDictInt("COLS", COLS); |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 2080 | |
| 2081 | return (PyObject *)PyCursesWindow_New(win); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2084 | static PyObject * |
| 2085 | PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds) |
| 2086 | { |
| 2087 | int fd = -1; |
| 2088 | int err; |
| 2089 | char* termstr = NULL; |
| 2090 | |
Martin v. Löwis | 15e6274 | 2006-02-27 16:46:16 +0000 | [diff] [blame] | 2091 | static char *kwlist[] = {"term", "fd", NULL}; |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2092 | |
| 2093 | if (!PyArg_ParseTupleAndKeywords( |
Jeremy Hylton | af68c87 | 2005-12-10 18:50:16 +0000 | [diff] [blame] | 2094 | args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) { |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2095 | return NULL; |
| 2096 | } |
| 2097 | |
| 2098 | if (fd == -1) { |
| 2099 | PyObject* sys_stdout; |
| 2100 | |
| 2101 | sys_stdout = PySys_GetObject("stdout"); |
| 2102 | |
Christian Heimes | 2be0373 | 2007-11-15 02:26:46 +0000 | [diff] [blame] | 2103 | if (sys_stdout == NULL || sys_stdout == Py_None) { |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2104 | PyErr_SetString( |
| 2105 | PyCursesError, |
| 2106 | "lost sys.stdout"); |
| 2107 | return NULL; |
| 2108 | } |
| 2109 | |
| 2110 | fd = PyObject_AsFileDescriptor(sys_stdout); |
| 2111 | |
| 2112 | if (fd == -1) { |
| 2113 | return NULL; |
| 2114 | } |
| 2115 | } |
| 2116 | |
| 2117 | if (setupterm(termstr,fd,&err) == ERR) { |
| 2118 | char* s = "setupterm: unknown error"; |
| 2119 | |
| 2120 | if (err == 0) { |
| 2121 | s = "setupterm: could not find terminal"; |
| 2122 | } else if (err == -1) { |
| 2123 | s = "setupterm: could not find terminfo database"; |
| 2124 | } |
| 2125 | |
| 2126 | PyErr_SetString(PyCursesError,s); |
| 2127 | return NULL; |
| 2128 | } |
| 2129 | |
| 2130 | initialised_setupterm = TRUE; |
| 2131 | |
| 2132 | Py_INCREF(Py_None); |
| 2133 | return Py_None; |
| 2134 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2135 | |
| 2136 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2137 | PyCurses_IntrFlush(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2138 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2139 | int ch; |
| 2140 | |
| 2141 | PyCursesInitialised |
| 2142 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2143 | switch(PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2144 | case 1: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2145 | 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] | 2146 | break; |
| 2147 | default: |
| 2148 | PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2149 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | return PyCursesCheckERR(intrflush(NULL,ch), "intrflush"); |
| 2153 | } |
| 2154 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2155 | #ifdef HAVE_CURSES_IS_TERM_RESIZED |
| 2156 | static PyObject * |
| 2157 | PyCurses_Is_Term_Resized(PyObject *self, PyObject *args) |
| 2158 | { |
| 2159 | int lines; |
| 2160 | int columns; |
| 2161 | int result; |
| 2162 | |
| 2163 | PyCursesInitialised |
| 2164 | |
| 2165 | if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns)) |
| 2166 | return NULL; |
| 2167 | result = is_term_resized(lines, columns); |
| 2168 | if (result == TRUE) { |
| 2169 | Py_INCREF(Py_True); |
| 2170 | return Py_True; |
| 2171 | } else { |
| 2172 | Py_INCREF(Py_False); |
| 2173 | return Py_False; |
| 2174 | } |
| 2175 | } |
| 2176 | #endif /* HAVE_CURSES_IS_TERM_RESIZED */ |
| 2177 | |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 2178 | #if !defined(__NetBSD__) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2179 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2180 | PyCurses_KeyName(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2181 | { |
| 2182 | const char *knp; |
| 2183 | int ch; |
| 2184 | |
| 2185 | PyCursesInitialised |
| 2186 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2187 | if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2188 | |
Andrew M. Kuchling | 7e23f00 | 2002-11-06 14:15:36 +0000 | [diff] [blame] | 2189 | if (ch < 0) { |
| 2190 | PyErr_SetString(PyExc_ValueError, "invalid key number"); |
| 2191 | return NULL; |
| 2192 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2193 | knp = keyname(ch); |
| 2194 | |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 2195 | return PyBytes_FromString((knp == NULL) ? "" : (char *)knp); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2196 | } |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 2197 | #endif |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2198 | |
| 2199 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2200 | PyCurses_KillChar(PyObject *self) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2201 | { |
| 2202 | char ch; |
| 2203 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2204 | ch = killchar(); |
| 2205 | |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 2206 | return PyBytes_FromStringAndSize(&ch, 1); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2210 | PyCurses_Meta(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2211 | { |
| 2212 | int ch; |
| 2213 | |
| 2214 | PyCursesInitialised |
| 2215 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2216 | switch(PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2217 | case 1: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2218 | 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] | 2219 | break; |
| 2220 | default: |
| 2221 | PyErr_SetString(PyExc_TypeError, "meta requires 1 argument"); |
| 2222 | return NULL; |
| 2223 | } |
| 2224 | |
| 2225 | return PyCursesCheckERR(meta(stdscr, ch), "meta"); |
| 2226 | } |
| 2227 | |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2228 | #ifdef NCURSES_MOUSE_VERSION |
| 2229 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2230 | PyCurses_MouseInterval(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2231 | { |
| 2232 | int interval; |
| 2233 | PyCursesInitialised |
| 2234 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2235 | if (!PyArg_ParseTuple(args,"i;interval",&interval)) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2236 | return NULL; |
| 2237 | return PyCursesCheckERR(mouseinterval(interval), "mouseinterval"); |
| 2238 | } |
| 2239 | |
| 2240 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2241 | PyCurses_MouseMask(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2242 | { |
Andrew M. Kuchling | 1a10400 | 2000-07-06 18:14:03 +0000 | [diff] [blame] | 2243 | int newmask; |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2244 | mmask_t oldmask, availmask; |
| 2245 | |
| 2246 | PyCursesInitialised |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2247 | if (!PyArg_ParseTuple(args,"i;mousemask",&newmask)) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2248 | return NULL; |
| 2249 | availmask = mousemask(newmask, &oldmask); |
| 2250 | return Py_BuildValue("(ll)", (long)availmask, (long)oldmask); |
| 2251 | } |
| 2252 | #endif |
| 2253 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2254 | static PyObject * |
Andrew M. Kuchling | 2824d7f | 2000-12-15 00:44:02 +0000 | [diff] [blame] | 2255 | PyCurses_Napms(PyObject *self, PyObject *args) |
| 2256 | { |
| 2257 | int ms; |
| 2258 | |
| 2259 | PyCursesInitialised |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2260 | if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL; |
Andrew M. Kuchling | 2824d7f | 2000-12-15 00:44:02 +0000 | [diff] [blame] | 2261 | |
| 2262 | return Py_BuildValue("i", napms(ms)); |
| 2263 | } |
| 2264 | |
| 2265 | |
| 2266 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2267 | PyCurses_NewPad(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2268 | { |
| 2269 | WINDOW *win; |
| 2270 | int nlines, ncols; |
| 2271 | |
| 2272 | PyCursesInitialised |
| 2273 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2274 | if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2275 | |
| 2276 | win = newpad(nlines, ncols); |
| 2277 | |
| 2278 | if (win == NULL) { |
| 2279 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 2280 | return NULL; |
| 2281 | } |
| 2282 | |
| 2283 | return (PyObject *)PyCursesWindow_New(win); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2287 | PyCurses_NewWindow(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2288 | { |
| 2289 | WINDOW *win; |
Andrew M. Kuchling | 5a76c44 | 2001-07-14 20:38:30 +0000 | [diff] [blame] | 2290 | int nlines, ncols, begin_y=0, begin_x=0; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2291 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2292 | PyCursesInitialised |
| 2293 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2294 | switch (PyTuple_Size(args)) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2295 | case 2: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2296 | if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2297 | return NULL; |
| 2298 | break; |
| 2299 | case 4: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2300 | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2301 | &nlines,&ncols,&begin_y,&begin_x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2302 | return NULL; |
| 2303 | break; |
| 2304 | default: |
| 2305 | PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments"); |
| 2306 | return NULL; |
| 2307 | } |
| 2308 | |
Andrew M. Kuchling | 5a76c44 | 2001-07-14 20:38:30 +0000 | [diff] [blame] | 2309 | win = newwin(nlines,ncols,begin_y,begin_x); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2310 | if (win == NULL) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2311 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 2312 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2313 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2314 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2315 | return (PyObject *)PyCursesWindow_New(win); |
| 2316 | } |
| 2317 | |
| 2318 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2319 | PyCurses_Pair_Content(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2320 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2321 | short pair,f,b; |
| 2322 | |
| 2323 | PyCursesInitialised |
| 2324 | PyCursesInitialisedColor |
| 2325 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2326 | switch(PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2327 | case 1: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2328 | if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2329 | break; |
| 2330 | default: |
| 2331 | PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2332 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2333 | } |
| 2334 | |
Andrew M. Kuchling | b5e7ff4 | 2005-06-15 18:46:50 +0000 | [diff] [blame] | 2335 | if (pair_content(pair, &f, &b)==ERR) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2336 | PyErr_SetString(PyCursesError, |
| 2337 | "Argument 1 was out of range. (1..COLOR_PAIRS-1)"); |
| 2338 | return NULL; |
| 2339 | } |
| 2340 | |
| 2341 | return Py_BuildValue("(ii)", f, b); |
| 2342 | } |
| 2343 | |
| 2344 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2345 | PyCurses_pair_number(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2346 | { |
| 2347 | int n; |
| 2348 | |
| 2349 | PyCursesInitialised |
| 2350 | PyCursesInitialisedColor |
| 2351 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2352 | switch(PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2353 | case 1: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2354 | if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2355 | break; |
| 2356 | default: |
| 2357 | PyErr_SetString(PyExc_TypeError, |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2358 | "pair_number requires 1 argument"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2359 | return NULL; |
| 2360 | } |
| 2361 | |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 2362 | return PyLong_FromLong((long) ((n & A_COLOR) >> 8)); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2366 | PyCurses_Putp(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2367 | { |
| 2368 | char *str; |
| 2369 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2370 | if (!PyArg_ParseTuple(args,"s;str", &str)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2371 | return PyCursesCheckERR(putp(str), "putp"); |
| 2372 | } |
| 2373 | |
| 2374 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2375 | PyCurses_QiFlush(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2376 | { |
| 2377 | int flag = 0; |
| 2378 | |
| 2379 | PyCursesInitialised |
| 2380 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2381 | switch(PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2382 | case 0: |
| 2383 | qiflush(); |
| 2384 | Py_INCREF(Py_None); |
| 2385 | return Py_None; |
| 2386 | case 1: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2387 | 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] | 2388 | if (flag) qiflush(); |
| 2389 | else noqiflush(); |
| 2390 | Py_INCREF(Py_None); |
| 2391 | return Py_None; |
| 2392 | default: |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2393 | PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2394 | return NULL; |
| 2395 | } |
| 2396 | } |
| 2397 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2398 | /* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES |
| 2399 | * and _curses.COLS */ |
Benjamin Peterson | fea6a94 | 2008-07-02 16:11:42 +0000 | [diff] [blame] | 2400 | #if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2401 | static int |
| 2402 | update_lines_cols(void) |
| 2403 | { |
| 2404 | PyObject *o; |
Christian Heimes | 072c0f1 | 2008-01-03 23:01:04 +0000 | [diff] [blame] | 2405 | PyObject *m = PyImport_ImportModuleNoBlock("curses"); |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2406 | |
| 2407 | if (!m) |
| 2408 | return 0; |
| 2409 | |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 2410 | o = PyLong_FromLong(LINES); |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2411 | if (!o) { |
| 2412 | Py_DECREF(m); |
| 2413 | return 0; |
| 2414 | } |
| 2415 | if (PyObject_SetAttrString(m, "LINES", o)) { |
| 2416 | Py_DECREF(m); |
| 2417 | Py_DECREF(o); |
| 2418 | return 0; |
| 2419 | } |
| 2420 | if (PyDict_SetItemString(ModDict, "LINES", o)) { |
| 2421 | Py_DECREF(m); |
| 2422 | Py_DECREF(o); |
| 2423 | return 0; |
| 2424 | } |
| 2425 | Py_DECREF(o); |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 2426 | o = PyLong_FromLong(COLS); |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2427 | if (!o) { |
| 2428 | Py_DECREF(m); |
| 2429 | return 0; |
| 2430 | } |
| 2431 | if (PyObject_SetAttrString(m, "COLS", o)) { |
| 2432 | Py_DECREF(m); |
| 2433 | Py_DECREF(o); |
| 2434 | return 0; |
| 2435 | } |
| 2436 | if (PyDict_SetItemString(ModDict, "COLS", o)) { |
| 2437 | Py_DECREF(m); |
| 2438 | Py_DECREF(o); |
| 2439 | return 0; |
| 2440 | } |
| 2441 | Py_DECREF(o); |
| 2442 | Py_DECREF(m); |
| 2443 | return 1; |
| 2444 | } |
Benjamin Peterson | fea6a94 | 2008-07-02 16:11:42 +0000 | [diff] [blame] | 2445 | #endif |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2446 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2447 | #ifdef HAVE_CURSES_RESIZETERM |
| 2448 | static PyObject * |
| 2449 | PyCurses_ResizeTerm(PyObject *self, PyObject *args) |
| 2450 | { |
| 2451 | int lines; |
| 2452 | int columns; |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2453 | PyObject *result; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2454 | |
| 2455 | PyCursesInitialised |
| 2456 | |
| 2457 | if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns)) |
| 2458 | return NULL; |
| 2459 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2460 | result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm"); |
| 2461 | if (!result) |
| 2462 | return NULL; |
| 2463 | if (!update_lines_cols()) |
| 2464 | return NULL; |
| 2465 | return result; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | #endif |
| 2469 | |
| 2470 | #ifdef HAVE_CURSES_RESIZE_TERM |
| 2471 | static PyObject * |
| 2472 | PyCurses_Resize_Term(PyObject *self, PyObject *args) |
| 2473 | { |
| 2474 | int lines; |
| 2475 | int columns; |
| 2476 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2477 | PyObject *result; |
| 2478 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2479 | PyCursesInitialised |
| 2480 | |
| 2481 | if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns)) |
| 2482 | return NULL; |
| 2483 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 2484 | result = PyCursesCheckERR(resize_term(lines, columns), "resize_term"); |
| 2485 | if (!result) |
| 2486 | return NULL; |
| 2487 | if (!update_lines_cols()) |
| 2488 | return NULL; |
| 2489 | return result; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2490 | } |
| 2491 | #endif /* HAVE_CURSES_RESIZE_TERM */ |
| 2492 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2493 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2494 | PyCurses_setsyx(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2495 | { |
| 2496 | int y,x; |
| 2497 | |
| 2498 | PyCursesInitialised |
| 2499 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2500 | if (PyTuple_Size(args)!=2) { |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2501 | PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2502 | return NULL; |
| 2503 | } |
| 2504 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2505 | if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2506 | |
| 2507 | setsyx(y,x); |
| 2508 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2509 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2510 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | static PyObject * |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2514 | PyCurses_Start_Color(PyObject *self) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2515 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2516 | int code; |
| 2517 | PyObject *c, *cp; |
| 2518 | |
| 2519 | PyCursesInitialised |
| 2520 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2521 | code = start_color(); |
| 2522 | if (code != ERR) { |
| 2523 | initialisedcolors = TRUE; |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 2524 | c = PyLong_FromLong((long) COLORS); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2525 | PyDict_SetItemString(ModDict, "COLORS", c); |
| 2526 | Py_DECREF(c); |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 2527 | cp = PyLong_FromLong((long) COLOR_PAIRS); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2528 | PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp); |
| 2529 | Py_DECREF(cp); |
| 2530 | Py_INCREF(Py_None); |
| 2531 | return Py_None; |
| 2532 | } else { |
| 2533 | PyErr_SetString(PyCursesError, "start_color() returned ERR"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2534 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2535 | } |
| 2536 | } |
| 2537 | |
| 2538 | static PyObject * |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2539 | PyCurses_tigetflag(PyObject *self, PyObject *args) |
| 2540 | { |
| 2541 | char *capname; |
| 2542 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2543 | PyCursesSetupTermCalled; |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2544 | |
| 2545 | if (!PyArg_ParseTuple(args, "z", &capname)) |
| 2546 | return NULL; |
| 2547 | |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 2548 | return PyLong_FromLong( (long) tigetflag( capname ) ); |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | static PyObject * |
| 2552 | PyCurses_tigetnum(PyObject *self, PyObject *args) |
| 2553 | { |
| 2554 | char *capname; |
| 2555 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2556 | PyCursesSetupTermCalled; |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2557 | |
| 2558 | if (!PyArg_ParseTuple(args, "z", &capname)) |
| 2559 | return NULL; |
| 2560 | |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 2561 | return PyLong_FromLong( (long) tigetnum( capname ) ); |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | static PyObject * |
| 2565 | PyCurses_tigetstr(PyObject *self, PyObject *args) |
| 2566 | { |
| 2567 | char *capname; |
| 2568 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2569 | PyCursesSetupTermCalled; |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2570 | |
| 2571 | if (!PyArg_ParseTuple(args, "z", &capname)) |
| 2572 | return NULL; |
| 2573 | |
| 2574 | capname = tigetstr( capname ); |
| 2575 | if (capname == 0 || capname == (char*) -1) { |
| 2576 | Py_INCREF(Py_None); |
| 2577 | return Py_None; |
| 2578 | } |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 2579 | return PyBytes_FromString( capname ); |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | static PyObject * |
Andrew M. Kuchling | f16e0ed | 2000-11-07 03:35:24 +0000 | [diff] [blame] | 2583 | PyCurses_tparm(PyObject *self, PyObject *args) |
| 2584 | { |
| 2585 | char* fmt; |
| 2586 | char* result = NULL; |
Michael W. Hudson | 2100798 | 2002-11-21 14:17:51 +0000 | [diff] [blame] | 2587 | 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] | 2588 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 2589 | PyCursesSetupTermCalled; |
Andrew M. Kuchling | f16e0ed | 2000-11-07 03:35:24 +0000 | [diff] [blame] | 2590 | |
| 2591 | if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm", |
| 2592 | &fmt, &i1, &i2, &i3, &i4, |
| 2593 | &i5, &i6, &i7, &i8, &i9)) { |
| 2594 | return NULL; |
| 2595 | } |
Michael W. Hudson | 2100798 | 2002-11-21 14:17:51 +0000 | [diff] [blame] | 2596 | |
Michael W. Hudson | 8f51460 | 2002-01-16 15:18:09 +0000 | [diff] [blame] | 2597 | result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 2598 | if (!result) { |
| 2599 | PyErr_SetString(PyCursesError, "tparm() returned NULL"); |
| 2600 | return NULL; |
| 2601 | } |
Michael W. Hudson | 2100798 | 2002-11-21 14:17:51 +0000 | [diff] [blame] | 2602 | |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 2603 | return PyBytes_FromString(result); |
Andrew M. Kuchling | f16e0ed | 2000-11-07 03:35:24 +0000 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2607 | PyCurses_TypeAhead(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 2608 | { |
Andrew M. Kuchling | 1a10400 | 2000-07-06 18:14:03 +0000 | [diff] [blame] | 2609 | int fd; |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 2610 | |
| 2611 | PyCursesInitialised |
| 2612 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2613 | if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL; |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 2614 | |
Michael W. Hudson | 7d6cc5b | 2004-08-04 14:33:28 +0000 | [diff] [blame] | 2615 | return PyCursesCheckERR(typeahead( fd ), "typeahead"); |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2619 | PyCurses_UnCtrl(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2620 | { |
| 2621 | PyObject *temp; |
| 2622 | chtype ch; |
| 2623 | |
| 2624 | PyCursesInitialised |
| 2625 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2626 | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2627 | |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 2628 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2629 | PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int"); |
| 2630 | return NULL; |
| 2631 | } |
| 2632 | |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 2633 | return PyBytes_FromString(unctrl(ch)); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2637 | PyCurses_UngetCh(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2638 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2639 | PyObject *temp; |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 2640 | chtype ch; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2641 | |
| 2642 | PyCursesInitialised |
| 2643 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2644 | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2645 | |
Guido van Rossum | 6c95da3 | 2007-07-24 00:16:38 +0000 | [diff] [blame] | 2646 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2647 | 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] | 2648 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2651 | return PyCursesCheckERR(ungetch(ch), "ungetch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2655 | PyCurses_Use_Env(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2656 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2657 | int flag; |
| 2658 | |
| 2659 | PyCursesInitialised |
| 2660 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2661 | switch(PyTuple_Size(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2662 | case 1: |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2663 | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2664 | return NULL; |
| 2665 | break; |
| 2666 | default: |
| 2667 | PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2668 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2669 | } |
| 2670 | use_env(flag); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2671 | Py_INCREF(Py_None); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2672 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2673 | } |
| 2674 | |
Andrew M. Kuchling | 69f31eb | 2003-08-13 23:11:04 +0000 | [diff] [blame] | 2675 | #ifndef STRICT_SYSV_CURSES |
| 2676 | static PyObject * |
| 2677 | PyCurses_Use_Default_Colors(PyObject *self) |
| 2678 | { |
| 2679 | int code; |
| 2680 | |
| 2681 | PyCursesInitialised |
| 2682 | PyCursesInitialisedColor |
| 2683 | |
| 2684 | code = use_default_colors(); |
| 2685 | if (code != ERR) { |
| 2686 | Py_INCREF(Py_None); |
| 2687 | return Py_None; |
| 2688 | } else { |
| 2689 | PyErr_SetString(PyCursesError, "use_default_colors() returned ERR"); |
| 2690 | return NULL; |
| 2691 | } |
| 2692 | } |
| 2693 | #endif /* STRICT_SYSV_CURSES */ |
| 2694 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2695 | /* List of functions defined in the module */ |
| 2696 | |
| 2697 | static PyMethodDef PyCurses_methods[] = { |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2698 | {"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS}, |
| 2699 | {"beep", (PyCFunction)PyCurses_beep, METH_NOARGS}, |
| 2700 | {"can_change_color", (PyCFunction)PyCurses_can_change_color, METH_NOARGS}, |
| 2701 | {"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS}, |
| 2702 | {"color_content", (PyCFunction)PyCurses_Color_Content, METH_VARARGS}, |
| 2703 | {"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS}, |
| 2704 | {"curs_set", (PyCFunction)PyCurses_Curs_Set, METH_VARARGS}, |
| 2705 | {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS}, |
| 2706 | {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS}, |
| 2707 | {"delay_output", (PyCFunction)PyCurses_Delay_Output, METH_VARARGS}, |
| 2708 | {"doupdate", (PyCFunction)PyCurses_doupdate, METH_NOARGS}, |
| 2709 | {"echo", (PyCFunction)PyCurses_echo, METH_VARARGS}, |
| 2710 | {"endwin", (PyCFunction)PyCurses_endwin, METH_NOARGS}, |
| 2711 | {"erasechar", (PyCFunction)PyCurses_EraseChar, METH_NOARGS}, |
| 2712 | {"filter", (PyCFunction)PyCurses_filter, METH_NOARGS}, |
| 2713 | {"flash", (PyCFunction)PyCurses_flash, METH_NOARGS}, |
| 2714 | {"flushinp", (PyCFunction)PyCurses_flushinp, METH_NOARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2715 | #ifdef NCURSES_MOUSE_VERSION |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2716 | {"getmouse", (PyCFunction)PyCurses_GetMouse, METH_NOARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2717 | {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS}, |
| 2718 | #endif |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2719 | {"getsyx", (PyCFunction)PyCurses_getsyx, METH_NOARGS}, |
| 2720 | {"getwin", (PyCFunction)PyCurses_GetWin, METH_O}, |
| 2721 | {"has_colors", (PyCFunction)PyCurses_has_colors, METH_NOARGS}, |
| 2722 | {"has_ic", (PyCFunction)PyCurses_has_ic, METH_NOARGS}, |
| 2723 | {"has_il", (PyCFunction)PyCurses_has_il, METH_NOARGS}, |
Andrew M. Kuchling | bf68026 | 2000-07-25 12:37:41 +0000 | [diff] [blame] | 2724 | #ifndef STRICT_SYSV_CURSES |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2725 | {"has_key", (PyCFunction)PyCurses_has_key, METH_VARARGS}, |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2726 | #endif |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2727 | {"halfdelay", (PyCFunction)PyCurses_HalfDelay, METH_VARARGS}, |
| 2728 | {"init_color", (PyCFunction)PyCurses_Init_Color, METH_VARARGS}, |
| 2729 | {"init_pair", (PyCFunction)PyCurses_Init_Pair, METH_VARARGS}, |
| 2730 | {"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS}, |
| 2731 | {"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS}, |
| 2732 | {"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS}, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2733 | #ifdef HAVE_CURSES_IS_TERM_RESIZED |
| 2734 | {"is_term_resized", (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS}, |
| 2735 | #endif |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 2736 | #if !defined(__NetBSD__) |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2737 | {"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS}, |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 2738 | #endif |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2739 | {"killchar", (PyCFunction)PyCurses_KillChar, METH_NOARGS}, |
| 2740 | {"longname", (PyCFunction)PyCurses_longname, METH_NOARGS}, |
| 2741 | {"meta", (PyCFunction)PyCurses_Meta, METH_VARARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2742 | #ifdef NCURSES_MOUSE_VERSION |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2743 | {"mouseinterval", (PyCFunction)PyCurses_MouseInterval, METH_VARARGS}, |
| 2744 | {"mousemask", (PyCFunction)PyCurses_MouseMask, METH_VARARGS}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2745 | #endif |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2746 | {"napms", (PyCFunction)PyCurses_Napms, METH_VARARGS}, |
| 2747 | {"newpad", (PyCFunction)PyCurses_NewPad, METH_VARARGS}, |
| 2748 | {"newwin", (PyCFunction)PyCurses_NewWindow, METH_VARARGS}, |
| 2749 | {"nl", (PyCFunction)PyCurses_nl, METH_VARARGS}, |
| 2750 | {"nocbreak", (PyCFunction)PyCurses_nocbreak, METH_NOARGS}, |
| 2751 | {"noecho", (PyCFunction)PyCurses_noecho, METH_NOARGS}, |
| 2752 | {"nonl", (PyCFunction)PyCurses_nonl, METH_NOARGS}, |
| 2753 | {"noqiflush", (PyCFunction)PyCurses_noqiflush, METH_NOARGS}, |
| 2754 | {"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS}, |
| 2755 | {"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS}, |
| 2756 | {"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS}, |
| 2757 | {"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS}, |
| 2758 | {"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS}, |
| 2759 | {"raw", (PyCFunction)PyCurses_raw, METH_VARARGS}, |
| 2760 | {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS}, |
| 2761 | {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS}, |
| 2762 | {"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS}, |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 2763 | #ifdef HAVE_CURSES_RESIZETERM |
| 2764 | {"resizeterm", (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS}, |
| 2765 | #endif |
| 2766 | #ifdef HAVE_CURSES_RESIZE_TERM |
| 2767 | {"resize_term", (PyCFunction)PyCurses_Resize_Term, METH_VARARGS}, |
| 2768 | #endif |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2769 | {"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS}, |
| 2770 | {"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS}, |
Andrew M. Kuchling | 16e65a0 | 2001-10-20 16:05:52 +0000 | [diff] [blame] | 2771 | {"setupterm", (PyCFunction)PyCurses_setupterm, |
| 2772 | METH_VARARGS|METH_KEYWORDS}, |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2773 | {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS}, |
| 2774 | {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS}, |
| 2775 | {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS}, |
Andrew M. Kuchling | 70e89c1 | 2000-07-26 02:57:20 +0000 | [diff] [blame] | 2776 | {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS}, |
| 2777 | {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS}, |
| 2778 | {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS}, |
Andrew M. Kuchling | f16e0ed | 2000-11-07 03:35:24 +0000 | [diff] [blame] | 2779 | {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS}, |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 2780 | {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS}, |
| 2781 | {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS}, |
| 2782 | {"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS}, |
| 2783 | {"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS}, |
Andrew M. Kuchling | 69f31eb | 2003-08-13 23:11:04 +0000 | [diff] [blame] | 2784 | #ifndef STRICT_SYSV_CURSES |
| 2785 | {"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS}, |
| 2786 | #endif |
Andrew M. Kuchling | 16e65a0 | 2001-10-20 16:05:52 +0000 | [diff] [blame] | 2787 | {NULL, NULL} /* sentinel */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2788 | }; |
| 2789 | |
| 2790 | /* Initialization function for the module */ |
| 2791 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 2792 | |
| 2793 | static struct PyModuleDef _cursesmodule = { |
| 2794 | PyModuleDef_HEAD_INIT, |
| 2795 | "_curses", |
| 2796 | NULL, |
| 2797 | -1, |
| 2798 | PyCurses_methods, |
| 2799 | NULL, |
| 2800 | NULL, |
| 2801 | NULL, |
| 2802 | NULL |
| 2803 | }; |
| 2804 | |
Mark Hammond | fe51c6d | 2002-08-02 02:27:13 +0000 | [diff] [blame] | 2805 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 2806 | PyInit__curses(void) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2807 | { |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 2808 | PyObject *m, *d, *v, *c_api_object; |
| 2809 | static void *PyCurses_API[PyCurses_API_pointers]; |
| 2810 | |
Guido van Rossum | 6915c4d | 2001-01-19 00:28:08 +0000 | [diff] [blame] | 2811 | /* Initialize object type */ |
Amaury Forgeot d'Arc | 1f900f1 | 2008-07-02 22:38:47 +0000 | [diff] [blame] | 2812 | if (PyType_Ready(&PyCursesWindow_Type) < 0) |
| 2813 | return NULL; |
Guido van Rossum | 6915c4d | 2001-01-19 00:28:08 +0000 | [diff] [blame] | 2814 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 2815 | /* Initialize the C API pointer array */ |
| 2816 | PyCurses_API[0] = (void *)&PyCursesWindow_Type; |
| 2817 | PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled; |
| 2818 | PyCurses_API[2] = (void *)func_PyCursesInitialised; |
| 2819 | PyCurses_API[3] = (void *)func_PyCursesInitialisedColor; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2820 | |
| 2821 | /* Create the module and add the functions */ |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 2822 | m = PyModule_Create(&_cursesmodule); |
Neal Norwitz | 1ac754f | 2006-01-19 06:09:39 +0000 | [diff] [blame] | 2823 | if (m == NULL) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 2824 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2825 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2826 | /* Add some symbolic constants to the module */ |
| 2827 | d = PyModule_GetDict(m); |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 2828 | if (d == NULL) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 2829 | return NULL; |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 2830 | ModDict = d; /* For PyCurses_InitScr to use later */ |
| 2831 | |
Benjamin Peterson | b173f78 | 2009-05-05 22:31:58 +0000 | [diff] [blame] | 2832 | /* Add a capsule for the C API */ |
| 2833 | c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, NULL); |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 2834 | PyDict_SetItemString(d, "_C_API", c_api_object); |
Martin v. Löwis | 00ff10c | 2001-11-11 14:24:05 +0000 | [diff] [blame] | 2835 | Py_DECREF(c_api_object); |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 2836 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2837 | /* For exception curses.error */ |
Fred Drake | 589c35b | 2000-07-06 19:38:49 +0000 | [diff] [blame] | 2838 | PyCursesError = PyErr_NewException("_curses.error", NULL, NULL); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2839 | PyDict_SetItemString(d, "error", PyCursesError); |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 2840 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2841 | /* Make the version available */ |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 2842 | v = PyBytes_FromString(PyCursesVersion); |
Guido van Rossum | 8fbf82b | 1995-02-17 13:54:04 +0000 | [diff] [blame] | 2843 | PyDict_SetItemString(d, "version", v); |
| 2844 | PyDict_SetItemString(d, "__version__", v); |
| 2845 | Py_DECREF(v); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2846 | |
Andrew M. Kuchling | caefb37 | 2000-12-26 15:57:01 +0000 | [diff] [blame] | 2847 | SetDictInt("ERR", ERR); |
| 2848 | SetDictInt("OK", OK); |
| 2849 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2850 | /* Here are some attributes you can add to chars to print */ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2851 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2852 | SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES); |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2853 | SetDictInt("A_NORMAL", A_NORMAL); |
| 2854 | SetDictInt("A_STANDOUT", A_STANDOUT); |
| 2855 | SetDictInt("A_UNDERLINE", A_UNDERLINE); |
| 2856 | SetDictInt("A_REVERSE", A_REVERSE); |
| 2857 | SetDictInt("A_BLINK", A_BLINK); |
| 2858 | SetDictInt("A_DIM", A_DIM); |
| 2859 | SetDictInt("A_BOLD", A_BOLD); |
| 2860 | SetDictInt("A_ALTCHARSET", A_ALTCHARSET); |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 2861 | #if !defined(__NetBSD__) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2862 | SetDictInt("A_INVIS", A_INVIS); |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 2863 | #endif |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2864 | SetDictInt("A_PROTECT", A_PROTECT); |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2865 | SetDictInt("A_CHARTEXT", A_CHARTEXT); |
| 2866 | SetDictInt("A_COLOR", A_COLOR); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2867 | |
| 2868 | /* The following are never available with strict SYSV curses */ |
| 2869 | #ifdef A_HORIZONTAL |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2870 | SetDictInt("A_HORIZONTAL", A_HORIZONTAL); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2871 | #endif |
| 2872 | #ifdef A_LEFT |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2873 | SetDictInt("A_LEFT", A_LEFT); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2874 | #endif |
| 2875 | #ifdef A_LOW |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2876 | SetDictInt("A_LOW", A_LOW); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2877 | #endif |
| 2878 | #ifdef A_RIGHT |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2879 | SetDictInt("A_RIGHT", A_RIGHT); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2880 | #endif |
| 2881 | #ifdef A_TOP |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2882 | SetDictInt("A_TOP", A_TOP); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 2883 | #endif |
| 2884 | #ifdef A_VERTICAL |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2885 | SetDictInt("A_VERTICAL", A_VERTICAL); |
| 2886 | #endif |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 2887 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2888 | SetDictInt("COLOR_BLACK", COLOR_BLACK); |
| 2889 | SetDictInt("COLOR_RED", COLOR_RED); |
| 2890 | SetDictInt("COLOR_GREEN", COLOR_GREEN); |
| 2891 | SetDictInt("COLOR_YELLOW", COLOR_YELLOW); |
| 2892 | SetDictInt("COLOR_BLUE", COLOR_BLUE); |
| 2893 | SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA); |
| 2894 | SetDictInt("COLOR_CYAN", COLOR_CYAN); |
| 2895 | SetDictInt("COLOR_WHITE", COLOR_WHITE); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2896 | |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2897 | #ifdef NCURSES_MOUSE_VERSION |
| 2898 | /* Mouse-related constants */ |
| 2899 | SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED); |
| 2900 | SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED); |
| 2901 | SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED); |
| 2902 | SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED); |
| 2903 | SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED); |
| 2904 | |
| 2905 | SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED); |
| 2906 | SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED); |
| 2907 | SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED); |
| 2908 | SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED); |
| 2909 | SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED); |
| 2910 | |
| 2911 | SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED); |
| 2912 | SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED); |
| 2913 | SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED); |
| 2914 | SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED); |
| 2915 | SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED); |
| 2916 | |
| 2917 | SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED); |
| 2918 | SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED); |
| 2919 | SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED); |
| 2920 | SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED); |
| 2921 | SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED); |
| 2922 | |
| 2923 | SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT); |
| 2924 | SetDictInt("BUTTON_CTRL", BUTTON_CTRL); |
| 2925 | SetDictInt("BUTTON_ALT", BUTTON_ALT); |
| 2926 | |
| 2927 | SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS); |
| 2928 | SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION); |
| 2929 | #endif |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2930 | /* Now set everything up for KEY_ variables */ |
| 2931 | { |
| 2932 | int key; |
| 2933 | char *key_n; |
| 2934 | char *key_n2; |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 2935 | #if !defined(__NetBSD__) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2936 | for (key=KEY_MIN;key < KEY_MAX; key++) { |
| 2937 | key_n = (char *)keyname(key); |
Guido van Rossum | f5c6d47 | 1995-02-07 15:38:32 +0000 | [diff] [blame] | 2938 | if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2939 | continue; |
| 2940 | if (strncmp(key_n,"KEY_F(",6)==0) { |
| 2941 | char *p1, *p2; |
| 2942 | key_n2 = malloc(strlen(key_n)+1); |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 2943 | if (!key_n2) { |
| 2944 | PyErr_NoMemory(); |
| 2945 | break; |
| 2946 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2947 | p1 = key_n; |
| 2948 | p2 = key_n2; |
| 2949 | while (*p1) { |
| 2950 | if (*p1 != '(' && *p1 != ')') { |
| 2951 | *p2 = *p1; |
| 2952 | p2++; |
| 2953 | } |
| 2954 | p1++; |
| 2955 | } |
| 2956 | *p2 = (char)0; |
| 2957 | } else |
| 2958 | key_n2 = key_n; |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 2959 | SetDictInt(key_n2,key); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2960 | if (key_n2 != key_n) |
| 2961 | free(key_n2); |
| 2962 | } |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 2963 | #endif |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2964 | SetDictInt("KEY_MIN", KEY_MIN); |
| 2965 | SetDictInt("KEY_MAX", KEY_MAX); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2966 | } |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 2967 | return m; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2968 | } |