forked from Rowland/EG
277 lines
9.4 KiB
Python
277 lines
9.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
快速菜单栏修复脚本
|
|
用于诊断和修复菜单栏显示问题
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget, QPushButton
|
|
from PyQt5.QtCore import Qt, QTimer
|
|
|
|
# 设置环境变量避免DPI问题
|
|
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
|
|
os.environ["QT_SCALE_FACTOR"] = "1"
|
|
|
|
class QuickMenuFix(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setupUI()
|
|
|
|
def setupUI(self):
|
|
"""设置UI"""
|
|
self.setWindowTitle("菜单栏快速修复工具")
|
|
self.setGeometry(300, 300, 900, 700)
|
|
|
|
# 强制窗口标志
|
|
self.setWindowFlags(Qt.Window)
|
|
|
|
# 设置主窗口样式
|
|
self.setStyleSheet("""
|
|
QMainWindow {
|
|
background-color: #1E1E1E;
|
|
color: #FFFFFF;
|
|
}
|
|
QPushButton {
|
|
background-color: #0078D4;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
margin: 5px;
|
|
border-radius: 5px;
|
|
font-size: 12px;
|
|
}
|
|
QPushButton:hover {
|
|
background-color: #106EBE;
|
|
}
|
|
QPushButton:pressed {
|
|
background-color: #005A9E;
|
|
}
|
|
""")
|
|
|
|
# 创建中央部件
|
|
central_widget = QWidget()
|
|
self.setCentralWidget(central_widget)
|
|
layout = QVBoxLayout(central_widget)
|
|
|
|
# 标题
|
|
title = QLabel("🔧 菜单栏修复工具")
|
|
title.setStyleSheet("font-size: 24px; font-weight: bold; color: #0078D4; margin: 20px;")
|
|
title.setAlignment(Qt.AlignCenter)
|
|
layout.addWidget(title)
|
|
|
|
# 状态显示
|
|
self.status_label = QLabel("准备就绪...")
|
|
self.status_label.setStyleSheet("font-size: 14px; color: white; margin: 10px; padding: 10px; background-color: #2D2D30; border-radius: 5px;")
|
|
self.status_label.setAlignment(Qt.AlignCenter)
|
|
layout.addWidget(self.status_label)
|
|
|
|
# 按钮区域
|
|
button_layout = QVBoxLayout()
|
|
|
|
# 测试按钮
|
|
test_btn = QPushButton("🔍 测试菜单栏显示")
|
|
test_btn.clicked.connect(self.testMenuBar)
|
|
button_layout.addWidget(test_btn)
|
|
|
|
# 修复按钮
|
|
fix_btn = QPushButton("🛠️ 强制修复菜单栏")
|
|
fix_btn.clicked.connect(self.forceFixMenuBar)
|
|
button_layout.addWidget(fix_btn)
|
|
|
|
# 重置按钮
|
|
reset_btn = QPushButton("🔄 重置菜单栏样式")
|
|
reset_btn.clicked.connect(self.resetMenuBarStyle)
|
|
button_layout.addWidget(reset_btn)
|
|
|
|
# 信息按钮
|
|
info_btn = QPushButton("📊 显示系统信息")
|
|
info_btn.clicked.connect(self.showSystemInfo)
|
|
button_layout.addWidget(info_btn)
|
|
|
|
layout.addLayout(button_layout)
|
|
|
|
# 创建初始菜单栏
|
|
self.createInitialMenuBar()
|
|
|
|
def createInitialMenuBar(self):
|
|
"""创建初始菜单栏"""
|
|
menubar = self.menuBar()
|
|
menubar.setNativeMenuBar(False)
|
|
|
|
# 添加基本菜单
|
|
file_menu = menubar.addMenu('文件')
|
|
file_menu.addAction('新建')
|
|
file_menu.addAction('打开')
|
|
|
|
edit_menu = menubar.addMenu('编辑')
|
|
edit_menu.addAction('复制')
|
|
edit_menu.addAction('粘贴')
|
|
|
|
help_menu = menubar.addMenu('帮助')
|
|
help_menu.addAction('关于')
|
|
|
|
print("✅ 初始菜单栏已创建")
|
|
|
|
def testMenuBar(self):
|
|
"""测试菜单栏显示"""
|
|
menubar = self.menuBar()
|
|
|
|
# 收集信息
|
|
info = []
|
|
info.append(f"可见性: {menubar.isVisible()}")
|
|
info.append(f"启用状态: {menubar.isEnabled()}")
|
|
info.append(f"高度: {menubar.height()}px")
|
|
info.append(f"宽度: {menubar.width()}px")
|
|
info.append(f"位置: {menubar.pos()}")
|
|
info.append(f"菜单数量: {len(menubar.actions())}")
|
|
info.append(f"原生菜单栏: {menubar.isNativeMenuBar()}")
|
|
|
|
# 显示结果
|
|
status_text = "📊 菜单栏状态:\n" + "\n".join(info)
|
|
self.status_label.setText(status_text)
|
|
|
|
# 控制台输出
|
|
print("\n🔍 菜单栏测试结果:")
|
|
for item in info:
|
|
print(f" - {item}")
|
|
|
|
# 判断是否正常
|
|
if menubar.isVisible() and menubar.height() > 0:
|
|
self.status_label.setStyleSheet("font-size: 14px; color: white; margin: 10px; padding: 10px; background-color: #0F7B0F; border-radius: 5px;")
|
|
print("✅ 菜单栏显示正常")
|
|
else:
|
|
self.status_label.setStyleSheet("font-size: 14px; color: white; margin: 10px; padding: 10px; background-color: #A80000; border-radius: 5px;")
|
|
print("❌ 菜单栏显示异常")
|
|
|
|
def forceFixMenuBar(self):
|
|
"""强制修复菜单栏"""
|
|
menubar = self.menuBar()
|
|
|
|
print("🛠️ 开始强制修复菜单栏...")
|
|
|
|
# 重置基本属性
|
|
menubar.setNativeMenuBar(False)
|
|
menubar.setVisible(True)
|
|
menubar.setEnabled(True)
|
|
|
|
# 设置尺寸
|
|
menubar.setMinimumHeight(50)
|
|
menubar.setMaximumHeight(50)
|
|
|
|
# 应用强制样式
|
|
menubar.setStyleSheet("""
|
|
QMenuBar {
|
|
background-color: #FF4444 !important;
|
|
color: #FFFFFF !important;
|
|
border: 4px solid #00FF00 !important;
|
|
min-height: 50px !important;
|
|
max-height: 50px !important;
|
|
font-size: 18px !important;
|
|
font-weight: bold !important;
|
|
padding: 8px !important;
|
|
}
|
|
QMenuBar::item {
|
|
background-color: #FFFF00 !important;
|
|
color: #000000 !important;
|
|
padding: 12px 20px !important;
|
|
margin: 4px !important;
|
|
font-size: 18px !important;
|
|
font-weight: bold !important;
|
|
border: 2px solid #FF0000 !important;
|
|
border-radius: 3px !important;
|
|
}
|
|
QMenuBar::item:selected {
|
|
background-color: #0066FF !important;
|
|
color: #FFFFFF !important;
|
|
}
|
|
""")
|
|
|
|
# 强制显示和刷新
|
|
menubar.show()
|
|
menubar.raise_()
|
|
menubar.update()
|
|
menubar.repaint()
|
|
self.update()
|
|
self.repaint()
|
|
|
|
self.status_label.setText("🛠️ 强制修复已应用!\n如果看到红色菜单栏说明修复成功")
|
|
self.status_label.setStyleSheet("font-size: 14px; color: white; margin: 10px; padding: 10px; background-color: #FF6600; border-radius: 5px;")
|
|
|
|
print("🛠️ 强制修复完成")
|
|
|
|
# 延迟测试结果
|
|
QTimer.singleShot(1000, self.testMenuBar)
|
|
|
|
def resetMenuBarStyle(self):
|
|
"""重置菜单栏样式"""
|
|
menubar = self.menuBar()
|
|
|
|
# 清除样式
|
|
menubar.setStyleSheet("")
|
|
|
|
# 重新设置基本样式
|
|
menubar.setStyleSheet("""
|
|
QMenuBar {
|
|
background-color: #2D2D30;
|
|
color: #FFFFFF;
|
|
border-bottom: 1px solid #3E3E42;
|
|
min-height: 30px;
|
|
font-size: 14px;
|
|
}
|
|
QMenuBar::item {
|
|
background-color: transparent;
|
|
color: #FFFFFF;
|
|
padding: 8px 12px;
|
|
margin: 0px 2px;
|
|
}
|
|
QMenuBar::item:selected {
|
|
background-color: #0078D4;
|
|
}
|
|
""")
|
|
|
|
menubar.update()
|
|
self.status_label.setText("🔄 菜单栏样式已重置为正常样式")
|
|
self.status_label.setStyleSheet("font-size: 14px; color: white; margin: 10px; padding: 10px; background-color: #2D2D30; border-radius: 5px;")
|
|
|
|
print("🔄 菜单栏样式已重置")
|
|
|
|
def showSystemInfo(self):
|
|
"""显示系统信息"""
|
|
import platform
|
|
from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
|
|
|
|
info = []
|
|
info.append(f"操作系统: {platform.system()} {platform.release()}")
|
|
info.append(f"Python版本: {sys.version.split()[0]}")
|
|
info.append(f"PyQt5版本: {PYQT_VERSION_STR}")
|
|
info.append(f"Qt版本: {QT_VERSION_STR}")
|
|
info.append(f"屏幕分辨率: {QApplication.desktop().screenGeometry().width()}x{QApplication.desktop().screenGeometry().height()}")
|
|
|
|
status_text = "📊 系统信息:\n" + "\n".join(info)
|
|
self.status_label.setText(status_text)
|
|
self.status_label.setStyleSheet("font-size: 12px; color: white; margin: 10px; padding: 10px; background-color: #0078D4; border-radius: 5px;")
|
|
|
|
print("\n📊 系统信息:")
|
|
for item in info:
|
|
print(f" - {item}")
|
|
|
|
def main():
|
|
"""主函数"""
|
|
app = QApplication(sys.argv)
|
|
|
|
# 设置应用样式
|
|
app.setStyle('Fusion')
|
|
|
|
print("🚀 启动菜单栏修复工具")
|
|
print("📋 这个工具可以帮助诊断和修复菜单栏显示问题")
|
|
print("🎯 使用明显的颜色来测试菜单栏是否正常显示")
|
|
|
|
window = QuickMenuFix()
|
|
window.show()
|
|
|
|
return app.exec_()
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main()) |