示例#1
0
class ResultImageView(ImageView):
    """
    :type _settings PartSettings:
    """
    def __init__(self, settings: PartSettings,
                 channel_property: ChannelProperty, name: str):
        super().__init__(settings, channel_property, name)
        self._channel_control_top = True
        self.only_border = QCheckBox("")
        self.image_state.only_borders = False
        self.only_border.setChecked(self.image_state.only_borders)
        self.only_border.stateChanged.connect(self.image_state.set_borders)
        self.opacity = QDoubleSpinBox()
        self.opacity.setRange(0, 1)
        self.opacity.setValue(self.image_state.opacity)
        self.opacity.setSingleStep(0.1)
        self.opacity.valueChanged.connect(self.image_state.set_opacity)
        self.opacity.setMinimumWidth(500)
        self.label1 = QLabel("Borders:")
        self.label2 = QLabel("Opacity:")
        self.btn_layout.insertWidget(3, self.label1)
        self.btn_layout.insertWidget(4, self.only_border)
        self.btn_layout.insertWidget(5, self.label2)
        self.btn_layout.insertWidget(6, self.opacity)
        self.label1.setVisible(False)
        self.label2.setVisible(False)
        self.opacity.setVisible(False)
        self.only_border.setVisible(False)

    def any_segmentation(self):
        for image_info in self.image_info.values():
            if image_info.segmentation is not None:
                return True
        return False

    @Slot()
    @Slot(SegmentationInfo)
    def set_segmentation(self,
                         segmentation_info: Optional[SegmentationInfo] = None,
                         image: Optional[Image] = None) -> None:
        super().set_segmentation(segmentation_info, image)
        show = self.any_segmentation()
        self.label1.setVisible(show)
        self.label2.setVisible(show)
        self.opacity.setVisible(show)
        self.only_border.setVisible(show)

    def resizeEvent(self, event: QResizeEvent):
        if event.size().width() > 700 and not self._channel_control_top:
            w = self.btn_layout2.takeAt(0).widget()
            self.btn_layout.takeAt(2)
            # noinspection PyArgumentList
            self.btn_layout.insertWidget(2, w)
            self._channel_control_top = True
        elif event.size().width() <= 700 and self._channel_control_top:
            w = self.btn_layout.takeAt(2).widget()
            self.btn_layout.insertStretch(2, 1)
            # noinspection PyArgumentList
            self.btn_layout2.insertWidget(0, w)
            self._channel_control_top = False
示例#2
0
 def createDoubleSpinBox(self, variable_name, variable_value, variable_type, analysis_module_variables_model):
     spinner = QDoubleSpinBox()
     spinner.setDecimals(6)
     spinner.setMinimumWidth(75)
     spinner.setMaximum(analysis_module_variables_model.getVariableMaximumValue(variable_name))
     spinner.setMinimum(analysis_module_variables_model.getVariableMinimumValue(variable_name))
     spinner.setSingleStep(analysis_module_variables_model.getVariableStepValue(variable_name))
     spinner.setValue(variable_value)
     spinner.valueChanged.connect(partial(self.valueChanged, variable_name, variable_type, spinner))
     return spinner
示例#3
0
class DimensionMDE(Dimension):
    binningChanged = Signal()
    """
    MDEventWorkspace has additional properties for either number_of_bins or thickness

    from mantidqt.widgets.sliceviewer.dimensionwidget import DimensionMDE
    from qtpy.QtWidgets import QApplication
    app = QApplication([])
    window = DimensionMDE({'minimum':-1.1, 'number_of_bins':11, 'width':0.2, 'name':'Dim0', 'units':'A'})
    window.show()
    app.exec_()
    """
    def __init__(self, dim_info, number=0, state=State.NONE, parent=None):

        # hack in a number_of_bins for MDEventWorkspace
        dim_info['number_of_bins'] = 1000
        dim_info['width'] = (dim_info['maximum'] - dim_info['minimum']) / 1000

        self.spinBins = QSpinBox()
        self.spinBins.setRange(2, 9999)
        self.spinBins.setValue(100)
        self.spinBins.hide()
        self.spinBins.setMinimumWidth(110)
        self.spinThick = QDoubleSpinBox()
        self.spinThick.setRange(0.001, 999)
        self.spinThick.setValue(0.1)
        self.spinThick.setSingleStep(0.1)
        self.spinThick.setDecimals(3)
        self.spinThick.setMinimumWidth(110)
        self.rebinLabel = QLabel("thick")
        self.rebinLabel.setMinimumWidth(44)

        super().__init__(dim_info, number, state, parent)

        self.spinBins.valueChanged.connect(self.binningChanged)
        self.spinThick.valueChanged.connect(self.valueChanged)

        self.layout.addWidget(self.spinBins)
        self.layout.addWidget(self.spinThick)
        self.layout.addWidget(self.rebinLabel)

    def get_bins(self):
        return int(self.spinBins.value())

    def get_thickness(self):
        return float(self.spinThick.value())

    def set_state(self, state):
        super().set_state(state)
        if self.state == State.X:
            self.spinBins.show()
            self.spinThick.hide()
            self.rebinLabel.setText('bins')
        elif self.state == State.Y:
            self.spinBins.show()
            self.spinThick.hide()
            self.rebinLabel.setText('bins')
        elif self.state == State.NONE:
            self.spinBins.hide()
            self.spinThick.show()
            self.rebinLabel.setText('thick')
        else:
            self.spinBins.hide()
            self.spinThick.hide()
            self.rebinLabel.hide()
示例#4
0
class DimensionNonIntegrated(Dimension):
    binningChanged = Signal()
    """
    A dimension that can either be sliced through or rebinned. It
    has additional properties for either number_of_bins or thickness

    from mantidqt.widgets.sliceviewer.dimensionwidget import DimensionMDE
    from qtpy.QtWidgets import QApplication
    app = QApplication([])
    window = DimensionNonIntegrated({'minimum':-1.1, 'number_of_bins':11,
                                     'width':0.2, 'name':'Dim0', 'units':'A'})
    window.show()
    app.exec_()
    """
    def __init__(self, dim_info, number=0, state=State.NONE, parent=None):
        # hack in a number_of_bins for MDEventWorkspace
        if dim_info['type'] == 'MDE':
            dim_info['number_of_bins'] = 100
            dim_info['width'] = (dim_info['maximum'] -
                                 dim_info['minimum']) / 100

        self.spinBins = QSpinBox()
        self.spinBins.setRange(2, 9999)
        self.spinBins.setValue(dim_info['number_of_bins'])
        self.spinBins.hide()
        self.spinBins.setMinimumWidth(110)
        self.spinThick = QDoubleSpinBox()
        self.spinThick.setRange(0.001, 999)
        self.spinThick.setValue(0.1)
        self.spinThick.setSingleStep(0.1)
        self.spinThick.setDecimals(3)
        self.spinThick.setMinimumWidth(110)
        self.rebinLabel = QLabel("thick")
        self.rebinLabel.setMinimumWidth(44)

        super().__init__(dim_info, number, state, parent)

        self.spinBins.valueChanged.connect(self.binningChanged)
        self.spinThick.valueChanged.connect(self.valueChanged)

        self.layout.addWidget(self.spinBins)
        self.layout.addWidget(self.spinThick)
        self.layout.addWidget(self.rebinLabel)

    def get_bins(self):
        return int(self.spinBins.value())

    def get_thickness(self):
        return float(self.spinThick.value())

    def set_state(self, state):
        super().set_state(state)
        if self.state == State.X:
            self.spinBins.show()
            self.spinThick.hide()
            self.rebinLabel.setText('bins')
        elif self.state == State.Y:
            self.spinBins.show()
            self.spinThick.hide()
            self.rebinLabel.setText('bins')
        elif self.state == State.NONE:
            self.spinBins.hide()
            self.spinThick.show()
            self.rebinLabel.setText('thick')
        else:
            self.spinBins.hide()
            self.spinThick.hide()
            self.rebinLabel.hide()

    def set_value(self, value):
        """Override the set_value for MDE, this allows the exact value to be
        set instead of limiting to the value of the slider. This
        allows when selecting a peak to go to the exact layer where
        the peak is.

        """
        self.value = value
        # temporary disable updating value from slider change
        self.update_value_from_slider = False
        self.update_slider()
        self.update_value_from_slider = True
        self.update_spinbox()
示例#5
0
class ResultImageView(ImageView):
    """
    :type _settings PartSettings:
    """
    def __init__(self, settings: PartSettings,
                 channel_property: ChannelProperty, name: str):
        super().__init__(settings, channel_property, name)
        self._channel_control_top = True
        self.only_border = QCheckBox("")
        self.image_state.only_borders = False
        self.only_border.setChecked(self.image_state.only_borders)
        self.only_border.stateChanged.connect(self.image_state.set_borders)
        self.opacity = QDoubleSpinBox()
        self.opacity.setRange(0, 1)
        self.opacity.setValue(self.image_state.opacity)
        self.opacity.setSingleStep(0.1)
        self.opacity.valueChanged.connect(self.image_state.set_opacity)
        self.opacity.setMinimumWidth(500)
        self.channel_control_index = self.btn_layout.indexOf(
            self.channel_control)
        self.label1 = QLabel("Borders:")
        self.label2 = QLabel("Opacity:")
        self.roi_alternative_select = QComboBox()
        self.roi_alternative_select.currentTextChanged.connect(
            self.image_state.set_roi_presented)

        self.btn_layout.insertWidget(self.channel_control_index + 1,
                                     self.label1)
        self.btn_layout.insertWidget(self.channel_control_index + 2,
                                     self.only_border)
        self.btn_layout.insertWidget(self.channel_control_index + 3,
                                     self.label2)
        self.btn_layout.insertWidget(self.channel_control_index + 4,
                                     self.opacity)
        self.btn_layout.insertWidget(self.channel_control_index + 1,
                                     self.roi_alternative_select)
        self.label1.setVisible(False)
        self.label2.setVisible(False)
        self.opacity.setVisible(False)
        self.only_border.setVisible(False)
        self.roi_alternative_select.setVisible(False)

    def any_roi(self):
        for image_info in self.image_info.values():
            if image_info.roi is not None:
                return True
        return False

    def available_alternatives(self):
        available_alternatives = set()
        for image_info in self.image_info.values():
            if image_info.roi_info.alternative:
                available_alternatives.update(
                    image_info.roi_info.alternative.keys())
        return available_alternatives

    @Slot()
    @Slot(ROIInfo)
    def set_roi(self,
                roi_info: Optional[ROIInfo] = None,
                image: Optional[Image] = None) -> None:
        super().set_roi(roi_info, image)
        show = self.any_roi()
        self.label1.setVisible(show)
        self.label2.setVisible(show)
        self.opacity.setVisible(show)
        self.only_border.setVisible(show)
        self.update_alternatives()

    def update_alternatives(self):
        alternatives = self.available_alternatives()
        self.roi_alternative_select.setVisible(bool(alternatives))
        text = self.roi_alternative_select.currentText()
        block = self.roi_alternative_select.signalsBlocked()
        self.roi_alternative_select.blockSignals(True)
        self.roi_alternative_select.clear()
        self.roi_alternative_select.addItems(["ROI"] + list(alternatives))
        self.roi_alternative_select.setCurrentText(text)
        self.roi_alternative_select.blockSignals(block)

    def resizeEvent(self, event: QResizeEvent):
        if event.size().width() > 700 and not self._channel_control_top:
            w = self.btn_layout2.takeAt(0).widget()
            self.btn_layout.takeAt(self.channel_control_index)
            # noinspection PyArgumentList
            self.btn_layout.insertWidget(self.channel_control_index, w)
            select = self.btn_layout2.takeAt(
                self.btn_layout2.indexOf(
                    self.roi_alternative_select)).widget()
            self.btn_layout.insertWidget(self.channel_control_index + 1,
                                         select)
            self._channel_control_top = True
        elif event.size().width() <= 700 and self._channel_control_top:
            w = self.btn_layout.takeAt(self.channel_control_index).widget()
            self.btn_layout.insertStretch(self.channel_control_index, 1)
            # noinspection PyArgumentList
            self.btn_layout2.insertWidget(0, w)
            select = self.btn_layout.takeAt(
                self.btn_layout.indexOf(self.roi_alternative_select)).widget()
            self.btn_layout2.insertWidget(1, select)
            self._channel_control_top = False
示例#6
0
class ResultImageView(ImageView):
    """
    :type _settings PartSettings:
    """

    def __init__(self, settings: PartSettings, channel_property: ChannelProperty, name: str):
        super().__init__(settings, channel_property, name)
        self._channel_control_top = True
        self.only_border = QCheckBox("")
        self._set_border_from_settings()
        self.only_border.stateChanged.connect(self._set_border)
        self.opacity = QDoubleSpinBox()
        self.opacity.setRange(0, 1)
        self.opacity.setSingleStep(0.1)
        self._set_opacity_from_settings()
        self.opacity.valueChanged.connect(self._set_opacity)
        self.opacity.setMinimumWidth(500)
        self.channel_control_index = self.btn_layout.indexOf(self.channel_control)
        self.label1 = QLabel("Borders:")
        self.label2 = QLabel("Opacity:")
        self.roi_alternative_select = QComboBox()
        self.roi_alternative_select.currentTextChanged.connect(self._set_roi_alternative_version)
        self.stretch = None

        self.btn_layout.insertWidget(self.channel_control_index + 1, self.label1)
        self.btn_layout.insertWidget(self.channel_control_index + 2, self.only_border)
        self.btn_layout.insertWidget(self.channel_control_index + 3, self.label2)
        self.btn_layout.insertWidget(self.channel_control_index + 4, self.opacity)
        self.btn_layout.insertWidget(self.channel_control_index + 1, self.roi_alternative_select)
        self.channel_control_index = self.btn_layout.indexOf(self.channel_control)

        self.label1.setVisible(False)
        self.label2.setVisible(False)
        self.opacity.setVisible(False)
        self.only_border.setVisible(False)
        self.roi_alternative_select.setVisible(False)

        self.settings.connect_to_profile(f"{self.name}.image_state.only_border", self._set_border_from_settings)
        self.settings.connect_to_profile(f"{self.name}.image_state.opacity", self._set_opacity_from_settings)

    def _set_border(self, value: bool):
        self.settings.set_in_profile(f"{self.name}.image_state.only_border", value)

    def _set_opacity(self, value: float):
        self.settings.set_in_profile(f"{self.name}.image_state.opacity", value)

    def _set_border_from_settings(self):
        self.only_border.setChecked(self.settings.get_from_profile(f"{self.name}.image_state.only_border", False))

    def _set_opacity_from_settings(self):
        self.opacity.setValue(self.settings.get_from_profile(f"{self.name}.image_state.opacity", 1))

    def _set_roi_alternative_version(self, name: str):
        self.roi_alternative_selection = name
        self.update_roi_border()

    def any_roi(self):
        return any(image_info.roi is not None for image_info in self.image_info.values())

    def available_alternatives(self):
        available_alternatives = set()
        for image_info in self.image_info.values():
            if image_info.roi_info.alternative:
                available_alternatives.update(image_info.roi_info.alternative.keys())
        return available_alternatives

    @Slot()
    @Slot(ROIInfo)
    def set_roi(self, roi_info: Optional[ROIInfo] = None, image: Optional[Image] = None) -> None:
        super().set_roi(roi_info, image)
        show = self.any_roi()
        self.label1.setVisible(show)
        self.label2.setVisible(show)
        self.opacity.setVisible(show)
        self.only_border.setVisible(show)
        self.update_alternatives()

    def update_alternatives(self):
        alternatives = self.available_alternatives()
        self.roi_alternative_select.setVisible(bool(alternatives))
        text = self.roi_alternative_select.currentText()
        block = self.roi_alternative_select.signalsBlocked()
        self.roi_alternative_select.blockSignals(True)
        self.roi_alternative_select.clear()
        values = ["ROI"] + list(alternatives)
        self.roi_alternative_select.addItems(values)
        try:
            self.roi_alternative_select.setCurrentIndex(values.index(text))
        except ValueError:
            pass
        self.roi_alternative_select.blockSignals(block)

    def resizeEvent(self, event: QResizeEvent):
        if event.size().width() > 800 and not self._channel_control_top:
            w = self.btn_layout2.takeAt(0).widget()
            channel_control_index = self.btn_layout.indexOf(self.search_roi_btn) + 1
            self.btn_layout.takeAt(channel_control_index)
            # noinspection PyArgumentList
            self.btn_layout.insertWidget(channel_control_index, w)
            select = self.btn_layout2.takeAt(self.btn_layout2.indexOf(self.roi_alternative_select)).widget()
            self.btn_layout.insertWidget(channel_control_index + 1, select)
            self._channel_control_top = True
        elif event.size().width() <= 800 and self._channel_control_top:
            channel_control_index = self.btn_layout.indexOf(self.channel_control)
            w = self.btn_layout.takeAt(channel_control_index).widget()
            self.btn_layout.insertStretch(channel_control_index, 1)
            # noinspection PyArgumentList
            self.btn_layout2.insertWidget(0, w)
            select = self.btn_layout.takeAt(self.btn_layout.indexOf(self.roi_alternative_select)).widget()
            self.btn_layout2.insertWidget(1, select)
            self._channel_control_top = False
示例#7
0
class DimensionMDE(Dimension):
    binningChanged = Signal()
    """
    MDEventWorkspace has additional properties for either number_of_bins or thickness

    from mantidqt.widgets.sliceviewer.dimensionwidget import DimensionMDE
    from qtpy.QtWidgets import QApplication
    app = QApplication([])
    window = DimensionMDE({'minimum':-1.1, 'number_of_bins':11, 'width':0.2, 'name':'Dim0', 'units':'A'})
    window.show()
    app.exec_()
    """
    def __init__(self, dim_info, number=0, state=State.NONE, parent=None):

        # hack in a number_of_bins for MDEventWorkspace
        dim_info['number_of_bins'] = 1000
        dim_info['width'] = (dim_info['maximum']-dim_info['minimum'])/1000

        self.spinBins = QSpinBox()
        self.spinBins.setRange(2,9999)
        self.spinBins.setValue(100)
        self.spinBins.hide()
        self.spinBins.setMinimumWidth(110)
        self.spinThick = QDoubleSpinBox()
        self.spinThick.setRange(0.001,999)
        self.spinThick.setValue(0.1)
        self.spinThick.setSingleStep(0.1)
        self.spinThick.setDecimals(3)
        self.spinThick.setMinimumWidth(110)
        self.rebinLabel = QLabel("thick")
        self.rebinLabel.setMinimumWidth(44)

        super(DimensionMDE, self).__init__(dim_info, number, state, parent)

        self.spinBins.valueChanged.connect(self.binningChanged)
        self.spinThick.valueChanged.connect(self.valueChanged)

        self.layout.addWidget(self.spinBins)
        self.layout.addWidget(self.spinThick)
        self.layout.addWidget(self.rebinLabel)

    def get_bins(self):
        return int(self.spinBins.value())

    def get_thickness(self):
        return float(self.spinThick.value())

    def set_state(self, state):
        super(DimensionMDE, self).set_state(state)
        if self.state == State.X:
            self.spinBins.show()
            self.spinThick.hide()
            self.rebinLabel.setText('bins')
        elif self.state == State.Y:
            self.spinBins.show()
            self.spinThick.hide()
            self.rebinLabel.setText('bins')
        elif self.state == State.NONE:
            self.spinBins.hide()
            self.spinThick.show()
            self.rebinLabel.setText('thick')
        else:
            self.spinBins.hide()
            self.spinThick.hide()
            self.rebinLabel.hide()