bricks-for-python/README.md

40 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# bricks-for-pythonpybricks
Bricks 前端的服务器端 Python 打包模块:把常用弹窗/消息 widget 的 JSON 构造
封装成 Python 函数,注册进 ahserver 的 ServerEnv供各模块 dspy/handler 直接返回 UI。
## 提供的函数bricks_for_python/init.py
| 函数 | widgettype | 用途 |
|------|-----------|------|
| `UiWindow(title, icon, content, cheight=10, cwidth=15)` | PopupWindow | 弹出内容窗口movable、auto_open |
| `UiConform(title, message, binds=[])` | Conform | 确认对话框 |
| `UiError(title, message, timeout=5)` | Error | 右上角错误提示 |
| `UiMessage(title, message, timeout=5)` | Message | 右上角普通消息 |
| `load_pybricks()` | — | 把上述四个函数注册到 ServerEnv 全局 |
## 宿主集成
宿主应用 `app/<name>.py``init()` 里:
```python
from bricks_for_python.init import load_pybricks
load_pybricks() # 注册 UiWindow/UiError/UiMessage/UiConform
```
之后任意 dspy/handler 可直接 `return UiMessage(title='成功', message='...')`
`bricks`(前端 JS 框架)配套:本模块只产 JSON 声明,渲染由前端 bricks 完成。
## 安装
```bash
pip install . # build.sh 基础包清单成员,产线/Sage 宿主都装
```
## 已知问题改代码前注意init.py 全文仅 import ServerEnv
- `UiConform` 当前调用即崩:`binds:json.dump(...)` 把变量 binds默认 [],不可哈希)当 dict 键 → TypeError`json``entire_url` 均未导入。修复需补 import 并改为 `"binds": json.dumps(...)`
- `UiWindow`/`UiConform` 里的 `entire_url(...)` 未导入UiWindow 仅在 icon 传空时触发 NameError传了 icon 则可用)。
- `UiWindow``if kw: dic.update(kw)` 位于 `return` 之后是死代码kw 实际不生效。
- `UiError`/`UiMessage` 无上述问题,可正常使用(现网主要用这两个)。