ReadGedcom patch from Mark Lewis, Filter update for event match problem, improved Find for ZODB

svn: r1022
This commit is contained in:
Don Allingham 2002-06-04 04:04:07 +00:00
parent 8479515577
commit bef3d944bf
8 changed files with 235 additions and 151 deletions

View File

@ -43,7 +43,7 @@ import libglade
#-------------------------------------------------------------------------
import RelLib
import const
import sort
import Sorter
import Utils
import GrampsCfg
@ -82,8 +82,13 @@ class AddSpouse:
self.ok = self.glade.get_widget('spouse_ok')
self.ok.set_sensitive(0)
self.name_list = self.db.getPersonMap().values()
self.name_list.sort(sort.by_last_name)
arrow_map = [(2,self.glade.get_widget('NameArrow')),
(3,self.glade.get_widget('DateArrow'))]
self.spouse_list.set_column_visibility(2,0)
self.spouse_list.set_column_visibility(3,0)
self.sorter = Sorter.Sorter(self.spouse_list,arrow_map,'spouse',self.top)
self.name_list = self.db.getPersonKeys()
self.rel_combo.set_popdown_strings(const.familyRelations)
title = _("Choose Spouse/Partner of %s") % GrampsCfg.nameof(person)
self.glade.get_widget("spouseTitle").set_text(title)
@ -127,11 +132,11 @@ class AddSpouse:
QuickAdd.QuickAdd(self.db,gen,self.update_list)
def update_list(self,person):
self.name_list.append(person)
self.name_list.sort(sort.by_last_name)
self.name_list.append(person.getId())
self.addperson(person)
self.relation_type_changed(self.relation_type)
row = self.spouse_list.find_row_from_data(person)
self.sorter.sort_list()
self.spouse_list.select_row(row,0)
self.spouse_list.moveto(row,0)
@ -143,7 +148,7 @@ class AddSpouse:
if len(self.spouse_list.selection) == 0:
return
row = self.spouse_list.selection[0]
spouse = self.spouse_list.get_row_data(row)
spouse = self.db.getPerson(self.spouse_list.get_row_data(row))
# don't do anything if the marriage already exists
for f in self.person.getFamilyList():
@ -188,13 +193,15 @@ class AddSpouse:
index = 0
self.spouse_list.clear()
self.spouse_list.freeze()
for person in self.name_list:
for key in self.name_list:
person = self.db.getPerson(key)
if person.getGender() == gender:
continue
name = person.getPrimaryName().getName()
self.spouse_list.append([name,Utils.birthday(person)])
self.spouse_list.set_row_data(index,person)
data = person.getDisplayInfo()
self.spouse_list.append([data[0],data[3],data[5],data[6]])
self.spouse_list.set_row_data(index,key)
index = index + 1
self.sorter.sort_list()
self.spouse_list.thaw()
#-------------------------------------------------------------------------
@ -280,7 +287,7 @@ class SetSpouse:
if len(self.spouse_list.selection) == 0:
return
row = self.spouse_list.selection[0]
spouse = self.spouse_list.get_row_data(row)
spouse = self.db.getPerson(self.spouse_list.get_row_data(row))
# don't do anything if the marriage already exists
for f in self.person.getFamilyList():

View File

@ -56,13 +56,14 @@ _ = gettext
class FindBase:
"""Opens find person dialog for gramps"""
def __init__(self,clist,task,name):
def __init__(self,clist,task,name,db):
"""Opens a dialog box instance that allows users to
search for a person.
clist - GtkCList containing the people information
task - function to call to change the active person"""
self.db = db
self.clist = clist
self.nlist = []
self.task = task
@ -84,12 +85,36 @@ class FindBase:
self.top.editable_enters(self.entry)
self.entry.grab_focus()
def get_value(self,id):
return None
def enable_autocomp(self):
if GrampsCfg.autocomp:
self.comp = AutoComp.AutoEntry(self.entry,self.nlist)
def advance(self,func):
pass
try:
self.row = self.clist.selection[0]
except IndexError:
gtk.gdk_beep()
return
text = self.entry.get_text()
if self.row == None or text == "":
gtk.gdk_beep()
return
orow = self.row
func()
while self.row != orow:
id = self.clist.get_row_data(self.row)
if id == None:
func()
continue
if string.find(string.upper(self.get_value(id)),string.upper(text)) >= 0:
self.task(self.row)
return
func()
gtk.gdk_beep()
def forward(self):
self.row = self.row + 1
@ -121,45 +146,22 @@ class FindBase:
class FindPerson(FindBase):
"""Opens a Find Person dialog for GRAMPS"""
def __init__(self,clist,task,plist):
def __init__(self,clist,task,db):
"""Opens a dialog box instance that allows users to
search for a person.
clist - GtkCList containing the people information
task - function to call to change the active person"""
FindBase.__init__(self,clist,task,_("Find Person"))
for n in plist:
self.nlist.append(n.getPrimaryName().getName())
FindBase.__init__(self,clist,task,_("Find Person"),db)
for n in self.db.getPersonKeys():
val = self.db.getPersonDisplay(n)
self.nlist.append(val[0])
self.enable_autocomp()
def advance(self,func):
try:
self.row = self.clist.selection[0]
except IndexError:
gtk.gdk_beep()
return
text = self.entry.get_text()
if self.row == None or text == "":
gtk.gdk_beep()
return
orow = self.row
func()
person = None
while self.row != orow:
value = self.clist.get_row_data(self.row)
if value == None:
func()
continue
person,alt = value
if alt == 0:
name = person.getPrimaryName().getName()
if string.find(string.upper(name),string.upper(text)) >= 0:
self.task(person)
return
func()
gtk.gdk_beep()
def get_value(self,id):
return self.db.getPersonDisplay(id)[0]
#-------------------------------------------------------------------------
#
@ -169,42 +171,20 @@ class FindPerson(FindBase):
class FindPlace(FindBase):
"""Opens a Find Place dialog for GRAMPS"""
def __init__(self,clist,task,plist):
def __init__(self,clist,task,db):
"""Opens a dialog box instance that allows users to
search for a place.
clist - GtkCList containing the people information
task - function to call to change the active person"""
FindBase.__init__(self,clist,task,_("Find Place"))
for n in plist:
self.nlist.append(n.get_title())
FindBase.__init__(self,clist,task,_("Find Place"),db)
for n in self.db.getPlaceKeys():
self.nlist.append(self.db.getPlaceDisplay(n)[0])
self.enable_autocomp()
def advance(self,func):
try:
self.row = self.clist.selection[0]
except IndexError:
gtk.gdk_beep()
return
text = self.entry.get_text()
if self.row == None or text == "":
gtk.gdk_beep()
return
orow = self.row
func()
while self.row != orow:
value = self.clist.get_row_data(self.row)
if value == None:
func()
continue
name = value.get_title()
if string.find(string.upper(name),string.upper(text)) >= 0:
self.task(self.row)
return
func()
gtk.gdk_beep()
def get_value(self,id):
return self.db.getPlaceDisplay(id)[0]
#-------------------------------------------------------------------------
#
@ -214,42 +194,20 @@ class FindPlace(FindBase):
class FindSource(FindBase):
"""Opens a Find Place dialog for GRAMPS"""
def __init__(self,clist,task,plist):
def __init__(self,clist,task,db):
"""Opens a dialog box instance that allows users to
search for a place.
clist - GtkCList containing the people information
task - function to call to change the active person"""
FindBase.__init__(self,clist,task,_("Find Source"))
for n in plist:
self.nlist.append(n.getTitle())
FindBase.__init__(self,clist,task,_("Find Source"),db)
for n in self.db.getSourceKeys():
self.nlist.append(n[0])
self.enable_autocomp()
def advance(self,func):
try:
self.row = self.clist.selection[0]
except IndexError:
gtk.gdk_beep()
return
text = self.entry.get_text()
if self.row == None or text == "":
gtk.gdk_beep()
return
orow = self.row
func()
while self.row != orow:
value = self.clist.get_row_data(self.row)
if value == None:
func()
continue
name = value.getTitle()
if string.find(string.upper(name),string.upper(text)) >= 0:
self.task(self.row)
return
func()
gtk.gdk_beep()
def get_value(self,id):
return self.db.getSourceDisplay(id)[0]
#-------------------------------------------------------------------------
#

View File

@ -413,12 +413,12 @@ class HasBirth(Rule):
def apply(self,p):
event = p.getBirth()
if self.list[2] and find(event.getDescription(),self.list[2])==-1:
if len(self.list) > 2 and find(event.getDescription(),self.list[2])==-1:
return 0
if self.date:
if date_cmp(self.date,event.getDateObj()) == 0:
return 0
if self.list[1] and find(p.getPlaceName(),self.list[1]) == -1:
if len(self.list) > 1 and find(event.getPlaceName(),self.list[1]) == -1:
return 0
return 1

View File

@ -1986,6 +1986,10 @@ class GrampsDB(Persistent):
"""returns a map of gramps's IDs to Family instances"""
return extmap(self.familyMap)
def getFamily(self,id):
"""returns a map of gramps's IDs to Family instances"""
return self.familyMap[id]
def setFamilyMap(self,map):
"""sets the map of gramps's IDs to Family instances"""
self.familyMap = map

View File

@ -4661,12 +4661,9 @@
<widget>
<class>GtkScrolledWindow</class>
<name>scrolledwindow9</name>
<border_width>10</border_width>
<width>400</width>
<height>200</height>
<hscrollbar_policy>GTK_POLICY_NEVER</hscrollbar_policy>
<vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy>
<name>scrolledwindow36</name>
<hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy>
<vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy>
<hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>
<vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy>
<child>
@ -4678,28 +4675,143 @@
<widget>
<class>GtkCList</class>
<name>spouseList</name>
<width>450</width>
<height>300</height>
<can_focus>True</can_focus>
<signal>
<name>select_row</name>
<handler>on_select_row</handler>
<last_modification_time>Fri, 29 Mar 2002 13:44:27 GMT</last_modification_time>
<last_modification_time>Sat, 01 Jun 2002 20:59:14 GMT</last_modification_time>
</signal>
<signal>
<name>unselect_row</name>
<handler>on_unselect_row</handler>
<last_modification_time>Fri, 29 Mar 2002 13:44:33 GMT</last_modification_time>
<last_modification_time>Sat, 01 Jun 2002 20:59:58 GMT</last_modification_time>
</signal>
<columns>2</columns>
<column_widths>256,80</column_widths>
<columns>4</columns>
<column_widths>229,85,5,80</column_widths>
<selection_mode>GTK_SELECTION_SINGLE</selection_mode>
<show_titles>True</show_titles>
<shadow_type>GTK_SHADOW_IN</shadow_type>
<widget>
<class>GtkHBox</class>
<child_name>CList:title</child_name>
<name>hbox82</name>
<homogeneous>True</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkHBox</class>
<name>hbox83</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label315</name>
<label>Name</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkArrow</class>
<name>NameArrow</name>
<width>10</width>
<height>10</height>
<arrow_type>GTK_ARROW_DOWN</arrow_type>
<shadow_type>GTK_SHADOW_OUT</shadow_type>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>True</fill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkHBox</class>
<child_name>CList:title</child_name>
<name>hbox80</name>
<homogeneous>True</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkHBox</class>
<name>hbox81</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label311</name>
<label>Birth Date</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkArrow</class>
<name>DateArrow</name>
<width>10</width>
<height>10</height>
<visible>False</visible>
<arrow_type>GTK_ARROW_DOWN</arrow_type>
<shadow_type>GTK_SHADOW_OUT</shadow_type>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label65</name>
<label>Name</label>
<name>label318</name>
<label></label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
@ -4711,8 +4823,8 @@
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label66</name>
<label>Birthdate</label>
<name>label319</name>
<label></label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>

View File

@ -330,25 +330,23 @@ class Gramps:
def on_find_activate(self,obj):
"""Display the find box"""
if self.notebook.get_current_page() == 4:
Find.FindPlace(self.place_view.place_list,self.find_goto_place,
self.db.getPlaceMap().values())
Find.FindPlace(self.place_view.place_list,self.find_goto_place,self.db)
elif self.notebook.get_current_page() == 3:
Find.FindSource(self.source_view.source_list,self.find_goto_source,
self.db.getSourceMap().values())
Find.FindSource(self.source_view.source_list,self.find_goto_source,self.db)
elif self.notebook.get_current_page() == 5:
Find.FindMedia(self.media_view.media_list,self.find_goto_media,
self.db.getObjectMap().values())
else:
Find.FindPerson(self.person_list,self.find_goto_to,
self.db.getPersonMap().values())
Find.FindPerson(self.person_list,self.find_goto_to,self.db)
def on_findname_activate(self,obj):
"""Display the find box"""
pass
def find_goto_to(self,person):
def find_goto_to(self,row):
"""Find callback to jump to the selected person"""
self.change_active_person(person)
id = self.person_list.get_row_data(row)
self.change_active_person(self.db.getPerson(id))
self.goto_active_person()
self.update_display(0)
@ -1290,9 +1288,9 @@ class Gramps:
EditPerson.EditPerson(person, self.db, self.update_after_edit)
def build_spouse_dropdown(self):
list = []
mymap = {}
mynmap = {}
list = []
sel = None
for f in self.active_person.getFamilyList():
if self.active_person == f.getFather():
@ -1303,8 +1301,8 @@ class Gramps:
list.append(c)
if f == self.active_family or sel == None:
sel = c
mymap[f] = c
mynmap[f] = sname
mynmap[f.getId()] = sname
mymap[f.getId()] = c
self.spouse_combo.disable_activate()
self.spouse_combo.list.clear_items(0,-1)
self.spouse_combo.list.append_items(list)
@ -1706,10 +1704,13 @@ class Gramps:
gnome.ui.GnomeErrorDialog(_("No default/home person has been set"))
def on_add_bookmark_activate(self,obj):
self.bookmarks.add(self.active_person)
name = GrampsCfg.nameof(self.active_person)
self.statusbar.set_status(_("%s has been bookmarked") % name)
gtk.timeout_add(5000,self.modify_statusbar)
if self.active_person:
self.bookmarks.add(self.active_person)
name = GrampsCfg.nameof(self.active_person)
self.statusbar.set_status(_("%s has been bookmarked") % name)
gtk.timeout_add(5000,self.modify_statusbar)
else:
GnomeWarningDialog(_("Bookmark could not be set because no one was selected"))
def on_edit_bookmarks_activate(self,obj):
self.bookmarks.edit()
@ -1760,7 +1761,7 @@ class Gramps:
if len(select) == 0:
self.active_family = None
else:
self.active_family = select[0].get_data('d')
self.active_family = self.db.getFamily(select[0].get_data('d'))
if self.active_family == self.active_person.getFamilyList()[0]:
self.pref_spouse.set_sensitive(0)

View File

@ -53,30 +53,30 @@ class PatchNames:
self.title_list = []
self.nick_list = []
personMap = self.db.getPersonMap()
for key in personMap.keys():
for key in self.db.getPersonKeys():
person = personMap[key]
person = self.db.getPerson(key)
first = person.getPrimaryName().getFirstName()
match = _title_re.match(first)
if match:
groups = match.groups()
self.title_list.append((person,groups[0],groups[1]))
self.title_list.append((key,groups[0],groups[1]))
match = _nick_re.match(first)
if match:
groups = match.groups()
self.nick_list.append((person,groups[0],groups[1]))
self.nick_list.append((key,groups[0],groups[1]))
msg = ""
if len(self.nick_list) > 0 or len(self.title_list) > 0:
for name in self.nick_list:
for (id,name,nick) in self.nick_list:
p = self.db.getPerson(id)
msg = msg + _("%s will be extracted as a nickname from %s\n") % \
(name[2],name[0].getPrimaryName().getName())
(nick,p.getPrimaryName().getName())
for name in self.title_list:
for (id,title,nick) in self.title_list:
p = self.db.getPerson(id)
msg = msg + _("%s will be extracted as a title from %s\n") % \
(name[0].getPrimaryName().getName(),name[1])
(title,p.getPrimaryName().getName())
base = os.path.dirname(__file__)
glade_file = base + os.sep + "patchnames.glade"
@ -93,15 +93,19 @@ class PatchNames:
def on_ok_clicked(self,obj):
for grp in self.nick_list:
name = grp[0].getPrimaryName()
p = self.db.getPerson(grp[0])
name = p.getPrimaryName()
name.setFirstName(grp[1])
grp[0].setNickName(grp[2])
p.setNickName(grp[2])
self.db.buildPersonDisplay(grp[0])
Utils.modified()
for grp in self.title_list:
name = grp[0].getPrimaryName()
p = self.db.getPerson(grp[0])
name = p.getPrimaryName()
name.setFirstName(grp[2])
name.setTitle(grp[1])
self.db.buildPersonDisplay(grp[0])
Utils.modified()
Utils.destroy_passed_object(obj)

View File

@ -1675,11 +1675,9 @@ class GedcomParser:
self.db.removePerson(person.getId())
person.setId(new_key)
self.db.addPersonAs(person)
# person currently using it was just added, change it
elif self.added.has_key(tp.getId()):
self.db.removePerson(person.getId())
person.setId(new_key)
self.db.addPersonAs(person)
# give up trying to use the refn as a key
else:
pass
self.db.pmapIndex = new_pmax