Skip to content

Commit 1b440af

Browse files
committed
[neuroj] make neuroj work on Octave 4.2
1 parent f4df6c6 commit 1b440af

File tree

3 files changed

+74
-66
lines changed

3 files changed

+74
-66
lines changed

jdict.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
end
174174
i = i + 1;
175175
end
176-
if (~(isempty(idxkey(end).subs) && strcmp(idxkey(end).type, '()')))
176+
if (~(isempty(idxkey(end).subs) && (strcmp(idxkey(end).type, '()') || strcmp(idxkey(end).type, '{}'))))
177177
val = jdict(val);
178178
end
179179
end

neuroj.m

Lines changed: 72 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
%
1010
% input:
1111
% command: a string, must be one of
12+
% 'gui':
13+
% - start a GUI and interactively browse datasets
1214
% 'list':
1315
% - if followed by nothing, list all databases
1416
% - if database is given, list its all datasets
@@ -26,7 +28,6 @@
2628
% regular expression pattern
2729
% - if dataset is a struct, find database using
2830
% the _find API
29-
% 'gui': start a GUI and interactively browse datasets
3031
%
3132
% admin commands (require database admin credentials):
3233
% 'put': create database, create dataset under a dataset, or
@@ -69,77 +70,19 @@
6970
return
7071
end
7172

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
13274

13375
if (nargin == 1 && strcmp(cmd, 'gui'))
134-
fmMain = figure;
76+
fmMain = figure('numbertitle', 'off', 'name', 'NeuroJSON.io Dataset Browser');
13577
tbTool = uitoolbar(fmMain);
136-
btLoadDb = uipushtool(tbTool, 'ClickedCallback', @loaddb);
78+
btLoadDb = uipushtool(tbTool, 'tooltipstring', 'List databases', 'ClickedCallback', @loaddb);
13779
if (~isoctavemesh)
138-
btLoadDb.CData = rand(40, 40, 3);
80+
btLoadDb.CData = zeros(40, 40, 3);
13981
end
14082
lsDb = uicontrol(fmMain, 'tooltipstring', 'Database', 'style', 'listbox', 'units', 'normalized', 'position', [0 0 1 / 5 1], 'Callback', @loadds, 'KeyPressFcn', @loadds);
14183
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]);
14386
return
14487
end
14588

@@ -310,4 +253,68 @@ function expandjsontree(src, event)
310253
end
311254
end
312255

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
313320
end

test/run_jsonlab_test.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ function run_jsonlab_test(tests)
443443
test_jsonlab('jd.(''key1'').(''subkey1'')', @savejson, jd.('key1').('subkey1'), '[1]', 'compact', 1);
444444
test_jsonlab('jd.(''key1'').(''subkey3'')', @savejson, jd.('key1').('subkey3'), '[8,"test",{"subsubkey1":0}]', 'compact', 1);
445445
test_jsonlab('jd.(''key1'').(''subkey3'')()', @savejson, jd.('key1').('subkey3')(), '[8,"test",{"subsubkey1":0}]', 'compact', 1);
446+
test_jsonlab('jd.(''key1'').(''subkey3'').v()', @savejson, class(jd.('key1').('subkey3').v()), '"cell"', 'compact', 1);
446447
test_jsonlab('jd.(''key1'').(''subkey3'').v(1)', @savejson, jd.('key1').('subkey3').v(1), '[8]', 'compact', 1);
447448
test_jsonlab('jd.(''key1'').(''subkey3'').v(3).(''subsubkey1'')', @savejson, jd.('key1').('subkey3').v(3).('subsubkey1'), '[0]', 'compact', 1);
448449
test_jsonlab('jd.(''key1'').(''subkey3'').v(2).v()', @savejson, jd.('key1').('subkey3').v(2).v(), '"test"', 'compact', 1);

0 commit comments

Comments
 (0)