1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# Copyright (C) 2011 by Guillaume Hain (zedtux) <zedtux@zedroot.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import gtk
from bzrlib.plugins.gtk import _i18n
class AvatarBox(gtk.HBox):
""" Improved gtk.HBox """
def __init__(self, homogeneous=False, spacing=0):
""" Constructor """
gtk.HBox.__init__(self, homogeneous, spacing)
self.__avatars = {}
self.__current_avatar = None
self.__displaying = None
# ~~~~~ Properties ~~~~~
# Avatar
def get_avatar(self):
return self.__current_avatar
def set_avatar(self, avatar):
self.__current_avatar = avatar
avatar = property(get_avatar, set_avatar)
# ~~~~~ Public methods ~~~~~
def reset_view(self):
""" Remove current avatars from the gtk box """
for child in self.get_children():
self.remove(child)
self.__displaying = None
def have_avatar(self, avatar):
"""
Return True if this box has registered given avatar,
otherwise return False
"""
return avatar.email in self.__avatars
def showing(self, avatar):
"""
Return True if the displaying avatar is the same
as the given one otherwise return False
"""
return self.__displaying and self.__displaying.is_identical(avatar)
def append_avatars_with(self, avatar):
"""
Append avatars collection with the given one if not already registed
otherwise render it back.
When an avatar is added this method True, otherwise, if the avatar
was in the collection, return False.
"""
if not avatar.email is "" and not avatar.email in self.__avatars:
self.__avatars[avatar.email] = avatar
self._new_cell_for_avatar(avatar)
return True
else:
self.and_avatar_email(avatar.email).come_back_to_gui()
return False
def and_avatar_email(self, email):
"""
Select the avatar from avatars collection
in order to apply future actions
"""
self.avatar = None
if not email is "":
self.avatar = self.__avatars[email] if email in self.__avatars else None
return self
def update_avatar_image_from_pixbuf_loader(self, loader):
""" Replace the gtk.Spinner with the given loader """
if self.avatar:
self.avatar.image = gtk.Image()
self.avatar.image.set_from_pixbuf(loader.get_pixbuf())
self.avatar.show_image()
self.__displaying = self.avatar
def come_back_to_gui(self):
""" Render back avatar in the GUI """
if self.avatar:
self.pack_start(self.avatar)
self.__displaying = self.avatar
else:
self._show_no_email()
# ~~~~~ Private methods ~~~~~~
def _new_cell_for_avatar(self, avatar):
""" Create a new cell in this box with a gtk.Spinner """
avatar.show_spinner()
self.pack_start(avatar)
avatar.show()
self.__displaying = avatar
def _show_no_email(self):
""" Show a gtk.Label with test 'No email' """
no_email = gtk.Label(_i18n("No email"))
self.pack_start(no_email)
no_email.show()
|