diff --git a/ChangeLog b/ChangeLog index 5db0f14e4..a4adb12fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-04-02 Don Allingham + * src/DisplayState.py: shorten match message + * src/GrampsDb/Makefile.am: Added _HelperFunctions.py + * src/GrampsDb/__init__.py: Added _HelperFunctions.py + * src/GrampsDb/_HelperFunctions.py: Added support functions + 2007-04-01 Don Allingham * src/GrampsDb/_GrampsDbBase.py: handle close/delete of active database * src/DbManager.py: clean up diff --git a/src/DisplayState.py b/src/DisplayState.py index 7fae34ad1..915edfd8d 100644 --- a/src/DisplayState.py +++ b/src/DisplayState.py @@ -82,7 +82,7 @@ class History(GrampsDb.GrampsDBCallback): self.index = -1 self.lock = False - def remove(self,person_handle,old_id=None): + def remove(self, person_handle, old_id=None): """Removes a person from the history list""" if old_id: del_id = old_id @@ -100,7 +100,7 @@ class History(GrampsDb.GrampsDBCallback): self.emit('changed',(self.history,)) self.emit('menu-changed',(self.mhistory,)) - def push(self,person_handle): + def push(self, person_handle): self.prune() if len(self.history) == 0 or person_handle != self.history[-1]: self.history.append(person_handle) @@ -111,7 +111,7 @@ class History(GrampsDb.GrampsDBCallback): self.emit('menu-changed',(self.mhistory,)) self.emit('changed',(self.history,)) - def forward(self,step=1): + def forward(self, step=1): self.index += step person_handle = self.history[self.index] if person_handle not in self.mhistory: @@ -119,7 +119,7 @@ class History(GrampsDb.GrampsDBCallback): self.emit('menu-changed',(self.mhistory,)) return str(self.history[self.index]) - def back(self,step=1): + def back(self, step=1): self.index -= step try: person_handle = self.history[self.index] @@ -339,7 +339,7 @@ class DisplayState(GrampsDb.GrampsDBCallback): gobject.timeout_add(5000,self.modify_statusbar,dbstate) def show_filter_results(self, dbstate, matched, total): - text = _("%d/%d matched") % (matched, total) + text = "%d/%d" % (matched, total) self.status.pop(1, self.last_bar) self.status.push(1, text, self.last_bar) diff --git a/src/GrampsDb/Makefile.am b/src/GrampsDb/Makefile.am index 7d9aa7a9a..b209fc75a 100644 --- a/src/GrampsDb/Makefile.am +++ b/src/GrampsDb/Makefile.am @@ -16,6 +16,7 @@ pkgdata_PYTHON = \ _GrampsInMemDB.py\ _GrampsXMLDB.py\ _GrampsDbConst.py\ + _HelperFunctions.py\ __init__.py pkgpyexecdir = @pkgpyexecdir@/GrampsDb diff --git a/src/GrampsDb/_HelperFunctions.py b/src/GrampsDb/_HelperFunctions.py new file mode 100644 index 000000000..6b3c2391a --- /dev/null +++ b/src/GrampsDb/_HelperFunctions.py @@ -0,0 +1,127 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2007 Donald N. Allingham +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +import RelLib + +def children_of_person(db, person): + """ + Returns a list of Person instances which represents children of + the specified person. + """ + families = [ db.get_family_from_handle(h) \ + for h in person.get_family_handle_list() ] + chandles = [] + for family in families: + chandles += [ ref.ref for ref in family.get_child_ref_list() ] + + return [ db.get_person_from_handle(h) for h in chandles ] + +def parents_of_person(db, person): + """ + Returns a list of Person instances which represents the parents of + the specified person. Each element in the list is a tuple consisting + of the (father, mother) + """ + + families = [ db.get_family_from_handle(h) \ + for h in person.get_parent_family_handle_list() ] + + parents = [] + for family in families: + fhandle = family.get_father_handle() + mhandle = family.get_mother_handle() + if fhandle: + father = db.get_person_from_handle(fhandle) + else: + father = None + if mhandle: + mother = db.get_person_from_handle(mhandle) + else: + mother = None + parents.append((father,mother)) + return parents + +def children_of_family(db, family): + """ + Returns a list of Person instances associated with the family. + """ + return [ db.get_person_from_handle(ref.ref) \ + for ref in family.get_child_ref_list() ] + +def parents_of_family(db, family): + """ + Returns a tuple of Person instances representing a father, mother pair. + """ + fhandle = family.get_father_handle() + mhandle = family.get_mother_handle() + if fhandle: + father = db.get_person_from_handle(fhandle) + else: + father = None + if mhandle: + mother = db.get_person_from_handle(mhandle) + else: + mother = None + return (father,mother) + +def primary_parents_of(db, person): + handle = person.get_main_parents_family_handle() + if not handle: + return (None, None) + family = db.get_family_from_handle(handle) + mhandle = family.get_mother_handle() + fhandle = family.get_father_handle() + if mhandle: + mother = db.get_person_from_handle(mhandle) + else: + mother = None + if fhandle: + father = db.get_person_from_handle(fhandle) + else: + father = None + return (father, mother) + +def primary_parent_family_of(db, person): + handle = person.get_main_parents_family_handle() + if not handle: + return db.get_family_from_handle(handle) + else: + return None + +#def events_of_person(db, person): +# pass + +#def events_of_family(db, family): +# pass + +def notes_of(db, obj): + return [ db.get_note_from_handle(h) for h in obj.get_note_handle_list() ] + +def sources_of(db, obj): + return [ db.get_source_from_handle(h) for h in obj.get_source_handle_list() ] + +def sources_of_event(db, event): + pass + +def sources_of_person(db, person): + pass + +def sources_of_note(db, note): + pass diff --git a/src/GrampsDb/__init__.py b/src/GrampsDb/__init__.py index cd4d0230f..9020855df 100644 --- a/src/GrampsDb/__init__.py +++ b/src/GrampsDb/__init__.py @@ -57,4 +57,4 @@ from _GrampsDbWriteXML import GrampsDbXmlWriter, \ from _LongOpStatus import LongOpStatus from _ProgressMonitor import ProgressMonitor - +from _HelperFunctions import *