From 97b6e39abb2a055a38e7034d2078535f0e1a8ec4 Mon Sep 17 00:00:00 2001 From: Splines Date: Sun, 10 Nov 2024 18:48:33 +0100 Subject: [PATCH] Init new focus() command --- manimlib/scene/scene.py | 6 ++++++ manimlib/window.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.py index b92eef0f..09efe2ab 100644 --- a/manimlib/scene/scene.py +++ b/manimlib/scene/scene.py @@ -234,6 +234,7 @@ class Scene(object): add=self.add, remove=self.remove, clear=self.clear, + focus=self.focus, save_state=self.save_state, undo=self.undo, redo=self.redo, @@ -985,6 +986,11 @@ class Scene(object): def on_close(self) -> None: pass + def focus(self) -> None: + if not self.window: + return + self.window.focus() + class SceneState(): def __init__(self, scene: Scene, ignore: list[Mobject] | None = None): diff --git a/manimlib/window.py b/manimlib/window.py index d6369166..f2e7ae80 100644 --- a/manimlib/window.py +++ b/manimlib/window.py @@ -49,6 +49,18 @@ class Window(PygletWindow): self.to_default_position() + def focus(self): + """ + Puts focus on this window by hiding and showing it again. + + Note that the pyglet `activate()` method didn't work as expected here, + so that's why we have to use this workaround. This will produce a small + flicker on the window but at least reliably focuses it. It may also + offset the window position slightly. + """ + self._window.set_visible(False) + self._window.set_visible(True) + def to_default_position(self): self.position = self.default_position # Hack. Sometimes, namely when configured to open in a separate window,