Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib/sugar/graphics/iconentry.py
blob: 83bc864a57483820515aff6353f48d0b6c7b42c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright (C) 2007, One Laptop Per Child
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

import gtk

from sugar import _sugarext

ICON_ENTRY_PRIMARY = _sugarext.ICON_ENTRY_PRIMARY
ICON_ENTRY_SECONDARY = _sugarext.ICON_ENTRY_SECONDARY

class IconEntry(_sugarext.IconEntry):
    def set_icon_from_name(self, position, name):
        icon_theme = gtk.icon_theme_get_default()
        icon_info = icon_theme.lookup_icon(name,
                                           gtk.ICON_SIZE_SMALL_TOOLBAR,
                                           0)

        pixbuf = gtk.gdk.pixbuf_new_from_file(icon_info.get_filename())

        image = gtk.Image()
        image.set_from_pixbuf(pixbuf)
        image.show()

        self.set_icon(position, image)

    def set_icon(self, position, image):
        if image.get_storage_type() not in [gtk.IMAGE_PIXBUF, gtk.IMAGE_STOCK]:
            raise ValueError('Image must have a storage type of pixbuf or ' +
                             'stock, not %r.' % image.get_storage_type())
        _sugarext.IconEntry.set_icon(self, position, image)