7070 return
7171end
7272
73- global fmMain lsDb lsDs lsJSON txValue
74-
7573if (nargin == 1 && strcmp(cmd , ' gui' ))
76- fmMain = figure(' numbertitle' , ' off' , ' name' , ' NeuroJSON.io Dataset Browser' );
77- tbTool = uitoolbar(fmMain );
78- btLoadDb = uipushtool(tbTool , ' tooltipstring' , ' List databases' , ' ClickedCallback' , @loaddb );
74+ handles.fmMain = figure(' numbertitle' , ' off' , ' name' , ' NeuroJSON.io Dataset Browser' );
75+ tbTool = uitoolbar(handles .fmMain );
76+ handles.lsDb = uicontrol(handles .fmMain , ' tooltipstring' , ' Database' , ' style' , ' listbox' , ' units' , ' normalized' , ' position' , [0 0 1 / 5 1 ]);
77+ handles.lsDs = uicontrol(handles .fmMain , ' tooltipstring' , ' Dataset' , ' style' , ' listbox' , ' units' , ' normalized' , ' position' , [1 / 5 0 1 / 4 1 ]);
78+ handles.lsJSON = uicontrol(handles .fmMain , ' tooltipstring' , ' Data' , ' style' , ' listbox' , ' units' , ' normalized' , ' position' , [9 / 20 1 / 4 1 - 9 / 20 3 / 4 ]);
79+ handles.txValue = uicontrol(handles .fmMain , ' tooltipstring' , ' Value' , ' style' , ' edit' , ' max' , 50 , ' HorizontalAlignment' , ' left' , ' units' , ' normalized' , ' position' , [9 / 20 0 1 - 9 / 20 1 / 4 ]);
80+ handles.t0 = cputime ;
81+ handles.hbox = msgbox(' Loading data' , ' modal' );
82+ set(handles .hbox , ' visible' , ' off' );
83+ set(handles .fmMain , ' userdata' , handles );
84+ set(handles .lsDb , ' Callback' , @(src , events ) loadds(src , events , handles .fmMain ));
85+ set(handles .lsDs , ' Callback' , @(src , events ) loaddsdata(src , events , handles .fmMain ));
86+ set(handles .lsJSON , ' Callback' , @(src , events ) expandjsontree(src , events , handles .fmMain ));
87+
88+ btLoadDb = uipushtool(tbTool , ' tooltipstring' , ' List databases' , ' ClickedCallback' , @(src , events ) loaddb(src , events , handles .fmMain ));
7989 if (~isoctavemesh )
8090 btLoadDb.CData = zeros(40 , 40 , 3 );
8191 end
82- lsDb = uicontrol(fmMain , ' tooltipstring' , ' Database' , ' style' , ' listbox' , ' units' , ' normalized' , ' position' , [0 0 1 / 5 1 ], ' Callback' , @loadds , ' KeyPressFcn' , @loadds );
83- lsDs = uicontrol(fmMain , ' tooltipstring' , ' Dataset' , ' style' , ' listbox' , ' units' , ' normalized' , ' position' , [1 / 5 0 1 / 4 1 ], ' Callback' , @loaddsdata , ' KeyPressFcn' , @loaddsdata );
84- lsJSON = uicontrol(fmMain , ' tooltipstring' , ' Data' , ' style' , ' listbox' , ' units' , ' normalized' , ' position' , [9 / 20 1 / 4 1 - 9 / 20 3 / 4 ], ' Callback' , @expandjsontree , ' KeyPressFcn' , @expandjsontree );
85- txValue = uicontrol(fmMain , ' tooltipstring' , ' Value' , ' style' , ' edit' , ' max' , 50 , ' HorizontalAlignment' , ' left' , ' units' , ' normalized' , ' position' , [9 / 20 0 1 - 9 / 20 1 / 4 ]);
8692 return
8793end
8894
253259 end
254260end
255261
256- function loaddb(src , event )
257- global lsDb
262+ function loaddb(src , event , hwin )
263+ handles = get(hwin , ' userdata' );
264+ set(handles .hbox , ' visible' , ' on' );
258265dbs = neuroj(' list' );
259- set(lsDb , ' String' , (cellfun(@(x ) x .id , dbs .database , ' UniformOutput' , false )));
266+ set(handles .lsDb , ' String' , (cellfun(@(x ) x .id , dbs .database , ' UniformOutput' , false )));
267+ set(handles .hbox , ' visible' , ' off' );
260268
261- function loadds(src , event )
262- global fmMain lsDb lsDs
263- get( fmMain , ' SelectionType ' );
264- if isfield(event , ' Key' ) && strcmp(event .Key , ' enter' ) || strcmp(get(fmMain , ' SelectionType' ), ' open' )
269+ function loadds(src , event , hwin )
270+ handles = get( hwin , ' userdata ' );
271+ set( handles . hbox , ' visible ' , ' on ' );
272+ if ( isfield(event , ' Key' ) && strcmp(event .Key , ' enter' )) || strcmp(get(handles . fmMain , ' SelectionType' ), ' open' ) || ( cputime - handles . t0 ) < 0.01
265273 idx = get(src , ' value' );
266274 dbs = get(src , ' string' );
267275 dslist = neuroj(' list' , dbs{idx });
268276 dslist.dataset = dslist .dataset(arrayfun(@(x ) x .id(1 ) ~= ' _' , dslist .dataset ));
269- set(lsDs , ' string' , {dslist .dataset .id }, ' value' , 1 );
270- set(lsDb , ' tag' , dbs{idx });
277+ set(handles . lsDs , ' string' , {dslist .dataset .id }, ' value' , 1 );
278+ set(handles . lsDb , ' tag' , dbs{idx });
271279end
280+ handles.t0 = cputime ;
281+ set(hwin , ' userdata' , handles );
282+ set(handles .hbox , ' visible' , ' off' );
272283
273- function loaddsdata(src , event )
274- global fmMain lsDb lsJSON
275- get( fmMain , ' SelectionType ' );
276- if isfield(event , ' Key' ) && strcmp(event .Key , ' enter' ) || strcmp(get(fmMain , ' SelectionType' ), ' open' )
284+ function loaddsdata(src , event , hwin )
285+ handles = get( hwin , ' userdata ' );
286+ set( handles . hbox , ' visible ' , ' on ' );
287+ if isfield(event , ' Key' ) && strcmp(event .Key , ' enter' ) || strcmp(get(handles . fmMain , ' SelectionType' ), ' open' ) || ( cputime - handles . t0 ) < 0.01
277288 idx = get(src , ' value' );
278289 dbs = get(src , ' string' );
279- dbid = get(lsDb , ' tag' );
290+ dbid = get(handles . lsDb , ' tag' );
280291 datasets = jdict(neuroj(' get' , dbid , dbs{idx }));
281- set(lsJSON , ' string' , cellfun(@(x ) decodevarname(x ), datasets .keys(), ' UniformOutput' , false ), ' value' , 1 );
282- set(lsJSON , ' userdata' , datasets );
283- set(lsJSON , ' tag' , ' ' );
292+ set(handles . lsJSON , ' string' , cellfun(@(x ) decodevarname(x ), datasets .keys(), ' UniformOutput' , false ), ' value' , 1 );
293+ set(handles . lsJSON , ' userdata' , datasets );
294+ set(handles . lsJSON , ' tag' , ' ' );
284295end
296+ handles.t0 = cputime ;
297+ set(hwin , ' userdata' , handles );
298+ set(handles .hbox , ' visible' , ' off' );
285299
286- function expandjsontree(src , event )
287- global fmMain lsJSON txValue
288- if (~isa(get(lsJSON , ' userdata' ), ' jdict' ))
300+ function expandjsontree(src , event , hwin )
301+ handles = get( hwin , ' userdata ' );
302+ if (~isa(get(handles . lsJSON , ' userdata' ), ' jdict' ))
289303 return
290304end
291- get(fmMain , ' SelectionType' );
292- if isfield(event , ' Key' ) && strcmp(event .Key , ' enter' ) || strcmp(get(fmMain , ' SelectionType' ), ' open' )
305+ set(handles .hbox , ' visible' , ' on' );
306+
307+ if isfield(event , ' Key' ) && strcmp(event .Key , ' enter' ) || strcmp(get(handles .fmMain , ' SelectionType' ), ' open' ) || (cputime - handles .t0 ) < 0.01
293308 idx = get(src , ' value' );
294309 dbs = get(src , ' string' );
295- rootpath = get(lsJSON , ' tag' );
296- datasets = get(lsJSON , ' userdata' );
310+ rootpath = get(handles . lsJSON , ' tag' );
311+ datasets = get(handles . lsJSON , ' userdata' );
297312 if (isempty(rootpath ))
298313 rootpath = ' $' ;
299314 end
@@ -310,11 +325,14 @@ function expandjsontree(src, event)
310325 if (~strcmp(rootpath , ' $' ))
311326 subitem = {' ..' , subitem{: }};
312327 end
313- set(lsJSON , ' string' , subitem , ' value' , 1 );
314- set(lsJSON , ' tag' , rootpath );
328+ set(handles . lsJSON , ' string' , subitem , ' value' , 1 );
329+ set(handles . lsJSON , ' tag' , rootpath );
315330 else
316- set(txValue , ' string' , datasets .v());
331+ set(handles . txValue , ' string' , datasets .v());
317332 end
318333 catch
319334 end
320335end
336+ handles.t0 = cputime ;
337+ set(hwin , ' userdata' , handles );
338+ set(handles .hbox , ' visible' , ' off' );
0 commit comments