當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。