Init new focus() command

This commit is contained in:
Splines 2024-11-10 18:48:33 +01:00
parent 003c4d8626
commit 97b6e39abb
No known key found for this signature in database
GPG key ID: 5F314C62908F7B8E
2 changed files with 18 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,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):

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,