SHARE
TWEET

PyQt4 pyuic error

a guest Mar 9th, 2011 179 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Copyright (c) 2010 Riverbank Computing Limited.
  2. # Copyright (c) 2006 Torsten Marek.
  3.  
  4.  
  5. import sys
  6. import os.path
  7.  
  8. from PyQt4.uic.exceptions import NoSuchWidgetError, WidgetPluginError
  9.  
  10. if sys.hexversion >= 0x03000000:
  11.     from PyQt4.uic.port_v3.load_plugin import load_plugin
  12. else:
  13.     from PyQt4.uic.port_v2.load_plugin import load_plugin
  14.  
  15.  
  16. # The list of directories that are searched for widget plugins.  This is
  17. # exposed as part of the API.
  18. widgetPluginPath = [os.path.join(os.path.dirname(__file__), 'widget-plugins')]
  19.  
  20.  
  21. MATCH = True
  22. NO_MATCH = False
  23. MODULE = 0
  24. CW_FILTER = 1
  25.  
  26.  
  27. class QObjectCreator(object):    
  28.     def __init__(self, creatorPolicy):
  29.         self._cpolicy = creatorPolicy
  30.  
  31.         self._cwFilters = []
  32.         self._modules = [self._cpolicy.createQtGuiWrapper()]
  33.  
  34.         # Get the optional plugins.
  35.         for plugindir in widgetPluginPath:
  36.             try:
  37.                 plugins = os.listdir(plugindir)
  38.             except:
  39.                 plugins = []
  40.  
  41.             for filename in plugins:
  42.                 if not filename.endswith('.py'):
  43.                     continue
  44.  
  45.                 filename = os.path.join(plugindir, filename)
  46.  
  47.                 plugin_globals = {
  48.                     "MODULE": MODULE,
  49.                     "CW_FILTER": CW_FILTER,
  50.                     "MATCH": MATCH,
  51.                     "NO_MATCH": NO_MATCH}
  52.  
  53.                 plugin_locals = {}
  54.  
  55.                 if load_plugin(open(filename), plugin_globals, plugin_locals):
  56.                     return # Esto está puesto para que no falle
  57.                     pluginType = plugin_locals["pluginType"]
  58.                     if pluginType == MODULE:
  59.                         modinfo = plugin_locals["moduleInformation"]()
  60.                         self._modules.append(self._cpolicy.createModuleWrapper(*modinfo))
  61.                     elif pluginType == CW_FILTER:
  62.                         self._cwFilters.append(plugin_locals["getFilter"]())
  63.                     else:
  64.                         raise WidgetPluginError("Unknown plugin type of %s" % filename)
  65.  
  66.         self._customWidgets = self._cpolicy.createCustomWidgetLoader()
  67.         self._modules.append(self._customWidgets)
  68.  
  69.     def createQObject(self, classname, *args, **kwargs):
  70.         classType = self.findQObjectType(classname)
  71.         if classType:
  72.             return self._cpolicy.instantiate(classType, *args, **kwargs)
  73.         raise NoSuchWidgetError(classname)
  74.  
  75.     def invoke(self, rname, method, args=()):
  76.         return self._cpolicy.invoke(rname, method, args)
  77.  
  78.     def findQObjectType(self, classname):
  79.         for module in self._modules:
  80.             w = module.search(classname)
  81.             if w is not None:
  82.                 return w
  83.         return None
  84.  
  85.     def getSlot(self, obj, slotname):
  86.         return self._cpolicy.getSlot(obj, slotname)
  87.  
  88.     def addCustomWidget(self, widgetClass, baseClass, module):
  89.         for cwFilter in self._cwFilters:
  90.             match, result = cwFilter(widgetClass, baseClass, module)
  91.             if match:
  92.                 widgetClass, baseClass, module = result
  93.                 break
  94.  
  95.         self._customWidgets.addCustomWidget(widgetClass, baseClass, module)
RAW Paste Data
Top