/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to avatarsbox.py

  • Committer: Jelmer Vernooij
  • Date: 2012-07-09 15:23:26 UTC
  • mto: This revision was merged to the branch mainline in revision 794.
  • Revision ID: jelmer@samba.org-20120709152326-dzxb8zoz0btull7n
Remove bzr-notify.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from gi.repository import Gtk
 
18
from gi.repository import GdkPixbuf
18
19
 
19
20
from bzrlib.config import parse_username
20
21
 
30
31
 
31
32
    def __init__(self, apparent_username):
32
33
        """ Constructor """
33
 
        Gtk.HBox.__init__(self)
 
34
        super(Avatar, self).__init__()
34
35
 
35
36
        self.apparent_username = apparent_username
36
37
        self.username, self.email = parse_username(apparent_username)
64
65
    def show_image(self):
65
66
        """Replace the current content of the Avatar with the Gtk.Image """
66
67
        if self.email and self.image:
67
 
            self.remove(self.get_children()[0])
 
68
            children = self.get_children()
 
69
            if children != []:
 
70
                self.remove(children[0])
68
71
            self.pack_start(self.image, True, True, 0)
69
72
            self.image.set_tooltip_text(self.apparent_username)
70
73
            self.image.show()
74
77
    """HBox showing an avatar."""
75
78
 
76
79
    def __init__(self, homogeneous=False, spacing=0):
77
 
        Gtk.HBox.__init__(self, homogeneous=homogeneous, spacing=spacing)
 
80
        super(AvatarBox, self).__init__(
 
81
            homogeneous=homogeneous, spacing=spacing)
78
82
        self.__avatars = {}
79
83
        self.avatar = None
80
84
        self.__displaying = None
146
150
        self.__displaying = avatar
147
151
 
148
152
    def _show_no_email(self):
149
 
        """Show a Gtk.Label with test 'No email'."""
 
153
        """Show a Gtk.Label with text 'No email'."""
150
154
        no_email = Gtk.Label(label=_i18n("No email"))
151
155
        self.pack_start(no_email, True, True, 0)
152
156
        no_email.show()
156
160
    """GTK container for author and committer avatars."""
157
161
 
158
162
    def __init__(self):
159
 
        Gtk.HBox.__init__(self, homogeneous=False, spacing=10)
160
 
 
 
163
        super(AvatarsBox, self).__init__(homogeneous=False, spacing=10)
161
164
        self.__committer_box = None
162
165
        self.__authors_box = None
163
166
        self._init_gui()
178
181
        # This callback method should be fired by all workers when a request
179
182
        # is done.
180
183
        self.__worker.set_callback_method(self._update_avatar_from_response)
181
 
        self.__worker.start()
 
184
        self.connect('destroy', self.on_destroy)
 
185
 
 
186
    def on_destroy(self, widget):
 
187
        self.__worker.stop()
 
188
        if self.__worker.is_alive():
 
189
            self.__worker.join()
182
190
 
183
191
    def add(self, username, role):
184
192
        """Add the given username in the role box and add in the worker queue.
185
193
        """
186
194
        avatar = Avatar(username)
187
 
        if (role == "author" and not self._role_box_for("committer").showing(avatar)) or role == "committer":
 
195
        is_shown = self._role_box_for("committer").showing(avatar)
 
196
        if (role == "author" and not is_shown) or role == "committer":
188
197
            if self._role_box_for(role).append_avatars_with(avatar):
189
198
                self.__worker.queue(avatar.email)
190
199
 
221
230
        :param response: a urllib2.urlopen() return value.
222
231
        :param email: used to identify item from self.__avatars.
223
232
        """
224
 
        # XXX sinzui 2011-08-01: This must be implemented in cairo
225
 
#        if email:
226
 
#            # Convert downloaded image from provider to Gtk.Image
227
 
#            loader = Gdk.GdkPixbuf.PixbufLoader()
228
 
#            loader.write(response.read())
229
 
#            loader.close()
 
233
        if email:
 
234
            # Convert downloaded image from provider to Gtk.Image
 
235
            loader = GdkPixbuf.PixbufLoader()
 
236
            loader.write(response.read())
 
237
            loader.close()
230
238
 
231
 
#            for role in ["committer", "author"]:
232
 
#                self._role_box_for(role).and_avatar_email(email).update_avatar_image_from_pixbuf_loader(loader)
 
239
            for role in ["committer", "author"]:
 
240
                self._role_box_for(role).and_avatar_email(
 
241
                    email).update_avatar_image_from_pixbuf_loader(loader)
233
242
 
234
243
    def _role_box_for(self, role):
235
244
        """ Return the Gtk.HBox for the given role """