Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/blocks/mrc_call_python_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const FUNCTION_KIND_MODULE = 'module';
const FUNCTION_KIND_STATIC = 'static';
const FUNCTION_KIND_CONSTRUCTOR = 'constructor';
const FUNCTION_KIND_INSTANCE = 'instance';
const FUNCTION_KIND_INSTANCE_WITHIN = 'instance_within';

const RETURN_TYPE_NONE = 'None';

Expand Down Expand Up @@ -127,6 +128,11 @@ const CALL_PYTHON_FUNCTION = {
tooltip = 'Calls the function ' + className + '.' + functionName + '.';
break;
}
case FUNCTION_KIND_INSTANCE_WITHIN: {
const functionName = this.getFieldValue(pythonUtils.FIELD_FUNCTION_NAME);
tooltip = 'Calls the method ' + functionName + '.';
break;
}
default:
throw new Error('mrcVarKind must be "module", "static", "constructor", or "instance".')
}
Expand Down Expand Up @@ -238,6 +244,11 @@ const CALL_PYTHON_FUNCTION = {
.appendField('.')
.appendField(createFieldNonEditableText(''), pythonUtils.FIELD_FUNCTION_NAME);
break;
case FUNCTION_KIND_INSTANCE_WITHIN:
this.appendDummyInput()
.appendField('call')
.appendField(createFieldNonEditableText(''), pythonUtils.FIELD_FUNCTION_NAME);
break;
default:
throw new Error('mrcVarKind must be "module", "static", "constructor", or "instance".')
}
Expand Down Expand Up @@ -301,6 +312,14 @@ export const pythonFromBlock = function(
argStartIndex = 1; // Skip the self argument.
break;
}
case FUNCTION_KIND_INSTANCE_WITHIN: {
const callPythonFunctionBlock = block as CallPythonFunctionBlock;
const functionName = (callPythonFunctionBlock.mrcActualFunctionName)
? callPythonFunctionBlock.mrcActualFunctionName
: block.getFieldValue(pythonUtils.FIELD_FUNCTION_NAME);
code = 'self.' + functionName;
break;
}
}
code += '(' + generateCodeForArguments(callPythonFunctionBlock, generator, argStartIndex) + ')';
if (block.outputConnection) {
Expand Down