/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: 2012-03-22 17:14:22 UTC
  • mto: This revision was merged to the branch mainline in revision 789.
  • Revision ID: sinzui.is@verizon.net-20120322171422-l7bq6muqqgr36nxr
Ensure that the per/file message widget fits at least one line.

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