示例#1
0
class locinatorClass(BaseMelWindow):
	from  cgm.lib import guiFactory
	guiFactory.initializeTemplates()
	USE_Template = 'cgmUITemplate'
	
	WINDOW_NAME = 'cgmLocinatorWindow'
	WINDOW_TITLE = 'cgm.locinator - %s'%__version__
	DEFAULT_SIZE = 180, 275
	DEFAULT_MENU = None
	RETAIN = True
	MIN_BUTTON = True
	MAX_BUTTON = False
	FORCE_DEFAULT_SIZE = True  #always resets the size of the window when its re-created


	def __init__(self):

		self.toolName = 'cgm.locinator'
		self.description = 'This tool makes locators based on selection types and provides ways to update those locators over time'
		self.author = 'Josh Burton'
		self.owner = 'CG Monks'
		self.website = 'www.cgmonks.com'
		self.version =  __version__ 
		self.optionVars = []

		self.currentFrameOnly = True
		self.startFrame = ''
		self.endFrame = ''
		self.startFrameField = ''
		self.endFrameField = ''
		self.forceBoundingBoxState = False
		self.forceEveryFrame = False
		self.showHelp = False
		self.helpBlurbs = []
		self.oldGenBlurbs = []

		self.showTimeSubMenu = False
		self.timeSubMenu = []
		

		#Menu
		self.setupVariables()
		self.UI_OptionsMenu = MelMenu( l='Options', pmc=self.buildOptionsMenu)
		self.UI_BufferMenu = MelMenu( l = 'Buffer', pmc=self.buildBufferMenu)
		self.UI_HelpMenu = MelMenu( l='Help', pmc=self.buildHelpMenu)
		
		self.ShowHelpOption = mc.optionVar( q='cgmVar_LocinatorShowHelp' )
		
		#Tabs
		tabs = MelTabLayout( self )
		TabBasic = MelColumnLayout(tabs)
		TabSpecial = MelColumnLayout( tabs )
		TabMatch = MelColumnLayout( tabs )
		n = 0
		for tab in 'Basic','Special','Match':
			tabs.setLabel(n,tab)
			n+=1

		self.buildBasicLayout(TabBasic)
		self.buildSpecialLayout(TabSpecial)
		self.buildMatchLayout(TabMatch)
		

		self.show()

	def setupVariables(self):
		self.LocinatorUpdateObjectsOptionVar = OptionVarFactory('cgmVar_LocinatorUpdateMode',defaultValue = 0)
		guiFactory.appendOptionVarList(self,'cgmVar_LocinatorUpdateMode')
		
		self.LocinatorUpdateObjectsBufferOptionVar = OptionVarFactory('cgmVar_LocinatorUpdateObjectsBuffer',defaultValue = [''])
		guiFactory.appendOptionVarList(self,'cgmVar_LocinatorUpdateObjectsBuffer')	
		
		self.DebugModeOptionVar = OptionVarFactory('cgmVar_LocinatorDebug',defaultValue=0)
		guiFactory.appendOptionVarList(self,self.DebugModeOptionVar.name)	
		
		self.SnapModeOptionVar = OptionVarFactory('cgmVar_SnapMatchMode',defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.SnapModeOptionVar.name)		
		
		#Old method...clean up at some point
		if not mc.optionVar( ex='cgmVar_ForceBoundingBoxState' ):
			mc.optionVar( iv=('cgmVar_ForceBoundingBoxState', 0) )
		if not mc.optionVar( ex='cgmVar_LocinatorShowHelp' ):
			mc.optionVar( iv=('cgmVar_LocinatorShowHelp', 0) )
		if not mc.optionVar( ex='cgmVar_LocinatorCurrentFrameOnly' ):
			mc.optionVar( iv=('cgmVar_LocinatorCurrentFrameOnly', 0) )
			
		if not mc.optionVar( ex='cgmVar_LocinatorBakingMode' ):
			mc.optionVar( iv=('cgmVar_LocinatorBakingMode', 0) )
			
		guiFactory.appendOptionVarList(self,'cgmVar_LocinatorShowHelp')	


	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	# Menus
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	def buildOptionsMenu( self, *a ):
		self.UI_OptionsMenu.clear()
		
		#>>>Match Mode
		MatchModeMenu = MelMenuItem( self.UI_OptionsMenu, l='Match Mode', subMenu=True)		
		self.MatchModeOptions = ['parent','point','orient']
		
		self.MatchModeCollection = MelRadioMenuCollection()
		self.MatchModeCollectionChoices = []
		
		self.SnapModeOptionVar.update()#Incase another tool changed			
		
		self.matchMode = self.SnapModeOptionVar.value
		for c,item in enumerate(self.MatchModeOptions):
			if self.matchMode == c:
				rbValue = True
			else:
				rbValue = False
			self.MatchModeCollectionChoices.append(self.MatchModeCollection.createButton(MatchModeMenu,label=item,
			                                                                             rb = rbValue,
			                                                                             command = Callback(self.SnapModeOptionVar.set,c)))		

		# Placement Menu
		PlacementMenu = MelMenuItem( self.UI_OptionsMenu, l='Placement', subMenu=True)
		PlacementMenuCollection = MelRadioMenuCollection()

		if mc.optionVar( q='cgmVar_ForceBoundingBoxState' ) == 0:
			cgmOption = False
			pivotOption = True
		else:
			cgmOption = True
			pivotOption = False

		PlacementMenuCollection.createButton(PlacementMenu,l='Bounding Box Center',
				                             c=lambda *a: mc.optionVar( iv=('cgmVar_ForceBoundingBoxState', 1)),
				                             rb=cgmOption )
		PlacementMenuCollection.createButton(PlacementMenu,l='Pivot',
				                             c=lambda *a: mc.optionVar( iv=('cgmVar_ForceBoundingBoxState', 0)),
				                             rb=pivotOption )
		# Tagging options
		AutoloadMenu = MelMenuItem( self.UI_OptionsMenu, l='Tagging', subMenu=True)
		if not mc.optionVar( ex='cgmVar_TaggingUpdateRO' ):
			mc.optionVar( iv=('cgmVar_TaggingUpdateRO', 1) )
		guiFactory.appendOptionVarList(self,'cgmVar_TaggingUpdateRO')	
	  
		RenameOnUpdateState = mc.optionVar( q='cgmVar_TaggingUpdateRO' )
		MelMenuItem( AutoloadMenu, l="Update Rotation Order",
	                 cb= mc.optionVar( q='cgmVar_TaggingUpdateRO' ),
	                 c= lambda *a: guiFactory.doToggleIntOptionVariable('cgmVar_TaggingUpdateRO'))
		
		# Update Mode
		UpdateMenu = MelMenuItem( self.UI_OptionsMenu, l='Update Mode', subMenu=True)
		UpdateMenuCollection = MelRadioMenuCollection()

		if self.LocinatorUpdateObjectsOptionVar.value == 0:
			slMode = True
			bufferMode = False
		else:
			slMode = False
			bufferMode = True

		UpdateMenuCollection.createButton(UpdateMenu,l='Selected',
				                             c=lambda *a: self.LocinatorUpdateObjectsOptionVar.set(0),
				                             rb=slMode )
		UpdateMenuCollection.createButton(UpdateMenu,l='Buffer',
				                             c=lambda *a:self.LocinatorUpdateObjectsOptionVar.set(1),
				                             rb=bufferMode )
		

			                    
		MelMenuItemDiv( self.UI_OptionsMenu )
		MelMenuItem( self.UI_OptionsMenu, l="Reset",
			         c=lambda *a: self.reset())	
		
	def reset(self):	
		Callback(guiFactory.resetGuiInstanceOptionVars(self.optionVars,run))
		
	def reload(self):	
		run()
		
	def buildBufferMenu( self, *a ):
		self.UI_BufferMenu.clear()
		
		MelMenuItem( self.UI_BufferMenu, l="Define",
		             c= lambda *a: locinatorLib.defineObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
		MelMenuItem( self.UI_BufferMenu, l="Add Selected",
		             c= lambda *a: locinatorLib.addSelectedToObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
		MelMenuItem( self.UI_BufferMenu, l="Remove Selected",
		             c= lambda *a: locinatorLib.removeSelectedFromObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
		MelMenuItemDiv( self.UI_BufferMenu )
		MelMenuItem( self.UI_BufferMenu, l="Select Members",
				     c= lambda *a: locinatorLib.selectObjBufferMembers(self.LocinatorUpdateObjectsBufferOptionVar))
		MelMenuItem( self.UI_BufferMenu, l="Clear",
		             c= lambda *a: locinatorLib.clearObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
	def buildHelpMenu( self, *a ):
		self.UI_HelpMenu.clear()
		MelMenuItem( self.UI_HelpMenu, l="Show Help",
				     cb=self.ShowHelpOption,
				     c= lambda *a: self.do_showHelpToggle())
		MelMenuItem( self.UI_HelpMenu, l="Print Tools Help",
				     c=lambda *a: self.printHelp() )

		MelMenuItemDiv( self.UI_HelpMenu )
		MelMenuItem( self.UI_HelpMenu, l="About",
				     c=lambda *a: self.showAbout() )
		MelMenuItem( self.UI_HelpMenu, l="Debug",
				     cb=self.DebugModeOptionVar.value,
				     c= lambda *a: self.DebugModeOptionVar.toggle())	
		
	def do_showHelpToggle( self):
		guiFactory.toggleMenuShowState(self.ShowHelpOption,self.helpBlurbs)
		mc.optionVar( iv=('cgmVar_LocinatorShowHelp', not self.ShowHelpOption))
		self.ShowHelpOption = mc.optionVar( q='cgmVar_LocinatorShowHelp' )

	def do_showTimeSubMenuToggleOn( self):
		guiFactory.toggleMenuShowState(1,self.timeSubMenu)
		mc.optionVar( iv=('cgmVar_LocinatorCurrentFrameOnly', 1))

	def do_showTimeSubMenuToggleOff( self):
		guiFactory.toggleMenuShowState(0,self.timeSubMenu)
		mc.optionVar( iv=('cgmVar_LocinatorCurrentFrameOnly', 0))


	def showAbout(self):
		window = mc.window( title="About", iconName='About', ut = 'cgmUITemplate',resizeToFitChildren=True )
		mc.columnLayout( adjustableColumn=True )
		guiFactory.header(self.toolName,overrideUpper = True)
		mc.text(label='>>>A Part of the cgmTools Collection<<<', ut = 'cgmUIInstructionsTemplate')
		guiFactory.headerBreak()
		guiFactory.lineBreak()
		descriptionBlock = guiFactory.textBlock(self.description)

		guiFactory.lineBreak()
		mc.text(label=('%s%s' %('Written by: ',self.author)))
		mc.text(label=('%s%s%s' %('Copyright ',self.owner,', 2011')))
		guiFactory.lineBreak()
		mc.text(label='Version: %s' % self.version)
		mc.text(label='')
		guiFactory.doButton('Visit Tool Webpage', 'import webbrowser;webbrowser.open(" http://www.cgmonks.com/tools/maya-tools/locinator/")')
		guiFactory.doButton('Close', 'import maya.cmds as mc;mc.deleteUI(\"' + window + '\", window=True)')
		mc.setParent( '..' )
		mc.showWindow( window )

	def printHelp(self):
		import locinatorLib
		help(locinatorLib)

	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	# Layouts
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	def buildPlaceHolder(self,parent):
		self.containerName = MelColumnLayout(parent,ut='cgmUISubTemplate')
		return self.containerName
	
	def buildTimeSubMenu(self,parent):
		self.containerName = MelColumnLayout(parent,ut='cgmUISubTemplate')
		# Time Submenu
		mc.setParent(self.containerName)
		self.helpBlurbs.extend(guiFactory.instructions(" Set your time range",vis = self.ShowHelpOption))

		timelineInfo = search.returnTimelineInfo()


		# TimeInput Row
		TimeInputRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate')
		self.timeSubMenu.append( TimeInputRow )
		MelSpacer(TimeInputRow)
		MelLabel(TimeInputRow,l='start')

		self.startFrameField = MelIntField(TimeInputRow,'cgmLocWinStartFrameField',
	                                       width = 40,
	                                       value= timelineInfo['rangeStart'])
		TimeInputRow.setStretchWidget( MelSpacer(TimeInputRow) )
		MelLabel(TimeInputRow,l='end')

		self.endFrameField = MelIntField(TimeInputRow,'cgmLocWinEndFrameField',
	                                     width = 40,
	                                     value= timelineInfo['rangeEnd'])

		MelSpacer(TimeInputRow)
		TimeInputRow.layout()

		MelSeparator(self.containerName,ut = 'cgmUISubTemplate',style='none',height = 5)
		

		# Button Row
		TimeButtonRow = MelHSingleStretchLayout(self.containerName,padding = 1, ut='cgmUISubTemplate')
		MelSpacer(TimeButtonRow,w=2)
		currentRangeButton = guiFactory.doButton2(TimeButtonRow,'Current Range',
	                                              lambda *a: locinatorLib.setGUITimeRangeToCurrent(self),
	                                              'Sets the time range to the current slider range')
		TimeButtonRow.setStretchWidget( MelSpacer(TimeButtonRow,w=2) )
		sceneRangeButton = guiFactory.doButton2(TimeButtonRow,'Scene Range',
	                                            lambda *a: locinatorLib.setGUITimeRangeToScene(self),
	                                            'Sets the time range to the current slider range')
		MelSpacer(TimeButtonRow,w=2)
		
		TimeButtonRow.layout()

		
		#>>> Base Settings Flags
		self.KeyingModeCollection = MelRadioCollection()
		self.KeyingModeCollectionChoices = []		
		if not mc.optionVar( ex='cgmVar_LocinatorKeyingMode' ):
			mc.optionVar( iv=('cgmVar_LocinatorKeyingMode', 0) )
		guiFactory.appendOptionVarList(self,'cgmVar_LocinatorKeyingMode')	
			
		
		KeysSettingsFlagsRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate',padding = 2)
		MelSpacer(KeysSettingsFlagsRow,w=2)	
		KeysSettingsFlagsRow.setStretchWidget( MelLabel(KeysSettingsFlagsRow,l='Anim Option: ',align='right') )
		self.keyingOptions = ['Keys','All']
		for item in self.keyingOptions:
			cnt = self.keyingOptions.index(item)
			self.KeyingModeCollectionChoices.append(self.KeyingModeCollection.createButton(KeysSettingsFlagsRow,label=self.keyingOptions[cnt],
			                                                                               onCommand = Callback(guiFactory.toggleOptionVarState,self.keyingOptions[cnt],self.keyingOptions,'cgmVar_LocinatorKeyingMode',True)))
			MelSpacer(KeysSettingsFlagsRow,w=5)
		mc.radioCollection(self.KeyingModeCollection ,edit=True,sl= (self.KeyingModeCollectionChoices[ (mc.optionVar(q='cgmVar_LocinatorKeyingMode')) ]))
		
		KeysSettingsFlagsRow.layout()

		#>>> Base Settings Flags
		self.KeyingTargetCollection = MelRadioCollection()
		self.KeyingTargetCollectionChoices = []		
		if not mc.optionVar( ex='cgmVar_LocinatorKeyingTarget' ):
			mc.optionVar( iv=('cgmVar_LocinatorKeyingTarget', 0) )
		guiFactory.appendOptionVarList(self,'cgmVar_LocinatorKeyingTarget')	
			
		
		BakeSettingsFlagsRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate',padding = 2)
		MelSpacer(BakeSettingsFlagsRow,w=2)	
		BakeSettingsFlagsRow.setStretchWidget( MelLabel(BakeSettingsFlagsRow,l='From: ',align='right') )
		MelSpacer(BakeSettingsFlagsRow)
		self.keyTargetOptions = ['source','self']
		for item in self.keyTargetOptions:
			cnt = self.keyTargetOptions.index(item)
			self.KeyingTargetCollectionChoices.append(self.KeyingTargetCollection.createButton(BakeSettingsFlagsRow,label=self.keyTargetOptions[cnt],
		                                                                                       onCommand = Callback(guiFactory.toggleOptionVarState,self.keyTargetOptions[cnt],self.keyTargetOptions,'cgmVar_LocinatorKeyingTarget',True)))
			MelSpacer(BakeSettingsFlagsRow,w=5)
		mc.radioCollection(self.KeyingTargetCollection ,edit=True,sl= (self.KeyingTargetCollectionChoices[ (mc.optionVar(q='cgmVar_LocinatorKeyingTarget')) ]))
		
		BakeSettingsFlagsRow.layout()
		
		return self.containerName
	
	def buildBasicLayout(self,parent):
		mc.setParent(parent)
		guiFactory.header('Update')

		#>>>Time Section
		UpdateOptionRadioCollection = MelRadioCollection()
		EveryFrameOption = mc.optionVar( q='cgmVar_LocinatorBakeState' )
		mc.setParent(parent)
		guiFactory.lineSubBreak()
		
		#>>> Time Menu Container
		self.BakeModeOptionList = ['Current Frame','Bake']
		cgmVar_Name = 'cgmVar_LocinatorBakeState'
		guiFactory.appendOptionVarList(self,'cgmVar_LocinatorBakeState')	
		
		if not mc.optionVar( ex=cgmVar_Name ):
			mc.optionVar( iv=(cgmVar_Name, 0) )
		
		#build our sub section options
		self.ContainerList = []
		
		#Mode Change row 
		ModeSetRow = MelHSingleStretchLayout(parent,ut='cgmUISubTemplate')
		self.BakeModeRadioCollection = MelRadioCollection()
		self.BakeModeChoiceList = []	
		MelSpacer(ModeSetRow,w=2)

		self.BakeModeChoiceList.append(self.BakeModeRadioCollection.createButton(ModeSetRow,label=self.BakeModeOptionList[0],
	                                                                      onCommand = Callback(guiFactory.toggleModeState,self.BakeModeOptionList[0],self.BakeModeOptionList,cgmVar_Name,self.ContainerList,True)))
		
		ModeSetRow.setStretchWidget( MelSpacer(ModeSetRow) )
		
		self.BakeModeChoiceList.append(self.BakeModeRadioCollection.createButton(ModeSetRow,label=self.BakeModeOptionList[1],
	                                                                      onCommand = Callback(guiFactory.toggleModeState,self.BakeModeOptionList[1],self.BakeModeOptionList,cgmVar_Name,self.ContainerList,True)))
		
		ModeSetRow.layout()
		
		
		#>>>
		self.ContainerList.append( self.buildPlaceHolder(parent) )
		self.ContainerList.append( self.buildTimeSubMenu( parent) )
		
		mc.radioCollection(self.BakeModeRadioCollection,edit=True, sl=self.BakeModeChoiceList[mc.optionVar(q=cgmVar_Name)])
		#>>>
		
		mc.setParent(parent)

		guiFactory.doButton2(parent,'Do it!',
	                         lambda *a: locinatorLib.doUpdateLoc(self),
	                         'Update a locator at a particular frame or through a timeline')

		guiFactory.lineSubBreak()



		#>>>  Loc Me Section
		guiFactory.lineBreak()
		guiFactory.lineSubBreak()
		guiFactory.doButton2(parent,'Just Loc Selected',
			                 lambda *a: locinatorLib.doLocMe(self),
			                 'Create an updateable locator based off the selection and options')



	def buildSpecialLayout(self,parent):
		SpecialColumn = MelColumnLayout(parent)

		#>>>  Center Section
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SpecialColumn,'Locate Center',
		                     lambda *a: locinatorLib.doLocCenter(self),
				             'Find the center point from a selection set')


		#>>>  Closest Point Section
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SpecialColumn,'Locate Closest Point',
		                     lambda *a: locinatorLib.doLocClosest(self),
				             'Select the proximity object(s), then the object to find point on. Accepted target object types are - nurbsCurves and surfaces and poly objects')

		#>>>  Curves Section
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SpecialColumn,'Loc CVs of curve',
		                     lambda *a: locinatorLib.doLocCVsOfObject(),
				             "Locs the cv's at the cv coordinates")

		guiFactory.lineSubBreak()
		guiFactory.doButton2(SpecialColumn,'Loc CVs on the curve',
		                     lambda *a: locinatorLib.doLocCVsOnObject(),
				             "Locs cv's at closest point on the curve")

		guiFactory.lineBreak()

		#>>> Update Section
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SpecialColumn,'Update Selected',
		                     lambda *a: locinatorLib.doUpdateLoc(self),
				             "Only works with locators created with this tool")


	def buildMatchLayout(self,parent):

		MatchColumn = MelColumnLayout(parent)

		#>>>  Tag Section
		guiFactory.lineSubBreak()
		guiFactory.doButton2(MatchColumn,'Tag it',
		                     lambda *a: locinatorLib.doTagObjects(self),
				             "Tag the selected objects to the first locator in the selection set. After this relationship is set up, you can match objects to that locator.")


		#>>>  Purge Section
		guiFactory.lineSubBreak()
		self.helpBlurbs.extend(guiFactory.instructions("  Purge all traces of cgmThinga tools from the object",vis = self.ShowHelpOption))
		guiFactory.doButton2(MatchColumn,'Purge it',
		                     lambda *a: locinatorLib.doPurgeCGMAttrs(self),
				             "Clean it")

		guiFactory.lineBreak()

		#>>> Update Section
		guiFactory.lineSubBreak()
		guiFactory.doButton2(MatchColumn,'Update Selected',
		                     lambda *a: locinatorLib.doUpdateLoc(self),
				             "Only works with locators created with this tool")
示例#2
0
class locinatorClass(BaseMelWindow):
    from cgm.lib import guiFactory
    guiFactory.initializeTemplates()
    USE_Template = 'cgmUITemplate'

    WINDOW_NAME = 'cgmLocinatorWindow'
    WINDOW_TITLE = 'cgm.locinator - %s' % __version__
    DEFAULT_SIZE = 180, 275
    DEFAULT_MENU = None
    RETAIN = True
    MIN_BUTTON = True
    MAX_BUTTON = False
    FORCE_DEFAULT_SIZE = True  #always resets the size of the window when its re-created

    def __init__(self):

        self.toolName = 'cgm.locinator'
        self.description = 'This tool makes locators based on selection types and provides ways to update those locators over time'
        self.author = 'Josh Burton'
        self.owner = 'CG Monks'
        self.website = 'www.cgmonks.com'
        self.version = __version__
        self.optionVars = []

        self.currentFrameOnly = True
        self.startFrame = ''
        self.endFrame = ''
        self.startFrameField = ''
        self.endFrameField = ''
        self.forceBoundingBoxState = False
        self.forceEveryFrame = False
        self.showHelp = False
        self.helpBlurbs = []
        self.oldGenBlurbs = []

        self.showTimeSubMenu = False
        self.timeSubMenu = []

        #Menu
        self.setupVariables()
        self.UI_OptionsMenu = MelMenu(l='Options', pmc=self.buildOptionsMenu)
        self.UI_BufferMenu = MelMenu(l='Buffer', pmc=self.buildBufferMenu)
        self.UI_HelpMenu = MelMenu(l='Help', pmc=self.buildHelpMenu)

        self.ShowHelpOption = mc.optionVar(q='cgmVar_LocinatorShowHelp')

        #Tabs
        tabs = MelTabLayout(self)
        TabBasic = MelColumnLayout(tabs)
        TabSpecial = MelColumnLayout(tabs)
        TabMatch = MelColumnLayout(tabs)
        n = 0
        for tab in 'Basic', 'Special', 'Match':
            tabs.setLabel(n, tab)
            n += 1

        self.buildBasicLayout(TabBasic)
        self.buildSpecialLayout(TabSpecial)
        self.buildMatchLayout(TabMatch)

        self.show()

    def setupVariables(self):
        self.LocinatorUpdateObjectsOptionVar = OptionVarFactory(
            'cgmVar_LocinatorUpdateMode', defaultValue=0)
        guiFactory.appendOptionVarList(self, 'cgmVar_LocinatorUpdateMode')

        self.LocinatorUpdateObjectsBufferOptionVar = OptionVarFactory(
            'cgmVar_LocinatorUpdateObjectsBuffer', defaultValue=[''])
        guiFactory.appendOptionVarList(self,
                                       'cgmVar_LocinatorUpdateObjectsBuffer')

        self.DebugModeOptionVar = OptionVarFactory('cgmVar_LocinatorDebug',
                                                   defaultValue=0)
        guiFactory.appendOptionVarList(self, self.DebugModeOptionVar.name)

        self.SnapModeOptionVar = OptionVarFactory('cgmVar_SnapMatchMode',
                                                  defaultValue=0)
        guiFactory.appendOptionVarList(self, self.SnapModeOptionVar.name)

        #Old method...clean up at some point
        if not mc.optionVar(ex='cgmVar_ForceBoundingBoxState'):
            mc.optionVar(iv=('cgmVar_ForceBoundingBoxState', 0))
        if not mc.optionVar(ex='cgmVar_LocinatorShowHelp'):
            mc.optionVar(iv=('cgmVar_LocinatorShowHelp', 0))
        if not mc.optionVar(ex='cgmVar_LocinatorCurrentFrameOnly'):
            mc.optionVar(iv=('cgmVar_LocinatorCurrentFrameOnly', 0))

        if not mc.optionVar(ex='cgmVar_LocinatorBakingMode'):
            mc.optionVar(iv=('cgmVar_LocinatorBakingMode', 0))

        guiFactory.appendOptionVarList(self, 'cgmVar_LocinatorShowHelp')

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Menus
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    def buildOptionsMenu(self, *a):
        self.UI_OptionsMenu.clear()

        #>>>Match Mode
        MatchModeMenu = MelMenuItem(self.UI_OptionsMenu,
                                    l='Match Mode',
                                    subMenu=True)
        self.MatchModeOptions = ['parent', 'point', 'orient']

        self.MatchModeCollection = MelRadioMenuCollection()
        self.MatchModeCollectionChoices = []

        self.SnapModeOptionVar.update()  #Incase another tool changed

        self.matchMode = self.SnapModeOptionVar.value
        for c, item in enumerate(self.MatchModeOptions):
            if self.matchMode == c:
                rbValue = True
            else:
                rbValue = False
            self.MatchModeCollectionChoices.append(
                self.MatchModeCollection.createButton(
                    MatchModeMenu,
                    label=item,
                    rb=rbValue,
                    command=Callback(self.SnapModeOptionVar.set, c)))

        # Placement Menu
        PlacementMenu = MelMenuItem(self.UI_OptionsMenu,
                                    l='Placement',
                                    subMenu=True)
        PlacementMenuCollection = MelRadioMenuCollection()

        if mc.optionVar(q='cgmVar_ForceBoundingBoxState') == 0:
            cgmOption = False
            pivotOption = True
        else:
            cgmOption = True
            pivotOption = False

        PlacementMenuCollection.createButton(
            PlacementMenu,
            l='Bounding Box Center',
            c=lambda *a: mc.optionVar(iv=('cgmVar_ForceBoundingBoxState', 1)),
            rb=cgmOption)
        PlacementMenuCollection.createButton(
            PlacementMenu,
            l='Pivot',
            c=lambda *a: mc.optionVar(iv=('cgmVar_ForceBoundingBoxState', 0)),
            rb=pivotOption)
        # Tagging options
        AutoloadMenu = MelMenuItem(self.UI_OptionsMenu,
                                   l='Tagging',
                                   subMenu=True)
        if not mc.optionVar(ex='cgmVar_TaggingUpdateRO'):
            mc.optionVar(iv=('cgmVar_TaggingUpdateRO', 1))
        guiFactory.appendOptionVarList(self, 'cgmVar_TaggingUpdateRO')

        RenameOnUpdateState = mc.optionVar(q='cgmVar_TaggingUpdateRO')
        MelMenuItem(AutoloadMenu,
                    l="Update Rotation Order",
                    cb=mc.optionVar(q='cgmVar_TaggingUpdateRO'),
                    c=lambda *a: guiFactory.doToggleIntOptionVariable(
                        'cgmVar_TaggingUpdateRO'))

        # Update Mode
        UpdateMenu = MelMenuItem(self.UI_OptionsMenu,
                                 l='Update Mode',
                                 subMenu=True)
        UpdateMenuCollection = MelRadioMenuCollection()

        if self.LocinatorUpdateObjectsOptionVar.value == 0:
            slMode = True
            bufferMode = False
        else:
            slMode = False
            bufferMode = True

        UpdateMenuCollection.createButton(
            UpdateMenu,
            l='Selected',
            c=lambda *a: self.LocinatorUpdateObjectsOptionVar.set(0),
            rb=slMode)
        UpdateMenuCollection.createButton(
            UpdateMenu,
            l='Buffer',
            c=lambda *a: self.LocinatorUpdateObjectsOptionVar.set(1),
            rb=bufferMode)

        MelMenuItemDiv(self.UI_OptionsMenu)
        MelMenuItem(self.UI_OptionsMenu, l="Reset", c=lambda *a: self.reset())

    def reset(self):
        Callback(guiFactory.resetGuiInstanceOptionVars(self.optionVars, run))

    def reload(self):
        run()

    def buildBufferMenu(self, *a):
        self.UI_BufferMenu.clear()

        MelMenuItem(self.UI_BufferMenu,
                    l="Define",
                    c=lambda *a: locinatorLib.defineObjBuffer(
                        self.LocinatorUpdateObjectsBufferOptionVar))

        MelMenuItem(self.UI_BufferMenu,
                    l="Add Selected",
                    c=lambda *a: locinatorLib.addSelectedToObjBuffer(
                        self.LocinatorUpdateObjectsBufferOptionVar))

        MelMenuItem(self.UI_BufferMenu,
                    l="Remove Selected",
                    c=lambda *a: locinatorLib.removeSelectedFromObjBuffer(
                        self.LocinatorUpdateObjectsBufferOptionVar))

        MelMenuItemDiv(self.UI_BufferMenu)
        MelMenuItem(self.UI_BufferMenu,
                    l="Select Members",
                    c=lambda *a: locinatorLib.selectObjBufferMembers(
                        self.LocinatorUpdateObjectsBufferOptionVar))
        MelMenuItem(self.UI_BufferMenu,
                    l="Clear",
                    c=lambda *a: locinatorLib.clearObjBuffer(
                        self.LocinatorUpdateObjectsBufferOptionVar))

    def buildHelpMenu(self, *a):
        self.UI_HelpMenu.clear()
        MelMenuItem(self.UI_HelpMenu,
                    l="Show Help",
                    cb=self.ShowHelpOption,
                    c=lambda *a: self.do_showHelpToggle())
        MelMenuItem(self.UI_HelpMenu,
                    l="Print Tools Help",
                    c=lambda *a: self.printHelp())

        MelMenuItemDiv(self.UI_HelpMenu)
        MelMenuItem(self.UI_HelpMenu, l="About", c=lambda *a: self.showAbout())
        MelMenuItem(self.UI_HelpMenu,
                    l="Debug",
                    cb=self.DebugModeOptionVar.value,
                    c=lambda *a: self.DebugModeOptionVar.toggle())

    def do_showHelpToggle(self):
        guiFactory.toggleMenuShowState(self.ShowHelpOption, self.helpBlurbs)
        mc.optionVar(iv=('cgmVar_LocinatorShowHelp', not self.ShowHelpOption))
        self.ShowHelpOption = mc.optionVar(q='cgmVar_LocinatorShowHelp')

    def do_showTimeSubMenuToggleOn(self):
        guiFactory.toggleMenuShowState(1, self.timeSubMenu)
        mc.optionVar(iv=('cgmVar_LocinatorCurrentFrameOnly', 1))

    def do_showTimeSubMenuToggleOff(self):
        guiFactory.toggleMenuShowState(0, self.timeSubMenu)
        mc.optionVar(iv=('cgmVar_LocinatorCurrentFrameOnly', 0))

    def showAbout(self):
        window = mc.window(title="About",
                           iconName='About',
                           ut='cgmUITemplate',
                           resizeToFitChildren=True)
        mc.columnLayout(adjustableColumn=True)
        guiFactory.header(self.toolName, overrideUpper=True)
        mc.text(label='>>>A Part of the cgmTools Collection<<<',
                ut='cgmUIInstructionsTemplate')
        guiFactory.headerBreak()
        guiFactory.lineBreak()
        descriptionBlock = guiFactory.textBlock(self.description)

        guiFactory.lineBreak()
        mc.text(label=('%s%s' % ('Written by: ', self.author)))
        mc.text(label=('%s%s%s' % ('Copyright ', self.owner, ', 2011')))
        guiFactory.lineBreak()
        mc.text(label='Version: %s' % self.version)
        mc.text(label='')
        guiFactory.doButton(
            'Visit Tool Webpage',
            'import webbrowser;webbrowser.open(" http://www.cgmonks.com/tools/maya-tools/locinator/")'
        )
        guiFactory.doButton(
            'Close', 'import maya.cmds as mc;mc.deleteUI(\"' + window +
            '\", window=True)')
        mc.setParent('..')
        mc.showWindow(window)

    def printHelp(self):
        import locinatorLib
        help(locinatorLib)

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Layouts
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    def buildPlaceHolder(self, parent):
        self.containerName = MelColumnLayout(parent, ut='cgmUISubTemplate')
        return self.containerName

    def buildTimeSubMenu(self, parent):
        self.containerName = MelColumnLayout(parent, ut='cgmUISubTemplate')
        # Time Submenu
        mc.setParent(self.containerName)
        self.helpBlurbs.extend(
            guiFactory.instructions(" Set your time range",
                                    vis=self.ShowHelpOption))

        timelineInfo = search.returnTimelineInfo()

        # TimeInput Row
        TimeInputRow = MelHSingleStretchLayout(self.containerName,
                                               ut='cgmUISubTemplate')
        self.timeSubMenu.append(TimeInputRow)
        MelSpacer(TimeInputRow)
        MelLabel(TimeInputRow, l='start')

        self.startFrameField = MelIntField(TimeInputRow,
                                           'cgmLocWinStartFrameField',
                                           width=40,
                                           value=timelineInfo['rangeStart'])
        TimeInputRow.setStretchWidget(MelSpacer(TimeInputRow))
        MelLabel(TimeInputRow, l='end')

        self.endFrameField = MelIntField(TimeInputRow,
                                         'cgmLocWinEndFrameField',
                                         width=40,
                                         value=timelineInfo['rangeEnd'])

        MelSpacer(TimeInputRow)
        TimeInputRow.layout()

        MelSeparator(self.containerName,
                     ut='cgmUISubTemplate',
                     style='none',
                     height=5)

        # Button Row
        TimeButtonRow = MelHSingleStretchLayout(self.containerName,
                                                padding=1,
                                                ut='cgmUISubTemplate')
        MelSpacer(TimeButtonRow, w=2)
        currentRangeButton = guiFactory.doButton2(
            TimeButtonRow, 'Current Range',
            lambda *a: locinatorLib.setGUITimeRangeToCurrent(self),
            'Sets the time range to the current slider range')
        TimeButtonRow.setStretchWidget(MelSpacer(TimeButtonRow, w=2))
        sceneRangeButton = guiFactory.doButton2(
            TimeButtonRow, 'Scene Range',
            lambda *a: locinatorLib.setGUITimeRangeToScene(self),
            'Sets the time range to the current slider range')
        MelSpacer(TimeButtonRow, w=2)

        TimeButtonRow.layout()

        #>>> Base Settings Flags
        self.KeyingModeCollection = MelRadioCollection()
        self.KeyingModeCollectionChoices = []
        if not mc.optionVar(ex='cgmVar_LocinatorKeyingMode'):
            mc.optionVar(iv=('cgmVar_LocinatorKeyingMode', 0))
        guiFactory.appendOptionVarList(self, 'cgmVar_LocinatorKeyingMode')

        KeysSettingsFlagsRow = MelHSingleStretchLayout(self.containerName,
                                                       ut='cgmUISubTemplate',
                                                       padding=2)
        MelSpacer(KeysSettingsFlagsRow, w=2)
        KeysSettingsFlagsRow.setStretchWidget(
            MelLabel(KeysSettingsFlagsRow, l='Anim Option: ', align='right'))
        self.keyingOptions = ['Keys', 'All']
        for item in self.keyingOptions:
            cnt = self.keyingOptions.index(item)
            self.KeyingModeCollectionChoices.append(
                self.KeyingModeCollection.createButton(
                    KeysSettingsFlagsRow,
                    label=self.keyingOptions[cnt],
                    onCommand=Callback(guiFactory.toggleOptionVarState,
                                       self.keyingOptions[cnt],
                                       self.keyingOptions,
                                       'cgmVar_LocinatorKeyingMode', True)))
            MelSpacer(KeysSettingsFlagsRow, w=5)
        mc.radioCollection(self.KeyingModeCollection,
                           edit=True,
                           sl=(self.KeyingModeCollectionChoices[(mc.optionVar(
                               q='cgmVar_LocinatorKeyingMode'))]))

        KeysSettingsFlagsRow.layout()

        #>>> Base Settings Flags
        self.KeyingTargetCollection = MelRadioCollection()
        self.KeyingTargetCollectionChoices = []
        if not mc.optionVar(ex='cgmVar_LocinatorKeyingTarget'):
            mc.optionVar(iv=('cgmVar_LocinatorKeyingTarget', 0))
        guiFactory.appendOptionVarList(self, 'cgmVar_LocinatorKeyingTarget')

        BakeSettingsFlagsRow = MelHSingleStretchLayout(self.containerName,
                                                       ut='cgmUISubTemplate',
                                                       padding=2)
        MelSpacer(BakeSettingsFlagsRow, w=2)
        BakeSettingsFlagsRow.setStretchWidget(
            MelLabel(BakeSettingsFlagsRow, l='From: ', align='right'))
        MelSpacer(BakeSettingsFlagsRow)
        self.keyTargetOptions = ['source', 'self']
        for item in self.keyTargetOptions:
            cnt = self.keyTargetOptions.index(item)
            self.KeyingTargetCollectionChoices.append(
                self.KeyingTargetCollection.createButton(
                    BakeSettingsFlagsRow,
                    label=self.keyTargetOptions[cnt],
                    onCommand=Callback(guiFactory.toggleOptionVarState,
                                       self.keyTargetOptions[cnt],
                                       self.keyTargetOptions,
                                       'cgmVar_LocinatorKeyingTarget', True)))
            MelSpacer(BakeSettingsFlagsRow, w=5)
        mc.radioCollection(
            self.KeyingTargetCollection,
            edit=True,
            sl=(self.KeyingTargetCollectionChoices[(mc.optionVar(
                q='cgmVar_LocinatorKeyingTarget'))]))

        BakeSettingsFlagsRow.layout()

        return self.containerName

    def buildBasicLayout(self, parent):
        mc.setParent(parent)
        guiFactory.header('Update')

        #>>>Time Section
        UpdateOptionRadioCollection = MelRadioCollection()
        EveryFrameOption = mc.optionVar(q='cgmVar_LocinatorBakeState')
        mc.setParent(parent)
        guiFactory.lineSubBreak()

        #>>> Time Menu Container
        self.BakeModeOptionList = ['Current Frame', 'Bake']
        cgmVar_Name = 'cgmVar_LocinatorBakeState'
        guiFactory.appendOptionVarList(self, 'cgmVar_LocinatorBakeState')

        if not mc.optionVar(ex=cgmVar_Name):
            mc.optionVar(iv=(cgmVar_Name, 0))

        #build our sub section options
        self.ContainerList = []

        #Mode Change row
        ModeSetRow = MelHSingleStretchLayout(parent, ut='cgmUISubTemplate')
        self.BakeModeRadioCollection = MelRadioCollection()
        self.BakeModeChoiceList = []
        MelSpacer(ModeSetRow, w=2)

        self.BakeModeChoiceList.append(
            self.BakeModeRadioCollection.createButton(
                ModeSetRow,
                label=self.BakeModeOptionList[0],
                onCommand=Callback(guiFactory.toggleModeState,
                                   self.BakeModeOptionList[0],
                                   self.BakeModeOptionList, cgmVar_Name,
                                   self.ContainerList, True)))

        ModeSetRow.setStretchWidget(MelSpacer(ModeSetRow))

        self.BakeModeChoiceList.append(
            self.BakeModeRadioCollection.createButton(
                ModeSetRow,
                label=self.BakeModeOptionList[1],
                onCommand=Callback(guiFactory.toggleModeState,
                                   self.BakeModeOptionList[1],
                                   self.BakeModeOptionList, cgmVar_Name,
                                   self.ContainerList, True)))

        ModeSetRow.layout()

        #>>>
        self.ContainerList.append(self.buildPlaceHolder(parent))
        self.ContainerList.append(self.buildTimeSubMenu(parent))

        mc.radioCollection(
            self.BakeModeRadioCollection,
            edit=True,
            sl=self.BakeModeChoiceList[mc.optionVar(q=cgmVar_Name)])
        #>>>

        mc.setParent(parent)

        guiFactory.doButton2(
            parent, 'Do it!', lambda *a: locinatorLib.doUpdateLoc(self),
            'Update a locator at a particular frame or through a timeline')

        guiFactory.lineSubBreak()

        #>>>  Loc Me Section
        guiFactory.lineBreak()
        guiFactory.lineSubBreak()
        guiFactory.doButton2(
            parent, 'Just Loc Selected', lambda *a: locinatorLib.doLocMe(self),
            'Create an updateable locator based off the selection and options')

    def buildSpecialLayout(self, parent):
        SpecialColumn = MelColumnLayout(parent)

        #>>>  Center Section
        guiFactory.lineSubBreak()
        guiFactory.doButton2(SpecialColumn, 'Locate Center',
                             lambda *a: locinatorLib.doLocCenter(self),
                             'Find the center point from a selection set')

        #>>>  Closest Point Section
        guiFactory.lineSubBreak()
        guiFactory.doButton2(
            SpecialColumn, 'Locate Closest Point',
            lambda *a: locinatorLib.doLocClosest(self),
            'Select the proximity object(s), then the object to find point on. Accepted target object types are - nurbsCurves and surfaces and poly objects'
        )

        #>>>  Curves Section
        guiFactory.lineSubBreak()
        guiFactory.doButton2(SpecialColumn, 'Loc CVs of curve',
                             lambda *a: locinatorLib.doLocCVsOfObject(),
                             "Locs the cv's at the cv coordinates")

        guiFactory.lineSubBreak()
        guiFactory.doButton2(SpecialColumn, 'Loc CVs on the curve',
                             lambda *a: locinatorLib.doLocCVsOnObject(),
                             "Locs cv's at closest point on the curve")

        guiFactory.lineBreak()

        #>>> Update Section
        guiFactory.lineSubBreak()
        guiFactory.doButton2(
            SpecialColumn, 'Update Selected',
            lambda *a: locinatorLib.doUpdateLoc(self),
            "Only works with locators created with this tool")

    def buildMatchLayout(self, parent):

        MatchColumn = MelColumnLayout(parent)

        #>>>  Tag Section
        guiFactory.lineSubBreak()
        guiFactory.doButton2(
            MatchColumn, 'Tag it', lambda *a: locinatorLib.doTagObjects(self),
            "Tag the selected objects to the first locator in the selection set. After this relationship is set up, you can match objects to that locator."
        )

        #>>>  Purge Section
        guiFactory.lineSubBreak()
        self.helpBlurbs.extend(
            guiFactory.instructions(
                "  Purge all traces of cgmThinga tools from the object",
                vis=self.ShowHelpOption))
        guiFactory.doButton2(MatchColumn, 'Purge it',
                             lambda *a: locinatorLib.doPurgeCGMAttrs(self),
                             "Clean it")

        guiFactory.lineBreak()

        #>>> Update Section
        guiFactory.lineSubBreak()
        guiFactory.doButton2(
            MatchColumn, 'Update Selected',
            lambda *a: locinatorLib.doUpdateLoc(self),
            "Only works with locators created with this tool")
示例#3
0
class puppetBoxClass(BaseMelWindow):
	from  cgm.lib import guiFactory
	guiFactory.initializeTemplates()
	USE_Template = 'cgmUITemplate'
	
	WINDOW_NAME = 'cgmPuppetBoxWindow'
	WINDOW_TITLE = 'cgm.puppetBox'
	DEFAULT_SIZE = 250, 400
	DEFAULT_MENU = None
	RETAIN = True
	MIN_BUTTON = True
	MAX_BUTTON = False
	FORCE_DEFAULT_SIZE = False  #always resets the size of the window when its re-created
	global cgmPuppet
	def __init__( self):		
		self.toolName = 'cgm.puppetBox'
		self.description = 'This is a series of tools for working with cgm Sets'
		self.author = 'Josh Burton'
		self.owner = 'CG Monks'
		self.website = 'www.cgmonks.com'
		self.version =  __version__ 
		self.optionVars = []
		self.scenePuppets = []
		self.Puppet = False
		self.PuppetBridge = {}
		self.puppetStateOptions = ['define']
		self.puppetStateOptions.extend(ModuleFactory.moduleStates)
		#self.addModules = ['Spine','Leg','Arm','Limb','Finger','Foot','Neck','Head','Spine']
		self.addModules = ['Segment']
		self.moduleFrames = {}
		self.moduleBaseNameFields = {}
		self.moduleHandleFields = {}
		self.moduleRollFields = {}
		self.moduleCurveFields = {}
		self.moduleStiffIndexFields = {}
		
		self.moduleDirectionMenus = {}
		self.modulePositionMenus = {}
		
		self.moduleDirections = ['none','left','right']
		self.modulePositions = ['none','front','rear','forward','back','top','bottom']
		
		
		
		self.setModes = ['<<< All Loaded Sets >>>','<<< Active Sets >>>']
		self.scenePuppets = modules.returnPuppetObjects()
		self.UI_StateRows = {'define':[],'template':[],'skeleton':[],'rig':[]}
		
		self.showHelp = False
		self.helpBlurbs = []
		self.oldGenBlurbs = []
		
		#Menu
		self.setupVariables()
		
		self.UI_PuppetMenu = MelMenu( l='Puppet', pmc=self.buildPuppetMenu)
		self.UI_AddModulesMenu = MelMenu( l='Add', pmc=self.buildAddModulesMenu)
		self.UI_OptionsMenu = MelMenu( l='Options', pmc=self.buildOptionsMenu)		
		self.UI_HelpMenu = MelMenu( l='Help', pmc=self.buildHelpMenu)
		
		self.ShowHelpOption = mc.optionVar( q='cgmVar_AnimToolsShowHelp' )
		
		#GUI
						
		self.Main_buildLayout(self)
		
		if self.Puppet:
			puppetBoxLib.updateUIPuppet(self)
		
		
		if self.scenePuppets:
			puppetBoxLib.activatePuppet(self,self.scenePuppets[0])
			
		self.show()
		
	def setupVariables(self):
		self.PuppetModeOptionVar = OptionVarFactory('cgmVar_PuppetCreateMode',defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.PuppetModeOptionVar.name)
		
		self.PuppetAimOptionVar = OptionVarFactory('cgmVar_PuppetAimAxis',defaultValue = 2)
		guiFactory.appendOptionVarList(self,self.PuppetAimOptionVar.name)		
		self.PuppetUpOptionVar = OptionVarFactory('cgmVar_PuppetUpAxis',defaultValue = 1)
		guiFactory.appendOptionVarList(self,self.PuppetUpOptionVar.name)	
		self.PuppetOutOptionVar = OptionVarFactory('cgmVar_PuppetOutAxis',defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.PuppetOutOptionVar.name)			
		
		
		self.ActiveObjectSetsOptionVar = OptionVarFactory('cgmVar_activeObjectSets',defaultValue = [''])
		self.ActiveRefsOptionVar = OptionVarFactory('cgmVar_activeRefs',defaultValue = [''])
		self.ActiveTypesOptionVar = OptionVarFactory('cgmVar_activeTypes',defaultValue = [''])
		self.SetToolsModeOptionVar = OptionVarFactory('cgmVar_puppetBoxMode', defaultValue = 0)
		self.KeyTypeOptionVar = OptionVarFactory('cgmVar_KeyType', defaultValue = 0)
		self.ShowHelpOptionVar = OptionVarFactory('cgmVar_puppetBoxShowHelp', defaultValue = 0)
		self.MaintainLocalSetGroupOptionVar = OptionVarFactory('cgmVar_MaintainLocalSetGroup', defaultValue = 1)
		self.HideSetGroupOptionVar = OptionVarFactory('cgmVar_HideSetGroups', defaultValue = 1)
		self.HideAnimLayerSetsOptionVar = OptionVarFactory('cgmVar_HideAnimLayerSets', defaultValue = 1)
		self.HideMayaSetsOptionVar = OptionVarFactory('cgmVar_HideMayaSets', defaultValue = 1)
		
		
		guiFactory.appendOptionVarList(self,self.ActiveObjectSetsOptionVar.name)
		guiFactory.appendOptionVarList(self,self.ActiveRefsOptionVar.name)
		guiFactory.appendOptionVarList(self,self.ActiveTypesOptionVar.name)
		guiFactory.appendOptionVarList(self,self.SetToolsModeOptionVar.name)
		guiFactory.appendOptionVarList(self,self.ShowHelpOptionVar.name)
		guiFactory.appendOptionVarList(self,self.KeyTypeOptionVar.name)
		guiFactory.appendOptionVarList(self,self.HideSetGroupOptionVar.name)
		guiFactory.appendOptionVarList(self,self.MaintainLocalSetGroupOptionVar.name)
		guiFactory.appendOptionVarList(self,self.HideAnimLayerSetsOptionVar.name)
		guiFactory.appendOptionVarList(self,self.HideMayaSetsOptionVar.name)

	def updateModulesUI(self):
		def optionMenuSet(item):
			print item
			#puppetBoxLib.uiModuleSetCGMTag(self,tag,item,index)
			"""
			i =  self.setModes.index(item)
			self.SetToolsModeOptionVar.set( i )
			self.setMode = i"""
			
		#deleteExisting
		self.ModuleListColumn.clear()
		
		if self.Puppet:			
			for i,b in enumerate(self.Puppet.ModulesBuffer.bufferList):
				# NEED to get colors
				#Build label for Frame
				self.moduleFrames[i] = MelFrameLayout(self.ModuleListColumn,l='',
			                                          collapse=True,
			                                          collapsable=True,
				                                      marginHeight=0,
				                                      marginWidth=0,
			                                          bgc = dictionary.guiDirectionColors['center'])
				puppetBoxLib.uiModuleUpdateFrameLabel(self,i)
				
				
				#Build Naming Row
				tmpNameRow = MelFormLayout(self.moduleFrames[i], h=25,
				                          )
				tmpNameLabel = MelLabel(tmpNameRow,l='base:',align='right')
				
				self.moduleBaseNameFields[i] = MelTextField(tmpNameRow,text=self.Puppet.Module[i].nameBase or '',
			                                                ec = Callback(puppetBoxLib.uiUpdateBaseName,self,i),
				                                            w=50,
			                                                h=20)
				
				tmpDirLabel = MelLabel(tmpNameRow,l='dir:',align='right')								
				self.moduleDirectionMenus[i] = MelOptionMenu(tmpNameRow, cc = Callback(puppetBoxLib.uiModuleOptionMenuSet,self,self.moduleDirectionMenus,self.moduleDirections,'cgmDirection',i))

				for cnt,o in enumerate(self.moduleDirections):
					self.moduleDirectionMenus[i].append(o)
					if o == self.Puppet.Module[i].ModuleNull.cgm['cgmDirection']:
						self.moduleDirectionMenus[i](edit = True, select = cnt + 1)
								
				tmpPosLabel = MelLabel(tmpNameRow,l='pos:',align='right')
				self.modulePositionMenus[i] = MelOptionMenu(tmpNameRow,
				                                            cc = Callback(puppetBoxLib.uiModuleOptionMenuSet,self,self.modulePositionMenus,self.modulePositions,'cgmPosition',i))
				for cnt,o in enumerate(self.modulePositions):
					self.modulePositionMenus[i].append(o)
					if o == self.Puppet.Module[i].ModuleNull.cgm['cgmPosition']:
						self.modulePositionMenus[i](edit = True, select = cnt + 1)					
					
				mc.formLayout(tmpNameRow, edit = True,
				              af = [(tmpNameLabel, "left", 10),
				                    (self.modulePositionMenus[i],"right",10)],
				              ac = [(self.moduleBaseNameFields[i],"left",5,tmpNameLabel),
				                    (self.moduleBaseNameFields[i],"right",5,tmpDirLabel),
				                    (tmpDirLabel,"right",5,self.moduleDirectionMenus[i]),
				                    (self.moduleDirectionMenus[i],"right",5,tmpPosLabel),
				                    (tmpPosLabel,"right",5,self.modulePositionMenus[i] ),
				                    ])
				#>>>>>>>>>>>>>>>>>>>>>
				
				if self.Puppet.Module[i].moduleClass == 'Limb':
				
					#Build Int Settings Row
					tmpIntRow = MelHSingleStretchLayout(self.moduleFrames[i], h=25,
					                                    )
					tmpIntRow.setStretchWidget(MelSpacer(tmpIntRow,w=5))
					                           
					MelLabel(tmpIntRow,l='Handles:')
					self.moduleHandleFields[i] = MelIntField(tmpIntRow,
					                                         v = self.Puppet.Module[i].optionHandles.value,
					                                         bgc = dictionary.returnStateColor('normal'),
					                                         ec = Callback(puppetBoxLib.uiModuleUpdateIntAttrFromField,self,self.moduleHandleFields,'optionHandles',i),
					                                         h = 20, w = 35)
					MelLabel(tmpIntRow,l='Roll:')
					self.moduleRollFields[i] = MelIntField(tmpIntRow,
					                                       v = self.Puppet.Module[i].optionRollJoints.value,					                                       
					                                       bgc = dictionary.returnStateColor('normal'),
					                                       ec = Callback(puppetBoxLib.uiModuleUpdateIntAttrFromField,self,self.moduleRollFields,'optionRollJoints',i),
					                                       h = 20, w = 35)
					MelLabel(tmpIntRow,l='Stiff Index:')
					self.moduleStiffIndexFields[i] = MelIntField(tmpIntRow,
					                                             v = self.Puppet.Module[i].optionStiffIndex.value,					                                             
					                                             bgc = dictionary.returnStateColor('normal'),
					                                             ec = Callback(puppetBoxLib.uiModuleUpdateIntAttrFromField,self,self.moduleStiffIndexFields,'optionStiffIndex',i),
					                                             h = 20, w = 35)	
					MelLabel(tmpIntRow,l='Curve:')
					self.moduleCurveFields[i] = MelIntField(tmpIntRow,
					                                        v = self.Puppet.Module[i].optionCurveDegree.value,					                                        
					                                        bgc = dictionary.returnStateColor('normal'),
					                                        ec = Callback(puppetBoxLib.uiModuleUpdateIntAttrFromField,self,self.moduleCurveFields,'optionCurveDegree',i),
					                                        h = 20, w = 35)
					
					
					MelSpacer(tmpIntRow,w=10)
					
					tmpIntRow.layout()
				


				#PopUp Menu!
				popUpMenu = MelPopupMenu(self.moduleFrames[i],button = 3)
				
				MelMenuItem(popUpMenu,
							label = "cls: %s"%self.Puppet.Module[i].moduleClass,
							enable = False)
				#Parent/MIrror				
				MelMenuItem(popUpMenu,
							label = "Set Parent>",
							enable = False)
				MelMenuItem(popUpMenu,
							label = "Set Mirror>",
							enable = False)	
				
				if self.Puppet.Module[i].moduleClass == 'Limb':
					MelMenuItem(popUpMenu,
						        label = 'FK',
						        cb = self.Puppet.Module[i].optionFK.value,
						        c = Callback(puppetBoxLib.uiModuleToggleBool,self,'optionFK',i))
					MelMenuItem(popUpMenu,
						        label = 'IK',
						        cb = self.Puppet.Module[i].optionIK.value,
					            c = Callback(puppetBoxLib.uiModuleToggleBool,self,'optionIK',i))
					MelMenuItem(popUpMenu,
						        label = 'Stretchy',
						        cb = self.Puppet.Module[i].optionStretchy.value,
					            c = Callback(puppetBoxLib.uiModuleToggleBool,self,'optionStretchy',i))
					MelMenuItem(popUpMenu,
						        label = 'Bendy',
						        cb = self.Puppet.Module[i].optionBendy.value,
					            c = Callback(puppetBoxLib.uiModuleToggleBool,self,'optionBendy',i))
					
				MelMenuItemDiv(popUpMenu)
				
				# Object Aim Menu
				ObjectAimMenu = MelMenuItem(popUpMenu, l='Aim:', subMenu=True)
				self.ObjectAimCollection = MelRadioMenuCollection()
			
				for index,axis in enumerate(dictionary.axisDirectionsByString):
					if self.Puppet.Module[i].optionAimAxis.get() == index:
						checkState = True
					else:
						checkState = False
					self.ObjectAimCollection.createButton(ObjectAimMenu,l=axis,
				                                          c= Callback(puppetBoxLib.doSetAxisAndUpdateModule,self,functions.doSetAimAxis,self.Puppet.Module[i],index),
				                                          rb = checkState)
				ObjectUpMenu = MelMenuItem(popUpMenu, l='Up:', subMenu=True)
				self.ObjectUpCollection = MelRadioMenuCollection()
			
				for index,axis in enumerate(dictionary.axisDirectionsByString):
					if self.Puppet.Module[i].optionUpAxis.get() == index:
						checkState = True
					else:
						checkState = False
					self.ObjectUpCollection.createButton(ObjectUpMenu,l=axis,
					                                     c= Callback(puppetBoxLib.doSetAxisAndUpdateModule,self,functions.doSetUpAxis,self.Puppet.Module[i],index),
				                                          rb = checkState)
				ObjectOutMenu = MelMenuItem(popUpMenu, l='Out:', subMenu=True)
				self.ObjectOutCollection = MelRadioMenuCollection()
			
				for index,axis in enumerate(dictionary.axisDirectionsByString):
					if self.Puppet.Module[i].optionOutAxis.get() == index:
						checkState = True
					else:
						checkState = False
					self.ObjectOutCollection.createButton(ObjectOutMenu,l=axis,
					                                      c= Callback(puppetBoxLib.doSetAxisAndUpdateModule,self,functions.doSetOutAxis,self.Puppet.Module[i],index),
				                                          rb = checkState)
					
					
				ObjectOutMenu = MelMenuItem(popUpMenu, l='Copy from Parent', 
				                            c= Callback(puppetBoxLib.doCopyAxisFromParent,self,self.Puppet.Module[i]))
				                            
				MelMenuItemDiv(popUpMenu)
				
				
				
				MelMenuItem(popUpMenu ,
							label = 'Remove',
							c = Callback(puppetBoxLib.doRemoveModule,self,i))
				
				MelMenuItem(popUpMenu ,
							label = 'Delete',
							c = Callback(puppetBoxLib.doDeleteModule,self,i))

 
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	# Menus
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	def buildPuppetMenu( self, *a ):
		self.UI_PuppetMenu.clear()
		
		#>>> Puppet Options	
		MelMenuItem( self.UI_PuppetMenu, l="New",
	                 c=lambda *a:puppetBoxLib.doPuppetCreate(self))
		
		#Build load menu
		self.scenePuppets = modules.returnPuppetObjects()		
		loadMenu = MelMenuItem( self.UI_PuppetMenu, l='Pick Puppet:', subMenu=True)
		
		if self.scenePuppets:
			for i,m in enumerate(self.scenePuppets):
				MelMenuItem( loadMenu, l="%s"%m,
					         c= Callback(puppetBoxLib.activatePuppet,self,m))		
		else:
			MelMenuItem( loadMenu, l="None found")
			
		if self.Puppet:
			MelMenuItemDiv( self.UI_PuppetMenu )	
			MelMenuItem( self.UI_PuppetMenu, l="Initialize",
				         c=lambda *a:puppetBoxLib.initializePuppet(self))
			if not self.Puppet.refState:
				MelMenuItem( self.UI_PuppetMenu, l="Verify",
					         c=lambda *a:puppetBoxLib.verifyPuppet(self))	
				MelMenuItem( self.UI_PuppetMenu, l="Delete",
					         c=lambda *a:puppetBoxLib.deletePuppet(self))	
		#>>> Reset Options		
		MelMenuItemDiv( self.UI_PuppetMenu )
		MelMenuItem( self.UI_PuppetMenu, l="Reload",
			         c=lambda *a: self.reload())		
		MelMenuItem( self.UI_PuppetMenu, l="Reset",
			         c=lambda *a: self.reset())
	
	def buildAddModulesMenu( self, *a ):
		self.UI_AddModulesMenu.clear()
		for i,m in enumerate(self.addModules):
			MelMenuItem( self.UI_AddModulesMenu, l="%s"%m,
				         c=lambda *a:puppetBoxLib.addModule(self,m))

		MelMenuItemDiv( self.UI_AddModulesMenu )
		
	def buildOptionsMenu( self, *a ):
		self.UI_OptionsMenu.clear()
		MelMenuItem( self.UI_OptionsMenu, l="Force module menu reload",
	                 c=lambda *a:puppetBoxLib.uiForceModuleUpdateUI(self))		
		
		
	def reset(self):	
		Callback(guiFactory.resetGuiInstanceOptionVars(self.optionVars,run))
		
	def reload(self):	
		run()
		

	def buildHelpMenu( self, *a ):
		self.UI_HelpMenu.clear()
		MelMenuItem( self.UI_HelpMenu, l="Show Help",
				     cb=self.ShowHelpOptionVar.value,
				     c= lambda *a: self.do_showHelpToggle())
		
		MelMenuItem( self.UI_HelpMenu, l="Print Set Report",
				     c=lambda *a: self.printReport() )
		MelMenuItem( self.UI_HelpMenu, l="Print Tools Help",
				     c=lambda *a: self.printHelp() )

		MelMenuItemDiv( self.UI_HelpMenu )
		MelMenuItem( self.UI_HelpMenu, l="About",
				     c=lambda *a: self.showAbout() )

	def do_showHelpToggle( self):
		guiFactory.toggleMenuShowState(self.ShowHelpOptionVar.value,self.helpBlurbs)
		self.ShowHelpOptionVar.toggle()


	def showAbout(self):
		window = mc.window( title="About", iconName='About', ut = 'cgmUITemplate',resizeToFitChildren=True )
		mc.columnLayout( adjustableColumn=True )
		guiFactory.header(self.toolName,overrideUpper = True)
		mc.text(label='>>>A Part of the cgmTools Collection<<<', ut = 'cgmUIInstructionsTemplate')
		guiFactory.headerBreak()
		guiFactory.lineBreak()
		descriptionBlock = guiFactory.textBlock(self.description)

		guiFactory.lineBreak()
		mc.text(label=('%s%s' %('Written by: ',self.author)))
		mc.text(label=('%s%s%s' %('Copyright ',self.owner,', 2011')))
		guiFactory.lineBreak()
		mc.text(label='Version: %s' % self.version)
		mc.text(label='')
		guiFactory.doButton('Visit Tool Webpage', 'import webbrowser;webbrowser.open(" http://www.cgmonks.com/tools/maya-tools/puppetBox/")')
		guiFactory.doButton('Close', 'import maya.cmds as mc;mc.deleteUI(\"' + window + '\", window=True)')
		mc.setParent( '..' )
		mc.showWindow( window )

	def printHelp(self):
		help(puppetBoxLib)
		
	def printReport(self):
		puppetBoxLib.printReport(self)


	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	# Layouts
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	
	def Main_buildLayout(self,parent):
		def modeSet( item ):
			i =  self.setModes.index(item)
			self.SetToolsModeOptionVar.set( i )
			self.setMode = i
		
		MainForm = MelFormLayout(parent)
		TopSection = MelColumnLayout(MainForm)	
		SetHeader = guiFactory.header('Puppet')
		
		#>>>  Top Section
		#Report
		self.puppetReport = MelLabel(TopSection,
				                     bgc = dictionary.returnStateColor('help'),
				                     align = 'center',
				                     label = '...',
				                     h=20)
		MelSeparator(TopSection,ut='cgmUITemplate',h=5)
		
		#Edit name and state mode buttons
		MasterPuppetRow = MelHSingleStretchLayout(TopSection,padding = 5)
		MelSpacer(MasterPuppetRow,w=5)
		self.MasterPuppetTF = MelTextField(MasterPuppetRow,
		                                   bgc = [1,1,1],
		                                   ec = lambda *a:puppetBoxLib.updatePuppetName(self))
		MasterPuppetRow.setStretchWidget(self.MasterPuppetTF)
		
		self.puppetStateButtonsDict = {}
		for i,s in enumerate(self.puppetStateOptions):
			self.puppetStateButtonsDict[i] = guiFactory.doButton2(MasterPuppetRow,s.capitalize(),
			                                                      "print '%s'"%s,
			                                                      enable = False)
		MelSpacer(MasterPuppetRow,w=20)
		
		MasterPuppetRow.layout()
		#MelSeparator(TopSection,ut='cgmUITemplate',h=2)
		
		#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		# Define State Rows
		#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>		
		#Initial State Mode Row
		self.PuppetModeCollection = MelRadioCollection()
		self.PuppetModeCollectionChoices = []			
		
		self.InitialStateModeRow = MelHSingleStretchLayout(TopSection,padding = 2,vis=False)	
		MelSpacer(self.InitialStateModeRow,w=5)				
		MelLabel(self.InitialStateModeRow,l='Template Modes')
		Spacer = MelSeparator(self.InitialStateModeRow,w=10)						
		for i,item in enumerate(CharacterTypes):
			self.PuppetModeCollectionChoices.append(self.PuppetModeCollection.createButton(self.InitialStateModeRow,label=item,
			                                                                               onCommand = Callback(puppetBoxLib.setPuppetBaseMode,self,i)))
			MelSpacer(self.InitialStateModeRow,w=3)
		self.InitialStateModeRow.setStretchWidget( Spacer )
		MelSpacer(self.InitialStateModeRow,w=2)		
		self.InitialStateModeRow.layout()	
		
		mc.radioCollection(self.PuppetModeCollection ,edit=True,sl= (self.PuppetModeCollectionChoices[ (self.PuppetModeOptionVar.value) ]))
		self.UI_StateRows['define'].append(self.InitialStateModeRow)
		
		
		self.AxisFrame = MelFrameLayout(TopSection,label = 'Axis',vis=False,
		                                collapse=True,
		                                collapsable=True,
		                                ut = 'cgmUIHeaderTemplate')
		self.UI_StateRows['define'].append(self.AxisFrame)
		MelSeparator(TopSection,style='none',h=5)						
		
		#Aim Axis Mode Row
		self.AimAxisCollection = MelRadioCollection()
		self.AimAxisCollectionChoices = []			
		
		self.AimAxisRow = MelHSingleStretchLayout(self.AxisFrame,padding = 2,vis=False)	
		MelSpacer(self.AimAxisRow,w=5)				
		MelLabel(self.AimAxisRow,l='Aim ')
		Spacer = MelSeparator(self.AimAxisRow,w=10)						
		for i,item in enumerate(axisDirectionsByString):
			self.AimAxisCollectionChoices.append(self.AimAxisCollection.createButton(self.AimAxisRow,label=item,
			                                                                         onCommand = Callback(puppetBoxLib.setPuppetAxisAim,self,i)))
			MelSpacer(self.AimAxisRow,w=3)
		self.AimAxisRow.setStretchWidget( Spacer )
		MelSpacer(self.AimAxisRow,w=2)		
		self.AimAxisRow.layout()	
		
		
		#Up Axis Mode Row
		self.UpAxisCollection = MelRadioCollection()
		self.UpAxisCollectionChoices = []			
		
		self.UpAxisRow = MelHSingleStretchLayout(self.AxisFrame,padding = 2,vis=False)	
		MelSpacer(self.UpAxisRow,w=5)				
		MelLabel(self.UpAxisRow,l='Up ')
		Spacer = MelSeparator(self.UpAxisRow,w=10)						
		for i,item in enumerate(axisDirectionsByString):
			self.UpAxisCollectionChoices.append(self.UpAxisCollection.createButton(self.UpAxisRow,label=item,
			                                                                         onCommand = Callback(puppetBoxLib.setPuppetAxisUp,self,i)))
			MelSpacer(self.UpAxisRow,w=3)
		self.UpAxisRow.setStretchWidget( Spacer )
		MelSpacer(self.UpAxisRow,w=2)		
		self.UpAxisRow.layout()	
		
		
		#Out Axis Mode Row
		self.OutAxisCollection = MelRadioCollection()
		self.OutAxisCollectionChoices = []			
		
		self.OutAxisRow = MelHSingleStretchLayout(self.AxisFrame,padding = 2,vis=False)	
		MelSpacer(self.OutAxisRow,w=5)				
		MelLabel(self.OutAxisRow,l='Out ')
		Spacer = MelSeparator(self.OutAxisRow,w=10)	
		for i,item in enumerate(axisDirectionsByString):
			self.OutAxisCollectionChoices.append(self.OutAxisCollection.createButton(self.OutAxisRow,label=item,
			                                                                         onCommand = Callback(puppetBoxLib.setPuppetAxisOut,self,i)))
			MelSpacer(self.OutAxisRow,w=3)
		self.OutAxisRow.setStretchWidget( Spacer )
		MelSpacer(self.OutAxisRow,w=2)		
		self.OutAxisRow.layout()	
		
		#Set toggles on menu
		mc.radioCollection(self.AimAxisCollection ,edit=True,sl= (self.AimAxisCollectionChoices[ (self.PuppetAimOptionVar.value) ]))		
		mc.radioCollection(self.UpAxisCollection ,edit=True,sl= (self.UpAxisCollectionChoices[ (self.PuppetUpOptionVar.value) ]))		
		mc.radioCollection(self.OutAxisCollection ,edit=True,sl= (self.OutAxisCollectionChoices[ (self.PuppetOutOptionVar.value) ]))
		
		
		#Initial State Button Row
		self.InitialStateButtonRow = MelHLayout(TopSection, h = 20,vis=False,padding = 5)
		guiFactory.doButton2(self.InitialStateButtonRow,'Add Geo',
		                     lambda *a:puppetBoxLib.doAddGeo(self))
		guiFactory.doButton2(self.InitialStateButtonRow,'Build Size Template',
		                     lambda *a:puppetBoxLib.doBuildSizeTemplate(self))
		
		self.InitialStateButtonRow.layout()
		self.UI_StateRows['define'].append(self.InitialStateButtonRow)
		
		#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		# Multi Module
		#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

		#>>>  All Sets menu
		AllModulesRow = MelFormLayout(MainForm,height = 20)
		activeState = True
		i = 1
			
		tmpActive = MelCheckBox(AllModulesRow,
	                            annotation = 'Sets all sets active',
	                            value = activeState,
	                            onCommand =  Callback(puppetBoxLib.doSetAllSetsAsActive,self),
	                            offCommand = Callback(puppetBoxLib.doSetAllSetsAsInactive,self))
		
		tmpSel = guiFactory.doButton2(AllModulesRow,
		                              ' s ',
		                              'Select All Loaded/Active Sets')
						
		# Mode toggle box
		self.ModuleModeOptionMenu = MelOptionMenu(AllModulesRow,
		                                       cc = modeSet)
			
			
		tmpKey = guiFactory.doButton2(AllModulesRow,
	                                  ' k ',
		                              'Key All Sets')
		tmpDeleteKey = guiFactory.doButton2(AllModulesRow,
	                                    ' d ',
	                                    'Delete All Set Keys')	
		tmpReset = guiFactory.doButton2(AllModulesRow,
	                                    ' r ',
	                                    'Reset All Set Keys')	
		
		mc.formLayout(AllModulesRow, edit = True,
	                  af = [(tmpActive, "left", 10),
	                        (tmpReset,"right",10)],
	                  ac = [(tmpSel,"left",0,tmpActive),
	                        (self.ModuleModeOptionMenu,"left",4,tmpSel),
	                        (self.ModuleModeOptionMenu,"right",4,tmpKey),
	                        (tmpKey,"right",2,tmpDeleteKey),
		                    (tmpDeleteKey,"right",2,tmpReset)
		                    ])
		
		#>>> Sets building section
		allPopUpMenu = MelPopupMenu(self.ModuleModeOptionMenu ,button = 3)
		
		allCategoryMenu = MelMenuItem(allPopUpMenu,
	                               label = 'Make Type:',
	                               sm = True)

			
		
		
		#>>> Sets building section
		ModuleListScroll = MelScrollLayout(MainForm,cr = 1, ut = 'cgmUISubTemplate')
		ModuleMasterForm = MelFormLayout(ModuleListScroll)
		self.ModuleListColumn = MelColumnLayout(ModuleMasterForm,ut = 'cgmUIInstructionsTemplate', adj = True, rowSpacing = 2)
		
		
		
		self.helpInfo = MelLabel(MainForm,
		                         h=20,
		                         l = "Add a Puppet",
		                         ut = 'cgmUIInstructionsTemplate',
		                         al = 'center',
		                         ww = True,vis = self.ShowHelpOptionVar.value)
		self.helpBlurbs.extend([self.helpInfo ])
		
		VerifyRow = guiFactory.doButton2(MainForm,
		                                'Check Puppet',
		                                'Create new buffer from selected buffer')	
			
		ModuleMasterForm(edit = True,
		                 af = [(self.ModuleListColumn,"top",0),
		                       (self.ModuleListColumn,"left",0),
		                       (self.ModuleListColumn,"right",0),
		                       (self.ModuleListColumn,"bottom",0)])
		
		
		MainForm(edit = True,
		         af = [(TopSection,"top",0),	
		               (TopSection,"left",0),
		               (TopSection,"right",0),		               
		               (AllModulesRow,"left",0),
		               (AllModulesRow,"right",0),
		               (ModuleListScroll,"left",0),
		               (ModuleListScroll,"right",0),
		               (ModuleListScroll,"left",0),
		               (ModuleListScroll,"right",0),				       
		               (self.helpInfo,"left",8),
		               (self.helpInfo,"right",8),
		               (VerifyRow,"left",4),
		               (VerifyRow,"right",4),		               
		               (VerifyRow,"bottom",4)],
		         ac = [(AllModulesRow,"top",2,TopSection),
		               (ModuleListScroll,"top",2,AllModulesRow),
		               (ModuleListScroll,"bottom",0,self.helpInfo),
		               (self.helpInfo,"bottom",0,VerifyRow)],
		         attachNone = [(VerifyRow,"top")])	
示例#4
0
class animToolsClass(BaseMelWindow):
	from  cgm.lib import guiFactory
	guiFactory.initializeTemplates()
	USE_Template = 'cgmUITemplate'
	
	WINDOW_NAME = 'cgmAnimToolsWindow'
	WINDOW_TITLE = 'cgm.animTools - %s'%__version__
	DEFAULT_SIZE = 180, 350
	DEFAULT_MENU = None
	RETAIN = True
	MIN_BUTTON = True
	MAX_BUTTON = False
	FORCE_DEFAULT_SIZE = True  #always resets the size of the window when its re-created


	def __init__( self):

		self.toolName = 'cgm.animTools'
		self.description = 'This is a series of tools for basic animation functions'
		self.author = 'Josh Burton'
		self.owner = 'CG Monks'
		self.website = 'www.cgmonks.com'
		self.version =  __version__ 
		self.optionVars = []

		self.currentFrameOnly = True
		self.startFrame = ''
		self.endFrame = ''
		self.startFrameField = ''
		self.endFrameField = ''
		self.forceBoundingBoxState = False
		self.forceEveryFrame = False
		self.showHelp = False
		self.helpBlurbs = []
		self.oldGenBlurbs = []

		self.showTimeSubMenu = False
		self.timeSubMenu = []

		#Menu
		self.setupVariables()
		self.UI_OptionsMenu = MelMenu( l='Options', pmc=self.buildOptionsMenu)
		self.UI_BufferMenu = MelMenu( l = 'Buffer', pmc=self.buildBufferMenu)
		self.UI_HelpMenu = MelMenu( l='Help', pmc=self.buildHelpMenu)
		
		self.ShowHelpOption = mc.optionVar( q='cgmVar_AnimToolsShowHelp' )
		
		#Tabs
		tabs = MelTabLayout( self )
		MatchTab = MelColumnLayout(tabs)
		SnapTab = MelColumnLayout( tabs )
		KeysTab = MelColumnLayout( tabs )

		n = 0
		for tab in 'Match','Snap','Keys':
			tabs.setLabel(n,tab)
			n+=1

		self.Match_buildLayout(MatchTab)
		self.Snap_buildLayout(SnapTab)
		self.Keys_buildLayout(KeysTab)

		self.show()

	def setupVariables(self):
		self.LocinatorUpdateObjectsOptionVar = OptionVarFactory('cgmVar_AnimToolsUpdateMode',defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.LocinatorUpdateObjectsOptionVar.name)
		
		self.LocinatorUpdateObjectsBufferOptionVar = OptionVarFactory('cgmVar_LocinatorUpdateObjectsBuffer',defaultValue = [''])
		guiFactory.appendOptionVarList(self,self.LocinatorUpdateObjectsBufferOptionVar.name)	
		
		self.DebugModeOptionVar = OptionVarFactory('cgmVar_AnimToolsDebug',defaultValue=0)
		guiFactory.appendOptionVarList(self,self.DebugModeOptionVar.name)		
		
		#Old method...clean up at some point
		if not mc.optionVar( ex='cgmVar_ForceBoundingBoxState' ):
			mc.optionVar( iv=('cgmVar_ForceBoundingBoxState', 0) )
		if not mc.optionVar( ex='cgmVar_ForceEveryFrame' ):
			mc.optionVar( iv=('cgmVar_ForceEveryFrame', 0) )
		if not mc.optionVar( ex='cgmVar_animToolsShowHelp' ):
			mc.optionVar( iv=('cgmVar_animToolsShowHelp', 0) )
		if not mc.optionVar( ex='cgmVar_CurrentFrameOnly' ):
			mc.optionVar( iv=('cgmVar_CurrentFrameOnly', 0) )
		if not mc.optionVar( ex='cgmVar_animToolsShowHelp' ):
			mc.optionVar( iv=('cgmVar_animToolsShowHelp', 0) )
			
		guiFactory.appendOptionVarList(self,'cgmVar_animToolsShowHelp')
		
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	# Menus
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	def buildOptionsMenu( self, *a ):
		self.UI_OptionsMenu.clear()

		# Placement Menu
		PlacementMenu = MelMenuItem( self.UI_OptionsMenu, l='Placement', subMenu=True)
		PlacementMenuCollection = MelRadioMenuCollection()

		if mc.optionVar( q='cgmVar_ForceBoundingBoxState' ) == 0:
			cgmOption = False
			pivotOption = True
		else:
			cgmOption = True
			pivotOption = False

		PlacementMenuCollection.createButton(PlacementMenu,l='Bounding Box Center',
				                             c=lambda *a: mc.optionVar( iv=('cgmVar_ForceBoundingBoxState', 1)),
				                             rb=cgmOption )
		PlacementMenuCollection.createButton(PlacementMenu,l='Pivot',
				                             c=lambda *a: mc.optionVar( iv=('cgmVar_ForceBoundingBoxState', 0)),
				                             rb=pivotOption )
		
		# Tagging options
		AutoloadMenu = MelMenuItem( self.UI_OptionsMenu, l='Tagging', subMenu=True)
		if not mc.optionVar( ex='cgmVar_TaggingUpdateRO' ):
			mc.optionVar( iv=('cgmVar_TaggingUpdateRO', 1) )
		guiFactory.appendOptionVarList(self,'cgmVar_TaggingUpdateRO')	
	  
		RenameOnUpdateState = mc.optionVar( q='cgmVar_TaggingUpdateRO' )
		MelMenuItem( AutoloadMenu, l="Update Rotation Order",
	                 cb= mc.optionVar( q='cgmVar_TaggingUpdateRO' ),
	                 c= lambda *a: guiFactory.doToggleIntOptionVariable('cgmVar_TaggingUpdateRO'))
		
		# Update Mode
		UpdateMenu = MelMenuItem( self.UI_OptionsMenu, l='Update Mode', subMenu=True)
		UpdateMenuCollection = MelRadioMenuCollection()

		if self.LocinatorUpdateObjectsOptionVar.value == 0:
			slMode = True
			bufferMode = False
		else:
			slMode = False
			bufferMode = True

		UpdateMenuCollection.createButton(UpdateMenu,l='Selected',
				                             c=lambda *a: self.LocinatorUpdateObjectsOptionVar.set(0),
				                             rb=slMode )
		UpdateMenuCollection.createButton(UpdateMenu,l='Buffer',
				                             c=lambda *a:self.LocinatorUpdateObjectsOptionVar.set(1),
				                             rb=bufferMode )
		
		
		MelMenuItemDiv( self.UI_OptionsMenu )
		MelMenuItem( self.UI_OptionsMenu, l="Reset",
			         c=lambda *a: guiFactory.resetGuiInstanceOptionVars(self.optionVars,run))

	def buildBufferMenu( self, *a ):
		self.UI_BufferMenu.clear()
		
		MelMenuItem( self.UI_BufferMenu, l="Define",
		             c= lambda *a: locinatorLib.defineObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
		MelMenuItem( self.UI_BufferMenu, l="Add Selected",
		             c= lambda *a: locinatorLib.addSelectedToObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
		MelMenuItem( self.UI_BufferMenu, l="Remove Selected",
		             c= lambda *a: locinatorLib.removeSelectedFromObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
		MelMenuItemDiv( self.UI_BufferMenu )
		MelMenuItem( self.UI_BufferMenu, l="Select Members",
				     c= lambda *a: locinatorLib.selectObjBufferMembers(self.LocinatorUpdateObjectsBufferOptionVar))
		MelMenuItem( self.UI_BufferMenu, l="Clear",
		             c= lambda *a: locinatorLib.clearObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
	def buildHelpMenu( self, *a ):
		self.UI_HelpMenu.clear()
		MelMenuItem( self.UI_HelpMenu, l="Show Help",
				     cb=self.ShowHelpOption,
				     c= lambda *a: self.do_showHelpToggle())
		MelMenuItem( self.UI_HelpMenu, l="Print Tools Help",
				     c=lambda *a: self.printHelp() )

		MelMenuItemDiv( self.UI_HelpMenu )
		MelMenuItem( self.UI_HelpMenu, l="About",
				     c=lambda *a: self.showAbout() )
		MelMenuItem( self.UI_HelpMenu, l="Debug",
				     cb=self.DebugModeOptionVar.value,
				     c= lambda *a: self.DebugModeOptionVar.toggle())			

	def do_showHelpToggle( self):
		guiFactory.toggleMenuShowState(self.ShowHelpOption,self.helpBlurbs)
		mc.optionVar( iv=('cgmVar_animToolsShowHelp', not self.ShowHelpOption))
		self.ShowHelpOption = mc.optionVar( q='cgmVar_animToolsShowHelp' )

	def do_showTimeSubMenuToggleOn( self):
		guiFactory.toggleMenuShowState(1,self.timeSubMenu)
		mc.optionVar( iv=('cgmVar_CurrentFrameOnly', 1))

	def do_showTimeSubMenuToggleOff( self):
		guiFactory.toggleMenuShowState(0,self.timeSubMenu)
		mc.optionVar( iv=('cgmVar_CurrentFrameOnly', 0))


	def showAbout(self):
		window = mc.window( title="About", iconName='About', ut = 'cgmUITemplate',resizeToFitChildren=True )
		mc.columnLayout( adjustableColumn=True )
		guiFactory.header(self.toolName,overrideUpper = True)
		mc.text(label='>>>A Part of the cgmTools Collection<<<', ut = 'cgmUIInstructionsTemplate')
		guiFactory.headerBreak()
		guiFactory.lineBreak()
		descriptionBlock = guiFactory.textBlock(self.description)

		guiFactory.lineBreak()
		mc.text(label=('%s%s' %('Written by: ',self.author)))
		mc.text(label=('%s%s%s' %('Copyright ',self.owner,', 2011')))
		guiFactory.lineBreak()
		mc.text(label='Version: %s' % self.version)
		mc.text(label='')
		guiFactory.doButton('Visit Tool Webpage', 'import webbrowser;webbrowser.open(" http://www.cgmonks.com/tools/maya-tools/animTools/")')
		guiFactory.doButton('Close', 'import maya.cmds as mc;mc.deleteUI(\"' + window + '\", window=True)')
		mc.setParent( '..' )
		mc.showWindow( window )

	def printHelp(self):
		import animToolsLib
		help(animToolsLib)

	def do_everyFrameToggle( self):
		EveryFrameOption = mc.optionVar( q='cgmVar_ForceEveryFrame' )
		guiFactory.toggleMenuShowState(EveryFrameOption,self.timeSubMenu)
		mc.optionVar( iv=('cgmVar_ForceEveryFrame', not EveryFrameOption))



	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	# Layouts
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	def buildPlaceHolder(self,parent):
		self.containerName = MelColumnLayout(parent,ut='cgmUISubTemplate')
		return self.containerName
	
	def buildTimeSubMenu(self,parent):
		self.containerName = MelColumnLayout(parent,ut='cgmUISubTemplate')
		# Time Submenu
		mc.setParent(self.containerName)
		self.helpBlurbs.extend(guiFactory.instructions(" Set your time range",vis = self.ShowHelpOption))

		timelineInfo = search.returnTimelineInfo()


		# TimeInput Row
		TimeInputRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate')
		self.timeSubMenu.append( TimeInputRow )
		MelSpacer(TimeInputRow)
		MelLabel(TimeInputRow,l='start')

		self.startFrameField = MelIntField(TimeInputRow,'cgmLocWinStartFrameField',
	                                       width = 40,
	                                       value= timelineInfo['rangeStart'])
		TimeInputRow.setStretchWidget( MelSpacer(TimeInputRow) )
		MelLabel(TimeInputRow,l='end')

		self.endFrameField = MelIntField(TimeInputRow,'cgmLocWinEndFrameField',
	                                     width = 40,
	                                     value= timelineInfo['rangeEnd'])

		MelSpacer(TimeInputRow)
		TimeInputRow.layout()

		MelSeparator(self.containerName,ut = 'cgmUISubTemplate',style='none',height = 5)
		

		# Button Row
		TimeButtonRow = MelHSingleStretchLayout(self.containerName,padding = 1, ut='cgmUISubTemplate')
		MelSpacer(TimeButtonRow,w=2)
		currentRangeButton = guiFactory.doButton2(TimeButtonRow,'Current Range',
	                                              lambda *a: locinatorLib.setGUITimeRangeToCurrent(self),
	                                              'Sets the time range to the current slider range')
		TimeButtonRow.setStretchWidget( MelSpacer(TimeButtonRow,w=2) )
		sceneRangeButton = guiFactory.doButton2(TimeButtonRow,'Scene Range',
	                                            lambda *a: locinatorLib.setGUITimeRangeToScene(self),
	                                            'Sets the time range to the current slider range')
		MelSpacer(TimeButtonRow,w=2)
		
		TimeButtonRow.layout()

		
		#>>> Base Settings Flags
		self.KeyingModeCollection = MelRadioCollection()
		self.KeyingModeCollectionChoices = []		
		if not mc.optionVar( ex='cgmVar_AnimToolsKeyingMode' ):
			mc.optionVar( iv=('cgmVar_AnimToolsKeyingMode', 0) )
		guiFactory.appendOptionVarList(self,'cgmVar_AnimToolsKeyingMode')
		
		KeysSettingsFlagsRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate',padding = 2)
		MelSpacer(KeysSettingsFlagsRow,w=2)	
		KeysSettingsFlagsRow.setStretchWidget( MelLabel(KeysSettingsFlagsRow,l='Anim Option: ',align='right') )
		self.keyingOptions = ['Keys','All']
		for item in self.keyingOptions:
			cnt = self.keyingOptions.index(item)
			self.KeyingModeCollectionChoices.append(self.KeyingModeCollection.createButton(KeysSettingsFlagsRow,label=self.keyingOptions[cnt],
			                                                                               onCommand = Callback(guiFactory.toggleOptionVarState,self.keyingOptions[cnt],self.keyingOptions,'cgmVar_AnimToolsKeyingMode',True)))
			MelSpacer(KeysSettingsFlagsRow,w=5)
		mc.radioCollection(self.KeyingModeCollection ,edit=True,sl= (self.KeyingModeCollectionChoices[ (mc.optionVar(q='cgmVar_AnimToolsKeyingMode')) ]))
		
		KeysSettingsFlagsRow.layout()

		#>>> Base Settings Flags
		self.KeyingTargetCollection = MelRadioCollection()
		self.KeyingTargetCollectionChoices = []		
		if not mc.optionVar( ex='cgmVar_AnimToolsKeyingTarget' ):
			mc.optionVar( iv=('cgmVar_AnimToolsKeyingTarget', 0) )
		guiFactory.appendOptionVarList(self,'cgmVar_AnimToolsKeyingTarget')
		
		BakeSettingsFlagsRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate',padding = 2)
		MelSpacer(BakeSettingsFlagsRow,w=2)	
		BakeSettingsFlagsRow.setStretchWidget( MelLabel(BakeSettingsFlagsRow,l='From: ',align='right') )
		MelSpacer(BakeSettingsFlagsRow)
		self.keyTargetOptions = ['source','self']
		for item in self.keyTargetOptions:
			cnt = self.keyTargetOptions.index(item)
			self.KeyingTargetCollectionChoices.append(self.KeyingTargetCollection.createButton(BakeSettingsFlagsRow,label=self.keyTargetOptions[cnt],
		                                                                                       onCommand = Callback(guiFactory.toggleOptionVarState,self.keyTargetOptions[cnt],self.keyTargetOptions,'cgmVar_AnimToolsKeyingTarget',True)))
			MelSpacer(BakeSettingsFlagsRow,w=5)
		mc.radioCollection(self.KeyingTargetCollection ,edit=True,sl= (self.KeyingTargetCollectionChoices[ (mc.optionVar(q='cgmVar_AnimToolsKeyingTarget')) ]))
		
		BakeSettingsFlagsRow.layout()
		
		return self.containerName
	
	def Match_buildLayout(self,parent):
		mc.setParent(parent)
		guiFactory.header('Update')

		#>>>Match Mode
		self.MatchModeCollection = MelRadioCollection()
		self.MatchModeCollectionChoices = []		
		if not mc.optionVar( ex='cgmVar_AnimToolsMatchMode' ):
			mc.optionVar( iv=('cgmVar_AnimToolsMatchMode', 0) )	
			
		guiFactory.appendOptionVarList(self,'cgmVar_AnimToolsMatchMode')
			
		#MatchModeFlagsRow = MelHLayout(parent,ut='cgmUISubTemplate',padding = 2)	
		MatchModeFlagsRow = MelHSingleStretchLayout(parent,ut='cgmUIReservedTemplate',padding = 2)	
		MelSpacer(MatchModeFlagsRow,w=2)				
		self.MatchModeOptions = ['parent','point','orient']
		for item in self.MatchModeOptions:
			cnt = self.MatchModeOptions.index(item)
			self.MatchModeCollectionChoices.append(self.MatchModeCollection.createButton(MatchModeFlagsRow,label=self.MatchModeOptions[cnt],
			                                                                             onCommand = Callback(guiFactory.toggleOptionVarState,self.MatchModeOptions[cnt],self.MatchModeOptions,'cgmVar_AnimToolsMatchMode',True)))
			MelSpacer(MatchModeFlagsRow,w=3)
		MatchModeFlagsRow.setStretchWidget( self.MatchModeCollectionChoices[-1] )
		MelSpacer(MatchModeFlagsRow,w=2)		
		MatchModeFlagsRow.layout()	
		
		mc.radioCollection(self.MatchModeCollection ,edit=True,sl= (self.MatchModeCollectionChoices[ (mc.optionVar(q='cgmVar_AnimToolsMatchMode')) ]))
		
		#>>>Time Section
		UpdateOptionRadioCollection = MelRadioCollection()
		
		#>>> Time Menu Container
		self.BakeModeOptionList = ['Current Frame','Bake']
		cgmVar_Name = 'cgmVar_AnimToolsBakeState'
		if not mc.optionVar( ex=cgmVar_Name ):
			mc.optionVar( iv=(cgmVar_Name, 0) )
			
		EveryFrameOption = mc.optionVar( q='cgmVar_AnimToolsBakeState' )
		guiFactory.appendOptionVarList(self,'cgmVar_AnimToolsBakeState')
		
		#build our sub section options
		self.ContainerList = []
		
		#Mode Change row 
		ModeSetRow = MelHSingleStretchLayout(parent,ut='cgmUISubTemplate')
		self.BakeModeRadioCollection = MelRadioCollection()
		self.BakeModeChoiceList = []	
		MelSpacer(ModeSetRow,w=2)

		self.BakeModeChoiceList.append(self.BakeModeRadioCollection.createButton(ModeSetRow,label=self.BakeModeOptionList[0],
	                                                                      onCommand = Callback(guiFactory.toggleModeState,self.BakeModeOptionList[0],self.BakeModeOptionList,cgmVar_Name,self.ContainerList,True)))
		
		ModeSetRow.setStretchWidget( MelSpacer(ModeSetRow) )
		
		self.BakeModeChoiceList.append(self.BakeModeRadioCollection.createButton(ModeSetRow,label=self.BakeModeOptionList[1],
	                                                                      onCommand = Callback(guiFactory.toggleModeState,self.BakeModeOptionList[1],self.BakeModeOptionList,cgmVar_Name,self.ContainerList,True)))
		
		ModeSetRow.layout()
		
		
		#>>>
		self.ContainerList.append( self.buildPlaceHolder(parent) )
		self.ContainerList.append( self.buildTimeSubMenu( parent) )
		
		mc.radioCollection(self.BakeModeRadioCollection,edit=True, sl=self.BakeModeChoiceList[mc.optionVar(q=cgmVar_Name)])
		#>>>
		
		mc.setParent(parent)

		guiFactory.doButton2(parent,'Do it!',
	                         lambda *a: locinatorLib.doUpdateLoc(self),
	                         'Update an obj or locator at a particular frame or through a timeline')

		guiFactory.lineSubBreak()


		#>>>  Loc Me Section
		guiFactory.lineBreak()
		guiFactory.lineSubBreak()
		guiFactory.doButton2(parent,'Just Loc Selected',
			                 lambda *a: locinatorLib.doLocMe(self),
			                 'Create an updateable locator based off the selection and options')


		#>>>  Tag Section
		guiFactory.lineSubBreak()
		guiFactory.doButton2(parent,'Tag it',
		                     lambda *a: locinatorLib.doTagObjects(self),
				             "Tag the selected objects to the first locator in the selection set. After this relationship is set up, you can match objects to that locator.")



	def Keys_buildLayout(self,parent):
		SpecialColumn = MelColumnLayout(parent)

		#>>>  Center Section
		guiFactory.header('Tangents')		
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SpecialColumn,'autoTangent',
		                     lambda *a: mel.eval('autoTangent'),
				             'Fantastic script courtesy of Michael Comet')
		
		guiFactory.lineBreak()		
		guiFactory.header('Breakdowns')
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SpecialColumn,'tweenMachine',
		                     lambda *a: mel.eval('tweenMachine'),
				             'Breakdown tool courtesy of Justin Barrett')
		guiFactory.lineSubBreak()		
		guiFactory.doButton2(SpecialColumn,'breakdownDragger',
		                     lambda *a: animToolsLib.ml_breakdownDraggerCall(),
				             'Breakdown tool courtesy of Morgan Loomis')
		
		guiFactory.lineBreak()		
		guiFactory.header('Utilities')
		guiFactory.lineSubBreak()		
		guiFactory.doButton2(SpecialColumn,'arcTracr',
		                     lambda *a: animToolsLib.ml_arcTracerCall(),
				             'Path tracing tool courtesy of Morgan Loomis')
		guiFactory.lineSubBreak()				
		guiFactory.doButton2(SpecialColumn,'copy Anim',
		                     lambda *a: animToolsLib.ml_copyAnimCall(),
				             'Animation copy tool courtesy of Morgan Loomis')
		guiFactory.lineSubBreak()				
		guiFactory.doButton2(SpecialColumn,'convert Rotation Order',
		                     lambda *a: animToolsLib.ml_convertRotationOrderCall(),
				             'Rotation Order Conversion tool courtesy of Morgan Loomis')
		guiFactory.lineSubBreak()				
		guiFactory.doButton2(SpecialColumn,'stopwatch',
		                     lambda *a: animToolsLib.ml_stopwatchCall(),
				             'Stop Watch tool courtesy of Morgan Loomis')

	def Snap_buildLayout(self,parent):

		SnapColumn = MelColumnLayout(parent)

		#>>>  Snap Section
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SnapColumn,'Parent Snap',
		                     lambda *a: tdToolsLib.doParentSnap(),
				             "Basic Parent Snap")
		
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SnapColumn,'Point Snap',
		                     lambda *a: tdToolsLib.doPointSnap(),
				             "Basic Point Snap")
		
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SnapColumn,'Orient Snap',
		                     lambda *a: tdToolsLib.doOrientSnap(),
				             "Basic Orient Snap")
示例#5
0
class attrToolsClass(BaseMelWindow):
	from  cgm.lib import guiFactory
	guiFactory.initializeTemplates()
	USE_Template = 'cgmUITemplate'
	
	WINDOW_NAME = 'attrTools'
	WINDOW_TITLE = 'cgm.attrTools - %s'%__version__
	DEFAULT_SIZE = 375, 350
	DEFAULT_MENU = None
	RETAIN = True
	MIN_BUTTON = True
	MAX_BUTTON = False
	FORCE_DEFAULT_SIZE = True  #always resets the size of the window when its re-created

	def __init__( self):	

		# Basic variables
		self.window = ''
		self.activeTab = ''
		self.toolName = 'attrTools'
		self.module = 'tdTools'
		self.winName = 'attrToolsWin'
		self.optionVars = []

		self.showHelp = False
		self.helpBlurbs = []
		self.oldGenBlurbs = []

		self.showTimeSubMenu = False
		self.timeSubMenu = []
		
		self.setupVariables()
		self.loadAttrs = []

		# About Window
		self.description = 'Tools for working with attributes'
		self.author = 'Josh Burton'
		self.owner = 'CG Monks'
		self.website = 'www.cgmonks.com'
		self.version = __version__

		# About Window

		#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		# Build
		#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

		#Menu
		self.UI_OptionsMenu = MelMenu( l='Options', pmc=self.buildOptionsMenu)
		self.UI_HelpMenu = MelMenu( l='Help', pmc=self.buildHelpMenu)
		

		WindowForm = MelColumnLayout(self)
		           
		self.buildAttributeTool(WindowForm)
		
		if mc.ls(sl=True):
			attrToolsLib.uiLoadSourceObject(self)
		
		self.show()


	def setupVariables(self):
		self.SortModifyOptionVar = OptionVarFactory('cgmVar_attrToolsSortModfiy', defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.SortModifyOptionVar.name)
		
		self.HideTransformsOptionVar = OptionVarFactory('cgmVar_attrToolsHideTransform', defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.HideTransformsOptionVar.name)
		
		self.HideUserDefinedOptionVar = OptionVarFactory('cgmVar_attrToolsHideUserDefined', defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.HideUserDefinedOptionVar.name)		
		
		self.HideParentAttrsOptionVar = OptionVarFactory('cgmVar_attrToolsHideParentAttrs', defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.HideParentAttrsOptionVar.name)
		
		self.HideCGMAttrsOptionVar = OptionVarFactory('cgmVar_attrToolsHideCGMAttrs', defaultValue = 1)
		guiFactory.appendOptionVarList(self,self.HideCGMAttrsOptionVar.name)
		
		self.HideNonstandardOptionVar = OptionVarFactory('cgmVar_attrToolsHideNonStandard', defaultValue = 1)
		guiFactory.appendOptionVarList(self,self.HideNonstandardOptionVar.name)			

		self.ShowHelpOptionVar = OptionVarFactory('cgmVar_attrToolsShowHelp', defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.ShowHelpOptionVar.name)
		
		self.SourceObjectOptionVar = OptionVarFactory('cgmVar_AttributeSourceObject', defaultValue= '')
		guiFactory.appendOptionVarList(self,self.SourceObjectOptionVar.name)
		
		self.CopyAttrModeOptionVar = OptionVarFactory('cgmVar_CopyAttributeMode', defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.CopyAttrModeOptionVar.name)	
		
		self.CopyAttrOptionsOptionVar = OptionVarFactory('cgmVar_CopyAttributeOptions', defaultValue = 1)
		guiFactory.appendOptionVarList(self,self.CopyAttrOptionsOptionVar.name)	
		
		self.TransferValueOptionVar = OptionVarFactory('cgmVar_AttributeTransferValueState', defaultValue = 1)
		guiFactory.appendOptionVarList(self,self.TransferValueOptionVar.name)	
		
		self.TransferIncomingOptionVar = OptionVarFactory('cgmVar_AttributeTransferInConnectionState', defaultValue = 1)
		guiFactory.appendOptionVarList(self,self.TransferIncomingOptionVar.name)		
		
		self.TransferOutgoingOptionVar = OptionVarFactory('cgmVar_AttributeTransferOutConnectionState', defaultValue = 1)
		guiFactory.appendOptionVarList(self,self.TransferOutgoingOptionVar.name)	
		
		self.TransferKeepSourceOptionVar = OptionVarFactory('cgmVar_AttributeTransferKeepSourceState', defaultValue = 1)
		guiFactory.appendOptionVarList(self,self.TransferKeepSourceOptionVar.name)	
		
		self.TransferConvertStateOptionVar = OptionVarFactory('cgmVar_AttributeTransferConvertState', defaultValue = 1)
		guiFactory.appendOptionVarList(self,self.TransferConvertStateOptionVar.name)
		
		self.TransferDriveSourceStateOptionVar = OptionVarFactory('cgmVar_AttributeTransferConnectToSourceState', defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.TransferDriveSourceStateOptionVar.name)	
		
		self.CreateAttrTypeOptionVar = OptionVarFactory('cgmVar_AttrCreateType',defaultValue='')
		guiFactory.appendOptionVarList(self,self.CreateAttrTypeOptionVar.name)	
		
		self.DebugModeOptionVar = OptionVarFactory('cgmVar_AttrToolsDebug',defaultValue=0)
		guiFactory.appendOptionVarList(self,self.DebugModeOptionVar.name)			
		
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	# Menus
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	def buildHelpMenu(self, *a ):
		self.UI_HelpMenu.clear()		
		MelMenuItem( self.UI_HelpMenu, l="Print Tools Help",
				     c=lambda *a: self.printHelp() )
		MelMenuItem( self.UI_HelpMenu, l="About",
				     c=lambda *a: self.showAbout() )
		MelMenuItemDiv( self.UI_HelpMenu )
		
		MelMenuItem( self.UI_HelpMenu, l="Debug",
				     cb=self.DebugModeOptionVar.value,
				     c= lambda *a: self.DebugModeOptionVar.toggle())		
		
	def buildOptionsMenu( self, *a ):
		self.UI_OptionsMenu.clear()
		
		#>>> Grouping Options
		HidingMenu = MelMenuItem( self.UI_OptionsMenu, l='Autohide:', subMenu=True)
		MelMenuItem( self.UI_OptionsMenu, l="Sort Modify",
			         cb=self.SortModifyOptionVar.value,
		             annotation = "Sort the list of attributes in/nthe modify section alphabetically",
		             c = lambda *a: attrToolsLib.uiToggleOptionCB(self,self.SortModifyOptionVar))	
		
		#guiFactory.appendOptionVarList(self,'cgmVar_MaintainLocalSetGroup')			
		MelMenuItem( HidingMenu, l="Transforms",
	                 cb= self.HideTransformsOptionVar.value,
	                 c= lambda *a: attrToolsLib.uiToggleOptionCB(self,self.HideTransformsOptionVar))
		
		MelMenuItem( HidingMenu, l="User Defined",
	                 cb= self.HideUserDefinedOptionVar.value,
	                 c= lambda *a: attrToolsLib.uiToggleOptionCB(self,self.HideUserDefinedOptionVar))		
		
		MelMenuItem( HidingMenu, l="Parent Attributes",
	                 cb= self.HideParentAttrsOptionVar.value,
	                 c= lambda *a: attrToolsLib.uiToggleOptionCB(self,self.HideParentAttrsOptionVar))
		
		MelMenuItem( HidingMenu, l="CGM Attributes",
	                 cb= self.HideCGMAttrsOptionVar.value,
	                 c= lambda *a: attrToolsLib.uiToggleOptionCB(self,self.HideCGMAttrsOptionVar))		
		
		MelMenuItem( HidingMenu, l="Nonstandard",
	                 cb= self.HideNonstandardOptionVar.value,
	                 c= lambda *a: attrToolsLib.uiToggleOptionCB(self,self.HideNonstandardOptionVar))
		
		
		#>>> Reset Options		
		MelMenuItemDiv( self.UI_OptionsMenu )
		MelMenuItem( self.UI_OptionsMenu, l="Reload",
			         c=lambda *a: self.reload())		
		MelMenuItem( self.UI_OptionsMenu, l="Reset",
			         c=lambda *a: self.reset())
		

	def showAbout(self):
		window = mc.window( title="About", iconName='About', ut = 'cgmUITemplate',resizeToFitChildren=True )
		mc.columnLayout( adjustableColumn=True )
		guiFactory.header(self.toolName,overrideUpper = True)
		mc.text(label='>>>A Part of the cgmTools Collection<<<', ut = 'cgmUIInstructionsTemplate')
		guiFactory.headerBreak()
		guiFactory.lineBreak()
		descriptionBlock = guiFactory.textBlock(self.description)

		guiFactory.lineBreak()
		mc.text(label=('%s%s' %('Written by: ',self.author)))
		mc.text(label=('%s%s%s' %('Copyright ',self.owner,', 2011')))
		guiFactory.lineBreak()
		mc.text(label='Version: %s' % self.version)
		mc.text(label='')
		guiFactory.doButton('Visit Website', 'import webbrowser;webbrowser.open("http://www.cgmonks.com/tools/maya-tools/attrtools/")')
		guiFactory.doButton('Close', 'import maya.cmds as mc;mc.deleteUI(\"' + window + '\", window=True)')
		mc.setParent( '..' )
		mc.showWindow( window )

	def printHelp(self):
		from cgm.tools.lib import attrToolsLib
		help(attrToolsLib)

	def reset(self):	
		Callback(guiFactory.resetGuiInstanceOptionVars(self.optionVars,run))
		
	def reload(self):	
		run()
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	# Tools
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	def buildAttributeTool(self,parent,vis=True):
		OptionList = ['Tools','Manager','Utilities']
		RadioCollectionName ='AttributeMode'
		RadioOptionList = 'AttributeModeSelectionChoicesList'

		ShowHelpOption = mc.optionVar( q='cgmVar_TDToolsShowHelp' )
		
		self.AttributeModeOptionVar = OptionVarFactory( 'cgmVar_AttributeMode',defaultValue = OptionList[0])
		
		MelSeparator(parent,ut = 'cgmUIHeaderTemplate',h=5)
		
		#Mode Change row 
		self.ModeSetRow = MelHLayout(parent,ut='cgmUISubTemplate',padding = 0)
		MelLabel(self.ModeSetRow, label = 'Choose Mode: ',align='right')
		self.RadioCollectionName = MelRadioCollection()
		self.RadioOptionList = []		

		#build our sub section options
		self.ContainerList = []

		self.ContainerList.append( self.buildAttributeEditingTool(parent,vis=False) )
		self.ContainerList.append( self.buildAttributeManagerTool( parent,vis=False) )
		self.ContainerList.append( self.buildAttributeUtilitiesTool( parent,vis=False) )
		
		for item in OptionList:
			self.RadioOptionList.append(self.RadioCollectionName.createButton(self.ModeSetRow,label=item,
						                                                      onCommand = Callback(guiFactory.toggleModeState,item,OptionList,self.AttributeModeOptionVar.name,self.ContainerList)))
		self.ModeSetRow.layout()


		mc.radioCollection(self.RadioCollectionName,edit=True, sl=self.RadioOptionList[OptionList.index(self.AttributeModeOptionVar.value)])

		
	def buildAttributeEditingTool(self,parent, vis=True):
		#Container
		containerName = 'Attributes Constainer'
		self.containerName = MelColumn(parent,vis=vis)
		
		###Create
		mc.setParent(self.containerName)
		guiFactory.header('Create')
		guiFactory.lineSubBreak()
		
		#>>>Create Row
		attrCreateRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate',padding = 5)
		MelSpacer(attrCreateRow)

		MelLabel(attrCreateRow,l='Names:',align='right')
		self.AttrNamesTextField = MelTextField(attrCreateRow,backgroundColor = [1,1,1],h=20,
		                                       ec = lambda *a: attrToolsLib.doAddAttributesToSelected(self),
		                                       annotation = "Names for the attributes. Create multiple with a ';'. \n Message nodes try to connect to the last object in a selection \n For example: 'Test1;Test2;Test3'")
		guiFactory.doButton2(attrCreateRow,'Add',
		                     lambda *a: attrToolsLib.doAddAttributesToSelected(self),
		                     "Add the attribute names from the text field")
		MelSpacer(attrCreateRow,w=2)

		attrCreateRow.setStretchWidget(self.AttrNamesTextField)
		attrCreateRow.layout()
		
		
		#>>> modify Section
		self.buildAttrTypeRow(self.containerName)
		MelSeparator(self.containerName,ut = 'cgmUIHeaderTemplate',h=2)
		MelSeparator(self.containerName,ut = 'cgmUITemplate',h=10)
		
		###Modify
		mc.setParent(self.containerName)
		guiFactory.header('Modify')

		
		AttrReportRow = MelHLayout(self.containerName ,ut='cgmUIInstructionsTemplate',h=20)
		self.AttrReportField = MelLabel(AttrReportRow,
		                                bgc = dictionary.returnStateColor('help'),
		                                align = 'center',
		                                label = '...',
		                                h=20)
		AttrReportRow.layout()
			
		MelSeparator(self.containerName,ut = 'cgmUISubTemplate',h=5)
		
		#>>> Load To Field
		LoadAttributeObjectRow = MelHSingleStretchLayout(self.containerName ,ut='cgmUISubTemplate',padding = 5)
	
		MelSpacer(LoadAttributeObjectRow,w=5)
		
		guiFactory.doButton2(LoadAttributeObjectRow,'>>',
	                        lambda *a:attrToolsLib.uiLoadSourceObject(self),
	                         'Load to field')
		
		self.SourceObjectField = MelTextField(LoadAttributeObjectRow, w= 125, h=20, ut = 'cgmUIReservedTemplate', editable = False)
	
		LoadAttributeObjectRow.setStretchWidget(self.SourceObjectField  )
		
		MelLabel(LoadAttributeObjectRow, l=' . ')
		self.ObjectAttributesOptionMenu = MelOptionMenu(LoadAttributeObjectRow, w = 100)
	
		self.DeleteAttrButton = guiFactory.doButton2(LoadAttributeObjectRow,'X',
		                                             lambda *a:attrToolsLib.uiDeleteAttr(self,self.ObjectAttributesOptionMenu),
		                                             'Delete attribute',
		                                             w = 25,
		                                             en = False)
	
		MelSpacer(LoadAttributeObjectRow,w=5)
	
		LoadAttributeObjectRow.layout()
		
	
		#>>> Standard Flags
		BasicAttrFlagsRow = MelHLayout(self.containerName ,ut='cgmUISubTemplate',padding = 2)
		MelSpacer(BasicAttrFlagsRow,w=5)
		self.KeyableAttrCB = MelCheckBox(BasicAttrFlagsRow,label = 'Keyable',en=False)
		MelSpacer(BasicAttrFlagsRow,w=5)
		self.HiddenAttrCB = MelCheckBox(BasicAttrFlagsRow,label = 'Hidden',en=False)
		MelSpacer(BasicAttrFlagsRow,w=5)
		self.LockedAttrCB = MelCheckBox(BasicAttrFlagsRow,label = 'Locked',en=False)
		MelSpacer(BasicAttrFlagsRow,w=5)
		BasicAttrFlagsRow.layout()
		
		
		#>>> Name Row
		self.EditNameSettingsRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate')
		self.EditNameSettingsRow.setStretchWidget(MelSpacer(self.EditNameSettingsRow,w=5))
		
		NameLabel = MelLabel(self.EditNameSettingsRow,label = 'Name: ')
		self.NameField = MelTextField(self.EditNameSettingsRow,en = False,
		                              bgc = dictionary.returnStateColor('normal'),
		                              ec = lambda *a: attrToolsLib.uiRenameAttr(self),
		                              h=20,
		                              w = 75)

		NiceNameLabel = MelLabel(self.EditNameSettingsRow,label = 'Nice: ')		
		self.NiceNameField = MelTextField(self.EditNameSettingsRow,en = False,
		                             bgc = dictionary.returnStateColor('normal'),
		                             ec = lambda *a: attrToolsLib.uiUpdateNiceName(self),		                             
		                             h=20,
		                             w = 75)
		AliasLabel = MelLabel(self.EditNameSettingsRow,label = 'Alias: ')		
		self.AliasField = MelTextField(self.EditNameSettingsRow,en = False,
		                                 bgc = dictionary.returnStateColor('normal'),
		                                 ec = lambda *a: attrToolsLib.uiUpdateAlias(self),		                                 
		                                 h=20,
		                                 w = 75)
		MelSpacer(self.EditNameSettingsRow,w=5)
		self.EditNameSettingsRow.layout()
		"""mc.formLayout(self.EditNameSettingsRow, edit = True,
	                  af = [(NameLabel, "left", 5),
	                        (self.AliasField,"right",5)],
	                  ac = [(self.NameField,"left",2,NameLabel),
	                        (NiceNameLabel,"left",2,self.NameField),
	                        (self.NiceNameField,"left",2,NiceNameLabel),
	                        (AliasLabel,"left",2,self.NiceNameField),
		                    (self.AliasField,"left",2,AliasLabel),
		                    ])"""
		
		#>>> Int Row
		#self.EditDigitSettingsRow = MelFormLayout(self.containerName,ut='cgmUISubTemplate',vis = False)
		self.EditDigitSettingsRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate',vis = False)
		self.EditDigitSettingsRow.setStretchWidget(MelSpacer(self.EditDigitSettingsRow,w=5))
		MinLabel = MelLabel(self.EditDigitSettingsRow,label = 'Min:')
		self.MinField = MelTextField(self.EditDigitSettingsRow,
		                             bgc = dictionary.returnStateColor('normal'),
		                             ec = lambda *a: attrToolsLib.uiUpdateMinValue(self),
		                             h = 20, w = 35)
		
		MaxLabel = MelLabel(self.EditDigitSettingsRow,label = 'Max:')		
		self.MaxField = MelTextField(self.EditDigitSettingsRow,
		                             bgc = dictionary.returnStateColor('normal'),
		                             ec = lambda *a: attrToolsLib.uiUpdateMaxValue(self),	
		                             h = 20, w = 35)
		
		DefaultLabel = MelLabel(self.EditDigitSettingsRow,label = 'dv:')		
		self.DefaultField = MelTextField(self.EditDigitSettingsRow,
		                                 bgc = dictionary.returnStateColor('normal'),
		                                 ec = lambda *a: attrToolsLib.uiUpdateDefaultValue(self),	
		                                 h = 20, w = 35)
		SoftMinLabel = MelLabel(self.EditDigitSettingsRow,label = 'sMin:')				
		self.SoftMinField = MelTextField(self.EditDigitSettingsRow,
		                                 bgc = dictionary.returnStateColor('normal'),
		                                 ec = lambda *a: attrToolsLib.uiUpdateSoftMinValue(self),	
		                                 h = 20, w = 35)
		
		SoftMaxLabel = MelLabel(self.EditDigitSettingsRow,label = 'sMax:')				
		self.SoftMaxField = MelTextField(self.EditDigitSettingsRow,
		                                 bgc = dictionary.returnStateColor('normal'),
		                                 ec = lambda *a: attrToolsLib.uiUpdateSoftMaxValue(self),	
		                                 h = 20, w = 35)
		
		MelSpacer(self.EditDigitSettingsRow,w=5)
		self.EditDigitSettingsRow.layout()
		
		"""mc.formLayout(self.EditDigitSettingsRow, edit = True,
	                  af = [(MinLabel, "left", 20),
	                        (self.SoftMinField,"right",20)],
	                  ac = [(self.MinField,"left",2,MinLabel),
	                        (MaxLabel,"left",2,self.MinField),
	                        (self.MaxField,"left",2,MaxLabel),
	                        (DefaultLabel,"left",2,self.MaxField),
		                    (self.DefaultField,"left",2,DefaultLabel),
		                    (SoftMaxLabel,"left",2,self.DefaultField),
		                    (self.SoftMaxField,"left",2,SoftMaxLabel),
		                    (SoftMinLabel,"left",2,self.SoftMaxField),		                    		                    
		                    (self.SoftMinField,"left",2,SoftMinLabel)		                    
		                    ])"""
		
		#>>> Enum
		self.EditEnumRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate',padding = 5, vis = False)
		MelSpacer(self.EditEnumRow,w=10)
		MelLabel(self.EditEnumRow,label = 'Enum: ')
		self.EnumField = MelTextField(self.EditEnumRow,
				                      annotation = "Options divided by ':'. \n Set values with '=' \n For example: 'off:on=1:maybe=23'",
		                              bgc = dictionary.returnStateColor('normal'),
		                              h = 20, w = 75)
		MelSpacer(self.EditEnumRow,w=10)
		self.EditEnumRow.setStretchWidget(self.EnumField)
		
		self.EditEnumRow.layout()
		
		#>>> String
		self.EditStringRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate',padding = 5, vis = False)
		MelSpacer(self.EditStringRow,w=10)
		MelLabel(self.EditStringRow,label = 'String: ')
		self.StringField = MelTextField(self.EditStringRow,
		                                h=20,
		                                bgc = dictionary.returnStateColor('normal'),
		                                w = 75)
		MelSpacer(self.EditStringRow,w=10)
		self.EditStringRow.setStretchWidget(self.StringField)
		
		self.EditStringRow.layout()
		
		#>>> Message
		self.EditMessageRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate',padding = 5, vis = False)
		MelSpacer(self.EditMessageRow,w=10)
		MelLabel(self.EditMessageRow,label = 'Message: ')
		self.MessageField = MelTextField(self.EditMessageRow,
		                                 h=20,
		                                 enable = False,
		                                 bgc = dictionary.returnStateColor('locked'),
		                                 ec = lambda *a: tdToolsLib.uiUpdateAutoNameTag(self,'cgmPosition'),
		                                 w = 75)
		self.LoadMessageButton = guiFactory.doButton2(self.EditMessageRow,'<<',
		                                              lambda *a:attrToolsLib.uiUpdateMessage(self),
		                                              'Load to message')
		MelSpacer(self.EditMessageRow,w=10)
		self.EditMessageRow.setStretchWidget(self.MessageField)

		self.EditMessageRow.layout()
		
		#>>> Conversion
		self.buildAttrConversionRow(self.containerName)
		self.AttrConvertRow(e=True, vis = False)
		


		#>>> Connect Report
		self.ConnectionReportRow = MelHLayout(self.containerName ,ut='cgmUIInstructionsTemplate',h=20,vis=False)
		self.ConnectionReportField = MelLabel(self.ConnectionReportRow,vis=False,
		                                bgc = dictionary.returnStateColor('help'),
		                                align = 'center',
		                                label = '...',
		                                h=20)	
		self.ConnectionReportRow.layout()	
		
		self.ConnectedPopUpMenu = MelPopupMenu(self.ConnectionReportRow,button = 3)
		
		MelSeparator(self.containerName,ut = 'cgmUIHeaderTemplate',h=2)
		
		mc.setParent(self.containerName )
		guiFactory.lineBreak()
		
		return self.containerName
	
	def buildAttrTypeRow(self,parent):	
		#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		# Attr type row
		#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		self.attrTypes = ['string','float','int','double3','bool','enum','message']
		attrShortTypes = ['str','float','int','[000]','bool','enum','msg']

		self.CreateAttrTypeRadioCollection = MelRadioCollection()
		self.CreateAttrTypeRadioCollectionChoices = []		
			
		#build our sub section options
		AttrTypeRow = MelHLayout(self.containerName,ut='cgmUISubTemplate',padding = 5)
		for cnt,item in enumerate(self.attrTypes):
			self.CreateAttrTypeRadioCollectionChoices.append(self.CreateAttrTypeRadioCollection.createButton(AttrTypeRow,label=attrShortTypes[cnt],
			                                                                                                 onCommand = Callback(self.CreateAttrTypeOptionVar.set,item)))
			MelSpacer(AttrTypeRow,w=2)
		
		if self.CreateAttrTypeOptionVar.value:
			mc.radioCollection(self.CreateAttrTypeRadioCollection ,edit=True,sl= (self.CreateAttrTypeRadioCollectionChoices[ self.attrTypes.index(self.CreateAttrTypeOptionVar.value) ]))
		
		AttrTypeRow.layout()
		
	def buildAttrConversionRow(self,parent):	
		#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		# Attr type row
		#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		self.attrConvertTypes = ['string','float','int','bool','enum','message']
		self.attrConvertShortTypes = ['str','float','int','bool','enum','msg']

		self.ConvertAttrTypeRadioCollection = MelRadioCollection()
		self.ConvertAttrTypeRadioCollectionChoices = []	
		
		self.ConvertAttrTypeOptionVar = OptionVarFactory('cgmVar_ActiveAttrConversionState','int')
		guiFactory.appendOptionVarList(self,self.ConvertAttrTypeOptionVar.name)
		self.ConvertAttrTypeOptionVar.set(0)
			
		#build our sub section options
		self.AttrConvertRow = MelHLayout(self.containerName,ut='cgmUISubTemplate',padding = 5)
		for cnt,item in enumerate(self.attrConvertTypes):
			self.ConvertAttrTypeRadioCollectionChoices.append(self.ConvertAttrTypeRadioCollection.createButton(self.AttrConvertRow,label=self.attrConvertShortTypes[cnt],
			                                                                                                   onCommand = Callback(attrToolsLib.uiConvertLoadedAttr,self,item)))
			MelSpacer(self.AttrConvertRow,w=2)

		self.AttrConvertRow.layout()

		
	def buildAttributeManagerTool(self,parent, vis=True):
		self.ManageForm = MelFormLayout(self.Get(),ut='cgmUITemplate')
		
		ManageHeader = guiFactory.header('Manage Attributes')

		#>>> Manager load frow
		ManagerLoadObjectRow = MelHSingleStretchLayout(self.ManageForm ,padding = 5)
	
		MelSpacer(ManagerLoadObjectRow,w=5)
		
		guiFactory.doButton2(ManagerLoadObjectRow,'>>',
	                        lambda *a:attrToolsLib.uiLoadSourceObject(self),
	                         'Load to field')
		
		self.ManagerSourceObjectField = MelTextField(ManagerLoadObjectRow, w= 125, h=20, ut = 'cgmUIReservedTemplate', editable = False)
	
		ManagerLoadObjectRow.setStretchWidget(self.ManagerSourceObjectField  )
		
	
		MelSpacer(ManagerLoadObjectRow,w=5)
	
		ManagerLoadObjectRow.layout()


		#>>> Attribute List
		self.ManageAttrList = MelObjectScrollList(self.ManageForm, allowMultiSelection=True )
		
		#>>> Reorder Button
		ReorderButtonsRow = MelHLayout(self.ManageForm,padding = 5)
		guiFactory.doButton2(ReorderButtonsRow,
		                     'Move Up',
		                     lambda *a: attrToolsLib.uiReorderAttributes(self,0),
		                     'Create new buffer from selected buffer')	
		guiFactory.doButton2(ReorderButtonsRow,
		                     'Move Down',
		                     lambda *a: attrToolsLib.uiReorderAttributes(self,1),
		                     'Create new buffer from selected buffer')	
		ReorderButtonsRow.layout()





		#>>>Transfer Options
		self.TransferModeCollection = MelRadioCollection()
		self.TransferModeCollectionChoices = []	
		
		TransferModeFlagsRow = MelHSingleStretchLayout(self.ManageForm,padding = 2)	
		MelLabel(TransferModeFlagsRow,l='Modes')
		Spacer = MelSeparator(TransferModeFlagsRow,w=10)						
		self.TransferModeOptions = ['Connect','Copy','Transfer']
		for i,item in enumerate(self.TransferModeOptions):
			self.TransferModeCollectionChoices.append(self.TransferModeCollection.createButton(TransferModeFlagsRow,label=item,
			                                                                             onCommand = Callback(self.CopyAttrModeOptionVar.set,i)))
			MelSpacer(TransferModeFlagsRow,w=3)
		TransferModeFlagsRow.setStretchWidget( Spacer )
		MelSpacer(TransferModeFlagsRow,w=2)		
		TransferModeFlagsRow.layout()	
		
		mc.radioCollection(self.TransferModeCollection ,edit=True,sl= (self.TransferModeCollectionChoices[ (self.CopyAttrModeOptionVar.value) ]))
		
		
		#>>>Transfer Options
		self.TransferOptionsCollection = MelRadioCollection()
		self.TransferOptionsCollectionChoices = []	
		
		TransferOptionsFlagsRow = MelHSingleStretchLayout(self.ManageForm,padding = 0)	
		Spacer = MelSpacer(TransferOptionsFlagsRow)						
		TransferOptionsFlagsRow.setStretchWidget( Spacer )
		
		self.ConvertCB = MelCheckBox(TransferOptionsFlagsRow,label = 'Convert',
				                           annotation = "Converts if necessary to finish the copy process",		                           
				                           value = self.TransferConvertStateOptionVar.value,
				                           onCommand = Callback(self.TransferConvertStateOptionVar.set,1),
				                           offCommand = Callback(self.TransferConvertStateOptionVar.set,0))

		self.ValueCB = MelCheckBox(TransferOptionsFlagsRow,label = 'Value',
		                           annotation = "Copy values",		                           
		                           value = self.TransferValueOptionVar.value,
		                           onCommand = Callback(self.TransferValueOptionVar.set,1),
		                           offCommand = Callback(self.TransferValueOptionVar.set,0))
		
		self.IncomingCB = MelCheckBox(TransferOptionsFlagsRow,label = 'In',
				                      annotation = "Copy or transfer incoming connections",		                              
		                              value = self.TransferIncomingOptionVar.value,
		                              onCommand = Callback(self.TransferIncomingOptionVar.set,1),
		                              offCommand = Callback(self.TransferIncomingOptionVar.set,0))

		self.OutgoingCB = MelCheckBox(TransferOptionsFlagsRow,label = 'Out',
		                              annotation = "Copy or transfer incoming connections",		                              
		                              value = self.TransferOutgoingOptionVar.value,
		                              onCommand = Callback(self.TransferOutgoingOptionVar.set,1),
		                              offCommand = Callback(self.TransferOutgoingOptionVar.set,0))	

		self.KeepSourceCB = MelCheckBox(TransferOptionsFlagsRow,label = 'Keep',
		                                annotation = "Keep source connections when copying",		                                
		                                value = self.TransferKeepSourceOptionVar.value,
		                                onCommand = Callback(self.TransferKeepSourceOptionVar.set,1),
		                                offCommand = Callback(self.TransferKeepSourceOptionVar.set,0))
		
		self.DriveSourceCB = MelCheckBox(TransferOptionsFlagsRow,label = 'Drive',
		                                annotation = "Connect the source attr \nto selected or created attribute",		                                
		                                value = self.TransferDriveSourceStateOptionVar.value,
		                                onCommand = Callback(self.TransferDriveSourceStateOptionVar.set,1),
		                                offCommand = Callback(self.TransferDriveSourceStateOptionVar.set,0))
		
		self.AttrOptionsCB = MelCheckBox(TransferOptionsFlagsRow,label = 'Options',
		                                annotation = "Copies the attributes basic flags\n(locked,keyable,hidden)",		                                
		                                value = self.CopyAttrOptionsOptionVar.value,
		                                onCommand = Callback(self.CopyAttrOptionsOptionVar.set,1),
		                                offCommand = Callback(self.TransferDriveSourceStateOptionVar.set,0))
		
		TransferOptionsFlagsRow.layout()	


		BottomButtonRow = guiFactory.doButton2(self.ManageForm,
		                                       'Connect/Copy/Transfer',
		                                       lambda *a: attrToolsLib.uiTransferAttributes(self),
		                                       'Create new buffer from selected buffer')	

		self.ManageForm(edit = True,
		         af = [(ManageHeader,"top",0),
		               (ManageHeader,"left",0),
		               (ManageHeader,"right",0),
		               (self.ManageAttrList,"left",0),
		               (self.ManageAttrList,"right",0),
		               (ManagerLoadObjectRow,"left",5),
		               (ManagerLoadObjectRow,"right",5),
		               (ReorderButtonsRow,"left",0),
		               (ReorderButtonsRow,"right",0),	
		               (TransferModeFlagsRow,"left",5),
		               (TransferModeFlagsRow,"right",5),
		               (BottomButtonRow,"left",5),
		               (BottomButtonRow,"right",5),		               
		               (TransferOptionsFlagsRow,"left",2),
		               (TransferOptionsFlagsRow,"right",2),
		               (TransferOptionsFlagsRow,"bottom",4)],
		         ac = [(ManagerLoadObjectRow,"top",5,ManageHeader),
		               (self.ManageAttrList,"top",5,ManagerLoadObjectRow),
		               (self.ManageAttrList,"bottom",5,ReorderButtonsRow),
		               (ReorderButtonsRow,"bottom",5,BottomButtonRow),		               
		               (BottomButtonRow,"bottom",5,TransferModeFlagsRow),
		               (TransferModeFlagsRow,"bottom",5,TransferOptionsFlagsRow)],
		         attachNone = [(TransferOptionsFlagsRow,"top")])	
		



		#Build pop up for attribute list field
		popUpMenu = MelPopupMenu(self.ManageAttrList,button = 3)
				
			
		MelMenuItem(popUpMenu ,
	                label = 'Make Keyable',
	                c = lambda *a: attrToolsLib.uiManageAttrsKeyable(self))
		
		MelMenuItem(popUpMenu ,
	                label = 'Make Unkeyable',
		            c = lambda *a: attrToolsLib.uiManageAttrsUnkeyable(self))
		
		MelMenuItemDiv(popUpMenu)
		
		MelMenuItem(popUpMenu ,
	                label = 'Hide',
		            c = lambda *a: attrToolsLib.uiManageAttrsHide(self))
		
		MelMenuItem(popUpMenu ,
	                label = 'Unhide',
		            c = lambda *a: attrToolsLib.uiManageAttrsUnhide(self))
		
		MelMenuItemDiv(popUpMenu)
		MelMenuItem(popUpMenu ,
	                label = 'Lock',
		            c = lambda *a: attrToolsLib.uiManageAttrsLocked(self))
		
		MelMenuItem(popUpMenu ,
	                label = 'Unlock',
		            c = lambda *a: attrToolsLib.uiManageAttrsUnlocked(self))
		
		MelMenuItemDiv(popUpMenu)
		MelMenuItem(popUpMenu ,
	                label = 'Delete',
		            c = lambda *a: attrToolsLib.uiManageAttrsDelete(self))


		return self.ManageForm
	

	
	def buildAttributeUtilitiesTool(self,parent, vis=True):
		containerName = 'Utilities Container'
		self.containerName = MelColumn(parent,vis=vis)

		#>>> Tag Labels
		mc.setParent(self.containerName)
		guiFactory.header('Short cuts')
		guiFactory.lineSubBreak()
		
		AttributeUtilityRow1 = MelHLayout(self.containerName,ut='cgmUISubTemplate',padding = 2)
	
		guiFactory.doButton2(AttributeUtilityRow1,'cgmName to Float',
			                 lambda *a:tdToolsLib.doCGMNameToFloat(),
			                 'Makes an animatalbe float attribute using the cgmName tag')
	
		mc.setParent(self.containerName)
		guiFactory.lineSubBreak()
	
		AttributeUtilityRow1.layout()
	
		#>>> SDK tools
		mc.setParent(self.containerName)
		guiFactory.lineBreak()
		guiFactory.header('SDK Tools')
		guiFactory.lineSubBreak()
	
	
		sdkRow = MelHLayout(self.containerName ,ut='cgmUISubTemplate',padding = 2)
		guiFactory.doButton2(sdkRow,'Select Driven Joints',
			                 lambda *a:tdToolsLib.doSelectDrivenJoints(self),
			                 "Selects driven joints from an sdk attribute")
	
	
		sdkRow.layout()
		mc.setParent(self.containerName)
		guiFactory.lineSubBreak()
		

		return self.containerName
示例#6
0
class puppetBoxClass(BaseMelWindow):
    from  cgm.lib import guiFactory
    guiFactory.initializeTemplates()
    USE_Template = 'cgmUITemplate'

    WINDOW_NAME = 'cgmPuppetBoxWindow'
    WINDOW_TITLE = 'cgm.puppetBox - %s'%__version__
    DEFAULT_SIZE = 250, 400
    DEFAULT_MENU = None
    RETAIN = True
    MIN_BUTTON = True
    MAX_BUTTON = False
    FORCE_DEFAULT_SIZE = False  #always resets the size of the window when its re-created
    global cgmPuppet

    def __init__( self):		
        self.toolName = 'cgm.puppetBox'
        self.description = 'This is a series of tools for working with cgm Sets'
        self.author = 'Josh Burton'
        self.owner = 'CG Monks'
        self.website = 'www.cgmonks.com'
        self.dockCnt = 'cgmPuppetBoxDoc'			
        self.version =  __version__ 
        self.optionVars = []
        self.scenePuppets = []
        self.Puppet = False
        self.PuppetBridge = {}
        self.puppetStateOptions = ['define']
        self.puppetStateOptions.extend(ModuleFactory.moduleStates)
        #self.addModules = ['Spine','Leg','Arm','Limb','Finger','Foot','Neck','Head','Spine']
        self.addModules = ['Segment']
        self.moduleFrames = {}
        self.moduleBaseNameFields = {}
        self.moduleHandleFields = {}
        self.moduleRollFields = {}
        self.moduleCurveFields = {}
        self.moduleStiffIndexFields = {}

        self.moduleDirectionMenus = {}
        self.modulePositionMenus = {}

        self.moduleDirections = ['none','left','right']
        self.modulePositions = ['none','front','rear','forward','back','top','bottom']



        self.setModes = ['<<< All Loaded Sets >>>','<<< Active Sets >>>']
        self.scenePuppets = modules.returnPuppetObjects()
        self.UI_StateRows = {'define':[],'template':[],'skeleton':[],'rig':[]}

        self.showHelp = False
        self.helpBlurbs = []
        self.oldGenBlurbs = []

        #Menu
        self.setupVariables()

        self.UI_PuppetMenu = MelMenu( l='Puppet', pmc=self.buildPuppetMenu)
        self.UI_AddModulesMenu = MelMenu( l='Add', pmc=self.buildAddModulesMenu)
        self.UI_OptionsMenu = MelMenu( l='Options', pmc=self.buildOptionsMenu)		
        self.UI_HelpMenu = MelMenu( l='Help', pmc=self.buildHelpMenu)

        self.ShowHelpOption = mc.optionVar( q='cgmVar_AnimToolsShowHelp' )

        #GUI

        self.Main_buildLayout(self)

        if self.Puppet:
            puppetBoxLib.updateUIPuppet(self)


        if self.scenePuppets:
            puppetBoxLib.activatePuppet(self,self.scenePuppets[0])

        #====================
        # Show and Dock
        #====================
        #Maya2011 QT docking - from Red9's examples
        try:
            #'Maya2011 dock delete'
            if mc.dockControl(self.dockCnt, exists=True):
                mc.deleteUI(self.dockCnt, control=True)  
        except:
            pass

        if self.dockOptionVar.value:
            try:
                allowedAreas = ['right', 'left']
                mc.dockControl(self.dockCnt, area='right', label=self.WINDOW_TITLE, content=self.WINDOW_NAME, floating=False, allowedArea=allowedAreas, width=400)
            except:
                #Dock failed, opening standard Window	
                self.show()
        else:self.show()


    def setupVariables(self):
        self.PuppetModeOptionVar = OptionVarFactory('cgmVar_PuppetCreateMode',defaultValue = 0)
        guiFactory.appendOptionVarList(self,self.PuppetModeOptionVar.name)

        self.PuppetAimOptionVar = OptionVarFactory('cgmVar_PuppetAimAxis',defaultValue = 2)
        guiFactory.appendOptionVarList(self,self.PuppetAimOptionVar.name)		
        self.PuppetUpOptionVar = OptionVarFactory('cgmVar_PuppetUpAxis',defaultValue = 1)
        guiFactory.appendOptionVarList(self,self.PuppetUpOptionVar.name)	
        self.PuppetOutOptionVar = OptionVarFactory('cgmVar_PuppetOutAxis',defaultValue = 0)
        guiFactory.appendOptionVarList(self,self.PuppetOutOptionVar.name)			

        self.ActiveObjectSetsOptionVar = OptionVarFactory('cgmVar_activeObjectSets',defaultValue = [''])
        self.ActiveRefsOptionVar = OptionVarFactory('cgmVar_activeRefs',defaultValue = [''])
        self.ActiveTypesOptionVar = OptionVarFactory('cgmVar_activeTypes',defaultValue = [''])
        self.SetToolsModeOptionVar = OptionVarFactory('cgmVar_puppetBoxMode', defaultValue = 0)
        self.KeyTypeOptionVar = OptionVarFactory('cgmVar_KeyType', defaultValue = 0)
        self.ShowHelpOptionVar = OptionVarFactory('cgmVar_puppetBoxShowHelp', defaultValue = 0)
        self.MaintainLocalSetGroupOptionVar = OptionVarFactory('cgmVar_MaintainLocalSetGroup', defaultValue = 1)
        self.HideSetGroupOptionVar = OptionVarFactory('cgmVar_HideSetGroups', defaultValue = 1)
        self.HideAnimLayerSetsOptionVar = OptionVarFactory('cgmVar_HideAnimLayerSets', defaultValue = 1)
        self.HideMayaSetsOptionVar = OptionVarFactory('cgmVar_HideMayaSets', defaultValue = 1)
        
        self.dockOptionVar = OptionVarFactory('cgmVar_PuppetBoxDock', defaultValue = 1)
        
        guiFactory.appendOptionVarList(self,self.ActiveObjectSetsOptionVar.name)
        guiFactory.appendOptionVarList(self,self.ActiveRefsOptionVar.name)
        guiFactory.appendOptionVarList(self,self.ActiveTypesOptionVar.name)
        guiFactory.appendOptionVarList(self,self.SetToolsModeOptionVar.name)
        guiFactory.appendOptionVarList(self,self.ShowHelpOptionVar.name)
        guiFactory.appendOptionVarList(self,self.KeyTypeOptionVar.name)
        guiFactory.appendOptionVarList(self,self.HideSetGroupOptionVar.name)
        guiFactory.appendOptionVarList(self,self.MaintainLocalSetGroupOptionVar.name)
        guiFactory.appendOptionVarList(self,self.HideAnimLayerSetsOptionVar.name)
        guiFactory.appendOptionVarList(self,self.HideMayaSetsOptionVar.name)
        guiFactory.appendOptionVarList(self,self.dockOptionVar.name)        

        self.DebugModeOptionVar = OptionVarFactory('cgmVar_PuppetBoxDebug',defaultValue=0)
        guiFactory.appendOptionVarList(self,self.DebugModeOptionVar.name)		

    def updateModulesUI(self):
        def optionMenuSet(item):
            print item
            #puppetBoxLib.uiModuleSetCGMTag(self,tag,item,index)
            """
			i =  self.setModes.index(item)
			self.SetToolsModeOptionVar.set( i )
			self.setMode = i"""

        #deleteExisting
        self.ModuleListColumn.clear()

        if self.Puppet:			
            for i,b in enumerate(self.Puppet.ModulesBuffer.bufferList):
                # NEED to get colors
                #Build label for Frame
                self.moduleFrames[i] = MelFrameLayout(self.ModuleListColumn,l='',
                                                      collapse=True,
                                                      collapsable=True,
                                                      marginHeight=0,
                                                      marginWidth=0,
                                                      bgc = dictionary.guiDirectionColors['center'])
                puppetBoxLib.uiModuleUpdateFrameLabel(self,i)


                #Build Naming Row
                tmpNameRow = MelFormLayout(self.moduleFrames[i], h=25,
                                           )
                tmpNameLabel = MelLabel(tmpNameRow,l='base:',align='right')

                self.moduleBaseNameFields[i] = MelTextField(tmpNameRow,text=self.Puppet.Module[i].nameBase or '',
                                                            ec = Callback(puppetBoxLib.uiUpdateBaseName,self,i),
                                                            w=50,
                                                            h=20)

                tmpDirLabel = MelLabel(tmpNameRow,l='dir:',align='right')								
                self.moduleDirectionMenus[i] = MelOptionMenu(tmpNameRow, cc = Callback(puppetBoxLib.uiModuleOptionMenuSet,self,self.moduleDirectionMenus,self.moduleDirections,'cgmDirection',i))

                for cnt,o in enumerate(self.moduleDirections):
                    self.moduleDirectionMenus[i].append(o)
                    if o == self.Puppet.Module[i].ModuleNull.cgm['cgmDirection']:
                        self.moduleDirectionMenus[i](edit = True, select = cnt + 1)

                tmpPosLabel = MelLabel(tmpNameRow,l='pos:',align='right')
                self.modulePositionMenus[i] = MelOptionMenu(tmpNameRow,
                                                            cc = Callback(puppetBoxLib.uiModuleOptionMenuSet,self,self.modulePositionMenus,self.modulePositions,'cgmPosition',i))
                for cnt,o in enumerate(self.modulePositions):
                    self.modulePositionMenus[i].append(o)
                    if o == self.Puppet.Module[i].ModuleNull.cgm['cgmPosition']:
                        self.modulePositionMenus[i](edit = True, select = cnt + 1)					

                mc.formLayout(tmpNameRow, edit = True,
                              af = [(tmpNameLabel, "left", 10),
                                    (self.modulePositionMenus[i],"right",10)],
                              ac = [(self.moduleBaseNameFields[i],"left",5,tmpNameLabel),
                                    (self.moduleBaseNameFields[i],"right",5,tmpDirLabel),
                                    (tmpDirLabel,"right",5,self.moduleDirectionMenus[i]),
                                    (self.moduleDirectionMenus[i],"right",5,tmpPosLabel),
                                    (tmpPosLabel,"right",5,self.modulePositionMenus[i] ),
                                    ])
                #>>>>>>>>>>>>>>>>>>>>>

                if self.Puppet.Module[i].moduleClass == 'Limb':

                    #Build Int Settings Row
                    tmpIntRow = MelHSingleStretchLayout(self.moduleFrames[i], h=25,
                                                        )
                    tmpIntRow.setStretchWidget(MelSpacer(tmpIntRow,w=5))

                    MelLabel(tmpIntRow,l='Handles:')
                    self.moduleHandleFields[i] = MelIntField(tmpIntRow,
                                                             v = self.Puppet.Module[i].optionHandles.value,
                                                             bgc = dictionary.returnStateColor('normal'),
                                                             ec = Callback(puppetBoxLib.uiModuleUpdateIntAttrFromField,self,self.moduleHandleFields,'optionHandles',i),
                                                             h = 20, w = 35)
                    MelLabel(tmpIntRow,l='Roll:')
                    self.moduleRollFields[i] = MelIntField(tmpIntRow,
                                                           v = self.Puppet.Module[i].optionRollJoints.value,					                                       
                                                           bgc = dictionary.returnStateColor('normal'),
                                                           ec = Callback(puppetBoxLib.uiModuleUpdateIntAttrFromField,self,self.moduleRollFields,'optionRollJoints',i),
                                                           h = 20, w = 35)
                    MelLabel(tmpIntRow,l='Stiff Index:')
                    self.moduleStiffIndexFields[i] = MelIntField(tmpIntRow,
                                                                 v = self.Puppet.Module[i].optionStiffIndex.value,					                                             
                                                                 bgc = dictionary.returnStateColor('normal'),
                                                                 ec = Callback(puppetBoxLib.uiModuleUpdateIntAttrFromField,self,self.moduleStiffIndexFields,'optionStiffIndex',i),
                                                                 h = 20, w = 35)	
                    MelLabel(tmpIntRow,l='Curve:')
                    self.moduleCurveFields[i] = MelIntField(tmpIntRow,
                                                            v = self.Puppet.Module[i].optionCurveDegree.value,					                                        
                                                            bgc = dictionary.returnStateColor('normal'),
                                                            ec = Callback(puppetBoxLib.uiModuleUpdateIntAttrFromField,self,self.moduleCurveFields,'optionCurveDegree',i),
                                                            h = 20, w = 35)


                    MelSpacer(tmpIntRow,w=10)

                    tmpIntRow.layout()



                #PopUp Menu!
                popUpMenu = MelPopupMenu(self.moduleFrames[i],button = 3)

                MelMenuItem(popUpMenu,
                            label = "cls: %s"%self.Puppet.Module[i].moduleClass,
                            enable = False)
                #Parent/MIrror				
                MelMenuItem(popUpMenu,
                            label = "Set Parent>",
                            enable = False)
                MelMenuItem(popUpMenu,
                            label = "Set Mirror>",
                            enable = False)	

                if self.Puppet.Module[i].moduleClass == 'Limb':
                    MelMenuItem(popUpMenu,
                                label = 'FK',
                                cb = self.Puppet.Module[i].optionFK.value,
                                c = Callback(puppetBoxLib.uiModuleToggleBool,self,'optionFK',i))
                    MelMenuItem(popUpMenu,
                                label = 'IK',
                                cb = self.Puppet.Module[i].optionIK.value,
                                c = Callback(puppetBoxLib.uiModuleToggleBool,self,'optionIK',i))
                    MelMenuItem(popUpMenu,
                                label = 'Stretchy',
                                cb = self.Puppet.Module[i].optionStretchy.value,
                                c = Callback(puppetBoxLib.uiModuleToggleBool,self,'optionStretchy',i))
                    MelMenuItem(popUpMenu,
                                label = 'Bendy',
                                cb = self.Puppet.Module[i].optionBendy.value,
                                c = Callback(puppetBoxLib.uiModuleToggleBool,self,'optionBendy',i))

                MelMenuItemDiv(popUpMenu)

                # Object Aim Menu
                ObjectAimMenu = MelMenuItem(popUpMenu, l='Aim:', subMenu=True)
                self.ObjectAimCollection = MelRadioMenuCollection()

                for index,axis in enumerate(dictionary.axisDirectionsByString):
                    if self.Puppet.Module[i].optionAimAxis.get() == index:
                        checkState = True
                    else:
                        checkState = False
                    self.ObjectAimCollection.createButton(ObjectAimMenu,l=axis,
                                                          c= Callback(puppetBoxLib.doSetAxisAndUpdateModule,self,functions.doSetAimAxis,self.Puppet.Module[i],index),
                                                          rb = checkState)
                ObjectUpMenu = MelMenuItem(popUpMenu, l='Up:', subMenu=True)
                self.ObjectUpCollection = MelRadioMenuCollection()

                for index,axis in enumerate(dictionary.axisDirectionsByString):
                    if self.Puppet.Module[i].optionUpAxis.get() == index:
                        checkState = True
                    else:
                        checkState = False
                    self.ObjectUpCollection.createButton(ObjectUpMenu,l=axis,
                                                         c= Callback(puppetBoxLib.doSetAxisAndUpdateModule,self,functions.doSetUpAxis,self.Puppet.Module[i],index),
                                                         rb = checkState)
                ObjectOutMenu = MelMenuItem(popUpMenu, l='Out:', subMenu=True)
                self.ObjectOutCollection = MelRadioMenuCollection()

                for index,axis in enumerate(dictionary.axisDirectionsByString):
                    if self.Puppet.Module[i].optionOutAxis.get() == index:
                        checkState = True
                    else:
                        checkState = False
                    self.ObjectOutCollection.createButton(ObjectOutMenu,l=axis,
                                                          c= Callback(puppetBoxLib.doSetAxisAndUpdateModule,self,functions.doSetOutAxis,self.Puppet.Module[i],index),
                                                          rb = checkState)


                ObjectOutMenu = MelMenuItem(popUpMenu, l='Copy from Parent', 
                                            c= Callback(puppetBoxLib.doCopyAxisFromParent,self,self.Puppet.Module[i]))

                MelMenuItemDiv(popUpMenu)



                MelMenuItem(popUpMenu ,
                            label = 'Remove',
                            c = Callback(puppetBoxLib.doRemoveModule,self,i))

                MelMenuItem(popUpMenu ,
                            label = 'Delete',
                            c = Callback(puppetBoxLib.doDeleteModule,self,i))


    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Menus
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    def buildPuppetMenu( self, *a ):
        self.UI_PuppetMenu.clear()

        #>>> Puppet Options	
        MelMenuItem( self.UI_PuppetMenu, l="New",
                     c=lambda *a:puppetBoxLib.doPuppetCreate(self))

        #Build load menu
        self.scenePuppets = modules.returnPuppetObjects()		
        loadMenu = MelMenuItem( self.UI_PuppetMenu, l='Pick Puppet:', subMenu=True)

        if self.scenePuppets:
            for i,m in enumerate(self.scenePuppets):
                MelMenuItem( loadMenu, l="%s"%m,
                             c= Callback(puppetBoxLib.activatePuppet,self,m))		
        else:
            MelMenuItem( loadMenu, l="None found")

        if self.Puppet:
            MelMenuItemDiv( self.UI_PuppetMenu )	
            MelMenuItem( self.UI_PuppetMenu, l="Initialize",
                         c=lambda *a:puppetBoxLib.initializePuppet(self))
            if not self.Puppet.refState:
                MelMenuItem( self.UI_PuppetMenu, l="Verify",
                             c=lambda *a:puppetBoxLib.verifyPuppet(self))	
                MelMenuItem( self.UI_PuppetMenu, l="Delete",
                             c=lambda *a:puppetBoxLib.deletePuppet(self))	
        #>>> Reset Options		
        MelMenuItemDiv( self.UI_PuppetMenu )
        MelMenuItem( self.UI_PuppetMenu, l="Reload",
                     c=lambda *a: self.reload())		
        MelMenuItem( self.UI_PuppetMenu, l="Reset",
                     c=lambda *a: self.reset())

    def buildAddModulesMenu( self, *a ):
        self.UI_AddModulesMenu.clear()
        for i,m in enumerate(self.addModules):
            MelMenuItem( self.UI_AddModulesMenu, l="%s"%m,
                         c=lambda *a:puppetBoxLib.addModule(self,m))

        MelMenuItemDiv( self.UI_AddModulesMenu )

    def buildOptionsMenu( self, *a ):
        self.UI_OptionsMenu.clear()
        MelMenuItem( self.UI_OptionsMenu, l="Force module menu reload",
                     c=lambda *a:puppetBoxLib.uiForceModuleUpdateUI(self))		


    def reset(self):	
        Callback(guiFactory.resetGuiInstanceOptionVars(self.optionVars,run))

    def reload(self):	
        run()


    def buildHelpMenu( self, *a ):
        self.UI_HelpMenu.clear()
        MelMenuItem( self.UI_HelpMenu, l="Show Help",
                     cb=self.ShowHelpOptionVar.value,
                     c= lambda *a: self.do_showHelpToggle())

        MelMenuItem( self.UI_HelpMenu, l="Print Set Report",
                     c=lambda *a: self.printReport() )
        MelMenuItem( self.UI_HelpMenu, l="Print Tools Help",
                     c=lambda *a: self.printHelp() )

        MelMenuItemDiv( self.UI_HelpMenu )
        MelMenuItem( self.UI_HelpMenu, l="About",
                     c=lambda *a: self.showAbout() )
        MelMenuItem( self.UI_HelpMenu, l="Debug",
                     cb=self.DebugModeOptionVar.value,
                     c= lambda *a: self.DebugModeOptionVar.toggle())			

    def do_showHelpToggle( self):
        guiFactory.toggleMenuShowState(self.ShowHelpOptionVar.value,self.helpBlurbs)
        self.ShowHelpOptionVar.toggle()


    def showAbout(self):
        window = mc.window( title="About", iconName='About', ut = 'cgmUITemplate',resizeToFitChildren=True )
        mc.columnLayout( adjustableColumn=True )
        guiFactory.header(self.toolName,overrideUpper = True)
        mc.text(label='>>>A Part of the cgmTools Collection<<<', ut = 'cgmUIInstructionsTemplate')
        guiFactory.headerBreak()
        guiFactory.lineBreak()
        descriptionBlock = guiFactory.textBlock(self.description)

        guiFactory.lineBreak()
        mc.text(label=('%s%s' %('Written by: ',self.author)))
        mc.text(label=('%s%s%s' %('Copyright ',self.owner,', 2011')))
        guiFactory.lineBreak()
        mc.text(label='Version: %s' % self.version)
        mc.text(label='')
        guiFactory.doButton('Visit Tool Webpage', 'import webbrowser;webbrowser.open(" http://www.cgmonks.com/tools/maya-tools/puppetBox/")')
        guiFactory.doButton('Close', 'import maya.cmds as mc;mc.deleteUI(\"' + window + '\", window=True)')
        mc.setParent( '..' )
        mc.showWindow( window )

    def printHelp(self):
        help(puppetBoxLib)

    def printReport(self):
        puppetBoxLib.printReport(self)


    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Layouts
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    def Main_buildLayout(self,parent):
        def modeSet( item ):
            i =  self.setModes.index(item)
            self.SetToolsModeOptionVar.set( i )
            self.setMode = i

        MainForm = MelFormLayout(parent)
        TopSection = MelColumnLayout(MainForm)	
        SetHeader = guiFactory.header('Puppet')

        #>>>  Top Section
        #Report
        self.puppetReport = MelLabel(TopSection,
                                     bgc = dictionary.returnStateColor('help'),
                                     align = 'center',
                                     label = '...',
                                     h=20)
        MelSeparator(TopSection,ut='cgmUITemplate',h=5)

        #Edit name and state mode buttons
        MasterPuppetRow = MelHSingleStretchLayout(TopSection,padding = 5)
        MelSpacer(MasterPuppetRow,w=5)
        self.MasterPuppetTF = MelTextField(MasterPuppetRow,
                                           bgc = [1,1,1],
                                           ec = lambda *a:puppetBoxLib.updatePuppetName(self))
        MasterPuppetRow.setStretchWidget(self.MasterPuppetTF)

        self.puppetStateButtonsDict = {}
        for i,s in enumerate(self.puppetStateOptions):
            self.puppetStateButtonsDict[i] = guiFactory.doButton2(MasterPuppetRow,s.capitalize(),
                                                                  "print '%s'"%s,
                                                                  enable = False)
        MelSpacer(MasterPuppetRow,w=20)

        MasterPuppetRow.layout()
        #MelSeparator(TopSection,ut='cgmUITemplate',h=2)

        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        # Define State Rows
        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>		
        #Initial State Mode Row
        self.PuppetModeCollection = MelRadioCollection()
        self.PuppetModeCollectionChoices = []			

        self.InitialStateModeRow = MelHSingleStretchLayout(TopSection,padding = 2,vis=False)	
        MelSpacer(self.InitialStateModeRow,w=5)				
        MelLabel(self.InitialStateModeRow,l='Template Modes')
        Spacer = MelSeparator(self.InitialStateModeRow,w=10)						
        for i,item in enumerate(CharacterTypes):
            self.PuppetModeCollectionChoices.append(self.PuppetModeCollection.createButton(self.InitialStateModeRow,label=item,
                                                                                           onCommand = Callback(puppetBoxLib.setPuppetBaseMode,self,i)))
            MelSpacer(self.InitialStateModeRow,w=3)
        self.InitialStateModeRow.setStretchWidget( Spacer )
        MelSpacer(self.InitialStateModeRow,w=2)		
        self.InitialStateModeRow.layout()	

        mc.radioCollection(self.PuppetModeCollection ,edit=True,sl= (self.PuppetModeCollectionChoices[ (self.PuppetModeOptionVar.value) ]))
        self.UI_StateRows['define'].append(self.InitialStateModeRow)


        self.AxisFrame = MelFrameLayout(TopSection,label = 'Axis',vis=False,
                                        collapse=True,
                                        collapsable=True,
                                        ut = 'cgmUIHeaderTemplate')
        self.UI_StateRows['define'].append(self.AxisFrame)
        MelSeparator(TopSection,style='none',h=5)						

        #Aim Axis Mode Row
        self.AimAxisCollection = MelRadioCollection()
        self.AimAxisCollectionChoices = []			

        self.AimAxisRow = MelHSingleStretchLayout(self.AxisFrame,padding = 2,vis=False)	
        MelSpacer(self.AimAxisRow,w=5)				
        MelLabel(self.AimAxisRow,l='Aim ')
        Spacer = MelSeparator(self.AimAxisRow,w=10)						
        for i,item in enumerate(axisDirectionsByString):
            self.AimAxisCollectionChoices.append(self.AimAxisCollection.createButton(self.AimAxisRow,label=item,
                                                                                     onCommand = Callback(puppetBoxLib.setPuppetAxisAim,self,i)))
            MelSpacer(self.AimAxisRow,w=3)
        self.AimAxisRow.setStretchWidget( Spacer )
        MelSpacer(self.AimAxisRow,w=2)		
        self.AimAxisRow.layout()	


        #Up Axis Mode Row
        self.UpAxisCollection = MelRadioCollection()
        self.UpAxisCollectionChoices = []			

        self.UpAxisRow = MelHSingleStretchLayout(self.AxisFrame,padding = 2,vis=False)	
        MelSpacer(self.UpAxisRow,w=5)				
        MelLabel(self.UpAxisRow,l='Up ')
        Spacer = MelSeparator(self.UpAxisRow,w=10)						
        for i,item in enumerate(axisDirectionsByString):
            self.UpAxisCollectionChoices.append(self.UpAxisCollection.createButton(self.UpAxisRow,label=item,
                                                                                   onCommand = Callback(puppetBoxLib.setPuppetAxisUp,self,i)))
            MelSpacer(self.UpAxisRow,w=3)
        self.UpAxisRow.setStretchWidget( Spacer )
        MelSpacer(self.UpAxisRow,w=2)		
        self.UpAxisRow.layout()	


        #Out Axis Mode Row
        self.OutAxisCollection = MelRadioCollection()
        self.OutAxisCollectionChoices = []			

        self.OutAxisRow = MelHSingleStretchLayout(self.AxisFrame,padding = 2,vis=False)	
        MelSpacer(self.OutAxisRow,w=5)				
        MelLabel(self.OutAxisRow,l='Out ')
        Spacer = MelSeparator(self.OutAxisRow,w=10)	
        for i,item in enumerate(axisDirectionsByString):
            self.OutAxisCollectionChoices.append(self.OutAxisCollection.createButton(self.OutAxisRow,label=item,
                                                                                     onCommand = Callback(puppetBoxLib.setPuppetAxisOut,self,i)))
            MelSpacer(self.OutAxisRow,w=3)
        self.OutAxisRow.setStretchWidget( Spacer )
        MelSpacer(self.OutAxisRow,w=2)		
        self.OutAxisRow.layout()	

        #Set toggles on menu
        mc.radioCollection(self.AimAxisCollection ,edit=True,sl= (self.AimAxisCollectionChoices[ (self.PuppetAimOptionVar.value) ]))		
        mc.radioCollection(self.UpAxisCollection ,edit=True,sl= (self.UpAxisCollectionChoices[ (self.PuppetUpOptionVar.value) ]))		
        mc.radioCollection(self.OutAxisCollection ,edit=True,sl= (self.OutAxisCollectionChoices[ (self.PuppetOutOptionVar.value) ]))


        #Initial State Button Row
        self.InitialStateButtonRow = MelHLayout(TopSection, h = 20,vis=False,padding = 5)
        guiFactory.doButton2(self.InitialStateButtonRow,'Add Geo',
                             lambda *a:puppetBoxLib.doAddGeo(self))
        guiFactory.doButton2(self.InitialStateButtonRow,'Build Size Template',
                             lambda *a:puppetBoxLib.doBuildSizeTemplate(self))

        self.InitialStateButtonRow.layout()
        self.UI_StateRows['define'].append(self.InitialStateButtonRow)

        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        # Multi Module
        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

        #>>>  All Sets menu
        AllModulesRow = MelFormLayout(MainForm,height = 20)
        activeState = True
        i = 1

        tmpActive = MelCheckBox(AllModulesRow,
                                annotation = 'Sets all sets active',
                                value = activeState,
                                onCommand =  Callback(puppetBoxLib.doSetAllSetsAsActive,self),
                                offCommand = Callback(puppetBoxLib.doSetAllSetsAsInactive,self))

        tmpSel = guiFactory.doButton2(AllModulesRow,
                                      ' s ',
                                      'Select All Loaded/Active Sets')

        # Mode toggle box
        self.ModuleModeOptionMenu = MelOptionMenu(AllModulesRow,
                                                  cc = modeSet)


        tmpKey = guiFactory.doButton2(AllModulesRow,
                                      ' k ',
                                      'Key All Sets')
        tmpDeleteKey = guiFactory.doButton2(AllModulesRow,
                                            ' d ',
                                            'Delete All Set Keys')	
        tmpReset = guiFactory.doButton2(AllModulesRow,
                                        ' r ',
                                        'Reset All Set Keys')	

        mc.formLayout(AllModulesRow, edit = True,
                      af = [(tmpActive, "left", 10),
                            (tmpReset,"right",10)],
                      ac = [(tmpSel,"left",0,tmpActive),
                            (self.ModuleModeOptionMenu,"left",4,tmpSel),
                            (self.ModuleModeOptionMenu,"right",4,tmpKey),
                            (tmpKey,"right",2,tmpDeleteKey),
                            (tmpDeleteKey,"right",2,tmpReset)
                            ])

        #>>> Sets building section
        allPopUpMenu = MelPopupMenu(self.ModuleModeOptionMenu ,button = 3)

        allCategoryMenu = MelMenuItem(allPopUpMenu,
                                      label = 'Make Type:',
                                      sm = True)




        #>>> Sets building section
        ModuleListScroll = MelScrollLayout(MainForm,cr = 1, ut = 'cgmUISubTemplate')
        ModuleMasterForm = MelFormLayout(ModuleListScroll)
        self.ModuleListColumn = MelColumnLayout(ModuleMasterForm,ut = 'cgmUIInstructionsTemplate', adj = True, rowSpacing = 2)



        self.helpInfo = MelLabel(MainForm,
                                 h=20,
                                 l = "Add a Puppet",
                                 ut = 'cgmUIInstructionsTemplate',
                                 al = 'center',
                                 ww = True,vis = self.ShowHelpOptionVar.value)
        self.helpBlurbs.extend([self.helpInfo ])

        VerifyRow = guiFactory.doButton2(MainForm,
                                         'Check Puppet',
                                         'Create new buffer from selected buffer')	

        ModuleMasterForm(edit = True,
                         af = [(self.ModuleListColumn,"top",0),
                               (self.ModuleListColumn,"left",0),
                               (self.ModuleListColumn,"right",0),
                               (self.ModuleListColumn,"bottom",0)])


        MainForm(edit = True,
                 af = [(TopSection,"top",0),	
                       (TopSection,"left",0),
                       (TopSection,"right",0),		               
                       (AllModulesRow,"left",0),
                       (AllModulesRow,"right",0),
                       (ModuleListScroll,"left",0),
                       (ModuleListScroll,"right",0),
                       (ModuleListScroll,"left",0),
                       (ModuleListScroll,"right",0),				       
                       (self.helpInfo,"left",8),
                       (self.helpInfo,"right",8),
                       (VerifyRow,"left",4),
                       (VerifyRow,"right",4),		               
                       (VerifyRow,"bottom",4)],
                 ac = [(AllModulesRow,"top",2,TopSection),
                       (ModuleListScroll,"top",2,AllModulesRow),
                       (ModuleListScroll,"bottom",0,self.helpInfo),
                       (self.helpInfo,"bottom",0,VerifyRow)],
                 attachNone = [(VerifyRow,"top")])	
示例#7
0
class animToolsClass(BaseMelWindow):
	from  cgm.lib import guiFactory
	guiFactory.initializeTemplates()
	USE_Template = 'cgmUITemplate'
	
	WINDOW_NAME = 'cgmAnimToolsWindow'
	WINDOW_TITLE = 'cgm.animTools - %s'%__version__
	DEFAULT_SIZE = 180, 350
	DEFAULT_MENU = None
	RETAIN = True
	MIN_BUTTON = True
	MAX_BUTTON = False
	FORCE_DEFAULT_SIZE = True  #always resets the size of the window when its re-created


	def __init__( self):

		self.toolName = 'cgm.animTools'
		self.description = 'This is a series of tools for basic animation functions'
		self.author = 'Josh Burton'
		self.owner = 'CG Monks'
		self.website = 'www.cgmonks.com'
		self.version =  __version__ 
		self.optionVars = []

		self.currentFrameOnly = True
		self.startFrame = ''
		self.endFrame = ''
		self.startFrameField = ''
		self.endFrameField = ''
		self.forceBoundingBoxState = False
		self.forceEveryFrame = False
		self.showHelp = False
		self.helpBlurbs = []
		self.oldGenBlurbs = []

		self.showTimeSubMenu = False
		self.timeSubMenu = []

		#Menu
		self.setupVariables()
		self.UI_OptionsMenu = MelMenu( l='Options', pmc=self.buildOptionsMenu)
		self.UI_BufferMenu = MelMenu( l = 'Buffer', pmc=self.buildBufferMenu)
		self.UI_HelpMenu = MelMenu( l='Help', pmc=self.buildHelpMenu)
		
		self.ShowHelpOption = mc.optionVar( q='cgmVar_AnimToolsShowHelp' )
		
		#Tabs
		tabs = MelTabLayout( self )
		MatchTab = MelColumnLayout(tabs)
		SnapTab = MelColumnLayout( tabs )
		KeysTab = MelColumnLayout( tabs )

		n = 0
		for tab in 'Match','Snap','Keys':
			tabs.setLabel(n,tab)
			n+=1

		self.Match_buildLayout(MatchTab)
		self.Snap_buildLayout(SnapTab)
		self.Keys_buildLayout(KeysTab)

		self.show()

	def setupVariables(self):
		self.LocinatorUpdateObjectsOptionVar = OptionVarFactory('cgmVar_AnimToolsUpdateMode',defaultValue = 0)
		guiFactory.appendOptionVarList(self,self.LocinatorUpdateObjectsOptionVar.name)
		
		self.LocinatorUpdateObjectsBufferOptionVar = OptionVarFactory('cgmVar_LocinatorUpdateObjectsBuffer',defaultValue = [''])
		guiFactory.appendOptionVarList(self,self.LocinatorUpdateObjectsBufferOptionVar.name)	
		
		self.DebugModeOptionVar = OptionVarFactory('cgmVar_AnimToolsDebug',defaultValue=0)
		guiFactory.appendOptionVarList(self,self.DebugModeOptionVar.name)		
		
		#Old method...clean up at some point
		if not mc.optionVar( ex='cgmVar_ForceBoundingBoxState' ):
			mc.optionVar( iv=('cgmVar_ForceBoundingBoxState', 0) )
		if not mc.optionVar( ex='cgmVar_ForceEveryFrame' ):
			mc.optionVar( iv=('cgmVar_ForceEveryFrame', 0) )
		if not mc.optionVar( ex='cgmVar_animToolsShowHelp' ):
			mc.optionVar( iv=('cgmVar_animToolsShowHelp', 0) )
		if not mc.optionVar( ex='cgmVar_CurrentFrameOnly' ):
			mc.optionVar( iv=('cgmVar_CurrentFrameOnly', 0) )
		if not mc.optionVar( ex='cgmVar_animToolsShowHelp' ):
			mc.optionVar( iv=('cgmVar_animToolsShowHelp', 0) )
			
		guiFactory.appendOptionVarList(self,'cgmVar_animToolsShowHelp')
		
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	# Menus
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	def buildOptionsMenu( self, *a ):
		self.UI_OptionsMenu.clear()

		# Placement Menu
		PlacementMenu = MelMenuItem( self.UI_OptionsMenu, l='Placement', subMenu=True)
		PlacementMenuCollection = MelRadioMenuCollection()

		if mc.optionVar( q='cgmVar_ForceBoundingBoxState' ) == 0:
			cgmOption = False
			pivotOption = True
		else:
			cgmOption = True
			pivotOption = False

		PlacementMenuCollection.createButton(PlacementMenu,l='Bounding Box Center',
				                             c=lambda *a: mc.optionVar( iv=('cgmVar_ForceBoundingBoxState', 1)),
				                             rb=cgmOption )
		PlacementMenuCollection.createButton(PlacementMenu,l='Pivot',
				                             c=lambda *a: mc.optionVar( iv=('cgmVar_ForceBoundingBoxState', 0)),
				                             rb=pivotOption )
		
		# Tagging options
		AutoloadMenu = MelMenuItem( self.UI_OptionsMenu, l='Tagging', subMenu=True)
		if not mc.optionVar( ex='cgmVar_TaggingUpdateRO' ):
			mc.optionVar( iv=('cgmVar_TaggingUpdateRO', 1) )
		guiFactory.appendOptionVarList(self,'cgmVar_TaggingUpdateRO')	
	  
		RenameOnUpdateState = mc.optionVar( q='cgmVar_TaggingUpdateRO' )
		MelMenuItem( AutoloadMenu, l="Update Rotation Order",
	                 cb= mc.optionVar( q='cgmVar_TaggingUpdateRO' ),
	                 c= lambda *a: guiFactory.doToggleIntOptionVariable('cgmVar_TaggingUpdateRO'))
		
		# Update Mode
		UpdateMenu = MelMenuItem( self.UI_OptionsMenu, l='Update Mode', subMenu=True)
		UpdateMenuCollection = MelRadioMenuCollection()

		if self.LocinatorUpdateObjectsOptionVar.value == 0:
			slMode = True
			bufferMode = False
		else:
			slMode = False
			bufferMode = True

		UpdateMenuCollection.createButton(UpdateMenu,l='Selected',
				                             c=lambda *a: self.LocinatorUpdateObjectsOptionVar.set(0),
				                             rb=slMode )
		UpdateMenuCollection.createButton(UpdateMenu,l='Buffer',
				                             c=lambda *a:self.LocinatorUpdateObjectsOptionVar.set(1),
				                             rb=bufferMode )
		
		
		MelMenuItemDiv( self.UI_OptionsMenu )
		MelMenuItem( self.UI_OptionsMenu, l="Reset",
			         c=lambda *a: guiFactory.resetGuiInstanceOptionVars(self.optionVars,run))

	def buildBufferMenu( self, *a ):
		self.UI_BufferMenu.clear()
		
		MelMenuItem( self.UI_BufferMenu, l="Define",
		             c= lambda *a: locinatorLib.defineObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
		MelMenuItem( self.UI_BufferMenu, l="Add Selected",
		             c= lambda *a: locinatorLib.addSelectedToObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
		MelMenuItem( self.UI_BufferMenu, l="Remove Selected",
		             c= lambda *a: locinatorLib.removeSelectedFromObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
		MelMenuItemDiv( self.UI_BufferMenu )
		MelMenuItem( self.UI_BufferMenu, l="Select Members",
				     c= lambda *a: locinatorLib.selectObjBufferMembers(self.LocinatorUpdateObjectsBufferOptionVar))
		MelMenuItem( self.UI_BufferMenu, l="Clear",
		             c= lambda *a: locinatorLib.clearObjBuffer(self.LocinatorUpdateObjectsBufferOptionVar))
		
	def buildHelpMenu( self, *a ):
		self.UI_HelpMenu.clear()
		MelMenuItem( self.UI_HelpMenu, l="Show Help",
				     cb=self.ShowHelpOption,
				     c= lambda *a: self.do_showHelpToggle())
		MelMenuItem( self.UI_HelpMenu, l="Print Tools Help",
				     c=lambda *a: self.printHelp() )

		MelMenuItemDiv( self.UI_HelpMenu )
		MelMenuItem( self.UI_HelpMenu, l="About",
				     c=lambda *a: self.showAbout() )
		MelMenuItem( self.UI_HelpMenu, l="Debug",
				     cb=self.DebugModeOptionVar.value,
				     c= lambda *a: self.DebugModeOptionVar.toggle())			

	def do_showHelpToggle( self):
		guiFactory.toggleMenuShowState(self.ShowHelpOption,self.helpBlurbs)
		mc.optionVar( iv=('cgmVar_animToolsShowHelp', not self.ShowHelpOption))
		self.ShowHelpOption = mc.optionVar( q='cgmVar_animToolsShowHelp' )

	def do_showTimeSubMenuToggleOn( self):
		guiFactory.toggleMenuShowState(1,self.timeSubMenu)
		mc.optionVar( iv=('cgmVar_CurrentFrameOnly', 1))

	def do_showTimeSubMenuToggleOff( self):
		guiFactory.toggleMenuShowState(0,self.timeSubMenu)
		mc.optionVar( iv=('cgmVar_CurrentFrameOnly', 0))


	def showAbout(self):
		window = mc.window( title="About", iconName='About', ut = 'cgmUITemplate',resizeToFitChildren=True )
		mc.columnLayout( adjustableColumn=True )
		guiFactory.header(self.toolName,overrideUpper = True)
		mc.text(label='>>>A Part of the cgmTools Collection<<<', ut = 'cgmUIInstructionsTemplate')
		guiFactory.headerBreak()
		guiFactory.lineBreak()
		descriptionBlock = guiFactory.textBlock(self.description)

		guiFactory.lineBreak()
		mc.text(label=('%s%s' %('Written by: ',self.author)))
		mc.text(label=('%s%s%s' %('Copyright ',self.owner,', 2011')))
		guiFactory.lineBreak()
		mc.text(label='Version: %s' % self.version)
		mc.text(label='')
		guiFactory.doButton('Visit Tool Webpage', 'import webbrowser;webbrowser.open(" http://www.cgmonks.com/tools/maya-tools/animTools/")')
		guiFactory.doButton('Close', 'import maya.cmds as mc;mc.deleteUI(\"' + window + '\", window=True)')
		mc.setParent( '..' )
		mc.showWindow( window )

	def printHelp(self):
		import animToolsLib
		help(animToolsLib)

	def do_everyFrameToggle( self):
		EveryFrameOption = mc.optionVar( q='cgmVar_ForceEveryFrame' )
		guiFactory.toggleMenuShowState(EveryFrameOption,self.timeSubMenu)
		mc.optionVar( iv=('cgmVar_ForceEveryFrame', not EveryFrameOption))



	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	# Layouts
	#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	def buildPlaceHolder(self,parent):
		self.containerName = MelColumnLayout(parent,ut='cgmUISubTemplate')
		return self.containerName
	
	def buildTimeSubMenu(self,parent):
		self.containerName = MelColumnLayout(parent,ut='cgmUISubTemplate')
		# Time Submenu
		mc.setParent(self.containerName)
		self.helpBlurbs.extend(guiFactory.instructions(" Set your time range",vis = self.ShowHelpOption))

		timelineInfo = search.returnTimelineInfo()


		# TimeInput Row
		TimeInputRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate')
		self.timeSubMenu.append( TimeInputRow )
		MelSpacer(TimeInputRow)
		MelLabel(TimeInputRow,l='start')

		self.startFrameField = MelIntField(TimeInputRow,'cgmLocWinStartFrameField',
	                                       width = 40,
	                                       value= timelineInfo['rangeStart'])
		TimeInputRow.setStretchWidget( MelSpacer(TimeInputRow) )
		MelLabel(TimeInputRow,l='end')

		self.endFrameField = MelIntField(TimeInputRow,'cgmLocWinEndFrameField',
	                                     width = 40,
	                                     value= timelineInfo['rangeEnd'])

		MelSpacer(TimeInputRow)
		TimeInputRow.layout()

		MelSeparator(self.containerName,ut = 'cgmUISubTemplate',style='none',height = 5)
		

		# Button Row
		TimeButtonRow = MelHSingleStretchLayout(self.containerName,padding = 1, ut='cgmUISubTemplate')
		MelSpacer(TimeButtonRow,w=2)
		currentRangeButton = guiFactory.doButton2(TimeButtonRow,'Current Range',
	                                              lambda *a: locinatorLib.setGUITimeRangeToCurrent(self),
	                                              'Sets the time range to the current slider range')
		TimeButtonRow.setStretchWidget( MelSpacer(TimeButtonRow,w=2) )
		sceneRangeButton = guiFactory.doButton2(TimeButtonRow,'Scene Range',
	                                            lambda *a: locinatorLib.setGUITimeRangeToScene(self),
	                                            'Sets the time range to the current slider range')
		MelSpacer(TimeButtonRow,w=2)
		
		TimeButtonRow.layout()

		
		#>>> Base Settings Flags
		self.KeyingModeCollection = MelRadioCollection()
		self.KeyingModeCollectionChoices = []		
		if not mc.optionVar( ex='cgmVar_AnimToolsKeyingMode' ):
			mc.optionVar( iv=('cgmVar_AnimToolsKeyingMode', 0) )
		guiFactory.appendOptionVarList(self,'cgmVar_AnimToolsKeyingMode')
		
		KeysSettingsFlagsRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate',padding = 2)
		MelSpacer(KeysSettingsFlagsRow,w=2)	
		KeysSettingsFlagsRow.setStretchWidget( MelLabel(KeysSettingsFlagsRow,l='Anim Option: ',align='right') )
		self.keyingOptions = ['Keys','All']
		for item in self.keyingOptions:
			cnt = self.keyingOptions.index(item)
			self.KeyingModeCollectionChoices.append(self.KeyingModeCollection.createButton(KeysSettingsFlagsRow,label=self.keyingOptions[cnt],
			                                                                               onCommand = Callback(guiFactory.toggleOptionVarState,self.keyingOptions[cnt],self.keyingOptions,'cgmVar_AnimToolsKeyingMode',True)))
			MelSpacer(KeysSettingsFlagsRow,w=5)
		mc.radioCollection(self.KeyingModeCollection ,edit=True,sl= (self.KeyingModeCollectionChoices[ (mc.optionVar(q='cgmVar_AnimToolsKeyingMode')) ]))
		
		KeysSettingsFlagsRow.layout()

		#>>> Base Settings Flags
		self.KeyingTargetCollection = MelRadioCollection()
		self.KeyingTargetCollectionChoices = []		
		if not mc.optionVar( ex='cgmVar_AnimToolsKeyingTarget' ):
			mc.optionVar( iv=('cgmVar_AnimToolsKeyingTarget', 0) )
		guiFactory.appendOptionVarList(self,'cgmVar_AnimToolsKeyingTarget')
		
		BakeSettingsFlagsRow = MelHSingleStretchLayout(self.containerName,ut='cgmUISubTemplate',padding = 2)
		MelSpacer(BakeSettingsFlagsRow,w=2)	
		BakeSettingsFlagsRow.setStretchWidget( MelLabel(BakeSettingsFlagsRow,l='From: ',align='right') )
		MelSpacer(BakeSettingsFlagsRow)
		self.keyTargetOptions = ['source','self']
		for item in self.keyTargetOptions:
			cnt = self.keyTargetOptions.index(item)
			self.KeyingTargetCollectionChoices.append(self.KeyingTargetCollection.createButton(BakeSettingsFlagsRow,label=self.keyTargetOptions[cnt],
		                                                                                       onCommand = Callback(guiFactory.toggleOptionVarState,self.keyTargetOptions[cnt],self.keyTargetOptions,'cgmVar_AnimToolsKeyingTarget',True)))
			MelSpacer(BakeSettingsFlagsRow,w=5)
		mc.radioCollection(self.KeyingTargetCollection ,edit=True,sl= (self.KeyingTargetCollectionChoices[ (mc.optionVar(q='cgmVar_AnimToolsKeyingTarget')) ]))
		
		BakeSettingsFlagsRow.layout()
		
		return self.containerName
	
	def Match_buildLayout(self,parent):
		mc.setParent(parent)
		guiFactory.header('Update')

		#>>>Match Mode
		self.MatchModeCollection = MelRadioCollection()
		self.MatchModeCollectionChoices = []		
		if not mc.optionVar( ex='cgmVar_AnimToolsMatchMode' ):
			mc.optionVar( iv=('cgmVar_AnimToolsMatchMode', 0) )	
			
		guiFactory.appendOptionVarList(self,'cgmVar_AnimToolsMatchMode')
			
		#MatchModeFlagsRow = MelHLayout(parent,ut='cgmUISubTemplate',padding = 2)	
		MatchModeFlagsRow = MelHSingleStretchLayout(parent,ut='cgmUIReservedTemplate',padding = 2)	
		MelSpacer(MatchModeFlagsRow,w=2)				
		self.MatchModeOptions = ['parent','point','orient']
		for item in self.MatchModeOptions:
			cnt = self.MatchModeOptions.index(item)
			self.MatchModeCollectionChoices.append(self.MatchModeCollection.createButton(MatchModeFlagsRow,label=self.MatchModeOptions[cnt],
			                                                                             onCommand = Callback(guiFactory.toggleOptionVarState,self.MatchModeOptions[cnt],self.MatchModeOptions,'cgmVar_AnimToolsMatchMode',True)))
			MelSpacer(MatchModeFlagsRow,w=3)
		MatchModeFlagsRow.setStretchWidget( self.MatchModeCollectionChoices[-1] )
		MelSpacer(MatchModeFlagsRow,w=2)		
		MatchModeFlagsRow.layout()	
		
		mc.radioCollection(self.MatchModeCollection ,edit=True,sl= (self.MatchModeCollectionChoices[ (mc.optionVar(q='cgmVar_AnimToolsMatchMode')) ]))
		
		#>>>Time Section
		UpdateOptionRadioCollection = MelRadioCollection()
		
		#>>> Time Menu Container
		self.BakeModeOptionList = ['Current Frame','Bake']
		cgmVar_Name = 'cgmVar_AnimToolsBakeState'
		if not mc.optionVar( ex=cgmVar_Name ):
			mc.optionVar( iv=(cgmVar_Name, 0) )
			
		EveryFrameOption = mc.optionVar( q='cgmVar_AnimToolsBakeState' )
		guiFactory.appendOptionVarList(self,'cgmVar_AnimToolsBakeState')
		
		#build our sub section options
		self.ContainerList = []
		
		#Mode Change row 
		ModeSetRow = MelHSingleStretchLayout(parent,ut='cgmUISubTemplate')
		self.BakeModeRadioCollection = MelRadioCollection()
		self.BakeModeChoiceList = []	
		MelSpacer(ModeSetRow,w=2)

		self.BakeModeChoiceList.append(self.BakeModeRadioCollection.createButton(ModeSetRow,label=self.BakeModeOptionList[0],
	                                                                      onCommand = Callback(guiFactory.toggleModeState,self.BakeModeOptionList[0],self.BakeModeOptionList,cgmVar_Name,self.ContainerList,True)))
		
		ModeSetRow.setStretchWidget( MelSpacer(ModeSetRow) )
		
		self.BakeModeChoiceList.append(self.BakeModeRadioCollection.createButton(ModeSetRow,label=self.BakeModeOptionList[1],
	                                                                      onCommand = Callback(guiFactory.toggleModeState,self.BakeModeOptionList[1],self.BakeModeOptionList,cgmVar_Name,self.ContainerList,True)))
		
		ModeSetRow.layout()
		
		
		#>>>
		self.ContainerList.append( self.buildPlaceHolder(parent) )
		self.ContainerList.append( self.buildTimeSubMenu( parent) )
		
		mc.radioCollection(self.BakeModeRadioCollection,edit=True, sl=self.BakeModeChoiceList[mc.optionVar(q=cgmVar_Name)])
		#>>>
		
		mc.setParent(parent)

		guiFactory.doButton2(parent,'Do it!',
	                         lambda *a: locinatorLib.doUpdateLoc(self),
	                         'Update an obj or locator at a particular frame or through a timeline')

		guiFactory.lineSubBreak()


		#>>>  Loc Me Section
		guiFactory.lineBreak()
		guiFactory.lineSubBreak()
		guiFactory.doButton2(parent,'Just Loc Selected',
			                 lambda *a: locinatorLib.doLocMe(self),
			                 'Create an updateable locator based off the selection and options')


		#>>>  Tag Section
		guiFactory.lineSubBreak()
		guiFactory.doButton2(parent,'Tag it',
		                     lambda *a: locinatorLib.doTagObjects(self),
				             "Tag the selected objects to the first locator in the selection set. After this relationship is set up, you can match objects to that locator.")



	def Keys_buildLayout(self,parent):
		SpecialColumn = MelColumnLayout(parent)

		#>>>  Center Section
		guiFactory.header('Tangents')		
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SpecialColumn,'autoTangent',
		                     lambda *a: mel.eval('autoTangent'),
				             'Fantastic script courtesy of Michael Comet')
		
		guiFactory.lineBreak()		
		guiFactory.header('Breakdowns')
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SpecialColumn,'tweenMachine',
		                     lambda *a: mel.eval('tweenMachine'),
				             'Breakdown tool courtesy of Justin Barrett')
		guiFactory.lineSubBreak()		
		guiFactory.doButton2(SpecialColumn,'breakdownDragger',
		                     lambda *a: animToolsLib.ml_breakdownDraggerCall(),
				             'Breakdown tool courtesy of Morgan Loomis')
		
		guiFactory.lineBreak()		
		guiFactory.header('Utilities')
		guiFactory.lineSubBreak()		
		guiFactory.doButton2(SpecialColumn,'arcTracr',
		                     lambda *a: animToolsLib.ml_arcTracerCall(),
				             'Path tracing tool courtesy of Morgan Loomis')
		guiFactory.lineSubBreak()				
		guiFactory.doButton2(SpecialColumn,'copy Anim',
		                     lambda *a: animToolsLib.ml_copyAnimCall(),
				             'Animation copy tool courtesy of Morgan Loomis')
		guiFactory.lineSubBreak()				
		guiFactory.doButton2(SpecialColumn,'convert Rotation Order',
		                     lambda *a: animToolsLib.ml_convertRotationOrderCall(),
				             'Rotation Order Conversion tool courtesy of Morgan Loomis')
		guiFactory.lineSubBreak()				
		guiFactory.doButton2(SpecialColumn,'stopwatch',
		                     lambda *a: animToolsLib.ml_stopwatchCall(),
				             'Stop Watch tool courtesy of Morgan Loomis')

	def Snap_buildLayout(self,parent):

		SnapColumn = MelColumnLayout(parent)

		#>>>  Snap Section
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SnapColumn,'Parent Snap',
		                     lambda *a: tdToolsLib.doParentSnap(),
				             "Basic Parent Snap")
		
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SnapColumn,'Point Snap',
		                     lambda *a: tdToolsLib.doPointSnap(),
				             "Basic Point Snap")
		
		guiFactory.lineSubBreak()
		guiFactory.doButton2(SnapColumn,'Orient Snap',
		                     lambda *a: tdToolsLib.doOrientSnap(),
				             "Basic Orient Snap")