Here is a tutorial to set a PyQt class in order to override the color syntax of Maya's Script editor reporter.
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
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|
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 =)
One shot ! You should see something like that ;
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
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 ;
Alright ! Now we have our widget we can work on the coloring
Author: Mehdi Louala
Submitted: 2017-01-07 07:22:24 UTC
Tags: syntax highlighting, script, syntax, script editor, and Color
Maxya (Maya MEL Script Editor) for Maya 5.2.0 (maya plugin)
Universal UV Randomization script for Maya 1.1.0 (maya script)
Render Window / viewport Batch Render Script for Maya 1.0.0 (maya script)
Nightshade UV Editor Pro for Maya 2.1.3 (maya script)
Christmas Color Ball 3D Model
3D Thumbnail Generator (batch script) for Maya 0.3.1 (maya script)
UV Texture Editor Tools Ur-edition for Maya 2.1.2 (maya script)
Attr Editor for Maya 1.3.0 (maya script)
Automatic Rigging System written in MEL for Maya 0.2.8 (maya script)