Exemple #1
0
    def customWidgets(self, elem):
        def header2module(header):
            """header2module(header) -> string

            Convert paths to C++ header files to according Python modules
            >>> header2module("foo/bar/baz.h")
            'foo.bar.baz'
            """
            if header.endswith(".h"):
                header = header[:-2]

            mpath = []
            for part in header.split('/'):
                # Ignore any empty parts or those that refer to the current
                # directory.
                if part not in ('', '.'):
                    if part == '..':
                        # We should allow this for Python3.
                        raise SyntaxError("custom widget header file name may not contain '..'.")

                    mpath.append(part)

            return '.'.join(mpath)
    
        for custom_widget in iter(elem):
            classname = custom_widget.findtext("class")
            if classname.startswith("Q3"):
                raise NoSuchWidgetError(classname)
            self.factory.addCustomWidget(classname,
                                     custom_widget.findtext("extends") or "QWidget",
                                     header2module(custom_widget.findtext("header")))
Exemple #2
0
    def createQObject(self, classname, *args, **kwargs):
        # Handle scoped names, typically static factory methods.
        parts = classname.split('.')
        factory = self.findQObjectType(parts[0])

        if factory is not None:
            for part in parts[1:]:
                factory = getattr(factory, part, None)
                if factory is None:
                    break
            else:
                return self._cpolicy.instantiate(factory, *args, **kwargs)

        raise NoSuchWidgetError(classname)
Exemple #3
0
 def createQObject(self, classname, *args, **kwargs):
     classType = self.findQObjectType(classname)
     if classType:
         return self._cpolicy.instantiate(classType, *args, **kwargs)
     raise NoSuchWidgetError(classname)