# MonoWidget User Guide
## Project Overview
MonoWidget is a Python tool for creating and managing parameter interfaces. It generates visual interface components through a simple API for defining parameters. It is particularly suitable for rapidly developing configuration interfaces, debugging tools, and parameter debuggers that require user interaction.
## Quick Start
### Installation
MonoWidget is currently a local development library. Simply clone or download the source code to your project.
### Basic Usage Example
```python
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
from monowidget import *
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("MonoWidget Example")
self.setGeometry(100, 100, 600, 400)
# Create central widget
central_widget = QWidget()
self.setCentralWidget(central_widget)
# Create main layout
main_layout = QVBoxLayout(central_widget)
# Define attribute list
attrs = [
MonoAttr("username", "Alice", label="Username"),
MonoAttr("age", 30, range=(18, 100), label="Age"),
MonoAttr("active", True, label="Active"),
MonoAttr("theme", "dark", enum=["light", "dark", "auto"], label="Theme"),
]
# Create Mono object
mono = Mono(attrs)
# Create Inspector and add to layout
inspector = QMonoInspector(mono)
main_layout.addWidget(inspector)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
```
## Core Concepts
### MonoAttr
`MonoAttr` is a parameter definition class used to describe all properties of a single parameter, including name, value, type, range, etc.
### Mono
`Mono` is a data model class that contains multiple `MonoAttr` properties and serves as the data source for `QMonoInspector`.
### QMonoInspector
`QMonoInspector` is the interface renderer responsible for rendering `Mono` objects into visual interfaces.
## Using MonoAttr to Create Inspector
### 1. Import Necessary Modules
```python
from monowidget import *
```
### 2. Define MonoAttr Properties
`MonoAttr` supports multiple parameter types. The system will automatically identify and generate corresponding interface controls based on the `value` type:
#### Supported Type Comparison Table
| Type | Python Value Example | Interface Control |
|------|---------------------|-------------------|
| **String** | `"text"` | Text input box |
| **Integer** | `42` | Number input box |
| **Float** | `3.14` | Float input box |
| **Boolean** | `True` | Checkbox |
| **Enum** | `"option1"` | Dropdown selection |
| **List** | `[1, 2, 3]` | List editor |
| **Dict** | `{"key": "value"}` | Dictionary editor |
| **Function Button** | `lambda: print("hi")` | Button |
| **DateTime** | `datetime.now()` | DateTime picker |
| **Color** | `"#ff0000"` | Color picker |
#### Usage Example
```python
from datetime import datetime
attrs = [
# Basic types
MonoAttr("name", "Example", label="Name"), # String
MonoAttr("count", 42, label="Count"), # Integer
MonoAttr("price", 29.99, label="Price"), # Float
MonoAttr("enabled", True, label="Enabled"), # Boolean
# Range-limited numbers
MonoAttr("volume", 75, range=(0, 100, 5), label="Volume"),
# Enum type
MonoAttr("mode", "normal", enum=["easy", "normal", "hard"], label="Mode"),
# Complex types
MonoAttr("tags", ["python", "qt"], label="Tags"), # List
MonoAttr("settings", {"theme": "dark", "font": 14}, label="Settings"), # Dict
# Function button
MonoAttr("save_button", lambda: print("Saved"), label="Save Settings"),
# DateTime
MonoAttr("start_time", datetime.now(), label="Start Time"),
# Color
MonoAttr("bg_color", "#ffffff", label="Background Color")
]
```
### 3. Create Mono Object
Use the attribute list to create a `Mono` object:
```python
mono = Mono(attrs)
```
### 4. Create and Display Inspector
```python
# Create QMonoInspector instance
inspector = QMonoInspector(mono)
# Add to layout
layout.addWidget(inspector)
```
### 5. Advanced Configuration - Grouping and Titles
You can use `group`, `header`, and `title` parameters to organize the interface layout:
```python
attrs = [
# Page title
MonoAttr("app_title", "Configuration Center", title="Application Configuration Center"),
# User info group
MonoAttr("username", "admin", label="Username", group="User Info", header="👤 User Configuration"),
MonoAttr("email", "admin@example.com", label="Email", group="User Info"),
# Interface settings group
MonoAttr("theme", "dark", enum=["light", "dark"], label="Theme", group="Interface Settings", header="🎨 Appearance Settings"),
```
---
# MonoWidget 使用指南
## 项目简介
MonoWidget 是一个用于创建和管理参数界面的Python工具,通过简洁的API定义参数,并自动生成可视化的界面组件。它特别适用于快速开发需要用户交互的配置界面、调试工具和参数调试器等场景。
## 快速开始
### 安装
MonoWidget 目前是一个本地开发库,直接克隆或下载源代码到您的项目中即可使用。
### 基本使用示例
```python
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
from monowidget import *
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("MonoWidget 示例")
self.setGeometry(100, 100, 600, 400)
# 创建中心部件
central_widget = QWidget()
self.setCentralWidget(central_widget)
# 创建主布局
main_layout = QVBoxLayout(central_widget)
# 定义属性列表
attrs = [
MonoAttr("username", "Alice", label="用户名"),
MonoAttr("age", 30, range=(18, 100), label="年龄"),
MonoAttr("active", True, label="是否激活"),
MonoAttr("theme", "dark", enum=["light", "dark", "auto"], label="界面主题"),
]
# 创建Mono对象
mono = Mono(attrs)
# 创建Inspector并添加到布局
inspector = QMonoInspector(mono)
main_layout.addWidget(inspector)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
```
## 核心概念
### MonoAttr
`MonoAttr` 是参数定义类,用于描述单个参数的所有属性,包括名称、值、类型、范围等。
### Mono
`Mono` 是数据模型类,包含多个 `MonoAttr` 属性,作为 `QMonoInspector` 的数据源。
### QMonoInspector
`QMonoInspector` 是界面渲染器,负责将 `Mono` 对象渲染为可视化界面。
## 使用 MonoAttr 创建 Inspector
### 1. 导入必要的模块
```python
from monowidget import *
```
### 2. 定义 MonoAttr 属性
`MonoAttr` 支持多种参数类型,系统会根据 `value` 的类型自动识别并生成相应的界面控件:
#### 支持的类型对照表
| 类型 | Python值示例 | 界面控件 |
|------|-------------|----------|
| **字符串** | `"text"` | 文本输入框 |
| **整数** | `42` | 数字输入框 |
| **浮点数** | `3.14` | 浮点输入框 |
| **布尔值** | `True` | 复选框 |
| **枚举** | `"option1"` | 下拉选择框 |
| **列表** | `[1, 2, 3]` | 列表编辑器 |
| **字典** | `{"key": "value"}` | 字典编辑器 |
| **函数按钮** | `lambda: print("hi")` | 按钮 |
| **日期时间** | `datetime.now()` | 日期时间选择器 |
| **颜色** | `"#ff0000"` | 颜色选择器 |
#### 使用示例
```python
from datetime import datetime
attrs = [
# 基本类型
MonoAttr("name", "Example", label="名称"), # 字符串
MonoAttr("count", 42, label="数量"), # 整数
MonoAttr("price", 29.99, label="价格"), # 浮点数
MonoAttr("enabled", True, label="启用"), # 布尔值
# 带范围限制的数值
MonoAttr("volume", 75, range=(0, 100, 5), label="音量"),
# 枚举类型
MonoAttr("mode", "normal", enum=["easy", "normal", "hard"], label="模式"),
# 复杂类型
MonoAttr("tags", ["python", "qt"], label="标签"), # 列表
MonoAttr("settings", {"theme": "dark", "font": 14}, label="设置"), # 字典
# 函数按钮
MonoAttr("save_button", lambda: print("已保存"), label="保存设置"),
# 日期时间
MonoAttr("start_time", datetime.now(), label="开始时间"),
# 颜色
MonoAttr("bg_color", "#ffffff", label="背景颜色")
]
```
### 3. 创建 Mono 对象
使用属性列表创建 `Mono` 对象:
```python
mono = Mono(attrs)
```
### 4. 创建并显示 Inspector
```python
# 创建QMonoInspector实例
inspector = QMonoInspector(mono)
# 添加到布局
layout.addWidget(inspector)
```
### 5. 高级配置 - 分组和标题
您可以使用 `group`、`header` 和 `title` 参数来组织界面布局:
```python
attrs = [
# 页面标题
MonoAttr("app_title", "配置中心", title="应用配置中心"),
# 用户信息分组
MonoAttr("username", "admin", label="用户名", group="用户信息", header="👤 用户配置"),
MonoAttr("email", "admin@example.com", label="邮箱", group="用户信息"),
# 界面设置分组
MonoAttr("theme", "dark", enum=["light", "dark"], label="主题", group="界面设置", header="🎨 外观设置"),
]
```
## 数据读写方法
### 方法1:使用字典形式读取所有参数值
```python
# 获取所有参数值(字典形式)
values = inspector.params # 返回包含所有参数值的字典
print(values) # 输出: {'username': 'Alice', 'age': 30, ...}
# 设置多个参数值
inspector.params = {
'username': 'Bob',
'age': 25
}
```
### 方法2:使用 inspector.vs 访问单个属性
```python
# 读取单个参数值
username = inspector.vs.username
print(f"当前用户名: {username}")
# 修改单个参数值
inspector.vs.username = "Charlie"
inspector.vs.age = 35
# 批量更新多个属性的值
new_values = {
'username': 'David',
'age': 40,
'active': False
}
for key, value in new_values.items():
setattr(inspector.vs, key, value)
```
### 方法3:监听参数变化事件
```python
# 监听单个参数变化
inspector.paramChanged.connect(lambda name, value: print(f"参数 {name} 已更改为: {value}"))
# 监听所有参数变化
inspector.paramsChanged.connect(lambda params: print(f"所有参数已更新: {params}"))
# 监听特定参数的变化(通过条件判断)
def on_param_changed(name, value):
if name == "username":
print(f"用户名已更改为: {value}")
elif name == "volume":
print(f"音量设置为: {value}")
# 这里可以添加实际的处理逻辑
update_audio_volume(value)
inspector.paramChanged.connect(on_param_changed)
```
## 常见问题
### 1. 如何控制组件的只读状态?
使用 `readonly=True` 参数:
```python
MonoAttr("server_url", "https://api.example.com", readonly=True, label="服务器地址")
```
### 2. 如何添加分隔符和空白间隔?
使用 `separator=True` 和 `space=True` 参数:
```python
attrs = [
MonoAttr("section1", "第一部分", title="第一部分"),
MonoAttr("param1", "value1", label="参数1"),
MonoAttr("param2", "value2", label="参数2", separator=True), # 添加分隔线
MonoAttr("section2", "第二部分", title="第二部分"),
MonoAttr("param3", "value3", label="参数3", space=True), # 添加上方空白
]
```
### 3. 如何处理参数变化事件?
使用信号槽机制监听参数变化:
```python
# 监听单个参数变化
inspector.paramChanged.connect(lambda name, value: print(f"参数 {name} 已更改为: {value}"))
# 监听所有参数变化
inspector.paramsChanged.connect(lambda params: print(f"所有参数已更新: {params}"))
# 监听特定参数的变化(通过条件判断)
def on_param_changed(name, value):
if name == "username":
print(f"用户名已更改为: {value}")
elif name == "volume":
print(f"音量设置为: {value}")
# 这里可以添加实际的处理逻辑
update_audio_volume(value)
inspector.paramChanged.connect(on_param_changed)
```
## 示例应用说明
项目包含多个示例文件,展示了MonoWidget的各种用法:
- **main.py**: 基础示例,展示如何创建简单的参数界面
- **debug_type_change_value.py**: 调试示例,展示各种数据类型的参数界面
- **inspector/**: Inspector相关模块,包含所有界面组件的实现
- **_utils/**: 工具模块,包含各种辅助类和组件
您可以通过运行 `main.py` 来查看基础示例,或者参考各个模块的源代码了解更详细的实现。
Raw data
{
"_id": null,
"home_page": "https://github.com/monowidget/monowidget",
"name": "monowidget",
"maintainer": "Eagle'sBaby",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "2229066748@qq.com",
"keywords": "pyqt6, parameter, interface, configuration, ui, widget, inspector",
"author": "Eagle'sBaby",
"author_email": "2229066748@qq.com",
"download_url": "https://files.pythonhosted.org/packages/f0/d5/745fddfd0ed37b42e83289785188db6e65985a0974cc8f579dfb48316feb/monowidget-0.1.1.tar.gz",
"platform": null,
"description": "# MonoWidget User Guide\r\n\r\n## Project Overview\r\n\r\nMonoWidget is a Python tool for creating and managing parameter interfaces. It generates visual interface components through a simple API for defining parameters. It is particularly suitable for rapidly developing configuration interfaces, debugging tools, and parameter debuggers that require user interaction.\r\n\r\n## Quick Start\r\n\r\n### Installation\r\n\r\nMonoWidget is currently a local development library. Simply clone or download the source code to your project.\r\n\r\n### Basic Usage Example\r\n\r\n```python\r\nimport sys\r\nfrom PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget\r\nfrom monowidget import *\r\n\r\nclass MainWindow(QMainWindow):\r\n def __init__(self):\r\n super().__init__()\r\n self.setWindowTitle(\"MonoWidget Example\")\r\n self.setGeometry(100, 100, 600, 400)\r\n \r\n # Create central widget\r\n central_widget = QWidget()\r\n self.setCentralWidget(central_widget)\r\n \r\n # Create main layout\r\n main_layout = QVBoxLayout(central_widget)\r\n \r\n # Define attribute list\r\n attrs = [\r\n MonoAttr(\"username\", \"Alice\", label=\"Username\"),\r\n MonoAttr(\"age\", 30, range=(18, 100), label=\"Age\"),\r\n MonoAttr(\"active\", True, label=\"Active\"),\r\n MonoAttr(\"theme\", \"dark\", enum=[\"light\", \"dark\", \"auto\"], label=\"Theme\"),\r\n ]\r\n \r\n # Create Mono object\r\n mono = Mono(attrs)\r\n \r\n # Create Inspector and add to layout\r\n inspector = QMonoInspector(mono)\r\n main_layout.addWidget(inspector)\r\n\r\nif __name__ == \"__main__\":\r\n app = QApplication(sys.argv)\r\n window = MainWindow()\r\n window.show()\r\n sys.exit(app.exec())\r\n```\r\n\r\n## Core Concepts\r\n\r\n### MonoAttr\r\n`MonoAttr` is a parameter definition class used to describe all properties of a single parameter, including name, value, type, range, etc.\r\n\r\n### Mono\r\n`Mono` is a data model class that contains multiple `MonoAttr` properties and serves as the data source for `QMonoInspector`.\r\n\r\n### QMonoInspector\r\n`QMonoInspector` is the interface renderer responsible for rendering `Mono` objects into visual interfaces.\r\n\r\n## Using MonoAttr to Create Inspector\r\n\r\n### 1. Import Necessary Modules\r\n```python\r\nfrom monowidget import *\r\n```\r\n\r\n### 2. Define MonoAttr Properties\r\n`MonoAttr` supports multiple parameter types. The system will automatically identify and generate corresponding interface controls based on the `value` type:\r\n\r\n#### Supported Type Comparison Table\r\n\r\n| Type | Python Value Example | Interface Control |\r\n|------|---------------------|-------------------|\r\n| **String** | `\"text\"` | Text input box |\r\n| **Integer** | `42` | Number input box |\r\n| **Float** | `3.14` | Float input box |\r\n| **Boolean** | `True` | Checkbox |\r\n| **Enum** | `\"option1\"` | Dropdown selection |\r\n| **List** | `[1, 2, 3]` | List editor |\r\n| **Dict** | `{\"key\": \"value\"}` | Dictionary editor |\r\n| **Function Button** | `lambda: print(\"hi\")` | Button |\r\n| **DateTime** | `datetime.now()` | DateTime picker |\r\n| **Color** | `\"#ff0000\"` | Color picker |\r\n\r\n#### Usage Example\r\n```python\r\nfrom datetime import datetime\r\n\r\nattrs = [\r\n # Basic types\r\n MonoAttr(\"name\", \"Example\", label=\"Name\"), # String\r\n MonoAttr(\"count\", 42, label=\"Count\"), # Integer\r\n MonoAttr(\"price\", 29.99, label=\"Price\"), # Float\r\n MonoAttr(\"enabled\", True, label=\"Enabled\"), # Boolean\r\n \r\n # Range-limited numbers\r\n MonoAttr(\"volume\", 75, range=(0, 100, 5), label=\"Volume\"),\r\n \r\n # Enum type\r\n MonoAttr(\"mode\", \"normal\", enum=[\"easy\", \"normal\", \"hard\"], label=\"Mode\"),\r\n \r\n # Complex types\r\n MonoAttr(\"tags\", [\"python\", \"qt\"], label=\"Tags\"), # List\r\n MonoAttr(\"settings\", {\"theme\": \"dark\", \"font\": 14}, label=\"Settings\"), # Dict\r\n \r\n # Function button\r\n MonoAttr(\"save_button\", lambda: print(\"Saved\"), label=\"Save Settings\"),\r\n \r\n # DateTime\r\n MonoAttr(\"start_time\", datetime.now(), label=\"Start Time\"),\r\n \r\n # Color\r\n MonoAttr(\"bg_color\", \"#ffffff\", label=\"Background Color\")\r\n]\r\n```\r\n\r\n### 3. Create Mono Object\r\nUse the attribute list to create a `Mono` object:\r\n```python\r\nmono = Mono(attrs)\r\n```\r\n\r\n### 4. Create and Display Inspector\r\n```python\r\n# Create QMonoInspector instance\r\ninspector = QMonoInspector(mono)\r\n\r\n# Add to layout\r\nlayout.addWidget(inspector)\r\n```\r\n\r\n### 5. Advanced Configuration - Grouping and Titles\r\nYou can use `group`, `header`, and `title` parameters to organize the interface layout:\r\n\r\n```python\r\nattrs = [\r\n # Page title\r\n MonoAttr(\"app_title\", \"Configuration Center\", title=\"Application Configuration Center\"),\r\n \r\n # User info group\r\n MonoAttr(\"username\", \"admin\", label=\"Username\", group=\"User Info\", header=\"\ud83d\udc64 User Configuration\"),\r\n MonoAttr(\"email\", \"admin@example.com\", label=\"Email\", group=\"User Info\"),\r\n \r\n # Interface settings group\r\n MonoAttr(\"theme\", \"dark\", enum=[\"light\", \"dark\"], label=\"Theme\", group=\"Interface Settings\", header=\"\ud83c\udfa8 Appearance Settings\"),\r\n```\r\n\r\n---\r\n\r\n# MonoWidget \u4f7f\u7528\u6307\u5357\r\n\r\n## \u9879\u76ee\u7b80\u4ecb\r\n\r\nMonoWidget \u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u548c\u7ba1\u7406\u53c2\u6570\u754c\u9762\u7684Python\u5de5\u5177\uff0c\u901a\u8fc7\u7b80\u6d01\u7684API\u5b9a\u4e49\u53c2\u6570\uff0c\u5e76\u81ea\u52a8\u751f\u6210\u53ef\u89c6\u5316\u7684\u754c\u9762\u7ec4\u4ef6\u3002\u5b83\u7279\u522b\u9002\u7528\u4e8e\u5feb\u901f\u5f00\u53d1\u9700\u8981\u7528\u6237\u4ea4\u4e92\u7684\u914d\u7f6e\u754c\u9762\u3001\u8c03\u8bd5\u5de5\u5177\u548c\u53c2\u6570\u8c03\u8bd5\u5668\u7b49\u573a\u666f\u3002\r\n\r\n## \u5feb\u901f\u5f00\u59cb\r\n\r\n### \u5b89\u88c5\r\n\r\nMonoWidget \u76ee\u524d\u662f\u4e00\u4e2a\u672c\u5730\u5f00\u53d1\u5e93\uff0c\u76f4\u63a5\u514b\u9686\u6216\u4e0b\u8f7d\u6e90\u4ee3\u7801\u5230\u60a8\u7684\u9879\u76ee\u4e2d\u5373\u53ef\u4f7f\u7528\u3002\r\n\r\n### \u57fa\u672c\u4f7f\u7528\u793a\u4f8b\r\n\r\n```python\r\nimport sys\r\nfrom PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget\r\nfrom monowidget import *\r\n\r\nclass MainWindow(QMainWindow):\r\n def __init__(self):\r\n super().__init__()\r\n self.setWindowTitle(\"MonoWidget \u793a\u4f8b\")\r\n self.setGeometry(100, 100, 600, 400)\r\n \r\n # \u521b\u5efa\u4e2d\u5fc3\u90e8\u4ef6\r\n central_widget = QWidget()\r\n self.setCentralWidget(central_widget)\r\n \r\n # \u521b\u5efa\u4e3b\u5e03\u5c40\r\n main_layout = QVBoxLayout(central_widget)\r\n \r\n # \u5b9a\u4e49\u5c5e\u6027\u5217\u8868\r\n attrs = [\r\n MonoAttr(\"username\", \"Alice\", label=\"\u7528\u6237\u540d\"),\r\n MonoAttr(\"age\", 30, range=(18, 100), label=\"\u5e74\u9f84\"),\r\n MonoAttr(\"active\", True, label=\"\u662f\u5426\u6fc0\u6d3b\"),\r\n MonoAttr(\"theme\", \"dark\", enum=[\"light\", \"dark\", \"auto\"], label=\"\u754c\u9762\u4e3b\u9898\"),\r\n ]\r\n \r\n # \u521b\u5efaMono\u5bf9\u8c61\r\n mono = Mono(attrs)\r\n \r\n # \u521b\u5efaInspector\u5e76\u6dfb\u52a0\u5230\u5e03\u5c40\r\n inspector = QMonoInspector(mono)\r\n main_layout.addWidget(inspector)\r\n\r\nif __name__ == \"__main__\":\r\n app = QApplication(sys.argv)\r\n window = MainWindow()\r\n window.show()\r\n sys.exit(app.exec())\r\n```\r\n\r\n## \u6838\u5fc3\u6982\u5ff5\r\n\r\n### MonoAttr\r\n`MonoAttr` \u662f\u53c2\u6570\u5b9a\u4e49\u7c7b\uff0c\u7528\u4e8e\u63cf\u8ff0\u5355\u4e2a\u53c2\u6570\u7684\u6240\u6709\u5c5e\u6027\uff0c\u5305\u62ec\u540d\u79f0\u3001\u503c\u3001\u7c7b\u578b\u3001\u8303\u56f4\u7b49\u3002\r\n\r\n### Mono\r\n`Mono` \u662f\u6570\u636e\u6a21\u578b\u7c7b\uff0c\u5305\u542b\u591a\u4e2a `MonoAttr` \u5c5e\u6027\uff0c\u4f5c\u4e3a `QMonoInspector` \u7684\u6570\u636e\u6e90\u3002\r\n\r\n### QMonoInspector\r\n`QMonoInspector` \u662f\u754c\u9762\u6e32\u67d3\u5668\uff0c\u8d1f\u8d23\u5c06 `Mono` \u5bf9\u8c61\u6e32\u67d3\u4e3a\u53ef\u89c6\u5316\u754c\u9762\u3002\r\n\r\n## \u4f7f\u7528 MonoAttr \u521b\u5efa Inspector\r\n\r\n### 1. \u5bfc\u5165\u5fc5\u8981\u7684\u6a21\u5757\r\n```python\r\nfrom monowidget import *\r\n```\r\n\r\n### 2. \u5b9a\u4e49 MonoAttr \u5c5e\u6027\r\n`MonoAttr` \u652f\u6301\u591a\u79cd\u53c2\u6570\u7c7b\u578b\uff0c\u7cfb\u7edf\u4f1a\u6839\u636e `value` \u7684\u7c7b\u578b\u81ea\u52a8\u8bc6\u522b\u5e76\u751f\u6210\u76f8\u5e94\u7684\u754c\u9762\u63a7\u4ef6\uff1a\r\n\r\n#### \u652f\u6301\u7684\u7c7b\u578b\u5bf9\u7167\u8868\r\n\r\n| \u7c7b\u578b | Python\u503c\u793a\u4f8b | \u754c\u9762\u63a7\u4ef6 |\r\n|------|-------------|----------|\r\n| **\u5b57\u7b26\u4e32** | `\"text\"` | \u6587\u672c\u8f93\u5165\u6846 |\r\n| **\u6574\u6570** | `42` | \u6570\u5b57\u8f93\u5165\u6846 |\r\n| **\u6d6e\u70b9\u6570** | `3.14` | \u6d6e\u70b9\u8f93\u5165\u6846 |\r\n| **\u5e03\u5c14\u503c** | `True` | \u590d\u9009\u6846 |\r\n| **\u679a\u4e3e** | `\"option1\"` | \u4e0b\u62c9\u9009\u62e9\u6846 |\r\n| **\u5217\u8868** | `[1, 2, 3]` | \u5217\u8868\u7f16\u8f91\u5668 |\r\n| **\u5b57\u5178** | `{\"key\": \"value\"}` | \u5b57\u5178\u7f16\u8f91\u5668 |\r\n| **\u51fd\u6570\u6309\u94ae** | `lambda: print(\"hi\")` | \u6309\u94ae |\r\n| **\u65e5\u671f\u65f6\u95f4** | `datetime.now()` | \u65e5\u671f\u65f6\u95f4\u9009\u62e9\u5668 |\r\n| **\u989c\u8272** | `\"#ff0000\"` | \u989c\u8272\u9009\u62e9\u5668 |\r\n\r\n#### \u4f7f\u7528\u793a\u4f8b\r\n```python\r\nfrom datetime import datetime\r\n\r\nattrs = [\r\n # \u57fa\u672c\u7c7b\u578b\r\n MonoAttr(\"name\", \"Example\", label=\"\u540d\u79f0\"), # \u5b57\u7b26\u4e32\r\n MonoAttr(\"count\", 42, label=\"\u6570\u91cf\"), # \u6574\u6570\r\n MonoAttr(\"price\", 29.99, label=\"\u4ef7\u683c\"), # \u6d6e\u70b9\u6570\r\n MonoAttr(\"enabled\", True, label=\"\u542f\u7528\"), # \u5e03\u5c14\u503c\r\n \r\n # \u5e26\u8303\u56f4\u9650\u5236\u7684\u6570\u503c\r\n MonoAttr(\"volume\", 75, range=(0, 100, 5), label=\"\u97f3\u91cf\"),\r\n \r\n # \u679a\u4e3e\u7c7b\u578b\r\n MonoAttr(\"mode\", \"normal\", enum=[\"easy\", \"normal\", \"hard\"], label=\"\u6a21\u5f0f\"),\r\n \r\n # \u590d\u6742\u7c7b\u578b\r\n MonoAttr(\"tags\", [\"python\", \"qt\"], label=\"\u6807\u7b7e\"), # \u5217\u8868\r\n MonoAttr(\"settings\", {\"theme\": \"dark\", \"font\": 14}, label=\"\u8bbe\u7f6e\"), # \u5b57\u5178\r\n \r\n # \u51fd\u6570\u6309\u94ae\r\n MonoAttr(\"save_button\", lambda: print(\"\u5df2\u4fdd\u5b58\"), label=\"\u4fdd\u5b58\u8bbe\u7f6e\"),\r\n \r\n # \u65e5\u671f\u65f6\u95f4\r\n MonoAttr(\"start_time\", datetime.now(), label=\"\u5f00\u59cb\u65f6\u95f4\"),\r\n \r\n # \u989c\u8272\r\n MonoAttr(\"bg_color\", \"#ffffff\", label=\"\u80cc\u666f\u989c\u8272\")\r\n]\r\n```\r\n\r\n### 3. \u521b\u5efa Mono \u5bf9\u8c61\r\n\u4f7f\u7528\u5c5e\u6027\u5217\u8868\u521b\u5efa `Mono` \u5bf9\u8c61\uff1a\r\n```python\r\nmono = Mono(attrs)\r\n```\r\n\r\n### 4. \u521b\u5efa\u5e76\u663e\u793a Inspector\r\n```python\r\n# \u521b\u5efaQMonoInspector\u5b9e\u4f8b\r\ninspector = QMonoInspector(mono)\r\n\r\n# \u6dfb\u52a0\u5230\u5e03\u5c40\r\nlayout.addWidget(inspector)\r\n```\r\n\r\n### 5. \u9ad8\u7ea7\u914d\u7f6e - \u5206\u7ec4\u548c\u6807\u9898\r\n\u60a8\u53ef\u4ee5\u4f7f\u7528 `group`\u3001`header` \u548c `title` \u53c2\u6570\u6765\u7ec4\u7ec7\u754c\u9762\u5e03\u5c40\uff1a\r\n\r\n```python\r\nattrs = [\r\n # \u9875\u9762\u6807\u9898\r\n MonoAttr(\"app_title\", \"\u914d\u7f6e\u4e2d\u5fc3\", title=\"\u5e94\u7528\u914d\u7f6e\u4e2d\u5fc3\"),\r\n \r\n # \u7528\u6237\u4fe1\u606f\u5206\u7ec4\r\n MonoAttr(\"username\", \"admin\", label=\"\u7528\u6237\u540d\", group=\"\u7528\u6237\u4fe1\u606f\", header=\"\ud83d\udc64 \u7528\u6237\u914d\u7f6e\"),\r\n MonoAttr(\"email\", \"admin@example.com\", label=\"\u90ae\u7bb1\", group=\"\u7528\u6237\u4fe1\u606f\"),\r\n \r\n # \u754c\u9762\u8bbe\u7f6e\u5206\u7ec4\r\n MonoAttr(\"theme\", \"dark\", enum=[\"light\", \"dark\"], label=\"\u4e3b\u9898\", group=\"\u754c\u9762\u8bbe\u7f6e\", header=\"\ud83c\udfa8 \u5916\u89c2\u8bbe\u7f6e\"),\r\n]\r\n```\r\n\r\n## \u6570\u636e\u8bfb\u5199\u65b9\u6cd5\r\n\r\n### \u65b9\u6cd51\uff1a\u4f7f\u7528\u5b57\u5178\u5f62\u5f0f\u8bfb\u53d6\u6240\u6709\u53c2\u6570\u503c\r\n```python\r\n# \u83b7\u53d6\u6240\u6709\u53c2\u6570\u503c\uff08\u5b57\u5178\u5f62\u5f0f\uff09\r\nvalues = inspector.params # \u8fd4\u56de\u5305\u542b\u6240\u6709\u53c2\u6570\u503c\u7684\u5b57\u5178\r\nprint(values) # \u8f93\u51fa: {'username': 'Alice', 'age': 30, ...}\r\n\r\n# \u8bbe\u7f6e\u591a\u4e2a\u53c2\u6570\u503c\r\ninspector.params = {\r\n 'username': 'Bob',\r\n 'age': 25\r\n}\r\n```\r\n\r\n### \u65b9\u6cd52\uff1a\u4f7f\u7528 inspector.vs \u8bbf\u95ee\u5355\u4e2a\u5c5e\u6027\r\n```python\r\n# \u8bfb\u53d6\u5355\u4e2a\u53c2\u6570\u503c\r\nusername = inspector.vs.username\r\nprint(f\"\u5f53\u524d\u7528\u6237\u540d: {username}\")\r\n\r\n# \u4fee\u6539\u5355\u4e2a\u53c2\u6570\u503c\r\ninspector.vs.username = \"Charlie\"\r\ninspector.vs.age = 35\r\n\r\n# \u6279\u91cf\u66f4\u65b0\u591a\u4e2a\u5c5e\u6027\u7684\u503c\r\nnew_values = {\r\n 'username': 'David',\r\n 'age': 40,\r\n 'active': False\r\n}\r\nfor key, value in new_values.items():\r\n setattr(inspector.vs, key, value)\r\n```\r\n\r\n### \u65b9\u6cd53\uff1a\u76d1\u542c\u53c2\u6570\u53d8\u5316\u4e8b\u4ef6\r\n```python\r\n# \u76d1\u542c\u5355\u4e2a\u53c2\u6570\u53d8\u5316\r\ninspector.paramChanged.connect(lambda name, value: print(f\"\u53c2\u6570 {name} \u5df2\u66f4\u6539\u4e3a: {value}\"))\r\n\r\n# \u76d1\u542c\u6240\u6709\u53c2\u6570\u53d8\u5316\r\ninspector.paramsChanged.connect(lambda params: print(f\"\u6240\u6709\u53c2\u6570\u5df2\u66f4\u65b0: {params}\"))\r\n\r\n# \u76d1\u542c\u7279\u5b9a\u53c2\u6570\u7684\u53d8\u5316\uff08\u901a\u8fc7\u6761\u4ef6\u5224\u65ad\uff09\r\ndef on_param_changed(name, value):\r\n if name == \"username\":\r\n print(f\"\u7528\u6237\u540d\u5df2\u66f4\u6539\u4e3a: {value}\")\r\n elif name == \"volume\":\r\n print(f\"\u97f3\u91cf\u8bbe\u7f6e\u4e3a: {value}\")\r\n # \u8fd9\u91cc\u53ef\u4ee5\u6dfb\u52a0\u5b9e\u9645\u7684\u5904\u7406\u903b\u8f91\r\n update_audio_volume(value)\r\n\r\ninspector.paramChanged.connect(on_param_changed)\r\n```\r\n\r\n## \u5e38\u89c1\u95ee\u9898\r\n\r\n### 1. \u5982\u4f55\u63a7\u5236\u7ec4\u4ef6\u7684\u53ea\u8bfb\u72b6\u6001\uff1f\r\n\u4f7f\u7528 `readonly=True` \u53c2\u6570\uff1a\r\n```python\r\nMonoAttr(\"server_url\", \"https://api.example.com\", readonly=True, label=\"\u670d\u52a1\u5668\u5730\u5740\")\r\n```\r\n\r\n### 2. \u5982\u4f55\u6dfb\u52a0\u5206\u9694\u7b26\u548c\u7a7a\u767d\u95f4\u9694\uff1f\r\n\u4f7f\u7528 `separator=True` \u548c `space=True` \u53c2\u6570\uff1a\r\n```python\r\nattrs = [\r\n MonoAttr(\"section1\", \"\u7b2c\u4e00\u90e8\u5206\", title=\"\u7b2c\u4e00\u90e8\u5206\"),\r\n MonoAttr(\"param1\", \"value1\", label=\"\u53c2\u65701\"),\r\n MonoAttr(\"param2\", \"value2\", label=\"\u53c2\u65702\", separator=True), # \u6dfb\u52a0\u5206\u9694\u7ebf\r\n MonoAttr(\"section2\", \"\u7b2c\u4e8c\u90e8\u5206\", title=\"\u7b2c\u4e8c\u90e8\u5206\"),\r\n MonoAttr(\"param3\", \"value3\", label=\"\u53c2\u65703\", space=True), # \u6dfb\u52a0\u4e0a\u65b9\u7a7a\u767d\r\n]\r\n```\r\n\r\n### 3. \u5982\u4f55\u5904\u7406\u53c2\u6570\u53d8\u5316\u4e8b\u4ef6\uff1f\r\n\u4f7f\u7528\u4fe1\u53f7\u69fd\u673a\u5236\u76d1\u542c\u53c2\u6570\u53d8\u5316\uff1a\r\n```python\r\n# \u76d1\u542c\u5355\u4e2a\u53c2\u6570\u53d8\u5316\r\ninspector.paramChanged.connect(lambda name, value: print(f\"\u53c2\u6570 {name} \u5df2\u66f4\u6539\u4e3a: {value}\"))\r\n\r\n# \u76d1\u542c\u6240\u6709\u53c2\u6570\u53d8\u5316\r\ninspector.paramsChanged.connect(lambda params: print(f\"\u6240\u6709\u53c2\u6570\u5df2\u66f4\u65b0: {params}\"))\r\n\r\n# \u76d1\u542c\u7279\u5b9a\u53c2\u6570\u7684\u53d8\u5316\uff08\u901a\u8fc7\u6761\u4ef6\u5224\u65ad\uff09\r\ndef on_param_changed(name, value):\r\n if name == \"username\":\r\n print(f\"\u7528\u6237\u540d\u5df2\u66f4\u6539\u4e3a: {value}\")\r\n elif name == \"volume\":\r\n print(f\"\u97f3\u91cf\u8bbe\u7f6e\u4e3a: {value}\")\r\n # \u8fd9\u91cc\u53ef\u4ee5\u6dfb\u52a0\u5b9e\u9645\u7684\u5904\u7406\u903b\u8f91\r\n update_audio_volume(value)\r\n\r\ninspector.paramChanged.connect(on_param_changed)\r\n```\r\n\r\n## \u793a\u4f8b\u5e94\u7528\u8bf4\u660e\r\n\r\n\u9879\u76ee\u5305\u542b\u591a\u4e2a\u793a\u4f8b\u6587\u4ef6\uff0c\u5c55\u793a\u4e86MonoWidget\u7684\u5404\u79cd\u7528\u6cd5\uff1a\r\n\r\n- **main.py**: \u57fa\u7840\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u521b\u5efa\u7b80\u5355\u7684\u53c2\u6570\u754c\u9762\r\n- **debug_type_change_value.py**: \u8c03\u8bd5\u793a\u4f8b\uff0c\u5c55\u793a\u5404\u79cd\u6570\u636e\u7c7b\u578b\u7684\u53c2\u6570\u754c\u9762\r\n- **inspector/**: Inspector\u76f8\u5173\u6a21\u5757\uff0c\u5305\u542b\u6240\u6709\u754c\u9762\u7ec4\u4ef6\u7684\u5b9e\u73b0\r\n- **_utils/**: \u5de5\u5177\u6a21\u5757\uff0c\u5305\u542b\u5404\u79cd\u8f85\u52a9\u7c7b\u548c\u7ec4\u4ef6\r\n\r\n\u60a8\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c `main.py` \u6765\u67e5\u770b\u57fa\u7840\u793a\u4f8b\uff0c\u6216\u8005\u53c2\u8003\u5404\u4e2a\u6a21\u5757\u7684\u6e90\u4ee3\u7801\u4e86\u89e3\u66f4\u8be6\u7ec6\u7684\u5b9e\u73b0\u3002\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A modern PyQt6 parameter interface library for creating interactive configuration panels with automatic UI generation.",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/monowidget/monowidget"
},
"split_keywords": [
"pyqt6",
" parameter",
" interface",
" configuration",
" ui",
" widget",
" inspector"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "caba5f093a1e28c72d199a83905c7d0060951456e68ac12f5062592064b7a5ad",
"md5": "e7e1d67d7a917d230e8270e3e065f1a4",
"sha256": "0fd94f80c8d28abadbc4c19c98ea535e51207d4ca30ec6bd0064db3bad7caca4"
},
"downloads": -1,
"filename": "monowidget-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e7e1d67d7a917d230e8270e3e065f1a4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 69905,
"upload_time": "2025-09-06T22:51:01",
"upload_time_iso_8601": "2025-09-06T22:51:01.909397Z",
"url": "https://files.pythonhosted.org/packages/ca/ba/5f093a1e28c72d199a83905c7d0060951456e68ac12f5062592064b7a5ad/monowidget-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "f0d5745fddfd0ed37b42e83289785188db6e65985a0974cc8f579dfb48316feb",
"md5": "5fc8d3dd1f093415a74810db7695bdad",
"sha256": "035db5754dc16f7978e16c07d7a65a84961d59758c04eb5e13931bb70c8a0ee2"
},
"downloads": -1,
"filename": "monowidget-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "5fc8d3dd1f093415a74810db7695bdad",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 55646,
"upload_time": "2025-09-06T22:51:03",
"upload_time_iso_8601": "2025-09-06T22:51:03.582552Z",
"url": "https://files.pythonhosted.org/packages/f0/d5/745fddfd0ed37b42e83289785188db6e65985a0974cc8f579dfb48316feb/monowidget-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-06 22:51:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "monowidget",
"github_project": "monowidget",
"github_not_found": true,
"lcname": "monowidget"
}