Пример #1
0
 def zoom(self, factor, center=None):
     # Init some variables
     center = center if (center is not None) else self.center
     assert len(center) in (2, 3, 4)
     # Get scale factor, take scale ratio into account
     if np.isscalar(factor):
         scale = [factor, factor]
     else:
         if len(factor) != 2:
             raise TypeError("factor must be scalar or length-2 sequence.")
         scale = list(factor)
     if self.aspect is not None:
         scale[0] = scale[1]
     # Make a new object (copy), so that allocation will
     # trigger view_changed:
     rect = Rect(self.rect)
     # Get space from given center to edges
     left_space = center[0] - rect.left
     right_space = rect.right - center[0]
     bottom_space = center[1] - rect.bottom
     top_space = rect.top - center[1]
     # Scale these spaces
     rect.left = center[0] - left_space * scale[0]
     rect.right = center[0] + right_space * scale[0]
     rect.bottom = center[1] - bottom_space * scale[1]
     rect.top = center[1] + top_space * scale[1]
     self.rect = rect
     self.currect_scale *= factor
     for text, font_size in zip(self.texts,self.font_sizes):
         text.font_size = font_size / self.currect_scale
 def set_state(self, state=None, **kwargs):
     D = state or {}
     if 'rect' not in D:
         return
     for cam in self._linked_cameras:
         r = Rect(D['rect'])
         if cam is self._linked_cameras_no_update:
             continue
         try:
             cam._linked_cameras_no_update = self
             cam_rect = cam.get_state()['rect']
             r.top = cam_rect.top
             r.bottom = cam_rect.bottom
             cam.set_state({'rect':r})
         finally:
             cam._linked_cameras_no_update = None
Пример #3
0
 def set_state(self, state=None, **kwargs):
     D = state or {}
     if 'rect' not in D:
         return
     for cam in self._linked_cameras:
         r = Rect(D['rect'])
         if cam is self._linked_cameras_no_update:
             continue
         try:
             cam._linked_cameras_no_update = self
             cam_rect = cam.get_state()['rect']
             r.top = cam_rect.top
             r.bottom = cam_rect.bottom
             cam.set_state({'rect': r})
         finally:
             cam._linked_cameras_no_update = None
Пример #4
0
    def zoom(self, factor, center=None):
        """ Zoom in (or out) at the given center

        Parameters
        ----------
        factor : float or tuple
            Fraction by which the scene should be zoomed (e.g. a factor of 2
            causes the scene to appear twice as large).
        center : tuple of 2-4 elements
            The center of the view. If not given or None, use the
            current center.
        """
        assert len(center) in (2, 3, 4)
        # Get scale factor, take scale ratio into account
        if np.isscalar(factor):
            scale = [factor, factor]
        else:
            if len(factor) != 2:
                raise TypeError("factor must be scalar or length-2 sequence.")
            scale = list(factor)
        if self.aspect is not None:
            scale[0] = scale[1]

        # Init some variables
        center = center if (center is not None) else self.center
        # Make a new object (copy), so that allocation will
        # trigger view_changed:
        rect = Rect(self.rect)
        # Get space from given center to edges
        left_space = center[0] - rect.left
        right_space = rect.right - center[0]
        bottom_space = center[1] - rect.bottom
        top_space = rect.top - center[1]
        # Scale these spaces
        rect.left = center[0] - left_space * scale[0]
        rect.right = center[0] + right_space * scale[0]
        rect.bottom = center[1] - bottom_space * scale[1]
        rect.top = center[1] + top_space * scale[1]

        self.limit_zoom(rect)

        self.rect = rect
Пример #5
0
    def zoom(self, factor, center=None):
        """ Zoom in (or out) at the given center
        Parameters
        ----------
        factor : float or tuple
            Fraction by which the scene should be zoomed (e.g. a factor of 2
            causes the scene to appear twice as large).
        center : tuple of 2-4 elements
            The center of the view. If not given or None, use the
            current center.
        """
        if self._zoomed:
            return
        assert len(center) in (2, 3, 4)
        # Get scale factor, take scale ratio into account
        if np.isscalar(factor):
            scale = [factor, factor]
        else:
            if len(factor) != 2:
                raise TypeError("factor must be scalar or length-2 sequence.")
            scale = list(factor)
        if self.aspect is not None:
            scale[0] = scale[1]

        # Init some variables
        center = center if (center is not None) else self.center
        # Make a new object (copy), so that allocation will
        # trigger view_changed:
        rect = Rect(self.rect)
        if rect.right - rect.left < 0.1 and scale[0] < 1:
            return
        # Get space from given center to edges
        left_space = center[0] - rect.left
        right_space = rect.right - center[0]
        bottom_space = center[1] - rect.bottom
        top_space = rect.top - center[1]
        # Scale these spaces
        if self._zoom_axis == 'both' or self._zoom_axis == 'x':
            rect.left = center[0] - left_space * scale[0]
            rect.right = center[0] + right_space * scale[0]
        if self._zoom_axis == 'both' or self._zoom_axis == 'y':
            rect.bottom = center[1] - bottom_space * scale[1]
            rect.top = center[1] + top_space * scale[1]
        if self._ybounds is not None:
            if rect.bottom < self._ybounds[0]:
                rect.bottom = self._ybounds[0]
            if rect.top > self._ybounds[1]:
                rect.top = self._ybounds[1]
        if self._xbounds is not None:
            if rect.left < self._xbounds[0]:
                rect.left = self._xbounds[0]
            if rect.right > self._xbounds[1]:
                rect.right = self._xbounds[1]

        self.rect = rect
        self._zoomed = True
        for c in self._linked_panzoom:
            if c._zoomed:
                continue
            new_center = []
            new_center.append(rescale(center[0], self._xbounds[1], c._xbounds[1]))
            new_center.append(rescale(center[1], self._ybounds[1], c._ybounds[1]))
            new_center.extend([0,1])
            c.zoom(factor, np.array(new_center))
        self._zoomed = False
Пример #6
0
    def zoom(self, factor, center=None):
        """ Zoom in (or out) at the given center
        Parameters
        ----------
        factor : float or tuple
            Fraction by which the scene should be zoomed (e.g. a factor of 2
            causes the scene to appear twice as large).
        center : tuple of 2-4 elements
            The center of the view. If not given or None, use the
            current center.
        """
        if self.zoom is None:
            return
        if self._zoomed:
            return
        assert len(center) in (2, 3, 4)
        # Get scale factor, take scale ratio into account
        if np.isscalar(factor):
            scale = [factor, factor]
        else:
            if len(factor) != 2:
                raise TypeError("factor must be scalar or length-2 sequence.")
            scale = list(factor)
        if self.aspect is not None:
            scale[0] = scale[1]

        # Init some variables
        center = center if (center is not None) else self.center
        # Make a new object (copy), so that allocation will
        # trigger view_changed:
        rect = Rect(self.rect)
        if rect.right - rect.left < 0.1 and scale[0] < 1:
            return
        # Get space from given center to edges
        left_space = center[0] - rect.left
        right_space = rect.right - center[0]
        bottom_space = center[1] - rect.bottom
        top_space = rect.top - center[1]
        # Scale these spaces
        if self._zoom_axis == 'both' or self._zoom_axis == 'x':
            rect.left = center[0] - left_space * scale[0]
            rect.right = center[0] + right_space * scale[0]
        if self._zoom_axis == 'both' or self._zoom_axis == 'y':
            rect.bottom = center[1] - bottom_space * scale[1]
            rect.top = center[1] + top_space * scale[1]
        if self._ybounds is not None:
            if rect.bottom < self._ybounds[0]:
                rect.bottom = self._ybounds[0]
            if rect.top > self._ybounds[1]:
                rect.top = self._ybounds[1]
        if self._xbounds is not None:
            if rect.left < self._xbounds[0]:
                rect.left = self._xbounds[0]
            if rect.right > self._xbounds[1]:
                rect.right = self._xbounds[1]

        self.rect = rect
        self._zoomed = True
        for c in self._linked_panzoom:
            if c._zoomed:
                continue
            new_center = []
            new_center.append(
                rescale(center[0], self._xbounds[1], c._xbounds[1]))
            new_center.append(
                rescale(center[1], self._ybounds[1], c._ybounds[1]))
            new_center.extend([0, 1])
            c.zoom(factor, np.array(new_center))
        self._zoomed = False