[Python-checkins] cpython: Close #6755: Add get_wch() method to curses.window class

victor.stinner python-checkins at python.org
Thu Jul 14 23:08:41 CEST 2011


http://hg.python.org/cpython/rev/dec10ad41b2a
changeset:   71338:dec10ad41b2a
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Thu Jul 14 23:07:44 2011 +0200
summary:
  Close #6755: Add get_wch() method to curses.window class

Patch by Iñigo Serna.

files:
  Doc/library/curses.rst  |   8 +++++++
  Doc/whatsnew/3.3.rst    |   8 +++++++
  Misc/ACKS               |   1 +
  Misc/NEWS               |   3 ++
  Modules/_cursesmodule.c |  33 +++++++++++++++++++++++++++++
  5 files changed, 53 insertions(+), 0 deletions(-)


diff --git a/Doc/library/curses.rst b/Doc/library/curses.rst
--- a/Doc/library/curses.rst
+++ b/Doc/library/curses.rst
@@ -846,6 +846,14 @@
    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`
diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst
--- a/Doc/whatsnew/3.3.rst
+++ b/Doc/whatsnew/3.3.rst
@@ -91,6 +91,14 @@
 
 (: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
 ------------
 
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -851,6 +851,7 @@
 Yury Selivanov
 Fred Sells
 Jiwon Seo
+Iñigo Serna
 Roger D. Serwy
 Jerry Seutter
 Denis Severson
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -225,6 +225,9 @@
 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.
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -907,6 +907,38 @@
 }
 
 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 @@
     {"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},

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list