Skip to content

Commit dada394

Browse files
author
minjk-bl
committed
Add allowModule option to DataSelector app
1 parent 76a275a commit dada394

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

visualpython/js/com/com_Kernel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,13 +654,13 @@ define([
654654
});
655655
}
656656

657-
getDataList(dataTypeList=[], excludeList=[]) {
657+
getDataList(dataTypeList=[], excludeList=[], allowModule=false) {
658658
// use function command to get variable list of selected data types
659659
var cmdSB = '_vp_print(_vp_get_variables_list(None))';
660660
if (!dataTypeList || dataTypeList.length <= 0) {
661661
dataTypeList = [];
662662
}
663-
cmdSB = com_util.formatString('_vp_print(_vp_get_variables_list({0}, {1}))', JSON.stringify(dataTypeList), JSON.stringify(excludeList));
663+
cmdSB = com_util.formatString('_vp_print(_vp_get_variables_list({0}, {1}, {2}))', JSON.stringify(dataTypeList), JSON.stringify(excludeList), allowModule?'True':'False');
664664

665665
var that = this;
666666
return new Promise(function(resolve, reject) {

visualpython/js/com/component/DataSelector.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ define([
5555
value: null, // pre-defined value
5656
finish: null, // callback after selection (value, dtype)
5757
select: null, // callback after selection from suggestInput (value, dtype)
58-
allowDataType: null,
58+
allowDataType: null, // list of allowed data types
5959
// additional options
6060
classes: '',
6161
placeholder: 'Select variable',
6262
required: false,
63+
allowModule: false,
6364
...this.prop
6465
}
6566

@@ -312,13 +313,18 @@ define([
312313
loadVariables() {
313314
let that = this;
314315
// Searchable variable types
315-
let types = [
316+
let types = [];
317+
if (this.prop.allowModule) {
318+
types = ['module'];
319+
}
320+
types = [
321+
...types,
316322
...vpConfig.getDataTypes(),
317323
// ML Data types
318324
...vpConfig.getMLDataTypes()
319325
];
320326

321-
vpKernel.getDataList(types).then(function(resultObj) {
327+
vpKernel.getDataList(types, [], this.prop.allowModule).then(function(resultObj) {
322328
var varList = JSON.parse(resultObj.result);
323329
// re-mapping variable list
324330
varList = varList.map(obj => {

visualpython/python/variableCommand.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,22 @@ def _vp_get_type(var=None):
4747
return str(type(var).__name__)
4848

4949

50-
def _vp_get_variables_list(types, exclude_types=[]):
50+
def _vp_get_variables_list(types, exclude_types=[], allow_module=False):
5151
"""
5252
Get Variable list in types
5353
"""
5454
# notUsingVariables = ['_html', '_nms', 'NamespaceMagics', '_Jupyter', 'In', 'Out', 'exit', 'quit', 'get_ipython']
5555
# notUsingTypes = ['module', 'function', 'builtin_function_or_method', 'instance', '_Feature', 'type', 'ufunc']
56+
not_using_types = _VP_NOT_USING_TYPES
5657

5758
varList = []
5859
searchList = globals()
5960
if (type(types) == list) and (len(types) > 0):
6061
varList = [{'varName': v, 'varType': type(eval(v)).__name__, 'varInfo': _vp_get_variable_info(eval(v))} for v in searchList if (not v.startswith('_')) & (v not in _VP_NOT_USING_VAR) & (type(eval(v)).__name__ not in exclude_types) & (type(eval(v)).__name__ in types)]
6162
else:
62-
varList = [{'varName': v, 'varType': type(eval(v)).__name__, 'varInfo': _vp_get_variable_info(eval(v))} for v in searchList if (not v.startswith('_')) & (v not in _VP_NOT_USING_VAR) & (type(eval(v)).__name__ not in exclude_types) & (type(eval(v)).__name__ not in _VP_NOT_USING_TYPES)]
63+
if allow_module == True:
64+
not_using_types.remove('module')
65+
varList = [{'varName': v, 'varType': type(eval(v)).__name__, 'varInfo': _vp_get_variable_info(eval(v))} for v in searchList if (not v.startswith('_')) & (v not in _VP_NOT_USING_VAR) & (type(eval(v)).__name__ not in exclude_types) & (type(eval(v)).__name__ not in not_using_types)]
6366

6467
return varList
6568

0 commit comments

Comments
 (0)