summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-07-14 21:07:44 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-07-14 21:07:44 (GMT)
commita7878b77dcddf365452b53b223324a2f67d9354d (patch)
treede1f7cf1e247903d2a6bf74a21d0361933cc9bcc /Modules
parentd33344a030bececd68ce487445cd47a11ebdb3fd (diff)
downloadcpython-a7878b77dcddf365452b53b223324a2f67d9354d.zip
cpython-a7878b77dcddf365452b53b223324a2f67d9354d.tar.gz
cpython-a7878b77dcddf365452b53b223324a2f67d9354d.tar.bz2
Close #6755: Add get_wch() method to curses.window class
Patch by IƱigo Serna.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_cursesmodule.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 9b3b8cd..9e57cd9 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -907,6 +907,38 @@ PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
}
static PyObject *
+PyCursesWindow_Get_WCh(PyCursesWindowObject *self, PyObject *args)
+{
+ int x, y;
+ int ct;
+ wint_t rtn;
+
+ switch (PyTuple_Size(args)) {
+ case 0:
+ Py_BEGIN_ALLOW_THREADS
+ ct = wget_wch(self->win,&rtn);
+ Py_END_ALLOW_THREADS
+ break;
+ case 2:
+ if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
+ return NULL;
+ Py_BEGIN_ALLOW_THREADS
+ ct = mvwget_wch(self->win,y,x,&rtn);
+ Py_END_ALLOW_THREADS
+ break;
+ default:
+ PyErr_SetString(PyExc_TypeError, "get_wch requires 0 or 2 arguments");
+ return NULL;
+ }
+ if (ct == ERR) {
+ /* get_wch() returns ERR in nodelay mode */
+ PyErr_SetString(PyCursesError, "no input");
+ return NULL;
+ }
+ return PyLong_FromLong(rtn);
+}
+
+static PyObject *
PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
{
int x, y, n;
@@ -1604,6 +1636,7 @@ static PyMethodDef PyCursesWindow_Methods[] = {
{"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS},
{"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS},
{"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS},
+ {"get_wch", (PyCFunction)PyCursesWindow_Get_WCh, METH_VARARGS},
{"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},
{"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},
{"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},