-
Notifications
You must be signed in to change notification settings - Fork 5
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
Windows 10 screen capture raises UnparsableClipboardFormatException #14
Comments
Thanks for raising this issue. Right now, It seems you have copied and subsequently tried to paste through the I guess I would wonder: (1) what format(s) is stored when screen grabs are used to populate the clipboard and (2) what should the behavior of |
Hi Spencer,
Thanks for the follow-up. In response:
1. I *think* screen grabs are stored in png format.
2. I think the behaviour of `.paste` should be to return the full binary
"blob" so it can be assigned to a variable. It seems that `pyclip` does
some inspection and validation of the binary data in addition to retrieval,
which makes sense too.
My ambition is to use `pyclip` to capture image data in the clipboard and
save them to disk from Jupyter which requires knowing what format the image
data is in.
The code I am working with checks the first 4 - 8 bytes of the blob against
the GIF, JPG, PNG signatures (as found in
https://en.wikipedia.org/wiki/List_of_file_signatures) so it assumes that
there is no additional header information "wrapping" the image data. So, if
no such "wrapping" exists on the clipboard data then perhaps adding a
`raw=True` flag to `.paste` could be an option to by-pass any validation?
…On Thu, Mar 31, 2022 at 10:53 PM Spencer Phillip Young < ***@***.***> wrote:
Thanks for raising this issue. Right now, pyclip supports a narrow set of
clipboard formats. Essentially, just text formats and hdrop (file
copy/paste).
It seems you have copied and subsequently tried to paste through the
pyclip program a format that is not supported.
I guess I would wonder: (1) what format(s) is stored when screen grabs are
used to populate the clipboard and (2) what should the behavior of .paste
do when dealing with these format(s).
—
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJFJEEJTCI4WSMXWOWU5WM3VC2FNLANCNFSM5SHSLV4Q>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hi @spyoungtech, After reading your source, and some of the Windows clipboard documentation, it seems that when one calls It seems that this clipboard format code is something of a generic code to refer to a I added an argument to def paste(self, encoding: str = None, text: bool = None, errors: str = None, format_override: int = None) -> Union[str, bytes]:
"""
Returns clipboard contents
:param encoding: same meaning as in ``bytes.encode``. Implies ``text=True``
:param text: if True, bytes object will be en
:param errors: same meaning as in ``bytes.encode``. Implies ``text=True``.
:param format_override: an attempt is made to find the format of the clipboard data internally but sometimes,
on Windows, this format is incorrect. Allows user to specify a format to return the data in.
See: https://docs.microsoft.com/en-us/windows/win32/dataxchg/standard-clipboard-formats
Use format code 8 for bitmap screen captures.
:return: clipboard contents. Return value is bytes by default
or str if any of ``encoding``, ``text``, or ``errors`` is provided.
"""
with self._clipboard as clip:
if format_override:
format = format_override
else:
format = clip.EnumClipboardFormats()
if format == 0:
if text or encoding or errors:
return ''
else:
return b''
... This byte data can be passed through a So, it seems that it is possible to get screen capture data using In my local copy, I created this Let me know your thoughts on this. If you are interested in being able to work with Windows screen captures, then perhaps you might have some other ideas on how to manage this. My approach seems kinda hacky and it may break the API (because you would have different kwargs for different platforms). |
I will try playing around with it locally to see if I can get it to work. If so, I will submit a draft PR for discussion.
…Sent from my iPhone
On Apr 1, 2022, at 09:08, Connor Ferster ***@***.***> wrote:
Hi Spencer,
Thanks for the follow-up. In response:
1. I *think* screen grabs are stored in png format.
2. I think the behaviour of `.paste` should be to return the full binary "blob" so it can be assigned to a variable. It seems that `pyclip` does some inspection and validation of the binary data in addition to retrieval, which makes sense too.
My ambition is to use `pyclip` to capture image data in the clipboard and save them to disk from Jupyter which requires knowing what format the image data is in.
The code I am working with checks the first 4 - 8 bytes of the blob against the GIF, JPG, PNG signatures (as found in https://en.wikipedia.org/wiki/List_of_file_signatures) so it assumes that there is no additional header information "wrapping" the image data. So, if no such "wrapping" exists on the clipboard data then perhaps adding a `raw=True` flag to `.paste` could be an option to by-pass any validation?
> On Thu, Mar 31, 2022 at 10:53 PM Spencer Phillip Young ***@***.***> wrote:
> Thanks for raising this issue. Right now, pyclip supports a narrow set of clipboard formats. Essentially, just text formats and hdrop (file copy/paste).
>
> It seems you have copied and subsequently tried to paste through the pyclip program a format that is not supported.
>
> I guess I would wonder: (1) what format(s) is stored when screen grabs are used to populate the clipboard and (2) what should the behavior of .paste do when dealing with these format(s).
>
> —
> Reply to this email directly, view it on GitHub, or unsubscribe.
> You are receiving this because you authored the thread.
|
Hi there!
I think this is a really great tool and I am excited to use it for engineering practice where it's common to copy-paste screen grabs of analysis models.
I install
pyclip
and immediately tried to use it with a screen capture only to be greeted with the following:I was hoping that with all of the additional clipboard formats available on Windows that it would be quite flexible. Is this something that is just a small fix or is there something funny going on with Windows and their proprietary formats?
Thanks for any time you can spend on this!
The text was updated successfully, but these errors were encountered: