开发者

creating a module with pythonqt

Is there any pythonqt documentation for createModuleFromFile? I've gotten pythonqt set up, but I'm not sure if I'm creating the module correctly to be seen in another context. In the following code, I try to create a new module from a file, which contains a class that I want to inherit from in another file.

Reading the docs, it implies createModuleFromFile creates another context, but I can't run code from it and I'll need to import more than one module anyway. Is anything else necessary to accomplish this? Right now it errors when trying to execute the second script with an ImportError saying that module doesn't exist. I've also tried just evaluating both scripts back to back without the import line, but then MeshImporter isn't defined in the second script.

PythonQt::init(PythonQt::RedirectStdOut);
PythonQtObjectPtr context = PythonQt::self()->getMainModule();

QObject::connect(PythonQt::self(), SIGNAL(pythonStdOut(QString)), this, SLOT(pythonStdOut(QString)));
QObject::connect(PythonQt::self(), SIGNAL(pythonStdErr(QString)), this, SLOT(pythonStdOut(QString)));

PythonQt::self()->createModuleFromFile("meshImporter", ":/plugins/meshImporter.py");
context.evalFile(":/plugins/objImporter.py");

Example module:

class MeshImporter:
    def extension(self):
        raise NotImplementedError()
    def importMesh(self, fileName):
        raise NotImplementedError()

Example script that tries to import module:

from meshImporter import 开发者_JAVA百科MeshImporter # fails here

class ObjImporter(MeshImporter):
    def extension(self): return '.obj'
    def importMesh(self, fileName):
        print('Importing mesh: %s' % fileName)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜