~ubuntu-branches/ubuntu/trusty/gramps/trusty-proposed

« back to all changes in this revision

Viewing changes to src/plugins/gramplet/RepositoryDetails.py

  • Committer: Package Import Robot
  • Author(s): Ross Gammon
  • Date: 2014-02-03 17:28:04 UTC
  • mfrom: (39.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140203172804-76y7nwxiw92zhlnj
Tags: 4.0.3+dfsg-1
* New upstream release (Closes: #720858)
* To-do notes improved and made persistent (Closes: #680692)
* Applied patch to setup.py to fix resource path problem
* Applied patch to disable the optional HTML View & prevent a crash
* Remove sourceless javascript files (Closes: #736436)
* Gramps uses Bat Mitzva internally (Closes: #502532)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Gramps - a GTK+/GNOME based genealogy program
2
 
#
3
 
# Copyright (C) 2011 Nick Hall
4
 
#
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.
9
 
#
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.
14
 
#
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
18
 
#
19
 
# $Id: RepositoryDetails.py 18679 2012-01-01 17:58:33Z nick-h $
20
 
#
21
 
 
22
 
from gen.lib import UrlType
23
 
from gen.plug import Gramplet
24
 
from gen.ggettext import gettext as _
25
 
import gtk
26
 
import pango
27
 
 
28
 
class RepositoryDetails(Gramplet):
29
 
    """
30
 
    Displays details for a repository.
31
 
    """
32
 
    def init(self):
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)
36
 
 
37
 
    def build_gui(self):
38
 
        """
39
 
        Build the GUI interface.
40
 
        """
41
 
        self.top = gtk.HBox()
42
 
        vbox = gtk.VBox()
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)
50
 
        self.top.show_all()
51
 
        return self.top
52
 
 
53
 
    def add_row(self, title, value):
54
 
        """
55
 
        Add a row to the table.
56
 
        """
57
 
        label = gtk.Label(title + ':')
58
 
        label.set_alignment(1, 0)
59
 
        label.show()
60
 
        value = gtk.Label(value)
61
 
        value.set_alignment(0, 0)
62
 
        value.show()
63
 
        rows = self.table.get_property('n-rows')
64
 
        rows += 1
65
 
        self.table.resize(rows, 2)
66
 
        self.table.attach(label, 0, 1, rows, rows + 1, xoptions=gtk.FILL,
67
 
                                                       xpadding=10)
68
 
        self.table.attach(value, 1, 2, rows, rows + 1)
69
 
        
70
 
    def clear_table(self):
71
 
        """
72
 
        Remove all the rows from the table.
73
 
        """
74
 
        map(self.table.remove, self.table.get_children())
75
 
        self.table.resize(1, 2)
76
 
 
77
 
    def db_changed(self):
78
 
        self.dbstate.db.connect('repository-update', self.update)
79
 
        self.connect_signal('Repository', self.update)
80
 
 
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)
85
 
 
86
 
    def main(self):
87
 
        active_handle = self.get_active('Repository')
88
 
        repo = self.dbstate.db.get_repository_from_handle(active_handle)
89
 
        self.top.hide()
90
 
        if repo:
91
 
            self.display_repo(repo)
92
 
            self.set_has_data(True)
93
 
        else:
94
 
            self.display_empty()
95
 
            self.set_has_data(False)
96
 
        self.top.show()
97
 
 
98
 
    def display_repo(self, repo):
99
 
        """
100
 
        Display details of the active repository.
101
 
        """
102
 
        self.name.set_text(repo.get_name())
103
 
 
104
 
        self.clear_table()
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()
110
 
            if phone:
111
 
                self.add_row(_('Phone'), phone)
112
 
 
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))
117
 
 
118
 
    def display_address(self, address):
119
 
        """
120
 
        Display an address.
121
 
        """
122
 
        lines = [line for line in address.get_text_data_list()[:-1] if line]
123
 
        self.add_row(_('Address'), '\n'.join(lines))
124
 
 
125
 
    def display_url(self, repo, url_type):
126
 
        """
127
 
        Display an url of the given url type.
128
 
        """
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())
132
 
 
133
 
    def display_empty(self):
134
 
        """
135
 
        Display empty details when no repository is selected.
136
 
        """
137
 
        self.name.set_text('')
138
 
        self.clear_table()
139
 
 
140
 
    def display_separator(self):
141
 
        """
142
 
        Display an empty row to separate groupd of entries.
143
 
        """
144
 
        label = gtk.Label('')
145
 
        label.modify_font(pango.FontDescription('sans 4'))
146
 
        label.show()
147
 
        rows = self.table.get_property('n-rows')
148
 
        rows += 1
149
 
        self.table.resize(rows, 2)
150
 
        self.table.attach(label, 0, 1, rows, rows + 1, xoptions=gtk.FILL)