source: python/trunk/Mac/Modules/help/helpsupport.py

Last change on this file was 2, checked in by Yuri Dario, 15 years ago

Initial import for vendor code.

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1# This script generates a Python interface for an Apple Macintosh Manager.
2# It uses the "bgen" package to generate C code.
3# The function specifications are generated by scanning the mamager's header file,
4# using the "scantools" package (customized for this particular manager).
5
6import string
7
8# Declarations that change for each manager
9MODNAME = '_Help' # The name of the module
10OBJECTNAME = 'UNUSED' # The basic name of the objects used here
11KIND = 'Record' # Usually 'Ptr' or 'Handle'
12
13# The following is *usually* unchanged but may still require tuning
14MODPREFIX = 'Help' # The prefix for module-wide routines
15OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
16OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
17INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
18OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
19
20from macsupport import *
21
22# Create the type objects
23MenuRef = OpaqueByValueType("MenuRef", "MenuObj")
24MenuItemIndex = Type("MenuItemIndex", "H")
25
26#WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
27
28#RgnHandle = FakeType("(RgnHandle)0")
29# XXXX Should be next, but this will break a lot of code...
30# RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
31
32#KeyMap = ArrayOutputBufferType("KeyMap")
33##MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
34##MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
35#EventMask = Type("EventMask", "H")
36#EventKind = Type("EventKind", "H")
37
38includestuff = includestuff + """
39#include <Carbon/Carbon.h>
40"""
41
42class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
43 def outputCheckNewArg(self):
44 Output("if (itself == NULL) return PyMac_Error(resNotFound);")
45 def outputCheckConvertArg(self):
46 OutLbrace("if (DlgObj_Check(v))")
47 Output("*p_itself = ((WindowObject *)v)->ob_itself;")
48 Output("return 1;")
49 OutRbrace()
50 Out("""
51 if (v == Py_None) { *p_itself = NULL; return 1; }
52 if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
53 """)
54
55# From here on it's basically all boiler plate...
56
57# Create the generator groups and link them
58module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
59##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
60##module.addobject(object)
61
62# Create the generator classes used to populate the lists
63Function = OSErrFunctionGenerator
64##Method = OSErrMethodGenerator
65
66# Create and populate the lists
67functions = []
68##methods = []
69execfile(INPUTFILE)
70
71# add the populated lists to the generator groups
72# (in a different wordl the scan program would generate this)
73for f in functions: module.add(f)
74##for f in methods: object.add(f)
75
76# generate output (open the output file as late as possible)
77SetOutputFileName(OUTPUTFILE)
78module.generate()
Note: See TracBrowser for help on using the repository browser.