Exemplo n.º 1
0
    def __init__(self, label='', world=None, lo=0, hi=10,
                 parent=None, world_unit=None,
                 world_warning=False):

        super(SliceWidget, self).__init__(parent)

        self.state = SliceState()
        self.state.label = label
        self.state.slice_center = (lo + hi) // 2

        self._world = np.asarray(world)
        self._world_warning = world_warning
        self._world_unit = world_unit

        self.ui = load_ui('data_slice_widget.ui', self,
                          directory=os.path.dirname(__file__))

        autoconnect_callbacks_to_qt(self.state, self.ui)

        font = self.text_warning.font()
        font.setPointSize(font.pointSize() * 0.75)
        self.text_warning.setFont(font)

        self.button_first.setStyleSheet('border: 0px')
        self.button_first.setIcon(get_icon('playback_first'))
        self.button_prev.setStyleSheet('border: 0px')
        self.button_prev.setIcon(get_icon('playback_prev'))
        self.button_back.setStyleSheet('border: 0px')
        self.button_back.setIcon(get_icon('playback_back'))
        self.button_stop.setStyleSheet('border: 0px')
        self.button_stop.setIcon(get_icon('playback_stop'))
        self.button_forw.setStyleSheet('border: 0px')
        self.button_forw.setIcon(get_icon('playback_forw'))
        self.button_next.setStyleSheet('border: 0px')
        self.button_next.setIcon(get_icon('playback_next'))
        self.button_last.setStyleSheet('border: 0px')
        self.button_last.setIcon(get_icon('playback_last'))

        self.value_slice_center.setMinimum(lo)
        self.value_slice_center.setMaximum(hi)
        self.value_slice_center.valueChanged.connect(nonpartial(self.set_label_from_slider))

        # Figure out the optimal format to use to show the world values. We do
        # this by figuring out the precision needed so that when converted to
        # a string, every string value is different.

        if world is not None and len(world) > 1:
            self.label_fmt = format_minimal(world)[0]
        else:
            self.label_fmt = "{:g}"

        self.text_slider_label.setMinimumWidth(80)
        self.state.slider_label = self.label_fmt.format(self.value_slice_center.value())
        self.text_slider_label.editingFinished.connect(nonpartial(self.set_slider_from_label))

        self._play_timer = QtCore.QTimer()
        self._play_timer.setInterval(500)
        self._play_timer.timeout.connect(nonpartial(self._play_slice))

        self.button_first.clicked.connect(nonpartial(self._browse_slice, 'first'))
        self.button_prev.clicked.connect(nonpartial(self._browse_slice, 'prev'))
        self.button_back.clicked.connect(nonpartial(self._adjust_play, 'back'))
        self.button_stop.clicked.connect(nonpartial(self._adjust_play, 'stop'))
        self.button_forw.clicked.connect(nonpartial(self._adjust_play, 'forw'))
        self.button_next.clicked.connect(nonpartial(self._browse_slice, 'next'))
        self.button_last.clicked.connect(nonpartial(self._browse_slice, 'last'))

        self.bool_use_world.toggled.connect(nonpartial(self.set_label_from_slider))

        if world is None:
            self.state.use_world = False
            self.bool_use_world.hide()
        else:
            self.state.use_world = not world_warning

        if world_unit:
            self.state.slider_unit = world_unit
        else:
            self.state.slider_unit = ''

        self._play_speed = 0

        self.set_label_from_slider()
Exemplo n.º 2
0
    def __init__(self,
                 label='',
                 world=None,
                 lo=0,
                 hi=10,
                 parent=None,
                 world_unit=None,
                 world_warning=False):

        super(SliceWidget, self).__init__(parent)

        self.state = SliceState()
        self.state.label = label
        self.state.slice_center = (lo + hi) // 2

        self._world = np.asarray(world)
        self._world_warning = world_warning
        self._world_unit = world_unit

        self.ui = load_ui('data_slice_widget.ui',
                          self,
                          directory=os.path.dirname(__file__))

        self._connections = autoconnect_callbacks_to_qt(self.state, self.ui)

        font = self.text_warning.font()
        font.setPointSize(font.pointSize() * 0.75)
        self.text_warning.setFont(font)

        self.button_first.setStyleSheet('border: 0px')
        self.button_first.setIcon(get_icon('playback_first'))
        self.button_prev.setStyleSheet('border: 0px')
        self.button_prev.setIcon(get_icon('playback_prev'))
        self.button_back.setStyleSheet('border: 0px')
        self.button_back.setIcon(get_icon('playback_back'))
        self.button_stop.setStyleSheet('border: 0px')
        self.button_stop.setIcon(get_icon('playback_stop'))
        self.button_forw.setStyleSheet('border: 0px')
        self.button_forw.setIcon(get_icon('playback_forw'))
        self.button_next.setStyleSheet('border: 0px')
        self.button_next.setIcon(get_icon('playback_next'))
        self.button_last.setStyleSheet('border: 0px')
        self.button_last.setIcon(get_icon('playback_last'))

        self.value_slice_center.setMinimum(lo)
        self.value_slice_center.setMaximum(hi)
        self.value_slice_center.valueChanged.connect(
            nonpartial(self.set_label_from_slider))

        # Figure out the optimal format to use to show the world values. We do
        # this by figuring out the precision needed so that when converted to
        # a string, every string value is different.

        if world is not None and len(world) > 1:
            self.label_fmt = format_minimal(world)[0]
        else:
            self.label_fmt = "{:g}"

        self.text_slider_label.setMinimumWidth(80)
        self.state.slider_label = self.label_fmt.format(
            self.value_slice_center.value())
        self.text_slider_label.editingFinished.connect(
            nonpartial(self.set_slider_from_label))

        self._play_timer = QtCore.QTimer()
        self._play_timer.setInterval(500)
        self._play_timer.timeout.connect(nonpartial(self._play_slice))

        self.button_first.clicked.connect(
            nonpartial(self._browse_slice, 'first'))
        self.button_prev.clicked.connect(nonpartial(self._browse_slice,
                                                    'prev'))
        self.button_back.clicked.connect(nonpartial(self._adjust_play, 'back'))
        self.button_stop.clicked.connect(nonpartial(self._adjust_play, 'stop'))
        self.button_forw.clicked.connect(nonpartial(self._adjust_play, 'forw'))
        self.button_next.clicked.connect(nonpartial(self._browse_slice,
                                                    'next'))
        self.button_last.clicked.connect(nonpartial(self._browse_slice,
                                                    'last'))

        self.bool_use_world.toggled.connect(
            nonpartial(self.set_label_from_slider))

        if world is None:
            self.state.use_world = False
            self.bool_use_world.hide()
        else:
            self.state.use_world = not world_warning

        if world_unit:
            self.state.slider_unit = world_unit
        else:
            self.state.slider_unit = ''

        self._play_speed = 0

        self.set_label_from_slider()