bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
|
719.2.1
by zedtux
Added committers and authors avatars from Gravatar (urllib2 version) |
1 |
# Copyright (C) 2011 by Guillaume Hain (zedtux) <zedtux@zedroot.org>
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
17 |
import gtk |
|
18 |
||
19 |
from bzrlib.plugins.gtk import _i18n |
|
20 |
from bzrlib.config import parse_username |
|
21 |
||
22 |
class Avatar(gtk.Box): |
|
23 |
""" Author or committer avatar """ |
|
24 |
||
25 |
def __init__(self, username): |
|
26 |
""" Constructor """ |
|
27 |
gtk.Box.__init__(self) |
|
28 |
||
29 |
self.__username = username |
|
30 |
self.__name, self.__email = parse_username(username) |
|
31 |
self.__image = None |
|
32 |
||
33 |
||
34 |
# ~~~~~ Properties ~~~~~
|
|
35 |
# username
|
|
36 |
def get_username(self): |
|
37 |
return self.__username |
|
38 |
def set_username(self, username): |
|
39 |
self.__username = username |
|
40 |
username = property(get_username, set_username) |
|
41 |
||
42 |
# Name
|
|
43 |
def get_name(self): |
|
44 |
return self.__name |
|
45 |
def set_name(self, name): |
|
46 |
self.__name = name |
|
47 |
name = property(get_name, set_name) |
|
48 |
||
49 |
# Email
|
|
50 |
def get_email(self): |
|
51 |
return self.__email |
|
52 |
def set_email(self, email): |
|
53 |
self.__email = email |
|
54 |
email = property(get_email, set_email) |
|
55 |
||
56 |
# Image
|
|
57 |
def get_image(self): |
|
58 |
return self.__image |
|
59 |
def set_image(self, image): |
|
60 |
self.__image = image |
|
61 |
image = property(get_image, set_image) |
|
62 |
||
63 |
||
64 |
# ~~~~~ Public methods ~~~~~
|
|
65 |
def show_spinner(self): |
|
66 |
""" |
|
67 |
Replace the current content of the Avatar with a gtk.Spinner
|
|
68 |
if an email address has been parsed. If not, show an gtk.Label with
|
|
69 |
the translatable 'No email' text.
|
|
70 |
"""
|
|
71 |
if not self.email is "": |
|
72 |
spinner = gtk.Spinner() |
|
73 |
spinner.start() |
|
74 |
self.pack_start(spinner, False) |
|
75 |
spinner.set_tooltip_text(_i18n("Retrieving avatar for %s...") % self.email) |
|
76 |
spinner.set_size_request(20, 20) |
|
77 |
spinner.show() |
|
78 |
else: |
|
79 |
no_email = gtk.Label(_i18n("No email")) |
|
80 |
self.pack_start(no_email) |
|
81 |
self.set_tooltip_text("self.username") |
|
82 |
no_email.show() |
|
83 |
||
84 |
def show_image(self): |
|
85 |
""" Replace the current content of the Avatar with the gtk.Image """ |
|
86 |
if not self.email is "" and self.image: |
|
87 |
self.remove(self.get_children()[0]) |
|
88 |
self.pack_start(self.image) |
|
89 |
self.image.set_tooltip_text(self.username) |
|
90 |
self.image.show() |
|
91 |
||
92 |
def is_identical(self, avatar): |
|
93 |
""" |
|
94 |
Return True if attributes of the given avatar
|
|
95 |
match to current object attributes otherwise return False
|
|
96 |
"""
|
|
97 |
return self.username == avatar.username and \ |
|
98 |
self.name == avatar.name and \ |
|
99 |
self.email == avatar.email |