首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >定制Maya的脚本编辑器字体

定制Maya的脚本编辑器字体
EN

Stack Overflow用户
提问于 2022-04-03 01:18:27
回答 1查看 344关注 0票数 1

直到Maya2019,我使用以下脚本自定义脚本编辑器字体。

代码语言:javascript
复制
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)

这样,我就可以在所有选项卡上统一更改脚本编辑器的字体样式和大小。

代码语言:javascript
复制
# this is my current favorite
set_font(font='Consolas', size=20) 

在玛雅2018年和2019年,这很好。我还没有测试2020,但在2022年和2023年,它执行时没有出现错误,但未能按照需要更改接口。

问题

自2019年以来所发生的变化会使这个脚本失败。任何关于如何使这个脚本工作的技巧都将不胜感激。否则,当我发现问题时,我会在这里发布一个解决方案。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-14 13:11:10

我没有一个完整的答案,但以下似乎是可行的。一个值得注意的变化是,QTextEdit似乎已被QPlainTextEdit所取代,但仅替换它并不能修复它。

然而,以下是玛雅版本之前和之后的2022年,似乎是有效的。

在适用相同解决方案的macOS 12.4和Maya 2022.2上进行了测试。它可能是一个不同的小版本的玛雅2022年需要旧的解决方案。

代码语言:javascript
复制
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) 
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71722293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档