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
"""
htmlText = '<html>\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>'''
respMessages = sorted(ResponseMessageRegistry)
print "RESPONSE:", responses; import sys; sys.stdout.flush()
for msgId in sorted(ResponseMessageRegistry):
entry = ResponseMessageRegistry[msgId]
timeout = entry[0]
conditions = entry[1]
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 )