-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
110 lines (92 loc) · 3.4 KB
/
app.py
File metadata and controls
110 lines (92 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import tkinter as tk
import importlib
import sys
import argparse
from tkinter import ttk
import pywinstyles
import webview
from typing import Any, Tuple
# 创建选择窗口
class UISelector(tk.Tk):
def __init__(self):
super().__init__()
self.title("选择UI框架")
self.geometry("300x185")
pywinstyles.apply_style(self, "mica")
self.selection = None
for ui_type in ['Tkinter', 'PySide6', 'wxPython', 'Flet', 'NiceGUI']:
ttk.Button(self, text=ui_type, command=lambda t=ui_type.lower(): self.select(t)).pack(pady=5)
def select(self, ui_type: str) -> None:
self.selection = ui_type
self.destroy()
# 动态导入UI模块
def load_ui_module(ui_type: str) -> Tuple[Any, Any]:
try:
if ui_type == 'pyside6':
from PySide6.QtWidgets import QApplication
return importlib.import_module('ui.pyside6_main_window'), QApplication
elif ui_type == 'wx':
import wx
return importlib.import_module('ui.wx_main_window'), wx.App
elif ui_type == 'nicegui':
from nicegui import ui
return importlib.import_module('ui.nicegui_main_window'), ui
elif ui_type == 'flet':
import flet as ft
return importlib.import_module('ui.flet_main_window'), ft.app
else: # Default to Tkinter
import tkinter as tk
return importlib.import_module('ui.main_window'), tk.Tk
except ImportError as e:
print(f"错误:未找到 {ui_type} 库,请先安装。详细信息:{e}")
sys.exit(1)
# 启动应用
def run_application(ui_type: str, ui_module: Any, app_class: Any) -> None:
if ui_type == 'pyside6':
app = app_class(sys.argv)
window = ui_module.App()
window.show()
sys.exit(app.exec())
elif ui_type == 'wx':
app = app_class(False)
window = ui_module.App()
app.MainLoop()
elif ui_type == 'nicegui':
from nicegui import ui
@ui.page('/')
def main_page():
window = ui_module.App()
ui.add_body_html('<script>window.resizeTo(800, 600)</script>')
def start_nicegui():
ui.run(port=8080, show=False, reload=False, title="PyJMeter")
import threading
server_thread = threading.Thread(target=start_nicegui, daemon=True)
server_thread.start()
import time
time.sleep(1)
webview.create_window("PyJMeter", "http://localhost:8080", width=800, height=600)
webview.start()
elif ui_type == 'flet':
app_class(target=lambda page: ui_module.App(page))
else: # Tkinter
root = app_class()
app = ui_module.App(root)
root.mainloop()
# 主程序入口
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='JMeter JMX Parser')
parser.add_argument('--ui', type=str, default=None,
choices=['tk', 'pyside6', 'wx', 'nicegui', 'flet'],
help='选择UI类型 (tk, pyside6, wx, nicegui, flet)')
args = parser.parse_args()
if args.ui:
ui_type = args.ui
else:
selector = UISelector()
selector.mainloop()
ui_type = selector.selection
if not ui_type:
print("错误:未选择任何UI框架。")
sys.exit(1)
ui_module, app_class = load_ui_module(ui_type)
run_application(ui_type, ui_module, app_class)