home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / AppInstall / widgets / SearchEntry.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  3.3 KB  |  74 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sexy
  5. import gtk
  6. import gobject
  7.  
  8. class SearchEntry(sexy.IconEntry, gobject.GObject):
  9.     __gsignals__ = {
  10.         'terms-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)) }
  11.     
  12.     def __init__(self, icon_theme):
  13.         '''
  14.         Creates an enhanced IconEntry that supports a time out when typing
  15.         and uses a different background colour when the search is active
  16.         '''
  17.         sexy.IconEntry.__init__(self)
  18.         self.__gobject_init__()
  19.         self._handler_changed = self.connect_after('changed', self._on_changed)
  20.         self.connect('icon-pressed', self._on_icon_pressed)
  21.         image = gtk.Image()
  22.         pixbuf = icon_theme.load_icon(gtk.STOCK_CLEAR, gtk.ICON_SIZE_MENU, 0)
  23.         image.set_from_pixbuf(pixbuf)
  24.         self.set_icon(sexy.ICON_ENTRY_SECONDARY, image)
  25.         self.set_icon_highlight(sexy.ICON_ENTRY_PRIMARY, True)
  26.         settings = gtk.settings_get_default()
  27.         theme = settings.get_property('gtk-theme-name')
  28.         if not theme.startswith('HighContrast'):
  29.             pass
  30.         self._a11y = theme.startswith('LowContrast')
  31.         self._timeout_id = 0
  32.  
  33.     
  34.     def _on_icon_pressed(self, widget, icon, mouse_button):
  35.         '''
  36.         Emit the terms-changed signal without any time out when the clear
  37.         button was clicked
  38.         '''
  39.         if icon == sexy.ICON_ENTRY_SECONDARY:
  40.             self.handler_block(self._handler_changed)
  41.             self.set_text('')
  42.             self._check_style()
  43.             self.handler_unblock(self._handler_changed)
  44.             self.emit('terms-changed', self.get_text())
  45.         
  46.  
  47.     
  48.     def _on_changed(self, widget):
  49.         '''
  50.         Call the actual search method after a small timeout to allow the user
  51.         to enter a longer search term
  52.         '''
  53.         self._check_style()
  54.         if self._timeout_id > 0:
  55.             gobject.source_remove(self._timeout_id)
  56.         
  57.         timeout = 1000
  58.         self._timeout_id = gobject.timeout_add((timeout,), (lambda : self.emit('terms-changed', self.get_text())))
  59.  
  60.     
  61.     def _check_style(self):
  62.         '''
  63.         Use a different background colour if a search is active
  64.         '''
  65.         yellowish = gtk.gdk.Color(63479, 63479, 48830)
  66.         if self._a11y == True:
  67.             return None
  68.         if self.get_text() == '':
  69.             self.modify_base(gtk.STATE_NORMAL, None)
  70.         else:
  71.             self.modify_base(gtk.STATE_NORMAL, yellowish)
  72.  
  73.  
  74.