Skip to content

Commit

Permalink
Attempt to fix OverflowError with Contrast Adjustment panel for con…
Browse files Browse the repository at this point in the history
…stant images

Fix #25
  • Loading branch information
PierreRaybaut committed Oct 1, 2024
1 parent 38e3d95 commit ea1787c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

🛠️ Bug fixes:

* [Issue #25](https://github.com/PlotPyStack/PlotPy/issues/25) - `OverflowError` with Contrast Adjustment panel for constant images
* When updating image parameters (`ImageParam`) from the associated item object:
* If `xmin`, `xmax`, `ymin`, `ymax` attributes are not yet set (i.e. `None`), do not update them with the image data bounds
* Previous behavior was to update them with the image data bounds, which was leading to breaking the automatic bounds update when the image data is updated
Expand Down
33 changes: 16 additions & 17 deletions plotpy/items/shape/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import qwt.scale_map
from qtpy.QtCore import QPointF, QRectF
from qtpy.QtGui import QPainter
from qwt import QwtSymbol

from plotpy.plot import BasePlot
from plotpy.styles.base import ItemParameters


Expand Down Expand Up @@ -137,34 +139,31 @@ def draw(
yMap: Y axis scale map
canvasRect: Canvas rectangle
"""
plot = self.plot()
plot: BasePlot = self.plot()
if not plot:
return
if self.selected:
pen = self.sel_pen
sym = self.sel_symbol
pen: QG.QPen = self.sel_pen
sym: QwtSymbol = self.sel_symbol
else:
pen = self.pen
sym = self.symbol
pen: QG.QPen = self.pen
sym: QwtSymbol = self.symbol

rct = plot.canvas().contentsRect()
rct2 = QC.QRectF(rct)
rct2.setLeft(xMap.transform(self._min))
rct2.setRight(xMap.transform(self._max))
rct = QC.QRectF(plot.canvas().contentsRect())
rct.setLeft(xMap.transform(self._min))
rct.setRight(xMap.transform(self._max))

painter.fillRect(rct2, self.brush)
painter.fillRect(rct, self.brush)
painter.setPen(pen)
painter.drawLine(rct2.topLeft(), rct2.bottomLeft())
painter.drawLine(rct2.topRight(), rct2.bottomRight())
painter.drawLine(rct.topLeft(), rct.bottomLeft())
painter.drawLine(rct.topRight(), rct.bottomRight())

dash = QG.QPen(pen)
dash.setStyle(QC.Qt.DashLine)
dash.setWidth(1)
painter.setPen(dash)

center_x = int(rct2.center().x())
top = int(rct2.top())
bottom = int(rct2.bottom())
painter.drawLine(center_x, top, center_x, bottom)
cx = rct.center().x()
painter.drawLine(QC.QPointF(cx, rct.top()), QC.QPointF(cx, rct.bottom()))

painter.setPen(pen)
x0, x1, y = self.get_handles_pos()
Expand Down

0 comments on commit ea1787c

Please sign in to comment.