Tablet Events Not Captured in ManimGL Window
- Lingua principale
- Python
- Stelle
- 93.8k
- Fork
- 7.7k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
### Discussed in https://github.com/3b1b/manim/discussions/2290
Originally posted by **aguemoug** January 2, 2025
Hellow
I am attempting to add support for graphic tablets as an input method in ManimGL. While tablet events (e.g., pen pressure, tilt) are successfully captured in a standalone Pyglet window, I am unable to capture these events within the ManimGL window.
It seems that ManimGL's custom window or event loop configuration might be interfering with the propagation of tablet-related events.
### Working Example
Below is a working example using a standalone Pyglet window to capture tablet input events.
```
import pyglet
# Create a resizable window for the whiteboard
window = pyglet.window.Window(800, 600, "Whiteboard", resizable=True)
def on_enter(cursor):
print(f"Cursor entered: {cursor}")
def on_leave(cursor):
print(f"Cursor left: {cursor}")
def on_motion(cursor, x, y, pressure, tilt_x, tilt_y, rotation):
if pressure > 0.2: # Only log events with significant pressure
print(f"Motion detected - x: {x}, y: {y}, pressure: {pressure}, tilt: ({tilt_x}, {tilt_y}), rotation: {rotation}")
tablets = pyglet.input.get_tablets()
if tablets:
tablet = tablets[0]
tablet = tablet.open(window)
tablet.event(on_motion)
tablet.event(on_enter)
tablet.event(on_leave)
else:
print("No tablet device found. Please connect a tablet.")
pyglet.app.run()
```
### Non-Working Example
Below is a non-working example where tablet events are not captured in a ManimGL-based window.
```
class Window(PygletWindow):
fullscreen: bool = False
resizable: bool = True
gl_version: tuple[int, int] = (3, 3)
vsync: bool = True
cursor: bool = True
def __init__(
self,
scene: Optional[Scene] = None,
position_string: str = "UR",
monitor_index: int = 1,
full_screen: bool = False,
size: Optional[tuple[int, int]] = None,
position: Optional[tuple[int, int]] = None,
samples: int = 0
):
self.scene = scene
self.monitor = self.get_monitor(monitor_index)
self.default_size = size or self.get_default_size(full_screen)
self.default_position = position or self.position_from_string(position_string)
self.pressed_keys = set()
super().__init__(samples=samples)
self.to_default_position()
# Enable tablet
tablets = pyglet.input.get_tablets()
if tablets:
tablet = tablets[0]
self.tablet = tablet.open(self._window)
self.tablet.event(self.on_motion)
self.tablet.event(self.on_enter)
self.tablet.event(self.on_leave)
print("Tablet initialized!")
else:
self.tablet = None
if self.scene:
self.init_for_scene(scene)
def on_enter(self, cursor):
print(f"Cursor entered: {cursor}")
def on_leave(self, cursor):
print(f"Cursor left: {cursor}")
def on_motion(self, cursor, x, y, pressure, tilt_x, tilt_y, rotation):
if pressure > 0.2:
print(f"Motion detected - x: {x}, y: {y}, pressure: {pressure}, tilt: ({tilt_x}, {tilt_y}), rotation: {rotation}")
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.