示例#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
示例#2
0
文件: command.py 项目: Xananax/dopey
 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()
示例#3
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
示例#4
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()
示例#5
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()
示例#6
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
示例#7
0
文件: command.py 项目: Xananax/dopey
 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