On Wed, Feb 6, 2019, 4:20 PM blossom ghuntla <bghuntla...@gmail.com> wrote:

> Hi Justin, its a question about the technique that i have used is it
> appropriate for longer term?
>


Sorry for the delayed reply.
Using the global window variable in the module could work fine. No one
should be using the reload() command in production anyways because it can
lead to broken code. It's only for specialised situations or testing.
Another way is if you look up the singleton pattern. But I leave that to
you to Google.

Hi Michael Boon, as per your suggestion i'll look into OpenMayaUI
>
>
>
> On Wed, Feb 6, 2019 at 4:03 AM Michael Boon <boons...@gmail.com> wrote:
>
>> For simple situations, this technique comes with some risk that you might
>> override or otherwise lose the global variable. Make sure you give it a
>> good, unique name. Note that if it's a module variable, and you reload the
>> module, Python does not delete the variable, so that should still work.
>>
>> The Maya documentation recommends you use
>> maya.OpenMayaUI.MQtUtil.findControl to find your windows by name, and then
>> shiboken.wrapInstance to bring it into Python. Assuming you continue to
>> make your window more sophisticated, and it ends up being saved in the Maya
>> workspace and automatically reopened when Maya opens, I think you will need
>> to do it that way.
>>
>> On Tuesday, 5 February 2019 17:31:11 UTC+11, blossom ghuntla wrote:
>>>
>>> yes
>>> but again is this the preferred technique
>>>
>>> On Tue, Feb 5, 2019 at 11:53 AM Justin Israel <justin...@gmail.com>
>>> wrote:
>>>
>>>>
>>>>
>>>> On Tue, Feb 5, 2019, 5:27 PM blossom ghuntla <bghun...@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 <justin...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>>
>>>>>>
>>>>>> On Sat, Feb 2, 2019, 5:30 AM blossom ghuntla <bghun...@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 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/5fdc601d-a4c5-47fa-85b2-4113652da455%40googlegroups.com
>> <https://groups.google.com/d/msgid/python_inside_maya/5fdc601d-a4c5-47fa-85b2-4113652da455%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 python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAJsZk%2BVreUJk%3D_TPN5GJ1SZERHH8QL_ut_Mt%2Bbg5x_HMXmWKNA%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAJsZk%2BVreUJk%3D_TPN5GJ1SZERHH8QL_ut_Mt%2Bbg5x_HMXmWKNA%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/CAPGFgA10%3DG72Vcake6-2UU%3DXasgaKc%3DmZu51494thwiSZtpURg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to