/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: 2011-11-02 11:11:06 UTC
  • mfrom: (734.1.55 gtk3)
  • Revision ID: jelmer@samba.org-20111102111106-7l0vso8eg24dpf87
Merge gtk3 support from Curtis.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
import gtk
 
17
from gi.repository import Gtk
 
18
from gi.repository import GdkPixbuf
18
19
 
19
20
from bzrlib.config import parse_username
20
21
 
25
26
    )
26
27
 
27
28
 
28
 
class Avatar(gtk.HBox):
 
29
class Avatar(Gtk.HBox):
29
30
    """ Author or committer avatar """
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)
43
44
 
44
45
    def show_spinner(self):
45
46
        """
46
 
        Replace the current content of the Avatar with a gtk.Spinner
47
 
        if an email address has been parsed. If not, show an gtk.Label with
 
47
        Replace the current content of the Avatar with a Gtk.Spinner
 
48
        if an email address has been parsed. If not, show an Gtk.Label with
48
49
        the translatable 'No email' text.
49
50
        """
50
51
        if self.email:
51
52
            tooltip = _i18n("Retrieving avatar for %s...") % self.email
52
 
            if getattr(gtk, "Spinner", False):
53
 
                spinner = gtk.Spinner()
54
 
                spinner.start()
55
 
                self.pack_start(spinner, False)
56
 
                spinner.set_tooltip_text(tooltip)
57
 
                spinner.set_size_request(20, 20)
58
 
                spinner.show()
59
 
            else:
60
 
                spinner = gtk.Label(tooltip)
61
 
                self.pack_start(spinner)
62
 
                self.set_tooltip_text(self.apparent_username)
63
 
                spinner.show()
 
53
            spinner = Gtk.Spinner()
 
54
            spinner.start()
 
55
            self.pack_start(spinner, False, True, 0)
 
56
            spinner.set_tooltip_text(tooltip)
 
57
            spinner.set_size_request(20, 20)
 
58
            spinner.show()
64
59
        else:
65
 
            no_email = gtk.Label(_i18n("No email"))
66
 
            self.pack_start(no_email)
 
60
            no_email = Gtk.Label(label=_i18n("No email"))
 
61
            self.pack_start(no_email, True, True, 0)
67
62
            self.set_tooltip_text(self.apparent_username)
68
63
            no_email.show()
69
64
 
70
65
    def show_image(self):
71
 
        """Replace the current content of the Avatar with the gtk.Image """
 
66
        """Replace the current content of the Avatar with the Gtk.Image """
72
67
        if self.email and self.image:
73
 
            self.remove(self.get_children()[0])
74
 
            self.pack_start(self.image)
 
68
            children = self.get_children()
 
69
            if children != []:
 
70
                self.remove(children[0])
 
71
            self.pack_start(self.image, True, True, 0)
75
72
            self.image.set_tooltip_text(self.apparent_username)
76
73
            self.image.show()
77
74
 
78
75
 
79
 
class AvatarBox(gtk.HBox):
 
76
class AvatarBox(Gtk.HBox):
80
77
    """HBox showing an avatar."""
81
78
 
82
79
    def __init__(self, homogeneous=False, spacing=0):
83
 
        gtk.HBox.__init__(self, homogeneous, spacing)
 
80
        super(AvatarBox, self).__init__(
 
81
            homogeneous=homogeneous, spacing=spacing)
84
82
        self.__avatars = {}
85
83
        self.avatar = None
86
84
        self.__displaying = None
129
127
        return self
130
128
 
131
129
    def update_avatar_image_from_pixbuf_loader(self, loader):
132
 
        """Replace the gtk.Spinner with the given loader."""
 
130
        """Replace the Gtk.Spinner with the given loader."""
133
131
        if self.avatar:
134
 
            self.avatar.image = gtk.Image()
 
132
            self.avatar.image = Gtk.Image()
135
133
            self.avatar.image.set_from_pixbuf(loader.get_pixbuf())
136
134
            self.avatar.show_image()
137
135
            self.__displaying = self.avatar
139
137
    def come_back_to_gui(self):
140
138
        """Render back avatar in the GUI."""
141
139
        if self.avatar:
142
 
            self.pack_start(self.avatar)
 
140
            self.pack_start(self.avatar, True, True, 0)
143
141
            self.__displaying = self.avatar
144
142
        else:
145
143
            self._show_no_email()
146
144
 
147
145
    def _new_cell_for_avatar(self, avatar):
148
 
        """Create a new cell in this box with a gtk.Spinner."""
 
146
        """Create a new cell in this box with a Gtk.Spinner."""
149
147
        avatar.show_spinner()
150
 
        self.pack_start(avatar)
 
148
        self.pack_start(avatar, True, True, 0)
151
149
        avatar.show()
152
150
        self.__displaying = avatar
153
151
 
154
152
    def _show_no_email(self):
155
 
        """Show a gtk.Label with test 'No email'."""
156
 
        no_email = gtk.Label(_i18n("No email"))
157
 
        self.pack_start(no_email)
 
153
        """Show a Gtk.Label with text 'No email'."""
 
154
        no_email = Gtk.Label(label=_i18n("No email"))
 
155
        self.pack_start(no_email, True, True, 0)
158
156
        no_email.show()
159
157
 
160
158
 
161
 
class AvatarsBox(gtk.HBox):
 
159
class AvatarsBox(Gtk.HBox):
162
160
    """GTK container for author and committer avatars."""
163
161
 
164
162
    def __init__(self):
165
 
        gtk.HBox.__init__(self, False, 10)
166
 
 
 
163
        super(AvatarsBox, self).__init__(homogeneous=False, spacing=10)
167
164
        self.__committer_box = None
168
165
        self.__authors_box = None
169
166
        self._init_gui()
215
212
 
216
213
    def _init_gui(self):
217
214
        """Create boxes where avatars will be displayed."""
218
 
        # 2 gtk.HBox: One for the committer and one for authors
 
215
        # 2 Gtk.HBox: One for the committer and one for authors
219
216
        # Committer
220
217
        self.__committer_box = AvatarBox()
221
218
        self.__committer_box.set_size_request(80, 80)
222
 
        self.pack_end(self.__committer_box, False)
 
219
        self.pack_end(self.__committer_box, False, True, 0)
223
220
        self.__committer_box.show()
224
221
        # Authors
225
222
        self.__authors_box = AvatarBox()
226
 
        self.pack_end(self.__authors_box, False)
 
223
        self.pack_end(self.__authors_box, False, True, 0)
227
224
        self.__authors_box.set_spacing(10)
228
225
        self.__authors_box.show()
229
226
 
234
231
        :param email: used to identify item from self.__avatars.
235
232
        """
236
233
        if email:
237
 
            # Convert downloaded image from provider to gtk.Image
238
 
            loader = gtk.gdk.PixbufLoader()
 
234
            # Convert downloaded image from provider to Gtk.Image
 
235
            loader = GdkPixbuf.PixbufLoader()
239
236
            loader.write(response.read())
240
237
            loader.close()
241
238
 
244
241
                    email).update_avatar_image_from_pixbuf_loader(loader)
245
242
 
246
243
    def _role_box_for(self, role):
247
 
        """ Return the gtk.HBox for the given role """
 
244
        """ Return the Gtk.HBox for the given role """
248
245
        if role == "committer":
249
246
            return self.__committer_box
250
247
        else: