def add_buttons_to_layout(self, layout): """Add tool buttons to layout""" # Image orientation angle_label = QLabel(_("Angle (°):")) layout.addWidget(angle_label) self.angle_combo = QComboBox(self) self.angle_combo.addItems(self.ROTATION_ANGLES) self.angle_combo.setCurrentIndex(1) self.angle_combo.currentIndexChanged.connect( lambda index: self.apply_transformation()) layout.addWidget(self.angle_combo) layout.addSpacing(10) # Image flipping flip_label = QLabel(_("Flip:")) layout.addWidget(flip_label) hflip = create_toolbutton(self, text="", icon=get_icon("hflip.png"), toggled=lambda state: self.apply_transformation(), autoraise=False) self.hflip_btn = hflip layout.addWidget(hflip) vflip = create_toolbutton(self, text="", icon=get_icon("vflip.png"), toggled=lambda state: self.apply_transformation(), autoraise=False) self.vflip_btn = vflip layout.addWidget(vflip) layout.addSpacing(15) self.add_reset_button(layout)
def __init__(self, item, parent_layout): AbstractDataSetWidget.__init__(self, item, parent_layout) self.group = QLabel() wordwrap = item.get_prop_value("display", "wordwrap", False) self.group.setWordWrap(wordwrap) self.group.setToolTip(item.get_help()) self.group.setStyleSheet(LABEL_CSS) self.group.setTextInteractionFlags(Qt.TextSelectableByMouse)
def __init__(self, parent): QWidget.__init__(self, parent) font = QFont(get_family(MONOSPACE), 10, QFont.Normal) info_icon = QLabel() icon = get_std_icon('MessageBoxInformation').pixmap(24, 24) info_icon.setPixmap(icon) info_icon.setFixedWidth(32) info_icon.setAlignment(Qt.AlignTop) self.desc_label = QLabel() self.desc_label.setWordWrap(True) self.desc_label.setAlignment(Qt.AlignTop) self.desc_label.setFont(font) group_desc = QGroupBox(_("Description"), self) layout = QHBoxLayout() layout.addWidget(info_icon) layout.addWidget(self.desc_label) group_desc.setLayout(layout) if CodeEditor is None: self.editor = QTextEdit(self) self.editor.setFont(font) else: self.editor = CodeEditor(self) self.editor.setup_editor(linenumbers=True, font=font) self.editor.set_color_scheme("Spyder") self.editor.setReadOnly(True) group_code = QGroupBox(_("Source code"), self) layout = QVBoxLayout() layout.addWidget(self.editor) group_code.setLayout(layout) self.run_button = QPushButton(get_icon("apply.png"), _("Run this script"), self) self.quit_button = QPushButton(get_icon("exit.png"), _("Quit"), self) hlayout = QHBoxLayout() hlayout.addWidget(self.run_button) hlayout.addStretch() hlayout.addWidget(self.quit_button) vlayout = QVBoxLayout() vlayout.addWidget(group_desc) vlayout.addWidget(group_code) vlayout.addLayout(hlayout) self.setLayout(vlayout)
def get_image_label(name, default="not_found.png"): """ Construct a QLabel from the file with specified name name, default: filenames with extensions """ label = QLabel() pixmap = QPixmap(get_image_file_path(name, default)) label.setPixmap(pixmap) return label
def place_label(self, layout, row, column): """ Place item label on layout at specified position (row, column) """ label_text = self.item.get_prop_value("display", "label") unit = self.item.get_prop_value("display", "unit", '') if unit and not self.READ_ONLY: label_text += (' (%s)' % unit) self.label = QLabel(label_text) self.label.setToolTip(self.item.get_help()) layout.addWidget(self.label, row, column)
def __init__(self, label, klass, wordwrap=False, **kwargs): QGroupBox.__init__(self, label) self.klass = klass self.dataset = klass(**kwargs) self.layout = QVBoxLayout() if self.dataset.get_comment(): label = QLabel(self.dataset.get_comment()) label.setWordWrap(wordwrap) self.layout.addWidget(label) self.grid_layout = QGridLayout() self.layout.addLayout(self.grid_layout) self.setLayout(self.layout) self.edit = self.get_edit_layout()
def create_widgets(self, parent, refresh_callback): self._refresh_callback = refresh_callback self.prefix_label = QLabel() font = self.prefix_label.font() font.setPointSize(font.pointSize() + self._size_offset) self.prefix_label.setFont(font) self.button = QPushButton() self.button.setIcon(get_icon('settings.png')) self.button.setToolTip( _("Edit '%s' fit parameter properties") % self.name) self.button.clicked.connect(lambda: self.edit_param(parent)) self.lineedit = QLineEdit() self.lineedit.editingFinished.connect(self.line_editing_finished) self.unit_label = QLabel(self.unit) self.slider = QSlider() self.slider.setOrientation(Qt.Horizontal) self.slider.setRange(0, self.steps - 1) self.slider.valueChanged.connect(self.slider_value_changed) self.update(refresh=False) self.add_widgets([ self.prefix_label, self.lineedit, self.unit_label, self.slider, self.button ])
def get_image_layout(imagename, text="", tooltip="", alignment=Qt.AlignLeft): """ Construct a QHBoxLayout including image from the file with specified name, left-aligned text [with specified tooltip] Return (layout, label) """ layout = QHBoxLayout() if alignment in (Qt.AlignCenter, Qt.AlignRight): layout.addStretch() layout.addWidget(get_image_label(imagename)) label = QLabel(text) label.setToolTip(tooltip) layout.addWidget(label) if alignment in (Qt.AlignCenter, Qt.AlignLeft): layout.addStretch() return (layout, label)
def __init__(self, instance, icon='', parent=None, apply=None, wordwrap=True, size=None): QDialog.__init__(self, parent) self.wordwrap = wordwrap self.apply_func = apply self.layout = QVBoxLayout() if instance.get_comment(): label = QLabel(instance.get_comment()) label.setWordWrap(wordwrap) self.layout.addWidget(label) self.instance = instance self.edit_layout = [] self.setup_instance(instance) if apply is not None: apply_button = QDialogButtonBox.Apply else: apply_button = QDialogButtonBox.NoButton bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel | apply_button) self.bbox = bbox bbox.accepted.connect(self.accept) bbox.rejected.connect(self.reject) bbox.clicked.connect(self.button_clicked) self.layout.addWidget(bbox) self.setLayout(self.layout) if parent is None: if not isinstance(icon, QIcon): icon = get_icon(icon, default="plotpy.svg") self.setWindowIcon(icon) self.setModal(True) self.setWindowTitle(instance.get_title()) if size is not None: if isinstance(size, QSize): self.resize(size) else: self.resize(*size)
def __init__(self, parent): QWidget.__init__(self, parent) layout = QHBoxLayout() row_nb = 14 cindex = 0 for child in dir(QStyle): if child.startswith('SP_'): if cindex == 0: col_layout = QVBoxLayout() icon_layout = QHBoxLayout() icon = get_std_icon(child) label = QLabel() label.setPixmap(icon.pixmap(32, 32)) icon_layout.addWidget(label) icon_layout.addWidget(QLineEdit(child.replace('SP_', ''))) col_layout.addLayout(icon_layout) cindex = (cindex + 1) % row_nb if cindex == 0: layout.addLayout(col_layout) self.setLayout(layout) self.setWindowTitle('Standard Platform Icons') self.setWindowIcon(get_std_icon('TitleBarMenuButton'))
def setup_instance(self, instance): """Override DataSetEditDialog method""" from plotpy.dataset.datatypes import DataSetGroup assert isinstance(instance, DataSetGroup) tabs = QTabWidget() # tabs.setUsesScrollButtons(False) self.layout.addWidget(tabs) for dataset in instance.datasets: layout = QVBoxLayout() layout.setAlignment(Qt.AlignTop) if dataset.get_comment(): label = QLabel(dataset.get_comment()) label.setWordWrap(self.wordwrap) layout.addWidget(label) grid = QGridLayout() self.edit_layout.append(self.layout_factory(dataset, grid)) layout.addLayout(grid) page = QWidget() page.setLayout(layout) if dataset.get_icon(): tabs.addTab(page, get_icon(dataset.get_icon()), dataset.get_title()) else: tabs.addTab(page, dataset.get_title())
def __init__(self, parent, new_size, old_size, text="", keep_original_size=False): QDialog.__init__(self, parent) intfunc = lambda tup: [int(val) for val in tup] if intfunc(new_size) == intfunc(old_size): self.keep_original_size = True else: self.keep_original_size = keep_original_size self.width, self.height = new_size self.old_width, self.old_height = old_size self.ratio = self.width / self.height layout = QVBoxLayout() self.setLayout(layout) formlayout = QFormLayout() layout.addLayout(formlayout) if text: label = QLabel(text) label.setAlignment(Qt.AlignHCenter) formlayout.addRow(label) self.w_edit = w_edit = QLineEdit(self) w_valid = QIntValidator(w_edit) w_valid.setBottom(1) w_edit.setValidator(w_valid) self.h_edit = h_edit = QLineEdit(self) h_valid = QIntValidator(h_edit) h_valid.setBottom(1) h_edit.setValidator(h_valid) zbox = QCheckBox(_("Original size"), self) formlayout.addRow(_("Width (pixels)"), w_edit) formlayout.addRow(_("Height (pixels)"), h_edit) formlayout.addRow('', zbox) formlayout.addRow(_("Original size:"), QLabel("%d x %d" % old_size)) self.z_label = QLabel() formlayout.addRow(_("Zoom factor:"), self.z_label) # Button box self.bbox = bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bbox.accepted.connect(self.accept) bbox.rejected.connect(self.reject) layout.addWidget(bbox) self.w_edit.setText(str(self.width)) self.h_edit.setText(str(self.height)) self.update_widgets() self.setWindowTitle(_("Resize")) w_edit.textChanged.connect(self.width_changed) h_edit.textChanged.connect(self.height_changed) zbox.toggled.connect(self.toggled_no_zoom) zbox.setChecked(self.keep_original_size)