Пример #1
0
 def __init__(self, sys_argv):
     # sys_argv += ['-style', 'material']  #! MUST HAVE
     self._m_vtkFboItem = None
     QApplication.setAttribute(Qt.AA_UseDesktopOpenGL)
     QSurfaceFormat.setDefaultFormat(
         defaultVtkFormat(False))  # from vtk 8.2.0
     super(App, self).__init__(sys_argv)
Пример #2
0
def set_format() -> QSurfaceFormat:
    surface_format = QSurfaceFormat()
    surface_format.setVersion(4, 1)
    surface_format.setProfile(QSurfaceFormat.CoreProfile)
    surface_format.setSamples(4)
    QSurfaceFormat.setDefaultFormat(surface_format)

    return surface_format
Пример #3
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

        QSurfaceFormat.setDefaultFormat(FboItem.defaultSurfaceFormat(False))
        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(FboItem, '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(FboItem, '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}')
Пример #4
0
        self.imageView.setPixmap(QPixmap(qimage[0]).scaledToWidth(400))
        self.glWidget.updateImage(qimage[0])

    def showSaveDialog(self):
        filename = QFileDialog.getSaveFileName(self, "Save file", "", ".STL")
        print(filename[0])
        self.glWidget.generateSTL(filename[0] + filename[1])


if __name__ == '__main__':
    app = QApplication(sys.argv)

    fmt = QSurfaceFormat()
    if "--multisample" in QCoreApplication.arguments():
        fmt.setSamples(4)
    if "--coreprofile" in QCoreApplication.arguments():
        fmt.setVersion(3, 2)
        fmt.setProfile(QSurfaceFormat.CoreProfile)
    QSurfaceFormat.setDefaultFormat(fmt)

    mainWindow = Window()
    if "--transparent" in QCoreApplication.arguments():
        mainWindow.setAttribute(Qt.WA_TranslucentBackground)
        mainWindow.setAttribute(Qt.WA_NoSystemBackground, False)

    mainWindow.resize(mainWindow.sizeHint())
    mainWindow.show()

    res = app.exec_()
    sys.exit(res)
Пример #5
0
            self.setXRotation(self.xRot + 8 * dy)
            self.setYRotation(self.yRot + 8 * dx)
        elif event.buttons() & Qt.RightButton:
            self.setXRotation(self.xRot + 8 * dy)
            self.setZRotation(self.zRot + 8 * dx)

        self.lastPos = QPoint(event.pos())

if __name__ == '__main__':
    app = QApplication(sys.argv)

    fmt = QSurfaceFormat()
    fmt.setDepthBufferSize(24)
    if "--multisample" in QCoreApplication.arguments():
        fmt.setSamples(4)
    if "--coreprofile" in QCoreApplication.arguments():
        fmt.setVersion(3, 2)
        fmt.setProfile(QSurfaceFormat.CoreProfile)
    QSurfaceFormat.setDefaultFormat(fmt)

    mainWindow = Window()
    if "--transparent" in QCoreApplication.arguments():
        mainWindow.setAttribute(Qt.WA_TranslucentBackground)
        mainWindow.setAttribute(Qt.WA_NoSystemBackground, False)

    mainWindow.resize(mainWindow.sizeHint())
    mainWindow.show()

    res = app.exec_()
    sys.exit(res)
Пример #6
0
        self.__slot_channels()

    def __slot_checkerboard(self):
        self._viewport.set_colors(True, None, None)

    def __slot_solid_color(self):
        color = QColorDialog.getColor(Qt.black, self,
                                      "Choose background color")
        if color.isValid():
            self._viewport.set_colors(False, color, color)


if __name__ == '__main__':
    # Create the Qt Application
    app = QApplication(sys.argv)
    # must be called before the OpenGLWidget or its parent window gets shown
    # set default OpenGL surface format
    glformat = QSurfaceFormat()
    glformat.setDepthBufferSize(24)
    glformat.setStencilBufferSize(8)
    glformat.setVersion(3, 1)
    glformat.setProfile(QSurfaceFormat.CoreProfile)
    QSurfaceFormat.setDefaultFormat(glformat)
    # Create and show the form
    form = TViewerWindow()
    form.show()
    sample = join(dirname(realpath(__file__)), "rgba.tga")
    form.view(sample)
    # Run the main Qt loop
    sys.exit(app.exec_())
Пример #7
0
def initialize_gl():
    QSurfaceFormat.setDefaultFormat(get_default_format(gles=True))
    QGuiApplication.setAttribute(Qt.AA_UseOpenGLES, True)
    QGuiApplication.setAttribute(Qt.AA_ShareOpenGLContexts, True)
Пример #8
0
import sys
from PySide2.QtWidgets import QApplication
from PySide2.QtGui import QSurfaceFormat
from PySide2.QtCore import Qt

from PolyEdit3D.Widgets import PlyMainWindow
from PolyEdit3D.GL.Setup import GLSurfaceFormat

if __name__ == '__main__':
    QApplication.setAttribute(Qt.AA_UseDesktopOpenGL)
    QSurfaceFormat.setDefaultFormat(GLSurfaceFormat())

    app = QApplication()

    window = PlyMainWindow()
    window.show()

    sys.exit(app.exec_())