|
9 | 9 | % |
10 | 10 | % input: |
11 | 11 | % command: a string, must be one of |
| 12 | +% 'gui': |
| 13 | +% - start a GUI and interactively browse datasets |
12 | 14 | % 'list': |
13 | 15 | % - if followed by nothing, list all databases |
14 | 16 | % - if database is given, list its all datasets |
|
26 | 28 | % regular expression pattern |
27 | 29 | % - if dataset is a struct, find database using |
28 | 30 | % the _find API |
29 | | -% 'gui': start a GUI and interactively browse datasets |
30 | 31 | % |
31 | 32 | % admin commands (require database admin credentials): |
32 | 33 | % 'put': create database, create dataset under a dataset, or |
|
69 | 70 | return |
70 | 71 | end |
71 | 72 |
|
72 | | -function loaddb(src, event) |
73 | | - dbs = neuroj('list'); |
74 | | - set(lsDb, 'String', (cellfun(@(x) x.id, dbs.database, 'UniformOutput', false))); |
75 | | -end |
76 | | - |
77 | | -function loadds(src, event) |
78 | | - get(fmMain, 'SelectionType'); |
79 | | - if isfield(event, 'Key') && strcmp(event.Key, 'enter') || strcmp(get(fmMain, 'SelectionType'), 'open') |
80 | | - idx = get(src, 'value'); |
81 | | - dbs = get(src, 'string'); |
82 | | - dslist = neuroj('list', dbs{idx}); |
83 | | - set(lsDs, 'string', {dslist.dataset.id}); |
84 | | - set(lsDb, 'tag', dbs{idx}); |
85 | | - end |
86 | | -end |
87 | | - |
88 | | -function loaddsdata(src, event) |
89 | | - get(fmMain, 'SelectionType'); |
90 | | - if isfield(event, 'Key') && strcmp(event.Key, 'enter') || strcmp(get(fmMain, 'SelectionType'), 'open') |
91 | | - idx = get(src, 'value'); |
92 | | - dbs = get(src, 'string'); |
93 | | - dbid = get(lsDb, 'tag'); |
94 | | - datasets = jdict(neuroj('get', dbid, dbs{idx})); |
95 | | - set(lsJSON, 'string', cellfun(@(x) decodevarname(x), datasets.keys(), 'UniformOutput', false), 'value', 1); |
96 | | - set(lsJSON, 'userdata', datasets); |
97 | | - set(lsJSON, 'tag', ''); |
98 | | - end |
99 | | -end |
100 | | - |
101 | | -function expandjsontree(src, event) |
102 | | - if (~isa(get(lsJSON, 'userdata'), 'jdict')) |
103 | | - return |
104 | | - end |
105 | | - get(fmMain, 'SelectionType'); |
106 | | - if isfield(event, 'Key') && strcmp(event.Key, 'enter') || strcmp(get(fmMain, 'SelectionType'), 'open') |
107 | | - idx = get(src, 'value'); |
108 | | - dbs = get(src, 'string'); |
109 | | - rootpath = get(lsJSON, 'tag'); |
110 | | - datasets = get(lsJSON, 'userdata'); |
111 | | - if (isempty(rootpath)) |
112 | | - rootpath = '$'; |
113 | | - end |
114 | | - if (strcmp(dbs{idx}, '..')) |
115 | | - rootpath = regexprep(rootpath, '\[[^\]]+\]$', ''); |
116 | | - else |
117 | | - rootpath = [rootpath '["' dbs{idx} '"]']; |
118 | | - end |
119 | | - |
120 | | - datasets = datasets.(rootpath); |
121 | | - try |
122 | | - subitem = cellfun(@(x) decodevarname(x), datasets.keys(), 'UniformOutput', false); |
123 | | - if (~strcmp(rootpath, '$')) |
124 | | - subitem = {'..', subitem{:}}; |
125 | | - end |
126 | | - set(lsJSON, 'string', subitem, 'value', 1); |
127 | | - set(lsJSON, 'tag', rootpath); |
128 | | - catch |
129 | | - end |
130 | | - end |
131 | | -end |
| 73 | +global fmMain lsDb lsDs lsJSON txValue |
132 | 74 |
|
133 | 75 | if (nargin == 1 && strcmp(cmd, 'gui')) |
134 | | - fmMain = figure; |
| 76 | + fmMain = figure('numbertitle', 'off', 'name', 'NeuroJSON.io Dataset Browser'); |
135 | 77 | tbTool = uitoolbar(fmMain); |
136 | | - btLoadDb = uipushtool(tbTool, 'ClickedCallback', @loaddb); |
| 78 | + btLoadDb = uipushtool(tbTool, 'tooltipstring', 'List databases', 'ClickedCallback', @loaddb); |
137 | 79 | if (~isoctavemesh) |
138 | | - btLoadDb.CData = rand(40, 40, 3); |
| 80 | + btLoadDb.CData = zeros(40, 40, 3); |
139 | 81 | end |
140 | 82 | lsDb = uicontrol(fmMain, 'tooltipstring', 'Database', 'style', 'listbox', 'units', 'normalized', 'position', [0 0 1 / 5 1], 'Callback', @loadds, 'KeyPressFcn', @loadds); |
141 | 83 | lsDs = uicontrol(fmMain, 'tooltipstring', 'Dataset', 'style', 'listbox', 'units', 'normalized', 'position', [1 / 5 0 1 / 4 1], 'Callback', @loaddsdata, 'KeyPressFcn', @loaddsdata); |
142 | | - lsJSON = uicontrol(fmMain, 'tooltipstring', 'Data', 'style', 'listbox', 'units', 'normalized', 'position', [9 / 20 0 1 - 9 / 20 1], 'Callback', @expandjsontree, 'KeyPressFcn', @expandjsontree); |
| 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]); |
143 | 86 | return |
144 | 87 | end |
145 | 88 |
|
@@ -310,4 +253,68 @@ function expandjsontree(src, event) |
310 | 253 | end |
311 | 254 | end |
312 | 255 |
|
| 256 | +function loaddb(src, event) |
| 257 | +global lsDb |
| 258 | +dbs = neuroj('list'); |
| 259 | +set(lsDb, 'String', (cellfun(@(x) x.id, dbs.database, 'UniformOutput', false))); |
| 260 | + |
| 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') |
| 265 | + idx = get(src, 'value'); |
| 266 | + dbs = get(src, 'string'); |
| 267 | + dslist = neuroj('list', dbs{idx}); |
| 268 | + 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}); |
| 271 | +end |
| 272 | + |
| 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') |
| 277 | + idx = get(src, 'value'); |
| 278 | + dbs = get(src, 'string'); |
| 279 | + dbid = get(lsDb, 'tag'); |
| 280 | + 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', ''); |
| 284 | +end |
| 285 | + |
| 286 | +function expandjsontree(src, event) |
| 287 | +global fmMain lsJSON txValue |
| 288 | +if (~isa(get(lsJSON, 'userdata'), 'jdict')) |
| 289 | + return |
| 290 | +end |
| 291 | +get(fmMain, 'SelectionType'); |
| 292 | +if isfield(event, 'Key') && strcmp(event.Key, 'enter') || strcmp(get(fmMain, 'SelectionType'), 'open') |
| 293 | + idx = get(src, 'value'); |
| 294 | + dbs = get(src, 'string'); |
| 295 | + rootpath = get(lsJSON, 'tag'); |
| 296 | + datasets = get(lsJSON, 'userdata'); |
| 297 | + if (isempty(rootpath)) |
| 298 | + rootpath = '$'; |
| 299 | + end |
| 300 | + if (strcmp(dbs{idx}, '..')) |
| 301 | + rootpath = regexprep(rootpath, '\[[^\]]+\]$', ''); |
| 302 | + else |
| 303 | + rootpath = [rootpath '["' dbs{idx} '"]']; |
| 304 | + end |
| 305 | + |
| 306 | + datasets = datasets.(rootpath); |
| 307 | + try |
| 308 | + if (iscell(datasets.keys())) |
| 309 | + subitem = cellfun(@(x) decodevarname(x), datasets.keys(), 'UniformOutput', false); |
| 310 | + if (~strcmp(rootpath, '$')) |
| 311 | + subitem = {'..', subitem{:}}; |
| 312 | + end |
| 313 | + set(lsJSON, 'string', subitem, 'value', 1); |
| 314 | + set(lsJSON, 'tag', rootpath); |
| 315 | + else |
| 316 | + set(txValue, 'string', datasets.v()); |
| 317 | + end |
| 318 | + catch |
| 319 | + end |
313 | 320 | end |
0 commit comments