Fix handle errors in gramplets

This commit is contained in:
Nick Hall 2015-12-15 13:55:33 +00:00
parent 621bf1e1e9
commit bde4b1bf10
3 changed files with 24 additions and 17 deletions

View File

@ -73,8 +73,8 @@ class Ancestor(Gramplet):
""" """
if active_handle: if active_handle:
person = self.dbstate.db.get_person_from_handle(active_handle) person = self.dbstate.db.get_person_from_handle(active_handle)
if person:
family_handle = person.get_main_parents_family_handle() family_handle = person.get_main_parents_family_handle()
if family_handle:
family = self.dbstate.db.get_family_from_handle(family_handle) family = self.dbstate.db.get_family_from_handle(family_handle)
if family and (family.get_father_handle() or if family and (family.get_father_handle() or
family.get_mother_handle()): family.get_mother_handle()):

View File

@ -20,6 +20,7 @@
from gramps.gui.editors import EditPerson from gramps.gui.editors import EditPerson
from gramps.gui.listmodel import ListModel, NOSORT from gramps.gui.listmodel import ListModel, NOSORT
from gramps.gen.plug import Gramplet from gramps.gen.plug import Gramplet
from gramps.gen.plug.report.utils import find_spouse
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
from gramps.gen.display.name import displayer as name_displayer from gramps.gen.display.name import displayer as name_displayer
@ -128,19 +129,18 @@ class PersonChildren(Children):
active_person = self.dbstate.db.get_person_from_handle(active_handle) active_person = self.dbstate.db.get_person_from_handle(active_handle)
for family_handle in active_person.get_family_handle_list(): for family_handle in active_person.get_family_handle_list():
family = self.dbstate.db.get_family_from_handle(family_handle) family = self.dbstate.db.get_family_from_handle(family_handle)
self.display_family(family, active_handle) self.display_family(family, active_person)
self.set_has_data(self.model.count > 0) self.set_has_data(self.model.count > 0)
def display_family(self, family, active_handle): def display_family(self, family, active_person):
""" """
Display the children of given family. Display the children of given family.
""" """
father_handle = family.get_father_handle() spouse_handle = find_spouse(active_person, family)
mother_handle = family.get_mother_handle() if spouse_handle:
if father_handle == active_handle: spouse = self.dbstate.db.get_person_from_handle(spouse_handle)
spouse = self.dbstate.db.get_person_from_handle(mother_handle)
else: else:
spouse = self.dbstate.db.get_person_from_handle(father_handle) spouse = None
for child_ref in family.get_child_ref_list(): for child_ref in family.get_child_ref_list():
child = self.dbstate.db.get_person_from_handle(child_ref.ref) child = self.dbstate.db.get_person_from_handle(child_ref.ref)

View File

@ -21,6 +21,7 @@ from gramps.gui.editors import EditEvent
from gramps.gen.lib import EventRoleType from gramps.gen.lib import EventRoleType
from gramps.gui.listmodel import ListModel, NOSORT from gramps.gui.listmodel import ListModel, NOSORT
from gramps.gen.plug import Gramplet from gramps.gen.plug import Gramplet
from gramps.gen.plug.report.utils import find_spouse
from gramps.gui.dbguielement import DbGUIElement from gramps.gui.dbguielement import DbGUIElement
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
@ -199,15 +200,21 @@ class PersonEvents(Events):
self.add_event_ref(event_ref) self.add_event_ref(event_ref)
for family_handle in active_person.get_family_handle_list(): for family_handle in active_person.get_family_handle_list():
family = self.dbstate.db.get_family_from_handle(family_handle) family = self.dbstate.db.get_family_from_handle(family_handle)
father_handle = family.get_father_handle() self.display_family(family, active_person)
mother_handle = family.get_mother_handle() self.set_has_data(self.model.count > 0)
if father_handle == active_handle:
spouse = self.dbstate.db.get_person_from_handle(mother_handle) def display_family(self, family, active_person):
"""
Display the events for the given family.
"""
spouse_handle = find_spouse(active_person, family)
if spouse_handle:
spouse = self.dbstate.db.get_person_from_handle(spouse_handle)
else: else:
spouse = self.dbstate.db.get_person_from_handle(father_handle) spouse = None
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
self.add_event_ref(event_ref, spouse) self.add_event_ref(event_ref, spouse)
self.set_has_data(self.model.count > 0)
def get_start_date(self): def get_start_date(self):
""" """