直到Maya2019,我使用以下脚本自定义脚本编辑器字体。
from PySide2 import QtGui, QtCore, QtWidgets
def set_font(font='Courier New', size=12):
"""
Sets the style sheet of Maya's script Editor
"""
# Find the script editor widget
app = QtWidgets.QApplication.instance()
win = next(w for w in app.topLevelWidgets() if w.objectName()=='MayaWindow')
# Add a custom property
win.setProperty('maya_ui', 'scriptEditor')
# Apply style sheet
styleSheet = '''
QWidget[maya_ui="scriptEditor"] QTextEdit {
font-family: %s;
font: normal %spx;
}
''' %(font, size)
app.setStyleSheet(styleSheet)这样,我就可以在所有选项卡上统一更改脚本编辑器的字体样式和大小。
# this is my current favorite
set_font(font='Consolas', size=20) 在玛雅2018年和2019年,这很好。我还没有测试2020,但在2022年和2023年,它执行时没有出现错误,但未能按照需要更改接口。
问题
自2019年以来所发生的变化会使这个脚本失败。任何关于如何使这个脚本工作的技巧都将不胜感激。否则,当我发现问题时,我会在这里发布一个解决方案。
发布于 2022-04-14 13:11:10
我没有一个完整的答案,但以下似乎是可行的。一个值得注意的变化是,QTextEdit似乎已被QPlainTextEdit所取代,但仅替换它并不能修复它。
然而,以下是玛雅版本之前和之后的2022年,似乎是有效的。
在适用相同解决方案的macOS 12.4和Maya 2022.2上进行了测试。它可能是一个不同的小版本的玛雅2022年需要旧的解决方案。
import maya.cmds as cmds
from PySide2 import QtGui, QtCore, QtWidgets
def set_font(font='Courier New', size=12):
"""
Sets the style sheet of Maya's script Editor
"""
app = QtWidgets.QApplication.instance()
win = None
for w in app.topLevelWidgets():
if "Script Editor" in w.windowTitle():
win = w
break
if win is None:
return
# for Maya 2022 and above
if int(cmds.about(version=True)) >= 2022:
style = '''
QPlainTextEdit {
font-family: %s;
font: normal %dpx;
}
''' % (font, size)
win.setStyleSheet(style)
# for Maya 2020 and older
else:
style = '''
QWidget[maya_ui="scriptEditor"] QTextEdit {
font-family: %s;
font: normal %dpx;
}
''' % (font, size)
win.setProperty('maya_ui', 'scriptEditor')
app.setStyleSheet(style)
set_font(font='Consolas', size=20) https://stackoverflow.com/questions/71722293
复制相似问题