Improved selectInput/Output/Folder #1818
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch allows you to call selectInput() and similar functions in previous manner (synchronous method), and improves the flexibility of the new callback-based method.
This pull request consists of two feature-enhancement patches. One allows you to pass an additional object to callback function, and the other serves selectInput(String) in previous manner. Let me explain the former patch at first.
Passing an object to the callback function
Example:
selectOutput("Save as...", "saverFunction", a_pg_graphic);
selectInput("Load CVS...", "loadCVSFile", target_table);
Background:
Passing an object to a callback function is a well-known technique to:
Previously selectInput/Output/Folder just returned a file name and the caller was responsible to handle the file name. Now callback function has to handle the file name out of the context.
Instead of writing a number of callback functions (e.g. saveTable1(), saveTable2()...) or using a global variable, you can just pass an argument to a single function.
Simulating previous behavior of selectInput/Output/Folder
Since Processing-2.0b7, selectInput() requires to pass a callback function and runs asynchronously. This is mandatory to make Processing stable, but many developers are confused. (e.g. #1254, 1)
This patch allows you to call selectInput and its friends in the same manner to Processing 1.5. You can call selectInput() then it returns a string when the user finished to select a file, as it is in Processing 1.5. It uses a synchronized queue to pass the file name from the callback function to the caller, that means this patch does not stop any other thread.
Test code attached: