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

adding type annotations and png example script #63

Merged
merged 1 commit into from
Jan 9, 2023

Conversation

FoamyGuy
Copy link
Contributor

Follow up on #61 to add typing annotations and an example of the new PNG loading functionality.

@FoamyGuy FoamyGuy requested a review from a team October 17, 2022 17:05
@tekktrik tekktrik marked this pull request as draft October 17, 2022 19:07
@tekktrik
Copy link
Member

Converted to draft to prevent merging, since this PR will help test new CI changes.

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad.git"


def load(
file, *, bitmap, palette=None
file: str, *, bitmap: BitmapConstructor, palette: PaletteConstructor = None
): # pylint: disable=too-many-locals,too-many-branches
Copy link
Contributor

Choose a reason for hiding this comment

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

I have been researching a little about how to annotate the return type of this correctly, without assuming that we are always going to use the displayio.Bitmap and displayio.Palette. It seems like we can do this by using type aliases (https://peps.python.org/pep-0484/#type-aliases) to make sure the function returns the same type as the constructor that it gets, and optionally maybe protocols (https://peps.python.org/pep-0544/) to make sure those types have the required methods on them.

image, palette = adafruit_imageload.load("images/test_image.png")

# Set the transparency index color to be hidden
palette.make_transparent(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is another todo – we could read the transparency information from the file, there are two kinds of chunks that can define that.

@tekktrik tekktrik marked this pull request as ready for review October 25, 2022 14:18
@tekktrik
Copy link
Member

@deshipu are those comments gating merging this in?

@FoamyGuy
Copy link
Contributor Author

FoamyGuy commented Jan 9, 2023

I've opened #65 try track transparency implementation issue. #62 also is there for the typing improvements with protocols.

Merging this one based on the approval to get it cleared out and get the example published for folks to find and use.

@FoamyGuy FoamyGuy merged commit b3953c8 into adafruit:main Jan 9, 2023
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 10, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 1.13.1 from 1.13.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#80 from BiffoBear/dhcp_error_handling

Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 1.17.0 from 1.16.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#63 from FoamyGuy/png_typing_and_example
  > Add .venv to .gitignore
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_Motor to 3.4.6 from 3.4.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_Motor#67 from tekktrik/pwmout-fix
  > Add .venv to .gitignore
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.12.12 from 1.12.11:
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#124 from adafruit/chain-exception-when-fail
  > Add .venv to .gitignore

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
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.

3 participants