Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix volume editor for Python 3.10 #301

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions modules/pmg_qt/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def paintGrid(self, painter, rect):
painter.setPen(pen)
for line in range(1, num_lines):
y = y0 + h * (1.0 - self.alphaToY(line / float(num_lines)))
y = round(y)
painter.drawLine(x0, y, x1, y)

def paintColorDots(self, painter, rect):
Expand All @@ -125,20 +126,22 @@ def paintColorDots(self, painter, rect):
x, y, r, g, b = point
x = rect.left() + rect.width() * self.dataToX(x)
y = rect.top() + rect.height() * (1.0 - self.alphaToY(y))
x = round(x)
y = round(y)
if scaled_pts:
painter.drawLine(scaled_pts[-1][0], scaled_pts[-1][1], x, y)
scaled_pts.append((x, y, r, g, b))

for x, y, r, g, b in scaled_pts:
painter.setBrush(QtGui.QColor(255 * r, 255 * g, 255 * b))
painter.setBrush(QtGui.QColor.fromRgbF(r, g, b))
painter.drawEllipse(x - DOT_RADIUS, y - DOT_RADIUS, 2 * DOT_RADIUS,
2 * DOT_RADIUS)

if 0 <= self.hover_point < len(scaled_pts):
# use larger radius for hover dot
radius = DOT_RADIUS + 2
x, y, r, g, b = scaled_pts[self.hover_point]
painter.setBrush(QtGui.QColor(255 * r, 255 * g, 255 * b))
painter.setBrush(QtGui.QColor.fromRgbF(r, g, b))
painter.drawEllipse(x - radius, y - radius, 2 * radius,
2 * radius)

Expand Down Expand Up @@ -182,7 +185,7 @@ def paintValueBox(self,
value,
format="%.3f"):
s = format % value
sw = font_metrics.width(s)
sw = font_metrics.boundingRect(s).size().width()
sh = font_metrics.height()
if right_just:
rect = QtCore.QRect(x - sw - 4, y - sh, sw + 4, sh + 2)
Expand Down Expand Up @@ -218,8 +221,9 @@ def paintAxes(self, painter, rect):
x = x0 + w / 2 + rect.width() * (tick - self.vmin
) / float(self.vmax - self.vmin)
if x - lastx > w + 2 * fw:
x = round(x)
painter.drawLine(x, y0, x, y1)
painter.drawText(x - w / 2, y1 + fh - 2, s)
painter.drawText(round(x - w / 2), y1 + fh - 2, s)
lastx = x

#vertical axis
Expand All @@ -229,8 +233,9 @@ def paintAxes(self, painter, rect):
t = tick / 10.0
y = y0 - self.alphaToY(t) * rect.height()
if lasty - y > fh and y > 2 * fh:
y = round(y)
painter.drawLine(x1 - 5, y, x1, y)
painter.drawText(x1 - 5 - 3 * fw, y - 2 + fh / 2, str(t))
painter.drawText(x1 - 5 - 3 * fw, round(y - 2 + fh / 2), str(t))
lasty = y

# text boxes
Expand Down Expand Up @@ -410,7 +415,7 @@ def setPointColor(self, point, triple):
self.color_dialog.currentColorChanged.connect(
self.updatePointColor)
self.color_dialog.finished.connect(self.colorDialogClosed)
self.original_color = QtGui.QColor(255 * r, 255 * g, 255 * b)
self.original_color = QtGui.QColor.fromRgbF(r, g, b)
self.color_dialog.setCurrentColor(self.original_color)
# open modal color dialog
self.color_dialog.open()
Expand Down Expand Up @@ -526,7 +531,7 @@ def wheelEvent(self, event):
delta /= -1000.0

for key, rect in self.text_boxes.items():
if rect.contains(event.pos()):
if rect.contains(event.position().toPoint()):
vrange = self.vmax - self.vmin
if key == "amax":
self.amax = max(min(self.amax * (1.0 + delta), 1.0), 0.0)
Expand Down