Skip to content

Commit 715327b

Browse files
committed
GUI: Add support for callback
1 parent 09cd245 commit 715327b

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

Functions/Plugins/ParameterGUI/BpodParameterGUI.m

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,47 +102,53 @@
102102
else
103103
BpodSystem.GUIData.ParameterGUI.LastParamValues{ParamNum} = ThisParam;
104104
end
105+
ThisParamStyle = 'edit'; % Just initial assumption
106+
ThisParamCB = '';
105107
if isfield(Meta, ThisParamName)
106108
if isstruct(Meta.(ThisParamName))
109+
ValidField = false;
107110
if isfield(Meta.(ThisParamName), 'Style')
108111
ThisParamStyle = Meta.(ThisParamName).Style;
109112
if isfield(Meta.(ThisParamName), 'String')
110113
ThisParamString = Meta.(ThisParamName).String;
111114
else
112115
ThisParamString = '';
113116
end
114-
else
115-
error(['Style not specified for parameter ' ThisParamName '.'])
117+
ValidField = true;
118+
end
119+
if isfield(Meta.(ThisParamName), 'Callback')
120+
ThisParamCB = Meta.(ThisParamName).Callback;
121+
ValidField = true;
122+
end
123+
if ~ValidField
124+
error(['Style or Callback not specified for parameter ' ThisParamName '.'])
116125
end
117126
else
118127
error(['GUIMeta entry for ' ThisParamName ' must be a struct.'])
119128
end
120-
else
121-
ThisParamStyle = 'edit';
122-
ThisParamValue = NaN;
123129
end
124130
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');
125131
switch lower(ThisParamStyle)
126132
case 'edit'
127133
BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 1;
128-
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');
134+
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);
129135
case 'text'
130136
BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 2;
131-
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');
137+
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);
132138
case 'checkbox'
133139
BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 3;
134-
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');
140+
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);
135141
case 'popupmenu'
136142
BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 4;
137-
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');
143+
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);
138144
case 'togglebutton' % INCOMPLETE
139145
BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 5;
140-
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');
146+
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);
141147
case 'pushbutton'
142148
BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 6;
143149
BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'pushbutton', 'String', ThisParamString,...
144150
'Value', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12,...
145-
'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center','Callback',Meta.OdorSettings.Callback);
151+
'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center','Callback',ThisParamCB);
146152
case 'table'
147153
BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 7;
148154
columnNames = fieldnames(Params.(ThisParamName));
@@ -166,12 +172,14 @@
166172
BpodSystem.GUIData.ParameterGUI.LastParamValues{ParamNum} = htable.Data;
167173
case 'edittext'
168174
BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 8;
169-
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');
175+
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);
170176
case 'slider'
171177
BpodSystem.GUIData.ParameterGUI.Styles(ParamNum) = 9;
172-
BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'slider', 'String', ThisParamString,...
178+
BpodSystem.GUIHandles.ParameterGUI.Params{ParamNum} = uicontrol(htab,'Style', 'slider', 'String', ThisParam,...
173179
'Value', ThisParam, 'Position', [HPos+220 VPos+InPanelPos+2 200 25], 'FontWeight', 'normal', 'FontSize', 12,...
174-
'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center', 'min', 0, 'max', 1);
180+
'BackgroundColor','white', 'FontName', 'Arial','HorizontalAlignment','Center', 'min', 0, 'max', 1,...
181+
'Callback',ThisParamCB);
182+
175183
otherwise
176184
error('Invalid parameter style specified. Valid parameters are: ''edit'', ''text'', ''checkbox'', ''popupmenu'', ''togglebutton'', ''pushbutton'', ''slider''');
177185
end

0 commit comments

Comments
 (0)