]> granicus.if.org Git - python/commitdiff
Close #6755: Add get_wch() method to curses.window class
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 14 Jul 2011 21:07:44 +0000 (23:07 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 14 Jul 2011 21:07:44 +0000 (23:07 +0200)
Patch by Iñigo Serna.

Doc/library/curses.rst
Doc/whatsnew/3.3.rst
Misc/ACKS
Misc/NEWS
Modules/_cursesmodule.c

index 16b7681661ae7b66d9431a1630d784dbdfffbaf2..34504949fa7073200053524f83a8efdf741b3da0 100644 (file)
@@ -846,6 +846,14 @@ the following methods:
    until a key is pressed.
 
 
+.. method:: window.get_wch([y, x])
+
+   Get a wide character. Like :meth:`getch`, but the integer returned is the
+   Unicode code point for the key pressed, so it can be passed to :func:`chr`.
+
+   .. versionadded:: 3.3
+
+
 .. method:: window.getkey([y, x])
 
    Get a character, returning a string instead of an integer, as :meth:`getch`
index 0498ca8505d59ef831c372b57e58b95cf2638cb8..051d165e416cb45d12656a7901518c9ed2d4d9b9 100644 (file)
@@ -91,6 +91,14 @@ versions.
 
 (:issue:`12100`)
 
+curses
+------
+
+The :class:`curses.window` class has a new :class:`~curses.window.get_wch`
+method to a wide character. Patch by Iñigo Serna.
+
+(:issue:`6755`)
+
 faulthandler
 ------------
 
index 10bdaf60297baa14b7ae2ecdd381471a3b4e7106..ed21b1a71417b951e2ae477093b03e9152eaa995 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -851,6 +851,7 @@ Nick Seidenman
 Yury Selivanov
 Fred Sells
 Jiwon Seo
+Iñigo Serna
 Roger D. Serwy
 Jerry Seutter
 Denis Severson
index 7e97bed311edf8fe8d92cc6b5d3928e1e27f3fb8..bfdc3a37a4bc2a408b05cc322acbae6a4ea1d025 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -225,6 +225,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #6755: Add get_wch() method to curses.window class. Patch by Iñigo
+  Serna.
+
 - Add cgi.closelog() function to close the log file.
 
 - Issue #12502: asyncore: fix polling loop with AF_UNIX sockets.
index 9b3b8cde0ec35a80c7264f379ed253e2d6250f15..9e57cd94f03c7d3819d4ccd61e6c789753159a7c 100644 (file)
@@ -906,6 +906,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)
 {
@@ -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},