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

add read_image api to ui.clipboard #4144

Merged
merged 4 commits into from
Jan 14, 2025
Merged

Conversation

liunux4odoo
Copy link
Contributor

make it easy to read copied image from client clipboard.

Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request, @liunux4odoo!

  • To be honest, I don't understand how to use this feature. How can I copy an image to the clipboard? Whatever I try, your demo says I need to copy an image first.

Apart from that, there are some problems with this implementation:

  1. We can't simply break existing API by renaming read and write. I suggest to leave them unchanged while adding read_image.
  2. The demo doesn't work for two reasons:
    1. The call to ui.clipboard.read_image() needs to be awaited.
    2. Awaiting a JavaScript command isn't allowed on the auto-index client, so the demo needs to be wrapped in a page function. But in order for the demo to keep working when embedded on the NiceGUI website, we need to prevent the decorator from adding a new route. Here is an example how to do that.

@liunux4odoo
Copy link
Contributor Author

I have reversed the clipboard.read & clipboard.write APIs.
User must copy an image to the clipboad before he can read it.

@falkoschindler
Copy link
Contributor

Ok, I managed to copy an image like this:

  1. Open an image in Preview (macOS)
  2. Use Edit > Copy

Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

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

Thanks again, @liunux4odoo!
I just improved the way PIL is imported because it is an optional dependency.
Let's merge!

@falkoschindler falkoschindler added the enhancement New feature or request label Jan 14, 2025
@falkoschindler falkoschindler added this to the 2.10 milestone Jan 14, 2025
@falkoschindler falkoschindler merged commit 068f6cd into zauberzeug:main Jan 14, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants