User Reference:Custom GUI Commands: Difference between revisions
No edit summary |
No edit summary |
||
| Line 8: | Line 8: | ||
; <code>CHOOSE INPUT FILE</code> (or equivalently <code>CHOOSE FILE</code>, or <code>CHOOSE INPUT</code>) | ; <code>CHOOSE INPUT FILE</code> (or equivalently <code>CHOOSE FILE</code>, or <code>CHOOSE INPUT</code>) | ||
: Prompts the user to select a single existing file | : Prompts the user to select a single existing file, and prints the resulting file path. | ||
; <code>CHOOSE INPUT FILES</code> (or equivalently<code>CHOOSE FILES</code>) | ; <code>CHOOSE INPUT FILES</code> (or equivalently<code>CHOOSE FILES</code>) | ||
: Prompts the user to select one or more existing files | : Prompts the user to select one or more existing files, and prints the resulting file paths. | ||
; <code>CHOOSE OUTPUT FILE</code> (or equivalently<code>CHOOSE OUTPUT</code>) | ; <code>CHOOSE OUTPUT FILE</code> (or equivalently<code>CHOOSE OUTPUT</code>) | ||
: Prompts the user to specify a file into which data can be saved (with an overwrite confirmation dialog if it already exists) | : Prompts the user to specify a file into which data can be saved (with an overwrite confirmation dialog if it already exists) and prints the resulting file path. | ||
; <code>CHOOSE DIRECTORY</code> | ; <code>CHOOSE DIRECTORY</code> | ||
: Prompts the user to specify a directory | : Prompts the user to specify a directory, and prints the resulting directory path. | ||
The commands may be followed by one or more of the following optional clauses (they must appear in this order): | The commands may be followed by one or more of the following optional clauses (they must appear in this order): | ||
Revision as of 20:54, 28 August 2025
BCI2000's Operator Module Scripting capabilities include the ability to prompt the user for specific pieces of information via modal Qt dialogs.
CHOOSE ...
The CHOOSE family of commands prompt the user to specify file or directory paths, via the Qt graphical user interface.
CHOOSE INPUT FILE(or equivalentlyCHOOSE FILE, orCHOOSE INPUT)- Prompts the user to select a single existing file, and prints the resulting file path.
CHOOSE INPUT FILES(or equivalentlyCHOOSE FILES)- Prompts the user to select one or more existing files, and prints the resulting file paths.
CHOOSE OUTPUT FILE(or equivalentlyCHOOSE OUTPUT)- Prompts the user to specify a file into which data can be saved (with an overwrite confirmation dialog if it already exists) and prints the resulting file path.
CHOOSE DIRECTORY- Prompts the user to specify a directory, and prints the resulting directory path.
The commands may be followed by one or more of the following optional clauses (they must appear in this order):
[OF] TYPE[S] <.ext1> [<.ext2> ...]- This limits the view (via a drop-down file-type selector) to files that have the specified extension(s). This clause cannot be used with
CHOOSE DIRECTORY. Instead of a file extension (starting with a dot) you can alternatively specify a glob pattern (containing a star).
[STARTING] AT <dir> ...](equivalently you can sayINorFROMif it reads better)- This specifies where the dialog's file-system navigation should start (by default, it will start in the current working directory).
[WITH] PROMPT <msg>- This specifies the text prompt at the top of the dialog.
Examples:
choose file of type .dat from ../data/samplefiles with prompt "Choose a data file for playback:" choose output file of type .prm in ../parms with prompt "Save parameters as..." choose directory starting at ../data with prompt "Select a subject directory:"
CUSTOM DIALOG ...
This command assembles a flexibly customizable modal dialog for communicating with the user. The command returns (prints) a string denoting which button the user pressed to complete the dialog, and as a side effect it may set any environment variables that the command specifies. If the user cancels the dialog, the command does nothing (prints nothing, does not change any environment variables).
The CUSTOM DIALOG command can be followed by as many clauses as you like. The main types of clause are MESSAGE and VAR clauses, which are rendered from top to bottom in the dialog, in the order you provide. Possible clauses are:
MESSAGE <msg>- Each message is rendered as text, word-wrapped to the width of the dialog window.
MESSAGE ""can be used to create blank vertical space. Any message that consists only of dashes (e.g.MESSAGE ---) will be turned into a horizontal rule. Simplest example:custom dialog message "Hello world!"
VAR <variableName> <visibleLabel> {} [DEFAULT <defaultText>] [MINIMUM <nChars>]- This creates a text field that the user can fill in. If you supply a
DEFAULTsubclause, the specified default text is pre-filled. If you specify aMINIMUMnumber of characters, the dialog buttons (except for the designatedESCAPEbutton) will be disabled until this text field contains at least that many characters. If the dialog is completed (by any button other than the designatedESCAPEbutton) then the environment variable designated by<variableName>will be set to the contents of the text field. For example:custom dialog var subjectName "Subject Name:" {} default test minimum 1
VAR <variableName> <visibleLabel> {<opt1>|<opt2>|...} [DEFAULT <defaultOption>] [MINIMUM <nChars>]- This is almost the same as the text-field
VARexample above, except that the braces are not empty: the|-delimited option labels inside the braces are then rendered as a drop-down menu with the specified limited set of options. TheDEFAULTsubclause, if provided, determines which option is pre-selected (if it is omitted, or the<defaultOption>does not match any of the options, then the first option is pre-selected). TheMINIMUMsubclause can be used in conjunction with an empty first/default option, to force the user to make an explicit selection. For example:custom dialog var runType "Run Type:" {|Calibration|Free Spelling} minimum 1
BUTTONS {<button1>|<button2>|...} [DEFAULT <defaultButton>] [ESCAPE <escapeButton>]- This explicitly overrides the sequence of buttons at the bottom of the dialog. The button label designated as
DEFAULT, if any, will be the one that gets highlighted by default and bound to the enter/return keystroke. If you do not specify a default, then "Ok" will be assumed to be the default button; if the designated default does not appear in the list of buttons, the buttons will all have equal status with no return-keystroke binding). The button label designated asESCAPE, if any, is the one that is bound to the escape keystroke, and pressing this button is equivalent to closing the dialog without making a selection (theCUSTOM DIALOGcommand will return the empty string in that case, and no environment variables will be touched). You will probably not need to configure the buttons explicitly in most cases. In dialogs withoutVARclauses (where you are simply displaying messages to the user), theBUTTONS {Ok} DEFAULT Okconfiguration is assumed. In dialogs with one or moreVARclauses (where you are asking the user for information), theBUTTONS {cancel|Ok} DEFAULT Ok ESCAPE cancelconfiguration is assumed.
TITLE <text>- This overrides the default dialog title "BCI2000".
SPACING <N>- Supply an integer value
Nto specify the vertical spacing between successiveMESSAGEand/orVARelements.
WIDTH <N>- Supply an integer value
Nto specify the minimum width of the dialog in pixels.
HEIGHT <N>- Supply an integer value
Nto specify the minimum width of the dialog in pixels.
LEFT <N>- Supply an integer value
Nto specify the horizontal coordinate of the dialog's left edge, in pixels.
TOP <N>- Supply an integer value
Nto specify the vertical coordinate of the dialog's top edge, in pixels.