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
21
class AvatarBox(gtk.HBox):
22
""" Improved gtk.HBox """
24
def __init__(self, homogeneous=False, spacing=0):
26
gtk.HBox.__init__(self, homogeneous, spacing)
29
self.__displaying = None
32
# ~~~~~ Public methods ~~~~~
34
""" Remove current avatars from the gtk box """
35
for child in self.get_children():
37
self.__displaying = None
39
def have_avatar(self, avatar):
41
Return True if this box has registered given avatar,
42
otherwise return False
44
return avatar.email in self.__avatars
46
def showing(self, avatar):
48
Return True if the displaying avatar is the same
49
as the given one otherwise return False
51
return self.__displaying and self.__displaying == avatar
53
def append_avatars_with(self, avatar):
55
Append avatars collection with the given one if not already registed
56
otherwise render it back.
57
When an avatar is added this method True, otherwise, if the avatar
58
was in the collection, return False.
60
if not avatar.email is "" and not avatar.email in self.__avatars:
61
self.__avatars[avatar.email] = avatar
62
self._new_cell_for_avatar(avatar)
65
self.and_avatar_email(avatar.email).come_back_to_gui()
68
def and_avatar_email(self, email):
70
Select the avatar from avatars collection
71
in order to apply future actions
74
if not email is "" and email in self.__avatars:
75
self.avatar = self.__avatars[email]
80
def update_avatar_image_from_pixbuf_loader(self, loader):
81
""" Replace the gtk.Spinner with the given loader """
83
self.avatar.image = gtk.Image()
84
self.avatar.image.set_from_pixbuf(loader.get_pixbuf())
85
self.avatar.show_image()
86
self.__displaying = self.avatar
88
def come_back_to_gui(self):
89
""" Render back avatar in the GUI """
91
self.pack_start(self.avatar)
92
self.__displaying = self.avatar
97
# ~~~~~ Private methods ~~~~~~
98
def _new_cell_for_avatar(self, avatar):
99
""" Create a new cell in this box with a gtk.Spinner """
100
avatar.show_spinner()
101
self.pack_start(avatar)
103
self.__displaying = avatar
105
def _show_no_email(self):
106
""" Show a gtk.Label with test 'No email' """
107
no_email = gtk.Label(_i18n("No email"))
108
self.pack_start(no_email)