You have a number of bugs in this script.

First, the reason you are seeing that error is because your cleanup code 
isn't doing what you think it is. You have a closeEvent() method defined on 
your class, but simply having this method doesn't do anything. You might be 
thinking of Qt, where a QWidget has a closeEvent() method? But your window 
is just an object. What is happening is that every time you close the 
window, you leak the callbacks. Then the callbacks keep trying to fire when 
selection changes, but the window and menu instance no longer exists. So 
maya is left broken at that point. What you can do is remove that 
closeEvent() code and add this to the end of your register_callback() 
method:

    cmds.scriptJob(runOnce=True, uiDeleted=[self.win, 
self.remove_callbacks])

And then also make sure to capture the window name in your __init__():

    self.win = myWindow = cmds.window(width=150, h=200)

The next bug is that your selection changed callback breaks selection 
completely in Maya. When selection changes, you trigger reload() which then 
triggers drawRadioMenu() which then rebuilds the menu AND changes selection 
to a camera... and...selection changed is triggered :-) Now selection no 
longer works in the viewport.
Additionally, you are registering the callbacks too soon, in your 
__init__(), before the window is shown and the required UI is built. This 
should be moved into your show() method after the menu is created. And 
then, don't change the selection in your selection callback. 

Is your goal to update the menu when the cameras change in the scene, or is 
it to match the selection of the cameras to your radio menu? I think using 
event callbacks here might be overkill, as you can get what you need if you 
just use the feature of the menu that will callback when it is about to be 
shown. You can completely sync your menu to the current list of camera and 
set it to the selected camera each time the menu is about to show.

Lastly, I am not sure what is happening when you keep creating the 
radioMenuItemCollection over and over in the callback. The original menu is 
never deleted, so my guess is that you keep building up these collection 
objects attached to the menu. But then again I don't have too much 
experience with radioMenuItemCollection lifetimes. It says they would get 
deleted when the menu gets deleted. Maybe you need to make sure to delete 
this collection each time as well?

Justin

-- 
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/3fcd6991-c948-4cb1-b86b-b00bc67c4784%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to