Skip to content

add message to prompt use of save_frame() #172

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

Merged
merged 3 commits into from
Oct 5, 2022

Conversation

zztkm
Copy link
Contributor

@zztkm zztkm commented Oct 5, 2022

#171

  • Move import py5 to outside of the if clause for screenshot() and the other frame hooks
  • For screenshot(), suggest using save_frame() instead

I would appreciate it if you could let me know if I have missed something.

backgroud: #170

@hx2A
Copy link
Collaborator

hx2A commented Oct 5, 2022

Thanks for the PR, @zztkm !

This is a good start. You found the right file and line of code to change to improve the error message.

There is one more change you need to make. Look at the previous line of code:

   if py5.bridge.check_run_method_callstack():

The original error message you received was "UnboundLocalError: local variable 'py5' referenced before assignment". That error message came from the above if statement.

Do you see how you would get that UnboundLocalError exception on that line if screenshot() is used in class mode, where you use the screenshot() function's sketch param, but would not give a UnboundLocalError exception if screenshot() is used in module mode, where you don't use the skech param? Trace through the previous lines of code in that function to see what is different in those two scenarios.

You'll need to move one line of code for this next change.

@zztkm
Copy link
Contributor Author

zztkm commented Oct 5, 2022

@hx2A Thanks for the Good advice. I've addressed it!

I have one question. Should py5 imports be done inside each function?
Or should I import at the top of this module?

Currently, import is done in each function.

@hx2A
Copy link
Collaborator

hx2A commented Oct 5, 2022

I have one question. Should py5 imports be done inside each function? Or should I import at the top of this module?

The py5 imports should be done inside each function, as you've done here. This is perfect.

One of the requirements of py5_tools is to provide a way for users to add jar files to the classpath or set JVM options. This must be done before the JVM is started. When you execute import py5, it starts the JVM, and no futher changes to the classpath or JVM options are possible. If import py5 was at the top of the module anywhere in py5_tools, a user that executes import py5_tools would also import py5 and start the JVM. Putting the import py5 statement inside each function is a way of delaying the import until a later time when py5 has already been imported and the JVM is already running.

@hx2A
Copy link
Collaborator

hx2A commented Oct 5, 2022

@zztkm , thanks for spotting the unused import and for noticing that other functions besides screenshot() in that file needed import py5 to be moved outside the if statements!

@hx2A hx2A merged commit a0879a9 into py5coding:main Oct 5, 2022
@zztkm
Copy link
Contributor Author

zztkm commented Oct 5, 2022

@hx2A

One of the requirements of py5_tools is to provide a way for users to add jar files to the classpath or set JVM options. This must be done before the JVM is started. When you execute import py5, it starts the JVM, and no futher changes to the classpath or JVM options are possible. If import py5 was at the top of the module anywhere in py5_tools, a user that executes import py5_tools would also import py5 and start the JVM. Putting the import py5 statement inside each function is a way of delaying the import until a later time when py5 has already been imported and the JVM is already running.

I see, so that was the reason.
I learned a lot! Thanks for the merge!

@zztkm zztkm deleted the fix-screenshot-error-message branch October 5, 2022 17:22
@hx2A
Copy link
Collaborator

hx2A commented Oct 5, 2022

I see, so that was the reason. I learned a lot! Thanks for the merge!

You are welcome! I'm happy you learned something doing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants