/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 avatarbox.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
 
 
21
 
class AvatarBox(gtk.HBox):
22
 
    """ Improved gtk.HBox """
23
 
    
24
 
    def __init__(self, homogeneous=False, spacing=0):
25
 
        """ Constructor """
26
 
        gtk.HBox.__init__(self, homogeneous, spacing)
27
 
        self.__avatars = {}
28
 
        self.avatar = None
29
 
        self.__displaying = None
30
 
    
31
 
    
32
 
    # ~~~~~ Public methods ~~~~~
33
 
    def reset_view(self):
34
 
        """ Remove current avatars from the gtk box """
35
 
        for child in self.get_children():
36
 
            self.remove(child)
37
 
        self.__displaying = None
38
 
    
39
 
    def have_avatar(self, avatar):
40
 
        """
41
 
        Return True if this box has registered given avatar,
42
 
        otherwise return False
43
 
        """
44
 
        return avatar.email in self.__avatars
45
 
    
46
 
    def showing(self, avatar):
47
 
        """
48
 
        Return True if the displaying avatar is the same
49
 
        as the given one otherwise return False
50
 
        """
51
 
        return self.__displaying and self.__displaying == avatar
52
 
    
53
 
    def append_avatars_with(self, avatar):
54
 
        """
55
 
        Append avatars collection with the given one if not already registed
56
 
        otherwise render it back.
57
 
        When an avatar is added this method True, otherwise, if the avatar
58
 
        was in the collection, return False.
59
 
        """
60
 
        if not avatar.email is "" and not avatar.email in self.__avatars:
61
 
            self.__avatars[avatar.email] = avatar
62
 
            self._new_cell_for_avatar(avatar)
63
 
            return True
64
 
        else:
65
 
            self.and_avatar_email(avatar.email).come_back_to_gui()
66
 
        return False
67
 
    
68
 
    def and_avatar_email(self, email):
69
 
        """
70
 
        Select the avatar from avatars collection
71
 
        in order to apply future actions
72
 
        """
73
 
        self.avatar = None
74
 
        if not email is "" and email in self.__avatars:
75
 
            self.avatar = self.__avatars[email]
76
 
        else:
77
 
            self.avatar = None
78
 
        return self
79
 
    
80
 
    def update_avatar_image_from_pixbuf_loader(self, loader):
81
 
        """ Replace the gtk.Spinner with the given loader """
82
 
        if self.avatar:
83
 
            self.avatar.image = gtk.Image()
84
 
            self.avatar.image.set_from_pixbuf(loader.get_pixbuf())
85
 
            self.avatar.show_image()
86
 
            self.__displaying = self.avatar
87
 
    
88
 
    def come_back_to_gui(self):
89
 
        """ Render back avatar in the GUI """
90
 
        if self.avatar:
91
 
            self.pack_start(self.avatar)
92
 
            self.__displaying = self.avatar
93
 
        else:
94
 
            self._show_no_email()
95
 
    
96
 
    
97
 
    # ~~~~~ Private methods ~~~~~~
98
 
    def _new_cell_for_avatar(self, avatar):
99
 
        """ Create a new cell in this box with a gtk.Spinner """
100
 
        avatar.show_spinner()
101
 
        self.pack_start(avatar)
102
 
        avatar.show()
103
 
        self.__displaying = avatar
104
 
    
105
 
    def _show_no_email(self):
106
 
        """ Show a gtk.Label with test 'No email' """
107
 
        no_email = gtk.Label(_i18n("No email"))
108
 
        self.pack_start(no_email)
109
 
        no_email.show()