|
| 1 | +BBC micro:bit MicroPython Editor for pythonineducation.org |
| 2 | +========================================================== |
| 3 | + |
| 4 | +This project is an editor that targets the MicroPython |
| 5 | +(http://micropython.org) version of the Python programming language |
| 6 | +(http://python.org/). Code written with this editor is expected to run on the |
| 7 | +BBC's micro:bit device (https://en.wikipedia.org/wiki/Micro_Bit). |
| 8 | + |
| 9 | +Developer Setup |
| 10 | +--------------- |
| 11 | + |
| 12 | +This editor is written to be embedded in the http://pythonineducation.org/ |
| 13 | +website. It means this project is served within an iFrame in the hosting |
| 14 | +website. For this to work for development purposes, you'll need both the |
| 15 | +pythonineducation.org site and this project serving locally. |
| 16 | + |
| 17 | +https://github.com/python/pythonineducation.org |
| 18 | + |
| 19 | +Code |
| 20 | +++++ |
| 21 | + |
| 22 | +* ace - a directory containing the Ace editor (http://ace.c9.io). |
| 23 | +* design - a directory containing design resources created by Steve Hawkes. |
| 24 | +* editor.html - the page to be embedded within the iFrame in TouchDevelop. |
| 25 | +* firmware.hex - copy of the "vanilla" MicroPython firmware used by the editor. |
| 26 | +* help.html - a single page user facing help page. |
| 27 | +* tests.html - the browser based test runner. |
| 28 | +* static - contains css, js and img sub-directories. |
| 29 | +* tests - contains the Python specific test suite. |
| 30 | + |
| 31 | +Usage |
| 32 | +----- |
| 33 | + |
| 34 | +The Python editor is based upon the "Ace" JavaScript editor (http://ace.c9.io) |
| 35 | +and includes syntax highlighting, code folding and (semi) intelligent |
| 36 | +auto-indentation. |
| 37 | + |
| 38 | +Following the TouchDevelop conventions, naming scripts is done automatically - |
| 39 | +it'll be something like, "distinct script" or "awesome script 2". This also |
| 40 | +applies to the description - it's automatically set to "A MicroPython script". |
| 41 | +You can change these at any time by clicking on them. |
| 42 | + |
| 43 | +All new scripts default to something simple and sensible. |
| 44 | + |
| 45 | +The layout and functionality apes Microsoft's own editors. Importantly this |
| 46 | +includes saving scripts to Microsoft's cloud and sharing them with others via |
| 47 | +TouchDevelop's publish functionality. |
| 48 | + |
| 49 | +The four buttons at the top left, act as follows: |
| 50 | + |
| 51 | +* My Scripts - returns you to the main menu listing all your scripts. |
| 52 | +* Download - creates a .hex file locally in the user's browser and prompts the user to download it. The resulting file should be copied over to the micro:bit device just like when using all the other editors. The filename will be the name of the script with spaces replaced by "_" and ending in .py. So "extraordinary script" is saved as extraordinary_script.py. |
| 53 | +* Snippets - allow user's to write code from pre-defined Python fragments (functions, loops, if...else etc). They are triggered by typing a keyword followed by TAB. For example, type "wh" followed by TAB to insert a while... loop. Clicking on the code snippets button opens up a modal dialog window containing instructions and a table of the available snippets along with their trigger and a short and simple description. |
| 54 | +* Help - opens a single page in a new tab that contains user-facing help. |
| 55 | + |
| 56 | +Directly next to the four large buttons are four smaller icons. In the first |
| 57 | +column are zoom in and zoom out buttons that make it easy for teachers to |
| 58 | +display code via a projector. In the second column the top icon indicates the |
| 59 | +script's status (changed, saved locally, saved to the cloud) and the other, |
| 60 | +shaped like a bug, will display a log of the events that occured during the |
| 61 | +current session of using the editor. |
| 62 | + |
| 63 | +In other TouchDevelop editors there are "compile" and "run" buttons. These |
| 64 | +target the TouchDevelop platform to create an AST and either use a third party |
| 65 | +service contacted via the network to create a downloadable .hex |
| 66 | +file (for the former) or run the code on an embedded simulator (for the |
| 67 | +latter). |
| 68 | + |
| 69 | +Since we're targeting MicroPython instead, we simply allow the user to |
| 70 | +download their locally generated .hex file. They simply drag the resulting |
| 71 | +file onto the device. If you connect to the device (and the script ISN'T in an |
| 72 | +infinite loop) you'll be presented with the Python REPL. If there was an error |
| 73 | +you should also see an error message. |
| 74 | + |
| 75 | +If you plug in your micro:bit and want to get the REPL you'll need to install |
| 76 | +pyserial and run the following command with the appropriate permissions (such |
| 77 | +as root, as shockingly demonstrated below):: |
| 78 | + |
| 79 | + $ sudo python -m serial.tools.miniterm -b 115200 /dev/ttyACM0 |
| 80 | + |
| 81 | +Remember to replace tty/ACM0 with the appropriate device for your computer. |
| 82 | + |
| 83 | +The .hex file is generated in the following way: |
| 84 | + |
| 85 | +* A "vanilla" version of the MicroPython hex is hidden within the DOM. |
| 86 | +* We take the Python code in the editor and turn it into a hex representation. |
| 87 | +* We insert the Python derived hex into the correct place within the MicroPython hex. |
| 88 | +* The resulting combination is downloaded onto the user's local filesystem for flashing onto the device. |
| 89 | + |
| 90 | +The hidden MicroPython hex is just over 600k. While this sounds large, it's |
| 91 | +relatively small when you consider: |
| 92 | + |
| 93 | +* The Guardian's front page is around 1.5mb |
| 94 | +* compression is built into the server |
| 95 | +* the web has caching built in (we should trust it) |
| 96 | +* we actually want kids to view source and find the .hex file in as raw a form as possible. |
| 97 | + |
| 98 | +Finally, we have removed the device simulator from the right hand side and |
| 99 | +put something "Pythonic" in its place. |
| 100 | + |
| 101 | +Documentation |
| 102 | +------------- |
| 103 | + |
| 104 | +For documentation for this project - you're reading it. ;-) |
| 105 | + |
| 106 | +For in-editor documentation aimed at the user, this is to be done but will |
| 107 | +encompass both code snippets and generic help in the help.html file. |
0 commit comments