[Maya] Update GUI when reference namespace changes

I have a PySide GUI in Maya that deals with referenced files. The GUI contains a QTabWidget, where each tab corresponds to a reference node. The name displayed on each tab is the namespace of the reference node.

The problem is that when a user goes into the Reference Editor and changes the namespace, my GUI does not know about it. How can I get the tab names to update when the namespace changes?

I’ve been looking into script jobs and callbacks, but I’m not sure what trigger to look for. I hoped I could do an attribute changed callback on the reference node, but the namespace is not an attribute of that node. Perhaps I am going in the wrong direction entirely.

You could use a node name changed callback, but what I would probably do is have some state in your code that maps each tab to a reference node and add an on-focus callback to your UI that checks the namespace of each reference node.

If you look in the attribute editor template code for the reference node, it gets the namespace using:

referenceQuery -namespace -shortName $refNodeName

I was hoping that the GUI would update without having to put the focus on it. But I guess it is not crucial in this case. If I get rid of that requirement, this is a great solution.

I cannot think of another way to track namespace changes outside of using a name changed callback. Even if you hijacked the reference editor namespace callback, you’re still only accounting for changes through that one method, and not direct calls to the file command.

That being said the API does let you attach name changed callbacks to single nodes. It’s a little simpler in your case since you are only tracking the namespaces of references, so you wouldn’t have to worry about nodes being deleted or moved into another namespace. I think additionally you’d only need to track when the reference gets unloaded, and remove the name changed callback in that case.

What node would I attach the name changed callback to? I don’t think I can attach it to the reference node because the name of that node doesn’t change. Only the namespace associated with the reference node changes. (I will run off and try it real quick, though, just to be sure.)

Edit: Yeah, just tried it. Name changed callback on the reference node doesn’t trigger when the namespace changes.

Hrm, bummer. I was assuming it would trigger. Was that using an MNodeCallback or a scriptJob? They may behave differently

That was using an MNodeMessage callback. I just tried using a script job, and that didn’t work either. I also made callbacks for all the triggers in MEventMessage and MConditionMessage, except for idle and busy events, and none of those trigger either.

I did one final test. I attached the name changed callback (MNodeMessage) to one of the nodes within the namespace, like “testRef:pCube1”. That did trigger. The thing with that method is that I would have to know the name of a node from the referenced file or find one.

So it seems like there are two options:
[ul]
[li]Use a focus event on the GUI to update the namespace
[/li][LIST]
[li]Pros: Do not have to know about the contents of the referenced file/namespace.
[/li][li]Cons: Will not update the GUI until the user clicks on its window.
[/li][/ul]
[li]Attach a name changed callback to a node from the referenced file:
[/li][ul]
[li]Pros: The GUI will update immediately.
[/li][li]Cons: Have to know about or find a node from the referenced file.
[/li][/ul]
[/LIST]
I’m still debating which way is better for my particular GUI. Thanks for all the help!

Oh that was actually my intent when suggesting the name changed callback: query the reference node to find a node contained by that reference, and attach a callback to that.