On Sat, Feb 2, 2019, 5:30 AM blossom ghuntla <[email protected]> wrote:
> Hello Guys, > > I have a query regarding shelf button of UI > i have created a ui with pyside2 and put it on the maya shelf > i click to open the ui it works well > as i do it for the second time it opens same UI for the second time > so is there a better way to write a main().close > would be very grateful if an example is provided > > > i found a reference on http://nathanhorne.com/pyqt-and-maya-2011/ > > def main(): > global win > try: > win.close() > except: pass > win = MyWindowClass() > win.show() > > Thank You. > The exact answer depends on how your shelf button code is actually launching the UI, and also then specific behavior you want. If your UI is still showing when they click the button a second time do you want it to close the existing one and show a new one? Or do you want it to leave the exist one and show a new copy? I'm guessing from your example that you keep a global reference to the UI instance that you launch, in your module, and that you probably launch it by calling a main() function. If that is what you do, you can try calling win.deleteLater() to kill the existing one and catch the exception if it's not there. Or if you want to allow multiple brand new instances, you can just not use the global to that you create a new one each time, and then have it automatically delete itself on close with win = CreateNewWin(...) win.setAttribute(QtCore.Qt.WA_DeleteOnClose, True) > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/da0be90d-88fd-4e22-a25e-67c9e024d3d9%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/da0be90d-88fd-4e22-a25e-67c9e024d3d9%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA31y5iQ9MC6JVKVMKoaMKh%3DmNtZwHm6GOKVDo_zWWMxJg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
