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)
28
self.__current_avatar = None
29
self.__displaying = None
32
# ~~~~~ Properties ~~~~~
35
return self.__current_avatar
36
def set_avatar(self, avatar):
37
self.__current_avatar = avatar
38
avatar = property(get_avatar, set_avatar)
41
# ~~~~~ Public methods ~~~~~
43
""" Remove current avatars from the gtk box """
44
for child in self.get_children():
46
self.__displaying = None
48
def have_avatar(self, avatar):
50
Return True if this box has registered given avatar,
51
otherwise return False
53
return avatar.email in self.__avatars
55
def showing(self, avatar):
57
Return True if the displaying avatar is the same
58
as the given one otherwise return False
60
return self.__displaying and self.__displaying.is_identical(avatar)
62
def append_avatars_with(self, avatar):
64
Append avatars collection with the given one if not already registed
65
otherwise render it back.
66
When an avatar is added this method True, otherwise, if the avatar
67
was in the collection, return False.
69
if not avatar.email is "" and not avatar.email in self.__avatars:
70
self.__avatars[avatar.email] = avatar
71
self._new_cell_for_avatar(avatar)
74
self.and_avatar_email(avatar.email).come_back_to_gui()
77
def and_avatar_email(self, email):
79
Select the avatar from avatars collection
80
in order to apply future actions
84
self.avatar = self.__avatars[email] if email in self.__avatars else None
87
def update_avatar_image_from_pixbuf_loader(self, loader):
88
""" Replace the gtk.Spinner with the given loader """
90
self.avatar.image = gtk.Image()
91
self.avatar.image.set_from_pixbuf(loader.get_pixbuf())
92
self.avatar.show_image()
93
self.__displaying = self.avatar
95
def come_back_to_gui(self):
96
""" Render back avatar in the GUI """
98
self.pack_start(self.avatar)
99
self.__displaying = self.avatar
101
self._show_no_email()
104
# ~~~~~ Private methods ~~~~~~
105
def _new_cell_for_avatar(self, avatar):
106
""" Create a new cell in this box with a gtk.Spinner """
107
avatar.show_spinner()
108
self.pack_start(avatar)
110
self.__displaying = avatar
112
def _show_no_email(self):
113
""" Show a gtk.Label with test 'No email' """
114
no_email = gtk.Label(_i18n("No email"))
115
self.pack_start(no_email)