User Reference:Custom GUI Commands: Difference between revisions
No edit summary |
|||
| Line 1: | Line 1: | ||
BCI2000's [[User_Reference:Operator_Module_Scripting|Operator Module Scripting]] capabilities include the ability to prompt the user for specific pieces of information via modal Qt dialogs. | BCI2000's [[User_Reference:Operator_Module_Scripting|Operator Module Scripting]] capabilities include the ability to prompt the user for specific pieces of information via modal Qt dialogs. | ||
=====CHOOSE ...===== | |||
The | The <code>CHOOSE</code> family of commands prompt the user to specify file or directory paths, via the Qt graphical user interface. | ||
; <code>CHOOSE INPUT FILE</code> (or equivalently <code>CHOOSE FILE</code>, or <code>CHOOSE INPUT</code>) : Prompt the user to select a single existing file. Print the resulting file path. | |||
; <code>CHOOSE INPUT FILES</code> (or equivalently<code>CHOOSE FILES</code>) : Prompt the user to select one or more existing files. Print the resulting file paths. | |||
; <code>CHOOSE OUTPUT FILE</code> (or equivalently<code>CHOOSE OUTPUT</code>) : Prompt the user to specify a file into which data can be saved (with an overwrite confirmation dialog if it already exists). Print the resulting file path. | |||
; <code>CHOOSE DIRECTORY</code> : Prompt the user to specify a directory. Print the resulting directory path. | |||
The commands may be followed by one or more of the following optional clauses (they must appear in this order): | |||
; <code>[OF] TYPE[S] <.ext1> [<.ext2> ...]</code> | |||
: Limit the choice, by default, to files that have the specified extension(s). This clause cannot be used with <code>CHOOSE DIRECTORY</code>. Instead of a file extension (starting with a dot) you can alternatively specify a glob pattern (containing a star). | |||
<code> | ; <code>[STARTING] AT <dir> ...]</code> (or equivalently <code>IN</code> or <code>FROM</code>) | ||
<code> | : Specify where the dialog's file-system navigation should start (by default, it | ||
in the | will start in the current working directory). | ||
; <code> | ; <code>[WITH] PROMPT <msg></code> | ||
: | : Specify the text prompt at the top of the dialog. | ||
Examples: | |||
<pre> | |||
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" | |||
</pre> | |||
=====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 <code>CUSTOM DIALOG</code> command can be followed by as many clauses as you like. The main types of clause are <code>MESSAGE</code> and <code>VAR</code> clauses, which are rendered from top to bottom in the dialog, in the order you provide. | |||
; <code>MESSAGE <msg></code> | |||
: Each message is rendered as text, word-wrapped to the width of the dialog window. <code>MESSAGE ""</code> can be used to create blank vertical space. Any message that consists only of dashes (e.g. <code>MESSAGE ---</code>) will be turned into a horizontal rule. Simplest example: <pre>custom dialog message "Hello world!"</pre> | |||
; <code>VAR <variableName> <visibleLabel> {} [DEFAULT <defaultText>] [MINIMUM <nChars>]</code> | ; <code>VAR <variableName> <visibleLabel> {} [DEFAULT <defaultText>] [MINIMUM <nChars>]</code> | ||
| Line 32: | Line 50: | ||
; <code>BUTTONS {<button1>|<button2>|...} [DEFAULT <defaultButton>] [ESCAPE <escapeButton>]</code> | ; <code>BUTTONS {<button1>|<button2>|...} [DEFAULT <defaultButton>] [ESCAPE <escapeButton>]</code> | ||
: This explicitly overrides the sequence of buttons at the bottom of the dialog. The button label designated as <code>DEFAULT</code>, if any, | : This explicitly overrides the sequence of buttons at the bottom of the dialog. The button label designated as <code>DEFAULT</code>, 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 as <code>ESCAPE</code>, 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 (the <code>CUSTOM DIALOG</code> command 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 with no <code>VAR</code> clauses (where you are simply displaying messages to the user), the <code>BUTTONS {Ok} DEFAULT Ok</code> configuration is assumed. In dialogs with one or more <code>VAR</code> clauses (where you are asking the user for information), the <code>BUTTONS {cancel|Ok} DEFAULT Ok ESCAPE cancel</code> configuration is assumed. | |||
; <code>TITLE <text></code> | |||
: This overrides the default dialog title "BCI2000". | |||
; <code>SPACING <N></code> | |||
: Supply an integer value <code>N</code> to specify the vertical spacing between successive <code>MESSAGE</code> and/or <code>VAR</code> elements. | |||
; <code>WIDTH <N></code> | |||
: Supply an integer value <code>N</code> to specify the minimum width of the dialog in pixels. | |||
; <code>HEIGHT <N></code> | |||
: Supply an integer value <code>N</code> to specify the minimum width of the dialog in pixels. | |||
; <code>LEFT <N></code> | |||
: Supply an integer value <code>N</code> to specify the horizontal coordinate of the dialog's left edge, in pixels. | |||
; <code>TOP <N></code> | |||
: Supply an integer value <code>N</code> to specify the vertical coordinate of the dialog's top edge, in pixels. | |||
Revision as of 20:29, 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)- Prompt the user to select a single existing file. Print the resulting file path.
CHOOSE INPUT FILES(or equivalentlyCHOOSE FILES)- Prompt the user to select one or more existing files. Print the resulting file paths.
CHOOSE OUTPUT FILE(or equivalentlyCHOOSE OUTPUT)- Prompt the user to specify a file into which data can be saved (with an overwrite confirmation dialog if it already exists). Print the resulting file path.
CHOOSE DIRECTORY- Prompt the user to specify a directory. Print 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> ...]- Limit the choice, by default, 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> ...](or equivalentlyINorFROM)- Specify where the dialog's file-system navigation should start (by default, it
will start in the current working directory).
[WITH] PROMPT <msg>- Specify 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.
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 with no
VARclauses (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.