PlotPyStack / PythonQwt

Qt plotting widgets for Python (pure Python reimplementation of Qwt C++ library)
https://pypi.org/project/PythonQwt/
Other
86 stars 25 forks source link

TypeError: unexpected type 'QSize' #79

Closed luc-j-bourhis closed 11 months ago

luc-j-bourhis commented 11 months ago

Code to trigger the bugs, with PyQt5 version 5.15.6 and PythonQwt version 0.10.2 (the latest release at the time of filling this bug)

import qwt
import numpy as np
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtCore import Qt

trigger_bug = 1
#trigger_bug = 2

app = QtWidgets.QApplication([])

# Create plot widget
plot = qwt.QwtPlot("Trigonometric functions")
plot.insertLegend(qwt.QwtLegend(), plot.BottomLegend)

# Create two curves and attach them to plot
x = np.arange(10)
y = np.cos(x)
c = qwt.QwtPlotCurve.make(x, y, "Cosinus", plot)
c.setStyle(c.Sticks)
c.setPen(QtGui.QPen(Qt.red, 40))
archetype = qwt.QwtText("0")
archetype.setFont(QtGui.QFont())
txt_height = QtGui.QFontMetrics(archetype.font()).height()
for xi, yi in zip(x, y):
    match trigger_bug:
        case 1:
            s = qwt.QwtSymbol.make(style=qwt.QwtSymbol.NoSymbol,
                                   pen=QtGui.QPen(Qt.blue))
        case 2:
            s = qwt.QwtSymbol.make(style=qwt.QwtSymbol.Diamond,
                                   pen=QtGui.QPen(Qt.blue))
    m = qwt.QwtPlotMarker.make(xvalue=xi, yvalue=yi,
                               label=qwt.QwtText(f'{yi:.1f}'),
                               symbol=s)
    m.setLabelAlignment(Qt.AlignTop)
    m.setSpacing(2*txt_height)
    m.attach(plot)

# Resize and show plot
plot.resize(600, 300)
plot.show()

app.exec_()

With trigger_bug=1, I get this traceback:

File "...\qwt_trial.py", line 32, in <module>
  m = qwt.QwtPlotMarker.make(xvalue=xi, yvalue=yi,
File "...\site-packages\qwt\plot_marker.py", line 140, in make
  item.setSymbol(symbol)
File "...\site-packages\qwt\plot_marker.py", line 405, in setSymbol
  self.setLegendIconSize(symbol.boundingRect().size())
File "...\site-packages\qwt\symbol.py", line 1230, in boundingRect
  rect.setSize(self.__data.size)

builtins.TypeError: setSize(self, s: QSizeF): argument 1 has unexpected type 'QSize'

and with trigger_bug=2, I get this one:

File "...\qwt_trial.py", line 43, in <module>
  app.exec_()
File "...\site-packages\qwt\plot_canvas.py", line 586, in event
  return QFrame.event(self, event)
File "...\site-packages\qwt\plot_canvas.py", line 643, in paintEvent
  self.drawCanvas(painter, False)
File "...\site-packages\qwt\plot_canvas.py", line 707, in drawCanvas
  self.plot().drawCanvas(painter)
File "...\site-packages\qwt\plot.py", line 1418, in drawCanvas
  self.drawItems(painter, self.__data.canvas.contentsRect(), maps)
File "...\site-packages\qwt\plot.py", line 1442, in drawItems
  item.draw(painter, maps[item.xAxis()], maps[item.yAxis()], canvasRect)
File "...\site-packages\qwt\plot_marker.py", line 248, in draw
  self.drawLabel(painter, canvasRect, pos)
File "...\site-packages\qwt\plot_marker.py", line 319, in drawLabel
  symbolOff = self.__data.symbol.size() + QSizeF(1, 1)

builtins.TypeError: unsupported operand type(s) for +: 'QSize' and 'QSizeF'
PierreRaybaut commented 11 months ago

Thanks for the feedback and for the test code. I'll look into it asap.

luc-j-bourhis commented 11 months ago

Thanks for the fix! Any chance you make a new release? We have this package in my team's development environment, relying on Anaconda…

PierreRaybaut commented 11 months ago

Absolutely. I was about to release a new version a few days ago. I'll upload the V0.10.3 by tomorrow.

PierreRaybaut commented 11 months ago

Done: https://github.com/PlotPyStack/PythonQwt/releases/tag/v0.10.3 https://pypi.org/project/PythonQwt/