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