mirror of
https://github.com/python/cpython.git
synced 2024-12-15 04:44:47 +08:00
Issue #15785: Modify window.get_wch() API of the curses module: return a
character for most keys, and an integer for special keys, instead of always returning an integer. So it is now possible to distinguish special keys like keypad keys.
This commit is contained in:
parent
3694401ad2
commit
ca2b64682e
@ -869,8 +869,8 @@ the following methods and attributes:
|
|||||||
|
|
||||||
.. method:: window.get_wch([y, x])
|
.. method:: window.get_wch([y, x])
|
||||||
|
|
||||||
Get a wide character. Like :meth:`getch`, but the integer returned is the
|
Get a wide character. Return a character for most keys, or an integer for
|
||||||
Unicode code point for the key pressed, so it can be passed to :func:`chr`.
|
function keys, keypad keys, and other special keys.
|
||||||
|
|
||||||
.. versionadded:: 3.3
|
.. versionadded:: 3.3
|
||||||
|
|
||||||
@ -878,8 +878,9 @@ the following methods and attributes:
|
|||||||
.. method:: window.getkey([y, x])
|
.. method:: window.getkey([y, x])
|
||||||
|
|
||||||
Get a character, returning a string instead of an integer, as :meth:`getch`
|
Get a character, returning a string instead of an integer, as :meth:`getch`
|
||||||
does. Function keys, keypad keys and so on return a multibyte string containing
|
does. Function keys, keypad keys and other special keys return a multibyte
|
||||||
the key name. In no-delay mode, an exception is raised if there is no input.
|
string containing the key name. In no-delay mode, an exception is raised if
|
||||||
|
there is no input.
|
||||||
|
|
||||||
|
|
||||||
.. method:: window.getmaxyx()
|
.. method:: window.getmaxyx()
|
||||||
|
@ -267,8 +267,7 @@ def test_issue6243(stdscr):
|
|||||||
def test_unget_wch(stdscr):
|
def test_unget_wch(stdscr):
|
||||||
if not hasattr(curses, 'unget_wch'):
|
if not hasattr(curses, 'unget_wch'):
|
||||||
return
|
return
|
||||||
import locale
|
encoding = stdscr.encoding
|
||||||
encoding = locale.getpreferredencoding()
|
|
||||||
for ch in ('a', '\xe9', '\u20ac', '\U0010FFFF'):
|
for ch in ('a', '\xe9', '\u20ac', '\U0010FFFF'):
|
||||||
try:
|
try:
|
||||||
ch.encode(encoding)
|
ch.encode(encoding)
|
||||||
@ -277,18 +276,17 @@ def test_unget_wch(stdscr):
|
|||||||
try:
|
try:
|
||||||
curses.unget_wch(ch)
|
curses.unget_wch(ch)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise Exception("unget_wch(%a) failed with locale encoding %s: %s"
|
raise Exception("unget_wch(%a) failed with encoding %s: %s"
|
||||||
% (ch, encoding, err))
|
% (ch, stdscr.encoding, err))
|
||||||
read = stdscr.get_wch()
|
read = stdscr.get_wch()
|
||||||
read = chr(read)
|
|
||||||
if read != ch:
|
if read != ch:
|
||||||
raise AssertionError("%r != %r" % (read, ch))
|
raise AssertionError("%r != %r" % (read, ch))
|
||||||
|
|
||||||
code = ord(ch)
|
code = ord(ch)
|
||||||
curses.unget_wch(code)
|
curses.unget_wch(code)
|
||||||
read = stdscr.get_wch()
|
read = stdscr.get_wch()
|
||||||
if read != code:
|
if read != ch:
|
||||||
raise AssertionError("%r != %r" % (read, code))
|
raise AssertionError("%r != %r" % (read, ch))
|
||||||
|
|
||||||
def test_issue10570():
|
def test_issue10570():
|
||||||
b = curses.tparm(curses.tigetstr("cup"), 5, 3)
|
b = curses.tparm(curses.tigetstr("cup"), 5, 3)
|
||||||
|
@ -13,6 +13,11 @@ Core and Builtins
|
|||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #15785: Modify window.get_wch() API of the curses module: return
|
||||||
|
a character for most keys, and an integer for special keys, instead of
|
||||||
|
always returning an integer. So it is now possible to distinguish special
|
||||||
|
keys like keypad keys.
|
||||||
|
|
||||||
|
|
||||||
What's New in Python 3.3.0 Release Candidate 1?
|
What's New in Python 3.3.0 Release Candidate 1?
|
||||||
===============================================
|
===============================================
|
||||||
@ -23,7 +28,7 @@ Core and Builtins
|
|||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
- Issue #15573: memoryview comparisons are now performed by value with full
|
- Issue #15573: memoryview comparisons are now performed by value with full
|
||||||
support for any valid struct module format definition.
|
support for any valid struct module format definition.
|
||||||
|
|
||||||
- Issue #15316: When an item in the fromlist for __import__ doesn't exist,
|
- Issue #15316: When an item in the fromlist for __import__ doesn't exist,
|
||||||
don't raise an error, but if an exception is raised as part of an import do
|
don't raise an error, but if an exception is raised as part of an import do
|
||||||
|
@ -1203,7 +1203,10 @@ PyCursesWindow_Get_WCh(PyCursesWindowObject *self, PyObject *args)
|
|||||||
PyErr_SetString(PyCursesError, "no input");
|
PyErr_SetString(PyCursesError, "no input");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return PyLong_FromLong(rtn);
|
if (ct == KEY_CODE_YES)
|
||||||
|
return PyLong_FromLong(rtn);
|
||||||
|
else
|
||||||
|
return PyUnicode_FromOrdinal(rtn);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user