This commit is contained in:
2025-05-07 01:31:21 +08:00
parent d27ef50341
commit 27240530b6
18 changed files with 2033 additions and 1160 deletions

View File

@@ -53,13 +53,15 @@ ASSETS_PATH = config.ASSETS_PATH
DNA_FILE_PATH = config.DNA_FILE_PATH
DNA_IMG_PATH = config.DNA_IMG_PATH
TOOL_COMMAND_ICON = config.TOOL_COMMAND_ICON
TOOL_WIDTH = config.TOOL_WIDTH
TOOL_HEIGHT = config.TOOL_HEIGHT
#======================================= MAIN FUNCTION =====================================
class MainWindow(QtWidgets.QWidget):
def __init__(self, parent=ui_utils.get_maya_main_window()):
super(MainWindow, self).__init__(parent)
self.setWindowTitle(TOOL_NAME)
self.setObjectName(f"{TOOL_NAME}MainWindow")
self.setMinimumSize(1200, 800)
self.setMinimumSize(TOOL_WIDTH, TOOL_HEIGHT)
self.setStyleSheet("")
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
@@ -249,9 +251,25 @@ class MainWindow(QtWidgets.QWidget):
def center_window(self):
"""将窗口居中显示在屏幕上"""
# 获取屏幕几何信息
desktop = QtWidgets.QApplication.desktop()
screen_rect = desktop.availableGeometry(desktop.primaryScreen())
# 获取屏幕几何信息 - 兼容PySide2和PySide6
try:
# 使用Qt.py兼容层方式获取屏幕信息
app = QtWidgets.QApplication.instance()
screen = app.primaryScreen() if hasattr(app, 'primaryScreen') else None
if screen:
screen_rect = screen.availableGeometry()
else:
# 尝试使用desktop方法PySide2兼容
if hasattr(QtWidgets.QApplication, 'desktop'):
desktop = QtWidgets.QApplication.desktop()
screen_rect = desktop.availableGeometry(desktop.primaryScreen())
else:
# 如果都失败,使用默认值
screen_rect = QtCore.QRect(0, 0, 1920, 1080)
except Exception as e:
print(f"获取屏幕信息时出错: {str(e)}")
# 使用默认值
screen_rect = QtCore.QRect(0, 0, 1920, 1080)
# 计算窗口居中位置
window_rect = self.frameGeometry()