update
This commit is contained in:
+17
-148
@@ -27,14 +27,12 @@ class MainWindow:
|
||||
|
||||
self.logLevel = LogLevel[configLogLevel]
|
||||
PrintLog(LogLevel.DEBUG, f"系统启动成功 {self.logLevel.name}")
|
||||
# 当前选中的策略Tab索引
|
||||
self.current_strategy_index = 0
|
||||
# 存储各个Frame的引用
|
||||
self.strategy_frames = {}
|
||||
# 日志面板可见性标志
|
||||
self.log_visible = False
|
||||
self.create_ui()
|
||||
|
||||
|
||||
eBus.subscribe(EventPrintLog, self.on_log_event)
|
||||
|
||||
|
||||
@@ -43,113 +41,24 @@ class MainWindow:
|
||||
# 主容器
|
||||
main_container = ttk.Frame(self.root)
|
||||
main_container.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
|
||||
|
||||
# 中间主体区域(左右布局)
|
||||
|
||||
# 中间主体区域
|
||||
content_area = ttk.Frame(main_container)
|
||||
content_area.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
# 左侧Tab按钮栏(垂直排列)
|
||||
tab_bar_frame = ttk.Frame(content_area)
|
||||
tab_bar_frame.pack(side=tk.LEFT, fill=tk.Y, padx=(0, 10))
|
||||
|
||||
# 创建自定义样式
|
||||
self.create_custom_styles()
|
||||
|
||||
# 创建Tab按钮(垂直排列,文字垂直显示)
|
||||
self.tab_buttons = []
|
||||
strategy_names = ["网格", "复盘"]
|
||||
|
||||
for idx, name in enumerate(strategy_names):
|
||||
btn = ttk.Button(
|
||||
tab_bar_frame,
|
||||
text=name,
|
||||
command=lambda i=idx: self.switch_strategy_tab(i),
|
||||
width=4,
|
||||
style='Bookmark.TButton' # 使用自定义书签样式
|
||||
)
|
||||
btn.pack(side=tk.TOP, pady=2, fill=tk.X)
|
||||
self.tab_buttons.append(btn)
|
||||
|
||||
# 在Tab按钮下方添加退出按钮和日志按钮(底部对齐)
|
||||
# 使用一个填充Frame将按钮推到底部
|
||||
spacer = ttk.Frame(tab_bar_frame)
|
||||
spacer.pack(side=tk.TOP, fill=tk.X, ipady=10)
|
||||
|
||||
# 清空日志按钮(底部第三个)
|
||||
clear_log_btn = ttk.Button(
|
||||
tab_bar_frame,
|
||||
text="🗑", # 垃圾桶图标
|
||||
command=self.clear_logs,
|
||||
width=3
|
||||
)
|
||||
clear_log_btn.pack(side=tk.TOP, pady=2, fill=tk.X)
|
||||
|
||||
# 日志显示按钮(退出按钮上方)
|
||||
self.log_toggle_btn = ttk.Button(
|
||||
tab_bar_frame,
|
||||
text="📋", # 日志图标
|
||||
command=self.toggle_log_panel,
|
||||
width=3
|
||||
)
|
||||
self.log_toggle_btn.pack(side=tk.TOP, pady=2, fill=tk.X)
|
||||
|
||||
# 退出按钮(最底部)
|
||||
exit_btn = ttk.Button(
|
||||
tab_bar_frame,
|
||||
text="⏻", # 电源图标
|
||||
command=self.on_exit,
|
||||
width=3
|
||||
)
|
||||
exit_btn.pack(side=tk.TOP, pady=2, fill=tk.X)
|
||||
|
||||
# 添加垂直分隔线
|
||||
separator = ttk.Separator(content_area, orient='vertical')
|
||||
separator.pack(side=tk.LEFT, fill=tk.Y, padx=1)
|
||||
|
||||
# 右侧内容区域容器(用于放置不同策略的Frame)
|
||||
|
||||
# 右侧内容区域容器
|
||||
self.content_container = ttk.Frame(content_area)
|
||||
self.content_container.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
||||
|
||||
# 创建各个策略的Frame
|
||||
|
||||
# 创建策略Frame
|
||||
strategy_names = ["网格"]
|
||||
self.create_strategy_frames(strategy_names)
|
||||
|
||||
|
||||
# 创建全局日志面板(默认隐藏)
|
||||
self.create_global_log_panel(main_container)
|
||||
|
||||
|
||||
# 默认显示第一个策略
|
||||
self.switch_strategy_tab(0)
|
||||
|
||||
def create_custom_styles(self):
|
||||
"""创建自定义样式"""
|
||||
style = ttk.Style()
|
||||
|
||||
# 创建书签样式
|
||||
style.configure(
|
||||
'Bookmark.TButton',
|
||||
relief='flat',
|
||||
borderwidth=1,
|
||||
padding=(5, 10),
|
||||
foreground='black',
|
||||
background='#FFE599', # 浅黄色背景,类似便签纸
|
||||
font=('Arial', 10, 'bold')
|
||||
)
|
||||
|
||||
# 设置焦点样式(选中状态)
|
||||
style.map(
|
||||
'Bookmark.TButton',
|
||||
background=[('active', '#F1C232'), ('pressed', '#F1C232')],
|
||||
relief=[('pressed', 'sunken')]
|
||||
)
|
||||
|
||||
# 创建选中状态的书签样式
|
||||
style.configure(
|
||||
'SelectedBookmark.TButton',
|
||||
relief='flat',
|
||||
borderwidth=1,
|
||||
padding=(5, 10),
|
||||
background='#3D85C6', # 蓝色背景表示选中状态
|
||||
font=('Arial', 10, 'bold')
|
||||
)
|
||||
self.show_strategy_frame(0)
|
||||
|
||||
def create_global_log_panel(self, parent):
|
||||
"""创建全局日志面板"""
|
||||
@@ -204,62 +113,22 @@ class MainWindow:
|
||||
|
||||
def create_strategy_frames(self, strategy_names):
|
||||
"""创建各个策略的Frame"""
|
||||
for idx, name in enumerate(strategy_names):
|
||||
if idx == 0:
|
||||
# 第一个Tab使用TradeTargetUI,传入main_window引用
|
||||
frame = TradeTargetUI(self.content_container)
|
||||
self.strategy_frames[idx] = frame
|
||||
else:
|
||||
# 其他策略使用占位Frame
|
||||
frame = ttk.Frame(self.content_container)
|
||||
self.strategy_frames[idx] = frame
|
||||
|
||||
# 添加占位内容
|
||||
placeholder = ttk.Label(
|
||||
frame,
|
||||
text=f"{name} - 策略界面将在此实现",
|
||||
font=('Arial', 14),
|
||||
foreground='gray'
|
||||
)
|
||||
placeholder.pack(expand=True)
|
||||
|
||||
def switch_strategy_tab(self, index):
|
||||
"""切换策略Tab"""
|
||||
# 隐藏当前Frame
|
||||
if self.current_strategy_index in self.strategy_frames:
|
||||
self.strategy_frames[self.current_strategy_index].pack_forget()
|
||||
|
||||
# 更新当前索引
|
||||
self.current_strategy_index = index
|
||||
|
||||
# 显示选中的Frame
|
||||
frame = TradeTargetUI(self.content_container)
|
||||
self.strategy_frames[0] = frame
|
||||
|
||||
def show_strategy_frame(self, index):
|
||||
"""显示策略Frame"""
|
||||
if index in self.strategy_frames:
|
||||
self.strategy_frames[index].pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
# 更新Tab按钮样式(可选,用于视觉反馈)
|
||||
self.update_tab_button_styles()
|
||||
|
||||
def update_tab_button_styles(self):
|
||||
"""更新Tab按钮的样式以显示选中状态"""
|
||||
# 重置所有按钮为普通书签样式
|
||||
for i, btn in enumerate(self.tab_buttons):
|
||||
if i == self.current_strategy_index:
|
||||
btn.configure(style='SelectedBookmark.TButton') # 选中状态
|
||||
else:
|
||||
btn.configure(style='Bookmark.TButton') # 普通状态
|
||||
|
||||
|
||||
def toggle_log_panel(self):
|
||||
"""切换日志面板的显示/隐藏"""
|
||||
if self.log_visible:
|
||||
# 隐藏日志面板
|
||||
self.log_frame.pack_forget()
|
||||
self.log_visible = False
|
||||
self.log_toggle_btn.config(text="📋") # 日志图标
|
||||
else:
|
||||
# 显示日志面板
|
||||
self.log_frame.pack(side=tk.BOTTOM, fill=tk.X, pady=(5, 0))
|
||||
self.log_visible = True
|
||||
self.log_toggle_btn.config(text="🔽") # 使用不同图标表示隐藏
|
||||
|
||||
def on_exit(self):
|
||||
"""退出程序"""
|
||||
|
||||
Reference in New Issue
Block a user