]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/py/wxd/genapi.py
doc tweaks, typo fixed, etc.
[wxWidgets.git] / wxPython / wx / py / wxd / genapi.py
1 """API generator for decorator classes.
2 """
3
4 __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
5 __cvsid__ = "$Id$"
6 __revision__ = "$Revision$"[11:-2]
7
8
9 import inspect
10 import os
11 import sys
12 import types
13
14
15 header = '''\
16 """wxPython decorator classes.
17
18 This file is automatically generated, and these are not the real
19 wxPython classes. These are Python versions for API documentation
20 purposes only.
21
22 Please send corrections, questions, and suggestions to:
23
24 Patrick K. O'Brien <pobrien@orbtech.com>
25 """
26
27 __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
28
29 from wxd import Parameters as wx
30
31 try:
32 True
33 except NameError:
34 True = 1==1
35 False = 1==0
36 '''
37
38 modlist = [
39 'Base',
40 'Window',
41 'Frames',
42 'Accelerators',
43 'App',
44 'ClipDragDrop',
45 'Config',
46 'Controls',
47 'DataStructures',
48 'DateTime',
49 'Dialogs',
50 'Drawing',
51 'Errors',
52 'EventFunctions',
53 'Events',
54 'FileSystem',
55 'Functions',
56 'Help',
57 'ImageHandlers',
58 'Joystick',
59 'LayoutConstraints',
60 'Logging',
61 'Menus',
62 'MimeTypes',
63 'Misc',
64 'Panel',
65 'Printing',
66 'Process',
67 'SashSplitter',
68 'Sizers',
69 'Streams',
70 'Threading',
71 'ToolBar',
72 'Tree',
73 'Validators',
74 ]
75
76 dir = os.path.realpath('api/wx/')
77 filename = os.path.join(dir, '__init__.py')
78
79 def main():
80 modules = {}
81 f = file(filename, 'w')
82 f.write(header)
83 for modname in modlist:
84 modules[modname] = __import__(modname, globals())
85 for modname in modlist:
86 module = modules[modname]
87 try:
88 source = inspect.getsource(module)
89 except IOError:
90 print 'No source for', module
91 else:
92 # Remove everything up to the first class or function definition.
93 splitter = '\n\nclass '
94 parts = source.split(splitter, 1)
95 if len(parts) == 2:
96 source = splitter + parts[1]
97 else:
98 splitter = '\n\ndef '
99 parts = source.split(splitter, 1)
100 if len(parts) == 2:
101 source = splitter + parts[1]
102 source = '\n\n\n' + source.strip()
103 f.write(source)
104 print 'Writing', modname
105 f.write('\n')
106 f.close()
107
108 # Add constants and any other missing stuff.
109 f = file(filename, 'a')
110 f.write('\n\n## Other Stuff:\n\n')
111 import wx as old
112 old = old.__dict__
113 sys.path.insert(0, dir) # Munge the sys.path so that we can
114 import __init__ # import the file we just created.
115 new = __init__.__dict__
116 l = [(k, v) for (k, v) in old.items() if (not k.startswith('_')
117 and not k.endswith('Ptr')
118 and not (k == 'cvar'))]
119 l.sort()
120 from wxPython import wx
121 for key, value in l:
122 if key not in new:
123 if (inspect.isclass(value)
124 or inspect.isroutine(value)
125 or type(value) is types.InstanceType):
126 value = repr(value)
127 text = '%s = %r' % (key, value)
128 f.write(text + '\n')
129 print 'Writing', text
130 f.close()
131
132 if __name__ == '__main__':
133 main()