GeezerVison is showing github.com — Create a Proxy subclass that we use for our Graphic classes · Issue #161 · fastplotlib/fastplotlib
Create a Proxy subclass that we use for our Graphic classes #161Descriptionthe purpose of this is having useful __repr__ etc. Activityclewis7 commented on Apr 11, 2023 just to clarify....
currently adding a graphic to a plot returns a __repr__ that looks like this:
<weakproxy at 0x7f28437e11d0 to ImageGraphic at 0x7f27f87d4610>
but we want to return __repr__ as they were before?
ImageGraphic @ 0x7fbb681a1360
kushalkolar commented on Apr 11, 2023 yup, along with name etc.
I just noticed that the real repr prints if you check a Plot or Subplot so this is actually not too important for now. If it takes > 30 mins to figure out let's skip this for now. clewis7 commented on Apr 11, 2023 yes, and if you call __repr__ on the proxy object that gets returned it will also give the correct __repr__ for a graphic clewis7 commented on Apr 11, 2023 so maybe just overriding the __repr__ method for the proxy so that it actually returns the __repr__ of what the proxy is pointing to as opposed to the current __repr__ it returns? kushalkolar commented on Apr 11, 2023
so maybe just overriding the __repr__ method for the proxy so that it actually returns the __repr__ of what the proxy is pointing to as opposed to the current __repr__ it returns?
if it's that simple, but I don't know almarklein commented on Mar 12, 2024 I briefly looked at this. I initially thought that the proxy was a custom object, but it's a weakref.proxy object, which is builtin and cannot be subclassed. So basically there's no way to change the repr. You technically can implement your own custom varianf of weakref.proxy ... but that's probably a rabbit-hole.
An alternative solution is that the Graphics object becomes the proxy. That makes sense, I think, because it already plays the role of a proxy, projection fpl features onto pygfx world objects. In terms of code, this'd mean that the graphics instance holds a weakref (weakref.ref() or weakref.proxy()) to the WorldObject ... and that should be about it. kushalkolar commented on Mar 13, 2024 Thanks for looking into it!
Each Graphic uses a weakref to the pygfx.WorldObject, however this was not sufficient for complete garbage collection. Since we have the various GraphicFeatures that wrap pygfx.Buffer (ex. ColorFeature) , and these can also hold event handlers of other graphics, it was necessary to have Graphic as a weakref as well to ensure both VRAM and system RAM get freed. This specifically traces back to this commit: 5e9f544#diff-87b8787e6cc96514902d278266d644006041f56cb59a1c3487193f564ea71afdL130-R150
Since the repr is typically useful in ipython or notebooks I think we'll just implement #428 for now.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|