How to create shared toolbox

已查看 90 次
跳至第一个未读帖子

Víctor Moreno

未读,
2021年4月30日 13:30:332021/4/30
收件人 Blockly
Hi, 

My project needs to display two workspaces for which the same blocks can be used. I would like to have only one toolbox for both of the workspaces instead of one toolbox for each of them.

Is there a way to achieve this?

Beka Westberg

未读,
2021年5月1日 15:25:032021/5/1
收件人 blo...@googlegroups.com
Hello Victor,

As far as I know, not really :/ The issue is that (1) the toolbox' flyout creates blocks in the workspace it is attached to and (2) the block dragger does not support dragging blocks between workspaces.

If possible, I recommend using a sort of "pages" approach instead. For example, Scratch has a page/workspace for each sprite that changes based on which sprite you have selected. App Inventor has a similar functionality for different activities, etc. So you might be able to use a toggle to switch between workspaces instead of displaying both at the same time. I'm not sure exactly what you're building though so that may not work with what you're trying to create hehe.

Otherwise your only option is to have a toolbox for each :/ Changing the toolbox position may make this look better.

Sorry I can't be more help :/
--Beka

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/08dee4b7-5cfc-42db-831c-5bfb0e772085n%40googlegroups.com.

Jonty Small

未读,
2021年5月1日 16:18:092021/5/1
收件人 Blockly
Hi Victor,

Why do you need 2 workspaces? Is it to do like 2 different functions? If so why not do something similar to this?
 Capture.PNG
Set up two blocks that have no prior and future connections. Have them occur when the program is loaded then generate two separate pieces of code from the blocks in each of the two start points? 
(put a save function in the onstart block. that saves the code in it to one file. then do the same for your equivalent of forever).

I'm not sure if you can make it that those blocks aren't removable. But if you can do that try that. If you really want it to seem like two workspaces maybe you can have a vertical line splitting between them?
It should functionally do what you want even if it might not look quite how you'd like it to? 

I hope that makes sense and solves your problem? I'm happy to elaborate on the idea more if its not clear

Best,
Jonty

Jason Schanker

未读,
2021年5月1日 22:47:112021/5/1
收件人 Blockly
Hi Victor,

Did you want something that would look like this where there's a toolbox in the center and workspaces to the left and right of it?

If so, you should still be able to simulate this effect in Blockly with one workspace which the user interacts with and two additional generated "mirror" ones that'd you use.  I believe that out of the box, you can set the toolbox vertically on the left or right (or horizontally on the top/bottom), but not in the middle.  However, you can adjust the toolbox's position by overriding the positioning logic (e.g., `Blockly.VerticalFlyout.prototype.getX`).

As for generating mirror workspaces, you could adapt the code from https://blockly-demo.appspot.com/static/demos/mirror/index.html.  Alternatively, if you only need the workspaces at certain points in time and not too often, say when you're generating JavaScript code to run the program from a workspace or when you're serializing to XML, an easy kludgy solution is to:

1. Serialize the entire workspace to XML and store it.
2. Remove all of the blocks to the right of the flyout, serialize it to XML, and then deserialize to create the left workspace.
3. Recreate the entire workspace from the original XML and then remove all of the blocks to the left of the flyout from this workspace.
4. Move all the remaining blocks on the right side left by the flyout's right coordinate and then serialize to XML and use it to generate the right workspace.

I'm also happy to elaborate if this is what you were looking for and you needed more specifics.

Best,
Jason
Screenshot (3164).png

Víctor Moreno

未读,
2021年5月3日 10:51:322021/5/3
收件人 Blockly
Hi guys,

Thank you so much for your great ideas. Ideally, I would need a toolbox on the left and two workspaces on its right, one above the other one.

I will see how the workaround that Jonty proposed works for my users, but it would be great if blockly supported this.

Thank you all again!
回复全部
回复作者
转发
0 个新帖子