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

convert_image() and convert_shape() methods should support Py5Image, Py5Graphics, and Py5Shape objects #405

Closed
hx2A opened this issue Jan 8, 2024 · 8 comments
Labels
good first issue Good for newcomers

Comments

@hx2A
Copy link
Collaborator

hx2A commented Jan 8, 2024

When passed Py5Image, Py5Graphics, and Py5Shape objects there is nothing to convert and it should just return the object unmodified without throwing an exception.

@hx2A hx2A added the good first issue Good for newcomers label Jan 8, 2024
@hx2A
Copy link
Collaborator Author

hx2A commented Jan 8, 2024

Adding the good first issue label if anyone wants to work on this. There's a quick fix for this that I'll explain if you're interested.

@MuhammadHasnain77
Copy link

Hi;
can you explain which file it is and what is the quick fix so that I can work on it.
As I am totally beginner.

@keko24
Copy link
Contributor

keko24 commented Jan 8, 2024

Hey @hx2A ,
so I started working on this issue and wanted to ask a question. Since convert_image() and convert_shape() are annotated to return Py5Image and Py5Shape correspondingly, how would you return another type of an object such as Py5Graphics?
Thanks in advance.

@hx2A
Copy link
Collaborator Author

hx2A commented Jan 9, 2024

Hello, @keko24 & @MuhammadHasnain77 ! Thank you both for your interest in fixing this.

First, I should give you a heads up that I am dealing with some family health problems right now and might not be as quick to respond as I normally am.

can you explain which file it is

I believe the best way to fix this by modifying this file:

py5_resources/py5_module/py5/sketch.py

The convert_shape() and convert_image() methods are both there. The solution is to test obj before the calls to _convert to see if it is an instance (with isinstance) of Py5Shape or an instance of Py5Image / Py5Graphics. If so, just return obj right away.

annotated to return Py5Image and Py5Shape correspondingly, how would you return another type of an object such as Py5Graphics?

Good question!

In Processing (Java), the PGraphics class inherits from PImage. Therefore, any PGraphics object is also an instance of PImage. Any method that accepts a PImage object will accept a PGraphics object because the PGraphics object is also a PImage.

In py5, the Py5Graphics class does not inherit from Py5Image, and the reasons for this have to do with some details about how py5 works internally. However, the conceptual relationship is the same, and you can pass a Py5Graphics object to any method that would accept a Py5Image object.

Since a Py5Graphics object can also be considered a Py5Image object, the convert_image() method can return a Py5Graphics object just fine without any concerns about the return type.

However, since the Py5Graphics class does not actually inherit from Py5Image, the code you write cannot be isinstance(obj, Py5Image). You must test for both with isinstance(obj, (Py5Image, Py5Graphics)).

@keko24 & @MuhammadHasnain77 , is all of that understandable?

@hx2A
Copy link
Collaborator Author

hx2A commented Jan 9, 2024

Also, to run the build process, look here:

https://py5coding.org/developer/build_process.html

If there's anything about the build process that is not clear, that's an issue that I will fix.

@MuhammadHasnain77
Copy link

thanks

@keko24
Copy link
Contributor

keko24 commented Jan 9, 2024

Hey @hx2A,
thanks for the reply. Sorry to hear about your family health problems, hope it gets better.
I made a pull request for this issue, but forgot to add you as a reviewer, thus I'm notifying you like this.

hx2A added a commit that referenced this issue Jan 12, 2024
Issue #405: Implemented corresponding changes to convert_image and convert_shape.
@hx2A
Copy link
Collaborator Author

hx2A commented Jan 12, 2024

Thank you, @keko24 , for PR #406 !

@hx2A hx2A closed this as completed Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants