It is actually the expected behavior with Qt, but just a little more
pronounced because it is in the persistent python sessions of Maya.
In python, by default a widget would only be deleted indirectly if it
either had no parent and its reference went out of scope, or its parent was
deleted which deletes the children. In C++ you would be more directly
responsible for deleting a widget on the heap with no parent.

Also, I am not supervised that it would be unstable to use shiboken.delete
on "self" within its close event. Its similar to how the docs say you
shouldn't delete objects from within their own slots and callbacks, but
rather use widget.deleteLater()

There is a widget attribute that tells a widget that it should be deleted
on close: WA_DeleteOnClose
I threw together an example which can run both on a standalone system
PySide, or from within Maya. It shows both ways, based on your initial
example, of either having the widgets delete themselves or not:
http://pastebin.com/h3A3saah

Usage:

# from a standalone shell
$ ./windowTest.py
$ ./windowTest.py -delete

# from within maya
import windowTest
windowTest.start(delete=True)

You will see it pop up a number of child windows, and then continually
print the count of existing child windows (stops automatically after it
reaches 0, or after 15 seconds)



On Thu, Jul 11, 2013 at 5:27 AM, Jan: <jan....@gmail.com> wrote:

> Oh you can also add a check for visibility so it doesn't destroy any
> windows that are still in the users view.
> i.e.
>
> if pm.window( 'testWindow', query = True, exists = True ) :
>             print 'exists'
>             if not pm.window( 'testWindow', query = True, visible = True )
> :
>                 print 'not visible'
>                 pm.deleteUI( 'testWindow' )
>
>
>
> 2013/7/10 Jan: <jan....@gmail.com>
>
> Hi Mike,
>>
>> I ran into the same problem and the easiest way I came up with was just
>> by forcing the window to be destroyed every time the script ran.
>> Just like you would do in the old days with mel :)
>>
>> if pm.window( 'testWindow', query = True, exists = True ) :
>>         pm.deleteUI( 'testWindow' )
>>
>> So add those lines to your script and that deletes the old window.
>>
>> Jan
>>
>>
>> 2013/7/10 Mike Malinowski (LIONHEAD) <mich...@microsoft.com>
>>
>>  Hey All,****
>>>
>>> ** **
>>>
>>> I’m getting an issue whereby my PySide windows are not being properly
>>> destroyed when they’re closed.****
>>>
>>> ** **
>>>
>>> ** **
>>>
>>> <code>****
>>>
>>> import pymel.core as pm****
>>>
>>> ** **
>>>
>>> from PySide.QtCore import *****
>>>
>>> from PySide.QtGui  import *****
>>>
>>> import shiboken****
>>>
>>> import maya.OpenMayaUI as mui****
>>>
>>> ** **
>>>
>>> def getMayaWindow():****
>>>
>>>     ptr = mui.MQtUtil.mainWindow()****
>>>
>>>     return shiboken.wrapInstance(long(ptr), QWidget)****
>>>
>>> ** **
>>>
>>> class testWindow( QMainWindow ) :****
>>>
>>>     ****
>>>
>>>     def __init__ ( self, parent=getMayaWindow() ) : ****
>>>
>>>         QMainWindow.__init__( self, parent=parent )****
>>>
>>>         self.setObjectName("testWindow")****
>>>
>>>         self.layout = QHBoxLayout()****
>>>
>>>         self.label  = QLabel("test panel")****
>>>
>>>         self.layout.addWidget(self.label)****
>>>
>>>         self.setLayout(self.layout)****
>>>
>>>     ****
>>>
>>> window = testWindow()****
>>>
>>> window.show()****
>>>
>>> ** **
>>>
>>> </code>****
>>>
>>> ** **
>>>
>>> Run the code above a couple of times, and close the window each time.
>>> Now run this :****
>>>
>>> ** **
>>>
>>> <code>****
>>>
>>> from PySide.QtCore import *****
>>>
>>> from PySide.QtGui import *****
>>>
>>> import shiboken****
>>>
>>> ** **
>>>
>>> import pymel.core      as pm****
>>>
>>> import maya.OpenMayaUI as mui****
>>>
>>> ** **
>>>
>>> def getMayaWindow():****
>>>
>>>     ptr = mui.MQtUtil.mainWindow()****
>>>
>>>     return shiboken.wrapInstance(long(ptr), QWidget)****
>>>
>>>     ****
>>>
>>> for child in getMayaWindow().children() :****
>>>
>>>     ****
>>>
>>>     objName = child.objectName()****
>>>
>>>     if objName == "" : print "->"+str(child)****
>>>
>>>     else : print "->" + objName****
>>>
>>> print len(getMayaWindow().children())****
>>>
>>> </code>****
>>>
>>> ** **
>>>
>>> Notice that there are multiple instances of the window still there. The
>>> only way I can currently clean it up is to add this to the QMainWindow
>>> class :****
>>>
>>> ** **
>>>
>>> <code>****
>>>
>>>     def closeEvent( self, event ) :****
>>>
>>>         QMainWindow.closeEvent( self, event )****
>>>
>>>         shiboken.delete(self)****
>>>
>>> </code>****
>>>
>>> ** **
>>>
>>> However, some of my dynamic UI’s cause a crash with this override, and
>>> it feels a little heavy handed to have to override the closeEvent. Has
>>> anyone else hit this issue?****
>>>
>>> ** **
>>>
>>> Mike****
>>>
>>> --
>>> 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 post to this group, send email to python_inside_maya@googlegroups.com
>>> .
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
>  --
> 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 post to this group, send email to python_inside_maya@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 post to this group, send email to python_inside_maya@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to