Add export methods for PIL and popular array libraries to the ScreenShot object
Currently, this shares memory with the .raw bytearray in some cases. We should consider whether we want to change that to always copy, or just wait until we have the full shared buffer support.
This implementation always does the array manipulation on the CPU. For PyTorch or TensorFlow, the user is likely to want to do the array manipulation on the GPU for performance. This is very easy to implement; I just wanted to get this draft out for now.
Changes proposed in this PR
Fixes #478
- [X] Tests added/updated
- [X] Documentation updated
- [ ] Changelog entry added
- [X]
./check.shpassed
Python 3.9 will be dropped in the next major release, so no need to take care of test failures.
I think we can do a release without this patch, right?
Certainly!
We can still wait to merge this, but the fix for Python 3.9 was simple, so I went ahead and committed it.
You can revert the Python 3.9 fix commit ;)
I've updated this a bit, but should probably review it before committing. It's been a while!
This is on hold pending a resolution to #536, which will affect how we should document these methods and their sharing semantics.
My last commit added a lot to the docs. There's a couple more things I want to add to the docs before closing this, even if they're somewhat out of scope for this PR.
Great! The documentation is very very good since you both started to work on the project with @halldorfannar 🤟
Go ahead for out-of-scope commits, I'll merge when you're ready.
Well, that test was weird. Glad you caught it.
All the stages seem to have completed in seconds. So I think this was a transient issue in GitHub's orchestration, not a problem with MSS. Orchestrating CI/CD on macOS is hard.
If it recurs, we can look more at it. But I'm not concerned yet.
I think this is now feature-complete, and ready for @BoboTiG and @halldorfannar 's reviews. Sorry it's such a long PR!
It seems that one of the macOS tests is stuck again.
Also, I previously said the stages had completed, but was mistaken: this is hanging during PyTest. If the CI/CD logs are complete (that is, not buffering several lines at a time), then it seems like it's now executing src/tests/test_issue_220.py::test_regression.
I'm not sure if this is a change in macOS, Python, or what. It could conceivably be related to my code, but I'm not sure how.
This test stressing tkinter, and the OS being macOS, we are not yet ready for all potential suprprises we could hit. Lets see if it happens on a regular basis, for now if retrying manually on timout fixes it, that's good.
The original issue, #220, was Linux-specific. You also tracked it down to an issue specific to Xlib error handling. Error handling is one big reason I wanted to migrate to XCB: it has a model that's much easier to work with when you have multiple libraries in a single program, let alone multiple threads.
I'll take a bit of a closer look at the issue and see if maybe it's making assumptions about things like event ordering that tkinter doesn't actually promise, and so has a race condition that just didn't happen to be a problem until recently. But if I don't find a way to fix the hang, I also wouldn't feel bad about limiting that test to just Linux.
Edit: if I do pursue changes related to this, it'll be in a separate PR. I just put the timeout in this PR so it didn't keep bugging us as we close it up.
Looks good to me!
Ok! I think there's always more to improve, but I feel like it's at a good point to merge.