class DataTicksCalculatorFmtWidget(QWidget): """Fmt widget for :class:`psy_simple.plotters.DataTicksCalculator` This widget contains a combo box with the different options from the :attr:`psy_simple.plotters.DataTicksCalculator.calc_funcs`, a spin box for the number of increments and two text widgets for minimum and maximum percentile""" def __init__(self, parent, fmto, what=None, N=None, pctl_min=None, pctl_max=None): QWidget.__init__(self, parent) hbox = QHBoxLayout() self.combo = QComboBox() self.combo.addItems(sorted(fmto.calc_funcs)) hbox.addWidget(self.combo) self.sb_N = QSpinBox() hbox.addWidget(self.sb_N) self.txt_min_pctl = QLineEdit() self.txt_min_pctl.setValidator(QDoubleValidator(0., 100., 10)) hbox.addWidget(QLabel('Percentiles:')) hbox.addWidget(QLabel('Min.:')) hbox.addWidget(self.txt_min_pctl) self.txt_max_pctl = QLineEdit() self.txt_max_pctl.setValidator(QDoubleValidator(0., 100., 10)) hbox.addWidget(QLabel('Max.:')) hbox.addWidget(self.txt_max_pctl) if what is not None: self.combo.setCurrentText(what) if N is not None: self.sb_N.setValue(N) if pctl_min is not None: self.txt_min_pctl.setText('%1.6g' % pctl_min) if pctl_max is not None: self.txt_max_pctl.setText('%1.6g' % pctl_max) self.combo.currentTextChanged.connect(self.set_obj) self.sb_N.valueChanged.connect(self.set_obj) self.txt_min_pctl.textChanged.connect(self.set_obj) self.txt_max_pctl.textChanged.connect(self.set_obj) self.setLayout(hbox) def set_obj(self): obj = [self.combo.currentText(), self.sb_N.value()] if (self.txt_min_pctl.text().strip() or self.txt_max_pctl.text().strip()): obj.append(float(self.txt_min_pctl.text().strip() or 0)) if self.txt_max_pctl.text().strip(): obj.append(float(self.txt_max_pctl.text().strip())) self.parent().set_obj(obj)
def __init__(self, parent, fmto, artist=None, base=None): """ Parameters ---------- %(LabelWidget.parameters.parent|fmto)s artist: matplotlib.text.Text The text instance this formatoption is modifying base: psyplot.plotter.Formatoption The original formatoption of the label the given `fmto` belongs to """ QWidget.__init__(self, parent) hbox = QHBoxLayout() hbox.addWidget(QLabel('Font weights:')) if artist is None: weight = 'normal' else: weight = artist.get_weight() self.spin_box = spin_box = QSpinBox(self) spin_box.setRange(1, 1000) try: weight = int(weight) except ValueError: spin_box.setValue(mpl_weight2qt(weight) * 10) else: spin_box.setValue(weight) spin_box.valueChanged.connect(parent.set_obj) hbox.addWidget(spin_box) combo = QComboBox() combo.addItems(list(weights_mpl2qt)) if weight in weights_mpl2qt: combo.setCurrentText(weight) else: combo.setCurrentText(weights_qt2mpl[mpl_weight2qt(weight)]) combo.currentTextChanged.connect(parent.set_obj) hbox.addWidget(combo) # add a button to change to the properties formatoption if base is not None: fmtos = [ base, getattr(fmto.plotter, base.key + 'props', None), getattr(fmto.plotter, base.key + 'size', None), ] fmtos = list(filter(None, fmtos)) hbox.addWidget(Switch2FmtButton(parent, *fmtos)) self.setLayout(hbox)