def _setup_options(self):
        """
        Set up the combo box with the list of attributes
        """

        # Set up radio buttons for subset mode selection if this is a subset
        if isinstance(self.layer, Subset):
            self._radio_size = QtGui.QButtonGroup()
            self._radio_size.addButton(self.ui.radio_subset_outline)
            self._radio_size.addButton(self.ui.radio_subset_data)
        else:
            self.ui.radio_subset_outline.hide()
            self.ui.radio_subset_data.hide()
            self.ui.label_subset_mode.hide()

        # Set up attribute list
        label_data = [(comp.label, comp) for comp in self.visible_components]
        update_combobox(self.ui.combo_attribute, label_data)

        # Set up connections with layer artist
        connect_current_combo(self.layer_artist, 'attribute', self.ui.combo_attribute)
        connect_float_edit(self.layer_artist, 'vmin', self.ui.value_min)
        connect_float_edit(self.layer_artist, 'vmax', self.ui.value_max)
        connect_color(self.layer_artist, 'color', self.ui.label_color)
        connect_value(self.layer_artist, 'alpha', self.ui.slider_alpha, value_range=(0, 1))

        # Set up internal connections
        self.ui.radio_subset_outline.toggled.connect(self._update_subset_mode)
        self.ui.radio_subset_data.toggled.connect(self._update_subset_mode)
        self.ui.value_min.editingFinished.connect(self._cache_limits)
        self.ui.value_max.editingFinished.connect(self._cache_limits)
        self.ui.combo_attribute.currentIndexChanged.connect(self._update_limits)
示例#2
0
 def _populate_function_combo(self):
     """ Add name of functions to function combo box """
     f = [f for f in link_function.members if len(f.output_labels) == 1]
     functions = ((get_function_name(l[0]), l)
                  for l in f + link_helper.members
                  if l.category == self.category)
     update_combobox(self._ui.function, functions)
    def update_info(self, index):
        """
        Update width and hight based on combo index.
        Callback for combo box.
        """
        key = self.slit_type_combo.currentData()

        length = width = None
        width_units = length_units = ''
        if key == 'default':
            slit_info = self.mosviz_viewer.get_slit_dimensions_from_file()
            width_units, length_units = self.mosviz_viewer.get_slit_units_from_file()
            if slit_info is None:
                length, width = ['N/A', 'N/A']
            else:
                length, width = slit_info
        elif key != 'custom':
            if 'length' in self.slit_dict[key]:
                length = self.slit_dict[key]['length']
            if 'width' in self.slit_dict[key]:
                width = self.slit_dict[key]['width']
        else:
            width_units = length_units = 'arcsec'

        for input_widget in [self.slit_width_input, self.slit_length_input]:
            input_widget.setStyleSheet("")

        if isinstance(width, list):
            self.slit_width_input.hide()
            self.slit_width_combo.show()
            combo_input = [(str(i), str(i)) for i in width]
            update_combobox(self.slit_width_combo, combo_input)
        elif width is None:
            self.slit_width_combo.hide()
            self.slit_width_input.show()
            self.slit_width_input.setText('')
            self.slit_width_input.setDisabled(False)
        else:
            self.slit_width_combo.hide()
            self.slit_width_input.show()
            self.slit_width_input.setText(str(width))
            self.slit_width_input.setDisabled(True)
        self.slit_width_units.setText(width_units)

        if isinstance(length, list):
            self.slit_length_input.hide()
            self.slit_length_combo.show()
            combo_input = [(str(i), str(i)) for i in length]
            update_combobox(self.slit_length_combo, combo_input)
        elif length is None:
            self.slit_length_combo.hide()
            self.slit_length_input.show()
            self.slit_length_input.setText('')
            self.slit_length_input.setDisabled(False)
        else:
            self.slit_length_combo.hide()
            self.slit_length_input.show()
            self.slit_length_input.setText(str(length))
            self.slit_length_input.setDisabled(True)
        self.slit_length_units.setText(length_units)
    def _setup_options(self):
        """
        Set up the combo box with the list of attributes
        """

        # Set up radio buttons for subset mode selection if this is a subset
        if isinstance(self.layer, Subset):
            self._radio_size = QtWidgets.QButtonGroup()
            self._radio_size.addButton(self.ui.radio_subset_outline)
            self._radio_size.addButton(self.ui.radio_subset_data)
        else:
            self.ui.radio_subset_outline.hide()
            self.ui.radio_subset_data.hide()
            self.ui.label_subset_mode.hide()

        # Set up attribute list
        label_data = [(comp.label, comp) for comp in self.visible_components]
        update_combobox(self.ui.combo_attribute, label_data)

        # Set up connections with layer artist
        connect_current_combo(self.layer_artist, 'attribute', self.ui.combo_attribute)
        connect_float_edit(self.layer_artist, 'vmin', self.ui.value_min)
        connect_float_edit(self.layer_artist, 'vmax', self.ui.value_max)
        connect_color(self.layer_artist, 'color', self.ui.label_color)
        connect_value(self.layer_artist, 'alpha', self.ui.slider_alpha, value_range=(0, 1))

        # Set up internal connections
        self.ui.radio_subset_outline.toggled.connect(self._update_subset_mode)
        self.ui.radio_subset_data.toggled.connect(self._update_subset_mode)
        self.ui.value_min.editingFinished.connect(self._cache_limits)
        self.ui.value_max.editingFinished.connect(self._cache_limits)
        self.ui.combo_attribute.currentIndexChanged.connect(self._update_limits)
示例#5
0
    def _init_ui(self):
        # LINE 1: Data component drop down
        self.component_prompt = QLabel("Data Component:")
        self.component_prompt.setWordWrap(True)
        # Add the data component labels to the drop down, with the ComponentID
        # set as the userData:
        if self.parent is not None and hasattr(self.parent, 'data_components'):
            self.label_data = [(str(cid), cid) for cid in self.parent.data_components]
        else:
            self.label_data = [(str(cid), cid) for cid in self.data.visible_components]

        default_index = 0
        self.component_combo = QComboBox()
        self.component_combo.setFixedWidth(200)
        update_combobox(self.component_combo, self.label_data, default_index=default_index)
        self.component_combo.currentIndexChanged.connect(self.update_unit_layout)

        # hbl is short for Horizontal Box Layout
        hbl1 = QHBoxLayout()
        hbl1.addWidget(self.component_prompt)
        hbl1.addWidget(self.component_combo)
        hbl1.addStretch(1)

        # LINE 2: Unit conversion layout
        # This layout is filled by CubeVizUnit
        self.unit_layout = QHBoxLayout()  # this is hbl2

        # LINE 3: Message box
        self.message_box = QLabel("")
        hbl3 = QHBoxLayout()
        hbl3.addWidget(self.message_box)
        hbl3.addStretch(1)

        # Line 4: Buttons
        ok_text = "Convert Data" if self.convert_data else "Convert Displayed Units"
        ok_function = self.convert_data_units if self.convert_data else self.convert_displayed_units
        self.okButton = QPushButton(ok_text)
        self.okButton.clicked.connect(ok_function)
        self.okButton.setDefault(True)

        self.cancelButton = QPushButton("Cancel")
        self.cancelButton.clicked.connect(self.cancel)

        hbl4 = QHBoxLayout()
        hbl4.addStretch(1)
        hbl4.addWidget(self.cancelButton)
        hbl4.addWidget(self.okButton)

        vbl = QVBoxLayout()
        vbl.addLayout(hbl1)
        vbl.addLayout(self.unit_layout)
        vbl.addLayout(hbl3)
        vbl.addLayout(hbl4)
        self.setLayout(vbl)
        self.vbl = vbl

        self.update_unit_layout(default_index)

        self.show()
示例#6
0
 def _setup_attribute_combo(self):
     self.attribute_combo.clear()
     if isinstance(self.data, Subset):
         components = self.data.data.visible_components
     else:
         components = self.data.visible_components
     label_data = [(comp.label, comp) for comp in components]
     update_combobox(self.attribute_combo, label_data)
    def _populate_combo(self, default_index=0):
        """Populate combo box with slit types"""
        name_list = [self._mosviz_table_option_text] + \
                    [self.slit_dict[s]['name'] for s in sorted(self.slit_dict)] + \
                    ['Custom']

        key_list = ['default'] + [s for s in sorted(self.slit_dict)] + ['custom']

        combo_input = [(name, key) for name, key in zip(name_list, key_list)]
        update_combobox(self.slit_type_combo, combo_input, default_index=default_index)
    def _populate_combo(self, default_index=0):
        """Populate combo box with slit types"""
        name_list = [self._mosviz_table_option_text] + \
                    [self.slit_dict[s]['name'] for s in sorted(self.slit_dict)] + \
                    ['Custom']

        key_list = ['default'] + [s for s in sorted(self.slit_dict)
                                  ] + ['custom']

        combo_input = [(name, key) for name, key in zip(name_list, key_list)]
        update_combobox(self.slit_type_combo,
                        combo_input,
                        default_index=default_index)
示例#9
0
    def refresh(self):

        label_data = []

        for data in self._data:

            if len(self._data) > 1:
                if data.label is None or data.label == '':
                    label_data.append(("Untitled Data", None))
                else:
                    label_data.append((data.label, None))

            if self.visible:
                all_component_ids = data.visible_components
            else:
                all_component_ids = data.components

            component_ids = []
            for cid in all_component_ids:
                comp = data.get_component(cid)
                if ((comp.numeric and self.numeric)
                        or (comp.categorical and self.categorical) or
                    (cid in data.pixel_component_ids and self.pixel_coord) or
                    (cid in data.world_component_ids and self.world_coord)):
                    component_ids.append(cid)

            label_data.extend([(cid.label, cid) for cid in component_ids])

        update_combobox(self._component_id_combo,
                        label_data,
                        default_index=self.default_index)

        # Disable header rows
        model = self._component_id_combo.model()
        for index in range(self._component_id_combo.count()):
            if self._component_id_combo.itemData(index) is None:
                item = model.item(index)
                palette = self._component_id_combo.palette()
                item.setFlags(item.flags()
                              & ~(Qt.ItemIsSelectable | Qt.ItemIsEnabled))
                item.setData(
                    palette.color(QtGui.QPalette.Disabled,
                                  QtGui.QPalette.Text))

        index = self._component_id_combo.currentIndex()
        if self._component_id_combo.itemData(index) is None:
            for index in range(index + 1, self._component_id_combo.count()):
                if self._component_id_combo.itemData(index) is not None:
                    self._component_id_combo.setCurrentIndex(index)
                    break
    def __init__(self, parent=None):

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

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

        # Set up tabs

        self.ui.tab_mode.currentChanged.connect(nonpartial(self._mode_changed))
        self.ui.tab_mode.currentChanged.connect(nonpartial(self._update_buttons))

        # Set up radio buttons

        self._line_mode = QtWidgets.QButtonGroup()
        self._line_mode.addButton(self.ui.radio_line_panzoom)
        self._line_mode.addButton(self.ui.radio_line_identify)
        self._line_mode.addButton(self.ui.radio_line_select)
        self._line_mode.addButton(self.ui.radio_line_keyboard)

        self.ui.radio_line_panzoom.setChecked(True)

        self._line_mode.buttonClicked.connect(nonpartial(self._mode_changed))

        self._cont_mode = QtWidgets.QButtonGroup()
        self._cont_mode.addButton(self.ui.radio_cont_panzoom)
        self._cont_mode.addButton(self.ui.radio_cont_select)
        self._cont_mode.addButton(self.ui.radio_cont_exclude)
        self._line_mode.addButton(self.ui.radio_cont_keyboard)

        self.ui.radio_cont_panzoom.setChecked(True)

        self._cont_mode.buttonClicked.connect(nonpartial(self._mode_changed))

        # Set up combo box

        labels = list(default_Registry.multifitters.items())
        update_combobox(self.ui.combo_line_fitters, labels)

        self.ui.combo_cont_fitters.setEnabled(False)

        # Set up buttons

        self.ui.button_fit.clicked.connect(nonpartial(self._fit))
        self.ui.button_subtract.clicked.connect(nonpartial(self._subtract))

        # Ensure consistent state

        self._update_buttons()
    def _setup_size_options(self):

        # Set up attribute list
        label_data = [(comp.label, comp) for comp in self.visible_components]
        update_combobox(self.ui.combo_size_attribute, label_data)

        # Set up connections with layer artist
        connect_float_edit(self.layer_artist, 'size', self.ui.value_fixed_size)
        connect_current_combo(self.layer_artist, 'size_attribute', self.ui.combo_size_attribute)
        connect_float_edit(self.layer_artist, 'size_vmin', self.ui.value_size_vmin)
        connect_float_edit(self.layer_artist, 'size_vmax', self.ui.value_size_vmax)
        connect_value(self.layer_artist, 'size_scaling', self.ui.slider_size_scaling, value_range=(0.1, 10), log=True)

        # Set up internal connections
        self.ui.combo_size_mode.currentIndexChanged.connect(self._update_size_mode)
        self.ui.combo_size_attribute.currentIndexChanged.connect(self._update_size_limits)
        self.ui.button_flip_size.clicked.connect(self._flip_size)
示例#12
0
def simple_update_combobox(combo, labels):
    """
    Wrapper around glue's update_combobox, which automatically sets the
    userData to a unique ID.
    """
    print("-> simple_update_combobox(", combo, labels, ")")
    labels_with_data = [(label, str(uuid.uuid4())) for label in labels]
    return update_combobox(combo, labels_with_data)
    def _setup_options(self):
        """
        Set up the combo box with the list of attributes
        """

        # Set up attribute list
        label_data = [(comp.label, comp) for comp in self.visible_components]
        update_combobox(self.ui.combo_attribute, label_data)

        # Set up connections with layer artist
        connect_current_combo(self.layer_artist, 'attribute', self.ui.combo_attribute)
        connect_float_edit(self.layer_artist, 'level', self.ui.value_level)
        connect_color(self.layer_artist, 'color', self.ui.label_color)
        connect_value(self.layer_artist, 'alpha', self.ui.slider_alpha, value_range=(0, 1))

        # Set up internal connections
        self.ui.value_level.editingFinished.connect(self._cache_levels)
        self.ui.combo_attribute.currentIndexChanged.connect(self._update_levels)
    def _setup_color_options(self):

        # Set up attribute list
        label_data = [(comp.label, comp) for comp in self.visible_components]
        update_combobox(self.ui.combo_cmap_attribute, label_data)

        # Set up connections with layer artist
        connect_color(self.layer_artist, 'color', self.ui.label_color)
        connect_current_combo(self.layer_artist, 'cmap_attribute', self.ui.combo_cmap_attribute)
        connect_float_edit(self.layer_artist, 'cmap_vmin', self.ui.value_cmap_vmin)
        connect_float_edit(self.layer_artist, 'cmap_vmax', self.ui.value_cmap_vmax)
        connect_current_combo(self.layer_artist, 'cmap', self.ui.combo_cmap)
        connect_value(self.layer_artist, 'alpha', self.ui.slider_alpha, value_range=(0, 1))

        # Set up internal connections
        self.ui.combo_color_mode.currentIndexChanged.connect(self._update_color_mode)
        self.ui.combo_cmap_attribute.currentIndexChanged.connect(self._update_cmap_limits)
        self.ui.button_flip_cmap.clicked.connect(self._flip_cmap)
示例#15
0
    def refresh(self):

        if self.data is None:
            self.layer_combo.clear()
            self.layer_combo.setEnabled(False)
            return

        self.layer_combo.setEnabled(True)

        # Set up contents of combo box
        labeldata = []

        # First include the dataset itself
        labeldata.append(('Full dataset', self.data))

        for subset in self.data.subsets:
            labeldata.append((subset.label, subset))

        update_combobox(self.layer_combo, labeldata)
示例#16
0
    def refresh(self):

        if self.data is None:
            self.layer_combo.clear()
            self.layer_combo.setEnabled(False)
            return

        self.layer_combo.setEnabled(True)

        # Set up contents of combo box
        labeldata = []

        # First include the dataset itself
        labeldata.append(('Full dataset', self.data))

        for subset in self.data.subsets:
            labeldata.append((subset.label, subset))

        update_combobox(self.layer_combo, labeldata)
示例#17
0
    def refresh(self):

        label_data = []

        for data in self._data:

            if len(self._data) > 1:
                if data.label is None or data.label == '':
                    label_data.append(("Untitled Data", None))
                else:
                    label_data.append((data.label, None))

            if self.visible:
                all_component_ids = data.visible_components
            else:
                all_component_ids = data.components

            component_ids = []
            for cid in all_component_ids:
                comp = data.get_component(cid)
                if (comp.numeric and self.numeric) or (comp.categorical and self.categorical):
                    component_ids.append(cid)

            label_data.extend([(cid.label, cid) for cid in component_ids])

        update_combobox(self._component_id_combo, label_data, default_index=self.default_index)

        # Disable header rows
        model = self._component_id_combo.model()
        for index in range(self._component_id_combo.count()):
            if self._component_id_combo.itemData(index) is None:
                item = model.item(index)
                palette = self._component_id_combo.palette()
                item.setFlags(item.flags() & ~(Qt.ItemIsSelectable | Qt.ItemIsEnabled))
                item.setData(palette.color(QtGui.QPalette.Disabled, QtGui.QPalette.Text))

        index = self._component_id_combo.currentIndex()
        if self._component_id_combo.itemData(index) is None:
            for index in range(index + 1, self._component_id_combo.count()):
                if self._component_id_combo.itemData(index) is not None:
                    self._component_id_combo.setCurrentIndex(index)
                    break
示例#18
0
    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')
示例#19
0
    def _update_subset_combo(self, msg=None):
        """
        Set up the combo listing the subsets.
        """

        # Prepare contents of combo box - we include a 'Create subset' item as
        # the last item
        labeldata = [(subset.label, subset) for subset in self._data_collection.subset_groups]
        labeldata.append(('None/Create New', None))

        # We now update the combo box, but we block the signals as we don't want
        # this to cause the current subset being edited to be modified.

        self.subset_combo.blockSignals(True)

        # The block_signals here is to prevent signals from being turned back
        # on inside update_combobox.
        update_combobox(self.subset_combo, labeldata, block_signals=False)
        self.subset_combo.setIconSize(QtCore.QSize(12, 12))
        for index, subset in enumerate(self._data_collection.subset_groups):
            self.subset_combo.setItemIcon(index, layer_icon(subset))

        self.subset_combo.blockSignals(False)
    def _setup_options(self):
        """
        Set up the combo box with the list of attributes
        """

        # Set up attribute list
        label_data = [(comp.label, comp) for comp in self.visible_components]
        update_combobox(self.ui.combo_attribute, label_data)

        # Set up connections with layer artist
        connect_current_combo(self.layer_artist, 'attribute',
                              self.ui.combo_attribute)
        connect_float_edit(self.layer_artist, 'level', self.ui.value_level)
        connect_color(self.layer_artist, 'color', self.ui.label_color)
        connect_value(self.layer_artist,
                      'alpha',
                      self.ui.slider_alpha,
                      value_range=(0, 1))

        # Set up internal connections
        self.ui.value_level.editingFinished.connect(self._cache_levels)
        self.ui.combo_attribute.currentIndexChanged.connect(
            self._update_levels)
示例#21
0
    def _update_subset_combo(self, msg=None):
        """
        Set up the combo listing the subsets.
        """

        # Prepare contents of combo box - we include a 'Create subset' item as
        # the last item
        labeldata = [(subset.label, subset) for subset in self._data_collection.subset_groups]
        labeldata.append(('None', None))

        # We now update the combo box, but we block the signals as we don't want
        # this to cause the current subset being edited to be modified.

        self.subset_combo.blockSignals(True)

        # The block_signals here is to prevent signals from being turned back
        # on inside update_combobox.
        update_combobox(self.subset_combo, labeldata, block_signals=False)
        self.subset_combo.setIconSize(QtCore.QSize(12, 12))
        for index, subset in enumerate(self._data_collection.subset_groups):
            self.subset_combo.setItemIcon(index, layer_icon(subset))

        self.subset_combo.blockSignals(False)
示例#22
0
 def _populate_category_combo(self):
     f = [f for f in link_function.members if len(f.output_labels) == 1]
     categories = sorted(set(l.category for l in f + link_helper.members))
     update_combobox(self._ui.category, list(zip(categories, categories)))
示例#23
0
 def refresh(self):
     label_data = [(data.label, data) for data in self._datasets]
     update_combobox(self._data_combo, label_data)
     self.refresh_component_ids()
示例#24
0
 def _update_combobox(self):
     labeldata = [(layer.label, layer) for layer in self._layers]
     update_combobox(self.ui.combo_active_layer, labeldata)
示例#25
0
 def set_attribute_combo(self, data):
     """ Update attribute combo box to reflect components in data"""
     labeldata = ((f.label, f) for f in data.visible_components)
     update_combobox(self.ui.attributeComboBox, labeldata)
示例#26
0
    def __init__(self, parent=None, data=None):

        QtWidgets.QDialog.__init__(self, parent=parent)

        self.data = data

        self.ui = load_ui('loader_selection.ui', self, directory=UI_DIR)

        update_combobox(self.ui.combotext_loader_spectrum1d,
                        zip(SPECTRUM1D_LOADERS, repeat(None)))
        update_combobox(self.ui.combotext_loader_spectrum2d,
                        zip(SPECTRUM2D_LOADERS, repeat(None)))
        update_combobox(self.ui.combotext_loader_cutout,
                        zip(CUTOUT_LOADERS, repeat(None)))

        if 'loaders' in data.meta:

            loaders = data.meta['loaders']

            if "spectrum1d" in loaders and loaders[
                    'spectrum1d'] in SPECTRUM1D_LOADERS:
                self.loader_spectrum1d = loaders['spectrum1d']
            if "spectrum2d" in loaders and loaders[
                    'spectrum2d'] in SPECTRUM2D_LOADERS:
                self.loader_spectrum2d = loaders['spectrum2d']
            if "cutout" in loaders and loaders['cutout'] in CUTOUT_LOADERS:
                self.loader_cutout = loaders['cutout']

        if self.loader_spectrum1d is None:
            self.loader_spectrum1d = 'NIRSpec 1D Spectrum'
        if self.loader_spectrum2d is None:
            self.loader_spectrum2d = 'NIRSpec 2D Spectrum'
        if self.loader_cutout is None:
            self.loader_cutout = 'NIRCam Image'

        # We set up ComponentIDComboHelper which takes care of populating the
        # combo box with the components.

        self._helpers = {}

        for column in self.columns:

            combo = getattr(self, 'combotext_' + column['property'])

            helper = ComponentIDComboHelper(combo,
                                            data=data,
                                            numeric=column['numeric'],
                                            categorical=column['categorical'])

            self._helpers[column['property']] = helper

            # Store components that appear in the combo inside the column object
            column['components'] = [
                combo.itemText(i) for i in range(combo.count())
            ]

        # We check whether any of the properties are already defined in the
        # Data.meta dictionary. This could happen for example if the user has
        # encoded some of these defaults in their data file (which we
        # document how to do).

        if 'special_columns' in data.meta:
            special_columns = data.meta['special_columns']
            for column in self.columns:
                if column['property'] in special_columns:
                    column_name = special_columns[column['property']]
                    if column_name in column['components']:
                        setattr(self, column['property'], column_name)

        # We now check whether each property is None, and if so we set it either
        # to the default, if present, or to the first component otherwise. In
        # future we could replace the default by a function that could do more
        # sophisticated auto-testing.

        for column in self.columns:
            if not column['components']:
                continue
            if getattr(self, column['property']) is None:
                if column['default'] in column['components']:
                    setattr(self, column['property'], column['default'])
                else:
                    setattr(self, column['property'], column['components'][0])

        # The following is a call to a function that deals with setting up the
        # linking between the callback properties here and the Qt widgets.

        autoconnect_callbacks_to_qt(self, self.ui)

        self.button_cancel.clicked.connect(self.reject)
        self.button_ok.clicked.connect(self.accept)

        self.add_global_callback(self._validation_checks)

        self._validation_checks()
示例#27
0
    def update_info(self, index):
        """
        Update width and hight based on combo index.
        Callback for combo box.
        """
        key = self.slit_type_combo.currentData()

        length = width = None
        width_units = length_units = ''
        if key == 'default':
            slit_info = self.mosviz_viewer.get_slit_dimensions_from_file()
            width_units, length_units = self.mosviz_viewer.get_slit_units_from_file(
            )
            if slit_info is None:
                length, width = ['N/A', 'N/A']
            else:
                length, width = slit_info
        elif key != 'custom':
            if 'length' in self.slit_dict[key]:
                length = self.slit_dict[key]['length']
            if 'width' in self.slit_dict[key]:
                width = self.slit_dict[key]['width']
        else:
            width_units = length_units = 'arcsec'

        for input_widget in [self.slit_width_input, self.slit_length_input]:
            input_widget.setStyleSheet("")

        if isinstance(width, list):
            self.slit_width_input.hide()
            self.slit_width_combo.show()
            combo_input = [(str(i), str(i)) for i in width]
            update_combobox(self.slit_width_combo, combo_input)
        elif width is None:
            self.slit_width_combo.hide()
            self.slit_width_input.show()
            self.slit_width_input.setText('')
            self.slit_width_input.setDisabled(False)
        else:
            self.slit_width_combo.hide()
            self.slit_width_input.show()
            self.slit_width_input.setText(str(width))
            self.slit_width_input.setDisabled(True)
        self.slit_width_units.setText(width_units)

        if isinstance(length, list):
            self.slit_length_input.hide()
            self.slit_length_combo.show()
            combo_input = [(str(i), str(i)) for i in length]
            update_combobox(self.slit_length_combo, combo_input)
        elif length is None:
            self.slit_length_combo.hide()
            self.slit_length_input.show()
            self.slit_length_input.setText('')
            self.slit_length_input.setDisabled(False)
        else:
            self.slit_length_combo.hide()
            self.slit_length_input.show()
            self.slit_length_input.setText(str(length))
            self.slit_length_input.setDisabled(True)
        self.slit_length_units.setText(length_units)
示例#28
0
 def _populate_category_combo(self):
     f = [f for f in link_function.members if len(f.output_labels) == 1]
     categories = sorted(set(l.category for l in f + link_helper.members))
     update_combobox(self._ui.category, list(zip(categories, categories)))
示例#29
0
    def _init_selection_ui(self):
        # LINE 1: Radio box spatial vs spectral axis
        self.axes_prompt = QLabel("Smoothing Axis:")
        self.axes_prompt.setMinimumWidth(150)

        self.spatial_radio = QRadioButton("Spatial")
        self.spatial_radio.setChecked(True)
        self.current_axis = "spatial"
        self.spatial_radio.toggled.connect(self.spatial_radio_checked)

        self.spectral_radio = QRadioButton("Spectral")
        self.spectral_radio.toggled.connect(self.spectral_radio_checked)

        # hbl is short for Horizontal Box Layout
        hbl1 = QHBoxLayout()
        hbl1.addWidget(self.axes_prompt)
        hbl1.addWidget(self.spatial_radio)
        hbl1.addWidget(self.spectral_radio)

        # LINE 2: Kernel Type prompt
        self.k_type_prompt = QLabel("Kernel Type:")
        self.k_type_prompt.setMinimumWidth(150)
        # Load kernel types + names and add to drop down
        self._load_options()
        self.combo = QComboBox()
        self.combo.setMinimumWidth(150)
        self.combo.addItems(self.options[self.current_axis])

        hbl2 = QHBoxLayout()
        hbl2.addWidget(self.k_type_prompt)
        hbl2.addWidget(self.combo)

        # LINE 3: Kernel size
        self.size_prompt = QLabel(self.smooth_cube.get_kernel_size_prompt(self.current_kernel_type))
        self.size_prompt.setWordWrap(True)
        self.size_prompt.setMinimumWidth(150)
        self.unit_label = QLabel(self.smooth_cube.get_kernel_unit(self.current_kernel_type))
        self.k_size = QLineEdit("1")  # Default Kernel size set here

        hbl3 = QHBoxLayout()
        hbl3.addWidget(self.size_prompt)
        hbl3.addWidget(self.k_size)
        hbl3.addWidget(self.unit_label)

        # LINE 4: Data component drop down
        self.component_prompt = QLabel("Data Component:")
        self.component_prompt.setWordWrap(True)
        self.component_prompt.setMinimumWidth(150)
        # Load component_ids and add to drop down

        # Add the data component labels to the drop down, with the ComponentID
        # set as the userData:

        if self.parent is not None and hasattr(self.parent, 'data_components'):
            labeldata = [(str(cid), cid) for cid in self.parent.data_components]
        else:
            labeldata = [(str(cid), cid) for cid in self.data.main_components()]

        self.component_combo = QComboBox()
        update_combobox(self.component_combo, labeldata)

        self.component_combo.setMaximumWidth(150)
        self.component_combo.setCurrentIndex(0)
        if self.allow_preview:
            self.component_combo.currentIndexChanged.connect(self.update_preview_button)

        hbl4 = QHBoxLayout()
        hbl4.addWidget(self.component_prompt)
        hbl4.addWidget(self.component_combo)

        # Line 5: Preview Message
        message = "Info: Smoothing previews are displayed on " \
                  "CubeViz's left and single image viewers."
        self.preview_message = QLabel(message)
        self.preview_message.setWordWrap(True)
        self.preview_message.hide()
        hbl5 = QHBoxLayout()
        hbl5.addWidget(self.preview_message)

        # LINE 6: preview ok cancel buttons
        self.previewButton = QPushButton("Preview Slice")
        self.previewButton.clicked.connect(self.call_preview)

        self.okButton = QPushButton("Smooth Cube")
        self.okButton.clicked.connect(self.call_main)
        self.okButton.setDefault(True)

        self.cancelButton = QPushButton("Cancel")
        self.cancelButton.clicked.connect(self.cancel)

        hbl6 = QHBoxLayout()
        hbl6.addStretch(1)
        if self.allow_preview:
            hbl6.addWidget(self.previewButton)
        hbl6.addWidget(self.cancelButton)
        hbl6.addWidget(self.okButton)

        # Add Lines to Vertical Layout
        # vbl is short for Vertical Box Layout
        vbl = QVBoxLayout()
        if self.allow_spectral_axes:
            vbl.addLayout(hbl1)
        vbl.addLayout(hbl2)
        vbl.addLayout(hbl3)
        vbl.addLayout(hbl4)
        vbl.addLayout(hbl5)
        vbl.addLayout(hbl6)

        self.setLayout(vbl)
        self.setMaximumWidth(330)

        # Connect kernel combo box to event handler
        self.combo.currentIndexChanged.connect(self.selection_changed)
        self.selection_changed(0)

        self.show()
示例#30
0
    def _init_selection_ui(self):
        # LINE 1: Radio box spatial vs spectral axis
        self.axes_prompt = QLabel("Smoothing Axis:")
        self.axes_prompt.setMinimumWidth(150)

        self.spatial_radio = QRadioButton("Spatial")
        self.spatial_radio.setChecked(True)
        self.current_axis = "spatial"
        self.spatial_radio.toggled.connect(self.spatial_radio_checked)

        self.spectral_radio = QRadioButton("Spectral")
        self.spectral_radio.toggled.connect(self.spectral_radio_checked)

        # hbl is short for Horizontal Box Layout
        hbl1 = QHBoxLayout()
        hbl1.addWidget(self.axes_prompt)
        hbl1.addWidget(self.spatial_radio)
        hbl1.addWidget(self.spectral_radio)

        # LINE 2: Kernel Type prompt
        self.k_type_prompt = QLabel("Kernel Type:")
        self.k_type_prompt.setMinimumWidth(150)
        # Load kernel types + names and add to drop down
        self._load_options()
        self.combo = QComboBox()
        self.combo.setMinimumWidth(150)
        self.combo.addItems(self.options[self.current_axis])

        hbl2 = QHBoxLayout()
        hbl2.addWidget(self.k_type_prompt)
        hbl2.addWidget(self.combo)

        # LINE 3: Kernel size
        self.size_prompt = QLabel(
            self.smooth_cube.get_kernel_size_prompt(self.current_kernel_type))
        self.size_prompt.setWordWrap(True)
        self.size_prompt.setMinimumWidth(150)
        self.unit_label = QLabel(
            self.smooth_cube.get_kernel_unit(self.current_kernel_type))
        self.k_size = QLineEdit("1")  # Default Kernel size set here

        hbl3 = QHBoxLayout()
        hbl3.addWidget(self.size_prompt)
        hbl3.addWidget(self.k_size)
        hbl3.addWidget(self.unit_label)

        # LINE 4: Data component drop down
        self.component_prompt = QLabel("Data Component:")
        self.component_prompt.setWordWrap(True)
        self.component_prompt.setMinimumWidth(150)
        # Load component_ids and add to drop down

        # Add the data component labels to the drop down, with the ComponentID
        # set as the userData:

        if self.parent is not None and hasattr(self.parent, 'data_components'):
            labeldata = [(str(cid), cid)
                         for cid in self.parent.data_components]
        else:
            labeldata = [(str(cid), cid)
                         for cid in self.data.main_components()]

        self.component_combo = QComboBox()
        update_combobox(self.component_combo, labeldata)

        self.component_combo.setMaximumWidth(150)
        self.component_combo.setCurrentIndex(0)
        if self.allow_preview:
            self.component_combo.currentIndexChanged.connect(
                self.update_preview_button)

        hbl4 = QHBoxLayout()
        hbl4.addWidget(self.component_prompt)
        hbl4.addWidget(self.component_combo)

        # Line 5: Preview Message
        message = "Info: Smoothing previews are displayed on " \
                  "CubeViz's left and single image viewers."
        self.preview_message = QLabel(message)
        self.preview_message.setWordWrap(True)
        self.preview_message.hide()
        hbl5 = QHBoxLayout()
        hbl5.addWidget(self.preview_message)

        # LINE 6: preview ok cancel buttons
        self.previewButton = QPushButton("Preview")
        self.previewButton.clicked.connect(self.call_preview)

        self.okButton = QPushButton("OK")
        self.okButton.clicked.connect(self.call_main)
        self.okButton.setDefault(True)

        self.cancelButton = QPushButton("Cancel")
        self.cancelButton.clicked.connect(self.cancel)

        hbl6 = QHBoxLayout()
        hbl6.addStretch(1)
        if self.allow_preview:
            hbl6.addWidget(self.previewButton)
        hbl6.addWidget(self.cancelButton)
        hbl6.addWidget(self.okButton)

        # Add Lines to Vertical Layout
        # vbl is short for Vertical Box Layout
        vbl = QVBoxLayout()
        if self.allow_spectral_axes:
            vbl.addLayout(hbl1)
        vbl.addLayout(hbl2)
        vbl.addLayout(hbl3)
        vbl.addLayout(hbl4)
        vbl.addLayout(hbl5)
        vbl.addLayout(hbl6)

        self.setLayout(vbl)
        self.setMaximumWidth(330)

        # Connect kernel combo box to event handler
        self.combo.currentIndexChanged.connect(self.selection_changed)
        self.selection_changed(0)

        self.show()
示例#31
0
 def _populate_function_combo(self):
     """ Add name of functions to function combo box """
     f = [f for f in link_function.members if len(f.output_labels) == 1]
     functions = ((get_function_name(l[0]), l) for l in f + link_helper.members if l.category == self.category)
     update_combobox(self._ui.function, functions)
示例#32
0
 def refresh(self):
     label_data = [(data.label, data) for data in self._datasets]
     update_combobox(self._data_combo, label_data)
     self.refresh_component_ids()
示例#33
0
 def set_attribute_combo(self, data):
     """ Update attribute combo box to reflect components in data"""
     labeldata = ((f.label, f) for f in data.visible_components)
     update_combobox(self.ui.attributeComboBox, labeldata)