1

I worked somewhere in the past where since we had multiple sessions of Maya open, the background color could be randomly changed so when you switched from a session quickly it was easy to sort out which window belonged to what Maya session.

And so far, I can change the bgc of the main UI by using:

window -e bgc 0.5 0.5 0.5 $gMainWindow;

After searching for other global variables, I found $AllWindows, $CommandWindow, among others since the docs state that 'bgc' is a windows only flag. I can not get any of the colors to change on any window besides the $gCommandWindow, which popped up and I do not recall seeing it before.

I'm hoping to at least change the Script Editor window in addition to MainWindow if anyone knows whether it's possible or not? It is not mission critical, but now I'm interested in seeing if it can be done.

Thanks!

alex04
  • 25
  • 6

1 Answers1

2

Since Maya's interface is using Qt, you can use the power of PySide to tweak any widget you want. Usually the only tricky part is actually finding the proper widget to modify.

Here's how you can tweak the Script Editor to give it a yellow border:

import shiboken2
from maya import cmds
from maya import OpenMayaUI
from PySide2 import QtWidgets


panels = cmds.getPanel(scriptType="scriptEditorPanel")  # Get all script editor panel names.

if panels:  # Make sure one actually exists!
    script_editor_ptr = OpenMayaUI.MQtUtil.findControl(panels[0])  # Grab its pointer with its internal name.
    script_editor = shiboken2.wrapInstance(long(script_editor_ptr), QtWidgets.QWidget)  # Convert pointer to a QtWidgets.QWidget
    editor_win = script_editor.parent().parent().parent().parent()  # Not very pretty but found that this was the best object to color with. Needed to traverse up its parents.
    editor_win.setObjectName("scriptEditorFramePanel")  # This object originally had no internal name, so let's set one.
    editor_win.setStyleSheet("#scriptEditorFramePanel {border: 3px solid rgb(150, 150, 45);}")  # Set its styleSheet with its internal name so that it doesn't effect any of its children.

OpenMayaUI.MQtUtil gives you the awesome ability to find any control by name, so as long as you know the name of the widget you want to modify, you can find it (tough part is finding it sometimes!). In this case I had to traverse up a few parents to find one that worked best to outline the whole window. You can fool around with this and color, let's say, only the text area. And since this is PySide's style sheets you can do whatever your heart desires, like effect the background color, the thickness of the outline, and so on.

Since we're only effecting the style sheet this also won't save with the preferences and will revert to what it was on a new session.

Hope that helps.

Example

Green Cell
  • 4,677
  • 2
  • 18
  • 49
  • This is very useful, thank you very much! I did not know about the OpenMayaUI.MQUtil, so will look at how I can use it to find the Script Editor main window. Great things to research further, cheers. – alex04 Mar 04 '20 at 17:51
  • Yes it has a few other convenience methods to fetch other objects, very cool to have. If this has answered your question then consider accepting this answer, otherwise edit your original post to clarify more. – Green Cell Mar 05 '20 at 06:14