rgerum / pylustrator

Visualisations of data are at the core of every publication of scientific research results. They have to be as clear as possible to facilitate the communication of research. As data can have different formats and shapes, the visualisations often have to be adapted to reflect the data as well as possible. We developed Pylustrator, an interface to directly edit python generated matplotlib graphs to finalize them for publication. Therefore, subplots can be resized and dragged around by the mouse, text and annotations can be added. The changes can be saved to the initial plot file as python code.
GNU General Public License v3.0
706 stars 38 forks source link

Crash when resizing the main Figure #43

Closed fconil closed 1 year ago

fconil commented 2 years ago

Hi,

Trying to do the same changes as in the demo video, the application crashes when I try to resize the main Figure.

I am using Ubuntu 22.04, Python 3.10, Pylustrator runs in a virtual environment.

$ python example_pylustrator.py
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
Traceback (most recent call last):
  File ".../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 941, in resizeEvent
    self.updateRuler()
  File ".../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 867, in updateRuler
    painterX.drawLine(x, l - l1 - 1, x, l - 1)
TypeError: arguments did not match any overloaded call:
  drawLine(self, QLineF): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, QLine): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, int, int, int, int): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, QPoint, QPoint): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, Union[QPointF, QPoint], Union[QPointF, QPoint]): argument 1 has unexpected type 'numpy.float64'
Traceback (most recent call last):
  File ".../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 932, in showEvent
    self.fitToView()
  File ".../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 1027, in fitToView
    self.canvas_container.move((self.canvas_canvas.width() - w) / 2 + 5,
TypeError: arguments did not match any overloaded call:
  move(self, QPoint): argument 1 has unexpected type 'float'
  move(self, int, int): argument 1 has unexpected type 'float'
Traceback (most recent call last):
  File ".../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 939, in resizeEvent
    self.fitToView(True)
  File ".../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 1016, in fitToView
    self.canvas_container.move((self.canvas_canvas.width() - w) / 2 + 5,
TypeError: arguments did not match any overloaded call:
  move(self, QPoint): argument 1 has unexpected type 'float'
  move(self, int, int): argument 1 has unexpected type 'float'
Traceback (most recent call last):
  File ".../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QComplexWidgets.py", line 1158, in changeSize
    self.parent.updateRuler()
  File ".../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 867, in updateRuler
    painterX.drawLine(x, l - l1 - 1, x, l - 1)
TypeError: arguments did not match any overloaded call:
  drawLine(self, QLineF): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, QLine): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, int, int, int, int): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, QPoint, QPoint): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, Union[QPointF, QPoint], Union[QPointF, QPoint]): argument 1 has unexpected type 'numpy.float64'
QPaintDevice: Cannot destroy paint device that is being painted
QPaintDevice: Cannot destroy paint device that is being painted
Erreur de segmentation (core dumped)

Regards

rgerum commented 2 years ago

Could you provide a list of installed packages with versions (e.g. Matplotlib version, pylustrator version and pyqt version) and an example code to reproduce? Then I can have a look at it. It normally should not occur.

fconil commented 2 years ago

Here it is

$ pip list
Package         Version
--------------- ---------
build           0.8.0
click           8.1.3
cycler          0.11.0
fonttools       4.35.0
imageio         2.21.1
kiwisolver      1.4.4
matplotlib      3.5.3
natsort         8.1.0
networkx        2.8.5
numpy           1.23.2
packaging       21.3
pep517          0.13.0
Pillow          9.2.0
pip             22.2.2
pip-tools       6.8.0
pylustrator     1.1.2
pyparsing       3.0.9
PyQt5           5.15.7
PyQt5-Qt5       5.15.2
PyQt5-sip       12.11.0
python-dateutil 2.8.2
PyWavelets      1.3.0
QtAwesome       1.1.1
QtPy            2.2.0
scikit-image    0.19.3
scipy           1.9.0
setuptools      65.0.2
six             1.16.0
tifffile        2022.8.12
tomli           2.0.1
wheel           0.37.1

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.2.0-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-gBFGDP/gcc-11-11.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-gBFGDP/gcc-11-11.2.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Ubuntu 11.2.0-19ubuntu1) 

$ uname -a
Linux xps-13-9370 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

$ apt list --installed | grep -i qt
libqt5concurrent5/jammy-updates,now 5.15.3+dfsg-2ubuntu0.1 amd64  [installé, automatique]
libqt5core5a/jammy-updates,now 5.15.3+dfsg-2ubuntu0.1 amd64  [installé, automatique]
libqt5dbus5/jammy-updates,now 5.15.3+dfsg-2ubuntu0.1 amd64  [installé, automatique]
libqt5gui5/jammy-updates,now 5.15.3+dfsg-2ubuntu0.1 amd64  [installé, automatique]
libqt5multimedia5-plugins/jammy,now 5.15.3-1 amd64  [installé, automatique]
libqt5multimedia5/jammy,now 5.15.3-1 amd64  [installé, automatique]
libqt5multimediagsttools5/jammy,now 5.15.3-1 amd64  [installé, automatique]
libqt5multimediawidgets5/jammy,now 5.15.3-1 amd64  [installé, automatique]
libqt5network5/jammy-updates,now 5.15.3+dfsg-2ubuntu0.1 amd64  [installé, automatique]
libqt5opengl5/jammy-updates,now 5.15.3+dfsg-2ubuntu0.1 amd64  [installé, automatique]
libqt5printsupport5/jammy-updates,now 5.15.3+dfsg-2ubuntu0.1 amd64  [installé, automatique]
libqt5svg5/jammy,now 5.15.3-1 amd64  [installé, automatique]
libqt5widgets5/jammy-updates,now 5.15.3+dfsg-2ubuntu0.1 amd64  [installé, automatique]
libqt5x11extras5/jammy,now 5.15.3-1 amd64  [installé, automatique]
qt5-gtk-platformtheme/jammy-updates,now 5.15.3+dfsg-2ubuntu0.1 amd64  [installé, automatique]
qttranslations5-l10n/jammy,jammy,now 5.15.3-1 all  [installé, automatique]
wireshark-qt/jammy,now 3.6.2-2 amd64  [installé, automatique]
rgerum commented 2 years ago

Hmm strange, I cannot reproduce if it I run it in a virtual environment with these packages. It seems somehow to be a problem with Qt and Numpy interacting with their datatypes of floats.

fconil commented 2 years ago

To be complete, this is what happened

# =============================================================================
# I already have error message just when I launch the code
# =============================================================================
$ python example_pylustrator.py 
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
Traceback (most recent call last):
  File "/.../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 941, in resizeEvent
    self.updateRuler()
  File "/.../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 867, in updateRuler
    painterX.drawLine(x, l - l1 - 1, x, l - 1)
TypeError: arguments did not match any overloaded call:
  drawLine(self, QLineF): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, QLine): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, int, int, int, int): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, QPoint, QPoint): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, Union[QPointF, QPoint], Union[QPointF, QPoint]): argument 1 has unexpected type 'numpy.float64'
Traceback (most recent call last):
  File "/.../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 932, in showEvent
    self.fitToView()
  File "/.../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 1027, in fitToView
    self.canvas_container.move((self.canvas_canvas.width() - w) / 2 + 5,
TypeError: arguments did not match any overloaded call:
  move(self, QPoint): argument 1 has unexpected type 'float'
  move(self, int, int): argument 1 has unexpected type 'float'
Traceback (most recent call last):
  File "/.../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 939, in resizeEvent
    self.fitToView(True)
  File "/.../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 1016, in fitToView
    self.canvas_container.move((self.canvas_canvas.width() - w) / 2 + 5,
TypeError: arguments did not match any overloaded call:
  move(self, QPoint): argument 1 has unexpected type 'float'
  move(self, int, int): argument 1 has unexpected type 'float'

# =============================================================================
# First error when I try to reduce the size by clicking on the arrow key once
# =============================================================================
Traceback (most recent call last):
  File "/.../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QComplexWidgets.py", line 1158, in changeSize
    self.parent.updateRuler()
  File "/.../Progs/python/pylustrator/.venv/lib/python3.10/site-packages/pylustrator/QtGuiDrag.py", line 867, in updateRuler
    painterX.drawLine(x, l - l1 - 1, x, l - 1)
TypeError: arguments did not match any overloaded call:
  drawLine(self, QLineF): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, QLine): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, int, int, int, int): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, QPoint, QPoint): argument 1 has unexpected type 'numpy.float64'
  drawLine(self, Union[QPointF, QPoint], Union[QPointF, QPoint]): argument 1 has unexpected type 'numpy.float64'

# =============================================================================
# When clicking on the arrow key for a second time, I get the core dump
# =============================================================================
QPaintDevice: Cannot destroy paint device that is being painted
QPaintDevice: Cannot destroy paint device that is being painted
Erreur de segmentation (core dumped)
fconil commented 2 years ago

I also tried to set QT_QPA_PLATFORM=wayland because of the first warning or QT_QPA_PLATFORM=wayland-egl (https://doc.ubuntu-fr.org/wayland) but then I could not use the controls of the interface.

$ env | grep XDG
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
XDG_MENU_PREFIX=gnome-
XDG_SESSION_DESKTOP=ubuntu
XDG_SESSION_TYPE=wayland
XDG_CURRENT_DESKTOP=ubuntu:GNOME
XDG_SESSION_CLASS=user
XDG_RUNTIME_DIR=/run/user/1000
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop

$ env | grep QT_
QT_ACCESSIBILITY=1
QT_IM_MODULE=ibus

$ sudo dpkg --get-selections | grep -i wayland
libwayland-client0:amd64            install
libwayland-cursor0:amd64            install
libwayland-egl1:amd64               install
libwayland-server0:amd64            install
xwayland                    install
rgerum commented 1 year ago

Now looking at it again it seems it was some issue with int and float numbers. JoostScheffer made a pull request https://github.com/rgerum/pylustrator/pull/46 that fixes issues with int and floats.

it might work now. You can try to install the github version pip install git+https://github.com/rgerum/pylustrator

fconil commented 1 year ago

I just made a try with the github code and it works now. Thanks