* src/DataViews/GrampletView.py: minor change

* src/plugins/DefaultGramplets.py: new RelativesGramplet
	  Response to issue #1758

2008-02-13 Benny Malengier <benny.malengier@gramps-project.org>


svn: r10027
This commit is contained in:
Benny Malengier 2008-02-13 19:52:40 +00:00
parent 74338d8a87
commit b7e7f90096
3 changed files with 112 additions and 3 deletions

View File

@ -1,3 +1,8 @@
2008-02-13 Benny Malengier <benny.malengier@gramps-project.org>
* src/DataViews/GrampletView.py: minor change
* src/plugins/DefaultGramplets.py: new RelativesGramplet
Response to issue #1758
2008-02-13 Benny Malengier <benny.malengier@gramps-project.org>
* src/plugins/WritePkg.py: add callback=None, issue #1398

View File

@ -343,7 +343,6 @@ class Gramplet(object):
return False # handle event further, if necessary
def on_button_press(self, view, event):
from Editors import EditPerson
buffer_location = view.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT,
int(event.x),
int(event.y))
@ -356,13 +355,14 @@ class Gramplet(object):
if event.button == 1: # left mouse
if event.type == gtk.gdk._2BUTTON_PRESS: # double
try:
from Editors import EditPerson
EditPerson(self.gui.dbstate,
self.gui.uistate,
[], person)
return True # handled event
except Errors.WindowActiveError:
pass
else: # single click
elif event.type == gtk.gdk.BUTTON_PRESS: # single click
self.gui.dbstate.change_active_person(person)
return True # handled event
elif link_type == 'Surname':

View File

@ -344,7 +344,104 @@ class SurnameCloudGramplet(Gramplet):
self.append_text(("\n" + _("Total unique surnames") + ": %d\n") %
total_surnames)
self.append_text((_("Total people") + ": %d") % total_people, "begin")
class RelativesGramplet(Gramplet):
"""
This gramplet gives a list of clickable relatives of the active person.
Clicking them, changes the active person.
"""
def init(self):
self.set_text(_("No Family Tree loaded."))
self.tooltip = _("Click name to make person active")
def db_changed(self):
"""
If person or family changes, the relatives of active person might have
changed
"""
self.dbstate.db.connect('person-add', self.update)
self.dbstate.db.connect('person-delete', self.update)
self.dbstate.db.connect('family-add', self.update)
self.dbstate.db.connect('family-delete', self.update)
def active_changed(self, handle):
self.update()
def main(self): # return false finishes
"""
Generator which will be run in the background.
"""
self.set_text("")
database = self.dbstate.db
active_person = self.dbstate.get_active_person()
if not active_person:
return
name = name_displayer.display(active_person)
self.append_text(_("Active person: %s") % name)
self.append_text("\n\n")
#obtain families
famc = 0
for family_handle in active_person.get_family_handle_list():
famc += 1
family = database.get_family_from_handle(family_handle)
if active_person.handle == family.get_father_handle():
spouse_handle = family.get_mother_handle()
else:
spouse_handle = family.get_father_handle()
if spouse_handle:
spouse = database.get_person_from_handle(spouse_handle)
spousename = name_displayer.display(spouse)
text = "%s" % spousename
self.append_text(_("%d. Partner: ") % (famc))
self.link(text, 'Person', spouse_handle)
self.append_text("\n")
else:
self.append_text(_("%d. Partner: Not known") % (famc))
self.append_text("\n")
#obtain children
childc = 0
for child_ref in family.get_child_ref_list():
childc += 1
child = database.get_person_from_handle(child_ref.ref)
childname = name_displayer.display(child)
text = "%s" % childname
self.append_text(" %d.%-3d: " % (famc, childc))
self.link(text, 'Person', child_ref.ref)
self.append_text("\n")
yield True
#obtain parent families
self.append_text("\n")
self.append_text("Parents:")
self.append_text("\n")
famc = 0
for family_handle in active_person.get_parent_family_handle_list():
famc += 1
family = database.get_family_from_handle(family_handle)
mother_handle = family.get_mother_handle()
father_handle = family.get_father_handle()
if mother_handle:
mother = database.get_person_from_handle(mother_handle)
mothername = name_displayer.display(mother)
text = "%s" % mothername
self.append_text(_(" %d.a Mother: ") % (famc))
self.link(text, 'Person', mother_handle)
self.append_text("\n")
else:
self.append_text(_(" %d.a Mother: ") % (famc))
self.append_text(_("Unknown"))
self.append_text("\n")
if father_handle:
father = database.get_person_from_handle(father_handle)
fathername = name_displayer.display(father)
text = "%s" % fathername
self.append_text(_(" %d.b Father: ") % (famc))
self.link(text, 'Person', father_handle)
self.append_text("\n")
else:
self.append_text(_(" %d.b Father: ") % (famc))
self.append_text(_("Unknown"))
self.append_text("\n")
class StatsGramplet(Gramplet):
def init(self):
self.set_text(_("No Family Tree loaded."))
@ -778,3 +875,10 @@ register(type="gramplet",
title=_("Age on Date"),
)
register(type="gramplet",
name="Relatives Gramplet",
tname=_("Relatives Gramplet"),
height=200,
content = RelativesGramplet,
title=_("Active Person's Relatives"),
)