Commit d77b1501 authored by Carlos Pereira Atencio's avatar Carlos Pereira Atencio Committed by carlospamg

Enabled Arduino code generation in:

  new "code_duino" app, based on "code" to test changes
  test/playground
  test/generator/index
parent 4b097a5c
/**
* Blockly Apps: Code
*
* Copyright 2012 Google Inc.
* https://blockly.googlecode.com/
*
* 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
*
* http://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 JavaScript for Blockly's Code application.
* @author fraser@google.com (Neil Fraser)
*/
// Supported languages.
BlocklyApps.LANGUAGES =
['en'];
BlocklyApps.LANG = BlocklyApps.getLang();
document.write('<script type="text/javascript" src="generated/' +
BlocklyApps.LANG + '.js"></script>\n');
/**
* Create a namespace for the application.
*/
var Code = {};
/**
* List of tab names.
* @private
*/
Code.TABS_ = ['blocks', 'arduino', 'javascript', 'python', 'dart', 'xml'];
Code.selected = 'blocks';
/**
* Switch the visible pane when a tab is clicked.
* @param {string} clickedName Name of tab clicked.
*/
Code.tabClick = function(clickedName) {
// If the XML tab was open, save and render the content.
if (document.getElementById('tab_xml').className == 'tabon') {
var xmlTextarea = document.getElementById('content_xml');
var xmlText = xmlTextarea.value;
var xmlDom = null;
try {
xmlDom = Blockly.Xml.textToDom(xmlText);
} catch (e) {
var q =
window.confirm(BlocklyApps.getMsg('Code_badXml').replace('%1', e));
if (!q) {
// Leave the user on the XML tab.
return;
}
}
if (xmlDom) {
Blockly.mainWorkspace.clear();
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, xmlDom);
}
}
// Deselect all tabs and hide all panes.
for (var i = 0; i < Code.TABS_.length; i++) {
var name = Code.TABS_[i];
document.getElementById('tab_' + name).className = 'taboff';
document.getElementById('content_' + name).style.visibility = 'hidden';
}
// Select the active tab.
Code.selected = clickedName;
document.getElementById('tab_' + clickedName).className = 'tabon';
// Show the selected pane.
document.getElementById('content_' + clickedName).style.visibility =
'visible';
Code.renderContent();
Blockly.fireUiEvent(window, 'resize');
};
/**
* Populate the currently selected pane with content generated from the blocks.
*/
Code.renderContent = function() {
var content = document.getElementById('content_' + Code.selected);
// Initialize the pane.
if (content.id == 'content_xml') {
var xmlTextarea = document.getElementById('content_xml');
var xmlDom = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace);
var xmlText = Blockly.Xml.domToPrettyText(xmlDom);
xmlTextarea.value = xmlText;
xmlTextarea.focus();
} else if (content.id == 'content_arduino') {
var code = Blockly.Arduino.workspaceToCode();
content.textContent = code;
if (typeof prettyPrintOne == 'function') {
code = content.innerHTML;
code = prettyPrintOne(code, 'js');
content.innerHTML = code;
}
} else if (content.id == 'content_javascript') {
var code = Blockly.JavaScript.workspaceToCode();
content.textContent = code;
if (typeof prettyPrintOne == 'function') {
code = content.innerHTML;
code = prettyPrintOne(code, 'js');
content.innerHTML = code;
}
} else if (content.id == 'content_python') {
code = Blockly.Python.workspaceToCode();
content.textContent = code;
if (typeof prettyPrintOne == 'function') {
code = content.innerHTML;
code = prettyPrintOne(code, 'py');
content.innerHTML = code;
}
} else if (content.id == 'content_dart') {
code = Blockly.Dart.workspaceToCode();
content.textContent = code;
if (typeof prettyPrintOne == 'function') {
code = content.innerHTML;
code = prettyPrintOne(code, 'dart');
content.innerHTML = code;
}
}
};
/**
* Initialize Blockly. Called on page load.
*/
Code.init = function() {
BlocklyApps.init();
var rtl = BlocklyApps.isRtl();
var container = document.getElementById('content_area');
var onresize = function(e) {
var bBox = BlocklyApps.getBBox_(container);
for (var i = 0; i < Code.TABS_.length; i++) {
var el = document.getElementById('content_' + Code.TABS_[i]);
el.style.top = bBox.y + 'px';
el.style.left = bBox.x + 'px';
// Height and width need to be set, read back, then set again to
// compensate for scrollbars.
el.style.height = bBox.height + 'px';
el.style.height = (2 * bBox.height - el.offsetHeight) + 'px';
el.style.width = bBox.width + 'px';
el.style.width = (2 * bBox.width - el.offsetWidth) + 'px';
}
// Make the 'Blocks' tab line up with the toolbox.
if (Blockly.Toolbox.width) {
document.getElementById('tab_blocks').style.minWidth =
(Blockly.Toolbox.width - 38) + 'px';
// Account for the 19 pixel margin and on each side.
}
};
window.addEventListener('resize', onresize, false);
var toolbox = document.getElementById('toolbox');
Blockly.inject(document.getElementById('content_blocks'),
{path: '../../',
rtl: rtl,
toolbox: toolbox});
// Add to reserved word list: Local variables in execution evironment (runJS)
// and the infinite loop detection function.
Blockly.JavaScript.addReservedWords('code,timeouts,checkTimeout');
BlocklyApps.loadBlocks('');
if ('BlocklyStorage' in window) {
// Hook a save function onto unload.
BlocklyStorage.backupOnUnload();
}
Code.tabClick(Code.selected);
Blockly.fireUiEvent(window, 'resize');
BlocklyApps.bindClick('trashButton',
function() {Code.discard(); Code.renderContent();});
BlocklyApps.bindClick('runButton', Code.runJS);
for (var i = 0; i < Code.TABS_.length; i++) {
var name = Code.TABS_[i];
BlocklyApps.bindClick('tab_' + name,
function(name_) {return function() {Code.tabClick(name_);};}(name));
}
// Lazy-load the syntax-highlighting.
window.setTimeout(BlocklyApps.importPrettify, 1);
};
if (window.location.pathname.match(/readonly.html$/)) {
window.addEventListener('load', BlocklyApps.initReadonly);
} else {
window.addEventListener('load', Code.init);
}
/**
* Execute the user's code.
* Just a quick and dirty eval. Catch infinite loops.
*/
Code.runJS = function() {
Blockly.JavaScript.INFINITE_LOOP_TRAP = ' checkTimeout();\n';
var timeouts = 0;
var checkTimeout = function() {
if (timeouts++ > 1000000) {
throw BlocklyApps.getMsg('Code_timeout');
}
};
var code = Blockly.JavaScript.workspaceToCode();
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
try {
eval(code);
} catch (e) {
alert(BlocklyApps.getMsg('Code_badCode').replace('%1', e));
}
};
/**
* Discard all blocks from the workspace.
*/
Code.discard = function() {
var count = Blockly.mainWorkspace.getAllBlocks().length;
if (count < 2 ||
window.confirm(BlocklyApps.getMsg('Code_discard').replace('%1', count))) {
Blockly.mainWorkspace.clear();
window.location.hash = '';
}
};
// This file was automatically generated from common.soy.
// Please don't edit this file by hand.
if (typeof apps == 'undefined') { var apps = {}; }
apps.messages = function(opt_data, opt_ignored, opt_ijData) {
return '<div style="display: none"><span id="subtitle">a visual programming environment</span><span id="blocklyMessage">Blockly</span><span id="codeTooltip">See generated JavaScript code.</span><span id="linkTooltip">Save and link to blocks.</span><span id="runTooltip">Run the program defined by the blocks in the workspace.</span><span id="runProgram">Run Program</span><span id="resetProgram">Reset</span><span id="dialogOk">OK</span><span id="dialogCancel">Cancel</span><span id="catLogic">Logic</span><span id="catLoops">Loops</span><span id="catMath">Math</span><span id="catText">Text</span><span id="catLists">Lists</span><span id="catColour">Colour</span><span id="catVariables">Variables</span><span id="catProcedures">Functions</span><span id="httpRequestError">There was a problem with the request.</span><span id="linkAlert">Share your blocks with this link:\\n\\n%1</span><span id="hashError">Sorry, \'%1\' doesn\'t correspond with any saved program.</span><span id="xmlError">Could not load your saved file. Perhaps it was created with a different version of Blockly?</span><span id="listVariable">list</span><span id="textVariable">text</span></div>';
};
apps.dialog = function(opt_data, opt_ignored, opt_ijData) {
return '<div id="dialogShadow" class="dialogAnimate"></div><div id="dialogBorder"></div><div id="dialog"></div>';
};
apps.codeDialog = function(opt_data, opt_ignored, opt_ijData) {
return '<div id="dialogCode" class="dialogHiddenContent"><pre id="containerCode"></pre>' + apps.ok(null, null, opt_ijData) + '</div>';
};
apps.storageDialog = function(opt_data, opt_ignored, opt_ijData) {
return '<div id="dialogStorage" class="dialogHiddenContent"><div id="containerStorage"></div>' + apps.ok(null, null, opt_ijData) + '</div>';
};
apps.ok = function(opt_data, opt_ignored, opt_ijData) {
return '<div class="farSide" style="padding: 1ex 3ex 0"><button class="secondary" onclick="BlocklyApps.hideDialog(true)">OK</button></div>';
};
;
// This file was automatically generated from template.soy.
// Please don't edit this file by hand.
if (typeof codepage == 'undefined') { var codepage = {}; }
codepage.messages = function(opt_data, opt_ignored, opt_ijData) {
return apps.messages(null, null, opt_ijData) + '<div style="display: none"><span id="Code_badXml">Error parsing XML:\\n%1\\n\\nSelect \'OK\' to abandon your changes or \'Cancel\' to further edit the XML.</span><span id="Code_badCode">Program error:\\n%1</span><span id="Code_timeout">Maximum execution iterations exceeded.</span><span id="Code_discard">Delete all %1 blocks?</span></div>';
};
codepage.start = function(opt_data, opt_ignored, opt_ijData) {
return codepage.messages(null, null, opt_ijData) + '<script type="text/javascript" src="../../blockly_compressed.js"><\/script><script type="text/javascript" src="../../blocks_compressed.js"><\/script><script type="text/javascript" src="../../generators/arduino.js"><\/script><script type="text/javascript" src="../../generators/arduino/base.js"><\/script><script type="text/javascript" src="../../generators/arduino/control.js"><\/script><script type="text/javascript" src="../../generators/arduino/logic.js"><\/script><!--script type="text/javascript" src="../../generators/arduino/loops.js"></script--><script type="text/javascript" src="../../generators/arduino/math.js"><\/script><script type="text/javascript" src="../../generators/arduino/text.js"><\/script><script type="text/javascript" src="../../generators/arduino/lists.js"><\/script><script type="text/javascript" src="../../generators/arduino/colour.js"><\/script><script type="text/javascript" src="../../generators/arduino/variables.js"><\/script><script type="text/javascript" src="../../generators/arduino/procedures.js"><\/script><script type="text/javascript" src="../../javascript_compressed.js"><\/script><script type="text/javascript" src="../../python_compressed.js"><\/script><script type="text/javascript" src="../../dart_compressed.js"><\/script><script type="text/javascript" src="../../' + soy.$$escapeHtml(opt_ijData.langSrc) + '"><\/script><table width="100%" height="100%"><tr><td><h1><span id="title"><a href="../index.html?lang=' + soy.$$escapeHtml(opt_ijData.lang) + '">Blockllllly</a> : Code</span></h1></td><td class="farSide"><select id="languageMenu"></select></td></tr><tr><td colspan=2><table width="100%"><tr id="tabRow" height="1em"><td id="tab_blocks" class="tabon">Blocks</td><td class="tabmin">&nbsp;</td><td id="tab_arduino" class="taboff">Arduino</td><td class="tabmin">&nbsp;</td><td id="tab_javascript" class="taboff">JavaScript</td><td class="tabmin">&nbsp;</td><td id="tab_python" class="taboff">Python</td><td class="tabmin">&nbsp;</td><td id="tab_dart" class="taboff">Dart</td><td class="tabmin">&nbsp;</td><td id="tab_xml" class="taboff">XML</td><td class="tabmax"><button id="trashButton" class="notext" title="Discard all blocks."><img src=\'../../media/1x1.gif\' class="trash icon21"></button> <button id="linkButton" class="notext" title="Save and link to blocks."><img src=\'../../media/1x1.gif\' class="link icon21"></button> <button id="runButton" class="notext primary" title="Run the program defined by the blocks in the workspace."><img src=\'../../media/1x1.gif\' class="run icon21"></button></td></tr></table></td></tr><tr><td height="99%" colspan=2 id="content_area">' + codepage.toolbox(null, null, opt_ijData) + '</td></tr></table><div id="content_blocks" class="content"></div><pre id="content_arduino" class="content"></pre><pre id="content_javascript" class="content"></pre><pre id="content_python" class="content"></pre><pre id="content_dart" class="content"></pre><textarea id="content_xml" class="content" wrap="off"></textarea>' + apps.dialog(null, null, opt_ijData) + apps.storageDialog(null, null, opt_ijData);
};
codepage.toolbox = function(opt_data, opt_ignored, opt_ijData) {
return '<xml id="toolbox" style="display: none"><category name="Logic"><block type="controls_if"></block><block type="logic_compare"></block><block type="logic_operation"></block><block type="logic_negate"></block><block type="logic_boolean"></block><block type="logic_null"></block><block type="logic_ternary"></block></category><category name="Loops"><block type="controls_repeat_ext"><value name="TIMES"><block type="math_number"><field name="NUM">10</field></block></value></block><block type="controls_whileUntil"></block><block type="controls_for"><value name="FROM"><block type="math_number"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number"><field name="NUM">10</field></block></value><value name="BY"><block type="math_number"><field name="NUM">1</field></block></value></block><block type="controls_forEach"></block><block type="controls_flow_statements"></block></category><category name="Math"><block type="math_number"></block><block type="math_arithmetic"></block><block type="math_single"></block><block type="math_trig"></block><block type="math_constant"></block><block type="math_number_property"></block><block type="math_change"><value name="DELTA"><block type="math_number"><field name="NUM">1</field></block></value></block><block type="math_round"></block><block type="math_on_list"></block><block type="math_modulo"></block><block type="math_constrain"><value name="LOW"><block type="math_number"><field name="NUM">1</field></block></value><value name="HIGH"><block type="math_number"><field name="NUM">100</field></block></value></block><block type="math_random_int"><value name="FROM"><block type="math_number"><field name="NUM">1</field></block></value><value name="TO"><block type="math_number"><field name="NUM">100</field></block></value></block><block type="math_random_float"></block></category><category name="Text"><block type="text"></block><block type="text_join"></block><block type="text_append"><value name="TEXT"><block type="text"></block></value></block><block type="text_length"></block><block type="text_isEmpty"></block><block type="text_indexOf"><value name="VALUE"><block type="variables_get"><field name="VAR">text</field></block></value></block><block type="text_charAt"><value name="VALUE"><block type="variables_get"><field name="VAR">text</field></block></value></block><block type="text_getSubstring"><value name="STRING"><block type="variables_get"><field name="VAR">text</field></block></value></block><block type="text_changeCase"></block><block type="text_trim"></block><block type="text_print"></block><block type="text_prompt_ext"><value name="TEXT"><block type="text"></block></value></block></category><category name="Lists"><block type="lists_create_empty"></block><block type="lists_create_with"></block><block type="lists_repeat"><value name="NUM"><block type="math_number"><field name="NUM">5</field></block></value></block><block type="lists_length"></block><block type="lists_isEmpty"></block><block type="lists_indexOf"><value name="VALUE"><block type="variables_get"><field name="VAR">list</field></block></value></block><block type="lists_getIndex"><value name="VALUE"><block type="variables_get"><field name="VAR">list</field></block></value></block><block type="lists_setIndex"><value name="LIST"><block type="variables_get"><field name="VAR">list</field></block></value></block><block type="lists_getSublist"><value name="LIST"><block type="variables_get"><field name="VAR">list</field></block></value></block></category><category name="Colour"><block type="colour_picker"></block><block type="colour_random"></block><block type="colour_rgb"></block><block type="colour_blend"></block></category><category name="Variables" custom="VARIABLE"></category><category name="Functions" custom="PROCEDURE"></category></xml>';
};
codepage.readonly = function(opt_data, opt_ignored, opt_ijData) {
return codepage.messages(null, null, opt_ijData) + '<script type="text/javascript" src="../../blockly_compressed.js"><\/script><script type="text/javascript" src="../../blocks_compressed.js"><\/script><script type="text/javascript" src="../../' + soy.$$escapeHtml(opt_ijData.langSrc) + '"><\/script><div id="blockly"></div>';
};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="google" value="notranslate">
<title>Blockly : Code</title>
<link rel="stylesheet" type="text/css" href="../common.css">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="../_soy/soyutils.js"></script>
<script type="text/javascript" src="../common.js"></script>
<script type="text/javascript" src="code.js"></script>
<!--script type="text/javascript" src="/storage.js"></script-->
</head>
<body>
<script type="text/javascript">
document.write(codepage.start({}, null,
{lang: BlocklyApps.LANG,
langSrc: BlocklyApps.languagePack()}));
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="google" value="notranslate">
<title>Blockly : Code Readonly</title>
<script type="text/javascript" src="../_soy/soyutils.js"></script>
<script type="text/javascript" src="../common.js"></script>
<script type="text/javascript" src="code.js"></script>
<style>
html, body {
background-color: #fff;
margin: 0;
padding: 0;
overflow: hidden;
height: 100%;
}
#blockly>svg {
border: none;
}
#blockly {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<script type="text/javascript">
document.write(codepage.readonly({}, null,
{langSrc: BlocklyApps.languagePack()}));
</script>
</body>
</html>
html, body {
height: 100%;
}
body {
margin: 0;
overflow: hidden;
}
h1 {
margin-left: 5px;
margin-right: 5px;
}
/* Tabs */
#tabRow>td {
border: 1px solid #ccc;
}
td.tabon {
border-bottom-color: #ddd !important;
background-color: #ddd;
padding: 5px 19px;
}
td.taboff {
cursor: pointer;
padding: 5px 19px;
}
td.taboff:hover {
background-color: #eee;
}
td.tabmin {
border-top-style: none !important;
border-left-style: none !important;
border-right-style: none !important;
}
td.tabmax {
border-top-style: none !important;
border-left-style: none !important;
border-right-style: none !important;
width: 99%;
padding-left: 10px;
padding-right: 10px;
text-align: right;
}
html[dir=rtl] td.tabmax {
text-align: left;
}
table {
border-collapse: collapse;
margin: 0;
padding: 0;
border: none;
}
td {
padding: 0;
vertical-align: top;
}
.content {
visibility: hidden;
margin: 0;
padding: 1ex;
position: absolute;
direction: ltr;
}
pre.content {
overflow: scroll;
}
#content_blocks {
padding: 0;
}
.blocklySvg {
border-top: none !important;
}
#content_xml {
resize: none;
outline: none;
border: none;
font-family: monospace;
overflow: scroll;
}
#languageMenu {
vertical-align: top;
margin-top: 15px;
margin-right: 15px;
}
/* Buttons */
button {
padding: 1px 10px;
margin: 1px 5px;
}
/* Sprited icons. */
.icon21 {
height: 21px;
width: 21px;
background-image: url(icons.png);
}
.trash {
background-position: 0px 0px;
}
.link {
background-position: -21px 0px;
}
.run {
background-position: -42px 0px;
}
{namespace codepage}
/**
* This is a Closure Template.
*
* To regenerate just en.js, run this command:
* java -jar ../_soy/SoyToJsSrcCompiler.jar --outputPathFormat generated/en.js --srcs ../common.soy,template.soy
*
* To regenerate all files, see: trunk/apps/common.soy
*/
/**
* Translated messages for use in JavaScript.
*/
{template .messages}
{call apps.messages /}
<div style="display: none">
<span id="Code_badXml">{msg meaning="Code.badXml" desc="alert - Message shown when the user tries switching from the XML tab after entering XML text that could not be parsed. This asks whether they wish to abandon the XML they added. If they select 'OK' (or the translated equivalent), the XML is cleared, and the other tab is shown. If they select 'Cancel', they remain on the XML tab with the bad XML.\n\nUsed in JavaScript <code>window.confirm()</code>."}Error parsing XML:\n%1\n\nSelect 'OK' to abandon your changes or 'Cancel' to further edit the XML.{/msg}</span>
<span id="Code_badCode">{msg meaning="Code.badCode" desc="alert - Message shown if an error occurs while interpreting the user program. The error description follows."}Program error:\n%1{/msg}</span>
<span id="Code_timeout">{msg meaning="Code.timeout" desc="alert - Message shown if the program has run for more than the permitted number of steps. This exists so that programs with infinite loops do not run forever."}Maximum execution iterations exceeded.{/msg}</span>
<span id="Code_discard">{msg meaning="Code.discard" desc="alert - Message shown after the user clicks on the 'discard all' icon. Selecting 'OK' (or the translated equivalent) causes all of the blocks to be discarded. Selecting 'Cancel' prevents blocks from being deleted.\n\nParameters:\n* %1 - number of blocks to be deleted. It is always an integer greater than or equal to 2."}Delete all %1 blocks?{/msg}</span>
</div>
{/template}
/**
* Web page structure.
*/
{template .start}
{call .messages /}
<script type="text/javascript" src="../../blockly_compressed.js"></script>
<script type="text/javascript" src="../../blocks_compressed.js"></script>
<script type="text/javascript" src="../../generators/arduino.js"></script>
<script type="text/javascript" src="../../generators/arduino/base.js"></script>
<script type="text/javascript" src="../../generators/arduino/control.js"></script>
<script type="text/javascript" src="../../generators/arduino/logic.js"></script>
<!--script type="text/javascript" src="../../generators/arduino/loops.js"></script-->
<script type="text/javascript" src="../../generators/arduino/math.js"></script>
<script type="text/javascript" src="../../generators/arduino/text.js"></script>
<script type="text/javascript" src="../../generators/arduino/lists.js"></script>
<script type="text/javascript" src="../../generators/arduino/colour.js"></script>
<script type="text/javascript" src="../../generators/arduino/variables.js"></script>
<script type="text/javascript" src="../../generators/arduino/procedures.js"></script>
<script type="text/javascript" src="../../javascript_compressed.js"></script>
<script type="text/javascript" src="../../python_compressed.js"></script>
<script type="text/javascript" src="../../dart_compressed.js"></script>
<script type="text/javascript" src="../../{$ij.langSrc}"></script>
<table width="100%" height="100%">
<tr>
<td>
<h1>
<span id="title">
<a href="../index.html?lang={$ij.lang}">{msg meaning="Apps.blocklyMessage" desc="IBID"}Blockllllly{/msg}</a>
{sp}:{sp}
{{msg meaning="Code.title" desc="title - Title of this application, indicating that it is for writing arbitrary programs.\n{lb}{lb}Identical|Code{rb}{rb}"}}
Code
{{/msg}}
</span>
</h1>
</td>
<td class="farSide">
<select id="languageMenu"></select>
</td>
</tr>
<tr>
<td colspan=2>
<table width="100%">
<tr id="tabRow" height="1em">
<td id="tab_blocks" class="tabon">{{msg meaning="Code.blocks" desc="tab text - Displays and allows editing of the user's program as blocks.\n{lb}{lb}Identical|Blocks{rb}{rb}"}}Blocks{{/msg}}</td>
<td class="tabmin">&nbsp;</td>
<td id="tab_arduino" class="taboff">Arduino</td>
<td class="tabmin">&nbsp;</td>
<td id="tab_javascript" class="taboff">JavaScript</td>
<td class="tabmin">&nbsp;</td>
<td id="tab_python" class="taboff">Python</td>
<td class="tabmin">&nbsp;</td>
<td id="tab_dart" class="taboff">Dart</td>
<td class="tabmin">&nbsp;</td>
<td id="tab_xml" class="taboff">XML</td>
<td class="tabmax">
<button id="trashButton" class="notext" title="{msg meaning="Code.trashTooltip" desc="tooltip - Clicking on this causes the user program to be discarded."}Discard all blocks.{/msg}">
<img src='../../media/1x1.gif' class="trash icon21">
</button>{sp}
<button id="linkButton" class="notext" title="{msg meaning="Apps.linkTooltip" desc="IBID."}Save and link to blocks.{/msg}">
<img src='../../media/1x1.gif' class="link icon21">
</button>{sp}
<button id="runButton" class="notext primary" title="{msg meaning="Apps.runTooltip" desc="IBID"}Run the program defined by the blocks in the workspace.{/msg}">
<img src='../../media/1x1.gif' class="run icon21">
</button>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="99%" colspan=2 id="content_area">
{call .toolbox /}
</td>
</tr>
</table>
<div id="content_blocks" class="content"></div>
<pre id="content_arduino" class="content"></pre>
<pre id="content_javascript" class="content"></pre>
<pre id="content_python" class="content"></pre>
<pre id="content_dart" class="content"></pre>
<textarea id="content_xml" class="content" wrap="off"></textarea>
{call apps.dialog /}
{call apps.storageDialog /}
{/template}
/**
* Toolbox.
*/
{template .toolbox}
<xml id="toolbox" style="display: none">
<category name="{msg meaning="Apps.catLogic" desc="IBID"}Logic{/msg}">
<block type="controls_if"></block>
<block type="logic_compare"></block>
<block type="logic_operation"></block>
<block type="logic_negate"></block>
<block type="logic_boolean"></block>
<block type="logic_null"></block>
<block type="logic_ternary"></block>
</category>
<category name="{msg meaning="Apps.catLoops" desc="IBID"}Loops{/msg}">
<block type="controls_repeat_ext">
<value name="TIMES">
<block type="math_number">
<field name="NUM">10</field>
</block>
</value>
</block>
<block type="controls_whileUntil"></block>
<block type="controls_for">
<value name="FROM">
<block type="math_number">
<field name="NUM">1</field>
</block>
</value>
<value name="TO">
<block type="math_number">
<field name="NUM">10</field>
</block>
</value>
<value name="BY">
<block type="math_number">
<field name="NUM">1</field>
</block>
</value>
</block>
<block type="controls_forEach"></block>
<block type="controls_flow_statements"></block>
</category>
<category name="{msg meaning="Apps.catMath" desc="IBID"}Math{/msg}">
<block type="math_number"></block>
<block type="math_arithmetic"></block>
<block type="math_single"></block>
<block type="math_trig"></block>
<block type="math_constant"></block>
<block type="math_number_property"></block>
<block type="math_change">
<value name="DELTA">
<block type="math_number">
<field name="NUM">1</field>
</block>
</value>
</block>
<block type="math_round"></block>
<block type="math_on_list"></block>
<block type="math_modulo"></block>
<block type="math_constrain">
<value name="LOW">
<block type="math_number">
<field name="NUM">1</field>
</block>
</value>
<value name="HIGH">
<block type="math_number">
<field name="NUM">100</field>
</block>
</value>
</block>
<block type="math_random_int">
<value name="FROM">
<block type="math_number">
<field name="NUM">1</field>
</block>
</value>
<value name="TO">
<block type="math_number">
<field name="NUM">100</field>
</block>
</value>
</block>
<block type="math_random_float"></block>
</category>
<category name="{msg meaning="Apps.catText" desc="IBID"}Text{/msg}">
<block type="text"></block>
<block type="text_join"></block>
<block type="text_append">
<value name="TEXT">
<block type="text"></block>
</value>
</block>
<block type="text_length"></block>
<block type="text_isEmpty"></block>
<block type="text_indexOf">
<value name="VALUE">
<block type="variables_get">
<field name="VAR">{msg meaning="Apps.textVariable" desc="IBID"}text{/msg}</field>
</block>
</value>
</block>
<block type="text_charAt">
<value name="VALUE">
<block type="variables_get">
<field name="VAR">{msg meaning="Apps.textVariable" desc="IBID"}text{/msg}</field>
</block>
</value>
</block>
<block type="text_getSubstring">
<value name="STRING">
<block type="variables_get">
<field name="VAR">{msg meaning="Apps.textVariable" desc="IBID"}text{/msg}</field>
</block>
</value>
</block>
<block type="text_changeCase"></block>
<block type="text_trim"></block>
<block type="text_print"></block>
<block type="text_prompt_ext">
<value name="TEXT">
<block type="text"></block>
</value>
</block>
</category>
<category name="{msg meaning="Apps.catLists" desc="IBID"}Lists{/msg}">
<block type="lists_create_empty"></block>
<block type="lists_create_with"></block>
<block type="lists_repeat">
<value name="NUM">
<block type="math_number">
<field name="NUM">5</field>
</block>
</value>
</block>
<block type="lists_length"></block>
<block type="lists_isEmpty"></block>
<block type="lists_indexOf">
<value name="VALUE">
<block type="variables_get">
<field name="VAR">{msg meaning="Apps.listVariable" desc="IBID"}list{/msg}</field>
</block>
</value>
</block>
<block type="lists_getIndex">
<value name="VALUE">
<block type="variables_get">
<field name="VAR">{msg meaning="Apps.listVariable" desc="IBID"}list{/msg}</field>
</block>
</value>
</block>
<block type="lists_setIndex">
<value name="LIST">
<block type="variables_get">
<field name="VAR">{msg meaning="Apps.listVariable" desc="IBID"}list{/msg}</field>
</block>
</value>
</block>
<block type="lists_getSublist">
<value name="LIST">
<block type="variables_get">
<field name="VAR">{msg meaning="Apps.listVariable" desc="IBID"}list{/msg}</field>
</block>
</value>
</block>
</category>
<category name="{msg meaning="Apps.catColour" desc="IBID"}Colour{/msg}">
<block type="colour_picker"></block>
<block type="colour_random"></block>
<block type="colour_rgb"></block>
<block type="colour_blend"></block>
</category>
<category name="{msg meaning="Apps.catVariables" desc="IBID"}Variables{/msg}" custom="VARIABLE"></category>
<category name="{msg meaning="Apps.catProcedures" desc="IBID"}Functions{/msg}" custom="PROCEDURE"></category>
</xml>
{/template}
/**
* Readonly Blockly in an iframe.
*/
{template .readonly}
{call .messages /}
<script type="text/javascript" src="../../blockly_compressed.js"></script>
<script type="text/javascript" src="../../blocks_compressed.js"></script>
<script type="text/javascript" src="../../{$ij.langSrc}"></script>
<div id="blockly"></div>
{/template}
...@@ -14,6 +14,16 @@ ...@@ -14,6 +14,16 @@
<script type="text/javascript" src="../../generators/javascript/colour.js"></script> <script type="text/javascript" src="../../generators/javascript/colour.js"></script>
<script type="text/javascript" src="../../generators/javascript/variables.js"></script> <script type="text/javascript" src="../../generators/javascript/variables.js"></script>
<script type="text/javascript" src="../../generators/javascript/procedures.js"></script> <script type="text/javascript" src="../../generators/javascript/procedures.js"></script>
<script type="text/javascript" src="../../generators/arduino.js"></script>
<!--script type="text/javascript" src="unittest_arduino.js"></script-->
<script type="text/javascript" src="../../generators/arduino/logic.js"></script>
<script type="text/javascript" src="../../generators/arduino/loops.js"></script>
<script type="text/javascript" src="../../generators/arduino/math.js"></script>
<script type="text/javascript" src="../../generators/arduino/text.js"></script>
<script type="text/javascript" src="../../generators/arduino/lists.js"></script>
<script type="text/javascript" src="../../generators/arduino/colour.js"></script>
<script type="text/javascript" src="../../generators/arduino/variables.js"></script>
<script type="text/javascript" src="../../generators/arduino/procedures.js"></script>
<script type="text/javascript" src="../../generators/python.js"></script> <script type="text/javascript" src="../../generators/python.js"></script>
<script type="text/javascript" src="unittest_python.js"></script> <script type="text/javascript" src="unittest_python.js"></script>
<script type="text/javascript" src="../../generators/python/logic.js"></script> <script type="text/javascript" src="../../generators/python/logic.js"></script>
...@@ -114,6 +124,12 @@ function toXml() { ...@@ -114,6 +124,12 @@ function toXml() {
setOutput(xmlText); setOutput(xmlText);
} }
function toArduino() {
var code = '\'use strict\';\n\n'
code += Blockly.Arduino.workspaceToCode();
setOutput(code);
}
function toJavaScript() { function toJavaScript() {
var code = '\'use strict\';\n\n' var code = '\'use strict\';\n\n'
code += Blockly.JavaScript.workspaceToCode(); code += Blockly.JavaScript.workspaceToCode();
...@@ -398,6 +414,7 @@ h1 { ...@@ -398,6 +414,7 @@ h1 {
<p> <p>
Generate: Generate:
<input type="button" value="XML" onclick="toXml()"> <input type="button" value="XML" onclick="toXml()">
<input type="button" value="Arduino" onclick="toArduino()">
<input type="button" value="JavaScript" onclick="toJavaScript()"> <input type="button" value="JavaScript" onclick="toJavaScript()">
<input type="button" value="Python" onclick="toPython()"> <input type="button" value="Python" onclick="toPython()">
<input type="button" value="Dart" onclick="toDart()"> <input type="button" value="Dart" onclick="toDart()">
......
...@@ -4,6 +4,15 @@ ...@@ -4,6 +4,15 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>Blockly Playground</title> <title>Blockly Playground</title>
<script type="text/javascript" src="../blockly_uncompressed.js"></script> <script type="text/javascript" src="../blockly_uncompressed.js"></script>
<script type="text/javascript" src="../../generators/arduino.js"></script>
<script type="text/javascript" src="../../generators/arduino/logic.js"></script>
<script type="text/javascript" src="../../generators/arduino/loops.js"></script>
<script type="text/javascript" src="../../generators/arduino/math.js"></script>
<script type="text/javascript" src="../../generators/arduino/text.js"></script>
<script type="text/javascript" src="../../generators/arduino/lists.js"></script>
<script type="text/javascript" src="../../generators/arduino/colour.js"></script>
<script type="text/javascript" src="../../generators/arduino/variables.js"></script>
<script type="text/javascript" src="../../generators/arduino/procedures.js"></script>
<script type="text/javascript" src="../generators/javascript.js"></script> <script type="text/javascript" src="../generators/javascript.js"></script>
<script type="text/javascript" src="../generators/javascript/logic.js"></script> <script type="text/javascript" src="../generators/javascript/logic.js"></script>
<script type="text/javascript" src="../generators/javascript/loops.js"></script> <script type="text/javascript" src="../generators/javascript/loops.js"></script>
...@@ -374,6 +383,8 @@ h1 { ...@@ -374,6 +383,8 @@ h1 {
&nbsp; &nbsp;
<input type="button" value="Import from XML" onclick="fromXml()"> <input type="button" value="Import from XML" onclick="fromXml()">
<br> <br>
<input type="button" value="To Arduino" onclick="toCode('Arduino')">
&nbsp;
<input type="button" value="To JavaScript" onclick="toCode('JavaScript')"> <input type="button" value="To JavaScript" onclick="toCode('JavaScript')">
&nbsp; &nbsp;
<input type="button" value="To Python" onclick="toCode('Python')"> <input type="button" value="To Python" onclick="toCode('Python')">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment