how can you learn via python script that your window is existing and delete it ?

how can you learn via python script that your window is existing and delete it ?

Anonymous
Not applicable
1,434 Views
3 Replies
Message 1 of 4

how can you learn via python script that your window is existing and delete it ?

Anonymous
Not applicable

I am using PySide to make UI in motion builder , but i can't find any command which will check for windows existence and if I want, to delete it.

Something like :

if cmds.window('someUi', exists=True):

     cmds.deleteUI('someUi' , wnd=True)

0 Likes
Accepted solutions (1)
1,435 Views
3 Replies
Replies (3)
Message 2 of 4

ThomasGryphon
Contributor
Contributor

My 2¢; generally I include a function at the end of my modules along the lines of

def Launch():
    try:
        test_ui.deleteLater()
    except:
        pass
    test_ui = MyMainWidgetClassName()
    try:
        test_ui.show()
    except Exception as e:
        test_ui.deleteLater()
        # traceback.print_exc()
# ... or ...
# print e

Then when you create your PySide window via ModuleName.Launch(), any prior existing MyMainWidgetClassName objects (that were created the same way, in the same sesssion) *should* be destroyed.

0 Likes
Message 3 of 4

ThomasGryphon
Contributor
Contributor
Accepted solution

... Ran out of time to edit after going away to triple check and it turns out that the above^ doesn't behave the same way as it does in Maya, so something more along the lines of this (at the end of your Module)

if __name__== "__builtin__" or __name__=="__main__":
    try:
        test.deleteLater()
    except:
        pass
    test = TestUi()
    test.create()
    test.show()

Does destroy the PySide object, but I personally don't like that approach; so anyone else with a better one, by all means.

0 Likes
Message 4 of 4

Anonymous
Not applicable

thanks to your idea , i got where to look at and this works for me : 

for gui in parent.children():

    if gui.__class__.__name__ == 'testUi':

           gui.close()