Creating blocks with specific Python code

181 views
Skip to first unread message

Al Bencomo

unread,
Mar 7, 2019, 8:33:21 PM3/7/19
to Blockly
Will it be possible to create a custom block that contains/generates the code below?

import asyncio

from dronecode_sdk import connect as dronecode_sdk_connect

drone = dronecode_sdk_connect(host="127.0.0.1")

async def run():

print("-- Arming")
await drone.action.arm()
print("-- Taking off")
await drone.action.takeoff()
await asyncio.sleep(5)
print("-- Landing")
await drone.action.land()

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

Coda Highland

unread,
Mar 7, 2019, 10:46:44 PM3/7/19
to blo...@googlegroups.com
You'll need to generate the prologue and epilogue outside of Blockly, most likely, but with four custom blocks to handle arm, takeoff, sleep, and land, you should have no difficulty in generating the run() function from a suitable workspace. (You might need to attach the "async" part manually as well.)

/s/ Adam

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

Al Bencomo

unread,
Mar 8, 2019, 8:49:52 PM3/8/19
to Blockly
Sorry Adam, but I'm new to Blockly development.  What do you mean with generate the prologue and epilogue outside of Blockly? And, also with generating the run() function from a suitable workspace?

Is there any link to documentation that provides more details on generating the prologue and epilogue as well as information about that suitable workspace?  Thanks!

Coda Highland

unread,
Mar 8, 2019, 10:30:47 PM3/8/19
to blo...@googlegroups.com
Like, the imports at the top and the part that kicks off the event loop at the bottom. General stuff, not Blockly-specific, so I don't know of any particular documentation; I wasn't meaning any of that as technical terms. The "suitable workspace" I was talking about was just meaning to say "if you put the four blocks that would do those things into the Blockly workspace" -- not anything fancier than that. Obviously if you put in different blocks, it'll generate different code, which is exactly the point.

Blockly will let you generate functions and imperative code, but it can't do everything by itself, so you'll need to incorporate the code it generates into some larger framework in order to make anything useful out of it.

/s/ Adam

On Fri, Mar 8, 2019 at 7:49 PM Al Bencomo <cagi...@gmail.com> wrote:
Sorry Adam, but I'm new to Blockly development.  What do you mean with generate the prologue and epilogue outside of Blockly? And, also with generating the run() function from a suitable workspace?

Is there any link to documentation that provides more details on generating the prologue and epilogue as well as information about that suitable workspace?  Thanks!

--
Reply all
Reply to author
Forward
0 new messages