123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>JSDoc: Source: imported.js</title>
- <script src="scripts/prettify/prettify.js"> </script>
- <script src="scripts/prettify/lang-css.js"> </script>
- <!--[if lt IE 9]>
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
- <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
- </head>
- <body>
- <div id="main">
- <h1 class="page-title">Source: imported.js</h1>
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>/*
- Blockly.Blocks['classics_get_all'] = {
- init: function() {
- this.setHelpUrl('http://www.example.com/');
- this.setColour(WEATHER_HUE);
- this.appendDummyInput()
- .appendField("classics.get all books");
- this.setInputsInline(false);
- this.setOutput(true, "Number");
- this.setTooltip('Returns all the books');
- }
- };
- Blockly.Python['classics_get_all'] = function(block) {
- Blockly.Python.definitions_['import_classics'] = 'import classics';
- var code = 'classics.get_all()';
- return [code, Blockly.Python.ORDER_ATOMIC];
- };
- PythonToBlocks.KNOWN_MODULES['classics'] = {
- "get_all": ["classics_get_all"]
- };
- */
- function newBlock(name) {
- var block = blockpy.components.editor.blockly.newBlock(name);
- block.initSvg();
- block.render();
- }
- var DAYS = [
- ["Monday", "MON"],
- ["Tuesday", "TUE"],
- ["Wednesday", "WED"],
- ["Thursday", "THU"],
- ["Friday", "FRI"],
- ["Saturday", "SAT"],
- ["Sunday", "SUN"]
- ]
- var DAYS_MAP = {
- 'mon': 'parking.Day("MON")',
- 'tue': 'parking.Day("TUE")',
- 'wed': 'parking.Day("WED")',
- 'thu': 'parking.Day("THU")',
- 'fri': 'parking.Day("FRI")',
- 'sat': 'parking.Day("SAT")',
- 'sun': 'parking.Day("SUN")',
- 'tod': 'parking.today()'
- };
- Blockly.Blocks['datetime_day'] = {
- /**
- * Block for datetime day.
- * @this Blockly.Block
- */
- init: function() {
- this.jsonInit({
- "message0": "%1",
- "args0": [
- {
- "type": "field_dropdown",
- "name": "DAY",
- "options": [["Today", "TODAY"]].concat(DAYS)
- }
- ],
- "output": "DatetimeDay",
- "colour": DATA_HUE,
- "tooltip": "Returns a day of the week",
- "helpUrl": ""
- });
- }
- };
- Blockly.Python['datetime_day'] = function(block) {
- Blockly.Python.definitions_['import_parking'] = 'import parking';
- var operator = DAYS_MAP[block.getFieldValue('DAY').slice(0, 3).toLowerCase()];
- return [operator, Blockly.Python.ORDER_ATOMIC];
- };
- var HOURS = [["1", "1"], ["2", "2"], ["3", "3"],
- ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"],
- ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"],
- ["12", "12"]];
- var MINUTES = [["00", "00"], ["30", "30"]];
- var MERIDIANS = [["am", "AM"], ["pm", "PM"]];
- Blockly.Blocks['datetime_time'] = {
- /**
- * Block for datetime day.
- * @this Blockly.Block
- */
- init: function() {
- this.setColour(DATA_HUE);
- var dropdown = new Blockly.FieldDropdown([["Now", "NOW"]].concat(HOURS), function(opt) {
- var isNow = (opt == 'NOW');
- this.sourceBlock_.updateShape_(isNow);
- });
- this.appendDummyInput()
- .appendField(dropdown, 'HOUR');
- this.setInputsInline(true);
- this.setOutput(true, 'DatetimeTime');
- this.setTooltip("Returns a time of day");
- },
- mutationToDom: function() {
- var container = document.createElement('mutation');
- var isNow = (this.getFieldValue('HOUR').toUpperCase() == 'NOW');
- container.setAttribute('isnow', isNow);
- return container;
- },
- domToMutation: function(xmlElement) {
- var isNow = (xmlElement.getAttribute('isnow') == 'true');
- this.updateShape_(isNow);
- },
- updateShape_: function(isNow) {
- // Add or remove a Value Input.
- var inputExists = this.getInput('EXTENDED');
- if (!isNow) {
- if (!inputExists) {
- var minuteMenu = new Blockly.FieldDropdown(MINUTES);
- var meridianMenu = new Blockly.FieldDropdown(MERIDIANS);
- this.appendDummyInput('EXTENDED')
- .appendField(':')
- .appendField(minuteMenu, 'MINUTE')
- .appendField(meridianMenu, 'MERIDIAN');
- }
- } else if (inputExists) {
- this.removeInput('EXTENDED');
- }
- }
- };
- var HOURS_MAP = {
- '1': 'parking.one()',
- '2': 'parking.two()',
- '3': 'parking.three()',
- '4': 'parking.four()',
- '5': 'parking.five()',
- '6': 'parking.six()',
- '7': 'parking.seven()',
- '8': 'parking.eight()',
- '9': 'parking.nine()',
- '10': 'parking.ten()',
- '11': 'parking.eleven()',
- '12': 'parking.twelve()',
- 'NOW': 'parking.now()'
- };
- var MINUTES_MAP = {
- '00': 'parking.exactly()',
- '30': 'parking.half()'
- }
- var MERIDIANS_MAP = {
- 'AM': 'parking.am()',
- 'PM': 'parking.pm()'
- }
- Blockly.Python['datetime_time'] = function(block) {
- Blockly.Python.definitions_['import_parking'] = 'import parking';
- var hour = block.getFieldValue('HOUR');
- var code;
- if (hour == "NOW") {
- code = "parking.now()";
- } else {
- var minute = parseInt(block.getFieldValue('MINUTE'));
- var meridian = Blockly.Python.quote_(block.getFieldValue('MERIDIAN'));
- code = 'parking.Time('+hour+','+minute+','+meridian+')';
- }
- return [code, Blockly.Python.ORDER_ATOMIC];
- };
- var convertDate = function(date) {
- date = date.slice(0, 3).toLowerCase();
- switch (date) {
- case "mon": return "Monday";
- case "tue": return "Tuesday";
- case "wed": return "Wednesday";
- case "thu": return "Thursday";
- case "fri": return "Friday";
- case "sat": return "Saturday";
- case "sun": return "Sunday";
- default: return date;
- }
- }
- var convertMinute = function(minute) {
- if (minute < 10) {
- return "0"+minute;
- } else {
- return ""+minute;
- }
- }
- PythonToBlocks.KNOWN_MODULES['parking'] = {
- "today": ["datetime_day", ["DAY", "TODAY"]],
- "day_compare": ["datetime_check_day", "OP",
- {"type": "variable", "mode": "value", "name": "LEFT"},
- {"type": "mapper", "name": "VALUE", "method": convertDate}],
- "Day": ["datetime_day", {"type": "mapper", "name": "DAY", "method": convertDate}],
- "now": ["datetime_time", ["HOUR", "NOW"]],
- "Time": ["datetime_time", {"type": "integer", "name": "HOUR", "add_mutation": {"name": "@isnow", "value": "false"}},
- {"type": "integer_mapper", "name": "MINUTE", "method": convertMinute},
- "MERIDIAN"],
- "time_compare": ["datetime_check_time", "OP",
- {"type": "variable", "mode": "value", "name": "LEFT"},
- {"type": "integer", "name": "HOURS"},
- {"type": "integer_mapper", "name": "MINUTES", "method": convertMinute},
- "MERIDIANS"]
- };
- var equalityOperators = [
- ["==", "IS"],
- ["<", "BEFORE"],
- [">", "AFTER"],
- ["<=", "BEFORE_EQUAL"],
- ["=>", "AFTER_EQUAL"],
- ["!=", "IS_NOT"]
- ];
- var equalityOperatorsConversions = {
- "IS": "parking.equal",
- "BEFORE": "parking.before",
- "AFTER": "parking.after",
- "BEFORE_EQUAL": "parking.before_equal",
- "AFTER_EQUAL": "parking.after_equal",
- "IS_NOT": "parking.not_equal",
- }
- // FINISH _time and _day
- // Add in numbers and days to KNOWN_MODULES
- Blockly.Blocks['datetime_check_day'] = {
- /**
- * Block for testing if something contains something.
- * @this Blockly.Block
- */
- init: function() {
- this.setColour(Blockly.Blocks.logic.HUE);
- this.setOutput(true, 'Boolean');
- this.appendValueInput('LEFT')
- .setCheck('DatetimeDay')
- .appendField(new Blockly.FieldDropdown(DAYS), 'VALUE')
- .appendField(new Blockly.FieldDropdown(equalityOperators), 'OP');
-
- this.setInputsInline(false);
- }
- };
- Blockly.Python['datetime_check_day'] = function(block) {
- Blockly.Python.definitions_['import_parking'] = 'import parking';
- var value = Blockly.Python.quote_(block.getFieldValue('VALUE'));
- var operator = Blockly.Python.quote_(block.getFieldValue('OP'));
- var left = Blockly.Python.valueToCode(block, 'LEFT', Blockly.Python.ORDER_ATOMIC) || "___";
- var code = "parking.day_compare(" + operator + ", " + left + ', ' + value + ")";
- return [code, Blockly.Python.ORDER_ATOMIC];
- };
- Blockly.Blocks['datetime_check_time'] = {
- /**
- * Block for testing if something contains something.
- * @this Blockly.Block
- */
- init: function() {
- this.setColour(Blockly.Blocks.logic.HUE);
- this.setOutput(true, 'Boolean');
- this.appendValueInput('LEFT')
- .setCheck('DatetimeTime')
- .appendField(new Blockly.FieldDropdown(HOURS), 'HOURS')
- .appendField(':')
- .appendField(new Blockly.FieldDropdown(MINUTES), 'MINUTES')
- .appendField(new Blockly.FieldDropdown(MERIDIANS), 'MERIDIANS')
- .appendField(new Blockly.FieldDropdown(equalityOperators), 'OP');
- //this.setInputsInline(true);
- }
- };
- Blockly.Python['datetime_check_time'] = function(block) {
- Blockly.Python.definitions_['import_parking'] = 'import parking';
- var hour = parseInt(block.getFieldValue('HOURS'));
- var minute = parseInt(block.getFieldValue('MINUTES'));
- var meridian = Blockly.Python.quote_(block.getFieldValue('MERIDIANS'));
- var operator = Blockly.Python.quote_(block.getFieldValue('OP'));
- var left = Blockly.Python.valueToCode(block, 'LEFT', Blockly.Python.ORDER_ATOMIC)
- var code = "parking.time_compare(" + operator+", "+left + ',' + hour + ',' + minute + ',' +meridian + ")";
- return [code, Blockly.Python.ORDER_ATOMIC];
- };
- Blockly.Blocks['controls_forEach'] = {
- /**
- * Block for 'for each' loop.
- * @this Blockly.Block
- */
- init: function() {
- this.jsonInit({
- "message0": "for each item %1 in list %2 : ", //Blockly.Msg.CONTROLS_FOREACH_TITLE,
- "args0": [
- {
- "type": "input_value",
- "name": "VAR",
- "check": "Tuple"
- },
- {
- "type": "input_value",
- "name": "LIST",
- "check": "Array"
- }
- ],
- "inputsInline": true,
- "previousStatement": null,
- "nextStatement": null,
- "colour": Blockly.Blocks.loops.HUE,
- "helpUrl": Blockly.Msg.CONTROLS_FOREACH_HELPURL
- });
- this.appendStatementInput('DO')
- .appendField(Blockly.Msg.CONTROLS_FOREACH_INPUT_DO);
- this.setInputsInline(true);
- // Assign 'this' to a variable for use in the tooltip closure below.
- var thisBlock = this;
- this.setTooltip(function() {
- return Blockly.Msg.CONTROLS_FOREACH_TOOLTIP.replace('%1',
- Blockly.Python.valueToCode(thisBlock, 'VAR', Blockly.Python.ORDER_RELATIONAL) || '___');
- });
- },
- customContextMenu: Blockly.Blocks['controls_for'].customContextMenu
- };
- Blockly.Python['controls_forEach'] = function(block) {
- // For each loop.
- var variable0 = Blockly.Python.valueToCode(block, 'VAR',
- Blockly.Python.ORDER_RELATIONAL) || '___';
- var argument0 = Blockly.Python.valueToCode(block, 'LIST',
- Blockly.Python.ORDER_RELATIONAL) || '___';
- var branch = Blockly.Python.statementToCode(block, 'DO');
- branch = Blockly.Python.addLoopTrap(branch, block.id) ||
- Blockly.Python.PASS;
- var code = 'for ' + variable0 + ' in ' + argument0 + ':\n' + branch;
- return code;
- };
- Blockly.Blocks['class_creation'] = {
- init: function() {
- this.appendDummyInput()
- .appendField("Create class")
- .appendField(new Blockly.FieldVariable("new class"), "CLASS");
- /*
- this.appendDummyInput()
- .appendField("Inherits from")
- .appendField(new Blockly.FieldVariable("j"), "NAME")
- .appendField(",")
- .appendField(new Blockly.FieldVariable("k"), "NAME");
- */
- this.appendStatementInput("BODY")
- .setCheck(null);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- this.setColour(230);
- this.setTooltip('');
- this.setHelpUrl('http://www.example.com/');
- }
- };
- Blockly.Python['class_creation'] = function(block) {
- var class_name = Blockly.Python.variableDB_.getName(block.getFieldValue('CLASS'), Blockly.Variables.NAME_TYPE) || '___';
- var body = Blockly.Python.statementToCode(block, 'BODY') ||
- Blockly.Python.PASS;
- // TODO: Assemble Python into code variable.
- var code = 'class ' + class_name + ':\n' + body;
- return code;
- };
- Blockly.Blocks['list_comprehension'] = {
- init: function() {
- this.appendValueInput("body")
- .setCheck(null)
- .appendField("[");
- this.appendValueInput("var")
- .setCheck(null)
- .appendField("for");
- this.appendValueInput("list")
- .setCheck(null)
- .appendField("in");
- this.appendDummyInput()
- .appendField("]");
- this.setInputsInline(true);
- this.setOutput(true, null);
- this.setTooltip('');
- this.setHelpUrl('http://www.example.com/');
- }
- };
- Blockly.Python['list_comprehension'] = function(block) {
- var value_body = Blockly.Python.valueToCode(block, 'body', Blockly.Python.ORDER_ATOMIC) || '___';
- var value_var = Blockly.Python.valueToCode(block, 'var', Blockly.Python.ORDER_ATOMIC) || '___';
- var value_list = Blockly.Python.valueToCode(block, 'list', Blockly.Python.ORDER_ATOMIC) || '___';
- // TODO: Assemble Python into code variable.
- var code = '['+value_body+' for '+value_var+' in '+value_list+']';
- // TODO: Change ORDER_NONE to the correct strength.
- return [code, Blockly.Python.ORDER_NONE];
- };
- /**
- * Decode an XML DOM and create blocks on the workspace, clearing out old blocks.
- * @param {!Element} xml XML DOM.
- * @param {!Blockly.Workspace} workspace The workspace.
- */
- Blockly.Xml.domToWorkspaceDestructive = function(xml, workspace, errorXml) {
- if (xml instanceof Blockly.Workspace) {
- var swap = xml;
- xml = workspace;
- workspace = swap;
- console.warn('Deprecated call to Blockly.Xml.domToWorkspace, ' +
- 'swap the arguments.');
- }
- var width; // Not used in LTR.
- if (workspace.RTL) {
- width = workspace.getWidth();
- }
- Blockly.Field.startCache();
- // Safari 7.1.3 is known to provide node lists with extra references to
- // children beyond the lists' length. Trust the length, do not use the
- // looping pattern of checking the index for an object.
- var childCount = xml.childNodes.length;
- var existingGroup = Blockly.Events.getGroup();
- if (!existingGroup) {
- Blockly.Events.setGroup(true);
- }
- Blockly.Events.disable();
- while (workspace.topBlocks_.length) {
- workspace.topBlocks_[0].dispose();
- }
- workspace.variableList.length = 0;
- Blockly.Events.enable();
- // Disable workspace resizes as an optimization.
- if (workspace.setResizesEnabled) {
- workspace.setResizesEnabled(false);
- }
- for (var i = 0; i < childCount; i++) {
- var xmlChild = xml.childNodes[i];
- var name = xmlChild.nodeName.toLowerCase();
- if (name == 'block' ||
- (name == 'shadow' && !Blockly.Events.recordUndo)) {
- // Allow top-level shadow blocks if recordUndo is disabled since
- // that means an undo is in progress. Such a block is expected
- // to be moved to a nested destination in the next operation.
- var block = Blockly.Xml.domToBlock(xmlChild, workspace);
- var blockX = parseInt(xmlChild.getAttribute('x'), 10);
- var blockY = parseInt(xmlChild.getAttribute('y'), 10);
- if (!isNaN(blockX) && !isNaN(blockY)) {
- block.moveBy(workspace.RTL ? width - blockX : blockX, blockY);
- }
- } else if (name == 'shadow') {
- goog.asserts.fail('Shadow block cannot be a top-level block.');
- }
- }
- if (!existingGroup) {
- Blockly.Events.setGroup(false);
- }
- Blockly.Field.stopCache();
- workspace.updateVariableList(false);
- // Re-enable workspace resizing.
- if (workspace.setResizesEnabled) {
- workspace.setResizesEnabled(true);
- }
- }
- Blockly.Blocks['comment_single'] = {
- init: function() {
- this.appendDummyInput()
- .appendField("Comment:")
- .appendField(new Blockly.FieldTextInput("will be ignored"), "BODY");
- this.setInputsInline(true);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- this.setColour(60);
- this.setTooltip('This is a comment, which will be ignored when you execute your code.');
- this.setHelpUrl('');
- }
- };
- Blockly.Python['comment_single'] = function(block) {
- var text_body = block.getFieldValue('BODY');
- // TODO: Assemble JavaScript into code variable.
- var code = '# '+text_body+'\n';
- return code;
- };
- Blockly.Blocks['string_multiline'] = {
- // Container.
- init: function() {
- this.appendDummyInput()
- .appendField('Multiline String:');
- this.appendDummyInput()
- .appendField(this.newQuote_(true))
- .appendField(new Blockly.FieldTextArea(''), 'TEXT')
- .appendField(this.newQuote_(false));
- this.setColour(Blockly.Blocks.texts.HUE);
- this.setOutput(true, 'String');
- },
- newQuote_: function(open) {
- if (open == this.RTL) {
- var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
- } else {
- var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
- }
- return new Blockly.FieldImage(file, 12, 12, '"');
- }
- };
- Blockly.Python['string_multiline'] = function(block) {
- var text_body = block.getFieldValue('TEXT');
- // TODO: Assemble JavaScript into code variable.
- var code = '"""'+text_body+'"""\n';
- return [code, Blockly.Python.ORDER_ATOMIC];
- };
- Blockly.Blocks['attribute_access'] = {
- init: function() {
- this.appendValueInput("MODULE")
- .setCheck(null);
- this.appendValueInput("NAME")
- .setCheck(null)
- .appendField(".");
- this.setInputsInline(true);
- this.setOutput(true, null);
- this.setColour(230);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Python['attribute_access'] = function(block) {
- var value_module = Blockly.Python.valueToCode(block, 'MODULE', Blockly.Python.ORDER_ATOMIC);
- var value_name = Blockly.Python.valueToCode(block, 'NAME', Blockly.Python.ORDER_ATOMIC);
- // TODO: Assemble JavaScript into code variable.
- var code = value_module+'.'+value_name;
- // TODO: Change ORDER_NONE to the correct strength.
- return [code, Blockly.Python.ORDER_NONE];
- };
- /**
- * Turtles!
- */
- Blockly.Blocks['turtle_create'] = {
- init: function() {
- this.appendDummyInput()
- .appendField("create new turtle");
- this.setOutput(true, 'Turtle');
- this.setColour(180);
- this.setTooltip('Creates a new turtle');
- this.setHelpUrl('');
- }
- };
- Blockly.Python['turtle_create'] = function(block) {
- Blockly.Python.definitions_['import_turtle'] = 'import turtle';
- var code = 'turtle.Turtle()\n';
- // TODO: Change ORDER_NONE to the correct strength.
- return [code, Blockly.Python.ORDER_NONE];
- };
- PythonToBlocks.KNOWN_MODULES['turtle'] = {
- "Turtle": ["turtle_create"]
- }
- Blockly.Blocks['turtle_color'] = {
- init: function() {
- this.appendValueInput("TURTLE")
- .setCheck("Turtle")
- .appendField("make turtle");
- this.appendValueInput("COLOR")
- .setCheck(null)
- .appendField("color");
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setOutput(false);
- this.setInputsInline(true);
- this.setColour(180);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Python['turtle_color'] = function(block) {
- var turtle = Blockly.Python.valueToCode(block, 'TURTLE', Blockly.Python.ORDER_ATOMIC);
- var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
- // TODO: Assemble Python into code variable.
- var code = turtle+'.color('+color+')\n';
- return code;
- };
- PythonToBlocks.KNOWN_ATTR_FUNCTIONS['color'] = function(func, args, keywords, starargs, kwargs, node) {
- if (args.length < 1 || args.length > 2) {
- throw new Error("Incorrect number of arguments to turtle.color!");
- }
- return [block("turtle_color", func.lineno, {}, {
- "COLOR": this.convert(args[0]),
- "TURTLE": this.convert(func.value)
- }, {"inline": "true"})];
- }
- Blockly.Blocks['turtle_forward'] = {
- init: function() {
- this.appendValueInput("TURTLE")
- .setCheck("Turtle")
- .appendField("make turtle");
- this.appendValueInput("DISTANCE")
- .setCheck(null)
- .appendField("move forward by");
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setInputsInline(true);
- this.setOutput(false);
- this.setColour(180);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Python['turtle_forward'] = function(block) {
- var turtle = Blockly.Python.valueToCode(block, 'TURTLE', Blockly.Python.ORDER_ATOMIC);
- var distance = Blockly.Python.valueToCode(block, 'DISTANCE', Blockly.Python.ORDER_ATOMIC);
- // TODO: Assemble Python into code variable.
- var code = turtle+'.forward('+distance+')\n';
- return code;
- };
- PythonToBlocks.KNOWN_ATTR_FUNCTIONS['forward'] = function(func, args, keywords, starargs, kwargs, node) {
- if (args.length != 1) {
- throw new Error("Incorrect number of arguments to turtle.forward!");
- }
- return [block("turtle_forward", func.lineno, {}, {
- "DISTANCE": this.convert(args[0]),
- "TURTLE": this.convert(func.value)
- }, {"inline": "true"})];
- }
- Blockly.Blocks['turtle_backward'] = {
- init: function() {
- this.appendValueInput("TURTLE")
- .setCheck("Turtle")
- .appendField("make turtle");
- this.appendValueInput("DISTANCE")
- .setCheck(null)
- .appendField("move backward by");
- this.setPreviousStatement(true);
- this.setInputsInline(true);
- this.setNextStatement(true);
- this.setOutput(false);
- this.setColour(180);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Python['turtle_backward'] = function(block) {
- var turtle = Blockly.Python.valueToCode(block, 'TURTLE', Blockly.Python.ORDER_ATOMIC);
- var distance = Blockly.Python.valueToCode(block, 'DISTANCE', Blockly.Python.ORDER_ATOMIC);
- // TODO: Assemble Python into code variable.
- var code = turtle+'.backward('+distance+')\n';
- return code;
- };
- PythonToBlocks.KNOWN_ATTR_FUNCTIONS['backward'] = function(func, args, keywords, starargs, kwargs, node) {
- if (args.length != 1) {
- throw new Error("Incorrect number of arguments to turtle.backward!");
- }
- return [block("turtle_backward", func.lineno, {}, {
- "DISTANCE": this.convert(args[0]),
- "TURTLE": this.convert(func.value)
- }, {"inline": "true"})];
- }
- Blockly.Blocks['turtle_left'] = {
- init: function() {
- this.appendValueInput("TURTLE")
- .setCheck("Turtle")
- .appendField("make turtle");
- this.appendValueInput("ANGLE")
- .setCheck(null)
- .appendField("turn left by");
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setInputsInline(true);
- this.setOutput(false);
- this.setColour(180);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Python['turtle_left'] = function(block) {
- var turtle = Blockly.Python.valueToCode(block, 'TURTLE', Blockly.Python.ORDER_ATOMIC);
- var angle = Blockly.Python.valueToCode(block, 'ANGLE', Blockly.Python.ORDER_ATOMIC);
- // TODO: Assemble Python into code variable.
- var code = turtle+'.left('+angle+')\n';
- return code;
- };
- PythonToBlocks.KNOWN_ATTR_FUNCTIONS['left'] = function(func, args, keywords, starargs, kwargs, node) {
- if (args.length != 1) {
- throw new Error("Incorrect number of arguments to turtle.left!");
- }
- return [block("turtle_left", func.lineno, {}, {
- "ANGLE": this.convert(args[0]),
- "TURTLE": this.convert(func.value)
- }, {"inline": "true"})];
- }
- Blockly.Blocks['turtle_right'] = {
- init: function() {
- this.appendValueInput("TURTLE")
- .setCheck("Turtle")
- .appendField("make turtle");
- this.appendValueInput("ANGLE")
- .setCheck(null)
- .appendField("turn right by");
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setInputsInline(true);
- this.setOutput(false);
- this.setColour(180);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Python['turtle_right'] = function(block) {
- var turtle = Blockly.Python.valueToCode(block, 'TURTLE', Blockly.Python.ORDER_ATOMIC);
- var angle = Blockly.Python.valueToCode(block, 'ANGLE', Blockly.Python.ORDER_ATOMIC);
- // TODO: Assemble Python into code variable.
- var code = turtle+'.right('+angle+')\n';
- return code;
- };
- PythonToBlocks.KNOWN_ATTR_FUNCTIONS['right'] = function(func, args, keywords, starargs, kwargs, node) {
- if (args.length != 1) {
- throw new Error("Incorrect number of arguments to turtle.right!");
- }
- return [block("turtle_right", func.lineno, {}, {
- "ANGLE": this.convert(args[0]),
- "TURTLE": this.convert(func.value)
- }, {"inline": "true"})];
- }</code></pre>
- </article>
- </section>
- </div>
- <nav>
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BlockPy.html">BlockPy</a></li><li><a href="BlockPyCorgis.html">BlockPyCorgis</a></li><li><a href="BlockPyDialog.html">BlockPyDialog</a></li><li><a href="BlockPyEditor.html">BlockPyEditor</a></li><li><a href="BlockPyEngine.html">BlockPyEngine</a></li><li><a href="BlockPyEnglish.html">BlockPyEnglish</a></li><li><a href="BlockPyFeedback.html">BlockPyFeedback</a></li><li><a href="BlockPyHistory.html">BlockPyHistory</a></li><li><a href="BlockPyPresentation.html">BlockPyPresentation</a></li><li><a href="BlockPyPrinter.html">BlockPyPrinter</a></li><li><a href="BlockPyServer.html">BlockPyServer</a></li><li><a href="BlockPyToolbar.html">BlockPyToolbar</a></li><li><a href="LocalStorageWrapper.html">LocalStorageWrapper</a></li><li><a href="PythonToBlocks.html">PythonToBlocks</a></li></ul><h3>Global</h3><ul><li><a href="global.html#BlockPyInterface">BlockPyInterface</a></li><li><a href="global.html#cloneNode">cloneNode</a></li><li><a href="global.html#encodeHTML">encodeHTML</a></li><li><a href="global.html#expandArray">expandArray</a></li><li><a href="global.html#EXTENDED_ERROR_EXPLANATION">EXTENDED_ERROR_EXPLANATION</a></li><li><a href="global.html#indent">indent</a></li><li><a href="global.html#instructor_module">instructor_module</a></li><li><a href="global.html#prettyPrintDateTime">prettyPrintDateTime</a></li><li><a href="global.html#randomInteger">randomInteger</a></li><li><a href="global.html#set_button_loaded">set_button_loaded</a></li><li><a href="global.html#timerGuard">timerGuard</a></li></ul>
- </nav>
- <br class="clear">
- <footer>
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Sun Mar 26 2017 09:45:03 GMT-0400 (Eastern Daylight Time)
- </footer>
- <script> prettyPrint(); </script>
- <script src="scripts/linenumber.js"> </script>
- </body>
- </html>
|