#!/usr/bin/python
# coding=UTF-8
from PySFML import sf
# Amélioration à faire : trouver les méthodes héritées, et de quelle classe
def function_str(function, class_name=None):
string = ''
name = function.__name__
doc = function.__doc__
if not doc.startswith(name+'('):
string += name+"(...)"+'\n'
string += doc+'\n'
strings = string.split('\n')
strings[0] = '
'+strings[0]+'
\n'
string = strings[0]
for s in strings[1:-1]:
string += s + '
'
string += strings[-1]
inherited = ''
if class_name != None:
try:
base_class_name = function.__objclass__.__name__
if base_class_name != class_name:
inherited = '
Inherited
\n'
except AttributeError:
pass
return string.replace('\t', ' ')+'
\n'+inherited
class FilesManager:
def __init__(self):
self.files = {}
f = open("header.htm")
self.header = f.read()
f.close()
f = open("footer.htm")
self.footer = f.read()
f.close()
def add(self, filename, string):
if not self.files.has_key(filename):
self.files[filename] = open('../doc/' + filename + '.html', 'w')
self.files[filename].write(self.header.replace('TITLE', filename))
self.files[filename].write(string)
def __del__(self):
for filename in self.files:
self.files[filename].write(self.footer)
self.files[filename].close()
def Main():
fm = FilesManager()
fm.add('index', 'PySFML index
\n')
fm.add('index', 'Classes
\n')
module_methods = ""
module_constants = ""
for m in dir(sf):
if not m.startswith('__'):
if m == 'Event':
attr = sf.Event()
else:
attr = getattr(sf, m)
if type(attr) == str:
module_constants += ''+m+'
\n"'+attr+'"
\n'
elif str(type(attr)) == "" or str(type(attr)) == "":
module_methods += function_str(attr)
else:
fm.add('index', ''+m+'
\n')
info = {'Attributes':'', 'Constants':'', 'Methods':'', 'Static methods':''}
members = ""
constants = ""
static_methods = ""
methods = ""
for n in dir(attr):
if not n.startswith('__'):
attr2 = getattr(attr, n)
if str(type(attr2)) == "": # member
info['Attributes'] += ''+n+'
\n'+attr2.__doc__+'
\n'
elif type(attr2) == long:
info['Attributes'] += ''+n+'
\n'
elif type(attr2) == int or type(attr2) == sf.Color: # int or color (constant)
info['Constants'] += ''+n+'
\n'
elif str(type(attr2)) == "": # static method
info['Static methods'] += function_str(attr2, m)
elif str(type(attr2)) == "": # method
info['Methods'] += function_str(attr2, m)
elif str(type(attr2)).startswith("'+n+'\n' + attr2.__doc__+'
\n'
for o in dir(attr2):
if not o.startswith('__'):
attr3 = getattr(attr2, o)
info['Attributes'] += ' > ' + o + '
\n'
else:
print "Warning : unknown type for " + n + " " + str(type(attr2))
fm.add(m, 'sf.'+m+' Class Reference
\n')
fm.add(m, ''+attr.__doc__.replace('\n', '
\n').replace('\t', ' ')+'
\n')
if m != 'Event':
base = attr.__base__.__name__
if base != 'object':
fm.add(m, '\n')
for t in info:
if info[t] != '':
fm.add(m, ''+t+'
\n'+info[t]+'
\n')
fm.add(m, '
\n
\n')
fm.add('index', 'Module methods
\n' + module_methods)
fm.add('index', 'Module constants
\n' + module_constants)
Main()