Working namedisplay

Working display section in preferences


svn: r15946
This commit is contained in:
Benny Malengier 2010-10-01 21:22:25 +00:00
parent f111dcbad9
commit e9599d762d
4 changed files with 164 additions and 230 deletions

View File

@ -1095,13 +1095,18 @@ def profile(func, *args):
# keyword, code, translated standard, translated upper # keyword, code, translated standard, translated upper
KEYWORDS = [("title", "t", _("Person|Title"), _("Person|TITLE")), KEYWORDS = [("title", "t", _("Person|Title"), _("Person|TITLE")),
("given", "f", _("Given"), _("GIVEN")), ("given", "f", _("Given"), _("GIVEN")),
("prefix", "p", _("Prefix"), _("PREFIX")), ("surname", "l", _("Surname"), _("SURNAME")),
("surname", "l", _("Surname"), _("SURNAME")), ("call", "c", _("Name|Call"), _("Name|CALL")),
("common", "x", _("Name|Common"), _("Name|COMMON")),
("initials", "i", _("Initials"), _("INITIALS")),
("suffix", "s", _("Suffix"), _("SUFFIX")), ("suffix", "s", _("Suffix"), _("SUFFIX")),
("patronymic","y", _("Patronymic"),_("PATRONYMIC")), ("rawsurnames", "q", _("Rawsurnames"), _("RAWSURNAMES")),
("call", "c", _("Call"), _("CALL")), ("patronymic", "y", _("Patronymic"), _("PATRONYMIC")),
("common", "x", _("Common"), _("COMMON")), ("notpatronymic", "o", _("Notpatronymic"),_("NOTPATRONYMIC")),
("initials", "i", _("Initials"), _("INITIALS")) ("primary", "m", _("Primary"), _("PRIMARY")),
("prefix", "p", _("Prefix"), _("PREFIX")),
("nickname", "n", _("Nickname"), _("NICKNAME")),
("familynick", "g", _("Familynick"), _("FAMILYNICK")),
] ]
KEY_TO_TRANS = {} KEY_TO_TRANS = {}
TRANS_TO_KEY = {} TRANS_TO_KEY = {}

View File

@ -31,7 +31,7 @@ Specific symbols for parts of a name are defined:
'c' : callname 'c' : callname
'x' : callname if existing, otherwise first first name (common name) 'x' : callname if existing, otherwise first first name (common name)
'i' : initials of the first names 'i' : initials of the first names
'f' : patronymic surname (father) 'y' : patronymic surname (father)
'o' : surnames without patronymic 'o' : surnames without patronymic
'm' : primary surname (main) 'm' : primary surname (main)
'p' : list of all prefixes 'p' : list of all prefixes
@ -101,7 +101,11 @@ _F_RAWFN = 4 # name format raw function
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# Because of occurring in an exec(), this couldn't be in a lambda: # Because of occurring in an exec(), this couldn't be in a lambda:
def _make_cmp(a, b): return -cmp(a[1], b[1]) # we sort names first on longest first, then last letter first, this to
# avoid translations of shorter terms which appear in longer ones, eg
# namelast may not be mistaken with name, so namelast must first be
# converted to %k before name is converted.
def _make_cmp(a, b): return -cmp((len(a[1]),a[1]), (len(b[1]), b[1]))
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -144,7 +148,7 @@ def _raw_primary_surname(raw_surn_data_list):
return '' return ''
def _raw_patro_surname(raw_surn_data_list): def _raw_patro_surname(raw_surn_data_list):
"""method for the 'f' symbol: patronymic surname""" """method for the 'y' symbol: patronymic surname"""
for raw_surn_data in raw_surn_data_list: for raw_surn_data in raw_surn_data_list:
if raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINPATRO: if raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINPATRO:
result = "%s %s" % (raw_surn_data[_PREFIX_IN_LIST], result = "%s %s" % (raw_surn_data[_PREFIX_IN_LIST],
@ -191,11 +195,11 @@ class NameDisplay(object):
STANDARD_FORMATS = [ STANDARD_FORMATS = [
(Name.DEF,_("Default format (defined by Gramps preferences)"),'',_ACT), (Name.DEF,_("Default format (defined by Gramps preferences)"),'',_ACT),
(Name.LNFN,_("Surname, Given"),'%p %l, %f %s',_ACT), (Name.LNFN,_("Surname, Given"),'%l, %f %s',_ACT),
(Name.FN,_("Given"),'%f',_ACT), (Name.FN,_("Given"),'%f',_ACT),
(Name.FNLN,_("Given Surname"),'%f %p %l %s',_ACT), (Name.FNLN,_("Given Surname"),'%f %l %s',_ACT),
# DEPRECATED FORMATS # DEPRECATED FORMATS
(Name.PTFN,_("Patronymic, Given"),'%p %y, %s %f',_INA), (Name.PTFN,_("Patronymic, Given"),'%y, %s %f',_INA),
] ]
def __init__(self): def __init__(self):
@ -352,21 +356,21 @@ class NameDisplay(object):
raw_data[_FIRSTNAME], raw_data[_FIRSTNAME],
raw_data[_SUFFIX]) raw_data[_SUFFIX])
Specific symbols for parts of a name are defined: Specific symbols for parts of a name are defined (keywords given):
't' : title 't' : title = title
'f' : given (first names) 'f' : given = given (first names)
'l' : full surname (lastname) 'l' : surname = full surname (lastname)
'c' : callname 'c' : call = callname
'x' : callname if existing, otherwise first first name (common name) 'x' : common = callname if existing, otherwise first first name (common name)
'i' : initials of the first names 'i' : initials = initials of the first names
'f' : patronymic surname (father) 'y' : patronymic = patronymic surname (father)
'o' : surnames without patronymic 'o' : notpatronymic = surnames without patronymic
'm' : primary surname (main) 'm' : primary = primary surname (main)
'p' : list of all prefixes 'p' : prefix = list of all prefixes
'q' : surnames without prefixes and connectors 'q' : rawsurnames = surnames without prefixes and connectors
's' : suffix 's' : suffix = suffix
'n' : nick name 'n' : nickname = nick name
'g' : family nick name 'g' : familynick = family nick name
""" """
@ -374,39 +378,39 @@ class NameDisplay(object):
# called to fill in each format flag. # called to fill in each format flag.
# Dictionary is "code": ("expression", "keyword", "i18n-keyword") # Dictionary is "code": ("expression", "keyword", "i18n-keyword")
d = {"t": ("raw_data[_TITLE]", "title", d = {"t": ("raw_data[_TITLE]", "title",
_("String replacement keyword Person|title")), _("Person|title")),
"f": ("raw_data[_FIRSTNAME]", "given", "f": ("raw_data[_FIRSTNAME]", "given",
_("String replacement keyword|given")), _("given")),
"l": ("_raw_full_surname(raw_data[_SURNAME_LIST])", "surname", "l": ("_raw_full_surname(raw_data[_SURNAME_LIST])", "surname",
_("String replacement keyword|surname")), _("surname")),
"s": ("raw_data[_SUFFIX]", "suffix", "s": ("raw_data[_SUFFIX]", "suffix",
_("String replacement keyword|suffix")), _("suffix")),
"c": ("raw_data[_CALL]", "call", "c": ("raw_data[_CALL]", "call",
_("String replacement keyword|call")), _("Name|call")),
"x": ("(raw_data[_CALL] or raw_data[_FIRSTNAME].split(' ')[0])", "x": ("(raw_data[_CALL] or raw_data[_FIRSTNAME].split(' ')[0])",
"common", "common",
_("String replacement keyword|common")), _("Name|common")),
"i": ("''.join([word[0] +'.' for word in ('. ' +" + "i": ("''.join([word[0] +'.' for word in ('. ' +" +
" raw_data[_FIRSTNAME]).split()][1:])", " raw_data[_FIRSTNAME]).split()][1:])",
"initials", "initials",
_("String replacement keyword|initials")), _("initials")),
"f": ("_raw_patro_surname(raw_data[_SURNAME_LIST])", "patronymic", "y": ("_raw_patro_surname(raw_data[_SURNAME_LIST])", "patronymic",
_("String replacement keyword|patronymic")), _("patronymic")),
"o": ("_raw_nonpatro_surname(raw_data[_SURNAME_LIST])", "notpatronymic", "o": ("_raw_nonpatro_surname(raw_data[_SURNAME_LIST])", "notpatronymic",
_("String replacement keyword|notpatronymic")), _("notpatronymic")),
"m": ("_raw_primary_surname(raw_data[_SURNAME_LIST])", "m": ("_raw_primary_surname(raw_data[_SURNAME_LIST])",
"primarysurname", "primary",
_("String replacement keyword|primarysurname")), _("Name|primary")),
"p": ("_raw_prefix_surname(raw_data[_SURNAME_LIST])", "p": ("_raw_prefix_surname(raw_data[_SURNAME_LIST])",
"prefix", "prefix",
_("String replacement keyword|prefix")), _("prefix")),
"q": ("_raw_single_surname(raw_data[_SURNAME_LIST])", "q": ("_raw_single_surname(raw_data[_SURNAME_LIST])",
"rawsurnames", "rawsurnames",
_("String replacement keyword|rawsurnames")), _("rawsurnames")),
"n": ("raw_data[_NICK]", "nickname", "n": ("raw_data[_NICK]", "nickname",
_("String replacement keyword|nickname")), _("nickname")),
"g": ("raw_data[_FAMNICK]", "famnick", "g": ("raw_data[_FAMNICK]", "familynick",
_("String replacement keyword|famnick")), _("familynick")),
} }
args = "raw_data" args = "raw_data"
return self._make_fn(format_str, d, args) return self._make_fn(format_str, d, args)
@ -427,55 +431,56 @@ class NameDisplay(object):
def fn(first, raw_surname_list, suffix, title, call,): def fn(first, raw_surname_list, suffix, title, call,):
return "%s %s" % (first,suffix) return "%s %s" % (first,suffix)
Specific symbols for parts of a name are defined: Specific symbols for parts of a name are defined (keywords given):
't' : title 't' : title = title
'f' : given (first names) 'f' : given = given (first names)
'l' : full surname (lastname) 'l' : surname = full surname (lastname)
'c' : callname 'c' : call = callname
'x' : callname if existing, otherwise first first name (common name) 'x' : common = callname if existing, otherwise first first name (common name)
'i' : initials of the first names 'i' : initials = initials of the first names
'f' : patronymic surname (father) 'y' : patronymic = patronymic surname (father)
'o' : surnames without patronymic 'o' : notpatronymic = surnames without patronymic
'm' : primary surname (main) 'm' : primary = primary surname (main)
'p' : list of all prefixes 'p' : prefix = list of all prefixes
'q' : surnames without prefixes and connectors 'q' : rawsurnames = surnames without prefixes and connectors
's' : suffix 's' : suffix = suffix
'n' : nick name 'n' : nickname = nick name
'g' : family nick name 'g' : familynick = family nick name
""" """
# 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.
# Dictionary is "code": ("expression", "keyword", "i18n-keyword") # Dictionary is "code": ("expression", "keyword", "i18n-keyword")
d = {"t": ("title", "title", d = {"t": ("title", "title",
_("String replacement keyword Person|title")), _("Person|title")),
"f": ("first", "given", "f": ("first", "given",
_("String replacement keyword|given")), _("given")),
"l": ("_raw_full_surname(raw_surname_list)", "surname", "l": ("_raw_full_surname(raw_surname_list)", "surname",
_("String replacement keyword|surname")), _("surname")),
"s": ("suffix", "suffix", "s": ("suffix", "suffix",
_("String replacement keyword|suffix")), _("suffix")),
"c": ("call", "call", "c": ("call", "call",
_("String replacement keyword|call")), _("Name|call")),
"x": ("(call or first.split(' ')[0])", "common", "x": ("(call or first.split(' ')[0])", "common",
_("String replacement keyword|common")), _("Name|common")),
"i": ("''.join([word[0] +'.' for word in ('. ' + first).split()][1:])", "i": ("''.join([word[0] +'.' for word in ('. ' + first).split()][1:])",
"initials", "initials",
_("String replacement keyword|initials")), _("initials")),
"f": ("_raw_patro_surname(raw_surname_list)", "patronymic", "y": ("_raw_patro_surname(raw_surname_list)", "patronymic",
_("String replacement keyword|patronymic")), _("patronymic")),
"o": ("_raw_nonpatro_surname(raw_surname_list)", "notpatro", "o": ("_raw_nonpatro_surname(raw_surname_list)", "notpatronymic",
_("String replacement keyword|notpatro")), _("notpatronymic")),
"m": ("_raw_primary_surname(raw_surname_list)", "primary", "m": ("_raw_primary_surname(raw_surname_list)", "primary",
_("String replacement keyword name|primary")), _("Name|primary")),
"p": ("_raw_prefix_surname(raw_surname_list)", "prefix", "p": ("_raw_prefix_surname(raw_surname_list)", "prefix",
_("String replacement keyword|prefix")), _("prefix")),
"q": ("_raw_single_surname(raw_surname_list)", "rawlastnames", "q": ("_raw_single_surname(raw_surname_list)", "rawsurnames",
_("String replacement keyword|rawlastnames")), _("rawsurnames")),
"n": ("nick", "nickname", "n": ("nick", "nickname",
_("String replacement keyword|nickname")), _("nickname")),
"g": ("famnick", "famnick", "g": ("famnick", "familynick",
_("String replacement keyword|famnick")), _("familynick")),
} }
args = "first,raw_surname_list,suffix,title,call,nick,famnick" args = "first,raw_surname_list,suffix,title,call,nick,famnick"
return self._make_fn(format_str, d, args) return self._make_fn(format_str, d, args)
@ -497,7 +502,7 @@ class NameDisplay(object):
pass pass
else: else:
d_keys = [(code, _tuple[2]) for code, _tuple in d.iteritems()] d_keys = [(code, _tuple[2]) for code, _tuple in d.iteritems()]
d_keys.sort(_make_cmp) # reverse sort by ikeyword d_keys.sort(_make_cmp) # reverse on length and by ikeyword
for (code, ikeyword) in d_keys: for (code, ikeyword) in d_keys:
exp, keyword, ikeyword = d[code] exp, keyword, ikeyword = d[code]
#ikeyword = unicode(ikeyword, "utf8") #ikeyword = unicode(ikeyword, "utf8")
@ -513,7 +518,7 @@ class NameDisplay(object):
pass pass
else: else:
d_keys = [(code, _tuple[1]) for code, _tuple in d.iteritems()] d_keys = [(code, _tuple[1]) for code, _tuple in d.iteritems()]
d_keys.sort(_make_cmp) # reverse sort by keyword d_keys.sort(_make_cmp) # reverse sort on length and by keyword
# if in double quotes, just use % codes # if in double quotes, just use % codes
for (code, keyword) in d_keys: for (code, keyword) in d_keys:
exp, keyword, ikeyword = d[code] exp, keyword, ikeyword = d[code]
@ -613,7 +618,7 @@ def fn(%s):
'%c' : callname '%c' : callname
'%x' : callname if existing, otherwise first first name (common name) '%x' : callname if existing, otherwise first first name (common name)
'%i' : initials of the first names '%i' : initials of the first names
'%f' : patronymic surname (father) '%y' : patronymic surname (father)
'%o' : surnames without patronymic '%o' : surnames without patronymic
'%m' : primary surname (main) '%m' : primary surname (main)
'%p' : list of all prefixes '%p' : list of all prefixes

View File

@ -188,5 +188,8 @@ class Surname(SecondaryObject):
"""Set if this surname is the primary surname.replace """Set if this surname is the primary surname.replace
Use :class:`~gen.lib.surname.SurnameBase` to set the primary surname Use :class:`~gen.lib.surname.SurnameBase` to set the primary surname
via :method:`~gen.lib.surname.SurnameBase.set_primary_surname` via :method:`~gen.lib.surname.SurnameBase.set_primary_surname`
:param primary: primay surname or not
:type primary: bool
""" """
self.primary = primary self.primary = primary

View File

@ -53,7 +53,7 @@ from gen.display.name import displayer as _nd
from gen.display.name import NameDisplayError from gen.display.name import NameDisplayError
import Utils import Utils
import gen.lib import gen.lib
from gen.lib import Name from gen.lib import Name, Surname, NameOriginType
import ManagedWindow import ManagedWindow
from gui.widgets import MarkupLabel, BasicLabel from gui.widgets import MarkupLabel, BasicLabel
from QuestionDialog import ErrorDialog, QuestionDialog2, OkDialog from QuestionDialog import ErrorDialog, QuestionDialog2, OkDialog
@ -98,21 +98,28 @@ class DisplayNameEditor(ManagedWindow.ManagedWindow):
table = self.dialog._build_custom_name_ui() table = self.dialog._build_custom_name_ui()
label = gtk.Label(_("""The following keywords will be replaced with the name: label = gtk.Label(_("""The following keywords will be replaced with the name:
<tt> <tt>
<b>Given</b> - given name (first name) <b>Given</b> - given name (first name) | <b>Surname</b> - surnames (with prefix and connectors)
<b>Surname</b> - surname (last name) <b>Title</b> - title (Dr., Mrs.) | <b>Suffix</b> - suffix (Jr., Sr.)
<b>Title</b> - title (Dr., Mrs.) <b>Call</b> - call name | <b>Nickname</b> - nick name
<b>Prefix</b> - prefix (von, de, de la) <b>Initials</b> - first letters of Given | <b>Common</b> - Call, otherwise first of Given
<b>Suffix</b> - suffix (Jr., Sr.) <b>Primary</b> - primary surname (main) | <b>Familynick</b> - Family nick name
<b>Call</b> - call name, or nickname Also:
<b>Common</b> - call name, otherwise first part of Given <b>Patronymic</b> - patronymic surname (father's name)
<b>Patronymic</b> - patronymic (father's name) <b>Notpatronymic</b> - all surnames except patronymic
<b>Initials</b> - persons's first letters of given names <b>Prefix</b> - all surnames prefixes (von, de, de la)
<b>Rawsurnames</b> - all surnames without prefixes and connectors
</tt> </tt>
Use the same keyword in UPPERCASE to force to upper. Parentheses and commas Use the same keyword in UPPERCASE to force to upper. Parentheses and commas
will be removed around empty fields. Other text will appear literally.""")) will be removed around empty fields. Other text will appear literally.
<b>Example fictituous name</b>: 'Dr. Edwin Jose von der Smith and Weston Wilson Sr ("Ed") - Underhills'
Here <i>Edwin Jose</i> are given names, <i>Smith</i> and <i>Weston</i> surnames, <i>Wilson</i> patronymic surname,
<i>Dr.</i> a title, <i>Sr</i> a suffix, <i>Ed</i> the nick name, <i>Underhills</i> family nick name.
Callname is <i>Jose</i>.
"""))
label.set_use_markup(True) label.set_use_markup(True)
self.window.vbox.add(label) self.window.vbox.pack_start(label, expand=False)
self.window.vbox.add(table) self.window.vbox.pack_start(table)
self.window.set_default_size(600, 550) self.window.set_default_size(600, 550)
self.window.connect('response', self.close) self.window.connect('response', self.close)
self.show() self.show()
@ -520,7 +527,7 @@ class GrampsPreferences(ConfigureDialog):
gobject.TYPE_STRING, gobject.TYPE_STRING,
gobject.TYPE_STRING, gobject.TYPE_STRING,
gobject.TYPE_STRING) gobject.TYPE_STRING)
index = 0 index = 0
the_index = 0 the_index = 0
for num, name, fmt_str, act in _nd.get_name_format(): for num, name, fmt_str, act in _nd.get_name_format():
translation = fmt_str translation = fmt_str
@ -538,40 +545,49 @@ class GrampsPreferences(ConfigureDialog):
lyst = ["%s, %s %s (%s)" % (_("Surname"), _("Given"), _("Suffix"), lyst = ["%s, %s %s (%s)" % (_("Surname"), _("Given"), _("Suffix"),
_("Common")), _("Common")),
"%s, %s %s (%s)" % (_("Surname"), _("Given"), _("Suffix"), "%s, %s %s (%s)" % (_("Surname"), _("Given"), _("Suffix"),
_("Call")), _("Nickname")),
"%s, %s %s (%s)" % (_("Surname"), _("Name|Common"), _("Suffix"),
_("Nickname")),
"%s, %s %s" % (_("Surname"), _("Name|Common"), _("Suffix")),
"%s, %s %s (%s)" % (_("SURNAME"), _("Given"), _("Suffix"), "%s, %s %s (%s)" % (_("SURNAME"), _("Given"), _("Suffix"),
_("Call")), _("Call")),
"%s, %s (%s)" % (_("Surname"), _("Given"), _("Common")), "%s, %s (%s)" % (_("Surname"), _("Given"), _("Name|Common")),
"%s, %s (%s)" % (_("Surname"), _("Given"), _("Call")), "%s, %s (%s)" % (_("Surname"), _("Name|Common"), _("Nickname")),
"%s %s" % (_("Given"), _("Surname")), "%s %s" % (_("Given"), _("Surname")),
"%s %s, %s" % (_("Given"), _("Surname"), _("Suffix")), "%s %s, %s" % (_("Given"), _("Surname"), _("Suffix")),
"%s %s %s" % (_("Given"), _("Surname"), _("Patronymic")), "%s %s %s" % (_("Given"), _("NotPatronymic"), _("Patronymic")),
"%s, %s %s (%s)" % (_("SURNAME"), _("Given"), _("Suffix"), "%s, %s %s (%s)" % (_("SURNAME"), _("Given"), _("Suffix"),
_("Common")), _("Common")),
"%s, %s (%s)" % (_("SURNAME"), _("Given"), _("Common")), "%s, %s (%s)" % (_("SURNAME"), _("Given"), _("Name|Common")),
"%s, %s (%s)" % (_("SURNAME"), _("Given"), _("Call")), "%s, %s (%s)" % (_("SURNAME"), _("Given"), _("Nickname")),
"%s %s" % (_("Given"), _("SURNAME")), "%s %s" % (_("Given"), _("SURNAME")),
"%s %s, %s" % (_("Given"), _("SURNAME"), _("Suffix")), "%s %s, %s" % (_("Given"), _("SURNAME"), _("Suffix")),
"%s /%s/" % (_("Given"), _("SURNAME")), "%s /%s/" % (_("Given"), _("SURNAME")),
"%s %s, %s" % (_("Given"), _("Rawsurnames"), _("Suffix")),
] ]
fmtlyst = ["%s, %s %s (%s)" % ("Surname", "Given", "Suffix", #repeat above list, but not translated.
"Common"), fmtlyst = ["%s, %s %s (%s)" % (("Surname"), ("Given"), ("Suffix"),
"%s, %s %s (%s)" % ("Surname", "Given", "Suffix", ("Common")),
"Call"), "%s, %s %s (%s)" % (("Surname"), ("Given"), ("Suffix"),
"%s, %s %s (%s)" % ("SURNAME", "Given", "Suffix", ("Nickname")),
"Call"), "%s, %s %s (%s)" % (("Surname"), ("Name|Common"), ("Suffix"),
"%s, %s (%s)" % ("Surname", "Given", "Common"), ("Nickname")),
"%s, %s (%s)" % ("Surname", "Given", "Call"), "%s, %s %s" % (("Surname"), ("Name|Common"), ("Suffix")),
"%s %s" % ("Given", "Surname"), "%s, %s %s (%s)" % (("SURNAME"), ("Given"), ("Suffix"),
"%s %s, %s" % ("Given", "Surname", "Suffix"), ("Call")),
"%s %s %s" % ("Given", "Surname", "Patronymic"), "%s, %s (%s)" % (("Surname"), ("Given"), ("Name|Common")),
"%s, %s %s (%s)" % ("SURNAME", "Given", "Suffix", "%s, %s (%s)" % (("Surname"), ("Name|Common"), ("Nickname")),
"Common"), "%s %s" % (("Given"), ("Surname")),
"%s, %s (%s)" % ("SURNAME", "Given", "Common"), "%s %s, %s" % (("Given"), ("Surname"), ("Suffix")),
"%s, %s (%s)" % ("SURNAME", "Given", "Call"), "%s %s %s" % (("Given"), ("NotPatronymic"), ("Patronymic")),
"%s %s" % ("Given", "SURNAME"), "%s, %s %s (%s)" % (("SURNAME"), ("Given"), ("Suffix"),
"%s %s, %s" % ("Given", "SURNAME", "Suffix"), ("Common")),
"%s /%s/" % ("Given", "SURNAME"), "%s, %s (%s)" % (("SURNAME"), ("Given"), ("Name|Common")),
"%s, %s (%s)" % (("SURNAME"), ("Given"), ("Nickname")),
"%s %s" % (("Given"), ("SURNAME")),
"%s %s, %s" % (("Given"), ("SURNAME"), ("Suffix")),
"%s /%s/" % (("Given"), ("SURNAME")),
"%s %s, %s" % (("Given"), ("Rawsurnames"), ("Suffix")),
] ]
rand = int(random.random() * len(lyst)) rand = int(random.random() * len(lyst))
f = lyst[rand] f = lyst[rand]
@ -722,11 +738,9 @@ class GrampsPreferences(ConfigureDialog):
self.insert_button = gtk.Button(stock=gtk.STOCK_ADD) self.insert_button = gtk.Button(stock=gtk.STOCK_ADD)
self.insert_button.connect('clicked', self.__new_name) self.insert_button.connect('clicked', self.__new_name)
#self.cb_insert_fmt_str)
self.edit_button = gtk.Button(stock=gtk.STOCK_EDIT) self.edit_button = gtk.Button(stock=gtk.STOCK_EDIT)
self.edit_button.connect('clicked', self.__edit_name) self.edit_button.connect('clicked', self.__edit_name)
#self.cb_edit_fmt_str)
self.edit_button.set_sensitive(False) self.edit_button.set_sensitive(False)
self.remove_button = gtk.Button(stock=gtk.STOCK_REMOVE) self.remove_button = gtk.Button(stock=gtk.STOCK_REMOVE)
@ -781,44 +795,6 @@ class GrampsPreferences(ConfigureDialog):
self.edit_button.set_sensitive(idx) self.edit_button.set_sensitive(idx)
self.name_renderer.set_property('editable', idx) self.name_renderer.set_property('editable', idx)
def cb_edit_fmt_str(self, obj):
"""
Name format editor Edit button callback
"""
num, name, fmt = self.selected_fmt[COL_NUM:COL_EXPL]
dlg = NameFormatEditDlg(name, fmt, self.examplename)
dlg.dlg.set_transient_for(self.window)
(res, name, fmt) = dlg.run()
if res == gtk.RESPONSE_OK and (name != self.selected_fmt[COL_NAME] or
fmt != self.selected_fmt[COL_FMT]):
exmpl = _nd.format_str(self.examplename, fmt)
self.fmt_model.set(self.iter, COL_NAME, name,
COL_FMT, fmt,
COL_EXPL, exmpl)
self.selected_fmt = (num, name, fmt, exmpl)
_nd.edit_name_format(num, name, fmt)
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
only_active=False)
def cb_insert_fmt_str(self, obj):
"""
Name format editor Insert button callback
"""
dlg = NameFormatEditDlg('', '', self.examplename)
dlg.dlg.set_transient_for(self.window)
(res, n, f) = dlg.run()
if res == gtk.RESPONSE_OK:
i = _nd.add_name_format(n, f)
self.fmt_model.append(row=[i, n, f,
_nd.format_str(self.examplename, f)])
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
only_active=False)
def cb_del_fmt_str(self, obj): def cb_del_fmt_str(self, obj):
""" """
Name format editor Remove button callback Name format editor Remove button callback
@ -842,13 +818,26 @@ class GrampsPreferences(ConfigureDialog):
# Display name: # Display name:
self.examplename = Name() self.examplename = Name()
examplesurname = Surname()
examplesurnamesecond = Surname()
examplesurnamepat = Surname()
self.examplename.set_title('Dr.') self.examplename.set_title('Dr.')
self.examplename.set_first_name('Edwin Jose') self.examplename.set_first_name('Edwin Jose')
self.examplename.set_surname_prefix('von der') examplesurname.set_prefix('von der')
self.examplename.set_surname('Smith') examplesurname.set_surname('Smith')
examplesurname.set_connector('and')
self.examplename.add_surname(examplesurname)
examplesurnamesecond.set_surname('Weston')
self.examplename.add_surname(examplesurnamesecond)
examplesurnamepat.set_surname('Wilson')
examplesurnamepat.set_origintype(
NameOriginType(NameOriginType.PATRONYMIC))
self.examplename.add_surname(examplesurnamepat)
self.examplename.set_primary_surname(0)
self.examplename.set_suffix('Sr') self.examplename.set_suffix('Sr')
self.examplename.set_patronymic('Wilson') self.examplename.set_call_name('Jose')
self.examplename.set_call_name('Ed') self.examplename.set_nick_name('Ed')
self.examplename.set_family_nick_name('Underhills')
# get the model for the combo and the treeview # get the model for the combo and the treeview
active = _nd.get_default_format() active = _nd.get_default_format()
self.fmt_model, active = self._build_name_format_model(active) self.fmt_model, active = self._build_name_format_model(active)
@ -1186,71 +1175,3 @@ class GrampsPreferences(ConfigureDialog):
button.add(image) button.add(image)
button.show() button.show()
return button return button
class NameFormatEditDlg(object):
"""
"""
def __init__(self, fmt_name, fmt_str, name):
self.fmt_name = fmt_name
self.fmt_str = fmt_str
self.name = name
self.valid = True
self.top = Glade()
self.dlg = self.top.get_object('namefmt_edit')
ManagedWindow.set_titles(self.dlg, None, _('Name Format Editor'))
self.examplelabel = self.top.get_object('example_label')
self.nameentry = self.top.get_object('name_entry')
self.nameentry.set_text('<span weight="bold">%s</span>' % self.fmt_name)
self.nameentry.set_use_markup(True)
self.formatentry = self.top.get_object('format_entry')
self.formatentry.connect('changed', self.cb_format_changed)
self.formatentry.set_text(self.fmt_str)
def run(self):
running = True
while running:
self.response = self.dlg.run()
running = False
self.fmt_name = self.nameentry.get_text()
self.fmt_str = self.formatentry.get_text()
if self.response == gtk.RESPONSE_OK:
if not self.valid:
q = 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
elif (self.fmt_name == '') ^ (self.fmt_str == ''):
ErrorDialog(
_('Both Format name and definition have to be defined.'),
parent=self.dlg)
running = True
self.dlg.destroy()
return (self.response, self.fmt_name, self.fmt_str)
def cb_format_changed(self, obj):
try:
t = (_nd.format_str(self.name, escape(obj.get_text())))
sample = '<span weight="bold" style="italic">%s</span>' % t
self.valid = True
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)
self.nameentry.set_text('<span weight="bold">%s</span>' % obj.get_text())
self.nameentry.set_use_markup(True)