[affichage] Ajout d'une liste de styles pour tableau, et bugfix
* On peut "styliser" des colonnes de tableau maintenant. * Le formatage pour les octets était foireux
This commit is contained in:
parent
8b87c092e8
commit
c4c142686d
1 changed files with 8 additions and 4 deletions
|
@ -41,7 +41,7 @@ import functools
|
|||
import time
|
||||
import re
|
||||
|
||||
oct_names = ["Pio", "Tio", "Gio", "Mio", "Kio", "o"]
|
||||
oct_names = ["Pio", "Tio", "Gio", "Mio", "Kio"]
|
||||
oct_sizes = [1024**(len(oct_names) - i - 1) for i in xrange(0, len(oct_names))]
|
||||
term_format = '\x1b\[[0-1];([0-9]|[0-9][0-9])m'
|
||||
dialog_format = '\\\Z.'
|
||||
|
@ -393,8 +393,9 @@ def format_data(data, format):
|
|||
for i in xrange(0, len(oct_names)):
|
||||
if data > oct_sizes[i]:
|
||||
return "%.2f %s" % (data/oct_sizes[i], oct_names[i])
|
||||
return "%.0f o" % (data)
|
||||
|
||||
def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog=False, width=None):
|
||||
def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog=False, width=None, styles=None):
|
||||
"""
|
||||
Retourne une chaine formatée repésentant un tableau.
|
||||
|
||||
|
@ -426,6 +427,9 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog
|
|||
if format is None:
|
||||
format = ['s'] * nb_cols
|
||||
|
||||
if styles is None:
|
||||
styles = [None] * nb_cols
|
||||
|
||||
data = [[format_data(ligne[i], format[i]) for i in xrange(nb_cols)] for ligne in data]
|
||||
|
||||
if not largeur :
|
||||
|
@ -452,7 +456,7 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog
|
|||
##########
|
||||
if titre :
|
||||
# ligne de titre
|
||||
chaine = sep_col + sep_col.join([aligne(titre[i], 'c', largeur[i], dialog) for i in range(nb_cols)]) + sep_col + u'\n'
|
||||
chaine = sep_col + sep_col.join([style(aligne(titre[i], 'c', largeur[i], dialog), styles[i]) for i in range(nb_cols)]) + sep_col + u'\n'
|
||||
# ligne de séparation
|
||||
chaine += sep_col + u'+'.join([u'-'*largeur[i] for i in range(nb_cols)]) + sep_col + u'\n'
|
||||
else :
|
||||
|
@ -460,7 +464,7 @@ def tableau(data, titre=None, largeur=None, alignement=None, format=None, dialog
|
|||
|
||||
# Les données
|
||||
#############
|
||||
chaine += u'\n'.join([sep_col + sep_col.join([ligne[i] for i in range(nb_cols)]) + sep_col for ligne in data])
|
||||
chaine += u'\n'.join([sep_col + sep_col.join([style(ligne[i], styles[i]) for i in range(nb_cols)]) + sep_col for ligne in data])
|
||||
|
||||
return chaine
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue