Don't use gdkpixbufs, add path-based icons into a supplemental icon
directory and create Gtk.Images from their fake names.
This commit is contained in:
parent
daed7b863b
commit
9f8f76b0eb
@ -36,15 +36,24 @@ class IconManager(GObject.GObject):
|
|||||||
# This takes to much time and there are only a very few applications that use icons from different themes
|
# This takes to much time and there are only a very few applications that use icons from different themes
|
||||||
#self.themes = map( createTheme, [ d for d in os.listdir( "/usr/share/icons" ) if os.path.isdir( os.path.join( "/usr/share/icons", d ) ) ] )
|
#self.themes = map( createTheme, [ d for d in os.listdir( "/usr/share/icons" ) if os.path.isdir( os.path.join( "/usr/share/icons", d ) ) ] )
|
||||||
|
|
||||||
defaultTheme = Gtk.IconTheme.get_default()
|
self.defaultTheme = Gtk.IconTheme.get_default()
|
||||||
defaultKdeTheme = createTheme( "kde.default" )
|
defaultKdeTheme = createTheme( "kde.default" )
|
||||||
|
|
||||||
|
# Setup and clean up the temp icon dir
|
||||||
|
configDir = GLib.get_user_config_dir()
|
||||||
|
self.iconDir = os.path.join(configDir, "mintmenu")
|
||||||
|
if not os.path.exists(self.iconDir):
|
||||||
|
os.makedirs(self.iconDir)
|
||||||
|
contents = os.listdir(self.iconDir)
|
||||||
|
for fn in contents:
|
||||||
|
os.remove(os.path.join(self.iconDir, fn))
|
||||||
|
|
||||||
|
self.defaultTheme.append_search_path(self.iconDir)
|
||||||
|
|
||||||
# Themes with the same content as the default them aren't needed
|
# Themes with the same content as the default them aren't needed
|
||||||
#self.themes = [ theme for theme in self.themes if theme.list_icons() != defaultTheme.list_icons() ]
|
#self.themes = [ theme for theme in self.themes if theme.list_icons() != defaultTheme.list_icons() ]
|
||||||
|
|
||||||
self.themes = [ defaultTheme, defaultKdeTheme ]
|
self.themes = [ self.defaultTheme, defaultKdeTheme ]
|
||||||
|
|
||||||
self.cache = {}
|
|
||||||
|
|
||||||
# Listen for changes in the themes
|
# Listen for changes in the themes
|
||||||
for theme in self.themes:
|
for theme in self.themes:
|
||||||
@ -58,35 +67,28 @@ class IconManager(GObject.GObject):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
iconFileName = ""
|
iconFileName = ""
|
||||||
canSetByName = True
|
realIconName = ""
|
||||||
|
needTempFile = False
|
||||||
#[ iconWidth, iconHeight ] = self.getIconSize( iconSize )
|
#[ iconWidth, iconHeight ] = self.getIconSize( iconSize )
|
||||||
if iconSize <= 0:
|
if iconSize <= 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
elif os.path.isabs( iconName ):
|
elif os.path.isabs( iconName ):
|
||||||
iconFileName = iconName
|
iconFileName = iconName
|
||||||
canSetByName = False
|
needTempFile = True
|
||||||
else:
|
else:
|
||||||
if iconName[-4:] in [".png", ".xpm", ".svg", ".gif"]:
|
if iconName[-4:] in [".png", ".xpm", ".svg", ".gif"]:
|
||||||
realIconName = iconName[:-4]
|
realIconName = iconName[:-4]
|
||||||
else:
|
else:
|
||||||
realIconName = iconName
|
realIconName = iconName
|
||||||
|
|
||||||
if iconFileName and not canSetByName and os.path.exists( iconFileName ):
|
if iconFileName and needTempFile and os.path.exists( iconFileName ):
|
||||||
icon = GdkPixbuf.Pixbuf.new_from_file_at_size( iconFileName, iconSize, iconSize )
|
tmpIconName = iconFileName.replace("/", "-")
|
||||||
|
shutil.copyfile(iconFileName, os.path.join(self.iconDir, tmpIconName))
|
||||||
|
realIconName = tmpIconName[:-4]
|
||||||
|
if not self.defaultTheme.has_icon( realIconName ):
|
||||||
|
self.defaultTheme.append_search_path(self.iconDir)
|
||||||
|
|
||||||
# if the actual icon size is to far from the desired size resize it
|
|
||||||
if icon and (( icon.get_width() - iconSize ) > 5 or ( icon.get_height() - iconSize ) > 5):
|
|
||||||
if icon.get_width() > icon.get_height():
|
|
||||||
newIcon = icon.scale_simple( iconSize, icon.get_height() * iconSize / icon.get_width(), GdkPixbuf.InterpType.BILINEAR )
|
|
||||||
else:
|
|
||||||
newIcon = icon.scale_simple( icon.get_width() * iconSize / icon.get_height(), iconSize, GdkPixbuf.InterpType.BILINEAR )
|
|
||||||
del icon
|
|
||||||
icon = newIcon
|
|
||||||
|
|
||||||
image = Gtk.Image.new_from_pixbuf(icon)
|
|
||||||
|
|
||||||
elif canSetByName:
|
|
||||||
image = Gtk.Image()
|
image = Gtk.Image()
|
||||||
icon_found = False
|
icon_found = False
|
||||||
for theme in self.themes:
|
for theme in self.themes:
|
||||||
@ -99,8 +101,6 @@ class IconManager(GObject.GObject):
|
|||||||
image.set_pixel_size(iconSize)
|
image.set_pixel_size(iconSize)
|
||||||
else:
|
else:
|
||||||
image = None
|
image = None
|
||||||
else:
|
|
||||||
image = None
|
|
||||||
|
|
||||||
return image
|
return image
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
@ -108,7 +108,6 @@ class IconManager(GObject.GObject):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def themeChanged( self, theme ):
|
def themeChanged( self, theme ):
|
||||||
self.cache = { }
|
|
||||||
self.emit( "changed" )
|
self.emit( "changed" )
|
||||||
|
|
||||||
GObject.type_register(IconManager)
|
GObject.type_register(IconManager)
|
||||||
@ -279,13 +278,8 @@ class ApplicationLauncher( easyButton ):
|
|||||||
|
|
||||||
icon = self.getIcon( Gtk.IconSize.DND )
|
icon = self.getIcon( Gtk.IconSize.DND )
|
||||||
if icon:
|
if icon:
|
||||||
if icon.get_storage_type() == Gtk.ImageType.PIXBUF:
|
iconName, s = icon.get_icon_name()
|
||||||
pb = icon.get_pixbuf()
|
c = c_char_p(iconName.encode('ascii', 'ignore'))
|
||||||
gtk.gtk_drag_source_set_icon_pixbuf( hash(self), hash(pb) )
|
|
||||||
del icon
|
|
||||||
else:
|
|
||||||
if self.iconName:
|
|
||||||
c = c_char_p(self.iconName.encode('ascii', 'ignore'))
|
|
||||||
gtk.gtk_drag_source_set_icon_name( hash(self), c)
|
gtk.gtk_drag_source_set_icon_name( hash(self), c)
|
||||||
|
|
||||||
self.connectSelf( "focus-in-event", self.onFocusIn )
|
self.connectSelf( "focus-in-event", self.onFocusIn )
|
||||||
@ -402,13 +396,8 @@ class ApplicationLauncher( easyButton ):
|
|||||||
|
|
||||||
icon = self.getIcon( Gtk.IconSize.DND )
|
icon = self.getIcon( Gtk.IconSize.DND )
|
||||||
if icon:
|
if icon:
|
||||||
if icon.get_storage_type() == Gtk.ImageType.PIXBUF:
|
iconName, size = icon.get_icon_name()
|
||||||
pb = icon.get_pixbuf()
|
c = c_char_p(iconName.encode('ascii', 'ignore'))
|
||||||
gtk.gtk_drag_source_set_icon_pixbuf( hash(self), hash(pb) )
|
|
||||||
del icon
|
|
||||||
else:
|
|
||||||
if self.iconName:
|
|
||||||
c = c_char_p(self.iconName.encode('ascii', 'ignore'))
|
|
||||||
gtk.gtk_drag_source_set_icon_name( hash(self), c)
|
gtk.gtk_drag_source_set_icon_name( hash(self), c)
|
||||||
|
|
||||||
def startupFileChanged( self, *args ):
|
def startupFileChanged( self, *args ):
|
||||||
|
Loading…
Reference in New Issue
Block a user