1
# Copyright (C) 2011 by Guillaume Hain (zedtux) <zedtux@zedroot.org>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
from bzrlib.plugins.gtk import _i18n
20
from bzrlib.config import parse_username
22
class Avatar(gtk.Box):
23
""" Author or committer avatar """
25
def __init__(self, apparent_username):
27
gtk.Box.__init__(self)
29
self.apparent_username = apparent_username
30
self.username, self.email = parse_username(apparent_username)
33
def __eq__(self, other):
35
Return True if attributes of the given avatar
36
match to current object attributes otherwise return False
38
return self.apparent_username == other.apparent_username and \
39
self.name == other.name and \
40
self.email == other.email
42
# ~~~~~ Public methods ~~~~~
43
def show_spinner(self):
45
Replace the current content of the Avatar with a gtk.Spinner
46
if an email address has been parsed. If not, show an gtk.Label with
47
the translatable 'No email' text.
49
if not self.email is "":
50
spinner = gtk.Spinner()
52
self.pack_start(spinner, False)
53
spinner.set_tooltip_text(_i18n("Retrieving avatar for %s...") % self.email)
54
spinner.set_size_request(20, 20)
57
no_email = gtk.Label(_i18n("No email"))
58
self.pack_start(no_email)
59
self.set_tooltip_text(self.apparent_username)
63
""" Replace the current content of the Avatar with the gtk.Image """
64
if not self.email is "" and self.image:
65
self.remove(self.get_children()[0])
66
self.pack_start(self.image)
67
self.image.set_tooltip_text(self.apparent_username)