py5coding / py5generator

Meta-programming project that creates the py5 library code.
https://py5coding.org/
GNU General Public License v3.0
52 stars 13 forks source link

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

Closed hx2A closed 9 months ago

hx2A commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

thanks

keko24 commented 9 months ago

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 commented 9 months ago

Thank you, @keko24 , for PR #406 !