IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
blockmenu.m
Go to the documentation of this file.
1 %> @ingroup guigroup
2 %> @file
3 %> @brief Class Selection Dialog
4 %>
5 %> @image html Screenshot-blockmenu.png
6 %>
7 %> <h3>Input parameters (varargin)</h3>
8 %> @arg rootclassname
9 %> @arg dsnames
10 %> <h3>Output</h3>
11 %> Structure containing the following fields: flag_ok, params, classname
12 function varargout = blockmenu(varargin)
13 
14 % Begin initialization code - DO NOT EDIT
15 gui_Singleton = 1;
16 gui_State = struct('gui_Name', mfilename, ...
17  'gui_Singleton', gui_Singleton, ...
18  'gui_OpeningFcn', @blockmenu_OpeningFcn, ...
19  'gui_OutputFcn', @blockmenu_OutputFcn, ...
20  'gui_LayoutFcn', [] , ...
21  'gui_Callback', []);
22 
23 % This was the default what-to-do with in arguments; this is the first time I am using them, so won't just delete the
24 % shit.
25 if nargin && ischar(varargin{1})
26  gui_State.gui_Callback = str2func(varargin{1});
27 end
28 
29 if nargout
30  [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
31 else
32  gui_mainfcn(gui_State, varargin{:});
33 end
34 % End initialization code - DO NOT EDIT
35 
36 
37 
38 
39 %> @cond
40 % --- Executes just before blockmenu is made visible.
41 function blockmenu_OpeningFcn(hObject, eventdata, handles, varargin) %#ok<*INUSL>
42 %
43 
44 if length(varargin) < 1
45  varargin{1} = 'block';
46 end;
47 if length(varargin) < 2
48  varargin{2} = [];
49 end;
50 
51 [rootclassname, dsnames] = varargin{[1, 2]};
52 
53 
54 handles.input.rootclassname = rootclassname;
55 handles.input.dsnames = dsnames;
56 % handles.input.prefix_behaviour = prefix_behaviour;
57 handles.output.flag_ok = 0;
58 
59 
60 %%% Population
61 
62 
63 % Resolves datasets.
64 flag_ds = ~isempty(dsnames);
65 if flag_ds
66  for i = 1:length(dsnames)
67  datasets(i) = evalin('base', [dsnames{i} ';']);
68  end;
69  inputclass = class(datasets(1));
70 else
71  inputclass = '';
72  datasets = [];
73 end;
74 
75 handles.input.datasets = datasets;
76 list = classmap_get_list(rootclassname, inputclass); % descendants of classname that have class(data) as inputclass
77 handles.list = list;
78 handles.idx_in = 1:numel(list); % Indexes of list elements to show
79 handles.al = lower(itemlist2cell(list));
80 handles.a = itemlist2cell(list);
81 
82 uicontrol(handles.edit_filter); % Sets focus
83 
84 guidata(hObject, handles);
85 
86 % The popupmenu ...
87 populate_listbox(handles);
88 
89 gui_set_position(hObject);
90 o = eval([rootclassname ';']);
91 set(hObject, 'Color', o.color);
92 set(handles.textChoose, 'BackgroundColor', o.color); % I don't know how to make staticText transparent so far, or inherit parent's color
93 set(handles.text_filter, 'BackgroundColor', o.color); % I don't know how to make staticText transparent so far, or inherit parent's color
94 
95 % if numel(list) == 1
96 % % If there is only one option, does an automatic OK button
97 % do_ok(handles);
98 % end;
99 
100 
101 
102 
103 
104 
105 %################################################################
106 %################################################################
107 
108 %#################################
109 function do_ok(handles)
110 
111 if length(get(handles.listboxType, 'String')) > 0 %#ok<*ISMT>
112  which = handles.idx_in(get(handles.listboxType, 'Value'));
113  item = handles.list(which);
114  if ~item.flag_final
115  msgbox('Please select a deepest-level option!');
116  else
117  classname = handles.list(which).name;
118  try
119  obj = eval([classname, ';']);
120  result = obj.get_params(handles.input.datasets);
121 
122  if result.flag_ok
123  handles.output.flag_ok = 1;
124  handles.output.classname = classname;
125  handles.output.params = result.params;
126  guidata(handles.figure1, handles);
127  uiresume;
128  end;
129 
130  catch ME
131  send_error(ME);
132  end;
133 
134  end;
135 end;
136 
137 
138 %#################################
139 function populate_listbox(handles)
140 filter = fel(get(handles.edit_filter, 'String'));
141 if ~isempty(filter)
142  filter = lower(filter);
143  idxs = find(cellfun(@(x) (~isempty(x)), cellfun(@(x) (findstr(filter, x)), handles.al, 'UniformOutput', 0)));
144  b = zeros(1, numel(handles.a));
145  for i = 1:numel(idxs)
146  if handles.list(idxs(i)).flag_final
147  b(idxs(i)) = 1;
148  ob = handles.list(idxs(i));
149  while 1
150  if ob.level == 1
151  break;
152  end;
153  ob = handles.list(ob.parentindex);
154  b(ob.index) = 1;
155  end;
156  end;
157  end;
158  handles.idx_in = find(b);
159 else
160  handles.idx_in = 1:numel(handles.a);
161 end;
162 
163 set(handles.listboxType, 'Value', 1);
164 set(handles.listboxType, 'String', handles.a(handles.idx_in));
165 guidata(handles.figure1, handles);
166 
167 %################################################################
168 %################################################################
169 
170 
171 
172 
173 
174 % --- Outputs from this function are returned to the command line.
175 function varargout = blockmenu_OutputFcn(hObject, eventdata, handles)
176 try
177  uiwait(handles.figure1);
178  handles = guidata(hObject); % Handles is not a handle(!), so gotta retrieve it again to see changes in .output
179  varargout{1} = handles.output;
180  delete(gcf);
181 catch %#ok<*CTCH>
182  output.flag_ok = 0;
183  output.params = {};
184  varargout{1} = output;
185 end;
186 
187 % --- Executes on button press in pushbuttonOk.
188 function pushbuttonOk_Callback(hObject, eventdata, handles) %#ok<*DEFNU>
189 do_ok(handles);
190 
191 % --- Executes on selection change in listboxType.
192 function listboxType_Callback(hObject, eventdata, handles)
193 if strcmp(get(handles.figure1, 'SelectionType'), 'open') % This is how you detect a double-click in MATLAB
194  do_ok(handles);
195 end;
196 
197 
198 % --- Executes during object creation, after setting all properties.
199 function listboxType_CreateFcn(hObject, eventdata, handles) %#ok<*INUSD>
200 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
201  set(hObject,'BackgroundColor','white');
202 end
203 
204 % --- Executes on button press in pushbutton_cancel.
205 function pushbutton_cancel_Callback(hObject, eventdata, handles)
206 close();
207 
208 
209 
210 function edit_filter_Callback(hObject, eventdata, handles)
211 populate_listbox(handles);
212 
213 % --- Executes during object creation, after setting all properties.
214 function edit_filter_CreateFcn(hObject, eventdata, handles)
215 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
216  set(hObject,'BackgroundColor','white');
217 end
218 
219 function edit_filter_KeyPressFcn(hObject, eventdata, handles)
220 %> @endcond
function blockmenu(in varargin)
Base Block class.
Definition: block.m:2