* src/Utils.py: Provide a locale-aware string formatting conversion

into C-locale string (for saving floats in XML)
* src/StyleEditor.py (draw): Call locale.str instead of str.
* src/TextDoc.py (StyleSheetList.save): Call gformat instead of '%f'.


svn: r1744
This commit is contained in:
Alex Roitman 2003-06-15 00:05:43 +00:00
parent 2bfa45813f
commit 3e512cd70d
4 changed files with 37 additions and 13 deletions

View File

@ -5,6 +5,10 @@
consequently, the target filename) -- was confused with family group.
* src/StyleEditor.py (save_paragraph): Call gfloat instead of float.
* src/TextDoc.py (SheetParser.startElement): Likewise.
* src/Utils.py: Provide a locale-aware string formatting conversion
into C-locale string (for saving floats in XML)
* src/StyleEditor.py (draw): Call locale.str instead of str.
* src/TextDoc.py (StyleSheetList.save): Call gformat instead of '%f'.
2003-06-14 Don Allingham <dallingham@users.sourceforge.net>
* src/preferences.glade: Don't immediately show preferences dialog

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000 Donald N. Allingham
# Copyright (C) 2000-2003 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -42,6 +42,7 @@ import Utils
import const
import TextDoc
import ListModel
import locale
from intl import gettext as _
class StyleListDisplay:
@ -223,9 +224,9 @@ class StyleEditor:
self.top.get_widget("calign").set_active(1)
else:
self.top.get_widget("jalign").set_active(1)
self.top.get_widget("rmargin").set_text(str(p.get_right_margin()))
self.top.get_widget("lmargin").set_text(str(p.get_left_margin()))
self.top.get_widget("pad").set_text(str(p.get_padding()))
self.top.get_widget("rmargin").set_text(locale.str(p.get_right_margin()))
self.top.get_widget("lmargin").set_text(locale.str(p.get_left_margin()))
self.top.get_widget("pad").set_text(locale.str(p.get_padding()))
self.top.get_widget("tborder").set_active(p.get_top_border())
self.top.get_widget("lborder").set_active(p.get_left_border())
self.top.get_widget("rborder").set_active(p.get_right_border())

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000 Donald N. Allingham
# Copyright (C) 2000-2003 Donald N. Allingham
#
# Modified September 2002 by Gary Shao
#
@ -777,13 +777,14 @@ class StyleSheetList:
f.write('underline="%d" ' % font.get_underline())
f.write('color="#%02x%02x%02x"/>\n' % font.get_color())
f.write('<para ')
rm = Utils.gfloat(p.get_right_margin())
lm = Utils.gfloat(p.get_left_margin())
fi = Utils.gfloat(p.get_first_indent())
f.write('rmargin="%.3f" ' % rm)
f.write('lmargin="%.3f" ' % lm)
f.write('first="%.3f" ' % fi)
f.write('pad="%.3f" ' % p.get_padding())
rm = float(p.get_right_margin())
lm = float(p.get_left_margin())
fi = float(p.get_first_indent())
pa = float(p.get_padding())
f.write('rmargin="%s" ' % Utils.gformat(rm))
f.write('lmargin="%s" ' % Utils.gformat(lm))
f.write('first="%s" ' % Utils.gformat(fi))
f.write('pad="%s" ' % Utils.gformat(pa))
f.write('bgcolor="#%02x%02x%02x" ' % p.get_background_color())
f.write('level="%d" ' % p.get_header_level())
f.write('align="%d" ' % p.get_alignment())

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000 Donald N. Allingham
# Copyright (C) 2000-2003 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -25,6 +25,7 @@
#-------------------------------------------------------------------------
import string
import os
import locale
#-------------------------------------------------------------------------
#
@ -523,6 +524,12 @@ def set_titles(window,title,t,msg=None):
window.set_title('%s - GRAMPS' % t)
def gfloat(val):
"""Converts to floating number, taking care of possible locale differences.
Useful for reading float values from text entry fields
while under non-English locale.
"""
try:
return float(val)
except:
@ -531,6 +538,17 @@ def gfloat(val):
except:
return float(val.replace(',','.'))
return 0.0
def gformat(val):
"""Performs ("%.3f" % val) formatting with the resulting string always
using dot ('.') as a decimal point.
Useful for writing float values into XML when under non-English locale.
"""
decimal_point = locale.localeconv()['decimal_point']
return_val = "%.3f" % val
return return_val.replace(decimal_point,'.')
#-------------------------------------------------------------------------
#