components/python/python34/patches/13-get_wch.patch
changeset 1907 446472de62e9
equal deleted inserted replaced
1906:06b8097543cd 1907:446472de62e9
       
     1 This patch adds wget_wch support to the curses module.  It may be contributed
       
     2 upstream at some point, but the suitability (or lack thereof) has not yet
       
     3 been determined.
       
     4 
       
     5 --- Python-3.4.0/Modules/_cursesmodule.c.~1~	2014-03-16 19:31:31.000000000 -0700
       
     6 +++ Python-3.4.0/Modules/_cursesmodule.c	2014-03-17 13:44:21.194828659 -0700
       
     7 @@ -1187,6 +1187,37 @@
       
     8  }
       
     9  
       
    10  static PyObject *
       
    11 +PyCursesWindow_Get_WCh(PyCursesWindowObject *self, PyObject *args)
       
    12 +{
       
    13 +    int x, y;
       
    14 +    int ct;
       
    15 +    wint_t rtn;
       
    16 +
       
    17 +    switch (PyTuple_Size(args)) {
       
    18 +    case 0:
       
    19 +        Py_BEGIN_ALLOW_THREADS
       
    20 +        ct = wget_wch(self->win,&rtn);
       
    21 +        Py_END_ALLOW_THREADS
       
    22 +        break;
       
    23 +    case 2:
       
    24 +        if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
       
    25 +            return NULL;
       
    26 +        Py_BEGIN_ALLOW_THREADS
       
    27 +        ct = mvwget_wch(self->win,y,x,&rtn);
       
    28 +        Py_END_ALLOW_THREADS
       
    29 +        break;
       
    30 +    default:
       
    31 +        PyErr_SetString(PyExc_TypeError, "get_wch requires 0 or 2 arguments");
       
    32 +        return NULL;
       
    33 +    }
       
    34 +    if (ct == ERR) {
       
    35 +        PyErr_SetString(PyCursesError, "get_wch failed");
       
    36 +        return NULL;
       
    37 +    }
       
    38 +    return PyLong_FromLong((long)rtn);
       
    39 +}
       
    40 +
       
    41 +static PyObject *
       
    42  PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
       
    43  {
       
    44      int x, y;
       
    45 @@ -2059,6 +2090,7 @@
       
    46      {"getbegyx",        (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},
       
    47      {"getbkgd",         (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS},
       
    48      {"getch",           (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS},
       
    49 +    {"get_wch",         (PyCFunction)PyCursesWindow_Get_WCh, METH_VARARGS},
       
    50      {"getkey",          (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS},
       
    51  #ifdef HAVE_NCURSESW
       
    52      {"get_wch",         (PyCFunction)PyCursesWindow_Get_WCh, METH_VARARGS},