Commit 3e0dafdb authored by 邱阿朋's avatar 邱阿朋

refactor(gui): 重构 GUI相关代码并优化日志处理

- 修改 easy_gui.py、price_gui.py、super_gui.py、tool_gui.py 中的界面布局和组件创建逻辑
- 更新 requirements.txt 中的依赖版本
- 调整 tool_cmd.py 中的模块导入顺序
- 统一使用小写字符串作为 fill 参数值
- 在调用 after 方法时添加空元组以忽略类型检查警告
parent e4836d9d
......@@ -150,7 +150,7 @@ class Application(ttk.Window):
# 创建日志队列
self.log_queue = queue.Queue()
self.create_widgets()
self.after(100, self.process_log_queue)
self.after(100, self.process_log_queue,()) # type: ignore
def _center_window(self):
"""设置窗口居中"""
......@@ -171,39 +171,39 @@ class Application(ttk.Window):
def create_widgets(self):
"""创建界面组件"""
main_frame = ttk.Frame(self)
main_frame.pack(fill=BOTH, expand=True, padx=10, pady=10)
main_frame.pack(fill='both', expand=True, padx=10, pady=10)
# 仓库选择
warehouse_frame = ttk.Labelframe(main_frame, text="仓库选择", padding=10)
warehouse_frame.pack(fill=X, pady=5)
warehouse_frame.pack(fill='x', pady=5)
self.warehouse_combo = ttk.Combobox(
warehouse_frame,
values=[f"{code} - {name}" for code, name in self.warehouse_map.items()],
state="readonly"
)
self.warehouse_combo.pack(fill=X, padx=5)
self.warehouse_combo.pack(fill='x', padx=5)
# 文件选择
file_frame = ttk.Labelframe(main_frame, text="Excel文件", padding=10)
file_frame.pack(fill=X, pady=5)
file_frame.pack(fill='x', pady=5)
self.file_entry = ttk.Entry(file_frame)
self.file_entry.pack(side=LEFT, fill=X, expand=True, padx=5)
ttk.Button(file_frame, text="浏览", command=self.select_file).pack(side=LEFT, padx=5)
self.file_entry.pack(side='left', fill='x', expand=True, padx=5)
ttk.Button(file_frame, text="浏览", command=self.select_file).pack(side='left', padx=5)
# 控制按钮
btn_frame = ttk.Frame(main_frame)
btn_frame.pack(fill=X, pady=10)
btn_frame.pack(fill='x', pady=10)
self.run_btn = ttk.Button(btn_frame, text="开始执行", command=self.start_process, style=PRIMARY)
self.run_btn.pack(pady=5)
# 日志显示
log_frame = ttk.Labelframe(main_frame, text="操作日志", padding=10)
log_frame.pack(fill=BOTH, expand=True)
log_frame.pack(fill='both', expand=True)
self.log_area = scrolledtext.ScrolledText(log_frame, state=DISABLED)
self.log_area.pack(fill=BOTH, expand=True)
self.log_area.pack(fill='both', expand=True)
def select_file(self):
"""选择Excel文件"""
......@@ -271,7 +271,7 @@ class Application(ttk.Window):
self.log_area.insert(END, msg + "\n")
self.log_area.config(state=DISABLED)
self.log_area.see(END)
self.after(100, self.process_log_queue)
self.after(100, self.process_log_queue,()) # type: ignore
if __name__ == "__main__":
......
......@@ -64,12 +64,12 @@ class AmazonPriceScraper:
self.file_label.pack(pady=5)
self.log_text = scrolledtext.ScrolledText(self.root, height=20, width=80)
self.log_text.pack(pady=10, padx=10, fill=BOTH, expand=True)
self.log_text.pack(pady=10, padx=10, fill='both', expand=True)
button_frame = ttk.Frame(self.root)
button_frame.pack(pady=5)
ttk.Button(button_frame, text="开始爬取", bootstyle=SUCCESS, command=self.start_scraping).pack(side=LEFT, padx=5)
ttk.Button(button_frame, text="停止", bootstyle=DANGER, command=self.stop_scraping).pack(side=LEFT, padx=5)
ttk.Button(button_frame, text="开始爬取", style=SUCCESS, command=self.start_scraping).pack(side='left', padx=5)
ttk.Button(button_frame, text="停止", style=DANGER, command=self.stop_scraping).pack(side='left', padx=5)
def log(self, message):
self.log_text.insert(END, f"{time.strftime('%Y-%m-%d %H:%M:%S')}: {message}\n")
......
......@@ -9,4 +9,5 @@ requests==2.32.3
redis==5.0.8
pika==1.3.2
python-dotenv==1.0.1
ttkbootstrap==1.10.1
\ No newline at end of file
ttkbootstrap==1.14.2
xmltodict==0.14.2
\ No newline at end of file
......@@ -48,7 +48,7 @@ class VCManagerGUI(ttk.Window):
self.create_widgets()
# 启动日志处理循环
self.after(100, self.process_log_queue)
self.after(100, self.process_log_queue,()) # type: ignore
def _center_window(self):
"""设置窗口居中"""
......@@ -69,16 +69,16 @@ class VCManagerGUI(ttk.Window):
def create_widgets(self):
"""创建主界面布局"""
main_frame = ttk.Frame(self)
main_frame.pack(fill=BOTH, expand=True, padx=15, pady=15)
main_frame.pack(fill='both', expand=True, padx=15, pady=15)
# 配置区域
config_frame = ttk.Labelframe(main_frame, text="配置参数", padding=10)
config_frame.pack(fill=X, pady=10)
config_frame.pack(fill='x', pady=10)
# 国家选择
country_frame = ttk.Frame(config_frame)
country_frame.grid(row=0, column=0, sticky=W, pady=5)
ttk.Label(country_frame, text="国家:", width=6).pack(side=LEFT)
ttk.Label(country_frame, text="国家:", width=6).pack(side='left')
self.country_var = ttk.StringVar(value="US")
countries = [
("美国", "US"),
......@@ -90,12 +90,12 @@ class VCManagerGUI(ttk.Window):
]
for i, (text, value) in enumerate(countries):
rb = ttk.Radiobutton(country_frame,text=text,variable=self.country_var,value=value)
rb.pack(side=LEFT, padx=(10 if i != 0 else 0))
rb.pack(side='left', padx=(10 if i != 0 else 0))
# 功能选择
action_frame = ttk.Frame(config_frame)
action_frame.grid(row=1, column=0, sticky=W, pady=5)
ttk.Label(action_frame, text="功能:", width=6).pack(side=LEFT)
ttk.Label(action_frame, text="功能:", width=6).pack(side='left')
self.action_var = ttk.StringVar()
actions = [
("广告费", "advert_cost"),
......@@ -103,21 +103,21 @@ class VCManagerGUI(ttk.Window):
]
for i, (text, value) in enumerate(actions):
rb = ttk.Radiobutton(action_frame, text=text, variable=self.action_var, value=value)
rb.pack(side=LEFT, padx=(10 if i != 0 else 0))
rb.pack(side='left', padx=(10 if i != 0 else 0))
# 控制按钮
btn_frame = ttk.Frame(main_frame)
btn_frame.pack(fill=X, pady=15)
btn_frame.pack(fill='x', pady=15)
self.run_btn = ttk.Button(btn_frame, text="开始执行", command=self.start_process,
style=PRIMARY, width=12)
self.run_btn.pack(side=RIGHT, padx=5)
self.run_btn.pack(side='right', padx=5)
# 日志显示
log_frame = ttk.Labelframe(main_frame, text="操作日志", padding=10)
log_frame.pack(fill=BOTH, expand=True)
log_frame.pack(fill='both', expand=True)
self.log_text = ttk.ScrolledText(log_frame, state=DISABLED)
self.log_text.pack(fill=BOTH, expand=True)
self.log_text.pack(fill='both', expand=True)
def start_process(self):
"""启动处理线程"""
......@@ -189,7 +189,7 @@ class VCManagerGUI(ttk.Window):
self.log_text.insert(ttk.END, msg + "\n")
self.log_text.configure(state=ttk.DISABLED)
self.log_text.see(ttk.END)
self.after(100, self.process_log_queue)
self.after(100, self.process_log_queue,()) # type: ignore
def clear_log(self):
"""清除日志"""
......@@ -208,7 +208,7 @@ class VCManagerGUI(ttk.Window):
finally:
self.page = None
self.running = False
self.after(0, lambda: self.run_btn.config(state=ttk.NORMAL))
self.after(0, lambda: self.run_btn.config(state=ttk.NORMAL),()) # type: ignore
if __name__ == "__main__":
......
# coding: utf-8
import os
from app.helper import file, domain, helper
from DrissionPage import ChromiumPage
from dotenv import load_dotenv
from app.helper import domain, helper
from app.helper.logger import ConsoleLog
from app.vc.payment import Payment
from app.vc.payment_push import PaymentPush
from app.vc.return_goods import ReturnGoods
from app.vc.spa import Spa
from DrissionPage import ChromiumPage
from dotenv import load_dotenv
if __name__ == '__main__':
load_dotenv()
......
......@@ -52,7 +52,7 @@ class VCManagerGUI(ttk.Window):
self.create_widgets()
# 启动日志处理循环
self.after(100, self.process_log_queue)
self.after(100, self.process_log_queue,()) # type: ignore
def _center_window(self):
"""设置窗口居中"""
......@@ -73,16 +73,16 @@ class VCManagerGUI(ttk.Window):
def create_widgets(self):
"""创建主界面布局"""
main_frame = ttk.Frame(self)
main_frame.pack(fill=BOTH, expand=True, padx=15, pady=15)
main_frame.pack(fill='both', expand=True, padx=15, pady=15)
# 配置区域
config_frame = ttk.Labelframe(main_frame, text="配置参数", padding=10)
config_frame.pack(fill=X, pady=10)
config_frame.pack(fill='x', pady=10)
# 国家选择
country_frame = ttk.Frame(config_frame)
country_frame.grid(row=0, column=0, sticky=W, pady=5)
ttk.Label(country_frame, text="国家:", width=6).pack(side=LEFT)
ttk.Label(country_frame, text="国家:", width=6).pack(side='left')
self.country_var = ttk.StringVar(value="US")
countries = [
("美国", "US"),
......@@ -99,12 +99,12 @@ class VCManagerGUI(ttk.Window):
variable=self.country_var,
value=value
)
rb.pack(side=LEFT, padx=(10 if i != 0 else 0))
rb.pack(side='left', padx=(10 if i != 0 else 0))
# 功能选择
action_frame = ttk.Frame(config_frame)
action_frame.grid(row=1, column=0, sticky=W, pady=5)
ttk.Label(action_frame, text="功能:", width=6).pack(side=LEFT)
ttk.Label(action_frame, text="功能:", width=6).pack(side='left')
self.action_var = ttk.StringVar()
actions = [
("SPA查询", "spa"),
......@@ -119,12 +119,12 @@ class VCManagerGUI(ttk.Window):
variable=self.action_var,
value=value
)
rb.pack(side=LEFT, padx=(10 if i != 0 else 0))
rb.pack(side='left', padx=(10 if i != 0 else 0))
# 是否推送消息
push_msg_frame = ttk.Frame(config_frame)
push_msg_frame.grid(row=2, column=0, sticky=W, pady=5)
ttk.Label(push_msg_frame, text="推送:", width=6).pack(side=LEFT)
ttk.Label(push_msg_frame, text="推送:", width=6).pack(side='left')
self.push_msg_var = ttk.StringVar(value="1")
push_msg_actions = [
("是", "1"),
......@@ -137,31 +137,31 @@ class VCManagerGUI(ttk.Window):
variable=self.push_msg_var,
value=value
)
rb.pack(side=LEFT, padx=(10 if i != 0 else 0))
rb.pack(side='left', padx=(10 if i != 0 else 0))
# 文件选择区域
file_frame = ttk.Labelframe(main_frame, text="数据文件", padding=10)
file_frame.pack(fill=X, pady=10)
file_frame.pack(fill='x', pady=10)
self.file_entry = ttk.Entry(file_frame)
self.file_entry.pack(side=LEFT, fill=X, expand=True, padx=5)
ttk.Button(file_frame, text="浏览", command=self.select_file, width=8).pack(side=LEFT)
self.file_entry.pack(side='left', fill='x', expand=True, padx=5)
ttk.Button(file_frame, text="浏览", command=self.select_file, width=8).pack(side='left')
# 控制按钮
btn_frame = ttk.Frame(main_frame)
btn_frame.pack(fill=X, pady=15)
btn_frame.pack(fill='x', pady=15)
self.run_btn = ttk.Button(btn_frame, text="开始执行", command=self.start_process,
style=PRIMARY, width=12)
self.run_btn.pack(side=LEFT, padx=5)
ttk.Button(btn_frame, text="清除日志", command=self.clear_log, width=10).pack(side=LEFT, padx=5)
ttk.Button(btn_frame, text="退出", command=self.quit_app, width=8).pack(side=RIGHT)
self.run_btn.pack(side='left', padx=5)
ttk.Button(btn_frame, text="清除日志", command=self.clear_log, width=10).pack(side='left', padx=5)
ttk.Button(btn_frame, text="退出", command=self.quit_app, width=8).pack(side='right')
# 日志显示
log_frame = ttk.Labelframe(main_frame, text="操作日志", padding=10)
log_frame.pack(fill=BOTH, expand=True)
log_frame.pack(fill='both', expand=True)
self.log_text = ttk.ScrolledText(log_frame, state=DISABLED)
self.log_text.pack(fill=BOTH, expand=True)
self.log_text.pack(fill='both', expand=True)
def select_file(self):
"""选择数据文件"""
......@@ -281,7 +281,7 @@ class VCManagerGUI(ttk.Window):
def get_payee_code(self):
"""获取回款Code"""
self.after(0, self._show_payee_dialog)
self.after(0, self._show_payee_dialog,()) # type: ignore
while self.running and not self.payee_code:
time.sleep(0.1)
......@@ -311,7 +311,7 @@ class VCManagerGUI(ttk.Window):
self.log_text.insert(ttk.END, msg + "\n")
self.log_text.configure(state=ttk.DISABLED)
self.log_text.see(ttk.END)
self.after(100, self.process_log_queue)
self.after(100, self.process_log_queue,()) # type: ignore
def clear_log(self):
"""清除日志"""
......@@ -349,7 +349,7 @@ class VCManagerGUI(ttk.Window):
finally:
self.page = None
self.running = False
self.after(0, lambda: self.run_btn.config(state=ttk.NORMAL))
self.after(0, lambda: self.run_btn.config(state=ttk.NORMAL),()) # type: ignore
def quit_app(self):
"""安全退出程序"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment