Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tablet Events Not Captured in ManimGL Window #2291

Open
aguemoug opened this issue Jan 2, 2025 Discussed in #2290 · 0 comments
Open

Tablet Events Not Captured in ManimGL Window #2291

aguemoug opened this issue Jan 2, 2025 Discussed in #2290 · 0 comments

Comments

@aguemoug
Copy link

aguemoug commented Jan 2, 2025

Discussed in #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}")

```</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant