def __init__(self, node, parameter, **kw):

        topLevelUI = maya.cmds.columnLayout()
        IECoreMaya.ParameterUI.__init__(self, node, parameter, topLevelUI,
                                        **kw)

        self.__column = maya.cmds.columnLayout(parent=topLevelUI)

        row = maya.cmds.rowLayout(
            parent=topLevelUI,
            numberOfColumns=2,
            columnAlign=(1, "right"),
            columnWidth2=[
                IECoreMaya.ParameterUI.textColumnWidthIndex,
                IECoreMaya.ParameterUI.singleWidgetWidthIndex
            ])

        maya.cmds.text(parent=row,
                       label=self.label(),
                       font="smallPlainLabelFont",
                       align="right",
                       annotation=self.description())

        addButton = maya.cmds.button(parent=row,
                                     label='Add Item',
                                     command=self._createCallback(
                                         self.__addItem))

        self.__fields = []

        self.__attributeChangedCallbackId = IECoreMaya.CallbackId(
            maya.OpenMaya.MNodeMessage.addAttributeChangedCallback(
                self.node(), self.__attributeChanged))

        self.replace(self.node(), self.parameter)
Esempio n. 2
0
    def test(self):

        # callback function just counts the number of times it has been invoked
        CallbackIdTest.numCalls = 0

        def callback(node, name, userData):

            CallbackIdTest.numCalls += 1

        # make a sphere and get the MObject from it
        sphere = maya.cmds.sphere()[0]
        s = maya.OpenMaya.MSelectionList()
        s.add(sphere)
        o = maya.OpenMaya.MObject()
        s.getDependNode(0, o)

        # attach a name changed callback
        c = IECoreMaya.CallbackId(
            maya.OpenMaya.MNodeMessage.addNameChangedCallback(o, callback))

        # check that the callback is invoked
        self.assertEqual(CallbackIdTest.numCalls, 0)
        sphere = maya.cmds.rename(sphere, sphere + "Different")
        self.assertEqual(CallbackIdTest.numCalls, 1)

        # delete the CallbackId object and make sure the callback is removed and therefore not invoked any more
        del c
        sphere = maya.cmds.rename(sphere, sphere + "DifferentAgain")
        self.assertEqual(CallbackIdTest.numCalls, 1)

        # also check that maya isn't holding onto any unecessary references to the callback function.
        w = weakref.ref(callback)
        del callback
        self.assertEqual(w(), None)
Esempio n. 3
0
	def __init__( self, 
		key=None,
		callback=None,
		title="Choose a file",
		path=None,
		**kw
	) :
	
		self.__key = key if key else "__global"

		self.__callback = callback
		
		self.__window = maya.cmds.window( title=title, mb=True )
		self.__bookmarksMenu = maya.cmds.menu( parent=self.__window, label="Bookmarks", postMenuCommand=self.__buildBookmarksMenu )

		# We need to turn the user closing the window into a 'cancel' event.
		callback = maya.OpenMayaUI.MUiMessage.addUiDeletedCallback( self.__window, self.__cancelled ) 
		self.__deletionCallback = IECoreMaya.CallbackId( callback )

		self.__browser = IECoreMaya.FileBrowser( self.__window, **kw )

		if path == "last" :
			path = FileDialog.__lastPath( self.__key )

		self.__browser.setPath( path if path else os.getcwd() )

		self.__browser.selectSignal.connect( self.__selected )
		self.__browser.cancelSignal.connect( self.__cancelled )

		maya.cmds.showWindow( self.__window )	
	def replace( self, node, parameter ) :

		IECoreMaya.ParameterUI.replace( self, node, parameter )

		self.__updateLabel()

		self._addPopupMenu( parentUI=self.__popupControl, attributeName = self.plugName(), button1=True )
		
		self.__attributeChangedCallbackId = IECoreMaya.CallbackId(
			maya.OpenMaya.MNodeMessage.addAttributeChangedCallback( self.node(), self.__attributeChanged )
		)
Esempio n. 5
0
	def __init__( self, topLevelUI ) :

		instanceRecord = IECore.Struct()
		instanceRecord.instance = self
		instanceRecord.callbacks = []
		# Saves errors in batch if UI work is still done....
		if not maya.cmds.about( batch=True ):
			instanceRecord.uiDeletedCallbackId = IECoreMaya.CallbackId( maya.OpenMayaUI.MUiMessage.addUiDeletedCallback( topLevelUI, self.__uiDeleted, topLevelUI ) )
		UIElement.__instances[topLevelUI] = instanceRecord

		self.__topLevelUI = topLevelUI
			paramList.append( parameter )
			__getParameters( c.parameters(), paramList )
		
	elif isinstance( parameter, IECore.ClassVectorParameter ) :
		
		cl = parameter.getClasses( False )
		if cl :
			paramList.append( parameter )
			for c in cl :
				__getParameters( c.parameters(), paramList )
	
	else :
		paramList.append( parameter )
	
# We need to clear out the references we're holding on parameters when the scene changes
def _clearReferences( *args, **kwargs ) :

	global _ieCoreParameterClipboardUILastParameterList
	global _ieCoreParameterClipboardUILastNode
	global _ieCoreParameterClipboardUILastRoot
	
	_ieCoreParameterClipboardUILastParameterList = None
	_ieCoreParameterClipboardUILastNode = None
	_ieCoreParameterClipboardUILastRoot = None

_ieCoreParameterClipboardCallbacks = []
if hasattr( maya.cmds, "about" ) and not maya.cmds.about( batch=True ):
	_ieCoreParameterClipboardCallbacks.append( IECoreMaya.CallbackId( maya.OpenMaya.MSceneMessage.addCallback( maya.OpenMaya.MSceneMessage.kBeforeNew, _clearReferences ) ) )
	_ieCoreParameterClipboardCallbacks.append( IECoreMaya.CallbackId( maya.OpenMaya.MSceneMessage.addCallback( maya.OpenMaya.MSceneMessage.kBeforeOpen, _clearReferences ) ) )

    def __drawHeaderParameterControl(self, parameter, fnPH):

        ## \todo This would be so much easier if we could just use ParameterUI
        # instances for each of the controls. We can't because they all do their
        # own labelling and are layed out for an attribute editor. if we do the
        # todo in ParameterUI to remove the labels and stuff then we can do the
        # todo here.

        control = None

        parameterPlugPath = fnPH.parameterPlugPath(parameter)
        annotation = IECore.StringUtil.wrap(
            "%s\n\n%s" %
            (parameterPlugPath.split(".")[1], parameter.description), 48)
        if parameter.presetsOnly:

            control = maya.cmds.iconTextStaticLabel(
                image="arrowDown.xpm",
                font="smallBoldLabelFont",
                style="iconAndTextHorizontal",
                height=23,
                width=80,
                annotation=annotation,
            )
            IECoreMaya.Menu(IECore.curry(self.__presetsMenu, parameter),
                            control)
            IECoreMaya.Menu(IECore.curry(self.__presetsMenu, parameter),
                            control,
                            button=1)
            self.__presetParameters.append(parameter)
            self.__presetUIs.append(control)
            if self.__attributeChangedCallbackId is None:
                self.__attributeChangedCallbackId = IECoreMaya.CallbackId(
                    maya.OpenMaya.MNodeMessage.addAttributeChangedCallback(
                        self.__vectorParent().node(), self.__attributeChanged))

            self.__updatePresetLabel(len(self.__presetUIs) - 1)

        elif isinstance(parameter, IECore.BoolParameter):

            control = maya.cmds.checkBox(label="", annotation=annotation)
            maya.cmds.connectControl(control, parameterPlugPath)

        elif isinstance(parameter, IECore.FloatParameter):

            control = maya.cmds.floatField(annotation=annotation,
                                           minValue=parameter.minValue,
                                           maxValue=parameter.maxValue,
                                           width=45,
                                           pre=4)
            maya.cmds.connectControl(control, parameterPlugPath)

        elif isinstance(parameter, IECore.IntParameter):

            kw = {}
            if parameter.hasMinValue():
                kw["minValue"] = parameter.minValue
            if parameter.hasMaxValue():
                kw["maxValue"] = parameter.maxValue

            control = maya.cmds.intField(annotation=annotation, width=45, **kw)
            maya.cmds.connectControl(control, parameterPlugPath)

        elif isinstance(parameter, IECore.Color3fParameter):

            control = maya.cmds.attrColorSliderGrp(
                label="",
                columnWidth=((1, 1), (2, 30), (3, 1)),
                columnAttach=((1, "both", 0), (2, "both", 0), (3, "left", 0)),
                attribute=parameterPlugPath,
                annotation=annotation,
                showButton=False)

        elif isinstance(parameter, IECore.StringParameter):

            control = maya.cmds.textField(annotation=annotation, width=150)
            maya.cmds.connectControl(control, parameterPlugPath)

        elif isinstance(parameter, IECore.V2fParameter):

            control = maya.cmds.rowLayout(nc=2, cw2=(45, 45))

            column1 = maya.cmds.floatField(annotation=annotation,
                                           width=45,
                                           pre=4,
                                           parent=control)

            maya.cmds.connectControl(column1, parameterPlugPath + "X")
            column2 = maya.cmds.floatField(annotation=annotation,
                                           width=45,
                                           pre=4,
                                           parent=control)

            maya.cmds.connectControl(column2, parameterPlugPath + "Y")

        else:

            IECore.msg(
                IECore.Msg.Level.Warning, "ClassVectorParameterUI",
                "Parameter \"%s\" has unsupported type for inclusion in header ( %s )."
                % (parameter.name, parameter.typeName()))

        return control