/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-08-01 14:46:23 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110801144623-ldjf0bu7kyi5bxzu
Updated commit to gtk3.

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