What does 'disabled' mean exactly (in Scratch blocks)?

114 views
Skip to first unread message

Matthew Bishop

unread,
Aug 9, 2019, 4:33:19 PM8/9/19
to Blockly
When a block is 'disabled', what can I expect to be different about it? I am trying to disable the following actions on a block in the workspace:

1. Cannot drag it into a new position
2. Cannot add / remove child blocks
3. Cannot edit fields
4. Blocks and their fields change appearance to 'look' ineditable

However, I see none of these things on workspace blocks that have been disabled. Here is how I am setting the disabled flag:

designWorkspace.getAllBlocks()
.forEach(b => b.setDisabled(isDisabled))

Sam El-Husseini

unread,
Aug 9, 2019, 5:57:14 PM8/9/19
to Blockly
Hey Matthew, 

A disabled block is a block that
  • If in the Flyout, it can not be dragged out of the Flyout.
  • Looks disabled, we render a disabled pattern on it
  • If it somehow ends up on the workspace (through XML / JS), it can still be interacted with.
  • If a parent block is disabled, so are the child blocks be. 
If what you're after is a read only workspace. A workspace where none of the blocks in it can be moved, or edited. There is a workspace option for that.
{readonly: true}

If you want to allow editing of some blocks but not others, then you can set a block's movable property to false
block.setMovable(false);

That might be a little limiting, you can achieve some of what you're after above. For example, you can set all blocks in a stack to setMovable(false) and you won't be able to remove blocks from the stack. However a user can still add blocks to the stack. 

Additionally, for fields, there isn't a property that will get you that from the xml / JS.

Cheers, 
Sam
Message has been deleted

Sam El-Husseini

unread,
Aug 9, 2019, 6:34:17 PM8/9/19
to Blockly
You will have to reload the workspace in order to change that setting. It also means there won't be a toolbox in that mode. 

You might also try the overlay method discussed here if you're just trying to momentarily disable user interaction: 


On Friday, August 9, 2019 at 3:28:02 PM UTC-7, Matthew Bishop wrote:
This might work. I want to make the workspace read-only when a WebSocket connection is down, and re-enable editing when the connection is reestablished.

Matthew Bishop

unread,
Aug 9, 2019, 6:38:31 PM8/9/19
to Blockly
I want to make the workspace read-only when a WebSocket connection is down, and re-enable editing when the connection is reestablished.

The toolbox can be disabled easily, I guess I am running into a gap in scratch-blocks? setting workspace blocks to disabled (also non-editable) appears to have no effect.

Matthew Bishop

unread,
Aug 9, 2019, 6:52:38 PM8/9/19
to Blockly
In answer to my own question, Scratch does not support disabled blocks: 

However I can simulate "disabled" close enough for my purposes with this:

designWorkspace.getAllBlocks()
.forEach(b => {
b.setMovable(!isDisabled)
b.setEditable(!isDisabled)
  }) 
Reply all
Reply to author
Forward
0 new messages