simpleui-py 1.2.1__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.
Files changed (26) hide show
  1. {simpleui_py-1.2.1/simpleui_py.egg-info → simpleui_py-1.2.2}/PKG-INFO +1 -1
  2. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/pyproject.toml +1 -1
  3. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/__init__.py +1 -1
  4. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/utils.py +47 -28
  5. {simpleui_py-1.2.1 → simpleui_py-1.2.2/simpleui_py.egg-info}/PKG-INFO +1 -1
  6. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/LICENSE +0 -0
  7. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/MANIFEST.in +0 -0
  8. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/README.md +0 -0
  9. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/setup.cfg +0 -0
  10. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/components/__init__.py +0 -0
  11. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/components/alert.py +0 -0
  12. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/components/button.py +0 -0
  13. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/components/card.py +0 -0
  14. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/components/input.py +0 -0
  15. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/components/layout.py +0 -0
  16. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/components/progress.py +0 -0
  17. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/components/switch.py +0 -0
  18. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/components/tag.py +0 -0
  19. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/components/window.py +0 -0
  20. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/core.py +0 -0
  21. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui/py.typed +0 -0
  22. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui_py.egg-info/SOURCES.txt +0 -0
  23. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui_py.egg-info/dependency_links.txt +0 -0
  24. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui_py.egg-info/entry_points.txt +0 -0
  25. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui_py.egg-info/requires.txt +0 -0
  26. {simpleui_py-1.2.1 → simpleui_py-1.2.2}/simpleui_py.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simpleui-py
3
- Version: 1.2.1
3
+ Version: 1.2.2
4
4
  Summary: Fluent风格Python UI组件库 - 简约设计,无限可能
5
5
  Author-email: SimpleUI Team <hello@simpleui.dev>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "simpleui-py"
7
- version = "1.2.1"
7
+ version = "1.2.2"
8
8
  description = "Fluent风格Python UI组件库 - 简约设计,无限可能"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -3,7 +3,7 @@ SimpleUI - Fluent 风格 Python UI 组件库
3
3
  简约设计,无限可能
4
4
  """
5
5
 
6
- __version__ = "1.2.1"
6
+ __version__ = "1.2.2"
7
7
  __author__ = "SimpleUI Team"
8
8
 
9
9
  # 从 core 导入核心功能
@@ -4,7 +4,7 @@ SimpleUI 工具模块
4
4
 
5
5
  import os
6
6
  import tempfile
7
- import webbrowser
7
+ import subprocess
8
8
  import platform
9
9
  from typing import Optional
10
10
 
@@ -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,6 +26,7 @@ def preview(
25
26
  title: 页面标题
26
27
  theme: 主题配置
27
28
  open_browser: 是否自动打开浏览器
29
+ browser: 指定浏览器
28
30
 
29
31
  返回:
30
32
  临时HTML文件路径
@@ -42,24 +44,36 @@ def preview(
42
44
  filepath = f.name
43
45
 
44
46
  if open_browser:
45
- # 修复 Windows 路径问题
46
- if platform.system() == "Windows":
47
- # Windows 使用绝对路径
48
- file_url = f"file:///{filepath.replace(os.sep, '/')}"
49
- else:
50
- # macOS/Linux
51
- file_url = f"file://{filepath}"
52
-
53
- # 尝试打开浏览器
54
- try:
55
- webbrowser.open(file_url)
56
- except Exception:
57
- # 如果失败,打印路径让用户手动打开
58
- print(f"请手动打开: {filepath}")
47
+ _open_file(filepath, browser)
59
48
 
60
49
  return filepath
61
50
 
62
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
+
63
77
  def serve(
64
78
  *components: Component,
65
79
  title: str = "SimpleUI App",
@@ -67,6 +81,7 @@ def serve(
67
81
  host: str = "localhost",
68
82
  port: int = 8080,
69
83
  open_browser: bool = True,
84
+ browser: Optional[str] = None,
70
85
  ) -> None:
71
86
  """
72
87
  启动本地服务器预览组件
@@ -81,34 +96,25 @@ def serve(
81
96
 
82
97
  html = render_html(*components, title=title, theme=theme)
83
98
 
84
- # 创建临时目录
85
99
  temp_dir = tempfile.mkdtemp()
86
100
  filepath = os.path.join(temp_dir, "index.html")
87
101
 
88
102
  with open(filepath, "w", encoding="utf-8") as f:
89
103
  f.write(html)
90
104
 
91
- # 切换到临时目录
92
105
  original_dir = os.getcwd()
93
106
  os.chdir(temp_dir)
94
107
 
95
- # 创建服务器
96
108
  server = HTTPServer((host, port), SimpleHTTPRequestHandler)
97
-
98
- # 在线程中启动服务器
99
109
  server_thread = threading.Thread(target=server.serve_forever, daemon=True)
100
110
  server_thread.start()
101
111
 
102
- # 打开浏览器
103
112
  if open_browser:
104
113
  time.sleep(0.5)
105
114
  url = f"http://{host}:{port}"
106
- try:
107
- webbrowser.open(url)
108
- except Exception:
109
- print(f"请手动打开: {url}")
115
+ _open_url(url, browser)
110
116
 
111
- print(f"服务器已启动: http://{host}:{port}")
117
+ print(f"服务器已启动: {url}")
112
118
  print("按 Ctrl+C 停止服务器")
113
119
 
114
120
  try:
@@ -120,6 +126,21 @@ def serve(
120
126
  os.chdir(original_dir)
121
127
 
122
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
+
123
144
  def demo() -> str:
124
145
  """运行演示"""
125
146
  from .components import (
@@ -133,7 +154,6 @@ def demo() -> str:
133
154
  btn_row = Row()
134
155
  btn_row.add_child(Button("主要按钮", variant="primary"))
135
156
  btn_row.add_child(Button("次要按钮", variant="secondary"))
136
- btn_row.add_child(Button("危险按钮", variant="danger"))
137
157
  container.add_child(btn_row)
138
158
 
139
159
  container.add_child(Input(label="用户名", placeholder="请输入用户名"))
@@ -142,7 +162,6 @@ def demo() -> str:
142
162
 
143
163
  tag_row = Row()
144
164
  tag_row.add_child(Tag("Python", variant="primary"))
145
- tag_row.add_child(Tag("UI", variant="success"))
146
165
  container.add_child(tag_row)
147
166
 
148
167
  container.add_child(Progress(value=75, label="下载进度"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simpleui-py
3
- Version: 1.2.1
3
+ Version: 1.2.2
4
4
  Summary: Fluent风格Python UI组件库 - 简约设计,无限可能
5
5
  Author-email: SimpleUI Team <hello@simpleui.dev>
6
6
  License: MIT
File without changes
File without changes
File without changes
File without changes