134 lines
3.7 KiB
Python
134 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
测试右上角按钮点击修复
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# 添加项目根目录到Python路径
|
|
project_root = Path(__file__).parent.parent
|
|
sys.path.insert(0, str(project_root))
|
|
sys.path.insert(0, str(project_root / 'MetaCore'))
|
|
|
|
from PyQt5.QtWidgets import *
|
|
from PyQt5.QtCore import *
|
|
from PyQt5.QtGui import *
|
|
|
|
from data.project_manager import ProjectManager, Project
|
|
from ui.project_card import ProjectCard
|
|
from ui.styles import StyleSheet
|
|
|
|
class TestButtonWindow(QWidget):
|
|
"""测试按钮修复的窗口"""
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setWindowTitle("右上角按钮修复测试")
|
|
self.setGeometry(100, 100, 800, 600)
|
|
self.setStyleSheet(StyleSheet.get_main_stylesheet())
|
|
|
|
# 设置深色背景
|
|
self.setStyleSheet("""
|
|
QWidget {
|
|
background-color: #1a1a1a;
|
|
color: #ffffff;
|
|
}
|
|
""" + StyleSheet.get_main_stylesheet())
|
|
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
"""初始化UI"""
|
|
layout = QVBoxLayout(self)
|
|
layout.setContentsMargins(40, 40, 40, 40)
|
|
layout.setSpacing(20)
|
|
|
|
# 标题
|
|
title = QLabel("右上角按钮修复测试")
|
|
title.setStyleSheet("""
|
|
QLabel {
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
color: #ffffff;
|
|
margin-bottom: 20px;
|
|
}
|
|
""")
|
|
title.setAlignment(Qt.AlignCenter)
|
|
layout.addWidget(title)
|
|
|
|
# 说明文字
|
|
description = QLabel("""
|
|
测试说明:
|
|
• 点击右上角的信息按钮应该显示上下文菜单,不应该闪退
|
|
• 菜单应该包含:刷新预览图、在资源管理器显示、移除项目
|
|
• 所有菜单项都应该能正常工作
|
|
""")
|
|
description.setStyleSheet("""
|
|
QLabel {
|
|
font-size: 14px;
|
|
color: #cccccc;
|
|
line-height: 1.5;
|
|
margin-bottom: 20px;
|
|
}
|
|
""")
|
|
layout.addWidget(description)
|
|
|
|
# 创建测试卡片
|
|
self.create_test_cards(layout)
|
|
|
|
def create_test_cards(self, layout):
|
|
"""创建测试卡片"""
|
|
# 卡片容器
|
|
cards_widget = QWidget()
|
|
cards_layout = QHBoxLayout(cards_widget)
|
|
cards_layout.setSpacing(24)
|
|
cards_layout.setContentsMargins(20, 20, 20, 20)
|
|
|
|
# 创建项目管理器
|
|
project_manager = ProjectManager()
|
|
|
|
# 创建测试项目
|
|
test_project = Project(
|
|
id='test_1',
|
|
title='测试项目',
|
|
date='2024-10-14 15:30',
|
|
project_type='smart',
|
|
status='active',
|
|
path="/test/path/1",
|
|
project_dir="/test/path/1",
|
|
image=None
|
|
)
|
|
|
|
# 创建网格视图卡片
|
|
grid_card = ProjectCard(test_project, project_manager, view_mode="grid")
|
|
cards_layout.addWidget(grid_card)
|
|
|
|
# 创建列表视图卡片
|
|
list_card = ProjectCard(test_project, project_manager, view_mode="list")
|
|
cards_layout.addWidget(list_card)
|
|
|
|
cards_layout.addStretch()
|
|
|
|
layout.addWidget(cards_widget)
|
|
layout.addStretch()
|
|
|
|
def main():
|
|
"""主函数"""
|
|
app = QApplication(sys.argv)
|
|
|
|
# 设置应用程序属性
|
|
app.setApplicationName("按钮修复测试")
|
|
app.setOrganizationName("MetaCore")
|
|
|
|
# 创建并显示测试窗口
|
|
window = TestButtonWindow()
|
|
window.show()
|
|
|
|
sys.exit(app.exec_())
|
|
|
|
if __name__ == '__main__':
|
|
main()
|