GithubHelp home page GithubHelp logo

Comments (9)

ezalorpro avatar ezalorpro commented on June 19, 2024 2

Hello, thanks for the quick answer, indeed it is possible, i figure it out like 20 minuts ago, i am currently expertimenting, but in breef it is just like you said, just replace PyQt5 import for PySide2 and replace pyqtsignal and pyqtslot for Signal and Slot.

pyside2pyvista

My only problem it is with the scalars and cmap, you can see in the imagen that dont correspond with the height, but that's another topic. i have intendet to release the code eventually, but i cant do it right now, since it is a work for university stuff.

btw, after making those changes, the basic example of PyVista + PyQt5 works with pyside2 changing Qt for QtWidgets.

from PySide2 import QtWidgets
import numpy as np
import pyvista as pv

class MainWindow(QtWidgets.QMainWindow):

    def __init__(self, parent=None, show=True):
        super(MainWindow, self).__init__(parent)

        # create the frame
        self.frame = QtWidgets.QFrame()
        vlayout = QtWidgets.QVBoxLayout()

        # add the pyvista interactor object
        self.vtk_widget = pv.QtInteractor(self.frame)
        vlayout.addWidget(self.vtk_widget)

        self.frame.setLayout(vlayout)
        self.setCentralWidget(self.frame)

        # simple menu to demo functions
        mainMenu = self.menuBar()
        fileMenu = mainMenu.addMenu('File')
        exitButton = QtWidgets.QAction('Exit', self)
        exitButton.setShortcut('Ctrl+Q')
        exitButton.triggered.connect(self.close)
        fileMenu.addAction(exitButton)

        # allow adding a sphere
        meshMenu = mainMenu.addMenu('Mesh')
        self.add_sphere_action = QtWidgets.QAction('Add Sphere', self)
        self.add_sphere_action.triggered.connect(self.add_sphere)
        meshMenu.addAction(self.add_sphere_action)

        if show:
            self.show()

    def add_sphere(self):
        """ add a sphere to the pyqt frame """
        sphere = pv.Sphere()
        self.vtk_widget.add_mesh(sphere)
        self.vtk_widget.reset_camera()

pyside2pyvistasphere

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

Yes, it is possible to embed a PyVista render window in a pyside2 app! This requires a bit of hacking but we could likely get a branch going in the main repo for this. I think simply replacing PyQt5 imports with PySide2 will do the trick

Are you familiar with PyVista’s BackgroundPlotter class and the internalQtInteractorclass it inherits?

https://github.com/pyvista/pyvista/blob/66e9495273adb0ca4fc5441e913d239837543140/pyvista/plotting/qt_plotting.py#L270

You’d likely need to inherit the QtInteractor class and embed that after replacing the PyQt5 imports for PySide2

Is this GUI app you’re making open source? If so maybe we could collaborate and get a general template for embedding pyvista in PySide2 apps...

Sent with GitHawk

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

Excellent work! I'm glad you were able to figure out how to get this working so quickly!

It'd be nice if we could set up PyVista to work with both. PyQt5 and PySide2 - I'll think about how we could make this work

My only problem it is with the scalars and cmap, you can see in the imagen that don't correspond with the height, but that's another topic.

Feel free to open another issue if you need help with this

from pyvista-support.

ezalorpro avatar ezalorpro commented on June 19, 2024

It'd be nice if we could set up PyVista to work with both. PyQt5 and PySide2 - I'll think about how we could make this work

about that, perhaps you can find inspiration in the Qt.py file of pyqtgraph, it deals with the same problem, kinda.

https://github.com/pyqtgraph/pyqtgraph/blob/develop/pyqtgraph/Qt.py

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

Nice find, thanks for sharing!

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

@ezalorpro - I actually cannot get the script you shared above to work... Am I missing something?:

from PySide2 import QtWidgets
import numpy as np
import pyvista as pv
import sys

class MainWindow(QtWidgets.QMainWindow):

    def __init__(self, parent=None, show=True):
        super(MainWindow, self).__init__(parent)

        # create the frame
        self.frame = QtWidgets.QFrame()
        vlayout = QtWidgets.QVBoxLayout()

        # add the pyvista interactor object
        self.vtk_widget = pv.QtInteractor(self.frame)
        vlayout.addWidget(self.vtk_widget)

        self.frame.setLayout(vlayout)
        self.setCentralWidget(self.frame)

        # simple menu to demo functions
        mainMenu = self.menuBar()
        fileMenu = mainMenu.addMenu('File')
        exitButton = QtWidgets.QAction('Exit', self)
        exitButton.setShortcut('Ctrl+Q')
        exitButton.triggered.connect(self.close)
        fileMenu.addAction(exitButton)

        # allow adding a sphere
        meshMenu = mainMenu.addMenu('Mesh')
        self.add_sphere_action = QtWidgets.QAction('Add Sphere', self)
        self.add_sphere_action.triggered.connect(self.add_sphere)
        meshMenu.addAction(self.add_sphere_action)

        if show:
            self.show()

    def add_sphere(self):
        """ add a sphere to the pyqt frame """
        sphere = pv.Sphere()
        self.vtk_widget.add_mesh(sphere)
        self.vtk_widget.reset_camera()


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()
    sys.exit(app.exec_())

Then I get the error:

Traceback (most recent call last):
  File "test.py", line 48, in <module>
    window = MainWindow()
  File "test.py", line 16, in __init__
    self.vtk_widget = pv.QtInteractor(self.frame)
  File "/Users/bane/Documents/OpenGeoVis/Software/pyvista/pyvista/plotting/qt_plotting.py", line 290, in __init__
    QVTKRenderWindowInteractor.__init__(self, parent)
  File "/Users/bane/anaconda3/envs/fras/lib/python3.7/site-packages/vtk/qt/QVTKRenderWindowInteractor.py", line 235, in __init__
    QGLWidget.__init__(self, parent)
TypeError: arguments did not match any overloaded call:
  QGLWidget(parent: QWidget = None, shareWidget: QGLWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'PySide2.QtWidgets.QFrame'
  QGLWidget(QGLContext, parent: QWidget = None, shareWidget: QGLWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'PySide2.QtWidgets.QFrame'
  QGLWidget(QGLFormat, parent: QWidget = None, shareWidget: QGLWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'PySide2.QtWidgets.QFrame'
Exception ignored in: <function BasePlotter.__del__ at 0x7fcd604de620>
Traceback (most recent call last):
  File "/Users/bane/Documents/OpenGeoVis/Software/pyvista/pyvista/plotting/plotting.py", line 3375, in __del__
    self.close()
RuntimeError: super-class __init__() of type QtInteractor was never called

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

I have version 5.13.0 of PyQt5 and version 5.13.0 of PySide2

from pyvista-support.

ezalorpro avatar ezalorpro commented on June 19, 2024

i am using:

python -> 3.7.3 - 32 bits
pyvista -> 0.21.4
PySide2 -> 5.13.0
VTK -> 8.2.0

No PyQt5 since it is a virtual enviroment, the only thing worth mentioning is that the line 235 of my QVTKRenderWindowInteractor.py is not that one the show the error, so maybe it is the VTK version?

I try the replace PySide2 thing cuz i read this in the QVTKRenderWindowInteractor.py :

Changes by Tobias Hänel, Sep. 2018
Support for PySide2

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

Ah yep - I had VTK 8.1.2 in that virtual env. VTK 8.2.0 resolves the issue

from pyvista-support.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.