1 # This script generates the Dialogs interface for Python.
2 # It uses the "bgen" package to generate C code.
3 # It execs the file dlggen.py which contain the function definitions
4 # (dlggen.py was generated by dlgscan.py, scanning the <Dialogs.h> header file).
7 addpack
.addpack(':Tools:bgen:bgen')
9 from macsupport
import *
11 # Create the type objects
13 DialogPtr
= OpaqueByValueType("DialogPtr", "DlgObj")
16 # An OptHandle is either a handle or None (in case NULL is passed in).
17 # This is needed for GetDialogItem().
18 OptHandle
= OpaqueByValueType("Handle", "OptResObj")
20 ModalFilterProcPtr
= InputOnlyType("PyObject*", "O")
21 ModalFilterProcPtr
.passInput
= lambda name
: "NewModalFilterProc(Dlg_PassFilterProc(%s))" % name
22 ModalFilterUPP
= ModalFilterProcPtr
24 RgnHandle
= OpaqueByValueType("RgnHandle", "ResObj")
26 DITLMethod
= Type("DITLMethod", "h")
28 includestuff
= includestuff
+ """
31 #ifndef HAVE_UNIVERSAL_HEADERS
32 #define NewModalFilterProc(x) (x)
35 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
37 /* XXX Shouldn't this be a stack? */
38 static PyObject *Dlg_FilterProc_callback = NULL;
40 static PyObject *DlgObj_New(DialogPtr); /* Forward */
42 static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
48 PyObject *callback = Dlg_FilterProc_callback;
50 return 0; /* Default behavior */
51 Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
52 args = Py_BuildValue("O&O&", WinObj_WhichWindow, dialog, PyMac_BuildEventRecord, event);
56 res = PyEval_CallObject(callback, args);
60 fprintf(stderr, "Exception in Dialog Filter\\n");
62 *itemHit = -1; /* Fake return item */
63 return 1; /* We handled it */
66 Dlg_FilterProc_callback = callback;
67 if (PyInt_Check(res)) {
68 *itemHit = PyInt_AsLong(res);
72 rv = PyObject_IsTrue(res);
78 static ModalFilterProcPtr
79 Dlg_PassFilterProc(PyObject *callback)
81 PyObject *tmp = Dlg_FilterProc_callback;
82 Dlg_FilterProc_callback = NULL;
83 if (callback == Py_None) {
88 Dlg_FilterProc_callback = callback;
90 return &Dlg_UnivFilterProc;
93 extern PyMethodChain WinObj_chain;
97 # Define a class which specializes our object definition
98 class MyObjectDefinition(GlobalObjectDefinition
):
99 def __init__(self
, name
, prefix
= None, itselftype
= None):
100 GlobalObjectDefinition
.__init
__(self
, name
, prefix
, itselftype
)
101 self
.basechain
= "&WinObj_chain"
102 def outputInitStructMembers(self
):
103 GlobalObjectDefinition
.outputInitStructMembers(self
)
104 Output("SetWRefCon(itself, (long)it);")
105 def outputCheckNewArg(self
):
106 Output("if (itself == NULL) return Py_None;")
107 def outputCheckConvertArg(self
):
108 Output("if (v == Py_None) { *p_itself = NULL; return 1; }")
109 Output("if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);")
110 Output(" return 1; }")
111 def outputFreeIt(self
, itselfname
):
112 Output("DisposeDialog(%s);", itselfname
)
114 # Create the generator groups and link them
115 module
= MacModule('Dlg', 'Dlg', includestuff
, finalstuff
, initstuff
)
116 object = MyObjectDefinition('Dialog', 'DlgObj', 'DialogPtr')
117 module
.addobject(object)
119 # Create the generator classes used to populate the lists
120 Function
= OSErrFunctionGenerator
121 Method
= OSErrMethodGenerator
123 # Create and populate the lists
126 execfile("dlggen.py")
128 # add the populated lists to the generator groups
129 for f
in functions
: module
.add(f
)
130 for f
in methods
: object.add(f
)
133 SetOutputFileName('Dlgmodule.c')