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 www.3dbunk.com, feel free, to check the other tutorial we released :-) !
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 !
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
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