def loadUiType(uiFile): import plugin.Qt as Qt if Qt.__binding__.startswith('PyQt'): from Qt import _uic as uic return uic.loadUiType(uiFile) elif Qt.__binding__ == 'PySide': import pysideuic as uic else: import pyside2uic as uic import xml.etree.ElementTree as xml from cStringIO import StringIO parsed = xml.parse(uiFile) widget_class = parsed.find('widget').get('class') form_class = parsed.find('class').text with open(uiFile, 'r') as f: o = StringIO() frame = {} uic.compileUi(f, o, indent=0) pyc = compile(o.getvalue(), '<string>', 'exec') exec pyc in frame # Fetch the base_class and form class based on their type # in the xml from designer form_class = frame['Ui_%s' % form_class] base_class = eval('%s' % widget_class) return form_class, base_class
def loadUiType(uiFile): """ Pyside "loadUiType" command like PyQt4 has one, so we have to convert the ui file to py code in-memory first and then execute it in a special frame to retrieve the form_class. """ import plugin.Qt as Qt if Qt.__binding__.startswith('PyQt'): from Qt import _uic as uic return uic.loadUiType(uiFile) elif Qt.__binding__ == 'PySide': import pysideuic as uic else: import pyside2uic as uic import xml.etree.ElementTree as xml from cStringIO import StringIO parsed = xml.parse(uiFile) widget_class = parsed.find('widget').get('class') form_class = parsed.find('class').text with open(uiFile, 'r') as f: o = StringIO() frame = {} uic.compileUi(f, o, indent=0) pyc = compile(o.getvalue(), '<string>', 'exec') exec pyc in frame # Fetch the base_class and form class based on their type # in the xml from designer form_class = frame['Ui_%s' % form_class] base_class = eval('%s' % widget_class) return form_class, base_class