Skip to content

Commit

Permalink
set attribute block
Browse files Browse the repository at this point in the history
  • Loading branch information
eskim committed Apr 14, 2015
1 parent effcc3e commit 14bea09
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
35 changes: 35 additions & 0 deletions rocon_composer_blockly/public/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,25 @@ Blockly.Blocks['ui_text'] = {

};

Blockly.Blocks['ui_set_attr'] = {

init: function() {
this.setColour(30);
this.appendDummyInput().appendField('Set Attribute' + name);

this.appendDummyInput().appendField('name:')
.appendField(new Blockly.FieldTextInput('name', null), 'NAME');

this.appendValueInput('ATTR').appendField('attr:');
this.appendValueInput('VALUE').appendField('value:');
this.setInputsInline(true);
this.setPreviousStatement(true);
return this.setNextStatement(true);


},

};
Blockly.Blocks['ui_button'] = {

init: function() {
Expand All @@ -2127,6 +2146,22 @@ Blockly.Blocks['ui_button'] = {
},

};
Blockly.JavaScript['ui_set_attr'] = function(block){
var attr = Blockly.JavaScript.valueToCode(block, 'ATTR', Blockly.JavaScript.ORDER_NONE) || "''";
var value = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_NONE) || "''";
var name = block.getFieldValue('NAME');


var data = {
rocon_id: name,
attr: eval(attr),
value: eval(value)
};
var code = _.template('$engine.publish("to-rocon-ui", "std_msgs/String", {data: <%= data %>});')({
data: "'" + JSON.stringify(data) + "'"
});
return code;
};
Blockly.JavaScript['ui_button'] = function(block){
var text = Blockly.JavaScript.valueToCode(block, 'TEXT', Blockly.JavaScript.ORDER_NONE) || "''";
var name = block.getFieldValue('NAME');
Expand Down
35 changes: 35 additions & 0 deletions rocon_composer_blockly/public/js/blocks/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ Blockly.Blocks['ui_text'] = {

};

Blockly.Blocks['ui_set_attr'] = {

init: function() {
this.setColour(30);
this.appendDummyInput().appendField('Set Attribute' + name);

this.appendDummyInput().appendField('name:')
.appendField(new Blockly.FieldTextInput('name', null), 'NAME');

this.appendValueInput('ATTR').appendField('attr:');
this.appendValueInput('VALUE').appendField('value:');
this.setInputsInline(true);
this.setPreviousStatement(true);
return this.setNextStatement(true);


},

};
Blockly.Blocks['ui_button'] = {

init: function() {
Expand All @@ -84,6 +103,22 @@ Blockly.Blocks['ui_button'] = {
},

};
Blockly.JavaScript['ui_set_attr'] = function(block){
var attr = Blockly.JavaScript.valueToCode(block, 'ATTR', Blockly.JavaScript.ORDER_NONE) || "''";
var value = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_NONE) || "''";
var name = block.getFieldValue('NAME');


var data = {
rocon_id: name,
attr: eval(attr),
value: eval(value)
};
var code = _.template('$engine.publish("to-rocon-ui", "std_msgs/String", {data: <%= data %>});')({
data: "'" + JSON.stringify(data) + "'"
});
return code;
};
Blockly.JavaScript['ui_button'] = function(block){
var text = Blockly.JavaScript.valueToCode(block, 'TEXT', Blockly.JavaScript.ORDER_NONE) || "''";
var name = block.getFieldValue('NAME');
Expand Down
4 changes: 4 additions & 0 deletions rocon_composer_blockly/public/js/tpl/blockly.html
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ <h3>List</h3>
<block type="text" />
</value>
</block>
<block type="ui_set_attr">
<value name="ATTR"><block type="text" /></value>
<value name="VALUE"><block type="text" /></value>
</block>
<block type="prezi_next_with_channel" />
<block type="prezi_prev_with_channel" />
<block type="prezi_move_with_channel" />
Expand Down

0 comments on commit 14bea09

Please sign in to comment.