2006-07-31 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/NameDisplay.py: Rewrite in more object oriented way; Interface change. * src/ViewManager.py (post_load_newdb): Change of NameDisplay interface. * src/GrampsDb/_ReadXML.py (parse): Change of NameDisplay interface. * src/GrampsDb/_ReadGrdb.py (importData): Change of NameDisplay interface. * src/GrampsCfg.py: Change of NameDisplay interface; Name format Edit and Add callbacks divided. * src/RelLib/_Name.py: Default/standard name format definitions moved to NameDisplay. * src/Editors/_EditName.py (_setup_fields): Change of NameDisplay interface. * src/plugins/Check.py (cleanup_deleted_name_formats): Change of NameDisplay interface. svn: r7099
This commit is contained in:
parent
54ffac988b
commit
86edc9d446
@ -1,3 +1,19 @@
|
||||
2006-07-31 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
|
||||
* src/NameDisplay.py: Rewrite in more object oriented way; Interface
|
||||
change.
|
||||
* src/ViewManager.py (post_load_newdb): Change of NameDisplay interface.
|
||||
* src/GrampsDb/_ReadXML.py (parse): Change of NameDisplay interface.
|
||||
* src/GrampsDb/_ReadGrdb.py (importData): Change of NameDisplay
|
||||
interface.
|
||||
* src/GrampsCfg.py: Change of NameDisplay interface; Name format Edit
|
||||
and Add callbacks divided.
|
||||
* src/RelLib/_Name.py: Default/standard name format definitions moved to
|
||||
NameDisplay.
|
||||
* src/Editors/_EditName.py (_setup_fields): Change of NameDisplay
|
||||
interface.
|
||||
* src/plugins/Check.py (cleanup_deleted_name_formats): Change of
|
||||
NameDisplay interface.
|
||||
|
||||
2006-07-30 Don Allingham <don@gramps-project.org>
|
||||
* src/GrampsDb/_ReadGedcom.py: handle missing event type
|
||||
* src/DataViews/_PlaceView.py: add tooltip for map button
|
||||
|
@ -96,13 +96,8 @@ class EditName(EditSecondary):
|
||||
if not self.original_group_as:
|
||||
self.group_as.force_value(self.obj.get_surname())
|
||||
|
||||
|
||||
(number,name,fmt_str) = RelLib.Name.DEFAULT_FORMAT
|
||||
format_list = [(name,number)]
|
||||
format_list += [(name,number) for (number,name,fmt_str)
|
||||
in RelLib.Name.STANDARD_FORMATS]
|
||||
format_list += [(name,number) for (number,name,fmt_str,act)
|
||||
in NameDisplay.displayer.CUSTOM_FORMATS if act]
|
||||
format_list = [(name,number) for (number,name,fmt_str,act)
|
||||
in NameDisplay.displayer.get_name_format(also_default=True)]
|
||||
|
||||
self.sort_as = MonitoredMenu(
|
||||
self.top.get_widget('sort_as'),
|
||||
|
@ -237,9 +237,8 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
table.set_row_spacings(6)
|
||||
|
||||
# get the model for the combo and the treeview
|
||||
# index is used to set the active format in the combo quickly
|
||||
# and to find an unused index number when a new format is created
|
||||
(self.fmt_model, self.fmt_index) = self._build_name_format_model()
|
||||
active = _nd.get_default_format()
|
||||
self.fmt_model,active = self._build_name_format_model(active)
|
||||
|
||||
# set up the combo to choose the preset format
|
||||
self.fmt_obox = gtk.ComboBox()
|
||||
@ -249,10 +248,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
self.fmt_obox.set_model(self.fmt_model)
|
||||
|
||||
# set the default value as active in the combo
|
||||
active = int(Config.get(Config.NAME_FORMAT))
|
||||
if active == 0 or not self.fmt_index.has_key(active):
|
||||
active = Name.LNFN
|
||||
self.fmt_obox.set_active(self.fmt_index[active])
|
||||
self.fmt_obox.set_active(active)
|
||||
self.fmt_obox.connect('changed', self.cb_name_changed)
|
||||
# label for the combo
|
||||
lwidget = BasicLabel("%s: " % _('_Display format'))
|
||||
@ -272,36 +268,23 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
|
||||
return table
|
||||
|
||||
def _build_name_format_model(self):
|
||||
def _build_name_format_model(self,active):
|
||||
"""
|
||||
Create a common model for ComboBox and TreeView
|
||||
"""
|
||||
|
||||
name_format_model = gtk.ListStore(int,str,str,str)
|
||||
|
||||
index = 0
|
||||
name_format_model_index = {}
|
||||
index = 0
|
||||
the_index = 0
|
||||
|
||||
# add all the standard formats to the list
|
||||
for num,name,fmt_str in Name.STANDARD_FORMATS:
|
||||
for num,name,fmt_str,act in _nd.get_name_format():
|
||||
self.examplename.set_display_as(num)
|
||||
name_format_model.append(
|
||||
row=[num, name, fmt_str, _nd.display_name(self.examplename)])
|
||||
name_format_model_index[num] = index
|
||||
if num == active: the_index = index
|
||||
index += 1
|
||||
|
||||
# add all the custom formats loaded from the db to the list
|
||||
for num,name,fmt_str,act in _nd.CUSTOM_FORMATS:
|
||||
if act:
|
||||
self.examplename.set_display_as(num)
|
||||
name_format_model.append(
|
||||
row=[num, name, fmt_str, _nd.display_name(self.examplename)])
|
||||
name_format_model_index[num] = index
|
||||
index += 1
|
||||
else:
|
||||
name_format_model_index[num] = -1
|
||||
|
||||
return (name_format_model, name_format_model_index)
|
||||
|
||||
return name_format_model,the_index
|
||||
|
||||
def _build_custom_name_ui(self):
|
||||
"""
|
||||
@ -341,11 +324,9 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
self.iter = None
|
||||
|
||||
insert_button = gtk.Button(stock=gtk.STOCK_ADD)
|
||||
insert_button.set_name(INS_BTN_NAME)
|
||||
insert_button.connect('clicked',self.cb_edit_fmt_str)
|
||||
insert_button.connect('clicked',self.cb_insert_fmt_str)
|
||||
|
||||
self.edit_button = gtk.Button(stock=gtk.STOCK_EDIT)
|
||||
self.edit_button.set_name(EDT_BTN_NAME)
|
||||
self.edit_button.connect('clicked',self.cb_edit_fmt_str)
|
||||
self.edit_button.set_sensitive(False)
|
||||
|
||||
@ -362,14 +343,12 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
def cb_name_changed(self,obj):
|
||||
"""
|
||||
Preset name format ComboBox callback
|
||||
|
||||
Save the new default to gconf and NameDisplay's fn_array
|
||||
"""
|
||||
the_list = obj.get_model()
|
||||
the_iter = the_list.get_iter(obj.get_active())
|
||||
the_iter = obj.get_active_iter()
|
||||
new_idx = the_list.get_value(the_iter,COL_NUM)
|
||||
Config.set(Config.NAME_FORMAT,new_idx)
|
||||
_nd.set_format_default(new_idx)
|
||||
_nd.set_default_format(new_idx)
|
||||
|
||||
def cb_format_tree_select(self, tree_selection):
|
||||
"""
|
||||
@ -377,6 +356,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
|
||||
Remember the values of the selected row (self.selected_fmt, self.iter)
|
||||
and set the Remove and Edit button sensitivity
|
||||
|
||||
"""
|
||||
model,self.iter = tree_selection.get_selected()
|
||||
if self.iter == None:
|
||||
@ -389,63 +369,55 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
|
||||
def cb_edit_fmt_str(self,obj):
|
||||
"""
|
||||
Name format editor Insert and Edit button callback
|
||||
Name format editor Edit button callback
|
||||
"""
|
||||
n = ''
|
||||
f = ''
|
||||
if obj.get_name() == EDT_BTN_NAME:
|
||||
n = self.selected_fmt[COL_NAME]
|
||||
f = self.selected_fmt[COL_FMT]
|
||||
dlg = NameFormatEditDlg(n,f,self.examplename)
|
||||
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 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:
|
||||
# if we created a new format...
|
||||
if obj.get_name() == INS_BTN_NAME:
|
||||
i = -1
|
||||
while self.fmt_index.has_key(i):
|
||||
i -= 1
|
||||
self.fmt_model.append(row=[i,n,f,_nd.format_str(self.examplename,f)])
|
||||
self.fmt_index[i] = len(self.fmt_model) - 1
|
||||
num = i
|
||||
# ...or if we edited an existing one
|
||||
else:
|
||||
if n != self.selected_fmt[COL_NAME] or \
|
||||
f != self.selected_fmt[COL_FMT]:
|
||||
e = _nd.format_str(self.examplename,f)
|
||||
self.fmt_model.set(self.iter,COL_NAME,n,
|
||||
COL_FMT,f,
|
||||
COL_EXPL,e)
|
||||
self.selected_fmt = (self.selected_fmt[COL_NUM],n,f,e)
|
||||
num = self.selected_fmt[COL_NUM]
|
||||
i = _nd.add_name_format(n,f)
|
||||
self.fmt_model.append(row=[i,n,f,
|
||||
_nd.format_str(self.examplename,f)])
|
||||
|
||||
self.register_fmt(num,n,f,1)
|
||||
self.cb_name_changed(self.fmt_obox)
|
||||
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
|
||||
only_active=False)
|
||||
|
||||
def cb_del_fmt_str(self,obj):
|
||||
"""
|
||||
Name format editor Remove button callback
|
||||
"""
|
||||
num = self.selected_fmt[COL_NUM]
|
||||
removed_idx = self.fmt_index[num]
|
||||
# if the item to be deleted is selected in the combo
|
||||
if self.fmt_obox.get_active() == removed_idx:
|
||||
self.fmt_obox.set_active(self.fmt_index[Name.LNFN])
|
||||
# mark the row deleted in the index
|
||||
self.fmt_index[num] = -1
|
||||
for i in self.fmt_index.items():
|
||||
if i[1] > removed_idx:
|
||||
self.fmt_index[i[0]] -= 1
|
||||
# delete the row from the model
|
||||
|
||||
if _nd.get_default_format() == num:
|
||||
self.fmt_obox.set_active(0)
|
||||
|
||||
self.fmt_model.remove(self.iter)
|
||||
# update the custom format registration in NameDisplay instance
|
||||
self.register_fmt(num,'','',0)
|
||||
|
||||
def register_fmt(self,num,name,str,act):
|
||||
_nd.update_custom_formats(num,name,str,act)
|
||||
self.dbstate.db.name_formats = _nd.CUSTOM_FORMATS
|
||||
|
||||
_nd.set_format_inactive(num)
|
||||
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
|
||||
only_active=False)
|
||||
|
||||
def add_formats_panel(self):
|
||||
table = gtk.Table(3,8)
|
||||
table.set_border_width(12)
|
||||
|
@ -81,7 +81,7 @@ def importData(database, filename, callback=None,cl=0,use_trans=True):
|
||||
# we need to do tricks to remap the format numbers
|
||||
if len(other_database.name_formats) > 0:
|
||||
formats_map = remap_name_formats(database,other_database)
|
||||
NameDisplay.displayer.register_custom_formats(database.name_formats)
|
||||
NameDisplay.displayer.set_name_format(database.name_formats)
|
||||
get_person = make_peron_name_remapper(other_database,formats_map)
|
||||
else:
|
||||
# No remapping necessary, proceed as usual
|
||||
|
@ -621,7 +621,7 @@ class GrampsParser(UpdateCallback):
|
||||
# add new name formats to the existing table
|
||||
self.db.name_formats += self.name_formats
|
||||
# Register new formats
|
||||
NameDisplay.displayer.register_custom_formats(self.db.name_formats)
|
||||
NameDisplay.displayer.set_name_format(self.db.name_formats)
|
||||
|
||||
self.db.set_researcher(self.owner)
|
||||
if self.home != None:
|
||||
|
@ -50,6 +50,15 @@ _SORT = 13
|
||||
_DISPLAY = 14
|
||||
_CALL = 15
|
||||
|
||||
_ACT = True
|
||||
_INA = False
|
||||
|
||||
_F_NAME = 0 # name of the format
|
||||
_F_FMT = 1 # the format string
|
||||
_F_ACT = 2 # if the format is active
|
||||
_F_FN = 3 # name format function
|
||||
_F_RAWFN = 4 # name format raw function
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# NameDisplay class
|
||||
@ -65,27 +74,24 @@ class NameDisplay:
|
||||
Name.get_first_name, Name.get_patronymic,
|
||||
Name.get_first_name)
|
||||
|
||||
def __init__(self,use_upper=False):
|
||||
"""
|
||||
Creates a new NameDisplay class.
|
||||
|
||||
@param use_upper: True indicates that the surname should be
|
||||
displayed in upper case.
|
||||
@type use_upper: bool
|
||||
"""
|
||||
|
||||
##self.force_upper = use_upper
|
||||
STANDARD_FORMATS = [
|
||||
(Name.DEF,_("Default format (defined by GRAMPS preferences)"),'',_ACT),
|
||||
(Name.LNFN,_("Family name, Given name Patronymic"),'%p %l, %f %y %s',_ACT),
|
||||
(Name.FNLN,_("Given name Family name"),'%f %y %p %l %s',_ACT),
|
||||
(Name.PTFN,_("Patronymic, Given name"),'%p %y, %s %f',_ACT),
|
||||
(Name.FN,_("Given name"),'%f',_ACT)
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
self.name_formats = {}
|
||||
self.set_name_format(self.STANDARD_FORMATS)
|
||||
|
||||
self.CUSTOM_FORMATS = []
|
||||
self.gramps_format = Name.LNFN
|
||||
self.fn_array = {}
|
||||
self.raw_fn_array = {}
|
||||
self.set_format_fn()
|
||||
|
||||
default_idx = Config.get(Config.NAME_FORMAT)
|
||||
if default_idx == 0:
|
||||
default_idx = Name.LNFN
|
||||
self.set_format_default(default_idx)
|
||||
self.default_format = Config.get(Config.NAME_FORMAT)
|
||||
if self.default_format == 0:
|
||||
self.default_format = Name.LNFN
|
||||
Config.set(Config.NAME_FORMAT,self.default_format)
|
||||
|
||||
self.set_default_format(self.default_format)
|
||||
|
||||
def _format_fn(self,fmt_str):
|
||||
return lambda x: self.format_str(x,fmt_str)
|
||||
@ -93,196 +99,92 @@ class NameDisplay:
|
||||
def _format_raw_fn(self,fmt_str):
|
||||
return lambda x: self.format_str_raw(x,fmt_str)
|
||||
|
||||
def set_format_fn(self):
|
||||
self.fn_array.clear()
|
||||
self.raw_fn_array.clear()
|
||||
# Add standard formats to mappings
|
||||
for number,name,fmt_str in Name.STANDARD_FORMATS:
|
||||
self.fn_array[number] = self._format_fn(fmt_str)
|
||||
self.raw_fn_array[number] = self._format_raw_fn(fmt_str)
|
||||
# Add custom formats to the mappings
|
||||
for number,name,fmt_str,act in self.CUSTOM_FORMATS:
|
||||
if act:
|
||||
self.fn_array[number] = self._format_fn(fmt_str)
|
||||
self.raw_fn_array[number] = self._format_raw_fn(fmt_str)
|
||||
|
||||
self.set_format_default(self.gramps_format)
|
||||
|
||||
def set_format_default(self,idx):
|
||||
# Add mappings for the gramps-prefs format
|
||||
if not self.fn_array.has_key(idx):
|
||||
idx = Name.LNFN
|
||||
# this should not happen if the default is kept in the db
|
||||
|
||||
self.gramps_format = idx
|
||||
self.fn_array[0] = self.fn_array[idx]
|
||||
self.raw_fn_array[0] = self.raw_fn_array[idx]
|
||||
def set_name_format(self,formats):
|
||||
for (num,name,fmt_str,act) in formats:
|
||||
self.name_formats[num] = (name,fmt_str,act,
|
||||
self._format_fn(fmt_str),
|
||||
self._format_raw_fn(fmt_str))
|
||||
|
||||
def register_custom_formats(self,formats):
|
||||
self.CUSTOM_FORMATS = formats[:]
|
||||
self.set_format_fn()
|
||||
|
||||
def update_custom_formats(self,num,name,str,act):
|
||||
i = 0
|
||||
while (i < len(self.CUSTOM_FORMATS) and
|
||||
self.CUSTOM_FORMATS[i][0] != num):
|
||||
i += 1
|
||||
|
||||
try:
|
||||
self.CUSTOM_FORMATS[i] = (num,name,str,act)
|
||||
except IndexError:
|
||||
self.CUSTOM_FORMATS.append((num,name,str,act))
|
||||
|
||||
self.set_format_fn()
|
||||
|
||||
##def use_upper(self,upper):
|
||||
##"""
|
||||
##Changes the NameDisplay class to enable or display the displaying
|
||||
##of surnames in upper case.
|
||||
|
||||
##@param upper: True indicates that the surname should be
|
||||
##displayed in upper case.
|
||||
##@type upper: bool
|
||||
##"""
|
||||
##self.force_upper = upper
|
||||
|
||||
def sort_string(self,name):
|
||||
return u"%-25s%-30s%s" % (name.surname,name.first_name,name.suffix)
|
||||
|
||||
##def _fn(self,name):
|
||||
##return self._fn_base(name.first_name)
|
||||
|
||||
##def _fn_raw(self,raw_data):
|
||||
##first = raw_data[_FIRSTNAME]
|
||||
##return self._fn_base(first)
|
||||
|
||||
##def _fn_base(self,first):
|
||||
##return first
|
||||
|
||||
##def _ptfn(self,name):
|
||||
##"""
|
||||
##Prints the Western style first name, last name style.
|
||||
##Typically this is::
|
||||
|
||||
##SurnamePrefix Patronymic SurnameSuffix, FirstName
|
||||
##"""
|
||||
|
||||
##return self._ptfn_base(name.first_name,name.suffix,
|
||||
##name.prefix,name.patronymic)
|
||||
|
||||
##def _ptfn_raw(self,raw_data):
|
||||
##"""
|
||||
##Prints the Western style first name, last name style.
|
||||
##Typically this is::
|
||||
|
||||
##SurnamePrefix Patronymic SurnameSuffix, FirstName
|
||||
##"""
|
||||
|
||||
##first = raw_data[_FIRSTNAME]
|
||||
##suffix = raw_data[_SUFFIX]
|
||||
##prefix = raw_data[_PREFIX]
|
||||
##patronymic = raw_data[_PATRONYM]
|
||||
|
||||
##return self._ptfn_base(first,suffix,prefix,patronymic)
|
||||
|
||||
##def _ptfn_base(self,first,suffix,prefix,patronymic):
|
||||
##if self.force_upper:
|
||||
##last = patronymic.upper()
|
||||
##else:
|
||||
##last = patronymic
|
||||
|
||||
##if suffix:
|
||||
##if prefix:
|
||||
##return "%s %s %s, %s" % (prefix, last, suffix, first)
|
||||
##else:
|
||||
##return "%s %s, %s" % (last, suffix, first)
|
||||
##else:
|
||||
##if prefix:
|
||||
##return "%s %s, %s" % (prefix, last, first)
|
||||
##else:
|
||||
##return "%s, %s" % (last, first)
|
||||
|
||||
##def _fnln(self,name):
|
||||
##"""
|
||||
##Prints the Western style first name, last name style.
|
||||
##Typically this is::
|
||||
|
||||
##FirstName Patronymic SurnamePrefix Surname SurnameSuffix
|
||||
##"""
|
||||
##return self._fnln_base(name.first_name,name.surname,name.suffix,
|
||||
##name.prefix,name.patronymic)
|
||||
|
||||
##def _fnln_raw(self,raw_data):
|
||||
##"""
|
||||
##Prints the Western style first name, last name style.
|
||||
##Typically this is::
|
||||
|
||||
##FirstName Patronymic SurnamePrefix Surname SurnameSuffix
|
||||
##"""
|
||||
##first = raw_data[_FIRSTNAME]
|
||||
##surname = raw_data[_SURNAME]
|
||||
##suffix = raw_data[_SUFFIX]
|
||||
##prefix = raw_data[_PREFIX]
|
||||
##patronymic = raw_data[_PATRONYM]
|
||||
##return self._fnln_base(first,surname,suffix,prefix,patronymic)
|
||||
|
||||
##def _fnln_base(self,first,surname,suffix,prefix,patronymic):
|
||||
##if patronymic:
|
||||
##first = "%s %s" % (first, patronymic)
|
||||
|
||||
##if self.force_upper:
|
||||
##last = surname.upper()
|
||||
##else:
|
||||
##last = surname
|
||||
|
||||
##if suffix:
|
||||
##if prefix:
|
||||
##return "%s %s %s, %s" % (first, prefix, last, suffix)
|
||||
##else:
|
||||
##return "%s %s, %s" % (first, last, suffix)
|
||||
##else:
|
||||
##if prefix:
|
||||
##return "%s %s %s" % (first, prefix, last)
|
||||
##else:
|
||||
##return "%s %s" % (first, last)
|
||||
|
||||
##def _lnfn(self,name):
|
||||
##"""
|
||||
##Prints the Western style last name, first name style.
|
||||
##Typically this is::
|
||||
|
||||
##SurnamePrefix Surname, FirstName Patronymic SurnameSuffix
|
||||
##"""
|
||||
##return self._lnfn_base(name.first_name,name.surname,name.prefix,
|
||||
##name.suffix,name.patronymic)
|
||||
|
||||
##def _lnfn_raw(self,raw_data):
|
||||
##"""
|
||||
##Prints the Western style last name, first name style.
|
||||
##Typically this is::
|
||||
|
||||
##SurnamePrefix Surname, FirstName Patronymic SurnameSuffix
|
||||
##"""
|
||||
|
||||
##surname = raw_data[_SURNAME]
|
||||
##prefix = raw_data[_PREFIX]
|
||||
##first = raw_data[_FIRSTNAME]
|
||||
##patronymic = raw_data[_PATRONYM]
|
||||
##suffix = raw_data[_SUFFIX]
|
||||
|
||||
##return self._lnfn_base(first,surname,prefix,suffix,patronymic)
|
||||
|
||||
##def _lnfn_base(self,first,surname,prefix,suffix,patronymic):
|
||||
##if self.force_upper:
|
||||
##last = surname.upper()
|
||||
##else:
|
||||
##last = surname
|
||||
|
||||
##if last:
|
||||
##last += ","
|
||||
|
||||
##return " ".join([prefix, last, first, patronymic, suffix])
|
||||
def add_name_format(self,name,fmt_str):
|
||||
num = -1
|
||||
while num in self.name_formats:
|
||||
num -= 1
|
||||
self.set_name_format([(num,name,fmt_str,_ACT)])
|
||||
return num
|
||||
|
||||
def edit_name_format(self,num,name,fmt_str):
|
||||
self.set_name_format([(num,name,fmt_str,_ACT)])
|
||||
if self.default_format == num:
|
||||
self.set_default_format(num)
|
||||
|
||||
def del_name_format(self,num):
|
||||
try:
|
||||
del self.name_formats[num]
|
||||
except:
|
||||
pass
|
||||
|
||||
def set_default_format(self,num):
|
||||
if num not in self.name_formats:
|
||||
num = Name.LNFN
|
||||
|
||||
self.default_format = num
|
||||
|
||||
self.name_formats[Name.DEF] = (self.name_formats[Name.DEF][_F_NAME],
|
||||
self.name_formats[Name.DEF][_F_FMT],
|
||||
self.name_formats[Name.DEF][_F_ACT],
|
||||
self.name_formats[num][_F_FN],
|
||||
self.name_formats[num][_F_RAWFN])
|
||||
|
||||
def get_default_format(self):
|
||||
return self.default_format
|
||||
|
||||
def set_format_inactive(self,num):
|
||||
try:
|
||||
self.name_formats[num] = (self.name_formats[num][_F_NAME],
|
||||
self.name_formats[num][_F_FMT],
|
||||
_INA,
|
||||
self.name_formats[num][_F_FN],
|
||||
self.name_formats[num][_F_RAWFN])
|
||||
except:
|
||||
pass
|
||||
|
||||
def get_name_format(self,also_default=False,
|
||||
only_custom=False,
|
||||
only_active=True):
|
||||
"""
|
||||
Get a list of tuples (num,name,fmt_str,act)
|
||||
"""
|
||||
the_list = []
|
||||
|
||||
keys = self.name_formats.keys()
|
||||
keys.sort(self._sort_name_format)
|
||||
|
||||
for num in keys:
|
||||
if ((also_default or num) and
|
||||
(not only_custom or (num < 0)) and
|
||||
(not only_active or self.name_formats[num][_F_ACT])):
|
||||
the_list.append((num,) + self.name_formats[num][_F_NAME:_F_FN])
|
||||
|
||||
return the_list
|
||||
|
||||
def _sort_name_format(self,x,y):
|
||||
if x<0:
|
||||
if y<0: return x+y
|
||||
else: return -x+y
|
||||
else:
|
||||
if y<0: return -x+y
|
||||
else: return x-y
|
||||
|
||||
def _is_format_valid(self,num):
|
||||
try:
|
||||
if not self.name_formats[num][_F_ACT]:
|
||||
num = 0
|
||||
except:
|
||||
num = 0
|
||||
return num
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
def format_str(self,name,format_str):
|
||||
return self._format_str_base(name.first_name,name.surname,name.prefix,
|
||||
name.suffix,name.patronymic,name.title,
|
||||
@ -349,6 +251,11 @@ class NameDisplay:
|
||||
namestr += output[i]
|
||||
|
||||
return namestr.strip()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
def sort_string(self,name):
|
||||
return u"%-25s%-30s%s" % (name.surname,name.first_name,name.suffix)
|
||||
|
||||
def sorted(self,person):
|
||||
"""
|
||||
@ -377,10 +284,8 @@ class NameDisplay:
|
||||
@returns: Returns the L{Name} string representation
|
||||
@rtype: str
|
||||
"""
|
||||
idx = name.sort_as
|
||||
if not self.fn_array.has_key(idx):
|
||||
idx = 0
|
||||
return self.fn_array[idx](name)
|
||||
id = self._is_format_valid(name.sort_as)
|
||||
return self.name_formats[id][_F_FN](name)
|
||||
|
||||
def raw_sorted_name(self,raw_data):
|
||||
"""
|
||||
@ -393,10 +298,8 @@ class NameDisplay:
|
||||
@returns: Returns the L{Name} string representation
|
||||
@rtype: str
|
||||
"""
|
||||
idx = raw_data[_SORT]
|
||||
if not self.raw_fn_array.has_key(idx):
|
||||
idx = 0
|
||||
return self.raw_fn_array[idx](raw_data)
|
||||
id = self._is_format_valid(raw_data[_SORT])
|
||||
return self.name_formats[id][_F_RAWFN](raw_data)
|
||||
|
||||
def display(self,person):
|
||||
"""
|
||||
@ -442,11 +345,8 @@ class NameDisplay:
|
||||
if name == None:
|
||||
return ""
|
||||
|
||||
idx = name.display_as
|
||||
if not self.fn_array.has_key(idx):
|
||||
idx = 0
|
||||
|
||||
return self.fn_array[idx](name)
|
||||
id = self._is_format_valid(name.display_as)
|
||||
return self.name_formats[id][_F_FN](name)
|
||||
|
||||
def display_given(self,person):
|
||||
name = person.get_primary_name()
|
||||
|
@ -61,16 +61,6 @@ class Name(SecondaryObject,PrivacyBase,SourceBase,NoteBase,DateBase):
|
||||
PTFN = 3 # patronymic first name
|
||||
FN = 4 # first name
|
||||
|
||||
DEFAULT_FORMAT = \
|
||||
(DEF,_("Default format (defined by GRAMPS preferences)"),'')
|
||||
|
||||
STANDARD_FORMATS = [
|
||||
(LNFN, _("Family name, Given name Patronymic"),'%p %l, %f %y %s'),
|
||||
(FNLN, _("Given name Family name"),'%f %y %p %l %s'),
|
||||
(PTFN, _("Patronymic, Given name"),'%p %y, %s %f'),
|
||||
(FN, _("Given name"),'%f')
|
||||
]
|
||||
|
||||
def __init__(self,source=None,data=None):
|
||||
"""creates a new Name instance, copying from the source if provided"""
|
||||
SecondaryObject.__init__(self)
|
||||
|
@ -782,10 +782,11 @@ class ViewManager:
|
||||
self.state.db.set_researcher(owner)
|
||||
|
||||
self.setup_bookmarks()
|
||||
NameDisplay.displayer.register_custom_formats(self.state.db.name_formats)
|
||||
|
||||
NameDisplay.displayer.set_name_format(self.state.db.name_formats)
|
||||
fmt_default = Config.get(Config.NAME_FORMAT)
|
||||
if fmt_default < 0:
|
||||
NameDisplay.displayer.set_format_default(fmt_default)
|
||||
NameDisplay.displayer.set_default_format(fmt_default)
|
||||
|
||||
self.state.db.enable_signals()
|
||||
self.state.signal_change()
|
||||
|
@ -237,6 +237,7 @@ class CheckIntegrity:
|
||||
deleted_name_formats = [number for (number,name,fmt_str,act)
|
||||
in self.db.name_formats if not act]
|
||||
|
||||
# remove the invalid references from all Name objects
|
||||
for person_handle in self.db.get_person_handles():
|
||||
person = self.db.get_person_from_handle(person_handle)
|
||||
|
||||
@ -269,11 +270,12 @@ class CheckIntegrity:
|
||||
self.removed_name_format.append(person_handle)
|
||||
|
||||
self.progress.step()
|
||||
|
||||
active_name_formats = [(i,n,s,act) for (i,n,s,act)
|
||||
in self.db.name_formats if act]
|
||||
self.db.name_formats = active_name_formats
|
||||
_nd.register_custom_formats(active_name_formats)
|
||||
|
||||
# update the custom name name format table
|
||||
for number in deleted_name_formats:
|
||||
_nd.del_name_format(number)
|
||||
self.db.name_formats = _nd.get_name_format(only_custom=True,
|
||||
only_active=False)
|
||||
|
||||
def cleanup_duplicate_spouses(self):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user