Skip to content

Commit

Permalink
delay block
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandruradovici committed Oct 28, 2019
1 parent a182156 commit e0a8157
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

* **added** social (email, facebook twitter and twilio) visual programming blocks
* **added** Adafruit DHT sensor visual programming blocks for Raspberry Pi and BeagleBone Black
* **added** delay block to visual programming blocks
* **feature** Wyapp PackageManager search with any case
* **fixed** Wyapp FileManager dispalying double names
* **fixed** (partially) scroll bug in Firefox (temporary fix)
Expand Down
Expand Up @@ -40,6 +40,11 @@ module.exports = function (blockly) {
return [code, Blockly.JavaScript.ORDER_NONE];
};

Blockly.JavaScript['delay'] = function(/* block */) {
var code = '// the delay function is not in javascript\n';
return code;
};

Blockly.JavaScript['format_numbers'] = function (block) {
var dropdown_name = block.getFieldValue('NAME');
var value_number = Blockly.Python.valueToCode(block, 'number', Blockly.Python.ORDER_ATOMIC);
Expand Down
@@ -1,6 +1,14 @@
module.exports = function (blockly) {
let Blockly = blockly.Blockly;

Blockly.Python.importtime = function ()
{
if (!Blockly.Python.definitions_['import_time'])
{
Blockly.Python.definitions_['import_time'] = 'from time import *\n';
}
};

Blockly.Python.datetime = function () {
if (!Blockly.Python.definitions_['import_datetime']) {
Blockly.Python.definitions_['import_datetime'] = 'from datetime import *\n';
Expand Down Expand Up @@ -70,4 +78,26 @@ module.exports = function (blockly) {
// TODO: Change ORDER_NONE to the correct strength.
return [code, Blockly.Python.ORDER_NONE];
};

Blockly.Python['delay'] = function(block) {
Blockly.Python.importtime ();
var value_millis = Blockly.Python.valueToCode(block, 'millis', Blockly.Python.ORDER_ATOMIC);
var type = parseInt (block.getFieldValue('type'));
if (isNaN(type)) type = 0;
// TODO: Assemble Python into code variable.
var code = '';
if (type === 0)
{
code = 'sleep (('+value_millis+')/1000.0'+')\n';
}
else if (type === 1)
{
code = 'sleep (('+value_millis+')/1000000.0)\n';
}
else
{
code = 'sleep ('+value_millis+')\n';
}
return code;
};
};
Expand Up @@ -28,6 +28,22 @@ module.exports = function (blockly) {
}
};

Blockly.Blocks['delay'] = {
init: function() {
this.setHelpUrl('https://projects.wyliodrin.com/wiki/languages/visual#delay');
this.setColour(180);
this.appendValueInput('millis')
.setCheck('Number')
.appendField('delay');
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([['milliseconds', '0'], ['microseconds', '1'], ['seconds', '2']]), 'type');
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip('Wait for some specified period.');
}
};

Blockly.Blocks['format_numbers'] = {
init: function () {
this.setHelpUrl('http://www.example.com/');
Expand Down
9 changes: 8 additions & 1 deletion source/plugins/language.visual.wyapp/visual/toolbox.xml
@@ -1,7 +1,14 @@
<toolbox>
<category name="Date and Hour" colour="180">
<category name="Date and Time" colour="180">
<block type="get_date"></block>
<block type="get_time"></block>
<block type="delay">
<value name="millis">
<block type="math_number">
<field name="NUM">1000</field>
</block>
</value>
</block>
<block type="format_numbers"></block>
</category>
<category name="HTTP" colour="230">
Expand Down
Expand Up @@ -444,5 +444,5 @@ module.exports = function (blockly) {
this.setTooltip('');
}
};

};
Expand Up @@ -9,7 +9,7 @@ module.exports = function (blockly) {
if (!Blockly.Python.definitions_['import_json']) {
Blockly.Python.definitions_['import_json'] = 'import json\n';
}
}
};

Blockly.Python['print'] = function (block) {
var value_value = Blockly.Python.valueToCode(block, 'value', Blockly.Python.ORDER_ATOMIC);
Expand Down Expand Up @@ -228,7 +228,7 @@ module.exports = function (blockly) {
var key = Blockly.Python.quote_(block.getFieldValue('KEY' + n));
var value = Blockly.Python.valueToCode(block, 'VALUE' + n,
Blockly.Python.ORDER_NONE) || '___';
code[n] = key + ": " + value;
code[n] = key + ': ' + value;
}
code = '{' + code.join(', ') + '}';
return [code, Blockly.Python.ORDER_ATOMIC];
Expand Down

0 comments on commit e0a8157

Please sign in to comment.