Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Blocks #21

Open
JoshuaLowe1002 opened this issue Sep 14, 2020 · 4 comments
Open

Adding Blocks #21

JoshuaLowe1002 opened this issue Sep 14, 2020 · 4 comments

Comments

@JoshuaLowe1002
Copy link

Hi @acbart

Great work on this, super useful tool.

I was wondering if there was any docs on how to add a simple block into BlockMirror and show in the toolbox? That would be super handy.

Josh

@JoshuaLowe1002
Copy link
Author

Hey @acbart, not sure if you've seen this (understand you're super busy) but wanted to reach out to check if you could point me in the right direction! :)

@acbart
Copy link
Collaborator

acbart commented Oct 15, 2020

Hi @JoshuaLowe1002, sorry for the delay. Things are indeed super busy, and I don't have any docs. However, this is actually pretty easy to do in BlockMirror just by editing the toolbars: https://github.com/blockpy-edu/BlockMirror/blob/master/src/toolbars.js#L66

This is an object mapping toolbox names to their list of categories (and string literals).

Each category is an object with name, colour, and blocks list.

The blocks is actually just a list of strings, where each string is a valid chunk of Python code that will be translated to the block representation.

Instead of a category, you can also provide a string literal instead that will be embedded directly. Examples are here for a horizontal separator bar and a special expressions block category: https://github.com/blockpy-edu/BlockMirror/blob/master/src/toolbars.js#L270-L272

Then to actually use a different toolbox, you can pass in toolbox as a field to the BlockMirror constructor: https://github.com/blockpy-edu/BlockMirror/blob/master/src/block_mirror.js#L89

And in fact, I apparently also coded it so that you can create custom toolboxes without ever needing to modify the source code. Instead of passing in the name of a predefined name of a toolbox to the toolbox configuration parameter, you can instead pass in desired list of categories... I think. That last feature I didn't spend much time on, I believe, but I think all the code is there?

If you give it a try and it's successful, feel free to PR some documentation for all of this ;)

@JoshuaLowe1002
Copy link
Author

Awesome thank you @acbart ! Managed to get some blocks added which is great.

One other quick question. Is there an extra step so that the block is detected when doing python to blocks translation? That doesn't seem to be working for me right now :)

@acbart
Copy link
Collaborator

acbart commented Oct 20, 2020

I'm not sure I know what you mean - the text side is not generating blocks automatically when you edit the text side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants