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. svn: r8619
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
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.
|
||||||
|
|
||||||
2007-06-20 Alex Roitman <shura@gramps-project.org>
|
2007-06-20 Alex Roitman <shura@gramps-project.org>
|
||||||
* src/Filters/Rules/Person/_RelationshipPathBetween.py
|
* src/Filters/Rules/Person/_RelationshipPathBetween.py
|
||||||
(apply_filter): Object/handle mixup, #1090.
|
(apply_filter): Object/handle mixup, #1090.
|
||||||
|
|||||||
@@ -372,12 +372,12 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
Name format editor Edit button callback
|
Name format editor Edit button callback
|
||||||
"""
|
"""
|
||||||
num,name,fmt = self.selected_fmt[COL_NUM:COL_EXPL]
|
num,name,fmt = self.selected_fmt[COL_NUM:COL_EXPL]
|
||||||
dlg = NameFormatEditDlg(name,fmt,self.examplename)
|
dlg = NameFormatEditDlg(name, fmt, self.examplename)
|
||||||
dlg.dlg.set_transient_for(self.window)
|
dlg.dlg.set_transient_for(self.window)
|
||||||
(res,name,fmt) = dlg.run()
|
(res,name,fmt) = dlg.run()
|
||||||
|
|
||||||
if name != self.selected_fmt[COL_NAME] or \
|
if res == gtk.RESPONSE_OK and (name != self.selected_fmt[COL_NAME] or
|
||||||
fmt != self.selected_fmt[COL_FMT]:
|
fmt != self.selected_fmt[COL_FMT]):
|
||||||
exmpl = _nd.format_str(self.examplename,fmt)
|
exmpl = _nd.format_str(self.examplename,fmt)
|
||||||
self.fmt_model.set(self.iter,COL_NAME,name,
|
self.fmt_model.set(self.iter,COL_NAME,name,
|
||||||
COL_FMT,fmt,
|
COL_FMT,fmt,
|
||||||
@@ -570,12 +570,13 @@ class NameFormatEditDlg:
|
|||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,fmt_name,fmt_str,name):
|
def __init__(self, fmt_name, fmt_str, name):
|
||||||
self.fmt_name = fmt_name
|
self.fmt_name = fmt_name
|
||||||
self.fmt_str = fmt_str
|
self.fmt_str = fmt_str
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.valid = True
|
||||||
|
|
||||||
self.top = gtk.glade.XML(const.gladeFile,'namefmt_edit','gramps')
|
self.top = gtk.glade.XML(const.gladeFile, 'namefmt_edit','gramps')
|
||||||
self.dlg = self.top.get_widget('namefmt_edit')
|
self.dlg = self.top.get_widget('namefmt_edit')
|
||||||
ManagedWindow.set_titles(self.dlg, None, _('Name Format Editor'))
|
ManagedWindow.set_titles(self.dlg, None, _('Name Format Editor'))
|
||||||
|
|
||||||
@@ -585,7 +586,7 @@ class NameFormatEditDlg:
|
|||||||
self.nameentry.set_text(self.fmt_name)
|
self.nameentry.set_text(self.fmt_name)
|
||||||
|
|
||||||
self.formatentry = self.top.get_widget('format_entry')
|
self.formatentry = self.top.get_widget('format_entry')
|
||||||
self.formatentry.connect('changed',self.cb_format_changed)
|
self.formatentry.connect('changed', self.cb_format_changed)
|
||||||
self.formatentry.set_text(self.fmt_str)
|
self.formatentry.set_text(self.fmt_str)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@@ -598,7 +599,15 @@ class NameFormatEditDlg:
|
|||||||
self.fmt_str = self.formatentry.get_text()
|
self.fmt_str = self.formatentry.get_text()
|
||||||
|
|
||||||
if self.response == gtk.RESPONSE_OK:
|
if self.response == gtk.RESPONSE_OK:
|
||||||
if self.fmt_name == '' and self.fmt_str == '':
|
if not self.valid:
|
||||||
|
q = QuestionDialog.QuestionDialog2(
|
||||||
|
_('The format definition is invalid'),
|
||||||
|
_('What would you like to do?'),
|
||||||
|
_('_Continue anyway'), _('_Modify format'),
|
||||||
|
parent=self.dlg)
|
||||||
|
running = not q.run()
|
||||||
|
self.response = gtk.RESPONSE_CANCEL
|
||||||
|
elif self.fmt_name == '' and self.fmt_str == '':
|
||||||
self.response = gtk.RESPONSE_CANCEL
|
self.response = gtk.RESPONSE_CANCEL
|
||||||
elif (self.fmt_name == '') ^ (self.fmt_str == ''):
|
elif (self.fmt_name == '') ^ (self.fmt_str == ''):
|
||||||
QuestionDialog.ErrorDialog(
|
QuestionDialog.ErrorDialog(
|
||||||
@@ -609,11 +618,15 @@ class NameFormatEditDlg:
|
|||||||
self.dlg.destroy()
|
self.dlg.destroy()
|
||||||
return (self.response, self.fmt_name, self.fmt_str)
|
return (self.response, self.fmt_name, self.fmt_str)
|
||||||
|
|
||||||
def cb_format_changed(self,obj):
|
def cb_format_changed(self, obj):
|
||||||
try:
|
try:
|
||||||
t = (_nd.format_str(self.name,obj.get_text()))
|
t = (_nd.format_str(self.name, obj.get_text()))
|
||||||
|
sample = '<span weight="bold" style="italic">%s</span>' % t
|
||||||
|
self.valid = True
|
||||||
except ValueError, msg:
|
except ValueError, msg:
|
||||||
t = _("Invalid format string: %s") % msg
|
t = _("Invalid or incomplete format definition")
|
||||||
self.examplelabel.set_text(
|
sample = '<span foreground="#FF0000">%s</span>' % t
|
||||||
'<span weight="bold" style="italic">%s</span>' % t)
|
self.valid = False
|
||||||
|
|
||||||
|
self.examplelabel.set_text(sample)
|
||||||
self.examplelabel.set_use_markup(True)
|
self.examplelabel.set_use_markup(True)
|
||||||
|
|||||||
@@ -233,19 +233,19 @@ class NameDisplay:
|
|||||||
|
|
||||||
|
|
||||||
def _gen_raw_func(self, format_str):
|
def _gen_raw_func(self, format_str):
|
||||||
"""The job of building the name from a format string is rather
|
"""The job of building the name from a format string is rather
|
||||||
expensive and it is called lots and lots of times. So it is worth
|
expensive and it is called lots and lots of times. So it is worth
|
||||||
going to some length to optimise it as much as possible.
|
going to some length to optimise it as much as possible.
|
||||||
|
|
||||||
This method constructs a new function that is specifically written
|
This method constructs a new function that is specifically written
|
||||||
to format a name given a particualar format string. This is worthwhile
|
to format a name given a particualar format string. This is worthwhile
|
||||||
because the format string itself rarely changes, so by caching the new
|
because the format string itself rarely changes, so by caching the new
|
||||||
function and calling it directly when asked to format a name to the
|
function and calling it directly when asked to format a name to the
|
||||||
same format string again we can be as quick as possible.
|
same format string again we can be as quick as possible.
|
||||||
|
|
||||||
The new function is of the form:
|
The new function is of the form:
|
||||||
|
|
||||||
def fn(raw_data):
|
def fn(raw_data):
|
||||||
return "%s %s %s %s %s" % (raw_data[_TITLE],
|
return "%s %s %s %s %s" % (raw_data[_TITLE],
|
||||||
raw_data[_FIRSTNAME],
|
raw_data[_FIRSTNAME],
|
||||||
raw_data[_PREFIX],
|
raw_data[_PREFIX],
|
||||||
@@ -254,15 +254,15 @@ class NameDisplay:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# we need the names of each of the variables or methods that are
|
# we need the names of each of the variables or methods that are
|
||||||
# called to fill in each format flag.
|
# called to fill in each format flag.
|
||||||
d = {"%t":"raw_data[_TITLE]",
|
d = {"%t":"raw_data[_TITLE]",
|
||||||
"%f":"raw_data[_FIRSTNAME]",
|
"%f":"raw_data[_FIRSTNAME]",
|
||||||
"%p":"raw_data[_PREFIX]",
|
"%p":"raw_data[_PREFIX]",
|
||||||
"%l":"raw_data[_SURNAME]",
|
"%l":"raw_data[_SURNAME]",
|
||||||
"%s":"raw_data[_SUFFIX]",
|
"%s":"raw_data[_SUFFIX]",
|
||||||
"%y":"raw_data[_PATRONYM]",
|
"%y":"raw_data[_PATRONYM]",
|
||||||
"%c":"raw_data[_CALL]",
|
"%c":"raw_data[_CALL]",
|
||||||
"%T":"raw_data[_TITLE].upper()",
|
"%T":"raw_data[_TITLE].upper()",
|
||||||
"%F":"raw_data[_FIRSTNAME].upper()",
|
"%F":"raw_data[_FIRSTNAME].upper()",
|
||||||
"%P":"raw_data[_PREFIX].upper()",
|
"%P":"raw_data[_PREFIX].upper()",
|
||||||
@@ -274,8 +274,8 @@ class NameDisplay:
|
|||||||
|
|
||||||
new_fmt = format_str
|
new_fmt = format_str
|
||||||
|
|
||||||
# replace the specific format string flags with a
|
# replace the specific format string flags with a
|
||||||
# flag that works in standard python format strings.
|
# flag that works in standard python format strings.
|
||||||
new_fmt = new_fmt.replace("%t","%s")
|
new_fmt = new_fmt.replace("%t","%s")
|
||||||
new_fmt = new_fmt.replace("%f","%s")
|
new_fmt = new_fmt.replace("%f","%s")
|
||||||
new_fmt = new_fmt.replace("%p","%s")
|
new_fmt = new_fmt.replace("%p","%s")
|
||||||
@@ -293,10 +293,10 @@ class NameDisplay:
|
|||||||
new_fmt = new_fmt.replace("%C","%s")
|
new_fmt = new_fmt.replace("%C","%s")
|
||||||
new_fmt = new_fmt.replace("%%",'%')
|
new_fmt = new_fmt.replace("%%",'%')
|
||||||
|
|
||||||
# find each format flag in the original format string
|
# find each format flag in the original format string
|
||||||
# for each one we find the variable name that is needed to
|
# 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
|
# replace it and add this to a list. This list will be used
|
||||||
# generate the replacement tuple.
|
# generate the replacement tuple.
|
||||||
pat = re.compile("%.")
|
pat = re.compile("%.")
|
||||||
|
|
||||||
param = ()
|
param = ()
|
||||||
@@ -307,37 +307,37 @@ class NameDisplay:
|
|||||||
|
|
||||||
s = 'def fn(raw_data):\n'\
|
s = 'def fn(raw_data):\n'\
|
||||||
' return "%s" %% (%s)' % (new_fmt,",".join(param))
|
' return "%s" %% (%s)' % (new_fmt,",".join(param))
|
||||||
exec(s)
|
exec(s)
|
||||||
|
|
||||||
return fn
|
return fn
|
||||||
|
|
||||||
def _gen_cooked_func(self, format_str):
|
def _gen_cooked_func(self, format_str):
|
||||||
"""The job of building the name from a format string is rather
|
"""The job of building the name from a format string is rather
|
||||||
expensive and it is called lots and lots of times. So it is worth
|
expensive and it is called lots and lots of times. So it is worth
|
||||||
going to some length to optimise it as much as possible.
|
going to some length to optimise it as much as possible.
|
||||||
|
|
||||||
This method constructs a new function that is specifically written
|
This method constructs a new function that is specifically written
|
||||||
to format a name given a particualar format string. This is worthwhile
|
to format a name given a particualar format string. This is worthwhile
|
||||||
because the format string itself rarely changes, so by caching the new
|
because the format string itself rarely changes, so by caching the new
|
||||||
function and calling it directly when asked to format a name to the
|
function and calling it directly when asked to format a name to the
|
||||||
same format string again we can be as quick as possible.
|
same format string again we can be as quick as possible.
|
||||||
|
|
||||||
The new function is of the form:
|
The new function is of the form:
|
||||||
|
|
||||||
def fn(first,surname,prefix,suffix,patronymic,title,call,):
|
def fn(first,surname,prefix,suffix,patronymic,title,call,):
|
||||||
return "%s %s %s %s %s" % (first,surname,prefix,suffix,patronymic)
|
return "%s %s %s %s %s" % (first,surname,prefix,suffix,patronymic)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# we need the names of each of the variables or methods that are
|
# we need the names of each of the variables or methods that are
|
||||||
# called to fill in each format flag.
|
# called to fill in each format flag.
|
||||||
d = {"%t":"title",
|
d = {"%t":"title",
|
||||||
"%f":"first",
|
"%f":"first",
|
||||||
"%p":"prefix",
|
"%p":"prefix",
|
||||||
"%l":"surname",
|
"%l":"surname",
|
||||||
"%s":"suffix",
|
"%s":"suffix",
|
||||||
"%y":"patronymic",
|
"%y":"patronymic",
|
||||||
"%c":"call",
|
"%c":"call",
|
||||||
"%T":"title.upper()",
|
"%T":"title.upper()",
|
||||||
"%F":"first.upper()",
|
"%F":"first.upper()",
|
||||||
"%P":"prefix.upper()",
|
"%P":"prefix.upper()",
|
||||||
@@ -350,8 +350,8 @@ class NameDisplay:
|
|||||||
|
|
||||||
new_fmt = format_str
|
new_fmt = format_str
|
||||||
|
|
||||||
# replace the specific format string flags with a
|
# replace the specific format string flags with a
|
||||||
# flag that works in standard python format strings.
|
# flag that works in standard python format strings.
|
||||||
new_fmt = new_fmt.replace("%t","%s")
|
new_fmt = new_fmt.replace("%t","%s")
|
||||||
new_fmt = new_fmt.replace("%f","%s")
|
new_fmt = new_fmt.replace("%f","%s")
|
||||||
new_fmt = new_fmt.replace("%p","%s")
|
new_fmt = new_fmt.replace("%p","%s")
|
||||||
@@ -369,10 +369,10 @@ class NameDisplay:
|
|||||||
new_fmt = new_fmt.replace("%C","%s")
|
new_fmt = new_fmt.replace("%C","%s")
|
||||||
new_fmt = new_fmt.replace("%%",'%')
|
new_fmt = new_fmt.replace("%%",'%')
|
||||||
|
|
||||||
# find each format flag in the original format string
|
# find each format flag in the original format string
|
||||||
# for each one we find the variable name that is needed to
|
# 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
|
# replace it and add this to a list. This list will be used
|
||||||
# generate the replacement tuple.
|
# generate the replacement tuple.
|
||||||
pat = re.compile("%.")
|
pat = re.compile("%.")
|
||||||
|
|
||||||
param = ()
|
param = ()
|
||||||
@@ -383,7 +383,7 @@ class NameDisplay:
|
|||||||
|
|
||||||
s = 'def fn(first,surname,prefix,suffix,patronymic,title,call,):\n'\
|
s = 'def fn(first,surname,prefix,suffix,patronymic,title,call,):\n'\
|
||||||
' return "%s" %% (%s)' % (new_fmt,",".join(param))
|
' return "%s" %% (%s)' % (new_fmt,",".join(param))
|
||||||
exec(s)
|
exec(s)
|
||||||
|
|
||||||
return fn
|
return fn
|
||||||
|
|
||||||
@@ -393,19 +393,19 @@ class NameDisplay:
|
|||||||
name.call,format_str)
|
name.call,format_str)
|
||||||
|
|
||||||
def format_str_raw(self,raw_data,format_str):
|
def format_str_raw(self,raw_data,format_str):
|
||||||
"""
|
"""
|
||||||
Format a name from the raw name list. To make this as fast as possible
|
Format a name from the raw name list. To make this as fast as possible
|
||||||
this uses _gen_raw_func to generate a new method for each new format_string.
|
this uses _gen_raw_func to generate a new method for each new format_string.
|
||||||
|
|
||||||
Is does not call _format_str_base because it would introduce an extra
|
Is does not call _format_str_base because it would introduce an extra
|
||||||
method call and we need all the speed we can squeeze out of this.
|
method call and we need all the speed we can squeeze out of this.
|
||||||
"""
|
"""
|
||||||
func = self.__class__.raw_format_funcs.get(format_str)
|
func = self.__class__.raw_format_funcs.get(format_str)
|
||||||
if func == None:
|
if func == None:
|
||||||
func = self._gen_raw_func(format_str)
|
func = self._gen_raw_func(format_str)
|
||||||
self.__class__.raw_format_funcs[format_str] = func
|
self.__class__.raw_format_funcs[format_str] = func
|
||||||
|
|
||||||
s = func(raw_data)
|
s = func(raw_data)
|
||||||
return ' '.join(s.split())
|
return ' '.join(s.split())
|
||||||
|
|
||||||
|
|
||||||
@@ -433,7 +433,7 @@ class NameDisplay:
|
|||||||
func = self._gen_cooked_func(format_str)
|
func = self._gen_cooked_func(format_str)
|
||||||
self.__class__.format_funcs[format_str] = func
|
self.__class__.format_funcs[format_str] = func
|
||||||
|
|
||||||
s = func(first,surname,prefix,suffix,patronymic,title,call)
|
s = func(first,surname,prefix,suffix,patronymic,title,call)
|
||||||
return ' '.join(s.split())
|
return ' '.join(s.split())
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user