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

PDF and SVG renderers in `size()` require exit_sketch() #137

Closed villares closed 2 years ago

villares commented 2 years ago
import py5

def setup():
    py5.size(500, 500, py5.PDF, 'out.pdf')
    py5.rect(50, 50, 100, 100)
    print(py5.__version__)

py5.run_sketch()

console: 0.8.2.dev0

file output: A zero-bytes out.pdf file.

import py5

def setup():
    py5.size(500, 500, py5.SVG, 'out.svg')
    py5.rect(50, 50, 100, 100)
    print(py5.__version__)

py5.run_sketch()

console: 0.8.2.dev0

file output:

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg xmlns:xlink="http://www.w3.org/1999/xlink" style="fill-opacity:1; color-rendering:auto; color-interpolation:auto; text-rendering:auto; stroke:black; stroke-linecap:square; stroke-miterlimit:10; shape-rendering:auto; stroke-opacity:1; fill:black; stroke-dasharray:none; font-weight:normal; stroke-width:1; font-family:'Dialog'; font-style:normal; stroke-linejoin:miter; font-size:12px; stroke-dashoffset:0; image-rendering:auto;" width="500" height="500" xmlns="http://www.w3.org/2000/svg"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
  /><g
/></svg
>
hx2A commented 2 years ago

For both of them you need to call py5.exit_sketch() for the Sketch to exit and for the output to be written. Is this different from how Processing and Processing.py works?

villares commented 2 years ago

For both of them you need to call py5.exit_sketch() for the Sketch to exit and for the output to be written. Is this different from how Processing and Processing.py works?

Hmmm, interesting! I have not found about the need for an "exit call" in the processing.org size() reference: https://processing.org/reference/size_.html https://py.processing.org/reference/size.html

But then... there it is in this PDF library page! image

So I suppose it is "works as designed" :)

Suggestion:

hx2A commented 2 years ago

The documentation could be more clear about the need for exit(). It is mentioned explicitly at the very end:

Again, exit() is really important when using PDF with size().

We could mention this in py5's size() reference page. I'm not sure what you mean by a post exit clean up routine. Post exit is after exit, and there is no longer a need to call exit_sketch() then. Do you mean have py5 call exit for you? I don't know if that's a good idea, we'd have to think that through to make sure there are no bad side effects.

villares commented 2 years ago

Yeah, precise language can be tricky for describing it... I meant something that could execute after a sketch ends if exit_sketch() is not called to guarantee things are closed properly. But I see it could be hard.

I vote to just close this with a mention added to the size() page for now.

hx2A commented 2 years ago

I vote to just close this with a mention added to the size() page for now.

Yes, I think that's the right thing to do here. Would you like to make a PR for this change?

villares commented 2 years ago

Oh... Sorry, could you point me for the n-th time to te instructions for building/contributing to the docs?

On Sun, 21 Aug 2022, 21:56 hx2A, @.***> wrote:

I vote to just close this with a mention added to the size() page for now.

Yes, I think that's the right thing to do here. Would you like to make a PR for this change?

— Reply to this email directly, view it on GitHub https://github.com/py5coding/py5generator/issues/137#issuecomment-1221667068, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4GADCZY3VJG673IK6TJVDV2LF3XANCNFSM57FUGQJA . You are receiving this because you authored the thread.Message ID: @.***>

hx2A commented 2 years ago

No problem. You need to submit a PR for a change to this file, adding a sentence or two to the @@ description section.

hx2A commented 2 years ago

This fixed and I merged the PR. Thank you!