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 / deskbar / Utils.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  4.0 KB  |  114 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import os
  5. import cgi
  6. import re
  7. from os.path import *
  8. import deskbar
  9. import deskbar.gnomedesktop as deskbar
  10. import gtk
  11. import gtk.gdk as gtk
  12. import gnome.ui as gnome
  13. from htmlentitydefs import name2codepoint
  14. ICON_THEME = gtk.icon_theme_get_default()
  15. factory = gnome.ui.ThumbnailFactory(deskbar.ICON_HEIGHT)
  16. charrefpat = re.compile('&(#(\\d+|x[\\da-fA-F]+)|[\\w.:-]+);?')
  17.  
  18. def htmldecode(text):
  19.     '''Decode HTML entities in the given text.'''
  20.     if type(text) is unicode:
  21.         uchr = unichr
  22.     else:
  23.         
  24.         uchr = lambda value: if not value > 255 or unichr(value):
  25. passchr(value)
  26.     
  27.     def entitydecode(match, uchr = uchr):
  28.         entity = match.group(1)
  29.         if entity.startswith('#x'):
  30.             return uchr(int(entity[2:], 16))
  31.         elif entity.startswith('#'):
  32.             return uchr(int(entity[1:]))
  33.         elif entity in name2codepoint:
  34.             return uchr(name2codepoint[entity])
  35.         else:
  36.             return match.group(0)
  37.  
  38.     return charrefpat.sub(entitydecode, text)
  39.  
  40.  
  41. def strip_html(string):
  42.     return re.sub('<.*?>|</.*?>', '', string)
  43.  
  44.  
  45. def more_information_dialog(parent, title, content):
  46.     message_dialog = gtk.MessageDialog(parent = parent, buttons = gtk.BUTTONS_CLOSE)
  47.     message_dialog.set_markup("<span size='larger' weight='bold'>%s</span>\n\n%s" % (cgi.escape(title), cgi.escape(content)))
  48.     resp = message_dialog.run()
  49.     if resp == gtk.RESPONSE_CLOSE:
  50.         message_dialog.destroy()
  51.     
  52.  
  53.  
  54. def get_xdg_data_dirs():
  55.     dirs = os.getenv('XDG_DATA_HOME')
  56.     if dirs == None:
  57.         dirs = expanduser('~/.local/share')
  58.     
  59.     sysdirs = os.getenv('XDG_DATA_DIRS')
  60.     if sysdirs == None:
  61.         sysdirs = '/usr/local/share:/usr/share'
  62.     
  63.     dirs = '%s:%s' % (dirs, sysdirs)
  64.     return _[1]
  65.  
  66.  
  67. def load_icon_for_file(f):
  68.     (icon_name, flags) = gnome.ui.icon_lookup(ICON_THEME, factory, f, '', gnome.ui.ICON_LOOKUP_FLAGS_SHOW_SMALL_IMAGES_AS_THEMSELVES)
  69.     return load_icon(icon_name)
  70.  
  71.  
  72. def load_icon_for_desktop_icon(icon):
  73.     if icon != None:
  74.         icon = deskbar.gnomedesktop.find_icon(ICON_THEME, icon, deskbar.ICON_HEIGHT, 0)
  75.         if icon != None:
  76.             return load_icon(icon)
  77.         
  78.     
  79.  
  80.  
  81. def load_icon(icon, width = deskbar.ICON_HEIGHT, height = deskbar.ICON_HEIGHT):
  82.     pixbuf = None
  83.     if icon != None and icon != '':
  84.         
  85.         try:
  86.             our_icon = join(deskbar.ART_DATA_DIR, icon)
  87.             if exists(our_icon):
  88.                 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(our_icon, width, height)
  89.             elif icon.startswith('/'):
  90.                 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon, width, height)
  91.             else:
  92.                 pixbuf = ICON_THEME.load_icon(splitext(icon)[0], width, gtk.ICON_LOOKUP_USE_BUILTIN)
  93.         except Exception:
  94.             msg1 = None
  95.             
  96.             try:
  97.                 pixbuf = ICON_THEME.load_icon(icon, width, gtk.ICON_LOOKUP_USE_BUILTIN)
  98.             except Exception:
  99.                 msg2 = None
  100.                 print 'Error:load_icon:Icon Load Error:%s (or %s)' % (msg1, msg2)
  101.             except:
  102.                 None<EXCEPTION MATCH>Exception
  103.             
  104.  
  105.             None<EXCEPTION MATCH>Exception
  106.         
  107.  
  108.     None<EXCEPTION MATCH>Exception
  109.     if pixbuf != None and pixbuf.get_height() > height:
  110.         pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
  111.     
  112.     return pixbuf
  113.  
  114.