From 667f36a2e7654e2ba6240de0648e11ea22db6d76 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 29 May 2022 08:43:25 +0800 Subject: [PATCH] gui: fix Python 3.10 PyQt float/int issues. Closes #1887 --- artiq/browser/files.py | 2 +- artiq/gui/scanwidget.py | 18 +++++++++--------- artiq/gui/waitingspinnerwidget.py | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/artiq/browser/files.py b/artiq/browser/files.py index 339c12d34..46bf10b3f 100644 --- a/artiq/browser/files.py +++ b/artiq/browser/files.py @@ -71,7 +71,7 @@ class ZoomIconView(QtWidgets.QListView): self._char_width = QtGui.QFontMetrics(self.font()).averageCharWidth() self.setViewMode(self.IconMode) w = self._char_width*self.default_size - self.setIconSize(QtCore.QSize(w, w*self.aspect)) + self.setIconSize(QtCore.QSize(w, int(w*self.aspect))) self.setFlow(self.LeftToRight) self.setResizeMode(self.Adjust) self.setWrapping(True) diff --git a/artiq/gui/scanwidget.py b/artiq/gui/scanwidget.py index 20e161d97..e3231c6ab 100644 --- a/artiq/gui/scanwidget.py +++ b/artiq/gui/scanwidget.py @@ -49,7 +49,7 @@ class ScanWidget(QtWidgets.QWidget): return self.minimumSizeHint() def minimumSizeHint(self): - return QtCore.QSize(2.5*3*self._labelSize.width(), + return QtCore.QSize(int(2.5*3*self._labelSize.width()), 4*self._labelSize.height()) def _axisToPixel(self, val): @@ -214,7 +214,7 @@ class ScanWidget(QtWidgets.QWidget): self._setView(left, scale) def wheelEvent(self, ev): - y = ev.angleDelta().y()/120. + y = round(ev.angleDelta().y()/120.) if not y: return if ev.modifiers() & QtCore.Qt.ShiftModifier: @@ -252,22 +252,22 @@ class ScanWidget(QtWidgets.QWidget): for t, l in zip(ticks, labels): t = self._axisToPixel(t) - painter.drawText(t - len(l)/2*avgCharWidth, 0, l) - painter.drawLine(t, descent, t, lineSpacing/2) - painter.translate(0, lineSpacing/2) + painter.drawText(int(t - len(l)/2*avgCharWidth), 0, l) + painter.drawLine(int(t), descent, int(t), int(lineSpacing/2)) + painter.translate(0, int(lineSpacing/2)) painter.drawLine(0, 0, self.width(), 0) for p in np.linspace(self._axisToPixel(self._start), self._axisToPixel(self._stop), self._num): - painter.drawLine(p, 0, p, lineSpacing/2) - painter.translate(0, lineSpacing/2) + painter.drawLine(int(p), 0, int(p), int(lineSpacing/2)) + painter.translate(0, int(lineSpacing/2)) for x, c in (self._start, QtCore.Qt.blue), (self._stop, QtCore.Qt.red): x = self._axisToPixel(x) painter.setPen(c) painter.setBrush(c) painter.drawPolygon(*(QtCore.QPointF(*i) for i in [ - (x, 0), (x - lineSpacing/2, lineSpacing), - (x + lineSpacing/2, lineSpacing)])) + (int(x), 0), (int(x - lineSpacing/2), lineSpacing), + (int(x + lineSpacing/2), lineSpacing)])) diff --git a/artiq/gui/waitingspinnerwidget.py b/artiq/gui/waitingspinnerwidget.py index 6771bdbfe..6967e6dea 100644 --- a/artiq/gui/waitingspinnerwidget.py +++ b/artiq/gui/waitingspinnerwidget.py @@ -75,7 +75,7 @@ class QtWaitingSpinner(QWidget): color = self.currentLineColor(distance, self._numberOfLines, self._trailFadePercentage, self._minimumTrailOpacity, self._color) painter.setBrush(color) - painter.drawRoundedRect(QRect(0, -self._lineWidth / 2, self._lineLength, self._lineWidth), self._roundness, + painter.drawRoundedRect(QRect(0, int(-self._lineWidth / 2), self._lineLength, self._lineWidth), self._roundness, self._roundness, Qt.RelativeSize) painter.restore() @@ -160,7 +160,7 @@ class QtWaitingSpinner(QWidget): self.setFixedSize(self.size, self.size) def updateTimer(self): - self._timer.setInterval(1000 / (self._numberOfLines * self._revolutionsPerSecond)) + self._timer.setInterval(int(1000 / (self._numberOfLines * self._revolutionsPerSecond))) def lineCountDistanceFromPrimary(self, current, primary, totalNrOfLines): distance = primary - current