/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:
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
19
18
 
20
19
from bzrlib.config import parse_username
21
20
 
31
30
 
32
31
    def __init__(self, apparent_username):
33
32
        """ Constructor """
34
 
        super(Avatar, self).__init__()
 
33
        GObject.GObject.__init__(self)
35
34
 
36
35
        self.apparent_username = apparent_username
37
36
        self.username, self.email = parse_username(apparent_username)
39
38
 
40
39
    def __eq__(self, other):
41
40
        return (self.apparent_username == other.apparent_username and
42
 
                self.username == other.username and
 
41
                self.name == other.name and
43
42
                self.email == other.email)
44
43
 
45
44
    def show_spinner(self):
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(label=tooltip)
 
61
                self.pack_start(spinner, True, True, 0)
 
62
                self.set_tooltip_text(self.apparent_username)
 
63
                spinner.show()
59
64
        else:
60
65
            no_email = Gtk.Label(label=_i18n("No email"))
61
66
            self.pack_start(no_email, True, True, 0)
65
70
    def show_image(self):
66
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])
 
73
            self.remove(self.get_children()[0])
71
74
            self.pack_start(self.image, True, True, 0)
72
75
            self.image.set_tooltip_text(self.apparent_username)
73
76
            self.image.show()
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
        GObject.GObject.__init__(self, homogeneous, spacing)
82
84
        self.__avatars = {}
83
85
        self.avatar = None
84
86
        self.__displaying = None
150
152
        self.__displaying = avatar
151
153
 
152
154
    def _show_no_email(self):
153
 
        """Show a Gtk.Label with text 'No email'."""
 
155
        """Show a Gtk.Label with test 'No email'."""
154
156
        no_email = Gtk.Label(label=_i18n("No email"))
155
157
        self.pack_start(no_email, True, True, 0)
156
158
        no_email.show()
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
        GObject.GObject.__init__(self, False, 10)
 
166
 
164
167
        self.__committer_box = None
165
168
        self.__authors_box = None
166
169
        self._init_gui()
181
184
        # This callback method should be fired by all workers when a request
182
185
        # is done.
183
186
        self.__worker.set_callback_method(self._update_avatar_from_response)
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()
 
187
        self.__worker.start()
190
188
 
191
189
    def add(self, username, role):
192
190
        """Add the given username in the role box and add in the worker queue.
193
191
        """
194
192
        avatar = Avatar(username)
195
 
        is_shown = self._role_box_for("committer").showing(avatar)
196
 
        if (role == "author" and not is_shown) or role == "committer":
 
193
        if (role == "author" and not self._role_box_for("committer").showing(avatar)) or role == "committer":
197
194
            if self._role_box_for(role).append_avatars_with(avatar):
198
195
                self.__worker.queue(avatar.email)
199
196
 
216
213
        # Committer
217
214
        self.__committer_box = AvatarBox()
218
215
        self.__committer_box.set_size_request(80, 80)
219
 
        self.pack_end(self.__committer_box, False, True, 0)
 
216
        self.pack_end(self.__committer_box, False)
220
217
        self.__committer_box.show()
221
218
        # Authors
222
219
        self.__authors_box = AvatarBox()
223
 
        self.pack_end(self.__authors_box, False, True, 0)
 
220
        self.pack_end(self.__authors_box, False)
224
221
        self.__authors_box.set_spacing(10)
225
222
        self.__authors_box.show()
226
223
 
237
234
            loader.close()
238
235
 
239
236
            for role in ["committer", "author"]:
240
 
                self._role_box_for(role).and_avatar_email(
241
 
                    email).update_avatar_image_from_pixbuf_loader(loader)
 
237
                self._role_box_for(role).and_avatar_email(email).update_avatar_image_from_pixbuf_loader(loader)
242
238
 
243
239
    def _role_box_for(self, role):
244
240
        """ Return the Gtk.HBox for the given role """