Skip to content

Commit

Permalink
Reduce the need to type 'self.' so much when embedding into a scene.
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Jan 19, 2021
1 parent 20b7872 commit e087844
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions manimlib/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ def embed(self):
shell = InteractiveShellEmbed()
# Have the frame update after each command
shell.events.register('post_run_cell', lambda *a, **kw: self.update_frame())
# Stack depth of 2 means the shell will use
# the namespace of the caller, not this method
shell(stack_depth=2)
# Use the locals of the caller as the local namespace
# once embeded, and add a few custom shortcuts
local_ns = inspect.currentframe().f_back.f_locals
local_ns["touch"] = self.interact
for term in ("play", "add", "remove", "clear"):
local_ns[term] = getattr(self, term)
shell(local_ns=local_ns, stack_depth=2)
# End scene when exiting an embed.
raise EndSceneEarlyException()

Expand Down

0 comments on commit e087844

Please sign in to comment.