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

TextInput widget's copy-paste fails silently #485

Closed
maqp opened this issue Aug 31, 2024 · 1 comment
Closed

TextInput widget's copy-paste fails silently #485

maqp opened this issue Aug 31, 2024 · 1 comment

Comments

@maqp
Copy link

maqp commented Aug 31, 2024

Problem:

On Ubuntu 24.04 LTS that defaults to Wayland, trying to paste to TextInput widget fails silently on line 1293.

The reason for this was that as per Pyperclip, one of the packets in xclip, xsel, or wl-clipboard was missing. Of these at least wl-clipboard works, I didn't test others.

Solution:

Perhaps the library could try to detect the platform and either print a warning, or raise an exception when this happens. E.g.

# Paste text in cursor
try:
    text = paste()
except PyperclipException:
    import os
    if os.getenv("XDG_SESSION_TYPE") == 'wayland':
        raise PyperclipException("Pasting from clipboard failed. Please install package 'wl-clipboard'")
    return False
@ppizarror
Copy link
Owner

Hi @maqp. I added two warnings if copy/paste fails.

def clipboard_warn(e: PyperclipException, op: str) -> None:
"""
Generates a warning message if clipboard failed.
:param e: Exception
:param op: Operation that failed
"""
paste_warn: str = f'{op} from clipboard failed ({e}). '
if os.getenv('XDG_SESSION_TYPE') == 'wayland':
paste_warn += 'Please install package "wl-clipboard"'
elif platform.system() == 'Linux':
paste_warn += 'On Linux, install "xclip" or "xsel"'
else:
paste_warn += (f'An unrecognized error happened. '
f'Please create a new issue on {pygame_menu.__url_bug_tracker__}')
warn(paste_warn)

Let me know if that addresses the enh, so you can close this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants