/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: Curtis Hovey
  • Date: 2011-09-03 22:00:09 UTC
  • mto: This revision was merged to the branch mainline in revision 738.
  • Revision ID: sinzui.is@verizon.net-20110903220009-rvrgi2q1npy27jsw
Added basic tests to verify __eq__ is fixed.

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