123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>JSDoc: Source: custom_blocks.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: custom_blocks.js</h1>
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>Blockly.Blocks['dicts_create_with_container'] = {
- /**
- * Dictionary block container
- * @this Blockly.Block
- */
- init: function() {
- this.setColour(Blockly.Blocks.dicts.HUE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.DICTS_CREATE_WITH_CONTAINER_TITLE_ADD);
- this.appendStatementInput('STACK');
- this.setTooltip(Blockly.Msg.DICTS_CREATE_WITH_CONTAINER_TOOLTIP);
- this.contextMenu = false;
- }
- };
- Blockly.Blocks['dicts_create_with_item'] = {
- // Add items.
- init: function() {
- this.setColour(Blockly.Blocks.dicts.HUE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.DICTS_CREATE_WITH_ITEM_TITLE);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setTooltip(Blockly.Msg.DICTS_CREATE_WITH_ITEM_TOOLTIP);
- this.contextMenu = false;
- }
- };
- Blockly.Blocks['dicts_create_with'] = {
- /**
- * Block for creating a dict with any number of elements of any type.
- * @this Blockly.Block
- */
- init: function() {
- console.log("init");
- this.setInputsInline(false);
- this.setColour(Blockly.Blocks.dicts.HUE);
- this.itemCount_ = 1;
- this.updateShape_();
- this.setOutput(true, 'dict');
- this.setMutator(new Blockly.Mutator(['dicts_create_with_item']));
- this.setTooltip(Blockly.Msg.DICTS_CREATE_WITH_TOOLTIP);
- },
- /**
- * Create XML to represent dict inputs.
- * @return {Element} XML storage element.
- * @this Blockly.Block
- */
- mutationToDom: function(workspace) {
- console.log("mutationToDom");
- var container = document.createElement('mutation');
- container.setAttribute('items', this.itemCount_);
- return container;
- },
- /**
- * Parse XML to restore the dict inputs.
- * @param {!Element} xmlElement XML storage element.
- * @this Blockly.Block
- */
- domToMutation: function(xmlElement) {
- console.log("domToMutation");
- this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
- this.updateShape_();
- },
- /**
- * Modify this block to have the correct number of inputs.
- * @private
- * @this Blockly.Block
- */
- updateShape_: function() {
- console.log("updateShape");
- // Delete everything.
- if (this.getInput("EMPTY")) {
- this.removeInput('EMPTY');
- }
- var keyNames = [];
- for (var i = 0; this.getInput('VALUE' + i); i++) {
- //this.getInput('VALUE' + i).removeField("KEY"+i);
- keyNames.push(this.getFieldValue("KEY"+i))
- this.removeInput('VALUE' + i);
- }
- // Rebuild block.
- if (this.itemCount_ == 0) {
- this.appendDummyInput('EMPTY')
- .appendField(Blockly.Msg.DICTS_CREATE_EMPTY_TITLE);
- } else {
- this.appendDummyInput('EMPTY')
- .appendField(Blockly.Msg.DICTS_CREATE_WITH_INPUT_WITH);
- for (var i = 0; i < this.itemCount_; i++) {
- this.appendValueInput('VALUE' + i)
- .setCheck(null)
- .setAlign(Blockly.ALIGN_RIGHT)
- .appendField(
- new Blockly.FieldTextInput(
- keyNames.length > i
- ? keyNames[i]
- : Blockly.Msg.DICTS_CREATE_WITH_ITEM_KEY),
- 'KEY'+i)
- .appendField(Blockly.Msg.DICTS_CREATE_WITH_ITEM_MAPPING);
- }
- }
- },
- /**
- * Populate the mutator's dialog with this block's components.
- * @param {!Blockly.Workspace} workspace Mutator's workspace.
- * @return {!Blockly.Block} Root block in mutator.
- * @this Blockly.Block
- */
- decompose: function(workspace) {
- console.log("Decompose");
- var containerBlock = workspace.newBlock('dicts_create_with_container');
- containerBlock.initSvg();
- var connection = containerBlock.getInput('STACK').connection;
- for (var x = 0; x < this.itemCount_; x++) {
- var itemBlock = workspace.newBlock('dicts_create_with_item');
- itemBlock.initSvg();
- connection.connect(itemBlock.previousConnection);
- connection = itemBlock.nextConnection;
- }
- return containerBlock;
- },
- /**
- * Reconfigure this block based on the mutator dialog's components.
- * @param {!Blockly.Block} containerBlock Root block in mutator.
- * @this Blockly.Block
- */
- compose: function(containerBlock) {
- console.log("Compose");
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- // Count number of inputs.
- var connections = [];
- var i = 0;
- while (itemBlock) {
- connections[i] = itemBlock.valueConnection_;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- i++;
- }
- this.itemCount_ = i;
- this.updateShape_();
- // Reconnect any child blocks.
- for (var i = 0; i < this.itemCount_; i++) {
- if (connections[i]) {
- this.getInput('VALUE' + i).connection.connect(connections[i]);
- }
- }
- },
- /**
- * Store pointers to any connected child blocks.
- * @param {!Blockly.Block} containerBlock Root block in mutator.
- * @this Blockly.Block
- */
- saveConnections: function(containerBlock) {
- console.log("SaveConnections");
- // Store a pointer to any connected child blocks.
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var x = 0;
- while (itemBlock) {
- var value_input = this.getInput('VALUE' + x);
- itemBlock.valueConnection_ = value_input && value_input.connection.targetConnection;
- x++;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- }
- };
- </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>
|