1 | n/a | /* |
---|
2 | n/a | * This is a curses module for Python. |
---|
3 | n/a | * |
---|
4 | n/a | * Based on prior work by Lance Ellinghaus and Oliver Andrich |
---|
5 | n/a | * Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse, |
---|
6 | n/a | * Cathedral City, California Republic, United States of America. |
---|
7 | n/a | * |
---|
8 | n/a | * Version 1.5b1, heavily extended for ncurses by Oliver Andrich: |
---|
9 | n/a | * Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany. |
---|
10 | n/a | * |
---|
11 | n/a | * Tidied for Python 1.6, and currently maintained by <amk@amk.ca>. |
---|
12 | n/a | * |
---|
13 | n/a | * Permission is hereby granted, free of charge, to any person obtaining |
---|
14 | n/a | * a copy of this source file to use, copy, modify, merge, or publish it |
---|
15 | n/a | * subject to the following conditions: |
---|
16 | n/a | * |
---|
17 | n/a | * The above copyright notice and this permission notice shall be included |
---|
18 | n/a | * in all copies or in any new file that contains a substantial portion of |
---|
19 | n/a | * this file. |
---|
20 | n/a | * |
---|
21 | n/a | * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF |
---|
22 | n/a | * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT |
---|
23 | n/a | * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES |
---|
24 | n/a | * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES |
---|
25 | n/a | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
---|
26 | n/a | * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE |
---|
27 | n/a | * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, |
---|
28 | n/a | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
---|
29 | n/a | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR |
---|
30 | n/a | * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
---|
31 | n/a | * PERFORMANCE OF THIS SOFTWARE. |
---|
32 | n/a | */ |
---|
33 | n/a | |
---|
34 | n/a | /* |
---|
35 | n/a | |
---|
36 | n/a | A number of SysV or ncurses functions don't have wrappers yet; if you |
---|
37 | n/a | need a given function, add it and send a patch. See |
---|
38 | n/a | http://www.python.org/dev/patches/ for instructions on how to submit |
---|
39 | n/a | patches to Python. |
---|
40 | n/a | |
---|
41 | n/a | Here's a list of currently unsupported functions: |
---|
42 | n/a | |
---|
43 | n/a | addchnstr addchstr color_set define_key |
---|
44 | n/a | del_curterm delscreen dupwin inchnstr inchstr innstr keyok |
---|
45 | n/a | mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr |
---|
46 | n/a | mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr |
---|
47 | n/a | mvwinchnstr mvwinchstr mvwinnstr newterm |
---|
48 | n/a | restartterm ripoffline scr_dump |
---|
49 | n/a | scr_init scr_restore scr_set scrl set_curterm set_term setterm |
---|
50 | n/a | tgetent tgetflag tgetnum tgetstr tgoto timeout tputs |
---|
51 | n/a | vidattr vidputs waddchnstr waddchstr |
---|
52 | n/a | wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl |
---|
53 | n/a | |
---|
54 | n/a | Low-priority: |
---|
55 | n/a | slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff |
---|
56 | n/a | slk_attron slk_attrset slk_clear slk_color slk_init slk_label |
---|
57 | n/a | slk_noutrefresh slk_refresh slk_restore slk_set slk_touch |
---|
58 | n/a | |
---|
59 | n/a | Menu extension (ncurses and probably SYSV): |
---|
60 | n/a | current_item free_item free_menu item_count item_description |
---|
61 | n/a | item_index item_init item_name item_opts item_opts_off |
---|
62 | n/a | item_opts_on item_term item_userptr item_value item_visible |
---|
63 | n/a | menu_back menu_driver menu_fore menu_format menu_grey |
---|
64 | n/a | menu_init menu_items menu_mark menu_opts menu_opts_off |
---|
65 | n/a | menu_opts_on menu_pad menu_pattern menu_request_by_name |
---|
66 | n/a | menu_request_name menu_spacing menu_sub menu_term menu_userptr |
---|
67 | n/a | menu_win new_item new_menu pos_menu_cursor post_menu |
---|
68 | n/a | scale_menu set_current_item set_item_init set_item_opts |
---|
69 | n/a | set_item_term set_item_userptr set_item_value set_menu_back |
---|
70 | n/a | set_menu_fore set_menu_format set_menu_grey set_menu_init |
---|
71 | n/a | set_menu_items set_menu_mark set_menu_opts set_menu_pad |
---|
72 | n/a | set_menu_pattern set_menu_spacing set_menu_sub set_menu_term |
---|
73 | n/a | set_menu_userptr set_menu_win set_top_row top_row unpost_menu |
---|
74 | n/a | |
---|
75 | n/a | Form extension (ncurses and probably SYSV): |
---|
76 | n/a | current_field data_ahead data_behind dup_field |
---|
77 | n/a | dynamic_fieldinfo field_arg field_back field_buffer |
---|
78 | n/a | field_count field_fore field_index field_info field_init |
---|
79 | n/a | field_just field_opts field_opts_off field_opts_on field_pad |
---|
80 | n/a | field_status field_term field_type field_userptr form_driver |
---|
81 | n/a | form_fields form_init form_opts form_opts_off form_opts_on |
---|
82 | n/a | form_page form_request_by_name form_request_name form_sub |
---|
83 | n/a | form_term form_userptr form_win free_field free_form |
---|
84 | n/a | link_field link_fieldtype move_field new_field new_form |
---|
85 | n/a | new_page pos_form_cursor post_form scale_form |
---|
86 | n/a | set_current_field set_field_back set_field_buffer |
---|
87 | n/a | set_field_fore set_field_init set_field_just set_field_opts |
---|
88 | n/a | set_field_pad set_field_status set_field_term set_field_type |
---|
89 | n/a | set_field_userptr set_fieldtype_arg set_fieldtype_choice |
---|
90 | n/a | set_form_fields set_form_init set_form_opts set_form_page |
---|
91 | n/a | set_form_sub set_form_term set_form_userptr set_form_win |
---|
92 | n/a | set_max_field set_new_page unpost_form |
---|
93 | n/a | |
---|
94 | n/a | |
---|
95 | n/a | */ |
---|
96 | n/a | |
---|
97 | n/a | /* Release Number */ |
---|
98 | n/a | |
---|
99 | n/a | char *PyCursesVersion = "2.2"; |
---|
100 | n/a | |
---|
101 | n/a | /* Includes */ |
---|
102 | n/a | |
---|
103 | n/a | #define PY_SSIZE_T_CLEAN |
---|
104 | n/a | |
---|
105 | n/a | #include "Python.h" |
---|
106 | n/a | |
---|
107 | n/a | |
---|
108 | n/a | #ifdef __hpux |
---|
109 | n/a | #define STRICT_SYSV_CURSES |
---|
110 | n/a | #endif |
---|
111 | n/a | |
---|
112 | n/a | #define CURSES_MODULE |
---|
113 | n/a | #include "py_curses.h" |
---|
114 | n/a | |
---|
115 | n/a | /* These prototypes are in <term.h>, but including this header |
---|
116 | n/a | #defines many common symbols (such as "lines") which breaks the |
---|
117 | n/a | curses module in other ways. So the code will just specify |
---|
118 | n/a | explicit prototypes here. */ |
---|
119 | n/a | extern int setupterm(char *,int,int *); |
---|
120 | n/a | #ifdef __sgi |
---|
121 | n/a | #include <term.h> |
---|
122 | n/a | #endif |
---|
123 | n/a | |
---|
124 | n/a | #ifdef HAVE_LANGINFO_H |
---|
125 | n/a | #include <langinfo.h> |
---|
126 | n/a | #endif |
---|
127 | n/a | |
---|
128 | n/a | #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5)) |
---|
129 | n/a | #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ |
---|
130 | n/a | typedef chtype attr_t; /* No attr_t type is available */ |
---|
131 | n/a | #endif |
---|
132 | n/a | |
---|
133 | n/a | #if defined(_AIX) |
---|
134 | n/a | #define STRICT_SYSV_CURSES |
---|
135 | n/a | #endif |
---|
136 | n/a | |
---|
137 | n/a | /*[clinic input] |
---|
138 | n/a | module curses |
---|
139 | n/a | class curses.window "PyCursesWindowObject *" "&PyCursesWindow_Type" |
---|
140 | n/a | [clinic start generated code]*/ |
---|
141 | n/a | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=88c860abdbb50e0c]*/ |
---|
142 | n/a | |
---|
143 | n/a | #include "clinic/_cursesmodule.c.h" |
---|
144 | n/a | |
---|
145 | n/a | /* Definition of exception curses.error */ |
---|
146 | n/a | |
---|
147 | n/a | static PyObject *PyCursesError; |
---|
148 | n/a | |
---|
149 | n/a | /* Tells whether setupterm() has been called to initialise terminfo. */ |
---|
150 | n/a | static int initialised_setupterm = FALSE; |
---|
151 | n/a | |
---|
152 | n/a | /* Tells whether initscr() has been called to initialise curses. */ |
---|
153 | n/a | static int initialised = FALSE; |
---|
154 | n/a | |
---|
155 | n/a | /* Tells whether start_color() has been called to initialise color usage. */ |
---|
156 | n/a | static int initialisedcolors = FALSE; |
---|
157 | n/a | |
---|
158 | n/a | static char *screen_encoding = NULL; |
---|
159 | n/a | |
---|
160 | n/a | /* Utility Macros */ |
---|
161 | n/a | #define PyCursesSetupTermCalled \ |
---|
162 | n/a | if (initialised_setupterm != TRUE) { \ |
---|
163 | n/a | PyErr_SetString(PyCursesError, \ |
---|
164 | n/a | "must call (at least) setupterm() first"); \ |
---|
165 | n/a | return 0; } |
---|
166 | n/a | |
---|
167 | n/a | #define PyCursesInitialised \ |
---|
168 | n/a | if (initialised != TRUE) { \ |
---|
169 | n/a | PyErr_SetString(PyCursesError, \ |
---|
170 | n/a | "must call initscr() first"); \ |
---|
171 | n/a | return 0; } |
---|
172 | n/a | |
---|
173 | n/a | #define PyCursesInitialisedColor \ |
---|
174 | n/a | if (initialisedcolors != TRUE) { \ |
---|
175 | n/a | PyErr_SetString(PyCursesError, \ |
---|
176 | n/a | "must call start_color() first"); \ |
---|
177 | n/a | return 0; } |
---|
178 | n/a | |
---|
179 | n/a | /* Utility Functions */ |
---|
180 | n/a | |
---|
181 | n/a | /* |
---|
182 | n/a | * Check the return code from a curses function and return None |
---|
183 | n/a | * or raise an exception as appropriate. These are exported using the |
---|
184 | n/a | * capsule API. |
---|
185 | n/a | */ |
---|
186 | n/a | |
---|
187 | n/a | static PyObject * |
---|
188 | n/a | PyCursesCheckERR(int code, const char *fname) |
---|
189 | n/a | { |
---|
190 | n/a | if (code != ERR) { |
---|
191 | n/a | Py_RETURN_NONE; |
---|
192 | n/a | } else { |
---|
193 | n/a | if (fname == NULL) { |
---|
194 | n/a | PyErr_SetString(PyCursesError, catchall_ERR); |
---|
195 | n/a | } else { |
---|
196 | n/a | PyErr_Format(PyCursesError, "%s() returned ERR", fname); |
---|
197 | n/a | } |
---|
198 | n/a | return NULL; |
---|
199 | n/a | } |
---|
200 | n/a | } |
---|
201 | n/a | |
---|
202 | n/a | /* Convert an object to a byte (an integer of type chtype): |
---|
203 | n/a | |
---|
204 | n/a | - int |
---|
205 | n/a | - bytes of length 1 |
---|
206 | n/a | - str of length 1 |
---|
207 | n/a | |
---|
208 | n/a | Return 1 on success, 0 on error (invalid type or integer overflow). */ |
---|
209 | n/a | static int |
---|
210 | n/a | PyCurses_ConvertToChtype(PyCursesWindowObject *win, PyObject *obj, chtype *ch) |
---|
211 | n/a | { |
---|
212 | n/a | long value; |
---|
213 | n/a | if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) { |
---|
214 | n/a | value = (unsigned char)PyBytes_AsString(obj)[0]; |
---|
215 | n/a | } |
---|
216 | n/a | else if (PyUnicode_Check(obj)) { |
---|
217 | n/a | if (PyUnicode_GetLength(obj) != 1) { |
---|
218 | n/a | PyErr_Format(PyExc_TypeError, |
---|
219 | n/a | "expect bytes or str of length 1, or int, " |
---|
220 | n/a | "got a str of length %zi", |
---|
221 | n/a | PyUnicode_GET_LENGTH(obj)); |
---|
222 | n/a | return 0; |
---|
223 | n/a | } |
---|
224 | n/a | value = PyUnicode_READ_CHAR(obj, 0); |
---|
225 | n/a | if (128 < value) { |
---|
226 | n/a | PyObject *bytes; |
---|
227 | n/a | const char *encoding; |
---|
228 | n/a | if (win) |
---|
229 | n/a | encoding = win->encoding; |
---|
230 | n/a | else |
---|
231 | n/a | encoding = screen_encoding; |
---|
232 | n/a | bytes = PyUnicode_AsEncodedString(obj, encoding, NULL); |
---|
233 | n/a | if (bytes == NULL) |
---|
234 | n/a | return 0; |
---|
235 | n/a | if (PyBytes_GET_SIZE(bytes) == 1) |
---|
236 | n/a | value = (unsigned char)PyBytes_AS_STRING(bytes)[0]; |
---|
237 | n/a | else |
---|
238 | n/a | value = -1; |
---|
239 | n/a | Py_DECREF(bytes); |
---|
240 | n/a | if (value < 0) |
---|
241 | n/a | goto overflow; |
---|
242 | n/a | } |
---|
243 | n/a | } |
---|
244 | n/a | else if (PyLong_CheckExact(obj)) { |
---|
245 | n/a | int long_overflow; |
---|
246 | n/a | value = PyLong_AsLongAndOverflow(obj, &long_overflow); |
---|
247 | n/a | if (long_overflow) |
---|
248 | n/a | goto overflow; |
---|
249 | n/a | } |
---|
250 | n/a | else { |
---|
251 | n/a | PyErr_Format(PyExc_TypeError, |
---|
252 | n/a | "expect bytes or str of length 1, or int, got %s", |
---|
253 | n/a | Py_TYPE(obj)->tp_name); |
---|
254 | n/a | return 0; |
---|
255 | n/a | } |
---|
256 | n/a | *ch = (chtype)value; |
---|
257 | n/a | if ((long)*ch != value) |
---|
258 | n/a | goto overflow; |
---|
259 | n/a | return 1; |
---|
260 | n/a | |
---|
261 | n/a | overflow: |
---|
262 | n/a | PyErr_SetString(PyExc_OverflowError, |
---|
263 | n/a | "byte doesn't fit in chtype"); |
---|
264 | n/a | return 0; |
---|
265 | n/a | } |
---|
266 | n/a | |
---|
267 | n/a | /* Convert an object to a byte (chtype) or a character (cchar_t): |
---|
268 | n/a | |
---|
269 | n/a | - int |
---|
270 | n/a | - bytes of length 1 |
---|
271 | n/a | - str of length 1 |
---|
272 | n/a | |
---|
273 | n/a | Return: |
---|
274 | n/a | |
---|
275 | n/a | - 2 if obj is a character (written into *wch) |
---|
276 | n/a | - 1 if obj is a byte (written into *ch) |
---|
277 | n/a | - 0 on error: raise an exception */ |
---|
278 | n/a | static int |
---|
279 | n/a | PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj, |
---|
280 | n/a | chtype *ch |
---|
281 | n/a | #ifdef HAVE_NCURSESW |
---|
282 | n/a | , wchar_t *wch |
---|
283 | n/a | #endif |
---|
284 | n/a | ) |
---|
285 | n/a | { |
---|
286 | n/a | long value; |
---|
287 | n/a | #ifdef HAVE_NCURSESW |
---|
288 | n/a | wchar_t buffer[2]; |
---|
289 | n/a | #endif |
---|
290 | n/a | |
---|
291 | n/a | if (PyUnicode_Check(obj)) { |
---|
292 | n/a | #ifdef HAVE_NCURSESW |
---|
293 | n/a | if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) { |
---|
294 | n/a | PyErr_Format(PyExc_TypeError, |
---|
295 | n/a | "expect bytes or str of length 1, or int, " |
---|
296 | n/a | "got a str of length %zi", |
---|
297 | n/a | PyUnicode_GET_LENGTH(obj)); |
---|
298 | n/a | return 0; |
---|
299 | n/a | } |
---|
300 | n/a | *wch = buffer[0]; |
---|
301 | n/a | return 2; |
---|
302 | n/a | #else |
---|
303 | n/a | return PyCurses_ConvertToChtype(win, obj, ch); |
---|
304 | n/a | #endif |
---|
305 | n/a | } |
---|
306 | n/a | else if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) { |
---|
307 | n/a | value = (unsigned char)PyBytes_AsString(obj)[0]; |
---|
308 | n/a | } |
---|
309 | n/a | else if (PyLong_CheckExact(obj)) { |
---|
310 | n/a | int overflow; |
---|
311 | n/a | value = PyLong_AsLongAndOverflow(obj, &overflow); |
---|
312 | n/a | if (overflow) { |
---|
313 | n/a | PyErr_SetString(PyExc_OverflowError, |
---|
314 | n/a | "int doesn't fit in long"); |
---|
315 | n/a | return 0; |
---|
316 | n/a | } |
---|
317 | n/a | } |
---|
318 | n/a | else { |
---|
319 | n/a | PyErr_Format(PyExc_TypeError, |
---|
320 | n/a | "expect bytes or str of length 1, or int, got %s", |
---|
321 | n/a | Py_TYPE(obj)->tp_name); |
---|
322 | n/a | return 0; |
---|
323 | n/a | } |
---|
324 | n/a | |
---|
325 | n/a | *ch = (chtype)value; |
---|
326 | n/a | if ((long)*ch != value) { |
---|
327 | n/a | PyErr_Format(PyExc_OverflowError, |
---|
328 | n/a | "byte doesn't fit in chtype"); |
---|
329 | n/a | return 0; |
---|
330 | n/a | } |
---|
331 | n/a | return 1; |
---|
332 | n/a | } |
---|
333 | n/a | |
---|
334 | n/a | /* Convert an object to a byte string (char*) or a wide character string |
---|
335 | n/a | (wchar_t*). Return: |
---|
336 | n/a | |
---|
337 | n/a | - 2 if obj is a character string (written into *wch) |
---|
338 | n/a | - 1 if obj is a byte string (written into *bytes) |
---|
339 | n/a | - 0 on error: raise an exception */ |
---|
340 | n/a | static int |
---|
341 | n/a | PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj, |
---|
342 | n/a | PyObject **bytes, wchar_t **wstr) |
---|
343 | n/a | { |
---|
344 | n/a | if (PyUnicode_Check(obj)) { |
---|
345 | n/a | #ifdef HAVE_NCURSESW |
---|
346 | n/a | assert (wstr != NULL); |
---|
347 | n/a | *wstr = PyUnicode_AsWideCharString(obj, NULL); |
---|
348 | n/a | if (*wstr == NULL) |
---|
349 | n/a | return 0; |
---|
350 | n/a | return 2; |
---|
351 | n/a | #else |
---|
352 | n/a | assert (wstr == NULL); |
---|
353 | n/a | *bytes = PyUnicode_AsEncodedString(obj, win->encoding, NULL); |
---|
354 | n/a | if (*bytes == NULL) |
---|
355 | n/a | return 0; |
---|
356 | n/a | return 1; |
---|
357 | n/a | #endif |
---|
358 | n/a | } |
---|
359 | n/a | else if (PyBytes_Check(obj)) { |
---|
360 | n/a | Py_INCREF(obj); |
---|
361 | n/a | *bytes = obj; |
---|
362 | n/a | return 1; |
---|
363 | n/a | } |
---|
364 | n/a | |
---|
365 | n/a | PyErr_Format(PyExc_TypeError, "expect bytes or str, got %s", |
---|
366 | n/a | Py_TYPE(obj)->tp_name); |
---|
367 | n/a | return 0; |
---|
368 | n/a | } |
---|
369 | n/a | |
---|
370 | n/a | /* Function versions of the 3 functions for testing whether curses has been |
---|
371 | n/a | initialised or not. */ |
---|
372 | n/a | |
---|
373 | n/a | static int func_PyCursesSetupTermCalled(void) |
---|
374 | n/a | { |
---|
375 | n/a | PyCursesSetupTermCalled; |
---|
376 | n/a | return 1; |
---|
377 | n/a | } |
---|
378 | n/a | |
---|
379 | n/a | static int func_PyCursesInitialised(void) |
---|
380 | n/a | { |
---|
381 | n/a | PyCursesInitialised; |
---|
382 | n/a | return 1; |
---|
383 | n/a | } |
---|
384 | n/a | |
---|
385 | n/a | static int func_PyCursesInitialisedColor(void) |
---|
386 | n/a | { |
---|
387 | n/a | PyCursesInitialisedColor; |
---|
388 | n/a | return 1; |
---|
389 | n/a | } |
---|
390 | n/a | |
---|
391 | n/a | /***************************************************************************** |
---|
392 | n/a | The Window Object |
---|
393 | n/a | ******************************************************************************/ |
---|
394 | n/a | |
---|
395 | n/a | /* Definition of the window type */ |
---|
396 | n/a | |
---|
397 | n/a | PyTypeObject PyCursesWindow_Type; |
---|
398 | n/a | |
---|
399 | n/a | /* Function prototype macros for Window object |
---|
400 | n/a | |
---|
401 | n/a | X - function name |
---|
402 | n/a | TYPE - parameter Type |
---|
403 | n/a | ERGSTR - format string for construction of the return value |
---|
404 | n/a | PARSESTR - format string for argument parsing |
---|
405 | n/a | */ |
---|
406 | n/a | |
---|
407 | n/a | #define Window_NoArgNoReturnFunction(X) \ |
---|
408 | n/a | static PyObject *PyCursesWindow_ ## X \ |
---|
409 | n/a | (PyCursesWindowObject *self, PyObject *args) \ |
---|
410 | n/a | { return PyCursesCheckERR(X(self->win), # X); } |
---|
411 | n/a | |
---|
412 | n/a | #define Window_NoArgTrueFalseFunction(X) \ |
---|
413 | n/a | static PyObject * PyCursesWindow_ ## X \ |
---|
414 | n/a | (PyCursesWindowObject *self) \ |
---|
415 | n/a | { \ |
---|
416 | n/a | if (X (self->win) == FALSE) { Py_RETURN_FALSE; } \ |
---|
417 | n/a | else { Py_RETURN_TRUE; } } |
---|
418 | n/a | |
---|
419 | n/a | #define Window_NoArgNoReturnVoidFunction(X) \ |
---|
420 | n/a | static PyObject * PyCursesWindow_ ## X \ |
---|
421 | n/a | (PyCursesWindowObject *self) \ |
---|
422 | n/a | { \ |
---|
423 | n/a | X(self->win); Py_RETURN_NONE; } |
---|
424 | n/a | |
---|
425 | n/a | #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \ |
---|
426 | n/a | static PyObject * PyCursesWindow_ ## X \ |
---|
427 | n/a | (PyCursesWindowObject *self) \ |
---|
428 | n/a | { \ |
---|
429 | n/a | TYPE arg1, arg2; \ |
---|
430 | n/a | X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); } |
---|
431 | n/a | |
---|
432 | n/a | #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \ |
---|
433 | n/a | static PyObject * PyCursesWindow_ ## X \ |
---|
434 | n/a | (PyCursesWindowObject *self, PyObject *args) \ |
---|
435 | n/a | { \ |
---|
436 | n/a | TYPE arg1; \ |
---|
437 | n/a | if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \ |
---|
438 | n/a | X(self->win,arg1); Py_RETURN_NONE; } |
---|
439 | n/a | |
---|
440 | n/a | #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \ |
---|
441 | n/a | static PyObject * PyCursesWindow_ ## X \ |
---|
442 | n/a | (PyCursesWindowObject *self, PyObject *args) \ |
---|
443 | n/a | { \ |
---|
444 | n/a | TYPE arg1; \ |
---|
445 | n/a | if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \ |
---|
446 | n/a | return PyCursesCheckERR(X(self->win, arg1), # X); } |
---|
447 | n/a | |
---|
448 | n/a | #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \ |
---|
449 | n/a | static PyObject * PyCursesWindow_ ## X \ |
---|
450 | n/a | (PyCursesWindowObject *self, PyObject *args) \ |
---|
451 | n/a | { \ |
---|
452 | n/a | TYPE arg1, arg2; \ |
---|
453 | n/a | if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \ |
---|
454 | n/a | return PyCursesCheckERR(X(self->win, arg1, arg2), # X); } |
---|
455 | n/a | |
---|
456 | n/a | /* ------------- WINDOW routines --------------- */ |
---|
457 | n/a | |
---|
458 | n/a | Window_NoArgNoReturnFunction(untouchwin) |
---|
459 | n/a | Window_NoArgNoReturnFunction(touchwin) |
---|
460 | n/a | Window_NoArgNoReturnFunction(redrawwin) |
---|
461 | n/a | Window_NoArgNoReturnFunction(winsertln) |
---|
462 | n/a | Window_NoArgNoReturnFunction(werase) |
---|
463 | n/a | Window_NoArgNoReturnFunction(wdeleteln) |
---|
464 | n/a | |
---|
465 | n/a | Window_NoArgTrueFalseFunction(is_wintouched) |
---|
466 | n/a | |
---|
467 | n/a | Window_NoArgNoReturnVoidFunction(wsyncup) |
---|
468 | n/a | Window_NoArgNoReturnVoidFunction(wsyncdown) |
---|
469 | n/a | Window_NoArgNoReturnVoidFunction(wstandend) |
---|
470 | n/a | Window_NoArgNoReturnVoidFunction(wstandout) |
---|
471 | n/a | Window_NoArgNoReturnVoidFunction(wcursyncup) |
---|
472 | n/a | Window_NoArgNoReturnVoidFunction(wclrtoeol) |
---|
473 | n/a | Window_NoArgNoReturnVoidFunction(wclrtobot) |
---|
474 | n/a | Window_NoArgNoReturnVoidFunction(wclear) |
---|
475 | n/a | |
---|
476 | n/a | Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)") |
---|
477 | n/a | Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)") |
---|
478 | n/a | Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay") |
---|
479 | n/a | |
---|
480 | n/a | Window_NoArg2TupleReturnFunction(getyx, int, "ii") |
---|
481 | n/a | Window_NoArg2TupleReturnFunction(getbegyx, int, "ii") |
---|
482 | n/a | Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii") |
---|
483 | n/a | Window_NoArg2TupleReturnFunction(getparyx, int, "ii") |
---|
484 | n/a | |
---|
485 | n/a | Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)") |
---|
486 | n/a | Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)") |
---|
487 | n/a | #if defined(__NetBSD__) |
---|
488 | n/a | Window_OneArgNoReturnVoidFunction(keypad, int, "i;True(1) or False(0)") |
---|
489 | n/a | #else |
---|
490 | n/a | Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)") |
---|
491 | n/a | #endif |
---|
492 | n/a | Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)") |
---|
493 | n/a | #if defined(__NetBSD__) |
---|
494 | n/a | Window_OneArgNoReturnVoidFunction(nodelay, int, "i;True(1) or False(0)") |
---|
495 | n/a | #else |
---|
496 | n/a | Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)") |
---|
497 | n/a | #endif |
---|
498 | n/a | Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)") |
---|
499 | n/a | Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)") |
---|
500 | n/a | Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines") |
---|
501 | n/a | Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)") |
---|
502 | n/a | |
---|
503 | n/a | Window_TwoArgNoReturnFunction(mvwin, int, "ii;y,x") |
---|
504 | n/a | Window_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x") |
---|
505 | n/a | Window_TwoArgNoReturnFunction(wmove, int, "ii;y,x") |
---|
506 | n/a | #ifndef STRICT_SYSV_CURSES |
---|
507 | n/a | Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns") |
---|
508 | n/a | #endif |
---|
509 | n/a | |
---|
510 | n/a | /* Allocation and deallocation of Window Objects */ |
---|
511 | n/a | |
---|
512 | n/a | static PyObject * |
---|
513 | n/a | PyCursesWindow_New(WINDOW *win, const char *encoding) |
---|
514 | n/a | { |
---|
515 | n/a | PyCursesWindowObject *wo; |
---|
516 | n/a | |
---|
517 | n/a | if (encoding == NULL) { |
---|
518 | n/a | #if defined(MS_WINDOWS) |
---|
519 | n/a | char *buffer[100]; |
---|
520 | n/a | UINT cp; |
---|
521 | n/a | cp = GetConsoleOutputCP(); |
---|
522 | n/a | if (cp != 0) { |
---|
523 | n/a | PyOS_snprintf(buffer, sizeof(buffer), "cp%u", cp); |
---|
524 | n/a | encoding = buffer; |
---|
525 | n/a | } |
---|
526 | n/a | #elif defined(CODESET) |
---|
527 | n/a | const char *codeset = nl_langinfo(CODESET); |
---|
528 | n/a | if (codeset != NULL && codeset[0] != 0) |
---|
529 | n/a | encoding = codeset; |
---|
530 | n/a | #endif |
---|
531 | n/a | if (encoding == NULL) |
---|
532 | n/a | encoding = "utf-8"; |
---|
533 | n/a | } |
---|
534 | n/a | |
---|
535 | n/a | wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type); |
---|
536 | n/a | if (wo == NULL) return NULL; |
---|
537 | n/a | wo->win = win; |
---|
538 | n/a | wo->encoding = _PyMem_Strdup(encoding); |
---|
539 | n/a | if (wo->encoding == NULL) { |
---|
540 | n/a | Py_DECREF(wo); |
---|
541 | n/a | PyErr_NoMemory(); |
---|
542 | n/a | return NULL; |
---|
543 | n/a | } |
---|
544 | n/a | return (PyObject *)wo; |
---|
545 | n/a | } |
---|
546 | n/a | |
---|
547 | n/a | static void |
---|
548 | n/a | PyCursesWindow_Dealloc(PyCursesWindowObject *wo) |
---|
549 | n/a | { |
---|
550 | n/a | if (wo->win != stdscr) delwin(wo->win); |
---|
551 | n/a | if (wo->encoding != NULL) |
---|
552 | n/a | PyMem_Free(wo->encoding); |
---|
553 | n/a | PyObject_DEL(wo); |
---|
554 | n/a | } |
---|
555 | n/a | |
---|
556 | n/a | /* Addch, Addstr, Addnstr */ |
---|
557 | n/a | |
---|
558 | n/a | /*[clinic input] |
---|
559 | n/a | |
---|
560 | n/a | curses.window.addch |
---|
561 | n/a | |
---|
562 | n/a | [ |
---|
563 | n/a | y: int |
---|
564 | n/a | Y-coordinate. |
---|
565 | n/a | x: int |
---|
566 | n/a | X-coordinate. |
---|
567 | n/a | ] |
---|
568 | n/a | |
---|
569 | n/a | ch: object |
---|
570 | n/a | Character to add. |
---|
571 | n/a | |
---|
572 | n/a | [ |
---|
573 | n/a | attr: long |
---|
574 | n/a | Attributes for the character. |
---|
575 | n/a | ] |
---|
576 | n/a | / |
---|
577 | n/a | |
---|
578 | n/a | Paint character ch at (y, x) with attributes attr. |
---|
579 | n/a | |
---|
580 | n/a | Paint character ch at (y, x) with attributes attr, |
---|
581 | n/a | overwriting any character previously painted at that location. |
---|
582 | n/a | By default, the character position and attributes are the |
---|
583 | n/a | current settings for the window object. |
---|
584 | n/a | [clinic start generated code]*/ |
---|
585 | n/a | |
---|
586 | n/a | static PyObject * |
---|
587 | n/a | curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, |
---|
588 | n/a | int x, PyObject *ch, int group_right_1, long attr) |
---|
589 | n/a | /*[clinic end generated code: output=99f7f85078ec06c3 input=5a41efb34a2de338]*/ |
---|
590 | n/a | { |
---|
591 | n/a | PyCursesWindowObject *cwself = (PyCursesWindowObject *)self; |
---|
592 | n/a | int coordinates_group = group_left_1; |
---|
593 | n/a | int attr_group = group_right_1; |
---|
594 | n/a | int rtn; |
---|
595 | n/a | int type; |
---|
596 | n/a | chtype cch = 0; |
---|
597 | n/a | #ifdef HAVE_NCURSESW |
---|
598 | n/a | wchar_t wstr[2]; |
---|
599 | n/a | cchar_t wcval; |
---|
600 | n/a | #endif |
---|
601 | n/a | const char *funcname; |
---|
602 | n/a | |
---|
603 | n/a | if (!attr_group) |
---|
604 | n/a | attr = A_NORMAL; |
---|
605 | n/a | |
---|
606 | n/a | #ifdef HAVE_NCURSESW |
---|
607 | n/a | type = PyCurses_ConvertToCchar_t(cwself, ch, &cch, wstr); |
---|
608 | n/a | if (type == 2) { |
---|
609 | n/a | funcname = "add_wch"; |
---|
610 | n/a | wstr[1] = L'\0'; |
---|
611 | n/a | setcchar(&wcval, wstr, attr, 0, NULL); |
---|
612 | n/a | if (coordinates_group) |
---|
613 | n/a | rtn = mvwadd_wch(cwself->win,y,x, &wcval); |
---|
614 | n/a | else { |
---|
615 | n/a | rtn = wadd_wch(cwself->win, &wcval); |
---|
616 | n/a | } |
---|
617 | n/a | } |
---|
618 | n/a | else |
---|
619 | n/a | #else |
---|
620 | n/a | type = PyCurses_ConvertToCchar_t(cwself, ch, &cch); |
---|
621 | n/a | #endif |
---|
622 | n/a | if (type == 1) { |
---|
623 | n/a | funcname = "addch"; |
---|
624 | n/a | if (coordinates_group) |
---|
625 | n/a | rtn = mvwaddch(cwself->win,y,x, cch | attr); |
---|
626 | n/a | else { |
---|
627 | n/a | rtn = waddch(cwself->win, cch | attr); |
---|
628 | n/a | } |
---|
629 | n/a | } |
---|
630 | n/a | else { |
---|
631 | n/a | return NULL; |
---|
632 | n/a | } |
---|
633 | n/a | return PyCursesCheckERR(rtn, funcname); |
---|
634 | n/a | } |
---|
635 | n/a | |
---|
636 | n/a | static PyObject * |
---|
637 | n/a | PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args) |
---|
638 | n/a | { |
---|
639 | n/a | int rtn; |
---|
640 | n/a | int x, y; |
---|
641 | n/a | int strtype; |
---|
642 | n/a | PyObject *strobj, *bytesobj = NULL; |
---|
643 | n/a | #ifdef HAVE_NCURSESW |
---|
644 | n/a | wchar_t *wstr = NULL; |
---|
645 | n/a | #endif |
---|
646 | n/a | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
---|
647 | n/a | long lattr; |
---|
648 | n/a | int use_xy = FALSE, use_attr = FALSE; |
---|
649 | n/a | const char *funcname; |
---|
650 | n/a | |
---|
651 | n/a | switch (PyTuple_Size(args)) { |
---|
652 | n/a | case 1: |
---|
653 | n/a | if (!PyArg_ParseTuple(args,"O;str", &strobj)) |
---|
654 | n/a | return NULL; |
---|
655 | n/a | break; |
---|
656 | n/a | case 2: |
---|
657 | n/a | if (!PyArg_ParseTuple(args,"Ol;str,attr", &strobj, &lattr)) |
---|
658 | n/a | return NULL; |
---|
659 | n/a | attr = lattr; |
---|
660 | n/a | use_attr = TRUE; |
---|
661 | n/a | break; |
---|
662 | n/a | case 3: |
---|
663 | n/a | if (!PyArg_ParseTuple(args,"iiO;int,int,str", &y, &x, &strobj)) |
---|
664 | n/a | return NULL; |
---|
665 | n/a | use_xy = TRUE; |
---|
666 | n/a | break; |
---|
667 | n/a | case 4: |
---|
668 | n/a | if (!PyArg_ParseTuple(args,"iiOl;int,int,str,attr", &y, &x, &strobj, &lattr)) |
---|
669 | n/a | return NULL; |
---|
670 | n/a | attr = lattr; |
---|
671 | n/a | use_xy = use_attr = TRUE; |
---|
672 | n/a | break; |
---|
673 | n/a | default: |
---|
674 | n/a | PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments"); |
---|
675 | n/a | return NULL; |
---|
676 | n/a | } |
---|
677 | n/a | #ifdef HAVE_NCURSESW |
---|
678 | n/a | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); |
---|
679 | n/a | #else |
---|
680 | n/a | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); |
---|
681 | n/a | #endif |
---|
682 | n/a | if (strtype == 0) |
---|
683 | n/a | return NULL; |
---|
684 | n/a | if (use_attr == TRUE) { |
---|
685 | n/a | attr_old = getattrs(self->win); |
---|
686 | n/a | (void)wattrset(self->win,attr); |
---|
687 | n/a | } |
---|
688 | n/a | #ifdef HAVE_NCURSESW |
---|
689 | n/a | if (strtype == 2) { |
---|
690 | n/a | funcname = "addwstr"; |
---|
691 | n/a | if (use_xy == TRUE) |
---|
692 | n/a | rtn = mvwaddwstr(self->win,y,x,wstr); |
---|
693 | n/a | else |
---|
694 | n/a | rtn = waddwstr(self->win,wstr); |
---|
695 | n/a | PyMem_Free(wstr); |
---|
696 | n/a | } |
---|
697 | n/a | else |
---|
698 | n/a | #endif |
---|
699 | n/a | { |
---|
700 | n/a | char *str = PyBytes_AS_STRING(bytesobj); |
---|
701 | n/a | funcname = "addstr"; |
---|
702 | n/a | if (use_xy == TRUE) |
---|
703 | n/a | rtn = mvwaddstr(self->win,y,x,str); |
---|
704 | n/a | else |
---|
705 | n/a | rtn = waddstr(self->win,str); |
---|
706 | n/a | Py_DECREF(bytesobj); |
---|
707 | n/a | } |
---|
708 | n/a | if (use_attr == TRUE) |
---|
709 | n/a | (void)wattrset(self->win,attr_old); |
---|
710 | n/a | return PyCursesCheckERR(rtn, funcname); |
---|
711 | n/a | } |
---|
712 | n/a | |
---|
713 | n/a | static PyObject * |
---|
714 | n/a | PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args) |
---|
715 | n/a | { |
---|
716 | n/a | int rtn, x, y, n; |
---|
717 | n/a | int strtype; |
---|
718 | n/a | PyObject *strobj, *bytesobj = NULL; |
---|
719 | n/a | #ifdef HAVE_NCURSESW |
---|
720 | n/a | wchar_t *wstr = NULL; |
---|
721 | n/a | #endif |
---|
722 | n/a | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
---|
723 | n/a | long lattr; |
---|
724 | n/a | int use_xy = FALSE, use_attr = FALSE; |
---|
725 | n/a | const char *funcname; |
---|
726 | n/a | |
---|
727 | n/a | switch (PyTuple_Size(args)) { |
---|
728 | n/a | case 2: |
---|
729 | n/a | if (!PyArg_ParseTuple(args,"Oi;str,n", &strobj, &n)) |
---|
730 | n/a | return NULL; |
---|
731 | n/a | break; |
---|
732 | n/a | case 3: |
---|
733 | n/a | if (!PyArg_ParseTuple(args,"Oil;str,n,attr", &strobj, &n, &lattr)) |
---|
734 | n/a | return NULL; |
---|
735 | n/a | attr = lattr; |
---|
736 | n/a | use_attr = TRUE; |
---|
737 | n/a | break; |
---|
738 | n/a | case 4: |
---|
739 | n/a | if (!PyArg_ParseTuple(args,"iiOi;y,x,str,n", &y, &x, &strobj, &n)) |
---|
740 | n/a | return NULL; |
---|
741 | n/a | use_xy = TRUE; |
---|
742 | n/a | break; |
---|
743 | n/a | case 5: |
---|
744 | n/a | if (!PyArg_ParseTuple(args,"iiOil;y,x,str,n,attr", &y, &x, &strobj, &n, &lattr)) |
---|
745 | n/a | return NULL; |
---|
746 | n/a | attr = lattr; |
---|
747 | n/a | use_xy = use_attr = TRUE; |
---|
748 | n/a | break; |
---|
749 | n/a | default: |
---|
750 | n/a | PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments"); |
---|
751 | n/a | return NULL; |
---|
752 | n/a | } |
---|
753 | n/a | #ifdef HAVE_NCURSESW |
---|
754 | n/a | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); |
---|
755 | n/a | #else |
---|
756 | n/a | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); |
---|
757 | n/a | #endif |
---|
758 | n/a | if (strtype == 0) |
---|
759 | n/a | return NULL; |
---|
760 | n/a | |
---|
761 | n/a | if (use_attr == TRUE) { |
---|
762 | n/a | attr_old = getattrs(self->win); |
---|
763 | n/a | (void)wattrset(self->win,attr); |
---|
764 | n/a | } |
---|
765 | n/a | #ifdef HAVE_NCURSESW |
---|
766 | n/a | if (strtype == 2) { |
---|
767 | n/a | funcname = "addnwstr"; |
---|
768 | n/a | if (use_xy == TRUE) |
---|
769 | n/a | rtn = mvwaddnwstr(self->win,y,x,wstr,n); |
---|
770 | n/a | else |
---|
771 | n/a | rtn = waddnwstr(self->win,wstr,n); |
---|
772 | n/a | PyMem_Free(wstr); |
---|
773 | n/a | } |
---|
774 | n/a | else |
---|
775 | n/a | #endif |
---|
776 | n/a | { |
---|
777 | n/a | char *str = PyBytes_AS_STRING(bytesobj); |
---|
778 | n/a | funcname = "addnstr"; |
---|
779 | n/a | if (use_xy == TRUE) |
---|
780 | n/a | rtn = mvwaddnstr(self->win,y,x,str,n); |
---|
781 | n/a | else |
---|
782 | n/a | rtn = waddnstr(self->win,str,n); |
---|
783 | n/a | Py_DECREF(bytesobj); |
---|
784 | n/a | } |
---|
785 | n/a | if (use_attr == TRUE) |
---|
786 | n/a | (void)wattrset(self->win,attr_old); |
---|
787 | n/a | return PyCursesCheckERR(rtn, funcname); |
---|
788 | n/a | } |
---|
789 | n/a | |
---|
790 | n/a | static PyObject * |
---|
791 | n/a | PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args) |
---|
792 | n/a | { |
---|
793 | n/a | PyObject *temp; |
---|
794 | n/a | chtype bkgd; |
---|
795 | n/a | attr_t attr = A_NORMAL; |
---|
796 | n/a | long lattr; |
---|
797 | n/a | |
---|
798 | n/a | switch (PyTuple_Size(args)) { |
---|
799 | n/a | case 1: |
---|
800 | n/a | if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) |
---|
801 | n/a | return NULL; |
---|
802 | n/a | break; |
---|
803 | n/a | case 2: |
---|
804 | n/a | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) |
---|
805 | n/a | return NULL; |
---|
806 | n/a | attr = lattr; |
---|
807 | n/a | break; |
---|
808 | n/a | default: |
---|
809 | n/a | PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments"); |
---|
810 | n/a | return NULL; |
---|
811 | n/a | } |
---|
812 | n/a | |
---|
813 | n/a | if (!PyCurses_ConvertToChtype(self, temp, &bkgd)) |
---|
814 | n/a | return NULL; |
---|
815 | n/a | |
---|
816 | n/a | return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd"); |
---|
817 | n/a | } |
---|
818 | n/a | |
---|
819 | n/a | static PyObject * |
---|
820 | n/a | PyCursesWindow_AttrOff(PyCursesWindowObject *self, PyObject *args) |
---|
821 | n/a | { |
---|
822 | n/a | long lattr; |
---|
823 | n/a | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) |
---|
824 | n/a | return NULL; |
---|
825 | n/a | return PyCursesCheckERR(wattroff(self->win, (attr_t)lattr), "attroff"); |
---|
826 | n/a | } |
---|
827 | n/a | |
---|
828 | n/a | static PyObject * |
---|
829 | n/a | PyCursesWindow_AttrOn(PyCursesWindowObject *self, PyObject *args) |
---|
830 | n/a | { |
---|
831 | n/a | long lattr; |
---|
832 | n/a | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) |
---|
833 | n/a | return NULL; |
---|
834 | n/a | return PyCursesCheckERR(wattron(self->win, (attr_t)lattr), "attron"); |
---|
835 | n/a | } |
---|
836 | n/a | |
---|
837 | n/a | static PyObject * |
---|
838 | n/a | PyCursesWindow_AttrSet(PyCursesWindowObject *self, PyObject *args) |
---|
839 | n/a | { |
---|
840 | n/a | long lattr; |
---|
841 | n/a | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) |
---|
842 | n/a | return NULL; |
---|
843 | n/a | return PyCursesCheckERR(wattrset(self->win, (attr_t)lattr), "attrset"); |
---|
844 | n/a | } |
---|
845 | n/a | |
---|
846 | n/a | static PyObject * |
---|
847 | n/a | PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args) |
---|
848 | n/a | { |
---|
849 | n/a | PyObject *temp; |
---|
850 | n/a | chtype bkgd; |
---|
851 | n/a | attr_t attr = A_NORMAL; |
---|
852 | n/a | long lattr; |
---|
853 | n/a | |
---|
854 | n/a | switch (PyTuple_Size(args)) { |
---|
855 | n/a | case 1: |
---|
856 | n/a | if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) |
---|
857 | n/a | return NULL; |
---|
858 | n/a | break; |
---|
859 | n/a | case 2: |
---|
860 | n/a | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) |
---|
861 | n/a | return NULL; |
---|
862 | n/a | attr = lattr; |
---|
863 | n/a | break; |
---|
864 | n/a | default: |
---|
865 | n/a | PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments"); |
---|
866 | n/a | return NULL; |
---|
867 | n/a | } |
---|
868 | n/a | |
---|
869 | n/a | if (!PyCurses_ConvertToChtype(self, temp, &bkgd)) |
---|
870 | n/a | return NULL; |
---|
871 | n/a | |
---|
872 | n/a | wbkgdset(self->win, bkgd | attr); |
---|
873 | n/a | return PyCursesCheckERR(0, "bkgdset"); |
---|
874 | n/a | } |
---|
875 | n/a | |
---|
876 | n/a | static PyObject * |
---|
877 | n/a | PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args) |
---|
878 | n/a | { |
---|
879 | n/a | PyObject *temp[8]; |
---|
880 | n/a | chtype ch[8]; |
---|
881 | n/a | int i; |
---|
882 | n/a | |
---|
883 | n/a | /* Clear the array of parameters */ |
---|
884 | n/a | for(i=0; i<8; i++) { |
---|
885 | n/a | temp[i] = NULL; |
---|
886 | n/a | ch[i] = 0; |
---|
887 | n/a | } |
---|
888 | n/a | |
---|
889 | n/a | if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br", |
---|
890 | n/a | &temp[0], &temp[1], &temp[2], &temp[3], |
---|
891 | n/a | &temp[4], &temp[5], &temp[6], &temp[7])) |
---|
892 | n/a | return NULL; |
---|
893 | n/a | |
---|
894 | n/a | for(i=0; i<8; i++) { |
---|
895 | n/a | if (temp[i] != NULL && !PyCurses_ConvertToChtype(self, temp[i], &ch[i])) |
---|
896 | n/a | return NULL; |
---|
897 | n/a | } |
---|
898 | n/a | |
---|
899 | n/a | wborder(self->win, |
---|
900 | n/a | ch[0], ch[1], ch[2], ch[3], |
---|
901 | n/a | ch[4], ch[5], ch[6], ch[7]); |
---|
902 | n/a | Py_RETURN_NONE; |
---|
903 | n/a | } |
---|
904 | n/a | |
---|
905 | n/a | static PyObject * |
---|
906 | n/a | PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args) |
---|
907 | n/a | { |
---|
908 | n/a | chtype ch1=0,ch2=0; |
---|
909 | n/a | switch(PyTuple_Size(args)){ |
---|
910 | n/a | case 0: break; |
---|
911 | n/a | default: |
---|
912 | n/a | if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2)) |
---|
913 | n/a | return NULL; |
---|
914 | n/a | } |
---|
915 | n/a | box(self->win,ch1,ch2); |
---|
916 | n/a | Py_RETURN_NONE; |
---|
917 | n/a | } |
---|
918 | n/a | |
---|
919 | n/a | #if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION) |
---|
920 | n/a | #define py_mvwdelch mvwdelch |
---|
921 | n/a | #else |
---|
922 | n/a | int py_mvwdelch(WINDOW *w, int y, int x) |
---|
923 | n/a | { |
---|
924 | n/a | mvwdelch(w,y,x); |
---|
925 | n/a | /* On HP/UX, mvwdelch already returns. On other systems, |
---|
926 | n/a | we may well run into this return statement. */ |
---|
927 | n/a | return 0; |
---|
928 | n/a | } |
---|
929 | n/a | #endif |
---|
930 | n/a | |
---|
931 | n/a | /* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */ |
---|
932 | n/a | |
---|
933 | n/a | static PyObject * |
---|
934 | n/a | PyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args) |
---|
935 | n/a | { |
---|
936 | n/a | int rtn; |
---|
937 | n/a | int x, y; |
---|
938 | n/a | int num = -1; |
---|
939 | n/a | short color; |
---|
940 | n/a | attr_t attr = A_NORMAL; |
---|
941 | n/a | long lattr; |
---|
942 | n/a | int use_xy = FALSE; |
---|
943 | n/a | |
---|
944 | n/a | switch (PyTuple_Size(args)) { |
---|
945 | n/a | case 1: |
---|
946 | n/a | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) |
---|
947 | n/a | return NULL; |
---|
948 | n/a | attr = lattr; |
---|
949 | n/a | break; |
---|
950 | n/a | case 2: |
---|
951 | n/a | if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr)) |
---|
952 | n/a | return NULL; |
---|
953 | n/a | attr = lattr; |
---|
954 | n/a | break; |
---|
955 | n/a | case 3: |
---|
956 | n/a | if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr)) |
---|
957 | n/a | return NULL; |
---|
958 | n/a | attr = lattr; |
---|
959 | n/a | use_xy = TRUE; |
---|
960 | n/a | break; |
---|
961 | n/a | case 4: |
---|
962 | n/a | if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr)) |
---|
963 | n/a | return NULL; |
---|
964 | n/a | attr = lattr; |
---|
965 | n/a | use_xy = TRUE; |
---|
966 | n/a | break; |
---|
967 | n/a | default: |
---|
968 | n/a | PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments"); |
---|
969 | n/a | return NULL; |
---|
970 | n/a | } |
---|
971 | n/a | |
---|
972 | n/a | color = (short)((attr >> 8) & 0xff); |
---|
973 | n/a | attr = attr - (color << 8); |
---|
974 | n/a | |
---|
975 | n/a | if (use_xy == TRUE) { |
---|
976 | n/a | rtn = mvwchgat(self->win,y,x,num,attr,color,NULL); |
---|
977 | n/a | touchline(self->win,y,1); |
---|
978 | n/a | } else { |
---|
979 | n/a | getyx(self->win,y,x); |
---|
980 | n/a | rtn = wchgat(self->win,num,attr,color,NULL); |
---|
981 | n/a | touchline(self->win,y,1); |
---|
982 | n/a | } |
---|
983 | n/a | return PyCursesCheckERR(rtn, "chgat"); |
---|
984 | n/a | } |
---|
985 | n/a | |
---|
986 | n/a | |
---|
987 | n/a | static PyObject * |
---|
988 | n/a | PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args) |
---|
989 | n/a | { |
---|
990 | n/a | int rtn; |
---|
991 | n/a | int x, y; |
---|
992 | n/a | |
---|
993 | n/a | switch (PyTuple_Size(args)) { |
---|
994 | n/a | case 0: |
---|
995 | n/a | rtn = wdelch(self->win); |
---|
996 | n/a | break; |
---|
997 | n/a | case 2: |
---|
998 | n/a | if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x)) |
---|
999 | n/a | return NULL; |
---|
1000 | n/a | rtn = py_mvwdelch(self->win,y,x); |
---|
1001 | n/a | break; |
---|
1002 | n/a | default: |
---|
1003 | n/a | PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments"); |
---|
1004 | n/a | return NULL; |
---|
1005 | n/a | } |
---|
1006 | n/a | return PyCursesCheckERR(rtn, "[mv]wdelch"); |
---|
1007 | n/a | } |
---|
1008 | n/a | |
---|
1009 | n/a | static PyObject * |
---|
1010 | n/a | PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args) |
---|
1011 | n/a | { |
---|
1012 | n/a | WINDOW *win; |
---|
1013 | n/a | int nlines, ncols, begin_y, begin_x; |
---|
1014 | n/a | |
---|
1015 | n/a | nlines = 0; |
---|
1016 | n/a | ncols = 0; |
---|
1017 | n/a | switch (PyTuple_Size(args)) { |
---|
1018 | n/a | case 2: |
---|
1019 | n/a | if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x)) |
---|
1020 | n/a | return NULL; |
---|
1021 | n/a | break; |
---|
1022 | n/a | case 4: |
---|
1023 | n/a | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", |
---|
1024 | n/a | &nlines,&ncols,&begin_y,&begin_x)) |
---|
1025 | n/a | return NULL; |
---|
1026 | n/a | break; |
---|
1027 | n/a | default: |
---|
1028 | n/a | PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments"); |
---|
1029 | n/a | return NULL; |
---|
1030 | n/a | } |
---|
1031 | n/a | |
---|
1032 | n/a | win = derwin(self->win,nlines,ncols,begin_y,begin_x); |
---|
1033 | n/a | |
---|
1034 | n/a | if (win == NULL) { |
---|
1035 | n/a | PyErr_SetString(PyCursesError, catchall_NULL); |
---|
1036 | n/a | return NULL; |
---|
1037 | n/a | } |
---|
1038 | n/a | |
---|
1039 | n/a | return (PyObject *)PyCursesWindow_New(win, NULL); |
---|
1040 | n/a | } |
---|
1041 | n/a | |
---|
1042 | n/a | static PyObject * |
---|
1043 | n/a | PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args) |
---|
1044 | n/a | { |
---|
1045 | n/a | PyObject *temp; |
---|
1046 | n/a | chtype ch; |
---|
1047 | n/a | attr_t attr = A_NORMAL; |
---|
1048 | n/a | long lattr; |
---|
1049 | n/a | |
---|
1050 | n/a | switch (PyTuple_Size(args)) { |
---|
1051 | n/a | case 1: |
---|
1052 | n/a | if (!PyArg_ParseTuple(args,"O;ch or int", &temp)) |
---|
1053 | n/a | return NULL; |
---|
1054 | n/a | break; |
---|
1055 | n/a | case 2: |
---|
1056 | n/a | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) |
---|
1057 | n/a | return NULL; |
---|
1058 | n/a | attr = lattr; |
---|
1059 | n/a | break; |
---|
1060 | n/a | default: |
---|
1061 | n/a | PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments"); |
---|
1062 | n/a | |
---|
1063 | n/a | |
---|
1064 | n/a | return NULL; |
---|
1065 | n/a | } |
---|
1066 | n/a | |
---|
1067 | n/a | if (!PyCurses_ConvertToChtype(self, temp, &ch)) |
---|
1068 | n/a | return NULL; |
---|
1069 | n/a | |
---|
1070 | n/a | #ifdef WINDOW_HAS_FLAGS |
---|
1071 | n/a | if (self->win->_flags & _ISPAD) |
---|
1072 | n/a | return PyCursesCheckERR(pechochar(self->win, ch | attr), |
---|
1073 | n/a | "echochar"); |
---|
1074 | n/a | else |
---|
1075 | n/a | #endif |
---|
1076 | n/a | return PyCursesCheckERR(wechochar(self->win, ch | attr), |
---|
1077 | n/a | "echochar"); |
---|
1078 | n/a | } |
---|
1079 | n/a | |
---|
1080 | n/a | #ifdef NCURSES_MOUSE_VERSION |
---|
1081 | n/a | static PyObject * |
---|
1082 | n/a | PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args) |
---|
1083 | n/a | { |
---|
1084 | n/a | int x, y; |
---|
1085 | n/a | if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x)) |
---|
1086 | n/a | return NULL; |
---|
1087 | n/a | |
---|
1088 | n/a | return PyLong_FromLong( wenclose(self->win,y,x) ); |
---|
1089 | n/a | } |
---|
1090 | n/a | #endif |
---|
1091 | n/a | |
---|
1092 | n/a | static PyObject * |
---|
1093 | n/a | PyCursesWindow_GetBkgd(PyCursesWindowObject *self) |
---|
1094 | n/a | { |
---|
1095 | n/a | return PyLong_FromLong((long) getbkgd(self->win)); |
---|
1096 | n/a | } |
---|
1097 | n/a | |
---|
1098 | n/a | static PyObject * |
---|
1099 | n/a | PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args) |
---|
1100 | n/a | { |
---|
1101 | n/a | int x, y; |
---|
1102 | n/a | int rtn; |
---|
1103 | n/a | |
---|
1104 | n/a | switch (PyTuple_Size(args)) { |
---|
1105 | n/a | case 0: |
---|
1106 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1107 | n/a | rtn = wgetch(self->win); |
---|
1108 | n/a | Py_END_ALLOW_THREADS |
---|
1109 | n/a | break; |
---|
1110 | n/a | case 2: |
---|
1111 | n/a | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
---|
1112 | n/a | return NULL; |
---|
1113 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1114 | n/a | rtn = mvwgetch(self->win,y,x); |
---|
1115 | n/a | Py_END_ALLOW_THREADS |
---|
1116 | n/a | break; |
---|
1117 | n/a | default: |
---|
1118 | n/a | PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments"); |
---|
1119 | n/a | return NULL; |
---|
1120 | n/a | } |
---|
1121 | n/a | return PyLong_FromLong((long)rtn); |
---|
1122 | n/a | } |
---|
1123 | n/a | |
---|
1124 | n/a | static PyObject * |
---|
1125 | n/a | PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args) |
---|
1126 | n/a | { |
---|
1127 | n/a | int x, y; |
---|
1128 | n/a | int rtn; |
---|
1129 | n/a | |
---|
1130 | n/a | switch (PyTuple_Size(args)) { |
---|
1131 | n/a | case 0: |
---|
1132 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1133 | n/a | rtn = wgetch(self->win); |
---|
1134 | n/a | Py_END_ALLOW_THREADS |
---|
1135 | n/a | break; |
---|
1136 | n/a | case 2: |
---|
1137 | n/a | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
---|
1138 | n/a | return NULL; |
---|
1139 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1140 | n/a | rtn = mvwgetch(self->win,y,x); |
---|
1141 | n/a | Py_END_ALLOW_THREADS |
---|
1142 | n/a | break; |
---|
1143 | n/a | default: |
---|
1144 | n/a | PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments"); |
---|
1145 | n/a | return NULL; |
---|
1146 | n/a | } |
---|
1147 | n/a | if (rtn == ERR) { |
---|
1148 | n/a | /* getch() returns ERR in nodelay mode */ |
---|
1149 | n/a | PyErr_CheckSignals(); |
---|
1150 | n/a | if (!PyErr_Occurred()) |
---|
1151 | n/a | PyErr_SetString(PyCursesError, "no input"); |
---|
1152 | n/a | return NULL; |
---|
1153 | n/a | } else if (rtn<=255) { |
---|
1154 | n/a | return Py_BuildValue("C", rtn); |
---|
1155 | n/a | } else { |
---|
1156 | n/a | const char *knp; |
---|
1157 | n/a | #if defined(__NetBSD__) |
---|
1158 | n/a | knp = unctrl(rtn); |
---|
1159 | n/a | #else |
---|
1160 | n/a | knp = keyname(rtn); |
---|
1161 | n/a | #endif |
---|
1162 | n/a | return PyUnicode_FromString((knp == NULL) ? "" : knp); |
---|
1163 | n/a | } |
---|
1164 | n/a | } |
---|
1165 | n/a | |
---|
1166 | n/a | #ifdef HAVE_NCURSESW |
---|
1167 | n/a | static PyObject * |
---|
1168 | n/a | PyCursesWindow_Get_WCh(PyCursesWindowObject *self, PyObject *args) |
---|
1169 | n/a | { |
---|
1170 | n/a | int x, y; |
---|
1171 | n/a | int ct; |
---|
1172 | n/a | wint_t rtn; |
---|
1173 | n/a | |
---|
1174 | n/a | switch (PyTuple_Size(args)) { |
---|
1175 | n/a | case 0: |
---|
1176 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1177 | n/a | ct = wget_wch(self->win,&rtn); |
---|
1178 | n/a | Py_END_ALLOW_THREADS |
---|
1179 | n/a | break; |
---|
1180 | n/a | case 2: |
---|
1181 | n/a | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
---|
1182 | n/a | return NULL; |
---|
1183 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1184 | n/a | ct = mvwget_wch(self->win,y,x,&rtn); |
---|
1185 | n/a | Py_END_ALLOW_THREADS |
---|
1186 | n/a | break; |
---|
1187 | n/a | default: |
---|
1188 | n/a | PyErr_SetString(PyExc_TypeError, "get_wch requires 0 or 2 arguments"); |
---|
1189 | n/a | return NULL; |
---|
1190 | n/a | } |
---|
1191 | n/a | if (ct == ERR) { |
---|
1192 | n/a | if (PyErr_CheckSignals()) |
---|
1193 | n/a | return NULL; |
---|
1194 | n/a | |
---|
1195 | n/a | /* get_wch() returns ERR in nodelay mode */ |
---|
1196 | n/a | PyErr_SetString(PyCursesError, "no input"); |
---|
1197 | n/a | return NULL; |
---|
1198 | n/a | } |
---|
1199 | n/a | if (ct == KEY_CODE_YES) |
---|
1200 | n/a | return PyLong_FromLong(rtn); |
---|
1201 | n/a | else |
---|
1202 | n/a | return PyUnicode_FromOrdinal(rtn); |
---|
1203 | n/a | } |
---|
1204 | n/a | #endif |
---|
1205 | n/a | |
---|
1206 | n/a | static PyObject * |
---|
1207 | n/a | PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args) |
---|
1208 | n/a | { |
---|
1209 | n/a | int x, y, n; |
---|
1210 | n/a | char rtn[1024]; /* This should be big enough.. I hope */ |
---|
1211 | n/a | int rtn2; |
---|
1212 | n/a | |
---|
1213 | n/a | switch (PyTuple_Size(args)) { |
---|
1214 | n/a | case 0: |
---|
1215 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1216 | n/a | rtn2 = wgetnstr(self->win,rtn, 1023); |
---|
1217 | n/a | Py_END_ALLOW_THREADS |
---|
1218 | n/a | break; |
---|
1219 | n/a | case 1: |
---|
1220 | n/a | if (!PyArg_ParseTuple(args,"i;n", &n)) |
---|
1221 | n/a | return NULL; |
---|
1222 | n/a | if (n < 0) { |
---|
1223 | n/a | PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative"); |
---|
1224 | n/a | return NULL; |
---|
1225 | n/a | } |
---|
1226 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1227 | n/a | rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023)); |
---|
1228 | n/a | Py_END_ALLOW_THREADS |
---|
1229 | n/a | break; |
---|
1230 | n/a | case 2: |
---|
1231 | n/a | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
---|
1232 | n/a | return NULL; |
---|
1233 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1234 | n/a | #ifdef STRICT_SYSV_CURSES |
---|
1235 | n/a | rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023); |
---|
1236 | n/a | #else |
---|
1237 | n/a | rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023); |
---|
1238 | n/a | #endif |
---|
1239 | n/a | Py_END_ALLOW_THREADS |
---|
1240 | n/a | break; |
---|
1241 | n/a | case 3: |
---|
1242 | n/a | if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n)) |
---|
1243 | n/a | return NULL; |
---|
1244 | n/a | if (n < 0) { |
---|
1245 | n/a | PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative"); |
---|
1246 | n/a | return NULL; |
---|
1247 | n/a | } |
---|
1248 | n/a | #ifdef STRICT_SYSV_CURSES |
---|
1249 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1250 | n/a | rtn2 = wmove(self->win,y,x)==ERR ? ERR : |
---|
1251 | n/a | wgetnstr(self->win, rtn, Py_MIN(n, 1023)); |
---|
1252 | n/a | Py_END_ALLOW_THREADS |
---|
1253 | n/a | #else |
---|
1254 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1255 | n/a | rtn2 = mvwgetnstr(self->win, y, x, rtn, Py_MIN(n, 1023)); |
---|
1256 | n/a | Py_END_ALLOW_THREADS |
---|
1257 | n/a | #endif |
---|
1258 | n/a | break; |
---|
1259 | n/a | default: |
---|
1260 | n/a | PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments"); |
---|
1261 | n/a | return NULL; |
---|
1262 | n/a | } |
---|
1263 | n/a | if (rtn2 == ERR) |
---|
1264 | n/a | rtn[0] = 0; |
---|
1265 | n/a | return PyBytes_FromString(rtn); |
---|
1266 | n/a | } |
---|
1267 | n/a | |
---|
1268 | n/a | static PyObject * |
---|
1269 | n/a | PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args) |
---|
1270 | n/a | { |
---|
1271 | n/a | PyObject *temp; |
---|
1272 | n/a | chtype ch; |
---|
1273 | n/a | int n, x, y, code = OK; |
---|
1274 | n/a | attr_t attr = A_NORMAL; |
---|
1275 | n/a | long lattr; |
---|
1276 | n/a | |
---|
1277 | n/a | switch (PyTuple_Size(args)) { |
---|
1278 | n/a | case 2: |
---|
1279 | n/a | if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n)) |
---|
1280 | n/a | return NULL; |
---|
1281 | n/a | break; |
---|
1282 | n/a | case 3: |
---|
1283 | n/a | if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr)) |
---|
1284 | n/a | return NULL; |
---|
1285 | n/a | attr = lattr; |
---|
1286 | n/a | break; |
---|
1287 | n/a | case 4: |
---|
1288 | n/a | if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n)) |
---|
1289 | n/a | return NULL; |
---|
1290 | n/a | code = wmove(self->win, y, x); |
---|
1291 | n/a | break; |
---|
1292 | n/a | case 5: |
---|
1293 | n/a | if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", |
---|
1294 | n/a | &y, &x, &temp, &n, &lattr)) |
---|
1295 | n/a | return NULL; |
---|
1296 | n/a | attr = lattr; |
---|
1297 | n/a | code = wmove(self->win, y, x); |
---|
1298 | n/a | break; |
---|
1299 | n/a | default: |
---|
1300 | n/a | PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments"); |
---|
1301 | n/a | return NULL; |
---|
1302 | n/a | } |
---|
1303 | n/a | |
---|
1304 | n/a | if (code != ERR) { |
---|
1305 | n/a | if (!PyCurses_ConvertToChtype(self, temp, &ch)) |
---|
1306 | n/a | return NULL; |
---|
1307 | n/a | return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline"); |
---|
1308 | n/a | } else |
---|
1309 | n/a | return PyCursesCheckERR(code, "wmove"); |
---|
1310 | n/a | } |
---|
1311 | n/a | |
---|
1312 | n/a | static PyObject * |
---|
1313 | n/a | PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args) |
---|
1314 | n/a | { |
---|
1315 | n/a | int rtn, x, y, use_xy = FALSE; |
---|
1316 | n/a | PyObject *temp; |
---|
1317 | n/a | chtype ch = 0; |
---|
1318 | n/a | attr_t attr = A_NORMAL; |
---|
1319 | n/a | long lattr; |
---|
1320 | n/a | |
---|
1321 | n/a | switch (PyTuple_Size(args)) { |
---|
1322 | n/a | case 1: |
---|
1323 | n/a | if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) |
---|
1324 | n/a | return NULL; |
---|
1325 | n/a | break; |
---|
1326 | n/a | case 2: |
---|
1327 | n/a | if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr)) |
---|
1328 | n/a | return NULL; |
---|
1329 | n/a | attr = lattr; |
---|
1330 | n/a | break; |
---|
1331 | n/a | case 3: |
---|
1332 | n/a | if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp)) |
---|
1333 | n/a | return NULL; |
---|
1334 | n/a | use_xy = TRUE; |
---|
1335 | n/a | break; |
---|
1336 | n/a | case 4: |
---|
1337 | n/a | if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &lattr)) |
---|
1338 | n/a | return NULL; |
---|
1339 | n/a | attr = lattr; |
---|
1340 | n/a | use_xy = TRUE; |
---|
1341 | n/a | break; |
---|
1342 | n/a | default: |
---|
1343 | n/a | PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments"); |
---|
1344 | n/a | return NULL; |
---|
1345 | n/a | } |
---|
1346 | n/a | |
---|
1347 | n/a | if (!PyCurses_ConvertToChtype(self, temp, &ch)) |
---|
1348 | n/a | return NULL; |
---|
1349 | n/a | |
---|
1350 | n/a | if (use_xy == TRUE) |
---|
1351 | n/a | rtn = mvwinsch(self->win,y,x, ch | attr); |
---|
1352 | n/a | else { |
---|
1353 | n/a | rtn = winsch(self->win, ch | attr); |
---|
1354 | n/a | } |
---|
1355 | n/a | return PyCursesCheckERR(rtn, "insch"); |
---|
1356 | n/a | } |
---|
1357 | n/a | |
---|
1358 | n/a | static PyObject * |
---|
1359 | n/a | PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args) |
---|
1360 | n/a | { |
---|
1361 | n/a | int x, y; |
---|
1362 | n/a | unsigned long rtn; |
---|
1363 | n/a | |
---|
1364 | n/a | switch (PyTuple_Size(args)) { |
---|
1365 | n/a | case 0: |
---|
1366 | n/a | rtn = winch(self->win); |
---|
1367 | n/a | break; |
---|
1368 | n/a | case 2: |
---|
1369 | n/a | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
---|
1370 | n/a | return NULL; |
---|
1371 | n/a | rtn = mvwinch(self->win,y,x); |
---|
1372 | n/a | break; |
---|
1373 | n/a | default: |
---|
1374 | n/a | PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments"); |
---|
1375 | n/a | return NULL; |
---|
1376 | n/a | } |
---|
1377 | n/a | return PyLong_FromUnsignedLong(rtn); |
---|
1378 | n/a | } |
---|
1379 | n/a | |
---|
1380 | n/a | static PyObject * |
---|
1381 | n/a | PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args) |
---|
1382 | n/a | { |
---|
1383 | n/a | int x, y, n; |
---|
1384 | n/a | char rtn[1024]; /* This should be big enough.. I hope */ |
---|
1385 | n/a | int rtn2; |
---|
1386 | n/a | |
---|
1387 | n/a | switch (PyTuple_Size(args)) { |
---|
1388 | n/a | case 0: |
---|
1389 | n/a | rtn2 = winnstr(self->win,rtn, 1023); |
---|
1390 | n/a | break; |
---|
1391 | n/a | case 1: |
---|
1392 | n/a | if (!PyArg_ParseTuple(args,"i;n", &n)) |
---|
1393 | n/a | return NULL; |
---|
1394 | n/a | if (n < 0) { |
---|
1395 | n/a | PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative"); |
---|
1396 | n/a | return NULL; |
---|
1397 | n/a | } |
---|
1398 | n/a | rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023)); |
---|
1399 | n/a | break; |
---|
1400 | n/a | case 2: |
---|
1401 | n/a | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) |
---|
1402 | n/a | return NULL; |
---|
1403 | n/a | rtn2 = mvwinnstr(self->win,y,x,rtn,1023); |
---|
1404 | n/a | break; |
---|
1405 | n/a | case 3: |
---|
1406 | n/a | if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n)) |
---|
1407 | n/a | return NULL; |
---|
1408 | n/a | if (n < 0) { |
---|
1409 | n/a | PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative"); |
---|
1410 | n/a | return NULL; |
---|
1411 | n/a | } |
---|
1412 | n/a | rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023)); |
---|
1413 | n/a | break; |
---|
1414 | n/a | default: |
---|
1415 | n/a | PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments"); |
---|
1416 | n/a | return NULL; |
---|
1417 | n/a | } |
---|
1418 | n/a | if (rtn2 == ERR) |
---|
1419 | n/a | rtn[0] = 0; |
---|
1420 | n/a | return PyBytes_FromString(rtn); |
---|
1421 | n/a | } |
---|
1422 | n/a | |
---|
1423 | n/a | static PyObject * |
---|
1424 | n/a | PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args) |
---|
1425 | n/a | { |
---|
1426 | n/a | int rtn; |
---|
1427 | n/a | int x, y; |
---|
1428 | n/a | int strtype; |
---|
1429 | n/a | PyObject *strobj, *bytesobj = NULL; |
---|
1430 | n/a | #ifdef HAVE_NCURSESW |
---|
1431 | n/a | wchar_t *wstr = NULL; |
---|
1432 | n/a | #endif |
---|
1433 | n/a | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
---|
1434 | n/a | long lattr; |
---|
1435 | n/a | int use_xy = FALSE, use_attr = FALSE; |
---|
1436 | n/a | const char *funcname; |
---|
1437 | n/a | |
---|
1438 | n/a | switch (PyTuple_Size(args)) { |
---|
1439 | n/a | case 1: |
---|
1440 | n/a | if (!PyArg_ParseTuple(args,"O;str", &strobj)) |
---|
1441 | n/a | return NULL; |
---|
1442 | n/a | break; |
---|
1443 | n/a | case 2: |
---|
1444 | n/a | if (!PyArg_ParseTuple(args,"Ol;str,attr", &strobj, &lattr)) |
---|
1445 | n/a | return NULL; |
---|
1446 | n/a | attr = lattr; |
---|
1447 | n/a | use_attr = TRUE; |
---|
1448 | n/a | break; |
---|
1449 | n/a | case 3: |
---|
1450 | n/a | if (!PyArg_ParseTuple(args,"iiO;y,x,str", &y, &x, &strobj)) |
---|
1451 | n/a | return NULL; |
---|
1452 | n/a | use_xy = TRUE; |
---|
1453 | n/a | break; |
---|
1454 | n/a | case 4: |
---|
1455 | n/a | if (!PyArg_ParseTuple(args,"iiOl;y,x,str,attr", &y, &x, &strobj, &lattr)) |
---|
1456 | n/a | return NULL; |
---|
1457 | n/a | attr = lattr; |
---|
1458 | n/a | use_xy = use_attr = TRUE; |
---|
1459 | n/a | break; |
---|
1460 | n/a | default: |
---|
1461 | n/a | PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments"); |
---|
1462 | n/a | return NULL; |
---|
1463 | n/a | } |
---|
1464 | n/a | |
---|
1465 | n/a | #ifdef HAVE_NCURSESW |
---|
1466 | n/a | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); |
---|
1467 | n/a | #else |
---|
1468 | n/a | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); |
---|
1469 | n/a | #endif |
---|
1470 | n/a | if (strtype == 0) |
---|
1471 | n/a | return NULL; |
---|
1472 | n/a | |
---|
1473 | n/a | if (use_attr == TRUE) { |
---|
1474 | n/a | attr_old = getattrs(self->win); |
---|
1475 | n/a | (void)wattrset(self->win,attr); |
---|
1476 | n/a | } |
---|
1477 | n/a | #ifdef HAVE_NCURSESW |
---|
1478 | n/a | if (strtype == 2) { |
---|
1479 | n/a | funcname = "inswstr"; |
---|
1480 | n/a | if (use_xy == TRUE) |
---|
1481 | n/a | rtn = mvwins_wstr(self->win,y,x,wstr); |
---|
1482 | n/a | else |
---|
1483 | n/a | rtn = wins_wstr(self->win,wstr); |
---|
1484 | n/a | PyMem_Free(wstr); |
---|
1485 | n/a | } |
---|
1486 | n/a | else |
---|
1487 | n/a | #endif |
---|
1488 | n/a | { |
---|
1489 | n/a | char *str = PyBytes_AS_STRING(bytesobj); |
---|
1490 | n/a | funcname = "insstr"; |
---|
1491 | n/a | if (use_xy == TRUE) |
---|
1492 | n/a | rtn = mvwinsstr(self->win,y,x,str); |
---|
1493 | n/a | else |
---|
1494 | n/a | rtn = winsstr(self->win,str); |
---|
1495 | n/a | Py_DECREF(bytesobj); |
---|
1496 | n/a | } |
---|
1497 | n/a | if (use_attr == TRUE) |
---|
1498 | n/a | (void)wattrset(self->win,attr_old); |
---|
1499 | n/a | return PyCursesCheckERR(rtn, funcname); |
---|
1500 | n/a | } |
---|
1501 | n/a | |
---|
1502 | n/a | static PyObject * |
---|
1503 | n/a | PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args) |
---|
1504 | n/a | { |
---|
1505 | n/a | int rtn, x, y, n; |
---|
1506 | n/a | int strtype; |
---|
1507 | n/a | PyObject *strobj, *bytesobj = NULL; |
---|
1508 | n/a | #ifdef HAVE_NCURSESW |
---|
1509 | n/a | wchar_t *wstr = NULL; |
---|
1510 | n/a | #endif |
---|
1511 | n/a | attr_t attr = A_NORMAL , attr_old = A_NORMAL; |
---|
1512 | n/a | long lattr; |
---|
1513 | n/a | int use_xy = FALSE, use_attr = FALSE; |
---|
1514 | n/a | const char *funcname; |
---|
1515 | n/a | |
---|
1516 | n/a | switch (PyTuple_Size(args)) { |
---|
1517 | n/a | case 2: |
---|
1518 | n/a | if (!PyArg_ParseTuple(args,"Oi;str,n", &strobj, &n)) |
---|
1519 | n/a | return NULL; |
---|
1520 | n/a | break; |
---|
1521 | n/a | case 3: |
---|
1522 | n/a | if (!PyArg_ParseTuple(args,"Oil;str,n,attr", &strobj, &n, &lattr)) |
---|
1523 | n/a | return NULL; |
---|
1524 | n/a | attr = lattr; |
---|
1525 | n/a | use_attr = TRUE; |
---|
1526 | n/a | break; |
---|
1527 | n/a | case 4: |
---|
1528 | n/a | if (!PyArg_ParseTuple(args,"iiOi;y,x,str,n", &y, &x, &strobj, &n)) |
---|
1529 | n/a | return NULL; |
---|
1530 | n/a | use_xy = TRUE; |
---|
1531 | n/a | break; |
---|
1532 | n/a | case 5: |
---|
1533 | n/a | if (!PyArg_ParseTuple(args,"iiOil;y,x,str,n,attr", &y, &x, &strobj, &n, &lattr)) |
---|
1534 | n/a | return NULL; |
---|
1535 | n/a | attr = lattr; |
---|
1536 | n/a | use_xy = use_attr = TRUE; |
---|
1537 | n/a | break; |
---|
1538 | n/a | default: |
---|
1539 | n/a | PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments"); |
---|
1540 | n/a | return NULL; |
---|
1541 | n/a | } |
---|
1542 | n/a | |
---|
1543 | n/a | #ifdef HAVE_NCURSESW |
---|
1544 | n/a | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); |
---|
1545 | n/a | #else |
---|
1546 | n/a | strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); |
---|
1547 | n/a | #endif |
---|
1548 | n/a | if (strtype == 0) |
---|
1549 | n/a | return NULL; |
---|
1550 | n/a | |
---|
1551 | n/a | if (use_attr == TRUE) { |
---|
1552 | n/a | attr_old = getattrs(self->win); |
---|
1553 | n/a | (void)wattrset(self->win,attr); |
---|
1554 | n/a | } |
---|
1555 | n/a | #ifdef HAVE_NCURSESW |
---|
1556 | n/a | if (strtype == 2) { |
---|
1557 | n/a | funcname = "insn_wstr"; |
---|
1558 | n/a | if (use_xy == TRUE) |
---|
1559 | n/a | rtn = mvwins_nwstr(self->win,y,x,wstr,n); |
---|
1560 | n/a | else |
---|
1561 | n/a | rtn = wins_nwstr(self->win,wstr,n); |
---|
1562 | n/a | PyMem_Free(wstr); |
---|
1563 | n/a | } |
---|
1564 | n/a | else |
---|
1565 | n/a | #endif |
---|
1566 | n/a | { |
---|
1567 | n/a | char *str = PyBytes_AS_STRING(bytesobj); |
---|
1568 | n/a | funcname = "insnstr"; |
---|
1569 | n/a | if (use_xy == TRUE) |
---|
1570 | n/a | rtn = mvwinsnstr(self->win,y,x,str,n); |
---|
1571 | n/a | else |
---|
1572 | n/a | rtn = winsnstr(self->win,str,n); |
---|
1573 | n/a | Py_DECREF(bytesobj); |
---|
1574 | n/a | } |
---|
1575 | n/a | if (use_attr == TRUE) |
---|
1576 | n/a | (void)wattrset(self->win,attr_old); |
---|
1577 | n/a | return PyCursesCheckERR(rtn, funcname); |
---|
1578 | n/a | } |
---|
1579 | n/a | |
---|
1580 | n/a | static PyObject * |
---|
1581 | n/a | PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args) |
---|
1582 | n/a | { |
---|
1583 | n/a | int line, erg; |
---|
1584 | n/a | if (!PyArg_ParseTuple(args,"i;line", &line)) |
---|
1585 | n/a | return NULL; |
---|
1586 | n/a | erg = is_linetouched(self->win, line); |
---|
1587 | n/a | if (erg == ERR) { |
---|
1588 | n/a | PyErr_SetString(PyExc_TypeError, |
---|
1589 | n/a | "is_linetouched: line number outside of boundaries"); |
---|
1590 | n/a | return NULL; |
---|
1591 | n/a | } else |
---|
1592 | n/a | if (erg == FALSE) { |
---|
1593 | n/a | Py_RETURN_FALSE; |
---|
1594 | n/a | } else { |
---|
1595 | n/a | Py_RETURN_TRUE; |
---|
1596 | n/a | } |
---|
1597 | n/a | } |
---|
1598 | n/a | |
---|
1599 | n/a | static PyObject * |
---|
1600 | n/a | PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args) |
---|
1601 | n/a | { |
---|
1602 | n/a | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; |
---|
1603 | n/a | int rtn; |
---|
1604 | n/a | |
---|
1605 | n/a | #ifndef WINDOW_HAS_FLAGS |
---|
1606 | n/a | if (0) |
---|
1607 | n/a | #else |
---|
1608 | n/a | if (self->win->_flags & _ISPAD) |
---|
1609 | n/a | #endif |
---|
1610 | n/a | { |
---|
1611 | n/a | switch(PyTuple_Size(args)) { |
---|
1612 | n/a | case 6: |
---|
1613 | n/a | if (!PyArg_ParseTuple(args, |
---|
1614 | n/a | "iiiiii;" \ |
---|
1615 | n/a | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", |
---|
1616 | n/a | &pminrow, &pmincol, &sminrow, |
---|
1617 | n/a | &smincol, &smaxrow, &smaxcol)) |
---|
1618 | n/a | return NULL; |
---|
1619 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1620 | n/a | rtn = pnoutrefresh(self->win, |
---|
1621 | n/a | pminrow, pmincol, sminrow, |
---|
1622 | n/a | smincol, smaxrow, smaxcol); |
---|
1623 | n/a | Py_END_ALLOW_THREADS |
---|
1624 | n/a | return PyCursesCheckERR(rtn, "pnoutrefresh"); |
---|
1625 | n/a | default: |
---|
1626 | n/a | PyErr_SetString(PyCursesError, |
---|
1627 | n/a | "noutrefresh() called for a pad " |
---|
1628 | n/a | "requires 6 arguments"); |
---|
1629 | n/a | return NULL; |
---|
1630 | n/a | } |
---|
1631 | n/a | } else { |
---|
1632 | n/a | if (!PyArg_ParseTuple(args, ":noutrefresh")) |
---|
1633 | n/a | return NULL; |
---|
1634 | n/a | |
---|
1635 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1636 | n/a | rtn = wnoutrefresh(self->win); |
---|
1637 | n/a | Py_END_ALLOW_THREADS |
---|
1638 | n/a | return PyCursesCheckERR(rtn, "wnoutrefresh"); |
---|
1639 | n/a | } |
---|
1640 | n/a | } |
---|
1641 | n/a | |
---|
1642 | n/a | static PyObject * |
---|
1643 | n/a | PyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args) |
---|
1644 | n/a | { |
---|
1645 | n/a | PyCursesWindowObject *temp; |
---|
1646 | n/a | int use_copywin = FALSE; |
---|
1647 | n/a | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; |
---|
1648 | n/a | int rtn; |
---|
1649 | n/a | |
---|
1650 | n/a | switch (PyTuple_Size(args)) { |
---|
1651 | n/a | case 1: |
---|
1652 | n/a | if (!PyArg_ParseTuple(args, "O!;window object", |
---|
1653 | n/a | &PyCursesWindow_Type, &temp)) |
---|
1654 | n/a | return NULL; |
---|
1655 | n/a | break; |
---|
1656 | n/a | case 7: |
---|
1657 | n/a | if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", |
---|
1658 | n/a | &PyCursesWindow_Type, &temp, &sminrow, &smincol, |
---|
1659 | n/a | &dminrow, &dmincol, &dmaxrow, &dmaxcol)) |
---|
1660 | n/a | return NULL; |
---|
1661 | n/a | use_copywin = TRUE; |
---|
1662 | n/a | break; |
---|
1663 | n/a | default: |
---|
1664 | n/a | PyErr_SetString(PyExc_TypeError, |
---|
1665 | n/a | "overlay requires one or seven arguments"); |
---|
1666 | n/a | return NULL; |
---|
1667 | n/a | } |
---|
1668 | n/a | |
---|
1669 | n/a | if (use_copywin == TRUE) { |
---|
1670 | n/a | rtn = copywin(self->win, temp->win, sminrow, smincol, |
---|
1671 | n/a | dminrow, dmincol, dmaxrow, dmaxcol, TRUE); |
---|
1672 | n/a | return PyCursesCheckERR(rtn, "copywin"); |
---|
1673 | n/a | } |
---|
1674 | n/a | else { |
---|
1675 | n/a | rtn = overlay(self->win, temp->win); |
---|
1676 | n/a | return PyCursesCheckERR(rtn, "overlay"); |
---|
1677 | n/a | } |
---|
1678 | n/a | } |
---|
1679 | n/a | |
---|
1680 | n/a | static PyObject * |
---|
1681 | n/a | PyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args) |
---|
1682 | n/a | { |
---|
1683 | n/a | PyCursesWindowObject *temp; |
---|
1684 | n/a | int use_copywin = FALSE; |
---|
1685 | n/a | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; |
---|
1686 | n/a | int rtn; |
---|
1687 | n/a | |
---|
1688 | n/a | switch (PyTuple_Size(args)) { |
---|
1689 | n/a | case 1: |
---|
1690 | n/a | if (!PyArg_ParseTuple(args, "O!;window object", |
---|
1691 | n/a | &PyCursesWindow_Type, &temp)) |
---|
1692 | n/a | return NULL; |
---|
1693 | n/a | break; |
---|
1694 | n/a | case 7: |
---|
1695 | n/a | if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", |
---|
1696 | n/a | &PyCursesWindow_Type, &temp, &sminrow, &smincol, |
---|
1697 | n/a | &dminrow, &dmincol, &dmaxrow, &dmaxcol)) |
---|
1698 | n/a | return NULL; |
---|
1699 | n/a | use_copywin = TRUE; |
---|
1700 | n/a | break; |
---|
1701 | n/a | default: |
---|
1702 | n/a | PyErr_SetString(PyExc_TypeError, |
---|
1703 | n/a | "overwrite requires one or seven arguments"); |
---|
1704 | n/a | return NULL; |
---|
1705 | n/a | } |
---|
1706 | n/a | |
---|
1707 | n/a | if (use_copywin == TRUE) { |
---|
1708 | n/a | rtn = copywin(self->win, temp->win, sminrow, smincol, |
---|
1709 | n/a | dminrow, dmincol, dmaxrow, dmaxcol, FALSE); |
---|
1710 | n/a | return PyCursesCheckERR(rtn, "copywin"); |
---|
1711 | n/a | } |
---|
1712 | n/a | else { |
---|
1713 | n/a | rtn = overwrite(self->win, temp->win); |
---|
1714 | n/a | return PyCursesCheckERR(rtn, "overwrite"); |
---|
1715 | n/a | } |
---|
1716 | n/a | } |
---|
1717 | n/a | |
---|
1718 | n/a | static PyObject * |
---|
1719 | n/a | PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *stream) |
---|
1720 | n/a | { |
---|
1721 | n/a | /* We have to simulate this by writing to a temporary FILE*, |
---|
1722 | n/a | then reading back, then writing to the argument stream. */ |
---|
1723 | n/a | char fn[100]; |
---|
1724 | n/a | int fd = -1; |
---|
1725 | n/a | FILE *fp = NULL; |
---|
1726 | n/a | PyObject *res = NULL; |
---|
1727 | n/a | |
---|
1728 | n/a | strcpy(fn, "/tmp/py.curses.putwin.XXXXXX"); |
---|
1729 | n/a | fd = mkstemp(fn); |
---|
1730 | n/a | if (fd < 0) |
---|
1731 | n/a | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
---|
1732 | n/a | if (_Py_set_inheritable(fd, 0, NULL) < 0) |
---|
1733 | n/a | goto exit; |
---|
1734 | n/a | fp = fdopen(fd, "wb+"); |
---|
1735 | n/a | if (fp == NULL) { |
---|
1736 | n/a | PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
---|
1737 | n/a | goto exit; |
---|
1738 | n/a | } |
---|
1739 | n/a | res = PyCursesCheckERR(putwin(self->win, fp), "putwin"); |
---|
1740 | n/a | if (res == NULL) |
---|
1741 | n/a | goto exit; |
---|
1742 | n/a | fseek(fp, 0, 0); |
---|
1743 | n/a | while (1) { |
---|
1744 | n/a | char buf[BUFSIZ]; |
---|
1745 | n/a | Py_ssize_t n = fread(buf, 1, BUFSIZ, fp); |
---|
1746 | n/a | _Py_IDENTIFIER(write); |
---|
1747 | n/a | |
---|
1748 | n/a | if (n <= 0) |
---|
1749 | n/a | break; |
---|
1750 | n/a | Py_DECREF(res); |
---|
1751 | n/a | res = _PyObject_CallMethodId(stream, &PyId_write, "y#", buf, n); |
---|
1752 | n/a | if (res == NULL) |
---|
1753 | n/a | break; |
---|
1754 | n/a | } |
---|
1755 | n/a | |
---|
1756 | n/a | exit: |
---|
1757 | n/a | if (fp != NULL) |
---|
1758 | n/a | fclose(fp); |
---|
1759 | n/a | else if (fd != -1) |
---|
1760 | n/a | close(fd); |
---|
1761 | n/a | remove(fn); |
---|
1762 | n/a | return res; |
---|
1763 | n/a | } |
---|
1764 | n/a | |
---|
1765 | n/a | static PyObject * |
---|
1766 | n/a | PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args) |
---|
1767 | n/a | { |
---|
1768 | n/a | int beg, num; |
---|
1769 | n/a | if (!PyArg_ParseTuple(args, "ii;beg,num", &beg, &num)) |
---|
1770 | n/a | return NULL; |
---|
1771 | n/a | return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln"); |
---|
1772 | n/a | } |
---|
1773 | n/a | |
---|
1774 | n/a | static PyObject * |
---|
1775 | n/a | PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args) |
---|
1776 | n/a | { |
---|
1777 | n/a | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; |
---|
1778 | n/a | int rtn; |
---|
1779 | n/a | |
---|
1780 | n/a | #ifndef WINDOW_HAS_FLAGS |
---|
1781 | n/a | if (0) |
---|
1782 | n/a | #else |
---|
1783 | n/a | if (self->win->_flags & _ISPAD) |
---|
1784 | n/a | #endif |
---|
1785 | n/a | { |
---|
1786 | n/a | switch(PyTuple_Size(args)) { |
---|
1787 | n/a | case 6: |
---|
1788 | n/a | if (!PyArg_ParseTuple(args, |
---|
1789 | n/a | "iiiiii;" \ |
---|
1790 | n/a | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", |
---|
1791 | n/a | &pminrow, &pmincol, &sminrow, |
---|
1792 | n/a | &smincol, &smaxrow, &smaxcol)) |
---|
1793 | n/a | return NULL; |
---|
1794 | n/a | |
---|
1795 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1796 | n/a | rtn = prefresh(self->win, |
---|
1797 | n/a | pminrow, pmincol, sminrow, |
---|
1798 | n/a | smincol, smaxrow, smaxcol); |
---|
1799 | n/a | Py_END_ALLOW_THREADS |
---|
1800 | n/a | return PyCursesCheckERR(rtn, "prefresh"); |
---|
1801 | n/a | default: |
---|
1802 | n/a | PyErr_SetString(PyCursesError, |
---|
1803 | n/a | "refresh() for a pad requires 6 arguments"); |
---|
1804 | n/a | return NULL; |
---|
1805 | n/a | } |
---|
1806 | n/a | } else { |
---|
1807 | n/a | if (!PyArg_ParseTuple(args, ":refresh")) |
---|
1808 | n/a | return NULL; |
---|
1809 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
1810 | n/a | rtn = wrefresh(self->win); |
---|
1811 | n/a | Py_END_ALLOW_THREADS |
---|
1812 | n/a | return PyCursesCheckERR(rtn, "prefresh"); |
---|
1813 | n/a | } |
---|
1814 | n/a | } |
---|
1815 | n/a | |
---|
1816 | n/a | static PyObject * |
---|
1817 | n/a | PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args) |
---|
1818 | n/a | { |
---|
1819 | n/a | int x, y; |
---|
1820 | n/a | if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x)) |
---|
1821 | n/a | return NULL; |
---|
1822 | n/a | return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg"); |
---|
1823 | n/a | } |
---|
1824 | n/a | |
---|
1825 | n/a | static PyObject * |
---|
1826 | n/a | PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args) |
---|
1827 | n/a | { |
---|
1828 | n/a | WINDOW *win; |
---|
1829 | n/a | int nlines, ncols, begin_y, begin_x; |
---|
1830 | n/a | |
---|
1831 | n/a | nlines = 0; |
---|
1832 | n/a | ncols = 0; |
---|
1833 | n/a | switch (PyTuple_Size(args)) { |
---|
1834 | n/a | case 2: |
---|
1835 | n/a | if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x)) |
---|
1836 | n/a | return NULL; |
---|
1837 | n/a | break; |
---|
1838 | n/a | case 4: |
---|
1839 | n/a | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", |
---|
1840 | n/a | &nlines,&ncols,&begin_y,&begin_x)) |
---|
1841 | n/a | return NULL; |
---|
1842 | n/a | break; |
---|
1843 | n/a | default: |
---|
1844 | n/a | PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments"); |
---|
1845 | n/a | return NULL; |
---|
1846 | n/a | } |
---|
1847 | n/a | |
---|
1848 | n/a | /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */ |
---|
1849 | n/a | #ifdef WINDOW_HAS_FLAGS |
---|
1850 | n/a | if (self->win->_flags & _ISPAD) |
---|
1851 | n/a | win = subpad(self->win, nlines, ncols, begin_y, begin_x); |
---|
1852 | n/a | else |
---|
1853 | n/a | #endif |
---|
1854 | n/a | win = subwin(self->win, nlines, ncols, begin_y, begin_x); |
---|
1855 | n/a | |
---|
1856 | n/a | if (win == NULL) { |
---|
1857 | n/a | PyErr_SetString(PyCursesError, catchall_NULL); |
---|
1858 | n/a | return NULL; |
---|
1859 | n/a | } |
---|
1860 | n/a | |
---|
1861 | n/a | return (PyObject *)PyCursesWindow_New(win, self->encoding); |
---|
1862 | n/a | } |
---|
1863 | n/a | |
---|
1864 | n/a | static PyObject * |
---|
1865 | n/a | PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args) |
---|
1866 | n/a | { |
---|
1867 | n/a | int nlines; |
---|
1868 | n/a | switch(PyTuple_Size(args)) { |
---|
1869 | n/a | case 0: |
---|
1870 | n/a | return PyCursesCheckERR(scroll(self->win), "scroll"); |
---|
1871 | n/a | case 1: |
---|
1872 | n/a | if (!PyArg_ParseTuple(args, "i;nlines", &nlines)) |
---|
1873 | n/a | return NULL; |
---|
1874 | n/a | return PyCursesCheckERR(wscrl(self->win, nlines), "scroll"); |
---|
1875 | n/a | default: |
---|
1876 | n/a | PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments"); |
---|
1877 | n/a | return NULL; |
---|
1878 | n/a | } |
---|
1879 | n/a | } |
---|
1880 | n/a | |
---|
1881 | n/a | static PyObject * |
---|
1882 | n/a | PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args) |
---|
1883 | n/a | { |
---|
1884 | n/a | int st, cnt, val; |
---|
1885 | n/a | switch (PyTuple_Size(args)) { |
---|
1886 | n/a | case 2: |
---|
1887 | n/a | if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt)) |
---|
1888 | n/a | return NULL; |
---|
1889 | n/a | return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline"); |
---|
1890 | n/a | case 3: |
---|
1891 | n/a | if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val)) |
---|
1892 | n/a | return NULL; |
---|
1893 | n/a | return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline"); |
---|
1894 | n/a | default: |
---|
1895 | n/a | PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments"); |
---|
1896 | n/a | return NULL; |
---|
1897 | n/a | } |
---|
1898 | n/a | } |
---|
1899 | n/a | |
---|
1900 | n/a | static PyObject * |
---|
1901 | n/a | PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args) |
---|
1902 | n/a | { |
---|
1903 | n/a | PyObject *temp; |
---|
1904 | n/a | chtype ch; |
---|
1905 | n/a | int n, x, y, code = OK; |
---|
1906 | n/a | attr_t attr = A_NORMAL; |
---|
1907 | n/a | long lattr; |
---|
1908 | n/a | |
---|
1909 | n/a | switch (PyTuple_Size(args)) { |
---|
1910 | n/a | case 2: |
---|
1911 | n/a | if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n)) |
---|
1912 | n/a | return NULL; |
---|
1913 | n/a | break; |
---|
1914 | n/a | case 3: |
---|
1915 | n/a | if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr)) |
---|
1916 | n/a | return NULL; |
---|
1917 | n/a | attr = lattr; |
---|
1918 | n/a | break; |
---|
1919 | n/a | case 4: |
---|
1920 | n/a | if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n)) |
---|
1921 | n/a | return NULL; |
---|
1922 | n/a | code = wmove(self->win, y, x); |
---|
1923 | n/a | break; |
---|
1924 | n/a | case 5: |
---|
1925 | n/a | if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", |
---|
1926 | n/a | &y, &x, &temp, &n, &lattr)) |
---|
1927 | n/a | return NULL; |
---|
1928 | n/a | attr = lattr; |
---|
1929 | n/a | code = wmove(self->win, y, x); |
---|
1930 | n/a | break; |
---|
1931 | n/a | default: |
---|
1932 | n/a | PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments"); |
---|
1933 | n/a | return NULL; |
---|
1934 | n/a | } |
---|
1935 | n/a | |
---|
1936 | n/a | if (code != ERR) { |
---|
1937 | n/a | if (!PyCurses_ConvertToChtype(self, temp, &ch)) |
---|
1938 | n/a | return NULL; |
---|
1939 | n/a | return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline"); |
---|
1940 | n/a | } else |
---|
1941 | n/a | return PyCursesCheckERR(code, "wmove"); |
---|
1942 | n/a | } |
---|
1943 | n/a | |
---|
1944 | n/a | static PyObject * |
---|
1945 | n/a | PyCursesWindow_get_encoding(PyCursesWindowObject *self, void *closure) |
---|
1946 | n/a | { |
---|
1947 | n/a | return PyUnicode_FromString(self->encoding); |
---|
1948 | n/a | } |
---|
1949 | n/a | |
---|
1950 | n/a | static int |
---|
1951 | n/a | PyCursesWindow_set_encoding(PyCursesWindowObject *self, PyObject *value) |
---|
1952 | n/a | { |
---|
1953 | n/a | PyObject *ascii; |
---|
1954 | n/a | char *encoding; |
---|
1955 | n/a | |
---|
1956 | n/a | /* It is illegal to del win.encoding */ |
---|
1957 | n/a | if (value == NULL) { |
---|
1958 | n/a | PyErr_SetString(PyExc_TypeError, |
---|
1959 | n/a | "encoding may not be deleted"); |
---|
1960 | n/a | return -1; |
---|
1961 | n/a | } |
---|
1962 | n/a | |
---|
1963 | n/a | if (!PyUnicode_Check(value)) { |
---|
1964 | n/a | PyErr_SetString(PyExc_TypeError, |
---|
1965 | n/a | "setting encoding to a non-string"); |
---|
1966 | n/a | return -1; |
---|
1967 | n/a | } |
---|
1968 | n/a | ascii = PyUnicode_AsASCIIString(value); |
---|
1969 | n/a | if (ascii == NULL) |
---|
1970 | n/a | return -1; |
---|
1971 | n/a | encoding = _PyMem_Strdup(PyBytes_AS_STRING(ascii)); |
---|
1972 | n/a | Py_DECREF(ascii); |
---|
1973 | n/a | if (encoding == NULL) { |
---|
1974 | n/a | PyErr_NoMemory(); |
---|
1975 | n/a | return -1; |
---|
1976 | n/a | } |
---|
1977 | n/a | PyMem_Free(self->encoding); |
---|
1978 | n/a | self->encoding = encoding; |
---|
1979 | n/a | return 0; |
---|
1980 | n/a | } |
---|
1981 | n/a | |
---|
1982 | n/a | |
---|
1983 | n/a | static PyMethodDef PyCursesWindow_Methods[] = { |
---|
1984 | n/a | CURSES_WINDOW_ADDCH_METHODDEF |
---|
1985 | n/a | {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS}, |
---|
1986 | n/a | {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS}, |
---|
1987 | n/a | {"attroff", (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS}, |
---|
1988 | n/a | {"attron", (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS}, |
---|
1989 | n/a | {"attrset", (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS}, |
---|
1990 | n/a | {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS}, |
---|
1991 | n/a | {"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS}, |
---|
1992 | n/a | {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS}, |
---|
1993 | n/a | {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS}, |
---|
1994 | n/a | {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS}, |
---|
1995 | n/a | {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS}, |
---|
1996 | n/a | {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS}, |
---|
1997 | n/a | {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS}, |
---|
1998 | n/a | {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS}, |
---|
1999 | n/a | {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS}, |
---|
2000 | n/a | {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS}, |
---|
2001 | n/a | {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS}, |
---|
2002 | n/a | {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS}, |
---|
2003 | n/a | {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS}, |
---|
2004 | n/a | #ifdef NCURSES_MOUSE_VERSION |
---|
2005 | n/a | {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS}, |
---|
2006 | n/a | #endif |
---|
2007 | n/a | {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS}, |
---|
2008 | n/a | {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS}, |
---|
2009 | n/a | {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS}, |
---|
2010 | n/a | {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS}, |
---|
2011 | n/a | {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS}, |
---|
2012 | n/a | #ifdef HAVE_NCURSESW |
---|
2013 | n/a | {"get_wch", (PyCFunction)PyCursesWindow_Get_WCh, METH_VARARGS}, |
---|
2014 | n/a | #endif |
---|
2015 | n/a | {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS}, |
---|
2016 | n/a | {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS}, |
---|
2017 | n/a | {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS}, |
---|
2018 | n/a | {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS}, |
---|
2019 | n/a | {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS}, |
---|
2020 | n/a | {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS}, |
---|
2021 | n/a | {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS}, |
---|
2022 | n/a | {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS}, |
---|
2023 | n/a | {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS}, |
---|
2024 | n/a | {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS}, |
---|
2025 | n/a | {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS}, |
---|
2026 | n/a | {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS}, |
---|
2027 | n/a | {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS}, |
---|
2028 | n/a | {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS}, |
---|
2029 | n/a | {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS}, |
---|
2030 | n/a | {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS}, |
---|
2031 | n/a | {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS}, |
---|
2032 | n/a | {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS}, |
---|
2033 | n/a | {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS}, |
---|
2034 | n/a | {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS}, |
---|
2035 | n/a | {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS}, |
---|
2036 | n/a | {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS}, |
---|
2037 | n/a | {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS}, |
---|
2038 | n/a | {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS}, |
---|
2039 | n/a | {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, |
---|
2040 | n/a | {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS}, |
---|
2041 | n/a | {"overwrite", (PyCFunction)PyCursesWindow_Overwrite, |
---|
2042 | n/a | METH_VARARGS}, |
---|
2043 | n/a | {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_O}, |
---|
2044 | n/a | {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS}, |
---|
2045 | n/a | {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS}, |
---|
2046 | n/a | {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS}, |
---|
2047 | n/a | #ifndef STRICT_SYSV_CURSES |
---|
2048 | n/a | {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS}, |
---|
2049 | n/a | #endif |
---|
2050 | n/a | {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS}, |
---|
2051 | n/a | {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS}, |
---|
2052 | n/a | {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS}, |
---|
2053 | n/a | {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS}, |
---|
2054 | n/a | {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS}, |
---|
2055 | n/a | {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, |
---|
2056 | n/a | {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, |
---|
2057 | n/a | {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS}, |
---|
2058 | n/a | {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS}, |
---|
2059 | n/a | {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS}, |
---|
2060 | n/a | {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS}, |
---|
2061 | n/a | {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS}, |
---|
2062 | n/a | {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS}, |
---|
2063 | n/a | {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS}, |
---|
2064 | n/a | {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS}, |
---|
2065 | n/a | {NULL, NULL} /* sentinel */ |
---|
2066 | n/a | }; |
---|
2067 | n/a | |
---|
2068 | n/a | static PyGetSetDef PyCursesWindow_getsets[] = { |
---|
2069 | n/a | {"encoding", |
---|
2070 | n/a | (getter)PyCursesWindow_get_encoding, |
---|
2071 | n/a | (setter)PyCursesWindow_set_encoding, |
---|
2072 | n/a | "the typecode character used to create the array"}, |
---|
2073 | n/a | {NULL, NULL, NULL, NULL } /* sentinel */ |
---|
2074 | n/a | }; |
---|
2075 | n/a | |
---|
2076 | n/a | /* -------------------------------------------------------*/ |
---|
2077 | n/a | |
---|
2078 | n/a | PyTypeObject PyCursesWindow_Type = { |
---|
2079 | n/a | PyVarObject_HEAD_INIT(NULL, 0) |
---|
2080 | n/a | "_curses.curses window", /*tp_name*/ |
---|
2081 | n/a | sizeof(PyCursesWindowObject), /*tp_basicsize*/ |
---|
2082 | n/a | 0, /*tp_itemsize*/ |
---|
2083 | n/a | /* methods */ |
---|
2084 | n/a | (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/ |
---|
2085 | n/a | 0, /*tp_print*/ |
---|
2086 | n/a | (getattrfunc)0, /*tp_getattr*/ |
---|
2087 | n/a | (setattrfunc)0, /*tp_setattr*/ |
---|
2088 | n/a | 0, /*tp_reserved*/ |
---|
2089 | n/a | 0, /*tp_repr*/ |
---|
2090 | n/a | 0, /*tp_as_number*/ |
---|
2091 | n/a | 0, /*tp_as_sequence*/ |
---|
2092 | n/a | 0, /*tp_as_mapping*/ |
---|
2093 | n/a | 0, /*tp_hash*/ |
---|
2094 | n/a | 0, /*tp_call*/ |
---|
2095 | n/a | 0, /*tp_str*/ |
---|
2096 | n/a | 0, /*tp_getattro*/ |
---|
2097 | n/a | 0, /*tp_setattro*/ |
---|
2098 | n/a | 0, /*tp_as_buffer*/ |
---|
2099 | n/a | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
---|
2100 | n/a | 0, /*tp_doc*/ |
---|
2101 | n/a | 0, /*tp_traverse*/ |
---|
2102 | n/a | 0, /*tp_clear*/ |
---|
2103 | n/a | 0, /*tp_richcompare*/ |
---|
2104 | n/a | 0, /*tp_weaklistoffset*/ |
---|
2105 | n/a | 0, /*tp_iter*/ |
---|
2106 | n/a | 0, /*tp_iternext*/ |
---|
2107 | n/a | PyCursesWindow_Methods, /*tp_methods*/ |
---|
2108 | n/a | 0, /* tp_members */ |
---|
2109 | n/a | PyCursesWindow_getsets, /* tp_getset */ |
---|
2110 | n/a | }; |
---|
2111 | n/a | |
---|
2112 | n/a | /********************************************************************* |
---|
2113 | n/a | Global Functions |
---|
2114 | n/a | **********************************************************************/ |
---|
2115 | n/a | |
---|
2116 | n/a | NoArgNoReturnFunction(beep) |
---|
2117 | n/a | NoArgNoReturnFunction(def_prog_mode) |
---|
2118 | n/a | NoArgNoReturnFunction(def_shell_mode) |
---|
2119 | n/a | NoArgNoReturnFunction(doupdate) |
---|
2120 | n/a | NoArgNoReturnFunction(endwin) |
---|
2121 | n/a | NoArgNoReturnFunction(flash) |
---|
2122 | n/a | NoArgNoReturnFunction(nocbreak) |
---|
2123 | n/a | NoArgNoReturnFunction(noecho) |
---|
2124 | n/a | NoArgNoReturnFunction(nonl) |
---|
2125 | n/a | NoArgNoReturnFunction(noraw) |
---|
2126 | n/a | NoArgNoReturnFunction(reset_prog_mode) |
---|
2127 | n/a | NoArgNoReturnFunction(reset_shell_mode) |
---|
2128 | n/a | NoArgNoReturnFunction(resetty) |
---|
2129 | n/a | NoArgNoReturnFunction(savetty) |
---|
2130 | n/a | |
---|
2131 | n/a | NoArgOrFlagNoReturnFunction(cbreak) |
---|
2132 | n/a | NoArgOrFlagNoReturnFunction(echo) |
---|
2133 | n/a | NoArgOrFlagNoReturnFunction(nl) |
---|
2134 | n/a | NoArgOrFlagNoReturnFunction(raw) |
---|
2135 | n/a | |
---|
2136 | n/a | NoArgReturnIntFunction(baudrate) |
---|
2137 | n/a | NoArgReturnIntFunction(termattrs) |
---|
2138 | n/a | |
---|
2139 | n/a | NoArgReturnStringFunction(termname) |
---|
2140 | n/a | NoArgReturnStringFunction(longname) |
---|
2141 | n/a | |
---|
2142 | n/a | NoArgTrueFalseFunction(can_change_color) |
---|
2143 | n/a | NoArgTrueFalseFunction(has_colors) |
---|
2144 | n/a | NoArgTrueFalseFunction(has_ic) |
---|
2145 | n/a | NoArgTrueFalseFunction(has_il) |
---|
2146 | n/a | NoArgTrueFalseFunction(isendwin) |
---|
2147 | n/a | NoArgNoReturnVoidFunction(flushinp) |
---|
2148 | n/a | NoArgNoReturnVoidFunction(noqiflush) |
---|
2149 | n/a | |
---|
2150 | n/a | static PyObject * |
---|
2151 | n/a | PyCurses_filter(PyObject *self) |
---|
2152 | n/a | { |
---|
2153 | n/a | /* not checking for PyCursesInitialised here since filter() must |
---|
2154 | n/a | be called before initscr() */ |
---|
2155 | n/a | filter(); |
---|
2156 | n/a | Py_RETURN_NONE; |
---|
2157 | n/a | } |
---|
2158 | n/a | |
---|
2159 | n/a | static PyObject * |
---|
2160 | n/a | PyCurses_Color_Content(PyObject *self, PyObject *args) |
---|
2161 | n/a | { |
---|
2162 | n/a | short color,r,g,b; |
---|
2163 | n/a | |
---|
2164 | n/a | PyCursesInitialised; |
---|
2165 | n/a | PyCursesInitialisedColor; |
---|
2166 | n/a | |
---|
2167 | n/a | if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL; |
---|
2168 | n/a | |
---|
2169 | n/a | if (color_content(color, &r, &g, &b) != ERR) |
---|
2170 | n/a | return Py_BuildValue("(iii)", r, g, b); |
---|
2171 | n/a | else { |
---|
2172 | n/a | PyErr_SetString(PyCursesError, |
---|
2173 | n/a | "Argument 1 was out of range. Check value of COLORS."); |
---|
2174 | n/a | return NULL; |
---|
2175 | n/a | } |
---|
2176 | n/a | } |
---|
2177 | n/a | |
---|
2178 | n/a | static PyObject * |
---|
2179 | n/a | PyCurses_color_pair(PyObject *self, PyObject *args) |
---|
2180 | n/a | { |
---|
2181 | n/a | int n; |
---|
2182 | n/a | |
---|
2183 | n/a | PyCursesInitialised; |
---|
2184 | n/a | PyCursesInitialisedColor; |
---|
2185 | n/a | |
---|
2186 | n/a | if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL; |
---|
2187 | n/a | return PyLong_FromLong((long) (n << 8)); |
---|
2188 | n/a | } |
---|
2189 | n/a | |
---|
2190 | n/a | static PyObject * |
---|
2191 | n/a | PyCurses_Curs_Set(PyObject *self, PyObject *args) |
---|
2192 | n/a | { |
---|
2193 | n/a | int vis,erg; |
---|
2194 | n/a | |
---|
2195 | n/a | PyCursesInitialised; |
---|
2196 | n/a | |
---|
2197 | n/a | if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL; |
---|
2198 | n/a | |
---|
2199 | n/a | erg = curs_set(vis); |
---|
2200 | n/a | if (erg == ERR) return PyCursesCheckERR(erg, "curs_set"); |
---|
2201 | n/a | |
---|
2202 | n/a | return PyLong_FromLong((long) erg); |
---|
2203 | n/a | } |
---|
2204 | n/a | |
---|
2205 | n/a | static PyObject * |
---|
2206 | n/a | PyCurses_Delay_Output(PyObject *self, PyObject *args) |
---|
2207 | n/a | { |
---|
2208 | n/a | int ms; |
---|
2209 | n/a | |
---|
2210 | n/a | PyCursesInitialised; |
---|
2211 | n/a | |
---|
2212 | n/a | if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL; |
---|
2213 | n/a | |
---|
2214 | n/a | return PyCursesCheckERR(delay_output(ms), "delay_output"); |
---|
2215 | n/a | } |
---|
2216 | n/a | |
---|
2217 | n/a | static PyObject * |
---|
2218 | n/a | PyCurses_EraseChar(PyObject *self) |
---|
2219 | n/a | { |
---|
2220 | n/a | char ch; |
---|
2221 | n/a | |
---|
2222 | n/a | PyCursesInitialised; |
---|
2223 | n/a | |
---|
2224 | n/a | ch = erasechar(); |
---|
2225 | n/a | |
---|
2226 | n/a | return PyBytes_FromStringAndSize(&ch, 1); |
---|
2227 | n/a | } |
---|
2228 | n/a | |
---|
2229 | n/a | static PyObject * |
---|
2230 | n/a | PyCurses_getsyx(PyObject *self) |
---|
2231 | n/a | { |
---|
2232 | n/a | int x = 0; |
---|
2233 | n/a | int y = 0; |
---|
2234 | n/a | |
---|
2235 | n/a | PyCursesInitialised; |
---|
2236 | n/a | |
---|
2237 | n/a | getsyx(y, x); |
---|
2238 | n/a | |
---|
2239 | n/a | return Py_BuildValue("(ii)", y, x); |
---|
2240 | n/a | } |
---|
2241 | n/a | |
---|
2242 | n/a | #ifdef NCURSES_MOUSE_VERSION |
---|
2243 | n/a | static PyObject * |
---|
2244 | n/a | PyCurses_GetMouse(PyObject *self) |
---|
2245 | n/a | { |
---|
2246 | n/a | int rtn; |
---|
2247 | n/a | MEVENT event; |
---|
2248 | n/a | |
---|
2249 | n/a | PyCursesInitialised; |
---|
2250 | n/a | |
---|
2251 | n/a | rtn = getmouse( &event ); |
---|
2252 | n/a | if (rtn == ERR) { |
---|
2253 | n/a | PyErr_SetString(PyCursesError, "getmouse() returned ERR"); |
---|
2254 | n/a | return NULL; |
---|
2255 | n/a | } |
---|
2256 | n/a | return Py_BuildValue("(hiiil)", |
---|
2257 | n/a | (short)event.id, |
---|
2258 | n/a | event.x, event.y, event.z, |
---|
2259 | n/a | (long) event.bstate); |
---|
2260 | n/a | } |
---|
2261 | n/a | |
---|
2262 | n/a | static PyObject * |
---|
2263 | n/a | PyCurses_UngetMouse(PyObject *self, PyObject *args) |
---|
2264 | n/a | { |
---|
2265 | n/a | MEVENT event; |
---|
2266 | n/a | |
---|
2267 | n/a | PyCursesInitialised; |
---|
2268 | n/a | if (!PyArg_ParseTuple(args, "hiiil", |
---|
2269 | n/a | &event.id, |
---|
2270 | n/a | &event.x, &event.y, &event.z, |
---|
2271 | n/a | (int *) &event.bstate)) |
---|
2272 | n/a | return NULL; |
---|
2273 | n/a | |
---|
2274 | n/a | return PyCursesCheckERR(ungetmouse(&event), "ungetmouse"); |
---|
2275 | n/a | } |
---|
2276 | n/a | #endif |
---|
2277 | n/a | |
---|
2278 | n/a | static PyObject * |
---|
2279 | n/a | PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream) |
---|
2280 | n/a | { |
---|
2281 | n/a | char fn[100]; |
---|
2282 | n/a | int fd = -1; |
---|
2283 | n/a | FILE *fp = NULL; |
---|
2284 | n/a | PyObject *data; |
---|
2285 | n/a | size_t datalen; |
---|
2286 | n/a | WINDOW *win; |
---|
2287 | n/a | _Py_IDENTIFIER(read); |
---|
2288 | n/a | PyObject *res = NULL; |
---|
2289 | n/a | |
---|
2290 | n/a | PyCursesInitialised; |
---|
2291 | n/a | |
---|
2292 | n/a | strcpy(fn, "/tmp/py.curses.getwin.XXXXXX"); |
---|
2293 | n/a | fd = mkstemp(fn); |
---|
2294 | n/a | if (fd < 0) |
---|
2295 | n/a | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
---|
2296 | n/a | if (_Py_set_inheritable(fd, 0, NULL) < 0) |
---|
2297 | n/a | goto error; |
---|
2298 | n/a | fp = fdopen(fd, "wb+"); |
---|
2299 | n/a | if (fp == NULL) { |
---|
2300 | n/a | PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
---|
2301 | n/a | goto error; |
---|
2302 | n/a | } |
---|
2303 | n/a | |
---|
2304 | n/a | data = _PyObject_CallMethodId(stream, &PyId_read, NULL); |
---|
2305 | n/a | if (data == NULL) |
---|
2306 | n/a | goto error; |
---|
2307 | n/a | if (!PyBytes_Check(data)) { |
---|
2308 | n/a | PyErr_Format(PyExc_TypeError, |
---|
2309 | n/a | "f.read() returned %.100s instead of bytes", |
---|
2310 | n/a | data->ob_type->tp_name); |
---|
2311 | n/a | Py_DECREF(data); |
---|
2312 | n/a | goto error; |
---|
2313 | n/a | } |
---|
2314 | n/a | datalen = PyBytes_GET_SIZE(data); |
---|
2315 | n/a | if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) { |
---|
2316 | n/a | Py_DECREF(data); |
---|
2317 | n/a | PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); |
---|
2318 | n/a | goto error; |
---|
2319 | n/a | } |
---|
2320 | n/a | Py_DECREF(data); |
---|
2321 | n/a | |
---|
2322 | n/a | fseek(fp, 0, 0); |
---|
2323 | n/a | win = getwin(fp); |
---|
2324 | n/a | if (win == NULL) { |
---|
2325 | n/a | PyErr_SetString(PyCursesError, catchall_NULL); |
---|
2326 | n/a | goto error; |
---|
2327 | n/a | } |
---|
2328 | n/a | res = PyCursesWindow_New(win, NULL); |
---|
2329 | n/a | |
---|
2330 | n/a | error: |
---|
2331 | n/a | if (fp != NULL) |
---|
2332 | n/a | fclose(fp); |
---|
2333 | n/a | else if (fd != -1) |
---|
2334 | n/a | close(fd); |
---|
2335 | n/a | remove(fn); |
---|
2336 | n/a | return res; |
---|
2337 | n/a | } |
---|
2338 | n/a | |
---|
2339 | n/a | static PyObject * |
---|
2340 | n/a | PyCurses_HalfDelay(PyObject *self, PyObject *args) |
---|
2341 | n/a | { |
---|
2342 | n/a | unsigned char tenths; |
---|
2343 | n/a | |
---|
2344 | n/a | PyCursesInitialised; |
---|
2345 | n/a | |
---|
2346 | n/a | if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL; |
---|
2347 | n/a | |
---|
2348 | n/a | return PyCursesCheckERR(halfdelay(tenths), "halfdelay"); |
---|
2349 | n/a | } |
---|
2350 | n/a | |
---|
2351 | n/a | #ifndef STRICT_SYSV_CURSES |
---|
2352 | n/a | /* No has_key! */ |
---|
2353 | n/a | static PyObject * PyCurses_has_key(PyObject *self, PyObject *args) |
---|
2354 | n/a | { |
---|
2355 | n/a | int ch; |
---|
2356 | n/a | |
---|
2357 | n/a | PyCursesInitialised; |
---|
2358 | n/a | |
---|
2359 | n/a | if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; |
---|
2360 | n/a | |
---|
2361 | n/a | if (has_key(ch) == FALSE) { |
---|
2362 | n/a | Py_RETURN_FALSE; |
---|
2363 | n/a | } |
---|
2364 | n/a | Py_RETURN_TRUE; |
---|
2365 | n/a | } |
---|
2366 | n/a | #endif /* STRICT_SYSV_CURSES */ |
---|
2367 | n/a | |
---|
2368 | n/a | static PyObject * |
---|
2369 | n/a | PyCurses_Init_Color(PyObject *self, PyObject *args) |
---|
2370 | n/a | { |
---|
2371 | n/a | short color, r, g, b; |
---|
2372 | n/a | |
---|
2373 | n/a | PyCursesInitialised; |
---|
2374 | n/a | PyCursesInitialisedColor; |
---|
2375 | n/a | |
---|
2376 | n/a | switch(PyTuple_Size(args)) { |
---|
2377 | n/a | case 4: |
---|
2378 | n/a | if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL; |
---|
2379 | n/a | break; |
---|
2380 | n/a | default: |
---|
2381 | n/a | PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments"); |
---|
2382 | n/a | return NULL; |
---|
2383 | n/a | } |
---|
2384 | n/a | |
---|
2385 | n/a | return PyCursesCheckERR(init_color(color, r, g, b), "init_color"); |
---|
2386 | n/a | } |
---|
2387 | n/a | |
---|
2388 | n/a | static PyObject * |
---|
2389 | n/a | PyCurses_Init_Pair(PyObject *self, PyObject *args) |
---|
2390 | n/a | { |
---|
2391 | n/a | short pair, f, b; |
---|
2392 | n/a | |
---|
2393 | n/a | PyCursesInitialised; |
---|
2394 | n/a | PyCursesInitialisedColor; |
---|
2395 | n/a | |
---|
2396 | n/a | if (PyTuple_Size(args) != 3) { |
---|
2397 | n/a | PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments"); |
---|
2398 | n/a | return NULL; |
---|
2399 | n/a | } |
---|
2400 | n/a | |
---|
2401 | n/a | if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL; |
---|
2402 | n/a | |
---|
2403 | n/a | return PyCursesCheckERR(init_pair(pair, f, b), "init_pair"); |
---|
2404 | n/a | } |
---|
2405 | n/a | |
---|
2406 | n/a | static PyObject *ModDict; |
---|
2407 | n/a | |
---|
2408 | n/a | static PyObject * |
---|
2409 | n/a | PyCurses_InitScr(PyObject *self) |
---|
2410 | n/a | { |
---|
2411 | n/a | WINDOW *win; |
---|
2412 | n/a | PyCursesWindowObject *winobj; |
---|
2413 | n/a | |
---|
2414 | n/a | if (initialised == TRUE) { |
---|
2415 | n/a | wrefresh(stdscr); |
---|
2416 | n/a | return (PyObject *)PyCursesWindow_New(stdscr, NULL); |
---|
2417 | n/a | } |
---|
2418 | n/a | |
---|
2419 | n/a | win = initscr(); |
---|
2420 | n/a | |
---|
2421 | n/a | if (win == NULL) { |
---|
2422 | n/a | PyErr_SetString(PyCursesError, catchall_NULL); |
---|
2423 | n/a | return NULL; |
---|
2424 | n/a | } |
---|
2425 | n/a | |
---|
2426 | n/a | initialised = initialised_setupterm = TRUE; |
---|
2427 | n/a | |
---|
2428 | n/a | /* This was moved from initcurses() because it core dumped on SGI, |
---|
2429 | n/a | where they're not defined until you've called initscr() */ |
---|
2430 | n/a | #define SetDictInt(string,ch) \ |
---|
2431 | n/a | do { \ |
---|
2432 | n/a | PyObject *o = PyLong_FromLong((long) (ch)); \ |
---|
2433 | n/a | if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \ |
---|
2434 | n/a | Py_DECREF(o); \ |
---|
2435 | n/a | } \ |
---|
2436 | n/a | } while (0) |
---|
2437 | n/a | |
---|
2438 | n/a | /* Here are some graphic symbols you can use */ |
---|
2439 | n/a | SetDictInt("ACS_ULCORNER", (ACS_ULCORNER)); |
---|
2440 | n/a | SetDictInt("ACS_LLCORNER", (ACS_LLCORNER)); |
---|
2441 | n/a | SetDictInt("ACS_URCORNER", (ACS_URCORNER)); |
---|
2442 | n/a | SetDictInt("ACS_LRCORNER", (ACS_LRCORNER)); |
---|
2443 | n/a | SetDictInt("ACS_LTEE", (ACS_LTEE)); |
---|
2444 | n/a | SetDictInt("ACS_RTEE", (ACS_RTEE)); |
---|
2445 | n/a | SetDictInt("ACS_BTEE", (ACS_BTEE)); |
---|
2446 | n/a | SetDictInt("ACS_TTEE", (ACS_TTEE)); |
---|
2447 | n/a | SetDictInt("ACS_HLINE", (ACS_HLINE)); |
---|
2448 | n/a | SetDictInt("ACS_VLINE", (ACS_VLINE)); |
---|
2449 | n/a | SetDictInt("ACS_PLUS", (ACS_PLUS)); |
---|
2450 | n/a | #if !defined(__hpux) || defined(HAVE_NCURSES_H) |
---|
2451 | n/a | /* On HP/UX 11, these are of type cchar_t, which is not an |
---|
2452 | n/a | integral type. If this is a problem on more platforms, a |
---|
2453 | n/a | configure test should be added to determine whether ACS_S1 |
---|
2454 | n/a | is of integral type. */ |
---|
2455 | n/a | SetDictInt("ACS_S1", (ACS_S1)); |
---|
2456 | n/a | SetDictInt("ACS_S9", (ACS_S9)); |
---|
2457 | n/a | SetDictInt("ACS_DIAMOND", (ACS_DIAMOND)); |
---|
2458 | n/a | SetDictInt("ACS_CKBOARD", (ACS_CKBOARD)); |
---|
2459 | n/a | SetDictInt("ACS_DEGREE", (ACS_DEGREE)); |
---|
2460 | n/a | SetDictInt("ACS_PLMINUS", (ACS_PLMINUS)); |
---|
2461 | n/a | SetDictInt("ACS_BULLET", (ACS_BULLET)); |
---|
2462 | n/a | SetDictInt("ACS_LARROW", (ACS_LARROW)); |
---|
2463 | n/a | SetDictInt("ACS_RARROW", (ACS_RARROW)); |
---|
2464 | n/a | SetDictInt("ACS_DARROW", (ACS_DARROW)); |
---|
2465 | n/a | SetDictInt("ACS_UARROW", (ACS_UARROW)); |
---|
2466 | n/a | SetDictInt("ACS_BOARD", (ACS_BOARD)); |
---|
2467 | n/a | SetDictInt("ACS_LANTERN", (ACS_LANTERN)); |
---|
2468 | n/a | SetDictInt("ACS_BLOCK", (ACS_BLOCK)); |
---|
2469 | n/a | #endif |
---|
2470 | n/a | SetDictInt("ACS_BSSB", (ACS_ULCORNER)); |
---|
2471 | n/a | SetDictInt("ACS_SSBB", (ACS_LLCORNER)); |
---|
2472 | n/a | SetDictInt("ACS_BBSS", (ACS_URCORNER)); |
---|
2473 | n/a | SetDictInt("ACS_SBBS", (ACS_LRCORNER)); |
---|
2474 | n/a | SetDictInt("ACS_SBSS", (ACS_RTEE)); |
---|
2475 | n/a | SetDictInt("ACS_SSSB", (ACS_LTEE)); |
---|
2476 | n/a | SetDictInt("ACS_SSBS", (ACS_BTEE)); |
---|
2477 | n/a | SetDictInt("ACS_BSSS", (ACS_TTEE)); |
---|
2478 | n/a | SetDictInt("ACS_BSBS", (ACS_HLINE)); |
---|
2479 | n/a | SetDictInt("ACS_SBSB", (ACS_VLINE)); |
---|
2480 | n/a | SetDictInt("ACS_SSSS", (ACS_PLUS)); |
---|
2481 | n/a | |
---|
2482 | n/a | /* The following are never available with strict SYSV curses */ |
---|
2483 | n/a | #ifdef ACS_S3 |
---|
2484 | n/a | SetDictInt("ACS_S3", (ACS_S3)); |
---|
2485 | n/a | #endif |
---|
2486 | n/a | #ifdef ACS_S7 |
---|
2487 | n/a | SetDictInt("ACS_S7", (ACS_S7)); |
---|
2488 | n/a | #endif |
---|
2489 | n/a | #ifdef ACS_LEQUAL |
---|
2490 | n/a | SetDictInt("ACS_LEQUAL", (ACS_LEQUAL)); |
---|
2491 | n/a | #endif |
---|
2492 | n/a | #ifdef ACS_GEQUAL |
---|
2493 | n/a | SetDictInt("ACS_GEQUAL", (ACS_GEQUAL)); |
---|
2494 | n/a | #endif |
---|
2495 | n/a | #ifdef ACS_PI |
---|
2496 | n/a | SetDictInt("ACS_PI", (ACS_PI)); |
---|
2497 | n/a | #endif |
---|
2498 | n/a | #ifdef ACS_NEQUAL |
---|
2499 | n/a | SetDictInt("ACS_NEQUAL", (ACS_NEQUAL)); |
---|
2500 | n/a | #endif |
---|
2501 | n/a | #ifdef ACS_STERLING |
---|
2502 | n/a | SetDictInt("ACS_STERLING", (ACS_STERLING)); |
---|
2503 | n/a | #endif |
---|
2504 | n/a | |
---|
2505 | n/a | SetDictInt("LINES", LINES); |
---|
2506 | n/a | SetDictInt("COLS", COLS); |
---|
2507 | n/a | |
---|
2508 | n/a | winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL); |
---|
2509 | n/a | screen_encoding = winobj->encoding; |
---|
2510 | n/a | return (PyObject *)winobj; |
---|
2511 | n/a | } |
---|
2512 | n/a | |
---|
2513 | n/a | static PyObject * |
---|
2514 | n/a | PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds) |
---|
2515 | n/a | { |
---|
2516 | n/a | int fd = -1; |
---|
2517 | n/a | int err; |
---|
2518 | n/a | char* termstr = NULL; |
---|
2519 | n/a | |
---|
2520 | n/a | static char *kwlist[] = {"term", "fd", NULL}; |
---|
2521 | n/a | |
---|
2522 | n/a | if (!PyArg_ParseTupleAndKeywords( |
---|
2523 | n/a | args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) { |
---|
2524 | n/a | return NULL; |
---|
2525 | n/a | } |
---|
2526 | n/a | |
---|
2527 | n/a | if (fd == -1) { |
---|
2528 | n/a | PyObject* sys_stdout; |
---|
2529 | n/a | |
---|
2530 | n/a | sys_stdout = PySys_GetObject("stdout"); |
---|
2531 | n/a | |
---|
2532 | n/a | if (sys_stdout == NULL || sys_stdout == Py_None) { |
---|
2533 | n/a | PyErr_SetString( |
---|
2534 | n/a | PyCursesError, |
---|
2535 | n/a | "lost sys.stdout"); |
---|
2536 | n/a | return NULL; |
---|
2537 | n/a | } |
---|
2538 | n/a | |
---|
2539 | n/a | fd = PyObject_AsFileDescriptor(sys_stdout); |
---|
2540 | n/a | |
---|
2541 | n/a | if (fd == -1) { |
---|
2542 | n/a | return NULL; |
---|
2543 | n/a | } |
---|
2544 | n/a | } |
---|
2545 | n/a | |
---|
2546 | n/a | if (!initialised_setupterm && setupterm(termstr,fd,&err) == ERR) { |
---|
2547 | n/a | char* s = "setupterm: unknown error"; |
---|
2548 | n/a | |
---|
2549 | n/a | if (err == 0) { |
---|
2550 | n/a | s = "setupterm: could not find terminal"; |
---|
2551 | n/a | } else if (err == -1) { |
---|
2552 | n/a | s = "setupterm: could not find terminfo database"; |
---|
2553 | n/a | } |
---|
2554 | n/a | |
---|
2555 | n/a | PyErr_SetString(PyCursesError,s); |
---|
2556 | n/a | return NULL; |
---|
2557 | n/a | } |
---|
2558 | n/a | |
---|
2559 | n/a | initialised_setupterm = TRUE; |
---|
2560 | n/a | |
---|
2561 | n/a | Py_RETURN_NONE; |
---|
2562 | n/a | } |
---|
2563 | n/a | |
---|
2564 | n/a | static PyObject * |
---|
2565 | n/a | PyCurses_IntrFlush(PyObject *self, PyObject *args) |
---|
2566 | n/a | { |
---|
2567 | n/a | int ch; |
---|
2568 | n/a | |
---|
2569 | n/a | PyCursesInitialised; |
---|
2570 | n/a | |
---|
2571 | n/a | switch(PyTuple_Size(args)) { |
---|
2572 | n/a | case 1: |
---|
2573 | n/a | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL; |
---|
2574 | n/a | break; |
---|
2575 | n/a | default: |
---|
2576 | n/a | PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument"); |
---|
2577 | n/a | return NULL; |
---|
2578 | n/a | } |
---|
2579 | n/a | |
---|
2580 | n/a | return PyCursesCheckERR(intrflush(NULL,ch), "intrflush"); |
---|
2581 | n/a | } |
---|
2582 | n/a | |
---|
2583 | n/a | #ifdef HAVE_CURSES_IS_TERM_RESIZED |
---|
2584 | n/a | static PyObject * |
---|
2585 | n/a | PyCurses_Is_Term_Resized(PyObject *self, PyObject *args) |
---|
2586 | n/a | { |
---|
2587 | n/a | int lines; |
---|
2588 | n/a | int columns; |
---|
2589 | n/a | int result; |
---|
2590 | n/a | |
---|
2591 | n/a | PyCursesInitialised; |
---|
2592 | n/a | |
---|
2593 | n/a | if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns)) |
---|
2594 | n/a | return NULL; |
---|
2595 | n/a | result = is_term_resized(lines, columns); |
---|
2596 | n/a | if (result == TRUE) { |
---|
2597 | n/a | Py_RETURN_TRUE; |
---|
2598 | n/a | } else { |
---|
2599 | n/a | Py_RETURN_FALSE; |
---|
2600 | n/a | } |
---|
2601 | n/a | } |
---|
2602 | n/a | #endif /* HAVE_CURSES_IS_TERM_RESIZED */ |
---|
2603 | n/a | |
---|
2604 | n/a | #if !defined(__NetBSD__) |
---|
2605 | n/a | static PyObject * |
---|
2606 | n/a | PyCurses_KeyName(PyObject *self, PyObject *args) |
---|
2607 | n/a | { |
---|
2608 | n/a | const char *knp; |
---|
2609 | n/a | int ch; |
---|
2610 | n/a | |
---|
2611 | n/a | PyCursesInitialised; |
---|
2612 | n/a | |
---|
2613 | n/a | if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; |
---|
2614 | n/a | |
---|
2615 | n/a | if (ch < 0) { |
---|
2616 | n/a | PyErr_SetString(PyExc_ValueError, "invalid key number"); |
---|
2617 | n/a | return NULL; |
---|
2618 | n/a | } |
---|
2619 | n/a | knp = keyname(ch); |
---|
2620 | n/a | |
---|
2621 | n/a | return PyBytes_FromString((knp == NULL) ? "" : knp); |
---|
2622 | n/a | } |
---|
2623 | n/a | #endif |
---|
2624 | n/a | |
---|
2625 | n/a | static PyObject * |
---|
2626 | n/a | PyCurses_KillChar(PyObject *self) |
---|
2627 | n/a | { |
---|
2628 | n/a | char ch; |
---|
2629 | n/a | |
---|
2630 | n/a | ch = killchar(); |
---|
2631 | n/a | |
---|
2632 | n/a | return PyBytes_FromStringAndSize(&ch, 1); |
---|
2633 | n/a | } |
---|
2634 | n/a | |
---|
2635 | n/a | static PyObject * |
---|
2636 | n/a | PyCurses_Meta(PyObject *self, PyObject *args) |
---|
2637 | n/a | { |
---|
2638 | n/a | int ch; |
---|
2639 | n/a | |
---|
2640 | n/a | PyCursesInitialised; |
---|
2641 | n/a | |
---|
2642 | n/a | switch(PyTuple_Size(args)) { |
---|
2643 | n/a | case 1: |
---|
2644 | n/a | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL; |
---|
2645 | n/a | break; |
---|
2646 | n/a | default: |
---|
2647 | n/a | PyErr_SetString(PyExc_TypeError, "meta requires 1 argument"); |
---|
2648 | n/a | return NULL; |
---|
2649 | n/a | } |
---|
2650 | n/a | |
---|
2651 | n/a | return PyCursesCheckERR(meta(stdscr, ch), "meta"); |
---|
2652 | n/a | } |
---|
2653 | n/a | |
---|
2654 | n/a | #ifdef NCURSES_MOUSE_VERSION |
---|
2655 | n/a | static PyObject * |
---|
2656 | n/a | PyCurses_MouseInterval(PyObject *self, PyObject *args) |
---|
2657 | n/a | { |
---|
2658 | n/a | int interval; |
---|
2659 | n/a | PyCursesInitialised; |
---|
2660 | n/a | |
---|
2661 | n/a | if (!PyArg_ParseTuple(args,"i;interval",&interval)) |
---|
2662 | n/a | return NULL; |
---|
2663 | n/a | return PyCursesCheckERR(mouseinterval(interval), "mouseinterval"); |
---|
2664 | n/a | } |
---|
2665 | n/a | |
---|
2666 | n/a | static PyObject * |
---|
2667 | n/a | PyCurses_MouseMask(PyObject *self, PyObject *args) |
---|
2668 | n/a | { |
---|
2669 | n/a | int newmask; |
---|
2670 | n/a | mmask_t oldmask, availmask; |
---|
2671 | n/a | |
---|
2672 | n/a | PyCursesInitialised; |
---|
2673 | n/a | if (!PyArg_ParseTuple(args,"i;mousemask",&newmask)) |
---|
2674 | n/a | return NULL; |
---|
2675 | n/a | availmask = mousemask(newmask, &oldmask); |
---|
2676 | n/a | return Py_BuildValue("(ll)", (long)availmask, (long)oldmask); |
---|
2677 | n/a | } |
---|
2678 | n/a | #endif |
---|
2679 | n/a | |
---|
2680 | n/a | static PyObject * |
---|
2681 | n/a | PyCurses_Napms(PyObject *self, PyObject *args) |
---|
2682 | n/a | { |
---|
2683 | n/a | int ms; |
---|
2684 | n/a | |
---|
2685 | n/a | PyCursesInitialised; |
---|
2686 | n/a | if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL; |
---|
2687 | n/a | |
---|
2688 | n/a | return Py_BuildValue("i", napms(ms)); |
---|
2689 | n/a | } |
---|
2690 | n/a | |
---|
2691 | n/a | |
---|
2692 | n/a | static PyObject * |
---|
2693 | n/a | PyCurses_NewPad(PyObject *self, PyObject *args) |
---|
2694 | n/a | { |
---|
2695 | n/a | WINDOW *win; |
---|
2696 | n/a | int nlines, ncols; |
---|
2697 | n/a | |
---|
2698 | n/a | PyCursesInitialised; |
---|
2699 | n/a | |
---|
2700 | n/a | if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL; |
---|
2701 | n/a | |
---|
2702 | n/a | win = newpad(nlines, ncols); |
---|
2703 | n/a | |
---|
2704 | n/a | if (win == NULL) { |
---|
2705 | n/a | PyErr_SetString(PyCursesError, catchall_NULL); |
---|
2706 | n/a | return NULL; |
---|
2707 | n/a | } |
---|
2708 | n/a | |
---|
2709 | n/a | return (PyObject *)PyCursesWindow_New(win, NULL); |
---|
2710 | n/a | } |
---|
2711 | n/a | |
---|
2712 | n/a | static PyObject * |
---|
2713 | n/a | PyCurses_NewWindow(PyObject *self, PyObject *args) |
---|
2714 | n/a | { |
---|
2715 | n/a | WINDOW *win; |
---|
2716 | n/a | int nlines, ncols, begin_y=0, begin_x=0; |
---|
2717 | n/a | |
---|
2718 | n/a | PyCursesInitialised; |
---|
2719 | n/a | |
---|
2720 | n/a | switch (PyTuple_Size(args)) { |
---|
2721 | n/a | case 2: |
---|
2722 | n/a | if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) |
---|
2723 | n/a | return NULL; |
---|
2724 | n/a | break; |
---|
2725 | n/a | case 4: |
---|
2726 | n/a | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", |
---|
2727 | n/a | &nlines,&ncols,&begin_y,&begin_x)) |
---|
2728 | n/a | return NULL; |
---|
2729 | n/a | break; |
---|
2730 | n/a | default: |
---|
2731 | n/a | PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments"); |
---|
2732 | n/a | return NULL; |
---|
2733 | n/a | } |
---|
2734 | n/a | |
---|
2735 | n/a | win = newwin(nlines,ncols,begin_y,begin_x); |
---|
2736 | n/a | if (win == NULL) { |
---|
2737 | n/a | PyErr_SetString(PyCursesError, catchall_NULL); |
---|
2738 | n/a | return NULL; |
---|
2739 | n/a | } |
---|
2740 | n/a | |
---|
2741 | n/a | return (PyObject *)PyCursesWindow_New(win, NULL); |
---|
2742 | n/a | } |
---|
2743 | n/a | |
---|
2744 | n/a | static PyObject * |
---|
2745 | n/a | PyCurses_Pair_Content(PyObject *self, PyObject *args) |
---|
2746 | n/a | { |
---|
2747 | n/a | short pair,f,b; |
---|
2748 | n/a | |
---|
2749 | n/a | PyCursesInitialised; |
---|
2750 | n/a | PyCursesInitialisedColor; |
---|
2751 | n/a | |
---|
2752 | n/a | switch(PyTuple_Size(args)) { |
---|
2753 | n/a | case 1: |
---|
2754 | n/a | if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL; |
---|
2755 | n/a | break; |
---|
2756 | n/a | default: |
---|
2757 | n/a | PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument"); |
---|
2758 | n/a | return NULL; |
---|
2759 | n/a | } |
---|
2760 | n/a | |
---|
2761 | n/a | if (pair_content(pair, &f, &b)==ERR) { |
---|
2762 | n/a | PyErr_SetString(PyCursesError, |
---|
2763 | n/a | "Argument 1 was out of range. (1..COLOR_PAIRS-1)"); |
---|
2764 | n/a | return NULL; |
---|
2765 | n/a | } |
---|
2766 | n/a | |
---|
2767 | n/a | return Py_BuildValue("(ii)", f, b); |
---|
2768 | n/a | } |
---|
2769 | n/a | |
---|
2770 | n/a | static PyObject * |
---|
2771 | n/a | PyCurses_pair_number(PyObject *self, PyObject *args) |
---|
2772 | n/a | { |
---|
2773 | n/a | int n; |
---|
2774 | n/a | |
---|
2775 | n/a | PyCursesInitialised; |
---|
2776 | n/a | PyCursesInitialisedColor; |
---|
2777 | n/a | |
---|
2778 | n/a | switch(PyTuple_Size(args)) { |
---|
2779 | n/a | case 1: |
---|
2780 | n/a | if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL; |
---|
2781 | n/a | break; |
---|
2782 | n/a | default: |
---|
2783 | n/a | PyErr_SetString(PyExc_TypeError, |
---|
2784 | n/a | "pair_number requires 1 argument"); |
---|
2785 | n/a | return NULL; |
---|
2786 | n/a | } |
---|
2787 | n/a | |
---|
2788 | n/a | return PyLong_FromLong((long) ((n & A_COLOR) >> 8)); |
---|
2789 | n/a | } |
---|
2790 | n/a | |
---|
2791 | n/a | static PyObject * |
---|
2792 | n/a | PyCurses_Putp(PyObject *self, PyObject *args) |
---|
2793 | n/a | { |
---|
2794 | n/a | char *str; |
---|
2795 | n/a | |
---|
2796 | n/a | if (!PyArg_ParseTuple(args,"y;str", &str)) |
---|
2797 | n/a | return NULL; |
---|
2798 | n/a | return PyCursesCheckERR(putp(str), "putp"); |
---|
2799 | n/a | } |
---|
2800 | n/a | |
---|
2801 | n/a | static PyObject * |
---|
2802 | n/a | PyCurses_QiFlush(PyObject *self, PyObject *args) |
---|
2803 | n/a | { |
---|
2804 | n/a | int flag = 0; |
---|
2805 | n/a | |
---|
2806 | n/a | PyCursesInitialised; |
---|
2807 | n/a | |
---|
2808 | n/a | switch(PyTuple_Size(args)) { |
---|
2809 | n/a | case 0: |
---|
2810 | n/a | qiflush(); |
---|
2811 | n/a | Py_RETURN_NONE; |
---|
2812 | n/a | case 1: |
---|
2813 | n/a | if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; |
---|
2814 | n/a | if (flag) qiflush(); |
---|
2815 | n/a | else noqiflush(); |
---|
2816 | n/a | Py_RETURN_NONE; |
---|
2817 | n/a | default: |
---|
2818 | n/a | PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments"); |
---|
2819 | n/a | return NULL; |
---|
2820 | n/a | } |
---|
2821 | n/a | } |
---|
2822 | n/a | |
---|
2823 | n/a | /* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES |
---|
2824 | n/a | * and _curses.COLS */ |
---|
2825 | n/a | #if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM) |
---|
2826 | n/a | static int |
---|
2827 | n/a | update_lines_cols(void) |
---|
2828 | n/a | { |
---|
2829 | n/a | PyObject *o; |
---|
2830 | n/a | PyObject *m = PyImport_ImportModuleNoBlock("curses"); |
---|
2831 | n/a | _Py_IDENTIFIER(LINES); |
---|
2832 | n/a | _Py_IDENTIFIER(COLS); |
---|
2833 | n/a | |
---|
2834 | n/a | if (!m) |
---|
2835 | n/a | return 0; |
---|
2836 | n/a | |
---|
2837 | n/a | o = PyLong_FromLong(LINES); |
---|
2838 | n/a | if (!o) { |
---|
2839 | n/a | Py_DECREF(m); |
---|
2840 | n/a | return 0; |
---|
2841 | n/a | } |
---|
2842 | n/a | if (_PyObject_SetAttrId(m, &PyId_LINES, o)) { |
---|
2843 | n/a | Py_DECREF(m); |
---|
2844 | n/a | Py_DECREF(o); |
---|
2845 | n/a | return 0; |
---|
2846 | n/a | } |
---|
2847 | n/a | /* PyId_LINES.object will be initialized here. */ |
---|
2848 | n/a | if (PyDict_SetItem(ModDict, PyId_LINES.object, o)) { |
---|
2849 | n/a | Py_DECREF(m); |
---|
2850 | n/a | Py_DECREF(o); |
---|
2851 | n/a | return 0; |
---|
2852 | n/a | } |
---|
2853 | n/a | Py_DECREF(o); |
---|
2854 | n/a | o = PyLong_FromLong(COLS); |
---|
2855 | n/a | if (!o) { |
---|
2856 | n/a | Py_DECREF(m); |
---|
2857 | n/a | return 0; |
---|
2858 | n/a | } |
---|
2859 | n/a | if (_PyObject_SetAttrId(m, &PyId_COLS, o)) { |
---|
2860 | n/a | Py_DECREF(m); |
---|
2861 | n/a | Py_DECREF(o); |
---|
2862 | n/a | return 0; |
---|
2863 | n/a | } |
---|
2864 | n/a | if (PyDict_SetItem(ModDict, PyId_COLS.object, o)) { |
---|
2865 | n/a | Py_DECREF(m); |
---|
2866 | n/a | Py_DECREF(o); |
---|
2867 | n/a | return 0; |
---|
2868 | n/a | } |
---|
2869 | n/a | Py_DECREF(o); |
---|
2870 | n/a | Py_DECREF(m); |
---|
2871 | n/a | return 1; |
---|
2872 | n/a | } |
---|
2873 | n/a | |
---|
2874 | n/a | static PyObject * |
---|
2875 | n/a | PyCurses_update_lines_cols(PyObject *self) |
---|
2876 | n/a | { |
---|
2877 | n/a | return PyLong_FromLong((long) update_lines_cols()); |
---|
2878 | n/a | } |
---|
2879 | n/a | |
---|
2880 | n/a | #endif |
---|
2881 | n/a | |
---|
2882 | n/a | #ifdef HAVE_CURSES_RESIZETERM |
---|
2883 | n/a | static PyObject * |
---|
2884 | n/a | PyCurses_ResizeTerm(PyObject *self, PyObject *args) |
---|
2885 | n/a | { |
---|
2886 | n/a | int lines; |
---|
2887 | n/a | int columns; |
---|
2888 | n/a | PyObject *result; |
---|
2889 | n/a | |
---|
2890 | n/a | PyCursesInitialised; |
---|
2891 | n/a | |
---|
2892 | n/a | if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns)) |
---|
2893 | n/a | return NULL; |
---|
2894 | n/a | |
---|
2895 | n/a | result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm"); |
---|
2896 | n/a | if (!result) |
---|
2897 | n/a | return NULL; |
---|
2898 | n/a | if (!update_lines_cols()) |
---|
2899 | n/a | return NULL; |
---|
2900 | n/a | return result; |
---|
2901 | n/a | } |
---|
2902 | n/a | |
---|
2903 | n/a | #endif |
---|
2904 | n/a | |
---|
2905 | n/a | #ifdef HAVE_CURSES_RESIZE_TERM |
---|
2906 | n/a | static PyObject * |
---|
2907 | n/a | PyCurses_Resize_Term(PyObject *self, PyObject *args) |
---|
2908 | n/a | { |
---|
2909 | n/a | int lines; |
---|
2910 | n/a | int columns; |
---|
2911 | n/a | |
---|
2912 | n/a | PyObject *result; |
---|
2913 | n/a | |
---|
2914 | n/a | PyCursesInitialised; |
---|
2915 | n/a | |
---|
2916 | n/a | if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns)) |
---|
2917 | n/a | return NULL; |
---|
2918 | n/a | |
---|
2919 | n/a | result = PyCursesCheckERR(resize_term(lines, columns), "resize_term"); |
---|
2920 | n/a | if (!result) |
---|
2921 | n/a | return NULL; |
---|
2922 | n/a | if (!update_lines_cols()) |
---|
2923 | n/a | return NULL; |
---|
2924 | n/a | return result; |
---|
2925 | n/a | } |
---|
2926 | n/a | #endif /* HAVE_CURSES_RESIZE_TERM */ |
---|
2927 | n/a | |
---|
2928 | n/a | static PyObject * |
---|
2929 | n/a | PyCurses_setsyx(PyObject *self, PyObject *args) |
---|
2930 | n/a | { |
---|
2931 | n/a | int y,x; |
---|
2932 | n/a | |
---|
2933 | n/a | PyCursesInitialised; |
---|
2934 | n/a | |
---|
2935 | n/a | if (PyTuple_Size(args)!=2) { |
---|
2936 | n/a | PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments"); |
---|
2937 | n/a | return NULL; |
---|
2938 | n/a | } |
---|
2939 | n/a | |
---|
2940 | n/a | if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL; |
---|
2941 | n/a | |
---|
2942 | n/a | setsyx(y,x); |
---|
2943 | n/a | |
---|
2944 | n/a | Py_RETURN_NONE; |
---|
2945 | n/a | } |
---|
2946 | n/a | |
---|
2947 | n/a | static PyObject * |
---|
2948 | n/a | PyCurses_Start_Color(PyObject *self) |
---|
2949 | n/a | { |
---|
2950 | n/a | int code; |
---|
2951 | n/a | PyObject *c, *cp; |
---|
2952 | n/a | |
---|
2953 | n/a | PyCursesInitialised; |
---|
2954 | n/a | |
---|
2955 | n/a | code = start_color(); |
---|
2956 | n/a | if (code != ERR) { |
---|
2957 | n/a | initialisedcolors = TRUE; |
---|
2958 | n/a | c = PyLong_FromLong((long) COLORS); |
---|
2959 | n/a | if (c == NULL) |
---|
2960 | n/a | return NULL; |
---|
2961 | n/a | PyDict_SetItemString(ModDict, "COLORS", c); |
---|
2962 | n/a | Py_DECREF(c); |
---|
2963 | n/a | cp = PyLong_FromLong((long) COLOR_PAIRS); |
---|
2964 | n/a | if (cp == NULL) |
---|
2965 | n/a | return NULL; |
---|
2966 | n/a | PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp); |
---|
2967 | n/a | Py_DECREF(cp); |
---|
2968 | n/a | Py_RETURN_NONE; |
---|
2969 | n/a | } else { |
---|
2970 | n/a | PyErr_SetString(PyCursesError, "start_color() returned ERR"); |
---|
2971 | n/a | return NULL; |
---|
2972 | n/a | } |
---|
2973 | n/a | } |
---|
2974 | n/a | |
---|
2975 | n/a | static PyObject * |
---|
2976 | n/a | PyCurses_tigetflag(PyObject *self, PyObject *args) |
---|
2977 | n/a | { |
---|
2978 | n/a | char *capname; |
---|
2979 | n/a | |
---|
2980 | n/a | PyCursesSetupTermCalled; |
---|
2981 | n/a | |
---|
2982 | n/a | if (!PyArg_ParseTuple(args, "s", &capname)) |
---|
2983 | n/a | return NULL; |
---|
2984 | n/a | |
---|
2985 | n/a | return PyLong_FromLong( (long) tigetflag( capname ) ); |
---|
2986 | n/a | } |
---|
2987 | n/a | |
---|
2988 | n/a | static PyObject * |
---|
2989 | n/a | PyCurses_tigetnum(PyObject *self, PyObject *args) |
---|
2990 | n/a | { |
---|
2991 | n/a | char *capname; |
---|
2992 | n/a | |
---|
2993 | n/a | PyCursesSetupTermCalled; |
---|
2994 | n/a | |
---|
2995 | n/a | if (!PyArg_ParseTuple(args, "s", &capname)) |
---|
2996 | n/a | return NULL; |
---|
2997 | n/a | |
---|
2998 | n/a | return PyLong_FromLong( (long) tigetnum( capname ) ); |
---|
2999 | n/a | } |
---|
3000 | n/a | |
---|
3001 | n/a | static PyObject * |
---|
3002 | n/a | PyCurses_tigetstr(PyObject *self, PyObject *args) |
---|
3003 | n/a | { |
---|
3004 | n/a | char *capname; |
---|
3005 | n/a | |
---|
3006 | n/a | PyCursesSetupTermCalled; |
---|
3007 | n/a | |
---|
3008 | n/a | if (!PyArg_ParseTuple(args, "s", &capname)) |
---|
3009 | n/a | return NULL; |
---|
3010 | n/a | |
---|
3011 | n/a | capname = tigetstr( capname ); |
---|
3012 | n/a | if (capname == 0 || capname == (char*) -1) { |
---|
3013 | n/a | Py_RETURN_NONE; |
---|
3014 | n/a | } |
---|
3015 | n/a | return PyBytes_FromString( capname ); |
---|
3016 | n/a | } |
---|
3017 | n/a | |
---|
3018 | n/a | static PyObject * |
---|
3019 | n/a | PyCurses_tparm(PyObject *self, PyObject *args) |
---|
3020 | n/a | { |
---|
3021 | n/a | char* fmt; |
---|
3022 | n/a | char* result = NULL; |
---|
3023 | n/a | int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0; |
---|
3024 | n/a | |
---|
3025 | n/a | PyCursesSetupTermCalled; |
---|
3026 | n/a | |
---|
3027 | n/a | if (!PyArg_ParseTuple(args, "y|iiiiiiiii:tparm", |
---|
3028 | n/a | &fmt, &i1, &i2, &i3, &i4, |
---|
3029 | n/a | &i5, &i6, &i7, &i8, &i9)) { |
---|
3030 | n/a | return NULL; |
---|
3031 | n/a | } |
---|
3032 | n/a | |
---|
3033 | n/a | result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9); |
---|
3034 | n/a | if (!result) { |
---|
3035 | n/a | PyErr_SetString(PyCursesError, "tparm() returned NULL"); |
---|
3036 | n/a | return NULL; |
---|
3037 | n/a | } |
---|
3038 | n/a | |
---|
3039 | n/a | return PyBytes_FromString(result); |
---|
3040 | n/a | } |
---|
3041 | n/a | |
---|
3042 | n/a | static PyObject * |
---|
3043 | n/a | PyCurses_TypeAhead(PyObject *self, PyObject *args) |
---|
3044 | n/a | { |
---|
3045 | n/a | int fd; |
---|
3046 | n/a | |
---|
3047 | n/a | PyCursesInitialised; |
---|
3048 | n/a | |
---|
3049 | n/a | if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL; |
---|
3050 | n/a | |
---|
3051 | n/a | return PyCursesCheckERR(typeahead( fd ), "typeahead"); |
---|
3052 | n/a | } |
---|
3053 | n/a | |
---|
3054 | n/a | static PyObject * |
---|
3055 | n/a | PyCurses_UnCtrl(PyObject *self, PyObject *args) |
---|
3056 | n/a | { |
---|
3057 | n/a | PyObject *temp; |
---|
3058 | n/a | chtype ch; |
---|
3059 | n/a | |
---|
3060 | n/a | PyCursesInitialised; |
---|
3061 | n/a | |
---|
3062 | n/a | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL; |
---|
3063 | n/a | |
---|
3064 | n/a | if (!PyCurses_ConvertToChtype(NULL, temp, &ch)) |
---|
3065 | n/a | return NULL; |
---|
3066 | n/a | |
---|
3067 | n/a | return PyBytes_FromString(unctrl(ch)); |
---|
3068 | n/a | } |
---|
3069 | n/a | |
---|
3070 | n/a | static PyObject * |
---|
3071 | n/a | PyCurses_UngetCh(PyObject *self, PyObject *args) |
---|
3072 | n/a | { |
---|
3073 | n/a | PyObject *temp; |
---|
3074 | n/a | chtype ch; |
---|
3075 | n/a | |
---|
3076 | n/a | PyCursesInitialised; |
---|
3077 | n/a | |
---|
3078 | n/a | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) |
---|
3079 | n/a | return NULL; |
---|
3080 | n/a | |
---|
3081 | n/a | if (!PyCurses_ConvertToChtype(NULL, temp, &ch)) |
---|
3082 | n/a | return NULL; |
---|
3083 | n/a | |
---|
3084 | n/a | return PyCursesCheckERR(ungetch(ch), "ungetch"); |
---|
3085 | n/a | } |
---|
3086 | n/a | |
---|
3087 | n/a | #ifdef HAVE_NCURSESW |
---|
3088 | n/a | /* Convert an object to a character (wchar_t): |
---|
3089 | n/a | |
---|
3090 | n/a | - int |
---|
3091 | n/a | - str of length 1 |
---|
3092 | n/a | |
---|
3093 | n/a | Return 1 on success, 0 on error. */ |
---|
3094 | n/a | static int |
---|
3095 | n/a | PyCurses_ConvertToWchar_t(PyObject *obj, |
---|
3096 | n/a | wchar_t *wch) |
---|
3097 | n/a | { |
---|
3098 | n/a | if (PyUnicode_Check(obj)) { |
---|
3099 | n/a | wchar_t buffer[2]; |
---|
3100 | n/a | if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) { |
---|
3101 | n/a | PyErr_Format(PyExc_TypeError, |
---|
3102 | n/a | "expect bytes or str of length 1, or int, " |
---|
3103 | n/a | "got a str of length %zi", |
---|
3104 | n/a | PyUnicode_GET_LENGTH(obj)); |
---|
3105 | n/a | return 0; |
---|
3106 | n/a | } |
---|
3107 | n/a | *wch = buffer[0]; |
---|
3108 | n/a | return 2; |
---|
3109 | n/a | } |
---|
3110 | n/a | else if (PyLong_CheckExact(obj)) { |
---|
3111 | n/a | long value; |
---|
3112 | n/a | int overflow; |
---|
3113 | n/a | value = PyLong_AsLongAndOverflow(obj, &overflow); |
---|
3114 | n/a | if (overflow) { |
---|
3115 | n/a | PyErr_SetString(PyExc_OverflowError, |
---|
3116 | n/a | "int doesn't fit in long"); |
---|
3117 | n/a | return 0; |
---|
3118 | n/a | } |
---|
3119 | n/a | *wch = (wchar_t)value; |
---|
3120 | n/a | if ((long)*wch != value) { |
---|
3121 | n/a | PyErr_Format(PyExc_OverflowError, |
---|
3122 | n/a | "character doesn't fit in wchar_t"); |
---|
3123 | n/a | return 0; |
---|
3124 | n/a | } |
---|
3125 | n/a | return 1; |
---|
3126 | n/a | } |
---|
3127 | n/a | else { |
---|
3128 | n/a | PyErr_Format(PyExc_TypeError, |
---|
3129 | n/a | "expect bytes or str of length 1, or int, got %s", |
---|
3130 | n/a | Py_TYPE(obj)->tp_name); |
---|
3131 | n/a | return 0; |
---|
3132 | n/a | } |
---|
3133 | n/a | } |
---|
3134 | n/a | |
---|
3135 | n/a | static PyObject * |
---|
3136 | n/a | PyCurses_Unget_Wch(PyObject *self, PyObject *args) |
---|
3137 | n/a | { |
---|
3138 | n/a | PyObject *obj; |
---|
3139 | n/a | wchar_t wch; |
---|
3140 | n/a | |
---|
3141 | n/a | PyCursesInitialised; |
---|
3142 | n/a | |
---|
3143 | n/a | if (!PyArg_ParseTuple(args,"O", &obj)) |
---|
3144 | n/a | return NULL; |
---|
3145 | n/a | |
---|
3146 | n/a | if (!PyCurses_ConvertToWchar_t(obj, &wch)) |
---|
3147 | n/a | return NULL; |
---|
3148 | n/a | return PyCursesCheckERR(unget_wch(wch), "unget_wch"); |
---|
3149 | n/a | } |
---|
3150 | n/a | #endif |
---|
3151 | n/a | |
---|
3152 | n/a | static PyObject * |
---|
3153 | n/a | PyCurses_Use_Env(PyObject *self, PyObject *args) |
---|
3154 | n/a | { |
---|
3155 | n/a | int flag; |
---|
3156 | n/a | |
---|
3157 | n/a | switch(PyTuple_Size(args)) { |
---|
3158 | n/a | case 1: |
---|
3159 | n/a | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag)) |
---|
3160 | n/a | return NULL; |
---|
3161 | n/a | break; |
---|
3162 | n/a | default: |
---|
3163 | n/a | PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument"); |
---|
3164 | n/a | return NULL; |
---|
3165 | n/a | } |
---|
3166 | n/a | use_env(flag); |
---|
3167 | n/a | Py_RETURN_NONE; |
---|
3168 | n/a | } |
---|
3169 | n/a | |
---|
3170 | n/a | #ifndef STRICT_SYSV_CURSES |
---|
3171 | n/a | static PyObject * |
---|
3172 | n/a | PyCurses_Use_Default_Colors(PyObject *self) |
---|
3173 | n/a | { |
---|
3174 | n/a | int code; |
---|
3175 | n/a | |
---|
3176 | n/a | PyCursesInitialised; |
---|
3177 | n/a | PyCursesInitialisedColor; |
---|
3178 | n/a | |
---|
3179 | n/a | code = use_default_colors(); |
---|
3180 | n/a | if (code != ERR) { |
---|
3181 | n/a | Py_RETURN_NONE; |
---|
3182 | n/a | } else { |
---|
3183 | n/a | PyErr_SetString(PyCursesError, "use_default_colors() returned ERR"); |
---|
3184 | n/a | return NULL; |
---|
3185 | n/a | } |
---|
3186 | n/a | } |
---|
3187 | n/a | #endif /* STRICT_SYSV_CURSES */ |
---|
3188 | n/a | |
---|
3189 | n/a | /* List of functions defined in the module */ |
---|
3190 | n/a | |
---|
3191 | n/a | static PyMethodDef PyCurses_methods[] = { |
---|
3192 | n/a | {"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS}, |
---|
3193 | n/a | {"beep", (PyCFunction)PyCurses_beep, METH_NOARGS}, |
---|
3194 | n/a | {"can_change_color", (PyCFunction)PyCurses_can_change_color, METH_NOARGS}, |
---|
3195 | n/a | {"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS}, |
---|
3196 | n/a | {"color_content", (PyCFunction)PyCurses_Color_Content, METH_VARARGS}, |
---|
3197 | n/a | {"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS}, |
---|
3198 | n/a | {"curs_set", (PyCFunction)PyCurses_Curs_Set, METH_VARARGS}, |
---|
3199 | n/a | {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS}, |
---|
3200 | n/a | {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS}, |
---|
3201 | n/a | {"delay_output", (PyCFunction)PyCurses_Delay_Output, METH_VARARGS}, |
---|
3202 | n/a | {"doupdate", (PyCFunction)PyCurses_doupdate, METH_NOARGS}, |
---|
3203 | n/a | {"echo", (PyCFunction)PyCurses_echo, METH_VARARGS}, |
---|
3204 | n/a | {"endwin", (PyCFunction)PyCurses_endwin, METH_NOARGS}, |
---|
3205 | n/a | {"erasechar", (PyCFunction)PyCurses_EraseChar, METH_NOARGS}, |
---|
3206 | n/a | {"filter", (PyCFunction)PyCurses_filter, METH_NOARGS}, |
---|
3207 | n/a | {"flash", (PyCFunction)PyCurses_flash, METH_NOARGS}, |
---|
3208 | n/a | {"flushinp", (PyCFunction)PyCurses_flushinp, METH_NOARGS}, |
---|
3209 | n/a | #ifdef NCURSES_MOUSE_VERSION |
---|
3210 | n/a | {"getmouse", (PyCFunction)PyCurses_GetMouse, METH_NOARGS}, |
---|
3211 | n/a | {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS}, |
---|
3212 | n/a | #endif |
---|
3213 | n/a | {"getsyx", (PyCFunction)PyCurses_getsyx, METH_NOARGS}, |
---|
3214 | n/a | {"getwin", (PyCFunction)PyCurses_GetWin, METH_O}, |
---|
3215 | n/a | {"has_colors", (PyCFunction)PyCurses_has_colors, METH_NOARGS}, |
---|
3216 | n/a | {"has_ic", (PyCFunction)PyCurses_has_ic, METH_NOARGS}, |
---|
3217 | n/a | {"has_il", (PyCFunction)PyCurses_has_il, METH_NOARGS}, |
---|
3218 | n/a | #ifndef STRICT_SYSV_CURSES |
---|
3219 | n/a | {"has_key", (PyCFunction)PyCurses_has_key, METH_VARARGS}, |
---|
3220 | n/a | #endif |
---|
3221 | n/a | {"halfdelay", (PyCFunction)PyCurses_HalfDelay, METH_VARARGS}, |
---|
3222 | n/a | {"init_color", (PyCFunction)PyCurses_Init_Color, METH_VARARGS}, |
---|
3223 | n/a | {"init_pair", (PyCFunction)PyCurses_Init_Pair, METH_VARARGS}, |
---|
3224 | n/a | {"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS}, |
---|
3225 | n/a | {"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS}, |
---|
3226 | n/a | {"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS}, |
---|
3227 | n/a | #ifdef HAVE_CURSES_IS_TERM_RESIZED |
---|
3228 | n/a | {"is_term_resized", (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS}, |
---|
3229 | n/a | #endif |
---|
3230 | n/a | #if !defined(__NetBSD__) |
---|
3231 | n/a | {"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS}, |
---|
3232 | n/a | #endif |
---|
3233 | n/a | {"killchar", (PyCFunction)PyCurses_KillChar, METH_NOARGS}, |
---|
3234 | n/a | {"longname", (PyCFunction)PyCurses_longname, METH_NOARGS}, |
---|
3235 | n/a | {"meta", (PyCFunction)PyCurses_Meta, METH_VARARGS}, |
---|
3236 | n/a | #ifdef NCURSES_MOUSE_VERSION |
---|
3237 | n/a | {"mouseinterval", (PyCFunction)PyCurses_MouseInterval, METH_VARARGS}, |
---|
3238 | n/a | {"mousemask", (PyCFunction)PyCurses_MouseMask, METH_VARARGS}, |
---|
3239 | n/a | #endif |
---|
3240 | n/a | {"napms", (PyCFunction)PyCurses_Napms, METH_VARARGS}, |
---|
3241 | n/a | {"newpad", (PyCFunction)PyCurses_NewPad, METH_VARARGS}, |
---|
3242 | n/a | {"newwin", (PyCFunction)PyCurses_NewWindow, METH_VARARGS}, |
---|
3243 | n/a | {"nl", (PyCFunction)PyCurses_nl, METH_VARARGS}, |
---|
3244 | n/a | {"nocbreak", (PyCFunction)PyCurses_nocbreak, METH_NOARGS}, |
---|
3245 | n/a | {"noecho", (PyCFunction)PyCurses_noecho, METH_NOARGS}, |
---|
3246 | n/a | {"nonl", (PyCFunction)PyCurses_nonl, METH_NOARGS}, |
---|
3247 | n/a | {"noqiflush", (PyCFunction)PyCurses_noqiflush, METH_NOARGS}, |
---|
3248 | n/a | {"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS}, |
---|
3249 | n/a | {"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS}, |
---|
3250 | n/a | {"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS}, |
---|
3251 | n/a | {"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS}, |
---|
3252 | n/a | {"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS}, |
---|
3253 | n/a | {"raw", (PyCFunction)PyCurses_raw, METH_VARARGS}, |
---|
3254 | n/a | {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS}, |
---|
3255 | n/a | {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS}, |
---|
3256 | n/a | {"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS}, |
---|
3257 | n/a | #ifdef HAVE_CURSES_RESIZETERM |
---|
3258 | n/a | {"resizeterm", (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS}, |
---|
3259 | n/a | #endif |
---|
3260 | n/a | #ifdef HAVE_CURSES_RESIZE_TERM |
---|
3261 | n/a | {"resize_term", (PyCFunction)PyCurses_Resize_Term, METH_VARARGS}, |
---|
3262 | n/a | #endif |
---|
3263 | n/a | {"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS}, |
---|
3264 | n/a | {"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS}, |
---|
3265 | n/a | {"setupterm", (PyCFunction)PyCurses_setupterm, |
---|
3266 | n/a | METH_VARARGS|METH_KEYWORDS}, |
---|
3267 | n/a | {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS}, |
---|
3268 | n/a | {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS}, |
---|
3269 | n/a | {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS}, |
---|
3270 | n/a | {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS}, |
---|
3271 | n/a | {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS}, |
---|
3272 | n/a | {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS}, |
---|
3273 | n/a | {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS}, |
---|
3274 | n/a | {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS}, |
---|
3275 | n/a | {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS}, |
---|
3276 | n/a | {"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS}, |
---|
3277 | n/a | #if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM) |
---|
3278 | n/a | {"update_lines_cols", (PyCFunction)PyCurses_update_lines_cols, METH_NOARGS}, |
---|
3279 | n/a | #endif |
---|
3280 | n/a | #ifdef HAVE_NCURSESW |
---|
3281 | n/a | {"unget_wch", (PyCFunction)PyCurses_Unget_Wch, METH_VARARGS}, |
---|
3282 | n/a | #endif |
---|
3283 | n/a | {"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS}, |
---|
3284 | n/a | #ifndef STRICT_SYSV_CURSES |
---|
3285 | n/a | {"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS}, |
---|
3286 | n/a | #endif |
---|
3287 | n/a | {NULL, NULL} /* sentinel */ |
---|
3288 | n/a | }; |
---|
3289 | n/a | |
---|
3290 | n/a | /* Initialization function for the module */ |
---|
3291 | n/a | |
---|
3292 | n/a | |
---|
3293 | n/a | static struct PyModuleDef _cursesmodule = { |
---|
3294 | n/a | PyModuleDef_HEAD_INIT, |
---|
3295 | n/a | "_curses", |
---|
3296 | n/a | NULL, |
---|
3297 | n/a | -1, |
---|
3298 | n/a | PyCurses_methods, |
---|
3299 | n/a | NULL, |
---|
3300 | n/a | NULL, |
---|
3301 | n/a | NULL, |
---|
3302 | n/a | NULL |
---|
3303 | n/a | }; |
---|
3304 | n/a | |
---|
3305 | n/a | PyMODINIT_FUNC |
---|
3306 | n/a | PyInit__curses(void) |
---|
3307 | n/a | { |
---|
3308 | n/a | PyObject *m, *d, *v, *c_api_object; |
---|
3309 | n/a | static void *PyCurses_API[PyCurses_API_pointers]; |
---|
3310 | n/a | |
---|
3311 | n/a | /* Initialize object type */ |
---|
3312 | n/a | if (PyType_Ready(&PyCursesWindow_Type) < 0) |
---|
3313 | n/a | return NULL; |
---|
3314 | n/a | |
---|
3315 | n/a | /* Initialize the C API pointer array */ |
---|
3316 | n/a | PyCurses_API[0] = (void *)&PyCursesWindow_Type; |
---|
3317 | n/a | PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled; |
---|
3318 | n/a | PyCurses_API[2] = (void *)func_PyCursesInitialised; |
---|
3319 | n/a | PyCurses_API[3] = (void *)func_PyCursesInitialisedColor; |
---|
3320 | n/a | |
---|
3321 | n/a | /* Create the module and add the functions */ |
---|
3322 | n/a | m = PyModule_Create(&_cursesmodule); |
---|
3323 | n/a | if (m == NULL) |
---|
3324 | n/a | return NULL; |
---|
3325 | n/a | |
---|
3326 | n/a | /* Add some symbolic constants to the module */ |
---|
3327 | n/a | d = PyModule_GetDict(m); |
---|
3328 | n/a | if (d == NULL) |
---|
3329 | n/a | return NULL; |
---|
3330 | n/a | ModDict = d; /* For PyCurses_InitScr to use later */ |
---|
3331 | n/a | |
---|
3332 | n/a | /* Add a capsule for the C API */ |
---|
3333 | n/a | c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, NULL); |
---|
3334 | n/a | PyDict_SetItemString(d, "_C_API", c_api_object); |
---|
3335 | n/a | Py_DECREF(c_api_object); |
---|
3336 | n/a | |
---|
3337 | n/a | /* For exception curses.error */ |
---|
3338 | n/a | PyCursesError = PyErr_NewException("_curses.error", NULL, NULL); |
---|
3339 | n/a | PyDict_SetItemString(d, "error", PyCursesError); |
---|
3340 | n/a | |
---|
3341 | n/a | /* Make the version available */ |
---|
3342 | n/a | v = PyBytes_FromString(PyCursesVersion); |
---|
3343 | n/a | PyDict_SetItemString(d, "version", v); |
---|
3344 | n/a | PyDict_SetItemString(d, "__version__", v); |
---|
3345 | n/a | Py_DECREF(v); |
---|
3346 | n/a | |
---|
3347 | n/a | SetDictInt("ERR", ERR); |
---|
3348 | n/a | SetDictInt("OK", OK); |
---|
3349 | n/a | |
---|
3350 | n/a | /* Here are some attributes you can add to chars to print */ |
---|
3351 | n/a | |
---|
3352 | n/a | SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES); |
---|
3353 | n/a | SetDictInt("A_NORMAL", A_NORMAL); |
---|
3354 | n/a | SetDictInt("A_STANDOUT", A_STANDOUT); |
---|
3355 | n/a | SetDictInt("A_UNDERLINE", A_UNDERLINE); |
---|
3356 | n/a | SetDictInt("A_REVERSE", A_REVERSE); |
---|
3357 | n/a | SetDictInt("A_BLINK", A_BLINK); |
---|
3358 | n/a | SetDictInt("A_DIM", A_DIM); |
---|
3359 | n/a | SetDictInt("A_BOLD", A_BOLD); |
---|
3360 | n/a | SetDictInt("A_ALTCHARSET", A_ALTCHARSET); |
---|
3361 | n/a | #if !defined(__NetBSD__) |
---|
3362 | n/a | SetDictInt("A_INVIS", A_INVIS); |
---|
3363 | n/a | #endif |
---|
3364 | n/a | SetDictInt("A_PROTECT", A_PROTECT); |
---|
3365 | n/a | SetDictInt("A_CHARTEXT", A_CHARTEXT); |
---|
3366 | n/a | SetDictInt("A_COLOR", A_COLOR); |
---|
3367 | n/a | |
---|
3368 | n/a | /* The following are never available with strict SYSV curses */ |
---|
3369 | n/a | #ifdef A_HORIZONTAL |
---|
3370 | n/a | SetDictInt("A_HORIZONTAL", A_HORIZONTAL); |
---|
3371 | n/a | #endif |
---|
3372 | n/a | #ifdef A_LEFT |
---|
3373 | n/a | SetDictInt("A_LEFT", A_LEFT); |
---|
3374 | n/a | #endif |
---|
3375 | n/a | #ifdef A_LOW |
---|
3376 | n/a | SetDictInt("A_LOW", A_LOW); |
---|
3377 | n/a | #endif |
---|
3378 | n/a | #ifdef A_RIGHT |
---|
3379 | n/a | SetDictInt("A_RIGHT", A_RIGHT); |
---|
3380 | n/a | #endif |
---|
3381 | n/a | #ifdef A_TOP |
---|
3382 | n/a | SetDictInt("A_TOP", A_TOP); |
---|
3383 | n/a | #endif |
---|
3384 | n/a | #ifdef A_VERTICAL |
---|
3385 | n/a | SetDictInt("A_VERTICAL", A_VERTICAL); |
---|
3386 | n/a | #endif |
---|
3387 | n/a | |
---|
3388 | n/a | SetDictInt("COLOR_BLACK", COLOR_BLACK); |
---|
3389 | n/a | SetDictInt("COLOR_RED", COLOR_RED); |
---|
3390 | n/a | SetDictInt("COLOR_GREEN", COLOR_GREEN); |
---|
3391 | n/a | SetDictInt("COLOR_YELLOW", COLOR_YELLOW); |
---|
3392 | n/a | SetDictInt("COLOR_BLUE", COLOR_BLUE); |
---|
3393 | n/a | SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA); |
---|
3394 | n/a | SetDictInt("COLOR_CYAN", COLOR_CYAN); |
---|
3395 | n/a | SetDictInt("COLOR_WHITE", COLOR_WHITE); |
---|
3396 | n/a | |
---|
3397 | n/a | #ifdef NCURSES_MOUSE_VERSION |
---|
3398 | n/a | /* Mouse-related constants */ |
---|
3399 | n/a | SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED); |
---|
3400 | n/a | SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED); |
---|
3401 | n/a | SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED); |
---|
3402 | n/a | SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED); |
---|
3403 | n/a | SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED); |
---|
3404 | n/a | |
---|
3405 | n/a | SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED); |
---|
3406 | n/a | SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED); |
---|
3407 | n/a | SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED); |
---|
3408 | n/a | SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED); |
---|
3409 | n/a | SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED); |
---|
3410 | n/a | |
---|
3411 | n/a | SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED); |
---|
3412 | n/a | SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED); |
---|
3413 | n/a | SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED); |
---|
3414 | n/a | SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED); |
---|
3415 | n/a | SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED); |
---|
3416 | n/a | |
---|
3417 | n/a | SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED); |
---|
3418 | n/a | SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED); |
---|
3419 | n/a | SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED); |
---|
3420 | n/a | SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED); |
---|
3421 | n/a | SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED); |
---|
3422 | n/a | |
---|
3423 | n/a | SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT); |
---|
3424 | n/a | SetDictInt("BUTTON_CTRL", BUTTON_CTRL); |
---|
3425 | n/a | SetDictInt("BUTTON_ALT", BUTTON_ALT); |
---|
3426 | n/a | |
---|
3427 | n/a | SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS); |
---|
3428 | n/a | SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION); |
---|
3429 | n/a | #endif |
---|
3430 | n/a | /* Now set everything up for KEY_ variables */ |
---|
3431 | n/a | { |
---|
3432 | n/a | int key; |
---|
3433 | n/a | char *key_n; |
---|
3434 | n/a | char *key_n2; |
---|
3435 | n/a | #if !defined(__NetBSD__) |
---|
3436 | n/a | for (key=KEY_MIN;key < KEY_MAX; key++) { |
---|
3437 | n/a | key_n = (char *)keyname(key); |
---|
3438 | n/a | if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0) |
---|
3439 | n/a | continue; |
---|
3440 | n/a | if (strncmp(key_n,"KEY_F(",6)==0) { |
---|
3441 | n/a | char *p1, *p2; |
---|
3442 | n/a | key_n2 = PyMem_Malloc(strlen(key_n)+1); |
---|
3443 | n/a | if (!key_n2) { |
---|
3444 | n/a | PyErr_NoMemory(); |
---|
3445 | n/a | break; |
---|
3446 | n/a | } |
---|
3447 | n/a | p1 = key_n; |
---|
3448 | n/a | p2 = key_n2; |
---|
3449 | n/a | while (*p1) { |
---|
3450 | n/a | if (*p1 != '(' && *p1 != ')') { |
---|
3451 | n/a | *p2 = *p1; |
---|
3452 | n/a | p2++; |
---|
3453 | n/a | } |
---|
3454 | n/a | p1++; |
---|
3455 | n/a | } |
---|
3456 | n/a | *p2 = (char)0; |
---|
3457 | n/a | } else |
---|
3458 | n/a | key_n2 = key_n; |
---|
3459 | n/a | SetDictInt(key_n2,key); |
---|
3460 | n/a | if (key_n2 != key_n) |
---|
3461 | n/a | PyMem_Free(key_n2); |
---|
3462 | n/a | } |
---|
3463 | n/a | #endif |
---|
3464 | n/a | SetDictInt("KEY_MIN", KEY_MIN); |
---|
3465 | n/a | SetDictInt("KEY_MAX", KEY_MAX); |
---|
3466 | n/a | } |
---|
3467 | n/a | return m; |
---|
3468 | n/a | } |
---|