Пример #1
0
    def _zoom_fit(self):
        data_info = self._controller.get_data()
        config = self._controller.get_config()

        def add_padding(bounding_box, max_x, max_y):
            bounding_box[0].x = max(bounding_box[0].x - 1, 0)
            bounding_box[0].y = max(bounding_box[0].y - 1, 0)

            bounding_box[1].y = min(bounding_box[1].y + 2, max_y)
            bounding_box[1].x = min(bounding_box[1].x + 2, max_x)

            return bounding_box

        if config.maps_to_show or len(data_info.maps):
            bounding_box = data_info.get_bounding_box(config.dimension, config.slice_index,
                                                      config.volume_index, config.rotate, config.maps_to_show)

            max_y = data_info.get_max_y_index(config.dimension, rotate=config.rotate, map_names=config.maps_to_show)
            max_x = data_info.get_max_x_index(config.dimension, rotate=config.rotate, map_names=config.maps_to_show)

            if not config.flipud:
                # Since the renderer plots with a left top coordinate system,
                # we need to flip the y coordinates upside down by default.
                tmp = max_y - bounding_box[0].y
                bounding_box[0].y = max_y - bounding_box[1].y
                bounding_box[1].y = tmp

            bounding_box = add_padding(bounding_box, max_x, max_y)

            self._controller.apply_action(SetZoom(Zoom(*bounding_box)))
Пример #2
0
    def _update_zoom(self):
        np0x, np0y = self.general_zoom_x_0.value(), self.general_zoom_y_0.value()
        np1x, np1y = self.general_zoom_x_1.value(), self.general_zoom_y_1.value()

        if np0x > np1x:
            np1x = np0x
        if np0y > np1y:
            np1y = np0y

        self._controller.apply_action(SetZoom(Zoom.from_coords(np0x, np0y, np1x, np1y)))
Пример #3
0
    def _perform_drag(self):
        current_model = self.controller.get_model()

        delta_x = int(np.round(self._start_x) - np.round(self._end_x))
        delta_y = int(np.round(self._start_y) - np.round(self._end_y))

        config = current_model.get_config()
        data_info = current_model.get_data()

        current_zoom = current_model.get_config().zoom

        max_y = data_info.get_max_y_index(config.dimension,
                                          rotate=config.rotate,
                                          map_names=config.maps_to_show)
        max_x = data_info.get_max_x_index(config.dimension,
                                          rotate=config.rotate,
                                          map_names=config.maps_to_show)

        new_x0 = current_zoom.p0.x + delta_x
        new_x1 = (current_zoom.p1.x or max_x) + delta_x
        new_y0 = current_zoom.p0.y + delta_y
        new_y1 = (current_zoom.p1.y or max_y) + delta_y

        if new_x0 < 0:
            new_x1 -= new_x0
            new_x0 = 0

        if new_x1 > max_x:
            new_x0 -= new_x1
            new_x1 = max_x

        if new_y0 < 0:
            new_y1 -= new_y0
            new_y0 = 0

        if new_y1 > max_y:
            new_y0 -= new_y1
            new_y1 = max_y

        try:
            new_zoom = Zoom.from_coords(new_x0, new_y0, new_x1, new_y1)
        except ValueError:
            new_zoom = current_zoom

        self.controller.apply_action(SetZoom(new_zoom))
        self._start_x = self._end_x
        self._start_y = self._end_y
Пример #4
0
    def _perform_scroll(self):
        current_model = self.controller.get_model()
        config = current_model.get_config()
        data_info = current_model.get_data()

        current_zoom = config.zoom

        max_y = data_info.get_max_y_index(config.dimension,
                                          rotate=config.rotate,
                                          map_names=config.maps_to_show)
        max_x = data_info.get_max_x_index(config.dimension,
                                          rotate=config.rotate,
                                          map_names=config.maps_to_show)

        scrolling = self._scrolls
        if abs(self._scrolls) > 1:
            scrolling *= 3

        new_x0 = current_zoom.p0.x + scrolling
        if new_x0 < 0:
            new_x0 = 0

        new_y0 = current_zoom.p0.y + scrolling
        if new_y0 < 0:
            new_y0 = 0

        new_x1 = (current_zoom.p1.x or max_x) - scrolling
        if new_x1 > max_x:
            new_x1 = max_x

        new_y1 = (current_zoom.p1.y or max_y) - scrolling
        if new_y1 > max_y:
            new_y1 = max_y

        try:
            new_zoom = Zoom.from_coords(new_x0, new_y0, new_x1, new_y1)
        except ValueError:
            new_zoom = current_zoom

        self.controller.apply_action(SetZoom(new_zoom))
        self._scrolls = 0
Пример #5
0
    def __init__(self, controller, parent=None):
        super(TabGeneral, self).__init__(parent)
        self.setupUi(self)

        self._controller = controller
        self._controller.new_data.connect(self.set_new_data)
        self._controller.new_config.connect(self.set_new_config)

        self.general_display_order.setDragDropMode(QAbstractItemView.InternalMove)
        self.general_display_order.setSelectionMode(QAbstractItemView.SingleSelection)

        self.general_colormap.addItems(self._controller.get_config().get_available_colormaps())
        self.general_rotate.addItems(['0', '90', '180', '270'])
        self.general_rotate.setCurrentText(str(self._controller.get_config().rotate))

        self.general_DisplayOrder.set_collapse(True)
        self.general_Miscellaneous.set_collapse(True)
        self.general_Zoom.set_collapse(True)
        self.general_Font.set_collapse(True)

        self.general_dimension.valueChanged.connect(lambda v: self._controller.apply_action(SetDimension(v)))
        self.general_slice_index.valueChanged.connect(lambda v: self._controller.apply_action(SetSliceIndex(v)))
        self.general_volume_index.valueChanged.connect(lambda v: self._controller.apply_action(SetVolumeIndex(v)))
        self.general_colormap.currentIndexChanged.connect(
            lambda i: self._controller.apply_action(SetColormap(self.general_colormap.itemText(i))))
        self.general_rotate.currentIndexChanged.connect(
            lambda i: self._controller.apply_action(SetRotate(int(self.general_rotate.itemText(i)))))

        self._map_selection_timer = TimedUpdate(self._update_maps_to_show)
        self.general_map_selection.itemSelectionChanged.connect(
            lambda: self._map_selection_timer.add_delayed_callback(500))

        self.general_deselect_all_maps.clicked.connect(self._deleselect_all_maps)
        self.general_invert_map_selection.clicked.connect(self._invert_map_selection)

        self.general_zoom_x_0.valueChanged.connect(self._update_zoom)
        self.general_zoom_x_1.valueChanged.connect(self._update_zoom)
        self.general_zoom_y_0.valueChanged.connect(self._update_zoom)
        self.general_zoom_y_1.valueChanged.connect(self._update_zoom)

        self.plot_title.textEdited.connect(lambda txt: self._controller.apply_action(SetPlotTitle(txt)))

        self.general_zoom_reset.clicked.connect(lambda: self._controller.apply_action(SetZoom(Zoom.no_zoom())))
        self.general_zoom_fit.clicked.connect(self._zoom_fit)

        self.general_display_order.items_reordered.connect(self._reorder_maps)
        self.general_show_axis.clicked.connect(lambda: self._controller.apply_action(
            SetShowAxis(self.general_show_axis.isChecked())))
        self.general_colorbar_nmr_ticks.valueChanged.connect(
            lambda v: self._controller.apply_action(SetColorBarNmrTicks(v)))

        self.general_font_family.addItems(Font.font_names())
        self.general_font_family.currentTextChanged.connect(
            lambda v: self._controller.apply_action(SetFont(self._controller.get_config().font.get_updated(family=v))))

        self.general_font_size.valueChanged.connect(
            lambda: self._controller.apply_action(
                SetFont(self._controller.get_config().font.get_updated(size=self.general_font_size.value()))))

        self.general_interpolation.addItems(self._controller.get_config().get_available_interpolations())
        self.general_interpolation.currentTextChanged.connect(
            lambda v: self._controller.apply_action(SetInterpolation(v)))

        self.general_flipud.clicked.connect(lambda: self._controller.apply_action(
            SetFlipud(self.general_flipud.isChecked())))

        self.mask_name.currentIndexChanged.connect(self._update_mask_name)