Esempio n. 1
0
    def __init__(self, sys_argv):
        super().__init__()
        self.__m_previousWorldX: float = 0.0
        self.__m_previousWorldY: float = 0.0
        self.__m_draggingMouse: bool = False
        self.__m_showFileDialog: bool = False
        self.__m_vtkFboItem = None
        #* Set style: https://stackoverflow.com/questions/43093797/PySide2-quickcontrols-material-style
        sys_argv += ['--style', 'material']  #! MUST HAVE
        app = QApplication(sys_argv)

        engine = QQmlApplicationEngine()
        # engine.setImportPathList(['C:\\Users\\tungdao\\.conda\\envs\\qtvtkpy\\Lib\\site-packages\\PySide2\\qml'])
        # print(engine.importPathList())
        app.setApplicationName('QtVTK-Py')

        #* Register QML Types
        qmlRegisterType(Squircle, 'QtVTK', 1, 0, 'VtkFboItem')

        # #* Create classes instances
        self.__m_processingEngine = ProcessingEngine()

        # #* Expose/Bind Python classes (QObject) to QML
        ctxt = engine.rootContext()  # returns QQmlContext
        ctxt.setContextProperty('canvasHandler', self)

        # #* Load main QML file
        engine.load(QUrl.fromLocalFile('resources\\main.qml'))

        # #* Get reference to the QVTKFramebufferObjectItem in QML
        rootObject = engine.rootObjects()[0]  # returns QObject
        self.__m_vtkFboItem = rootObject.findChild(Squircle, 'vtkFboItem')

        # # #* Give the vtkFboItem reference to the CanvasHandler
        if (self.__m_vtkFboItem):
            qDebug(
                'CanvasHandler::CanvasHandler: setting vtkFboItem to CanvasHandler'
            )
            self.__m_vtkFboItem.setProcessingEngine(self.__m_processingEngine)

            self.__m_vtkFboItem.rendererInitialized.connect(
                self.startApplication)
            self.__m_vtkFboItem.isModelSelectedChanged.connect(
                self.isModelSelectedChanged)
            self.__m_vtkFboItem.selectedModelPositionXChanged.connect(
                self.selectedModelPositionXChanged)
            self.__m_vtkFboItem.selectedModelPositionYChanged.connect(
                self.selectedModelPositionYChanged)
        else:
            qCritical(
                'CanvasHandler::CanvasHandler: Unable to get vtkFboItem instance'
            )
            return

        rc = app.exec_()
        qDebug(
            f'CanvasHandler::CanvasHandler: Execution finished with return code: {rc}'
        )
Esempio n. 2
0
    def setup(self, engine):
        # Get reference to the QVTKFramebufferObjectItem in QML
        rootObject = engine.rootObjects()[0]  # returns QObject
        self._m_vtkFboItem = rootObject.findChild(FboItem, 'vtkFboItem')

        # Give the vtkFboItem reference to the CanvasHandler
        if (self._m_vtkFboItem):
            qDebug(
                'CanvasHandler::CanvasHandler: setting vtkFboItem to CanvasHandler'
            )
            self._m_vtkFboItem.rendererInitialized.connect(
                self.startApplication)
        else:
            qCritical(
                'CanvasHandler::CanvasHandler: Unable to get vtkFboItem instance'
            )
            return
Esempio n. 3
0
    def __init__(self, sys_argv):
        super().__init__()
        self.__m_vtkFboItem = None
        #* Set style: https://stackoverflow.com/questions/43093797/PySide2-quickcontrols-material-style
        sys_argv += ['--style', 'material'] #! MUST HAVE


        QApplication.setAttribute( Qt.AA_UseDesktopOpenGL )
        QtGui.QSurfaceFormat.setDefaultFormat(defaultFormat(False)) # from vtk 8.2.0
        app = QApplication(sys_argv)

        engine = QQmlApplicationEngine()
        app.setApplicationName('QtVTK-Py')

        # Register QML Types
        qmlRegisterType(FboItem, 'QtVTK', 1, 0, 'VtkFboItem')

        # Expose/Bind Python classes (QObject) to QML
        ctxt = engine.rootContext() # returns QQmlContext
        ctxt.setContextProperty('canvasHandler', self)
        self.dataProvider = ChartDataProvider()
        ctxt.setContextProperty('chartDataProvider', self.dataProvider)

        # Load main QML file
        engine.load(QUrl.fromLocalFile('resources/main.qml'))

        # Get reference to the QVTKFramebufferObjectItem in QML
        rootObject = engine.rootObjects()[0] # returns QObject
        self.__m_vtkFboItem = rootObject.findChild(FboItem, 'vtkFboItem')

        # Give the vtkFboItem reference to the CanvasHandler
        if (self.__m_vtkFboItem):
            qDebug('CanvasHandler::CanvasHandler: setting vtkFboItem to CanvasHandler')
            self.__m_vtkFboItem.rendererInitialized.connect(self.startApplication)
        else:
            qCritical('CanvasHandler::CanvasHandler: Unable to get vtkFboItem instance')
            return

        rc = app.exec_()
        qDebug(f'CanvasHandler::CanvasHandler: Execution finished with return code: {rc}')