RE: [Maya-Python] In 2014, mayapy errors on exit if sceneAssembly plugin loaded

2013-07-10 Thread Mike Malinowski (LIONHEAD)
Thanks for sharing Paul.

Mike

From: python_inside_maya@googlegroups.com 
[mailto:python_inside_maya@googlegroups.com] On Behalf Of Paul Molodowitch
Sent: 09 July 2013 18:29
To: python_inside_maya
Subject: [Maya-Python] In 2014, mayapy errors on exit if sceneAssembly plugin 
loaded

Thought I should let other people know about this, in case they were 
experiencing similar problems: we noticed that, when using 2014's mayapy 
interpreter, it would always segfault when exiting.

We tracked the issue down to a particular plugin, the sceneAssembly plugin. If 
this plugin is not loaded, mayapy will exit cleanly.

We reported this to Autodesk, and they suggested using os._exit... 
unfortunately, this would require us to modify every single mayapy script we 
have (including any mayapy -c uses), wrap them to catch SystemExit 
exceptions, and instead us os._exit.  Plus, python would no longer do it's 
normal cleanup (ie, output buffers wouldn't be flushed, and os-level resources 
like file handles might not get released, etc).

So, it seems much easier to just not use sceneAssembly.  The only trick here is 
that simply unloading it won't work - if the plugin was EVER loaded, mayapy 
will still crash on exit - and maya will by default set this plugin to 
autoload.

To work around this, you can disable the setting of sceneAssembly to autoload 
for new users by sticking this somewhere in your site's maya startup (mel) code:
optionVar -iv oneTimeDefaultPluginLoad2013Update 1;

For users which already have started 2014 at least once, it will have already 
been set to autoload; so the next time maya starts up, the plugin will load, 
but you can prevent it from loading again by putting in code like this:
# check for and disable autoload of sceneAssembly plugin - will cause
# mayapy to exit with an error if loaded... get rid of this if they fix
# this bug...
if pm.versions.current() = pm.versions.v2014:
def sceneAssemblyDisable():
if pm.pluginInfo('sceneAssembly', q=1, loaded=1):
pm.pluginInfo('sceneAssembly', e=1, autoload=False)
# do this on selection changed, because need a way to delay this
# so we KNOW it's after the plugins have loaded.  executeDeferred
# and idleEvent both were too early...
pm.scriptJob(event=('SelectionChanged', sceneAssemblyDisable), 
runOnce=True)

(The reasoning for this somewhat strange logic is that, when userSetup.py runs, 
autoloaded plugins haven't been loaded yet. This would seem to be ideal, except 
that it seems to only way to turn OFF autoloading is AFTER the plugin has 
actually been loaded.  Nor can you even check to see if it WOULD be autoloaded. 
 So... we need a way to stall until AFTER all auto-loaded plugins have been 
loaded, check if the plugin WAS loaded, and if so, turn off it's autoload from 
then on...)

- Paul
--
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.commailto:python_inside_maya+unsubscr...@googlegroups.com.
To post to this group, send email to 
python_inside_maya@googlegroups.commailto: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.




[Maya-Python] Closing PySide windows in Maya

2013-07-10 Thread Mike Malinowski (LIONHEAD)
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.




Re: [Maya-Python] Closing PySide windows in Maya

2013-07-10 Thread Jan:
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.




Re: [Maya-Python] Closing PySide windows in Maya

2013-07-10 Thread Jan:
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.




[Maya-Python] Getting the main file menu in modern days

2013-07-10 Thread Ævar Guðmundsson
Hi there

  I use this to get the Maya file menu and start populating it with various 
things:

import maya.cmds as cmds
from pymel.core import menuItem,melGlobals
from maya.mel import eval as melcommand
gMainFileMenu=cmds.menu(melGlobals['$gMainFileMenu'],q=1,postMenuCommand=1)
melcommand('string $fileMenuRefreshCmd = `menu -q -postMenuCommand 
$gMainFileMenu`')
melcommand('eval($fileMenuRefreshCmd)')  
defaultMenuItems=cmds.menu(melGlobals['$gMainFileMenu'],q=1,ia=True)

  It's embarrassing to admit, but in my defense it just works and I've been 
copy pasting this example into my code for years.  Finally figured to step into 
modern days and figure out how to do this using a little bit friendlier 
syntax...

  Problem being I have no idea how to do that and am still sat with this 
Frankenstein code I wrote dragging along with me.

  Can someone please translate this for me into a more syntax and sharable 
friendly way or point me at a good page to read up on this?

  Thanks in advance.
-Ævar

-- 
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.