当前位置: 首页>>代码示例>>Python>>正文


Python pysideuic.compileUi方法代码示例

本文整理汇总了Python中pysideuic.compileUi方法的典型用法代码示例。如果您正苦于以下问题:Python pysideuic.compileUi方法的具体用法?Python pysideuic.compileUi怎么用?Python pysideuic.compileUi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pysideuic的用法示例。


在下文中一共展示了pysideuic.compileUi方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ui2py

# 需要导入模块: import pysideuic [as 别名]
# 或者: from pysideuic import compileUi [as 别名]
def ui2py(filePath=None, *args):
    """Convert qtDesigner .ui files to .py"""

    if not filePath:
        startDir = pm.workspace(q=True, rootDirectory=True)
        filePath = pm.fileDialog2(dialogStyle=2,
                                  fileMode=1,
                                  startingDirectory=startDir,
                                  fileFilter='PyQt Designer (*%s)' % UI_EXT,
                                  okc="Compile to .py")
        if not filePath:
            return False
        filePath = filePath[0]
    if not filePath:
        return False

    if not filePath.endswith(UI_EXT):
        filePath += UI_EXT
    compiledFilePath = filePath[:-2] + "py"
    pyfile = open(compiledFilePath, 'w')
    compileUi(filePath, pyfile, False, 4, False)
    pyfile.close()

    info = "PyQt Designer file compiled to .py in: "
    pm.displayInfo(info + compiledFilePath) 
开发者ID:mgear-dev,项目名称:mgear_core,代码行数:27,代码来源:pyqt.py

示例2: loadUiType

# 需要导入模块: import pysideuic [as 别名]
# 或者: from pysideuic import compileUi [as 别名]
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.
    http://tech-artists.org/forum/showthread.php?3035-PySide-in-Maya-2013 (ChrisE)
    """
    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('QtWidgets.%s'%widget_class)
    return form_class, base_class 
开发者ID:chrisevans3d,项目名称:uExport,代码行数:24,代码来源:uExport.py

示例3: load_ui_type

# 需要导入模块: import pysideuic [as 别名]
# 或者: from pysideuic import compileUi [as 别名]
def load_ui_type(ui_file):
    if "PySide" in Qt.__binding__:
        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 = getattr(QtGui, widget_class)
        return form_class, base_class
    elif Qt.__binding__ == "PyQt4":
        import PyQt4.uic
        return PyQt4.uic.loadUiType(ui_file) 
开发者ID:cineuse,项目名称:CNCGToolKit,代码行数:24,代码来源:load_ui_type.py

示例4: loadUiType

# 需要导入模块: import pysideuic [as 别名]
# 或者: from pysideuic import compileUi [as 别名]
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
        
        #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 
开发者ID:patcorwin,项目名称:fossil,代码行数:23,代码来源:ui.py

示例5: loadUiType

# 需要导入模块: import pysideuic [as 别名]
# 或者: from pysideuic import compileUi [as 别名]
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 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:35,代码来源:Qt.py

示例6: _qt_import

# 需要导入模块: import pysideuic [as 别名]
# 或者: from pysideuic import compileUi [as 别名]
def _qt_import(binding, shi=False, cui=False):
    QtGui = None
    QtCore = None
    QtWidgets = None
    wrapInstance = None

    if binding == "PySide2":
        from PySide2 import QtGui, QtCore, QtWidgets
        import shiboken2 as shiboken
        from shiboken2 import wrapInstance
        from pyside2uic import compileUi

    elif binding == "PySide":
        from PySide import QtGui, QtCore
        import PySide.QtGui as QtWidgets
        import shiboken
        from shiboken import wrapInstance
        from pysideuic import compileUi

    elif binding == "PyQt4":
        from PyQt4 import QtGui
        from PyQt4 import QtCore
        import PyQt4.QtGui as QtWidgets
        from sip import wrapinstance as wrapInstance
        from PyQt4.uic import compileUi
        print("Warning: 'shiboken' is not supported in 'PyQt4' Qt binding")
        shiboken = None

    else:
        raise Exception("Unsupported python Qt binding '%s'" % binding)

    rv = [QtGui, QtCore, QtWidgets, wrapInstance]
    if shi:
        rv.append(shiboken)
    if cui:
        rv.append(compileUi)
    return rv 
开发者ID:mgear-dev,项目名称:mgear_core,代码行数:39,代码来源:pyqt.py

示例7: loadUiType

# 需要导入模块: import pysideuic [as 别名]
# 或者: from pysideuic import compileUi [as 别名]
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), {}) 
开发者ID:dreamworksanimation,项目名称:usdmanager,代码行数:52,代码来源:utils.py

示例8: load_ui_type

# 需要导入模块: import pysideuic [as 别名]
# 或者: from pysideuic import compileUi [as 别名]
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 
开发者ID:mottosso,项目名称:Qt.py,代码行数:44,代码来源:baseinstance2.py


注:本文中的pysideuic.compileUi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。