We are about to switch to a new forum software. Until then we have removed the registration on this forum.
As per the subject, is there a way to create a blocking version of selectFolder()? I want to ask for the folder of images in setup(), it doesn't make sense to proceed without that directory.
You mean selectFolder () is blocking the execution of the rest of your sketch until selectFolder has given a result...?
@paulbourke -- it would help to know when are you calling this selectFolder() (at the beginning of the sketch, or in the middle) and what specifically are you blocking -- the contents of draw()?
Here is an example that adds the built-ins
noLoop()to the default reference sketch for
selectFolder(). The text shows the current draw frame. Test it by clicking with the mouse.
Yeah, thanks. I did something similar without knowing about loop/noloop. Declared a boolean global as false, did nothing in the draw while it was false, set it true in the callback.
I always integrate this boolean into the state concept I use for bigger projects.
The main distinction is that with a boolean, frameCount will continue to iterate as draw() loops at frameRate per sec.
This only matters you use frameCount-based math for animation -- and then it that may be a good or bad thing depending on what your desired behavior is.
The standard Java file chooser dialog window is synchronous which means it halts (blocks) the execution of the main thread until it is closed by choosing an option.
This was how Processing worked until V2 (~Jan 2013) when the Processing developers changed the file/folder chooser code so it ran in another thread making it asynchronous (non blocking).
The most obvious way is to ad your own method to use the Java file chooser directly.
This webpage gives sample code to select a folder. Alternatively use G4P as its dialogs are asynchronous, I added them to provide an alternative to the methods provided by Processing.