Interactive/ContextMenuCustom.py

# (C) Copyright 2012 Autodesk, Inc.  All rights reserved.
#
# Use of this software is subject to the terms of the Autodesk license
# agreement provided at the time of installation or download, or which
# otherwise accompanies this software in either electronic or hard copy
# form.

# You will need Autodesk Showcase 2009 R1 or later.
#
 
#
# You will get a custom menu item in the context menu for the
# alternatives, behaviors, environments, materials, shots and storyboard.

__all__ = ['ContextMenuCustom', 'instantiate']

from UserCustomization         import UserCustomBase, CustomInfo
from GenericPopupMenu          import GenericPopupMenuItem
from MessageInterpreter        import MessageInterpreter

import StoryboardIO

class ContextMenu( UserCustomBase ):
    def __init__( self ):
        #UserCustomBase.__init__(self)
        self.__myInterpreter = LocalInterpreter()

    def getInterpreter( self, isInteractive ):
        if isInteractive:
            return self.__myInterpreter
        return None

    def appendPopupMenuItems( self, id, popupMenu, item ):
        menuItem = None
        if "AlternativeSelector" == id:
            menuItem = GenericPopupMenuItem(_( 'Custom for Alternative'),
                                            self.__cbCustomAlternative,
                                            item )
        elif "BehaviorSelector" == id:
            menuItem = GenericPopupMenuItem(_( 'Custom for Behavior'),
                                            self.__cbCustomBehavior,
                                            item )
        elif "EnvSceneSelector" == id or "EnvLibrarySelector" == id:
            menuItem = GenericPopupMenuItem(_( 'Custom for Environment'),
                                            self.__cbCustomEnvironment,
                                            item )
        elif "MaterialSelector" == id:
            menuItem = GenericPopupMenuItem(_( 'Custom for Material'),
                                            self.__cbCustomMaterial,
                                            item )
        elif "ShotSelector" == id:
            menuItem = GenericPopupMenuItem(_( 'Custom for Shot'),
                                            self.__cbCustomShot,
                                            item )
        elif "StoryboardSelector" == id:
            menuItem = GenericPopupMenuItem(_( 'Custom for Storyboard'),
                                            self.__cbCustomStoryboard,
                                            item )
        else:
            print "Unrecognized id %s" % id

        if menuItem is not None:
            popupMenu.append( menuItem )


    def __cbCustomAlternative( self, item ):
        print 'Alternative callback with %s' % item

    def __cbCustomBehavior( self, item ):
        print 'Behavior callback with %s' % item
        print 'Behavior UI item name %s' % item.name()
        print 'Behavior UI item label %s' % item.getLabel()
        print 'Behavior UI item type %s' % item.getType()

    def __cbCustomEnvironment( self, item ):
        print 'Environment callback with %s' % item

    def __cbCustomMaterial( self, item ):
        print 'Material callback with %s' % item

    def __cbCustomShot( self, item ):
        print 'Shot callback with %s' % item

    def __cbCustomStoryboard( self, item ):
        print 'Storyboard callback with %s' % item
        print 'Slide id is %s' % (item.getId())
        sb = self.__myInterpreter.myDocument.get(StoryboardIO.id)
        print "Slide is %s" % (sb[item.getId()])


class LocalInterpreter( MessageInterpreter ):

    def __init__( self ):
        MessageInterpreter.__init__( self )
        self.__myStoryboard = None

    def SET_DOCUMENT( self, message ):
        (self.myDocument,) = message.data


def instantiate():
    return ContextMenu()


def info():
    customInfo = CustomInfo()
    customInfo.vendor = 'Autodesk'
    customInfo.version = '2.0'
    customInfo.api = '2013'
    customInfo.shortInfo = "Add menu item under the context menu."
    customInfo.longInfo = \
"""A sample add-in showing how to add menu item in the context menu for the alternatives, \
behaviors, environments, materials, shots and storyboard.
"""
    return customInfo