/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-07-31 15:52:43 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110731155243-ln8istmxbryhb4pz
Mechanical changes made by pygi.convert.sh.

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