monowidget 0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- monowidget-0.1/PKG-INFO +443 -0
- monowidget-0.1/README.md +403 -0
- monowidget-0.1/monowidget/__init__.py +14 -0
- monowidget-0.1/monowidget/_utils/__init__.py +25 -0
- monowidget-0.1/monowidget/_utils/const.py +14 -0
- monowidget-0.1/monowidget/_utils/core.py +104 -0
- monowidget-0.1/monowidget/_utils/ordered_dict.py +240 -0
- monowidget-0.1/monowidget/_utils/qcalendar.py +195 -0
- monowidget-0.1/monowidget/_utils/qdatetime.py +179 -0
- monowidget-0.1/monowidget/_utils/qslabel.py +170 -0
- monowidget-0.1/monowidget/_utils/qslider.py +155 -0
- monowidget-0.1/monowidget/_utils/qspacer.py +15 -0
- monowidget-0.1/monowidget/_utils/qtimeedit.py +112 -0
- monowidget-0.1/monowidget/_utils/rangef.py +59 -0
- monowidget-0.1/monowidget/_utils/reset_button.py +67 -0
- monowidget-0.1/monowidget/_utils/validate_components.py +19 -0
- monowidget-0.1/monowidget/inspector/__init__.py +40 -0
- monowidget-0.1/monowidget/inspector/inspector_area.py +220 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item.py +73 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item_base.py +206 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item_bool.py +52 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item_complex.py +76 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item_datetime.py +173 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item_dict.py +529 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item_factory.py +147 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item_float.py +117 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item_function.py +108 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item_int.py +117 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item_list.py +409 -0
- monowidget-0.1/monowidget/inspector/mono_attr_item_str.py +83 -0
- monowidget-0.1/monowidget/inspector/mono_group.py +126 -0
- monowidget-0.1/monowidget/inspector/mono_runtime.py +409 -0
- monowidget-0.1/monowidget/inspector/mono_separator.py +56 -0
- monowidget-0.1/monowidget/inspector/qmono_inspector.py +71 -0
- monowidget-0.1/monowidget/inspector/ui_classes.py +13 -0
- monowidget-0.1/monowidget/inspector/utils.py +79 -0
- monowidget-0.1/monowidget/main.py +479 -0
- monowidget-0.1/monowidget/mono/__init__.py +10 -0
- monowidget-0.1/monowidget/mono/mono.py +12 -0
- monowidget-0.1/monowidget/mono/mono_attr.py +114 -0
- monowidget-0.1/monowidget.egg-info/PKG-INFO +443 -0
- monowidget-0.1/monowidget.egg-info/SOURCES.txt +45 -0
- monowidget-0.1/monowidget.egg-info/dependency_links.txt +1 -0
- monowidget-0.1/monowidget.egg-info/requires.txt +2 -0
- monowidget-0.1/monowidget.egg-info/top_level.txt +1 -0
- monowidget-0.1/setup.cfg +4 -0
- monowidget-0.1/setup.py +39 -0
monowidget-0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: monowidget
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: A modern PyQt6 parameter interface library for creating interactive configuration panels with automatic UI generation.
|
|
5
|
+
Home-page: https://github.com/monowidget/monowidget
|
|
6
|
+
Author: Eagle'sBaby
|
|
7
|
+
Author-email: 2229066748@qq.com
|
|
8
|
+
Maintainer: Eagle'sBaby
|
|
9
|
+
Maintainer-email: 2229066748@qq.com
|
|
10
|
+
License: MIT
|
|
11
|
+
Keywords: pyqt6,parameter,interface,configuration,ui,widget,inspector
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Topic :: Desktop Environment
|
|
22
|
+
Classifier: Topic :: Software Development :: User Interfaces
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: PyQt6
|
|
26
|
+
Requires-Dist: rbpop>=0.3
|
|
27
|
+
Dynamic: author
|
|
28
|
+
Dynamic: author-email
|
|
29
|
+
Dynamic: classifier
|
|
30
|
+
Dynamic: description
|
|
31
|
+
Dynamic: description-content-type
|
|
32
|
+
Dynamic: home-page
|
|
33
|
+
Dynamic: keywords
|
|
34
|
+
Dynamic: license
|
|
35
|
+
Dynamic: maintainer
|
|
36
|
+
Dynamic: maintainer-email
|
|
37
|
+
Dynamic: requires-dist
|
|
38
|
+
Dynamic: requires-python
|
|
39
|
+
Dynamic: summary
|
|
40
|
+
|
|
41
|
+
# MonoWidget User Guide
|
|
42
|
+
|
|
43
|
+
## Project Overview
|
|
44
|
+
|
|
45
|
+
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.
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
### Installation
|
|
50
|
+
|
|
51
|
+
MonoWidget is currently a local development library. Simply clone or download the source code to your project.
|
|
52
|
+
|
|
53
|
+
### Basic Usage Example
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import sys
|
|
57
|
+
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
|
|
58
|
+
from monowidget import *
|
|
59
|
+
|
|
60
|
+
class MainWindow(QMainWindow):
|
|
61
|
+
def __init__(self):
|
|
62
|
+
super().__init__()
|
|
63
|
+
self.setWindowTitle("MonoWidget Example")
|
|
64
|
+
self.setGeometry(100, 100, 600, 400)
|
|
65
|
+
|
|
66
|
+
# Create central widget
|
|
67
|
+
central_widget = QWidget()
|
|
68
|
+
self.setCentralWidget(central_widget)
|
|
69
|
+
|
|
70
|
+
# Create main layout
|
|
71
|
+
main_layout = QVBoxLayout(central_widget)
|
|
72
|
+
|
|
73
|
+
# Define attribute list
|
|
74
|
+
attrs = [
|
|
75
|
+
MonoAttr("username", "Alice", label="Username"),
|
|
76
|
+
MonoAttr("age", 30, range=(18, 100), label="Age"),
|
|
77
|
+
MonoAttr("active", True, label="Active"),
|
|
78
|
+
MonoAttr("theme", "dark", enum=["light", "dark", "auto"], label="Theme"),
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
# Create Mono object
|
|
82
|
+
mono = Mono(attrs)
|
|
83
|
+
|
|
84
|
+
# Create Inspector and add to layout
|
|
85
|
+
inspector = QMonoInspector(mono)
|
|
86
|
+
main_layout.addWidget(inspector)
|
|
87
|
+
|
|
88
|
+
if __name__ == "__main__":
|
|
89
|
+
app = QApplication(sys.argv)
|
|
90
|
+
window = MainWindow()
|
|
91
|
+
window.show()
|
|
92
|
+
sys.exit(app.exec())
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Core Concepts
|
|
96
|
+
|
|
97
|
+
### MonoAttr
|
|
98
|
+
`MonoAttr` is a parameter definition class used to describe all properties of a single parameter, including name, value, type, range, etc.
|
|
99
|
+
|
|
100
|
+
### Mono
|
|
101
|
+
`Mono` is a data model class that contains multiple `MonoAttr` properties and serves as the data source for `QMonoInspector`.
|
|
102
|
+
|
|
103
|
+
### QMonoInspector
|
|
104
|
+
`QMonoInspector` is the interface renderer responsible for rendering `Mono` objects into visual interfaces.
|
|
105
|
+
|
|
106
|
+
## Using MonoAttr to Create Inspector
|
|
107
|
+
|
|
108
|
+
### 1. Import Necessary Modules
|
|
109
|
+
```python
|
|
110
|
+
from monowidget import *
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 2. Define MonoAttr Properties
|
|
114
|
+
`MonoAttr` supports multiple parameter types. The system will automatically identify and generate corresponding interface controls based on the `value` type:
|
|
115
|
+
|
|
116
|
+
#### Supported Type Comparison Table
|
|
117
|
+
|
|
118
|
+
| Type | Python Value Example | Interface Control |
|
|
119
|
+
|------|---------------------|-------------------|
|
|
120
|
+
| **String** | `"text"` | Text input box |
|
|
121
|
+
| **Integer** | `42` | Number input box |
|
|
122
|
+
| **Float** | `3.14` | Float input box |
|
|
123
|
+
| **Boolean** | `True` | Checkbox |
|
|
124
|
+
| **Enum** | `"option1"` | Dropdown selection |
|
|
125
|
+
| **List** | `[1, 2, 3]` | List editor |
|
|
126
|
+
| **Dict** | `{"key": "value"}` | Dictionary editor |
|
|
127
|
+
| **Function Button** | `lambda: print("hi")` | Button |
|
|
128
|
+
| **DateTime** | `datetime.now()` | DateTime picker |
|
|
129
|
+
| **Color** | `"#ff0000"` | Color picker |
|
|
130
|
+
|
|
131
|
+
#### Usage Example
|
|
132
|
+
```python
|
|
133
|
+
from datetime import datetime
|
|
134
|
+
|
|
135
|
+
attrs = [
|
|
136
|
+
# Basic types
|
|
137
|
+
MonoAttr("name", "Example", label="Name"), # String
|
|
138
|
+
MonoAttr("count", 42, label="Count"), # Integer
|
|
139
|
+
MonoAttr("price", 29.99, label="Price"), # Float
|
|
140
|
+
MonoAttr("enabled", True, label="Enabled"), # Boolean
|
|
141
|
+
|
|
142
|
+
# Range-limited numbers
|
|
143
|
+
MonoAttr("volume", 75, range=(0, 100, 5), label="Volume"),
|
|
144
|
+
|
|
145
|
+
# Enum type
|
|
146
|
+
MonoAttr("mode", "normal", enum=["easy", "normal", "hard"], label="Mode"),
|
|
147
|
+
|
|
148
|
+
# Complex types
|
|
149
|
+
MonoAttr("tags", ["python", "qt"], label="Tags"), # List
|
|
150
|
+
MonoAttr("settings", {"theme": "dark", "font": 14}, label="Settings"), # Dict
|
|
151
|
+
|
|
152
|
+
# Function button
|
|
153
|
+
MonoAttr("save_button", lambda: print("Saved"), label="Save Settings"),
|
|
154
|
+
|
|
155
|
+
# DateTime
|
|
156
|
+
MonoAttr("start_time", datetime.now(), label="Start Time"),
|
|
157
|
+
|
|
158
|
+
# Color
|
|
159
|
+
MonoAttr("bg_color", "#ffffff", label="Background Color")
|
|
160
|
+
]
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 3. Create Mono Object
|
|
164
|
+
Use the attribute list to create a `Mono` object:
|
|
165
|
+
```python
|
|
166
|
+
mono = Mono(attrs)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 4. Create and Display Inspector
|
|
170
|
+
```python
|
|
171
|
+
# Create QMonoInspector instance
|
|
172
|
+
inspector = QMonoInspector(mono)
|
|
173
|
+
|
|
174
|
+
# Add to layout
|
|
175
|
+
layout.addWidget(inspector)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 5. Advanced Configuration - Grouping and Titles
|
|
179
|
+
You can use `group`, `header`, and `title` parameters to organize the interface layout:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
attrs = [
|
|
183
|
+
# Page title
|
|
184
|
+
MonoAttr("app_title", "Configuration Center", title="Application Configuration Center"),
|
|
185
|
+
|
|
186
|
+
# User info group
|
|
187
|
+
MonoAttr("username", "admin", label="Username", group="User Info", header="👤 User Configuration"),
|
|
188
|
+
MonoAttr("email", "admin@example.com", label="Email", group="User Info"),
|
|
189
|
+
|
|
190
|
+
# Interface settings group
|
|
191
|
+
MonoAttr("theme", "dark", enum=["light", "dark"], label="Theme", group="Interface Settings", header="🎨 Appearance Settings"),
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
# MonoWidget 使用指南
|
|
197
|
+
|
|
198
|
+
## 项目简介
|
|
199
|
+
|
|
200
|
+
MonoWidget 是一个用于创建和管理参数界面的Python工具,通过简洁的API定义参数,并自动生成可视化的界面组件。它特别适用于快速开发需要用户交互的配置界面、调试工具和参数调试器等场景。
|
|
201
|
+
|
|
202
|
+
## 快速开始
|
|
203
|
+
|
|
204
|
+
### 安装
|
|
205
|
+
|
|
206
|
+
MonoWidget 目前是一个本地开发库,直接克隆或下载源代码到您的项目中即可使用。
|
|
207
|
+
|
|
208
|
+
### 基本使用示例
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
import sys
|
|
212
|
+
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
|
|
213
|
+
from monowidget import *
|
|
214
|
+
|
|
215
|
+
class MainWindow(QMainWindow):
|
|
216
|
+
def __init__(self):
|
|
217
|
+
super().__init__()
|
|
218
|
+
self.setWindowTitle("MonoWidget 示例")
|
|
219
|
+
self.setGeometry(100, 100, 600, 400)
|
|
220
|
+
|
|
221
|
+
# 创建中心部件
|
|
222
|
+
central_widget = QWidget()
|
|
223
|
+
self.setCentralWidget(central_widget)
|
|
224
|
+
|
|
225
|
+
# 创建主布局
|
|
226
|
+
main_layout = QVBoxLayout(central_widget)
|
|
227
|
+
|
|
228
|
+
# 定义属性列表
|
|
229
|
+
attrs = [
|
|
230
|
+
MonoAttr("username", "Alice", label="用户名"),
|
|
231
|
+
MonoAttr("age", 30, range=(18, 100), label="年龄"),
|
|
232
|
+
MonoAttr("active", True, label="是否激活"),
|
|
233
|
+
MonoAttr("theme", "dark", enum=["light", "dark", "auto"], label="界面主题"),
|
|
234
|
+
]
|
|
235
|
+
|
|
236
|
+
# 创建Mono对象
|
|
237
|
+
mono = Mono(attrs)
|
|
238
|
+
|
|
239
|
+
# 创建Inspector并添加到布局
|
|
240
|
+
inspector = QMonoInspector(mono)
|
|
241
|
+
main_layout.addWidget(inspector)
|
|
242
|
+
|
|
243
|
+
if __name__ == "__main__":
|
|
244
|
+
app = QApplication(sys.argv)
|
|
245
|
+
window = MainWindow()
|
|
246
|
+
window.show()
|
|
247
|
+
sys.exit(app.exec())
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## 核心概念
|
|
251
|
+
|
|
252
|
+
### MonoAttr
|
|
253
|
+
`MonoAttr` 是参数定义类,用于描述单个参数的所有属性,包括名称、值、类型、范围等。
|
|
254
|
+
|
|
255
|
+
### Mono
|
|
256
|
+
`Mono` 是数据模型类,包含多个 `MonoAttr` 属性,作为 `QMonoInspector` 的数据源。
|
|
257
|
+
|
|
258
|
+
### QMonoInspector
|
|
259
|
+
`QMonoInspector` 是界面渲染器,负责将 `Mono` 对象渲染为可视化界面。
|
|
260
|
+
|
|
261
|
+
## 使用 MonoAttr 创建 Inspector
|
|
262
|
+
|
|
263
|
+
### 1. 导入必要的模块
|
|
264
|
+
```python
|
|
265
|
+
from monowidget import *
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### 2. 定义 MonoAttr 属性
|
|
269
|
+
`MonoAttr` 支持多种参数类型,系统会根据 `value` 的类型自动识别并生成相应的界面控件:
|
|
270
|
+
|
|
271
|
+
#### 支持的类型对照表
|
|
272
|
+
|
|
273
|
+
| 类型 | Python值示例 | 界面控件 |
|
|
274
|
+
|------|-------------|----------|
|
|
275
|
+
| **字符串** | `"text"` | 文本输入框 |
|
|
276
|
+
| **整数** | `42` | 数字输入框 |
|
|
277
|
+
| **浮点数** | `3.14` | 浮点输入框 |
|
|
278
|
+
| **布尔值** | `True` | 复选框 |
|
|
279
|
+
| **枚举** | `"option1"` | 下拉选择框 |
|
|
280
|
+
| **列表** | `[1, 2, 3]` | 列表编辑器 |
|
|
281
|
+
| **字典** | `{"key": "value"}` | 字典编辑器 |
|
|
282
|
+
| **函数按钮** | `lambda: print("hi")` | 按钮 |
|
|
283
|
+
| **日期时间** | `datetime.now()` | 日期时间选择器 |
|
|
284
|
+
| **颜色** | `"#ff0000"` | 颜色选择器 |
|
|
285
|
+
|
|
286
|
+
#### 使用示例
|
|
287
|
+
```python
|
|
288
|
+
from datetime import datetime
|
|
289
|
+
|
|
290
|
+
attrs = [
|
|
291
|
+
# 基本类型
|
|
292
|
+
MonoAttr("name", "Example", label="名称"), # 字符串
|
|
293
|
+
MonoAttr("count", 42, label="数量"), # 整数
|
|
294
|
+
MonoAttr("price", 29.99, label="价格"), # 浮点数
|
|
295
|
+
MonoAttr("enabled", True, label="启用"), # 布尔值
|
|
296
|
+
|
|
297
|
+
# 带范围限制的数值
|
|
298
|
+
MonoAttr("volume", 75, range=(0, 100, 5), label="音量"),
|
|
299
|
+
|
|
300
|
+
# 枚举类型
|
|
301
|
+
MonoAttr("mode", "normal", enum=["easy", "normal", "hard"], label="模式"),
|
|
302
|
+
|
|
303
|
+
# 复杂类型
|
|
304
|
+
MonoAttr("tags", ["python", "qt"], label="标签"), # 列表
|
|
305
|
+
MonoAttr("settings", {"theme": "dark", "font": 14}, label="设置"), # 字典
|
|
306
|
+
|
|
307
|
+
# 函数按钮
|
|
308
|
+
MonoAttr("save_button", lambda: print("已保存"), label="保存设置"),
|
|
309
|
+
|
|
310
|
+
# 日期时间
|
|
311
|
+
MonoAttr("start_time", datetime.now(), label="开始时间"),
|
|
312
|
+
|
|
313
|
+
# 颜色
|
|
314
|
+
MonoAttr("bg_color", "#ffffff", label="背景颜色")
|
|
315
|
+
]
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### 3. 创建 Mono 对象
|
|
319
|
+
使用属性列表创建 `Mono` 对象:
|
|
320
|
+
```python
|
|
321
|
+
mono = Mono(attrs)
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### 4. 创建并显示 Inspector
|
|
325
|
+
```python
|
|
326
|
+
# 创建QMonoInspector实例
|
|
327
|
+
inspector = QMonoInspector(mono)
|
|
328
|
+
|
|
329
|
+
# 添加到布局
|
|
330
|
+
layout.addWidget(inspector)
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### 5. 高级配置 - 分组和标题
|
|
334
|
+
您可以使用 `group`、`header` 和 `title` 参数来组织界面布局:
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
attrs = [
|
|
338
|
+
# 页面标题
|
|
339
|
+
MonoAttr("app_title", "配置中心", title="应用配置中心"),
|
|
340
|
+
|
|
341
|
+
# 用户信息分组
|
|
342
|
+
MonoAttr("username", "admin", label="用户名", group="用户信息", header="👤 用户配置"),
|
|
343
|
+
MonoAttr("email", "admin@example.com", label="邮箱", group="用户信息"),
|
|
344
|
+
|
|
345
|
+
# 界面设置分组
|
|
346
|
+
MonoAttr("theme", "dark", enum=["light", "dark"], label="主题", group="界面设置", header="🎨 外观设置"),
|
|
347
|
+
]
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## 数据读写方法
|
|
351
|
+
|
|
352
|
+
### 方法1:使用字典形式读取所有参数值
|
|
353
|
+
```python
|
|
354
|
+
# 获取所有参数值(字典形式)
|
|
355
|
+
values = inspector.params # 返回包含所有参数值的字典
|
|
356
|
+
print(values) # 输出: {'username': 'Alice', 'age': 30, ...}
|
|
357
|
+
|
|
358
|
+
# 设置多个参数值
|
|
359
|
+
inspector.params = {
|
|
360
|
+
'username': 'Bob',
|
|
361
|
+
'age': 25
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### 方法2:使用 inspector.vs 访问单个属性
|
|
366
|
+
```python
|
|
367
|
+
# 读取单个参数值
|
|
368
|
+
username = inspector.vs.username
|
|
369
|
+
print(f"当前用户名: {username}")
|
|
370
|
+
|
|
371
|
+
# 修改单个参数值
|
|
372
|
+
inspector.vs.username = "Charlie"
|
|
373
|
+
inspector.vs.age = 35
|
|
374
|
+
|
|
375
|
+
# 批量更新多个属性的值
|
|
376
|
+
new_values = {
|
|
377
|
+
'username': 'David',
|
|
378
|
+
'age': 40,
|
|
379
|
+
'active': False
|
|
380
|
+
}
|
|
381
|
+
for key, value in new_values.items():
|
|
382
|
+
setattr(inspector.vs, key, value)
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### 方法3:监听参数变化事件
|
|
386
|
+
```python
|
|
387
|
+
# 监听单个参数变化
|
|
388
|
+
@mono.on("username")
|
|
389
|
+
def on_username_changed(value):
|
|
390
|
+
print(f"用户名已更改为: {value}")
|
|
391
|
+
|
|
392
|
+
# 监听所有参数变化
|
|
393
|
+
@mono.on("*")
|
|
394
|
+
def on_any_param_changed(name, value):
|
|
395
|
+
print(f"参数 {name} 已更改为: {value}")
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## 常见问题
|
|
399
|
+
|
|
400
|
+
### 1. 如何控制组件的只读状态?
|
|
401
|
+
使用 `readonly=True` 参数:
|
|
402
|
+
```python
|
|
403
|
+
MonoAttr("server_url", "https://api.example.com", readonly=True, label="服务器地址")
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### 2. 如何添加分隔符和空白间隔?
|
|
407
|
+
使用 `separator=True` 和 `space=True` 参数:
|
|
408
|
+
```python
|
|
409
|
+
attrs = [
|
|
410
|
+
MonoAttr("section1", "第一部分", title="第一部分"),
|
|
411
|
+
MonoAttr("param1", "value1", label="参数1"),
|
|
412
|
+
MonoAttr("param2", "value2", label="参数2", separator=True), # 添加分隔线
|
|
413
|
+
MonoAttr("section2", "第二部分", title="第二部分"),
|
|
414
|
+
MonoAttr("param3", "value3", label="参数3", space=True), # 添加上方空白
|
|
415
|
+
]
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### 3. 如何处理参数变化事件?
|
|
419
|
+
使用 `@mono.on()` 装饰器监听参数变化:
|
|
420
|
+
```python
|
|
421
|
+
# 监听特定参数
|
|
422
|
+
@mono.on("volume")
|
|
423
|
+
def on_volume_changed(value):
|
|
424
|
+
print(f"音量设置为: {value}")
|
|
425
|
+
# 这里可以添加实际的处理逻辑
|
|
426
|
+
update_audio_volume(value)
|
|
427
|
+
|
|
428
|
+
# 监听所有参数变化
|
|
429
|
+
@mono.on("*")
|
|
430
|
+
def on_any_change(name, value):
|
|
431
|
+
print(f"参数 {name} 变更为: {value}")
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## 示例应用说明
|
|
435
|
+
|
|
436
|
+
项目包含多个示例文件,展示了MonoWidget的各种用法:
|
|
437
|
+
|
|
438
|
+
- **main.py**: 基础示例,展示如何创建简单的参数界面
|
|
439
|
+
- **debug_type_change_value.py**: 调试示例,展示各种数据类型的参数界面
|
|
440
|
+
- **inspector/**: Inspector相关模块,包含所有界面组件的实现
|
|
441
|
+
- **_utils/**: 工具模块,包含各种辅助类和组件
|
|
442
|
+
|
|
443
|
+
您可以通过运行 `main.py` 来查看基础示例,或者参考各个模块的源代码了解更详细的实现。
|