Enhance the Locations gramplet

Create a new "Encloses" gramplet to the display places that the
active place encloses. Rename existing gramplet to "Enclosed By".
This commit is contained in:
Nick Hall 2016-02-08 19:27:46 +00:00
parent 202e1f5594
commit 524413f7c3
3 changed files with 119 additions and 42 deletions

View File

@ -1262,15 +1262,29 @@ register(GRAMPLET,
) )
register(GRAMPLET, register(GRAMPLET,
id="Place Locations", id="Place Enclosed By",
name=_("Place Locations"), name=_("Place Enclosed By"),
description = _("Gramplet showing the locations of a place over time"), description = _("Gramplet showing the places enclosed by the active place"),
version="1.0.0", version="1.0.0",
gramps_target_version=MODULE_VERSION, gramps_target_version=MODULE_VERSION,
status = STABLE, status = STABLE,
fname="locations.py", fname="locations.py",
height=200, height=200,
gramplet = 'Locations', gramplet = 'EnclosedBy',
gramplet_title=_("Locations"), gramplet_title=_("Enclosed By"),
navtypes=["Place"],
)
register(GRAMPLET,
id="Place Encloses",
name=_("Place Encloses"),
description = _("Gramplet showing the places that the active place encloses"),
version="1.0.0",
gramps_target_version=MODULE_VERSION,
status = STABLE,
fname="locations.py",
height=200,
gramplet = 'Encloses',
gramplet_title=_("Encloses"),
navtypes=["Place"], navtypes=["Place"],
) )

View File

@ -1,6 +1,6 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2014 Nick Hall # Copyright (C) 2014-2016 Nick Hall
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -44,14 +44,14 @@ _ = glocale.translation.gettext
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class Locations(Gramplet, DbGUIElement): class Locations(Gramplet, DbGUIElement):
def __init__(self, gui, nav_group=0):
Gramplet.__init__(self, gui, nav_group)
DbGUIElement.__init__(self, self.dbstate.db)
""" """
Gramplet showing the locations of a place over time. Gramplet showing the locations of a place over time.
""" """
def __init__(self, gui, nav_group=0):
Gramplet.__init__(self, gui, nav_group)
DbGUIElement.__init__(self, self.dbstate.db)
self.db = self.dbstate.db
def init(self): def init(self):
self.gui.WIDGET = self.build_gui() self.gui.WIDGET = self.build_gui()
self.gui.get_container_widget().remove(self.gui.textview) self.gui.get_container_widget().remove(self.gui.textview)
@ -96,17 +96,23 @@ class Locations(Gramplet, DbGUIElement):
def update_has_data(self): def update_has_data(self):
active_handle = self.get_active('Place') active_handle = self.get_active('Place')
if active_handle: if active_handle:
active = self.dbstate.db.get_place_from_handle(active_handle) active = self.db.get_place_from_handle(active_handle)
self.set_has_data(self.get_has_data(active)) self.set_has_data(self.get_has_data(active))
else: else:
self.set_has_data(False) self.set_has_data(False)
def get_has_data(self, place):
"""
Return True if the gramplet has data, else return False.
"""
pass
def main(self): def main(self):
self.model.clear() self.model.clear()
self.callman.unregister_all() self.callman.unregister_all()
active_handle = self.get_active('Place') active_handle = self.get_active('Place')
if active_handle: if active_handle:
active = self.dbstate.db.get_place_from_handle(active_handle) active = self.db.get_place_from_handle(active_handle)
if active: if active:
self.display_place(active, None, [active_handle]) self.display_place(active, None, [active_handle])
else: else:
@ -114,6 +120,50 @@ class Locations(Gramplet, DbGUIElement):
else: else:
self.set_has_data(False) self.set_has_data(False)
def display_place(self, place, node, visited):
"""
Display the location hierarchy for the active place.
"""
pass
def add_place(self, placeref, place, node, visited):
"""
Add a place to the model.
"""
place_date = get_date(placeref)
place_sort = '%012d' % placeref.get_date_object().get_sort_value()
place_name = place.get_name().get_value()
place_type = str(place.get_type())
new_node = self.model.add([place.handle,
place_name,
place_type,
place_date,
place_sort],
node=node)
self.display_place(place, new_node, visited + [place.handle])
def edit_place(self, treeview):
"""
Edit the selected place.
"""
model, iter_ = treeview.get_selection().get_selected()
if iter_:
handle = model.get_value(iter_, 0)
place = self.db.get_place_from_handle(handle)
try:
EditPlace(self.dbstate, self.uistate, [], place)
except WindowActiveError:
pass
#-------------------------------------------------------------------------
#
# EnclosedBy gramplet
#
#-------------------------------------------------------------------------
class EnclosedBy(Locations):
def display_place(self, place, node, visited): def display_place(self, place, node, visited):
""" """
Display the location hierarchy for the active place. Display the location hierarchy for the active place.
@ -123,22 +173,8 @@ class Locations(Gramplet, DbGUIElement):
if placeref.ref in visited: if placeref.ref in visited:
continue continue
place_date = get_date(placeref) parent_place = self.db.get_place_from_handle(placeref.ref)
place_sort = '%012d' % placeref.get_date_object().get_sort_value() self.add_place(placeref, parent_place, node, visited)
parent_place = self.dbstate.db.get_place_from_handle(placeref.ref)
parent_name = parent_place.get_name().get_value()
parent_type = str(parent_place.get_type())
parent_node = self.model.add([placeref.ref,
parent_name,
parent_type,
place_date,
place_sort],
node=node)
self.display_place(parent_place,
parent_node,
visited + [placeref.ref])
self.set_has_data(self.model.count > 0) self.set_has_data(self.model.count > 0)
self.model.tree.expand_all() self.model.tree.expand_all()
@ -151,18 +187,44 @@ class Locations(Gramplet, DbGUIElement):
return False return False
if len(place.get_placeref_list()) > 0: if len(place.get_placeref_list()) > 0:
return True return True
else: return False
return False
def edit_place(self, treeview): #-------------------------------------------------------------------------
#
# Encloses gramplet
#
#-------------------------------------------------------------------------
class Encloses(Locations):
def display_place(self, place, node, visited):
""" """
Edit the selected place. Display the location hierarchy for the active place.
""" """
model, iter_ = treeview.get_selection().get_selected() self.callman.register_obj(place)
if iter_: for link in self.db.find_backlink_handles(place.handle,
handle = model.get_value(iter_, 0) include_classes=['Place']):
place = self.dbstate.db.get_place_from_handle(handle) if link[1] in visited:
try: continue
EditPlace(self.dbstate, self.uistate, [], place)
except WindowActiveError: child_place = self.db.get_place_from_handle(link[1])
pass placeref = None
for placeref in child_place.get_placeref_list():
if placeref.ref != place.handle:
continue
if placeref:
self.add_place(placeref, child_place, node, visited)
self.set_has_data(self.model.count > 0)
self.model.tree.expand_all()
def get_has_data(self, place):
"""
Return True if the gramplet has data, else return False.
"""
if place is None:
return False
for link in self.db.find_backlink_handles(place.handle,
include_classes=['Place']):
return True
return False

View File

@ -458,7 +458,8 @@ class PlaceBaseView(ListView):
""" """
return (("Place Filter",), return (("Place Filter",),
("Place Details", ("Place Details",
"Place Locations", "Place Enclosed By",
"Place Encloses",
"Place Gallery", "Place Gallery",
"Place Citations", "Place Citations",
"Place Notes", "Place Notes",