Skip to content

Commit

Permalink
Let checkpoint_paste work on methods of the current scene
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Mar 2, 2024
1 parent ffbe5c8 commit 9432a73
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions manimlib/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pyperclip
import random
import time
import re
from functools import wraps

from IPython.terminal import pt_inputhooks
Expand Down Expand Up @@ -777,13 +778,31 @@ def checkpoint_paste(
)

pasted = pyperclip.paste()
line0 = pasted.lstrip().split("\n")[0]
if line0.startswith("#"):
if line0 not in self.checkpoint_states:
self.checkpoint(line0)
lines = pasted.split("\n")

# Commented lines trigger saved checkpoints
if lines[0].lstrip().startswith("#"):
if lines[0] not in self.checkpoint_states:
self.checkpoint(lines[0])
else:
self.revert_to_checkpoint(line0)
self.revert_to_checkpoint(lines[0])

# Copied methods of a scene are handled specially
# A bit hacky, yes, but convenient
method_pattern = r"^def\s+([a-zA-Z_]\w*)\s*\(self.*\):"
method_names = re.findall(method_pattern ,lines[0].strip())
if method_names:
method_name = method_names[0]
indent = " " * lines[0].index(lines[0].strip())
pasted = "\n".join([
# Remove self from function signature
re.sub(r"self(,\s*)?", "", lines[0]),
*lines[1:],
# Attach to scene via self.func_name = func_name
f"{indent}self.{method_name} = {method_name}"
])

# Keep track of skipping and progress bar status
prev_skipping = self.skip_animations
self.skip_animations = skip

Expand Down

0 comments on commit 9432a73

Please sign in to comment.