Ejemplo n.º 1
0
class OptionsWidget(QWidget):

    file_att = CurrentComboDataProperty('ui.combo_file_attribute')

    def __init__(self, parent=None, data_viewer=None):

        super(OptionsWidget, self).__init__(parent=parent)

        self.ui = load_ui('viewer_options.ui',
                          self,
                          directory=os.path.dirname(__file__))

        self.file_helper = ComponentIDComboHelper(self.ui.combo_file_attribute,
                                                  data_viewer._data)

        self._data_viewer = data_viewer

        self._data = None

    def set_data(self, data):
        self.file_helper.clear()

        if isinstance(data, Subset):
            self.file_helper.append_data(data.data)
        else:
            self.file_helper.append_data(data)
Ejemplo n.º 2
0
class OptionsWidget(QWidget):

    file_att = CurrentComboDataProperty('ui.combo_file_attribute')

    def __init__(self, parent=None, data_viewer=None):

        super(OptionsWidget, self).__init__(parent=parent)

        self.ui = load_ui('viewer_options.ui', self,
                          directory=os.path.dirname(__file__))

        self.file_helper = ComponentIDComboHelper(self.ui.combo_file_attribute,
                                                  data_viewer._data, categorical=True, numeric=False)

        self._data_viewer = data_viewer

        self._data = None

    def set_data(self, data):
        self.file_helper.clear()

        if isinstance(data, Subset):
            self.file_helper.append_data(data.data)
        else:
            self.file_helper.append_data(data)
        print(self.file_att)
Ejemplo n.º 3
0
class ImageLayerStyleEditor(QtWidgets.QWidget):

    def __init__(self, layer, parent=None):

        super(ImageLayerStyleEditor, self).__init__(parent=parent)

        self.ui = load_ui('layer_style_editor.ui', self,
                          directory=os.path.dirname(__file__))

        connect_kwargs = {'alpha': dict(value_range=(0, 1)),
                          'contrast': dict(value_range=(0.1, 10), log=True),
                          'bias': dict(value_range=(1.5, -0.5))}

        percentiles = [('Min/Max', 100),
                       ('99.5%', 99.5),
                       ('99%', 99),
                       ('95%', 95),
                       ('90%', 90),
                       ('Custom', 'Custom')]

        update_combobox(self.ui.combodata_percentile, percentiles)

        stretches = [('Linear', 'linear'),
                     ('Square Root', 'sqrt'),
                     ('Arcsinh', 'arcsinh'),
                     ('Logarithmic', 'log')]

        update_combobox(self.ui.combodata_stretch, stretches)

        self.attribute_helper = ComponentIDComboHelper(self.ui.combodata_attribute,
                                                       layer.data_collection)

        self.attribute_helper.append_data(layer.layer)

        autoconnect_callbacks_to_qt(layer.state, self.ui, connect_kwargs)

        layer._viewer_state.add_callback('color_mode', self._update_color_mode)

        self._update_color_mode(layer._viewer_state.color_mode)

        self.ui.bool_global_sync.setToolTip('Whether to sync the color and transparency with other viewers')

    def _update_color_mode(self, color_mode):
        if color_mode == 'Colormaps':
            self.ui.color_color.hide()
            self.ui.combodata_cmap.show()
        else:
            self.ui.color_color.show()
            self.ui.combodata_cmap.hide()
class OptionsWidget(QtWidgets.QWidget):

    x_att = TextProperty('ui.text_x_attribute')
    y_att = CurrentComboProperty('ui.combo_y_attribute')

    def __init__(self, parent=None, data_viewer=None):

        super(OptionsWidget, self).__init__(parent=parent)

        self.ui = load_ui('viewer_options.ui', self,
                          directory=os.path.dirname(__file__))

        self.y_helper = ComponentIDComboHelper(self.ui.combo_y_attribute,
                                               data_viewer._data, categorical=False)

        self._data_viewer = data_viewer

        self._data = None

    def append(self, data):
        self.y_helper.append_data(data)

    def remove(self, data):
        self.y_helper.remove_data(data)
Ejemplo n.º 5
0
class TestAttributeLimitsHelper():
    def setup_method(self, method):

        self.attribute_combo = QtWidgets.QComboBox()
        self.lower_value = QtWidgets.QLineEdit()
        self.upper_value = QtWidgets.QLineEdit()
        self.mode_combo = QtWidgets.QComboBox()
        self.flip_button = QtWidgets.QToolButton()

        self.log_button = QtWidgets.QToolButton()
        self.log_button.setCheckable(True)

        self.data = Data(x=np.linspace(-100, 100, 10000),
                         y=np.linspace(2, 3, 10000),
                         label='test_data')

        self.data_collection = DataCollection([self.data])

        self.helper = AttributeLimitsHelper(self.attribute_combo,
                                            self.lower_value,
                                            self.upper_value,
                                            mode_combo=self.mode_combo,
                                            flip_button=self.flip_button,
                                            log_button=self.log_button)

        self.component_helper = ComponentIDComboHelper(self.attribute_combo,
                                                       self.data_collection)

        self.component_helper.append_data(self.data)

        self.x_id = self.data.visible_components[0]
        self.y_id = self.data.visible_components[1]

    def test_attributes(self):
        assert self.attribute_combo.count() == 2
        assert self.attribute_combo.itemText(0) == 'x'
        assert self.attribute_combo.itemData(0)[0] is self.x_id
        assert self.attribute_combo.itemData(0)[1] is self.data
        assert self.attribute_combo.itemText(1) == 'y'
        assert self.attribute_combo.itemData(1)[0] is self.y_id
        assert self.attribute_combo.itemData(1)[1] is self.data

    def test_minmax(self):
        assert self.helper.vlo == -100
        assert self.helper.vhi == +100

    def test_change_attribute(self):
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == -100
        assert self.helper.vhi == +100

    def test_change_scale_mode(self):

        # Changing scale mode updates the limits
        self.helper.scale_mode = '99.5%'
        assert self.helper.vlo == -99.5
        assert self.helper.vhi == +99.5
        self.helper.scale_mode = '99%'
        assert self.helper.vlo == -99
        assert self.helper.vhi == +99
        self.helper.scale_mode = '90%'
        assert self.helper.vlo == -90
        assert self.helper.vhi == +90

        # When switching to custom, the last limits are retained
        self.helper.scale_mode = 'Custom'
        assert self.helper.vlo == -90
        assert self.helper.vhi == +90

    def test_scale_mode_cached(self):
        # Make sure that if we change scale and change attribute, the scale
        # modes are cached on a per-attribute basis.
        self.helper.scale_mode = '99.5%'
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.scale_mode == 'Min/Max'
        self.helper.scale_mode = '99%'
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.scale_mode == '99.5%'
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.scale_mode == '99%'

    def test_flip_button(self):

        # Flipping should swap lower and upper value
        try:
            self.flip_button.clicked.emit(True)
        except TypeError:  # PySide
            self.flip_button.clicked.emit()

        assert self.helper.vlo == +100
        assert self.helper.vhi == -100

        # Make sure that values were re-cached when flipping
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == +100
        assert self.helper.vhi == -100

    def test_manual_edit(self):

        # Make sure that values are re-cached when edited manually
        self.helper.scale_mode = 'Custom'
        self.lower_value.setText('-122')
        self.upper_value.setText('234')
        self.helper.vlog = True
        assert self.helper.vlo == -122
        assert self.helper.vhi == 234
        assert self.helper.vlog
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        assert not self.helper.vlog
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == -122
        assert self.helper.vhi == 234
        assert self.helper.vlog
Ejemplo n.º 6
0
class TestAttributeLimitsHelper():

    def setup_method(self, method):

        self.attribute_combo = QtWidgets.QComboBox()
        self.lower_value = QtWidgets.QLineEdit()
        self.upper_value = QtWidgets.QLineEdit()
        self.mode_combo = QtWidgets.QComboBox()
        self.flip_button = QtWidgets.QToolButton()

        self.log_button = QtWidgets.QToolButton()
        self.log_button.setCheckable(True)

        self.data = Data(x=np.linspace(-100, 100, 10000),
                         y=np.linspace(2, 3, 10000), label='test_data')

        self.data_collection = DataCollection([self.data])

        self.helper = AttributeLimitsHelper(self.attribute_combo,
                                            self.lower_value, self.upper_value,
                                            mode_combo=self.mode_combo,
                                            flip_button=self.flip_button,
                                            log_button=self.log_button)

        self.component_helper = ComponentIDComboHelper(self.attribute_combo, self.data_collection)

        self.component_helper.append_data(self.data)

        self.x_id = self.data.visible_components[0]
        self.y_id = self.data.visible_components[1]

    def test_attributes(self):
        assert self.attribute_combo.count() == 2
        assert self.attribute_combo.itemText(0) == 'x'
        assert self.attribute_combo.itemData(0)[0] is self.x_id
        assert self.attribute_combo.itemData(0)[1] is self.data
        assert self.attribute_combo.itemText(1) == 'y'
        assert self.attribute_combo.itemData(1)[0] is self.y_id
        assert self.attribute_combo.itemData(1)[1] is self.data

    def test_minmax(self):
        assert self.helper.vlo == -100
        assert self.helper.vhi == +100

    def test_change_attribute(self):
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == -100
        assert self.helper.vhi == +100

    def test_change_scale_mode(self):

        # Changing scale mode updates the limits
        self.helper.scale_mode = '99.5%'
        assert self.helper.vlo == -99.5
        assert self.helper.vhi == +99.5
        self.helper.scale_mode = '99%'
        assert self.helper.vlo == -99
        assert self.helper.vhi == +99
        self.helper.scale_mode = '90%'
        assert self.helper.vlo == -90
        assert self.helper.vhi == +90

        # When switching to custom, the last limits are retained
        self.helper.scale_mode = 'Custom'
        assert self.helper.vlo == -90
        assert self.helper.vhi == +90

    def test_scale_mode_cached(self):
        # Make sure that if we change scale and change attribute, the scale
        # modes are cached on a per-attribute basis.
        self.helper.scale_mode = '99.5%'
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.scale_mode == 'Min/Max'
        self.helper.scale_mode = '99%'
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.scale_mode == '99.5%'
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.scale_mode == '99%'

    def test_flip_button(self):

        # Flipping should swap lower and upper value
        try:
            self.flip_button.clicked.emit(True)
        except TypeError:  # PySide
            self.flip_button.clicked.emit()

        assert self.helper.vlo == +100
        assert self.helper.vhi == -100

        # Make sure that values were re-cached when flipping
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == +100
        assert self.helper.vhi == -100

    def test_manual_edit(self):

        # Make sure that values are re-cached when edited manually
        self.helper.scale_mode = 'Custom'
        self.lower_value.setText('-122')
        self.upper_value.setText('234')
        self.helper.vlog = True
        assert self.helper.vlo == -122
        assert self.helper.vhi == 234
        assert self.helper.vlog
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        assert not self.helper.vlog
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == -122
        assert self.helper.vhi == 234
        assert self.helper.vlog