def _addSlider(self, v, cnt): control = QSlider(Qt.Horizontal) control.setMinimumWidth(172) control.setFocusPolicy(Qt.StrongFocus) control.setMaximum(v.max * 160) control.setMinimum(v.min * 160) control.setValue(v.value * 160) control.tag = cnt if self.styleName == "mac": control.setAttribute(Qt.WA_MacMiniSize, True) self.layout.addWidget(control, cnt, 1) self.connect(control, SIGNAL("valueChanged(int)"), self.numberChanged_)
class LinearPoti(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletLinearPoti, *args) self.lp = self.device self.cbe_position = CallbackEmulator(self.lp.get_position, self.cb_position, self.increase_error_count) self.slider = QSlider(Qt.Horizontal) self.slider.setRange(0, 100) self.slider.setMinimumWidth(200) self.current_position = None plots = [('Position', Qt.red, lambda: self.current_position, str)] self.plot_widget = PlotWidget('Position', plots, extra_key_widgets=[self.slider], curve_motion_granularity=40, update_interval=0.025) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def start(self): async_call(self.lp.get_position, None, self.cb_position, self.increase_error_count) self.cbe_position.set_period(25) self.plot_widget.stop = False def stop(self): self.cbe_position.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLinearPoti.DEVICE_IDENTIFIER def cb_position(self, position): self.current_position = position self.slider.setValue(position)
class LinearPoti(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletLinearPoti, *args) self.lp = self.device self.cbe_position = CallbackEmulator(self.lp.get_position, self.cb_position, self.increase_error_count) self.slider = QSlider(Qt.Horizontal) self.slider.setRange(0, 100) self.slider.setMinimumWidth(200) self.current_position = None plots = [('Position', Qt.red, lambda: self.current_position, str)] self.plot_widget = PlotWidget('Position', plots, extra_key_widgets=[self.slider], curve_motion_granularity=40, update_interval=0.025) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def start(self): async_call(self.lp.get_position, None, self.cb_position, self.increase_error_count) self.cbe_position.set_period(25) self.plot_widget.stop = False def stop(self): self.cbe_position.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'linear_poti' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLinearPoti.DEVICE_IDENTIFIER def cb_position(self, position): self.current_position = position self.slider.setValue(position)
class SpinAndSliderWidget(QWidget): """this combinate a spin box and a slider in log scale""" sigChanged = pyqtSignal() def __init__( self, parent=None, value=1., limits=[0.001, 1000], orientation=Qt.Horizontal, ): QWidget.__init__(self, parent) self._val = None self.limits = limits if orientation == Qt.Horizontal: self.mainlayout = QHBoxLayout() else: self.mainlayout = QVBoxLayout() self.setLayout(self.mainlayout) #~ self.spinbox = QDoubleSpinBox(decimals = 4, singleStep = .1, #~ minimum = self.limits[0], maximum = self.limits[1]) self.spinbox = pg.SpinBox(decimals=4, singleStep=.1, minimum=self.limits[0], maximum=self.limits[1]) self.mainlayout.addWidget(self.spinbox) self.slider = QSlider(Qt.Horizontal, minimum=0, maximum=100) self.mainlayout.addWidget(self.slider) self.slider.setMinimumWidth(20) self.spinbox.valueChanged.connect(self.spinbox_changed) self.slider.valueChanged.connect(self.slider_changed) self.setValue(value) def value(self): return self._val def setValue(self, val): self._val = val self.spinbox.valueChanged.disconnect(self.spinbox_changed) self.spinbox.setValue(val) self.spinbox.valueChanged.connect(self.spinbox_changed) self.slider.valueChanged.disconnect(self.slider_changed) self.slider.setValue(self.to_log(val)) self.slider.valueChanged.connect(self.slider_changed) def to_log(self, val): min, max = self.limits return int((np.log10(val) - np.log10(min)) / (np.log10(max) - np.log10(min)) * 100) def from_log(self, val): min, max = self.limits return 10**((val / 100.) * (np.log10(max) - np.log10(min)) + np.log10(min)) def slider_changed(self, val): self._val = self.from_log(val) self.spinbox.valueChanged.disconnect(self.spinbox_changed) self.spinbox.setValue(self._val) self.spinbox.valueChanged.connect(self.spinbox_changed) self.sigChanged.emit() def spinbox_changed(self, val): self._val = val self.slider.valueChanged.disconnect(self.slider_changed) self.slider.setValue(self.to_log(self._val)) self.slider.valueChanged.connect(self.slider_changed) self.sigChanged.emit() def updateDisplayLabel(self, value=None): if value is None: value = self.param.value() opts = self.param.opts if value is None: text = '' else: text = '{}'.format(self._val) self.displayLabel.setText(text)
class MotorizedLinearPoti(COMCUPluginBase): def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletMotorizedLinearPoti, *args) self.mp = self.device self.cbe_position = CallbackEmulator(self.mp.get_position, self.cb_position, self.increase_error_count) self.current_position = None self.slider = QSlider(Qt.Horizontal) self.slider.setRange(0, 100) self.slider.setMinimumWidth(200) self.slider.setEnabled(False) plots = [('Potentiometer Position', Qt.red, lambda: self.current_position, str)] self.plot_widget = PlotWidget('Position', plots, extra_key_widgets=[self.slider], curve_motion_granularity=40, update_interval=0.025) self.motor_slider = QSlider(Qt.Horizontal) self.motor_slider.setRange(0, 100) self.motor_slider.valueChanged.connect(self.motor_slider_value_changed) self.motor_hold_position = QCheckBox("Hold Position") self.motor_drive_mode = QComboBox() self.motor_drive_mode.addItem('Fast') self.motor_drive_mode.addItem('Smooth') def get_motor_slider_value(): return self.motor_slider.value() self.motor_hold_position.stateChanged.connect(lambda x: self.motor_slider_value_changed(get_motor_slider_value())) self.motor_drive_mode.currentIndexChanged.connect(lambda x: self.motor_slider_value_changed(get_motor_slider_value())) self.motor_position_label = MotorPositionLabel('Motor Target Position:') hlayout = QHBoxLayout() hlayout.addWidget(self.motor_position_label) hlayout.addWidget(self.motor_slider) hlayout.addWidget(self.motor_drive_mode) hlayout.addWidget(self.motor_hold_position) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout) def start(self): async_call(self.mp.get_position, None, self.cb_position, self.increase_error_count) async_call(self.mp.get_motor_position, None, self.cb_motor_position, self.increase_error_count) self.cbe_position.set_period(25) self.plot_widget.stop = False def stop(self): self.cbe_position.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletMotorizedLinearPoti.DEVICE_IDENTIFIER def cb_position(self, position): self.current_position = position self.slider.setValue(position) def cb_motor_position(self, motor): self.motor_slider.blockSignals(True) self.motor_hold_position.blockSignals(True) self.motor_drive_mode.blockSignals(True) self.motor_hold_position.setChecked(motor.hold_position) self.motor_drive_mode.setCurrentIndex(motor.drive_mode) self.motor_position_label.setText(str(motor.position)) self.motor_slider.setValue(motor.position) self.motor_slider.blockSignals(False) self.motor_hold_position.blockSignals(False) self.motor_drive_mode.blockSignals(False) def motor_slider_value_changed(self, position): self.motor_position_label.setText(str(position)) self.mp.set_motor_position(self.motor_slider.value(), self.motor_drive_mode.currentIndex(), self.motor_hold_position.isChecked())
class MotorizedPoti(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletMotorizedPoti, *args) self.mp = self.device self.cbe_position = CallbackEmulator(self.mp.get_position, self.cb_position, self.increase_error_count) self.current_position = None self.slider = QSlider(Qt.Horizontal) self.slider.setRange(0, 100) self.slider.setMinimumWidth(200) plots = [('Position', Qt.red, lambda: self.current_position, str)] self.plot_widget = PlotWidget('Position', plots, extra_key_widgets=[self.slider], curve_motion_granularity=40, update_interval=0.025) self.motor_slider = QSlider(Qt.Horizontal) self.motor_slider.setRange(0, 100) self.motor_slider.sliderReleased.connect(self.motor_slider_released) self.motor_slider.sliderMoved.connect(self.motor_slider_moved) self.motor_enable = QCheckBox("Enable Motor") self.motor_enable.stateChanged.connect(self.motor_enable_changed) self.motor_position_label = MotorPositionLabel('Motor Position: ') hlayout = QHBoxLayout() hlayout.addWidget(self.motor_position_label) hlayout.addWidget(self.motor_slider) hlayout.addWidget(self.motor_enable) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout) def start(self): async_call(self.mp.get_position, None, self.cb_position, self.increase_error_count) async_call(self.mp.get_motor_position, None, self.cb_motor_position, self.increase_error_count) async_call(self.mp.is_motor_enabled, None, self.cb_is_motor_enabled, self.increase_error_count) self.cbe_position.set_period(25) self.plot_widget.stop = False def stop(self): self.cbe_position.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'motorized_poti' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletMotorizedPoti.DEVICE_IDENTIFIER def cb_position(self, position): self.current_position = position self.slider.setValue(position) def cb_motor_position(self, motor_position): self.motor_slider.setValue(motor_position.position) self.motor_slider_moved(motor_position.position) def cb_is_motor_enabled(self, enabled): self.motor_enable.setChecked(enabled) def motor_slider_moved(self, position): self.motor_position_label.setText(str(position)) def motor_slider_released(self): self.mp.set_motor_position(self.motor_slider.value(), False) def motor_enable_changed(self, state): if self.motor_enable.isChecked(): self.mp.enable_motor() else: self.mp.disable_motor()
class QuadStatusBar(QHBoxLayout): positionChanged = pyqtSignal(int, int, int) # x,y,z def __init__(self, parent=None ): QHBoxLayout.__init__(self, parent) self.setContentsMargins(0,4,0,0) self.setSpacing(0) self.timeControlFontSize = 12 def showXYCoordinates(self): self.zLabel.setHidden(True) self.zSpinBox.setHidden(True) def showXYZCoordinates(self): self.zLabel.setHidden(False) self.zSpinBox.setHidden(False) def hideTimeSlider(self,flag): self.timeSlider.setHidden(flag) self.timeEndButton.setHidden(flag) self.timeStartButton.setHidden(flag) def setToolTipTimeButtonsCrop(self,croppingFlag=False): if croppingFlag==True: self.timeStartButton.setToolTip("Set the time coordinate to the beginning of the current crop.") self.timeEndButton.setToolTip("Set the time coordinate to the end of the current crop.") else: self.timeStartButton.setToolTip("Set the time coordinate to the beginning of the current dataset.") self.timeEndButton.setToolTip("Set the time coordinate to the end of the current dataset.") def setToolTipTimeSliderCrop(self,croppingFlag=False): if croppingFlag==True: self.timeSlider.setToolTip("Choose the time coordinate of the current crop.") else: self.timeSlider.setToolTip("Choose the time coordinate of the current dataset.") def createQuadViewStatusBar(self, xbackgroundColor, xforegroundColor, ybackgroundColor, yforegroundColor, zbackgroundColor, zforegroundColor): self.xLabel, self.xSpinBox = _get_pos_widget('X', xbackgroundColor, xforegroundColor) self.yLabel, self.ySpinBox = _get_pos_widget('Y', ybackgroundColor, yforegroundColor) self.zLabel, self.zSpinBox = _get_pos_widget('Z', zbackgroundColor, zforegroundColor) self.xSpinBox.delayedValueChanged.connect( partial(self._handlePositionBoxValueChanged, 'x') ) self.ySpinBox.delayedValueChanged.connect( partial(self._handlePositionBoxValueChanged, 'y') ) self.zSpinBox.delayedValueChanged.connect( partial(self._handlePositionBoxValueChanged, 'z') ) self.addWidget(self.xLabel) self.addWidget(self.xSpinBox) self.addWidget(self.yLabel) self.addWidget(self.ySpinBox) self.addWidget(self.zLabel) self.addWidget(self.zSpinBox) self.addSpacing(10) self.busyIndicator = QProgressBar() self.busyIndicator.setMaximumWidth(200) self.busyIndicator.setMaximum(0) self.busyIndicator.setMinimum(0) self.busyIndicator.setVisible(False) self.busyIndicator.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.addWidget( self.busyIndicator ) self.setStretchFactor(self.busyIndicator, 1) self.addStretch() self.addSpacing(10) self.positionCheckBox = QCheckBox() self.positionCheckBox.setChecked(True) self.positionCheckBox.setCheckable(True) self.positionCheckBox.setText("Position") self.addWidget(self.positionCheckBox) self.addSpacing(20) self.timeSpinBox = DelayedSpinBox(750) self.timeStartButton = QPushButton("Start") self.addWidget(self.timeStartButton) self.timeStartButton.clicked.connect(self._onTimeStartButtonClicked) self.timeSlider = QSlider(Qt.Horizontal) self.timeSlider.setMinimumWidth(10) self.timeSlider.setMaximumWidth(200) self.setToolTipTimeSliderCrop() self.addWidget(self.timeSlider) self.timeSlider.valueChanged.connect(self._onTimeSliderChanged) self.timeEndButton = QPushButton("End") self.timeEndButton.setFixedWidth(4*self.timeControlFontSize) self.timeStartButton.setFixedWidth(4*self.timeControlFontSize) self.setToolTipTimeButtonsCrop() self.addWidget(self.timeEndButton) self.timeEndButton.clicked.connect(self._onTimeEndButtonClicked) self.timeLabel = QLabel(" Time:") self.addWidget(self.timeLabel) timeControlFont = self.timeSpinBox.font() if self.timeControlFontSize > timeControlFont.pointSize(): timeControlFont.setPixelSize(self.timeControlFontSize) self.timeStartButton.setFont(timeControlFont) self.timeEndButton.setFont(timeControlFont) self.timeLabel.setFont(timeControlFont) self.timeSpinBox.setFont(timeControlFont) self.addWidget(self.timeSpinBox) self.timeSpinBox.delayedValueChanged.connect(self._onTimeSpinBoxChanged) def _onTimeStartButtonClicked(self): self.timeSpinBox.setValue(self.parent().parent().parent().editor.cropModel.get_roi_t()[0]) def _onTimeEndButtonClicked(self): self.timeSpinBox.setValue(self.parent().parent().parent().editor.cropModel.get_roi_t()[1]) def _onTimeSpinBoxChanged(self): editor = self.parent().parent().parent().editor cropModel = editor.cropModel minValueT = cropModel.get_roi_t()[0] maxValueT = cropModel.get_roi_t()[1] if cropModel.get_scroll_time_outside_crop(): if minValueT > self.timeSpinBox.value() or maxValueT < self.timeSpinBox.value(): for imgView in editor.imageViews: imgView._croppingMarkers._shading_item.set_paint_full_frame(True) else: for imgView in editor.imageViews: imgView._croppingMarkers._shading_item.set_paint_full_frame(False) self.timeSlider.setValue(self.timeSpinBox.value()) else: for imgView in editor.imageViews: imgView._croppingMarkers._shading_item.set_paint_full_frame(False) if minValueT > self.timeSpinBox.value(): self.timeSlider.setValue(minValueT) elif maxValueT < self.timeSpinBox.value(): self.timeSlider.setValue(maxValueT) elif minValueT <= self.timeSpinBox.value() and self.timeSpinBox.value() <= maxValueT: self.timeSlider.setValue(self.timeSpinBox.value()) def _onTimeSliderChanged(self): cropModel = self.parent().parent().parent().editor.cropModel minValueT = cropModel.get_roi_t()[0] maxValueT = cropModel.get_roi_t()[1] if cropModel.get_scroll_time_outside_crop(): self.timeSpinBox.setValue(self.timeSlider.value()) else: if minValueT > self.timeSlider.value(): self.timeSpinBox.setValue(minValueT) self.timeSlider.setValue(minValueT) elif self.timeSlider.value() > maxValueT: self.timeSpinBox.setValue(maxValueT) self.timeSlider.setValue(maxValueT) elif minValueT <= self.timeSlider.value() and self.timeSlider.value() <= maxValueT: self.timeSpinBox.setValue(self.timeSlider.value()) def _handlePositionBoxValueChanged(self, axis, value): new_position = [self.xSpinBox.value(), self.ySpinBox.value(), self.zSpinBox.value()] changed_axis = ord(axis) - ord('x') new_position[changed_axis] = value self.positionChanged.emit(*new_position) def updateShape5D(self, shape5D): self.timeSpinBox.setMaximum(shape5D[0]-1) self.xSpinBox.setMaximum(shape5D[1]-1) self.ySpinBox.setMaximum(shape5D[2]-1) self.zSpinBox.setMaximum(shape5D[3]-1) def updateShape5Dcropped(self, shape5DcropMin, shape5Dmax): self.timeSpinBox.setMaximum(shape5Dmax[0]-1) self.xSpinBox.setMaximum(shape5Dmax[1]-1) self.ySpinBox.setMaximum(shape5Dmax[2]-1) self.zSpinBox.setMaximum(shape5Dmax[3]-1) self.timeSlider.setMaximum(shape5Dmax[0]-1) self.timeSpinBox.setValue(shape5DcropMin[0]) self.xSpinBox.setValue(shape5DcropMin[1]) self.ySpinBox.setValue(shape5DcropMin[2]) self.zSpinBox.setValue(shape5DcropMin[3]) self.timeSlider.setValue(shape5DcropMin[0]) def setMouseCoords(self, x, y, z): self.xSpinBox.setValueWithoutSignal(x) self.ySpinBox.setValueWithoutSignal(y) self.zSpinBox.setValueWithoutSignal(z)
class QuadStatusBar(QHBoxLayout): positionChanged = pyqtSignal(int, int, int) # x,y,z def __init__(self, parent=None ): QHBoxLayout.__init__(self, parent) self.setContentsMargins(0,4,0,0) self.setSpacing(0) self.timeControlFontSize = 12 def showXYCoordinates(self): self.zLabel.setHidden(True) self.zSpinBox.setHidden(True) def showXYZCoordinates(self): self.zLabel.setHidden(False) self.zSpinBox.setHidden(False) def hideTimeSlider(self,flag): self.timeSlider.setHidden(flag) self.timeEndButton.setHidden(flag) self.timeStartButton.setHidden(flag) def setToolTipTimeButtonsCrop(self,croppingFlag=False): if croppingFlag==True: self.timeStartButton.setToolTip("Set the time coordinate to the beginning of the current crop.") self.timeEndButton.setToolTip("Set the time coordinate to the end of the current crop.") self.timePreviousButton.setToolTip("Set the time coordinate to the previous time frame.") self.timeNextButton.setToolTip("Set the time coordinate to the next time frame.") else: self.timeStartButton.setToolTip("Set the time coordinate to the beginning of the current dataset.") self.timeEndButton.setToolTip("Set the time coordinate to the end of the current dataset.") self.timePreviousButton.setToolTip("Set the time coordinate to the previous time frame.") self.timeNextButton.setToolTip("Set the time coordinate to the next time frame.") def setToolTipTimeSliderCrop(self,croppingFlag=False): if croppingFlag==True: self.timeSlider.setToolTip("Choose the time coordinate of the current crop.") else: self.timeSlider.setToolTip("Choose the time coordinate of the current dataset.") def createQuadViewStatusBar(self, xbackgroundColor, xforegroundColor, ybackgroundColor, yforegroundColor, zbackgroundColor, zforegroundColor): self.xLabel, self.xSpinBox = _get_pos_widget('X', xbackgroundColor, xforegroundColor) self.yLabel, self.ySpinBox = _get_pos_widget('Y', ybackgroundColor, yforegroundColor) self.zLabel, self.zSpinBox = _get_pos_widget('Z', zbackgroundColor, zforegroundColor) self.xSpinBox.delayedValueChanged.connect( partial(self._handlePositionBoxValueChanged, 'x') ) self.ySpinBox.delayedValueChanged.connect( partial(self._handlePositionBoxValueChanged, 'y') ) self.zSpinBox.delayedValueChanged.connect( partial(self._handlePositionBoxValueChanged, 'z') ) self.addWidget(self.xLabel) self.addWidget(self.xSpinBox) self.addWidget(self.yLabel) self.addWidget(self.ySpinBox) self.addWidget(self.zLabel) self.addWidget(self.zSpinBox) self.addSpacing(10) self.busyIndicator = QProgressBar() self.busyIndicator.setMaximumWidth(200) self.busyIndicator.setMaximum(0) self.busyIndicator.setMinimum(0) self.busyIndicator.setVisible(False) self.busyIndicator.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.addWidget( self.busyIndicator ) self.setStretchFactor(self.busyIndicator, 1) self.addStretch() self.addSpacing(10) self.positionCheckBox = QCheckBox() self.positionCheckBox.setChecked(False) self.positionCheckBox.setCheckable(True) self.positionCheckBox.setText("Position") self.addWidget(self.positionCheckBox) self.addSpacing(20) self.timeSpinBox = DelayedSpinBox(750) self.timeStartButton = QPushButton("|<") self.addWidget(self.timeStartButton) self.timeStartButton.clicked.connect(self._onTimeStartButtonClicked) self.timePreviousButton = QPushButton("<") self.addWidget(self.timePreviousButton) self.timePreviousButton.clicked.connect(self._onTimePreviousButtonClicked) self.timePreviousButton.setFixedWidth(4*self.timeControlFontSize) self.timeSlider = QSlider(Qt.Horizontal) self.timeSlider.setMinimumWidth(10) self.timeSlider.setMaximumWidth(200) self.setToolTipTimeSliderCrop() self.addWidget(self.timeSlider) self.timeSlider.valueChanged.connect(self._onTimeSliderChanged) self.timeNextButton = QPushButton(">") self.addWidget(self.timeNextButton) self.timeNextButton.clicked.connect(self._onTimeNextButtonClicked) self.timeNextButton.setFixedWidth(4*self.timeControlFontSize) self.timeEndButton = QPushButton(">|") self.timeEndButton.setFixedWidth(4*self.timeControlFontSize) self.timeStartButton.setFixedWidth(4*self.timeControlFontSize) self.setToolTipTimeButtonsCrop() self.addWidget(self.timeEndButton) self.timeEndButton.clicked.connect(self._onTimeEndButtonClicked) self.timeLabel = QLabel(" Time:") self.addWidget(self.timeLabel) timeControlFont = self.timeSpinBox.font() if self.timeControlFontSize > timeControlFont.pointSize(): timeControlFont.setPixelSize(2*self.timeControlFontSize) self.timeStartButton.setFont(timeControlFont) self.timeEndButton.setFont(timeControlFont) self.timeLabel.setFont(timeControlFont) self.timeSpinBox.setFont(timeControlFont) self.addWidget(self.timeSpinBox) self.timeSpinBox.delayedValueChanged.connect(self._onTimeSpinBoxChanged) def _onTimeStartButtonClicked(self): self.timeSpinBox.setValue(self.parent().parent().parent().editor.cropModel.get_roi_t()[0]) def _onTimeEndButtonClicked(self): self.timeSpinBox.setValue(self.parent().parent().parent().editor.cropModel.get_roi_t()[1]) def _onTimePreviousButtonClicked(self): self.timeSpinBox.setValue(self.timeSpinBox.value()-1) def _onTimeNextButtonClicked(self): self.timeSpinBox.setValue(self.timeSpinBox.value()+1) def _onTimeSpinBoxChanged(self): editor = self.parent().parent().parent().editor cropModel = editor.cropModel minValueT = cropModel.get_roi_t()[0] maxValueT = cropModel.get_roi_t()[1] if cropModel.get_scroll_time_outside_crop(): if minValueT > self.timeSpinBox.value() or maxValueT < self.timeSpinBox.value(): for imgView in editor.imageViews: imgView._croppingMarkers._shading_item.set_paint_full_frame(True) else: for imgView in editor.imageViews: imgView._croppingMarkers._shading_item.set_paint_full_frame(False) self.timeSlider.setValue(self.timeSpinBox.value()) else: for imgView in editor.imageViews: imgView._croppingMarkers._shading_item.set_paint_full_frame(False) if minValueT > self.timeSpinBox.value(): self.timeSlider.setValue(minValueT) elif maxValueT < self.timeSpinBox.value(): self.timeSlider.setValue(maxValueT) elif minValueT <= self.timeSpinBox.value() and self.timeSpinBox.value() <= maxValueT: self.timeSlider.setValue(self.timeSpinBox.value()) def _onTimeSliderChanged(self): cropModel = self.parent().parent().parent().editor.cropModel minValueT = cropModel.get_roi_t()[0] maxValueT = cropModel.get_roi_t()[1] if cropModel.get_scroll_time_outside_crop(): self.timeSpinBox.setValue(self.timeSlider.value()) else: if minValueT > self.timeSlider.value(): self.timeSpinBox.setValue(minValueT) self.timeSlider.setValue(minValueT) elif self.timeSlider.value() > maxValueT: self.timeSpinBox.setValue(maxValueT) self.timeSlider.setValue(maxValueT) elif minValueT <= self.timeSlider.value() and self.timeSlider.value() <= maxValueT: self.timeSpinBox.setValue(self.timeSlider.value()) def _handlePositionBoxValueChanged(self, axis, value): new_position = [self.xSpinBox.value(), self.ySpinBox.value(), self.zSpinBox.value()] changed_axis = ord(axis) - ord('x') new_position[changed_axis] = value self.positionChanged.emit(*new_position) def updateShape5D(self, shape5D): self.timeSpinBox.setMaximum(shape5D[0]-1) self.xSpinBox.setMaximum(shape5D[1]-1) self.ySpinBox.setMaximum(shape5D[2]-1) self.zSpinBox.setMaximum(shape5D[3]-1) def updateShape5Dcropped(self, shape5DcropMin, shape5Dmax): self.timeSpinBox.setMaximum(shape5Dmax[0]-1) self.xSpinBox.setMaximum(shape5Dmax[1]-1) self.ySpinBox.setMaximum(shape5Dmax[2]-1) self.zSpinBox.setMaximum(shape5Dmax[3]-1) self.timeSlider.setMaximum(shape5Dmax[0]-1) self.timeSpinBox.setValue(shape5DcropMin[0]) self.xSpinBox.setValue(shape5DcropMin[1]) self.ySpinBox.setValue(shape5DcropMin[2]) self.zSpinBox.setValue(shape5DcropMin[3]) self.timeSlider.setValue(shape5DcropMin[0]) def setMouseCoords(self, x, y, z): self.xSpinBox.setValueWithoutSignal(x) self.ySpinBox.setValueWithoutSignal(y) self.zSpinBox.setValueWithoutSignal(z)
class QuadStatusBar(QHBoxLayout): positionChanged = pyqtSignal(int, int, int) # x,y,z def __init__(self, parent=None): QHBoxLayout.__init__(self, parent) self.setContentsMargins(0, 4, 0, 0) self.setSpacing(0) self.timeControlFontSize = 12 def showXYCoordinates(self): self.zLabel.setHidden(True) self.zSpinBox.setHidden(True) def showXYZCoordinates(self): self.zLabel.setHidden(False) self.zSpinBox.setHidden(False) def hideTimeSlider(self, flag): visibleBefore = not self.timeSlider.isHidden() self.timeSlider.setHidden(flag) self.timeEndButton.setHidden(flag) self.timeStartButton.setHidden(flag) self.timePreviousButton.setHidden(flag) self.timeNextButton.setHidden(flag) self._registerTimeframeShortcuts(enabled=not flag, remove=visibleBefore) def setToolTipTimeButtonsCrop(self, croppingFlag=False): if croppingFlag == True: self.timeStartButton.setToolTip( "Jump to lirst frame of current crop") self.timeEndButton.setToolTip("Jump to last frame of current crop") self.timePreviousButton.setToolTip("Previous Frame") self.timeNextButton.setToolTip("Next Frame") else: self.timeStartButton.setToolTip("First Frame") self.timeEndButton.setToolTip("Last Frame") self.timePreviousButton.setToolTip("Previous Frame") self.timeNextButton.setToolTip("Next Frame") def setToolTipTimeSliderCrop(self, croppingFlag=False): if croppingFlag == True: self.timeSlider.setToolTip( "Choose the time coordinate of the current crop.") else: self.timeSlider.setToolTip( "Choose the time coordinate of the current dataset.") def createQuadViewStatusBar(self, xbackgroundColor, xforegroundColor, ybackgroundColor, yforegroundColor, zbackgroundColor, zforegroundColor): self.xLabel, self.xSpinBox = _get_pos_widget('X', xbackgroundColor, xforegroundColor) self.yLabel, self.ySpinBox = _get_pos_widget('Y', ybackgroundColor, yforegroundColor) self.zLabel, self.zSpinBox = _get_pos_widget('Z', zbackgroundColor, zforegroundColor) self.xSpinBox.delayedValueChanged.connect( partial(self._handlePositionBoxValueChanged, 'x')) self.ySpinBox.delayedValueChanged.connect( partial(self._handlePositionBoxValueChanged, 'y')) self.zSpinBox.delayedValueChanged.connect( partial(self._handlePositionBoxValueChanged, 'z')) self.addWidget(self.xLabel) self.addWidget(self.xSpinBox) self.addWidget(self.yLabel) self.addWidget(self.ySpinBox) self.addWidget(self.zLabel) self.addWidget(self.zSpinBox) self.addSpacing(10) self.crosshairsCheckbox = QCheckBox() self.crosshairsCheckbox.setChecked(False) self.crosshairsCheckbox.setCheckable(True) self.crosshairsCheckbox.setText("Crosshairs") self.addWidget(self.crosshairsCheckbox) self.addSpacing(10) self.busyIndicator = QProgressBar() self.busyIndicator.setMaximumWidth(200) self.busyIndicator.setMaximum(0) self.busyIndicator.setMinimum(0) self.busyIndicator.setVisible(False) self.busyIndicator.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.addWidget(self.busyIndicator) self.setStretchFactor(self.busyIndicator, 1) self.addStretch() self.addSpacing(20) self.timeSpinBox = DelayedSpinBox(750) icons_dir = os.path.dirname(volumina.__file__) + "/icons" self.timeStartButton = QToolButton() self.timeStartButton.setIcon(QIcon(icons_dir + "/skip-start.png")) self.addWidget(self.timeStartButton) self.timeStartButton.clicked.connect(self._onTimeStartButtonClicked) #self.timeStartButton.setFixedWidth(4*self.timeControlFontSize) self.timePreviousButton = QToolButton() self.timePreviousButton.setIcon(QIcon(icons_dir + "/play-reverse.png")) self.addWidget(self.timePreviousButton) self.timePreviousButton.clicked.connect( self._onTimePreviousButtonClicked) #self.timePreviousButton.setFixedWidth(4*self.timeControlFontSize) self.timeSlider = QSlider(Qt.Horizontal) self.timeSlider.setMinimumWidth(10) self.timeSlider.setMaximumWidth(200) self.setToolTipTimeSliderCrop() self.addWidget(self.timeSlider) self.timeSlider.valueChanged.connect(self._onTimeSliderChanged) self.timeNextButton = QToolButton() self.timeNextButton.setIcon(QIcon(icons_dir + "/play.png")) self.addWidget(self.timeNextButton) self.timeNextButton.clicked.connect(self._onTimeNextButtonClicked) #self.timeNextButton.setFixedWidth(4*self.timeControlFontSize) self.timeEndButton = QToolButton() self.timeEndButton.setIcon(QIcon(icons_dir + "/skip-end.png")) #self.timeEndButton.setFixedWidth(4*self.timeControlFontSize) self.setToolTipTimeButtonsCrop() self.addWidget(self.timeEndButton) self.timeEndButton.clicked.connect(self._onTimeEndButtonClicked) self.timeLabel = QLabel(" Time:") self.addWidget(self.timeLabel) timeControlFont = self.timeSpinBox.font() if self.timeControlFontSize > timeControlFont.pointSize(): timeControlFont.setPixelSize(2 * self.timeControlFontSize) self.timeStartButton.setFont(timeControlFont) self.timeEndButton.setFont(timeControlFont) self.timeLabel.setFont(timeControlFont) self.timeSpinBox.setFont(timeControlFont) self.addWidget(self.timeSpinBox) self.timeSpinBox.delayedValueChanged.connect( self._onTimeSpinBoxChanged) self._registerTimeframeShortcuts() def _registerTimeframeShortcuts(self, enabled=True, remove=True): """ Register or deregister "," and "." as keyboard shortcuts for scrolling in time """ mgr = ShortcutManager() ActionInfo = ShortcutManager.ActionInfo def action(key, actionInfo): if enabled: mgr.register(key, actionInfo) else: if remove: mgr.unregister(actionInfo) action( "<", ActionInfo("Navigation", "Go to next time frame", "Go to next time frame", self._onTimeNextButtonClicked, self.timeNextButton, self.timeNextButton)) action( ">", ActionInfo("Navigation", "Go to previous time frame", "Go to previous time frame", self._onTimePreviousButtonClicked, self.timePreviousButton, self.timePreviousButton)) def _onTimeStartButtonClicked(self): self.timeSpinBox.setValue( self.parent().parent().parent().editor.cropModel.get_roi_t()[0]) def _onTimeEndButtonClicked(self): self.timeSpinBox.setValue( self.parent().parent().parent().editor.cropModel.get_roi_t()[1]) def _onTimePreviousButtonClicked(self): self.timeSpinBox.setValue(self.timeSpinBox.value() - 1) def _onTimeNextButtonClicked(self): self.timeSpinBox.setValue(self.timeSpinBox.value() + 1) def _onTimeSpinBoxChanged(self): editor = self.parent().parent().parent().editor cropModel = editor.cropModel minValueT = cropModel.get_roi_t()[0] maxValueT = cropModel.get_roi_t()[1] if cropModel.get_scroll_time_outside_crop(): if minValueT > self.timeSpinBox.value( ) or maxValueT < self.timeSpinBox.value(): for imgView in editor.imageViews: imgView._croppingMarkers._shading_item.set_paint_full_frame( True) else: for imgView in editor.imageViews: imgView._croppingMarkers._shading_item.set_paint_full_frame( False) self.timeSlider.setValue(self.timeSpinBox.value()) else: for imgView in editor.imageViews: imgView._croppingMarkers._shading_item.set_paint_full_frame( False) if minValueT > self.timeSpinBox.value(): self.timeSlider.setValue(minValueT) elif maxValueT < self.timeSpinBox.value(): self.timeSlider.setValue(maxValueT) elif minValueT <= self.timeSpinBox.value( ) and self.timeSpinBox.value() <= maxValueT: self.timeSlider.setValue(self.timeSpinBox.value()) def _onTimeSliderChanged(self): cropModel = self.parent().parent().parent().editor.cropModel minValueT = cropModel.get_roi_t()[0] maxValueT = cropModel.get_roi_t()[1] if cropModel.get_scroll_time_outside_crop(): self.timeSpinBox.setValue(self.timeSlider.value()) else: if minValueT > self.timeSlider.value(): self.timeSpinBox.setValue(minValueT) self.timeSlider.setValue(minValueT) elif self.timeSlider.value() > maxValueT: self.timeSpinBox.setValue(maxValueT) self.timeSlider.setValue(maxValueT) elif minValueT <= self.timeSlider.value( ) and self.timeSlider.value() <= maxValueT: self.timeSpinBox.setValue(self.timeSlider.value()) def _handlePositionBoxValueChanged(self, axis, value): new_position = [ self.xSpinBox.value(), self.ySpinBox.value(), self.zSpinBox.value() ] changed_axis = ord(axis) - ord('x') new_position[changed_axis] = value self.positionChanged.emit(*new_position) def updateShape5D(self, shape5D): self.timeSpinBox.setMaximum(shape5D[0] - 1) self.xSpinBox.setMaximum(shape5D[1] - 1) self.ySpinBox.setMaximum(shape5D[2] - 1) self.zSpinBox.setMaximum(shape5D[3] - 1) def updateShape5Dcropped(self, shape5DcropMin, shape5Dmax): self.timeSpinBox.setMaximum(shape5Dmax[0] - 1) self.xSpinBox.setMaximum(shape5Dmax[1] - 1) self.ySpinBox.setMaximum(shape5Dmax[2] - 1) self.zSpinBox.setMaximum(shape5Dmax[3] - 1) self.timeSlider.setMaximum(shape5Dmax[0] - 1) self.timeSpinBox.setValue(shape5DcropMin[0]) self.xSpinBox.setValue(shape5DcropMin[1]) self.ySpinBox.setValue(shape5DcropMin[2]) self.zSpinBox.setValue(shape5DcropMin[3]) self.timeSlider.setValue(shape5DcropMin[0]) def setMouseCoords(self, x, y, z): self.xSpinBox.setValueWithoutSignal(x) self.ySpinBox.setValueWithoutSignal(y) self.zSpinBox.setValueWithoutSignal(z)