|
|
import tkinter as tk
|
|
|
import customtkinter as ctk
|
|
|
|
|
|
# 导入拆分的组件
|
|
|
from ui.components.chat_component import ChatComponent
|
|
|
from ui.components.todo_schedule_component import TodoScheduleComponent
|
|
|
from ui.components.settings_component import SettingsComponent
|
|
|
|
|
|
class UIComponents:
|
|
|
def __init__(self, app):
|
|
|
self.app = app
|
|
|
self.root = app.root
|
|
|
self.api = app.api
|
|
|
self.main_frame = None
|
|
|
self.conversation_frame = None
|
|
|
self.conversation_title = None
|
|
|
self.new_conversation_btn = None
|
|
|
self.conversation_listbox = None
|
|
|
self.delete_conversation_btn = None
|
|
|
self.bottom_nav_frame = None
|
|
|
self.chat_nav_btn = None
|
|
|
self.todo_schedule_nav_btn = None
|
|
|
self.settings_nav_btn = None
|
|
|
|
|
|
# 初始化拆分的组件
|
|
|
self.chat_component = None
|
|
|
self.todo_schedule_component = None
|
|
|
self.settings_component = None
|
|
|
|
|
|
def init_ui(self, create_new_conversation_callback, delete_conversation_callback, show_schedules_callback, show_todos_callback, show_logs_callback):
|
|
|
"""初始化UI组件"""
|
|
|
# 创建主容器
|
|
|
self.main_frame = ctk.CTkFrame(self.root, fg_color="#1e1e1e")
|
|
|
self.main_frame.pack(fill="both", expand=True, padx=10, pady=10)
|
|
|
|
|
|
# 左侧对话列表区域
|
|
|
self.conversation_frame = ctk.CTkFrame(self.main_frame, fg_color="#252525", corner_radius=10, width=200)
|
|
|
self.conversation_frame.pack(side="left", fill="y", padx=5, pady=0, ipady=5)
|
|
|
|
|
|
# 对话列表标题
|
|
|
self.conversation_title = ctk.CTkLabel(
|
|
|
self.conversation_frame,
|
|
|
text="对话历史",
|
|
|
font=ctk.CTkFont(family="Microsoft YaHei UI", size=18, weight="bold"),
|
|
|
text_color="#ffffff"
|
|
|
)
|
|
|
self.conversation_title.pack(fill="x", pady=(10, 5), padx=10)
|
|
|
|
|
|
# 新建对话按钮
|
|
|
self.new_conversation_btn = ctk.CTkButton(
|
|
|
self.conversation_frame,
|
|
|
text="新建对话",
|
|
|
command=create_new_conversation_callback,
|
|
|
corner_radius=8,
|
|
|
fg_color="#005a9e",
|
|
|
hover_color="#004a80",
|
|
|
width=180,
|
|
|
height=35,
|
|
|
font=ctk.CTkFont(family="Microsoft YaHei UI", size=14)
|
|
|
)
|
|
|
self.new_conversation_btn.pack(pady=5, padx=10)
|
|
|
|
|
|
# 对话列表
|
|
|
self.conversation_listbox = tk.Listbox(
|
|
|
self.conversation_frame,
|
|
|
bg="#2a2a2a",
|
|
|
fg="#e0e0e0",
|
|
|
borderwidth=2,
|
|
|
highlightthickness=0,
|
|
|
selectbackground="#0078d4",
|
|
|
selectforeground="#ffffff",
|
|
|
font=ctk.CTkFont(family="Microsoft YaHei UI", size=27),
|
|
|
width=25,
|
|
|
height=15,
|
|
|
relief="solid",
|
|
|
bd=0,
|
|
|
activestyle="none"
|
|
|
)
|
|
|
self.conversation_listbox.pack(fill="both", expand=True, padx=10, pady=5)
|
|
|
|
|
|
# 删除对话按钮
|
|
|
self.delete_conversation_btn = ctk.CTkButton(
|
|
|
self.conversation_frame,
|
|
|
text="删除对话",
|
|
|
command=delete_conversation_callback,
|
|
|
corner_radius=8,
|
|
|
fg_color="#E74C3C",
|
|
|
hover_color="#C0392B",
|
|
|
width=180,
|
|
|
height=35,
|
|
|
font=ctk.CTkFont(family="Microsoft YaHei UI", size=14)
|
|
|
)
|
|
|
self.delete_conversation_btn.pack(pady=5, padx=10)
|
|
|
|
|
|
# 4. 右侧导航栏(仅包含三个主按钮)
|
|
|
self.bottom_nav_frame = ctk.CTkFrame(self.main_frame, fg_color="#252525", corner_radius=10, width=150)
|
|
|
self.bottom_nav_frame.pack(side="right", fill="y", padx=(0, 5), pady=10)
|
|
|
|
|
|
# 对话界面按钮
|
|
|
self.chat_nav_btn = ctk.CTkButton(
|
|
|
self.bottom_nav_frame,
|
|
|
text="对话界面",
|
|
|
command=lambda: self._show_tab("chat"),
|
|
|
corner_radius=8,
|
|
|
fg_color="#005a9e",
|
|
|
hover_color="#004a80",
|
|
|
width=130,
|
|
|
height=40,
|
|
|
font=ctk.CTkFont(family="Microsoft YaHei UI", size=14)
|
|
|
)
|
|
|
self.chat_nav_btn.pack(pady=10, padx=10)
|
|
|
|
|
|
# 待办日程按钮
|
|
|
self.todo_schedule_nav_btn = ctk.CTkButton(
|
|
|
self.bottom_nav_frame,
|
|
|
text="待办日程",
|
|
|
command=lambda: self._show_tab("todo_schedule"),
|
|
|
corner_radius=8,
|
|
|
fg_color="#005a9e",
|
|
|
hover_color="#004a80",
|
|
|
width=130,
|
|
|
height=40,
|
|
|
font=ctk.CTkFont(family="Microsoft YaHei UI", size=14)
|
|
|
)
|
|
|
self.todo_schedule_nav_btn.pack(pady=10, padx=10)
|
|
|
|
|
|
# 设置按钮
|
|
|
self.settings_nav_btn = ctk.CTkButton(
|
|
|
self.bottom_nav_frame,
|
|
|
text="设置",
|
|
|
command=lambda: self._show_tab("settings"),
|
|
|
corner_radius=8,
|
|
|
fg_color="#005a9e",
|
|
|
hover_color="#004a80",
|
|
|
width=130,
|
|
|
height=40,
|
|
|
font=ctk.CTkFont(family="Microsoft YaHei UI", size=14)
|
|
|
)
|
|
|
self.settings_nav_btn.pack(pady=10, padx=10)
|
|
|
|
|
|
# 初始化拆分的组件
|
|
|
self.chat_component = ChatComponent(self.main_frame, self.app)
|
|
|
self.todo_schedule_component = TodoScheduleComponent(self.main_frame, self.app)
|
|
|
self.settings_component = SettingsComponent(self.main_frame, self.app, self.api)
|
|
|
|
|
|
# 初始化时显示聊天界面(所有UI元素创建完成后)
|
|
|
self._show_tab("chat")
|
|
|
|
|
|
def bind_events(self, send_message_callback, clear_chat_callback, on_model_change_callback, insert_newline_callback):
|
|
|
"""绑定事件"""
|
|
|
self.chat_component.bind_events(send_message_callback, clear_chat_callback, on_model_change_callback, insert_newline_callback)
|
|
|
|
|
|
def get_conversation_listbox(self):
|
|
|
"""获取对话列表框"""
|
|
|
return self.conversation_listbox
|
|
|
|
|
|
def get_chat_scrollable_frame(self):
|
|
|
"""获取聊天滚动区域"""
|
|
|
return self.chat_component.get_chat_scrollable_frame()
|
|
|
|
|
|
def get_user_input(self):
|
|
|
"""获取用户输入框"""
|
|
|
return self.chat_component.get_user_input()
|
|
|
|
|
|
def get_model_var(self):
|
|
|
"""获取模型选择变量"""
|
|
|
return self.chat_component.get_model_var()
|
|
|
|
|
|
def get_model_combo(self):
|
|
|
"""获取模型选择下拉框"""
|
|
|
return self.chat_component.get_model_combo()
|
|
|
|
|
|
def _show_tab(self, tab_name):
|
|
|
"""显示指定标签页"""
|
|
|
# 切换按钮样式
|
|
|
for btn in [self.chat_nav_btn, self.todo_schedule_nav_btn, self.settings_nav_btn]:
|
|
|
btn.configure(fg_color="#757575", hover_color="#616161")
|
|
|
|
|
|
if tab_name == "chat":
|
|
|
self.chat_nav_btn.configure(fg_color="#005a9e", hover_color="#004a80")
|
|
|
self.conversation_frame.pack(side="left", fill="y", padx=5, pady=0, ipady=5)
|
|
|
self.chat_component.show()
|
|
|
self.todo_schedule_component.hide()
|
|
|
self.settings_component.hide()
|
|
|
elif tab_name == "todo_schedule":
|
|
|
self.todo_schedule_nav_btn.configure(fg_color="#005a9e", hover_color="#004a80")
|
|
|
self.conversation_frame.pack_forget()
|
|
|
self.chat_component.hide()
|
|
|
self.todo_schedule_component.show()
|
|
|
self.settings_component.hide()
|
|
|
elif tab_name == "settings":
|
|
|
self.settings_nav_btn.configure(fg_color="#005a9e", hover_color="#004a80")
|
|
|
self.conversation_frame.pack_forget()
|
|
|
self.chat_component.hide()
|
|
|
self.todo_schedule_component.hide()
|
|
|
self.settings_component.show()
|
|
|
|
|
|
|