simpleui-py 1.2.0__tar.gz → 1.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.
- {simpleui_py-1.2.0/simpleui_py.egg-info → simpleui_py-1.2.2}/PKG-INFO +1 -1
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/pyproject.toml +1 -1
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/__init__.py +1 -1
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/utils.py +53 -62
- {simpleui_py-1.2.0 → simpleui_py-1.2.2/simpleui_py.egg-info}/PKG-INFO +1 -1
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/LICENSE +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/MANIFEST.in +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/README.md +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/setup.cfg +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/components/__init__.py +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/components/alert.py +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/components/button.py +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/components/card.py +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/components/input.py +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/components/layout.py +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/components/progress.py +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/components/switch.py +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/components/tag.py +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/components/window.py +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/core.py +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui/py.typed +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui_py.egg-info/SOURCES.txt +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui_py.egg-info/dependency_links.txt +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui_py.egg-info/entry_points.txt +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui_py.egg-info/requires.txt +0 -0
- {simpleui_py-1.2.0 → simpleui_py-1.2.2}/simpleui_py.egg-info/top_level.txt +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"""
|
|
2
2
|
SimpleUI 工具模块
|
|
3
|
-
提供预览、服务、演示等功能
|
|
4
3
|
"""
|
|
5
4
|
|
|
6
5
|
import os
|
|
7
6
|
import tempfile
|
|
8
|
-
import
|
|
7
|
+
import subprocess
|
|
8
|
+
import platform
|
|
9
9
|
from typing import Optional
|
|
10
10
|
|
|
11
11
|
from .core import Component, Theme, render_html
|
|
@@ -16,6 +16,7 @@ def preview(
|
|
|
16
16
|
title: str = "SimpleUI Preview",
|
|
17
17
|
theme: Optional[Theme] = None,
|
|
18
18
|
open_browser: bool = True,
|
|
19
|
+
browser: Optional[str] = None,
|
|
19
20
|
) -> str:
|
|
20
21
|
"""
|
|
21
22
|
在浏览器中预览组件
|
|
@@ -25,12 +26,10 @@ def preview(
|
|
|
25
26
|
title: 页面标题
|
|
26
27
|
theme: 主题配置
|
|
27
28
|
open_browser: 是否自动打开浏览器
|
|
29
|
+
browser: 指定浏览器
|
|
28
30
|
|
|
29
31
|
返回:
|
|
30
32
|
临时HTML文件路径
|
|
31
|
-
|
|
32
|
-
示例:
|
|
33
|
-
preview(Button("点击我"), Card(title="卡片"))
|
|
34
33
|
"""
|
|
35
34
|
html = render_html(*components, title=title, theme=theme)
|
|
36
35
|
|
|
@@ -45,11 +44,36 @@ def preview(
|
|
|
45
44
|
filepath = f.name
|
|
46
45
|
|
|
47
46
|
if open_browser:
|
|
48
|
-
|
|
47
|
+
_open_file(filepath, browser)
|
|
49
48
|
|
|
50
49
|
return filepath
|
|
51
50
|
|
|
52
51
|
|
|
52
|
+
def _open_file(filepath: str, browser: Optional[str] = None):
|
|
53
|
+
"""
|
|
54
|
+
使用默认浏览器打开文件
|
|
55
|
+
|
|
56
|
+
参数:
|
|
57
|
+
filepath: 文件路径
|
|
58
|
+
browser: 指定浏览器
|
|
59
|
+
"""
|
|
60
|
+
system = platform.system()
|
|
61
|
+
|
|
62
|
+
if browser:
|
|
63
|
+
# 使用指定浏览器
|
|
64
|
+
import webbrowser
|
|
65
|
+
webbrowser.get(browser).open(filepath)
|
|
66
|
+
elif system == "Windows":
|
|
67
|
+
# Windows 使用 start 命令打开默认浏览器
|
|
68
|
+
os.startfile(filepath)
|
|
69
|
+
elif system == "Darwin":
|
|
70
|
+
# macOS 使用 open 命令
|
|
71
|
+
subprocess.run(["open", filepath])
|
|
72
|
+
else:
|
|
73
|
+
# Linux 使用 xdg-open
|
|
74
|
+
subprocess.run(["xdg-open", filepath])
|
|
75
|
+
|
|
76
|
+
|
|
53
77
|
def serve(
|
|
54
78
|
*components: Component,
|
|
55
79
|
title: str = "SimpleUI App",
|
|
@@ -57,17 +81,10 @@ def serve(
|
|
|
57
81
|
host: str = "localhost",
|
|
58
82
|
port: int = 8080,
|
|
59
83
|
open_browser: bool = True,
|
|
84
|
+
browser: Optional[str] = None,
|
|
60
85
|
) -> None:
|
|
61
86
|
"""
|
|
62
87
|
启动本地服务器预览组件
|
|
63
|
-
|
|
64
|
-
参数:
|
|
65
|
-
*components: 要预览的组件
|
|
66
|
-
title: 页面标题
|
|
67
|
-
theme: 主题配置
|
|
68
|
-
host: 主机地址
|
|
69
|
-
port: 端口号
|
|
70
|
-
open_browser: 是否自动打开浏览器
|
|
71
88
|
"""
|
|
72
89
|
try:
|
|
73
90
|
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
@@ -79,30 +96,25 @@ def serve(
|
|
|
79
96
|
|
|
80
97
|
html = render_html(*components, title=title, theme=theme)
|
|
81
98
|
|
|
82
|
-
# 创建临时目录
|
|
83
99
|
temp_dir = tempfile.mkdtemp()
|
|
84
100
|
filepath = os.path.join(temp_dir, "index.html")
|
|
85
101
|
|
|
86
102
|
with open(filepath, "w", encoding="utf-8") as f:
|
|
87
103
|
f.write(html)
|
|
88
104
|
|
|
89
|
-
# 切换到临时目录
|
|
90
105
|
original_dir = os.getcwd()
|
|
91
106
|
os.chdir(temp_dir)
|
|
92
107
|
|
|
93
|
-
# 创建服务器
|
|
94
108
|
server = HTTPServer((host, port), SimpleHTTPRequestHandler)
|
|
95
|
-
|
|
96
|
-
# 在线程中启动服务器
|
|
97
109
|
server_thread = threading.Thread(target=server.serve_forever, daemon=True)
|
|
98
110
|
server_thread.start()
|
|
99
111
|
|
|
100
|
-
# 打开浏览器
|
|
101
112
|
if open_browser:
|
|
102
113
|
time.sleep(0.5)
|
|
103
|
-
|
|
114
|
+
url = f"http://{host}:{port}"
|
|
115
|
+
_open_url(url, browser)
|
|
104
116
|
|
|
105
|
-
print(f"服务器已启动:
|
|
117
|
+
print(f"服务器已启动: {url}")
|
|
106
118
|
print("按 Ctrl+C 停止服务器")
|
|
107
119
|
|
|
108
120
|
try:
|
|
@@ -114,71 +126,50 @@ def serve(
|
|
|
114
126
|
os.chdir(original_dir)
|
|
115
127
|
|
|
116
128
|
|
|
129
|
+
def _open_url(url: str, browser: Optional[str] = None):
|
|
130
|
+
"""打开URL"""
|
|
131
|
+
system = platform.system()
|
|
132
|
+
|
|
133
|
+
if browser:
|
|
134
|
+
import webbrowser
|
|
135
|
+
webbrowser.get(browser).open(url)
|
|
136
|
+
elif system == "Windows":
|
|
137
|
+
os.system(f'start "" "{url}"')
|
|
138
|
+
elif system == "Darwin":
|
|
139
|
+
subprocess.run(["open", url])
|
|
140
|
+
else:
|
|
141
|
+
subprocess.run(["xdg-open", url])
|
|
142
|
+
|
|
143
|
+
|
|
117
144
|
def demo() -> str:
|
|
118
|
-
"""
|
|
119
|
-
运行演示程序
|
|
120
|
-
|
|
121
|
-
返回:
|
|
122
|
-
预览文件路径
|
|
123
|
-
"""
|
|
145
|
+
"""运行演示"""
|
|
124
146
|
from .components import (
|
|
125
147
|
Button, Input, Card, Switch, Tag, Progress, Alert,
|
|
126
148
|
Container, Row
|
|
127
149
|
)
|
|
128
150
|
|
|
129
|
-
# 创建容器
|
|
130
151
|
container = Container()
|
|
152
|
+
container.add_child("<h1 style='text-align:center;margin-bottom:2rem;color:var(--text-primary)'>SimpleUI 组件演示</h1>")
|
|
131
153
|
|
|
132
|
-
# 标题
|
|
133
|
-
container.add_child(
|
|
134
|
-
"<h1 style='text-align:center;margin-bottom:2rem;color:var(--text-primary)'>"
|
|
135
|
-
"SimpleUI 组件演示"
|
|
136
|
-
"</h1>"
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
# 按钮演示
|
|
140
154
|
btn_row = Row()
|
|
141
155
|
btn_row.add_child(Button("主要按钮", variant="primary"))
|
|
142
156
|
btn_row.add_child(Button("次要按钮", variant="secondary"))
|
|
143
|
-
btn_row.add_child(Button("轮廓按钮", variant="outline"))
|
|
144
|
-
btn_row.add_child(Button("危险按钮", variant="danger"))
|
|
145
|
-
btn_row.add_child(Button("成功按钮", variant="success"))
|
|
146
157
|
container.add_child(btn_row)
|
|
147
158
|
|
|
148
|
-
# 输入框演示
|
|
149
159
|
container.add_child(Input(label="用户名", placeholder="请输入用户名"))
|
|
150
|
-
container.add_child(
|
|
151
|
-
|
|
152
|
-
# 卡片演示
|
|
153
|
-
container.add_child(Card(
|
|
154
|
-
title="示例卡片",
|
|
155
|
-
text="这是一个示例卡片组件",
|
|
156
|
-
image="var(--gradient-1)"
|
|
157
|
-
))
|
|
158
|
-
|
|
159
|
-
# 开关演示
|
|
160
|
+
container.add_child(Card(title="示例卡片", text="这是一个示例卡片", image="var(--gradient-1)"))
|
|
160
161
|
container.add_child(Switch("启用功能", checked=True))
|
|
161
162
|
|
|
162
|
-
# 标签演示
|
|
163
163
|
tag_row = Row()
|
|
164
164
|
tag_row.add_child(Tag("Python", variant="primary"))
|
|
165
|
-
tag_row.add_child(Tag("UI", variant="success"))
|
|
166
165
|
container.add_child(tag_row)
|
|
167
166
|
|
|
168
|
-
# 进度条演示
|
|
169
167
|
container.add_child(Progress(value=75, label="下载进度"))
|
|
170
|
-
|
|
171
|
-
# 提示演示
|
|
172
168
|
container.add_child(Alert.success("成功", "欢迎使用 SimpleUI!"))
|
|
173
169
|
|
|
174
170
|
return preview(container, title="SimpleUI 组件演示")
|
|
175
171
|
|
|
176
172
|
|
|
177
173
|
def playground() -> str:
|
|
178
|
-
"""
|
|
179
|
-
打开交互式组件游乐场
|
|
180
|
-
|
|
181
|
-
返回:
|
|
182
|
-
预览文件路径
|
|
183
|
-
"""
|
|
174
|
+
"""打开交互式组件游乐场"""
|
|
184
175
|
return demo()
|
|
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
|