本文整理匯總了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)
示例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
示例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)
示例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
示例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
示例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
示例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), {})
示例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