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