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