feat: add Tkinter GUI application for ERP automation tools
Implement a comprehensive GUI application with the following features: - Data Extraction tab: Extract material plan data from ERP system - Material Validation tab: Validate material status and match deletions - Data Query tab: Query database for production order information - Settings tab: Manage ERP, database, browser, and path configurations Key components: - MainWindow: Tabbed interface with status bar - ConfigManager: JSON-based configuration management - LogText: Custom read-only text widget with colored logging - FileSelector: Reusable file/directory selection component - ProgressDialog: Modal progress dialog for long operations Technical details: - Thread-safe UI updates using root.after() - Stdout capture for legacy script integration - Event-based readonly mode allowing copy/select operations - Custom widget composition to avoid Tkinter ScrolledText issues Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
125
gui/main_window.py
Normal file
125
gui/main_window.py
Normal file
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
主窗口
|
||||
|
||||
ERP 自动化工具的主窗口,包含多个功能标签页。
|
||||
"""
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from gui.config_manager import ConfigManager
|
||||
from gui.data_extraction_tab import DataExtractionTab
|
||||
from gui.material_validation_tab import MaterialValidationTab
|
||||
from gui.data_query_tab import DataQueryTab
|
||||
from gui.settings_tab import SettingsTab
|
||||
|
||||
|
||||
class MainWindow:
|
||||
"""主窗口类"""
|
||||
|
||||
def __init__(self, root: tk.Tk):
|
||||
"""
|
||||
初始化主窗口
|
||||
|
||||
Args:
|
||||
root: Tk 根窗口
|
||||
"""
|
||||
self.root = root
|
||||
self.config = ConfigManager()
|
||||
|
||||
# 设置窗口属性
|
||||
self.root.title("ERP 自动化工具 v1.0")
|
||||
self.root.geometry("1000x700")
|
||||
|
||||
# 设置最小窗口大小
|
||||
self.root.minsize(800, 600)
|
||||
|
||||
# 创建菜单栏
|
||||
self.create_menu()
|
||||
|
||||
# 创建主界面
|
||||
self.create_widgets()
|
||||
|
||||
# 创建状态栏
|
||||
self.create_status_bar()
|
||||
|
||||
# 居中窗口
|
||||
self._center_window()
|
||||
|
||||
def create_menu(self):
|
||||
"""创建菜单栏"""
|
||||
menubar = tk.Menu(self.root)
|
||||
self.root.config(menu=menubar)
|
||||
|
||||
# 文件菜单
|
||||
file_menu = tk.Menu(menubar, tearoff=0)
|
||||
menubar.add_cascade(label="文件", menu=file_menu)
|
||||
file_menu.add_command(label="退出", command=self.root.quit)
|
||||
|
||||
# 帮助菜单
|
||||
help_menu = tk.Menu(menubar, tearoff=0)
|
||||
menubar.add_cascade(label="帮助", menu=help_menu)
|
||||
help_menu.add_command(label="关于", command=self.show_about)
|
||||
|
||||
def create_widgets(self):
|
||||
"""创建主界面组件"""
|
||||
# 创建 Notebook(标签页容器)
|
||||
self.notebook = ttk.Notebook(self.root)
|
||||
self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
||||
|
||||
# 数据提取标签页
|
||||
self.extraction_tab = DataExtractionTab(self.notebook, self.config)
|
||||
self.notebook.add(self.extraction_tab, text="数据提取")
|
||||
|
||||
# 物料校验标签页
|
||||
self.validation_tab = MaterialValidationTab(self.notebook, self.config)
|
||||
self.notebook.add(self.validation_tab, text="物料校验")
|
||||
|
||||
# 数据查询标签页
|
||||
self.query_tab = DataQueryTab(self.notebook, self.config)
|
||||
self.notebook.add(self.query_tab, text="数据查询")
|
||||
|
||||
# 设置标签页
|
||||
self.settings_tab = SettingsTab(self.notebook, self.config)
|
||||
self.notebook.add(self.settings_tab, text="设置")
|
||||
|
||||
def create_status_bar(self):
|
||||
"""创建状态栏"""
|
||||
self.status_bar = ttk.Frame(self.root, relief=tk.SUNKEN)
|
||||
self.status_bar.pack(side=tk.BOTTOM, fill=tk.X)
|
||||
|
||||
# 状态文本
|
||||
self.status_text = tk.StringVar()
|
||||
self.status_text.set("就绪")
|
||||
status_label = ttk.Label(self.status_bar, textvariable=self.status_text, anchor=tk.W)
|
||||
status_label.pack(side=tk.LEFT, padx=5)
|
||||
|
||||
# 配置状态指示
|
||||
self.config_status = tk.StringVar()
|
||||
self.config_status.set("配置已加载")
|
||||
config_label = ttk.Label(self.status_bar, textvariable=self.config_status, anchor=tk.E)
|
||||
config_label.pack(side=tk.RIGHT, padx=5)
|
||||
|
||||
def _center_window(self):
|
||||
"""将窗口居中显示"""
|
||||
self.root.update_idletasks()
|
||||
width = self.root.winfo_width()
|
||||
height = self.root.winfo_height()
|
||||
x = (self.root.winfo_screenwidth() // 2) - (width // 2)
|
||||
y = (self.root.winfo_screenheight() // 2) - (height // 2)
|
||||
self.root.geometry(f"{width}x{height}+{x}+{y}")
|
||||
|
||||
def show_about(self):
|
||||
"""显示关于对话框"""
|
||||
from tkinter import messagebox
|
||||
messagebox.showinfo(
|
||||
"关于 ERP 自动化工具",
|
||||
"ERP 自动化工具 v1.0\n\n"
|
||||
"功能:\n"
|
||||
"• 数据提取 - 从 ERP 系统提取备料计划数据\n"
|
||||
"• 物料校验 - 校验物料状态并匹配待删除物料\n"
|
||||
"• 数据查询 - 查询生产订单号等信息\n"
|
||||
"• 设置管理 - 管理系统配置\n\n"
|
||||
"基于 Playwright 和 Python 开发"
|
||||
)
|
||||
Reference in New Issue
Block a user