70
70
return
71
71
end
72
72
73
- global fmMain lsDb lsDs lsJSON txValue
74
-
75
73
if (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 ));
79
89
if (~isoctavemesh )
80
90
btLoadDb.CData = zeros(40 , 40 , 3 );
81
91
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 ]);
86
92
return
87
93
end
88
94
253
259
end
254
260
end
255
261
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' );
258
265
dbs = 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' );
260
268
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
265
273
idx = get(src , ' value' );
266
274
dbs = get(src , ' string' );
267
275
dslist = neuroj(' list' , dbs{idx });
268
276
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 });
271
279
end
280
+ handles.t0 = cputime ;
281
+ set(hwin , ' userdata' , handles );
282
+ set(handles .hbox , ' visible' , ' off' );
272
283
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
277
288
idx = get(src , ' value' );
278
289
dbs = get(src , ' string' );
279
- dbid = get(lsDb , ' tag' );
290
+ dbid = get(handles . lsDb , ' tag' );
280
291
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' , ' ' );
284
295
end
296
+ handles.t0 = cputime ;
297
+ set(hwin , ' userdata' , handles );
298
+ set(handles .hbox , ' visible' , ' off' );
285
299
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' ))
289
303
return
290
304
end
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
293
308
idx = get(src , ' value' );
294
309
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' );
297
312
if (isempty(rootpath ))
298
313
rootpath = ' $' ;
299
314
end
@@ -310,11 +325,14 @@ function expandjsontree(src, event)
310
325
if (~strcmp(rootpath , ' $' ))
311
326
subitem = {' ..' , subitem{: }};
312
327
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 );
315
330
else
316
- set(txValue , ' string' , datasets .v());
331
+ set(handles . txValue , ' string' , datasets .v());
317
332
end
318
333
catch
319
334
end
320
335
end
336
+ handles.t0 = cputime ;
337
+ set(hwin , ' userdata' , handles );
338
+ set(handles .hbox , ' visible' , ' off' );
0 commit comments