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 | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 103 | #define CURSES_MODULE |
| 104 | #include "py_curses.h" |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 105 | |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 106 | #ifdef __osf__ |
| 107 | #define _XOPEN_SOURCE_EXTENDED /* Define macro for OSF/1 */ |
Andrew M. Kuchling | bf68026 | 2000-07-25 12:37:41 +0000 | [diff] [blame] | 108 | #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 109 | #endif |
| 110 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 111 | /* These prototypes are in <term.h>, but including this header |
| 112 | #defines many common symbols (such as "lines") which breaks the |
| 113 | curses module in other ways. So the code will just specify |
| 114 | explicit prototypes here. */ |
| 115 | extern int setupterm(char *,int,int *); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 116 | #ifdef sgi |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 117 | extern char *tigetstr(char *); |
Andrew M. Kuchling | 399b8af | 2001-01-28 18:10:23 +0000 | [diff] [blame] | 118 | extern char *tparm(char *instring, ...); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 119 | #endif |
| 120 | |
| 121 | #if defined(sgi) || defined(__sun__) |
Andrew M. Kuchling | bf68026 | 2000-07-25 12:37:41 +0000 | [diff] [blame] | 122 | #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 123 | typedef chtype attr_t; /* No attr_t type is available */ |
Guido van Rossum | 1266a01 | 1996-02-25 04:50:31 +0000 | [diff] [blame] | 124 | #endif |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 125 | |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 126 | #if defined(_AIX) |
| 127 | #define STRICT_SYSV_CURSES |
| 128 | #endif |
| 129 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 130 | /* Definition of exception curses.error */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 131 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 132 | static PyObject *PyCursesError; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 133 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 134 | /* Tells whether setupterm() has been called to initialise terminfo. */ |
| 135 | static int initialised_setupterm = FALSE; |
| 136 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 137 | /* Tells whether initscr() has been called to initialise curses. */ |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 138 | static int initialised = FALSE; |
| 139 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 140 | /* Tells whether start_color() has been called to initialise color usage. */ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 141 | static int initialisedcolors = FALSE; |
| 142 | |
| 143 | /* Utility Macros */ |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 144 | #define PyCursesSetupTermCalled \ |
| 145 | if (initialised_setupterm != TRUE) { \ |
| 146 | PyErr_SetString(PyCursesError, \ |
| 147 | "must call (at least) setupterm() first"); \ |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 148 | return 0; } |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 149 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 150 | #define PyCursesInitialised \ |
| 151 | if (initialised != TRUE) { \ |
| 152 | PyErr_SetString(PyCursesError, \ |
| 153 | "must call initscr() first"); \ |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 154 | return 0; } |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 155 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 156 | #define PyCursesInitialisedColor \ |
| 157 | if (initialisedcolors != TRUE) { \ |
| 158 | PyErr_SetString(PyCursesError, \ |
| 159 | "must call start_color() first"); \ |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 160 | return 0; } |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 161 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 162 | /* Utility Functions */ |
Guido van Rossum | fbea2f3 | 1994-08-31 22:05:27 +0000 | [diff] [blame] | 163 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 164 | /* |
| 165 | * Check the return code from a curses function and return None |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 166 | * or raise an exception as appropriate. These are exported using the |
| 167 | * CObject API. |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 168 | */ |
| 169 | |
| 170 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 171 | PyCursesCheckERR(int code, char *fname) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 172 | { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 173 | if (code != ERR) { |
| 174 | Py_INCREF(Py_None); |
| 175 | return Py_None; |
| 176 | } else { |
| 177 | if (fname == NULL) { |
| 178 | PyErr_SetString(PyCursesError, catchall_ERR); |
| 179 | } else { |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 180 | PyErr_Format(PyCursesError, "%s() returned ERR", fname); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 181 | } |
| 182 | return NULL; |
| 183 | } |
| 184 | } |
| 185 | |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 186 | static int |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 187 | PyCurses_ConvertToChtype(PyObject *obj, chtype *ch) |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 188 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 189 | if (PyInt_Check(obj)) { |
| 190 | *ch = (chtype) PyInt_AsLong(obj); |
| 191 | } else if(PyString_Check(obj) & |
| 192 | (PyString_Size(obj) == 1)) { |
| 193 | *ch = (chtype) *PyString_AsString(obj); |
| 194 | } else { |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 195 | return 0; |
| 196 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 197 | return 1; |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 200 | /* Function versions of the 3 functions for tested whether curses has been |
| 201 | initialised or not. */ |
| 202 | |
| 203 | static int func_PyCursesSetupTermCalled(void) |
| 204 | { |
| 205 | PyCursesSetupTermCalled; |
| 206 | return 1; |
| 207 | } |
| 208 | |
| 209 | static int func_PyCursesInitialised(void) |
| 210 | { |
| 211 | PyCursesInitialised; |
| 212 | return 1; |
| 213 | } |
| 214 | |
| 215 | static int func_PyCursesInitialisedColor(void) |
| 216 | { |
| 217 | PyCursesInitialisedColor; |
| 218 | return 1; |
| 219 | } |
| 220 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 221 | /***************************************************************************** |
| 222 | The Window Object |
| 223 | ******************************************************************************/ |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 224 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 225 | /* Definition of the window type */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 226 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 227 | PyTypeObject PyCursesWindow_Type; |
| 228 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 229 | /* Function prototype macros for Window object |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 230 | |
| 231 | X - function name |
| 232 | TYPE - parameter Type |
| 233 | ERGSTR - format string for construction of the return value |
| 234 | PARSESTR - format string for argument parsing |
| 235 | */ |
| 236 | |
| 237 | #define Window_NoArgNoReturnFunction(X) \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 238 | static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \ |
| 239 | { if (!PyArg_NoArgs(args)) return NULL; \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 240 | return PyCursesCheckERR(X(self->win), # X); } |
| 241 | |
| 242 | #define Window_NoArgTrueFalseFunction(X) \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 243 | static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 244 | { \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 245 | if (!PyArg_NoArgs(args)) return NULL; \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 246 | if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \ |
| 247 | else { Py_INCREF(Py_True); return Py_True; } } |
| 248 | |
| 249 | #define Window_NoArgNoReturnVoidFunction(X) \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 250 | static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 251 | { \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 252 | if (!PyArg_NoArgs(args)) return NULL; \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 253 | X(self->win); Py_INCREF(Py_None); return Py_None; } |
| 254 | |
| 255 | #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 256 | static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 257 | { \ |
| 258 | TYPE arg1, arg2; \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 259 | if (!PyArg_NoArgs(args)) return NULL; \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 260 | X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); } |
| 261 | |
| 262 | #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 263 | static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 264 | { \ |
| 265 | TYPE arg1; \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 266 | if (!PyArg_Parse(args, PARSESTR, &arg1)) return NULL; \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 267 | X(self->win,arg1); Py_INCREF(Py_None); return Py_None; } |
| 268 | |
| 269 | #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 270 | static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 271 | { \ |
| 272 | TYPE arg1; \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 273 | if (!PyArg_Parse(args,PARSESTR, &arg1)) return NULL; \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 274 | return PyCursesCheckERR(X(self->win, arg1), # X); } |
| 275 | |
| 276 | #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 277 | static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 278 | { \ |
| 279 | TYPE arg1, arg2; \ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 280 | if (!PyArg_Parse(args,PARSESTR, &arg1, &arg2)) return NULL; \ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 281 | return PyCursesCheckERR(X(self->win, arg1, arg2), # X); } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 282 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 283 | /* ------------- WINDOW routines --------------- */ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 284 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 285 | Window_NoArgNoReturnFunction(untouchwin) |
| 286 | Window_NoArgNoReturnFunction(touchwin) |
| 287 | Window_NoArgNoReturnFunction(redrawwin) |
| 288 | Window_NoArgNoReturnFunction(winsertln) |
| 289 | Window_NoArgNoReturnFunction(werase) |
| 290 | Window_NoArgNoReturnFunction(wdeleteln) |
| 291 | |
| 292 | Window_NoArgTrueFalseFunction(is_wintouched) |
| 293 | |
| 294 | Window_NoArgNoReturnVoidFunction(wsyncup) |
| 295 | Window_NoArgNoReturnVoidFunction(wsyncdown) |
| 296 | Window_NoArgNoReturnVoidFunction(wstandend) |
| 297 | Window_NoArgNoReturnVoidFunction(wstandout) |
| 298 | Window_NoArgNoReturnVoidFunction(wcursyncup) |
| 299 | Window_NoArgNoReturnVoidFunction(wclrtoeol) |
| 300 | Window_NoArgNoReturnVoidFunction(wclrtobot) |
| 301 | Window_NoArgNoReturnVoidFunction(wclear) |
| 302 | |
| 303 | Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)") |
| 304 | Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 305 | Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay") |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 306 | |
| 307 | Window_NoArg2TupleReturnFunction(getyx, int, "(ii)") |
| 308 | Window_NoArg2TupleReturnFunction(getbegyx, int, "(ii)") |
| 309 | Window_NoArg2TupleReturnFunction(getmaxyx, int, "(ii)") |
| 310 | Window_NoArg2TupleReturnFunction(getparyx, int, "(ii)") |
| 311 | |
| 312 | Window_OneArgNoReturnFunction(wattron, attr_t, "l;attr") |
| 313 | Window_OneArgNoReturnFunction(wattroff, attr_t, "l;attr") |
| 314 | Window_OneArgNoReturnFunction(wattrset, attr_t, "l;attr") |
| 315 | Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)") |
| 316 | Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 317 | #if defined(__NetBSD__) |
| 318 | Window_OneArgNoReturnVoidFunction(keypad, int, "i;True(1) or False(0)") |
| 319 | #else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 320 | Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 321 | #endif |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 322 | Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 323 | #if defined(__NetBSD__) |
| 324 | Window_OneArgNoReturnVoidFunction(nodelay, int, "i;True(1) or False(0)") |
| 325 | #else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 326 | Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 327 | #endif |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 328 | Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)") |
| 329 | Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)") |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 330 | Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines") |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 331 | Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)") |
| 332 | |
| 333 | Window_TwoArgNoReturnFunction(mvwin, int, "(ii);y,x") |
| 334 | Window_TwoArgNoReturnFunction(mvderwin, int, "(ii);y,x") |
| 335 | Window_TwoArgNoReturnFunction(wmove, int, "(ii);y,x") |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 336 | #ifndef STRICT_SYSV_CURSES |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 337 | Window_TwoArgNoReturnFunction(wresize, int, "(ii);lines,columns") |
| 338 | #endif |
| 339 | |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 340 | /* Allocation and deallocation of Window Objects */ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 341 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 342 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 343 | PyCursesWindow_New(WINDOW *win) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 344 | { |
| 345 | PyCursesWindowObject *wo; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 346 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 347 | wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type); |
| 348 | if (wo == NULL) return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 349 | wo->win = win; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 350 | return (PyObject *)wo; |
| 351 | } |
| 352 | |
| 353 | static void |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 354 | PyCursesWindow_Dealloc(PyCursesWindowObject *wo) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 355 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 356 | if (wo->win != stdscr) delwin(wo->win); |
| 357 | PyMem_DEL(wo); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 360 | /* Addch, Addstr, Addnstr */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 361 | |
| 362 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 363 | PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 364 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 365 | int rtn, x, y, use_xy = FALSE; |
| 366 | PyObject *temp; |
| 367 | chtype ch = 0; |
| 368 | attr_t attr = A_NORMAL; |
| 369 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 370 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 371 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 372 | if (!PyArg_Parse(args, "O;ch or int", &temp)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 373 | return NULL; |
| 374 | break; |
| 375 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 376 | if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 377 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 378 | break; |
| 379 | case 3: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 380 | 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] | 381 | return NULL; |
| 382 | use_xy = TRUE; |
| 383 | break; |
| 384 | case 4: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 385 | if (!PyArg_Parse(args,"(iiOl);y,x,ch or int, attr", |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 386 | &y, &x, &temp, &attr)) |
| 387 | return NULL; |
| 388 | use_xy = TRUE; |
| 389 | break; |
| 390 | default: |
| 391 | PyErr_SetString(PyExc_TypeError, "addch requires 1 or 4 arguments"); |
| 392 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 393 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 394 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 395 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 396 | PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int"); |
| 397 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 398 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 399 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 400 | if (use_xy == TRUE) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 401 | rtn = mvwaddch(self->win,y,x, ch | attr); |
| 402 | else { |
| 403 | rtn = waddch(self->win, ch | attr); |
| 404 | } |
| 405 | return PyCursesCheckERR(rtn, "addch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 409 | PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 410 | { |
| 411 | int rtn; |
| 412 | int x, y; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 413 | char *str; |
| 414 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 415 | int use_xy = FALSE, use_attr = FALSE; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 416 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 417 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 418 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 419 | if (!PyArg_Parse(args,"s;str", &str)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 420 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 421 | break; |
| 422 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 423 | if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 424 | return NULL; |
| 425 | use_attr = TRUE; |
| 426 | break; |
| 427 | case 3: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 428 | if (!PyArg_Parse(args,"(iis);int,int,str", &y, &x, &str)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 429 | return NULL; |
| 430 | use_xy = TRUE; |
| 431 | break; |
| 432 | case 4: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 433 | 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] | 434 | return NULL; |
| 435 | use_xy = use_attr = TRUE; |
| 436 | break; |
| 437 | default: |
| 438 | PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments"); |
| 439 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 440 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 441 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 442 | if (use_attr == TRUE) { |
| 443 | attr_old = getattrs(self->win); |
| 444 | wattrset(self->win,attr); |
| 445 | } |
| 446 | if (use_xy == TRUE) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 447 | rtn = mvwaddstr(self->win,y,x,str); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 448 | else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 449 | rtn = waddstr(self->win,str); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 450 | if (use_attr == TRUE) |
| 451 | wattrset(self->win,attr_old); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 452 | return PyCursesCheckERR(rtn, "addstr"); |
| 453 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 454 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 455 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 456 | PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 457 | { |
| 458 | int rtn, x, y, n; |
| 459 | char *str; |
| 460 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 461 | int use_xy = FALSE, use_attr = FALSE; |
| 462 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 463 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 464 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 465 | if (!PyArg_Parse(args,"(si);str,n", &str, &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 466 | return NULL; |
| 467 | break; |
| 468 | case 3: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 469 | if (!PyArg_Parse(args,"(sil);str,n,attr", &str, &n, &attr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 470 | return NULL; |
| 471 | use_attr = TRUE; |
| 472 | break; |
| 473 | case 4: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 474 | 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] | 475 | return NULL; |
| 476 | use_xy = TRUE; |
| 477 | break; |
| 478 | case 5: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 479 | 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] | 480 | return NULL; |
| 481 | use_xy = use_attr = TRUE; |
| 482 | break; |
| 483 | default: |
| 484 | PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments"); |
| 485 | return NULL; |
| 486 | } |
| 487 | |
| 488 | if (use_attr == TRUE) { |
| 489 | attr_old = getattrs(self->win); |
| 490 | wattrset(self->win,attr); |
| 491 | } |
| 492 | if (use_xy == TRUE) |
| 493 | rtn = mvwaddnstr(self->win,y,x,str,n); |
| 494 | else |
| 495 | rtn = waddnstr(self->win,str,n); |
| 496 | if (use_attr == TRUE) |
| 497 | wattrset(self->win,attr_old); |
| 498 | return PyCursesCheckERR(rtn, "addnstr"); |
| 499 | } |
| 500 | |
| 501 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 502 | PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 503 | { |
| 504 | PyObject *temp; |
| 505 | chtype bkgd; |
| 506 | attr_t attr = A_NORMAL; |
| 507 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 508 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 509 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 510 | if (!PyArg_Parse(args, "O;ch or int", &temp)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 511 | return NULL; |
| 512 | break; |
| 513 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 514 | if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 515 | return NULL; |
| 516 | break; |
| 517 | default: |
| 518 | PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments"); |
| 519 | return NULL; |
| 520 | } |
| 521 | |
| 522 | if (!PyCurses_ConvertToChtype(temp, &bkgd)) { |
| 523 | PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int"); |
| 524 | return NULL; |
| 525 | } |
| 526 | |
| 527 | return PyCursesCheckERR(wbkgd(self->win, bkgd | A_NORMAL), "bkgd"); |
| 528 | } |
| 529 | |
| 530 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 531 | PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 532 | { |
| 533 | PyObject *temp; |
| 534 | chtype bkgd; |
| 535 | attr_t attr = A_NORMAL; |
| 536 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 537 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 538 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 539 | if (!PyArg_Parse(args, "O;ch or int", &temp)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 540 | return NULL; |
| 541 | break; |
| 542 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 543 | if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 544 | return NULL; |
| 545 | break; |
| 546 | default: |
| 547 | PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments"); |
| 548 | return NULL; |
| 549 | } |
| 550 | |
| 551 | if (!PyCurses_ConvertToChtype(temp, &bkgd)) { |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 552 | 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] | 553 | return NULL; |
| 554 | } |
| 555 | |
| 556 | wbkgdset(self->win, bkgd | attr); |
| 557 | return PyCursesCheckERR(0, "bkgdset"); |
| 558 | } |
| 559 | |
| 560 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 561 | PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 562 | { |
| 563 | chtype ls, rs, ts, bs, tl, tr, bl, br; |
| 564 | ls = rs = ts = bs = tl = tr = bl = br = 0; |
| 565 | if (!PyArg_Parse(args,"|llllllll;ls,rs,ts,bs,tl,tr,bl,br", |
| 566 | &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br)) |
| 567 | return NULL; |
| 568 | wborder(self->win, ls, rs, ts, bs, tl, tr, bl, br); |
| 569 | Py_INCREF(Py_None); |
| 570 | return Py_None; |
| 571 | } |
| 572 | |
| 573 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 574 | PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 575 | { |
| 576 | chtype ch1=0,ch2=0; |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 577 | if (!PyArg_NoArgs(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 578 | PyErr_Clear(); |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 579 | if (!PyArg_Parse(args,"(ll);vertint,horint", &ch1, &ch2)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 580 | return NULL; |
| 581 | } |
| 582 | box(self->win,ch1,ch2); |
| 583 | Py_INCREF(Py_None); |
| 584 | return Py_None; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 588 | PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 589 | { |
| 590 | int rtn; |
| 591 | int x, y; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 592 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 593 | switch (ARG_COUNT(args)) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 594 | case 0: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 595 | rtn = wdelch(self->win); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 596 | break; |
| 597 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 598 | if (!PyArg_Parse(args,"(ii);y,x", &y, &x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 599 | return NULL; |
| 600 | rtn = mvwdelch(self->win,y,x); |
| 601 | break; |
| 602 | default: |
| 603 | PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments"); |
| 604 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 605 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 606 | return PyCursesCheckERR(rtn, "[mv]wdelch"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 610 | PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 611 | { |
| 612 | WINDOW *win; |
| 613 | int nlines, ncols, begin_y, begin_x; |
| 614 | |
| 615 | nlines = 0; |
| 616 | ncols = 0; |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 617 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 618 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 619 | 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] | 620 | return NULL; |
| 621 | break; |
| 622 | case 4: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 623 | if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x", |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 624 | &nlines,&ncols,&begin_y,&begin_x)) |
| 625 | return NULL; |
| 626 | break; |
| 627 | default: |
| 628 | PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments"); |
| 629 | return NULL; |
| 630 | } |
| 631 | |
| 632 | win = derwin(self->win,nlines,ncols,begin_y,begin_x); |
| 633 | |
| 634 | if (win == NULL) { |
| 635 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 636 | return NULL; |
| 637 | } |
| 638 | |
| 639 | return (PyObject *)PyCursesWindow_New(win); |
| 640 | } |
| 641 | |
| 642 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 643 | PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 644 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 645 | PyObject *temp; |
| 646 | chtype ch; |
| 647 | attr_t attr = A_NORMAL; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 648 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 649 | switch (ARG_COUNT(args)) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 650 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 651 | if (!PyArg_Parse(args,"O;ch or int", &temp)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 652 | return NULL; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 653 | break; |
| 654 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 655 | if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 656 | return NULL; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 657 | break; |
| 658 | default: |
| 659 | PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 660 | |
| 661 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 662 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 663 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 664 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 665 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 666 | 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] | 667 | return NULL; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 668 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 669 | |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 670 | #if !defined(__NetBSD__) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 671 | if (self->win->_flags & _ISPAD) |
| 672 | return PyCursesCheckERR(pechochar(self->win, ch | attr), |
| 673 | "echochar"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 674 | else |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 675 | #endif |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 676 | return PyCursesCheckERR(wechochar(self->win, ch | attr), |
| 677 | "echochar"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 680 | #ifdef NCURSES_MOUSE_VERSION |
| 681 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 682 | PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 683 | { |
| 684 | int x, y; |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 685 | if (!PyArg_Parse(args,"(ii);y,x", &y, &x)) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 686 | return NULL; |
| 687 | |
| 688 | return PyInt_FromLong( wenclose(self->win,y,x) ); |
| 689 | } |
| 690 | #endif |
| 691 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 692 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 693 | PyCursesWindow_GetBkgd(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 694 | { |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 695 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 696 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 697 | return PyInt_FromLong((long) getbkgd(self->win)); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 701 | PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 702 | { |
| 703 | int x, y; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 704 | chtype rtn; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 705 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 706 | switch (ARG_COUNT(args)) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 707 | case 0: |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 708 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 709 | rtn = wgetch(self->win); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 710 | Py_END_ALLOW_THREADS |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 711 | break; |
| 712 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 713 | if (!PyArg_Parse(args,"(ii);y,x",&y,&x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 714 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 715 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 716 | rtn = mvwgetch(self->win,y,x); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 717 | Py_END_ALLOW_THREADS |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 718 | break; |
| 719 | default: |
| 720 | PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments"); |
| 721 | return NULL; |
| 722 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 723 | return PyInt_FromLong(rtn); |
| 724 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 725 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 726 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 727 | PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 728 | { |
| 729 | int x, y; |
| 730 | chtype rtn; |
| 731 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 732 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 733 | case 0: |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 734 | Py_BEGIN_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 735 | rtn = wgetch(self->win); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 736 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 737 | break; |
| 738 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 739 | if (!PyArg_Parse(args,"(ii);y,x",&y,&x)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 740 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 741 | Py_BEGIN_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 742 | rtn = mvwgetch(self->win,y,x); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 743 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 744 | break; |
| 745 | default: |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 746 | PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 747 | return NULL; |
| 748 | } |
| 749 | if (rtn<=255) |
| 750 | return Py_BuildValue("c", rtn); |
| 751 | else |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 752 | #if defined(__NetBSD__) |
| 753 | return PyString_FromString(unctrl(rtn)); |
| 754 | #else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 755 | return PyString_FromString((char *)keyname(rtn)); |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 756 | #endif |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 760 | PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 761 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 762 | int x, y, n; |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 763 | char rtn[1024]; /* This should be big enough.. I hope */ |
| 764 | int rtn2; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 765 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 766 | switch (ARG_COUNT(args)) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 767 | case 0: |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 768 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 769 | rtn2 = wgetstr(self->win,rtn); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 770 | Py_END_ALLOW_THREADS |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 771 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 772 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 773 | if (!PyArg_Parse(args,"i;n", &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 774 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 775 | Py_BEGIN_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 776 | rtn2 = wgetnstr(self->win,rtn,n); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 777 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 778 | break; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 779 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 780 | if (!PyArg_Parse(args,"(ii);y,x",&y,&x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 781 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 782 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 783 | rtn2 = mvwgetstr(self->win,y,x,rtn); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 784 | Py_END_ALLOW_THREADS |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 785 | break; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 786 | case 3: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 787 | if (!PyArg_Parse(args,"(iii);y,x,n", &y, &x, &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 788 | return NULL; |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 789 | #ifdef STRICT_SYSV_CURSES |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 790 | /* Untested */ |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 791 | Py_BEGIN_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 792 | rtn2 = wmove(self->win,y,x)==ERR ? ERR : |
| 793 | wgetnstr(self->win, rtn, n); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 794 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 795 | #else |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 796 | Py_BEGIN_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 797 | rtn2 = mvwgetnstr(self->win, y, x, rtn, n); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 798 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 799 | #endif |
| 800 | break; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 801 | default: |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 802 | PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 2 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 803 | return NULL; |
| 804 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 805 | if (rtn2 == ERR) |
| 806 | rtn[0] = 0; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 807 | return PyString_FromString(rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 811 | PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 812 | { |
| 813 | PyObject *temp; |
| 814 | chtype ch; |
| 815 | int n, x, y, code = OK; |
| 816 | attr_t attr = A_NORMAL; |
| 817 | |
| 818 | switch (ARG_COUNT(args)) { |
| 819 | case 2: |
| 820 | if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n)) |
| 821 | return NULL; |
| 822 | break; |
| 823 | case 3: |
| 824 | if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr)) |
| 825 | return NULL; |
| 826 | break; |
| 827 | case 4: |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 828 | 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] | 829 | return NULL; |
| 830 | code = wmove(self->win, y, x); |
| 831 | break; |
| 832 | case 5: |
| 833 | if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr", |
| 834 | &y, &x, &temp, &n, &attr)) |
| 835 | return NULL; |
| 836 | code = wmove(self->win, y, x); |
| 837 | default: |
| 838 | PyErr_SetString(PyExc_TypeError, "hline requires 2 or 5 arguments"); |
| 839 | return NULL; |
| 840 | } |
| 841 | |
| 842 | if (code != ERR) { |
| 843 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 844 | PyErr_SetString(PyExc_TypeError, |
| 845 | "argument 1 or 3 must be a ch or an int"); |
| 846 | return NULL; |
| 847 | } |
| 848 | return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline"); |
| 849 | } else |
| 850 | return PyCursesCheckERR(code, "wmove"); |
| 851 | } |
| 852 | |
| 853 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 854 | PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 855 | { |
| 856 | int rtn, x, y, use_xy = FALSE; |
| 857 | PyObject *temp; |
| 858 | chtype ch = 0; |
| 859 | attr_t attr = A_NORMAL; |
| 860 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 861 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 862 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 863 | if (!PyArg_Parse(args, "O;ch or int", &temp)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 864 | return NULL; |
| 865 | break; |
| 866 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 867 | if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 868 | return NULL; |
| 869 | break; |
| 870 | case 3: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 871 | 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] | 872 | return NULL; |
| 873 | use_xy = TRUE; |
| 874 | break; |
| 875 | case 4: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 876 | 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] | 877 | return NULL; |
| 878 | use_xy = TRUE; |
| 879 | break; |
| 880 | default: |
| 881 | PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments"); |
| 882 | return NULL; |
| 883 | } |
| 884 | |
| 885 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 886 | PyErr_SetString(PyExc_TypeError, |
| 887 | "argument 1 or 3 must be a ch or an int"); |
| 888 | return NULL; |
| 889 | } |
| 890 | |
| 891 | if (use_xy == TRUE) |
| 892 | rtn = mvwinsch(self->win,y,x, ch | attr); |
| 893 | else { |
| 894 | rtn = winsch(self->win, ch | attr); |
| 895 | } |
| 896 | return PyCursesCheckERR(rtn, "insch"); |
| 897 | } |
| 898 | |
| 899 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 900 | PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 901 | { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 902 | int x, y, rtn; |
| 903 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 904 | switch (ARG_COUNT(args)) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 905 | case 0: |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 906 | rtn = winch(self->win); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 907 | break; |
| 908 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 909 | if (!PyArg_Parse(args,"(ii);y,x",&y,&x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 910 | return NULL; |
| 911 | rtn = mvwinch(self->win,y,x); |
| 912 | break; |
| 913 | default: |
| 914 | PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments"); |
| 915 | return NULL; |
| 916 | } |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 917 | return PyInt_FromLong((long) rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 921 | PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 922 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 923 | int x, y, n; |
| 924 | char rtn[1024]; /* This should be big enough.. I hope */ |
| 925 | int rtn2; |
| 926 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 927 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 928 | case 0: |
| 929 | rtn2 = winstr(self->win,rtn); |
| 930 | break; |
| 931 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 932 | if (!PyArg_Parse(args,"i;n", &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 933 | return NULL; |
| 934 | rtn2 = winnstr(self->win,rtn,n); |
| 935 | break; |
| 936 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 937 | if (!PyArg_Parse(args,"(ii);y,x",&y,&x)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 938 | return NULL; |
| 939 | rtn2 = mvwinstr(self->win,y,x,rtn); |
| 940 | break; |
| 941 | case 3: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 942 | if (!PyArg_Parse(args, "(iii);y,x,n", &y, &x, &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 943 | return NULL; |
| 944 | rtn2 = mvwinnstr(self->win, y, x, rtn, n); |
| 945 | break; |
| 946 | default: |
| 947 | PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 948 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 949 | } |
| 950 | if (rtn2 == ERR) |
| 951 | rtn[0] = 0; |
| 952 | return PyString_FromString(rtn); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 956 | PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 957 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 958 | int rtn; |
| 959 | int x, y; |
| 960 | char *str; |
| 961 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 962 | int use_xy = FALSE, use_attr = FALSE; |
| 963 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 964 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 965 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 966 | if (!PyArg_Parse(args,"s;str", &str)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 967 | return NULL; |
| 968 | break; |
| 969 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 970 | if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 971 | return NULL; |
| 972 | use_attr = TRUE; |
| 973 | break; |
| 974 | case 3: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 975 | if (!PyArg_Parse(args,"(iis);y,x,str", &y, &x, &str)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 976 | return NULL; |
| 977 | use_xy = TRUE; |
| 978 | break; |
| 979 | case 4: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 980 | 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] | 981 | return NULL; |
| 982 | use_xy = use_attr = TRUE; |
| 983 | break; |
| 984 | default: |
| 985 | PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 986 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | if (use_attr == TRUE) { |
| 990 | attr_old = getattrs(self->win); |
| 991 | wattrset(self->win,attr); |
| 992 | } |
| 993 | if (use_xy == TRUE) |
| 994 | rtn = mvwinsstr(self->win,y,x,str); |
| 995 | else |
| 996 | rtn = winsstr(self->win,str); |
| 997 | if (use_attr == TRUE) |
| 998 | wattrset(self->win,attr_old); |
| 999 | return PyCursesCheckERR(rtn, "insstr"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1003 | PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1004 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1005 | int rtn, x, y, n; |
| 1006 | char *str; |
| 1007 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
| 1008 | int use_xy = FALSE, use_attr = FALSE; |
| 1009 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1010 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1011 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1012 | if (!PyArg_Parse(args,"(si);str,n", &str, &n)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1013 | return NULL; |
| 1014 | break; |
| 1015 | case 3: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1016 | if (!PyArg_Parse(args,"(sil);str,n,attr", &str, &n, &attr)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1017 | return NULL; |
| 1018 | use_attr = TRUE; |
| 1019 | break; |
| 1020 | case 4: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1021 | 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] | 1022 | return NULL; |
| 1023 | use_xy = TRUE; |
| 1024 | break; |
| 1025 | case 5: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1026 | 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] | 1027 | return NULL; |
| 1028 | use_xy = use_attr = TRUE; |
| 1029 | break; |
| 1030 | default: |
| 1031 | PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1032 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | if (use_attr == TRUE) { |
| 1036 | attr_old = getattrs(self->win); |
| 1037 | wattrset(self->win,attr); |
| 1038 | } |
| 1039 | if (use_xy == TRUE) |
| 1040 | rtn = mvwinsnstr(self->win,y,x,str,n); |
| 1041 | else |
| 1042 | rtn = winsnstr(self->win,str,n); |
| 1043 | if (use_attr == TRUE) |
| 1044 | wattrset(self->win,attr_old); |
| 1045 | return PyCursesCheckERR(rtn, "insnstr"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1049 | PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1050 | { |
| 1051 | int line, erg; |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1052 | if (!PyArg_Parse(args,"i;line", &line)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1053 | return NULL; |
| 1054 | erg = is_linetouched(self->win, line); |
| 1055 | if (erg == ERR) { |
| 1056 | PyErr_SetString(PyExc_TypeError, |
| 1057 | "is_linetouched: line number outside of boundaries"); |
| 1058 | return NULL; |
| 1059 | } else |
| 1060 | if (erg == FALSE) { |
| 1061 | Py_INCREF(Py_False); |
| 1062 | return Py_False; |
| 1063 | } else { |
| 1064 | Py_INCREF(Py_True); |
| 1065 | return Py_True; |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1070 | PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1071 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1072 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1073 | int rtn; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1074 | |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1075 | #if defined(__NetBSD__) |
| 1076 | if (0) { |
| 1077 | #else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1078 | if (self->win->_flags & _ISPAD) { |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1079 | #endif |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1080 | switch(ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1081 | case 6: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1082 | if (!PyArg_Parse(args, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1083 | "(iiiiii);" \ |
| 1084 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", |
| 1085 | &pminrow, &pmincol, &sminrow, |
| 1086 | &smincol, &smaxrow, &smaxcol)) |
| 1087 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1088 | Py_BEGIN_ALLOW_THREADS |
| 1089 | rtn = pnoutrefresh(self->win, |
| 1090 | pminrow, pmincol, sminrow, |
Andrew M. Kuchling | b6e4687 | 2000-06-27 15:01:10 +0000 | [diff] [blame] | 1091 | smincol, smaxrow, smaxcol); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1092 | Py_END_ALLOW_THREADS |
| 1093 | return PyCursesCheckERR(rtn, "pnoutrefresh"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1094 | default: |
| 1095 | PyErr_SetString(PyCursesError, |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1096 | "noutrefresh() called for a pad " |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1097 | "requires 6 arguments"); |
| 1098 | return NULL; |
| 1099 | } |
| 1100 | } else { |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1101 | if (!PyArg_NoArgs(args)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1102 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1103 | |
| 1104 | Py_BEGIN_ALLOW_THREADS |
| 1105 | rtn = wnoutrefresh(self->win); |
| 1106 | Py_END_ALLOW_THREADS |
| 1107 | return PyCursesCheckERR(rtn, "wnoutrefresh"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | static PyObject * |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1112 | PyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args) |
| 1113 | { |
| 1114 | PyCursesWindowObject *temp; |
| 1115 | int use_copywin = FALSE; |
| 1116 | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; |
| 1117 | int rtn; |
| 1118 | |
| 1119 | switch (ARG_COUNT(args)) { |
| 1120 | case 1: |
| 1121 | if (!PyArg_ParseTuple(args, "O!;window object", |
| 1122 | &PyCursesWindow_Type, &temp)) |
| 1123 | return NULL; |
| 1124 | break; |
| 1125 | case 7: |
| 1126 | if (!PyArg_ParseTuple(args, "(O!iiiiii);window object, int, int, int, int, int, int", |
| 1127 | &PyCursesWindow_Type, &temp, &sminrow, &smincol, |
| 1128 | &dminrow, &dmincol, &dmaxrow, &dmaxcol)) |
| 1129 | return NULL; |
| 1130 | use_copywin = TRUE; |
| 1131 | break; |
| 1132 | default: |
| 1133 | PyErr_SetString(PyExc_TypeError, |
| 1134 | "overlay requires one or seven arguments"); |
| 1135 | return NULL; |
| 1136 | } |
| 1137 | |
| 1138 | if (use_copywin == TRUE) { |
| 1139 | rtn = copywin(self->win, temp->win, sminrow, smincol, |
| 1140 | dminrow, dmincol, dmaxrow, dmaxcol, TRUE); |
| 1141 | return PyCursesCheckERR(rtn, "copywin"); |
| 1142 | } |
| 1143 | else { |
| 1144 | rtn = overlay(self->win, temp->win); |
| 1145 | return PyCursesCheckERR(rtn, "overlay"); |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | static PyObject * |
| 1150 | PyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args) |
| 1151 | { |
| 1152 | PyCursesWindowObject *temp; |
| 1153 | int use_copywin = FALSE; |
| 1154 | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; |
| 1155 | int rtn; |
| 1156 | |
| 1157 | switch (ARG_COUNT(args)) { |
| 1158 | case 1: |
| 1159 | if (!PyArg_ParseTuple(args, "O!;window object", |
| 1160 | &PyCursesWindow_Type, &temp)) |
| 1161 | return NULL; |
| 1162 | break; |
| 1163 | case 7: |
| 1164 | if (!PyArg_ParseTuple(args, "(O!iiiiii);window object, int, int, int, int, int, int", |
| 1165 | &PyCursesWindow_Type, &temp, &sminrow, &smincol, |
| 1166 | &dminrow, &dmincol, &dmaxrow, &dmaxcol)) |
| 1167 | return NULL; |
| 1168 | use_copywin = TRUE; |
| 1169 | break; |
| 1170 | default: |
| 1171 | PyErr_SetString(PyExc_TypeError, |
| 1172 | "overwrite requires one or seven arguments"); |
| 1173 | return NULL; |
| 1174 | } |
| 1175 | |
| 1176 | if (use_copywin == TRUE) { |
| 1177 | rtn = copywin(self->win, temp->win, sminrow, smincol, |
| 1178 | dminrow, dmincol, dmaxrow, dmaxcol, FALSE); |
| 1179 | return PyCursesCheckERR(rtn, "copywin"); |
| 1180 | } |
| 1181 | else { |
| 1182 | rtn = overwrite(self->win, temp->win); |
| 1183 | return PyCursesCheckERR(rtn, "overwrite"); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1188 | PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1189 | { |
| 1190 | PyObject *temp; |
| 1191 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1192 | if (!PyArg_Parse(args, "O;fileobj", &temp)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1193 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1194 | if (!PyFile_Check(temp)) { |
| 1195 | PyErr_SetString(PyExc_TypeError, "argument must be a file object"); |
| 1196 | return NULL; |
| 1197 | } |
| 1198 | return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)), |
| 1199 | "putwin"); |
| 1200 | } |
| 1201 | |
| 1202 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1203 | PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1204 | { |
| 1205 | int beg, num; |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1206 | if (!PyArg_Parse(args,"(ii);beg,num", &beg, &num)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1207 | return NULL; |
| 1208 | return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln"); |
| 1209 | } |
| 1210 | |
| 1211 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1212 | PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1213 | { |
| 1214 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1215 | int rtn; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1216 | |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1217 | #if defined(__NetBSD__) |
| 1218 | if (0) { |
| 1219 | #else |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1220 | if (self->win->_flags & _ISPAD) { |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1221 | #endif |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1222 | switch(ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1223 | case 6: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1224 | if (!PyArg_Parse(args, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1225 | "(iiiiii);" \ |
| 1226 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", |
| 1227 | &pminrow, &pmincol, &sminrow, |
| 1228 | &smincol, &smaxrow, &smaxcol)) |
| 1229 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1230 | |
| 1231 | Py_BEGIN_ALLOW_THREADS |
| 1232 | rtn = prefresh(self->win, |
| 1233 | pminrow, pmincol, sminrow, |
Andrew M. Kuchling | b6e4687 | 2000-06-27 15:01:10 +0000 | [diff] [blame] | 1234 | smincol, smaxrow, smaxcol); |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1235 | Py_END_ALLOW_THREADS |
| 1236 | return PyCursesCheckERR(rtn, "prefresh"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1237 | default: |
| 1238 | PyErr_SetString(PyCursesError, |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1239 | "refresh() for a pad requires 6 arguments"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1240 | return NULL; |
| 1241 | } |
| 1242 | } else { |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1243 | if (!PyArg_NoArgs(args)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1244 | return NULL; |
Andrew M. Kuchling | f419572 | 2000-06-23 01:36:21 +0000 | [diff] [blame] | 1245 | Py_BEGIN_ALLOW_THREADS |
| 1246 | rtn = wrefresh(self->win); |
| 1247 | Py_END_ALLOW_THREADS |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1248 | return PyCursesCheckERR(rtn, "prefresh"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1249 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1253 | PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1254 | { |
| 1255 | int x, y; |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1256 | if (!PyArg_Parse(args,"(ii);top, bottom",&y,&x)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1257 | return NULL; |
| 1258 | return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1262 | PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1263 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1264 | WINDOW *win; |
| 1265 | int nlines, ncols, begin_y, begin_x; |
| 1266 | |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1267 | nlines = 0; |
| 1268 | ncols = 0; |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1269 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1270 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1271 | 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] | 1272 | return NULL; |
| 1273 | break; |
| 1274 | case 4: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1275 | if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x", |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1276 | &nlines,&ncols,&begin_y,&begin_x)) |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1277 | return NULL; |
| 1278 | break; |
| 1279 | default: |
| 1280 | PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1281 | return NULL; |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1282 | } |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1283 | |
Andrew M. Kuchling | 8353f62 | 2000-07-26 18:36:27 +0000 | [diff] [blame] | 1284 | /* 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] | 1285 | #if !defined(__NetBSD__) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1286 | if (self->win->_flags & _ISPAD) |
| 1287 | win = subpad(self->win, nlines, ncols, begin_y, begin_x); |
| 1288 | else |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1289 | #endif |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1290 | win = subwin(self->win, nlines, ncols, begin_y, begin_x); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1291 | |
| 1292 | if (win == NULL) { |
| 1293 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1294 | return NULL; |
| 1295 | } |
| 1296 | |
| 1297 | return (PyObject *)PyCursesWindow_New(win); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1301 | PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1302 | { |
Andrew M. Kuchling | e1c4352 | 2001-01-29 20:31:29 +0000 | [diff] [blame] | 1303 | int nlines; |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1304 | switch(ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1305 | case 0: |
| 1306 | return PyCursesCheckERR(scroll(self->win), "scroll"); |
| 1307 | break; |
| 1308 | case 1: |
Andrew M. Kuchling | e1c4352 | 2001-01-29 20:31:29 +0000 | [diff] [blame] | 1309 | if (!PyArg_Parse(args, "i;nlines", &nlines)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1310 | return NULL; |
Andrew M. Kuchling | e1c4352 | 2001-01-29 20:31:29 +0000 | [diff] [blame] | 1311 | return PyCursesCheckERR(wscrl(self->win, nlines), "scroll"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1312 | default: |
| 1313 | PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1314 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1315 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1319 | PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1320 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1321 | int st, cnt, val; |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1322 | switch (ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1323 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1324 | if (!PyArg_Parse(args,"(ii);start,count",&st,&cnt)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1325 | return NULL; |
| 1326 | return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline"); |
| 1327 | break; |
| 1328 | case 3: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1329 | if (!PyArg_Parse(args, "(iii);start,count,val", &st, &cnt, &val)) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1330 | return NULL; |
| 1331 | return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline"); |
| 1332 | default: |
| 1333 | PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1334 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1339 | PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1340 | { |
| 1341 | PyObject *temp; |
| 1342 | chtype ch; |
| 1343 | int n, x, y, code = OK; |
| 1344 | attr_t attr = A_NORMAL; |
| 1345 | |
| 1346 | switch (ARG_COUNT(args)) { |
| 1347 | case 2: |
| 1348 | if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n)) |
| 1349 | return NULL; |
| 1350 | break; |
| 1351 | case 3: |
| 1352 | if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr)) |
| 1353 | return NULL; |
| 1354 | break; |
| 1355 | case 4: |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1356 | 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] | 1357 | return NULL; |
| 1358 | code = wmove(self->win, y, x); |
| 1359 | break; |
| 1360 | case 5: |
| 1361 | if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr", |
| 1362 | &y, &x, &temp, &n, &attr)) |
| 1363 | return NULL; |
| 1364 | code = wmove(self->win, y, x); |
| 1365 | default: |
| 1366 | PyErr_SetString(PyExc_TypeError, "vline requires 2 or 5 arguments"); |
| 1367 | return NULL; |
| 1368 | } |
| 1369 | |
| 1370 | if (code != ERR) { |
| 1371 | if (!PyCurses_ConvertToChtype(temp, &ch)) { |
| 1372 | PyErr_SetString(PyExc_TypeError, |
| 1373 | "argument 1 or 3 must be a ch or an int"); |
| 1374 | return NULL; |
| 1375 | } |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1376 | return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1377 | } else |
| 1378 | return PyCursesCheckERR(code, "wmove"); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | static PyMethodDef PyCursesWindow_Methods[] = { |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1382 | {"addch", (PyCFunction)PyCursesWindow_AddCh}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1383 | {"addnstr", (PyCFunction)PyCursesWindow_AddNStr}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1384 | {"addstr", (PyCFunction)PyCursesWindow_AddStr}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1385 | {"attroff", (PyCFunction)PyCursesWindow_wattroff}, |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1386 | {"attron", (PyCFunction)PyCursesWindow_wattron}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1387 | {"attrset", (PyCFunction)PyCursesWindow_wattrset}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1388 | {"bkgd", (PyCFunction)PyCursesWindow_Bkgd}, |
| 1389 | {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1390 | {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS}, |
| 1391 | {"box", (PyCFunction)PyCursesWindow_Box}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1392 | {"clear", (PyCFunction)PyCursesWindow_wclear}, |
| 1393 | {"clearok", (PyCFunction)PyCursesWindow_clearok}, |
| 1394 | {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot}, |
| 1395 | {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol}, |
| 1396 | {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup}, |
| 1397 | {"delch", (PyCFunction)PyCursesWindow_DelCh}, |
| 1398 | {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln}, |
| 1399 | {"derwin", (PyCFunction)PyCursesWindow_DerWin}, |
| 1400 | {"echochar", (PyCFunction)PyCursesWindow_EchoChar}, |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1401 | #ifdef NCURSES_MOUSE_VERSION |
| 1402 | {"enclose", (PyCFunction)PyCursesWindow_Enclose}, |
| 1403 | #endif |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1404 | {"erase", (PyCFunction)PyCursesWindow_werase}, |
| 1405 | {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx}, |
| 1406 | {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1407 | {"getch", (PyCFunction)PyCursesWindow_GetCh}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1408 | {"getkey", (PyCFunction)PyCursesWindow_GetKey}, |
| 1409 | {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx}, |
| 1410 | {"getparyx", (PyCFunction)PyCursesWindow_getparyx}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1411 | {"getstr", (PyCFunction)PyCursesWindow_GetStr}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1412 | {"getyx", (PyCFunction)PyCursesWindow_getyx}, |
| 1413 | {"hline", (PyCFunction)PyCursesWindow_Hline}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1414 | {"idcok", (PyCFunction)PyCursesWindow_idcok}, |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1415 | {"idlok", (PyCFunction)PyCursesWindow_idlok}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1416 | {"immedok", (PyCFunction)PyCursesWindow_immedok}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1417 | {"inch", (PyCFunction)PyCursesWindow_InCh}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1418 | {"insch", (PyCFunction)PyCursesWindow_InsCh}, |
| 1419 | {"insdelln", (PyCFunction)PyCursesWindow_winsdelln}, |
| 1420 | {"insertln", (PyCFunction)PyCursesWindow_winsertln}, |
| 1421 | {"insnstr", (PyCFunction)PyCursesWindow_InsNStr}, |
| 1422 | {"insstr", (PyCFunction)PyCursesWindow_InsStr}, |
| 1423 | {"instr", (PyCFunction)PyCursesWindow_InStr}, |
| 1424 | {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched}, |
| 1425 | {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched}, |
| 1426 | {"keypad", (PyCFunction)PyCursesWindow_keypad}, |
| 1427 | {"leaveok", (PyCFunction)PyCursesWindow_leaveok}, |
| 1428 | {"move", (PyCFunction)PyCursesWindow_wmove}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1429 | {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin}, |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1430 | {"mvwin", (PyCFunction)PyCursesWindow_mvwin}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1431 | {"nodelay", (PyCFunction)PyCursesWindow_nodelay}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1432 | {"notimeout", (PyCFunction)PyCursesWindow_notimeout}, |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1433 | {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh}, |
Andrew M. Kuchling | a98e92b | 2000-08-20 23:37:02 +0000 | [diff] [blame] | 1434 | /* Backward compatibility alias -- remove in Python 2.1 */ |
Andrew M. Kuchling | 9de6ffa | 2000-12-21 16:22:22 +0000 | [diff] [blame] | 1435 | {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh}, |
| 1436 | {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS}, |
| 1437 | {"overwrite", (PyCFunction)PyCursesWindow_Overwrite, METH_VARARGS}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1438 | {"putwin", (PyCFunction)PyCursesWindow_PutWin}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1439 | {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine}, |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1440 | {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1441 | {"refresh", (PyCFunction)PyCursesWindow_Refresh}, |
Andrew M. Kuchling | a1e4b05 | 2000-06-27 21:49:47 +0000 | [diff] [blame] | 1442 | #ifndef STRICT_SYSV_CURSES |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1443 | {"resize", (PyCFunction)PyCursesWindow_wresize}, |
| 1444 | #endif |
| 1445 | {"scroll", (PyCFunction)PyCursesWindow_Scroll}, |
| 1446 | {"scrollok", (PyCFunction)PyCursesWindow_scrollok}, |
Sjoerd Mullender | 14ece16 | 1995-03-17 12:18:38 +0000 | [diff] [blame] | 1447 | {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1448 | {"standend", (PyCFunction)PyCursesWindow_wstandend}, |
| 1449 | {"standout", (PyCFunction)PyCursesWindow_wstandout}, |
| 1450 | {"subpad", (PyCFunction)PyCursesWindow_SubWin}, |
| 1451 | {"subwin", (PyCFunction)PyCursesWindow_SubWin}, |
| 1452 | {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown}, |
| 1453 | {"syncok", (PyCFunction)PyCursesWindow_syncok}, |
| 1454 | {"syncup", (PyCFunction)PyCursesWindow_wsyncup}, |
Andrew M. Kuchling | 97311bb | 2000-06-21 01:41:48 +0000 | [diff] [blame] | 1455 | {"timeout", (PyCFunction)PyCursesWindow_wtimeout}, |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1456 | {"touchline", (PyCFunction)PyCursesWindow_TouchLine}, |
| 1457 | {"touchwin", (PyCFunction)PyCursesWindow_touchwin}, |
| 1458 | {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin}, |
| 1459 | {"vline", (PyCFunction)PyCursesWindow_Vline}, |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1460 | {NULL, NULL} /* sentinel */ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1461 | }; |
| 1462 | |
| 1463 | static PyObject * |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 1464 | PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1465 | { |
Guido van Rossum | a597dde | 1995-01-10 20:56:29 +0000 | [diff] [blame] | 1466 | return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1469 | /* -------------------------------------------------------*/ |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1470 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1471 | PyTypeObject PyCursesWindow_Type = { |
Guido van Rossum | 6915c4d | 2001-01-19 00:28:08 +0000 | [diff] [blame] | 1472 | PyObject_HEAD_INIT(NULL) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1473 | 0, /*ob_size*/ |
| 1474 | "curses window", /*tp_name*/ |
| 1475 | sizeof(PyCursesWindowObject), /*tp_basicsize*/ |
| 1476 | 0, /*tp_itemsize*/ |
| 1477 | /* methods */ |
| 1478 | (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/ |
| 1479 | 0, /*tp_print*/ |
| 1480 | (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/ |
| 1481 | (setattrfunc)0, /*tp_setattr*/ |
| 1482 | 0, /*tp_compare*/ |
| 1483 | 0, /*tp_repr*/ |
| 1484 | 0, /*tp_as_number*/ |
| 1485 | 0, /*tp_as_sequence*/ |
| 1486 | 0, /*tp_as_mapping*/ |
| 1487 | 0, /*tp_hash*/ |
| 1488 | }; |
| 1489 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1490 | /********************************************************************* |
| 1491 | Global Functions |
| 1492 | **********************************************************************/ |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1493 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1494 | NoArgNoReturnFunction(beep) |
| 1495 | NoArgNoReturnFunction(def_prog_mode) |
| 1496 | NoArgNoReturnFunction(def_shell_mode) |
| 1497 | NoArgNoReturnFunction(doupdate) |
| 1498 | NoArgNoReturnFunction(endwin) |
| 1499 | NoArgNoReturnFunction(flash) |
| 1500 | NoArgNoReturnFunction(nocbreak) |
| 1501 | NoArgNoReturnFunction(noecho) |
| 1502 | NoArgNoReturnFunction(nonl) |
| 1503 | NoArgNoReturnFunction(noraw) |
| 1504 | NoArgNoReturnFunction(reset_prog_mode) |
| 1505 | NoArgNoReturnFunction(reset_shell_mode) |
| 1506 | NoArgNoReturnFunction(resetty) |
| 1507 | NoArgNoReturnFunction(savetty) |
| 1508 | |
| 1509 | NoArgOrFlagNoReturnFunction(cbreak) |
| 1510 | NoArgOrFlagNoReturnFunction(echo) |
| 1511 | NoArgOrFlagNoReturnFunction(nl) |
| 1512 | NoArgOrFlagNoReturnFunction(raw) |
| 1513 | |
| 1514 | NoArgReturnIntFunction(baudrate) |
| 1515 | NoArgReturnIntFunction(termattrs) |
| 1516 | |
| 1517 | NoArgReturnStringFunction(termname) |
| 1518 | NoArgReturnStringFunction(longname) |
| 1519 | |
| 1520 | NoArgTrueFalseFunction(can_change_color) |
| 1521 | NoArgTrueFalseFunction(has_colors) |
| 1522 | NoArgTrueFalseFunction(has_ic) |
| 1523 | NoArgTrueFalseFunction(has_il) |
| 1524 | NoArgTrueFalseFunction(isendwin) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1525 | NoArgNoReturnVoidFunction(filter) |
| 1526 | NoArgNoReturnVoidFunction(flushinp) |
| 1527 | NoArgNoReturnVoidFunction(noqiflush) |
| 1528 | |
| 1529 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1530 | PyCurses_Color_Content(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1531 | { |
| 1532 | short color,r,g,b; |
| 1533 | |
| 1534 | PyCursesInitialised |
| 1535 | PyCursesInitialisedColor |
| 1536 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1537 | if (ARG_COUNT(args) != 1) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1538 | PyErr_SetString(PyExc_TypeError, |
| 1539 | "color_content requires 1 argument"); |
| 1540 | return NULL; |
| 1541 | } |
| 1542 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1543 | if (!PyArg_Parse(args, "h;color", &color)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1544 | |
| 1545 | if (color_content(color, &r, &g, &b) != ERR) |
| 1546 | return Py_BuildValue("(iii)", r, g, b); |
| 1547 | else { |
| 1548 | PyErr_SetString(PyCursesError, |
| 1549 | "Argument 1 was out of range. Check value of COLORS."); |
| 1550 | return NULL; |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1555 | PyCurses_color_pair(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1556 | { |
| 1557 | int n; |
| 1558 | |
| 1559 | PyCursesInitialised |
| 1560 | PyCursesInitialisedColor |
| 1561 | |
Andrew M. Kuchling | 4463acb | 2000-07-24 23:54:49 +0000 | [diff] [blame] | 1562 | if (ARG_COUNT(args) != 1) { |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1563 | PyErr_SetString(PyExc_TypeError, "color_pair requires 1 argument"); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1564 | return NULL; |
| 1565 | } |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1566 | if (!PyArg_Parse(args, "i;number", &n)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1567 | return PyInt_FromLong((long) (n << 8)); |
| 1568 | } |
| 1569 | |
| 1570 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1571 | PyCurses_Curs_Set(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1572 | { |
| 1573 | int vis,erg; |
| 1574 | |
| 1575 | PyCursesInitialised |
| 1576 | |
Andrew M. Kuchling | 4463acb | 2000-07-24 23:54:49 +0000 | [diff] [blame] | 1577 | if (ARG_COUNT(args)!=1) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1578 | PyErr_SetString(PyExc_TypeError, "curs_set requires 1 argument"); |
| 1579 | return NULL; |
| 1580 | } |
| 1581 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1582 | if (!PyArg_Parse(args, "i;int", &vis)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1583 | |
| 1584 | erg = curs_set(vis); |
| 1585 | if (erg == ERR) return PyCursesCheckERR(erg, "curs_set"); |
| 1586 | |
| 1587 | return PyInt_FromLong((long) erg); |
| 1588 | } |
| 1589 | |
| 1590 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1591 | PyCurses_Delay_Output(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1592 | { |
| 1593 | int ms; |
| 1594 | |
| 1595 | PyCursesInitialised |
| 1596 | |
Andrew M. Kuchling | 4463acb | 2000-07-24 23:54:49 +0000 | [diff] [blame] | 1597 | if (ARG_COUNT(args) != 1) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1598 | PyErr_SetString(PyExc_TypeError, "delay_output requires 1 argument"); |
| 1599 | return NULL; |
| 1600 | } |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1601 | if (!PyArg_Parse(args, "i;ms", &ms)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1602 | |
| 1603 | return PyCursesCheckERR(delay_output(ms), "delay_output"); |
| 1604 | } |
| 1605 | |
| 1606 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1607 | PyCurses_EraseChar(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1608 | { |
| 1609 | char ch; |
| 1610 | |
| 1611 | PyCursesInitialised |
| 1612 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1613 | if (!PyArg_NoArgs(args)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1614 | |
| 1615 | ch = erasechar(); |
| 1616 | |
| 1617 | return PyString_FromString(&ch); |
| 1618 | } |
| 1619 | |
| 1620 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1621 | PyCurses_getsyx(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1622 | { |
| 1623 | int x,y; |
| 1624 | |
| 1625 | PyCursesInitialised |
| 1626 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1627 | if (!PyArg_NoArgs(args)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1628 | |
| 1629 | getsyx(y, x); |
| 1630 | |
| 1631 | return Py_BuildValue("(ii)", y, x); |
| 1632 | } |
| 1633 | |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1634 | #ifdef NCURSES_MOUSE_VERSION |
| 1635 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1636 | PyCurses_GetMouse(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1637 | { |
| 1638 | int rtn; |
| 1639 | MEVENT event; |
| 1640 | |
| 1641 | PyCursesInitialised |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1642 | if (!PyArg_NoArgs(args)) return NULL; |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1643 | |
| 1644 | rtn = getmouse( &event ); |
| 1645 | if (rtn == ERR) { |
| 1646 | PyErr_SetString(PyCursesError, "getmouse() returned ERR"); |
| 1647 | return NULL; |
| 1648 | } |
| 1649 | return Py_BuildValue("(hiiil)", |
| 1650 | (short)event.id, |
| 1651 | event.x, event.y, event.z, |
| 1652 | (long) event.bstate); |
| 1653 | } |
| 1654 | |
| 1655 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1656 | PyCurses_UngetMouse(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1657 | { |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1658 | MEVENT event; |
| 1659 | |
| 1660 | PyCursesInitialised |
| 1661 | if (!PyArg_ParseTuple(args, "(hiiil)", |
| 1662 | &event.id, |
| 1663 | &event.x, &event.y, &event.z, |
| 1664 | (int *) &event.bstate)) |
| 1665 | return NULL; |
| 1666 | |
| 1667 | return PyCursesCheckERR(ungetmouse(&event), "ungetmouse"); |
| 1668 | } |
| 1669 | #endif |
| 1670 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1671 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1672 | PyCurses_GetWin(PyCursesWindowObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1673 | { |
| 1674 | WINDOW *win; |
| 1675 | PyObject *temp; |
| 1676 | |
| 1677 | PyCursesInitialised |
| 1678 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1679 | if (!PyArg_Parse(args, "O;fileobj", &temp)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1680 | |
| 1681 | if (!PyFile_Check(temp)) { |
| 1682 | PyErr_SetString(PyExc_TypeError, "argument must be a file object"); |
| 1683 | return NULL; |
| 1684 | } |
| 1685 | |
| 1686 | win = getwin(PyFile_AsFile(temp)); |
| 1687 | |
| 1688 | if (win == NULL) { |
| 1689 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1690 | return NULL; |
| 1691 | } |
| 1692 | |
| 1693 | return PyCursesWindow_New(win); |
| 1694 | } |
| 1695 | |
| 1696 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1697 | PyCurses_HalfDelay(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1698 | { |
| 1699 | unsigned char tenths; |
| 1700 | |
| 1701 | PyCursesInitialised |
| 1702 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1703 | switch(ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1704 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1705 | if (!PyArg_Parse(args, "b;tenths", &tenths)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1706 | break; |
| 1707 | default: |
| 1708 | PyErr_SetString(PyExc_TypeError, "halfdelay requires 1 argument"); |
| 1709 | return NULL; |
| 1710 | } |
| 1711 | |
| 1712 | return PyCursesCheckERR(halfdelay(tenths), "halfdelay"); |
| 1713 | } |
| 1714 | |
Andrew M. Kuchling | bf68026 | 2000-07-25 12:37:41 +0000 | [diff] [blame] | 1715 | #ifndef STRICT_SYSV_CURSES |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1716 | /* No has_key! */ |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1717 | static PyObject * PyCurses_has_key(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1718 | { |
| 1719 | int ch; |
| 1720 | |
| 1721 | PyCursesInitialised |
| 1722 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1723 | if (!PyArg_Parse(args,"i",&ch)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1724 | |
| 1725 | if (has_key(ch) == FALSE) { |
| 1726 | Py_INCREF(Py_False); |
| 1727 | return Py_False; |
| 1728 | } |
| 1729 | Py_INCREF(Py_True); |
| 1730 | return Py_True; |
| 1731 | } |
Andrew M. Kuchling | bf68026 | 2000-07-25 12:37:41 +0000 | [diff] [blame] | 1732 | #endif /* STRICT_SYSV_CURSES */ |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1733 | |
| 1734 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1735 | PyCurses_Init_Color(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1736 | { |
| 1737 | short color, r, g, b; |
| 1738 | |
| 1739 | PyCursesInitialised |
| 1740 | PyCursesInitialisedColor |
| 1741 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1742 | switch(ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1743 | case 4: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1744 | 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] | 1745 | break; |
| 1746 | default: |
| 1747 | PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments"); |
| 1748 | return NULL; |
| 1749 | } |
| 1750 | |
| 1751 | return PyCursesCheckERR(init_color(color, r, g, b), "init_color"); |
| 1752 | } |
| 1753 | |
| 1754 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1755 | PyCurses_Init_Pair(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1756 | { |
| 1757 | short pair, f, b; |
| 1758 | |
| 1759 | PyCursesInitialised |
| 1760 | PyCursesInitialisedColor |
| 1761 | |
Andrew M. Kuchling | 4463acb | 2000-07-24 23:54:49 +0000 | [diff] [blame] | 1762 | if (ARG_COUNT(args) != 3) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1763 | PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments"); |
| 1764 | return NULL; |
| 1765 | } |
| 1766 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1767 | 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] | 1768 | |
| 1769 | return PyCursesCheckERR(init_pair(pair, f, b), "init_pair"); |
| 1770 | } |
| 1771 | |
Andrew M. Kuchling | 3255268 | 2000-12-22 21:52:27 +0000 | [diff] [blame] | 1772 | static PyObject *ModDict; |
| 1773 | |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1774 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1775 | PyCurses_InitScr(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1776 | { |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1777 | WINDOW *win; |
Andrew M. Kuchling | e1c4352 | 2001-01-29 20:31:29 +0000 | [diff] [blame] | 1778 | PyObject *nlines, *cols; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1779 | |
| 1780 | if (!PyArg_NoArgs(args)) return NULL; |
| 1781 | |
Guido van Rossum | 585c6dc | 1995-02-24 13:45:43 +0000 | [diff] [blame] | 1782 | if (initialised == TRUE) { |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1783 | wrefresh(stdscr); |
| 1784 | return (PyObject *)PyCursesWindow_New(stdscr); |
| 1785 | } |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1786 | |
| 1787 | win = initscr(); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1788 | |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1789 | if (win == NULL) { |
| 1790 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 1791 | return NULL; |
| 1792 | } |
| 1793 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 1794 | initialised = initialised_setupterm = TRUE; |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1795 | |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1796 | /* This was moved from initcurses() because it core dumped on SGI, |
| 1797 | where they're not defined until you've called initscr() */ |
| 1798 | #define SetDictInt(string,ch) \ |
| 1799 | PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch))); |
| 1800 | |
| 1801 | /* Here are some graphic symbols you can use */ |
| 1802 | SetDictInt("ACS_ULCORNER", (ACS_ULCORNER)); |
| 1803 | SetDictInt("ACS_LLCORNER", (ACS_LLCORNER)); |
| 1804 | SetDictInt("ACS_URCORNER", (ACS_URCORNER)); |
| 1805 | SetDictInt("ACS_LRCORNER", (ACS_LRCORNER)); |
| 1806 | SetDictInt("ACS_LTEE", (ACS_LTEE)); |
| 1807 | SetDictInt("ACS_RTEE", (ACS_RTEE)); |
| 1808 | SetDictInt("ACS_BTEE", (ACS_BTEE)); |
| 1809 | SetDictInt("ACS_TTEE", (ACS_TTEE)); |
| 1810 | SetDictInt("ACS_HLINE", (ACS_HLINE)); |
| 1811 | SetDictInt("ACS_VLINE", (ACS_VLINE)); |
| 1812 | SetDictInt("ACS_PLUS", (ACS_PLUS)); |
| 1813 | SetDictInt("ACS_S1", (ACS_S1)); |
| 1814 | SetDictInt("ACS_S9", (ACS_S9)); |
| 1815 | SetDictInt("ACS_DIAMOND", (ACS_DIAMOND)); |
| 1816 | SetDictInt("ACS_CKBOARD", (ACS_CKBOARD)); |
| 1817 | SetDictInt("ACS_DEGREE", (ACS_DEGREE)); |
| 1818 | SetDictInt("ACS_PLMINUS", (ACS_PLMINUS)); |
| 1819 | SetDictInt("ACS_BULLET", (ACS_BULLET)); |
| 1820 | SetDictInt("ACS_LARROW", (ACS_LARROW)); |
| 1821 | SetDictInt("ACS_RARROW", (ACS_RARROW)); |
| 1822 | SetDictInt("ACS_DARROW", (ACS_DARROW)); |
| 1823 | SetDictInt("ACS_UARROW", (ACS_UARROW)); |
| 1824 | SetDictInt("ACS_BOARD", (ACS_BOARD)); |
| 1825 | SetDictInt("ACS_LANTERN", (ACS_LANTERN)); |
| 1826 | SetDictInt("ACS_BLOCK", (ACS_BLOCK)); |
| 1827 | SetDictInt("ACS_BSSB", (ACS_ULCORNER)); |
| 1828 | SetDictInt("ACS_SSBB", (ACS_LLCORNER)); |
| 1829 | SetDictInt("ACS_BBSS", (ACS_URCORNER)); |
| 1830 | SetDictInt("ACS_SBBS", (ACS_LRCORNER)); |
| 1831 | SetDictInt("ACS_SBSS", (ACS_RTEE)); |
| 1832 | SetDictInt("ACS_SSSB", (ACS_LTEE)); |
| 1833 | SetDictInt("ACS_SSBS", (ACS_BTEE)); |
| 1834 | SetDictInt("ACS_BSSS", (ACS_TTEE)); |
| 1835 | SetDictInt("ACS_BSBS", (ACS_HLINE)); |
| 1836 | SetDictInt("ACS_SBSB", (ACS_VLINE)); |
| 1837 | SetDictInt("ACS_SSSS", (ACS_PLUS)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 1838 | |
| 1839 | /* The following are never available with strict SYSV curses */ |
| 1840 | #ifdef ACS_S3 |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1841 | SetDictInt("ACS_S3", (ACS_S3)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 1842 | #endif |
| 1843 | #ifdef ACS_S7 |
| 1844 | SetDictInt("ACS_S7", (ACS_S7)); |
| 1845 | #endif |
| 1846 | #ifdef ACS_LEQUAL |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1847 | SetDictInt("ACS_LEQUAL", (ACS_LEQUAL)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 1848 | #endif |
| 1849 | #ifdef ACS_GEQUAL |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1850 | SetDictInt("ACS_GEQUAL", (ACS_GEQUAL)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 1851 | #endif |
| 1852 | #ifdef ACS_PI |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1853 | SetDictInt("ACS_PI", (ACS_PI)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 1854 | #endif |
| 1855 | #ifdef ACS_NEQUAL |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1856 | SetDictInt("ACS_NEQUAL", (ACS_NEQUAL)); |
Andrew M. Kuchling | e7d3616 | 2000-11-01 19:59:12 +0000 | [diff] [blame] | 1857 | #endif |
| 1858 | #ifdef ACS_STERLING |
Andrew M. Kuchling | 03e644b | 2000-05-23 16:24:54 +0000 | [diff] [blame] | 1859 | SetDictInt("ACS_STERLING", (ACS_STERLING)); |
| 1860 | #endif |
| 1861 | |
Andrew M. Kuchling | e1c4352 | 2001-01-29 20:31:29 +0000 | [diff] [blame] | 1862 | nlines = PyInt_FromLong((long) LINES); |
| 1863 | PyDict_SetItemString(ModDict, "LINES", nlines); |
| 1864 | Py_DECREF(nlines); |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1865 | cols = PyInt_FromLong((long) COLS); |
| 1866 | PyDict_SetItemString(ModDict, "COLS", cols); |
| 1867 | Py_DECREF(cols); |
Guido van Rossum | 56bf235 | 1994-08-31 22:06:24 +0000 | [diff] [blame] | 1868 | |
| 1869 | return (PyObject *)PyCursesWindow_New(win); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
Andrew M. Kuchling | 26cc66f | 2000-11-18 17:45:59 +0000 | [diff] [blame] | 1872 | static PyObject * |
| 1873 | PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds) |
| 1874 | { |
| 1875 | int fd = -1; |
| 1876 | int err; |
| 1877 | char* termstr = NULL; |
| 1878 | |
| 1879 | static char *kwlist[] = {"term", "fd", NULL}; |
| 1880 | |
| 1881 | if (!PyArg_ParseTupleAndKeywords( |
| 1882 | args,keywds,"|zi:setupterm",kwlist,&termstr,&fd)) { |
| 1883 | return NULL; |
| 1884 | } |
| 1885 | |
| 1886 | if (fd == -1) { |
| 1887 | PyObject* sys_stdout; |
| 1888 | |
| 1889 | sys_stdout = PySys_GetObject("stdout"); |
| 1890 | |
| 1891 | if (sys_stdout == NULL) { |
| 1892 | PyErr_SetString( |
| 1893 | PyCursesError, |
| 1894 | "lost sys.stdout"); |
| 1895 | return NULL; |
| 1896 | } |
| 1897 | |
| 1898 | fd = PyObject_AsFileDescriptor(sys_stdout); |
| 1899 | |
| 1900 | if (fd == -1) { |
| 1901 | return NULL; |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | if (setupterm(termstr,fd,&err) == ERR) { |
| 1906 | char* s = "setupterm: unknown error"; |
| 1907 | |
| 1908 | if (err == 0) { |
| 1909 | s = "setupterm: could not find terminal"; |
| 1910 | } else if (err == -1) { |
| 1911 | s = "setupterm: could not find terminfo database"; |
| 1912 | } |
| 1913 | |
| 1914 | PyErr_SetString(PyCursesError,s); |
| 1915 | return NULL; |
| 1916 | } |
| 1917 | |
| 1918 | initialised_setupterm = TRUE; |
| 1919 | |
| 1920 | Py_INCREF(Py_None); |
| 1921 | return Py_None; |
| 1922 | } |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1923 | |
| 1924 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1925 | PyCurses_IntrFlush(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 1926 | { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1927 | int ch; |
| 1928 | |
| 1929 | PyCursesInitialised |
| 1930 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1931 | switch(ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1932 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1933 | 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] | 1934 | break; |
| 1935 | default: |
| 1936 | PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument"); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 1937 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | return PyCursesCheckERR(intrflush(NULL,ch), "intrflush"); |
| 1941 | } |
| 1942 | |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1943 | #if !defined(__NetBSD__) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1944 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1945 | PyCurses_KeyName(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1946 | { |
| 1947 | const char *knp; |
| 1948 | int ch; |
| 1949 | |
| 1950 | PyCursesInitialised |
| 1951 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1952 | if (!PyArg_Parse(args,"i",&ch)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1953 | |
| 1954 | knp = keyname(ch); |
| 1955 | |
| 1956 | return PyString_FromString((knp == NULL) ? "" : (char *)knp); |
| 1957 | } |
Andrew M. Kuchling | 2d339f9 | 2001-01-29 20:47:59 +0000 | [diff] [blame] | 1958 | #endif |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1959 | |
| 1960 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1961 | PyCurses_KillChar(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1962 | { |
| 1963 | char ch; |
| 1964 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1965 | if (!PyArg_NoArgs(args)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1966 | |
| 1967 | ch = killchar(); |
| 1968 | |
| 1969 | return PyString_FromString(&ch); |
| 1970 | } |
| 1971 | |
| 1972 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1973 | PyCurses_Meta(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1974 | { |
| 1975 | int ch; |
| 1976 | |
| 1977 | PyCursesInitialised |
| 1978 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1979 | switch(ARG_COUNT(args)) { |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 1980 | case 1: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1981 | 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] | 1982 | break; |
| 1983 | default: |
| 1984 | PyErr_SetString(PyExc_TypeError, "meta requires 1 argument"); |
| 1985 | return NULL; |
| 1986 | } |
| 1987 | |
| 1988 | return PyCursesCheckERR(meta(stdscr, ch), "meta"); |
| 1989 | } |
| 1990 | |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1991 | #ifdef NCURSES_MOUSE_VERSION |
| 1992 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1993 | PyCurses_MouseInterval(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1994 | { |
| 1995 | int interval; |
| 1996 | PyCursesInitialised |
| 1997 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 1998 | if (!PyArg_Parse(args,"i;interval",&interval)) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 1999 | return NULL; |
| 2000 | return PyCursesCheckERR(mouseinterval(interval), "mouseinterval"); |
| 2001 | } |
| 2002 | |
| 2003 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2004 | PyCurses_MouseMask(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2005 | { |
Andrew M. Kuchling | 1a10400 | 2000-07-06 18:14:03 +0000 | [diff] [blame] | 2006 | int newmask; |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2007 | mmask_t oldmask, availmask; |
| 2008 | |
| 2009 | PyCursesInitialised |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2010 | if (!PyArg_Parse(args,"i;mousemask",&newmask)) |
Andrew M. Kuchling | 8e9d23b | 2000-06-27 03:10:38 +0000 | [diff] [blame] | 2011 | return NULL; |
| 2012 | availmask = mousemask(newmask, &oldmask); |
| 2013 | return Py_BuildValue("(ll)", (long)availmask, (long)oldmask); |
| 2014 | } |
| 2015 | #endif |
| 2016 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2017 | static PyObject * |
Andrew M. Kuchling | 2824d7f | 2000-12-15 00:44:02 +0000 | [diff] [blame] | 2018 | PyCurses_Napms(PyObject *self, PyObject *args) |
| 2019 | { |
| 2020 | int ms; |
| 2021 | |
| 2022 | PyCursesInitialised |
| 2023 | if (!PyArg_Parse(args, "i;ms", &ms)) return NULL; |
| 2024 | |
| 2025 | return Py_BuildValue("i", napms(ms)); |
| 2026 | } |
| 2027 | |
| 2028 | |
| 2029 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2030 | PyCurses_NewPad(PyObject *self, PyObject *args) |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2031 | { |
| 2032 | WINDOW *win; |
| 2033 | int nlines, ncols; |
| 2034 | |
| 2035 | PyCursesInitialised |
| 2036 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2037 | if (!PyArg_Parse(args,"(ii);nlines,ncols",&nlines,&ncols)) return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2038 | |
| 2039 | win = newpad(nlines, ncols); |
| 2040 | |
| 2041 | if (win == NULL) { |
| 2042 | PyErr_SetString(PyCursesError, catchall_NULL); |
| 2043 | return NULL; |
| 2044 | } |
| 2045 | |
| 2046 | return (PyObject *)PyCursesWindow_New(win); |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | static PyObject * |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2050 | PyCurses_NewWindow(PyObject *self, PyObject *args) |
Guido van Rossum | f6971e2 | 1994-08-30 12:25:20 +0000 | [diff] [blame] | 2051 | { |
| 2052 | WINDOW *win; |
| 2053 | int nlines, ncols, begin_y, begin_x; |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2054 | |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2055 | PyCursesInitialised |
| 2056 | |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2057 | switch (ARG_COUNT(args)) { |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2058 | case 2: |
Andrew M. Kuchling | ad9b1f8 | 2000-07-09 14:35:00 +0000 | [diff] [blame] | 2059 | if (!PyArg_Parse(args,"(ii);nlines,ncols",&nlines,&ncols)) |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2060 | return NULL; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2061 | win = newpad(nlines, ncols); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 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; |
Andrew M. Kuchling | 22b88ce | 2000-05-23 16:18:03 +0000 | [diff] [blame] | 2067 | win = newwin(nlines,ncols,begin_y,begin_x); |
Guido van Rossum | 8573847 | 1995-02-17 13:50:17 +0000 | [diff] [blame] | 2068 | break; |
| 2069 | default: |
| 2070 | PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments"); |
| 2071 | return NULL; |
| 2072 | } |
| 2073 | |
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 | } |