Interactive/ResponseMessagesList.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 or later.
#
 
#
# You will get Help -> All Response Messages to show all the Response Messages.
#

from MessageInterpreter     import MessageInterpreter
from UserCustomization      import UserCustomBase, CustomInfo
from awSupportApi           import Product
from Dialogs.AboutDialog    import AboutDialog

from ScriptRunner           import ResponseMessageRegistry

def instantiate():
    return DumpMenusCustomization()

class DumpMenusCustomization(UserCustomBase):
    def __init__(self):
        self.__myInterpreter = LocalInterpreter()
        self.__myMenu = None
        self.__myDumpId = None
        self.__myLocalMenu = None

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

    def appendMenu(self, menuInterpreter):
        self.__myMenuInterpreter = menuInterpreter
        
    def appendMenuItems(self,id,menu):
        if "Help" == id:
            self.__myMenu = menu
            menu.appendItem(_( 'Show All Response Messages' ), self.__onAllResponseMessages )
            
    def __onAllResponseMessages( self, event ):
        self.__myInterpreter.AllResponseMessages(self.__myMenuInterpreter, self.__myMenu)

        
class LocalInterpreter(MessageInterpreter):
    def __init__(self):
        MessageInterpreter.__init__(self)
        self.__myResponseMessages = ResponseMessageRegistry
        self.kSpacing = "    "


    def assembleItem( self, prefix, item ):
        return "%s%s<br>\n" % (prefix,item)


    def assembleFirst( self, prefix, item ):
        return "%s<b>%s</b><br>\n" % (prefix,item)

    def assembleResponseMessages( self ):
        res = "<table border=1>\n"
        for message in sorted(self.__myResponseMessages):
            res += "<tr><td>%s</td><td>%s</td></tr>\n" % (message,self.__myResponseMessages[message])
        res += "</table>\n"
        return res

    def AllResponseMessages(self, menuInterpreter, menu):
        product = Product.instance()
        productName = product.getFullNameNoFlavour()
        yearId = "%s" % (product.getCutId()[0:4])

        hd = "<html>\n"
        hd += self.assembleResponseMessages()
        hd += "</html>\n"

        msgs = AboutDialog(scrollHeight=500,doHtml=True,printTitle=productName)
        msgs.showRes( menu.getParentWindow(),
                      '%s Response Messages' % (productName),
                      product.getBrandingResourceFile(),
                      product.getBrandingIndexAboutImage(),
                      "",
                      "Copyright %s Autodesk, Inc. All rights reserved. Do not distribute." % (yearId),
                      "",
                      hd )


    def __invoke(self,top, val):
        if val:
            return '&nbsp;&nbsp;<font color="red" size="-1">Access with MENU_INVOKE_ITEM(%s,%s)</font>' % (str(top),str(val))
        else:
            return ""

def info():
    customInfo = CustomInfo()
    customInfo.vendor = 'Autodesk'
    customInfo.version = '1.0'
    customInfo.api = '2013'
    customInfo.shortInfo = "Show all Response Messages"
    customInfo.longInfo = \
"""Add one menu item under "Help" menu to show all the response messages.  The menu items list also shows the syntax for the MENU_INVOKE_ITEM message to access it.
"""
    return customInfo