Merge pull request #2241 from Splines/feature/focus

Add `focus()` command
This commit is contained in:
Grant Sanderson 2024-11-25 10:06:48 -06:00 committed by GitHub
commit 314ca89a45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View file

@ -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,14 @@ class Scene(object):
def on_close(self) -> None:
pass
def focus(self) -> None:
"""
Puts focus on the ManimGL window.
"""
if not self.window:
return
self.window.focus()
class SceneState():
def __init__(self, scene: Scene, ignore: list[Mobject] | None = None):

View file

@ -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,