Controls
You can create several kinds of run-time widgets and read/ write the values of the widget during the experiment. Controls will issue a trigger when their value is changed. This event is captured in the Pynapse event loop. You can also read the value of the controls inside any Python method.
Controls Tab |
Runtime Tab Showing Example Controls |
You can add up to 50 custom controls. Right-click on the 'Main' page to add new controls. Drag and drop the controls in the tree to set the order they are displayed at runtime. Right-click on 'Main' to add a new page of controls. Controls will be organized into tabs at runtime.
Runtime Control Tab Example |
Phase Presets
User-adjustable controls (Toggle Switch, Spin Control, Slider Control, and Combo Box) can be assigned preset values for different phases of the experiment, so you can quickly change several controls with the click of a button. When combined with Session Controls you can tell the Pynapse scheduler how many trials / blocks of each phase you want to run and it automatically handles it for you. The Session Scheduler takes this one step further and allows you to schedule the sequence of phase preset conditions to run in order.
Check the Phase Presets box to enable this feature and make a comma-separated list with your own custom phase name. Check the Preset Controlled option on any control you want to add to the presets.
Assign controls to phases |
At run-time, the phase presets appear as buttons. Setup the control values that you want, then right-click on one of the phase buttons and select 'Store To Preset' to assign those values to that button. The button text changes to black to indicate preset values have been assigned, and the button outline changes to blue to indicate it is currently selected.
Phase buttons: assigned, selected, and undefined |
Right-click on a phase button for more options:
Locking
Choose when to lock controls during the experiment.
Note
The Lock icon next to the icon at runtime must be locked in order for this setting
to take effect. The Lock icon is unlocked by default in Preview
mode, and locked
by default in Record
mode.
Slider control in unlocked and locked state |
Slot Methods for Responding to Control Changes
This control slot method captures status information about the controls. It is available as method definitions inside Pynapse states for each control. Write a method with this name to react to the corresponding event.
All custom control slot methods s_{CONTROL_NAME}_change
. Type def s_
in the
Pynapse Code Editor and let the code completion do the work for you.
Example
Print a slider value when it is changed at runtime.
class Always: # StateID = 0
# capture any control value change with this
def s_MyControl_change(value):
print('new control value', value)
Methods
All control methods have the form p_Control.{CONTROL_NAME}.{METHOD}
. Type p_
in the Pynapse Code Editor
and let the code completion do the work for you.
Status
read
value = p_Control.MyControl.read()
Read the current value of the control. For combo box controls, the value is the index into the list of items in the combo box.
Example
Set the next stimulation based on a slider value controlled by the user at runtime.
class PrepStim: #StateID = 0
def s_State_enter():
# get next stim ready
wave_freq = p_Control.MyControl.read()
p_Param.p_Param.WaveFreq_write(wave_freq)
Control
write
p_Control.MyControl.write(val)
Write a new value to the control. For combo box controls, the value is the index into the list of items in the combo box. For Led Indicators, the value is the index into the list of colors.
Example
Increment a progress bar.
class EndTrial: #StateID = 0
def s_State_enter():
# increment completed trials counter
p_Metric.completed_trials.inc()
# update progress bar
progress = 100 * p_Metric.completed_trials.read() / p_Metric.desired_trials.read()
p_Control.MyProgressBar.write(progress)
lock
p_Control.MyControl.lock()
Lock the control to prevent modification.
Example
Lock control during a portion of the experiment
class StartTrial: #StateID = 0
def s_State_enter():
p_Control.MyControl.lock()
unlock
p_Control.MyControl.unlock()
Unlock the control to allow modification.
Example
Unlock control during a portion of the experiment
class EndTrial: #StateID = 0
def s_State_enter():
p_Metric.completed_trials.inc()
p_Control.MyControl.unlock()
setRange
p_Control.MyControl.setRange(minv, maxv)
Set the value range of the control between minv and maxv. This is only valid for Spin Control, Slider Control, and Progress Bar controls.
setLabel
p_Control.MyControl.setLabel(txt)
Sets the text label of the control.
hide
p_Control.MyControl.hide()
Hides the control on the user interface.
show
p_Control.MyControl.show()
Shows the control on the user interface.