예제 #1
0
파일: uiloader.py 프로젝트: dbarsam/kousen
    def loadUiType(cls, uifile, respath=None):
        """
        Pyside lacks the "loadUiType" command, 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.
        """
        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 = {}

            pysideuic.compileUi(f, o, indent=0)
            pyc = compile(o.getvalue(), '<string>', 'exec')

            hasres = respath and respath not in sys.path
            if hasres:
                sys.path.append(respath)

            exec(pyc, frame)

            if hasres:
                sys.path.remove(respath)

            #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('PySide.QtGui.%s'%widget_class)
        return form_class, base_class
예제 #2
0
    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 pysideuic
        import xml.etree.ElementTree as xml
        #from io 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 = {}

            pysideuic.compileUi(f, o, indent=0)
            pyc = compile(o.getvalue(), '<string>', 'exec')
            exec(pyc, 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('QtGui.%s' % widget_class)

        return form_class, base_class
예제 #3
0
def get_pyside_class( ui_file ):
   """
   Pablo Winant
   """

   parsed = xml.parse( ui_file )
   #print parsed
   widget_class = parsed.find( 'widget' ).get( 'class' )
   form_class = parsed.find( 'class' ).text
   #print widget_class, form_class
   with open( ui_file, 'r' ) as f:
      print f
      o = StringIO()
      frame = {}
      try:
         pysideuic.compileUi( f, o, indent = 0 )
      except:
         print 'errroorrrrr'

      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_{0}'.format( form_class )]
      base_class = eval( 'QtGui.{0}'.format( widget_class ) )
      
   return form_class, base_class
예제 #4
0
def _load_ui_type(ui_file):
    """Load a ui file for PySide.

    PySide lacks the "_load_ui_type" command, so we have to convert
    the UI file to python code in-memory first and then execute it in a
    special frame to retrieve the form_class.
    Args:
        ui_file (str): The .ui file.
    Returns:
        The base and form class, derived from the .ui file.
    """
    parsed = xml.parse(ui_file)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text
    with open(ui_file, 'r') as f:
        o = StringIO()
        frame = {}

        pysideuic.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
        base_class = getattr(QtWidgets, widget_class)
        form_class = frame['Ui_%s' % form_class]
        return base_class, form_class
예제 #5
0
def get_pyside_class(ui_file):
    """
   Pablo Winant
   """

    parsed = xml.parse(ui_file)
    #print parsed
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text
    #print widget_class, form_class
    with open(ui_file, 'r') as f:
        print f
        o = StringIO()
        frame = {}
        try:
            pysideuic.compileUi(f, o, indent=0)
        except:
            print 'errroorrrrr'

        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_{0}'.format(form_class)]
        base_class = eval('QtGui.{0}'.format(widget_class))

    return form_class, base_class
예제 #6
0
def loadUi(uifile, widget):
    """
    Load .ui file into widget

    @param uifile: filename
    @type uifile: str
    @type widget: QtWidgets.QWidget
    """
    if PYQT_NAME != 'PySide':
        m = __import__(PYQT_NAME + '.uic')
        return m.uic.loadUi(uifile, widget)

    import io, pysideuic
    stream = io.BytesIO()
    pysideuic.compileUi(uifile, stream)
    ns_locals = {}
    exec(stream.getvalue(), None, ns_locals)

    if 'Ui_Form' in ns_locals:
        form = ns_locals['Ui_Form']()
    else:
        form = ns_locals['Ui_Dialog']()

    form.setupUi(widget)
    return form
예제 #7
0
파일: helpers.py 프로젝트: csaez/wishlib
def loadUiType(ui_file):
    from wishlib.qt import active, QtGui
    if active == "PySide":
        import pysideuic
        parsed = xml.parse(ui_file)
        widget_class = parsed.find('widget').get('class')
        form_class = parsed.find('class').text

        with open(ui_file, 'r') as f:
            o = StringIO()
            frame = {}

            pysideuic.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('QtGui.%s' % widget_class)
            base_class = getattr(QtGui, widget_class)
        return form_class, base_class
    elif active == "PyQt4":
        from PyQt4 import uic
        return uic.loadUiType(ui_file)
    return None
예제 #8
0
    def loadUiType(cls, uifile, respath=None):
        """
        Pyside lacks the "loadUiType" command, 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.
        """
        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 = {}

            pysideuic.compileUi(f, o, indent=0)
            pyc = compile(o.getvalue(), '<string>', 'exec')

            hasres = respath and respath not in sys.path
            if hasres:
                sys.path.append(respath)

            exec(pyc, frame)

            if hasres:
                sys.path.remove(respath)

            #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('PySide.QtGui.%s' % widget_class)
        return form_class, base_class
예제 #9
0
    def loadUiType(ui_file):
        """
        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.
        """

        parsed = xml.parse(ui_file)
        widget_class = parsed.find('widget').get('class')
        form_class = parsed.find('class').text

        with open(ui_file, 'r') as f:
            stringioval = StringIO()
            frame = {}

            uic.compileUi(f, stringioval, indent=0)
            pyc = compile(stringioval.getvalue(), '<string>', 'exec')
            exec(pyc, 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('QtWidgets.%s' % widget_class)

        return form_class, base_class
예제 #10
0
def compile_file(in_path, out_path):
    """
    Compile a .ui file into a .py file.

    :param in_path: Input .ui file path.
    :type in_path: basestring

    :param out_path: Output .py file path.
    :type out_path: basestring

    :returns: Nothing.
    """
    if in_path.endswith('.ui') is False:
        print('Warning: Skipping %r' % in_path)
        return
    if not os.path.isfile(in_path):
        print('Warning: Skipping: %r' % in_path)
        return
    in_dir, in_name = os.path.split(in_path)
    out_dir, out_name = os.path.split(out_path)

    msg = 'Compiling: {0} -> {1}'
    print(msg.format(in_name, out_name))
    try:
        f = open(out_path, 'w')
        compileUi(in_path, f, False, 4, False)
        f.close()
    except Exception:
        print('Warning: File did not compile, %r' % in_path)
        raise
    return
예제 #11
0
    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.

        from stackoverflow: http://stackoverflow.com/a/14195313/3781327

        seems like this might also be a legitimate solution, but I'm not sure
        how to make PyQt4 and pyside look the same...
            http://stackoverflow.com/a/8717832
        """
        import pysideuic
        import xml.etree.ElementTree as xml
        #from io 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 = {}

            pysideuic.compileUi(f, o, indent=0)
            pyc = compile(o.getvalue(), '<string>', 'exec')
            exec(pyc, 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('QtGui.%s' % widget_class)

        return form_class, base_class
예제 #12
0
def loadUiType(ui_file):
    """
    Pyside lacks the "loadUiType" command, 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.
    """
    
    parsed = xml.parse(ui_file)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text
    
    with open(ui_file, 'r') as f:
        o = StringIO()
        frame = {}
    
        pysideuic.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('QtGui.%s' % widget_class)
    
    return form_class, base_class    
예제 #13
0
def load_ui_type(UI_FILE):
	'''
	Pyside lacks the "load_ui_type" command, 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.
	'''
	parsed = xml.parse(UI_FILE)
	widget_class = parsed.find('widget').get('class')
	form_class = parsed.find('class').text

	with open(UI_FILE, 'r') as f:
		o = StringIO()
		frame = {}

		if QT_BINDINGS == 'PySide':
			pysideuic.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('QtGui.%s'%widget_class)
		elif QT_BINDINGS == 'PyQt':
			form_class = PyQtFixer
			base_class = QtGui.QMainWindow
	return form_class, base_class
def _load_ui_type(ui_file):
    """Load a ui file for PySide.

    PySide lacks the "_load_ui_type" command, so we have to convert
    the UI file to python code in-memory first and then execute it in a
    special frame to retrieve the form_class.
    Args:
        ui_file (str): The .ui file.
    Returns:
        The base and form class, derived from the .ui file.
    """
    parsed = xml.parse(ui_file)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text
    with open(ui_file, 'r') as f:
        o = StringIO()
        frame = {}

        pysideuic.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
        base_class = getattr(QtWidgets, widget_class)
        form_class = frame['Ui_%s' % form_class]
        return base_class, form_class
예제 #15
0
파일: ui.py 프로젝트: Mikfr83/fossil
def loadUiType(uiFile):
    '''
    Pyside lacks the "loadUiType" command, 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.
    '''
    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 = {}

        pysideuic.compileUi(f, o, indent=0)
        pyc = compile(o.getvalue(), '<string>', 'exec')

        if PY_2:
            exec('''pyc in frame''')
        else:
            exec(pyc, 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('QtGui.%s' % widget_class)
    return form_class, base_class
예제 #16
0
def loadUiType(fileVar, subFolder="ui", uiName=None):
    """
	To use this, pass the path to a UI file, and capture the output
	as FormClass and BaseClass.  Define your class inheriting from both
	and call self.setupUi(self) in the __init__
	"""
    uiFolder, filename = os.path.split(fileVar)
    if uiName is None:
        uiName = os.path.splitext(filename)[0]
    if subFolder:
        uiFile = os.path.join(uiFolder, subFolder, uiName + ".ui")

    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_{0}'.format(form_class)]

        try:
            base_class = eval('QtGui.{0}'.format(widget_class))
        except:
            base_class = eval('QtWidgets.{0}'.format(widget_class))

    return form_class, base_class
예제 #17
0
def loadUiType(ui_file):
        """
        Pyside lacks the "loadUiType" command, 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.

        Usage:

            >>> class SomeDialog(loadUiType('some_dialog.ui')):
            >>>     def __init__(self, *args, **kwargs):
            >>>         super(SomeDialog, self).__init__(*args, **kwargs)

        """
        parsed = xml.parse(ui_file)
        widget_class = parsed.find('widget').get('class')
        form_class = parsed.find('class').text

        with open(ui_file, 'r') as f:
            o = StringIO()
            frame = {}

            pysideuic.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('QtGui.%s' % widget_class)
        return type('PySideUI', (form_class, base_class), {})
예제 #18
0
파일: Qt.py 프로젝트: mainczjs/Playground
    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.

        from stackoverflow: http://stackoverflow.com/a/14195313/3781327

        seems like this might also be a legitimate solution, but I'm not sure
        how to make PyQt4 and pyside look the same...
            http://stackoverflow.com/a/8717832
        """
        import pysideuic
        import xml.etree.ElementTree as xml

        # from io 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 = {}

            pysideuic.compileUi(f, o, indent=0)
            pyc = compile(o.getvalue(), "<string>", "exec")
            exec(pyc, 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("QtGui.%s" % widget_class)

        return form_class, base_class
예제 #19
0
    def compile_ui(self, ui_file, py_file=None):
        """Compile the .ui files to python modules."""
        self._wrapuic(i18n_module=self.i18n_module)
        if py_file is None:
            py_file = os.path.join(
                self.output_dir,
                os.path.basename(ui_file).replace(
                    '.ui', self.generated_extension
                ).lower()
            )

        fi = open(ui_file, 'r')
        fo = open(py_file, 'wt')
        try:
            from pysideuic import compileUi
            compileUi(fi, fo, execute=self.ui_execute, indent=self.indent,
                      from_imports=self.from_imports)
            log.info("Compiled %s into %s", ui_file, py_file)
        except ImportError:
            log.warn("You need to have pyside-tools installed in order to "
                     "compile .ui files.")
        except Exception, err:
            log.warn("Failed to generate %r from %r: %s", py_file, ui_file, err)
            if not os.path.exists(py_file) or not not file(py_file).read():
                raise SystemExit(1)
            return
예제 #20
0
파일: Qt.py 프로젝트: jensengrouppsu/rapid
    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 pysideuic
        import xml.etree.ElementTree as xml
        #from io 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 = {}

            pysideuic.compileUi(f, o, indent=0)
            pyc = compile(o.getvalue(), '<string>', 'exec')
            exec(pyc, 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('QtGui.%s'%widget_class)

        return form_class, base_class
def loadUiType(uiFile):
    """
	Pyside lacks the "loadUiType" command, 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.
	"""
    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 = {}

        if QtType == "PySide":
            pysideuic.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("QtGui.%s" % widget_class)
        elif QtType == "PyQt":
            form_class = PyQtFixer
            base_class = QtGui.QMainWindow
    return form_class, base_class
예제 #22
0
def generateUi(uifname, pyfname, execute, indent):
    if pyfname == "-":
        pyfile = sys.stdout
    else:
        pyfile = file(pyfname, "w")

    pysideuic.compileUi(uifname, pyfile, execute, indent)
    return 0
예제 #23
0
파일: pyside-uic.py 프로젝트: csaez/mauto
def convert(input_file):
    if not input_file.endswith(".ui"):
        return False
    output_file = os.path.join(os.path.dirname(input_file),
                               os.path.basename(input_file).replace(".ui", ".py"))
    with open(output_file, 'w') as fp:
        compileUi(input_file, fp, False, 4, False)
    return output_file
예제 #24
0
파일: utils.py 프로젝트: kissinger31/May9
def compileUI():
	from pysideuic import compileUi
	
	moduleName = __name__.split('.')[0]
	modulePath = os.path.abspath(imp.find_module(moduleName)[1])
	pyfile = open(modulePath+'\\mainWindow.py', 'w')
	compileUi(modulePath+"\\mainWindow.ui", pyfile, False, 4,False)
	pyfile.close()
예제 #25
0
def pysdieConvert():
    """
	@convert ui file to the python file
	"""
    uiPath = mc.fileDialog2(ff="*ui", dialogStyle=1, fileMode=1)[0]
    pyPath = uiPath.replace(".ui", "_ui.py")
    pyFile = open(pyPath, "w")
    compileUi(uiPath, pyFile, False, 4, False)
    pyFile.close()
예제 #26
0
파일: pyside-uic.py 프로젝트: Aserun/mauto
def convert(input_file):
    if not input_file.endswith(".ui"):
        return False
    output_file = os.path.join(
        os.path.dirname(input_file),
        os.path.basename(input_file).replace(".ui", ".py"))
    with open(output_file, 'w') as fp:
        compileUi(input_file, fp, False, 4, False)
    return output_file
예제 #27
0
def compileUIFiles(uiDir):
    for name in os.listdir(uiDir):
        uiFilePath = os.path.join(uiDir, name)

        if os.path.isfile(uiFilePath):
            if name.endswith(".ui"):
                uiResultPath = (name[:-3] + ".py").lower()

                with open(os.path.join(uiDir, uiResultPath), "w") as f:
                    compileUi(uiFilePath, f)
예제 #28
0
def compileUIFiles(uiDir):
    for name in os.listdir(uiDir):
        uiFilePath = os.path.join(uiDir, name)

        if os.path.isfile(uiFilePath):
            if name.endswith(".ui"):
                uiResultPath = (name[:-3] + ".py").lower()

                with open(os.path.join(uiDir, uiResultPath), "w") as f:
                    compileUi(uiFilePath, f)
예제 #29
0
def _loadUiType(uiFile):
    """
    PySide lacks a "loadUiType" command like PyQt4's, 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.

    from stackoverflow: http://stackoverflow.com/a/14195313/3781327

    seems like this might also be a legitimate solution, but I'm not sure
    how to make PyQt4 and pyside look the same...
        http://stackoverflow.com/a/8717832
    """

    if QT_LIB == "PYSIDE":
        import pysideuic
    else:
        try:
            import pyside2uic as pysideuic
        except ImportError:
            # later vserions of pyside2 have dropped pysideuic; use the uic binary instead.
            pysideuic = None

    # get class names from ui file
    import xml.etree.ElementTree as xml
    parsed = xml.parse(uiFile)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text

    # convert ui file to python code
    if pysideuic is None:
        if QT_LIB == PYSIDE2:
            pyside2version = tuple(map(int, PySide2.__version__.split(".")))
            if pyside2version >= (5, 14) and pyside2version < (5, 14, 2, 2):
                warnings.warn(
                    'For UI compilation, it is recommended to upgrade to PySide >= 5.15'
                )
        uic_executable = QT_LIB.lower() + '-uic'
        uipy = subprocess.check_output([uic_executable, uiFile])
    else:
        o = _StringIO()
        with open(uiFile, 'r') as f:
            pysideuic.compileUi(f, o, indent=0)
        uipy = o.getvalue()

    # exceute python code
    pyc = compile(uipy, '<string>', 'exec')
    frame = {}
    exec(pyc, 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('QtGui.%s' % widget_class)

    return form_class, base_class
예제 #30
0
파일: ui_to_py.py 프로젝트: k0k0c/scripts
def rebuild_pyui_file(filename):
    uifile_patch = LTK_PATCH + LGT_UI_PATCH + filename
    pyfile_patch = LTK_PATCH + LGT_PYUI_PATCH + filename.split(".")[0] + ".py"
    uifile_time = os.path.getmtime(uifile_patch)
    pyfile_time = os.path.isfile(pyfile_patch) == True and os.path.getmtime(pyfile_patch) or 0
    if pyfile_time < uifile_time:
        uifile = open(uifile_patch, "r")
        pyfile = open(pyfile_patch, "w")
        uic.compileUi(uifile, pyfile)
        print "RECOMPILE: " + LTK_PATCH + LGT_UI_PATCH + filename
        uifile.close()
        pyfile.close()
예제 #31
0
def load_ui_type(ui_file):
    """
    Pyside lacks the "loadUiType" command, 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.
    This function return the form and base classes for the given qtdesigner ui file.
    """

    # add path for pysideuic
    import sys
    sys.path.append(THIRD_PARTY_PATH)

    # lazy import

    try:
        # python
        import os
        import logging
        import re
        import shutil
        from cStringIO import StringIO
        import xml.etree.ElementTree as xml
        import types
        # PySide
        from PySide import QtGui
        from PySide import QtCore
        from PySide import QtUiTools
        import pysideuic

    except Exception as exception_instance:
        # log
        logger.debug('Import failed: {0}'.format(exception_instance))
        # return None
        return None

    # compile ui

    parsed = xml.parse(ui_file)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text

    with open(ui_file, 'r') as f:
        o = StringIO()
        frame = {}

        pysideuic.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('QtGui.%s' % widget_class)

    return form_class, base_class
예제 #32
0
def rebuild_pyui_file(filename):
    uifile_patch = LTK_PATCH + LGT_UI_PATCH + filename
    pyfile_patch = LTK_PATCH + LGT_PYUI_PATCH + filename.split(".")[0] + ".py"
    uifile_time = os.path.getmtime(uifile_patch)
    pyfile_time = os.path.isfile(pyfile_patch) == True and os.path.getmtime(
        pyfile_patch) or 0
    if pyfile_time < uifile_time:
        uifile = open(uifile_patch, "r")
        pyfile = open(pyfile_patch, "w")
        uic.compileUi(uifile, pyfile)
        print "RECOMPILE: " + LTK_PATCH + LGT_UI_PATCH + filename
        uifile.close()
        pyfile.close()
예제 #33
0
def compile_if_necessary(input_ui_file,output_py_file):
    #prepare the file names
    input_path = module_folder+input_ui_file
    output_path = module_folder+output_py_file
    #recompile the .ui Qt file if this script is launched directly
    #or if the compiled .py GUI file does not exist
    #or if it is more recent than the compiled .py GUI file,
    #if __name__=='__main__' or not(os.path.isfile(output_path)) or os.path.getmtime(input_path)>os.path.getmtime(output_path):
    if not(os.path.isfile(output_path)) or os.path.getmtime(input_path)>os.path.getmtime(output_path):
        print "update detected: recompiling "+input_ui_file
        f=open(output_path,"w")
        pysideuic.compileUi(input_path,f)
        f.close()    
예제 #34
0
def loadUiType(uiFile):
    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 = {}
        pysideuic.compileUi(f, o, indent=0)
        pyc = compile(o.getvalue(), '<string>', 'exec')
        exec pyc in frame
        form_class = frame['Ui_%s' % form_class]
        base_class = getattr(QtWidgets, widget_class)
    return form_class, base_class
def main():
    for root, dirs, files in os.walk(os.path.abspath(CURRENT_DIR)):
        for f in files:
            print f
            if f.lower().endswith(".qrc"):
                name = os.path.basename(f).split(".")[0] + ".py"
                subprocess.call([PYSIDE_RCC_EXE, os.path.join(root, f), "-o", os.path.join(OUTPUT_DIR, name)])

            if f.lower().endswith(".ui"):
                name = os.path.basename(f).split(".")[0] + ".py"
                ui_path = os.path.join(root, f)
                pyfile = open(os.path.join(OUTPUT_DIR, name), 'w')
                compileUi(ui_path, pyfile, False, 4, False)
                pyfile.close()
예제 #36
0
파일: utils.py 프로젝트: iVerb/usdmanager
def loadUiType(uiFile, sourceFile=None, className="DefaultWidgetClass"):
    """ Used to define a custom widget's class.
    
    :Parameters:
        uiFile : `str`
            UI file path. Can be relative if loading from the same directory as sourceFile.
        sourceFile : `str`
            File path of loading module.
            Used to help find embedded resources and to find uiFile when the file path is relative.
        className : `str`
            Class name
    :Returns:
        Class type
    :Rtype:
        `type`
    """
    import sys
    import xml.etree.ElementTree as xml
    from StringIO import StringIO
    from Qt import QtWidgets

    if not os.path.exists(uiFile) and not os.path.isabs(uiFile):
        if sourceFile is None:
            uiFile = resource_filename(__name__, uiFile)
            sourceDir = os.path.dirname(uiFile)
        else:
            sourceDir = os.path.dirname(sourceFile)
            uiFile = os.path.join(sourceDir, uiFile)
    else:
        sourceDir = os.path.dirname(uiFile)

    # Search for resources in this tool's directory.
    if sourceDir not in sys.path:
        sys.path.insert(0, sourceDir)

    parsed = xml.parse(uiFile)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text

    with open(uiFile) 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.
        form_class = frame["Ui_{}".format(form_class)]
        base_class = eval("QtWidgets.{}".format(widget_class))
    return type("{}Base".format(className), (form_class, base_class), {})
예제 #37
0
파일: loadUI.py 프로젝트: RobRuckus/rcTools
def load_ui_type(ui_file):
	parsed= xml.parse(ui_file)
	widget_class =parsed.find('widget').get('class')
	form_class =parsed.find('class').text
	with open(ui_file,'r') as f:
		o= StringIO()
		frame={}
		
		pysideuic.compileUi(f,o,indent=0)
		pyc= compile(o.getvalue(), '<string>',  'exec')
		exec pyc in frame
		
		form_class = frame ['Ui_{0}'.format (form_class)]
		base_class = eval( 'QtGui.{0}'.format(widget_class))
	return form_class, base_class
예제 #38
0
def convertUItoPython(filePath):
	'''
	PyQt Designer: Convert .ui file to .py file
	filePath: str 'D:\Google Drive\My3DWork\QtDesigner\bulletUi.ui'
	Returns:

	'''
	import sys, pprint
	from pysideuic import compileUi
	filePath = filePath.replace('\\', '/')
	print 'converting %s'%filePath
	pyfilePath = filePath.replace('.ui', '.py')
	pyfile = open(pyfilePath, 'w')
	compileUi(filePath, pyfile, False, 4,False)
	pyfile.close()
예제 #39
0
def compile_ui(uifile):
    """Compile the given Qt designer file. The compiled file will be in the same directory but ends with _ui.py.

    :param uifile: filepath to the uifile
    :type uifile: str
    :returns: None
    :rtype: None
    :raises: None
    """
    print "Compileing: %s" % uifile
    outputpath = uifile.rsplit(os.path.extsep, 1)[0] + "_ui.py"
    print "Outputfile: %s" % outputpath
    outputfile = open(os.path.abspath(outputpath), "w")
    pysideuic.compileUi(os.path.abspath(uifile), outputfile)
    print "Done!"
예제 #40
0
def compileAllUis(p_sInitPath):
	sDirFiles = os.listdir(p_sInitPath)
	for sFile in sDirFiles:
		if (os.path.splitext(sFile)[1] == ".ui"):
			sUiFile = os.path.join(p_sInitPath, sFile) 
			sPyUiFilePath = os.path.join(p_sInitPath, ((os.path.splitext(sFile)[0]) + "_ui.py"))
			# print sUiFile
			# print sPyUiFilePath
			fPyUiFile = open(sPyUiFilePath, "w")
			pui.compileUi(sUiFile, fPyUiFile)
			fPyUiFile.close()
	
	sSubdirs = io.getImmediateSubdirectories(p_sInitPath)
	for sPath in sSubdirs:
		compileAllUis(sPath)
예제 #41
0
파일: setup.py 프로젝트: dacut/ret
    def run(self):
        if self.pyside_ui_dirs is not None:
            from pysideuic import compileUi
            for ui_dir in self.pyside_ui_dirs:
                for ui_file in listdir(ui_dir):
                    if not ui_file.endswith(".ui"):
                        continue
                    ui_path = path_join(ui_dir, ui_file)
                    py_file = "Ui_" + splitext(ui_file)[0] + ".py"
                    py_path = path_join(ui_dir, py_file)

                    if newer(ui_path, py_path):
                        log.info("pysideuic %s -> %s", ui_path, py_path)
                        with open(ui_path, "r") as ifd:
                            with open(py_path, "w") as ofd:
                                compileUi(ifd, ofd)
예제 #42
0
    def _generate(self):
        """ Generate the Python code. """

        if sys.hexversion >= 0x03000000:
            if self._opts.output == '-':
                from io import TextIOWrapper

                pyfile = TextIOWrapper(sys.stdout.buffer, encoding='utf8')
            else:
                pyfile = open(self._opts.output, 'wt', encoding='utf8')
        else:
            if self._opts.output == '-':
                pyfile = sys.stdout
            else:
                pyfile = open(self._opts.output, 'wt')

        compileUi(self._ui_file, pyfile, self._opts.execute, self._opts.indent, self._opts.from_imports)
예제 #43
0
    def convertFile(self, *args):
        if self.filePathName is not None and self.textInput.getText() != '':
            import sys, pprint
            from pysideuic import compileUi

            drive, path = os.path.splitdrive(self.filePathName)
            path, filename = os.path.split(path)
            outFilePath = drive + path + "/" + self.textInput.getText()
            #print ("%s , %s , %s" % (drive,path,filename))

            pyfile = open(outFilePath, 'w')
            compileUi(self.filePathName, pyfile, False, 4, False)
            pyfile.close()
        elif self.textInput.getText() == '':
            print "No output Filename"
        else:
            print "No File Selected"
예제 #44
0
def loadUiType(uiFile):
    """
	Pyside lacks the "loadUiType" command, 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.
	"""
    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 = {}
        pysideuic.compileUi(f, o, indent=0)
        pyc = compile(o.getvalue(), '<string>', 'exec')
        exec pyc in frame
        form_class = frame['Ui_%s' % form_class]
        base_class = getattr(QtWidgets, widget_class)
    return form_class, base_class
예제 #45
0
def loadUiType(uiFile):
    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 = {}

        pysideuic.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('QtGui.%s' % widget_class)
    return form_class, base_class
예제 #46
0
def get_pyside_class(ui_file):
    parsed = xml.parse(ui_file)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text

    with open(ui_file, 'r') as f:
        o = StringIO()
        frame = {}

        pysideuic.compileUi(f, o, indent=0)
        pyc = compile(o.getvalue(), '<string>', 'exec')
        exec pyc in frame

        form_class = frame['Ui_{0}'.format(form_class)]
        base_class = eval('QtGui.{0}'.format(widget_class))

    return form_class, base_class
예제 #47
0
def compile_file(in_path, out_path):
    if not os.path.isfile(in_path):
        print('Warning: Skipping', in_path)
        return
    in_dir, in_name = os.path.split(in_path)
    out_dir, out_name = os.path.split(out_path)

    print('Compiling:', in_name, '->', out_name)
    try:
        f = open(out_path, 'w')
        compileUi(in_path, f, False, 4, False)
        f.close()
    except Exception as e:
        print('Warning: File did not compile, %r' % in_path)
        # print e
        raise
    return
예제 #48
0
def load_ui_type(filename):
  """Loads and parses ui file created by Qt Designer"""
  xml = ElementTree.parse(filename)
  # pylint: disable=no-member
  form_class = xml.find('class').text

  with open(filename, 'r') as ui_file:
    output_stream = StringIO()
    frame = {}

    pysideuic.compileUi(ui_file, output_stream, indent=0)
    compiled = compile(output_stream.getvalue(), '<string>', 'exec')
    # pylint: disable=exec-used
    exec compiled in frame

    form_class = frame['Ui_%s'%form_class]

  return form_class
예제 #49
0
파일: compiler.py 프로젝트: mkolar/Tapp
    def initUI(self):

        fileName = QtGui.QFileDialog.getOpenFileName(self, 'Open UI File',
                                                     '../..', 'UI File (*.ui)')
        if fileName:
            uiFile = open(fileName[0], 'r')

            parentdir = os.path.abspath(os.path.join(fileName[0], os.pardir))
            filename = os.path.basename(os.path.splitext(fileName[0])[0])

            pyFile = open(os.path.join(parentdir, filename) + '.py', 'w')

            pysideuic.compileUi(uiFile, pyFile)

            uiFile.close()
            pyFile.close()

        sys.exit(0)
예제 #50
0
def _load_ui_type(filename):
    """Loads and parses ui file created by Qt Designer"""
    xml = ElementTree.parse(filename)
    # pylint: disable=no-member
    form_class = xml.find('class').text

    with open(filename, 'r') as ui_file:
        output_stream = StringIO()
        frame = {}

        pysideuic.compileUi(ui_file, output_stream, indent=0)
        compiled = compile(output_stream.getvalue(), '<string>', 'exec')
        # pylint: disable=exec-used
        exec compiled in frame

        form_class = frame['Ui_%s' % form_class]

    return form_class
예제 #51
0
def LoadUiType(uiFile):
	# LoadUiType only accept ascii encoding chars
	uiFile = str(uiFile)
	parsed = exml.parse(uiFile)
	widget_class = parsed.find('widget').get('class')
	ui_class_name = parsed.find('class').text
	with open(uiFile, 'r') as f:
		o = BytesIO()
		frame = {}
		pysideuic.compileUi(f, o)
		pyc = compile(o.getvalue(), '<string>', 'exec')
		exec pyc in frame
		ui_class = frame['Ui_%s' % ui_class_name]
		print str(ui_class)
		base_class = eval(widget_class)
		print str(base_class)

	return ui_class, base_class
예제 #52
0
    def initUI(self):

        fileName = QtGui.QFileDialog.getOpenFileName(self, 'Open UI File',
                                                     '../..', 'UI File (*.ui)')
        if fileName:
            uiFile = open(fileName[0], 'r')

            parentdir = os.path.abspath(os.path.join(fileName[0], os.pardir))
            filename = os.path.basename(os.path.splitext(fileName[0])[0])

            pyFile = open(os.path.join(parentdir, filename) + '.py', 'w')

            pysideuic.compileUi(uiFile, pyFile)

            uiFile.close()
            pyFile.close()

        sys.exit(0)
예제 #53
0
def loadUiType( uiFile ):
    if default ==  "pyqt4":
        form_class, base_class =  uic.loadUiType( uiFile )
    else:
        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 = {}

            pysideuic.compileUi( f, o, indent=0 )
            pyc = compile( o.getvalue(), '<string>', 'exec' )
            exec pyc in frame

            form_class = frame[ 'Ui_%s'%form_class ]
            base_class = eval( '%s'%widget_class )
    return form_class, base_class
예제 #54
0
	def loadUiType(self):
		parsed = xml.parse(self.uiFile)
		widget_class = parsed.find('widget').get('class')
		form_class = parsed.find('class').text

		with open(self.uiFile, 'r') as f:
			o = StringIO()
			frame = {}

			
			pysideuic.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
			self.form_class = frame['Ui_%s'%form_class]
			self.base_class = eval('QtGui.%s'%widget_class)

		return self.form_class, self.base_class
예제 #55
0
def loadUiType(uiFile):
    """
    Pablo Winant
    """
    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 = {}
        
        pysideuic.compileUi(f, o, indent=0)
        pyc = compile(o.getvalue(), '<string>', 'exec')
        exec pyc in frame
        
        form_class = frame['Ui_%s'%form_class]
        base_class = eval('QtGui.%s'%widget_class)
    return form_class, base_class
예제 #56
0
def load_ui_type(uifile):
    """Pyside equivalent for the loadUiType function in PyQt.

    From the PyQt4 documentation:
        Load a Qt Designer .ui file and return a tuple of the generated form
        class and the Qt base class. These can then be used to create any
        number of instances of the user interface without having to parse the
        .ui file more than once.

    Note:
        Pyside lacks the "loadUiType" command, 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.

    Args:
        uifile (str): Absolute path to .ui file


    Returns:
        tuple: the generated form class, the Qt base class
    """
    import pysideuic
    import xml.etree.ElementTree as ElementTree
    from cStringIO import StringIO

    parsed = ElementTree.parse(uifile)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text

    with open(uifile, 'r') as f:
        o = StringIO()
        frame = {}

        pysideuic.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('QtWidgets.%s' % widget_class)
    return form_class, base_class