home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_2441 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  3.1 KB  |  93 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import os.path as os
  6. from PyQt4.uic.exceptions import NoSuchWidgetError, WidgetPluginError
  7. if sys.hexversion >= 50331648:
  8.     from PyQt4.uic.port_v3.load_plugin import load_plugin
  9. else:
  10.     from PyQt4.uic.port_v2.load_plugin import load_plugin
  11. widgetPluginPath = [
  12.     os.path.join(os.path.dirname(__file__), 'widget-plugins')]
  13. MATCH = True
  14. NO_MATCH = False
  15. MODULE = 0
  16. CW_FILTER = 1
  17.  
  18. class QObjectCreator(object):
  19.     
  20.     def __init__(self, creatorPolicy):
  21.         self._cpolicy = creatorPolicy
  22.         self._cwFilters = []
  23.         self._modules = [
  24.             self._cpolicy.createQtGuiWrapper()]
  25.         for plugindir in widgetPluginPath:
  26.             
  27.             try:
  28.                 plugins = os.listdir(plugindir)
  29.             except:
  30.                 plugins = []
  31.  
  32.             for filename in plugins:
  33.                 if not filename.endswith('.py'):
  34.                     continue
  35.                 
  36.                 filename = os.path.join(plugindir, filename)
  37.                 plugin_globals = {
  38.                     'MODULE': MODULE,
  39.                     'CW_FILTER': CW_FILTER,
  40.                     'MATCH': MATCH,
  41.                     'NO_MATCH': NO_MATCH }
  42.                 plugin_locals = { }
  43.                 if load_plugin(open(filename), plugin_globals, plugin_locals):
  44.                     pluginType = plugin_locals['pluginType']
  45.                     if pluginType == MODULE:
  46.                         modinfo = plugin_locals['moduleInformation']()
  47.                         self._modules.append(self._cpolicy.createModuleWrapper(*modinfo))
  48.                     elif pluginType == CW_FILTER:
  49.                         self._cwFilters.append(plugin_locals['getFilter']())
  50.                     else:
  51.                         raise WidgetPluginError('Unknown plugin type of %s' % filename)
  52.                 pluginType == MODULE
  53.             
  54.         
  55.         self._customWidgets = self._cpolicy.createCustomWidgetLoader()
  56.         self._modules.append(self._customWidgets)
  57.  
  58.     
  59.     def createQObject(self, classname, *args, **kwargs):
  60.         classType = self.findQObjectType(classname)
  61.         if classType:
  62.             return self._cpolicy.instantiate(classType, *args, **kwargs)
  63.         raise NoSuchWidgetError(classname)
  64.  
  65.     
  66.     def invoke(self, rname, method, args = ()):
  67.         return self._cpolicy.invoke(rname, method, args)
  68.  
  69.     
  70.     def findQObjectType(self, classname):
  71.         for module in self._modules:
  72.             w = module.search(classname)
  73.             if w is not None:
  74.                 return w
  75.         
  76.  
  77.     
  78.     def getSlot(self, obj, slotname):
  79.         return self._cpolicy.getSlot(obj, slotname)
  80.  
  81.     
  82.     def addCustomWidget(self, widgetClass, baseClass, module):
  83.         for cwFilter in self._cwFilters:
  84.             (match, result) = cwFilter(widgetClass, baseClass, module)
  85.             if match:
  86.                 (widgetClass, baseClass, module) = result
  87.                 break
  88.                 continue
  89.         
  90.         self._customWidgets.addCustomWidget(widgetClass, baseClass, module)
  91.  
  92.  
  93.