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 screenshot 1342 #2039

Open
wants to merge 46 commits into
base: development
Choose a base branch
from

Conversation

sabadam32
Copy link
Contributor

@sabadam32 sabadam32 commented Mar 29, 2024

Fixes #1342

Copy link
Member

@pushfoo pushfoo left a comment

Choose a reason for hiding this comment

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

I can't speaks to the GL side, but there are some immediate changes I see as room for improvement. Included file in here + some possible improvements.

tash apply Outdated Show resolved Hide resolved
arcade/application.py Outdated Show resolved Hide resolved
arcade/window_commands.py Outdated Show resolved Hide resolved
tash apply Outdated Show resolved Hide resolved
arcade/application.py Outdated Show resolved Hide resolved
tests/unit/window/test_screenshot.py Outdated Show resolved Hide resolved
@einarf
Copy link
Member

einarf commented Mar 29, 2024

What about the old arcade.get_image() and arcade.get_pixel()? We also talked about having screenshot feature in cameras. I think get_image() also have some history related to pixel ratio > 1.0. I don't quite remeber if we ended up scaling the screenshot itself.

@pushfoo
Copy link
Member

pushfoo commented Mar 31, 2024

also have some history related to pixel ratio > 1.0

Is this HiDPI or strange edge cases where non-square pixels exist? To my knowledge, that only exists on ancient platforms, but I figured I should double check.

pushfoo and others added 13 commits March 31, 2024 11:18
* Remove extra sentence

* Add list item linking the better datetime overview
* Re-order arguments for get_timestamp

* Improve default timestamp format string

* Add time-machine test helper to pyproject.toml

* Add tests for get_timestamp

* Update doc to cover changes
* Add %Z to get_timestamp

* Add doc on it + cross-refs

* Clean datetime test imports
Begin strengthening screenshot PR
Copy link
Member

@pushfoo pushfoo left a comment

Choose a reason for hiding this comment

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

TL;DR: _TzInfo is protected and ugly, but so was my previous PR due to pyright breakage. Sorry about that.

I'd run a local pyright check on the changes I proposed. My pyright is broken because of nodejs issues on my distro, sadly. Sorry about my previous PR being a little broken because of it.

@@ -34,6 +35,50 @@ def configure_logging(level: Optional[int] = None):
LOG.addHandler(ch)


def get_timestamp(
how: str = "%Y_%m_%d_%H%M_%S_%f%Z",
when: Optional[types.HasStrftime | datetime] = None,
Copy link
Member

Choose a reason for hiding this comment

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

  1. Did HasStrftime not match datetime? Was it only pyright which complained?
  2. To my understanding, the | syntax is a 3.9+ feature, but we support 3.8+

Copy link
Contributor Author

@sabadam32 sabadam32 Apr 6, 2024

Choose a reason for hiding this comment

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

No it didn't. pyright complained for sure, but I don't remember if the build failed due to this check

Copy link
Member

@pushfoo pushfoo Apr 6, 2024

Choose a reason for hiding this comment

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

Are you sure? I see references to line 41 in the GitHub CI builds on the previous commits. That's the other line it seems.

@@ -9,7 +9,7 @@
# Error out if we import Arcade with an incompatible version of Python.
import sys
import os
from datetime import datetime
from datetime import datetime, _TzInfo
Copy link
Member

Choose a reason for hiding this comment

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

My initial PR might have been a little busted due to my local nodejs breaking my pyright (I know pyright shouldn't depend on node, but it does 😢). This should work (I think):

Suggested change
from datetime import datetime, _TzInfo
from datetime import datetime, tzinfo

The Python source for the datetime module shows it as a real ABC, and it should be less brittle than _TZInfo.

when: Optional[types.HasStrftime] = None,
tzinfo: Optional[datetime.tzinfo] = None
when: Optional[types.HasStrftime | datetime] = None,
tzinfo: Optional[_TzInfo] = None
Copy link
Member

Choose a reason for hiding this comment

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

I think I removed a top-level datetime import but left behind the broken property datetime.tzinfo line earlier. With the import suggestion at the top, I think this should work.

Suggested change
tzinfo: Optional[_TzInfo] = None
tzinfo: Optional[tzinfo] = None

@pvcraven
Copy link
Member

I like having the additional docs.

Although, in the past, when people have wanted to do a screenshot we've just pointed them to:

image = get_image()
image.save('screenshot.png', 'PNG')

This seems like a lot to add to the library for screenshots when two-lines can also run a screenshot.

If we do add it, can we get some unit tests?

@pushfoo
Copy link
Member

pushfoo commented Apr 11, 2024

TL;DR:

  1. We have some unit tests already
  2. It seems since it's all at once instead of over 3+ years
  3. save_image is clear and discoverable

The Precedent is 2-3 Feature Exposures

This seems like a lot to add to the library for screenshots

In the past, we slowly added features to the top-level namespace, Window, and View. Two of the top examples:

Feature Window View Top-level
Clearing Window.clear() View.clear() arcade.start_render() (arcade.get_window.clear())
Setting BG color Window.background_color View.background_color arcade.set_background_color

Why Do It For Screenshots?

  1. View is expected to share core API features with Window
  2. arcade.get_image sets the precedent for exposing screenshots at the top level

Unit Tests

If we do add it, can we get some unit tests?

Can you elaborate? We already have some here:

If you'd like, we add some to explicitly cover View.

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.

Build improved screenshot API
4 participants