This commit is contained in:
2026-06-05 06:08:27 +08:00
parent 1816d585bf
commit ef4c1cca32
7 changed files with 551 additions and 168 deletions
+41 -27
View File
@@ -1,24 +1,24 @@
# coding:utf-8
import os
import sys
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
import configparser
from core.main_ui import MainWindow
import config as sdConstants
class ConfigWindow:
def __init__(self, root):
self.root = root
self.root.title("系统配置")
self.root.geometry("500x250")
self.root.geometry("500x300")
self.root.resizable(False, False)
# 居中显示
self.root.withdraw() # 先隐藏窗口
self.root.update_idletasks()
x = (self.root.winfo_screenwidth() // 2) - (500 // 2)
y = (self.root.winfo_screenheight() // 2) - (250 // 2)
self.root.geometry(f"500x250+{x}+{y}")
y = (self.root.winfo_screenheight() // 2) - (300 // 2)
self.root.geometry(f"500x300+{x}+{y}")
self.root.deiconify() # 再显示窗口
self.miniQMTPath = tk.StringVar()
@@ -30,29 +30,38 @@ class ConfigWindow:
# 创建主框架
main_frame = ttk.Frame(self.root, padding="20")
main_frame.pack(fill=tk.BOTH, expand=True)
# miniQMT路径配置
path_frame = ttk.Frame(main_frame)
path_frame.pack(fill=tk.X, pady=5)
path_label = ttk.Label(path_frame, text="miniQMT路径:")
path_label.pack(side=tk.LEFT)
path_entry = ttk.Entry(path_frame, textvariable=self.miniQMTPath, width=40)
path_entry.pack(side=tk.LEFT, padx=(10, 5), fill=tk.X, expand=True)
browse_btn = ttk.Button(path_frame, text="浏览", command=self.browse_folder)
browse_btn.pack(side=tk.LEFT)
# 资金账号配置
account_frame = ttk.Frame(main_frame)
account_frame.pack(fill=tk.X, pady=5)
account_label = ttk.Label(account_frame, text="资金账号:")
account_label.pack(side=tk.LEFT)
account_entry = ttk.Entry(account_frame, textvariable=self.account_no, width=40)
account_entry.pack(side=tk.LEFT, padx=(10, 0))
# 模拟模式复选框
self.use_simulated = tk.BooleanVar(value=False)
simulated_check = ttk.Checkbutton(
main_frame,
text="使用模拟交易模式(无需真实 QMT 连接)",
variable=self.use_simulated
)
simulated_check.pack(fill=tk.X, pady=5)
# 说明文本
info_label = ttk.Label(
@@ -100,6 +109,7 @@ class ConfigWindow:
config['config'] = {
'miniQMTPath': mini_qmt_path.replace('\\', '/'),
'account_no': account_number,
'use_simulated_qmt': str(self.use_simulated.get()),
'log_level': 'INFO'
}
@@ -118,26 +128,29 @@ def check_and_create_config():
config_window = ConfigWindow(root)
root.mainloop()
def ask_mode():
"""询问用户选择模式"""
root = tk.Tk()
root.withdraw() # 隐藏主窗口
result = messagebox.askyesno(
"选择交易模式",
"是否使用模拟交易模式?\n\n" +
"是 → 模拟交易(无需 miniQMT,可在 macOS/Linux 运行)\n" +
"否 → 真实交易(需要 Windows + miniQMT"
)
root.destroy()
return result
def resolve_simulated_mode() -> bool:
"""确定是否使用模拟模式(CLI > 配置文件 > 默认 real"""
if '--simulated' in sys.argv:
print('[配置] 命令行指定: 模拟交易模式')
return True
if sdConstants.exist_config():
sdConstants.initConfig()
if sdConstants.use_simulated_qmt:
print('[配置] 配置文件指定: 模拟交易模式')
return True
print('[配置] 默认: 真实交易模式')
return False
def initialize_system():
"""初始化系统"""
simulated = resolve_simulated_mode()
sdConstants.use_simulated_qmt = simulated
try:
# 询问用户选择模式
if ask_mode():
# 模拟模式
if simulated:
from core.qmt_dummy import qmtv as selected_qmtv
print("[模拟模式] 使用模拟交易器")
sdConstants.miniQMTPath = '/dummy/path'
@@ -145,16 +158,17 @@ def initialize_system():
sdConstants.log_level = 'INFO'
selected_qmtv.init_qmtv()
selected_qmtv.connect()
from core.main_ui import MainWindow
window = MainWindow(sdConstants.log_level)
window.run()
else:
# 真实 QMT 模式
from core.qmt_real import qmtv as selected_qmtv
while True:
if sdConstants.exist_config() and sdConstants.initConfig():
selected_qmtv.init_qmtv()
connected = selected_qmtv.connect()
if connected:
from core.main_ui import MainWindow
window = MainWindow(sdConstants.log_level)
window.run()
break