yes but again is this the preferred technique On Tue, Feb 5, 2019 at 11:53 AM Justin Israel <justinisr...@gmail.com> wrote:
> > > On Tue, Feb 5, 2019, 5:27 PM blossom ghuntla <bghuntla...@gmail.com> > wrote: > >> Hello Justin, >> Thanks for the reply >> and sorry for late reply i was not well >> >> >> *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?* >> yes >> >> >> *Or do you want it to leave the exist one and show a new copy? * >> no >> >> *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. * >> the way i am doing is >> i have created multiple classes and saved as a package >> and i have the path saved in env variable >> so i just import the module and do exactly as you mentioned above execute >> main() >> >> so i saved the above import in the shelf >> clicking it opens the UI >> clicking the shelf button second time should close the existing UI and >> open the UI again and, even if the UI is closed its instance should be >> deleted and, when clicked on shelf button again create a new UI(instance) >> probably this is what you meant >> >> *What is the logic behid this?* >> 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 >> win = CreateNewWin(...) >> win.setAttribute(QtCore.Qt.WA_DeleteOnClose, True) >> >> and which is the most preferred one >> > > Based on your clarifications, you want to check if your win global > variable is not None, and then call win.deleteLater() > This will kill the previous window so that you may create a new instance. > > >> On Fri, Feb 1, 2019 at 11:49 PM Justin Israel <justinisr...@gmail.com> >> wrote: >> >>> >>> >>> On Sat, Feb 2, 2019, 5:30 AM blossom ghuntla <bghuntla...@gmail.com> >>> 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 python_inside_maya+unsubscr...@googlegroups.com. >>>> 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 a topic in the >>> Google Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/python_inside_maya/-O5JDzj0X1s/unsubscribe >>> . >>> To unsubscribe from this group and all its topics, send an email to >>> python_inside_maya+unsubscr...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA31y5iQ9MC6JVKVMKoaMKh%3DmNtZwHm6GOKVDo_zWWMxJg%40mail.gmail.com >>> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA31y5iQ9MC6JVKVMKoaMKh%3DmNtZwHm6GOKVDo_zWWMxJg%40mail.gmail.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 python_inside_maya+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/CAJsZk%2BWPceNG%3D2UAQunWh0XN7EBXmgs9CDiBhhUVb80b%3D%2BjUFA%40mail.gmail.com >> <https://groups.google.com/d/msgid/python_inside_maya/CAJsZk%2BWPceNG%3D2UAQunWh0XN7EBXmgs9CDiBhhUVb80b%3D%2BjUFA%40mail.gmail.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 a topic in the > Google Groups "Python Programming for Autodesk Maya" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/python_inside_maya/-O5JDzj0X1s/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > python_inside_maya+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0VTf7rVU%2Beo8-evMecStw%3Dj9Qtd3en0QVg5_xOyg7f4w%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0VTf7rVU%2Beo8-evMecStw%3Dj9Qtd3en0QVg5_xOyg7f4w%40mail.gmail.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 python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJsZk%2BVdsuKK5dur-Fnwg1xSDHM8c4cGQyoC2Y39mzwJiYUS5w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.