Next: Redirecting the command output, Previous: Querying project switches, Up: Executing external tools [Index]
Another solution to query the arguments for the tool is to ask the user interactively. The scripting languages provides a number of solutions for these.
They generally have their own native way to read input, possibly by creating a dialog.
In addition, the simplest solution is to use the predefined GPS commands for this. These are the two functions:
yes_no_dialog
This function takes a single argument, which is a question to display. Two buttons are then available to the user, "Yes" and "No". The result of this function is the button the user has selected, as a boolean value.
input_dialog
This function is more general. It takes a minimum of two arguments, with no upper limit. The first argument is a message describing what input is expected from the user. The second, third and following arguments each correspond to an entry line in the dialog, to query one specific value (as a string). The result of this function is a list of strings, each corresponding to these arguments.
From the GPS shell, it is only convenient to query one value at a time, since it doesn’t have support for lists, and would return a concatenation of the values. However, this function is especially useful with other scripting languages.
The following is a short example that queries the name of a directory and a file name, and displays each in the Messages window.
<?xml version="1.0" ?> <query_file> <action name="query file and dir"> <shell lang="python">list=GPS.MDI.input_dialog \ ("Please enter directory and file name", "Directory", "File")</shell> <shell lang="python">print ("Dir=" + list[0], "File=" + list[1])</shell> </shell> </action> </query_file>
Next: Redirecting the command output, Previous: Querying project switches, Up: Executing external tools [Index]