1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2024 PyMeasure Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
import logging
import pyqtgraph as pg
from ..curves import ResultsImage
from ..Qt import QtCore, QtWidgets
from .tab_widget import TabWidget
from .image_frame import ImageFrame
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
class ImageWidget(TabWidget, QtWidgets.QWidget):
""" Extends the :class:`ImageFrame<pymeasure.display.widgets.image_frame.ImageFrame>`
to allow different columns of the data to be dynamically chosen
"""
def __init__(self, name, columns, x_axis, y_axis, z_axis=None, refresh_time=0.2,
check_status=True, parent=None):
super().__init__(name, parent)
self.columns = columns
self.refresh_time = refresh_time
self.check_status = check_status
self.x_axis = x_axis
self.y_axis = y_axis
self._setup_ui()
self._layout()
if z_axis is not None:
self.columns_z.setCurrentIndex(self.columns_z.findText(z_axis))
self.image_frame.change_z_axis(z_axis)
def _setup_ui(self):
self.columns_z_label = QtWidgets.QLabel(self)
self.columns_z_label.setMaximumSize(QtCore.QSize(45, 16777215))
self.columns_z_label.setText('Z Axis:')
self.columns_z = QtWidgets.QComboBox(self)
for column in self.columns:
self.columns_z.addItem(column)
self.columns_z.activated.connect(self.update_z_column)
self.image_frame = ImageFrame(
self.x_axis,
self.y_axis,
self.columns[0],
self.refresh_time,
self.check_status
)
self.updated = self.image_frame.updated
self.plot = self.image_frame.plot
self.columns_z.setCurrentIndex(2)
def _layout(self):
vbox = QtWidgets.QVBoxLayout(self)
vbox.setSpacing(0)
hbox = QtWidgets.QHBoxLayout()
hbox.setSpacing(10)
hbox.setContentsMargins(-1, 6, -1, 6)
hbox.addWidget(self.columns_z_label)
hbox.addWidget(self.columns_z)
vbox.addLayout(hbox)
vbox.addWidget(self.image_frame)
self.setLayout(vbox)
def sizeHint(self):
return QtCore.QSize(300, 600)
def new_curve(self, results, color=pg.intColor(0), **kwargs):
""" Creates a new image """
image = ResultsImage(results,
wdg=self,
x=self.image_frame.x_axis,
y=self.image_frame.y_axis,
z=self.image_frame.z_axis,
**kwargs
)
return image
def update_z_column(self, index):
axis = self.columns_z.itemText(index)
self.image_frame.change_z_axis(axis)
def load(self, curve):
curve.z = self.columns_z.currentText()
curve.update_data()
self.plot.addItem(curve)
def remove(self, curve):
self.plot.removeItem(curve)
|