def __init__(self, dims, axis, reverse=False, fps=10, mode=LoopMode.LOOP): super().__init__() self.dims = dims self.axis = axis self.reverse = reverse self.fps = fps self.mode = mode self.setProperty('reverse', str(reverse)) # for styling self.setProperty('playing', 'False') # for styling # build popup modal form self.popup = QtPopup(self) form_layout = QFormLayout() self.popup.frame.setLayout(form_layout) fpsspin = QtCustomDoubleSpinBox(self.popup) fpsspin.setAlignment(Qt.AlignCenter) fpsspin.setValue(self.fps) if hasattr(fpsspin, 'setStepType'): # this was introduced in Qt 5.12. Totally optional, just nice. fpsspin.setStepType(QDoubleSpinBox.AdaptiveDecimalStepType) fpsspin.setMaximum(500) fpsspin.setMinimum(0) form_layout.insertRow(0, QLabel('frames per second:', parent=self.popup), fpsspin) self.fpsspin = fpsspin revcheck = QCheckBox(self.popup) form_layout.insertRow(1, QLabel('play direction:', parent=self.popup), revcheck) self.reverse_check = revcheck # THIS IS HERE TEMPORARILY UNTIL I CAN ADD FRAME_RANGE TO THE POPUP # dimsrange = dims.dims.range[axis] # minspin = QDoubleSpinBox(self.popup) # minspin.setAlignment(Qt.AlignCenter) # minspin.setValue(dimsrange[0]) # minspin.valueChanged.connect(self.set_minframe) # form_layout.insertRow( # 1, QLabel('start frame:', parent=self.popup), minspin # ) # maxspin = QDoubleSpinBox(self.popup) # maxspin.setAlignment(Qt.AlignCenter) # maxspin.setValue(dimsrange[1] * dimsrange[2]) # maxspin.valueChanged.connect(self.set_maxframe) # form_layout.insertRow( # 2, QLabel('end frame:', parent=self.popup), maxspin # ) mode_combo = QComboBox(self.popup) mode_combo.addItems([str(i).replace('_', ' ') for i in LoopMode]) form_layout.insertRow(2, QLabel('play mode:', parent=self.popup), mode_combo) mode_combo.setCurrentText(str(self.mode)) self.mode_combo = mode_combo
def __init__(self, dims, axis, reverse=False, fps=10, mode=LoopMode.LOOP): super().__init__() self.dims = dims self.axis = axis self.reverse = reverse self.fps = fps self.mode = mode self.setProperty('reverse', str(reverse)) # for styling self.setProperty('playing', 'False') # for styling # build popup modal form self.popup = QtPopup(self) form_layout = QFormLayout() self.popup.frame.setLayout(form_layout) fpsspin = QtCustomDoubleSpinBox(self.popup) fpsspin.setObjectName("fpsSpinBox") fpsspin.setAlignment(Qt.AlignCenter) fpsspin.setValue(self.fps) if hasattr(fpsspin, 'setStepType'): # this was introduced in Qt 5.12. Totally optional, just nice. fpsspin.setStepType(QDoubleSpinBox.AdaptiveDecimalStepType) fpsspin.setMaximum(500) fpsspin.setMinimum(0) form_layout.insertRow( 0, QLabel(trans._('frames per second:'), parent=self.popup), fpsspin, ) self.fpsspin = fpsspin revcheck = QCheckBox(self.popup) revcheck.setObjectName("playDirectionCheckBox") form_layout.insertRow( 1, QLabel(trans._('play direction:'), parent=self.popup), revcheck ) self.reverse_check = revcheck mode_combo = QComboBox(self.popup) mode_combo.addItems([str(i).replace('_', ' ') for i in LoopMode]) form_layout.insertRow( 2, QLabel(trans._('play mode:'), parent=self.popup), mode_combo ) mode_combo.setCurrentText(str(self.mode)) self.mode_combo = mode_combo
class AxisSettingsDisplay(Display): def __init__(self, main_display, parent=None): super(AxisSettingsDisplay, self).__init__(parent=parent) self.main_layout = QFormLayout() self.main_display = main_display self.chart = self.main_display.chart self.x_axis_lbl = QLabel("x-axis Label") self.x_axis_label_line_edt = QLineEdit() current_x_label = self.chart.labels["bottom"] if current_x_label: current_x_label = current_x_label[current_x_label. find(X_AXIS_LABEL_SEPARATOR) + len(X_AXIS_LABEL_SEPARATOR):] self.x_axis_label_line_edt.setText(current_x_label) self.x_axis_label_line_edt.textChanged.connect( partial(self.handle_axis_label_change, "bottom")) self.x_axis_font_btn = QPushButton() self.x_axis_font_btn.setMaximumHeight(32) self.x_axis_font_btn.setMaximumWidth(32) self.x_axis_font_btn.setIcon(IconFont().icon("font")) self.x_axis_font_btn.clicked.connect( partial(self.handle_font_change, "bottom")) self.x_axis_unit_lbl = QLabel("x-axis Unit") self.x_axis_unit_edt = QLineEdit() self.x_axis_unit_edt.setMaximumWidth(150) self.x_axis_unit_edt.setText(self.chart.units["bottom"]) self.x_axis_unit_edt.textChanged.connect( partial(self.handle_axis_label_change, "bottom", is_unit=True)) self.y_axis_lbl = QLabel("y-axis Label") self.y_axis_label_line_edt = QLineEdit() self.y_axis_label_line_edt.setText(self.chart.labels["left"]) self.y_axis_label_line_edt.textChanged.connect( partial(self.handle_axis_label_change, "left")) self.y_axis_font_btn = QPushButton() self.y_axis_font_btn.setMaximumHeight(32) self.y_axis_font_btn.setMaximumWidth(32) self.y_axis_font_btn.setIcon(IconFont().icon("font")) self.y_axis_font_btn.clicked.connect( partial(self.handle_font_change, "left")) self.y_axis_unit_lbl = QLabel("y-axis Unit") self.y_axis_unit_edt = QLineEdit() self.y_axis_unit_edt.setMaximumWidth(150) self.y_axis_unit_edt.setText(self.chart.units["left"]) self.y_axis_unit_edt.textChanged.connect( partial(self.handle_axis_label_change, "left", is_unit=True)) self.right_y_axis_label_line_edt = QLineEdit() self.display_right_y_axis_chk = QCheckBox("Display the right y-axis") self.display_right_y_axis_chk.setChecked(self.chart.getShowRightAxis()) self.display_right_y_axis_chk.clicked.connect( self.handle_right_y_axis_checkbox_changed) self.display_right_y_axis_chk.setChecked(self.chart.getShowRightAxis()) self.right_y_axis_lbl = None self.right_y_axis_unit_edt = None self.right_y_axis_unit_lbl = None self.right_y_axis_unit_edt = None self.close_dialog_btn = QPushButton("Close") self.close_dialog_btn.clicked.connect(self.handle_close_button_clicked) self.setWindowTitle("Axis Settings") self.setMinimumSize(500, 300) self.setWindowModality(Qt.ApplicationModal) self.setup_ui() def ui_filepath(self): """ The path to the UI file created by Qt Designer, if applicable. """ # No UI file is being used return None def ui_filename(self): """ The name of the UI file created by Qt Designer, if applicable. """ # No UI file is being used return None def setup_ui(self): x_axis_layout = QHBoxLayout() x_axis_layout.addWidget(self.x_axis_label_line_edt) x_axis_layout.addWidget(self.x_axis_font_btn) y_axis_layout = QHBoxLayout() y_axis_layout.addWidget(self.y_axis_label_line_edt) y_axis_layout.addWidget(self.y_axis_font_btn) # Add widgets to the form layout self.main_layout.setSpacing(10) self.main_layout.addRow(self.x_axis_lbl, x_axis_layout) self.main_layout.addRow(self.x_axis_unit_lbl, self.x_axis_unit_edt) self.main_layout.addRow(self.y_axis_lbl, y_axis_layout) self.main_layout.addRow(self.y_axis_unit_lbl, self.y_axis_unit_edt) self.main_layout.addRow(self.display_right_y_axis_chk, None) self.main_layout.addRow(None, self.close_dialog_btn) self.display_right_y_axis_chk.setChecked(self.chart.getShowRightAxis()) if self.chart.getShowRightAxis(): self.display_right_y_axis_chk.clicked.emit( self.chart.getShowRightAxis()) self.setLayout(self.main_layout) def handle_right_y_axis_checkbox_changed(self, is_checked): self.chart.setShowRightAxis(is_checked) if is_checked: right_label = self.chart.labels["right"] if not right_label: right_label = self.y_axis_label_line_edt.text() right_unit = self.chart.units["right"] if not right_unit: right_unit = self.y_axis_unit_edt.text() self.right_y_axis_font_btn = QPushButton() self.right_y_axis_font_btn.setMaximumHeight(32) self.right_y_axis_font_btn.setMaximumWidth(32) self.right_y_axis_font_btn.setIcon(IconFont().icon("font")) self.right_y_axis_font_btn.clicked.connect( partial(self.handle_font_change, "right")) self.right_y_axis_lbl = QLabel("Right y-axis Label") self.right_y_axis_label_line_edt = QLineEdit() self.right_y_axis_label_line_edt.textChanged.connect( partial(self.handle_axis_label_change, "right")) self.right_y_axis_unit_lbl = QLabel("Right y-axis Unit") self.right_y_axis_unit_edt = QLineEdit() self.right_y_axis_unit_edt.setMaximumWidth(150) self.right_y_axis_unit_edt.textChanged.connect( partial(self.handle_axis_label_change, "right", is_unit=True)) self.right_y_axis_label_line_edt.setText(right_label) self.right_y_axis_unit_edt.setText(right_unit) right_y_axis_layout = QHBoxLayout() right_y_axis_layout.addWidget(self.right_y_axis_label_line_edt) right_y_axis_layout.addWidget(self.right_y_axis_font_btn) self.main_layout.insertRow(self.main_layout.rowCount() - 1, self.right_y_axis_lbl, right_y_axis_layout) self.main_layout.insertRow(self.main_layout.rowCount() - 1, self.right_y_axis_unit_lbl, self.right_y_axis_unit_edt) else: self.chart.showAxis("right", show=False) self.right_y_axis_lbl.deleteLater() self.right_y_axis_label_line_edt.deleteLater() self.right_y_axis_unit_lbl.deleteLater() self.right_y_axis_unit_edt.deleteLater() self.right_y_axis_font_btn.deleteLater() def handle_axis_label_change(self, axis_position, new_label, is_unit=False): if is_unit: self.chart.setLabel(axis_position, units=new_label) self.chart.units[axis_position] = new_label else: if axis_position == "bottom": current_label = self.chart.getBottomAxisLabel() if X_AXIS_LABEL_SEPARATOR in current_label: current_label = current_label[:current_label.find( X_AXIS_LABEL_SEPARATOR) - len(X_AXIS_LABEL_SEPARATOR)] new_label = current_label + X_AXIS_LABEL_SEPARATOR + new_label self.chart.setLabel(axis_position, text=new_label) self.chart.labels[axis_position] = new_label return def change_axis_font(self, axis, font): axis.setTickFont(font) axis.label.setFont(font) def handle_font_change(self, axis_position): axis = self.chart.getAxis(axis_position) label = axis.label initial = axis.tickFont dialog = QFontDialog(self) if initial: dialog.setCurrentFont(initial) dialog.setOption(QFontDialog.DontUseNativeDialog, True) dialog.fontSelected.connect(partial(self.change_axis_font, axis)) dialog.open() def closeEvent(self, event): self.handle_close_button_clicked() def handle_close_button_clicked(self): """ Close the dialog when the Close button is clicked. """ self.close()
def _open_grid_popup(self): """Open grid options pop up widget.""" # widgets popup = QtPopup(self) grid_stride = QtSpinBox(popup) grid_width = QtSpinBox(popup) grid_height = QtSpinBox(popup) shape_help_symbol = QtToolTipLabel(self) stride_help_symbol = QtToolTipLabel(self) blank = QLabel(self) # helps with placing help symbols. shape_help_msg = trans._( 'Number of rows and columns in the grid. A value of -1 for either or both of width and height will trigger an auto calculation of the necessary grid shape to appropriately fill all the layers at the appropriate stride. 0 is not a valid entry.' ) stride_help_msg = trans._( 'Number of layers to place in each grid square before moving on to the next square. The default ordering is to place the most visible layer in the top left corner of the grid. A negative stride will cause the order in which the layers are placed in the grid to be reversed. 0 is not a valid entry.' ) # set up stride_min = self.viewer.grid.__fields__['stride'].type_.ge stride_max = self.viewer.grid.__fields__['stride'].type_.le stride_not = self.viewer.grid.__fields__['stride'].type_.ne grid_stride.setObjectName("gridStrideBox") grid_stride.setAlignment(Qt.AlignCenter) grid_stride.setRange(stride_min, stride_max) grid_stride.setProhibitValue(stride_not) grid_stride.setValue(self.viewer.grid.stride) grid_stride.valueChanged.connect(self._update_grid_stride) self.grid_stride_box = grid_stride width_min = self.viewer.grid.__fields__['shape'].sub_fields[1].type_.ge width_not = self.viewer.grid.__fields__['shape'].sub_fields[1].type_.ne grid_width.setObjectName("gridWidthBox") grid_width.setAlignment(Qt.AlignCenter) grid_width.setMinimum(width_min) grid_width.setProhibitValue(width_not) grid_width.setValue(self.viewer.grid.shape[1]) grid_width.valueChanged.connect(self._update_grid_width) self.grid_width_box = grid_width height_min = ( self.viewer.grid.__fields__['shape'].sub_fields[0].type_.ge) height_not = ( self.viewer.grid.__fields__['shape'].sub_fields[0].type_.ne) grid_height.setObjectName("gridStrideBox") grid_height.setAlignment(Qt.AlignCenter) grid_height.setMinimum(height_min) grid_height.setProhibitValue(height_not) grid_height.setValue(self.viewer.grid.shape[0]) grid_height.valueChanged.connect(self._update_grid_height) self.grid_height_box = grid_height shape_help_symbol.setObjectName("help_label") shape_help_symbol.setToolTip(shape_help_msg) stride_help_symbol.setObjectName("help_label") stride_help_symbol.setToolTip(stride_help_msg) # layout form_layout = QFormLayout() form_layout.insertRow(0, QLabel(trans._('Grid stride:')), grid_stride) form_layout.insertRow(1, QLabel(trans._('Grid width:')), grid_width) form_layout.insertRow(2, QLabel(trans._('Grid height:')), grid_height) help_layout = QVBoxLayout() help_layout.addWidget(stride_help_symbol) help_layout.addWidget(blank) help_layout.addWidget(shape_help_symbol) layout = QHBoxLayout() layout.addLayout(form_layout) layout.addLayout(help_layout) popup.frame.setLayout(layout) popup.show_above_mouse() # adjust placement of shape help symbol. Must be done last # in order for this movement to happen. delta_x = 0 delta_y = -15 shape_pos = ( shape_help_symbol.x() + delta_x, shape_help_symbol.y() + delta_y, ) shape_help_symbol.move(QPoint(*shape_pos))