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