-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoptionsGUI.m
More file actions
128 lines (119 loc) · 4.23 KB
/
Copy pathoptionsGUI.m
File metadata and controls
128 lines (119 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function optsOut = optionsGUI(opts, tooltips)
caller = dbstack;
if length(caller)>1
caller = caller(2).name;
else
caller = 'Unknown Function';
end
if nargin<2
tooltips = [];
end
optsOut = opts;
[optNames, sortorder]= sort(fieldnames(opts)); %#ok<FLPST>
N = length(optNames);
titlesX = 5; titlesW = 80;
etX = titlesX+titlesW+20; etW = 100;
H = 15;
H0 =10;
HOK = 40;
handles.F = figure('Name', caller, 'pos', [600 600 titlesW+etW+40 N*(H+H0)+HOK+5], 'toolbar', 'none', 'menubar', 'none', 'resize', 'off', 'numbertitle', 'off');
handles.OK = uicontrol(...
'Units','pixels',...
'Parent',handles.F,...
'Style','pushbutton',...
'Position',[etX 5 etW 20],...
'String','OK',...
'Callback', @OK);
handles.ET = [];
for n = 1:length(optNames)
handles.titles(n) = uicontrol(...
'Units','pixels',...
'Parent',handles.F,...
'Style','text',...
'Position',[titlesX HOK+(n-1)*(H+H0)-4 titlesW H],...
'String',optNames(n));
handles.reset(n) = uicontrol(...
'Units','pixels',...
'Parent',handles.F,...
'Style','pushbutton',...
'Position',[etX+etW+5 HOK+(n-1)*(H+H0)-4 10 H],...
'String','',...
'Callback', @(varargin)(reset(n)));
reset(n);
end
waitfor(handles.F);
function parseET(src,n)
type=class(opts.(optNames{n}));
set(handles.titles(n), 'ForegroundColor', 'k')
try
switch type
case 'logical'
optsOut.(optNames{n}) = eval(src.String{src.Value});
case 'double'
optsOut.(optNames{n}) = eval(['[' src.String ']']);
case 'cell'
optsOut.(optNames{n}) = eval(src.String{src.Value});
case 'char'
optsOut.(optNames{n}) = src.String;
end
catch ME
%make the text error
set(handles.titles(n), 'ForegroundColor', 'r')
end
end
function OK(varargin)
for k = 1:length(handles.ET)
parseET(get(handles.ET(k)), k)
end
delete(handles.F)
end
function reset(n)
set(handles.titles(n), 'ForegroundColor', 'k')
optsOut.(optNames{n}) = opts.(optNames{n});
if length(handles.ET)>=n
delete(handles.ET(n));
end
switch class(opts.(optNames{n}))
case 'logical' %make a drop down menu
handles.ET(n) = uicontrol(...
'Units','pixels',...
'Parent',handles.F,...
'Style','popupmenu',...
'String', {'false', 'true'},...
'Value', double(opts.(optNames{n}))+1,...
'Position',[etX HOK+(n-1)*(H+H0) etW H],...
'callback', @(src,evnt)(parseET(src, n)));
case 'double'
handles.ET(n) = uicontrol(...
'Units','pixels',...
'Parent',handles.F,...
'Style','edit',...
'String', num2str(opts.(optNames{n})),...
'Position',[etX HOK+(n-1)*(H+H0)-4 etW H],...
'callback', @(src,evnt)(parseET(src, n)));
case 'char'
handles.ET(n) = uicontrol(...
'Units','pixels',...
'Parent',handles.F,...
'Style','edit',...
'String', opts.(optNames{n}),...
'Position',[etX HOK+(n-1)*(H+H0)-4 etW H],...
'callback', @(src,evnt)(parseET(src, n)));
case 'cell' %make a drop down
handles.ET(n) = uicontrol(...
'Units','pixels',...
'Parent',handles.F,...
'Style','popupmenu',...
'String', opts.(optNames{n}),...
'Value', 1,...
'Position',[etX HOK+(n-1)*(H+H0) etW H],...
'callback', @(src,evnt)(parseET(src, n)));
otherwise
keyboard
end
if isfield(tooltips, optNames{n})
set(handles.titles(n), 'TooltipString', tooltips.(optNames{n}));
set(handles.ET(n), 'TooltipString', tooltips.(optNames{n}));
end
end
end