示例#1
0
    def _build_waverange_dialog(self, wave_range, line_list):

        dialog = QDialog(parent=self.centralWidget)

        loadUi(os.path.join(os.path.dirname(__file__), "ui", "linelists_waverange.ui"), dialog)

        dialog.min_text.setText("%.2f" % wave_range[0].value)
        dialog.max_text.setText("%.2f" % wave_range[1].value)

        validator = QDoubleValidator()
        validator.setBottom(0.0)
        validator.setDecimals(2)
        dialog.min_text.setValidator(validator)
        dialog.max_text.setValidator(validator)

        dialog.nlines_label = self._compute_nlines_in_waverange(line_list, dialog.min_text, dialog.max_text,
                                                                dialog.nlines_label)

        dialog.min_text.editingFinished.connect(lambda: self._compute_nlines_in_waverange(line_list,
                                                 dialog.min_text, dialog.max_text, dialog.nlines_label))
        dialog.max_text.editingFinished.connect(lambda: self._compute_nlines_in_waverange(line_list,
                                                 dialog.min_text, dialog.max_text, dialog.nlines_label))

        accepted = dialog.exec_() > 0

        amin = amax = None
        if accepted:
            return self._get_range_from_textfields(dialog.min_text, dialog.max_text)

        return (amin, amax)
示例#2
0
    def _build_waverange_dialog(self, wave_range, line_list):

        dialog = QDialog()

        loadUi(os.path.join(os.path.dirname(__file__), "ui", "linelists_waverange.ui"), dialog)

        # convert from line list native units to whatever units
        # are currently being displayed in the spectral axis.
        linelist_units = wave_range[0].unit
        spectral_axis_unit = self.hub.plot_widget.spectral_axis_unit
        w0 = wave_range[0].to(spectral_axis_unit, equivalencies=u.spectral())
        w1 = wave_range[1].to(spectral_axis_unit, equivalencies=u.spectral())

        # populate labels with correct physical quantity name
        dispersion_unit = u.Unit(spectral_axis_unit or "")
        if dispersion_unit.physical_type == 'length':
            dialog.minwave_label.setText("Minimum wavelength")
            dialog.maxwave_label.setText("Maximum wavelength")
        elif dispersion_unit.physical_type == 'frequency':
            dialog.minwave_label.setText("Minimum frequency")
            dialog.maxwave_label.setText("Maximum frequency")
        elif dispersion_unit.physical_type == 'energy':
            dialog.minwave_label.setText("Minimum energy")
            dialog.maxwave_label.setText("Maximum energy")
        else:
            dialog.minwave_label.setText("Minimum disp. var.")
            dialog.maxwave_label.setText("Maximum disp. var.")

        # pick a good format to display values represented
        # in the currently selected plot units.
        if str(w0.unit) in units_formats:
            fmt = units_formats[str(w0.unit)]
        else:
            # use generic formatting for weirder units
            fmt = "%.6g"

        dialog.min_text.setText(fmt % w0.value)
        dialog.max_text.setText(fmt % w1.value)

        validator = QDoubleValidator()
        validator.setBottom(0.0)
        dialog.min_text.setValidator(validator)
        dialog.max_text.setValidator(validator)

        dialog.nlines_label = self._compute_nlines_in_waverange(line_list, dialog.min_text, dialog.max_text,
                                                                dialog.nlines_label, linelist_units, spectral_axis_unit)

        dialog.min_text.editingFinished.connect(lambda: self._compute_nlines_in_waverange(line_list,
                                                                                          dialog.min_text,
                                                                                          dialog.max_text,
                                                                                          dialog.nlines_label,
                                                                                          linelist_units,
                                                                                          spectral_axis_unit))
        dialog.max_text.editingFinished.connect(lambda: self._compute_nlines_in_waverange(line_list,
                                                                                          dialog.min_text,
                                                                                          dialog.max_text,
                                                                                          dialog.nlines_label,
                                                                                          linelist_units,
                                                                                          spectral_axis_unit))
        accepted = dialog.exec_() > 0

        amin = amax = None
        if accepted:
            return self._get_range_from_textfields(dialog.min_text, dialog.max_text,
                                                   linelist_units, spectral_axis_unit)
        return (amin, amax)