Get a callback when ui created?

Get a callback when ui created?

icapathos
Advocate Advocate
998 Views
4 Replies
Message 1 of 5

Get a callback when ui created?

icapathos
Advocate
Advocate

In case of "uiDeleted", I can do that easily with MUiMessage or scriptJob command.

But, when a ui is created, how can I catch it?

0 Likes
999 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Hi icapathos

 

So if I am understanding you correctly, you want to get a callback when your UI is opened...not deleted?

 

Usually you don't need to do anything special for this because you already have a hook in your CreateUI method and you can hook up any logic there. For example:

 

proc OnMyUIOpened()
{
    // Do callback stuff here
}

global proc OpenMyUI()
{
    window -title "My UI";
    // Do window stuff here
    
    OnMyUIOpened();    
}

Hope that helps

 

Mike

0 Likes
Message 3 of 5

icapathos
Advocate
Advocate

Right,

As you mentioned, I want to get a callback when "ui created".

But, unfortunately the ui what I want to get callback is modelEditor.

I cannot jump into the process of creating modelEditor.

0 Likes
Message 4 of 5

Anonymous
Not applicable

Hi

 

Yeah you can't hook up directly to "any" modelPanel being opened, but you can hook up to your own one using the method above. I guess it depends on what exactly you are trying to do.

 

Because you're using modelPanels, one alternative thing you can do is to apply any changes to all existing panels in the current application. The default modelPanels in Maya actually don't get deleted when you close them, just hidden, so you could run a process triggered off some other event which applied your settings to all existing panels. I know this is not exactly the same as a callback, but might give you what you need. e.g.

 

string $allPanels[] = `getPanel -type modelPanel`;
for ($panel in $allPanels)
{
    // Apply settings here
}

Hope it helps

 

Mike

 

0 Likes
Message 5 of 5

icapathos
Advocate
Advocate

At last, I finally decided to use scriptJob as below.

 

def _whenModelEditorCreated():
    ....

cmds.scriptJob(event=["modelEditorChanged", _whenModelEditorCreated])

The event "modelEditorChanged" calls when something changes in all modelEditors including created.

So, it works for my purpose.

BUT it calls more than I need, so I have to say that I WILL NOT SUGGEST IT :'‑)

 

 

0 Likes