Skip to content

GUI: Add support for slider component and for UI callbacks #16

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

oraby
Copy link

@oraby oraby commented May 16, 2018

The pull-request adds support for MATLAB slider and UI callbacks in Bpod.

I assume in the usual use case for slider, the user would add below the slider a 'text' field that reflects the value of the slider. Without a callback, the value of the text field wouldn't be be updated until the next GUI 'sync' is called.
To get real time update of the slider value, one can add a `callback' to the slider handle to update the text value instantly.

An example for creating a slider and its text value while being update by a callback:

%% SliderExample/SliderExample.m
function SliderExample
    global BpodSystem;
    global Settings;
    Settings = BpodSystem.ProtocolSettings;
    if isempty(fieldnames(Settings))
        Settings.GUI.Probability = 0.5;
        Settings.GUIMeta.Probability.Style = 'slider';
        Settings.GUIMeta.Probability.Callback = @UpdateText;
        Settings.GUI.ProbabilityText = Settings.GUI.Probability;
        Settings.GUIMeta.ProbabilityText.Style = 'text';
        Settings.GUIPanels.Panel = {'Probability', 'ProbabilityText'};
        Settings.GUITabs.Example = {'Panel'};
    end
    BpodParameterGUI('init', Settings);

    while BpodSystem.BeingUsed
        Settings = BpodParameterGUI('sync', Settings);
        HandlePauseCondition;
        pause(0.1);
    end
end

%% SliderExample/UpdateText.m
function UpdateText(SliderHandler,~)
    global BpodSystem;
    global Settings ;
    HandlerIdx = find(strcmp(BpodSystem.GUIData.ParameterGUI.ParamNames, 'ProbabilityText'), 1);
    ProbabiliyTextHandler = BpodSystem.GUIHandles.ParameterGUI.Params{HandlerIdx};
    set(ProbabiliyTextHandler, 'String', num2str(SliderHandler.Value));
    % Has to update GUI.ProbabiliyText as well or otherwise it will be
    % over-written in the next GUI sync with the old value.
    Settings.GUI.ProbabilityText = num2str(SliderHandler.Value);
end

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant