2007-10-09 Benny Malengier <benny.malengier@gramps-project.org>

* src/GrampsDb/_GrampsInMemDB.py: correctly store global name grouping
	* src/GrampsDb/_GrampsBSDDB.py: correctly store global name grouping
	* src/RelLib/_Name.py: allow grouping equal to surname
	* src/Editors/_EditName.py: correct handling of name grouping, issue #647

2007-10-09 Benny Malengier <benny.malengier@gramps-project.org> 


svn: r9115
This commit is contained in:
Benny Malengier 2007-10-09 13:03:23 +00:00
parent efb702db44
commit fd9e484fb2
5 changed files with 166 additions and 42 deletions

View File

@ -1,4 +1,10 @@
2007-10-06 Benny Malengier <benny.malengier@gramps-project.org> 2007-10-09 Benny Malengier <benny.malengier@gramps-project.org>
* src/GrampsDb/_GrampsInMemDB.py: correctly store global name grouping
* src/GrampsDb/_GrampsBSDDB.py: correctly store global name grouping
* src/RelLib/_Name.py: allow grouping equal to surname
* src/Editors/_EditName.py: correct handling of name grouping, issue #647
2007-10-09 Benny Malengier <benny.malengier@gramps-project.org>
* src/Editors/_EditPerson.py: change tabs in spaces (I HATE THIS !!!) * src/Editors/_EditPerson.py: change tabs in spaces (I HATE THIS !!!)
2007-10-07 Douglas Blank <dblank@cs.brynmawr.edu> 2007-10-07 Douglas Blank <dblank@cs.brynmawr.edu>

View File

@ -71,17 +71,24 @@ class EditName(EditSecondary):
_("Name Editor")) _("Name Editor"))
self.original_group_as = self.obj.get_group_as() self.original_group_as = self.obj.get_group_as()
self.original_group_set = not (self.original_group_as == '')
srn = self.obj.get_surname()
self._get_global_grouping(srn)
self.general_label = self.top.get_widget("general_tab") self.general_label = self.top.get_widget("general_tab")
self.group_over = self.top.get_widget('group_over') self.group_over = self.top.get_widget('group_over')
self.group_over.connect('toggled',self.on_group_over_toggled) self.group_over.connect('toggled',self.on_group_over_toggled)
self.group_over.set_sensitive(not self.db.readonly) self.group_over.set_sensitive(not self.db.readonly)
self.toggle_dirty = False
Utils.bold_label(self.general_label) Utils.bold_label(self.general_label)
def _post_init(self): def _post_init(self):
if self.original_group_as and \ """if there is override, set the override toggle active
(self.original_group_as != self.obj.get_surname()): """
if self.original_group_set or self.global_group_set :
self.group_over.set_active(True) self.group_over.set_active(True)
def _connect_signals(self): def _connect_signals(self):
@ -96,7 +103,10 @@ class EditName(EditSecondary):
self.obj.get_group_as, self.obj.get_group_as,
self.db.readonly) self.db.readonly)
if not self.original_group_as: if not self.original_group_set:
if self.global_group_set :
self.group_as.force_value(self.global_group_as)
else :
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) format_list = [(name,number) for (number,name,fmt_str,act)
@ -200,6 +210,18 @@ class EditName(EditSecondary):
self._setup_notebook_tabs( notebook) self._setup_notebook_tabs( notebook)
def _get_global_grouping(self, srn):
""" we need info on the global grouping of the surname on init,
and on change of surname
"""
self.global_group_as = self.db.get_name_group_mapping(srn)
if srn == self.global_group_as:
self.global_group_as = None
self.global_group_set = False
else:
self.global_group_set = True
def build_menu_names(self,name): def build_menu_names(self,name):
if name: if name:
ntext = NameDisplay.displayer.display_name(name) ntext = NameDisplay.displayer.display_name(name)
@ -210,48 +232,141 @@ class EditName(EditSecondary):
return (menu_label,submenu_label) return (menu_label,submenu_label)
def update_group_as(self,obj): def update_group_as(self,obj):
if not self.group_over.get_active(): """Callback if surname changes on GUI
if self.obj.get_group_as() != self.obj.get_surname(): If overwrite is not set, we change the group name too
val = self.obj.get_group_as() """
else:
name = self.obj.get_surname() name = self.obj.get_surname()
val = self.db.get_name_group_mapping(name) if not self.group_over.get_active():
self.group_as.force_value(val) self.group_as.force_value(name)
#new surname, so perhaps now a different grouping?
self._get_global_grouping(name)
if not self.group_over.get_active() and self.global_group_set :
self.group_over.set_active(True)
self.group_as.enable(True)
self.toggle_dirty = True
self.group_as.force_value(self.global_group_as)
elif self.group_over.get_active() and self.toggle_dirty:
#changing surname caused active group_over in past, change
# group_over as we type
if self.global_group_set :
self.group_as.force_value(self.global_group_as)
else:
self.toggle_dirty = False
self.group_as.force_value(name)
self.group_over.set_active(False)
self.group_as.enable(False)
def on_group_over_toggled(self,obj): def on_group_over_toggled(self,obj):
""" group over changes, if activated, enable edit,
if unactivated, go back to surname.
"""
self.toggle_dirty = False
#enable group as box
self.group_as.enable(obj.get_active()) self.group_as.enable(obj.get_active())
if not obj.get_active(): if not obj.get_active():
field_value = self.obj.get_surname() surname = self.obj.get_surname()
mapping = self.db.get_name_group_mapping(field_value) self.group_as.set_text(surname)
self.group_as.set_text(mapping)
def save(self,*obj): def save(self,*obj):
"""Save the name setting. All is ok, except grouping. We need to
consider:
1/ global set, not local set --> unset (ask if global unset)
2/ global set, local set --> unset (only local unset!)
3/ not global set, local set
or not global set, not local set --> unset
4/ not local set, not global set
or not local set, global set --> set val (ask global or local)
5/ local set, not global set --> set (change local)
6/ local set, global set --> set (set to global if possible)
"""
closeit = True
surname = self.obj.get_surname()
group_as= self.obj.get_group_as()
grouping_active = self.group_over.get_active()
if not self.group_over.get_active(): if not grouping_active :
self.obj.set_group_as("") #user wants to group with surname
elif self.obj.get_group_as() == self.obj.get_surname(): if self.global_group_set and not self.original_group_set :
self.obj.set_group_as("") #warn that group will revert to surname
elif self.obj.get_group_as() != self.original_group_as:
grp_as = self.obj.get_group_as()
srn = self.obj.get_surname()
if grp_as not in self.db.get_name_group_keys():
from QuestionDialog import QuestionDialog2 from QuestionDialog import QuestionDialog2
q = QuestionDialog2(
_("Break global name grouping?"),
_("All people with the name of %(surname)s will no longer "
"be grouped with the name of %(group_name)s."
) % { 'surname' : surname,
'group_name':group_as},
_("Continue"),
_("Return to Name Editor"))
val = q.run()
if val:
#delete the grouping link on database
self.db.set_name_group_mapping(surname, None)
self.obj.set_group_as("")
else :
closeit = False
elif self.global_group_set and self.original_group_set:
#we change it only back to surname locally, so store group_as
# Note: if all surnames are locally changed to surname, we
# should actually unsed the global group here ....
pass
else :
#global group not set, don't set local group too:
self.obj.set_group_as("")
else:
#user wants to override surname, see what he wants
if not self.original_group_set :
#if changed, ask if this has to happen for the entire group,
#this might be creation of group link, or change of group link
if self.global_group_as != group_as:
from QuestionDialog import QuestionDialog2
q = QuestionDialog2( q = QuestionDialog2(
_("Group all people with the same name?"), _("Group all people with the same name?"),
_("You have the choice of grouping all people with the " _("You have the choice of grouping all people with the "
"name of %(surname)s with the name of %(group_name)s, or " "name of %(surname)s with the name of %(group_name)s, or "
"just mapping this particular name.") % { 'surname' : srn, "just mapping this particular name."
'group_name':grp_as}, ) % { 'surname' : surname,
'group_name':group_as},
_("Group all"), _("Group all"),
_("Group this name only")) _("Group this name only"))
val = q.run() val = q.run()
if val: if val:
self.obj.set_group_as("") if group_as == surname :
self.db.set_name_group_mapping(srn,grp_as) self.db.set_name_group_mapping(surname, None)
else: else:
self.obj.set_group_as(grp_as) self.db.set_name_group_mapping(surname, group_as)
self.obj.set_group_as("")
else:
if self.global_group_set :
#allow smith to Dummy, but one person still Smith
self.obj.set_group_as(group_as)
elif group_as == surname :
self.obj.set_group_as("")
else:
self.obj.set_group_as(group_as)
else:
#keep original value, no original group
self.obj.set_group_as("")
elif not self.global_group_set :
#don't ask user, group was set locally before,
#change it locally only
if group_as == surname :
#remove grouping
self.obj.set_group_as("")
else:
pass
else:
#locally set group and global group set
if group_as == self.global_group_as :
#unset local group, go with global one
self.obj.set_group_as("")
else :
#local set is different from global, keep it like that
pass
if closeit:
if self.callback: if self.callback:
self.callback(self.obj) self.callback(self.obj)
self.close() self.close()

View File

@ -1180,6 +1180,9 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.event_map.sync() self.event_map.sync()
def set_name_group_mapping(self,name,group): def set_name_group_mapping(self,name,group):
"""Make name group under the value of group.
If group =None, the old grouping is deleted
"""
if not self.readonly: if not self.readonly:
if self.UseTXN: if self.UseTXN:
# Start transaction if needed # Start transaction if needed
@ -1188,9 +1191,9 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
the_txn = None the_txn = None
name = str(name) name = str(name)
data = self.name_group.get(name, txn=the_txn) data = self.name_group.get(name, txn=the_txn)
if not group and data: if data is not None:
self.name_group.delete(name, txn=the_txn) self.name_group.delete(name, txn=the_txn)
else: if group is not None:
self.name_group.put(name,group,txn=the_txn) self.name_group.put(name,group,txn=the_txn)
if self.UseTXN: if self.UseTXN:
the_txn.commit() the_txn.commit()

View File

@ -140,7 +140,7 @@ class GrampsInMemDB(GrampsDbBase):
def set_name_group_mapping(self,name,group): def set_name_group_mapping(self,name,group):
if group == None and self.name_group.has_key(name): if group == None and self.name_group.has_key(name):
del self.name_group[name] del self.name_group[name]
else: if group is not None :
self.name_group[name] = group self.name_group[name] = group
def build_surname_list(self): def build_surname_list(self):

View File

@ -170,10 +170,10 @@ class Name(SecondaryObject, PrivacyBase, SourceBase, NoteBase, DateBase):
Sets the grouping name for a person. Normally, this is the person's Sets the grouping name for a person. Normally, this is the person's
surname. However, some locales group equivalent names (e.g. Ivanova surname. However, some locales group equivalent names (e.g. Ivanova
and Ivanov in Russian are usually considered equivalent. and Ivanov in Russian are usually considered equivalent.
Note that there is also a database wide grouping set_name_group_mapping
So one might map a name Smith to SmithNew, and have one person still
grouped with name Smith. Hence, group_as can be equal to surname!
""" """
if name == self.surname:
self.group_as = ""
else:
self.group_as = name self.group_as = name
def get_group_as(self): def get_group_as(self):