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 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 _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 _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 _writeImportCode(self): imports = {} for widget in self._usedWidgets: _, module = self._widgets[widget] imports.setdefault(module, []).append(widget) # For repeatability sort the imports and the classes being imported and # in a way that is portable between Python v2 and v3. modules = list(imports.keys()) modules.sort() for module in modules: classes = imports[module] classes.sort() write_code("from %s import %s" % (module, ", ".join(classes)))
def _writeImportCode(self): imports = {} for widget in self._usedWidgets: _, module = self._widgets[widget] imports.setdefault(module, []).append(widget) # For repeatability sort the imports and the classes being imported and # in a way that is portable between Python v2 and v3. modules = list(imports.keys()) modules.sort() for module in modules: classes = imports[module] classes.sort() 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(obj_to_argument, 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 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)
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 __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 __call__(self, *args): if self.function_name == "setProperty": str_args = (as_string(args[0], encode=False), as_string(args[1])) else: str_args = map(as_string, args) func_call = "%s.%s(%s)" % (self.proxy, self.function_name, ", ".join(str_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): if self.function_name == 'setProperty': args = (as_string(args[0], encode=False), as_string(args[1])) else: args = map(as_string, args) func_call = "%s.%s(%s)" % (self.proxy, self.function_name, ", ".join(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 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)
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)
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)