[issue6755] Patch: new method get_wch for ncurses bindings: accept wide characters (unicode)

2009-08-21 Thread Iñigo Serna

New submission from Iñigo Serna :

Currently,there is no a simple way in curses bindings to get the code
associated with a key press of non ascii keystroke (f.e. ç) in terminals
configured with UTF-8 encoding. 

getch returns the code for a wide character byte a byte.
But ncurses library has a proper function to do it: get_wch.

Patch against Python v2.6.2 to provide this missing get_wch method
in the ncurses bindings.

Include a test example and a patch to the documentation as well.

More info and a partial solution without patching python curses module
on this thread:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/67dce30f0a2742a6?fwc=2

--
components: Extension Modules
messages: 91816
nosy: inigoserna
severity: normal
status: open
title: Patch: new method get_wch for ncurses bindings: accept wide characters 
(unicode)
type: feature request
versions: Python 2.6, Python 2.7

___
Python tracker 
<http://bugs.python.org/issue6755>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6755] Patch: new method get_wch for ncurses bindings: accept wide characters (unicode)

2009-08-21 Thread Iñigo Serna

Iñigo Serna  added the comment:

Added patch for the documentation

--
keywords: +patch
Added file: http://bugs.python.org/file14753/curses.get_wch.patch

___
Python tracker 
<http://bugs.python.org/issue6755>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6755] Patch: new method get_wch for ncurses bindings: accept wide characters (unicode)

2009-08-21 Thread Iñigo Serna

Iñigo Serna  added the comment:

Added test example

--
Added file: http://bugs.python.org/file14754/test_get_wch.py

___
Python tracker 
<http://bugs.python.org/issue6755>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6755] Patch: new method get_wch for ncurses bindings: accept wide characters (unicode)

2009-08-21 Thread Iñigo Serna

Iñigo Serna  added the comment:

Added missing file: patch against Python v2.6.2

--
Added file: http://bugs.python.org/file14755/_cursesmodule.get_wch.patch

___
Python tracker 
<http://bugs.python.org/issue6755>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6755] Patch: new method get_wch for ncurses bindings: accept wide characters (unicode)

2009-08-21 Thread Iñigo Serna

Iñigo Serna  added the comment:

Added patch against Python v3.1.1. 
NOT TESTED!

--
versions: +Python 3.1, Python 3.2
Added file: http://bugs.python.org/file14756/_cursesmodule.311.get_wch.patch

___
Python tracker 
<http://bugs.python.org/issue6755>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6755] Patch: new method get_wch for ncurses bindings: accept wide characters (unicode)

2009-08-22 Thread Iñigo Serna

Iñigo Serna  added the comment:

Thanks for the pointer, haven't seen anything when I searched for get_wch.

The patch provided here only adds this get_wch function, because as A.M.
Kuchling explained in issue700921, it's possible to use wide chars now,
the only feature missing is get_wch.

--

___
Python tracker 
<http://bugs.python.org/issue6755>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue700921] Wide-character curses

2009-08-22 Thread Iñigo Serna

Iñigo Serna  added the comment:

In issue6755 I provide a patch to support get_wch, which is the only
wide chars related feature I miss in current bindings (as python v2.6.2
or v3.1.1).

--
nosy: +inigoserna

___
Python tracker 
<http://bugs.python.org/issue700921>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6755] Patch: new method get_wch for ncurses bindings: accept wide characters (unicode)

2009-08-26 Thread Iñigo Serna

Iñigo Serna  added the comment:

Q. Why not change getch() to always use get_wch()?

This could break backwards compatibility.
There are some code out there that may use getch() to get the bytes
stream one by one and build the wide char.
In fact I'm using this trick to get unicode chars by now.
Look the thread link in first comment to find the implementation I've
developed for my app. Other people are using similar approaches too.


Q. I think you also want fix getkey() / introduce get_wkey().

In my own experience get_wkey isn't be as useful when dealing with wide
chars. But, of course, that's only my use cases.

--

___
Python tracker 
<http://bugs.python.org/issue6755>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6755] Patch: new method get_wch for ncurses bindings: accept wide characters (unicode)

2009-08-26 Thread Iñigo Serna

Iñigo Serna  added the comment:

Btw, I don't know if this is the best place to comment it but as it is
somehow related with ncurses...

Other functions I miss a lot are wcwidth() and wcswidth(). 

These functions return the real width (read, cells length in screen) for
unicode strings. 

An example to clarify the issue: one simple Chinese character could need
2 cells on screen, thus len(chinese_unicode_string) won't return the
real screen width needed to show the string.

i.e., len(chinese_unicode_string) != wcswidth(chinese_unicode_string)


Those functions are included into not so old glibc versions (2.2+?), at
least on my Linux systems.

Sadly enough, python doesn't bind them, afaik.
I've tried ctypes but don't work for me (don't know the reason), so I've
written some replacements.

Please look at these files: 

* test_ucs2w.py: benchmarks to different implementations. Most of them,
pure python. Please consider only ucs2w_1x, other are only experiments.

* ucs2w.c: C extension implementation


I think Python could benefit from having these functions in the standard
library. Surely, most simple way should be to bind glibc functions, but
don't know if they exist on other platforms such as MacOS X or Windows.

Neither do I know where they fit... perhaps in unicodedata module.


What do you think? who is the person to convince? (please, don't ask me
to write a PEP, my English is not good enough).

--

___
Python tracker 
<http://bugs.python.org/issue6755>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6755] Patch: new method get_wch for ncurses bindings: accept wide characters (unicode)

2009-08-26 Thread Iñigo Serna

Changes by Iñigo Serna :


Added file: http://bugs.python.org/file14782/test_ucs2w.py

___
Python tracker 
<http://bugs.python.org/issue6755>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6755] Patch: new method get_wch for ncurses bindings: accept wide characters (unicode)

2009-08-26 Thread Iñigo Serna

Changes by Iñigo Serna :


Added file: http://bugs.python.org/file14783/ucs2w.c

___
Python tracker 
<http://bugs.python.org/issue6755>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com