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 / LibGladeApplication.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-05-11  |  2.7 KB  |  72 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. '''This module contains the LibGladeApplication class.'''
  5. import signal
  6. import gtk
  7. from gtk import glade
  8. from GtkAttributesFacade import GtkAttributesFacade
  9.  
  10. class LibGladeApplication:
  11.     '''This is the base class for applications that use Glade.
  12.     
  13.     The following attributes are used:
  14.  
  15.     xml - This is an instance of glade.XML which encapsulates the Glade GUI.
  16.  
  17.     The following private variables are used:
  18.  
  19.     _signalsAreDone - The UNIX signal handlers only have to be set once. 
  20.  
  21.     '''
  22.     _signalsAreDone = False
  23.     
  24.     def __init__(self, gladeFile):
  25.         '''Setup the appropriate signal handlers and call setHandlers.'''
  26.         if not self._signalsAreDone:
  27.             self._signalsAreDone = True
  28.             signal.signal(signal.SIGINT, signal.SIG_DFL)
  29.         
  30.         self.xml = glade.XML(gladeFile)
  31.         self.setHandlers()
  32.  
  33.     
  34.     def setHandlers(self):
  35.         '''Automatically autoconnect all of the handlers.
  36.         
  37.         Any methods (even in subclasses) that start with "on_" will be treated
  38.         as a handler that is automatically connected to by
  39.         xml.signal_autoconnect.
  40.  
  41.         '''
  42.         handlers = { }
  43.         for i in dir(self):
  44.             if i.startswith('on_'):
  45.                 handlers[i] = getattr(self, i)
  46.                 continue
  47.         
  48.         self.xml.signal_autoconnect(handlers)
  49.  
  50.     
  51.     def __getattr__(self, name):
  52.         """If self doesn't have the attribute, check self.xml.
  53.  
  54.         If self.xml does have the attribute, wrap it in a GtkAttributesFacade 
  55.         instance, cache it in self, and return it.
  56.         
  57.         """
  58.         obj = self.xml.get_widget(name)
  59.         if obj:
  60.             obj = GtkAttributesFacade(obj)
  61.             setattr(self, name, obj)
  62.             return obj
  63.         
  64.         raise AttributeError("%s instance has no attribute '%s'" % (self.__class__.__name__, name))
  65.  
  66.     
  67.     def on_quit_activate(self, *args):
  68.         '''Ignore args and call gtk.mainquit().'''
  69.         gtk.main_quit()
  70.  
  71.  
  72.