/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 avatar.py

  • Committer: zedtux
  • Date: 2011-03-15 16:46:35 UTC
  • mto: This revision was merged to the branch mainline in revision 723.
  • Revision ID: zedtux@zedroot.org-20110315164635-4dwbd5pl0o25gg71
Moved Avatar and AvatarBox classes into avatarsbox file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2011 by Guillaume Hain (zedtux) <zedtux@zedroot.org>
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
import gtk
18
 
 
19
 
from bzrlib.plugins.gtk import _i18n
20
 
from bzrlib.config import parse_username
21
 
 
22
 
class Avatar(gtk.Box):
23
 
    """ Author or committer avatar """
24
 
    
25
 
    def __init__(self, apparent_username):
26
 
        """ Constructor """
27
 
        gtk.Box.__init__(self)
28
 
        
29
 
        self.apparent_username = apparent_username
30
 
        self.username, self.email = parse_username(apparent_username)
31
 
        self.image = None
32
 
    
33
 
    def __eq__(self, other):
34
 
        """
35
 
        Return True if attributes of the given avatar
36
 
        match to current object attributes otherwise return False
37
 
        """
38
 
        return self.apparent_username == other.apparent_username and \
39
 
               self.name == other.name and \
40
 
               self.email == other.email
41
 
    
42
 
    # ~~~~~ Public methods ~~~~~
43
 
    def show_spinner(self):
44
 
        """
45
 
        Replace the current content of the Avatar with a gtk.Spinner
46
 
        if an email address has been parsed. If not, show an gtk.Label with
47
 
        the translatable 'No email' text.
48
 
        """
49
 
        if not self.email is "":
50
 
            spinner = gtk.Spinner()
51
 
            spinner.start()
52
 
            self.pack_start(spinner, False)
53
 
            spinner.set_tooltip_text(_i18n("Retrieving avatar for %s...") % self.email)
54
 
            spinner.set_size_request(20, 20)
55
 
            spinner.show()
56
 
        else:
57
 
            no_email = gtk.Label(_i18n("No email"))
58
 
            self.pack_start(no_email)
59
 
            self.set_tooltip_text(self.apparent_username)
60
 
            no_email.show()
61
 
    
62
 
    def show_image(self):
63
 
        """ Replace the current content of the Avatar with the gtk.Image """
64
 
        if not self.email is "" and self.image:
65
 
            self.remove(self.get_children()[0])
66
 
            self.pack_start(self.image)
67
 
            self.image.set_tooltip_text(self.apparent_username)
68
 
            self.image.show()