Exemple #1
0
    def stop_recording(self, revert=False):
        """Ends the recording phase

        :param bool revert: revert any changes to the model
        :rtype: bool
        :returns: whether any changes were made

        When called with default arguments,
        this method makes the command ready to add to the command stack
        using the document model's do() method.
        If no changes were made, you can (and should)
        just discard the command instead.

        If `revert` is true,
        all changes made to the layer during recording
        will be rolled back,
        so that the layer has its original appearance and state.
        Reverted commands should be discarded.

        After this method is called,
        the `stroke_to()` method must not be called again.

        """
        self._check_recording_started()
        layer = self._stroke_target_layer
        self._stroke_target_layer = None  # prevent potential leak
        self._recording_finished = True
        if self._stroke_seq is None:
            # Unclear circumstances, but I've seen it happen
            # (unpaintable layers and visibility state toggling).
            # Perhaps _recording_started should be made synonymous with this?
            logger.warning(
                "No recorded stroke, but recording was started? "
                "Please report this glitch if you can reliably reproduce it."
            )
            return False  # nothing recorded, so nothing changed
        self._stroke_seq.stop_recording()
        if layer is None:
            return False  # wasn't suitable for painting, thus nothing changed
        if revert:
            assert self._sshot_before is not None
            logger.debug(
                "Brushwork: stop_recording: rollback %0.3fs",
                self._stroke_seq.total_painting_time,
            )
            layer.load_snapshot(self._sshot_before)
            return False  # nothing changed
        t0 = self._time_before
        self._time_after = t0 + self._stroke_seq.total_painting_time
        layer.add_stroke_shape(self._stroke_seq, self._sshot_before)
        self._sshot_after = layer.save_snapshot()
        self._sshot_after_applied = True  # changes happened before redo()
        tiles_changed = (not self._stroke_seq.empty)
        logger.debug(
            "Brushwork: stop_recording: %0.3fs, tiles_changed=%r",
            self._stroke_seq.total_painting_time,
            tiles_changed,
        )
        return tiles_changed
Exemple #2
0
 def undo(self):
     """Undoes the effects of redo()"""
     model = self.doc
     layer = model.layer_stack.deepget(self._layer_path)
     assert self._recording_finished, "Call stop_recording() first"
     layer.load_snapshot(self._sshot_before)
     model.unsaved_painting_time = self._time_before
     self._sshot_after_applied = False
Exemple #3
0
 def undo(self):
     """Undoes the effects of redo()"""
     model = self.doc
     layer = model.layer_stack.deepget(self._layer_path)
     assert self._recording_finished, "Call stop_recording() first"
     layer.load_snapshot(self._sshot_before)
     model.unsaved_painting_time = self._time_before
     self._sshot_after_applied = False
Exemple #4
0
 def update(self, brushinfo):
     """Retrace the last stroke with a new brush"""
     layer = self.doc.layer_stack.deepget(self._layer_path)
     layer.load_snapshot(self._sshot_before)
     stroke = self._stroke_seq.copy_using_different_brush(brushinfo)
     layer.render_stroke(stroke)
     self._stroke_seq = stroke
     layer.add_stroke_shape(stroke, self._sshot_before)
     self._sshot_after = layer.save_snapshot()
Exemple #5
0
 def redo(self):
     layer = self.doc.layer_stack.deepget(self._layer_path)
     if not self._before:
         self._before = layer.save_snapshot()
     if self._after:
         layer.load_snapshot(self._after)
     else:
         layer.load_from_external_edit_tempfile(self._tmpfile)
         self._after = layer.save_snapshot()
Exemple #6
0
 def redo(self):
     layer = self.doc.layer_stack.deepget(self._layer_path)
     if not self._before:
         self._before = layer.save_snapshot()
     if self._after:
         layer.load_snapshot(self._after)
     else:
         layer.load_from_external_edit_tempfile(self._tmpfile)
         self._after = layer.save_snapshot()
Exemple #7
0
    def stop_recording(self, revert=False):
        """Ends the recording phase

        :param bool revert: revert any changes to the model
        :rtype: bool
        :returns: whether any changes were made

        When called with default arguments,
        this method makes the command ready to add to the command stack
        using the document model's do() method.
        If no changes were made, you can (and should)
        just discard the command instead.

        If `revert` is true,
        all changes made to the layer during recording
        will be rolled back,
        so that the layer has its original appearance and state.
        Reverted commands should be discarded.

        After this method is called,
        the `stroke_to()` method must not be called again.

        """
        self._check_recording_started()
        layer = self._stroke_target_layer
        self._stroke_target_layer = None  # prevent potential leak
        self._recording_finished = True
        if self._stroke_seq is None:
            # Unclear circumstances, but I've seen it happen
            # (unpaintable layers and visibility state toggling).
            # Perhaps _recording_started should be made synonymous with this?
            logger.warning(
                "No recorded stroke, but recording was started? "
                "Please report this glitch if you can reliably reproduce it."
            )
            return False  # nothing recorded, so nothing changed
        self._stroke_seq.stop_recording()
        if layer is None:
            return False  # wasn't suitable for painting, thus nothing changed
        if revert:
            assert self._sshot_before is not None
            layer.load_snapshot(self._sshot_before)
            logger.debug("Reverted %r: tiles_changed=%r", self, False)
            return False  # nothing changed
        t0 = self._time_before
        self._time_after = t0 + self._stroke_seq.total_painting_time
        layer.add_stroke_shape(self._stroke_seq, self._sshot_before)
        self._sshot_after = layer.save_snapshot()
        self._sshot_after_applied = True  # changes happened before redo()
        tiles_changed = (not self._stroke_seq.empty)
        logger.debug(
            "Stopped recording %r: tiles_changed=%r",
            self, tiles_changed,
        )
        return tiles_changed
Exemple #8
0
 def update(self, brushinfo):
     """Retrace the last stroke with a new brush"""
     model = self.doc
     layer = model.layer_stack.deepget(self._layer_path)
     assert self._recording_finished, "Call stop_recording() first"
     assert self._sshot_after_applied, "command.Brushwork must be applied before being updated"
     layer.load_snapshot(self._sshot_before)
     stroke = self._stroke_seq.copy_using_different_brush(brushinfo)
     layer.render_stroke(stroke)
     self._stroke_seq = stroke
     layer.add_stroke_shape(stroke, self._sshot_before)
     self._sshot_after = layer.save_snapshot()
Exemple #9
0
 def update(self, brushinfo):
     """Retrace the last stroke with a new brush"""
     model = self.doc
     layer = model.layer_stack.deepget(self._layer_path)
     assert self._recording_finished, "Call stop_recording() first"
     assert self._sshot_after_applied, \
         "command.Brushwork must be applied before being updated"
     layer.load_snapshot(self._sshot_before)
     stroke = self._stroke_seq.copy_using_different_brush(brushinfo)
     layer.render_stroke(stroke)
     self._stroke_seq = stroke
     layer.add_stroke_shape(stroke, self._sshot_before)
     self._sshot_after = layer.save_snapshot()
Exemple #10
0
 def redo(self):
     """Performs, or re-performs after undo"""
     model = self.doc
     layer = model.layer_stack.deepget(self._layer_path)
     assert self._recording_finished, "Call stop_recording() first"
     assert self._sshot_before is not None
     assert self._sshot_after is not None
     assert self._time_before is not None
     if not self._sshot_after_applied:
         layer.load_snapshot(self._sshot_after)
         self._sshot_after_applied = True
     # Update painting time
     assert self._time_after is not None
     model.unsaved_painting_time = self._time_after
Exemple #11
0
    def stop_recording(self, revert=False):
        """Ends the recording phase

        :param bool revert: revert any changes to the model
        :rtype: bool
        :returns: whether any changes were made

        When called with default arguments,
        this method makes the command ready to add to the command stack
        using the document model's do() method.
        If no changes were made, you can (and should)
        just discard the command instead.

        If `revert` is true,
        all changes made to the layer during recording
        will be rolled back,
        so that the layer has its original appearance and state.
        Reverted commands should be discarded.

        After this method is called,
        the `stroke_to()` method must not be called again.

        """
        self._check_recording_started()
        layer = self._stroke_target_layer
        self._stroke_target_layer = None  # prevent potential leak
        self._recording_finished = True
        self._stroke_seq.stop_recording()
        if layer is None:
            return False  # wasn't suitable for painting, thus nothing changed
        if revert:
            assert self._sshot_before is not None
            logger.debug(
                "Brushwork: stop_recording: rollback %0.3fs",
                self._stroke_seq.total_painting_time,
            )
            layer.load_snapshot(self._sshot_before)
            return False  # nothing changed
        t0 = self._time_before
        self._time_after = t0 + self._stroke_seq.total_painting_time
        layer.add_stroke_shape(self._stroke_seq, self._sshot_before)
        self._sshot_after = layer.save_snapshot()
        self._sshot_after_applied = True  # changes happened before redo()
        tiles_changed = (not self._stroke_seq.empty)
        logger.debug(
            "Brushwork: stop_recording: %0.3fs, tiles_changed=%r",
            self._stroke_seq.total_painting_time,
            tiles_changed,
        )
        return tiles_changed
Exemple #12
0
 def redo(self):
     """Performs, or re-performs after undo"""
     model = self.doc
     layer = model.layer_stack.deepget(self._layer_path)
     assert self._recording_finished, "Call stop_recording() first"
     assert self._sshot_before is not None
     assert self._sshot_after is not None
     assert self._time_before is not None
     if not self._sshot_after_applied:
         layer.load_snapshot(self._sshot_after)
         self._sshot_after_applied = True
     # Update painting time
     assert self._time_after is not None
     model.unsaved_painting_time = self._time_after
Exemple #13
0
 def redo(self):
     """Performs, or re-performs after undo"""
     model = self.doc
     layer = model.layer_stack.deepget(self._layer_path)
     if self._stroke_seq is None:
         return
     assert self._stroke_seq.finished, "Call stop_recording() first"
     if self._sshot_after is None:
         t0 = self._time_before
         self._time_after = t0 + self._stroke_seq.total_painting_time
         layer.add_stroke_shape(self._stroke_seq, self._sshot_before)
         self._sshot_after = layer.save_snapshot()
     else:
         layer.load_snapshot(self._sshot_after)
     # Update painting time
     assert self._time_after is not None
     self.doc.unsaved_painting_time = self._time_after
Exemple #14
0
 def undo(self):
     layer = self.doc.layer_stack.current
     layer.load_snapshot(self._before)
     self._before = None
Exemple #15
0
 def undo(self):
     layer = self.doc.layer_stack.deepget(self._layer_path)
     layer.load_snapshot(self._before)
Exemple #16
0
 def undo(self):
     layer = self.doc.layer_stack.deepget(self._layer_path)
     layer.load_snapshot(self._before)
Exemple #17
0
 def undo(self):
     """Undoes the effects of redo()"""
     layer = self.doc.layer_stack.deepget(self._layer_path)
     layer.load_snapshot(self._sshot_before)
     self.doc.unsaved_painting_time = self._time_before
Exemple #18
0
 def undo(self):
     layer = self.doc.layer_stack.current
     layer.load_snapshot(self._before)
     self._before = None