[Microbit-Python] Blockly to MicroPython - is it possible?

Andrew Ferguson andrewferguson500 at gmail.com
Sun Mar 13 16:03:59 EDT 2016


Hi Carlos,

Thanks for the link to that discussion - hopefully a fix will become
available in due course. This was something that I also overlooked when
planning this, when I did the this for the Pleo dinosaur I had no issues -
it has four self-contained VM's.

Right now our methods appear to be very different. As far as I can see you
are using JS and the blockly editor to generate the python, while I'm using
python and BeautifulSoup to parse the XML file from the downloaded JSZ
file. Please keep me updated as to your progress (and any pitfalls you come
across) - I'll do the same.

My code is probably even less advanced than yours - there is more of it,
but most of that will need rewriting!

I don't suppose you've investigated translating TouchDevelop into python at
all? Initial investigations shows that JSON is generated inside the JSZ
file, but the JSON seems full of obscure characters.

Andrew

On 13 March 2016 at 18:50, Carlos P.A. <carlos.p.a.87 at gmail.com> wrote:

> Hi Andrew,
>
> You are right and that is something I completely overlooked when thinking
> about this, currently it will not be possible to implement the current
> micropython implementation. Hopefully this should be a temporary issue,
> have a look at the discussion in
> https://github.com/bbcmicrobit/micropython/issues/36
>
> In case you are interested I had added my (almost inexistent) progress to
> https://github.com/carlosperate/microbit-blocks-python , which is
> basically extracting only the required compiled files to have the block
> implementation and adding the default blockly Python generator, as I really
> didn't have the time to do anything else. Hopefully next week I will be
> able to dedicate a bit more time to this, let me know how you are doing and
> we could combine efforts.
>
> Regards,
> Carlos
>
> On 13 March 2016 at 16:53, Andrew Ferguson <andrewferguson500 at gmail.com>
> wrote:
>
>> Ah, OK. I think I'm finally getting to grips with how the XML is
>> formatted.
>>
>> All blocks that come after another block are actually contained within
>> the first block. So each block needs to be checked to see if it contains a
>> 'next' tag, as that indicates if another block comes after that block.
>>
>> Any pointers or ideas for the concurrent script problem (as described in
>> previous message) would be useful, as I'm still not sure what to do.
>>
>> On 13 March 2016 at 14:16, Andrew Ferguson <andrewferguson500 at gmail.com>
>> wrote:
>>
>>> So based on Carlos' earlier idea for a converter from Blockly to Python,
>>> I thought I'd have a go at doing this, just to see if it was possible. I've
>>> done something similar before (Scratch 2.0 to C / Pawn for the Pleo
>>> Dinosaur robot - side note, do any schools apart from mine have these?).
>>> That was fairly easy*: Scratch 2 uses JSON in a intuitive way.
>>>
>>> Blockly is proving to be a lot less intuitive. See the following snippet
>>> from a simple example from the website:
>>>
>>> <xml xmlns="http://www.w3.org/1999/xhtml">
>>>     <block type="device_button_event" x="69" y="38">
>>>         <field name="NAME">A</field>
>>>         <statement name="HANDLER">
>>>             <block type="variables_set">
>>>                 <field name="VAR">answer</field>
>>>                 <value name="VALUE">
>>>                     <block type="device_random">
>>>                         <field name="limit">3</field>
>>>                     </block>
>>>                 </value>
>>>                 <next>
>>>                     <block type="controls_if">
>>>                         <mutation elseif="1" else="1"></mutation>
>>>                         <value name="IF0">
>>>
>>>
>>> At first I assumed that each 'block' was contained in a 'block' tag,
>>> with one tag for each block. That appears to be the case sometimes, but not
>>> always. Observe how the "device_random" block is self contained but the
>>> "variables_set" block continues down into the "controls_if" block!
>>>
>>> In addition, Blockly supports concurrently running scripts, while I
>>> suspect MicroPython does not (or does it - would be fantastic if it does!).
>>> If my suspicion is correct, this would mean that a script in Blockly that
>>> has a group of blocks in a "forever" loop and another group of blocks in a
>>> "when button pressed" block, would not be possible to convert to
>>> MicroPython. Any way round this?
>>>
>>> Oh, and the Blockly editor seems to have stopped working in Chromium (at
>>> least it has on my computer with very outdated version - but it worked
>>> yesterday). Clicking "Compile" makes the logo rotate forever (I waited 55
>>> minutes) and nothing else happens. Has there been a recent update?
>>> (Chromium has no Java / Flash support, so that could be the cause).
>>>
>>> Looking forward to trying out some stuff on a real MicroBit when it
>>> arrives!
>>>
>>> Andrew
>>>
>>>
>>> *Fairly easy until I realised their development tools were all closed
>>> under an NDA, so I had to rewrite and reverse engineer a *lot* to get the
>>> basics working.
>>>
>>
>>
>> _______________________________________________
>> Microbit mailing list
>> Microbit at python.org
>> https://mail.python.org/mailman/listinfo/microbit
>>
>>
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/microbit/attachments/20160313/0249d368/attachment.html>


More information about the Microbit mailing list