mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Merge pull request #2241 from Splines/feature/focus
Add `focus()` command
This commit is contained in:
commit
314ca89a45
2 changed files with 21 additions and 0 deletions
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue