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