def setup_children(self, item): tree = self.straditizer_widgets.tree tree.setItemWidget(item, 0, self.btn_plot) child = QTreeWidgetItem(0) item.addChild(child) widget = QWidget() vbox = QVBoxLayout() vbox.addWidget(self.cb_final) vbox.addWidget(self.cb_transformed) widget.setLayout(vbox) tree.setItemWidget(child, 0, widget)
def __init__(self, canvas, num): from psyplot_gui.main import mainwindow self.main = mainwindow if mainwindow is None: return super(PsyplotCanvasManager, self).__init__(canvas, num) self.window = dock = QDockWidget("Figure %d" % num, parent=mainwindow) parent_widget = QWidget() dock.setWidget(parent_widget) parent_widget.vbox = vbox = QVBoxLayout() mainwindow.addDockWidget(Qt.TopDockWidgetArea, dock) if mainwindow.figures: mainwindow.tabifyDockWidget(mainwindow.figures[-1], dock) mainwindow.figures.append(dock) FigureManagerBase.__init__(self, canvas, num) self.canvas = canvas self.window.setWindowTitle("Figure %d" % num) self.toolbar = self._get_toolbar(canvas, parent_widget) if self.toolbar is not None: vbox.addWidget(self.toolbar) self.toolbar.message.connect(self._show_message) vbox.addWidget(canvas) parent_widget.setLayout(vbox) self.parent_widget = parent_widget # Give the keyboard focus to the figure instead of the # manager; StrongFocus accepts both tab and click to focus and # will enable the canvas to process event w/o clicking. # ClickFocus only takes the focus is the window has been # clicked # on. http://qt-project.org/doc/qt-4.8/qt.html#FocusPolicy-enum or # http://doc.qt.digia.com/qt/qt.html#FocusPolicy-enum self.canvas.setFocusPolicy(Qt.StrongFocus) self.canvas.setFocus() self.window._destroying = False # add text label to status bar self.statusbar_label = QLabel() mainwindow.statusBar().addWidget(self.statusbar_label) self.main.show() def notify_axes_change(fig): # This will be called whenever the current axes is changed if self.toolbar is not None: self.toolbar.update() self.canvas.figure.add_axobserver(notify_axes_change)
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)
def _init_digitize_child(self): self.lbl_col = QLabel('') self.btn_prev = QPushButton('<') self.btn_next = QPushButton('>') self.btn_edit = QPushButton('Edit') self.btn_add = QPushButton('+') self.reset_lbl_col() self.btn_box = w = QWidget() vbox = QVBoxLayout() vbox.addWidget(self.lbl_col) hbox = QHBoxLayout() hbox.addWidget(self.btn_prev) hbox.addWidget(self.btn_next) hbox.addWidget(self.btn_edit) hbox.addWidget(self.btn_add) vbox.addLayout(hbox) w.setLayout(vbox) self.digitize_child = QTreeWidgetItem(0) self.straditizer_widgets.digitizer.digitize_item.addChild( self.digitize_child) self.straditizer_widgets.digitizer.tree.setItemWidget( self.digitize_child, 0, w) self.widgets2disable = [self.btn_prev, self.btn_next, self.btn_edit, self.btn_add] self.btn_next.clicked.connect(self.increase_current_col) self.btn_prev.clicked.connect(self.decrease_current_col) self.btn_edit.clicked.connect(self.select_current_column) self.btn_add.clicked.connect(self.select_and_add_current_column)
def test_arrayname_validator(self): """Test the :class:`psyplot_gui.plot_creator.ArrayNameValidator`""" # open dataset fname = self.get_file('test-t2m-u-v.nc') ds = psy.open_dataset(fname) self.pc.bt_get_ds.get_from_shell(ds) # add data arrays QTest.mouseClick(self.pc.bt_add_all, Qt.LeftButton) # get names atab = self.pc.array_table names = atab.current_names # get itemdelegate item_delegate = atab.itemDelegateForColumn(atab.arr_col) # create editor and validator widget = QWidget() option = QStyleOptionViewItem() index = atab.indexFromItem(atab.item(0, atab.arr_col)) editor = item_delegate.createEditor(widget, option, index) validator = editor.validator() # check validation self.assertEqual(validator.validate(names[1], len(names[1]))[0], validator.Intermediate) self.assertEqual(validator.validate('dummy', 5)[0], validator.Acceptable) self.assertNotIn(validator.fixup(names[1]), names) ds.close()
def __init__(self, parent, fmto, project): QWidget.__init__(self, parent) hbox = QHBoxLayout() # add a select colormap button self.btn_choose = button = QPushButton('Choose...') button.clicked.connect(partial(self.choose_cmap, None)) hbox.addWidget(button) # add a show colormap button self.btn_show = button = QPushButton('Show...') button.clicked.connect(self.show_cmap) hbox.addWidget(button) hbox.addWidget(Switch2FmtButton(parent, fmto.bounds, fmto.cbar)) self.setLayout(hbox)
def __init__(self, parent, array=None): QWidget.__init__(self, parent) self.txt_min = QLineEdit() self.txt_min.setValidator(QDoubleValidator()) self.txt_max = QLineEdit() self.txt_max.setValidator(QDoubleValidator()) self.txt_step = QLineEdit() self.txt_step.setValidator(QDoubleValidator(1e-10, 1e10, 10)) self.sb_nsteps = QSpinBox() self.step_inc_combo = combo = QComboBox() combo.addItems(['Step', '# Steps']) if array is not None: self.txt_min.setText('%1.4g' % array.min()) self.txt_max.setText('%1.4g' % array.max()) steps = np.diff(array) if len(steps) == 1 or np.diff(steps).max() < 1e-5: self.txt_step.setText('%1.4g' % steps[0]) combo.setCurrentIndex(0) else: combo.setCurrentIndex(1) self.sb_nsteps.setValue(len(array)) self.toggle_txt_step(combo.currentText()) hbox = QHBoxLayout() hbox.addWidget(QLabel('Min.')) hbox.addWidget(self.txt_min) hbox.addWidget(QLabel('Max.')) hbox.addWidget(self.txt_max) hbox.addWidget(combo) hbox.addWidget(self.txt_step) hbox.addWidget(self.sb_nsteps) self.setLayout(hbox) for w in [self.txt_min, self.txt_max, self.txt_step]: w.textChanged.connect(self.set_array) self.sb_nsteps.valueChanged.connect(self.set_array) combo.currentTextChanged.connect(self.toggle_txt_step)
def __init__(self, parent, fmto, project): """ Parameters ---------- parent: psyplot_gui.fmt_widget.FormatoptionWidget The formatoption widget where this widget is inserted fmto: psyplot.plotter.Formatoption The formatoption that is represented by this widget project: psyplot.project.Project The current psyplot subproject""" QWidget.__init__(self, parent) hbox = QHBoxLayout() # Create a combo box for the rcParams 'labels' key label_combo = DictCombo(fmto.rc['labels'], parent, modulo_style=False) hbox.addWidget(label_combo) # Create a combo for the :attr:`enhanced_attrs` attrs = OrderedDict( sorted( utils.join_dicts([ getattr(plotter, fmto.key).enhanced_attrs for plotter in project.plotters ], delimiter=', ').items())) attr_combo = DictCombo(attrs, parent) hbox.addWidget(attr_combo) fmtos = [ # add a button to change to the properties formatoption getattr(fmto.plotter, fmto.key + 'props', None), getattr(fmto.plotter, fmto.key + 'size', None), getattr(fmto.plotter, fmto.key + 'weight', None) ] fmtos = list(filter(None, fmtos)) if fmtos: hbox.addWidget(Switch2FmtButton(parent, *fmtos)) self.setLayout(hbox)
def __init__(self, parent, norm): QWidget.__init__(self, parent) self.norm = norm validator = QDoubleValidator() self.txt_min = QLineEdit() self.txt_min.setValidator(validator) self.txt_max = QLineEdit() self.txt_max.setValidator(validator) self.lbl_linthresh = QLabel('linthresh:') self.txt_linthresh = QLineEdit() # linthresh for SymLogNorm self.txt_linthresh.setValidator(validator) self.txt_linthresh.setToolTip( 'The threshold for linear scaling. Within this distance from 0, ' 'the scaling will be linear, not logarithmic.') self.lbl_gamma = QLabel('gamma:') self.txt_gamma = QLineEdit() # gamma for PowerNorm self.txt_gamma.setValidator(validator) self.txt_gamma.setToolTip('The power value for the PowerNorm') self.fill_from_norm() hbox = QHBoxLayout() hbox.addWidget(QLabel('Min.:')) hbox.addWidget(self.txt_min) hbox.addWidget(QLabel('Max.:')) hbox.addWidget(self.txt_max) hbox.addWidget(self.lbl_linthresh) hbox.addWidget(self.txt_linthresh) hbox.addWidget(self.lbl_gamma) hbox.addWidget(self.txt_gamma) self.setLayout(hbox) self.txt_min.textChanged.connect(self.set_obj) self.txt_max.textChanged.connect(self.set_obj) self.txt_linthresh.textChanged.connect(self.set_obj) self.txt_gamma.textChanged.connect(self.set_obj)
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 __init__(self, parent, fmto, project): QWidget.__init__(self, parent) hbox = QHBoxLayout() self.combo = combo = QComboBox(self) combo.addItems(['Auto discrete', 'No normalization', 'Discrete', 'Logarithmic', 'Symmetric logarithmic', 'Power-law', 'Custom']) hbox.addWidget(combo) value = fmto.value if value is None: combo.setCurrentText('No normalization') value = mcol.Normalize() elif isinstance(value, mcol.Normalize): if isinstance(value, mcol.LogNorm): combo.setCurrentText('Logarithmic') elif isinstance(value, mcol.SymLogNorm): combo.setCurrentText('Symmetric logarithmic') elif isinstance(value, mcol.PowerNorm): combo.setCurrentText('Power-law') else: combo.setCurrentText('Custom') elif isinstance(value[0], six.string_types): combo.setCurrentText('Auto discrete') else: combo.setCurrentText('Discrete') combo.currentTextChanged.connect(self.toggle_combo) # add a button to select other formatoptions hbox.addWidget(Switch2FmtButton(parent, fmto.cmap, fmto.cbar)) self.setLayout(hbox) self.toggle_combo(combo.currentText()) # refresh the norm widget if necessary if isinstance(value, mcol.Normalize): self.current_widget.norm = value self.current_widget.fill_from_norm()
def __init__(self, parent, fmto, artist=None, base=None): """ Parameters ---------- %(FontWeightWidget.parameters)s """ QWidget.__init__(self, parent) hbox = QHBoxLayout() hbox.addWidget(QLabel('Font sizes:')) self.spin_box = spin_box = QSpinBox(self) spin_box.setRange(1, 1e9) if artist is not None: spin_box.setValue(int(artist.get_size())) spin_box.valueChanged.connect(parent.set_obj) hbox.addWidget(spin_box) combo = QComboBox() combo.addItems([ 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large' ]) 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 + 'weight', None), ] fmtos = list(filter(None, fmtos)) hbox.addWidget(Switch2FmtButton(parent, *fmtos)) self.setLayout(hbox)
def test_variablename_validator(self): """Test the :class:`psyplot_gui.plot_creator.VariableItemDelegate`""" # open dataset try: from psyplot_gui.compat.qtcompat import QString except ImportError: QString = six.text_type fname = self.get_file('test-t2m-u-v.nc') ds = psy.open_dataset(fname) self.pc.bt_get_ds.get_from_shell(ds) # add data arrays QTest.mouseClick(self.pc.bt_add_all, Qt.LeftButton) # get names atab = self.pc.array_table names = sorted(list(set(ds.variables).difference(ds.coords))) # get itemdelegate item_delegate = atab.itemDelegateForColumn(atab.var_col) # create editor and validator widget = QWidget() option = QStyleOptionViewItem() index = atab.indexFromItem(atab.item(0, atab.arr_col)) editor = item_delegate.createEditor(widget, option, index) validator = editor.validator() # check validation self.assertEqual(validator.validate(QString('dummy'), 5)[0], QValidator.Invalid) self.assertEqual(validator.validate(QString(names[0]), len(names[0]))[0], QValidator.Acceptable) self.assertEqual(validator.validate(QString(names[0])[:2], 2)[0], QValidator.Intermediate) s = atab.sep.join(names) self.assertEqual(validator.validate(QString(s), len(s))[0], QValidator.Acceptable) self.assertEqual( validator.validate( QString(s[:3] + 'dummy' + s[3:]), len(s) + 5)[0], QValidator.Invalid) ds.close()
def __init__(self, parent, fmto, artist=None, base=None): """ Parameters ---------- %(FontWeightWidget.parameters)s """ QWidget.__init__(self, parent) hbox = QHBoxLayout() if artist is not None: self.current_font = self.artist_to_qfont(artist) self.current_color = QtGui.QColor.fromRgbF( *mcol.to_rgba(artist.get_color())) else: self.current_color = QtGui.QColor(Qt.black) self.fmto_name = fmto.name or fmto.key # choose font button button = QPushButton('Choose font') button.clicked.connect(partial(self.choose_font, None)) hbox.addWidget(button) # font size spin box self.spin_box = spin_box = QSpinBox(self) spin_box.setRange(1, 1e9) if artist is not None: spin_box.setValue(int(artist.get_size())) spin_box.valueChanged.connect(self.modify_size) hbox.addWidget(spin_box) # font color button self.btn_font_color = button = QToolButton(self) button.setIcon(QIcon(get_icon('font_color.png'))) button.clicked.connect(partial(self.choose_color, None)) hbox.addWidget(button) # bold button self.btn_bold = button = QToolButton(self) button.setIcon(QIcon(get_icon('bold.png'))) button.clicked.connect(self.toggle_bold) button.setCheckable(True) if artist is not None: button.setChecked(self.current_font.weight() > 50) hbox.addWidget(button) # italic button self.btn_italic = button = QToolButton(self) button.setIcon(QIcon(get_icon('italic.png'))) button.clicked.connect(self.toggle_italic) button.setCheckable(True) if artist is not None: button.setChecked(self.current_font.italic()) hbox.addWidget(button) if base is not None: # add a button to change to the base formatoption fmtos = [ base, getattr(fmto.plotter, base.key + 'size', None), getattr(fmto.plotter, base.key + 'weight', None), ] fmtos = list(filter(None, fmtos)) hbox.addWidget(Switch2FmtButton(parent, *fmtos)) self.setLayout(hbox)