8000 Added JSON converter + fixed default `py` code in the `Python` compon… · totaljs/flowstreamcomponents@bea06ec · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit bea06ec

Browse files
committed
Added JSON converter + fixed default py code in the Python component.
1 parent 15689e0 commit bea06ec

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

components/python.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
exports.id = 'python';
44
exports.name = 'Python';
55
exports.group = 'Common';
6-
exports.version = '1';
6+
exports.version = '2';
77
exports.icon = 'ti ti-script';
88
exports.author = 'Total.js';
9-
exports.config = { code: '# Python code\nimport json\n\ndata = json.loads(sys.argv[1])\n\nprint(data)' };
9+
exports.config = { code: '# Python code\nimport sys\nimport json\n\ndata = json.loads(sys.argv[1])\n\nprint(data)', json: true };
1010
exports.inputs = [{ id: 'input', name: 'Input' }];
1111
exports.outputs = [{ id: 'output', name: 'Output' }, { id: 'error', name: 'Error' }];
1212
exports.meta = { settingswidth: 1200 };
@@ -27,10 +27,11 @@
2727
}
2828

2929
F.Child.execFile('python3', [filename, JSON.stringify($.data)], function(err, response, error) {
30-
if (err)
30+
if (err) {
3131
$.send('error', error || err);
32-
else
33-
$.send('output', response);
32+
} else {
33+
$.send('output', config.json ? response.parseJSON(true) : response);
34+
}
3435
});
3536
};
3637

@@ -51,7 +52,8 @@
5152

5253
<settings>
5354
<div class="padding">
54-
<ui-component name="codemirror" path="?.code" config="type:python;minheight:300;parent:auto;margin:60;tabs:true;trim:true"></ui-component>
55+
<ui-component name="codemirror" path="?.code" config="type:python;minheight:300;parent:auto;margin:80;tabs:true;trim:true" class="m"></ui-component>
56+
<ui-component name="input" path="?.json" config="type:checkbox">Parse output to JSON</ui-component>
5557
</div>
5658
</settings>
5759

0 commit comments

Comments
 (0)
0