The code provided below is SO close to working the way I want it to. The behavior of the block works, however, the shape does not update unless I move the block on the workspace.
Here's the block definition and the Python generator (which i realize has no 'code' in it). I'll work out the Python stuff after the block works the way it's supposed to.
Blockly.Blocks['custom_block'] = {
init: function() {
var block = this;
this.appendDummyInput()
.appendField("Wait ")
.appendField(new Blockly.FieldNumber(0, 0, 23, 1), "hours")
.appendField("H ")
.appendField(new Blockly.FieldNumber(0, 0, 59, 1), "minutes")
.appendField("M ")
.appendField(new Blockly.FieldNumber(0, 0, 59, 1), "seconds")
.appendField("S ")
.appendField(new Blockly.FieldNumber(0, 0, 999, 1), "milliseconds")
.appendField("ms ");
this.appendDummyInput("showOnRunInput")
.appendField("Show on Run Screen:")
.appendField(new Blockly.FieldCheckbox("FALSE", function(value) {
block.updateShape_(value === 'TRUE');
block.setCollapsed(false); // Force an update to fix rendering issues
block.render(); // Render the block to update its shape
}), "checkbox");
this.appendDummyInput("variableInput")
.appendField("Select Timer Alias:")
.appendField(new Blockly.FieldVariable("Timer Alias"), "TimerAlias")
.setVisible(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
// Delay the rendering process until after the block is initialized
setTimeout(function() {
block.updateShape_(block.getFieldValue('checkbox') === 'TRUE');
}, 0);
},
updateShape_: function(value) {
var variableInput = this.getInput('variableInput');
// Check if the block is in the toolbox and the checkbox is false
var isInToolbox = this.isInFlyout || (this.workspace && this.workspace.isFlyout);
variableInput.setVisible(!isInToolbox && value);
// Rerender the block to update its shape
if (this.rendered) {
this.render();
}
}
};
Blockly.Python['custom_block'] = function(block) {
// Generate Python code for the block.
// You can customize this function to define the desired behavior.
var code = '...';
return code;
};