Open fidergo-stephane-gourichon opened 3 years ago
Very interesting, thanks. Changing from PySide2 to QtPy in my opinion is not so minor, although I have already done something similar (trying PySide2 and then, if it fails, falling back to PyQt5) in order to be able to run on older Macs. I will not merge your pull request immediately, maybe I will try to do a development branch with it instead, in order to test things.
One problem is that, if one uses a wrapper like qtpy
, what happens to dependencies? If one installs guietta using pip, at least one of PySide2 or PyQt5 should be specified as a dependency, otherwise the package will not work out of the box. I browsed the qtpy project but did not find hints on this. What do you think?
One problem is that, if one uses a wrapper like
qtpy
, what happens to dependencies? If one installs guietta using pip, at least one of PySide2 or PyQt5 should be specified as a dependency, otherwise the package will not work out of the box. I browsed the qtpy project but did not find hints on this. What do you think?
Mmhh, I think I see what you mean. That would an issue to discuss with QtPy people.
On Ubuntu, installing qtpy package automatically pulls the PyQt5 option. So, in practice it works. It's a little Debianish way (choose the GPL option).
I saw that you try to import PySide2 with fallback to PyQt5, on https://github.com/alfiopuglisi/guietta/pull/14/commits/3bf9cbad5bc89425c7047235b02fd59ce6b1651d#diff-4a60ed8f52256b01ee98d3e645f9e341 .
That works in the simplest examples, but breaks as soon as client code runs
someQtWidget = QComboBox()
gui = Gui( [ someQtWidget ] )
it fails like this:
python3 mycode.py
Traceback (most recent call last): File "mycode.py", line 34, in
gui = Gui( File "/.../guietta/guietta/guietta.py", line 1488, in init self._rows.map_in_place(_check_widget) File "/.../guietta/guietta/guietta.py", line 1279, in map_in_place row[i] = func(row[i]) File "/.../guietta/guietta/guietta.py", line 1130, in _check_widget raise ValueError('Element ' + str(x) + ' must be a widget ' ValueError: Element <PyQt5.QtWidgets.QComboBox object at 0x7f99ba9d5160> must be a widget or a (widget, name) tuple
qtpy benefit goes further than just try import one and try import the other.
Actually I had made the change with the PyQt5 fallback for other reasons (mostly, to make it run on my older Mac which does not have a PySide2 package available), but I see the problem: once two different Qt modules are available, it becomes difficult to check if a class is an instance of QWidget or not, because there are now two possible QWidgets.
I will experimen with qtpy then :)
Ok, I could reproduce your problem, even using qtpy
! If qtpy selects PyQt5 and then I import a widget from PySide2, I get your traceback. Same with reversing the two imports. At this point, any widget import outside guietta should be done using qtpy too, in order to select the correct library.
I see no way out of this PyQt5/PySide2 mess. Maybe an option is to produce two different pip packages. A big difference is that PyQt is GPL, while PySide2 is LGPL, and this makes a difference if you want to redistribute your program.
Hi,
Doc says
https://github.com/alfiopuglisi/guietta says:
Steps to reproduce
On a Rasbperry Pi running recent version of Raspberry Pi OS:
Search before posting
Installing PySide2 on the Pi was discussed in several places:
Tried the provided steps (below) on a Pi 1, Pi 3 a Pi 4, the original symptom remains.
sudo apt-get install python3-pyside2.qt3dcore python3-pyside2.qt3dinput python3-pyside2.qt3dlogic python3-pyside2.qt3drender python3-pyside2.qtcharts python3-pyside2.qtconcurrent python3-pyside2.qtcore python3-pyside2.qtgui python3-pyside2.qthelp python3-pyside2.qtlocation python3-pyside2.qtmultimedia python3-pyside2.qtmultimediawidgets python3-pyside2.qtnetwork python3-pyside2.qtopengl python3-pyside2.qtpositioning python3-pyside2.qtprintsupport python3-pyside2.qtqml python3-pyside2.qtquick python3-pyside2.qtquickwidgets python3-pyside2.qtscript python3-pyside2.qtscripttools python3-pyside2.qtsensors python3-pyside2.qtsql python3-pyside2.qtsvg python3-pyside2.qttest python3-pyside2.qttexttospeech python3-pyside2.qtuitools python3-pyside2.qtwebchannel python3-pyside2.qtwebsockets python3-pyside2.qtwidgets python3-pyside2.qtx11extras python3-pyside2.qtxml python3-pyside2.qtxmlpatterns python3-pyside2uic
Other attempts:
Workaround
In practice
python3-qtpy
PySide2
are replaced byqtpy
(done it for all code, documentation should be updated, not done).Success!
Not sure this is the best thing to do, anyway it works for me. Will open PR if you want to follow this. It might help adoption of guietta, perhaps a lot, I don't know.