# -*- coding: utf-8 -*-
"""
This file contains custom widgets to facilitate 2D image display with an adjustable colorscale and
various other interactive features.
Copyright (c) 2021, the qudi developers. See the AUTHORS.md file at the top-level directory of this
distribution and on <https://github.com/Ulm-IQO/qudi-core/>
This file is part of qudi.
Qudi is free software: you can redistribute it and/or modify it under the terms of
the GNU Lesser General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
Qudi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with qudi.
If not, see <https://www.gnu.org/licenses/>.
"""
__all__ = ['ImageWidget', 'MouseTrackingImageWidget', 'RubberbandZoomImageWidget',
'DataSelectionImageWidget', 'RubberbandZoomSelectionImageWidget']
from typing import Union, Optional, Tuple, List, Dict
from PySide2 import QtCore, QtWidgets
from pyqtgraph import PlotWidget as _PlotWidget
from qudi.util.widgets.plotting.plot_item import DataImageItem as _DataImageItem
from qudi.util.widgets.plotting.colorbar import ColorBarWidget as _ColorBarWidget
import qudi.util.widgets.plotting.plot_widget as _pw
[docs]
class MouseTrackingMixin:
""" Extends the normal qudi ImageWidget with a custom PlotWidget type that tracks mouse
activity and sends signals.
"""
_plot_widget_type = _pw.MouseTrackingPlotWidget
[docs]
def __init__(self, parent: Optional[QtWidgets.QWidget] = None, **kwargs):
super().__init__(parent=parent, **kwargs)
@property
def sigMouseMoved(self) -> QtCore.Signal:
return self.plot_widget.sigMouseMoved
@property
def sigMouseDragged(self) -> QtCore.Signal:
return self.plot_widget.sigMouseDragged
@property
def sigMouseClicked(self) -> QtCore.Signal:
return self.plot_widget.sigMouseClicked
[docs]
class RubberbandZoomMixin:
""" Extends the qudi MouseTrackingImageWidget with a rubberband zoom tool.
"""
_plot_widget_type = _pw.RubberbandZoomPlotWidget
SelectionMode = _pw.RubberbandZoomPlotWidget.SelectionMode
[docs]
def __init__(self, parent: Optional[QtWidgets.QWidget] = None, **kwargs):
super().__init__(parent=parent, **kwargs)
self.set_rubberband_zoom_selection_mode = self.plot_widget.set_rubberband_zoom_selection_mode
@property
def sigZoomAreaApplied(self) -> QtCore.Signal:
return self.plot_widget.sigZoomAreaApplied
@property
def rubberband_zoom_selection_mode(self) -> SelectionMode:
return self.plot_widget.rubberband_zoom_selection_mode
[docs]
class DataSelectionMixin:
""" Extends the qudi MouseTrackingImageWidget with data selection tools and signals.
"""
_plot_widget_type = _pw.DataSelectionPlotWidget
SelectionMode = _pw.DataSelectionPlotWidget.SelectionMode
[docs]
def __init__(self, parent: Optional[QtWidgets.QWidget] = None, **kwargs):
super().__init__(parent=parent, **kwargs)
self.set_region_selection_mode = self.plot_widget.set_region_selection_mode
self.set_marker_selection_mode = self.plot_widget.set_marker_selection_mode
self.set_selection_mutable = self.plot_widget.set_selection_mutable
self.set_selection_bounds = self.plot_widget.set_selection_bounds
self.add_region_selection = self.plot_widget.add_region_selection
self.add_marker_selection = self.plot_widget.add_marker_selection
self.move_region_selection = self.plot_widget.move_region_selection
self.move_marker_selection = self.plot_widget.move_marker_selection
self.clear_marker_selections = self.plot_widget.clear_marker_selections
self.delete_marker_selection = self.plot_widget.delete_marker_selection
self.clear_region_selections = self.plot_widget.clear_region_selections
self.delete_region_selection = self.plot_widget.delete_region_selection
self.hide_marker_selections = self.plot_widget.hide_marker_selections
self.show_marker_selections = self.plot_widget.show_marker_selections
self.hide_marker_selection = self.plot_widget.hide_marker_selection
self.show_marker_selection = self.plot_widget.show_marker_selection
self.hide_region_selections = self.plot_widget.hide_region_selections
self.show_region_selections = self.plot_widget.show_region_selections
self.hide_region_selection = self.plot_widget.hide_region_selection
self.show_region_selection = self.plot_widget.show_region_selection
@property
def sigMarkerSelectionChanged(self) -> QtCore.Signal:
return self.plot_widget.sigMarkerSelectionChanged
@property
def sigRegionSelectionChanged(self) -> QtCore.Signal:
return self.plot_widget.sigRegionSelectionChanged
@property
def marker_selection(self) -> Dict[SelectionMode, List[Tuple[float, float]]]:
return self.plot_widget.marker_selection
@property
def region_selection(self) -> Dict[SelectionMode, List[Tuple[Tuple[float, float], Tuple[float, float]]]]:
return self.plot_widget.region_selection
@property
def region_selection_mode(self) -> _pw.DataSelectionPlotWidget.SelectionMode:
return self.plot_widget.region_selection_mode
@property
def marker_selection_mode(self) -> _pw.DataSelectionPlotWidget.SelectionMode:
return self.plot_widget.marker_selection_mode
@property
def selection_mutable(self) -> bool:
return self.plot_widget.selection_mutable
@property
def selection_bounds(self) -> Union[None, List[Union[None, Tuple[float, float]]]]:
return self.plot_widget.selection_bounds