2007-06-21 Alex Roitman <shura@gramps-project.org>
* src/GrampsCfg.py (cb_format_changed): Catch new exception; escape special chars from displayed span. * src/NameDisplay.py (_gen_cooked_func): Only replace known parameters, leave the rest as is; (_format_str_base): Catch formatting exceptions and raise our own. * src/Errors.py (NameDisplayError): Add class. svn: r8620
This commit is contained in:
parent
79257df532
commit
e63bc9936d
@ -1,3 +1,11 @@
|
||||
2007-06-21 Alex Roitman <shura@gramps-project.org>
|
||||
* src/GrampsCfg.py (cb_format_changed): Catch new exception;
|
||||
escape special chars from displayed span.
|
||||
* src/NameDisplay.py (_gen_cooked_func): Only replace known
|
||||
parameters, leave the rest as is;
|
||||
(_format_str_base): Catch formatting exceptions and raise our own.
|
||||
* src/Errors.py (NameDisplayError): Add class.
|
||||
|
||||
2007-06-22 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
|
||||
* src/NameDisplay.py: fix indentation (use only spaces).
|
||||
* src/GrampsCfg.py: handle invalid name format: #1025.
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2003-2006 Donald N. Allingham
|
||||
# Copyright (C) 2003-2007 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
|
||||
@ -135,3 +135,13 @@ class MaskError(Exception):
|
||||
class ValidationError(Exception):
|
||||
pass
|
||||
|
||||
class NameDisplayError(Exception):
|
||||
"""
|
||||
Error used to report that the name display format string is invalid.
|
||||
"""
|
||||
def __init__(self,value):
|
||||
Exception.__init__(self)
|
||||
self.value = value
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
|
@ -26,6 +26,7 @@
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
from xml.sax.saxutils import escape
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -46,6 +47,7 @@ from RelLib import Name
|
||||
import ManagedWindow
|
||||
from GrampsWidgets import *
|
||||
import QuestionDialog
|
||||
from Errors import NameDisplayError
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -620,13 +622,13 @@ class NameFormatEditDlg:
|
||||
|
||||
def cb_format_changed(self, obj):
|
||||
try:
|
||||
t = (_nd.format_str(self.name, obj.get_text()))
|
||||
t = (_nd.format_str(self.name, escape(obj.get_text())))
|
||||
sample = '<span weight="bold" style="italic">%s</span>' % t
|
||||
self.valid = True
|
||||
except ValueError, msg:
|
||||
except NameDisplayError:
|
||||
t = _("Invalid or incomplete format definition")
|
||||
sample = '<span foreground="#FF0000">%s</span>' % t
|
||||
self.valid = False
|
||||
|
||||
|
||||
self.examplelabel.set_text(sample)
|
||||
self.examplelabel.set_use_markup(True)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2004-2006 Donald N. Allingham
|
||||
# Copyright (C) 2004-2007 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
|
||||
@ -39,6 +39,7 @@ import re
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Name
|
||||
import Config
|
||||
from Errors import NameDisplayError
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -373,7 +374,7 @@ class NameDisplay:
|
||||
# for each one we find the variable name that is needed to
|
||||
# replace it and add this to a list. This list will be used
|
||||
# generate the replacement tuple.
|
||||
pat = re.compile("%.")
|
||||
pat = re.compile('|'.join(d.keys()))
|
||||
|
||||
param = ()
|
||||
mat = pat.search(format_str)
|
||||
@ -433,10 +434,14 @@ class NameDisplay:
|
||||
func = self._gen_cooked_func(format_str)
|
||||
self.__class__.format_funcs[format_str] = func
|
||||
|
||||
s = func(first,surname,prefix,suffix,patronymic,title,call)
|
||||
try:
|
||||
s = func(first,surname,prefix,suffix,patronymic,title,call)
|
||||
except (ValueError,TypeError,):
|
||||
raise NameDisplayError, "Incomplete format string"
|
||||
|
||||
return ' '.join(s.split())
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
def sort_string(self,name):
|
||||
return u"%-25s%-30s%s" % (name.surname,name.first_name,name.suffix)
|
||||
|
Loading…
Reference in New Issue
Block a user