Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

catching close event of MayaQWidgetDockableMixin in Maya2017

catching close event of MayaQWidgetDockableMixin in Maya2017

Anonymous
Not applicable
4,626 Views
6 Replies
Message 1 of 7

catching close event of MayaQWidgetDockableMixin in Maya2017

Anonymous
Not applicable

I'm creating a dockable window from MayaQWidgetDockableMixin. The window creates and manages some callbacks.

In Maya 2016 the function "dockCloseEventTriggered" was called when the window was closed and I could clean up my callbacks.

But in 2017 this function is not called anymore. I tried using the new "closeCallback" that get's passed to the workspaceControl but it seems the window is already destroyed at this moment and  I can't find a way to clean the callbacks. The callbacks remain and keep messing up my scene.

 

Is there a new way to catch the close event of a MayaQWidgetDockableMixin?

 

Thanks,

Nico

0 Likes
Accepted solutions (1)
4,627 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

I'm also encountering this issue - did you have any conclusion? 

0 Likes
Message 3 of 7

Anonymous
Not applicable

I've spent some time looking into this now, eventually comparing the mayaMixin.py files between 2016 and 2017 

It appears in 2016 they created a MayaQDockWidget *within* the MayaQDockableMixin and propogated the signal of closeEvent on the QDockWidget to the MayaQDockableMixin. 

In 2017 they have removed the MayaQDockWidget and left the signal inside MayaQDockableMixin unhooked!! ( Jeez! like really?! ) 
Instead, in 2017 they have replaced this functionality with a new option for .show( closeCallback=... ) which initially looked really cool as they were handling the workspace creation + cleanup, the big gotcha however is you *cannot* pass a bound/unbound method to the closeCallback, you have to pass a string that can be evaluated such as "import MyTest\rMyTest.runSomeMethod()"

This seems... like a step back in my opinion, i have yet to reach a answer i find satisfactory as now to trigger an event on the close of my Qt interface, i can't just call its internal cleanup method, i need to import and assign the interface again to call its shutdown.... 

I'm going to head home and think on this over the weekend, i'll return if i find a happy solution

Message 4 of 7

Anonymous
Not applicable

Back at work digging into this more,

According to the Maya 2017 SP4 Release notes

"

MAYA-76709 :mayaMixin functions floatingChanged and dockCloseEventTriggered are not called with Workspace controls

"

This has been fixed, but diffing the code - nothing has changed.... also now im getting error spam re:

"
# AttributeError: 'module' object has no attribute 'workspaceControlClosed'
# AttributeError: 'module' object has no attribute 'workspaceControlReparented'
"

Whenever working with workspaces....

I'm getting Maya 2018 to see if its fixed in there, if not ill roll back to 2017 vanilla and apply my own patch ( will post code if it works )

@Anonymous support peeps - any comment on why the fix was in the patch notes but there is no change in code?

0 Likes
Message 5 of 7

Anonymous
Not applicable
Accepted solution

Ok

Finished rebuilding my dock factory in 2018 as the signals work there again as expected,

You may come across a internal C++ runtime error though when using workspace retain=False - it appears that there is a "workspaceControlDeleted" method *and* a __del__ method of the mixin that both attempt to remove the mixin class - the first will run successfully, the second will cause the C++ error

I resolved this by having a dockable factory i call with UI files - in my factory i override the __del__ with pass to avoid the duplicate call - all seems stable once more - huzzah!

Message 6 of 7

Anonymous
Not applicable

Hi there, sorry to bump into this old thread.

I was using Maya 2018 and it seems that I am getting the issue - unable to 'capture' the close events (have used either closeEvent or the dockCloseEventTriggered).

 

Accordingly to your last post, do correct me if I am wrong, for the workspaceControls - should I or should I not delete them if found?

FYI - I did try it out in Maya 2017, while sing dockCloseEventTriggered seems to have work, and I did factor in my function to delete any existing workspaceControls if found, I am still unable to figure out why it is not working for Maya 2018.

Message 7 of 7

Anonymous
Not applicable

Hi no worries, Will help if i can!

So its been a while but the jist of what i have is a Dockable class that derives from the MayaQWidgetDockableMixin and my UiClass

 

__init__

  1. Predict what the workspace name by the name of the ui file
  2. Attempt to remove any existing workspaces matching that predicted name
  3. Call Super 

def dockCloseEventTriggered()

  1. Call application.postEvent(QtCore.QEvent(QtCore.QEvent.Close))
  2. Call application.sendPostedEvents()

def close():

  1. Call a cleanup function ( removes workspace + sets widget parent to be None / deletes self ) 
  2. Call super of close

Thats about it 🙂 Hth!

0 Likes