Blockly.defineBlocksWithJsonArray([ { "type": "block_print", "message0": "print ( %1 )", "args0": [ { "type": "input_value", "name": "EXP" } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, "colour": 200, "tooltip": "Instruction pour afficher un message à l'écran", "helpUrl": "" }, { "type": "block_free", "message0": "%1", "args0": [ { "type": "field_input", "name": "STR", "text": "expression Python libre" }, ], "inputsInline": true, "output": null, "colour": 185, "tooltip": "Expression Python libre", "helpUrl": "" }, { "type": "block_return", "message0": "return ( %1 )", "args0": [ { "type": "input_value", "name": "EXP" } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, "colour": 150, "tooltip": "Instruction pour renvoyer le résultat d'une fonction", "helpUrl": "" }, { "type": "block_function_call", "message0": "%1( )", "args0": [ { "type": "field_input", "name": "STR", "text": "ma_fonction" }, ], "inputsInline": true, "output": null, "colour": 150, "tooltip": "Appelle une fonction pour l'exécuter", "helpUrl": "" }, { "type": "block_function_call_one", "message0": "%1( %2 )", "args0": [ { "type": "field_input", "name": "STR", "text": "ma_fonction" }, { "type": "input_value", "name": "EXP" } ], "inputsInline": true, "output": null, "colour": 150, "tooltip": "Appelle une fonction pour l'exécuter", "helpUrl": "" }, { "type": "block_function_call_two", "message0": "%1( %2, %3 )", "args0": [ { "type": "field_input", "name": "STR", "text": "ma_fonction" }, { "type": "input_value", "name": "EXP" }, { "type": "input_value", "name": "EXPTWO" } ], "inputsInline": true, "output": null, "colour": 150, "tooltip": "Appelle une fonction pour l'exécuter", "helpUrl": "" }, { "type": "block_function_call_three", "message0": "%1( %2, %3, %4 )", "args0": [ { "type": "field_input", "name": "STR", "text": "ma_fonction" }, { "type": "input_value", "name": "EXP" }, { "type": "input_value", "name": "EXPTWO" }, { "type": "input_value", "name": "EXPTHREE" } ], "inputsInline": true, "output": null, "colour": 150, "tooltip": "Appelle une fonction pour l'exécuter", "helpUrl": "" }, { "type": "block_function_call_four", "message0": "%1( %2, %3, %4, %5 )", "args0": [ { "type": "field_input", "name": "STR", "text": "ma_fonction" }, { "type": "input_value", "name": "EXP" }, { "type": "input_value", "name": "EXPTWO" }, { "type": "input_value", "name": "EXPTHREE" }, { "type": "input_value", "name": "EXPFOUR" } ], "inputsInline": true, "output": null, "colour": 150, "tooltip": "Appelle une fonction pour l'exécuter", "helpUrl": "" }, { "type": "block_set_bool", "message0": "%1 = %2", "args0": [ { "type": "field_variable", "name": "VAR", "variable": "ok", "variableTypes": ["Boolean"], "defaultType": "Boolean" }, { "type": "input_value", "name": "VALUE", "check": "Boolean" } ], "previousStatement": null, "nextStatement": null, "colour": 340, "tooltip": "Affectation de la variable à la valeur d'une expression logique", "helpUrl": "" }, { "type": "block_set_int", "message0": "%1 = %2", "args0": [ { "type": "field_variable", "name": "VAR", "variable": "nombre", "variableTypes": ["Number"], "defaultType": "Number" }, { "type": "input_value", "name": "VALUE", "check": "Number" } ], "previousStatement": null, "nextStatement": null, "colour": 20, "tooltip": "Affectation de la variable à la valeur d'une expression arithmétique", "helpUrl": "" }, { "type": "block_set_str", "message0": "%1 = %2", "args0": [ { "type": "field_variable", "name": "VAR", "variable": "message", "variableTypes": ["String"], "defaultType": "String" }, { "type": "input_value", "name": "VALUE", "check": "String" } ], "previousStatement": null, "nextStatement": null, "colour": 300, "tooltip": "Affectation de la variable à la valeur d'une chaîne de caractères", "helpUrl": "" }, { "type": "block_while", "message0": "while %1 %2 : %3 %4", "args0": [ { "type": "input_dummy" }, { "type": "input_value", "name": "COND", "check": "Boolean", "align": "CENTRE" }, { "type": "input_dummy" }, { "type": "input_statement", "name": "INST" } ], "previousStatement": null, "nextStatement": null, "colour": 240, "tooltip": "Instruction composée, répétant les instructions imbriquées tant que la condition est vraie", "helpUrl": "" }, { "type": "block_function", "message0": "def %1 ( ) : %2 %3", "args0": [ { "type": "field_input", "name": "STR", "text": "ma_fonction" }, { "type": "input_dummy" }, { "type": "input_statement", "name": "INST" } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, "colour": 150, "tooltip": "Définit une fonction.", "helpUrl": "", "extensions": [ "ajoutVariableContextMenu" ] }, { "type": "block_function_one", "message0": "def %1 ( %2 %3 ) : %4 %5", "args0": [ { "type": "field_input", "name": "STR", "text": "ma_fonction" }, { "type": "input_dummy" }, { "type": "input_value", "name": "VAR" }, { "type": "input_dummy" }, { "type": "input_statement", "name": "INST" } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, "colour": 150, "tooltip": "Définit une fonction.", "helpUrl": "", "extensions": [ "ajoutVariableContextMenu" ] }, { "type": "block_function_two", "message0": "def %1 ( %2 %3, %4 %5) : %6 %7", "args0": [ { "type": "field_input", "name": "STR", "text": "ma_fonction" }, { "type": "input_dummy" }, { "type": "input_value", "name": "VAR" }, { "type": "input_dummy" }, { "type": "input_value", "name": "VARTWO" }, { "type": "input_dummy" }, { "type": "input_statement", "name": "INST" } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, "colour": 150, "tooltip": "Définit une fonction.", "helpUrl": "", "extensions": [ "ajoutVariableContextMenu" ] }, { "type": "block_function_three", "message0": "def %1 ( %2 %3, %4 %5, %6 %7) : %8 %9", "args0": [ { "type": "field_input", "name": "STR", "text": "ma_fonction" }, { "type": "input_dummy" }, { "type": "input_value", "name": "VAR" }, { "type": "input_dummy" }, { "type": "input_value", "name": "VARTWO" }, { "type": "input_dummy" }, { "type": "input_value", "name": "VARTHREE" }, { "type": "input_dummy" }, { "type": "input_statement", "name": "INST" } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, "colour": 150, "tooltip": "Définit une fonction.", "helpUrl": "", "extensions": [ "ajoutVariableContextMenu" ] }, { "type": "block_function_four", "message0": "def %1 ( %2 %3, %4 %5, %6 %7, %8 %9) : %10 %11", "args0": [ { "type": "field_input", "name": "STR", "text": "ma_fonction" }, { "type": "input_dummy" }, { "type": "input_value", "name": "VAR" }, { "type": "input_dummy" }, { "type": "input_value", "name": "VARTWO" }, { "type": "input_dummy" }, { "type": "input_value", "name": "VARTHREE" }, { "type": "input_dummy" }, { "type": "input_value", "name": "VARFOUR" }, { "type": "input_dummy" }, { "type": "input_statement", "name": "INST" } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, "colour": 150, "tooltip": "Définit une fonction.", "helpUrl": "", "extensions": [ "ajoutVariableContextMenu" ] }, { "type": "block_for", "message0": "for %1 in range ( %2 %3 ) : %4 %5", "args0": [ { "type": "field_variable", "name": "VAR", "variable": null, "variableTypes": ["Indice"], "defaultType": "Indice" }, { "type": "input_dummy" }, { "type": "input_value", "name": "FIN", "check": "Number" }, { "type": "input_dummy" }, { "type": "input_statement", "name": "INST" } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, "colour": 240, "tooltip": "Instruction composée, répétant les instructions imbriquées pour toutes les valeurs de la variable entre 0 et le nombre donné (exclus).", "helpUrl": "", "extensions": [ "ajoutVariableContextMenu" ] }, { "type": "block_if", "message0": "if %1 : %2 %3", "args0": [ { "type": "input_value", "name": "COND", "check": "Boolean" }, { "type": "input_dummy" }, { "type": "input_statement", "name": "INST" } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, "colour": 240, "tooltip": "Instruction conditionnelle, exécutant les instructions imbriquées si la condition est vraie", "helpUrl": "" }, { "type": "block_ifelse", "message0": "if %1 : %2 %3 else : %4", "args0": [ { "type": "input_value", "name": "COND", "check": "Boolean" }, { "type": "input_dummy" }, { "type": "input_statement", "name": "INST1" }, { "type": "input_statement", "name": "INST2" } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, "colour": 240, "tooltip": "Instruction alternative, exécutant les instructions après : si la condition est vraie, ou sinon les instructions après else : ", "helpUrl": "" }, { "type": "block_get_bool", "message0": "%1", "args0": [ { "type": "field_variable", "name": "VAR", "variable": "ok", "variableTypes": ["Boolean"], "defaultType": "Boolean" } ], "output": "Boolean", "colour": 340, "tooltip": "Variable booléenne, peut prendre la valeur vrai ou faux", "helpUrl": "" }, { "type": "block_true", "message0": "True", "output": "Boolean", "colour": 340, "tooltip": "Constante booléenne, vrai", "helpUrl": "" }, { "type": "block_false", "message0": "False", "output": "Boolean", "colour": 340, "tooltip": "Constante booléenne, faux", "helpUrl": "" }, { "type": "block_and", "message0": "%1 and %2", "args0": [ { "type": "input_value", "name": "ARG1", "check": "Boolean" }, { "type": "input_value", "name": "ARG2", "check": "Boolean" } ], "inputsInline": true, "output": "Boolean", "colour": 340, "tooltip": "Expression booléenne vraie si et seulement si ses deux arguments valent vrai", "helpUrl": "" }, { "type": "block_or", "message0": "%1 or %2", "args0": [ { "type": "input_value", "name": "ARG1", "check": "Boolean" }, { "type": "input_value", "name": "ARG2", "check": "Boolean" } ], "inputsInline": true, "output": "Boolean", "colour": 340, "tooltip": "Expression booléenne vraie si et seulement si au moins l'un de ses deux arguments vaut vrai", "helpUrl": "" }, { "type": "block_not", "message0": "not %1", "args0": [ { "type": "input_value", "name": "ARG", "check": "Boolean" } ], "inputsInline": true, "output": "Boolean", "colour": 340, "tooltip": "Expression booléenne vraie si et seulement si son argument vaut faux", "helpUrl": "" }, { "type": "block_comp", "message0": "%1 %2 %3", "args0": [ { "type": "input_value", "name": "ARG1", "check": [ "Number", "String" ] }, { "type": "field_dropdown", "name": "COMP", "options": [ [ "==", "EGAL" ], [ "!=", "DIFF" ], [ "<", "INF" ], [ "<=", "INFEGAL" ], [ ">", "SUP" ], [ ">=", "SUPEGAL" ] ] }, { "type": "input_value", "name": "ARG2", "check": [ "Number", "String" ] } ], "inputsInline": true, "output": "Boolean", "colour": 340, "tooltip": "Expression booléenne vraie si la comparaison est vérifiée", "helpUrl": "" }, { "type": "block_get_int", "message0": "%1", "args0": [ { "type": "field_variable", "name": "VAR", "variable": "nombre", "variableTypes": ["Number"], "defaultType": "Number" } ], "output": "Number", "colour": 20, "tooltip": "Variable numérique", "helpUrl": "" }, { "type": "block_get_indice", "message0": "%1", "args0": [ { "type": "field_variable", "name": "VAR", "variable": "i", "variableTypes": ["Indice"], "defaultType": "Indice" } ], "output": "Number", "colour": 20, "tooltip": "Variable indice", "helpUrl": "" }, { "type": "block_constint", "message0": "%1", "args0": [ { "type": "field_number", "name": "CONST", "value": 0 } ], "output": "Number", "colour": 20, "tooltip": "Constante numérique", "helpUrl": "" }, { "type": "block_plus", "message0": "%1 + %2", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" }, { "type": "input_value", "name": "EXP2", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 20, "tooltip": "Addition", "helpUrl": "" }, { "type": "block_minus", "message0": "%1 - %2", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" }, { "type": "input_value", "name": "EXP2", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 20, "tooltip": "Soustraction", "helpUrl": "" }, { "type": "block_mult", "message0": "%1 * %2", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" }, { "type": "input_value", "name": "EXP2", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 20, "tooltip": "Multiplication", "helpUrl": "" }, { "type": "block_div", "message0": "%1 / %2", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" }, { "type": "input_value", "name": "EXP2", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 20, "tooltip": "Division", "helpUrl": "" }, { "type": "block_div_eucl", "message0": "%1 // %2", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" }, { "type": "input_value", "name": "EXP2", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 20, "tooltip": "Division entière", "helpUrl": "" }, { "type": "block_mod", "message0": "%1 \% %2", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" }, { "type": "input_value", "name": "EXP2", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 20, "tooltip": "Reste de la division entière", "helpUrl": "" }, { "type": "block_pow", "message0": "%1 ** %2", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" }, { "type": "input_value", "name": "EXP2", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 20, "tooltip": "Puissance", "helpUrl": "" }, { "type": "block_neg", "message0": "- %1", "args0": [ { "type": "input_value", "name": "EXP", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 20, "tooltip": "Opposé d'un nombre", "helpUrl": "" }, { "type": "block_int", "message0": "int ( %1 )", "args0": [ { "type": "input_value", "name": "EXP", "check": "String" } ], "inputsInline": true, "output": "Number", "colour": 20, "tooltip": "Conversion en entier d'une chaîne de caractères", "helpUrl": "" }, { "type": "block_len", "message0": "len ( %1 )", "args0": [ { "type": "input_value", "name": "EXP", "check": "String" } ], "inputsInline": true, "output": "Number", "colour": 20, "tooltip": "Longueur d'une chaîne de caractères", "helpUrl": "" }, { "type": "block_ord", "message0": "ord ( %1 )", "args0": [ { "type": "input_value", "name": "EXP", "check": "String" } ], "inputsInline": true, "output": "Number", "colour": 20, "tooltip": "Code entier d'un caractère", "helpUrl": "" }, { "type": "block_get_str", "message0": "%1", "args0": [ { "type": "field_variable", "name": "VAR", "variable": "message", "variableTypes": ["String"], "defaultType": "String" } ], "output": "String", "colour": 300, "tooltip": "Variable chaîne de caractères", "helpUrl": "" }, { "type": "block_constchaine", "message0": "\"%1\"", "args0": [ { "type": "field_input", "name": "STR", "text": "bonjour" } ], "output": "String", "colour": 300, "tooltip": "Constante chaîne de caractères", "helpUrl": "" }, { "type": "block_input", "message0": "input ( %1 )", "args0": [ { "type": "input_value", "name": "ARG", "check": "String" } ], "inputsInline": true, "output": "String", "colour": 300, "tooltip": "Fonction permettant d'afficher un message et de saisir une chaîne de caractères", "helpUrl": "" }, { "type": "block_concat", "message0": "%1 + %2", "args0": [ { "type": "input_value", "name": "STR1", "check": "String" }, { "type": "input_value", "name": "STR2", "check": "String" } ], "inputsInline": true, "output": "String", "colour": 300, "tooltip": "Opération de concaténation de chaînes de caractères", "helpUrl": "" }, { "type": "block_str", "message0": "str ( %1 )", "args0": [ { "type": "input_value", "name": "EXP", "check": "Number" } ], "inputsInline": true, "output": "String", "colour": 300, "tooltip": "Conversion d'un entier en chaîne de caractères", "helpUrl": "" }, { "type": "block_chr", "message0": "chr ( %1 )", "args0": [ { "type": "input_value", "name": "EXP", "check": "Number" } ], "inputsInline": true, "output": "String", "colour": 300, "tooltip": "Décodage d'un caractère à partir de son code entier", "helpUrl": "" }, { "type": "block_nth", "message0": "%1 [ %2 ]", "args0": [ { "type": "input_value", "name": "EXP", "check": "String" }, { "type": "input_value", "name": "INDEX", "check": "Number" } ], "inputsInline": true, "output": "String", "colour": 300, "tooltip": "Accès au ieme caractère d'une chaîne de caractères", "helpUrl": "" }, // ------------- librairie random ----------------- { "type": "block_import_random", "message0": "from random import *", "previousStatement": null, "nextStatement": null, "colour": 50, "tooltip": "Importe la bibliothèque random", "helpUrl": "" }, { "type": "block_random", "message0": "random()", "output": "Number", "colour": 50, "tooltip": "Renvoie un nombre aléatoire dans l'intervalle [0,1[", "helpUrl": "" }, { "type": "block_randint", "message0": "randint (%1, %2)", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" }, { "type": "input_value", "name": "EXP2", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 50, "tooltip": "randint(a,b) renvoie un entier aléatoire entre deux entiers a et b avec a ≤ N ≤ b", "helpUrl": "" }, { "type": "block_randrange", "message0": "randrange(%1, %2)", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" }, { "type": "input_value", "name": "EXP2", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 50, "tooltip": "randrange(a,b) renvoie un entier aléatoire entre deux entiers a et b avec a ≤ N ≤ b-1", "helpUrl": "" }, // ------------- librairie math ----------------- { "type": "block_import_math", "message0": "from math import *", "previousStatement": null, "nextStatement": null, "colour": 35, "tooltip": "Importe la bibliothèque math", "helpUrl": "" }, { "type": "block_abs", "message0": "abs(%1)", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 35, "tooltip": "Valeur absolue d'un nombre", "helpUrl": "" }, { "type": "block_floor", "message0": "floor(%1)", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 35, "tooltip": "floor(x) renvoie le plancher de x, le plus grand entier plus petit ou égal à x", "helpUrl": "" }, { "type": "block_ceil", "message0": "ceil(%1)", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 35, "tooltip": "ceil(x) renvoie la fonction plafond de x, le plus petit entier plus grand ou égal à x", "helpUrl": "" }, { "type": "block_exp", "message0": "exp(%1)", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 35, "tooltip": "Fonction exponentielle", "helpUrl": "" }, { "type": "block_log", "message0": "log(%1)", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 35, "tooltip": "Fonction logarithme néperien", "helpUrl": "" }, { "type": "block_sqrt", "message0": "sqrt(%1)", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 35, "tooltip": "Fonction racine carrée", "helpUrl": "" }, { "type": "block_cos", "message0": "cos(%1)", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 35, "tooltip": "Fonction cosinus", "helpUrl": "" }, { "type": "block_sin", "message0": "sin(%1)", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 35, "tooltip": "Fonction sinus", "helpUrl": "" }, { "type": "block_tan", "message0": "tan(%1)", "args0": [ { "type": "input_value", "name": "EXP1", "check": "Number" } ], "inputsInline": true, "output": "Number", "colour": 35, "tooltip": "Fonction tangente", "helpUrl": "" }, { "type": "block_pi", "message0": "pi", "output": "Number", "colour": 35, "tooltip": "Constante pi", "helpUrl": "" }, { "type": "block_e", "message0": "e", "output": "Number", "colour": 35, "tooltip": "Constante e", "helpUrl": "" }, ]); /** * Mixin to add a context menu item to create a 'variables_get' block. * Used by blocks 'controls_for' and 'controls_forEach'. * @mixin * @augments Blockly.Block * @package * @readonly */ Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN = { /** * Add context menu option to create getter block for the loop's variable. * (customContextMenu support limited to web BlockSvg.) * @param {!Array} options List of menu options to add to. * @this {Blockly.Block} */ customContextMenu: function(options) { if (this.isInFlyout) { return; } var variable = this.getField('VAR').getVariable(); var varName = variable.name; if (!this.isCollapsed() && varName != null) { var option = {enabled: true}; option.text = Blockly.Msg['VARIABLES_SET_CREATE_GET'].replace('%1', varName); // var xmlField = Blockly.Variables.generateVariableFieldDom(variable); // xmlField.setAttribute('name', 'VAR'); // xmlField.setAttribute('variable', varName); // xmlField.setAttribute('variabletype', ''); // var xmlBlock = Blockly.utils.xml.createElement('block'); // xmlBlock.setAttribute('type', 'block_get_int'); // xmlBlock.appendChild(xmlField); var xmlBlock = Blockly.Xml.textToDom(' ' + varName + ' '); option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock); options.push(option); } } }; Blockly.Extensions.registerMixin('ajoutVariableContextMenu', Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN); Blockly.Extensions.register('controlTooltip', Blockly.Extensions.buildTooltipWithFieldText( '%{BKY_CONTROLS_FOR_TOOLTIP}', 'VAR'));