Adverti horiz upsell
Color syntaxing the Script Editor Reporter
Color syntaxing the Script Editor Reporter
mlouala, updated 2017-04-16 11:20:08 UTC 6,815 views  Rating:
(1 rating)
Page 1 of 5

Hi there,
 
As a script TD, rigger, or anybody who need to open the Maya's Script Editor, aren't you tired to scroll through tons of grey lines like these one below ? What about color syntaxing all this stuff ?
 

Here is a tutorial to set a PyQt class in order to override the color syntax of Maya's Script editor reporter.
The tutorial has been originally wrote for 3dbunk.com, feel free, to check the other tutorial we released :-) !
 

Introduction

This tutorial will be a nice occasion to have a look to PyQt in a very light way, and how we can associate its strength with Maya, our aim is the following ; the Command History of Maya is a bit sickly and pale so we're going to add some colors to make it more readable.

We'll first try to identify the scriptEditor's window, then we'll manage to get the correct QTextEdit child object, finally we'll assigne a QSyntaxHighlighter to it. Regular expressions basic knowledge may be useful to create your own coloring, let's start !

Tips ; These two websites are great help if you want to learn more about regular expressions !
Online Regex Tester
Wikipedia's article

PyQt


Identify our aim

So we're going to search the PyQt widget we want thank to the wrapinstance function from sip, aka wrapInstance for shiboken in completion with the wonderful class MQtUtil from OpenMayaUI in order to search inside Maya the widgets we are looking for. First let's find the Maya main window, which will be an easy shot;

Note ; The wrapInstance function needs a unique 'id' corresponding to the QWidget, and the main class of the widget, for our current example we're looking for the main window, so the class will be a QWidget

from PySide import QtCore, QtGui
from shiboken import wrapInstance
from maya.OpenMayaUI import MQtUtil
 
maya_win = wrapInstance(long(MQtUtil.mainWindow()), QWidget)

Fine, now we can loop through children to find the scriptEditor window, several ways of approach can be used, we're just going to find all the children which contains 'script' in their object name, I'm pretty confident this will be the case for our script Editor window =)

for child in maya_win.children():
    if 'script' in child.objectName():
        print 'CHILD => %s' % child.objectName()

One shot ! You should see something like that ;

# CHILD => scriptEditorPanel1Window 

 We now have the name of our scriptEditor window and especially the corresponding object. Our second task will be to iterate inside its numerous children to find the QTextEdit of the History. The method is quite the same as above, except we need to do this recursively in all children and children's children to find all the QTextEdit instances to get the correct object's name. We spare you the pain of the search, so the name QTextEdit we're looking for is named cmdScrollFieldReporter1, take note that this widget have a unique name, and that a number is automatically added at the end. This means we could meet cmdScrollFieldReporter4.

Thank to the wonderful class MQtUtil we can now access to the widget using the function findControl

script_stdout = wrapInstance(long(MQtUtil.findControl('cmdScrollFieldReporter1')), QTextEdit)

Considering the fact that we don't now exactly the index of the widget's name we're going to use a little while loop to find the correct occurence ;

getting the correct scriptEditor Reporter instance
i = 1
while i:
    try:
        se_edit = wrapInstance(long(MQtUtil.findControl('cmdScrollFieldReporter%i' % i)),
                                                        QtGui.QTextEdit)
        break
    except TypeError:
        i += 1

Alright ! Now we have our widget we can work on the coloring