home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / hal / device-manager / GtkAttributesFacade.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-05-11  |  2.5 KB  |  68 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. '''This module contains the GtkAttributesFacade class.'''
  5. from gobject import GObject
  6.  
  7. class GtkAttributesFacade:
  8.     '''Wrap a GTK instance to simplify the way attributes are referenced.
  9.  
  10.     Given a GTK instance i, make it possible for any functions i.get_foo() and
  11.     i.set_foo(value) to be accessed via i.foo like a normal attribute.
  12.  
  13.     The following attributes are used:
  14.  
  15.     instance - This is the GTK instance that is being wrapped.
  16.  
  17.     '''
  18.     
  19.     def __init__(self, instance):
  20.         '''Accept the instance.'''
  21.         self.__dict__['instance'] = instance
  22.  
  23.     
  24.     def __setattr__(self, name, value):
  25.         '''Simplify the way attributes are referenced.
  26.  
  27.         When trying to do self.foo = something, if there is a
  28.         self.instance.set_foo() method, use it.  Otherwise, just set the
  29.         attribute in self.
  30.  
  31.         Return value so that chaining is possible.
  32.         
  33.         '''
  34.         setter = 'set_' + name
  35.         if hasattr(self.instance, setter):
  36.             apply(getattr(self.instance, setter), [
  37.                 value])
  38.         else:
  39.             self.__dict__[name] = value
  40.         return value
  41.  
  42.     
  43.     def __getattr__(self, name):
  44.         '''Simplify the way attributes are referenced.
  45.  
  46.         Remember that this method is called after a failed lookup in self.  Try
  47.         looking for self.instance.foo.  Next, try looking for a
  48.         self.instance.get_foo() method, and call it if it exists.  Otherwise,
  49.         raise an exception.
  50.  
  51.         If a value is successfully looked up, and if it is a subclass of 
  52.         GObject, wrap it in a GtkAttributesFacade before returning it.
  53.         
  54.         '''
  55.         getter = 'get_' + name
  56.         if hasattr(self.instance, name):
  57.             ret = getattr(self.instance, name)
  58.         elif hasattr(self.instance, getter):
  59.             ret = apply(getattr(self.instance, getter))
  60.         else:
  61.             raise AttributeError("%s instance has no attribute '%s'" % (self.instance.__class__.__name__, name))
  62.         if isinstance(ret, GObject):
  63.             ret = GtkAttributesFacade(ret)
  64.         
  65.         return ret
  66.  
  67.  
  68.