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
e9cf818b7c
commit
a16b488d1d
16
ChangeLog
16
ChangeLog
@ -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>
|
2006-07-30 Don Allingham <don@gramps-project.org>
|
||||||
* src/GrampsDb/_ReadGedcom.py: handle missing event type
|
* src/GrampsDb/_ReadGedcom.py: handle missing event type
|
||||||
* src/DataViews/_PlaceView.py: add tooltip for map button
|
* src/DataViews/_PlaceView.py: add tooltip for map button
|
||||||
|
@ -96,13 +96,8 @@ class EditName(EditSecondary):
|
|||||||
if not self.original_group_as:
|
if not self.original_group_as:
|
||||||
self.group_as.force_value(self.obj.get_surname())
|
self.group_as.force_value(self.obj.get_surname())
|
||||||
|
|
||||||
|
format_list = [(name,number) for (number,name,fmt_str,act)
|
||||||
(number,name,fmt_str) = RelLib.Name.DEFAULT_FORMAT
|
in NameDisplay.displayer.get_name_format(also_default=True)]
|
||||||
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]
|
|
||||||
|
|
||||||
self.sort_as = MonitoredMenu(
|
self.sort_as = MonitoredMenu(
|
||||||
self.top.get_widget('sort_as'),
|
self.top.get_widget('sort_as'),
|
||||||
|
122
src/GrampsCfg.py
122
src/GrampsCfg.py
@ -237,9 +237,8 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
table.set_row_spacings(6)
|
table.set_row_spacings(6)
|
||||||
|
|
||||||
# get the model for the combo and the treeview
|
# get the model for the combo and the treeview
|
||||||
# index is used to set the active format in the combo quickly
|
active = _nd.get_default_format()
|
||||||
# and to find an unused index number when a new format is created
|
self.fmt_model,active = self._build_name_format_model(active)
|
||||||
(self.fmt_model, self.fmt_index) = self._build_name_format_model()
|
|
||||||
|
|
||||||
# set up the combo to choose the preset format
|
# set up the combo to choose the preset format
|
||||||
self.fmt_obox = gtk.ComboBox()
|
self.fmt_obox = gtk.ComboBox()
|
||||||
@ -249,10 +248,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
self.fmt_obox.set_model(self.fmt_model)
|
self.fmt_obox.set_model(self.fmt_model)
|
||||||
|
|
||||||
# set the default value as active in the combo
|
# set the default value as active in the combo
|
||||||
active = int(Config.get(Config.NAME_FORMAT))
|
self.fmt_obox.set_active(active)
|
||||||
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.connect('changed', self.cb_name_changed)
|
self.fmt_obox.connect('changed', self.cb_name_changed)
|
||||||
# label for the combo
|
# label for the combo
|
||||||
lwidget = BasicLabel("%s: " % _('_Display format'))
|
lwidget = BasicLabel("%s: " % _('_Display format'))
|
||||||
@ -272,36 +268,23 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
|
|
||||||
return table
|
return table
|
||||||
|
|
||||||
def _build_name_format_model(self):
|
def _build_name_format_model(self,active):
|
||||||
"""
|
"""
|
||||||
Create a common model for ComboBox and TreeView
|
Create a common model for ComboBox and TreeView
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name_format_model = gtk.ListStore(int,str,str,str)
|
name_format_model = gtk.ListStore(int,str,str,str)
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
name_format_model_index = {}
|
the_index = 0
|
||||||
|
|
||||||
# add all the standard formats to the list
|
for num,name,fmt_str,act in _nd.get_name_format():
|
||||||
for num,name,fmt_str in Name.STANDARD_FORMATS:
|
|
||||||
self.examplename.set_display_as(num)
|
self.examplename.set_display_as(num)
|
||||||
name_format_model.append(
|
name_format_model.append(
|
||||||
row=[num, name, fmt_str, _nd.display_name(self.examplename)])
|
row=[num, name, fmt_str, _nd.display_name(self.examplename)])
|
||||||
name_format_model_index[num] = index
|
if num == active: the_index = index
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
# add all the custom formats loaded from the db to the list
|
return name_format_model,the_index
|
||||||
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)
|
|
||||||
|
|
||||||
def _build_custom_name_ui(self):
|
def _build_custom_name_ui(self):
|
||||||
"""
|
"""
|
||||||
@ -341,11 +324,9 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
self.iter = None
|
self.iter = None
|
||||||
|
|
||||||
insert_button = gtk.Button(stock=gtk.STOCK_ADD)
|
insert_button = gtk.Button(stock=gtk.STOCK_ADD)
|
||||||
insert_button.set_name(INS_BTN_NAME)
|
insert_button.connect('clicked',self.cb_insert_fmt_str)
|
||||||
insert_button.connect('clicked',self.cb_edit_fmt_str)
|
|
||||||
|
|
||||||
self.edit_button = gtk.Button(stock=gtk.STOCK_EDIT)
|
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.connect('clicked',self.cb_edit_fmt_str)
|
||||||
self.edit_button.set_sensitive(False)
|
self.edit_button.set_sensitive(False)
|
||||||
|
|
||||||
@ -362,14 +343,12 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
def cb_name_changed(self,obj):
|
def cb_name_changed(self,obj):
|
||||||
"""
|
"""
|
||||||
Preset name format ComboBox callback
|
Preset name format ComboBox callback
|
||||||
|
|
||||||
Save the new default to gconf and NameDisplay's fn_array
|
|
||||||
"""
|
"""
|
||||||
the_list = obj.get_model()
|
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)
|
new_idx = the_list.get_value(the_iter,COL_NUM)
|
||||||
Config.set(Config.NAME_FORMAT,new_idx)
|
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):
|
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)
|
Remember the values of the selected row (self.selected_fmt, self.iter)
|
||||||
and set the Remove and Edit button sensitivity
|
and set the Remove and Edit button sensitivity
|
||||||
|
|
||||||
"""
|
"""
|
||||||
model,self.iter = tree_selection.get_selected()
|
model,self.iter = tree_selection.get_selected()
|
||||||
if self.iter == None:
|
if self.iter == None:
|
||||||
@ -389,62 +369,54 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
|
|
||||||
def cb_edit_fmt_str(self,obj):
|
def cb_edit_fmt_str(self,obj):
|
||||||
"""
|
"""
|
||||||
Name format editor Insert and Edit button callback
|
Name format editor Edit button callback
|
||||||
"""
|
"""
|
||||||
n = ''
|
num,name,fmt = self.selected_fmt[COL_NUM:COL_EXPL]
|
||||||
f = ''
|
dlg = NameFormatEditDlg(name,fmt,self.examplename)
|
||||||
if obj.get_name() == EDT_BTN_NAME:
|
dlg.dlg.set_transient_for(self.window)
|
||||||
n = self.selected_fmt[COL_NAME]
|
(res,name,fmt) = dlg.run()
|
||||||
f = self.selected_fmt[COL_FMT]
|
|
||||||
dlg = NameFormatEditDlg(n,f,self.examplename)
|
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)
|
dlg.dlg.set_transient_for(self.window)
|
||||||
(res,n,f) = dlg.run()
|
(res,n,f) = dlg.run()
|
||||||
|
|
||||||
if res == gtk.RESPONSE_OK:
|
if res == gtk.RESPONSE_OK:
|
||||||
# if we created a new format...
|
i = _nd.add_name_format(n,f)
|
||||||
if obj.get_name() == INS_BTN_NAME:
|
self.fmt_model.append(row=[i,n,f,
|
||||||
i = -1
|
_nd.format_str(self.examplename,f)])
|
||||||
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]
|
|
||||||
|
|
||||||
self.register_fmt(num,n,f,1)
|
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
|
||||||
self.cb_name_changed(self.fmt_obox)
|
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
|
||||||
"""
|
"""
|
||||||
num = self.selected_fmt[COL_NUM]
|
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
|
|
||||||
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):
|
if _nd.get_default_format() == num:
|
||||||
_nd.update_custom_formats(num,name,str,act)
|
self.fmt_obox.set_active(0)
|
||||||
self.dbstate.db.name_formats = _nd.CUSTOM_FORMATS
|
|
||||||
|
self.fmt_model.remove(self.iter)
|
||||||
|
_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):
|
def add_formats_panel(self):
|
||||||
table = gtk.Table(3,8)
|
table = gtk.Table(3,8)
|
||||||
|
@ -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
|
# we need to do tricks to remap the format numbers
|
||||||
if len(other_database.name_formats) > 0:
|
if len(other_database.name_formats) > 0:
|
||||||
formats_map = remap_name_formats(database,other_database)
|
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)
|
get_person = make_peron_name_remapper(other_database,formats_map)
|
||||||
else:
|
else:
|
||||||
# No remapping necessary, proceed as usual
|
# No remapping necessary, proceed as usual
|
||||||
|
@ -621,7 +621,7 @@ class GrampsParser(UpdateCallback):
|
|||||||
# add new name formats to the existing table
|
# add new name formats to the existing table
|
||||||
self.db.name_formats += self.name_formats
|
self.db.name_formats += self.name_formats
|
||||||
# Register new 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)
|
self.db.set_researcher(self.owner)
|
||||||
if self.home != None:
|
if self.home != None:
|
||||||
|
@ -50,6 +50,15 @@ _SORT = 13
|
|||||||
_DISPLAY = 14
|
_DISPLAY = 14
|
||||||
_CALL = 15
|
_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
|
# NameDisplay class
|
||||||
@ -65,27 +74,24 @@ class NameDisplay:
|
|||||||
Name.get_first_name, Name.get_patronymic,
|
Name.get_first_name, Name.get_patronymic,
|
||||||
Name.get_first_name)
|
Name.get_first_name)
|
||||||
|
|
||||||
def __init__(self,use_upper=False):
|
STANDARD_FORMATS = [
|
||||||
"""
|
(Name.DEF,_("Default format (defined by GRAMPS preferences)"),'',_ACT),
|
||||||
Creates a new NameDisplay class.
|
(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)
|
||||||
|
]
|
||||||
|
|
||||||
@param use_upper: True indicates that the surname should be
|
def __init__(self):
|
||||||
displayed in upper case.
|
self.name_formats = {}
|
||||||
@type use_upper: bool
|
self.set_name_format(self.STANDARD_FORMATS)
|
||||||
"""
|
|
||||||
|
|
||||||
##self.force_upper = use_upper
|
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.CUSTOM_FORMATS = []
|
self.set_default_format(self.default_format)
|
||||||
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)
|
|
||||||
|
|
||||||
def _format_fn(self,fmt_str):
|
def _format_fn(self,fmt_str):
|
||||||
return lambda x: self.format_str(x,fmt_str)
|
return lambda x: self.format_str(x,fmt_str)
|
||||||
@ -93,195 +99,91 @@ class NameDisplay:
|
|||||||
def _format_raw_fn(self,fmt_str):
|
def _format_raw_fn(self,fmt_str):
|
||||||
return lambda x: self.format_str_raw(x,fmt_str)
|
return lambda x: self.format_str_raw(x,fmt_str)
|
||||||
|
|
||||||
def set_format_fn(self):
|
def set_name_format(self,formats):
|
||||||
self.fn_array.clear()
|
for (num,name,fmt_str,act) in formats:
|
||||||
self.raw_fn_array.clear()
|
self.name_formats[num] = (name,fmt_str,act,
|
||||||
# Add standard formats to mappings
|
self._format_fn(fmt_str),
|
||||||
for number,name,fmt_str in Name.STANDARD_FORMATS:
|
self._format_raw_fn(fmt_str))
|
||||||
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 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 set_format_default(self,idx):
|
def edit_name_format(self,num,name,fmt_str):
|
||||||
# Add mappings for the gramps-prefs format
|
self.set_name_format([(num,name,fmt_str,_ACT)])
|
||||||
if not self.fn_array.has_key(idx):
|
if self.default_format == num:
|
||||||
idx = Name.LNFN
|
self.set_default_format(num)
|
||||||
# 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 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
|
|
||||||
|
|
||||||
|
def del_name_format(self,num):
|
||||||
try:
|
try:
|
||||||
self.CUSTOM_FORMATS[i] = (num,name,str,act)
|
del self.name_formats[num]
|
||||||
except IndexError:
|
except:
|
||||||
self.CUSTOM_FORMATS.append((num,name,str,act))
|
pass
|
||||||
|
|
||||||
self.set_format_fn()
|
def set_default_format(self,num):
|
||||||
|
if num not in self.name_formats:
|
||||||
|
num = Name.LNFN
|
||||||
|
|
||||||
##def use_upper(self,upper):
|
self.default_format = num
|
||||||
##"""
|
|
||||||
##Changes the NameDisplay class to enable or display the displaying
|
|
||||||
##of surnames in upper case.
|
|
||||||
|
|
||||||
##@param upper: True indicates that the surname should be
|
self.name_formats[Name.DEF] = (self.name_formats[Name.DEF][_F_NAME],
|
||||||
##displayed in upper case.
|
self.name_formats[Name.DEF][_F_FMT],
|
||||||
##@type upper: bool
|
self.name_formats[Name.DEF][_F_ACT],
|
||||||
##"""
|
self.name_formats[num][_F_FN],
|
||||||
##self.force_upper = upper
|
self.name_formats[num][_F_RAWFN])
|
||||||
|
|
||||||
def sort_string(self,name):
|
def get_default_format(self):
|
||||||
return u"%-25s%-30s%s" % (name.surname,name.first_name,name.suffix)
|
return self.default_format
|
||||||
|
|
||||||
##def _fn(self,name):
|
def set_format_inactive(self,num):
|
||||||
##return self._fn_base(name.first_name)
|
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 _fn_raw(self,raw_data):
|
def get_name_format(self,also_default=False,
|
||||||
##first = raw_data[_FIRSTNAME]
|
only_custom=False,
|
||||||
##return self._fn_base(first)
|
only_active=True):
|
||||||
|
"""
|
||||||
|
Get a list of tuples (num,name,fmt_str,act)
|
||||||
|
"""
|
||||||
|
the_list = []
|
||||||
|
|
||||||
##def _fn_base(self,first):
|
keys = self.name_formats.keys()
|
||||||
##return first
|
keys.sort(self._sort_name_format)
|
||||||
|
|
||||||
##def _ptfn(self,name):
|
for num in keys:
|
||||||
##"""
|
if ((also_default or num) and
|
||||||
##Prints the Western style first name, last name style.
|
(not only_custom or (num < 0)) and
|
||||||
##Typically this is::
|
(not only_active or self.name_formats[num][_F_ACT])):
|
||||||
|
the_list.append((num,) + self.name_formats[num][_F_NAME:_F_FN])
|
||||||
|
|
||||||
##SurnamePrefix Patronymic SurnameSuffix, FirstName
|
return the_list
|
||||||
##"""
|
|
||||||
|
|
||||||
##return self._ptfn_base(name.first_name,name.suffix,
|
def _sort_name_format(self,x,y):
|
||||||
##name.prefix,name.patronymic)
|
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 _ptfn_raw(self,raw_data):
|
def _is_format_valid(self,num):
|
||||||
##"""
|
try:
|
||||||
##Prints the Western style first name, last name style.
|
if not self.name_formats[num][_F_ACT]:
|
||||||
##Typically this is::
|
num = 0
|
||||||
|
except:
|
||||||
|
num = 0
|
||||||
|
return num
|
||||||
|
|
||||||
##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 format_str(self,name,format_str):
|
def format_str(self,name,format_str):
|
||||||
return self._format_str_base(name.first_name,name.surname,name.prefix,
|
return self._format_str_base(name.first_name,name.surname,name.prefix,
|
||||||
@ -350,6 +252,11 @@ class NameDisplay:
|
|||||||
|
|
||||||
return namestr.strip()
|
return namestr.strip()
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def sort_string(self,name):
|
||||||
|
return u"%-25s%-30s%s" % (name.surname,name.first_name,name.suffix)
|
||||||
|
|
||||||
def sorted(self,person):
|
def sorted(self,person):
|
||||||
"""
|
"""
|
||||||
Returns a text string representing the L{RelLib.Person} instance's
|
Returns a text string representing the L{RelLib.Person} instance's
|
||||||
@ -377,10 +284,8 @@ class NameDisplay:
|
|||||||
@returns: Returns the L{Name} string representation
|
@returns: Returns the L{Name} string representation
|
||||||
@rtype: str
|
@rtype: str
|
||||||
"""
|
"""
|
||||||
idx = name.sort_as
|
id = self._is_format_valid(name.sort_as)
|
||||||
if not self.fn_array.has_key(idx):
|
return self.name_formats[id][_F_FN](name)
|
||||||
idx = 0
|
|
||||||
return self.fn_array[idx](name)
|
|
||||||
|
|
||||||
def raw_sorted_name(self,raw_data):
|
def raw_sorted_name(self,raw_data):
|
||||||
"""
|
"""
|
||||||
@ -393,10 +298,8 @@ class NameDisplay:
|
|||||||
@returns: Returns the L{Name} string representation
|
@returns: Returns the L{Name} string representation
|
||||||
@rtype: str
|
@rtype: str
|
||||||
"""
|
"""
|
||||||
idx = raw_data[_SORT]
|
id = self._is_format_valid(raw_data[_SORT])
|
||||||
if not self.raw_fn_array.has_key(idx):
|
return self.name_formats[id][_F_RAWFN](raw_data)
|
||||||
idx = 0
|
|
||||||
return self.raw_fn_array[idx](raw_data)
|
|
||||||
|
|
||||||
def display(self,person):
|
def display(self,person):
|
||||||
"""
|
"""
|
||||||
@ -442,11 +345,8 @@ class NameDisplay:
|
|||||||
if name == None:
|
if name == None:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
idx = name.display_as
|
id = self._is_format_valid(name.display_as)
|
||||||
if not self.fn_array.has_key(idx):
|
return self.name_formats[id][_F_FN](name)
|
||||||
idx = 0
|
|
||||||
|
|
||||||
return self.fn_array[idx](name)
|
|
||||||
|
|
||||||
def display_given(self,person):
|
def display_given(self,person):
|
||||||
name = person.get_primary_name()
|
name = person.get_primary_name()
|
||||||
|
@ -61,16 +61,6 @@ class Name(SecondaryObject,PrivacyBase,SourceBase,NoteBase,DateBase):
|
|||||||
PTFN = 3 # patronymic first name
|
PTFN = 3 # patronymic first name
|
||||||
FN = 4 # 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):
|
def __init__(self,source=None,data=None):
|
||||||
"""creates a new Name instance, copying from the source if provided"""
|
"""creates a new Name instance, copying from the source if provided"""
|
||||||
SecondaryObject.__init__(self)
|
SecondaryObject.__init__(self)
|
||||||
|
@ -782,10 +782,11 @@ class ViewManager:
|
|||||||
self.state.db.set_researcher(owner)
|
self.state.db.set_researcher(owner)
|
||||||
|
|
||||||
self.setup_bookmarks()
|
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)
|
fmt_default = Config.get(Config.NAME_FORMAT)
|
||||||
if fmt_default < 0:
|
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.db.enable_signals()
|
||||||
self.state.signal_change()
|
self.state.signal_change()
|
||||||
|
@ -237,6 +237,7 @@ class CheckIntegrity:
|
|||||||
deleted_name_formats = [number for (number,name,fmt_str,act)
|
deleted_name_formats = [number for (number,name,fmt_str,act)
|
||||||
in self.db.name_formats if not 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():
|
for person_handle in self.db.get_person_handles():
|
||||||
person = self.db.get_person_from_handle(person_handle)
|
person = self.db.get_person_from_handle(person_handle)
|
||||||
|
|
||||||
@ -270,10 +271,11 @@ class CheckIntegrity:
|
|||||||
|
|
||||||
self.progress.step()
|
self.progress.step()
|
||||||
|
|
||||||
active_name_formats = [(i,n,s,act) for (i,n,s,act)
|
# update the custom name name format table
|
||||||
in self.db.name_formats if act]
|
for number in deleted_name_formats:
|
||||||
self.db.name_formats = active_name_formats
|
_nd.del_name_format(number)
|
||||||
_nd.register_custom_formats(active_name_formats)
|
self.db.name_formats = _nd.get_name_format(only_custom=True,
|
||||||
|
only_active=False)
|
||||||
|
|
||||||
def cleanup_duplicate_spouses(self):
|
def cleanup_duplicate_spouses(self):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user