149 lines
4.7 KiB
Python
149 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
测试导入对话框功能
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
def test_import_dialog():
|
|
"""测试导入对话框"""
|
|
print("🔍 测试导入对话框功能...")
|
|
|
|
try:
|
|
from PyQt5.QtWidgets import QApplication
|
|
from data.project_manager import ProjectManager
|
|
from ui.import_project_dialog import ImportProjectDialog
|
|
|
|
# 创建应用程序实例
|
|
app = QApplication.instance()
|
|
if app is None:
|
|
app = QApplication([])
|
|
|
|
# 创建项目管理器
|
|
project_manager = ProjectManager()
|
|
print("✅ ProjectManager 创建成功")
|
|
|
|
# 创建导入对话框
|
|
dialog = ImportProjectDialog(project_manager)
|
|
print("✅ ImportProjectDialog 创建成功")
|
|
|
|
# 测试对话框属性
|
|
print(f"✅ 对话框标题: {dialog.windowTitle()}")
|
|
print(f"✅ 对话框大小: {dialog.size().width()}x{dialog.size().height()}")
|
|
|
|
# 测试上传区域
|
|
upload_area = dialog.upload_area
|
|
print("✅ UploadArea 组件存在")
|
|
|
|
# 检查信号连接
|
|
print("✅ 检查信号连接:")
|
|
print(f" - files_dropped 信号: {'已连接' if upload_area.files_dropped.receivers() > 0 else '未连接'}")
|
|
print(f" - select_files_requested 信号: {'已连接' if upload_area.select_files_requested.receivers() > 0 else '未连接'}")
|
|
|
|
# 显示对话框进行手动测试
|
|
print("\n💡 对话框将显示,请测试以下功能:")
|
|
print(" 1. 点击拖拽区域内的'点击选择'按钮")
|
|
print(" 2. 点击下方的'点击选择文件'按钮")
|
|
print(" 3. 拖拽文件到拖拽区域")
|
|
print(" 4. 关闭对话框完成测试")
|
|
|
|
# 显示对话框
|
|
dialog.show()
|
|
result = dialog.exec_()
|
|
|
|
if result == dialog.Accepted:
|
|
print("✅ 对话框正常关闭(用户点击了导入)")
|
|
else:
|
|
print("✅ 对话框正常关闭(用户取消了操作)")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ 测试失败: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def test_upload_area_signals():
|
|
"""测试上传区域信号"""
|
|
print("\n🔍 测试UploadArea信号...")
|
|
|
|
try:
|
|
from PyQt5.QtWidgets import QApplication
|
|
from ui.import_project_dialog import UploadArea
|
|
|
|
# 创建应用程序实例
|
|
app = QApplication.instance()
|
|
if app is None:
|
|
app = QApplication([])
|
|
|
|
# 创建上传区域
|
|
upload_area = UploadArea()
|
|
print("✅ UploadArea 创建成功")
|
|
|
|
# 测试信号存在
|
|
print("✅ 检查信号定义:")
|
|
print(f" - files_dropped: {'存在' if hasattr(upload_area, 'files_dropped') else '不存在'}")
|
|
print(f" - select_files_requested: {'存在' if hasattr(upload_area, 'select_files_requested') else '不存在'}")
|
|
|
|
# 测试信号连接
|
|
signal_test_result = []
|
|
|
|
def on_files_dropped(files):
|
|
signal_test_result.append(f"files_dropped: {len(files)} 个文件")
|
|
|
|
def on_select_files_requested():
|
|
signal_test_result.append("select_files_requested: 信号触发")
|
|
|
|
upload_area.files_dropped.connect(on_files_dropped)
|
|
upload_area.select_files_requested.connect(on_select_files_requested)
|
|
|
|
print("✅ 信号连接成功")
|
|
|
|
# 模拟信号触发
|
|
upload_area.select_files_requested.emit()
|
|
|
|
if signal_test_result:
|
|
print(f"✅ 信号测试成功: {signal_test_result}")
|
|
else:
|
|
print("⚠️ 信号测试未收到响应")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ 信号测试失败: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print("🚀 测试导入对话框按钮修复...")
|
|
print("=" * 60)
|
|
|
|
# 测试信号
|
|
signal_success = test_upload_area_signals()
|
|
|
|
if signal_success:
|
|
# 测试完整对话框
|
|
dialog_success = test_import_dialog()
|
|
|
|
if dialog_success:
|
|
print("\n🎉 所有测试通过!")
|
|
print("💡 '点击选择'按钮现在应该可以正常工作了。")
|
|
return True
|
|
else:
|
|
print("\n❌ 对话框测试失败")
|
|
return False
|
|
else:
|
|
print("\n❌ 信号测试失败")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
print("\n按Enter键退出...")
|
|
input()
|
|
sys.exit(0 if success else 1)
|