Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/blocks/mrc_call_python_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export const pythonFromBlock = function(
if (block.outputConnection) {
return [code, Order.FUNCTION_CALL];
} else {
return code; + '\n';
return code + '\n';
}
};

Expand Down
14 changes: 14 additions & 0 deletions src/blocks/mrc_class_method_def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export type Parameter = {
type ClassMethodDefBlock = Blockly.Block & ClassMethodDefMixin & Blockly.BlockSvg;
interface ClassMethodDefMixin extends ClassMethodDefMixinType {
mrcCanChangeSignature: boolean,
mrcCanBeCalledWithinClass: boolean,
mrcCanBeCalledOutsideClass: boolean,
mrcReturnType: string,
mrcParameters: Parameter[],
mrcPythonMethodName: string,
Expand All @@ -57,6 +59,14 @@ type ClassMethodDefExtraState = {
* Can change name and parameters and return type
*/
canChangeSignature: boolean,
/**
* Can be called from within the class.
*/
canBeCalledWithinClass: boolean,
/**
* Can be called from outside the class.
*/
canBeCalledOutsideClass: boolean,
/**
* The return type of the function.
* Use 'None' for no return value.
Expand Down Expand Up @@ -95,6 +105,8 @@ const CLASS_METHOD_DEF = {
this: ClassMethodDefBlock): ClassMethodDefExtraState {
const extraState: ClassMethodDefExtraState = {
canChangeSignature: this.mrcCanChangeSignature,
canBeCalledWithinClass: this.mrcCanBeCalledWithinClass,
canBeCalledOutsideClass: this.mrcCanBeCalledOutsideClass,
returnType: this.mrcReturnType,
params: [],
};
Expand All @@ -118,6 +130,8 @@ const CLASS_METHOD_DEF = {
extraState: ClassMethodDefExtraState
): void {
this.mrcCanChangeSignature = extraState.canChangeSignature;
this.mrcCanBeCalledWithinClass = extraState.canBeCalledWithinClass;
this.mrcCanBeCalledOutsideClass = extraState.canBeCalledOutsideClass;
this.mrcPythonMethodName = extraState.pythonMethodName ? extraState.pythonMethodName : '';
this.mrcReturnType = extraState.returnType;
this.mrcParameters = [];
Expand Down
5 changes: 5 additions & 0 deletions src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as Blockly from 'blockly/core';
import { extendedPythonGenerator } from './extended_python_generator';
import * as commonStorage from '../storage/common_storage';
import { getToolboxJSON } from '../toolbox/toolbox';
import { MethodsCategory} from '../toolbox/methods_category';


const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
Expand All @@ -34,6 +35,7 @@ const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
export class Editor {
private blocklyWorkspace: Blockly.WorkspaceSvg;
private storage: commonStorage.Storage;
private methodsCategory: MethodsCategory;
private currentModule: commonStorage.Module | null = null;
private modulePath: string = '';
private projectPath: string = '';
Expand All @@ -45,6 +47,7 @@ export class Editor {
constructor(blocklyWorkspace: Blockly.WorkspaceSvg, storage: commonStorage.Storage) {
this.blocklyWorkspace = blocklyWorkspace;
this.storage = storage;
this.methodsCategory = new MethodsCategory(blocklyWorkspace);
}

private onChangeWhileLoading(event: Blockly.Events.Abstract) {
Expand Down Expand Up @@ -105,6 +108,7 @@ export class Editor {

public async loadModuleBlocks(currentModule: commonStorage.Module | null) {
this.currentModule = currentModule;
this.methodsCategory.setCurrentModule(currentModule);
if (currentModule) {
this.modulePath = currentModule.modulePath;
this.projectPath = commonStorage.makeProjectPath(currentModule.projectName);
Expand Down Expand Up @@ -219,4 +223,5 @@ export class Editor {
throw e;
}
}

}
6 changes: 5 additions & 1 deletion src/modules/mechanism_start.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"deletable": false,
"extraState": {
"canChangeSignature": false,
"canBeCalledWithinClass": false,
"canBeCalledOutsideClass": false,
"returnType": "None",
"params": [],
"pythonMethodName": "__init__"
Expand All @@ -26,6 +28,8 @@
"deletable": false,
"extraState": {
"canChangeSignature": false,
"canBeCalledWithinClass": false,
"canBeCalledOutsideClass": false,
"returnType": "None",
"params": []
},
Expand All @@ -35,4 +39,4 @@
}
]
}
}
}
6 changes: 5 additions & 1 deletion src/modules/opmode_start.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"deletable": false,
"extraState": {
"canChangeSignature": false,
"canBeCalledWithinClass": false,
"canBeCalledOutsideClass": false,
"returnType": "None",
"params": [],
"pythonMethodName": "__init__"
Expand All @@ -26,6 +28,8 @@
"deletable": false,
"extraState": {
"canChangeSignature": false,
"canBeCalledWithinClass": false,
"canBeCalledOutsideClass": false,
"returnType": "None",
"params": []
},
Expand All @@ -35,4 +39,4 @@
}
]
}
}
}
4 changes: 3 additions & 1 deletion src/modules/robot_start.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"deletable": false,
"extraState": {
"canChangeSignature": false,
"canBeCalledWithinClass": false,
"canBeCalledOutsideClass": false,
"returnType": "None",
"params": [],
"pythonMethodName": "__init__"
Expand All @@ -20,4 +22,4 @@
}
]
}
}
}
15 changes: 10 additions & 5 deletions src/themes/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@ export const MRC_STYLE_ENUM = 'mrc_style_enum';
export const MRC_STYLE_VARIABLES = 'mrc_style_variables';
export const MRC_STYLE_COMMENTS = 'mrc_style_comments';
export const MRC_STYLE_MISC = 'mrc_style_misc';
export const MRC_STYLE_CLASS_BLOCKS = 'mrc_style_class_blocks'
export const MRC_STYLE_CLASS_BLOCKS = 'mrc_style_class_blocks';
export const MRC_CATEGORY_STYLE_METHODS = 'mrc_category_style_methods';

export const add_mrc_styles = function(theme : Blockly.Theme) : Blockly.Theme {
theme.setBlockStyle(MRC_STYLE_FUNCTIONS,{
colourPrimary: "#805ba5",
colourSecondary: "#e6deed",
colourTertiary: "#664984",
hat: ""
hat: ""
});
theme.setBlockStyle(MRC_STYLE_ENUM,{
colourPrimary: "#5ba5a5",
colourSecondary: "#deeded",
colourTertiary: "#498484",
hat: ""
hat: ""
});
theme.setBlockStyle(MRC_STYLE_VARIABLES, {
colourPrimary: "#5ba55b",
Expand All @@ -53,13 +54,17 @@ export const add_mrc_styles = function(theme : Blockly.Theme) : Blockly.Theme {
colourTertiary:"#CDB6E9",
hat:""
});
theme.setBlockStyle(MRC_STYLE_COMMENTS,{
theme.setCategoryStyle(MRC_CATEGORY_STYLE_METHODS, {
colour: '#4A148C',
});

theme.setBlockStyle(MRC_STYLE_COMMENTS, {
colourPrimary: "#5b5ba5",
colourSecondary: "#dedeed",
colourTertiary: "#494984",
hat:""
});
theme.setBlockStyle(MRC_STYLE_MISC,{
theme.setBlockStyle(MRC_STYLE_MISC, {
colourPrimary: "#5b5ba5",
colourSecondary: "#dedeed",
colourTertiary: "#494984",
Expand Down
47 changes: 47 additions & 0 deletions src/toolbox/mechanism_class_methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @author [email protected] (Liz Looney)
*/

import * as toolboxItems from '../toolbox/items';


/**
* The blocks that define the methods for the Mechanism class.
*
* These blocks will be added (if appropriate) to the Methods category in the
* toolbox.
*/
export const mechanism_class_blocks: toolboxItems.Block[] = [
{
kind: 'block',
type: 'mrc_class_method_def',
fields: {
'NAME': 'update',
},
extraState: {
canChangeSignature: false,
canBeCalledWithinClass: false,
canBeCalledOutsideClass: false,
canDelete: false,
returnType: 'None',
params: [],
},
},
];
Loading