473,783 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UTF-8 Support of Curses in Python 2.5

Hi All,

Recently I ran into a problem with UTF-8 surrport when using curses
library in python 2.5 in Fedora 7. I found out that the program using
curses cannot print out unicode characters correctly on UTF-8 enabled
console. I googled around and got an impression that the reason for
this problem is that python is linked with libcurses library instead
of libcursesw. The latter one is said to be able to solve this
problem. Has anybody tried this? How to manually let python use
libcursesw? Thanks a lot!

Here is a test program:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import curses
def keyloop(stdscr) :
# Clear the screen and display the menu of keys
stdscr_y, stdscr_x = stdscr.getmaxyx ()
menu_y = (stdscr_y-3)-1
str = u'This is my first curses python program. Press \'q\' to
exit. (¤£™)'
stdscr.addstr(m enu_y, 4, str.encode('utf-8'))
xpos = stdscr_x / 2
ypos = stdscr_y / 2
while (1):
stdscr.move(ypo s, xpos)
c = stdscr.getch()
if 0 < c < 256:
c = chr(c)
if c in 'Qq': break
else: pass
elif c == curses.KEY_UP and ypos 0: ypos -= 1
elif c == curses.KEY_DOWN and ypos < stdscr_y - 1: ypos += 1
elif c == curses.KEY_LEFT and xpos 0: xpos -= 1
elif c == curses.KEY_RIGH T and xpos < stdscr_x - 1: xpos += 1
else: pass
def main(stdscr):
keyloop(stdscr)
if __name__ == '__main__':
curses.wrapper( main)

Jul 4 '07 #1
1 2835
Yes, it does solve the problem.
Compile python with ncursesw library.
Btw Ubuntu 7 has it "out of the box".

Hi All,

Recently I ran into a problem with UTF-8 surrport when using curses
library in python 2.5 in Fedora 7. I found out that the program using
curses cannot print out unicode characters correctly on UTF-8 enabled
console. I googled around and got an impression that the reason for
this problem is that python is linked with libcurses library instead
of libcursesw. The latter one is said to be able to solve this
problem. Has anybody tried this? How to manually let python use
libcursesw? Thanks a lot!

Here is a test program:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import curses
def keyloop(stdscr) :
# Clear the screen and display the menu of keys
stdscr_y, stdscr_x = stdscr.getmaxyx ()
menu_y = (stdscr_y-3)-1
str = u'This is my first curses python program. Press \'q\' to
exit. (¤£™)'
stdscr.addstr(m enu_y, 4, str.encode('utf-8'))
xpos = stdscr_x / 2
ypos = stdscr_y / 2
while (1):
stdscr.move(ypo s, xpos)
c = stdscr.getch()
if 0 < c < 256:
c = chr(c)
if c in 'Qq': break
else: pass
elif c == curses.KEY_UP and ypos 0: ypos -= 1
elif c == curses.KEY_DOWN and ypos < stdscr_y - 1: ypos += 1
elif c == curses.KEY_LEFT and xpos 0: xpos -= 1
elif c == curses.KEY_RIGH T and xpos < stdscr_x - 1: xpos += 1
else: pass
def main(stdscr):
keyloop(stdscr)
if __name__ == '__main__':
curses.wrapper( main)
Jul 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4192
by: lawrence | last post by:
Someone on www.php.net suggested using a seems_utf8() method to test text for UTF-8 character encoding but didn't specify how to write such a method. Can anyone suggest a test that might work? Something that maybe gives 90% confidence that a given block of text is or is not UTF-8 encoded?
38
5739
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I find an answer to this question (don't find it in the W3C_char_entities document). -- Haines Brown brownh@hartford-hwp.com
32
49730
by: Wolfgang Draxinger | last post by:
I understand that it is perfectly possible to store UTF-8 strings in a std::string, however doing so can cause some implicaions. E.g. you can't count the amount of characters by length() | size(). Instead one has to iterate through the string, parse all UTF-8 multibytes and count each multibyte as one character. To address this problem the GTKmm bindings for the GTK+ toolkit have implemented a own string class Glib::ustring...
6
18765
by: jmgonet | last post by:
Hello everybody, I'm having troubles loading a Xml string encoded in UTF-8. If I try this code: ------------------------------ XmlDocument doc=new XmlDocument(); String s="<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><a>Schönbühl</a>"; doc.LoadXml(s); doc.Save("d:\\temp\\test.xml");
7
12152
by: Jimmy Shaw | last post by:
Hi everybody, Is there any SIMPLE way to convert from UTF-16 to UTF-32? I may be mixed up, but is it possible that all UTF-16 "code points" that are 16 bits long appear just the same in UTF-32, but with zero padding and hence no real conversion is necessary? If I am completely wrong and some intricate conversion operation needs to take place, can anyone give me some primer on the subject?
4
2352
by: shreshth.luthra | last post by:
Hi All, I am having a GUI which accepts a Unicode string and searches a given set of xml files for that string. Now, i have 2 XML files both of them saved in UTF-8 format, having characters of different language. Although both of them are having UTF-8 as BoM, but only first file is having UTF-8 defined in XML declration at the top of the XML file as
10
19579
by: Jed | last post by:
I have a form that needs to handle international characters withing the UTF-8 character set. I have tried all the recommended strategies for getting utf-8 characters from form input to email message and I cannot get it to work. I need to stay with classic asp for this. Here are some things I tried: 'CDONTS Call msg.SetLocaleIDs(65001)
23
5029
by: Allan Ebdrup | last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc chineese chars. My Ajax webapplication runs in a HTML page that is UTF-8 Encoded. I copy and paste some chineese chars from another HTML page viewed in IE7, that is also UTF-8 encoded (search for "china" on google.com). I paste the chineese chars into a content editable div. My Ajax webservice compiles an XML where the data from the content editable div is...
35
4357
by: Bjoern Hoehrmann | last post by:
Hi, For a free software project, I had to write a routine that, given a Unicode scalar value U+0000 - U+10FFFF, returns an integer that holds the UTF-8 encoded form of it, for example, U+00F6 becomes 0x0000C3B6. I came up with the following. I am looking for a more elegant solution, that is, roughly, faster, shorter, more readable, ... while producing the same ouput for the cited range. unsigned int
4
6875
by: =?ISO-8859-2?Q?Boris_Du=B9ek?= | last post by:
Hi, I have an API that returns UTF-8 encoded strings. I have a utf8 codevt facet available to do the conversion from UTF-8 to wchar_t encoding defined by the platform. I have no trouble converting when a UTF-8 encoded string comes from file - I just create a std::wifstream and imbue it with a locale that uses the utf-8 facet for std::locale::ctype. Then I just use operator>to get wstring properly decoded from UTF-8. I thought I could...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.