Пример #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")))
Пример #2
0
 def createQObject(self, classname, *args, **kwargs):
     classType = self.findQObjectType(classname)
     if classType:
         return self._cpolicy.instantiate(classType, *args, **kwargs)
     raise NoSuchWidgetError(classname)