Skip to content

Commit e0acfc4

Browse files
EMSUSD-1813 fix custom AE callbacks
- Add the custom callback to teh list of section to add. - Create a unit test that verify it works.
1 parent 56d2b24 commit e0acfc4

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

lib/mayaUsd/resources/ae/usdschemabase/ae_template.py

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def __init__(self, ufeSceneItem):
239239

240240
# Build the list of schemas with their associated attributes.
241241
schemasAttributes = {
242+
'customCallbacks' : [],
242243
'extraAttributes' : [],
243244
'metadata' : [],
244245
}

test/lib/testAttributeEditorTemplate.py

+76-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424

2525
from maya import cmds
2626
from maya import mel
27-
from maya import standalone
27+
import maya.internal.common.ufe_ae.template as ufeAeTemplate
2828

2929
from mayaUsdLibRegisterStrings import getMayaUsdLibString
3030
import mayaUsd_createStageWithNewLayer
31-
32-
from pxr import Usd
31+
import mayaUsd.lib
3332

3433
import ufe
3534

@@ -527,6 +526,80 @@ def testAEForLight(self):
527526
actualSectionLabels[-len(expectedFinalSectionLabels):],
528527
expectedFinalSectionLabels)
529528

529+
def testAECustomAttributeCallback(self):
530+
'''Test that the custm atribute callbacks work.'''
531+
532+
# AE template UI callback function.
533+
self.templateUseCount = 0
534+
customSectionName ='UnlikelySectionName'
535+
536+
# Callback function which receives two params as input: callback context and
537+
# callback data (empty).
538+
def onBuildAETemplateCallback(context, data):
539+
# In the callback context you can retrieve the ufe path string.
540+
ufe_path_string = context.get('ufe_path_string')
541+
ufePath = ufe.PathString.path(ufe_path_string)
542+
ufeItem = ufe.Hierarchy.createItem(ufePath)
543+
self.assertTrue(ufeItem)
544+
545+
# The callback data is empty.
546+
547+
# Note: do not import this globally, because at unit test startup time
548+
# the Python search path is not setup to find it. Once Maya runs,
549+
# we can import it.
550+
from ufe_ae.usd.nodes.usdschemabase.ae_template import AETemplate as mayaUsd_AETemplate
551+
552+
mayaUsdAETemplate = mayaUsd_AETemplate.getAETemplateForCustomCallback()
553+
self.assertTrue(mayaUsdAETemplate)
554+
if mayaUsdAETemplate:
555+
# Create a new section and add attributes to it.
556+
with ufeAeTemplate.Layout(mayaUsdAETemplate, customSectionName, collapse=False):
557+
pass
558+
559+
self.templateUseCount = self.templateUseCount + 1
560+
561+
# Register your callback so it will be called during the MayaUsd AE
562+
# template UI building code. This would probably done during plugin loading.
563+
# The first param string 'onBuildAETemplate' is the callback operation and the
564+
# second is the name of your callback function.
565+
mayaUsd.lib.registerUICallback('onBuildAETemplate', onBuildAETemplateCallback)
566+
567+
try:
568+
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
569+
proxyShapePath = ufe.PathString.path(proxyShape)
570+
proxyShapeItem = ufe.Hierarchy.createItem(proxyShapePath)
530571

572+
# Create a capsule prim.
573+
proxyShapeContextOps = ufe.ContextOps.contextOps(proxyShapeItem)
574+
proxyShapeContextOps.doOp(['Add New Prim', 'Capsule'])
575+
fullPrimPath = proxyShape + ",/Capsule1"
576+
cmds.select(fullPrimPath)
577+
578+
# Make sure the AE is visible.
579+
import maya.mel
580+
maya.mel.eval('openAEWindow')
581+
582+
capsuleFormLayout = self.attrEdFormLayoutName('Capsule')
583+
self.assertTrue(cmds.formLayout(capsuleFormLayout, exists=True))
584+
startLayout = cmds.formLayout(capsuleFormLayout, query=True, fullPathName=True)
585+
self.assertIsNotNone(startLayout, 'Could not get full path for Capsule formLayout')
586+
587+
# Augment the maixmum diff size to get better error message when comparing the lists.
588+
self.maxDiff = 2000
589+
590+
actualSectionLabels = self.findAllFrameLayoutLabels(startLayout)
591+
592+
# Verify we got the custom section.
593+
self.assertIn(customSectionName, actualSectionLabels)
594+
self.assertGreater(self.templateUseCount, 0)
595+
except:
596+
# During your plugin unload you should unregister the callback (and any attribute
597+
# nice naming function you also added).
598+
mayaUsd.lib.unregisterUICallback('onBuildAETemplate', onBuildAETemplateCallback)
599+
raise
600+
else:
601+
mayaUsd.lib.unregisterUICallback('onBuildAETemplate', onBuildAETemplateCallback)
602+
603+
531604
if __name__ == '__main__':
532605
fixturesUtils.runTests(globals())

0 commit comments

Comments
 (0)