~ubuntu-branches/ubuntu/maverick/awn-extras-applets/maverick

« back to all changes in this revision

Viewing changes to applets/unmaintained/stacks/stacks_icons.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-08-29 14:29:52 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100829142952-rhvuetyms9bv5uu7
Tags: upstream-0.4.0+bzr1372
ImportĀ upstreamĀ versionĀ 0.4.0+bzr1372

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
 
 
3
2
# Copyright (c) 2007 Timon ter Braak
4
3
#
5
4
# This library is free software; you can redistribute it and/or
18
17
# Boston, MA 02111-1307, USA.
19
18
 
20
19
import os
21
 
import gnome.ui
22
 
import gnomevfs
 
20
import gio
23
21
import gtk
24
 
import urllib
 
22
 
 
23
try:
 
24
    import gnome.ui
 
25
except ImportError:
 
26
    pass
 
27
 
25
28
 
26
29
# Borrowed Thumbnailer from "gimmie"
27
30
class Thumbnailer:
33
36
        self.cached_timestamp = None
34
37
        self.cached_size = None
35
38
 
36
 
 
37
39
    def get_icon(self, icon_size, timestamp = 0):
38
40
        if not self.cached_icon or \
39
41
                icon_size != self.cached_size or \
44
46
            self.cached_timestamp = timestamp
45
47
        return self.cached_icon
46
48
 
47
 
 
48
49
    def _lookup_or_make_thumb(self, icon_size, timestamp):
49
 
        icon_theme = gtk.icon_theme_get_default()
50
 
        thumb_factory = gnome.ui.ThumbnailFactory("normal")
51
 
        icon_name, icon_type = \
 
50
        icon_name = None
 
51
 
 
52
        # FIXME replace gnome.ui usage by something else
 
53
        try:
 
54
            icon_theme = gtk.icon_theme_get_default()
 
55
            thumb_factory = gnome.ui.ThumbnailFactory("normal")
 
56
            icon_name, icon_type = \
52
57
                gnome.ui.icon_lookup(icon_theme, thumb_factory, self.uri, self.mimetype, 0)
53
 
        try:
54
58
            if icon_type == gnome.ui.ICON_LOOKUP_RESULT_FLAGS_THUMBNAIL or \
55
59
                    thumb_factory.has_valid_failed_thumbnail(self.uri, timestamp):
56
60
                # Use existing thumbnail
68
72
        except:
69
73
            pass
70
74
 
 
75
        if icon_name is None:
 
76
            icon_name = "image-missing"
71
77
        # Fallback to mime-type icon on failure
72
 
        thumb = IconFactory().load_icon(icon_name, icon_size)
73
 
        
74
 
        return thumb
75
 
 
 
78
        return IconFactory().load_icon(icon_name, icon_size)
76
79
 
77
80
    def _is_local_uri(self, uri):
78
81
        # NOTE: gnomevfs.URI.is_local seems to hang for some URIs (e.g. ssh
110
113
                pass
111
114
        return None
112
115
 
113
 
 
114
116
    def load_icon_from_data_dirs(self, icon_value, icon_size = None):
115
117
        data_dirs = None
116
118
        if os.environ.has_key("XDG_DATA_DIRS"):
131
133
 
132
134
        return None
133
135
 
134
 
 
135
136
    def scale_to_bounded(self, icon, size):
136
137
        if icon:
137
138
            if icon.get_height() > size:
150
151
                    icon = _icon
151
152
        return icon
152
153
 
153
 
 
154
154
    def load_icon(self, icon_value, icon_size, force_size = True):
155
155
        assert icon_value, "No icon to load!"
156
156
 
184
184
        icon = None
185
185
        icon_theme = gtk.icon_theme_get_default()
186
186
        info = icon_theme.lookup_icon(icon_name, icon_size, gtk.ICON_LOOKUP_USE_BUILTIN)
187
 
        
 
187
 
188
188
        if info:
189
189
            if icon_name.startswith("gtk-"):
190
190
                # NOTE: IconInfo/IconTheme.load_icon leaks a ref to the icon, so
201
201
            return self.scale_to_bounded(icon, icon_size)
202
202
        return icon
203
203
 
204
 
 
205
 
    def load_image(self, icon_value, icon_size, force_size = True):
206
 
        
 
204
    def load_image(self, icon_value, icon_size, force_size=True):
207
205
        pixbuf = self.load_icon(icon_value, icon_size, force_size)
208
206
        img = gtk.Image()
209
207
        img.set_from_pixbuf(pixbuf)