-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtuple.js
More file actions
56 lines (55 loc) · 1.7 KB
/
Copy pathtuple.js
File metadata and controls
56 lines (55 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Blockly.Python['tuple_create'] = function(block) {
// Create a list with any number of elements of any type.
var elements = new Array(block.itemCount_);
for (var i = 0; i < block.itemCount_; i++) {
elements[i] = (Blockly.Python.valueToCode(block, 'ADD' + i,
Blockly.Python.ORDER_NONE) || '___' );
}
var code = elements.join(', ');
if (block.itemCount_ == 1) {
code = '(' + code + ',)';
} else {
code = '(' + code + ')';
}
return [code, Blockly.Python.ORDER_ATOMIC];
}
Blockly.Blocks['tuple_create'] = {
/**
* Block for creating a list with any number of elements of any type.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl(Blockly.Msg.LISTS_CREATE_WITH_HELPURL);
this.setColour(Blockly.Blocks.lists.HUE+10);
this.itemCount_ = 3;
this.updateShape_();
this.setOutput(true, 'Tuple');
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_TOOLTIP);
},
/**
* Create XML to represent list inputs.
* @return {!Element} XML storage element.
* @this Blockly.Block
*/
mutationToDom: function() {
var container = document.createElement('mutation');
container.setAttribute('items', this.itemCount_);
return container;
},
/**
* Parse XML to restore the list inputs.
* @param {!Element} xmlElement XML storage element.
* @this Blockly.Block
*/
domToMutation: function(xmlElement) {
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
this.updateShape_();
},
/**
* Modify this block to have the correct number of inputs.
* @private
* @this Blockly.Block
*/
updateShape_: PLUS_MINUS_updateShape('ADD', "create tuple of")
};