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
55 changes: 55 additions & 0 deletions src/blocks/mrc_none.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @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.
*/

/**
* @fileoverview Block for Python's None keyword.
* @author [email protected] (Liz Looney)
*/


import * as Blockly from 'blockly';
import { MRC_STYLE_NONE } from '../themes/styles'
import { Order, PythonGenerator } from 'blockly/python';

export const BLOCK_NAME = 'mrc_none';

export function setup() {
Blockly.Blocks[BLOCK_NAME] = {
init: function() {
this.setOutput(true); // no type for None
this.appendDummyInput()
.appendField(Blockly.Msg.NONE);
this.setStyle(MRC_STYLE_NONE);
this.setTooltip(Blockly.Msg.NONE_TOOLTIP);
},
};
}

export function pythonFromBlock(
_block: Blockly.Block,
_generator: PythonGenerator,
): [string, Order] {
return ['None', Order.ATOMIC];
}

export function createNoneShadowValue(): any {
return {
'shadow': {
'type': 'mrc_none',
},
}
}
36 changes: 19 additions & 17 deletions src/blocks/setup_custom_blocks.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@

import * as CallPythonFunction from './mrc_call_python_function';
import * as ClassMethodDef from './mrc_class_method_def';
import * as Component from './mrc_component';
import * as Event from './mrc_event';
import * as EventHandler from './mrc_event_handler';
import * as GetParameter from './mrc_get_parameter';
import * as GetPythonEnumValue from './mrc_get_python_enum_value';
import * as GetPythonVariable from './mrc_get_python_variable';
import * as ListAddItem from './mrc_list_add_item';
import * as MathMinMax from './mrc_math_min_max';
import * as Mechanism from './mrc_mechanism';
import * as MechanismComponentHolder from './mrc_mechanism_component_holder';
import * as MiscComment from './mrc_misc_comment';
import * as MiscEvaluateButIgnoreResult from './mrc_misc_evaluate_but_ignore_result';
import * as SetPythonVariable from './mrc_set_python_variable';
import * as ClassMethodDef from './mrc_class_method_def';
import * as Mechanism from './mrc_mechanism';
import * as Component from './mrc_component';
import * as MechanismContainerHolder from './mrc_mechanism_component_holder';
import * as Port from './mrc_port';
import * as None from './mrc_none';
import * as OpModeDetails from './mrc_opmode_details';
import * as Event from './mrc_event';
import * as GetParameter from './mrc_get_parameter';
import * as ParameterMutator from './mrc_param_container'
import * as EventHandler from './mrc_event_handler';
import * as Port from './mrc_port';
import * as SetPythonVariable from './mrc_set_python_variable';

const customBlocks = [
CallPythonFunction,
ClassMethodDef,
Component,
Event,
EventHandler,
GetParameter,
GetPythonEnumValue,
GetPythonVariable,
ListAddItem,
MathMinMax,
Mechanism,
MechanismComponentHolder,
MiscComment,
MiscEvaluateButIgnoreResult,
SetPythonVariable,
Mechanism,
Component,
MechanismContainerHolder,
Port,
None,
OpModeDetails,
Event,
GetParameter,
ParameterMutator,
EventHandler,
Port,
SetPythonVariable,
];

export const setup = function(forBlock: any) {
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export function customTokens(t: (key: string) => string): typeof Blockly.Msg {
EVALUATE_BUT_IGNORE_RESULT: t('BLOCKLY.EVALUATE_BUT_IGNORE_RESULT'),
EVALUATE_BUT_IGNORE_RESULT_TOOLTIP:
t('BLOCKLY.TOOLTIP.EVALUATE_BUT_IGNORE_RESULT'),
NONE: t('BLOCKLY.NONE'),
NONE_TOOLTIP: t('BLOCKLY.TOOLTIP.NONE'),
AUTO: t('BLOCKLY.AUTO'),
TELEOP: t('BLOCKLY.TELEOP'),
TEST: t('BLOCKLY.TEST'),
Expand Down
5 changes: 2 additions & 3 deletions src/blocks/utils/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import { getAlias } from './python';
import * as variable from './variable';
import { createNoneShadowValue } from '../mrc_none';


export function valueForFunctionArgInput(argType: string, argDefaultValue: string): any {
Expand Down Expand Up @@ -50,9 +51,7 @@ export function valueForFunctionArgInput(argType: string, argDefaultValue: strin
break;
case 'str':
if (argDefaultValue === 'None') {
// TODO(lizlooney): Make a block for python None
// In RobotPy function hal.report(), the arg named feature has a default value of None.
return null;
return createNoneShadowValue()
}
// If argDefaultValue is surrounded by single or double quotes, it's a literal string.
if (argDefaultValue.startsWith("'") && argDefaultValue.endsWith("'") ||
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"COMPONENTS": "Components",
"EVENTS": "Events",
"EVALUATE_BUT_IGNORE_RESULT": "evaluate but ignore result",
"NONE": "None",
"TYPE": "Type",
"ENABLED": "Enabled",
"DISPLAY_NAME": "Display Name",
Expand All @@ -57,6 +58,7 @@
"NO_MECHANISM_CONTENTS": "No Mechanism Contents",
"TOOLTIP":{
"EVALUATE_BUT_IGNORE_RESULT": "Executes the connected block and ignores the result. Allows you to call a function and ignore the return value.",
"NONE": "Returns None.",
"OPMODE_TYPE": "What sort of OpMode this is",
"OPMODE_ENABLED": "Whether the OpMode is shown on Driver Station",
"OPMODE_NAME": "The name shown on the Driver Station. If blank will use the class name.",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"COMPONENTS": "Componentes",
"EVENTS": "Eventos",
"EVALUATE_BUT_IGNORE_RESULT": "evaluar pero ignorar resultado",
"NONE": "None",
"TYPE": "Tipo",
"ENABLED": "Habilitado",
"DISPLAY_NAME": "Nombre a Mostrar",
Expand All @@ -58,6 +59,7 @@
"NO_MECHANISM_CONTENTS": "Sin Contenido de Mecanismo",
"TOOLTIP": {
"EVALUATE_BUT_IGNORE_RESULT": "Ejecuta el bloque conectado e ignora el resultado. Te permite llamar una función e ignorar el valor de retorno.",
"NONE": "No devuelve ninguno.",
"OPMODE_TYPE": "Qué tipo de OpMode es este",
"OPMODE_ENABLED": "Si el OpMode se muestra en la Estación del Conductor",
"OPMODE_NAME": "El nombre mostrado en la Estación del Conductor. Si está en blanco usará el nombre de la clase.",
Expand All @@ -82,4 +84,4 @@
"TEST": "Prueba"
}
}
}
}
2 changes: 2 additions & 0 deletions src/i18n/locales/he/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"COMPONENTS": "רכיבים",
"EVENTS": "אירועים",
"EVALUATE_BUT_IGNORE_RESULT": "הערך אך התעלם מהתוצאה",
"NONE": "אַף לֹא אֶחָד",
"TYPE": "סוג",
"ENABLED": "מופעל",
"DISPLAY_NAME": "שם תצוגה",
Expand All @@ -57,6 +58,7 @@
"NO_MECHANISM_CONTENTS": "אין תוכן מנגנון",
"TOOLTIP":{
"EVALUATE_BUT_IGNORE_RESULT": "מריץ את הבלוק המחובר ומתעלם מהתוצאה. מאפשר לך לקרוא לפונקציה ולהתעלם מערך ההחזרה.",
"NONE": "החזרות אין.",
"OPMODE_TYPE": "איזה סוג של מצב פעולה זה",
"OPMODE_ENABLED": "האם מצב הפעולה מוצג בתחנת הנהג",
"OPMODE_NAME": "השם המוצג בתחנת הנהג. אם ריק ישתמש בשם הכיתה.",
Expand Down
6 changes: 5 additions & 1 deletion src/themes/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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_NONE = 'mrc_style_none';
export const MRC_STYLE_CLASS_BLOCKS = 'mrc_style_class_blocks';
export const MRC_CATEGORY_STYLE_METHODS = 'mrc_category_style_methods';
export const MRC_STYLE_MECHANISMS = 'mrc_style_mechanisms';
Expand All @@ -38,6 +39,7 @@ export const MRC_CATEGORY_STYLE_COMPONENTS = 'mrc_category_style_components';
export const add_mrc_styles = function (theme: Blockly.Theme): Blockly.Theme {
const procedureStyle = theme.blockStyles['procedure_blocks'];
const variableStyle = theme.blockStyles['variable_blocks'];
const logicStyle = theme.blockStyles['logic_blocks'];

theme.setBlockStyle(MRC_STYLE_FUNCTIONS, {
...procedureStyle
Expand Down Expand Up @@ -74,12 +76,14 @@ export const add_mrc_styles = function (theme: Blockly.Theme): Blockly.Theme {
colourTertiary: "#494984",
hat: ""
});
theme.setBlockStyle(MRC_STYLE_NONE, {
...logicStyle
});
theme.setBlockStyle(MRC_STYLE_MECHANISMS, {
colourPrimary: "#5b61a5",
colourSecondary: "#dedfed",
colourTertiary: "#494e84",
hat: ""

});
theme.setBlockStyle(MRC_STYLE_COMPONENTS, {
colourPrimary: "#5b80a5",
Expand Down
2 changes: 1 addition & 1 deletion src/toolbox/logic_category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const getCategory = () => (
},
{
kind: 'block',
type: 'logic_null',
type: 'mrc_none',
},
{
kind: 'block',
Expand Down