home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / AppInstall / common.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  3.3 KB  |  129 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import gtk
  5. import gobject
  6. import pygtk
  7. from warnings import warn
  8.  
  9. class ToughIconTheme:
  10.     
  11.     def __init__(self):
  12.         self.fallback = gtk.IconTheme()
  13.         self.fallback.set_custom_theme('hicolor')
  14.         self.crystal = gtk.IconTheme()
  15.         self.crystal.set_custom_theme('crystal')
  16.         self.gnome = gtk.IconTheme()
  17.         self.gnome.set_custom_theme('gnome')
  18.         self.default = gtk.icon_theme_get_default()
  19.         self.themes = [
  20.             self.default,
  21.             self.gnome,
  22.             self.fallback,
  23.             self.crystal]
  24.         self._internal_cache = { }
  25.  
  26.     
  27.     def load_icon(self, icon, size = 48, flags = 0):
  28.         for theme in self.themes:
  29.             
  30.             try:
  31.                 return theme.load_icon(icon, size, flags)
  32.             continue
  33.             continue
  34.             continue
  35.  
  36.         
  37.         return self.fallback.load_icon(gtk.STOCK_MISSING_IMAGE, size, flags)
  38.  
  39.     
  40.     def prepend_search_path(self, path):
  41.         for theme in self.themes:
  42.             
  43.             try:
  44.                 theme.prepend_search_path(path)
  45.             continue
  46.             continue
  47.             continue
  48.  
  49.         
  50.  
  51.     
  52.     def lookup_icon(self, name, size, flags = 0):
  53.         for theme in self.themes:
  54.             info = theme.lookup_icon(name, size, flags)
  55.             if info != None:
  56.                 return info
  57.                 continue
  58.         
  59.  
  60.     
  61.     def get_icon_sizes(self, icon_name):
  62.         for theme in self.themes:
  63.             
  64.             try:
  65.                 return theme.get_icon_sizes(icon_name)
  66.             continue
  67.             continue
  68.             continue
  69.  
  70.         
  71.  
  72.     
  73.     def has_icon(self, icon_name):
  74.         for theme in self.themes:
  75.             if theme.has_icon(icon_name) == True:
  76.                 return True
  77.                 continue
  78.         
  79.         return False
  80.  
  81.     
  82.     def _getIcon(self, name, size):
  83.         cache_name = '%s-%s' % (name, size)
  84.         if self._internal_cache.has_key(cache_name):
  85.             return self._internal_cache[cache_name]
  86.         
  87.         if name is None or name == '':
  88.             warn('ICON: Using dummy icon')
  89.             name = 'gnome-other'
  90.         
  91.         if name.startswith('/'):
  92.             warn("ICON: Doesn't handle absolute paths: '%s'" % name)
  93.             name = 'gnome-other'
  94.         
  95.         if name.find('.') != -1:
  96.             import os.path as os
  97.             if len(os.path.splitext(name)[1]) == 3 + 1:
  98.                 name = os.path.splitext(name)[0]
  99.             
  100.         
  101.         if not self.has_icon(name):
  102.             warn("ICON: Icon '%s' is not in theme" % name)
  103.             name = 'gnome-other'
  104.         
  105.         
  106.         try:
  107.             icon = self.load_icon(name, size, 0)
  108.         except gobject.GError:
  109.             icon = self.load_icon('gnome-other', size, 0)
  110.             name = 'gnome-other'
  111.  
  112.         if icon.get_width() != size:
  113.             warn('ICON: Got badly sized icon for %s' % name)
  114.             icon = icon.scale_simple(size, size, gtk.gdk.INTERP_BILINEAR)
  115.         
  116.         info = self.lookup_icon(name, size, gtk.ICON_LOOKUP_NO_SVG | gtk.ICON_LOOKUP_USE_BUILTIN)
  117.         if info is None:
  118.             info = self.lookup_icon('gnome-other', size, gtk.ICON_LOOKUP_NO_SVG | gtk.ICON_LOOKUP_USE_BUILTIN)
  119.             if info is None:
  120.                 filename = None
  121.             else:
  122.                 filename = info.get_filename()
  123.         else:
  124.             filename = info.get_filename()
  125.         self._internal_cache[cache_name] = icon
  126.         return icon
  127.  
  128.  
  129.