From 20cd11e5fc848730858180ef4f6e8c4be0919d3f Mon Sep 17 00:00:00 2001 From: Hatem Oraby Date: Mon, 14 May 2018 18:26:50 +0200 Subject: [PATCH 1/3] ParameterGUI: Arrange switch cases sequentially --- .../Plugins/ParameterGUI/BpodParameterGUI.m | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Functions/Plugins/ParameterGUI/BpodParameterGUI.m b/Functions/Plugins/ParameterGUI/BpodParameterGUI.m index cc41c15..327572e 100644 --- a/Functions/Plugins/ParameterGUI/BpodParameterGUI.m +++ b/Functions/Plugins/ParameterGUI/BpodParameterGUI.m @@ -126,9 +126,6 @@ case 'edit' BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 1; BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'edit', 'String', num2str(ThisParam), 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); - case 'edittext' - BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 8; - BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'edit', 'String', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); case 'text' BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 2; BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'text', 'String', num2str(ThisParam), 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); @@ -167,6 +164,9 @@ ThisPanelHeight = ThisPanelHeight + (htable.Position(4)-25); BpodSystem.GUIHandles.ParameterGUI.Panels.(ThisTabPanelNames{p}).Position(4) = ThisPanelHeight; BpodSystem.GUIData.ParameterGUI.LastParamValues{ParamNum} = htable.Data; + case 'edittext' + BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 8; + BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'edit', 'String', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); otherwise error('Invalid parameter style specified. Valid parameters are: ''edit'', ''text'', ''checkbox'', ''popupmenu'', ''togglebutton'', ''pushbutton'''); end @@ -216,13 +216,6 @@ elseif Params.GUI.(ThisParamName) ~= ThisParamLastValue set(ThisParamHandle, 'String', num2str(GUIParam)); end - case 8 % Edit Text - GUIParam = get(ThisParamHandle, 'String'); - if ~strcmpi(GUIParam, ThisParamLastValue) - Params.GUI.(ThisParamName) = GUIParam; - elseif ~strcmpi(Params.GUI.(ThisParamName), ThisParamLastValue) - set(ThisParamHandle, 'String', GUIParam); - end case 2 % Text GUIParam = Params.GUI.(ThisParamName); Text = GUIParam; @@ -265,6 +258,13 @@ elseif any(argData(:) ~= ThisParamLastValue(:)) % Change originated in TaskParameters propagates to the GUI ThisParamHandle.Data = argData; end + case 8 % Edit Text + GUIParam = get(ThisParamHandle, 'String'); + if ~strcmpi(GUIParam, ThisParamLastValue) + Params.GUI.(ThisParamName) = GUIParam; + elseif ~strcmpi(Params.GUI.(ThisParamName), ThisParamLastValue) + set(ThisParamHandle, 'String', GUIParam); + end end BpodSystem.GUIData.ParameterGUI.LastParamValues{p} = GUIParam; end From 09cd24598b3eedd5b9e289f9f6bba0cec9914873 Mon Sep 17 00:00:00 2001 From: Hatem Oraby Date: Mon, 14 May 2018 18:27:25 +0200 Subject: [PATCH 2/3] ParameterGUI: Add support for slider component --- Functions/Plugins/ParameterGUI/BpodParameterGUI.m | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Functions/Plugins/ParameterGUI/BpodParameterGUI.m b/Functions/Plugins/ParameterGUI/BpodParameterGUI.m index 327572e..143bef1 100644 --- a/Functions/Plugins/ParameterGUI/BpodParameterGUI.m +++ b/Functions/Plugins/ParameterGUI/BpodParameterGUI.m @@ -167,8 +167,13 @@ case 'edittext' BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 8; BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'edit', 'String', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); + case 'slider' + BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 9; + BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'slider', 'String', ThisParamString,... + 'Value', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12,... + 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center', 'min', 0, 'max', 1); otherwise - error('Invalid parameter style specified. Valid parameters are: ''edit'', ''text'', ''checkbox'', ''popupmenu'', ''togglebutton'', ''pushbutton'''); + error('Invalid parameter style specified. Valid parameters are: ''edit'', ''text'', ''checkbox'', ''popupmenu'', ''togglebutton'', ''pushbutton'', ''slider'''); end InPanelPos = InPanelPos + 35; ParamNum = ParamNum + 1; @@ -265,6 +270,13 @@ elseif ~strcmpi(Params.GUI.(ThisParamName), ThisParamLastValue) set(ThisParamHandle, 'String', GUIParam); end + case 9 % Slider + GUIParam = get(ThisParamHandle, 'Value'); + if GUIParam ~= ThisParamLastValue + Params.GUI.(ThisParamName) = GUIParam; + elseif Params.GUI.(ThisParamName) ~= ThisParamLastValue + set(ThisParamHandle, 'Value', GUIParam); + end end BpodSystem.GUIData.ParameterGUI.LastParamValues{p} = GUIParam; end From 715327bae9128c70b7076f0c8bcd54a0d507eb81 Mon Sep 17 00:00:00 2001 From: Hatem Oraby Date: Wed, 16 May 2018 14:28:18 +0200 Subject: [PATCH 3/3] GUI: Add support for callback --- .../Plugins/ParameterGUI/BpodParameterGUI.m | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/Functions/Plugins/ParameterGUI/BpodParameterGUI.m b/Functions/Plugins/ParameterGUI/BpodParameterGUI.m index 143bef1..a9890ed 100644 --- a/Functions/Plugins/ParameterGUI/BpodParameterGUI.m +++ b/Functions/Plugins/ParameterGUI/BpodParameterGUI.m @@ -102,8 +102,11 @@ else BpodSystem.GUIData.ParameterGUI.LastParamValues{ParamNum} = ThisParam; end + ThisParamStyle = 'edit'; % Just initial assumption + ThisParamCB = ''; if isfield(Meta, ThisParamName) if isstruct(Meta.(ThisParamName)) + ValidField = false; if isfield(Meta.(ThisParamName), 'Style') ThisParamStyle = Meta.(ThisParamName).Style; if isfield(Meta.(ThisParamName), 'String') @@ -111,38 +114,41 @@ else ThisParamString = ''; end - else - error(['Style not specified for parameter ' ThisParamName '.']) + ValidField = true; + end + if isfield(Meta.(ThisParamName), 'Callback') + ThisParamCB = Meta.(ThisParamName).Callback; + ValidField = true; + end + if ~ValidField + error(['Style or Callback not specified for parameter ' ThisParamName '.']) end else error(['GUIMeta entry for ' ThisParamName ' must be a struct.']) end - else - ThisParamStyle = 'edit'; - ThisParamValue = NaN; end BpodSystem.GUIHandles.ParameterGUI.Labels(ParamNum) = uicontrol(htab,'Style', 'text', 'String', ThisParamName, 'Position', [HPos+5 VPos+InPanelPos 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); switch lower(ThisParamStyle) case 'edit' BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 1; - BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'edit', 'String', num2str(ThisParam), 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); + BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'edit', 'String', num2str(ThisParam), 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center','Callback',ThisParamCB); case 'text' BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 2; - BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'text', 'String', num2str(ThisParam), 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); + BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'text', 'String', num2str(ThisParam), 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center','Callback',ThisParamCB); case 'checkbox' BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 3; - BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'checkbox', 'Value', ThisParam, 'String', ' (check to activate)', 'Position', [HPos+220 VPos+InPanelPos+4 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); + BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'checkbox', 'Value', ThisParam, 'String', ' (check to activate)', 'Position', [HPos+220 VPos+InPanelPos+4 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center','Callback',ThisParamCB); case 'popupmenu' BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 4; - BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'popupmenu', 'String', ThisParamString, 'Value', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); + BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'popupmenu', 'String', ThisParamString, 'Value', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center','Callback',ThisParamCB); case 'togglebutton' % INCOMPLETE BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 5; - BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'togglebutton', 'String', ThisParamString, 'Value', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); + BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'togglebutton', 'String', ThisParamString, 'Value', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center','Callback',ThisParamCB); case 'pushbutton' BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 6; BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'pushbutton', 'String', ThisParamString,... 'Value', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12,... - 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center','Callback',Meta.OdorSettings.Callback); + 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center','Callback',ThisParamCB); case 'table' BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 7; columnNames = fieldnames(Params.(ThisParamName)); @@ -166,12 +172,14 @@ BpodSystem.GUIData.ParameterGUI.LastParamValues{ParamNum} = htable.Data; case 'edittext' BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 8; - BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'edit', 'String', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center'); + BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'edit', 'String', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12, 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center','Callback',ThisParamCB); case 'slider' BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 9; - BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'slider', 'String', ThisParamString,... + BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'slider', 'String', ThisParam,... 'Value', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12,... - 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center', 'min', 0, 'max', 1); + 'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center', 'min', 0, 'max', 1,... + 'Callback',ThisParamCB); + otherwise error('Invalid parameter style specified. Valid parameters are: ''edit'', ''text'', ''checkbox'', ''popupmenu'', ''togglebutton'', ''pushbutton'', ''slider'''); end