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)))
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
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