diff --git a/src/metro/devices/display/fast_plot.py b/src/metro/devices/display/fast_plot.py index dd2ab2a..5fdc12a 100644 --- a/src/metro/devices/display/fast_plot.py +++ b/src/metro/devices/display/fast_plot.py @@ -558,12 +558,16 @@ def paintEvent(self, event): for x_data, text in vlines_it: if self.plot_axes[0] < x_data < self.plot_axes[1]: - x_widget = int(x_data * div) - p.drawLine(x_widget, 0, x_widget, y_end) + x_widget = x_data * div + p.drawLine( + QtCore.QPointF(x_widget, 0), + QtCore.QPointF(x_widget, y_end) + ) if text is not None: p.drawText(p.boundingRect( - x_widget+5, y_end, 1, 1, flags, text), + QtCore.QRectF(x_widget+5, y_end, 1, 1), + flags, text), flags, text) p.restore() @@ -587,12 +591,13 @@ def paintEvent(self, event): for y_data, text in hlines_it: if self.plot_axes[2] < y_data < self.plot_axes[3]: - y_widget = int(-y_data * div) + y_widget = -y_data * div p.drawLine(0, y_widget, x_end, y_widget) if text is not None: p.drawText(p.boundingRect( - x_end, y_widget, 1, 1, flags, text), + QtCore.QRectF(x_end, y_widget, 1, 1), + flags, text), flags, text) p.restore() @@ -791,7 +796,7 @@ def on_render_completed(self): def _buildAxisLabel(self, value, x, y, p, flags): text = str(value) - r = p.boundingRect(int(x), int(y), 1, 1, flags, text) + r = p.boundingRect(QtCore.QRectF(x, y, 1, 1), flags, text) r._flags = flags r._str = text diff --git a/src/metro/devices/display/hist2d.py b/src/metro/devices/display/hist2d.py index b823fb8..4ee8a69 100755 --- a/src/metro/devices/display/hist2d.py +++ b/src/metro/devices/display/hist2d.py @@ -117,8 +117,8 @@ def __init__(self, parent, size_x, size_y, roi_map={}, title=None): # The spectrum along y, how often does each y value occur self.y_spectrum = numpy.zeros((size_y,), dtype=numpy.int32) - self.x_spectrum_polygon = QtGui.QPolygon(size_x) - self.y_spectrum_polygon = QtGui.QPolygon(size_y) + self.x_spectrum_polygon = QtGui.QPolygonF(size_x) + self.y_spectrum_polygon = QtGui.QPolygonF(size_y) self.x_scaling = 1 self.y_scaling = 1 @@ -269,13 +269,15 @@ def paintEvent(self, event): x_scale = n_points / self.data_img_dest.width() y_scale = x_spectrum_max / 130 - polygon = self.x_spectrum_polygon - for i in range(0, n_points): - polygon.setPoint( - i, int(i / x_scale), - 145 - int(x_spectrum[x_min+i] / y_scale)) + self.x_spectrum_polygon = QtGui.QPolygonF( + [QtCore.QPointF( + i / x_scale, + 145 - x_spectrum[x_min+i] / y_scale + ) + for i in range(n_points)] + ) - qp.drawPolyline(polygon) + qp.drawPolyline(self.x_spectrum_polygon) qp.rotate(90) qp.drawText(3, -(self.data_img_dest.width()+22), 150, 20, @@ -294,14 +296,15 @@ def paintEvent(self, event): x_offset = 5 + int(self.data_img_dest.right()) - polygon = self.y_spectrum_polygon - for i in range(0, n_points): - polygon.setPoint( - i, + self.y_spectrum_polygon = QtGui.QPolygonF( + [QtCore.QPointF( x_offset + int(y_spectrum[y_min+i] / x_scale), - 150 + int(self.data_img_dest.height() - i / y_scale)) + 150 + self.data_img_dest.height() - i / y_scale + ) + for i in range(n_points)] + ) - qp.drawPolyline(polygon) + qp.drawPolyline(self.y_spectrum_polygon) qp.drawText(self.data_img_dest.right(), 150 - 22, 97, 20, QtCore.Qt.AlignRight | QtCore.Qt.AlignBottom, @@ -348,12 +351,12 @@ def paintEvent(self, event): for label, line in zip(self.axes_tick_x_labels, self.axes_tick_x_lines): - qp.drawText(int(line.x1()) - 40, int(line.y1()) - 20, 80, 20, + qp.drawText(QtCore.QRectF(line.x1() - 40, line.y1() - 20, 80, 20), QtCore.Qt.AlignCenter, str(label)) for label, line in zip(self.axes_tick_y_labels, self.axes_tick_y_lines): - qp.drawText(int(line.x1()) + 10, int(line.y1()) - 10, 80, 20, + qp.drawText(QtCore.QRectF(line.x1() + 10, line.y1() - 10, 80, 20), QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, str(label)) @@ -445,7 +448,7 @@ def _buildAxisRect(self, qp, name, x, y, flags): return r def _buildRoiAreaRect(self, qp, name, x, y, w, h): - r = QtCore.QRect(x, y, w, h) + r = QtCore.QRectF(x, y, w, h) r.roi_name = name r.cursor = QtCore.Qt.SizeAllCursor r.type = DetectorImageWidget.HOT_RECT_ROI_AREA @@ -453,7 +456,7 @@ def _buildRoiAreaRect(self, qp, name, x, y, w, h): self.hot_rects.append(r) def _buildRoiEdgeRect(self, qp, name, edge_id, x, y, w, h): - r = QtCore.QRect(x, y, w, h) + r = QtCore.QRectF(x, y, w, h) r.roi_name = name r.cursor = QtCore.Qt.SizeVerCursor \ if w > h else QtCore.Qt.SizeHorCursor @@ -589,7 +592,7 @@ def _rebuildStaticObjects(self, qp): if (left_visible and bottom_visible and right_visible and top_visible): - roi['shape'] = QtCore.QRect(roi_x, 150 + roi_y, + roi['shape'] = QtCore.QRectF(roi_x, 150 + roi_y, roi_width, roi_height) else: shapes = [] @@ -1091,9 +1094,9 @@ def _updateRects(self): self.axes['y_max'] - self.axes['y_min'] ) - self.x_spectrum_polygon = QtGui.QPolygon( + self.x_spectrum_polygon = QtGui.QPolygonF( self.axes['x_max'] - self.axes['x_min']) - self.y_spectrum_polygon = QtGui.QPolygon( + self.y_spectrum_polygon = QtGui.QPolygonF( self.axes['y_max'] - self.axes['y_min']) def _updateProj(self): diff --git a/src/metro/devices/display/image.py b/src/metro/devices/display/image.py index 617aeaa..b8e0f53 100644 --- a/src/metro/devices/display/image.py +++ b/src/metro/devices/display/image.py @@ -13,7 +13,7 @@ from PyQt5 import QtGui from PyQt5 import QtWidgets import pyqtgraph -pyqtgraph.setConfigOptions(antialias=False) +pyqtgraph.setConfigOptions(antialias=True) import metro from metro.devices.abstract import fittable_plot @@ -22,8 +22,7 @@ # lower bracket though for very small values (< 1e-3 relatively) which # is pure black. from pyqtgraph.graphicsItems.GradientEditorItem import Gradients -#from metro.external.pyqtgraph.graphicsItems.GradientEditorItem \ -# import Gradients # noqa + default_gradient = Gradients['viridis'].copy() default_gradient['ticks'][0] = (1e-3, default_gradient['ticks'][0][1]) default_gradient['ticks'].insert(0, (0.0, (0, 0, 0, 255))) @@ -133,15 +132,17 @@ def _drawMarkers(self, p, view, markers): for label, pos in markers: m = view.mapViewToDevice(pos) - x = int(m.x()) - y = int(m.y()) + x = m.x() + y = m.y() - p.drawLine(x - 20, y, x + 20, y) - p.drawLine(x, y - 20, x, y + 20) + p.drawLine(QtCore.QPointF(x - 20, y), QtCore.QPointF(x + 20, y)) + p.drawLine(QtCore.QPointF(x, y - 20), QtCore.QPointF(x, y + 20)) if label is not None: p.drawText(p.boundingRect( - x, y + 20, 1, 1, flags, label), flags, label) + QtCore.QRectF(x, y + 20, 1, 1), flags, label), + flags, label + ) def paint(self, p, *args): # Verbatim copy of ImageItem.paint() except for the actual @@ -183,12 +184,13 @@ def paint(self, p, *args): vlines_it = zip(self.vlines, repeat(None)) for dx, text in vlines_it: - rx = int(view.mapViewToDevice(QtCore.QPointF(dx, 0)).x()) - p.drawLine(rx, 0, rx, height) + rx = view.mapViewToDevice(QtCore.QPointF(dx, 0)).x() + p.drawLine(QtCore.QPointF(rx, 0), QtCore.QPointF(rx, height)) if text is not None: p.drawText(p.boundingRect( - rx + 4, 4, 1, 1, flags, text), flags, text) + QtCore.QRectF(rx + 4, 4, 1, 1), flags, text), + flags, text) if self.hlines is not None: width = p.device().geometry().width() @@ -200,12 +202,13 @@ def paint(self, p, *args): hlines_it = zip(self.hlines, repeat(None)) for dy, text in hlines_it: - ry = int(view.mapViewToDevice(QtCore.QPointF(0, dy)).y()) - p.drawLine(0, ry, width, ry) + ry = view.mapViewToDevice(QtCore.QPointF(0, dy)).y() + p.drawLine(QtCore.QPointF(0, ry), QtCore.QPointF(width, ry)) if text is not None: p.drawText(p.boundingRect( - width - 4, ry + 2, 1, 1, flags, text), flags, text) + QtCore.QRectF(width - 4, ry + 2, 1, 1), flags, text), + flags, text) if self.rects is not None: flags = QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft @@ -250,8 +253,10 @@ def paint(self, p, *args): if text is not None: p.drawText(p.boundingRect( - rect.center().x(), rect.bottom() + 1, 1, 1, flags, text - ), flags, text) + QtCore.QRectF( + rect.center().x(), rect.bottom() + 1, 1, 1), + flags, text), + flags, text) p.setFont(self._marker_font)