2011-02-25 22:03:41 +00:00
|
|
|
# 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 gen.plug import Gramplet
|
2011-04-28 22:06:44 +00:00
|
|
|
from gui.widgets import Photo
|
2011-02-25 22:03:41 +00:00
|
|
|
from gen.ggettext import gettext as _
|
|
|
|
from PlaceUtils import conv_lat_lon
|
|
|
|
import Utils
|
|
|
|
import gtk
|
|
|
|
import pango
|
|
|
|
|
|
|
|
class PlaceDetails(Gramplet):
|
|
|
|
"""
|
|
|
|
Displays details for a place.
|
|
|
|
"""
|
|
|
|
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)
|
|
|
|
|
|
|
|
def build_gui(self):
|
|
|
|
"""
|
|
|
|
Build the GUI interface.
|
|
|
|
"""
|
|
|
|
self.top = gtk.HBox()
|
|
|
|
vbox = gtk.VBox()
|
2011-05-03 21:33:19 +00:00
|
|
|
self.photo = Photo()
|
2011-02-25 22:03:41 +00:00
|
|
|
self.title = gtk.Label()
|
|
|
|
self.title.set_alignment(0, 0)
|
|
|
|
self.title.modify_font(pango.FontDescription('sans bold 12'))
|
|
|
|
vbox.pack_start(self.title, fill=True, expand=False, padding=7)
|
2011-04-28 22:06:44 +00:00
|
|
|
self.table = gtk.Table(1, 2)
|
|
|
|
vbox.pack_start(self.table, fill=True, expand=False)
|
2011-02-25 22:03:41 +00:00
|
|
|
self.top.pack_start(self.photo, fill=True, expand=False, padding=5)
|
|
|
|
self.top.pack_start(vbox, fill=True, expand=False, padding=10)
|
|
|
|
self.top.show_all()
|
|
|
|
return self.top
|
|
|
|
|
2011-04-28 22:06:44 +00:00
|
|
|
def add_row(self, title, value):
|
2011-02-25 22:03:41 +00:00
|
|
|
"""
|
2011-04-28 22:06:44 +00:00
|
|
|
Add a row to the table.
|
2011-02-25 22:03:41 +00:00
|
|
|
"""
|
|
|
|
label = gtk.Label(title + ':')
|
|
|
|
label.set_alignment(1, 0)
|
2011-04-28 22:06:44 +00:00
|
|
|
label.show()
|
|
|
|
value = gtk.Label(value)
|
|
|
|
value.set_alignment(0, 0)
|
|
|
|
value.show()
|
|
|
|
rows = self.table.get_property('n-rows')
|
|
|
|
rows += 1
|
|
|
|
self.table.resize(rows, 2)
|
|
|
|
self.table.attach(label, 0, 1, rows, rows + 1, xoptions=gtk.FILL,
|
|
|
|
xpadding=10)
|
|
|
|
self.table.attach(value, 1, 2, rows, rows + 1)
|
|
|
|
|
|
|
|
def clear_table(self):
|
|
|
|
"""
|
|
|
|
Remove all the rows from the table.
|
|
|
|
"""
|
|
|
|
map(self.table.remove, self.table.get_children())
|
|
|
|
self.table.resize(1, 2)
|
2011-02-25 22:03:41 +00:00
|
|
|
|
|
|
|
def db_changed(self):
|
|
|
|
self.dbstate.db.connect('place-update', self.update)
|
|
|
|
self.connect_signal('Place', self.update)
|
|
|
|
self.update()
|
|
|
|
|
2011-04-05 18:24:44 +00:00
|
|
|
def update_has_data(self):
|
|
|
|
active_handle = self.get_active('Person')
|
|
|
|
active_person = self.dbstate.db.get_person_from_handle(active_handle)
|
|
|
|
self.set_has_data(active_person is not None)
|
|
|
|
|
2011-02-25 22:03:41 +00:00
|
|
|
def main(self):
|
|
|
|
active_handle = self.get_active('Place')
|
|
|
|
place = self.dbstate.db.get_place_from_handle(active_handle)
|
|
|
|
self.top.hide()
|
|
|
|
if place:
|
|
|
|
self.display_place(place)
|
2011-04-05 18:24:44 +00:00
|
|
|
self.set_has_data(True)
|
2011-02-25 22:03:41 +00:00
|
|
|
else:
|
|
|
|
self.display_empty()
|
2011-04-05 18:24:44 +00:00
|
|
|
self.set_has_data(False)
|
2011-02-25 22:03:41 +00:00
|
|
|
self.top.show()
|
|
|
|
|
|
|
|
def display_place(self, place):
|
|
|
|
"""
|
|
|
|
Display details of the active place.
|
|
|
|
"""
|
|
|
|
self.load_place_image(place)
|
|
|
|
self.title.set_text(place.get_title())
|
2011-04-28 22:06:44 +00:00
|
|
|
|
|
|
|
self.clear_table()
|
|
|
|
self.display_location(place.get_main_location())
|
|
|
|
self.display_separator()
|
2011-02-25 22:03:41 +00:00
|
|
|
lat, lon = conv_lat_lon(place.get_latitude(),
|
|
|
|
place.get_longitude(),
|
|
|
|
format='DEG')
|
|
|
|
if lat:
|
2011-04-28 22:06:44 +00:00
|
|
|
self.add_row(_('Latitude'), lat)
|
2011-02-25 22:03:41 +00:00
|
|
|
if lon:
|
2011-04-28 22:06:44 +00:00
|
|
|
self.add_row(_('Longitude'), lat)
|
|
|
|
|
|
|
|
def display_location(self, location):
|
|
|
|
"""
|
|
|
|
Display a location.
|
|
|
|
"""
|
|
|
|
lines = [line for line in location.get_text_data_list()[:-1] if line]
|
|
|
|
self.add_row(_('Location'), '\n'.join(lines))
|
2011-02-25 22:03:41 +00:00
|
|
|
|
|
|
|
def display_empty(self):
|
|
|
|
"""
|
|
|
|
Display empty details when no repository is selected.
|
|
|
|
"""
|
|
|
|
self.photo.set_image(None)
|
|
|
|
self.title.set_text('')
|
2011-04-28 22:06:44 +00:00
|
|
|
self.clear_table()
|
|
|
|
|
|
|
|
def display_separator(self):
|
|
|
|
"""
|
|
|
|
Display an empty row to separate groupd of entries.
|
|
|
|
"""
|
|
|
|
label = gtk.Label('')
|
|
|
|
label.modify_font(pango.FontDescription('sans 4'))
|
|
|
|
label.show()
|
|
|
|
rows = self.table.get_property('n-rows')
|
|
|
|
rows += 1
|
|
|
|
self.table.resize(rows, 2)
|
|
|
|
self.table.attach(label, 0, 1, rows, rows + 1, xoptions=gtk.FILL)
|
2011-02-25 22:03:41 +00:00
|
|
|
|
|
|
|
def load_place_image(self, place):
|
|
|
|
"""
|
|
|
|
Load the primary image if it exists.
|
|
|
|
"""
|
|
|
|
media_list = place.get_media_list()
|
|
|
|
if media_list:
|
|
|
|
media_ref = media_list[0]
|
|
|
|
object_handle = media_ref.get_reference_handle()
|
|
|
|
obj = self.dbstate.db.get_object_from_handle(object_handle)
|
|
|
|
full_path = Utils.media_path_full(self.dbstate.db, obj.get_path())
|
|
|
|
mime_type = obj.get_mime_type()
|
|
|
|
if mime_type and mime_type.startswith("image"):
|
2011-05-03 21:33:19 +00:00
|
|
|
self.photo.set_image(full_path, mime_type,
|
|
|
|
media_ref.get_rectangle())
|
2011-02-25 22:03:41 +00:00
|
|
|
else:
|
|
|
|
self.photo.set_image(None)
|
|
|
|
else:
|
|
|
|
self.photo.set_image(None)
|