Giter Site home page Giter Site logo

Support for PySide2 (qt) about pyvistaqt HOT 12 CLOSED

pyvista avatar pyvista commented on May 25, 2024 3
Support for PySide2 (qt)

from pyvistaqt.

Comments (12)

akaszynski avatar akaszynski commented on May 25, 2024 2

Hello @RubendeBruin and thanks for your interest pyside2 integration.

We've been in contact with another company that's tried to do the same thing with some success and I'd like to post part of the details of the implementation here:

VTK needs to be fiddled as mentioned in https://discourse.vtk.org/t/vtk-8-2-0-come-and-get-it/174/9

The PySide2 support is provided by two Python files:
https://gitlab.kitware.com/vtk/vtk/tree/master/Wrapping/Python/vtkmodules/qt 19

You can copy those files into an existing VTK 8.1.2 installation in order to get PySide2 support. If that isn’t possible, you can copy QVTKRenderWindowInteractor.py into your own project and import it directly.

Then PySide2 needs to be included in the PyVista modules

In the init.py of the qt module

# PyQtImpl can be set by the user
PyQtImpl = "PySide2"

# Has an implementation has been imported yet?

if PyQtImpl is None:
    for impl in ["PyQt5", "PySide2", "PyQt4", "PySide"]:
        if impl in sys.modules:
            PyQtImpl = impl
            break

In `qt_plotting.py`
```python
if vtk.qt.PyQtImpl == 'PySide2':

    try:

        from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
        from PySide2.QtCore import (Signal as pyqtSignal, Slot as pyqtSlot, QObject, QTimer)
        from PySide2 import QtGui
        from PySide2 import QtCore

        from PySide2.QtWidgets import (QMenuBar, QVBoxLayout, QHBoxLayout, QDoubleSpinBox,

                                    QFrame, QMainWindow, QSlider, QAction,
                                    QSpinBox, QHBoxLayout, QDialog,
                                    QFormLayout, QGroupBox, QFileDialog)

        has_pyqt = True
    except ImportError:  # pragma: no cover
        pass

Considering that BackgroundPlotter uses pyqt extensively and load the plotter on init, we'd have to rework the class to make it work with both pyqt and pyside. I personally never liked (and always through it was a bit of a hack) to load a module and then have to set a value in the module and then proceed with an import. Rather, I'd prefer to have either BackgroudPlotter(backend='pyside') or PySideBackgroundPlotter (name needs work).

@GuillaumeFavelier, your throughs? Considering that this is continuing to get more complex, we might consider implementing this alongside pyvista/pyvista#614.

from pyvistaqt.

RubendeBruin avatar RubendeBruin commented on May 25, 2024 2

Hi @akaszynski ,
the code that you pasted looks a lot like the way matplotlib is handeling the compatibility: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/qt_compat.py

So I guess it is a good way of doing it.

On the other hand, since vtk is a hard requirement, it may also make sense to adopt their way of doing it. Adopting the vtk has the benefit that you are sure that any vtk module that is used is using the same implementation.

from pyvistaqt.

adeak avatar adeak commented on May 25, 2024

Also related: pyvista/pyvista-support#44

from pyvistaqt.

RubendeBruin avatar RubendeBruin commented on May 25, 2024

from pyvista/pyvista#44: "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"

--> Propose to do the same as vtk does:

import vtkmodules.qt
vtkmodules.qt.PyQtImpl = 'PySide2'

so we can check the value of vtkmodules.qt.PyQtImpl and base on that either import PyQt or Pyside.

from pyvistaqt.

GuillaumeFavelier avatar GuillaumeFavelier commented on May 25, 2024

That would be awesome to have support for PySide2! I think we could use vtkmodules directly like @RubendeBruin described then import depending on the implementation?

@akaszynski I agree with you BackgroundPlotter(backend='pyside') looks cleaner

Considering that this is continuing to get more complex, we might consider implementing this alongside pyvista/pyvista#614.

Sounds like a plan. Maybe we could draft a roadmap for it actually.

from pyvistaqt.

akaszynski avatar akaszynski commented on May 25, 2024

Spoke with the guys who make PyQt at Riverbank, and it seems that if you're developing commercial software that imports PyQt, you'll have to make your code subject to GPL. We can include references to PyQt in our source, but as soon as we start importing PyQt, the MIT license not longer applies.

We're going to have to make a switch over to pyside at some point in the near future so people can develop commercial applications that use pyvista without resorting to GPL licensing.

from pyvistaqt.

RubendeBruin avatar RubendeBruin commented on May 25, 2024

Well, let me know if you need some help. Very recently did this for two other applications and it is basically just replacing the imports than changing QtCore.pyqtSignal and QtCore.pyqtSlot to PySide2 it’s QtCore.Signal and QtCore.Slot.
And then forcing matplotlib and vtk to use pyside as backend.

from pyvistaqt.

imsodin avatar imsodin commented on May 25, 2024

Spoke with the guys who make PyQt at Riverbank, and it seems that if you're developing commercial software that imports PyQt, you'll have to make your code subject to LGPL. We can include references to PyQt in our source, but as soon as we start importing PyQt, the MIT license not longer applies.

Correction to that (laymans explanations, obviously not court material): PzQt is GPL, not LGPL - and that's the problem as it is much more restrictive. Pyside on the other hand is LGPL, which only applies to Pyside itsel, not to the code importing it.

from pyvistaqt.

akaszynski avatar akaszynski commented on May 25, 2024

Updated my comment. Thanks @imsodin.

from pyvistaqt.

GuillaumeFavelier avatar GuillaumeFavelier commented on May 25, 2024

And what do you think about qtpy?

from pyvistaqt.

larsoner avatar larsoner commented on May 25, 2024

qtpy looks like a good option

from pyvistaqt.

GuillaumeFavelier avatar GuillaumeFavelier commented on May 25, 2024

Closing by #61

from pyvistaqt.

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.