def compileUi(uifile, pyfile, execute=False, indent=4, from_imports=False): """compileUi(uifile, pyfile, execute=False, indent=4, from_imports=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. from_imports is optionally set to generate import statements that are relative to '.'. """ from time import ctime import PySide try: uifname = uifile.name except AttributeError: uifname = uifile indenter.indentwidth = indent global PySideToolsVersion pyfile.write(_header % (uifname, ctime(), __version__, PySide.__version__)) winfo = compiler.UICompiler().compileUi(uifile, pyfile, from_imports) if execute: indenter.write_code(_display_code % winfo)
def _writeImportCode(self): imports = {} for widget in self._usedWidgets: _, module = self._widgets[widget] imports.setdefault(module, []).append(widget) for module, classes in imports.items(): write_code("from %s import %s" % (module, ", ".join(classes)))
def __call__(self, *args): func_call = "%s.%s(%s)" % (self.proxy, self.function_name, ", ".join( map(as_string, args))) if self.flags & AS_ARGUMENT: self.proxy._uic_name = func_call return self.proxy else: needs_translation = False for arg in args: if isinstance(arg, i18n_string): needs_translation = True if needs_translation: i18n_print(func_call) else: write_code(func_call)
def __call__(self, *args): func_call = "%s.%s(%s)" % (self.proxy, self.function_name, ", ".join(map(as_string, args))) if self.flags & AS_ARGUMENT: self.proxy._uic_name = func_call return self.proxy else: needs_translation = False for arg in args: if isinstance(arg, i18n_string): needs_translation = True if needs_translation: i18n_print(func_call) else: write_code(func_call)
def __init__(self, objectname, is_attribute, args=(), noInstantiation=False): if objectname: if is_attribute: objectname = "self." + objectname self._uic_name = objectname else: self._uic_name = "Unnamed" if not noInstantiation: funcall = "%s(%s)" % \ (moduleMember(self.module, self.__class__.__name__), ", ".join(map(str, args))) if objectname: funcall = "%s = %s" % (objectname, funcall) write_code(funcall)
def write_import(module_name, from_imports): if from_imports: write_code("from . import %s" % module_name) else: write_code("import %s" % module_name)
def _writeImportCode(self): if self._used: if self._package is None: write_code("import %s" % self._module) else: write_code("from %s import %s" % (self._package, self._module))
def setDelayedProps(self): write_code("") write_code("self.retranslateUi(%s)" % self.toplevelWidget) UIParser.setDelayedProps(self)