import string
from ScriptRunner import ScriptRunner, ResponseMessageRegistry
from Message import Message
from MessageRegistry import theMessageRegistry
class MessageDocumentation( ScriptRunner ):
def __init__( self, scriptName, args ):
ScriptRunner.__init__( self, scriptName, args )
def Main( self ):
"""
This will save documentation to C:/AutodeskShowcaseMessages.html
"""
disclaimer = """
Copyright 2009 Autodesk, Inc. All rights reserved.<br>
This publication, or parts thereof, may not be reproduced in any form,
by any method, for any purpose.<br>
<br>
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
PARTICULAR PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS
AVAILABLE SOLELY ON AN "AS-IS" BASIS.<br>
<br>
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF
PURCHASE OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO
AUTODESK, INC., REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE
PURCHASE PRICE OF THE MATERIALS DESCRIBED HEREIN. <br>
<br>
Autodesk, Inc., reserves the right to revise and improve its products as it
sees fit. This publication describes the state of this product at the time of
its publication, and may not reflect the product at all times in the future.
<br><br>
Autodesk Internal Confidential Document. Do not distribute.<br><br>
"""
htmlText = '<html>\n' + disclaimer + "\n<hr>\n"
ids = sorted(theMessageRegistry.ids())
htmlText += '<A href="#Responses">Response Messages</A><br><br>\n'
for first in string.ascii_uppercase:
htmlText += '<A href="#Letter%s">%s</A>\n' % (first,first)
htmlText += "<br><br>\n"
parHeader = '''
<table border="0" cellpadding="0" cellspacing="0">
<tr><td><b>%s:</b></td><td colspan="2">
</td></tr>''' % (_("Parameters"))
first = ''
for k in ids:
if theMessageRegistry.hasProperty( k, Message.kInternal ):
continue
(desc,pars,cats) = ['Undocumented.', [['unknown','unknown']],()]
doc = theMessageRegistry.documentation(k)
fullcats = ''
if doc:
if len(doc) == 3:
(desc, pars, cats) = doc
if cats and len(cats) > 0:
fullcats = ' <font size="-1">(%s)</font>' % ' '.join(cats)
elif len(doc) == 2:
(desc, pars) = doc
if first != k[0]:
first = k[0]
htmlText += '<A name="Letter%s"> </A><br>\n' % (first)
if len(pars) == len(theMessageRegistry.dataType(k)):
htmlText += '<font size="+1"><b>%s</b></font>%s\n' % ( k,fullcats )
else:
htmlText += '<font size="+1" color="red"><b>%s</b></font>%s\n' % ( k,fullcats )
properties = ''
if theMessageRegistry.hasProperty( k, Message.kUndoable ) and \
theMessageRegistry.hasProperty( k, Message.kBroadcastable ):
properties = _('This message is broadcastable and undoable.')
elif theMessageRegistry.hasProperty( k, Message.kBroadcastable ):
properties = _('This message is broadcastable.')
elif theMessageRegistry.hasProperty( k, Message.kUndoable ):
properties = _('This message is undoable.')
htmlText += '<br>%s %s<br>\n' % (desc,properties)
firstPar = True
for par in pars:
( a, b ) = par
if a != '' or b != '':
if firstPar:
htmlText += parHeader
firstPar = False
htmlText += ( '<tr><td><i>%s</i></td><td> </td><td>%s</td></tr>\n' % ( a, b ) )
htmlText += '</table><br><br>\n'
responses = '''
<A name="Responses"><hr><br>
<font size="+1"><b>MESSAGE RESPONSES</b></font>
</A><br><br>\n'''
responses += '<table border="1">\n'
responses += '''
<tr><td align="center"><b>Message sent</b></td>
<td align="center"><b>Message(s) to wait for</b></td>
<td align="center"><b>Default maximum waiting time</b></td></tr>'''
for msgId in sorted(ResponseMessageRegistry):
(timeout, conditions) = ResponseMessageRegistry[msgId]
if callable(conditions):
all = ""
for k in ids:
if conditions((k,),k):
if all != "":
all += "<br>"
all += k
if all == "":
conditions = " "
else:
conditions = all
responses += '''
<tr><td valign="top">%s</td>
<td valign="top">%s</td>
<td valign="top" align="center">%s</td>
</tr>''' % (msgId,str(conditions),str(timeout))
responses += '</table>\n'
htmlText += (responses + '</html>\n')
f = open( "C:/AutodeskShowcaseMessages.html", 'w' )
f.write( htmlText )
f.close()
self.sendMessageSync( 'STATUSBAR_SET_TEXT',
(("Saved message documentation to C:/AutodeskShowcaseMessages.html"),))
def instantiate( scriptName, args ):
return MessageDocumentation( scriptName, args )