Add children bottombar gramplets
svn: r16621
This commit is contained in:
parent
84a1c79fc2
commit
dc505e7671
@ -258,6 +258,7 @@ src/plugins/gramplet/Attributes.py
|
||||
src/plugins/gramplet/AttributesGramplet.py
|
||||
src/plugins/gramplet/bottombar.gpr.py
|
||||
src/plugins/gramplet/CalendarGramplet.py
|
||||
src/plugins/gramplet/Children.py
|
||||
src/plugins/gramplet/DescendGramplet.py
|
||||
src/plugins/gramplet/FanChartGramplet.py
|
||||
src/plugins/gramplet/FaqGramplet.py
|
||||
|
@ -65,7 +65,6 @@ from gui.widgets.grampletpane import (AVAILABLE_GRAMPLETS,
|
||||
make_requested_gramplet,
|
||||
GuiGramplet)
|
||||
from gui.widgets.undoablebuffer import UndoableBuffer
|
||||
from ListModel import ListModel, NOSORT
|
||||
from gui.utils import add_menuitem
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
202
src/plugins/gramplet/Children.py
Normal file
202
src/plugins/gramplet/Children.py
Normal file
@ -0,0 +1,202 @@
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2011 Nick Hall
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
from gui.editors import EditPerson
|
||||
from ListModel import ListModel, NOSORT
|
||||
from gen.plug import Gramplet
|
||||
from gen.ggettext import gettext as _
|
||||
from gen.display.name import displayer as name_displayer
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
import DateHandler
|
||||
import Errors
|
||||
import gtk
|
||||
|
||||
class Children(Gramplet):
|
||||
"""
|
||||
Displays the children of a person or family.
|
||||
"""
|
||||
def init(self):
|
||||
self.gui.WIDGET = self.build_gui()
|
||||
self.gui.get_container_widget().remove(self.gui.textview)
|
||||
self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET)
|
||||
self.gui.WIDGET.show()
|
||||
self.uistate.connect('nameformat-changed', self.update)
|
||||
|
||||
def get_date_place(self, event):
|
||||
"""
|
||||
Return the date and place of the given event.
|
||||
"""
|
||||
event_date = ''
|
||||
event_place = ''
|
||||
event_sort = '%012d' % 0
|
||||
if event:
|
||||
event_date = DateHandler.get_date(event)
|
||||
event_sort = '%012d' % event.get_date_object().get_sort_value()
|
||||
handle = event.get_place_handle()
|
||||
if handle:
|
||||
place = self.dbstate.db.get_place_from_handle(handle)
|
||||
event_place = place.get_title()
|
||||
return (event_date, event_sort, event_place)
|
||||
|
||||
def edit_person(self, treeview):
|
||||
"""
|
||||
Edit the selected child.
|
||||
"""
|
||||
model, iter_ = treeview.get_selection().get_selected()
|
||||
if iter_:
|
||||
handle = model.get_value(iter_, 0)
|
||||
try:
|
||||
person = self.dbstate.db.get_person_from_handle(handle)
|
||||
EditPerson(self.dbstate, self.uistate, [], person)
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
|
||||
class PersonChildren(Children):
|
||||
"""
|
||||
Displays the children of a person.
|
||||
"""
|
||||
def build_gui(self):
|
||||
"""
|
||||
Build the GUI interface.
|
||||
"""
|
||||
tip = _('Double-click on a row to edit the selected child.')
|
||||
self.set_tooltip(tip)
|
||||
top = gtk.TreeView()
|
||||
titles = [('', NOSORT, 50,),
|
||||
(_('Child'), 1, 250),
|
||||
(_('Birth Date'), 3, 100),
|
||||
(_(''), 3, 100),
|
||||
(_('Death Date'), 5, 100),
|
||||
(_(''), 5, 100),
|
||||
(_('Spouse'), 6, 250)]
|
||||
self.model = ListModel(top, titles, event_func=self.edit_person)
|
||||
return top
|
||||
|
||||
def db_changed(self):
|
||||
self.dbstate.db.connect('person-update', self.update)
|
||||
self.update()
|
||||
|
||||
def active_changed(self, handle):
|
||||
self.update()
|
||||
|
||||
def main(self):
|
||||
active_handle = self.get_active('Person')
|
||||
self.model.clear()
|
||||
if active_handle:
|
||||
self.display_person(active_handle)
|
||||
|
||||
def display_person(self, active_handle):
|
||||
"""
|
||||
Display the children of the active person.
|
||||
"""
|
||||
active_person = self.dbstate.db.get_person_from_handle(active_handle)
|
||||
for family_handle in active_person.get_family_handle_list():
|
||||
family = self.dbstate.db.get_family_from_handle(handle)
|
||||
self.display_family(family, active_handle)
|
||||
|
||||
def display_family(self, family, active_handle):
|
||||
"""
|
||||
Display the children of given family.
|
||||
"""
|
||||
father_handle = family.get_father_handle()
|
||||
mother_handle = family.get_mother_handle()
|
||||
if father_handle == active_handle:
|
||||
spouse = self.dbstate.db.get_person_from_handle(mother_handle)
|
||||
else:
|
||||
spouse = self.dbstate.db.get_person_from_handle(father_handle)
|
||||
|
||||
for child_ref in family.get_child_ref_list():
|
||||
child = self.dbstate.db.get_person_from_handle(child_ref.ref)
|
||||
self.add_child(child, spouse)
|
||||
|
||||
def add_child(self, child, spouse):
|
||||
"""
|
||||
Add a child to the model.
|
||||
"""
|
||||
name = name_displayer.display(child)
|
||||
spouse = name_displayer.display(spouse)
|
||||
birth = get_birth_or_fallback(self.dbstate.db, child)
|
||||
birth_date, birth_sort, birth_place = self.get_date_place(birth)
|
||||
death = get_death_or_fallback(self.dbstate.db, child)
|
||||
death_date, death_sort, death_place = self.get_date_place(death)
|
||||
self.model.add((child.get_handle(),
|
||||
name,
|
||||
birth_date,
|
||||
birth_sort,
|
||||
death_date,
|
||||
death_sort,
|
||||
spouse))
|
||||
|
||||
class FamilyChildren(Children):
|
||||
"""
|
||||
Displays the children of a family.
|
||||
"""
|
||||
def build_gui(self):
|
||||
"""
|
||||
Build the GUI interface.
|
||||
"""
|
||||
tip = _('Double-click on a row to edit the selected child.')
|
||||
self.set_tooltip(tip)
|
||||
top = gtk.TreeView()
|
||||
titles = [('', NOSORT, 50,),
|
||||
(_('Child'), 1, 250),
|
||||
(_('Birth Date'), 3, 100),
|
||||
(_(''), 3, 100),
|
||||
(_('Death Date'), 5, 100),
|
||||
(_(''), 5, 100)]
|
||||
self.model = ListModel(top, titles, event_func=self.edit_person)
|
||||
return top
|
||||
|
||||
def db_changed(self):
|
||||
self.dbstate.db.connect('family-update', self.update)
|
||||
self.connect_signal('Family', self.update)
|
||||
self.update()
|
||||
|
||||
def main(self):
|
||||
active_handle = self.get_active('Family')
|
||||
self.model.clear()
|
||||
if active_handle:
|
||||
family = self.dbstate.db.get_family_from_handle(active_handle)
|
||||
self.display_family(family)
|
||||
|
||||
def display_family(self, family):
|
||||
"""
|
||||
Display the children of given family.
|
||||
"""
|
||||
for child_ref in family.get_child_ref_list():
|
||||
child = self.dbstate.db.get_person_from_handle(child_ref.ref)
|
||||
self.add_child(child)
|
||||
|
||||
def add_child(self, child):
|
||||
"""
|
||||
Add a child to the model.
|
||||
"""
|
||||
name = name_displayer.display(child)
|
||||
birth = get_birth_or_fallback(self.dbstate.db, child)
|
||||
birth_date, birth_sort, birth_place = self.get_date_place(birth)
|
||||
death = get_death_or_fallback(self.dbstate.db, child)
|
||||
death_date, death_sort, death_place = self.get_date_place(death)
|
||||
self.model.add((child.get_handle(),
|
||||
name,
|
||||
birth_date,
|
||||
birth_sort,
|
||||
death_date,
|
||||
death_sort))
|
@ -12,6 +12,7 @@ pkgdata_PYTHON = \
|
||||
AttributesGramplet.py \
|
||||
bottombar.gpr.py \
|
||||
CalendarGramplet.py \
|
||||
Children.py \
|
||||
DescendGramplet.py \
|
||||
FanChartGramplet.py \
|
||||
FaqGramplet.py \
|
||||
|
@ -108,9 +108,6 @@ class EventSources(Sources):
|
||||
self.connect_signal('Event', self.update)
|
||||
self.update()
|
||||
|
||||
def active_changed(self, handle):
|
||||
self.update()
|
||||
|
||||
def main(self):
|
||||
active_handle = self.get_active('Event')
|
||||
active = self.dbstate.db.get_event_from_handle(active_handle)
|
||||
@ -128,9 +125,6 @@ class FamilySources(Sources):
|
||||
self.connect_signal('Family', self.update)
|
||||
self.update()
|
||||
|
||||
def active_changed(self, handle):
|
||||
self.update()
|
||||
|
||||
def main(self):
|
||||
active_handle = self.get_active('Family')
|
||||
active = self.dbstate.db.get_family_from_handle(active_handle)
|
||||
@ -148,9 +142,6 @@ class PlaceSources(Sources):
|
||||
self.connect_signal('Place', self.update)
|
||||
self.update()
|
||||
|
||||
def active_changed(self, handle):
|
||||
self.update()
|
||||
|
||||
def main(self):
|
||||
active_handle = self.get_active('Place')
|
||||
active = self.dbstate.db.get_place_from_handle(active_handle)
|
||||
@ -168,9 +159,6 @@ class MediaSources(Sources):
|
||||
self.connect_signal('Media', self.update)
|
||||
self.update()
|
||||
|
||||
def active_changed(self, handle):
|
||||
self.update()
|
||||
|
||||
def main(self):
|
||||
active_handle = self.get_active('Media')
|
||||
active = self.dbstate.db.get_object_from_handle(active_handle)
|
||||
|
@ -311,6 +311,32 @@ register(GRAMPLET,
|
||||
gramplet_title=_("Sources"),
|
||||
)
|
||||
|
||||
register(GRAMPLET,
|
||||
id="Person Children Gramplet",
|
||||
name=_("Person Children Gramplet"),
|
||||
description = _("Gramplet showing the children of a person"),
|
||||
version="1.0.0",
|
||||
gramps_target_version="3.3",
|
||||
status = STABLE,
|
||||
fname="Children.py",
|
||||
height=200,
|
||||
gramplet = 'PersonChildren',
|
||||
gramplet_title=_("Children"),
|
||||
)
|
||||
|
||||
register(GRAMPLET,
|
||||
id="Family Children Gramplet",
|
||||
name=_("Family Children Gramplet"),
|
||||
description = _("Gramplet showing the children of a family"),
|
||||
version="1.0.0",
|
||||
gramps_target_version="3.3",
|
||||
status = STABLE,
|
||||
fname="Children.py",
|
||||
height=200,
|
||||
gramplet = 'FamilyChildren',
|
||||
gramplet_title=_("Children"),
|
||||
)
|
||||
|
||||
register(GRAMPLET,
|
||||
id="Person Filter Gramplet",
|
||||
name=_("Person Filter Gramplet"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user