Skip to content

Pyglet Clipboard Support#1313

Merged
caffeinepills merged 1 commit intopyglet:masterfrom
csd4ni3l:csd4ni3l-add-clipboard-events
Jun 11, 2025
Merged

Pyglet Clipboard Support#1313
caffeinepills merged 1 commit intopyglet:masterfrom
csd4ni3l:csd4ni3l-add-clipboard-events

Conversation

@csd4ni3l
Copy link
Copy Markdown
Contributor

@csd4ni3l csd4ni3l commented May 6, 2025

This Draft adds clipboard support to pyglet.

First, it adds the on_clipboard_copy and on_clipboard_paste events to Caret.

Then, the Caret is now an EventDispatcher, and is registered for these events. There is a new optional window argument, which sets _window and will be used to set the clipboard content.

In on_text_motion, if the motion is MOTION_COPY, it will dispatch on_clipboard_copy, and will copy the text.

If the motion is MOTION_PASTE, it will paste the text inside the layout, overriding if something else was selected, and then dispatching on_clipboard_paste to the window that was passed in.

Please, feel free to correct my code or even push your local changes if you want to.

Copy link
Copy Markdown
Collaborator

@caffeinepills caffeinepills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just needs cleaning up.

self.visible = True

self._window = window
self.push_handlers(window)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer need to push the window as a handler if the Caret is dispatching. (Also the value could be None, so this would fail regardless)

during runtime.
"""

def on_clipboard_copy(self, text: str) -> EVENT_HANDLE_STATE:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to the Caret.

BaseWindow.register_event_type('on_file_drop')
BaseWindow.register_event_type('on_draw')
BaseWindow.register_event_type('on_refresh')
BaseWindow.register_event_type('on_clipboard_copy')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove.

@csd4ni3l csd4ni3l force-pushed the csd4ni3l-add-clipboard-events branch 2 times, most recently from 588b4b7 to 6882533 Compare May 24, 2025 19:20
@csd4ni3l csd4ni3l force-pushed the csd4ni3l-add-clipboard-events branch from 6882533 to 0ee4e77 Compare May 24, 2025 19:23
@caffeinepills caffeinepills marked this pull request as ready for review June 11, 2025 15:36
@caffeinepills caffeinepills merged commit 963f8a1 into pyglet:master Jun 11, 2025
16 checks passed
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

Successfully merging this pull request may close these issues.

2 participants