def reset_view_cb(self, command):
     if command is None:
         command_name = None
         reset_all = True
     else:
         command_name = command.get_name()
         reset_all = (command_name is None) or ('View' in command_name)
     if reset_all or ('Rotation' in command_name):
         self.tdw.set_rotation(0.0)
     if reset_all or ('Zoom' in command_name):
         default_zoom = self.app.preferences['view.default_zoom']
         self.tdw.set_zoom(default_zoom)
     if reset_all or ('Mirror' in command_name):
         self.tdw.set_mirrored(False)
     if reset_all:
         self.tdw.recenter_document()
     elif 'Fit' in command_name:
         # View>Fit: fits image within window's borders.
         junk, junk, w, h = self.tdw.doc.get_effective_bbox()
         if w == 0:
             # When there is nothing on the canvas reset zoom to default.
             self.reset_view_cb(None)
         else:
             allocation = self.tdw.get_allocation()
             w1, h1 = allocation.width, allocation.height
             # Store radians and reset rotation to zero.
             radians = self.tdw.rotation
             self.tdw.set_rotation(0.0)
             # Store mirror and temporarily it turn off mirror.
             mirror = self.tdw.mirrored
             self.tdw.set_mirrored(False)
             # Using w h as the unrotated bbox, calculate the bbox of the
             # rotated doc.
             cos = math.cos(radians)
             sin = math.sin(radians)
             wcos = w * cos
             hsin = h * sin
             wsin = w * sin
             hcos = h * cos
             # We only need to calculate the positions of two corners of the
             # bbox since it is centered and symetrical, but take the max
             # value since during rotation one corner's distance along the
             # x axis shortens while the other lengthens. Same for the y axis.
             x = max(abs(wcos - hsin), abs(wcos + hsin))
             y = max(abs(wsin + hcos), abs(wsin - hcos))
             # Compare the doc and window dimensions and take the best fit
             zoom = min((w1-20)/x, (h1-20)/y)
             # Reapply all transformations
             self.tdw.recenter_document() # Center image
             self.tdw.set_rotation(radians) # reapply canvas rotation
             self.tdw.set_mirrored(mirror) #reapply mirror
             self.tdw.set_zoom(zoom, at_pointer=False) # Set new zoom level
Пример #2
0
 def reset_view_cb(self, command):
     if command is None:
         command_name = None
         reset_all = True
     else:
         command_name = command.get_name()
         reset_all = (command_name is None) or ("View" in command_name)
     if reset_all or ("Rotation" in command_name):
         self.tdw.set_rotation(0.0)
     if reset_all or ("Zoom" in command_name):
         default_zoom = self.app.preferences["view.default_zoom"]
         self.zoomlevel = self.zoomlevel_values.index(default_zoom)
         self.tdw.set_zoom(default_zoom)
     if reset_all or ("Mirror" in command_name):
         self.tdw.set_mirrored(False)
     if reset_all:
         self.tdw.recenter_document()
Пример #3
0
    def reset_view_cb(self, command):
        """Action callback: resets various aspects of the view.

        The reset chosen depends on the action's name.

        """
        if command is None:
            command_name = None
        else:
            command_name = command.get_name()
        zoom = mirror = rotation = False
        if command_name is None or 'View' in command_name:
            zoom = mirror = rotation = True
        elif 'Rotation' in command_name:
            rotation = True
        elif 'Zoom' in command_name:
            zoom = True
        elif 'Mirror' in command_name:
            mirror = True
        if rotation or zoom or mirror:
            self.reset_view(rotation, zoom, mirror)
            self.clear_saved_view()