|
| 1 | +--- |
| 2 | +title: "发布 CodeLab Adapter 4.8" |
| 3 | +date: 2021-05-07 |
| 4 | +tags: ["CodeLab"] |
| 5 | +Slug: adapter-5-7 |
| 6 | +--- |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +以下是自 4.7 版本以来的主要改进。 具体细节参考[changelog](https://adapter.codelab.club/changelog/) |
| 11 | + |
| 12 | +<!--truncate--> |
| 13 | + |
| 14 | +# 内核(core)更新 |
| 15 | + |
| 16 | +[软件更新源(`LATEST_VERSION`)](https://adapter.codelab.club/dev_guide/%E5%AE%9A%E5%88%B6%E4%B8%8E%E5%88%86%E5%8F%91/#_2)可配置,方便定制后二次分发。 |
| 17 | + |
| 18 | +## webUI 更新 |
| 19 | + |
| 20 | +* 添加可扩展的 webUI extension: [extension_webUI_manager.py](https://github.com/CodeLabClub/codelab_adapter_extensions/blob/master/extensions_v3/extension_webUI_manager.py), 使开发者可以自行扩展 UI 功能。该插件开机自启。 |
| 21 | +* 使用 [CodeLab 社区创作平台](https://create.codelab.club/projects/editor/) 替代 [scratch beta](https://scratch-beta.codelab.club/) |
| 22 | +* 添加打开 host 目录功能 |
| 23 | +* 系统小图标添加打开主目录( **Open Adapter Home** )菜单按钮 |
| 24 | + |
| 25 | +# Python 环境更新 |
| 26 | +添加 Toio 和 microbit 的 Python 驱动; |
| 27 | + |
| 28 | +你可以直接在 Adapter Jupyterlab 中与 Toio 和 microbit **交互** ! |
| 29 | + |
| 30 | +<video width='80%' src="https://adapter.codelab.club/video/1620365683263637.mp4" controls="controls"></video> |
| 31 | + |
| 32 | +入门案例可以看 Adapter 内置的 notebooks: |
| 33 | + |
| 34 | +* hello_Toio.ipynb |
| 35 | +* hello_microbit.ipynb: 在本地 Python 中与 microbit 实时交互,无需烧入,意味着可以在本地Python程序中,把microbit视为 **活的** 外设 |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +# 插件更新 |
| 40 | + |
| 41 | +## Python 插件 |
| 42 | +为 [Python 插件](https://adapter.codelab.club/extension_guide/extension_python_kernel/)引入 [requests](https://docs.python-requests.org/zh_CN/latest/)。 |
| 43 | + |
| 44 | +考虑到网络极为强大,Python 插件允许用户在 Scratch 中直接与 requests 交互(只支持表达式,形如`requests.get(...), requests.post(...)`)。 |
| 45 | + |
| 46 | +由于 requests 的 API 极为漂亮(支持链式风格),你几乎可以单个表达式中干绝大多数的事情! |
| 47 | + |
| 48 | +一些典型的用例包括: |
| 49 | + |
| 50 | +* [两个 Adapter 之间的消息通信](https://adapter.codelab.club/user_guide/%E4%B8%8E%E5%A4%96%E9%83%A8%E7%B3%BB%E7%BB%9F%E9%80%9A%E4%BF%A1/#requests) |
| 51 | +* 触发 webhook |
| 52 | +* 请求[公开的网络 API](https://github.com/public-apis/public-apis) |
| 53 | +* 与自己搭建的 web server 交互 |
| 54 | + |
| 55 | +### demo |
| 56 | +```py |
| 57 | +requests.get("http://httpbin.org/get") |
| 58 | +# 链式写法 |
| 59 | +requests.get("http://httpbin.org/get").text |
| 60 | +requests.get("http://httpbin.org/get").json() |
| 61 | + |
| 62 | +# 携带参数 |
| 63 | +requests.get("http://httpbin.org/get", params={"name": "codelab"}) |
| 64 | + |
| 65 | +# post |
| 66 | +requests.post('http://httpbin.org/post', data = {'key':'value'}) |
| 67 | +``` |
| 68 | + |
| 69 | +### 一些奇怪的想法 |
| 70 | +* 通过与带有存储能力的 API 结合,可以构建出类似云变量这种东西 |
| 71 | + * 或者使用 [json-server](https://github.com/typicode/json-server) 临时搭建一个 |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +## OSC 插件 |
| 76 | +加速 [OSC](https://adapter.codelab.club/extension_guide/osc/) send 的速度, 从 Scratch 发出的消息,延迟在2-3毫秒。 |
| 77 | + |
| 78 | +音乐项目对实时性要求很高,为了更好地支持[NeverlandBeats](https://www.codelab.club/blog/2021/04/08/neverlandsle),我们改进了 OSC 机制,缩短消息流转的时间。 |
| 79 | + |
| 80 | +## microbit radio 插件 |
| 81 | +为 [microbit radio](https://github.com/CodeLabClub/codelab_adapter_extensions/blob/master/extensions_v3/extension_microbit_radio.py#L116) 插件加锁 |
| 82 | + |
0 commit comments