summaryrefslogtreecommitdiffstats
path: root/Doc/tools/support.py
blob: 30d4575cb649a48254c31b346b9de381abc1913f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
"""Miscellaneous support code shared by some of the tool scripts.

This includes option parsing code, HTML formatting code, and a couple of
useful helpers.

"""
__version__ = '$Revision$'


import getopt
import os.path
import sys


class Options:
    __short_args = "a:c:ho:"
    __long_args = [
        # script controls
        "columns=", "help", "output=",

        # content components
        "address=", "iconserver=", "favicon=",
        "title=", "uplink=", "uptitle="]

    outputfile = "-"
    columns = 1
    letters = 0
    uplink = "index.html"
    uptitle = "Python Documentation Index"
    favicon = None

    # The "Aesop Meta Tag" is poorly described, and may only be used
    # by the Aesop search engine (www.aesop.com), but doesn't hurt.
    #
    # There are a number of values this may take to roughly categorize
    # a page.  A page should be marked according to its primary
    # category.  Known values are:
    #   'personal'    -- personal-info
    #   'information' -- information
    #   'interactive' -- interactive media
    #   'multimedia'  -- multimedia presenetation (non-sales)
    #   'sales'       -- sales material
    #   'links'       -- links to other information pages
    #
    # Setting the aesop_type value to one of these strings will cause
    # get_header() to add the appropriate <meta> tag to the <head>.
    #
    aesop_type = None

    def __init__(self):
        self.args = []
        self.variables = {"address": "",
                          "iconserver": "icons",
                          "imgtype": "gif",
                          "title": "Global Module Index",
                          }

    def add_args(self, short=None, long=None):
        if short:
            self.__short_args = self.__short_args + short
        if long:
            self.__long_args = self.__long_args + long

    def parse(self, args):
        try:
            opts, args = getopt.getopt(args, self.__short_args,
                                       self.__long_args)
        except getopt.error:
            sys.stdout = sys.stderr
            self.usage()
            sys.exit(2)
        self.args = self.args + args
        for opt, val in opts:
            if opt in ("-a", "--address"):
                val = val.strip()
                if val:
                    val = "<address>\n%s\n</address>\n" % val
                    self.variables["address"] = val
            elif opt in ("-h", "--help"):
                self.usage()
                sys.exit()
            elif opt in ("-o", "--output"):
                self.outputfile = val
            elif opt in ("-c", "--columns"):
                self.columns = int(val)
            elif opt == "--title":
                self.variables["title"] = val.strip()
            elif opt == "--uplink":
                self.uplink = val.strip()
            elif opt == "--uptitle":
                self.uptitle = val.strip()
            elif opt == "--iconserver":
                self.variables["iconserver"] = val.strip() or "."
            elif opt == "--favicon":
                self.favicon = val.strip()
            else:
                self.handle_option(opt, val)
        if self.uplink and self.uptitle:
            self.variables["uplinkalt"] = "up"
            self.variables["uplinkicon"] = "up"
        else:
            self.variables["uplinkalt"] = ""
            self.variables["uplinkicon"] = "blank"
        self.variables["uplink"] = self.uplink
        self.variables["uptitle"] = self.uptitle

    def handle_option(self, opt, val):
        raise getopt.error("option %s not recognized" % opt)

    def get_header(self):
        s = HEAD % self.variables
        if self.uplink:
            if self.uptitle:
                link = ('<link rel="up" href="%s" title="%s">'
                        % (self.uplink, self.uptitle))
            else:
                link = '<link rel="up" href="%s">' % self.uplink
            repl = "  %s\n</head>" % link
            s = s.replace("</head>", repl, 1)
        if self.aesop_type:
            meta = '<meta name="aesop" content="%s">\n  ' % self.aesop_type
            # Insert this in the middle of the head that's been
            # generated so far, keeping <meta> and <link> elements in
            # neat groups:
            s = s.replace("<link ", meta + "<link ", 1)
        if self.favicon:
            ext = os.path.splitext(self.favicon)[1]
            if ext in (".gif", ".png"):
                type = ' type="image/%s"' % ext[1:]
            else:
                type = ''
            link = ('<link rel="SHORTCUT ICON" href="%s"%s>\n  '
                    % (self.favicon, type))
            s = s.replace("<link ", link + "<link ", 1)
        return s

    def get_footer(self):
        return TAIL % self.variables

    def get_output_file(self, filename=None):
        if filename is None:
            filename = self.outputfile
        if filename == "-":
            return sys.stdout
        else:
            return open(filename, "w")


NAVIGATION = '''\
<div class="navigation">
<table width="100%%" cellpadding="0" cellspacing="2">
<tr>
<td><img width="32" height="32" align="bottom" border="0" alt=""
 src="%(iconserver)s/blank.%(imgtype)s"></td>
<td><a href="%(uplink)s"
 title="%(uptitle)s"><img width="32" height="32" align="bottom" border="0"
 alt="%(uplinkalt)s"
 src="%(iconserver)s/%(uplinkicon)s.%(imgtype)s"></a></td>
<td><img width="32" height="32" align="bottom" border="0" alt=""
 src="%(iconserver)s/blank.%(imgtype)s"></td>
<td align="center" width="100%%">%(title)s</td>
<td><img width="32" height="32" align="bottom" border="0" alt=""
 src="%(iconserver)s/blank.%(imgtype)s"></td>
<td><img width="32" height="32" align="bottom" border="0" alt=""
 src="%(iconserver)s/blank.%(imgtype)s"></td>
<td><img width="32" height="32" align="bottom" border="0" alt=""
 src="%(iconserver)s/blank.%(imgtype)s"></td>
</tr></table>
<b class="navlabel">Up:</b> <span class="sectref"><a href="%(uplink)s"
 title="%(uptitle)s">%(uptitle)s</A></span>
<br></div>
'''

HEAD = '''\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <title>%(title)s</title>
  <meta name="description" content="%(title)s">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <link rel="STYLESHEET" href="lib/lib.css">
</head>
<body>
''' + NAVIGATION + '''\
<hr>

<h2>%(title)s</h2>

'''

TAIL = "<hr>\n" + NAVIGATION + '''\
%(address)s</body>
</html>
'''
oss-git/cpython.git/diff/Mac/Modules/res/ressupport.py?h=v3.8.14&id=182b5aca27d376b08a2904bed42b751496f932f3'>Mac/Modules/res/ressupport.py296
-rw-r--r--Mac/Modules/scrap/scrapscan.py84
-rw-r--r--Mac/Modules/scrap/scrapsupport.py25
-rw-r--r--Mac/Modules/snd/sndscan.py222
-rw-r--r--Mac/Modules/snd/sndsupport.py356
-rw-r--r--Mac/Modules/te/tescan.py94
-rw-r--r--Mac/Modules/te/tesupport.py245
-rw-r--r--Mac/Modules/waste/wastescan.py260
-rw-r--r--Mac/Modules/waste/wastesupport.py441
-rw-r--r--Mac/Modules/win/winedit.py24
-rw-r--r--Mac/Modules/win/winscan.py233
-rw-r--r--Mac/Modules/win/winsupport.py180
71 files changed, 5823 insertions, 5849 deletions
diff --git a/Mac/Modules/ae/aescan.py b/Mac/Modules/ae/aescan.py
index 80c198c..1283c1d 100644
--- a/Mac/Modules/ae/aescan.py
+++ b/Mac/Modules/ae/aescan.py
@@ -13,87 +13,87 @@ sys.path.append(BGENDIR)
from scantools import Scanner
def main():
- print "=== Scanning AEDataModel.h, AppleEvents.h, AERegistry.h, AEObjects.h ==="
- input = ["AEDataModel.h", "AEInteraction.h", "AppleEvents.h", "AERegistry.h", "AEObjects.h"]
- output = "aegen.py"
- defsoutput = TOOLBOXDIR + "AppleEvents.py"
- scanner = AppleEventsScanner(input, output, defsoutput)
- scanner.scan()
- scanner.close()
- print "=== Testing definitions output code ==="
- execfile(defsoutput, {}, {})
- print "=== Done Scanning and Generating, now doing 'import aesupport' ==="
- import aesupport
- print "=== Done 'import aesupport'. It's up to you to compile AEmodule.c ==="
+ print "=== Scanning AEDataModel.h, AppleEvents.h, AERegistry.h, AEObjects.h ==="
+ input = ["AEDataModel.h", "AEInteraction.h", "AppleEvents.h", "AERegistry.h", "AEObjects.h"]
+ output = "aegen.py"
+ defsoutput = TOOLBOXDIR + "AppleEvents.py"
+ scanner = AppleEventsScanner(input, output, defsoutput)
+ scanner.scan()
+ scanner.close()
+ print "=== Testing definitions output code ==="
+ execfile(defsoutput, {}, {})
+ print "=== Done Scanning and Generating, now doing 'import aesupport' ==="
+ import aesupport
+ print "=== Done 'import aesupport'. It's up to you to compile AEmodule.c ==="
class AppleEventsScanner(Scanner):
- def destination(self, type, name, arglist):
- classname = "AEFunction"
- listname = "functions"
- if arglist:
- t, n, m = arglist[0]
- if t[-4:] == "_ptr" and m == "InMode" and \
- t[:-4] in ("AEDesc", "AEAddressDesc", "AEDescList",
- "AERecord", "AppleEvent"):
- classname = "AEMethod"
- listname = "aedescmethods"
- return classname, listname
-
- def makeblacklistnames(self):
- return [
- "AEDisposeDesc",
-# "AEGetEventHandler",
- "AEGetDescData", # Use object.data
- "AEGetSpecialHandler",
- # Constants with funny definitions
- "kAEDontDisposeOnResume",
- "kAEUseStandardDispatch",
- ]
-
- def makeblacklisttypes(self):
- return [
- "ProcPtr",
- "AEArrayType",
- "AECoercionHandlerUPP",
- "UniversalProcPtr",
- "OSLCompareUPP",
- "OSLAccessorUPP",
- ]
-
- def makerepairinstructions(self):
- return [
- ([("Boolean", "isSysHandler", "InMode")],
- [("AlwaysFalse", "*", "*")]),
-
- ([("void_ptr", "*", "InMode"), ("Size", "*", "InMode")],
- [("InBuffer", "*", "*")]),
-
- ([("EventHandlerProcPtr", "*", "InMode"), ("long", "*", "InMode")],
- [("EventHandler", "*", "*")]),
-
- ([("EventHandlerProcPtr", "*", "OutMode"), ("long", "*", "OutMode")],
- [("EventHandler", "*", "*")]),
-
- ([("AEEventHandlerUPP", "*", "InMode"), ("long", "*", "InMode")],
- [("EventHandler", "*", "*")]),
-
- ([("AEEventHandlerUPP", "*", "OutMode"), ("long", "*", "OutMode")],
- [("EventHandler", "*", "*")]),
-
- ([("void", "*", "OutMode"), ("Size", "*", "InMode"),
- ("Size", "*", "OutMode")],
- [("VarVarOutBuffer", "*", "InOutMode")]),
-
- ([("AppleEvent", "theAppleEvent", "OutMode")],
- [("AppleEvent_ptr", "*", "InMode")]),
-
- ([("AEDescList", "theAEDescList", "OutMode")],
- [("AEDescList_ptr", "*", "InMode")]),
- ]
-
- def writeinitialdefs(self):
- self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
+ def destination(self, type, name, arglist):
+ classname = "AEFunction"
+ listname = "functions"
+ if arglist:
+ t, n, m = arglist[0]
+ if t[-4:] == "_ptr" and m == "InMode" and \
+ t[:-4] in ("AEDesc", "AEAddressDesc", "AEDescList",
+ "AERecord", "AppleEvent"):
+ classname = "AEMethod"
+ listname = "aedescmethods"
+ return classname, listname
+
+ def makeblacklistnames(self):
+ return [
+ "AEDisposeDesc",
+# "AEGetEventHandler",
+ "AEGetDescData", # Use object.data
+ "AEGetSpecialHandler",
+ # Constants with funny definitions
+ "kAEDontDisposeOnResume",
+ "kAEUseStandardDispatch",
+ ]
+
+ def makeblacklisttypes(self):
+ return [
+ "ProcPtr",
+ "AEArrayType",
+ "AECoercionHandlerUPP",
+ "UniversalProcPtr",
+ "OSLCompareUPP",
+ "OSLAccessorUPP",
+ ]
+
+ def makerepairinstructions(self):
+ return [
+ ([("Boolean", "isSysHandler", "InMode")],
+ [("AlwaysFalse", "*", "*")]),
+
+ ([("void_ptr", "*", "InMode"), ("Size", "*", "InMode")],
+ [("InBuffer", "*", "*")]),
+
+ ([("EventHandlerProcPtr", "*", "InMode"), ("long", "*", "InMode")],
+ [("EventHandler", "*", "*")]),
+
+ ([("EventHandlerProcPtr", "*", "OutMode"), ("long", "*", "OutMode")],
+ [("EventHandler", "*", "*")]),
+
+ ([("AEEventHandlerUPP", "*", "InMode"), ("long", "*", "InMode")],
+ [("EventHandler", "*", "*")]),
+
+ ([("AEEventHandlerUPP", "*", "OutMode"), ("long", "*", "OutMode")],
+ [("EventHandler", "*", "*")]),
+
+ ([("void", "*", "OutMode"), ("Size", "*", "InMode"),
+ ("Size", "*", "OutMode")],
+ [("VarVarOutBuffer", "*", "InOutMode")]),
+
+ ([("AppleEvent", "theAppleEvent", "OutMode")],
+ [("AppleEvent_ptr", "*", "InMode")]),
+
+ ([("AEDescList", "theAEDescList", "OutMode")],
+ [("AEDescList_ptr", "*", "InMode")]),
+ ]
+
+ def writeinitialdefs(self):
+ self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
if __name__ == "__main__":
- main()
+ main()
diff --git a/Mac/Modules/ae/aesupport.py b/Mac/Modules/ae/aesupport.py
index 17184db..91c5b82 100644
--- a/Mac/Modules/ae/aesupport.py
+++ b/Mac/Modules/ae/aesupport.py
@@ -39,29 +39,29 @@ AppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc')
class EHType(Type):
- def __init__(self, name = 'EventHandler', format = ''):
- Type.__init__(self, name, format)
- def declare(self, name):
- Output("AEEventHandlerUPP %s__proc__ = upp_GenericEventHandler;", name)
- Output("PyObject *%s;", name)
- def getargsFormat(self):
- return "O"
- def getargsArgs(self, name):
- return "&%s" % name
- def passInput(self, name):
- return "%s__proc__, (long)%s" % (name, name)
- def passOutput(self, name):
- return "&%s__proc__, (long *)&%s" % (name, name)
- def mkvalueFormat(self):
- return "O"
- def mkvalueArgs(self, name):
- return name
- def cleanup(self, name):
- Output("Py_INCREF(%s); /* XXX leak, but needed */", name)
+ def __init__(self, name = 'EventHandler', format = ''):
+ Type.__init__(self, name, format)
+ def declare(self, name):
+ Output("AEEventHandlerUPP %s__proc__ = upp_GenericEventHandler;", name)
+ Output("PyObject *%s;", name)
+ def getargsFormat(self):
+ return "O"
+ def getargsArgs(self, name):
+ return "&%s" % name
+ def passInput(self, name):
+ return "%s__proc__, (long)%s" % (name, name)
+ def passOutput(self, name):
+ return "&%s__proc__, (long *)&%s" % (name, name)
+ def mkvalueFormat(self):
+ return "O"
+ def mkvalueArgs(self, name):
+ return name
+ def cleanup(self, name):
+ Output("Py_INCREF(%s); /* XXX leak, but needed */", name)
class EHNoRefConType(EHType):
- def passInput(self, name):
- return "upp_GenericEventHandler"
+ def passInput(self, name):
+ return "upp_GenericEventHandler"
EventHandler = EHType()
EventHandlerNoRefCon = EHNoRefConType()
@@ -101,9 +101,9 @@ AEEventHandlerUPP upp_GenericEventHandler;
static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn)
{
- if ( PyOS_InterruptOccurred() )
- return 1;
- return 0;
+ if ( PyOS_InterruptOccurred() )
+ return 1;
+ return 0;
}
AEIdleUPP upp_AEIdleProc;
@@ -113,99 +113,99 @@ finalstuff = finalstuff + """
static pascal OSErr
GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon)
{
- PyObject *handler = (PyObject *)refcon;
- AEDescObject *requestObject, *replyObject;
- PyObject *args, *res;
- if ((requestObject = (AEDescObject *)AEDesc_New((AppleEvent *)request)) == NULL) {
- return -1;
- }
- if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) {
- Py_DECREF(requestObject);
- return -1;
- }
- if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) {
- Py_DECREF(requestObject);
- Py_DECREF(replyObject);
- return -1;
- }
- res = PyEval_CallObject(handler, args);
- requestObject->ob_itself.descriptorType = 'null';
- requestObject->ob_itself.dataHandle = NULL;
- replyObject->ob_itself.descriptorType = 'null';
- replyObject->ob_itself.dataHandle = NULL;
- Py_DECREF(args);
- if (res == NULL) {
- PySys_WriteStderr("Exception in AE event handler function\\n");
- PyErr_Print();
- return -1;
- }
- Py_DECREF(res);
- return noErr;
+ PyObject *handler = (PyObject *)refcon;
+ AEDescObject *requestObject, *replyObject;
+ PyObject *args, *res;
+ if ((requestObject = (AEDescObject *)AEDesc_New((AppleEvent *)request)) == NULL) {
+ return -1;
+ }
+ if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) {
+ Py_DECREF(requestObject);
+ return -1;
+ }
+ if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) {
+ Py_DECREF(requestObject);
+ Py_DECREF(replyObject);
+ return -1;
+ }
+ res = PyEval_CallObject(handler, args);
+ requestObject->ob_itself.descriptorType = 'null';
+ requestObject->ob_itself.dataHandle = NULL;
+ replyObject->ob_itself.descriptorType = 'null';
+ replyObject->ob_itself.dataHandle = NULL;
+ Py_DECREF(args);
+ if (res == NULL) {
+ PySys_WriteStderr("Exception in AE event handler function\\n");
+ PyErr_Print();
+ return -1;
+ }
+ Py_DECREF(res);
+ return noErr;
}
PyObject *AEDesc_NewBorrowed(AEDesc *itself)
{
- PyObject *it;
-
- it = AEDesc_New(itself);
- if (it)
- ((AEDescObject *)it)->ob_owned = 0;
- return (PyObject *)it;
+ PyObject *it;
+
+ it = AEDesc_New(itself);
+ if (it)
+ ((AEDescObject *)it)->ob_owned = 0;
+ return (PyObject *)it;
}
"""
initstuff = initstuff + """
- upp_AEIdleProc = NewAEIdleUPP(AEIdleProc);
- upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler);
- PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New);
- PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_NewBorrowed);
- PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);
+ upp_AEIdleProc = NewAEIdleUPP(AEIdleProc);
+ upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_NewBorrowed);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);
"""
module = MacModule('_AE', 'AE', includestuff, finalstuff, initstuff)
class AEDescDefinition(PEP253Mixin, GlobalObjectDefinition):
- getsetlist = [(
- 'type',
- 'return PyMac_BuildOSType(self->ob_itself.descriptorType);',
- None,
- 'Type of this AEDesc'
- ), (
- 'data',
- """
- PyObject *res;
- Size size;
- char *ptr;
- OSErr err;
-
- size = AEGetDescDataSize(&self->ob_itself);
- if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
- return NULL;
- if ( (ptr = PyString_AsString(res)) == NULL )
- return NULL;
- if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
- return PyMac_Error(err);
- return res;
- """,
- None,
- 'The raw data in this AEDesc'
- )]
-
- def __init__(self, name, prefix = None, itselftype = None):
- GlobalObjectDefinition.__init__(self, name, prefix or name, itselftype or name)
- self.argref = "*"
-
- def outputStructMembers(self):
- GlobalObjectDefinition.outputStructMembers(self)
- Output("int ob_owned;")
-
- def outputInitStructMembers(self):
- GlobalObjectDefinition.outputInitStructMembers(self)
- Output("it->ob_owned = 1;")
-
- def outputCleanupStructMembers(self):
- Output("if (self->ob_owned) AEDisposeDesc(&self->ob_itself);")
+ getsetlist = [(
+ 'type',
+ 'return PyMac_BuildOSType(self->ob_itself.descriptorType);',
+ None,
+ 'Type of this AEDesc'
+ ), (
+ 'data',
+ """
+ PyObject *res;
+ Size size;
+ char *ptr;
+ OSErr err;
+
+ size = AEGetDescDataSize(&self->ob_itself);
+ if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
+ return NULL;
+ if ( (ptr = PyString_AsString(res)) == NULL )
+ return NULL;
+ if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
+ return PyMac_Error(err);
+ return res;
+ """,
+ None,
+ 'The raw data in this AEDesc'
+ )]
+
+ def __init__(self, name, prefix = None, itselftype = None):
+ GlobalObjectDefinition.__init__(self, name, prefix or name, itselftype or name)
+ self.argref = "*"
+
+ def outputStructMembers(self):
+ GlobalObjectDefinition.outputStructMembers(self)
+ Output("int ob_owned;")
+
+ def outputInitStructMembers(self):
+ GlobalObjectDefinition.outputInitStructMembers(self)
+ Output("it->ob_owned = 1;")
+
+ def outputCleanupStructMembers(self):
+ Output("if (self->ob_owned) AEDisposeDesc(&self->ob_itself);")
aedescobject = AEDescDefinition('AEDesc')
module.addobject(aedescobject)
diff --git a/Mac/Modules/ah/ahscan.py b/Mac/Modules/ah/ahscan.py
index cced19f..0b7fe08 100644
--- a/Mac/Modules/ah/ahscan.py
+++ b/Mac/Modules/ah/ahscan.py
@@ -11,42 +11,42 @@ SHORT = "ah"
OBJECT = "NOTUSED"
def main():
- input = LONG + ".h"
- output = SHORT + "gen.py"
- defsoutput = TOOLBOXDIR + LONG + ".py"
- scanner = MyScanner(input, output, defsoutput)
- scanner.scan()
- scanner.close()
- print "=== Testing definitions output code ==="
- execfile(defsoutput, {}, {})
- print "=== Done scanning and generating, now importing the generated code... ==="
- exec "import " + SHORT + "support"
- print "=== Done. It's up to you to compile it now! ==="
+ input = LONG + ".h"
+ output = SHORT + "gen.py"
+ defsoutput = TOOLBOXDIR + LONG + ".py"
+ scanner = MyScanner(input, output, defsoutput)
+ scanner.scan()
+ scanner.close()
+ print "=== Testing definitions output code ==="
+ execfile(defsoutput, {}, {})
+ print "=== Done scanning and generating, now importing the generated code... ==="
+ exec "import " + SHORT + "support"
+ print "=== Done. It's up to you to compile it now! ==="
class MyScanner(Scanner_OSX):
- def destination(self, type, name, arglist):
- classname = "Function"
- listname = "functions"
- if arglist:
- t, n, m = arglist[0]
- # This is non-functional today
- if t == OBJECT and m == "InMode":
- classname = "Method"
- listname = "methods"
- return classname, listname
-
- def makeblacklistnames(self):
- return [
- ]
-
- def makeblacklisttypes(self):
- return [
- ]
-
- def makerepairinstructions(self):
- return [
- ]
-
+ def destination(self, type, name, arglist):
+ classname = "Function"
+ listname = "functions"
+ if arglist:
+ t, n, m = arglist[0]
+ # This is non-functional today
+ if t == OBJECT and m == "InMode":
+ classname = "Method"
+ listname = "methods"
+ return classname, listname
+
+ def makeblacklistnames(self):
+ return [
+ ]
+
+ def makeblacklisttypes(self):
+ return [
+ ]
+
+ def makerepairinstructions(self):
+ return [
+ ]
+
if __name__ == "__main__":
- main()
+ main()
diff --git a/Mac/Modules/ah/ahsupport.py b/Mac/Modules/ah/ahsupport.py
index c91c298..c5f24be 100644
--- a/Mac/Modules/ah/ahsupport.py
+++ b/Mac/Modules/ah/ahsupport.py
@@ -6,13 +6,13 @@
import string
# Declarations that change for each manager
-MACHEADERFILE = 'AppleHelp.h' # The Apple header file
-MODNAME = '_AH' # The name of the module
+MACHEADERFILE = 'AppleHelp.h' # The Apple header file
+MODNAME = '_AH' # The name of the module
# The following is *usually* unchanged but may still require tuning
-MODPREFIX = 'Ah' # The prefix for module-wide routines
+MODPREFIX = 'Ah' # The prefix for module-wide routines
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
-OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
+OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
from macsupport import *
@@ -43,4 +43,3 @@ for f in functions: module.add(f)
# generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE)
module.generate()
-
diff --git a/Mac/Modules/app/appscan.py b/Mac/Modules/app/appscan.py
index 822651d..1b04859 100644
--- a/Mac/Modules/app/appscan.py
+++ b/Mac/Modules/app/appscan.py
@@ -11,71 +11,71 @@ SHORT = "app"
OBJECT = "ThemeDrawingState"
def main():
- input = LONG + ".h"
- output = SHORT + "gen.py"
- defsoutput = TOOLBOXDIR + LONG + ".py"
- scanner = MyScanner(input, output, defsoutput)
- scanner.scan()
- scanner.close()
- print "=== Testing definitions output code ==="
- execfile(defsoutput, {}, {})
- print "=== Done scanning and generating, now importing the generated code... ==="
- exec "import " + SHORT + "support"
- print "=== Done. It's up to you to compile it now! ==="
+ input = LONG + ".h"
+ output = SHORT + "gen.py"
+ defsoutput = TOOLBOXDIR + LONG + ".py"
+ scanner = MyScanner(input, output, defsoutput)
+ scanner.scan()
+ scanner.close()
+ print "=== Testing definitions output code ==="
+ execfile(defsoutput, {}, {})
+ print "=== Done scanning and generating, now importing the generated code... ==="
+ exec "import " + SHORT + "support"
+ print "=== Done. It's up to you to compile it now! ==="
class MyScanner(Scanner):
- def destination(self, type, name, arglist):
- classname = "Function"
- listname = "functions"
- if arglist:
- t, n, m = arglist[0]
- # This is non-functional today
- if t == OBJECT and m == "InMode":
- classname = "Method"
- listname = "methods"
- return classname, listname
+ def destination(self, type, name, arglist):
+ classname = "Function"
+ listname = "functions"
+ if arglist:
+ t, n, m = arglist[0]
+ # This is non-functional today
+ if t == OBJECT and m == "InMode":
+ classname = "Method"
+ listname = "methods"
+ return classname, listname
- def writeinitialdefs(self):
- self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
+ def writeinitialdefs(self):
+ self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
- def makeblacklistnames(self):
- return [
- "GetThemeFont", # Funny stringbuffer in/out parameter, I think...
- # Constants with funny definitions
- "appearanceBadBrushIndexErr",
- "appearanceProcessRegisteredErr",
- "appearanceProcessNotRegisteredErr",
- "appearanceBadTextColorIndexErr",
- "appearanceThemeHasNoAccents",
- "appearanceBadCursorIndexErr",
- ]
+ def makeblacklistnames(self):
+ return [
+ "GetThemeFont", # Funny stringbuffer in/out parameter, I think...
+ # Constants with funny definitions
+ "appearanceBadBrushIndexErr",
+ "appearanceProcessRegisteredErr",
+ "appearanceProcessNotRegisteredErr",
+ "appearanceBadTextColorIndexErr",
+ "appearanceThemeHasNoAccents",
+ "appearanceBadCursorIndexErr",
+ ]
- def makeblacklisttypes(self):
- return [
- "MenuTitleDrawingUPP",
- "MenuItemDrawingUPP",
- "ThemeIteratorUPP",
- "ThemeTabTitleDrawUPP",
-# "ThemeEraseUPP",
-# "ThemeButtonDrawUPP",
- "WindowTitleDrawingUPP",
- "ProcessSerialNumber_ptr", # Too much work for now.
- "ThemeTrackDrawInfo_ptr", # Too much work
-# "ThemeButtonDrawInfo_ptr", # ditto
- "ThemeWindowMetrics_ptr", # ditto
-# "ThemeDrawingState", # This is an opaque pointer, so it should be simple. Later.
- "Collection", # No interface to collection mgr yet.
- "BytePtr", # Not yet.
- ]
+ def makeblacklisttypes(self):
+ return [
+ "MenuTitleDrawingUPP",
+ "MenuItemDrawingUPP",
+ "ThemeIteratorUPP",
+ "ThemeTabTitleDrawUPP",
+# "ThemeEraseUPP",
+# "ThemeButtonDrawUPP",
+ "WindowTitleDrawingUPP",
+ "ProcessSerialNumber_ptr", # Too much work for now.
+ "ThemeTrackDrawInfo_ptr", # Too much work
+# "ThemeButtonDrawInfo_ptr", # ditto
+ "ThemeWindowMetrics_ptr", # ditto
+# "ThemeDrawingState", # This is an opaque pointer, so it should be simple. Later.
+ "Collection", # No interface to collection mgr yet.
+ "BytePtr", # Not yet.
+ ]
+
+ def makerepairinstructions(self):
+ return [
+ ([("void", 'inContext', "OutMode")],
+ [("NULL", 'inContext', "InMode")]),
+ ([("Point", 'ioBounds', "OutMode")],
+ [("Point", 'ioBounds', "InOutMode")]),
+ ]
- def makerepairinstructions(self):
- return [
- ([("void", 'inContext', "OutMode")],
- [("NULL", 'inContext', "InMode")]),
- ([("Point", 'ioBounds', "OutMode")],
- [("Point", 'ioBounds', "InOutMode")]),
- ]
-
if __name__ == "__main__":
- main()
+ main()
diff --git a/Mac/Modules/app/appsupport.py b/Mac/Modules/app/appsupport.py
index a9d8768..177dfd5 100644
--- a/Mac/Modules/app/appsupport.py
+++ b/Mac/Modules/app/appsupport.py
@@ -6,17 +6,17 @@
import string
# Declarations that change for each manager
-MACHEADERFILE = 'Appearance.h' # The Apple header file
-MODNAME = '_App' # The name of the module
-OBJECTNAME = 'ThemeDrawingState' # The basic name of the objects used here
-KIND = '' # Usually 'Ptr' or 'Handle'
+MACHEADERFILE = 'Appearance.h' # The Apple header file
+MODNAME = '_App' # The name of the module
+OBJECTNAME = 'ThemeDrawingState' # The basic name of the objects used here
+KIND = '' # Usually 'Ptr' or 'Handle'
# The following is *usually* unchanged but may still require tuning
-MODPREFIX = 'App' # The prefix for module-wide routines
-OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
-OBJECTPREFIX = OBJECTNAME + 'Obj' # The prefix for object methods
+MODPREFIX = 'App' # The prefix for module-wide routines
+OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
+OBJECTPREFIX = OBJECTNAME + 'Obj' # The prefix for object methods
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
-OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
+OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
from macsupport import *
@@ -84,24 +84,24 @@ includestuff = includestuff + """
int ThemeButtonDrawInfo_Convert(PyObject *v, ThemeButtonDrawInfo *p_itself)
{
- return PyArg_Parse(v, "(iHH)", &p_itself->state, &p_itself->value, &p_itself->adornment);
+ return PyArg_Parse(v, "(iHH)", &p_itself->state, &p_itself->value, &p_itself->adornment);
}
"""
class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
- pass
-## def outputCheckNewArg(self):
-## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
-## def outputCheckConvertArg(self):
-## OutLbrace("if (DlgObj_Check(v))")
-## Output("*p_itself = ((WindowObject *)v)->ob_itself;")
-## Output("return 1;")
-## OutRbrace()
-## Out("""
-## if (v == Py_None) { *p_itself = NULL; return 1; }
-## if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
-## """)
+ pass
+## def outputCheckNewArg(self):
+## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+## def outputCheckConvertArg(self):
+## OutLbrace("if (DlgObj_Check(v))")
+## Output("*p_itself = ((WindowObject *)v)->ob_itself;")
+## Output("return 1;")
+## OutRbrace()
+## Out("""
+## if (v == Py_None) { *p_itself = NULL; return 1; }
+## if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
+## """)
# From here on it's basically all boiler plate...
@@ -131,4 +131,3 @@ for f in methods: object.add(f)
# generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE)
module.generate()
-
diff --git a/Mac/Modules/carbonevt/CarbonEvtscan.py b/Mac/Modules/carbonevt/CarbonEvtscan.py
index c6bf93f..e3c72ae 100644
--- a/Mac/Modules/carbonevt/CarbonEvtscan.py
+++ b/Mac/Modules/carbonevt/CarbonEvtscan.py
@@ -12,106 +12,106 @@ sys.path.append(BGENDIR)
from scantools import Scanner, Scanner_OSX
def main():
- print "---Scanning CarbonEvents.h---"
- input = ["CarbonEvents.h"]
- output = "CarbonEventsgen.py"
- defsoutput = TOOLBOXDIR + "CarbonEvents.py"
- scanner = CarbonEvents_Scanner(input, output, defsoutput)
- scanner.scan()
- scanner.close()
- print "=== Testing definitions output code ==="
- execfile(defsoutput, {}, {})
- print "--done scanning, importing--"
- import CarbonEvtsupport
- print "done"
+ print "---Scanning CarbonEvents.h---"
+ input = ["CarbonEvents.h"]
+ output = "CarbonEventsgen.py"
+ defsoutput = TOOLBOXDIR + "CarbonEvents.py"
+ scanner = CarbonEvents_Scanner(input, output, defsoutput)
+ scanner.scan()
+ scanner.close()
+ print "=== Testing definitions output code ==="
+ execfile(defsoutput, {}, {})
+ print "--done scanning, importing--"
+ import CarbonEvtsupport
+ print "done"
-RefObjectTypes = ["EventRef",
- "EventQueueRef",
- "EventLoopRef",
- "EventLoopTimerRef",
- "EventHandlerRef",
- "EventHandlerCallRef",
- "EventTargetRef",
- "EventHotKeyRef",
- ]
+RefObjectTypes = ["EventRef",
+ "EventQueueRef",
+ "EventLoopRef",
+ "EventLoopTimerRef",
+ "EventHandlerRef",
+ "EventHandlerCallRef",
+ "EventTargetRef",
+ "EventHotKeyRef",
+ ]
class CarbonEvents_Scanner(Scanner_OSX):
- def destination(self, type, name, arglist):
- classname = "CarbonEventsFunction"
- listname = "functions"
- if arglist:
- t, n, m = arglist[0]
- if t in RefObjectTypes and m == "InMode":
- if t == "EventHandlerRef":
- classname = "EventHandlerRefMethod"
- else:
- classname = "CarbonEventsMethod"
- listname = t + "methods"
- #else:
- # print "not method"
- return classname, listname
+ def destination(self, type, name, arglist):
+ classname = "CarbonEventsFunction"
+ listname = "functions"
+ if arglist:
+ t, n, m = arglist[0]
+ if t in RefObjectTypes and m == "InMode":
+ if t == "EventHandlerRef":
+ classname = "EventHandlerRefMethod"
+ else:
+ classname = "CarbonEventsMethod"
+ listname = t + "methods"
+ #else:
+ # print "not method"
+ return classname, listname
- def writeinitialdefs(self):
- self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
- self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
- self.defsfile.write("false = 0\n")
- self.defsfile.write("true = 1\n")
- self.defsfile.write("keyAEEventClass = FOUR_CHAR_CODE('evcl')\n")
- self.defsfile.write("keyAEEventID = FOUR_CHAR_CODE('evti')\n")
-
- def makeblacklistnames(self):
- return [
- "sHandler",
- "MacCreateEvent",
-# "TrackMouseLocationWithOptions",
-# "TrackMouseLocation",
-# "TrackMouseRegion",
- "RegisterToolboxObjectClass",
- "UnregisterToolboxObjectClass",
- "ProcessHICommand",
- "GetCFRunLoopFromEventLoop",
-
- "InvokeEventHandlerUPP",
- "InvokeEventComparatorUPP",
- "InvokeEventLoopTimerUPP",
- "NewEventComparatorUPP",
- "NewEventLoopTimerUPP",
- "NewEventHandlerUPP",
- "DisposeEventComparatorUPP",
- "DisposeEventLoopTimerUPP",
- "DisposeEventHandlerUPP",
+ def writeinitialdefs(self):
+ self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
+ self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
+ self.defsfile.write("false = 0\n")
+ self.defsfile.write("true = 1\n")
+ self.defsfile.write("keyAEEventClass = FOUR_CHAR_CODE('evcl')\n")
+ self.defsfile.write("keyAEEventID = FOUR_CHAR_CODE('evti')\n")
- # Wrote by hand
- "InstallEventHandler",
- "RemoveEventHandler",
-
- # Write by hand?
- "GetEventParameter",
- "FlushSpecificEventsFromQueue",
- "FindSpecificEventInQueue",
- "InstallEventLoopTimer",
+ def makeblacklistnames(self):
+ return [
+ "sHandler",
+ "MacCreateEvent",
+# "TrackMouseLocationWithOptions",
+# "TrackMouseLocation",
+# "TrackMouseRegion",
+ "RegisterToolboxObjectClass",
+ "UnregisterToolboxObjectClass",
+ "ProcessHICommand",
+ "GetCFRunLoopFromEventLoop",
- # Don't do these because they require a CFRelease
- "CreateTypeStringWithOSType",
- "CopyEvent",
- ]
+ "InvokeEventHandlerUPP",
+ "InvokeEventComparatorUPP",
+ "InvokeEventLoopTimerUPP",
+ "NewEventComparatorUPP",
+ "NewEventLoopTimerUPP",
+ "NewEventHandlerUPP",
+ "DisposeEventComparatorUPP",
+ "DisposeEventLoopTimerUPP",
+ "DisposeEventHandlerUPP",
-# def makeblacklisttypes(self):
-# return ["EventComparatorUPP",
-# "EventLoopTimerUPP",
-# #"EventHandlerUPP",
-# "EventComparatorProcPtr",
-# "EventLoopTimerProcPtr",
-# "EventHandlerProcPtr",
-# ]
+ # Wrote by hand
+ "InstallEventHandler",
+ "RemoveEventHandler",
- def makerepairinstructions(self):
- return [
- ([("UInt32", 'inSize', "InMode"), ("void_ptr", 'inDataPtr', "InMode")],
- [("MyInBuffer", 'inDataPtr', "InMode")]),
- ([("Boolean", 'ioWasInRgn', "OutMode")],
- [("Boolean", 'ioWasInRgn', "InOutMode")]),
- ]
+ # Write by hand?
+ "GetEventParameter",
+ "FlushSpecificEventsFromQueue",
+ "FindSpecificEventInQueue",
+ "InstallEventLoopTimer",
+
+ # Don't do these because they require a CFRelease
+ "CreateTypeStringWithOSType",
+ "CopyEvent",
+ ]
+
+# def makeblacklisttypes(self):
+# return ["EventComparatorUPP",
+# "EventLoopTimerUPP",
+# #"EventHandlerUPP",
+# "EventComparatorProcPtr",
+# "EventLoopTimerProcPtr",
+# "EventHandlerProcPtr",
+# ]
+
+ def makerepairinstructions(self):
+ return [
+ ([("UInt32", 'inSize', "InMode"), ("void_ptr", 'inDataPtr', "InMode")],
+ [("MyInBuffer", 'inDataPtr', "InMode")]),
+ ([("Boolean", 'ioWasInRgn', "OutMode")],
+ [("Boolean", 'ioWasInRgn', "InOutMode")]),
+ ]
if __name__ == "__main__":
- main()
+ main()
diff --git a/Mac/Modules/carbonevt/CarbonEvtsupport.py b/Mac/Modules/carbonevt/CarbonEvtsupport.py
index 3cc1672..77d12b6 100644
--- a/Mac/Modules/carbonevt/CarbonEvtsupport.py
+++ b/Mac/Modules/carbonevt/CarbonEvtsupport.py
@@ -8,23 +8,23 @@ from CarbonEvtscan import RefObjectTypes
CFStringRef = OpaqueByValueType('CFStringRef')
for typ in RefObjectTypes:
- execstr = "%(name)s = OpaqueByValueType('%(name)s')" % {"name": typ}
- exec execstr
+ execstr = "%(name)s = OpaqueByValueType('%(name)s')" % {"name": typ}
+ exec execstr
if 0:
- # these types will have no methods and will merely be opaque blobs
- # should write getattr and setattr for them?
+ # these types will have no methods and will merely be opaque blobs
+ # should write getattr and setattr for them?
- StructObjectTypes = ["EventTypeSpec",
- "HIPoint",
- "HICommand",
- "EventHotKeyID",
- ]
+ StructObjectTypes = ["EventTypeSpec",
+ "HIPoint",
+ "HICommand",
+ "EventHotKeyID",
+ ]
- for typ in StructObjectTypes:
- execstr = "%(name)s = OpaqueType('%(name)s')" % {"name": typ}
- exec execstr
+ for typ in StructObjectTypes:
+ execstr = "%(name)s = OpaqueType('%(name)s')" % {"name": typ}
+ exec execstr
EventHotKeyID = OpaqueByValueType("EventHotKeyID", "EventHotKeyID")
EventTypeSpec_ptr = OpaqueType("EventTypeSpec", "EventTypeSpec")
@@ -35,10 +35,10 @@ void_ptr = stringptr
# here are some types that are really other types
class MyVarInputBufferType(VarInputBufferType):
- def passInput(self, name):
- return "%s__len__, %s__in__" % (name, name)
+ def passInput(self, name):
+ return "%s__len__, %s__in__" % (name, name)
-MyInBuffer = MyVarInputBufferType('char', 'long', 'l') # (buf, len)
+MyInBuffer = MyVarInputBufferType('char', 'long', 'l') # (buf, len)
EventTime = double
EventTimeout = EventTime
@@ -61,11 +61,11 @@ CarbonEventsFunction = OSErrFunctionGenerator
CarbonEventsMethod = OSErrMethodGenerator
class EventHandlerRefMethod(OSErrMethodGenerator):
- def precheck(self):
- OutLbrace('if (_self->ob_itself == NULL)')
- Output('PyErr_SetString(CarbonEvents_Error, "Handler has been removed");')
- Output('return NULL;')
- OutRbrace()
+ def precheck(self):
+ OutLbrace('if (_self->ob_itself == NULL)')
+ Output('PyErr_SetString(CarbonEvents_Error, "Handler has been removed");')
+ Output('return NULL;')
+ OutRbrace()
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
@@ -89,17 +89,17 @@ PyObject *EventRef_New(EventRef itself);
static PyObject*
EventTypeSpec_New(EventTypeSpec *in)
{
- return Py_BuildValue("ll", in->eventClass, in->eventKind);
+ return Py_BuildValue("ll", in->eventClass, in->eventKind);
}
static int
EventTypeSpec_Convert(PyObject *v, EventTypeSpec *out)
{
- if (PyArg_Parse(v, "(O&l)",
- PyMac_GetOSType, &(out->eventClass),
- &(out->eventKind)))
- return 1;
- return NULL;
+ if (PyArg_Parse(v, "(O&l)",
+ PyMac_GetOSType, &(out->eventClass),
+ &(out->eventKind)))
+ return 1;
+ return NULL;
}
/********** end EventTypeSpec *******/
@@ -110,15 +110,15 @@ EventTypeSpec_Convert(PyObject *v, EventTypeSpec *out)
static PyObject*
HIPoint_New(HIPoint *in)
{
- return Py_BuildValue("ff", in->x, in->y);
+ return Py_BuildValue("ff", in->x, in->y);
}
static int
HIPoint_Convert(PyObject *v, HIPoint *out)
{
- if (PyArg_ParseTuple(v, "ff", &(out->x), &(out->y)))
- return 1;
- return NULL;
+ if (PyArg_ParseTuple(v, "ff", &(out->x), &(out->y)))
+ return 1;
+ return NULL;
}
#endif
@@ -129,15 +129,15 @@ HIPoint_Convert(PyObject *v, HIPoint *out)
static PyObject*
EventHotKeyID_New(EventHotKeyID *in)
{
- return Py_BuildValue("ll", in->signature, in->id);
+ return Py_BuildValue("ll", in->signature, in->id);
}
static int
EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out)
{
- if (PyArg_ParseTuple(v, "ll", &out->signature, &out->id))
- return 1;
- return NULL;
+ if (PyArg_ParseTuple(v, "ll", &out->signature, &out->id))
+ return 1;
+ return NULL;
}
/********** end EventHotKeyID *******/
@@ -148,27 +148,27 @@ static EventHandlerUPP myEventHandlerUPP;
static pascal OSStatus
myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
- PyObject *retValue;
- int status;
-
- retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&",
- EventHandlerCallRef_New, handlerRef,
- EventRef_New, event);
- if (retValue == NULL) {
- PySys_WriteStderr("Error in event handler callback:\n");
- PyErr_Print(); /* this also clears the error */
- status = noErr; /* complain? how? */
- } else {
- if (retValue == Py_None)
- status = noErr;
- else if (PyInt_Check(retValue)) {
- status = PyInt_AsLong(retValue);
- } else
- status = noErr; /* wrong object type, complain? */
- Py_DECREF(retValue);
- }
-
- return status;
+ PyObject *retValue;
+ int status;
+
+ retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&",
+ EventHandlerCallRef_New, handlerRef,
+ EventRef_New, event);
+ if (retValue == NULL) {
+ PySys_WriteStderr("Error in event handler callback:\n");
+ PyErr_Print(); /* this also clears the error */
+ status = noErr; /* complain? how? */
+ } else {
+ if (retValue == Py_None)
+ status = noErr;
+ else if (PyInt_Check(retValue)) {
+ status = PyInt_AsLong(retValue);
+ } else
+ status = noErr; /* wrong object type, complain? */
+ Py_DECREF(retValue);
+ }
+
+ return status;
}
/******** end myEventHandler ***********/
@@ -184,56 +184,56 @@ module = MacModule('_CarbonEvt', 'CarbonEvents', includestuff, finalstuff, inits
class EventHandlerRefObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
- def outputStructMembers(self):
- Output("%s ob_itself;", self.itselftype)
- Output("PyObject *ob_callback;")
- def outputInitStructMembers(self):
- Output("it->ob_itself = %sitself;", self.argref)
- Output("it->ob_callback = NULL;")
- def outputFreeIt(self, name):
- OutLbrace("if (self->ob_itself != NULL)")
- Output("RemoveEventHandler(self->ob_itself);")
- Output("Py_DECREF(self->ob_callback);")
- OutRbrace()
-
+ def outputStructMembers(self):
+ Output("%s ob_itself;", self.itselftype)
+ Output("PyObject *ob_callback;")
+ def outputInitStructMembers(self):
+ Output("it->ob_itself = %sitself;", self.argref)
+ Output("it->ob_callback = NULL;")
+ def outputFreeIt(self, name):
+ OutLbrace("if (self->ob_itself != NULL)")
+ Output("RemoveEventHandler(self->ob_itself);")
+ Output("Py_DECREF(self->ob_callback);")
+ OutRbrace()
+
class MyGlobalObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
- pass
+ pass
for typ in RefObjectTypes:
- if typ == 'EventHandlerRef':
- EventHandlerRefobject = EventHandlerRefObjectDefinition('EventHandlerRef')
- else:
- execstr = typ + 'object = MyGlobalObjectDefinition(typ)'
- exec execstr
- module.addobject(eval(typ + 'object'))
+ if typ == 'EventHandlerRef':
+ EventHandlerRefobject = EventHandlerRefObjectDefinition('EventHandlerRef')
+ else:
+ execstr = typ + 'object = MyGlobalObjectDefinition(typ)'
+ exec execstr
+ module.addobject(eval(typ + 'object'))
functions = []
for typ in RefObjectTypes: ## go thru all ObjectTypes as defined in CarbonEventsscan.py
- # initialize the lists for carbongen to fill
- execstr = typ + 'methods = []'
- exec execstr
+ # initialize the lists for carbongen to fill
+ execstr = typ + 'methods = []'
+ exec execstr
execfile('CarbonEventsgen.py')
-for f in functions: module.add(f) # add all the functions carboneventsgen put in the list
+for f in functions: module.add(f) # add all the functions carboneventsgen put in the list
-for typ in RefObjectTypes: ## go thru all ObjectTypes as defined in CarbonEventsscan.py
- methods = eval(typ + 'methods') ## get a reference to the method list from the main namespace
- obj = eval(typ + 'object') ## get a reference to the object
- for m in methods: obj.add(m) ## add each method in the list to the object
+for typ in RefObjectTypes: ## go thru all ObjectTypes as defined in CarbonEventsscan.py
+ methods = eval(typ + 'methods') ## get a reference to the method list from the main namespace
+ obj = eval(typ + 'object') ## get a reference to the object
+ for m in methods: obj.add(m) ## add each method in the list to the object
removeeventhandler = """
OSStatus _err;
if (_self->ob_itself == NULL) {
- PyErr_SetString(CarbonEvents_Error, "Handler has been removed");
- return NULL;
+ PyErr_SetString(CarbonEvents_Error, "Handler has been removed");
+ return NULL;
}
if (!PyArg_ParseTuple(_args, ""))
- return NULL;
+ return NULL;
_err = RemoveEventHandler(_self->ob_itself);
if (_err != noErr) return PyMac_Error(_err);
_self->ob_itself = NULL;
@@ -255,15 +255,15 @@ EventHandlerRef outRef;
OSStatus _err;
if (!PyArg_ParseTuple(_args, "O&O", EventTypeSpec_Convert, &inSpec, &callback))
- return NULL;
+ return NULL;
_err = InstallEventHandler(_self->ob_itself, myEventHandlerUPP, 1, &inSpec, (void *)callback, &outRef);
if (_err != noErr) return PyMac_Error(_err);
_res = EventHandlerRef_New(outRef);
if (_res != NULL) {
- ((EventHandlerRefObject*)_res)->ob_callback = callback;
- Py_INCREF(callback);
+ ((EventHandlerRefObject*)_res)->ob_callback = callback;
+ Py_INCREF(callback);
}
return _res;"""
diff --git a/Mac/Modules/cf/cfscan.py b/Mac/Modules/cf/cfscan.py