def loadUiType(uifile, from_imports=False): """loadUiType(uifile) -> (form class, base class) Load a Qt Designer .ui file and return the generated form class and the Qt base class. uifile is a file name or file-like object containing the .ui file. from_imports is optionally set to use import statements that are relative to '.'. """ import sys from PyQt4 import QtGui if sys.hexversion >= 0x03000000: from PyQt4.uic.port_v3.string_io import StringIO else: from PyQt4.uic.port_v2.string_io import StringIO code_string = StringIO() winfo = compiler.UICompiler().compileUi(uifile, code_string, from_imports) ui_globals = {} exec(code_string.getvalue(), ui_globals) return (ui_globals[winfo["uiclass"]], getattr(QtGui, winfo["baseclass"]))
def loadUiType(uifile, from_imports=False, resource_suffix='_rc'): """loadUiType.py(uifile, from_imports=False) -> (form class, base class) Load a Qt Designer .ui file and return the generated form class and the Qt base class. uifile is a file name or file-like object containing the .ui file. from_imports is optionally set to use import statements that are relative to '.'. resource_suffix is the suffix appended to the basename of any resource file specified in the .ui file to create the name of the Python module generated from the resource file by pyrcc4. The default is '_rc', i.e. if the .ui file specified a resource file called foo.qrc then the corresponding Python module is foo_rc. """ import sys from PyQt4 import QtGui if sys.hexversion >= 0x03000000: from PyQt4.uic.port_v3.string_io import StringIO else: from PyQt4.uic.port_v2.string_io import StringIO code_string = StringIO() winfo = compiler.UICompiler().compileUi(uifile, code_string, from_imports, resource_suffix) ui_globals = {} exec(code_string.getvalue(), ui_globals) return (ui_globals[winfo["uiclass"]], getattr(QtGui, winfo["baseclass"]))
def compileUi(uifile, pyfile, execute=False, indent=4, pyqt3_wrapper=False): """compileUi(uifile, pyfile, execute=False, indent=4, pyqt3_wrapper=False) Creates a Python module from a Qt Designer .ui file. uifile is a file name or file-like object containing the .ui file. pyfile is the file-like object to which the Python code will be written to. execute is optionally set to generate extra Python code that allows the code to be run as a standalone application. The default is False. indent is the optional indentation width using spaces. If it is 0 then a tab is used. The default is 4. pyqt3_wrapper is optionally set to generate extra code that allows the code to be used as it would be with PyQt v3. """ from time import ctime from PyQt4.QtCore import PYQT_VERSION_STR try: uifname = uifile.name except AttributeError: uifname = uifile indenter.indentwidth = indent pyfile.write(_header % (uifname, ctime(), PYQT_VERSION_STR)) winfo = compiler.UICompiler().compileUi(uifile, pyfile) if pyqt3_wrapper: indenter.write_code(_pyqt3_wrapper_code % winfo) if execute: indenter.write_code(_display_code % winfo)
def processUI(uifile, output_filename=None, exe=False, indent=4): """Compile and process the UI file.""" if output_filename is not None: output = open(output_filename,'w') else: output = sys.stdout # Write out the header. output.write(HEADER % (uifile, time.ctime())) indenter.indentwidth = indent comp = compiler.UICompiler() pyqt_version_tuple = tuple(map(int, QtCore.PYQT_VERSION_STR.split("."))) # the method signature for compileUI changed in 4.10.0 if pyqt_version_tuple < (4,10,0): winfo = comp.compileUi(uifile, output, None) else: winfo = comp.compileUi(uifile, output, None, "") if exe: output.write(DISPLAY_CODE % winfo["uiclass"]) if output_filename is not None: output.close()
def processUI(uifile, output_filename=None, exe=False, indent=4): if output_filename is not None: output = open(output_filename, 'w') else: output = sys.stdout # Write out the header. output.write(header % (uifile, time.ctime())) indenter.indentwidth = indent comp = compiler.UICompiler() comp.factory._cwFilters.append(kdeFilter()) winfo = comp.compileUi(uifile, output) if exe: output.write(""" if __name__ == '__main__': import sys global app class MainWin(kdeui.KMainWindow, """ + winfo['uiclass'] + """): def __init__ (self, *args): kdeui.KMainWindow.__init__ (self) rootWidget = QtGui.QWidget(self) self.setupUi(rootWidget) self.resize(640, 480) self.setCentralWidget(rootWidget) appName = "default" catalog = "" programName = kdecore.ki18n("default") version = "1.0" description = kdecore.ki18n("Default Example") license = kdecore.KAboutData.License_GPL copyright = kdecore.ki18n("unknown") text = kdecore.ki18n("none") homePage = "" bugEmail = "email" aboutData = kdecore.KAboutData(appName, catalog, programName, version, description, license, copyright, text, homePage, bugEmail) kdecore.KCmdLineArgs.init(sys.argv, aboutData) app = kdeui.KApplication() mainWindow = MainWin(None, "main window") mainWindow.show() app.connect (app, QtCore.SIGNAL ("lastWindowClosed ()"), app.quit) app.exec_ () """) if output_filename is not None: output.close()
def compileUi(uifile, pyfile, execute=False, indent=4, pyqt3_wrapper=False, from_imports=False, resource_suffix='_rc'): """compileUi(uifile, pyfile, execute=False, indent=4, pyqt3_wrapper=False, from_imports=False, resource_suffix='_rc') Creates a Python module from a Qt Designer .ui file. uifile is a file name or file-like object containing the .ui file. pyfile is the file-like object to which the Python code will be written to. execute is optionally set to generate extra Python code that allows the code to be run as a standalone application. The default is False. indent is the optional indentation width using spaces. If it is 0 then a tab is used. The default is 4. pyqt3_wrapper is optionally set to generate extra code that allows the code to be used as it would be with PyQt v3. from_imports is optionally set to generate import statements that are relative to '.'. resource_suffix is the suffix appended to the basename of any resource file specified in the .ui file to create the name of the Python module generated from the resource file by pyrcc4. The default is '_rc', i.e. if the .ui file specified a resource file called foo.qrc then the corresponding Python module is foo_rc. """ from time import ctime from PyQt4.QtCore import PYQT_VERSION_STR try: uifname = uifile.name except AttributeError: uifname = uifile indenter.indentwidth = indent pyfile.write(_header % (uifname, PYQT_VERSION_STR)) winfo = compiler.UICompiler().compileUi(uifile, pyfile, from_imports, resource_suffix) if pyqt3_wrapper: indenter.write_code(_pyqt3_wrapper_code % winfo) if execute: indenter.write_code(_display_code % winfo)
$NetBSD: patch-tools_pykdeuic4_pykdeuic4.py,v 1.1 2014/08/21 21:34:33 wiz Exp $ --- tools/pykdeuic4/pykdeuic4.py.orig 2014-01-02 19:29:05.000000000 +0000 +++ tools/pykdeuic4/pykdeuic4.py @@ -23,6 +23,7 @@ import sys import time import optparse +from PyQt4 import QtCore from PyQt4.uic.Compiler import indenter, compiler from PyQt4.uic.Compiler import qtproxies from PyQt4.uic.objcreator import MATCH,NO_MATCH @@ -101,7 +102,12 @@ def processUI(uifile, output_filename=No output.write(HEADER % (uifile, time.ctime())) indenter.indentwidth = indent comp = compiler.UICompiler() - winfo = comp.compileUi(uifile, output, None) + pyqt_version_tuple = tuple(map(int, QtCore.PYQT_VERSION_STR.split("."))) + # the method signature for compileUI changed in 4.10.0 + if pyqt_version_tuple < (4,10,0): + winfo = comp.compileUi(uifile, output, None) + else: + winfo = comp.compileUi(uifile, output, None, "") if exe: output.write(DISPLAY_CODE % winfo["uiclass"])