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

feat:use context manager to open and close clipboard automatically #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

atticus-lv
Copy link

maybe a easier way to use it

import clipette

# old
if clipette.open_clipboard():
    clipette.empty_cliboard()
    clipette.set_UNICODETEXT("<some text>")
    clipette.close_clipboard()

# new
with clipette.clipboard():
    clipette.empty_cliboard()
    clipette.set_UNICODETEXT("<some text>")

@b-init
Copy link
Owner

b-init commented Nov 24, 2023

Using a context manager makes a lot of sense for this. Thanks for the PR.

But testing this made me realize a flaw that existed earlier too, if a non-custom exception is raised after successfully opening the clipboard, it'll halt the program without calling close_clipboard(). It seems that can also be fixed using contextmanagers? Perhaps the current system of having custom exceptions and calling close_clipboard() in them separately can be improved.

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