Implementation of pixbufs for use with X11 window icons.

master
Sebastian Silva 10 years ago
parent a082cf1cca
commit 2a7d4da38a

@ -100,6 +100,7 @@ class _IconBuffer(object):
self.height = None self.height = None
self.cache = False self.cache = False
self.scale = 1.0 self.scale = 1.0
self.pixbuf = None
def _get_cache_key(self, sensitive): def _get_cache_key(self, sensitive):
if self.background_color is None: if self.background_color is None:
@ -107,7 +108,8 @@ class _IconBuffer(object):
else: else:
color = (self.background_color.red, self.background_color.green, color = (self.background_color.red, self.background_color.green,
self.background_color.blue) self.background_color.blue)
return (self.icon_name, self.file_name, self.fill_color,
return (self.icon_name, self.file_name, self.pixbuf, self.fill_color,
self.stroke_color, self.badge_name, self.width, self.height, self.stroke_color, self.badge_name, self.width, self.height,
color, sensitive) color, sensitive)
@ -252,35 +254,43 @@ class _IconBuffer(object):
if cache_key in self._surface_cache: if cache_key in self._surface_cache:
return self._surface_cache[cache_key] return self._surface_cache[cache_key]
# We run two attempts at finding the icon. First, we try the icon if self.pixbuf:
# requested by the user. If that fails, we fall back on # We alredy have the pixbuf for this icon.
# document-generic. If that doesn't work out, bail. pixbuf = self.pixbuf
icon_width = None icon_width = pixbuf.get_width()
for (file_name, icon_name) in ((self.file_name, self.icon_name), icon_height = pixbuf.get_height()
(None, 'document-generic')): icon_info = self._get_icon_info(self.file_name, self.icon_name)
icon_info = self._get_icon_info(file_name, icon_name) is_svg = False
if icon_info.file_name is None: else:
return None # We run two attempts at finding the icon. First, we try the icon
# requested by the user. If that fails, we fall back on
is_svg = icon_info.file_name.endswith('.svg') # document-generic. If that doesn't work out, bail.
icon_width = None
if is_svg: for (file_name, icon_name) in ((self.file_name, self.icon_name),
try: (None, 'document-generic')):
handle = self._load_svg(icon_info.file_name) icon_info = self._get_icon_info(file_name, icon_name)
icon_width = handle.props.width if icon_info.file_name is None:
icon_height = handle.props.height return None
break
except IOError: is_svg = icon_info.file_name.endswith('.svg')
pass
else: if is_svg:
try: try:
path = icon_info.file_name handle = self._load_svg(icon_info.file_name)
pixbuf = GdkPixbuf.Pixbuf.new_from_file(path) icon_width = handle.props.width
icon_width = pixbuf.get_width() icon_height = handle.props.height
icon_height = pixbuf.get_height() break
break except IOError:
except GObject.GError: pass
pass else:
try:
path = icon_info.file_name
pixbuf = GdkPixbuf.Pixbuf.new_from_file(path)
icon_width = pixbuf.get_width()
icon_height = pixbuf.get_height()
break
except GObject.GError:
pass
if icon_width is None: if icon_width is None:
# Neither attempt found an icon for us to use # Neither attempt found an icon for us to use
@ -365,6 +375,14 @@ class Icon(Gtk.Image):
file = GObject.property(type=object, setter=set_file, getter=get_file) file = GObject.property(type=object, setter=set_file, getter=get_file)
def get_pixbuf(self):
return self._buffer.pixbuf
def set_pixbuf(self, pixbuf):
self._buffer.pixbuf = pixbuf
pixbuf = GObject.property(type=object, setter=set_pixbuf, getter=get_pixbuf)
def _sync_image_properties(self): def _sync_image_properties(self):
if self._buffer.icon_name != self.props.icon_name: if self._buffer.icon_name != self.props.icon_name:
self._buffer.icon_name = self.props.icon_name self._buffer.icon_name = self.props.icon_name

Loading…
Cancel
Save