[Maya] WorkspaceControl, MayaQWidgetDockableMixin remember configuration?


I’m building different tools with their own UIs, and most of them use dockable windows using: class DockableWindow(MayaQWidgetDockableMixin, QtWidgets.QMainWindow) class. Here’s a bit outdated but mostly still relevant gist of what I use: Maya - Creating PySide windows in Maya 2014-2018+, with docking · GitHub

I just realized that I can very conveniently open different tools and stack them together, not just to Maya’s main window. Naturally it’s would be great if one could just re-open the whole stack of tools and not go through openning each one and docking it again.

So what ways are there to remember state of custom dockable UI windows in Maya? Any pointers?

One of the parameters in a workspaceControl is uiScript.

When a workspaceControl is saved with a workspace layout, the code string stored in uiScript will be ran upon Maya startup (or when switching back to this workspace layout, from another). It’s intended for code to build a UI, but it can be anything technically. The trick here is that the workspaceControl object now exists before that code is executed. So if you have code that attempts to make a workspaceControl, of the same name, now you have to handle that. :slight_smile:

Additionally, another parameter, retain, presents different problems when set to either True or False. Although a UI may appear closed, it may in fact be “hidden”, not closed, which fires a different event (this is when retain is True).

Finally, if you have “floating” workspaceControls stacked on each other - this may need to be handled differently. I believe a workspace layout only saves docked windows on Maya’s main window, but I cannot confirm.

1 Like