PDA

View Full Version : C++ API: what are the names of maya windows?


nuttynut
11-23-2010, 04:06 PM
I'm trying to use the MQtUtil::findWindow() function to get the "Uv Texture Editor" QWidget*.

I've tried:
QWidget* window = MQtUtil::findWindow("TextureViewWindow");

// And
QWidget* window = MQtUtil::findWindow("Uv Texture Editor");


...without luck.

Does anyone know how to get a window name?

zoharl
11-24-2010, 09:03 PM
Try Visual Studio spy++ to find the window name.

schizofrantic
11-25-2010, 05:23 AM
You can turn on output all in script editor, then when you open them up it should tell you the name.

nuttynut
11-25-2010, 09:02 AM
TextureViewWindow;
tearOffPanel "UV Texture Editor" "polyTexturePlacementPanel" true;
addTextureWindow polyTexturePlacementPanel1;
createModelPanelMenu modelPanel1;
createModelPanelMenu modelPanel2;
createModelPanelMenu modelPanel3;
createModelPanelMenu modelPanel4;
buildPanelPopupMenu scriptEditorPanel1;
buildPanelPopupMenu [B]polyTexturePlacementPanel1[B];
// Result: polyTexturePlacementPanel1Window //

Yeah, that should be it! Thanks

nuttynut
11-26-2010, 09:22 AM
Here's the code to get the window or panel (in case it's docked)

// First look for the panel, it could be docked and is most likely to be found
QWidget* polyTexturePlacementPanel = MQtUtil::findLayout("polyTexturePlacementPanel1");
QWidget* polyTextureWindow;

if (polyTexturePlacementPanel != 0)
{
// Hmm ok, we've found the panel, maybe we can now find the window
QWidget* polyTextureWindow = MQtUtil::findWindow("polyTexturePlacementPanel1Window");
if (polyTextureWindow != 0)
{
// Nice, we've found the window so we now know it's not docked
// Meh, for example's sake we'll just close it!
polyTextureWindow->close();
}
}
else
{
// Hmm the panel doesn't exist, so we can assume the window doesn't exist either
// So by calling this command we ensure it's initialized for the first time
MGlobal::executeCommand("TextureViewWindow;");

// Now we should find the panel AND window without problems
polyTexturePlacementPanel = MQtUtil::findLayout("polyTexturePlacementPanel1");
polyTextureWindow = MQtUtil::findWindow("polyTexturePlacementPanel1Window");

// Maybe it's safer to check if these were actually found again.
// ...

// Maybe now I can close the window as now I have the pointer, and the user did not have that window open yet
polyTextureWindow->close();
}

nuttynut
11-26-2010, 09:33 AM
There is also a dirty way to find a window, loop through the a huge list of widgets and try and find a matching name.

Not advisable

// This is a dirty way of finding a window, you should use MQtUtil::findWindow instead
// Only do this if you have a good reason to

// Get the maya app
QApplication* mayaApp = dynamic_cast<QApplication*>(QCoreApplication::instance());

// Get the maya QMainWindow
QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(MQtUtil::mainWindow());

// Open up the UvTextureEditor so we can be sure it exists in the app's top-level widgets
MGlobal::executeCommand("TextureViewWindow;");

// Get all top-level (Windows, tear-off menu's, ..) widgets, and check if the windowTitle matches up
QWidgetList allWidgets = mayaApp->topLevelWidgets();
QWidget* uvTextureEditorWindow = 0;

// We need to iterate over all top level widgets to find a window with the matching name. But I've noticed this is somewhere
// at the beginning, so it only loops +- 25 times
for (int i=0; i<allWidgets.length(); ++i)
{
QWidget* widget = allWidgets.at(i);

// To see what we're finding...
MGlobal::displayInfo(MQtUtil::toMString(widget->windowTitle()));

if (widget->windowTitle() == "UV Texture Editor")
{
// This is it!
uvTextureEditorWindow = widget;
break;
}
}

// Do stuff with that window
if (uvTextureEditorWindow != 0)
{
// For example: now you can close it again :)
uvTextureEditorWindow->close();
}

CGTalk Moderation
11-26-2010, 09:33 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.