1
# Gramps - a GTK+/GNOME based genealogy program
3
# Copyright (C) 2011 Nick Hall
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
# $Id: RepositoryDetails.py 18679 2012-01-01 17:58:33Z nick-h $
22
from gen.lib import UrlType
23
from gen.plug import Gramplet
24
from gen.ggettext import gettext as _
28
class RepositoryDetails(Gramplet):
30
Displays details for a repository.
33
self.gui.WIDGET = self.build_gui()
34
self.gui.get_container_widget().remove(self.gui.textview)
35
self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET)
39
Build the GUI interface.
43
self.name = gtk.Label()
44
self.name.set_alignment(0, 0)
45
self.name.modify_font(pango.FontDescription('sans bold 12'))
46
vbox.pack_start(self.name, fill=True, expand=False, padding=7)
47
self.table = gtk.Table(1, 2)
48
vbox.pack_start(self.table, fill=True, expand=False)
49
self.top.pack_start(vbox, fill=True, expand=False, padding=10)
53
def add_row(self, title, value):
55
Add a row to the table.
57
label = gtk.Label(title + ':')
58
label.set_alignment(1, 0)
60
value = gtk.Label(value)
61
value.set_alignment(0, 0)
63
rows = self.table.get_property('n-rows')
65
self.table.resize(rows, 2)
66
self.table.attach(label, 0, 1, rows, rows + 1, xoptions=gtk.FILL,
68
self.table.attach(value, 1, 2, rows, rows + 1)
70
def clear_table(self):
72
Remove all the rows from the table.
74
map(self.table.remove, self.table.get_children())
75
self.table.resize(1, 2)
78
self.dbstate.db.connect('repository-update', self.update)
79
self.connect_signal('Repository', self.update)
81
def update_has_data(self):
82
active_handle = self.get_active('Person')
83
active_person = self.dbstate.db.get_person_from_handle(active_handle)
84
self.set_has_data(active_person is not None)
87
active_handle = self.get_active('Repository')
88
repo = self.dbstate.db.get_repository_from_handle(active_handle)
91
self.display_repo(repo)
92
self.set_has_data(True)
95
self.set_has_data(False)
98
def display_repo(self, repo):
100
Display details of the active repository.
102
self.name.set_text(repo.get_name())
105
address_list = repo.get_address_list()
106
if len(address_list) > 0:
107
self.display_address(address_list[0])
108
self.display_separator()
109
phone = address_list[0].get_phone()
111
self.add_row(_('Phone'), phone)
113
self.display_url(repo, UrlType(UrlType.EMAIL))
114
self.display_url(repo, UrlType(UrlType.WEB_HOME))
115
self.display_url(repo, UrlType(UrlType.WEB_SEARCH))
116
self.display_url(repo, UrlType(UrlType.WEB_FTP))
118
def display_address(self, address):
122
lines = [line for line in address.get_text_data_list()[:-1] if line]
123
self.add_row(_('Address'), '\n'.join(lines))
125
def display_url(self, repo, url_type):
127
Display an url of the given url type.
129
for url in repo.get_url_list():
130
if url.get_type() == url_type:
131
self.add_row(str(url_type), url.get_path())
133
def display_empty(self):
135
Display empty details when no repository is selected.
137
self.name.set_text('')
140
def display_separator(self):
142
Display an empty row to separate groupd of entries.
144
label = gtk.Label('')
145
label.modify_font(pango.FontDescription('sans 4'))
147
rows = self.table.get_property('n-rows')
149
self.table.resize(rows, 2)
150
self.table.attach(label, 0, 1, rows, rows + 1, xoptions=gtk.FILL)