Text editing with blockly

524 views
Skip to first unread message

Burak Bilgehan

unread,
Nov 1, 2016, 6:20:41 AM11/1/16
to Blockly
Hello, I'm new to Blockly, and I just started researching its features.
I want to choose my programming method. Blokly only allows to edit the program with the help of the blocks. I want to make the generated code to be editable by the user, so that the user can both type and drag&drop while creating his/her program.
After that, me and my friends may implement a feature that generates blocks from the given text. Like the opposite functions that Blockly do. I wonder if these are possible?

(It's my first post here, sorry if I said something unrelated/inappropriate.)

Wolfgang Koehler

unread,
Nov 1, 2016, 12:51:42 PM11/1/16
to Blockly
Not sure about editing within Blockly but you could save the file, edit it somewhere else and then re-parse it to create the blocks, For example:

      var childBlock = workspace.newBlock('actOpt');
      var parentConnection = parentBlock.getInput("actionConn").connection;
      childBlock.initSvg();
      childBlock.render();
      var childConnection = childBlock.previousConnection;
      parentConnection.connect(childConnection);

Or you could directly manipulate the blockly XML. Creating the blocks is no problems there are plenty of functions to do that. The problem is to limit your edits in such a way that the edited file still can be successfully parsed.

Neil Fraser

unread,
Nov 1, 2016, 7:17:40 PM11/1/16
to blo...@googlegroups.com
Code to blocks is not supported by Blockly.  There have been a half-dozen attempts to implement this over the past few years, but none have really succeeded since it's not actually possible.  A simple example is what happens if one writes a closure, then tries to convert that to blocks?  Or Duff's device.

If you want code to blocks, the only approach is to constrain the code to a very limited set.  An example of this working is the Droplet editor which powers PencilCode.  https://github.com/droplet-editor/droplet

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Austin Bart

unread,
Nov 2, 2016, 2:54:43 PM11/2/16
to Blockly, ro...@neil.fraser.name
Well, just to offer another example, the BlockPy project uses Blockly and Skulpt to let users transition between blocks and text. It's not a true one-to-one mapping, but it's not meant to be. However, all the code that our students write (for loops, if statements, functions, most language constructs) will survive the translation unharmed.

Link to BlockPy site: https://blockpy.com

The method is pretty straightforward. Blockly turns blocks into valid Python code. Skulpt parses the Python code, and we grab out that parse tree. We walk that parse tree in a custom JS module to generate valid Blockly XML. 

We've published a little on it. From our experience, being able to go back and forth is pretty helpful for students' understanding.

~Cory
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages