Exemplo n.º 1
0
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)
Exemplo n.º 2
0
    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)))
Exemplo n.º 3
0
    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)))
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
def write_import(module_name, from_imports):
    if from_imports:
        write_code("from . import %s" % module_name)
    else:
        write_code("import %s" % module_name)
Exemplo n.º 9
0
 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))
Exemplo n.º 10
0
 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))
Exemplo n.º 11
0
 def setDelayedProps(self):
     write_code("")
     write_code("self.retranslateUi(%s)" % self.toplevelWidget)
     UIParser.setDelayedProps(self)
Exemplo n.º 12
0
def write_import(module_name, from_imports):
    if from_imports:
        write_code("from . import %s" % module_name)
    else:
        write_code("import %s" % module_name)
Exemplo n.º 13
0
 def setDelayedProps(self):
     write_code("")
     write_code("self.retranslateUi(%s)" % self.toplevelWidget)
     UIParser.setDelayedProps(self)