monowidget 0.2.1__tar.gz → 0.2.2__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.2.1 → monowidget-0.2.2}/PKG-INFO +1 -1
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/__init__.py +2 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item_factory.py +3 -0
- monowidget-0.2.2/monowidget/inspector/mono_attr_item_path.py +109 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_runtime.py +24 -5
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget.egg-info/PKG-INFO +1 -1
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget.egg-info/SOURCES.txt +1 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/setup.py +1 -1
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/__init__.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/__init__.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/const.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/core.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/ordered_dict.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/qcalendar.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/qdatetime.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/qslabel.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/qslider.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/qspacer.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/qtimeedit.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/rangef.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/_utils/reset_button.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/demo.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/_item_container.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/inspector_area.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item_base.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item_bool.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item_complex.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item_datetime.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item_dict.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item_float.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item_function.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item_int.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item_list.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_attr_item_str.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/mono_group.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/qmono_inspector.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/inspector/ui_classes.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/mono/__init__.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/mono/mono.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/mono/mono_attr.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget/protocols.py +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget.egg-info/dependency_links.txt +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget.egg-info/requires.txt +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/monowidget.egg-info/top_level.txt +0 -0
- {monowidget-0.2.1 → monowidget-0.2.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: monowidget
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A modern PyQt6 parameter interface library for creating interactive configuration panels with automatic UI generation.
|
|
5
5
|
Home-page: https://github.com/monowidget/monowidget
|
|
6
6
|
Author: Eagle'sBaby
|
|
@@ -14,6 +14,7 @@ from monowidget.inspector.mono_attr_item_function import QMonoAttrFunctionItem
|
|
|
14
14
|
from monowidget.inspector.mono_attr_item_int import QMonoAttrItemInt
|
|
15
15
|
|
|
16
16
|
from monowidget.inspector.mono_attr_item_list import QMonoAttrItemList
|
|
17
|
+
from monowidget.inspector.mono_attr_item_path import QMonoAttrItemPath
|
|
17
18
|
from monowidget.inspector.mono_attr_item_str import QMonoAttrItemStr
|
|
18
19
|
from monowidget.inspector.mono_group import QMonoGroup
|
|
19
20
|
from monowidget.inspector.mono_runtime import MonoaRuntime
|
|
@@ -37,6 +38,7 @@ __all__ = [
|
|
|
37
38
|
"QMonoAttrItemDateTime",
|
|
38
39
|
"QMonoAttrItemList",
|
|
39
40
|
"QMonoAttrItemDict",
|
|
41
|
+
"QMonoAttrItemPath",
|
|
40
42
|
"QMonoAttrFunctionItem",
|
|
41
43
|
"QMonoAttrItemFactory",
|
|
42
44
|
"MonoaRuntime",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
15
|
from datetime import datetime
|
|
16
|
+
from pathlib import Path
|
|
16
17
|
from typing import Any, Dict, Optional, Type
|
|
17
18
|
|
|
18
19
|
from monowidget._utils import IdOrderedDict
|
|
@@ -25,6 +26,7 @@ from monowidget.inspector.mono_attr_item_float import QMonoAttrItemFloat
|
|
|
25
26
|
from monowidget.inspector.mono_attr_item_function import QMonoAttrFunctionItem
|
|
26
27
|
from monowidget.inspector.mono_attr_item_int import QMonoAttrItemInt
|
|
27
28
|
from monowidget.inspector.mono_attr_item_list import QMonoAttrItemList
|
|
29
|
+
from monowidget.inspector.mono_attr_item_path import QMonoAttrItemPath
|
|
28
30
|
from monowidget.inspector.mono_attr_item_str import QMonoAttrItemStr
|
|
29
31
|
from monowidget.inspector.ui_classes import QMonoWithoutBorder
|
|
30
32
|
|
|
@@ -42,6 +44,7 @@ class QMonoAttrItemFactory:
|
|
|
42
44
|
list: QMonoAttrItemList,
|
|
43
45
|
dict: QMonoAttrItemDict,
|
|
44
46
|
IdOrderedDict: QMonoAttrItemDict,
|
|
47
|
+
Path: QMonoAttrItemPath,
|
|
45
48
|
"function": QMonoAttrFunctionItem,
|
|
46
49
|
}
|
|
47
50
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""monowidget.inspector.mono_attr_item_path —— 文件路径属性项(pathlib.Path)。
|
|
3
|
+
|
|
4
|
+
QLineEdit + “浏览…”按钮。``enum`` 声明可选后缀,'.' 与大小写不敏感:
|
|
5
|
+
``enum=["txt", ".xlsx"]`` 与 ``enum=[".TXT", "xlsx"]`` 等价。浏览对话框按
|
|
6
|
+
后缀过滤;选中后缀不匹配的文件会被拒绝(rbpop 提示,未安装则静默忽略)。
|
|
7
|
+
|
|
8
|
+
自定义属性 ``placeholder`` 可设置输入框占位文本。
|
|
9
|
+
|
|
10
|
+
空值约定:``Path("")``(即 ``Path(".")``),输入框显示为空串。
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any, List
|
|
18
|
+
|
|
19
|
+
from PyQt6.QtWidgets import QFileDialog, QLineEdit, QPushButton
|
|
20
|
+
|
|
21
|
+
from monowidget._utils.const import MONO_FONT, MONO_VALUE_FONT
|
|
22
|
+
from monowidget._utils.core import QPop, QPWarn
|
|
23
|
+
from monowidget.inspector.mono_attr_item_base import QMonoAttrItemBase
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class QMonoAttrItemPath(QMonoAttrItemBase):
|
|
27
|
+
"""文件路径属性项。"""
|
|
28
|
+
|
|
29
|
+
def build(self) -> None:
|
|
30
|
+
self._mwd = QLineEdit()
|
|
31
|
+
font = MONO_VALUE_FONT or MONO_FONT
|
|
32
|
+
if font:
|
|
33
|
+
self._mwd.setFont(font)
|
|
34
|
+
_ph = self.attr.get("placeholder")
|
|
35
|
+
if _ph:
|
|
36
|
+
self._mwd.setPlaceholderText(str(_ph))
|
|
37
|
+
self.layout.insertWidget(1, self._mwd, 1)
|
|
38
|
+
self.register(self._mwd)
|
|
39
|
+
self._mwd.textChanged.connect(self._path_value_changed)
|
|
40
|
+
|
|
41
|
+
self._btn_browse = QPushButton("浏览…")
|
|
42
|
+
if MONO_FONT:
|
|
43
|
+
self._btn_browse.setFont(MONO_FONT)
|
|
44
|
+
self.layout.insertWidget(2, self._btn_browse)
|
|
45
|
+
self.register(self._btn_browse)
|
|
46
|
+
self._btn_browse.clicked.connect(self._on_browse)
|
|
47
|
+
|
|
48
|
+
# ---- 值读写 ----
|
|
49
|
+
|
|
50
|
+
def apply(self, *_, value: Any = None) -> None:
|
|
51
|
+
value = value if value is not None else self.attr["value"]
|
|
52
|
+
self._path_value_changed(value)
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def _to_path(value: Any) -> Path:
|
|
56
|
+
if isinstance(value, Path):
|
|
57
|
+
return value
|
|
58
|
+
return Path(str(value)) if str(value) else Path("")
|
|
59
|
+
|
|
60
|
+
def _path_value_changed(self, value: Any) -> None:
|
|
61
|
+
if getattr(self, "_vc_flag", False):
|
|
62
|
+
return
|
|
63
|
+
self._vc_flag = True
|
|
64
|
+
try:
|
|
65
|
+
value = self._to_path(value)
|
|
66
|
+
_text = str(value)
|
|
67
|
+
# Path("") 的 str 是 ".",显示为空串
|
|
68
|
+
self._mwd.setText("" if _text == "." else _text)
|
|
69
|
+
finally:
|
|
70
|
+
self._vc_flag = False
|
|
71
|
+
self.notify(value)
|
|
72
|
+
|
|
73
|
+
# ---- 后缀限定(enum:'.' 与大小写不敏感)----
|
|
74
|
+
|
|
75
|
+
def _suffixes(self) -> List[str]:
|
|
76
|
+
"""enum 归一化为小写无点后缀列表;空列表表示不限后缀。"""
|
|
77
|
+
return [str(e).strip().lower().lstrip(".")
|
|
78
|
+
for e in (self.attr.get("enum") or []) if str(e).strip(". ")]
|
|
79
|
+
|
|
80
|
+
def _match_suffix(self, path: Path) -> bool:
|
|
81
|
+
_suffixes = self._suffixes()
|
|
82
|
+
if not _suffixes:
|
|
83
|
+
return True
|
|
84
|
+
return path.suffix.lower().lstrip(".") in _suffixes
|
|
85
|
+
|
|
86
|
+
# ---- 浏览 ----
|
|
87
|
+
|
|
88
|
+
def _on_browse(self) -> None:
|
|
89
|
+
_suffixes = self._suffixes()
|
|
90
|
+
if _suffixes:
|
|
91
|
+
_filter = (f"支持的文件 ({' '.join(f'*.{s}' for s in _suffixes)});;"
|
|
92
|
+
f"所有文件 (*)")
|
|
93
|
+
else:
|
|
94
|
+
_filter = "所有文件 (*)"
|
|
95
|
+
_cur = self._mwd.text().strip()
|
|
96
|
+
_path, _ = QFileDialog.getOpenFileName(
|
|
97
|
+
self, "选择文件", _cur if os.path.isfile(_cur) else "", _filter)
|
|
98
|
+
if not _path:
|
|
99
|
+
return
|
|
100
|
+
_path = Path(os.path.abspath(_path))
|
|
101
|
+
if not self._match_suffix(_path):
|
|
102
|
+
QPop(QPWarn(
|
|
103
|
+
f"仅支持以下后缀:{', '.join('.' + s for s in _suffixes)}\n{_path}",
|
|
104
|
+
"文件类型不支持", 4000))
|
|
105
|
+
return
|
|
106
|
+
self._path_value_changed(_path)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
__all__ = ["QMonoAttrItemPath"]
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
from __future__ import annotations
|
|
25
25
|
|
|
26
26
|
from datetime import datetime
|
|
27
|
+
from pathlib import Path
|
|
27
28
|
from typing import Any, Dict, List, Tuple
|
|
28
29
|
|
|
29
30
|
from PyQt6.QtGui import QColor
|
|
@@ -36,7 +37,7 @@ from monowidget._utils.rangef import rangef
|
|
|
36
37
|
from monowidget.mono.mono_attr import MonoAttr
|
|
37
38
|
|
|
38
39
|
# 支持自动推断的值类型
|
|
39
|
-
_VALUE_TYPES = (int, float, str, bool, complex, datetime, list, dict)
|
|
40
|
+
_VALUE_TYPES = (int, float, str, bool, complex, datetime, list, dict, Path)
|
|
40
41
|
# 会被收集进 lst(而非 res)的“检视器级”键
|
|
41
42
|
_INSPECTOR_KEYS = ("group", "header", "title", "separator", "space")
|
|
42
43
|
|
|
@@ -264,9 +265,12 @@ class MonoaRuntime:
|
|
|
264
265
|
# 类型推断与转换
|
|
265
266
|
# =====================================================================
|
|
266
267
|
def _infer_type(self, monoa: MonoAttr, res: dict):
|
|
267
|
-
# 用户在 _attrs 中显式给的 type
|
|
268
|
+
# 用户在 _attrs 中显式给的 type:"function"(MonoAttr 对可调用值自动标记)
|
|
269
|
+
# 或已知内置类型。显式标记优先,因为它不受运行时的影响——
|
|
270
|
+
# Nuitka 编译后绑定方法的类名变成 "compiled_method",下面的类名
|
|
271
|
+
# 兜底检查会漏判,显式 "function" 标记则始终可靠。
|
|
268
272
|
explicit = getattr(monoa, "_attrs", {}).get("type")
|
|
269
|
-
if explicit in _VALUE_TYPES:
|
|
273
|
+
if explicit == "function" or explicit in _VALUE_TYPES:
|
|
270
274
|
return explicit
|
|
271
275
|
|
|
272
276
|
# None 值静默退化为 str(旧行为保留)
|
|
@@ -274,14 +278,20 @@ class MonoaRuntime:
|
|
|
274
278
|
monoa.value = ""
|
|
275
279
|
return str
|
|
276
280
|
|
|
277
|
-
#
|
|
281
|
+
# 函数按钮:可调用且非类型(类名兜底,含 Nuitka 编译版的
|
|
282
|
+
# compiled_function/compiled_method)
|
|
278
283
|
if (
|
|
279
284
|
callable(monoa.value)
|
|
280
285
|
and not isinstance(monoa.value, type)
|
|
281
|
-
and monoa.value.__class__.__name__ in (
|
|
286
|
+
and monoa.value.__class__.__name__ in (
|
|
287
|
+
"function", "method", "compiled_function", "compiled_method")
|
|
282
288
|
):
|
|
283
289
|
return "function"
|
|
284
290
|
|
|
291
|
+
# Path 实例:type() 得到的是 WindowsPath/PosixPath 子类,须 isinstance
|
|
292
|
+
if isinstance(monoa.value, Path):
|
|
293
|
+
return Path
|
|
294
|
+
|
|
285
295
|
# 按 value 的 Python 类型
|
|
286
296
|
vt = type(monoa.value)
|
|
287
297
|
if vt in _VALUE_TYPES:
|
|
@@ -333,6 +343,15 @@ class MonoaRuntime:
|
|
|
333
343
|
return
|
|
334
344
|
if _type == bool:
|
|
335
345
|
raise MonoaRuntimeEvalError(self.cmonoa, f"Type '{_type}' is not supported for Enum.")
|
|
346
|
+
if _type is Path:
|
|
347
|
+
# Path 的 enum 是"可选后缀"限定(str),不是候选值;
|
|
348
|
+
# '.'/大小写不敏感的归一化在控件层(QMonoAttrItemPath)处理
|
|
349
|
+
for e in _enum:
|
|
350
|
+
if not isinstance(e, str):
|
|
351
|
+
raise MonoaRuntimeEvalError(
|
|
352
|
+
self.cmonoa, f"Enum of Path must be str suffixes. but got Enum={_enum}"
|
|
353
|
+
)
|
|
354
|
+
return
|
|
336
355
|
# str/complex 值不在 enum 中时,把它插到首位(旧行为)
|
|
337
356
|
if _type in (str, complex) and _value not in _enum:
|
|
338
357
|
_enum.insert(0, _value)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: monowidget
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A modern PyQt6 parameter interface library for creating interactive configuration panels with automatic UI generation.
|
|
5
5
|
Home-page: https://github.com/monowidget/monowidget
|
|
6
6
|
Author: Eagle'sBaby
|
|
@@ -33,6 +33,7 @@ monowidget/inspector/mono_attr_item_float.py
|
|
|
33
33
|
monowidget/inspector/mono_attr_item_function.py
|
|
34
34
|
monowidget/inspector/mono_attr_item_int.py
|
|
35
35
|
monowidget/inspector/mono_attr_item_list.py
|
|
36
|
+
monowidget/inspector/mono_attr_item_path.py
|
|
36
37
|
monowidget/inspector/mono_attr_item_str.py
|
|
37
38
|
monowidget/inspector/mono_group.py
|
|
38
39
|
monowidget/inspector/mono_runtime.py
|
|
@@ -6,7 +6,7 @@ from setuptools import find_packages, setup
|
|
|
6
6
|
|
|
7
7
|
setup(
|
|
8
8
|
name='monowidget',
|
|
9
|
-
version='0.2.
|
|
9
|
+
version='0.2.2',
|
|
10
10
|
description='A modern PyQt6 parameter interface library for creating interactive configuration panels with automatic UI generation.',
|
|
11
11
|
# long_description=open('README.md', encoding='utf-8').read(),
|
|
12
12
|
# long_description_content_type='text/markdown',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|