py5coding / py5book

juypter book repo for py5
https://py5coding.org/
64 stars 10 forks source link

`save_pickle()` and `load_pickle()` reference improvements #111

Closed villares closed 7 months ago

villares commented 7 months ago

I think this line at https://py5coding.org/reference/sketch_save_pickle.html is incorrect: Underlying Processing method: savePickle

Then at https://py5coding.org/reference/sketch_load_pickle.html we have Underlying Processing method: loadPickle, and, as far as I understand there are no such methods in Processing.

Another thing is I think we should mention that on imported mode if you define a new class on your code you can't pickle its objects as discussed in https://github.com/py5coding/py5generator/issues/222, so if we add a warning then we can perhaps close that issue...

My proposed wording would be something like this:

When using py5 on imported mode save_pickle() and load_pickle(), as well as the Python's standard library pickle module methods they depend upon, will not work on objects instantiated from new classes you have defined yourself on the main sketch file. If you need to pickle objects from classes you defined, put those class definitions on a different .py file you can then import as a module or import the class names from. Otherwise, you could also try using module mode if you want to use pickle with your classes and keep all the sketch code in a single file.

hx2A commented 7 months ago

Another thing is I think we should mention that on imported mode if you define a new class on your code you can't pickle its objects as discussed in https://github.com/py5coding/py5generator/issues/222, so if we add a warning then we can perhaps close that issue

I just added that warning. You can see it on the dev website:

http://dev.py5coding.org/reference/sketch_save_pickle.html http://dev.py5coding.org/reference/sketch_load_pickle.html

I'll also close out that other py5 pickle issue.

Underlying Processing method: loadPickle

I agree, that is misleading.

The original reason for this was I wanted the documentation to indicate which methods are implemented in Java by pointing to the Processing docs for the Java methods. In general this works correctly, but there some curve balls. For example. there are py5 methods that are implemented in Java that are unknown to Processing. For example vertices(). There are also py5 methods like the trigonometry methods and data methods load_bytes() and load_strings() where Processing functions exist but py5 does not use them. When you pointed this out I found the mistake in a few other places. I fixed them but I suspect there are more. Addressing it will require more careful review. I will open a new issue to track that.

villares commented 7 months ago

great! thanks!