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