2006-07-27 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/GrampsCfg.py: Custom name format support improvements. * src/Editors/_EditName.py: Custom name format support improvements. * src/NameDisplay.py: Custom name format support improvements. * src/plugins/Check.py (cleanup_deleted_name_formats): Db cleanup of deleted custom name format references. svn: r7083
This commit is contained in:
parent
0fa6a8eaa0
commit
c7d9e4b9fe
@ -1,3 +1,10 @@
|
||||
2006-07-27 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
|
||||
* src/GrampsCfg.py: Custom name format support improvements.
|
||||
* src/Editors/_EditName.py: Custom name format support improvements.
|
||||
* src/NameDisplay.py: Custom name format support improvements.
|
||||
* src/plugins/Check.py (cleanup_deleted_name_formats): Db cleanup of
|
||||
deleted custom name format references.
|
||||
|
||||
2006-07-26 Steve Hall <digitect@mindspring.org>
|
||||
* windows/nsis/gramps-build.bat: Add windows building scripts.
|
||||
* windows/nsis/gramps.nsi: Add windows building scripts.
|
||||
|
@ -97,12 +97,12 @@ class EditName(EditSecondary):
|
||||
self.group_as.force_value(self.obj.get_surname())
|
||||
|
||||
|
||||
(number,name,fmt_str) =RelLib.Name.DEFAULT_FORMAT
|
||||
(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)
|
||||
in NameDisplay.displayer.CUSTOM_FORMATS]
|
||||
format_list += [(name,number) for (number,name,fmt_str,act)
|
||||
in NameDisplay.displayer.CUSTOM_FORMATS if act]
|
||||
|
||||
self.sort_as = MonitoredMenu(
|
||||
self.top.get_widget('sort_as'),
|
||||
|
@ -290,12 +290,15 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
index += 1
|
||||
|
||||
# add all the custom formats loaded from the db to the list
|
||||
for num,name,fmt_str in _nd.CUSTOM_FORMATS:
|
||||
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
|
||||
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)
|
||||
|
||||
@ -359,7 +362,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
"""
|
||||
Preset name format ComboBox callback
|
||||
|
||||
Saves the new default to gconf and NameDisplay's fn_array
|
||||
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())
|
||||
@ -371,8 +374,8 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
"""
|
||||
Name format editor TreeView callback
|
||||
|
||||
Remebers the selected row's values (self.selected_fmt, self.iter)
|
||||
and sets the Remove and Edit button sensitivity
|
||||
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:
|
||||
@ -404,6 +407,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
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 \
|
||||
@ -413,37 +417,34 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
COL_FMT,f,
|
||||
COL_EXPL,e)
|
||||
self.selected_fmt = (self.selected_fmt[COL_NUM],n,f,e)
|
||||
self.register_fmt()
|
||||
num = self.selected_fmt[COL_NUM]
|
||||
|
||||
self.register_fmt(num,n,f,1)
|
||||
self.cb_name_changed(self.fmt_obox)
|
||||
|
||||
def cb_del_fmt_str(self,obj):
|
||||
"""
|
||||
Name format editor Remove button callback
|
||||
"""
|
||||
removed_idx = self.fmt_index[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])
|
||||
# delete the row from the index...
|
||||
del(self.fmt_index[self.selected_fmt[COL_NUM]])
|
||||
# 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
|
||||
# ...and from the model
|
||||
# delete the row from the model
|
||||
self.fmt_model.remove(self.iter)
|
||||
# update the custom format registration in NameDisplay instance
|
||||
self.register_fmt()
|
||||
self.register_fmt(num,'','',0)
|
||||
|
||||
def register_fmt(self):
|
||||
formats = []
|
||||
iter = self.fmt_model.get_iter_first()
|
||||
while iter:
|
||||
(i,n,f) = self.fmt_model.get(iter,COL_NUM,COL_NAME,COL_FMT)
|
||||
if i < 0:
|
||||
formats.append((i,n,f))
|
||||
iter = self.fmt_model.iter_next(iter)
|
||||
self.dbstate.db.name_formats = formats
|
||||
_nd.register_custom_formats(formats)
|
||||
|
||||
def register_fmt(self,num,name,str,act):
|
||||
_nd.update_custom_formats(num,name,str,act)
|
||||
self.dbstate.db.name_formats = _nd.CUSTOM_FORMATS
|
||||
|
||||
def add_formats_panel(self):
|
||||
table = gtk.Table(3,8)
|
||||
table.set_border_width(12)
|
||||
|
@ -50,16 +50,6 @@ _SORT = 13
|
||||
_DISPLAY = 14
|
||||
_CALL = 15
|
||||
|
||||
##-------------------------------------------------------------------------
|
||||
##
|
||||
## formats registration
|
||||
##
|
||||
##-------------------------------------------------------------------------
|
||||
##CUSTOM_FORMATS = []
|
||||
|
||||
##def register_custom_formats(formats):
|
||||
##CUSTOM_FORMATS = formats[:]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# NameDisplay class
|
||||
@ -87,21 +77,9 @@ class NameDisplay:
|
||||
##self.force_upper = use_upper
|
||||
|
||||
self.CUSTOM_FORMATS = []
|
||||
|
||||
self.fn_array = {
|
||||
##Name.LNFN: self._lnfn,
|
||||
##Name.FNLN: self._fnln,
|
||||
##Name.PTFN: self._ptfn,
|
||||
##Name.FN: self._fn,
|
||||
}
|
||||
|
||||
self.raw_fn_array = {
|
||||
##Name.LNFN: self._lnfn_raw,
|
||||
##Name.FNLN: self._fnln_raw,
|
||||
##Name.PTFN: self._ptfn_raw,
|
||||
##Name.FN: self._fn_raw,
|
||||
}
|
||||
|
||||
self.gramps_format = Name.LNFN
|
||||
self.fn_array = {}
|
||||
self.raw_fn_array = {}
|
||||
self.set_format_fn()
|
||||
|
||||
default_idx = Config.get(Config.NAME_FORMAT)
|
||||
@ -116,14 +94,19 @@ class NameDisplay:
|
||||
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 in self.CUSTOM_FORMATS:
|
||||
self.fn_array[number] = self._format_fn(fmt_str)
|
||||
self.raw_fn_array[number] = self._format_raw_fn(fmt_str)
|
||||
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
|
||||
@ -138,6 +121,19 @@ class NameDisplay:
|
||||
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):
|
||||
##"""
|
||||
@ -381,7 +377,10 @@ class NameDisplay:
|
||||
@returns: Returns the L{Name} string representation
|
||||
@rtype: str
|
||||
"""
|
||||
return self.fn_array[name.sort_as](name)
|
||||
idx = name.sort_as
|
||||
if not self.fn_array.has_key(idx):
|
||||
idx = 0
|
||||
return self.fn_array[idx](name)
|
||||
|
||||
def raw_sorted_name(self,raw_data):
|
||||
"""
|
||||
@ -394,7 +393,10 @@ class NameDisplay:
|
||||
@returns: Returns the L{Name} string representation
|
||||
@rtype: str
|
||||
"""
|
||||
return self.raw_fn_array[raw_data[_SORT]](raw_data)
|
||||
idx = raw_data[_SORT]
|
||||
if not self.raw_fn_array.has_key(idx):
|
||||
idx = 0
|
||||
return self.raw_fn_array[idx](raw_data)
|
||||
|
||||
def display(self,person):
|
||||
"""
|
||||
@ -439,7 +441,12 @@ class NameDisplay:
|
||||
"""
|
||||
if name == None:
|
||||
return ""
|
||||
return self.fn_array[name.display_as](name)
|
||||
|
||||
idx = name.display_as
|
||||
if not self.fn_array.has_key(idx):
|
||||
idx = 0
|
||||
|
||||
return self.fn_array[idx](name)
|
||||
|
||||
def display_given(self,person):
|
||||
name = person.get_primary_name()
|
||||
|
@ -60,6 +60,7 @@ import ManagedWindow
|
||||
|
||||
from PluginUtils import Tool, register_tool
|
||||
from QuestionDialog import OkDialog, MissingMediaDialog
|
||||
from NameDisplay import displayer as _nd
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -163,6 +164,7 @@ class Check(Tool.BatchTool):
|
||||
checker = CheckIntegrity(dbstate, uistate, trans)
|
||||
checker.fix_encoding()
|
||||
checker.cleanup_missing_photos(cli)
|
||||
checker.cleanup_deleted_name_formats()
|
||||
|
||||
prev_total = -1
|
||||
total = 0
|
||||
@ -211,6 +213,7 @@ class CheckIntegrity:
|
||||
self.invalid_death_events = []
|
||||
self.invalid_place_references = []
|
||||
self.invalid_source_references = []
|
||||
self.removed_name_format = []
|
||||
self.progress = Utils.ProgressMeter(_('Checking database'),'')
|
||||
|
||||
def family_errors(self):
|
||||
@ -219,6 +222,59 @@ class CheckIntegrity:
|
||||
len(self.empty_family) + \
|
||||
len(self.duplicate_links)
|
||||
|
||||
def cleanup_deleted_name_formats(self):
|
||||
"""
|
||||
Permanently remove deleted name formats from db
|
||||
|
||||
When user deletes custom name format those are not removed only marked
|
||||
as "inactive". This method does the cleanup of the name format table,
|
||||
as well as fixes the display_as, sort_as values for each Name in the db.
|
||||
|
||||
"""
|
||||
self.progress.set_pass(_('Looking for invalid name format references'),
|
||||
self.db.get_number_of_people())
|
||||
|
||||
deleted_name_formats = [number for (number,name,fmt_str,act)
|
||||
in self.db.name_formats if not act]
|
||||
|
||||
for person_handle in self.db.get_person_handles():
|
||||
person = self.db.get_person_from_handle(person_handle)
|
||||
|
||||
p_changed = False
|
||||
name = person.get_primary_name()
|
||||
if name.get_sort_as() in deleted_name_formats:
|
||||
name.set_sort_as(0)
|
||||
p_changed = True
|
||||
if name.get_display_as() in deleted_name_formats:
|
||||
name.set_display_as(0)
|
||||
p_changed = True
|
||||
if p_changed:
|
||||
person.set_primary_name(name)
|
||||
|
||||
a_changed = False
|
||||
name_list = []
|
||||
for name in person.get_alternate_names():
|
||||
if name.get_sort_as() in deleted_name_formats:
|
||||
name.set_sort_as(0)
|
||||
a_changed = True
|
||||
if name.get_display_as() in deleted_name_formats:
|
||||
name.set_display_as(0)
|
||||
a_changed = True
|
||||
name_list.append(name)
|
||||
if a_changed:
|
||||
person.set_alternate_names(name_list)
|
||||
|
||||
if p_changed or a_changed:
|
||||
self.db.commit_person(person,self.trans)
|
||||
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)
|
||||
|
||||
def cleanup_duplicate_spouses(self):
|
||||
|
||||
self.progress.set_pass(_('Looking for duplicate spouses'),
|
||||
@ -754,6 +810,7 @@ class CheckIntegrity:
|
||||
person = birth_invalid + death_invalid
|
||||
place_references = len(self.invalid_place_references)
|
||||
source_references = len(self.invalid_source_references)
|
||||
name_format = len(self.removed_name_format)
|
||||
|
||||
errors = blink + efam + photos + rel + person \
|
||||
+ event_invalid + place_references + source_references
|
||||
@ -869,6 +926,11 @@ class CheckIntegrity:
|
||||
self.text.write(_("1 source was referenced but not found\n"))
|
||||
elif source_references > 1:
|
||||
self.text.write(_("%d sources were referenced, but not found\n") % source_references)
|
||||
if name_format == 1:
|
||||
self.text.write(_("1 invalid name format reference was removed\n"))
|
||||
elif name_format > 1:
|
||||
self.text.write(_("%d invalid name format references were removed\n")
|
||||
% name_format)
|
||||
|
||||
return errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user