J'ai installé curses sous Win7 curse sous windows 7.
Cela se passe bien tant qu'il n'y a pas d'accent.
Voici ma config d'encodage (fichier source en utf8 édité avec sublime-text):
print( 'élémentaire!')
print( 'StdOut encoding: %s' % sys.stdout.encoding )
print( 'filesystem encoding: %s' % sys.getfilesystemencoding() )
print( 'preferred encoding (curse): %s' % locale.getpreferredencoding() )
Ma console dos est en cp850 et l'impression des accentués avec print() est impeccable.
élémentaire!
StdOut encoding: cp850
filesystem encoding: mbcs
preferred encoding (curse): cp1252
Par contre, curse utilise locale.getpreferredencoding() pour l'encodage !
Par conséquent, les accents sont encodés en cp1252 pour être affiché dans une console DOS en cp850.
Cela donne ce résultat (voyez le script en fin de billet):
Cr├®ationsuivant pr├®c├®denLister Recherche Modifier Annuler Fourn XR├®fKit BO
Texte Libre Y-etiq Voir Mail-it Inv. + / Quitter
J'ai essayé de fixer PYTHONIOENCODING (la variable d'environnement) sur cp1252 mais l'affichage est tout aussi mauvais.
Quelqu'un aurait-il une suggestion?
Voici le code (beta) utilisé:
# coding: utf8
""" See c:\Python34\Lib\curses\has_key.py for extra key_strokes """
import curses
from curses.textpad import Textbox, rectangle
import sys
import locale
def show_dspmenuwin(stdscr, menuitems):
""" Open a screen and display a navigation menu """
# ScreenSize: (0,0) to (curses.LINES - 1, curses.COLS - 1).
menu_height = 2
menu_width = curses.COLS
rawitems = [] # collection of (labels,y,x) items
win = curses.newwin( menu_height, menu_width, curses.LINES-menu_height,0 ) # Height, width, begin_y, begin_x
x_pos = 0
y_pos = 0
for item in menuitems:
# Check if new item is still on the screen otherwise Wrap line
if x_pos + len( item )+1 > menu_width:
x_pos = 0
y_pos += 1
if y_pos >= menu_height:
raise Exception( 'Too much lines (%s) for menu' % (y_pos+1) )
# Register menuitem
rawitem = (item,y_pos, x_pos)
rawitems.append( rawitem )
# Increment next item position
x_pos += len( item )+1
# Former display
win.addstr( rawitem[1], rawitem[2], rawitem[0] ) # y, x, "text"
#win.addstr( 0,0, "Line1, cols: %s" % curses.COLS ) # y,x
#win.addstr( 1,0, "line2, lines: %s" % curses.LINES )
win.refresh()
win.getch()
def main(stdscr):
menuitems = ["Création", "suivant", 'précédent', 'Lister', 'Recherche', 'Modifier', 'Annuler',
'Fourn', 'XRéf', 'Kit', 'BO', 'Texte Libre', 'Y-etiq', 'Voir', 'Mail-it', 'Inv.', '+', '/', 'Quitter']
show_dspmenuwin(stdscr, menuitems)
curses.wrapper(main)
#print( 'élémentaire!')
#print( 'StdOut encoding: %s' % sys.stdout.encoding )
#print( 'filesystem encoding: %s' % sys.getfilesystemencoding() )
#print( 'preferred encoding (curse): %s' % locale.getpreferredencoding() )