From 17448e24081eb713ac00d7bcb681f4f0d8abfcbf Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 30 Jan 1995 11:53:55 +0000 Subject: Committed a more or less working version. --- Mac/Demo/resources/copyres.py | 57 ++ Mac/Demo/resources/listres.py | 60 ++ Mac/Demo/sound/morse.py | 180 ++++++ Mac/Demo/sound/playaiff.py | 45 ++ Mac/Lib/Audio_mac.py | 108 ++++ Mac/Lib/audiodev.py | 241 ++++++++ Mac/Lib/test/aete.py | 402 +++++++++++++ Mac/Lib/test/tctl.py | 17 + Mac/Lib/test/tdlg.py | 15 + Mac/Lib/test/tmenu.py | 60 ++ Mac/Lib/test/tsnd.py | 18 + Mac/Lib/test/twin.py | 9 + Mac/Lib/toolbox/AppleEvents.py | 103 ++++ Mac/Lib/toolbox/Controls.py | 41 ++ Mac/Lib/toolbox/Dialogs.py | 20 + Mac/Lib/toolbox/Events.py | 49 ++ Mac/Lib/toolbox/Menus.py | 12 + Mac/Lib/toolbox/Resources.py | 12 + Mac/Lib/toolbox/Sound.py | 101 ++++ Mac/Lib/toolbox/Windows.py | 41 ++ Mac/Lib/toolbox/aetools.py | 296 +++++++++ Mac/Modules/ae/AEmodule.c | 1257 +++++++++++++++++++++++++++++++++++++++ Mac/Modules/ae/aegen.py | 314 ++++++++++ Mac/Modules/ae/aescan.py | 71 +++ Mac/Modules/ae/aesupport.py | 168 ++++++ Mac/Modules/ctl/Ctlmodule.c | 691 +++++++++++++++++++++ Mac/Modules/ctl/ctlgen.py | 172 ++++++ Mac/Modules/ctl/ctlscan.py | 60 ++ Mac/Modules/ctl/ctlsupport.py | 86 +++ Mac/Modules/dlg/Dlgmodule.c | 905 ++++++++++++++++++++++++++++ Mac/Modules/dlg/dlggen.py | 224 +++++++ Mac/Modules/dlg/dlgscan.py | 67 +++ Mac/Modules/dlg/dlgsupport.py | 121 ++++ Mac/Modules/evt/Evtmodule.c | 228 +++++++ Mac/Modules/evt/evtgen.py | 47 ++ Mac/Modules/evt/evtscan.py | 59 ++ Mac/Modules/evt/evtsupport.py | 74 +++ Mac/Modules/menu/Menumodule.c | 908 ++++++++++++++++++++++++++++ Mac/Modules/menu/menugen.py | 242 ++++++++ Mac/Modules/menu/menuscan.py | 53 ++ Mac/Modules/menu/menusupport.py | 55 ++ Mac/Modules/qd/Qdmodule.c | 168 ++++++ Mac/Modules/qd/qdedit.py | 29 + Mac/Modules/qd/qdsupport.py | 72 +++ Mac/Modules/res/Resmodule.c | 1256 ++++++++++++++++++++++++++++++++++++++ Mac/Modules/res/resgen.py | 271 +++++++++ Mac/Modules/res/resscan.py | 60 ++ Mac/Modules/res/ressupport.py | 77 +++ Mac/Modules/snd/Sndmodule.c | 786 ++++++++++++++++++++++++ Mac/Modules/snd/sndgen.py | 131 ++++ Mac/Modules/snd/sndscan.py | 84 +++ Mac/Modules/snd/sndsupport.py | 218 +++++++ Mac/Modules/win/Winmodule.c | 872 +++++++++++++++++++++++++++ Mac/Modules/win/wingen.py | 226 +++++++ Mac/Modules/win/winscan.py | 68 +++ Mac/Modules/win/winsupport.py | 103 ++++ 56 files changed, 12110 insertions(+) create mode 100644 Mac/Demo/resources/copyres.py create mode 100644 Mac/Demo/resources/listres.py create mode 100644 Mac/Demo/sound/morse.py create mode 100644 Mac/Demo/sound/playaiff.py create mode 100644 Mac/Lib/Audio_mac.py create mode 100644 Mac/Lib/audiodev.py create mode 100644 Mac/Lib/test/aete.py create mode 100644 Mac/Lib/test/tctl.py create mode 100644 Mac/Lib/test/tdlg.py create mode 100644 Mac/Lib/test/tmenu.py create mode 100644 Mac/Lib/test/tsnd.py create mode 100644 Mac/Lib/test/twin.py create mode 100644 Mac/Lib/toolbox/AppleEvents.py create mode 100644 Mac/Lib/toolbox/Controls.py create mode 100644 Mac/Lib/toolbox/Dialogs.py create mode 100644 Mac/Lib/toolbox/Events.py create mode 100644 Mac/Lib/toolbox/Menus.py create mode 100644 Mac/Lib/toolbox/Resources.py create mode 100644 Mac/Lib/toolbox/Sound.py create mode 100644 Mac/Lib/toolbox/Windows.py create mode 100644 Mac/Lib/toolbox/aetools.py create mode 100644 Mac/Modules/ae/AEmodule.c create mode 100644 Mac/Modules/ae/aegen.py create mode 100644 Mac/Modules/ae/aescan.py create mode 100644 Mac/Modules/ae/aesupport.py create mode 100644 Mac/Modules/ctl/Ctlmodule.c create mode 100644 Mac/Modules/ctl/ctlgen.py create mode 100644 Mac/Modules/ctl/ctlscan.py create mode 100644 Mac/Modules/ctl/ctlsupport.py create mode 100644 Mac/Modules/dlg/Dlgmodule.c create mode 100644 Mac/Modules/dlg/dlggen.py create mode 100644 Mac/Modules/dlg/dlgscan.py create mode 100644 Mac/Modules/dlg/dlgsupport.py create mode 100644 Mac/Modules/evt/Evtmodule.c create mode 100644 Mac/Modules/evt/evtgen.py create mode 100644 Mac/Modules/evt/evtscan.py create mode 100644 Mac/Modules/evt/evtsupport.py create mode 100644 Mac/Modules/menu/Menumodule.c create mode 100644 Mac/Modules/menu/menugen.py create mode 100644 Mac/Modules/menu/menuscan.py create mode 100644 Mac/Modules/menu/menusupport.py create mode 100644 Mac/Modules/qd/Qdmodule.c create mode 100644 Mac/Modules/qd/qdedit.py create mode 100644 Mac/Modules/qd/qdsupport.py create mode 100644 Mac/Modules/res/Resmodule.c create mode 100644 Mac/Modules/res/resgen.py create mode 100644 Mac/Modules/res/resscan.py create mode 100644 Mac/Modules/res/ressupport.py create mode 100644 Mac/Modules/snd/Sndmodule.c create mode 100644 Mac/Modules/snd/sndgen.py create mode 100644 Mac/Modules/snd/sndscan.py create mode 100644 Mac/Modules/snd/sndsupport.py create mode 100644 Mac/Modules/win/Winmodule.c create mode 100644 Mac/Modules/win/wingen.py create mode 100644 Mac/Modules/win/winscan.py create mode 100644 Mac/Modules/win/winsupport.py diff --git a/Mac/Demo/resources/copyres.py b/Mac/Demo/resources/copyres.py new file mode 100644 index 0000000..b401142 --- /dev/null +++ b/Mac/Demo/resources/copyres.py @@ -0,0 +1,57 @@ +from Res import * +from Resources import * +import MacOS + +READ = 1 +WRITE = 2 +smAllScripts = -3 + +def copyres(src, dst): + """Copy resource from src file to dst file.""" + + cur = CurResFile() + ctor, type = MacOS.GetCreatorAndType(src) + input = FSpOpenResFile(src, READ) + try: + FSpCreateResFile(dst, ctor, type, smAllScripts) + except: + raw_input("%s already exists... CR to write anyway! " % dst) + output = FSpOpenResFile(dst, WRITE) + UseResFile(input) + ntypes = Count1Types() + for itype in range(1, 1+ntypes): + type = Get1IndType(itype) + nresources = Count1Resources(type) + for ires in range(1, 1+nresources): + res = Get1IndResource(type, ires) + res.LoadResource() + id, type, name = res.GetResInfo() + size = res.SizeResource() + attrs = res.GetResAttrs() + print id, type, name, size, hex(attrs) + res.DetachResource() + UseResFile(output) + try: + res2 = Get1Resource(type, id) + except (RuntimeError, Res.Error), msg: + res2 = None + if res2: + print "Duplicate type+id, not copied" + print (res2.size, res2.data) + print res2.GetResInfo() + if res2.HomeResFile() == output: + 'OK' + elif res2.HomeResFile() == input: + 'BAD!' + else: + print 'Home:', res2.HomeResFile() + else: + res.AddResource(type, id, name) + #res.SetResAttrs(attrs) + res.WriteResource() + UseResFile(input) + UseResFile(cur) + CloseResFile(output) + CloseResFile(input) + +copyres('::python.¹.rsrc', '::foo.rsrc') diff --git a/Mac/Demo/resources/listres.py b/Mac/Demo/resources/listres.py new file mode 100644 index 0000000..a0b2423 --- /dev/null +++ b/Mac/Demo/resources/listres.py @@ -0,0 +1,60 @@ +# List all resources + +import Res +from Resources import * + +def list1resources(): + ntypes = Res.Count1Types() + for itype in range(1, 1+ntypes): + type = Res.Get1IndType(itype) + print "Type:", `type` + nresources = Res.Count1Resources(type) + for i in range(1, 1 + nresources): + Res.SetResLoad(0) + res = Res.Get1IndResource(type, i) + Res.SetResLoad(1) + info(res) + +def listresources(): + ntypes = Res.CountTypes() + for itype in range(1, 1+ntypes): + type = Res.GetIndType(itype) + print "Type:", `type` + nresources = Res.CountResources(type) + for i in range(1, 1 + nresources): + Res.SetResLoad(0) + res = Res.GetIndResource(type, i) + Res.SetResLoad(1) + info(res) + +def info(res): + print res.GetResInfo(), res.SizeResource(), decodeattrs(res.GetResAttrs()) + +attrnames = { + resChanged: 'Changed', + resPreload: 'Preload', + resProtected: 'Protected', + resLocked: 'Locked', + resPurgeable: 'Purgeable', + resSysHeap: 'SysHeap', +} + +def decodeattrs(attrs): + names = [] + for bit in range(16): + mask = 1<> 8) & 255) + chr(val & 255) + sinewave = sinewave + sample[:SAMPWIDTH] + nowave = '\0' * (n*SAMPWIDTH) + +mkwave(OCTAVE) + +class BufferedAudioDev: + def __init__(self, *args): + import audiodev + self._base = apply(audiodev.AudioDev, args) + self._buffer = [] + self._filled = 0 + self._addmethods(self._base, self._base.__class__) + def _addmethods(self, inst, cls): + for name in cls.__dict__.keys(): + if not hasattr(self, name): + try: + setattr(self, name, getattr(inst, name)) + except: + pass + for basecls in cls.__bases__: + self._addmethods(self, inst, basecls) + def writeframesraw(self, frames): + self._buffer.append(frames) + self._filled = self._filled + len(frames) + if self._filled >= QSIZE: + self.flush() + def wait(self): + self.flush() + self._base.wait() + def flush(self): + print 'flush: %d blocks, %d bytes' % (len(self._buffer), self._filled) + if self._buffer: + import string + self._base.writeframes(string.joinfields(self._buffer, '')) + self._buffer = [] + self._filled = 0 + +def main(args = sys.argv[1:]): + import getopt, string + try: + opts, args = getopt.getopt(args, 'o:p:') + except getopt.error: + sys.stderr.write('Usage ' + sys.argv[0] + + ' [ -o outfile ] [ args ] ...\n') + sys.exit(1) + dev = None + for o, a in opts: + if o == '-o': + import aifc + dev = aifc.open(a, 'w') + dev.setframerate(FRAMERATE) + dev.setsampwidth(SAMPWIDTH) + dev.setnchannels(1) + if o == '-p': + mkwave(string.atoi(a)) + if not dev: + dev = BufferedAudioDev() + dev.setoutrate(FRAMERATE) + dev.setsampwidth(SAMPWIDTH) + dev.setnchannels(1) + dev.close = dev.stop + if args: + line = string.join(args) + else: + line = sys.stdin.readline() + while line: + print line + mline = morse(line) + print mline + play(mline, dev) + if hasattr(dev, 'wait'): + dev.wait() + if not args: + line = sys.stdin.readline() + else: + line = '' + dev.close() + +# Convert a string to morse code with \001 between the characters in +# the string. +def morse(line): + res = '' + for c in line: + try: + res = res + morsetab[c] + '\001' + except KeyError: + pass + return res + +# Play a line of morse code. +def play(line, dev): + for c in line: + if c == '.': + sine(dev, DOT) + elif c == '-': + sine(dev, DAH) + else: + pause(dev, DAH) + pause(dev, DOT) + +def sine(dev, length): + dev.writeframesraw(sinewave*length) + +def pause(dev, length): + dev.writeframesraw(nowave*length) + +if __name__ == '__main__' or sys.argv[0] == __name__: + main() diff --git a/Mac/Demo/sound/playaiff.py b/Mac/Demo/sound/playaiff.py new file mode 100644 index 0000000..1022fc8 --- /dev/null +++ b/Mac/Demo/sound/playaiff.py @@ -0,0 +1,45 @@ +from Sound import * +import Snd + +import aifc, audioop + +fn = 'f:just samples:2ndbeat.aif' +af = aifc.open(fn, 'r') +print af.getparams() +print 'nframes =', af.getnframes() +print 'nchannels =', af.getnchannels() +print 'framerate =', af.getframerate() +nframes = min(af.getnframes(), 100000) +frames = af.readframes(nframes) +print 'len(frames) =', len(frames) +print repr(frames[:100]) +frames = audioop.add(frames, '\x80'*len(frames), 1) +print repr(frames[:100]) + +import struct + +header1 = struct.pack('llhhllbbl', + 0, + af.getnchannels(), + af.getframerate(),0, + 0, + 0, + 0xFF, + 60, + nframes) +print repr(header1) +header2 = struct.pack('llhlll', 0, 0, 0, 0, 0, 0) +header3 = struct.pack('hhlll', + af.getsampwidth()*8, + 0, + 0, + 0, + 0) +print repr(header3) +header = header1 + header2 + header3 + +buffer = header + frames + +chan = Snd.SndNewChannel(5,0x00C0) + +Snd.SndDoCommand(chan, (bufferCmd, 0, buffer), 0) diff --git a/Mac/Lib/Audio_mac.py b/Mac/Lib/Audio_mac.py new file mode 100644 index 0000000..373f16a --- /dev/null +++ b/Mac/Lib/Audio_mac.py @@ -0,0 +1,108 @@ +QSIZE = 100000 + +class Play_Audio_mac: + + def __init__(self): + self._chan = None + self._qsize = QSIZE + self._outrate = 22254 + self._sampwidth = 1 + self._nchannels = 1 + self._gc = [] + + def __del__(self): + self.stop() + + def wait(self): + import time + while self.getfilled(): + time.sleep(0.1) + self._chan = None + self._gc = [] + + def stop(self, quietNow = 1): + ##chan = self._chan + self._chan = None + ##chan.SndDisposeChannel(1) + self._gc = [] + + def setoutrate(self, outrate): + self._outrate = outrate + + def setsampwidth(self, sampwidth): + self._sampwidth = sampwidth + + def setnchannels(self, nchannels): + self._nchannels = nchannels + + def writeframes(self, data): + import time + from Sound import * + import struct + if not self._chan: + import Snd + self._chan = Snd.SndNewChannel(5, 0, self._callback) + nframes = len(data) / self._nchannels / self._sampwidth + if len(data) != nframes * self._nchannels * self._sampwidth: + raise ValueError, 'data is not a whole number of frames' + while self._gc and \ + self.getfilled() + nframes > \ + self._qsize / self._nchannels / self._sampwidth: + time.sleep(0.1) + if self._sampwidth == 1: + import audioop + data = audioop.add(data, '\x80'*len(data), 1) + h1 = struct.pack('llhhllbbl', + id(data)+12, + self._nchannels, + self._outrate, 0, + 0, + 0, + extSH, + 60, + nframes) + h2 = 22*'\0' + h3 = struct.pack('hhlll', + self._sampwidth*8, + 0, + 0, + 0, + 0) + header = h1+h2+h3 + self._gc.append((header, data)) + self._chan.SndDoCommand((bufferCmd, 0, header), 0) + self._chan.SndDoCommand((callBackCmd, 0, 0), 0) + + def _callback(self, *args): + del self._gc[0] + + def getfilled(self): + filled = 0 + for header, data in self._gc: + filled = filled + len(data) + return filled / self._nchannels / self._sampwidth + + def getfillable(self): + return self._qsize - self.getfilled() + + def ulaw2lin(self, data): + import audioop + return audioop.ulaw2lin(data, 2) + +def test(fn = 'f:just samples:just.aif'): + import aifc + af = aifc.open(fn, 'r') + print af.getparams() + p = Play_Audio_mac() + p.setoutrate(af.getframerate()) + p.setsampwidth(af.getsampwidth()) + p.setnchannels(af.getnchannels()) + BUFSIZ = 10000 + while 1: + data = af.readframes(BUFSIZ) + if not data: break + p.writeframes(data) + p.wait() + +if __name__ == '__main__': + test() diff --git a/Mac/Lib/audiodev.py b/Mac/Lib/audiodev.py new file mode 100644 index 0000000..adfeb96 --- /dev/null +++ b/Mac/Lib/audiodev.py @@ -0,0 +1,241 @@ +error = 'audiodev.error' + +class Play_Audio_sgi: + # Private instance variables + access frameratelist, nchannelslist, sampwidthlist, oldparams, \ + params, config, inited_outrate, inited_width, \ + inited_nchannels, port, converter, classinited: private + + classinited = 0 + frameratelist = nchannelslist = sampwidthlist = None + + def initclass(self): + import AL + Play_Audio_sgi.frameratelist = [ + (48000, AL.RATE_48000), + (44100, AL.RATE_44100), + (32000, AL.RATE_32000), + (22050, AL.RATE_22050), + (16000, AL.RATE_16000), + (11025, AL.RATE_11025), + ( 8000, AL.RATE_8000), + ] + Play_Audio_sgi.nchannelslist = [ + (1, AL.MONO), + (2, AL.STEREO), + ] + Play_Audio_sgi.sampwidthlist = [ + (1, AL.SAMPLE_8), + (2, AL.SAMPLE_16), + (3, AL.SAMPLE_24), + ] + Play_Audio_sgi.classinited = 1 + + def __init__(self): + import al, AL + if not self.classinited: + self.initclass() + self.oldparams = [] + self.params = [AL.OUTPUT_RATE, 0] + self.config = al.newconfig() + self.inited_outrate = 0 + self.inited_width = 0 + self.inited_nchannels = 0 + self.converter = None + self.port = None + return + + def __del__(self): + if self.port: + self.stop() + if self.oldparams: + import al, AL + al.setparams(AL.DEFAULT_DEVICE, self.oldparams) + self.oldparams = [] + + def wait(self): + if not self.port: + return + import time + while self.port.getfilled() > 0: + time.sleep(0.1) + self.stop() + + def stop(self): + if self.port: + self.port.closeport() + self.port = None + if self.oldparams: + import al, AL + al.setparams(AL.DEFAULT_DEVICE, self.oldparams) + self.oldparams = [] + + def setoutrate(self, rate): + for (raw, cooked) in self.frameratelist: + if rate == raw: + self.params[1] = cooked + self.inited_outrate = 1 + break + else: + raise error, 'bad output rate' + + def setsampwidth(self, width): + for (raw, cooked) in self.sampwidthlist: + if width == raw: + self.config.setwidth(cooked) + self.inited_width = 1 + break + else: + if width == 0: + import AL + self.inited_width = 0 + self.config.setwidth(AL.SAMPLE_16) + self.converter = self.ulaw2lin + else: + raise error, 'bad sample width' + + def setnchannels(self, nchannels): + for (raw, cooked) in self.nchannelslist: + if nchannels == raw: + self.config.setchannels(cooked) + self.inited_nchannels = 1 + break + else: + raise error, 'bad # of channels' + + def writeframes(self, data): + if not (self.inited_outrate and self.inited_nchannels): + raise error, 'params not specified' + if not self.port: + import al, AL + self.port = al.openport('Python', 'w', self.config) + self.oldparams = self.params[:] + al.getparams(AL.DEFAULT_DEVICE, self.oldparams) + al.setparams(AL.DEFAULT_DEVICE, self.params) + if self.converter: + data = self.converter(data) + self.port.writesamps(data) + + def getfilled(self): + if self.port: + return self.port.getfilled() + else: + return 0 + + def getfillable(self): + if self.port: + return self.port.getfillable() + else: + return self.config.getqueuesize() + + # private methods + access *: private + + def ulaw2lin(self, data): + import audioop + return audioop.ulaw2lin(data, 2) + +class Play_Audio_sun: + access outrate, sampwidth, nchannels, inited_outrate, inited_width, \ + inited_nchannels, converter: private + + def __init__(self): + self.outrate = 0 + self.sampwidth = 0 + self.nchannels = 0 + self.inited_outrate = 0 + self.inited_width = 0 + self.inited_nchannels = 0 + self.converter = None + self.port = None + return + + def __del__(self): + self.stop() + + def setoutrate(self, rate): + self.outrate = rate + self.inited_outrate = 1 + + def setsampwidth(self, width): + self.sampwidth = width + self.inited_width = 1 + + def setnchannels(self, nchannels): + self.nchannels = nchannels + self.inited_nchannels = 1 + + def writeframes(self, data): + if not (self.inited_outrate and self.inited_width and self.inited_nchannels): + raise error, 'params not specified' + if not self.port: + import sunaudiodev, SUNAUDIODEV + self.port = sunaudiodev.open('w') + info = self.port.getinfo() + info.o_sample_rate = self.outrate + info.o_channels = self.nchannels + if self.sampwidth == 0: + info.o_precision = 8 + self.o_encoding = ENCODING_ULAW + else: + info.o_precision = 8 * self.sampwidth + info.o_encoding = SUNAUDIODEV.ENCODING_LINEAR + self.port.setinfo(info) + if self.converter: + data = self.converter(data) + self.port.write(data) + + def wait(self): + if not self.port: + return + self.port.drain() + self.stop() + + def stop(self): + if self.port: + self.port.flush() + self.port.close() + self.port = None + + def getfilled(self): + if self.port: + return self.port.obufcount() + else: + return 0 + + def getfillable(self): + return BUFFERSIZE - self.getfilled() + +def AudioDev(): + try: + import al + return Play_Audio_sgi() + except ImportError: + try: + import sunaudiodev + return Play_Audio_sun() + except ImportError: + try: + import Audio_mac + return Audio_mac.Play_Audio_mac() + except ImportError: + raise error, 'no audio device' + +def test(fn = 'f:just samples:just.aif'): + import aifc + af = aifc.open(fn, 'r') + print fn, af.getparams() + p = AudioDev() + p.setoutrate(af.getframerate()) + p.setsampwidth(af.getsampwidth()) + p.setnchannels(af.getnchannels()) + BUFSIZ = af.getframerate()/af.getsampwidth()/af.getnchannels() + while 1: + data = af.readframes(BUFSIZ) + if not data: break + print len(data) + p.writeframes(data) + p.wait() + +if __name__ == '__main__': + test() diff --git a/Mac/Lib/test/aete.py b/Mac/Lib/test/aete.py new file mode 100644 index 0000000..5a91d89 --- /dev/null +++ b/Mac/Lib/test/aete.py @@ -0,0 +1,402 @@ +# Look for scriptable applications -- that is, applications with an 'aete' resource +# Also contains (partially) reverse engineered 'aete' resource decoding + +import MacOS +import os +import string +import sys +import types +import StringIO + +from Res import * + +def main(): + filename = raw_input("Listing file? (default stdout): ") + redirect(filename, realmain) + +def redirect(filename, func, *args): + f = filename and open(filename, 'w') + save_stdout = sys.stdout + try: + if f: sys.stdout = f + return apply(func, args) + finally: + sys.stdout = save_stdout + if f: f.close() + +def realmain(): + #list('C:Tao AppleScript:Finder Liaison:Finder Liaison 1.0') + #list('C:Internet:Eudora 1.4.2:Eudora1.4.2') + list('E:Excel 4.0:Microsoft Excel') + #list('C:Internet:Netscape 1.0N:Netscape 1.0N') + #find('C:') + #find('D:') + #find('E:') + #find('F:') + +def find(dir, maxlevel = 5): + hits = [] + cur = CurResFile() + names = os.listdir(dir) + tuples = map(lambda x: (os.path.normcase(x), x), names) + tuples.sort() + names = map(lambda (x, y): y, tuples) + for name in names: + if name in (os.curdir, os.pardir): continue + fullname = os.path.join(dir, name) + if os.path.islink(fullname): + pass + if os.path.isdir(fullname): + if maxlevel > 0: + sys.stderr.write(" %s\n" % `fullname`) + hits = hits + find(fullname, maxlevel-1) + else: + ctor, type = MacOS.GetCreatorAndType(fullname) + if type == 'APPL': + sys.stderr.write(" %s\n" % `fullname`) + try: + rf = OpenRFPerm(fullname, 0, '\1') + except MacOS.Error, msg: + print "Error:", fullname, msg + continue + UseResFile(rf) + n = Count1Resources('aete') + if rf <> cur: + CloseResFile(rf) + UseResFile(cur) + if n > 1: + hits.append(fullname) + sys.stderr.write("YES! %d in %s\n" % (n, `fullname`)) + list(fullname) + return hits + +def list(fullname): + cur = CurResFile() + rf = OpenRFPerm(fullname, 0, '\1') + try: + UseResFile(rf) + resources = [] + for i in range(Count1Resources('aete')): + res = Get1IndResource('aete', 1+i) + resources.append(res) + for i in range(Count1Resources('aeut')): + res = Get1IndResource('aeut', 1+i) + resources.append(res) + print "\nLISTING aete+aeut RESOURCE IN", `fullname` + for res in resources: + print res.GetResInfo() + data = res.data + try: + aete = decode(data) + showaete(aete) + f = StringIO.StringIO() + putaete(f, aete) + newdata = f.getvalue() + if len(newdata) == len(data): + if newdata == data: + print "putaete created identical data" + else: + newaete = decode(newdata) + if newaete == aete: + print "putaete created equivalent data" + else: + print "putaete failed the test:" + showaete(newaete) + else: + print "putaete created different data:" + print `newdata` + except: + import traceback + traceback.print_exc() + sys.stdout.flush() + finally: + if rf <> cur: + CloseResFile(rf) + UseResFile(cur) + +def decode(data): + f = StringIO.StringIO(data) + aete = generic(getaete, f) + aete = simplify(aete) + processed = f.tell() + unprocessed = len(f.read()) + total = f.tell() + if unprocessed: + sys.stderr.write("%d processed + %d unprocessed = %d total\n" % + (processed, unprocessed, total)) + return aete + +def simplify(item): + if type(item) is types.ListType: + return map(simplify, item) + elif type(item) == types.TupleType and len(item) == 2: + return simplify(item[1]) + else: + return item + + +# Here follows the aete resource decoder. +# It is presented bottom-up instead of top-down because there are direct +# references to the lower-level part-decoders from the high-level part-decoders. + +def getword(f, *args): + getalign(f) + s = f.read(2) + if len(s) < 2: + raise EOFError, 'in getword' + str(args) + return (ord(s[0])<<8) | ord(s[1]) + +def getlong(f, *args): + getalign(f) + s = f.read(4) + if len(s) < 4: + raise EOFError, 'in getlong' + str(args) + return (ord(s[0])<<24) | (ord(s[1])<<16) | (ord(s[2])<<8) | ord(s[3]) + +def getostype(f, *args): + getalign(f) + s = f.read(4) + if len(s) < 4: + raise EOFError, 'in getostype' + str(args) + return s + +def getpstr(f, *args): + c = f.read(1) + if len(c) < 1: + raise EOFError, 'in getpstr[1]' + str(args) + nbytes = ord(c) + if nbytes == 0: return '' + s = f.read(nbytes) + if len(s) < nbytes: + raise EOFError, 'in getpstr[2]' + str(args) + return s + +def getalign(f): + if f.tell() & 1: + c = f.read(1) + ##if c <> '\0': + ## print 'align:', `c` + +def getlist(f, description, getitem): + count = getword(f) + list = [] + for i in range(count): + getalign(f) + list.append(generic(getitem, f)) + return list + +def alt_generic(what, f, *args): + print "generic", `what`, args + res = vageneric(what, f, args) + print '->', `res` + return res + +def generic(what, f, *args): + if type(what) == types.FunctionType: + return apply(what, (f,) + args) + if type(what) == types.ListType: + record = [] + for thing in what: + item = apply(generic, thing[:1] + (f,) + thing[1:]) + record.append((thing[1], item)) + return record + return "BAD GENERIC ARGS: %s" % `what` + +getdata = [(getostype, "type"), (getpstr, "description"), (getword, "flags")] +getoptarg = [(getpstr, "name"), (getostype, "keyword"), (getdata, "what")] +getcommand = [(getpstr, "name"), (getpstr, "description"), + (getostype, "suite code"), (getostype, "command code"), + (getdata, "returns"), + (getdata, "accepts"), + (getlist, "optional arguments", getoptarg)] +getprop = [(getpstr, "name"), (getostype, "code"), (getdata, "what")] +getelem = [(getostype, "type"), (getlist, "accessibility", getostype)] +getclass = [(getpstr, "name"), (getostype, "class code"), (getpstr, "description"), + (getlist, "properties", getprop), (getlist, "elements", getelem)] +getenumitem = [(getpstr, "name"), (getostype, "value"), (getpstr, "description")] +getenum = [(getostype, "enumtype"), (getlist, "enumitem", getenumitem)] +getsuite = [(getpstr, "name"), (getpstr, "description"), (getostype, "code"), + (getword, "flags1"), (getword, "flags2"), + (getlist, "commands", getcommand), + (getlist, "classes", getclass), + (getword, "count???"), (getlist, "enums", getenum)] +getaete = [(getword, "skip1"), (getword, "skip2"), (getword, "skip3"), + (getlist, "suites", getsuite)] + + +# Display 'aete' resources in a friendly manner. +# This one's done top-down again... + +def showaete(aete): + [flags1, flags2, flags3, suites] = aete + print "\nGlobal flags: x%x, x%x, x%x\n" % (flags1, flags2, flags3) + for suite in suites: + showsuite(suite) + +def showsuite(suite): + [name, desc, code, flags1, flags2, commands, classes, skip1, enums] = suite + print "\nSuite %s -- %s (%s)" % (`name`, `desc`, `code`) + for command in commands: + showcommand(command) + for classe in classes: + showclass(classe) + for enum in enums: + showenum(enum) + +def showcommand(command): + [name, desc, code, subcode, returns, accepts, arguments] = command + print "\n Command %s -- %s (%s, %s)" % (`name`, `desc`, `code`, `subcode`) + print " returns", showdata(returns) + print " accepts", showdata(accepts) + for arg in arguments: + showargument(arg) + +def showargument(arg): + [name, keyword, what] = arg + print " %s (%s)" % (name, `keyword`), showdata(what) + +def showclass(classe): + [name, code, desc, properties, elements] = classe + print "\n Class %s (%s) -- %s" % (`name`, `code`, `desc`) + for prop in properties: + showproperty(prop) + for elem in elements: + showelement(elem) + +def showproperty(prop): + [name, code, what] = prop + print " property %s (%s)" % (name, code), showdata(what) + +def showelement(elem): + [code, accessibility] = elem + print " element %s" % `code`, "as", accessibility + +def showenum(enum): + [code, items] = enum + print "\n Enum %s" % `code` + for item in items: + showitem(item) + +def showitem(item): + [name, code, desc] = item + print " %s (%s) -- %s" % (`name`, `code`, `desc`) + +def showdata(data): + [type, description, flags] = data + return "%s -- %s %s" % (`type`, `description`, showdataflags(flags)) + +dataflagdict = {15: "optional", 14: "list", 13: "enum", 12: "writable"} +def showdataflags(flags): + bits = [] + for i in range(16): + if flags & (1<>8)&0xff)) + f.write(chr(value&0xff)) + +def putostype(f, value): + putalign(f) + if type(value) != types.StringType or len(value) != 4: + raise TypeError, "ostype must be 4-char string" + f.write(value) + +def putpstr(f, value): + if type(value) != types.StringType or len(value) > 255: + raise TypeError, "pstr must be string <= 255 chars" + f.write(chr(len(value)) + value) + + +# Call the main program + +if __name__ == '__main__': + main() +else: + realmain() diff --git a/Mac/Lib/test/tctl.py b/Mac/Lib/test/tctl.py new file mode 100644 index 0000000..862eeb5 --- /dev/null +++ b/Mac/Lib/test/tctl.py @@ -0,0 +1,17 @@ +# play with controls + +from Dlg import * +from Ctl import * +from Win import * +from Evt import * +import time + +def main(): + r = (40, 40, 400, 300) + w = NewWindow(r, "The Spanish Inquisition", 1, 0, -1, 1, 0x55555555) + w.DrawGrowIcon() + r = (40, 40, 100, 60) + c = NewControl(w, r, "SPAM!", 1, 0, 0, 1, 0, 0) + + +main() diff --git a/Mac/Lib/test/tdlg.py b/Mac/Lib/test/tdlg.py new file mode 100644 index 0000000..f234a70 --- /dev/null +++ b/Mac/Lib/test/tdlg.py @@ -0,0 +1,15 @@ +# This program requires that a DLOG resource with ID=128 exists. +# You can make one with ResEdit if necessary. + +from Res import * +from Dlg import * + +ires = 128 + +def filter(*args): print 'filter:', args + +d = GetNewDialog(ires, -1) +while 1: + n = ModalDialog(filter) + print 'item:', n + if n == 1: break diff --git a/Mac/Lib/test/tmenu.py b/Mac/Lib/test/tmenu.py new file mode 100644 index 0000000..1b156d7 --- /dev/null +++ b/Mac/Lib/test/tmenu.py @@ -0,0 +1,60 @@ +# Create hierarchical menus for some volumes. + +import os +from Menu import * + +# Since we can't (yet) list the mounted volumes, here's a list of some: +my_volumes = ['C:', 'D:', 'E:', 'F:'] + +def main(): + global oldbar + oldbar = GetMenuBar() + ClearMenuBar() + makevolmenus(my_volumes) + DrawMenuBar() + +def reset(): + oldbar.SetMenuBar() + DrawMenuBar() + +id = 1 +def nextid(): + global id + nid = id + id = id+1 + return nid + +def makevolmenus(volumes): + for vol in volumes: + makevolmenu(vol) + +def makevolmenu(vol): + menu = NewMenu(nextid(), vol) + adddirectory(menu, vol) + menu.InsertMenu(0) + +def adddirectory(menu, dir, maxdepth = 1): + print "adddirectory:", `dir`, maxdepth + files = os.listdir(dir) + item = 0 + for file in files: + item = item+1 + menu.AppendMenu('x') # add a dummy string + menu.SetItem(item, file) # set the actual text + fullname = os.path.join(dir, file) + if os.path.isdir(fullname): + menu.SetItem(item, ':' + file + ':') # append colons + if maxdepth > 0: + id = nextid() + submenu = NewMenu(id, fullname) + adddirectory(submenu, fullname, maxdepth-1) + submenu.InsertMenu(-1) + # If the 'Cmd' is 0x1B, then the 'Mark' is the submenu id + menu.SetItemMark(item, id) + menu.SetItemCmd(item, 0x1B) + if not files: + menu.AppendMenu(':') # dummy item to make it selectable + return menu + +if __name__ == '__main__': + main() diff --git a/Mac/Lib/test/tsnd.py b/Mac/Lib/test/tsnd.py new file mode 100644 index 0000000..ac347cb --- /dev/null +++ b/Mac/Lib/test/tsnd.py @@ -0,0 +1,18 @@ +# Show off SndPlay (and some resource manager functions). +# Get a list of all 'snd ' resources in the system and play them all. + +from Res import * +from Snd import * + +ch = SndNewChannel(0, 0, None) +print "Channel:", ch + +type = 'snd ' + +for i in range(CountResources(type)): + r = GetIndResource(type, i+1) + print r.GetResInfo(), r.size + if r.GetResInfo()[0] == 1: + print "Skipping simple beep" + continue + ch.SndPlay(r, 0) diff --git a/Mac/Lib/test/twin.py b/Mac/Lib/test/twin.py new file mode 100644 index 0000000..0904d32 --- /dev/null +++ b/Mac/Lib/test/twin.py @@ -0,0 +1,9 @@ +# Test Win module + +from Win import * + +r = (40, 40, 400, 300) +w = NewWindow(r, "Hello world", 1, 0, -1, 1, 0x55555555) +w.DrawGrowIcon() +import time +time.sleep(10) diff --git a/Mac/Lib/toolbox/AppleEvents.py b/Mac/Lib/toolbox/AppleEvents.py new file mode 100644 index 0000000..b3780d0 --- /dev/null +++ b/Mac/Lib/toolbox/AppleEvents.py @@ -0,0 +1,103 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:AppleEvents.h' +typeBoolean = 'bool' +typeChar = 'TEXT' +typeSMInt = 'shor' +typeInteger = 'long' +typeSMFloat = 'sing' +typeFloat = 'doub' +typeLongInteger = 'long' +typeShortInteger = 'shor' +typeLongFloat = 'doub' +typeShortFloat = 'sing' +typeExtended = 'exte' +typeComp = 'comp' +typeMagnitude = 'magn' +typeAEList = 'list' +typeAERecord = 'reco' +typeAppleEvent = 'aevt' +typeTrue = 'true' +typeFalse = 'fals' +typeAlias = 'alis' +typeEnumerated = 'enum' +typeType = 'type' +typeAppParameters = 'appa' +typeProperty = 'prop' +typeFSS = 'fss ' +typeKeyword = 'keyw' +typeSectionH = 'sect' +typeWildCard = '****' +typeApplSignature = 'sign' +typeSessionID = 'ssid' +typeTargetID = 'targ' +typeProcessSerialNumber = 'psn ' +typeNull = 'null' +keyDirectObject = '----' +keyErrorNumber = 'errn' +keyErrorString = 'errs' +keyProcessSerialNumber = 'psn ' +keyTransactionIDAttr = 'tran' +keyReturnIDAttr = 'rtid' +keyEventClassAttr = 'evcl' +keyEventIDAttr = 'evid' +keyAddressAttr = 'addr' +keyOptionalKeywordAttr = 'optk' +keyTimeoutAttr = 'timo' +keyInteractLevelAttr = 'inte' +keyEventSourceAttr = 'esrc' +keyMissedKeywordAttr = 'miss' +keyOriginalAddressAttr = 'from' +keyPreDispatch = 'phac' +keySelectProc = 'selh' +keyAERecorderCount = 'recr' +keyAEVersion = 'vers' +kCoreEventClass = 'aevt' +kAEOpenApplication = 'oapp' +kAEOpenDocuments = 'odoc' +kAEPrintDocuments = 'pdoc' +kAEQuitApplication = 'quit' +kAEAnswer = 'ansr' +kAEApplicationDied = 'obit' +kAENoReply = 0x00000001 +kAEQueueReply = 0x00000002 +kAEWaitReply = 0x00000003 +kAENeverInteract = 0x00000010 +kAECanInteract = 0x00000020 +kAEAlwaysInteract = 0x00000030 +kAECanSwitchLayer = 0x00000040 +kAEDontReconnect = 0x00000080 +kAEDontRecord = 0x00001000 +kAEDontExecute = 0x00002000 +kAENormalPriority = 0x00000000 +kAEStartRecording = 'reca' +kAEStopRecording = 'recc' +kAENotifyStartRecording = 'rec1' +kAENotifyStopRecording = 'rec0' +kAENotifyRecording = 'recr' +kAutoGenerateReturnID = -1 +kAnyTransactionID = 0 +kAEDefaultTimeout = -1 +kNoTimeOut = -2 +kAENoDispatch = 0 +kAEUseStandardDispatch = -1 +errAECoercionFail = -1700 +errAEDescNotFound = -1701 +errAECorruptData = -1702 +errAEWrongDataType = -1703 +errAENotAEDesc = -1704 +errAEBadListItem = -1705 +errAENewerVersion = -1706 +errAENotAppleEvent = -1707 +errAEEventNotHandled = -1708 +errAEReplyNotValid = -1709 +errAEUnknownSendMode = -1710 +errAEWaitCanceled = -1711 +errAETimeout = -1712 +errAENoUserInteraction = -1713 +errAENotASpecialFunction = -1714 +errAEParamMissed = -1715 +errAEUnknownAddressType = -1716 +errAEHandlerNotFound = -1717 +errAEReplyNotArrived = -1718 +errAEIllegalIndex = -1719 +errAEUnknownObjectType = -1731 +errAERecordingIsAlreadyOn = -1732 diff --git a/Mac/Lib/toolbox/Controls.py b/Mac/Lib/toolbox/Controls.py new file mode 100644 index 0000000..c95ea11 --- /dev/null +++ b/Mac/Lib/toolbox/Controls.py @@ -0,0 +1,41 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Controls.h' +pushButProc = 0 +checkBoxProc = 1 +radioButProc = 2 +useWFont = 8 +scrollBarProc = 16 +inButton = 10 +inCheckBox = 11 +inUpButton = 20 +inDownButton = 21 +inPageUp = 22 +inPageDown = 23 +inThumb = 129 +popupMenuProc = 1008 +inLabel = 1 +inMenu = 2 +inTriangle = 4 +popupUseWFont = 1 << 3 +popupTitleOutline = 1 << 11 +popupTitleExtend = 1 << 14 +popupTitleLeftJust = 0x00000000 +popupTitleCenterJust = 0x00000001 +popupTitleRightJust = 0x000000FF +noConstraint = 0 +hAxisOnly = 1 +vAxisOnly = 2 +drawCntl = 0 +testCntl = 1 +calcCRgns = 2 +initCntl = 3 +dispCntl = 4 +posCntl = 5 +thumbCntl = 6 +dragCntl = 7 +autoTrack = 8 +calcCntlRgn = 10 +calcThumbRgn = 11 +cFrameColor = 0 +cBodyColor = 1 +cTextColor = 2 +cThumbColor = 3 diff --git a/Mac/Lib/toolbox/Dialogs.py b/Mac/Lib/toolbox/Dialogs.py new file mode 100644 index 0000000..297568c --- /dev/null +++ b/Mac/Lib/toolbox/Dialogs.py @@ -0,0 +1,20 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Dialogs.h' +ctrlItem = 4 +btnCtrl = 0 +chkCtrl = 1 +radCtrl = 2 +resCtrl = 3 +statText = 8 +editText = 16 +iconItem = 32 +picItem = 64 +userItem = 0 +itemDisable = 128 +ok = 1 +cancel = 2 +stopIcon = 0 +noteIcon = 1 +cautionIcon = 2 +overlayDITL = 0 +appendDITLRight = 1 +appendDITLBottom = 2 diff --git a/Mac/Lib/toolbox/Events.py b/Mac/Lib/toolbox/Events.py new file mode 100644 index 0000000..ac32c3f --- /dev/null +++ b/Mac/Lib/toolbox/Events.py @@ -0,0 +1,49 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Events.h' +nullEvent = 0 +mouseDown = 1 +mouseUp = 2 +keyDown = 3 +keyUp = 4 +autoKey = 5 +updateEvt = 6 +diskEvt = 7 +activateEvt = 8 +osEvt = 15 +mDownMask = 2 +mUpMask = 4 +keyDownMask = 8 +keyUpMask = 16 +autoKeyMask = 32 +updateMask = 64 +diskMask = 128 +activMask = 256 +highLevelEventMask = 1024 +osMask = -32768 +everyEvent = -1 +charCodeMask = 0x000000FF +keyCodeMask = 0x0000FF00 +adbAddrMask = 0x00FF0000 +osEvtMessageMask = 0xFF000000 +mouseMovedMessage = 0xFA +suspendResumeMessage = 0x01 +resumeFlag = 1 +convertClipboardFlag = 2 +activeFlag = 1 +btnState = 128 +cmdKey = 256 +shiftKey = 512 +alphaLock = 1024 +optionKey = 2048 +controlKey = 4096 +networkEvt = 10 +driverEvt = 11 +app1Evt = 12 +app2Evt = 13 +app3Evt = 14 +app4Evt = 15 +networkMask = 1024 +driverMask = 2048 +app1Mask = 4096 +app2Mask = 8192 +app3Mask = 16384 +app4Mask = -32768 diff --git a/Mac/Lib/toolbox/Menus.py b/Mac/Lib/toolbox/Menus.py new file mode 100644 index 0000000..11b9a48 --- /dev/null +++ b/Mac/Lib/toolbox/Menus.py @@ -0,0 +1,12 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Menus.h' +mDrawMsg = 0 +mChooseMsg = 1 +mSizeMsg = 2 +mDrawItemMsg = 4 +mCalcItemMsg = 5 +textMenuProc = 0 +hMenuCmd = 27 +hierMenu = -1 +mPopUpMsg = 3 +mctAllItems = -98 +mctLastIDIndic = -99 /*last color table entry has this in ID field*/ diff --git a/Mac/Lib/toolbox/Resources.py b/Mac/Lib/toolbox/Resources.py new file mode 100644 index 0000000..743c656 --- /dev/null +++ b/Mac/Lib/toolbox/Resources.py @@ -0,0 +1,12 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Resources.h' +resSysHeap = 64 +resPurgeable = 32 +resLocked = 16 +resProtected = 8 +resPreload = 4 +resChanged = 2 +mapReadOnly = 128 +mapCompact = 64 +mapChanged = 32 +mapTrue = 0xFFFF +mapFalse = 0xFF00 diff --git a/Mac/Lib/toolbox/Sound.py b/Mac/Lib/toolbox/Sound.py new file mode 100644 index 0000000..600adcd --- /dev/null +++ b/Mac/Lib/toolbox/Sound.py @@ -0,0 +1,101 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Sound.h' +swMode = -1 +ftMode = 1 +ffMode = 0 +rate22khz = 0x56EE8BA3 +rate11khz = 0x2B7745D1 +squareWaveSynth = 1 +waveTableSynth = 3 +sampledSynth = 5 +MACE3snthID = 11 +MACE6snthID = 13 +nullCmd = 0 +initCmd = 1 +freeCmd = 2 +quietCmd = 3 +flushCmd = 4 +reInitCmd = 5 +waitCmd = 10 +pauseCmd = 11 +resumeCmd = 12 +callBackCmd = 13 +syncCmd = 14 +emptyCmd = 15 +tickleCmd = 20 +requestNextCmd = 21 +howOftenCmd = 22 +wakeUpCmd = 23 +availableCmd = 24 +versionCmd = 25 +totalLoadCmd = 26 +loadCmd = 27 +scaleCmd = 30 +tempoCmd = 31 +freqDurationCmd = 40 +restCmd = 41 +freqCmd = 42 +ampCmd = 43 +timbreCmd = 44 +getAmpCmd = 45 +waveTableCmd = 60 +phaseCmd = 61 +soundCmd = 80 +bufferCmd = 81 +rateCmd = 82 +continueCmd = 83 +doubleBufferCmd = 84 +getRateCmd = 85 +sizeCmd = 90 +convertCmd = 91 +stdQLength = 128 +dataOffsetFlag = 0x8000 +waveInitChannelMask = 0x07 +waveInitChannel0 = 0x04 +waveInitChannel1 = 0x05 +waveInitChannel2 = 0x06 +waveInitChannel3 = 0x07 +initPanMask = 0x0003 +initSRateMask = 0x0030 +initStereoMask = 0x00C0 +initCompMask = 0xFF00 +initChanLeft = 0x0002 +initChanRight = 0x0003 +initNoInterp = 0x0004 +initNoDrop = 0x0008 +initMono = 0x0080 +initStereo = 0x00C0 +initMACE3 = 0x0300 +initMACE6 = 0x0400 +initChan0 = 0x0004 +initChan1 = 0x0005 +initChan2 = 0x0006 +initChan3 = 0x0007 +stdSH = 0x00 +extSH = 0xFF +cmpSH = 0xFE +notCompressed = 0 +twoToOne = 1 +eightToThree = 2 +threeToOne = 3 +sixToOne = 4 +outsideCmpSH = 0 +insideCmpSH = 1 +aceSuccess = 0 +aceMemFull = 1 +aceNilBlock = 2 +aceBadComp = 3 +aceBadEncode = 4 +aceBadDest = 5 +aceBadCmd = 6 +sixToOnePacketSize = 8 +threeToOnePacketSize = 16 +stateBlockSize = 64 +leftOverBlockSize = 32 +firstSoundFormat = 0x0001 +secondSoundFormat = 0x0002 +dbBufferReady = 0x00000001 +dbLastBuffer = 0x00000004 +sysBeepDisable = 0x0000 +sysBeepEnable = 0x0001 +unitTypeNoSelection = 0xFFFF +unitTypeSeconds = 0x0000 diff --git a/Mac/Lib/toolbox/Windows.py b/Mac/Lib/toolbox/Windows.py new file mode 100644 index 0000000..5d5bd7a --- /dev/null +++ b/Mac/Lib/toolbox/Windows.py @@ -0,0 +1,41 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Windows.h' +documentProc = 0 +dBoxProc = 1 +plainDBox = 2 +altDBoxProc = 3 +noGrowDocProc = 4 +movableDBoxProc = 5 +zoomDocProc = 8 +zoomNoGrow = 12 +rDocProc = 16 +dialogKind = 2 +userKind = 8 +inDesk = 0 +inMenuBar = 1 +inSysWindow = 2 +inContent = 3 +inDrag = 4 +inGrow = 5 +inGoAway = 6 +inZoomIn = 7 +inZoomOut = 8 +wDraw = 0 +wHit = 1 +wCalcRgns = 2 +wNew = 3 +wDispose = 4 +wGrow = 5 +wDrawGIcon = 6 +wNoHit = 0 +wInContent = 1 +wInDrag = 2 +wInGrow = 3 +wInGoAway = 4 +wInZoomIn = 5 +wInZoomOut = 6 +deskPatID = 16 +wContentColor = 0 +wFrameColor = 1 +wTextColor = 2 +wHiliteColor = 3 +wTitleBarColor = 4 diff --git a/Mac/Lib/toolbox/aetools.py b/Mac/Lib/toolbox/aetools.py new file mode 100644 index 0000000..745bce7 --- /dev/null +++ b/Mac/Lib/toolbox/aetools.py @@ -0,0 +1,296 @@ +import struct +import types +import AE +import MacOS +import StringIO + +AEDescType = type(AE.AECreateDesc('TEXT', '')) + +def pack(x): + if x == None: + return AE.AECreateDesc('null', '') + t = type(x) + if t == AEDescType: + return x + if t == types.IntType: + return AE.AECreateDesc('long', struct.pack('l', x)) + if t == types.FloatType: + return AE.AECreateDesc('exte', struct.pack('d', x)[2:]) + if t == types.StringType: + return AE.AECreateDesc('TEXT', x) + if t == types.ListType: + list = AE.AECreateList('', 0) + for item in x: + list.AEPutDesc(0, pack(item)) + return list + if t == types.TupleType: + t, d = x + return AE.AECreateDesc(t, d) + if t == types.DictionaryType: + record = AE.AECreateList('', 1) + for key, value in x.items(): + record.AEPutKeyDesc(key, pack(value)) + if t == types.InstanceType and hasattr(x, '__aepack__'): + return x.__aepack__() + return AE.AECreateDesc('TEXT', repr(x)) # Copout + +def unpack(desc): + t = desc.type + if t == 'TEXT': + return desc.data + if t == 'fals': + return 0 + if t == 'true': + return 1 + if t == 'long': + return struct.unpack('l', desc.data)[0] + if t == 'shor': + return struct.unpack('h', desc.data)[0] + if t == 'sing': + return struct.unpack('f', desc.data)[0] + if t == 'exte': + data = desc.data + return struct.unpack('d', data[:2] + data)[0] + if t in ('doub', 'comp', 'magn'): + return unpack(desc.AECoerceDesc('exte')) + if t == 'enum': + return ('enum', desc.data) + if t == 'null': + return None + if t == 'list': + l = [] + for i in range(desc.AECountItems()): + keyword, item = desc.AEGetNthDesc(i+1, '****') + l.append(unpack(item)) + return l + if t == 'reco': + d = {} + for i in range(desc.AECountItems()): + keyword, item = desc.AEGetNthDesc(i+1, '****') + d[keyword] = unpack(item) + return d + if t == 'obj ': + return unpackobject(desc.data) + return desc.type, desc.data # Copout + +class Object: + def __init__(self, dict = {}): + self.dict = dict + for key, value in dict.items(): + self.dict[key] = value + def __repr__(self): + return "Object(%s)" % `self.dict` + def __str__(self): + want = self.dict['want'] + form = self.dict['form'] + seld = self.dict['seld'] + s = "%s %s %s" % (nicewant(want), niceform(form), niceseld(seld)) + fr = self.dict['from'] + if fr: + s = s + " of " + str(fr) + return s + def __aepack__(self): + f = StringIO.StringIO() + putlong(f, len(self.dict)) + putlong(f, 0) + for key, value in self.dict.items(): + putcode(f, key) + desc = pack(value) + putcode(f, desc.type) + data = desc.data + putlong(f, len(data)) + f.write(data) + return AE.AECreateDesc('obj ', f.getvalue()) + +def nicewant(want): + if type(want) == types.TupleType and len(want) == 2: + return reallynicewant(want) + else: + return `want` + +def reallynicewant((t, w)): + if t != 'type': return `t, w` + # These should be taken from the "elements" of the 'aete' resource + if w == 'cins': return 'insertion point' + if w == 'cha ': return 'character' + if w == 'word': return 'word' + if w == 'para': return 'paragraph' + if w == 'ccel': return 'cell' + if w == 'ccol': return 'column' + if w == 'crow': return 'row' + if w == 'crng': return 'range' + if w == 'wind': return 'window' + if w == 'docu': return 'document' + return `w` + +def niceform(form): + if type(form) == types.TupleType and len(form) == 2: + return reallyniceform(form) + else: + return `form` + +def reallyniceform((t, f)): + if t <> 'enum': return `t, f` + if f == 'indx': return '' + if f == 'name': return '' + if f == 'rele': return '' + return `f` + +def niceseld(seld): + if type(seld) == types.TupleType and len(seld) == 2: + return reallyniceseld(seld) + else: + return `seld` + +def reallyniceseld((t, s)): + if t == 'long': return `s` + if t == 'TEXT': return `s` + if t == 'enum': + if s == 'next': return 'after' + if s == 'prev': return 'before' + return `t, s` + +def unpackobject(data): + f = StringIO.StringIO(data) + nkey = getlong(f) + dumm = getlong(f) + dict = {} + for i in range(nkey): + keyw = getcode(f) + type = getcode(f) + size = getlong(f) + if size: + data = f.read(size) + else: + data = '' + desc = AE.AECreateDesc(type, data) + dict[keyw] = unpack(desc) + return Object(dict) + + +# --- get various data types from a "file" + +def getword(f, *args): + getalgn(f) + s = f.read(2) + if len(s) < 2: + raise EOFError, 'in getword' + str(args) + return (ord(s[0])<<8) | ord(s[1]) + +def getlong(f, *args): + getalgn(f) + s = f.read(4) + if len(s) < 4: + raise EOFError, 'in getlong' + str(args) + return (ord(s[0])<<24) | (ord(s[1])<<16) | (ord(s[2])<<8) | ord(s[3]) + +def getcode(f, *args): + getalgn(f) + s = f.read(4) + if len(s) < 4: + raise EOFError, 'in getcode' + str(args) + return s + +def getpstr(f, *args): + c = f.read(1) + if len(c) < 1: + raise EOFError, 'in getpstr[1]' + str(args) + nbytes = ord(c) + if nbytes == 0: return '' + s = f.read(nbytes) + if len(s) < nbytes: + raise EOFError, 'in getpstr[2]' + str(args) + return s + +def getalgn(f): + if f.tell() & 1: + c = f.read(1) + ##if c <> '\0': + ## print 'align:', `c` + +# ---- end get routines + + +# ---- put various data types to a "file" + +def putlong(f, value): + putalgn(f) + f.write(chr((value>>24)&0xff)) + f.write(chr((value>>16)&0xff)) + f.write(chr((value>>8)&0xff)) + f.write(chr(value&0xff)) + +def putword(f, value): + putalgn(f) + f.write(chr((value>>8)&0xff)) + f.write(chr(value&0xff)) + +def putcode(f, value): + if type(value) != types.StringType or len(value) != 4: + raise TypeError, "ostype must be 4-char string" + putalgn(f) + f.write(value) + +def putpstr(f, value): + if type(value) != types.StringType or len(value) > 255: + raise TypeError, "pstr must be string <= 255 chars" + f.write(chr(len(value)) + value) + +def putalgn(f): + if f.tell() & 1: + f.write('\0') + +# ---- end put routines + + +aekeywords = [ + 'tran', + 'rtid', + 'evcl', + 'evid', + 'addr', + 'optk', + 'timo', + 'inte', # this attribute is read only - will be set in AESend + 'esrc', # this attribute is read only + 'miss', # this attribute is read only + 'from' # new in 1.0.1 +] + +def missed(ae): + try: + desc = ae.AEGetAttributeDesc('miss', 'keyw') + except AE.Error, msg: + return None + return desc.data + +def unpackevent(ae): + parameters = {} + while 1: + key = missed(ae) + if not key: break + parameters[key] = unpack(ae.AEGetParamDesc(key, '****')) + attributes = {} + for key in aekeywords: + try: + desc = ae.AEGetAttributeDesc(key, '****') + except (AE.Error, MacOS.Error), msg: + if msg[0] != -1701: + raise sys.exc_type, sys.exc_value + continue + attributes[key] = unpack(desc) + return parameters, attributes + +def packevent(ae, parameters = {}, attributes = {}): + for key, value in parameters.items(): + ae.AEPutParamDesc(key, pack(value)) + for key, value in attributes.items(): + ae.AEPutAttributeDesc(key, pack(value)) + +def test(): + target = AE.AECreateDesc('sign', 'KAHL') + ae = AE.AECreateAppleEvent('aevt', 'oapp', target, -1, 0) + print unpackevent(ae) + +if __name__ == '__main__': + test() diff --git a/Mac/Modules/ae/AEmodule.c b/Mac/Modules/ae/AEmodule.c new file mode 100644 index 0000000..544c4e2 --- /dev/null +++ b/Mac/Modules/ae/AEmodule.c @@ -0,0 +1,1257 @@ + +/* =========================== Module AE ============================ */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include +#include +#include +#include + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +#include + +#ifdef THINK_C +#define AEFilterProcPtr EventFilterProcPtr +#define AEEventHandlerProcPtr EventHandlerProcPtr +#endif + +static pascal OSErr GenericEventHandler(); /* Forward */ + +static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn) +{ + (void) PyMac_Idle(); + return 0; +} + +static PyObject *AE_Error; + +/* ----------------------- Object type AEDesc ----------------------- */ + +staticforward PyTypeObject AEDesc_Type; + +#define AEDesc_Check(x) ((x)->ob_type == &AEDesc_Type) + +typedef struct AEDescObject { + PyObject_HEAD + AEDesc ob_itself; +} AEDescObject; + +static PyObject *AEDesc_New(itself) + const AEDesc *itself; +{ + AEDescObject *it; + it = PyObject_NEW(AEDescObject, &AEDesc_Type); + if (it == NULL) return NULL; + it->ob_itself = *itself; + return (PyObject *)it; +} +static AEDesc_Convert(v, p_itself) + PyObject *v; + AEDesc *p_itself; +{ + if (!AEDesc_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "AEDesc required"); + return 0; + } + *p_itself = ((AEDescObject *)v)->ob_itself; + return 1; +} + +static void AEDesc_dealloc(self) + AEDescObject *self; +{ + AEDisposeDesc(&self->ob_itself); + PyMem_DEL(self); +} + +static PyObject *AEDesc_AECoerceDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + DescType toType; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &toType)) + return NULL; + _err = AECoerceDesc(&_self->ob_itself, + toType, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AEDuplicateDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEDesc result; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AEDuplicateDesc(&_self->ob_itself, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AECountItems(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long theCount; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AECountItems(&_self->ob_itself, + &theCount); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("l", + theCount); + return _res; +} + +static PyObject *AEDesc_AEPutPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "lO&s#", + &index, + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__)) + return NULL; + _err = AEPutPtr(&_self->ob_itself, + index, + typeCode, + dataPtr__in__, dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEPutDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + AEDesc theAEDesc; + if (!PyArg_ParseTuple(_args, "lO&", + &index, + AEDesc_Convert, &theAEDesc)) + return NULL; + _err = AEPutDesc(&_self->ob_itself, + index, + &theAEDesc); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEGetNthPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + DescType desiredType; + AEKeyword theAEKeyword; + DescType typeCode; + char *dataPtr__out__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "lO&l", + &index, + PyMac_GetOSType, &desiredType, + &dataPtr__len__)) + return NULL; + if ((dataPtr__out__ = malloc(dataPtr__len__)) == NULL) + { + PyErr_NoMemory(); + goto dataPtr__error__; + } + _err = AEGetNthPtr(&_self->ob_itself, + index, + desiredType, + &theAEKeyword, + &typeCode, + dataPtr__out__, dataPtr__len__, &dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&O&s#", + PyMac_BuildOSType, theAEKeyword, + PyMac_BuildOSType, typeCode, + dataPtr__out__, dataPtr__len__); + free(dataPtr__out__); + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEGetNthDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + DescType desiredType; + AEKeyword theAEKeyword; + AEDesc result; + if (!PyArg_ParseTuple(_args, "lO&", + &index, + PyMac_GetOSType, &desiredType)) + return NULL; + _err = AEGetNthDesc(&_self->ob_itself, + index, + desiredType, + &theAEKeyword, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&O&", + PyMac_BuildOSType, theAEKeyword, + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AESizeOfNthItem(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + DescType typeCode; + Size dataSize; + if (!PyArg_ParseTuple(_args, "l", + &index)) + return NULL; + _err = AESizeOfNthItem(&_self->ob_itself, + index, + &typeCode, + &dataSize); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&l", + PyMac_BuildOSType, typeCode, + dataSize); + return _res; +} + +static PyObject *AEDesc_AEDeleteItem(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + if (!PyArg_ParseTuple(_args, "l", + &index)) + return NULL; + _err = AEDeleteItem(&_self->ob_itself, + index); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEPutKeyPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&s#", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__)) + return NULL; + _err = AEPutKeyPtr(&_self->ob_itself, + theAEKeyword, + typeCode, + dataPtr__in__, dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEPutKeyDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + AEDesc theAEDesc; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + AEDesc_Convert, &theAEDesc)) + return NULL; + _err = AEPutKeyDesc(&_self->ob_itself, + theAEKeyword, + &theAEDesc); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEGetKeyPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + DescType typeCode; + char *dataPtr__out__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&l", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType, + &dataPtr__len__)) + return NULL; + if ((dataPtr__out__ = malloc(dataPtr__len__)) == NULL) + { + PyErr_NoMemory(); + goto dataPtr__error__; + } + _err = AEGetKeyPtr(&_self->ob_itself, + theAEKeyword, + desiredType, + &typeCode, + dataPtr__out__, dataPtr__len__, &dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&s#", + PyMac_BuildOSType, typeCode, + dataPtr__out__, dataPtr__len__); + free(dataPtr__out__); + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEGetKeyDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType)) + return NULL; + _err = AEGetKeyDesc(&_self->ob_itself, + theAEKeyword, + desiredType, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AESizeOfKeyDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + Size dataSize; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theAEKeyword)) + return NULL; + _err = AESizeOfKeyDesc(&_self->ob_itself, + theAEKeyword, + &typeCode, + &dataSize); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&l", + PyMac_BuildOSType, typeCode, + dataSize); + return _res; +} + +static PyObject *AEDesc_AEDeleteKeyDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theAEKeyword)) + return NULL; + _err = AEDeleteKeyDesc(&_self->ob_itself, + theAEKeyword); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEPutParamPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&s#", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__)) + return NULL; + _err = AEPutParamPtr(&_self->ob_itself, + theAEKeyword, + typeCode, + dataPtr__in__, dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEPutParamDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + AEDesc theAEDesc; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + AEDesc_Convert, &theAEDesc)) + return NULL; + _err = AEPutParamDesc(&_self->ob_itself, + theAEKeyword, + &theAEDesc); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEGetParamPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + DescType typeCode; + char *dataPtr__out__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&l", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType, + &dataPtr__len__)) + return NULL; + if ((dataPtr__out__ = malloc(dataPtr__len__)) == NULL) + { + PyErr_NoMemory(); + goto dataPtr__error__; + } + _err = AEGetParamPtr(&_self->ob_itself, + theAEKeyword, + desiredType, + &typeCode, + dataPtr__out__, dataPtr__len__, &dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&s#", + PyMac_BuildOSType, typeCode, + dataPtr__out__, dataPtr__len__); + free(dataPtr__out__); + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEGetParamDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType)) + return NULL; + _err = AEGetParamDesc(&_self->ob_itself, + theAEKeyword, + desiredType, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AESizeOfParam(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + Size dataSize; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theAEKeyword)) + return NULL; + _err = AESizeOfParam(&_self->ob_itself, + theAEKeyword, + &typeCode, + &dataSize); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&l", + PyMac_BuildOSType, typeCode, + dataSize); + return _res; +} + +static PyObject *AEDesc_AEDeleteParam(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theAEKeyword)) + return NULL; + _err = AEDeleteParam(&_self->ob_itself, + theAEKeyword); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEGetAttributePtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + DescType typeCode; + char *dataPtr__out__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&l", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType, + &dataPtr__len__)) + return NULL; + if ((dataPtr__out__ = malloc(dataPtr__len__)) == NULL) + { + PyErr_NoMemory(); + goto dataPtr__error__; + } + _err = AEGetAttributePtr(&_self->ob_itself, + theAEKeyword, + desiredType, + &typeCode, + dataPtr__out__, dataPtr__len__, &dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&s#", + PyMac_BuildOSType, typeCode, + dataPtr__out__, dataPtr__len__); + free(dataPtr__out__); + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEGetAttributeDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType)) + return NULL; + _err = AEGetAttributeDesc(&_self->ob_itself, + theAEKeyword, + desiredType, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AESizeOfAttribute(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + Size dataSize; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theAEKeyword)) + return NULL; + _err = AESizeOfAttribute(&_self->ob_itself, + theAEKeyword, + &typeCode, + &dataSize); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&l", + PyMac_BuildOSType, typeCode, + dataSize); + return _res; +} + +static PyObject *AEDesc_AEPutAttributePtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&s#", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__)) + return NULL; + _err = AEPutAttributePtr(&_self->ob_itself, + theAEKeyword, + typeCode, + dataPtr__in__, dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEPutAttributeDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + AEDesc theAEDesc; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + AEDesc_Convert, &theAEDesc)) + return NULL; + _err = AEPutAttributeDesc(&_self->ob_itself, + theAEKeyword, + &theAEDesc); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AESend(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AppleEvent reply; + AESendMode sendMode; + AESendPriority sendPriority; + long timeOutInTicks; + if (!PyArg_ParseTuple(_args, "lhl", + &sendMode, + &sendPriority, + &timeOutInTicks)) + return NULL; + _err = AESend(&_self->ob_itself, + &reply, + sendMode, + sendPriority, + timeOutInTicks, + AEIdleProc, + (AEFilterProcPtr)0); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &reply); + return _res; +} + +static PyObject *AEDesc_AEResetTimer(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AEResetTimer(&_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AESuspendTheCurrentEvent(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AESuspendTheCurrentEvent(&_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEResumeTheCurrentEvent(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AppleEvent reply; + AEEventHandlerProcPtr dispatcher__proc__ = GenericEventHandler; + PyObject *dispatcher; + if (!PyArg_ParseTuple(_args, "O&O", + AEDesc_Convert, &reply, + &dispatcher)) + return NULL; + _err = AEResumeTheCurrentEvent(&_self->ob_itself, + &reply, + dispatcher__proc__, (long)dispatcher); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AESetTheCurrentEvent(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AESetTheCurrentEvent(&_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef AEDesc_methods[] = { + {"AECoerceDesc", (PyCFunction)AEDesc_AECoerceDesc, 1, + "(DescType toType) -> (AEDesc result)"}, + {"AEDuplicateDesc", (PyCFunction)AEDesc_AEDuplicateDesc, 1, + "() -> (AEDesc result)"}, + {"AECountItems", (PyCFunction)AEDesc_AECountItems, 1, + "() -> (long theCount)"}, + {"AEPutPtr", (PyCFunction)AEDesc_AEPutPtr, 1, + "(long index, DescType typeCode, Buffer dataPtr) -> None"}, + {"AEPutDesc", (PyCFunction)AEDesc_AEPutDesc, 1, + "(long index, AEDesc theAEDesc) -> None"}, + {"AEGetNthPtr", (PyCFunction)AEDesc_AEGetNthPtr, 1, + "(long index, DescType desiredType, Buffer dataPtr) -> (AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr)"}, + {"AEGetNthDesc", (PyCFunction)AEDesc_AEGetNthDesc, 1, + "(long index, DescType desiredType) -> (AEKeyword theAEKeyword, AEDesc result)"}, + {"AESizeOfNthItem", (PyCFunction)AEDesc_AESizeOfNthItem, 1, + "(long index) -> (DescType typeCode, Size dataSize)"}, + {"AEDeleteItem", (PyCFunction)AEDesc_AEDeleteItem, 1, + "(long index) -> None"}, + {"AEPutKeyPtr", (PyCFunction)AEDesc_AEPutKeyPtr, 1, + "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"}, + {"AEPutKeyDesc", (PyCFunction)AEDesc_AEPutKeyDesc, 1, + "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"}, + {"AEGetKeyPtr", (PyCFunction)AEDesc_AEGetKeyPtr, 1, + "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"}, + {"AEGetKeyDesc", (PyCFunction)AEDesc_AEGetKeyDesc, 1, + "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"}, + {"AESizeOfKeyDesc", (PyCFunction)AEDesc_AESizeOfKeyDesc, 1, + "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"}, + {"AEDeleteKeyDesc", (PyCFunction)AEDesc_AEDeleteKeyDesc, 1, + "(AEKeyword theAEKeyword) -> None"}, + {"AEPutParamPtr", (PyCFunction)AEDesc_AEPutParamPtr, 1, + "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"}, + {"AEPutParamDesc", (PyCFunction)AEDesc_AEPutParamDesc, 1, + "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"}, + {"AEGetParamPtr", (PyCFunction)AEDesc_AEGetParamPtr, 1, + "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"}, + {"AEGetParamDesc", (PyCFunction)AEDesc_AEGetParamDesc, 1, + "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"}, + {"AESizeOfParam", (PyCFunction)AEDesc_AESizeOfParam, 1, + "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"}, + {"AEDeleteParam", (PyCFunction)AEDesc_AEDeleteParam, 1, + "(AEKeyword theAEKeyword) -> None"}, + {"AEGetAttributePtr", (PyCFunction)AEDesc_AEGetAttributePtr, 1, + "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"}, + {"AEGetAttributeDesc", (PyCFunction)AEDesc_AEGetAttributeDesc, 1, + "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"}, + {"AESizeOfAttribute", (PyCFunction)AEDesc_AESizeOfAttribute, 1, + "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"}, + {"AEPutAttributePtr", (PyCFunction)AEDesc_AEPutAttributePtr, 1, + "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"}, + {"AEPutAttributeDesc", (PyCFunction)AEDesc_AEPutAttributeDesc, 1, + "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"}, + {"AESend", (PyCFunction)AEDesc_AESend, 1, + "(AESendMode sendMode, AESendPriority sendPriority, long timeOutInTicks) -> (AppleEvent reply)"}, + {"AEResetTimer", (PyCFunction)AEDesc_AEResetTimer, 1, + "() -> None"}, + {"AESuspendTheCurrentEvent", (PyCFunction)AEDesc_AESuspendTheCurrentEvent, 1, + "() -> None"}, + {"AEResumeTheCurrentEvent", (PyCFunction)AEDesc_AEResumeTheCurrentEvent, 1, + "(AppleEvent reply, EventHandler dispatcher) -> None"}, + {"AESetTheCurrentEvent", (PyCFunction)AEDesc_AESetTheCurrentEvent, 1, + "() -> None"}, + {NULL, NULL, 0} +}; + +static PyMethodChain AEDesc_chain = { AEDesc_methods, NULL }; + +static PyObject *AEDesc_getattr(self, name) + AEDescObject *self; + char *name; +{ + + if (strcmp(name, "type") == 0) + return PyMac_BuildOSType(self->ob_itself.descriptorType); + if (strcmp(name, "data") == 0) { + PyObject *res; + char state; + state = HGetState(self->ob_itself.dataHandle); + HLock(self->ob_itself.dataHandle); + res = PyString_FromStringAndSize( + *self->ob_itself.dataHandle, + GetHandleSize(self->ob_itself.dataHandle)); + HUnlock(self->ob_itself.dataHandle); + HSetState(self->ob_itself.dataHandle, state); + return res; + } + if (strcmp(name, "__members__") == 0) + return Py_BuildValue("[ss]", "data", "type"); + + return Py_FindMethodInChain(&AEDesc_chain, (PyObject *)self, name); +} + +#define AEDesc_setattr NULL + +static PyTypeObject AEDesc_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "AEDesc", /*tp_name*/ + sizeof(AEDescObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) AEDesc_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) AEDesc_getattr, /*tp_getattr*/ + (setattrfunc) AEDesc_setattr, /*tp_setattr*/ +}; + +/* --------------------- End object type AEDesc --------------------- */ + + +static PyObject *AE_AECreateDesc(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&s#", + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__)) + return NULL; + _err = AECreateDesc(typeCode, + dataPtr__in__, dataPtr__len__, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + dataPtr__error__: ; + return _res; +} + +static PyObject *AE_AECoercePtr(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + DescType toType; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&s#O&", + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__, + PyMac_GetOSType, &toType)) + return NULL; + _err = AECoercePtr(typeCode, + dataPtr__in__, dataPtr__len__, + toType, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + dataPtr__error__: ; + return _res; +} + +static PyObject *AE_AECreateList(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + char *factoringPtr__in__; + long factoringPtr__len__; + Boolean isRecord; + AEDescList resultList; + if (!PyArg_ParseTuple(_args, "s#b", + &factoringPtr__in__, &factoringPtr__len__, + &isRecord)) + return NULL; + _err = AECreateList(factoringPtr__in__, factoringPtr__len__, + isRecord, + &resultList); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &resultList); + factoringPtr__error__: ; + return _res; +} + +static PyObject *AE_AECreateAppleEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEEventClass theAEEventClass; + AEEventID theAEEventID; + AEAddressDesc target; + short returnID; + long transactionID; + AppleEvent result; + if (!PyArg_ParseTuple(_args, "O&O&O&hl", + PyMac_GetOSType, &theAEEventClass, + PyMac_GetOSType, &theAEEventID, + AEDesc_Convert, &target, + &returnID, + &transactionID)) + return NULL; + _err = AECreateAppleEvent(theAEEventClass, + theAEEventID, + &target, + returnID, + transactionID, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AE_AEProcessAppleEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + EventRecord theEventRecord; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetEventRecord, &theEventRecord)) + return NULL; + _err = AEProcessAppleEvent(&theEventRecord); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AE_AEGetTheCurrentEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AppleEvent theAppleEvent; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AEGetTheCurrentEvent(&theAppleEvent); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &theAppleEvent); + return _res; +} + +static PyObject *AE_AEGetInteractionAllowed(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEInteractAllowed level; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AEGetInteractionAllowed(&level); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("b", + level); + return _res; +} + +static PyObject *AE_AESetInteractionAllowed(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEInteractAllowed level; + if (!PyArg_ParseTuple(_args, "b", + &level)) + return NULL; + _err = AESetInteractionAllowed(level); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AE_AEInteractWithUser(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long timeOutInTicks; + if (!PyArg_ParseTuple(_args, "l", + &timeOutInTicks)) + return NULL; + _err = AEInteractWithUser(timeOutInTicks, + (NMRecPtr)0, + AEIdleProc); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AE_AEInstallEventHandler(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEEventClass theAEEventClass; + AEEventID theAEEventID; + AEEventHandlerProcPtr handler__proc__ = GenericEventHandler; + PyObject *handler; + if (!PyArg_ParseTuple(_args, "O&O&O", + PyMac_GetOSType, &theAEEventClass, + PyMac_GetOSType, &theAEEventID, + &handler)) + return NULL; + _err = AEInstallEventHandler(theAEEventClass, + theAEEventID, + handler__proc__, (long)handler, + 0); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AE_AERemoveEventHandler(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEEventClass theAEEventClass; + AEEventID theAEEventID; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEEventClass, + PyMac_GetOSType, &theAEEventID)) + return NULL; + _err = AERemoveEventHandler(theAEEventClass, + theAEEventID, + GenericEventHandler, + 0); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AE_AEManagerInfo(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword keyWord; + long result; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &keyWord)) + return NULL; + _err = AEManagerInfo(keyWord, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("l", + result); + return _res; +} + +static PyMethodDef AE_methods[] = { + {"AECreateDesc", (PyCFunction)AE_AECreateDesc, 1, + "(DescType typeCode, Buffer dataPtr) -> (AEDesc result)"}, + {"AECoercePtr", (PyCFunction)AE_AECoercePtr, 1, + "(DescType typeCode, Buffer dataPtr, DescType toType) -> (AEDesc result)"}, + {"AECreateList", (PyCFunction)AE_AECreateList, 1, + "(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)"}, + {"AECreateAppleEvent", (PyCFunction)AE_AECreateAppleEvent, 1, + "(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, short returnID, long transactionID) -> (AppleEvent result)"}, + {"AEProcessAppleEvent", (PyCFunction)AE_AEProcessAppleEvent, 1, + "(EventRecord theEventRecord) -> None"}, + {"AEGetTheCurrentEvent", (PyCFunction)AE_AEGetTheCurrentEvent, 1, + "() -> (AppleEvent theAppleEvent)"}, + {"AEGetInteractionAllowed", (PyCFunction)AE_AEGetInteractionAllowed, 1, + "() -> (AEInteractAllowed level)"}, + {"AESetInteractionAllowed", (PyCFunction)AE_AESetInteractionAllowed, 1, + "(AEInteractAllowed level) -> None"}, + {"AEInteractWithUser", (PyCFunction)AE_AEInteractWithUser, 1, + "(long timeOutInTicks) -> None"}, + {"AEInstallEventHandler", (PyCFunction)AE_AEInstallEventHandler, 1, + "(AEEventClass theAEEventClass, AEEventID theAEEventID, EventHandler handler) -> None"}, + {"AERemoveEventHandler", (PyCFunction)AE_AERemoveEventHandler, 1, + "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None"}, + {"AEManagerInfo", (PyCFunction)AE_AEManagerInfo, 1, + "(AEKeyword keyWord) -> (long result)"}, + {NULL, NULL, 0} +}; + + + +static pascal OSErr +GenericEventHandler(const AppleEvent *request, AppleEvent *reply, long refcon) +{ + PyObject *handler = (PyObject *)refcon; + AEDescObject *requestObject, *replyObject; + PyObject *args, *res; + if ((requestObject = (AEDescObject *)AEDesc_New(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) + return -1; + Py_DECREF(res); + return noErr; +} + + +void initAE() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("AE", AE_methods); + d = PyModule_GetDict(m); + AE_Error = PyMac_GetOSErrException(); + if (AE_Error == NULL || + PyDict_SetItemString(d, "Error", AE_Error) != 0) + Py_FatalError("can't initialize AE.Error"); +} + +/* ========================= End module AE ========================== */ + diff --git a/Mac/Modules/ae/aegen.py b/Mac/Modules/ae/aegen.py new file mode 100644 index 0000000..ea9b3b6 --- /dev/null +++ b/Mac/Modules/ae/aegen.py @@ -0,0 +1,314 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:AppleEvents.h' + +f = AEFunction(OSErr, 'AECreateDesc', + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), + (AEDesc, 'result', OutMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AECoercePtr', + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), + (DescType, 'toType', InMode), + (AEDesc, 'result', OutMode), +) +functions.append(f) + +f = AEMethod(OSErr, 'AECoerceDesc', + (AEDesc_ptr, 'theAEDesc', InMode), + (DescType, 'toType', InMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEDuplicateDesc', + (AEDesc_ptr, 'theAEDesc', InMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEFunction(OSErr, 'AECreateList', + (InBuffer, 'factoringPtr', InMode), + (Boolean, 'isRecord', InMode), + (AEDescList, 'resultList', OutMode), +) +functions.append(f) + +f = AEMethod(OSErr, 'AECountItems', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'theCount', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutPtr', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutDesc', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), + (AEDesc_ptr, 'theAEDesc', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetNthPtr', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), + (DescType, 'desiredType', InMode), + (AEKeyword, 'theAEKeyword', OutMode), + (DescType, 'typeCode', OutMode), + (VarVarOutBuffer, 'dataPtr', InOutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetNthDesc', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), + (DescType, 'desiredType', InMode), + (AEKeyword, 'theAEKeyword', OutMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AESizeOfNthItem', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), + (DescType, 'typeCode', OutMode), + (Size, 'dataSize', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEDeleteItem', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutKeyPtr', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutKeyDesc', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (AEDesc_ptr, 'theAEDesc', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetKeyPtr', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (DescType, 'typeCode', OutMode), + (VarVarOutBuffer, 'dataPtr', InOutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetKeyDesc', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AESizeOfKeyDesc', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', OutMode), + (Size, 'dataSize', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEDeleteKeyDesc', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutParamPtr', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutParamDesc', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (AEDesc_ptr, 'theAEDesc', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetParamPtr', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (DescType, 'typeCode', OutMode), + (VarVarOutBuffer, 'dataPtr', InOutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetParamDesc', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AESizeOfParam', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', OutMode), + (Size, 'dataSize', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEDeleteParam', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetAttributePtr', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (DescType, 'typeCode', OutMode), + (VarVarOutBuffer, 'dataPtr', InOutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetAttributeDesc', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AESizeOfAttribute', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', OutMode), + (Size, 'dataSize', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutAttributePtr', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutAttributeDesc', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (AEDesc_ptr, 'theAEDesc', InMode), +) +aedescmethods.append(f) + +f = AEFunction(OSErr, 'AECreateAppleEvent', + (AEEventClass, 'theAEEventClass', InMode), + (AEEventID, 'theAEEventID', InMode), + (AEAddressDesc_ptr, 'target', InMode), + (short, 'returnID', InMode), + (long, 'transactionID', InMode), + (AppleEvent, 'result', OutMode), +) +functions.append(f) + +f = AEMethod(OSErr, 'AESend', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AppleEvent, 'reply', OutMode), + (AESendMode, 'sendMode', InMode), + (AESendPriority, 'sendPriority', InMode), + (long, 'timeOutInTicks', InMode), + (IdleProcPtr, 'idleProc', InMode), + (EventFilterProcPtr, 'filterProc', InMode), +) +aedescmethods.append(f) + +f = AEFunction(OSErr, 'AEProcessAppleEvent', + (EventRecord_ptr, 'theEventRecord', InMode), +) +functions.append(f) + +f = AEMethod(OSErr, 'AEResetTimer', + (AppleEvent_ptr, 'reply', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AESuspendTheCurrentEvent', + (AppleEvent_ptr, 'theAppleEvent', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEResumeTheCurrentEvent', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AppleEvent_ptr, 'reply', InMode), + (EventHandler, 'dispatcher', InMode), +) +aedescmethods.append(f) + +f = AEFunction(OSErr, 'AEGetTheCurrentEvent', + (AppleEvent, 'theAppleEvent', OutMode), +) +functions.append(f) + +f = AEMethod(OSErr, 'AESetTheCurrentEvent', + (AppleEvent_ptr, 'theAppleEvent', InMode), +) +aedescmethods.append(f) + +f = AEFunction(OSErr, 'AEGetInteractionAllowed', + (AEInteractAllowed, 'level', OutMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AESetInteractionAllowed', + (AEInteractAllowed, 'level', InMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AEInteractWithUser', + (long, 'timeOutInTicks', InMode), + (NMRecPtr, 'nmReqPtr', InMode), + (IdleProcPtr, 'idleProc', InMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AEInstallEventHandler', + (AEEventClass, 'theAEEventClass', InMode), + (AEEventID, 'theAEEventID', InMode), + (EventHandler, 'handler', InMode), + (AlwaysFalse, 'isSysHandler', InMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AERemoveEventHandler', + (AEEventClass, 'theAEEventClass', InMode), + (AEEventID, 'theAEEventID', InMode), + (EventHandlerProcPtr, 'handler', InMode), + (AlwaysFalse, 'isSysHandler', InMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AEManagerInfo', + (AEKeyword, 'keyWord', InMode), + (long, 'result', OutMode), +) +functions.append(f) diff --git a/Mac/Modules/ae/aescan.py b/Mac/Modules/ae/aescan.py new file mode 100644 index 0000000..75003ec --- /dev/null +++ b/Mac/Modules/ae/aescan.py @@ -0,0 +1,71 @@ +# Scan AppleEvents.h header file, generate aegen.py and AppleEvents.py files. +# Then run aesupport to generate AEmodule.c. +0# (Should learn how to tell the compiler to compile it as well.) + +import sys +import os +import string +import regex +import regsub +import MacOS + +from scantools import Scanner + +def main(): + input = "AppleEvents.h" + output = "aegen.py" + defsoutput = "AppleEvents.py" + scanner = AppleEventsScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + 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", + ] + + def makeblacklisttypes(self): + return [ + "ProcPtr", + "AEArrayType", + ] + + def makerepairinstructions(self): + return [ + ([("Boolean", "isSysHandler", "InMode")], + [("AlwaysFalse", "*", "*")]), + + ([("void_ptr", "*", "InMode"), ("Size", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("EventHandlerProcPtr", "*", "InMode"), ("long", "*", "InMode")], + [("EventHandler", "*", "*")]), + + ([("EventHandlerProcPtr", "*", "OutMode"), ("long", "*", "OutMode")], + [("EventHandler", "*", "*")]), + + ([("void", "*", "OutMode"), ("Size", "*", "InMode"), + ("Size", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/ae/aesupport.py b/Mac/Modules/ae/aesupport.py new file mode 100644 index 0000000..49f072b --- /dev/null +++ b/Mac/Modules/ae/aesupport.py @@ -0,0 +1,168 @@ +# This script will generate the AppleEvents interface for Python. +# It uses the "bgen" package to generate C code. +# It execs the file aegen.py which contain the function definitions +# (aegen.py was generated by aescan.py, scanning the header file). + + +from macsupport import * + + +AEArrayType = Type("AEArrayType", "c") +AESendMode = Type("AESendMode", "l") +AESendPriority = Type("AESendPriority", "h") +AEInteractAllowed = Type("AEInteractAllowed", "b") + + +AEEventClass = OSTypeType('AEEventClass') +AEEventID = OSTypeType('AEEventID') +AEKeyword = OSTypeType('AEKeyword') +DescType = OSTypeType('DescType') + + +AEDesc = OpaqueType('AEDesc') +AEDesc_ptr = OpaqueType('AEDesc') + +AEAddressDesc = OpaqueType('AEAddressDesc', 'AEDesc') +AEAddressDesc_ptr = OpaqueType('AEAddressDesc', 'AEDesc') + +AEDescList = OpaqueType('AEDescList', 'AEDesc') +AEDescList_ptr = OpaqueType('AEDescList', 'AEDesc') + +AERecord = OpaqueType('AERecord', 'AEDesc') +AERecord_ptr = OpaqueType('AERecord', 'AEDesc') + +AppleEvent = OpaqueType('AppleEvent', 'AEDesc') +AppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc') + + +class EHType(Type): + def __init__(self, name = 'EventHandler', format = ''): + Type.__init__(self, name, format) + def declare(self, name): + Output("AEEventHandlerProcPtr %s__proc__ = 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 + +class EHNoRefConType(EHType): + def passInput(self, name): + return "GenericEventHandler" + +EventHandler = EHType() +EventHandlerNoRefCon = EHNoRefConType() + + +IdleProcPtr = FakeType("AEIdleProc") +EventFilterProcPtr = FakeType("(AEFilterProcPtr)0") +NMRecPtr = FakeType("(NMRecPtr)0") +EventHandlerProcPtr = FakeType("GenericEventHandler") +AlwaysFalse = FakeType("0") + + +AEFunction = OSErrFunctionGenerator +AEMethod = OSErrMethodGenerator + + +includestuff = includestuff + """ +#include + +#ifdef THINK_C +#define AEFilterProcPtr EventFilterProcPtr +#define AEEventHandlerProcPtr EventHandlerProcPtr +#endif + +static pascal OSErr GenericEventHandler(); /* Forward */ + +static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn) +{ + return !PyMac_Idle(); +} +""" + +finalstuff = finalstuff + """ +static pascal OSErr +GenericEventHandler(const AppleEvent *request, AppleEvent *reply, long refcon) +{ + PyObject *handler = (PyObject *)refcon; + AEDescObject *requestObject, *replyObject; + PyObject *args, *res; + if ((requestObject = (AEDescObject *)AEDesc_New(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) + return -1; + Py_DECREF(res); + return noErr; +} +""" + +module = MacModule('AE', 'AE', includestuff, finalstuff, initstuff) + +class AEDescDefiniton(ObjectDefinition): + + def __init__(self, name, prefix = None, itselftype = None): + ObjectDefinition.__init__(self, name, prefix or name, itselftype or name) + self.argref = "*" + + def outputFreeIt(self, name): + Output("AEDisposeDesc(&%s);", name) + + def outputGetattrHook(self): + Output(""" +if (strcmp(name, "type") == 0) + return PyMac_BuildOSType(self->ob_itself.descriptorType); +if (strcmp(name, "data") == 0) { + PyObject *res; + char state; + state = HGetState(self->ob_itself.dataHandle); + HLock(self->ob_itself.dataHandle); + res = PyString_FromStringAndSize( + *self->ob_itself.dataHandle, + GetHandleSize(self->ob_itself.dataHandle)); + HUnlock(self->ob_itself.dataHandle); + HSetState(self->ob_itself.dataHandle, state); + return res; +} +if (strcmp(name, "__members__") == 0) + return Py_BuildValue("[ss]", "data", "type"); +""") + + +aedescobject = AEDescDefiniton('AEDesc') +module.addobject(aedescobject) + +functions = [] +aedescmethods = [] + +execfile('aegen.py') + +for f in functions: module.add(f) +for f in aedescmethods: aedescobject.add(f) + +SetOutputFileName('AEmodule.c') +module.generate() diff --git a/Mac/Modules/ctl/Ctlmodule.c b/Mac/Modules/ctl/Ctlmodule.c new file mode 100644 index 0000000..fb1459a --- /dev/null +++ b/Mac/Modules/ctl/Ctlmodule.c @@ -0,0 +1,691 @@ + +/* =========================== Module Ctl =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include +#include +#include +#include + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ + +extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */ + +#ifdef THINK_C +#define ControlActionUPP ProcPtr +#endif + +static PyObject *Ctl_Error; + +/* ---------------------- Object type Control ----------------------- */ + +PyTypeObject Control_Type; + +#define CtlObj_Check(x) ((x)->ob_type == &Control_Type) + +typedef struct ControlObject { + PyObject_HEAD + ControlHandle ob_itself; +} ControlObject; + +PyObject *CtlObj_New(itself) + const ControlHandle itself; +{ + ControlObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + it = PyObject_NEW(ControlObject, &Control_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + SetCRefCon(itself, (long)it); + return (PyObject *)it; +} +CtlObj_Convert(v, p_itself) + PyObject *v; + ControlHandle *p_itself; +{ + if (!CtlObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "Control required"); + return 0; + } + *p_itself = ((ControlObject *)v)->ob_itself; + return 1; +} + +static void CtlObj_dealloc(self) + ControlObject *self; +{ + /* Cleanup of self->ob_itself goes here */ + PyMem_DEL(self); +} + +static PyObject *CtlObj_SetCTitle(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 title; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, title)) + return NULL; + SetCTitle(_self->ob_itself, + title); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_GetCTitle(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 title; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, title)) + return NULL; + GetCTitle(_self->ob_itself, + title); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_DisposeControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DisposeControl(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_HideControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + HideControl(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_ShowControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ShowControl(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_Draw1Control(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + Draw1Control(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_HiliteControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short hiliteState; + if (!PyArg_ParseTuple(_args, "h", + &hiliteState)) + return NULL; + HiliteControl(_self->ob_itself, + hiliteState); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_MoveControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short h; + short v; + if (!PyArg_ParseTuple(_args, "hh", + &h, + &v)) + return NULL; + MoveControl(_self->ob_itself, + h, + v); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_SizeControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short w; + short h; + if (!PyArg_ParseTuple(_args, "hh", + &w, + &h)) + return NULL; + SizeControl(_self->ob_itself, + w, + h); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_SetCtlValue(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short theValue; + if (!PyArg_ParseTuple(_args, "h", + &theValue)) + return NULL; + SetCtlValue(_self->ob_itself, + theValue); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_GetCtlValue(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetCtlValue(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *CtlObj_SetCtlMin(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short minValue; + if (!PyArg_ParseTuple(_args, "h", + &minValue)) + return NULL; + SetCtlMin(_self->ob_itself, + minValue); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_GetCtlMin(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetCtlMin(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *CtlObj_SetCtlMax(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short maxValue; + if (!PyArg_ParseTuple(_args, "h", + &maxValue)) + return NULL; + SetCtlMax(_self->ob_itself, + maxValue); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_GetCtlMax(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetCtlMax(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *CtlObj_SetCRefCon(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long data; + if (!PyArg_ParseTuple(_args, "l", + &data)) + return NULL; + SetCRefCon(_self->ob_itself, + data); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_GetCRefCon(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetCRefCon(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CtlObj_DragControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point startPt; + Rect limitRect; + Rect slopRect; + short axis; + if (!PyArg_ParseTuple(_args, "O&O&O&h", + PyMac_GetPoint, &startPt, + PyMac_GetRect, &limitRect, + PyMac_GetRect, &slopRect, + &axis)) + return NULL; + DragControl(_self->ob_itself, + startPt, + &limitRect, + &slopRect, + axis); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_TestControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Point thePt; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePt)) + return NULL; + _rv = TestControl(_self->ob_itself, + thePt); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *CtlObj_TrackControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Point thePoint; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePoint)) + return NULL; + _rv = TrackControl(_self->ob_itself, + thePoint, + (ControlActionUPP)0); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *CtlObj_GetCVariant(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetCVariant(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyMethodDef CtlObj_methods[] = { + {"SetCTitle", (PyCFunction)CtlObj_SetCTitle, 1, + "(Str255 title) -> None"}, + {"GetCTitle", (PyCFunction)CtlObj_GetCTitle, 1, + "(Str255 title) -> None"}, + {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1, + "() -> None"}, + {"HideControl", (PyCFunction)CtlObj_HideControl, 1, + "() -> None"}, + {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1, + "() -> None"}, + {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1, + "() -> None"}, + {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1, + "(short hiliteState) -> None"}, + {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1, + "(short h, short v) -> None"}, + {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1, + "(short w, short h) -> None"}, + {"SetCtlValue", (PyCFunction)CtlObj_SetCtlValue, 1, + "(short theValue) -> None"}, + {"GetCtlValue", (PyCFunction)CtlObj_GetCtlValue, 1, + "() -> (short _rv)"}, + {"SetCtlMin", (PyCFunction)CtlObj_SetCtlMin, 1, + "(short minValue) -> None"}, + {"GetCtlMin", (PyCFunction)CtlObj_GetCtlMin, 1, + "() -> (short _rv)"}, + {"SetCtlMax", (PyCFunction)CtlObj_SetCtlMax, 1, + "(short maxValue) -> None"}, + {"GetCtlMax", (PyCFunction)CtlObj_GetCtlMax, 1, + "() -> (short _rv)"}, + {"SetCRefCon", (PyCFunction)CtlObj_SetCRefCon, 1, + "(long data) -> None"}, + {"GetCRefCon", (PyCFunction)CtlObj_GetCRefCon, 1, + "() -> (long _rv)"}, + {"DragControl", (PyCFunction)CtlObj_DragControl, 1, + "(Point startPt, Rect limitRect, Rect slopRect, short axis) -> None"}, + {"TestControl", (PyCFunction)CtlObj_TestControl, 1, + "(Point thePt) -> (short _rv)"}, + {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1, + "(Point thePoint) -> (short _rv)"}, + {"GetCVariant", (PyCFunction)CtlObj_GetCVariant, 1, + "() -> (short _rv)"}, + {NULL, NULL, 0} +}; + +PyMethodChain CtlObj_chain = { CtlObj_methods, NULL }; + +static PyObject *CtlObj_getattr(self, name) + ControlObject *self; + char *name; +{ + return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name); +} + +#define CtlObj_setattr NULL + +PyTypeObject Control_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Control", /*tp_name*/ + sizeof(ControlObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) CtlObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) CtlObj_getattr, /*tp_getattr*/ + (setattrfunc) CtlObj_setattr, /*tp_setattr*/ +}; + +/* -------------------- End object type Control --------------------- */ + + +static PyObject *Ctl_NewControl(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ControlHandle _rv; + WindowPtr theWindow; + Rect boundsRect; + Str255 title; + Boolean visible; + short value; + short min; + short max; + short procID; + long refCon; + if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl", + WinObj_Convert, &theWindow, + PyMac_GetRect, &boundsRect, + PyMac_GetStr255, title, + &visible, + &value, + &min, + &max, + &procID, + &refCon)) + return NULL; + _rv = NewControl(theWindow, + &boundsRect, + title, + visible, + value, + min, + max, + procID, + refCon); + _res = Py_BuildValue("O&", + CtlObj_New, _rv); + return _res; +} + +static PyObject *Ctl_GetNewControl(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ControlHandle _rv; + short controlID; + WindowPtr owner; + if (!PyArg_ParseTuple(_args, "hO&", + &controlID, + WinObj_Convert, &owner)) + return NULL; + _rv = GetNewControl(controlID, + owner); + _res = Py_BuildValue("O&", + CtlObj_New, _rv); + return _res; +} + +static PyObject *Ctl_KillControls(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr theWindow; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &theWindow)) + return NULL; + KillControls(theWindow); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Ctl_DrawControls(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr theWindow; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &theWindow)) + return NULL; + DrawControls(theWindow); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Ctl_UpdtControl(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr theWindow; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &theWindow)) + return NULL; + UpdtControl(theWindow, + theWindow->visRgn); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Ctl_UpdateControls(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr theWindow; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &theWindow)) + return NULL; + UpdateControls(theWindow, + theWindow->visRgn); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Ctl_FindControl(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Point thePoint; + WindowPtr theWindow; + ControlHandle theControl; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetPoint, &thePoint, + WinObj_Convert, &theWindow)) + return NULL; + _rv = FindControl(thePoint, + theWindow, + &theControl); + _res = Py_BuildValue("hO&", + _rv, + CtlObj_WhichControl, theControl); + return _res; +} + +static PyMethodDef Ctl_methods[] = { + {"NewControl", (PyCFunction)Ctl_NewControl, 1, + "(WindowPtr theWindow, Rect boundsRect, Str255 title, Boolean visible, short value, short min, short max, short procID, long refCon) -> (ControlHandle _rv)"}, + {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1, + "(short controlID, WindowPtr owner) -> (ControlHandle _rv)"}, + {"KillControls", (PyCFunction)Ctl_KillControls, 1, + "(WindowPtr theWindow) -> None"}, + {"DrawControls", (PyCFunction)Ctl_DrawControls, 1, + "(WindowPtr theWindow) -> None"}, + {"UpdtControl", (PyCFunction)Ctl_UpdtControl, 1, + "(WindowPtr theWindow) -> None"}, + {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1, + "(WindowPtr theWindow) -> None"}, + {"FindControl", (PyCFunction)Ctl_FindControl, 1, + "(Point thePoint, WindowPtr theWindow) -> (short _rv, ControlHandle theControl)"}, + {NULL, NULL, 0} +}; + + + +PyObject * +CtlObj_WhichControl(ControlHandle c) +{ + PyObject *it; + + /* XXX What if we find a control belonging to some other package? */ + if (c == NULL) + it = NULL; + else + it = (PyObject *) GetCRefCon(c); + if (it == NULL || ((ControlObject *)it)->ob_itself != c) + it = Py_None; + Py_INCREF(it); + return it; +} + + +void initCtl() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Ctl", Ctl_methods); + d = PyModule_GetDict(m); + Ctl_Error = PyMac_GetOSErrException(); + if (Ctl_Error == NULL || + PyDict_SetItemString(d, "Error", Ctl_Error) != 0) + Py_FatalError("can't initialize Ctl.Error"); +} + +/* ========================= End module Ctl ========================= */ + diff --git a/Mac/Modules/ctl/ctlgen.py b/Mac/Modules/ctl/ctlgen.py new file mode 100644 index 0000000..fcbf0f4 --- /dev/null +++ b/Mac/Modules/ctl/ctlgen.py @@ -0,0 +1,172 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Controls.h' + +f = Function(ControlHandle, 'NewControl', + (WindowPtr, 'theWindow', InMode), + (Rect_ptr, 'boundsRect', InMode), + (ConstStr255Param, 'title', InMode), + (Boolean, 'visible', InMode), + (short, 'value', InMode), + (short, 'min', InMode), + (short, 'max', InMode), + (short, 'procID', InMode), + (long, 'refCon', InMode), +) +functions.append(f) + +f = Method(void, 'SetCTitle', + (ControlHandle, 'theControl', InMode), + (ConstStr255Param, 'title', InMode), +) +methods.append(f) + +f = Method(void, 'GetCTitle', + (ControlHandle, 'theControl', InMode), + (Str255, 'title', InMode), +) +methods.append(f) + +f = Function(ControlHandle, 'GetNewControl', + (short, 'controlID', InMode), + (WindowPtr, 'owner', InMode), +) +functions.append(f) + +f = Method(void, 'DisposeControl', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Function(void, 'KillControls', + (WindowPtr, 'theWindow', InMode), +) +functions.append(f) + +f = Method(void, 'HideControl', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'ShowControl', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Function(void, 'DrawControls', + (WindowPtr, 'theWindow', InMode), +) +functions.append(f) + +f = Method(void, 'Draw1Control', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'HiliteControl', + (ControlHandle, 'theControl', InMode), + (short, 'hiliteState', InMode), +) +methods.append(f) + +f = Function(void, 'UpdtControl', + (WindowPtr, 'theWindow', InMode), + (RgnHandle, 'updateRgn', InMode), +) +functions.append(f) + +f = Function(void, 'UpdateControls', + (WindowPtr, 'theWindow', InMode), + (RgnHandle, 'updateRgn', InMode), +) +functions.append(f) + +f = Method(void, 'MoveControl', + (ControlHandle, 'theControl', InMode), + (short, 'h', InMode), + (short, 'v', InMode), +) +methods.append(f) + +f = Method(void, 'SizeControl', + (ControlHandle, 'theControl', InMode), + (short, 'w', InMode), + (short, 'h', InMode), +) +methods.append(f) + +f = Method(void, 'SetCtlValue', + (ControlHandle, 'theControl', InMode), + (short, 'theValue', InMode), +) +methods.append(f) + +f = Method(short, 'GetCtlValue', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'SetCtlMin', + (ControlHandle, 'theControl', InMode), + (short, 'minValue', InMode), +) +methods.append(f) + +f = Method(short, 'GetCtlMin', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'SetCtlMax', + (ControlHandle, 'theControl', InMode), + (short, 'maxValue', InMode), +) +methods.append(f) + +f = Method(short, 'GetCtlMax', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'SetCRefCon', + (ControlHandle, 'theControl', InMode), + (long, 'data', InMode), +) +methods.append(f) + +f = Method(long, 'GetCRefCon', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'DragControl', + (ControlHandle, 'theControl', InMode), + (Point, 'startPt', InMode), + (Rect_ptr, 'limitRect', InMode), + (Rect_ptr, 'slopRect', InMode), + (short, 'axis', InMode), +) +methods.append(f) + +f = Method(short, 'TestControl', + (ControlHandle, 'theControl', InMode), + (Point, 'thePt', InMode), +) +methods.append(f) + +f = Method(short, 'TrackControl', + (ControlHandle, 'theControl', InMode), + (Point, 'thePoint', InMode), + (FakeType('(ControlActionUPP)0'), 'actionProc', InMode), +) +methods.append(f) + +f = Function(short, 'FindControl', + (Point, 'thePoint', InMode), + (WindowPtr, 'theWindow', InMode), + (ExistingControlHandle, 'theControl', OutMode), +) +functions.append(f) + +f = Method(short, 'GetCVariant', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) diff --git a/Mac/Modules/ctl/ctlscan.py b/Mac/Modules/ctl/ctlscan.py new file mode 100644 index 0000000..f104e8d --- /dev/null +++ b/Mac/Modules/ctl/ctlscan.py @@ -0,0 +1,60 @@ +# Scan , generating ctlgen.py. + +from scantools import Scanner + +def main(): + input = "Controls.h" + output = "ctlgen.py" + defsoutput = "Controls.py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now doing 'import ctlsupport' ===" + import ctlsupport + print "=== Done. It's up to you to compile Ctlmodule.c ===" + +class MyScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "Function" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t == "ControlHandle" and m == "InMode": + classname = "Method" + listname = "methods" + return classname, listname + + def makeblacklistnames(self): + return [ + 'DisposeControl' # Implied by deletion of control object + 'KillControls', # Implied by close of dialog + 'SetCtlAction', + ] + + def makeblacklisttypes(self): + return [ + 'ProcPtr', + 'CCTabHandle', + 'AuxCtlHandle', + ] + + def makerepairinstructions(self): + return [ + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + + # For TrackControl + ([("ProcPtr", "actionProc", "InMode")], + [("FakeType('(ControlActionUPP)0')", "*", "*")]), + + ([("ControlHandle", "*", "OutMode")], + [("ExistingControlHandle", "*", "*")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/ctl/ctlsupport.py b/Mac/Modules/ctl/ctlsupport.py new file mode 100644 index 0000000..97b1f33 --- /dev/null +++ b/Mac/Modules/ctl/ctlsupport.py @@ -0,0 +1,86 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'Controls.h' # The Apple header file +MODNAME = 'Ctl' # The name of the module +OBJECTNAME = 'Control' # The basic name of the objects used here + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +OBJECTTYPE = OBJECTNAME + 'Handle' # The C type used to represent them +OBJECTPREFIX = MODPREFIX + '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 + +from macsupport import * + +# Create the type objects + +ControlHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) +ExistingControlHandle = OpaqueByValueType(OBJECTTYPE, "CtlObj_WhichControl", "BUG") + +RgnHandle = FakeType("theWindow->visRgn") # XXX + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ + +extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */ + +#ifdef THINK_C +#define ControlActionUPP ProcPtr +#endif +""" + +finalstuff = finalstuff + """ +PyObject * +CtlObj_WhichControl(ControlHandle c) +{ + PyObject *it; + + /* XXX What if we find a control belonging to some other package? */ + if (c == NULL) + it = NULL; + else + it = (PyObject *) GetCRefCon(c); + if (it == NULL || ((ControlObject *)it)->ob_itself != c) + it = Py_None; + Py_INCREF(it); + return it; +} +""" + +class MyObjectDefinition(GlobalObjectDefinition): + def outputCheckNewArg(self): + Output("if (itself == NULL) return PyMac_Error(resNotFound);") + def outputInitStructMembers(self): + GlobalObjectDefinition.outputInitStructMembers(self) + Output("SetCRefCon(itself, (long)it);") + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) +object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) +module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +execfile(INPUTFILE) + +# add the populated lists to the generator groups +for f in functions: module.add(f) +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/dlg/Dlgmodule.c b/Mac/Modules/dlg/Dlgmodule.c new file mode 100644 index 0000000..b03f24f --- /dev/null +++ b/Mac/Modules/dlg/Dlgmodule.c @@ -0,0 +1,905 @@ + +/* =========================== Module Dlg =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include +#include +#include +#include + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ + +/* XXX Shouldn't this be a stack? */ +static PyObject *Dlg_FilterProc_callback = NULL; + +static PyObject *DlgObj_New(DialogPtr); /* Forward */ + +static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog, + EventRecord *event, + short *itemHit) +{ + Boolean rv; + PyObject *args, *res; + PyObject *callback = Dlg_FilterProc_callback; + if (callback == NULL) + return 0; /* Default behavior */ + Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */ + args = Py_BuildValue("O&s#", DlgObj_New, dialog, event, sizeof(EventRecord)); + if (args == NULL) + res = NULL; + else { + res = PyEval_CallObject(callback, args); + Py_DECREF(args); + } + if (res == NULL) { + fprintf(stderr, "Exception in Dialog Filter\n"); + PyErr_Print(); + *itemHit = -1; /* Fake return item */ + return 1; /* We handled it */ + } + else { + Dlg_FilterProc_callback = callback; + if (PyInt_Check(res)) { + *itemHit = PyInt_AsLong(res); + rv = 1; + } + else + rv = PyObject_IsTrue(res); + } + Py_DECREF(res); + return rv; +} + +static ModalFilterProcPtr +Dlg_PassFilterProc(PyObject *callback) +{ + PyObject *tmp = Dlg_FilterProc_callback; + Dlg_FilterProc_callback = NULL; + if (callback == Py_None) { + Py_XDECREF(tmp); + return NULL; + } + Py_INCREF(callback); + Dlg_FilterProc_callback = callback; + Py_XDECREF(tmp); + return &Dlg_UnivFilterProc; +} + +extern PyMethodChain WinObj_chain; + +static PyObject *Dlg_Error; + +/* ----------------------- Object type Dialog ----------------------- */ + +PyTypeObject Dialog_Type; + +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +typedef struct DialogObject { + PyObject_HEAD + DialogPtr ob_itself; +} DialogObject; + +PyObject *DlgObj_New(itself) + const DialogPtr itself; +{ + DialogObject *it; + if (itself == NULL) return Py_None; + it = PyObject_NEW(DialogObject, &Dialog_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + SetWRefCon(itself, (long)it); + return (PyObject *)it; +} +DlgObj_Convert(v, p_itself) + PyObject *v; + DialogPtr *p_itself; +{ + if (v == Py_None) { *p_itself = NULL; return 1; } + if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v); + return 1; } + if (!DlgObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "Dialog required"); + return 0; + } + *p_itself = ((DialogObject *)v)->ob_itself; + return 1; +} + +static void DlgObj_dealloc(self) + DialogObject *self; +{ + DisposeDialog(self->ob_itself); + PyMem_DEL(self); +} + +static PyObject *DlgObj_DrawDialog(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DrawDialog(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_UpdtDialog(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + UpdtDialog(_self->ob_itself, + _self->ob_itself->visRgn); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_UpdateDialog(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + UpdateDialog(_self->ob_itself, + _self->ob_itself->visRgn); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_GetDItem(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short itemNo; + short itemType; + Handle item; + Rect box; + if (!PyArg_ParseTuple(_args, "h", + &itemNo)) + return NULL; + GetDItem(_self->ob_itself, + itemNo, + &itemType, + &item, + &box); + _res = Py_BuildValue("hO&O&", + itemType, + ResObj_New, item, + PyMac_BuildRect, &box); + return _res; +} + +static PyObject *DlgObj_SetDItem(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short itemNo; + short itemType; + Handle item; + Rect box; + if (!PyArg_ParseTuple(_args, "hhO&O&", + &itemNo, + &itemType, + ResObj_Convert, &item, + PyMac_GetRect, &box)) + return NULL; + SetDItem(_self->ob_itself, + itemNo, + itemType, + item, + &box); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_HideDItem(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short itemNo; + if (!PyArg_ParseTuple(_args, "h", + &itemNo)) + return NULL; + HideDItem(_self->ob_itself, + itemNo); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_ShowDItem(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short itemNo; + if (!PyArg_ParseTuple(_args, "h", + &itemNo)) + return NULL; + ShowDItem(_self->ob_itself, + itemNo); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_SelIText(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short itemNo; + short strtSel; + short endSel; + if (!PyArg_ParseTuple(_args, "hhh", + &itemNo, + &strtSel, + &endSel)) + return NULL; + SelIText(_self->ob_itself, + itemNo, + strtSel, + endSel); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_FindDItem(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Point thePt; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePt)) + return NULL; + _rv = FindDItem(_self->ob_itself, + thePt); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *DlgObj_DlgCut(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DlgCut(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_DlgPaste(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DlgPaste(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_DlgCopy(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DlgCopy(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_DlgDelete(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DlgDelete(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_AppendDITL(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle theHandle; + DITLMethod method; + if (!PyArg_ParseTuple(_args, "O&h", + ResObj_Convert, &theHandle, + &method)) + return NULL; + AppendDITL(_self->ob_itself, + theHandle, + method); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_CountDITL(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CountDITL(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *DlgObj_ShortenDITL(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short numberItems; + if (!PyArg_ParseTuple(_args, "h", + &numberItems)) + return NULL; + ShortenDITL(_self->ob_itself, + numberItems); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef DlgObj_methods[] = { + {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1, + "() -> None"}, + {"UpdtDialog", (PyCFunction)DlgObj_UpdtDialog, 1, + "() -> None"}, + {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1, + "() -> None"}, + {"GetDItem", (PyCFunction)DlgObj_GetDItem, 1, + "(short itemNo) -> (short itemType, Handle item, Rect box)"}, + {"SetDItem", (PyCFunction)DlgObj_SetDItem, 1, + "(short itemNo, short itemType, Handle item, Rect box) -> None"}, + {"HideDItem", (PyCFunction)DlgObj_HideDItem, 1, + "(short itemNo) -> None"}, + {"ShowDItem", (PyCFunction)DlgObj_ShowDItem, 1, + "(short itemNo) -> None"}, + {"SelIText", (PyCFunction)DlgObj_SelIText, 1, + "(short itemNo, short strtSel, short endSel) -> None"}, + {"FindDItem", (PyCFunction)DlgObj_FindDItem, 1, + "(Point thePt) -> (short _rv)"}, + {"DlgCut", (PyCFunction)DlgObj_DlgCut, 1, + "() -> None"}, + {"DlgPaste", (PyCFunction)DlgObj_DlgPaste, 1, + "() -> None"}, + {"DlgCopy", (PyCFunction)DlgObj_DlgCopy, 1, + "() -> None"}, + {"DlgDelete", (PyCFunction)DlgObj_DlgDelete, 1, + "() -> None"}, + {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1, + "(Handle theHandle, DITLMethod method) -> None"}, + {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1, + "() -> (short _rv)"}, + {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1, + "(short numberItems) -> None"}, + {NULL, NULL, 0} +}; + +PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain }; + +static PyObject *DlgObj_getattr(self, name) + DialogObject *self; + char *name; +{ + return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name); +} + +#define DlgObj_setattr NULL + +PyTypeObject Dialog_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Dialog", /*tp_name*/ + sizeof(DialogObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) DlgObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) DlgObj_getattr, /*tp_getattr*/ + (setattrfunc) DlgObj_setattr, /*tp_setattr*/ +}; + +/* --------------------- End object type Dialog --------------------- */ + + +static PyObject *Dlg_NewDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + DialogPtr _rv; + Rect boundsRect; + Str255 title; + Boolean visible; + short procID; + WindowPtr behind; + Boolean goAwayFlag; + long refCon; + Handle itmLstHndl; + if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", + PyMac_GetRect, &boundsRect, + PyMac_GetStr255, title, + &visible, + &procID, + WinObj_Convert, &behind, + &goAwayFlag, + &refCon, + ResObj_Convert, &itmLstHndl)) + return NULL; + _rv = NewDialog((void *)0, + &boundsRect, + title, + visible, + procID, + behind, + goAwayFlag, + refCon, + itmLstHndl); + _res = Py_BuildValue("O&", + DlgObj_New, _rv); + return _res; +} + +static PyObject *Dlg_GetNewDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + DialogPtr _rv; + short dialogID; + WindowPtr behind; + if (!PyArg_ParseTuple(_args, "hO&", + &dialogID, + WinObj_Convert, &behind)) + return NULL; + _rv = GetNewDialog(dialogID, + (void *)0, + behind); + _res = Py_BuildValue("O&", + DlgObj_New, _rv); + return _res; +} + +static PyObject *Dlg_CouldDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short dialogID; + if (!PyArg_ParseTuple(_args, "h", + &dialogID)) + return NULL; + CouldDialog(dialogID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_FreeDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short dialogID; + if (!PyArg_ParseTuple(_args, "h", + &dialogID)) + return NULL; + FreeDialog(dialogID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_ParamText(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 param0; + Str255 param1; + Str255 param2; + Str255 param3; + if (!PyArg_ParseTuple(_args, "O&O&O&O&", + PyMac_GetStr255, param0, + PyMac_GetStr255, param1, + PyMac_GetStr255, param2, + PyMac_GetStr255, param3)) + return NULL; + ParamText(param0, + param1, + param2, + param3); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_ModalDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + PyObject* filterProc; + short itemHit; + if (!PyArg_ParseTuple(_args, "O", + &filterProc)) + return NULL; + ModalDialog(Dlg_PassFilterProc(filterProc), + &itemHit); + _res = Py_BuildValue("h", + itemHit); + return _res; +} + +static PyObject *Dlg_IsDialogEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + EventRecord theEvent; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetEventRecord, &theEvent)) + return NULL; + _rv = IsDialogEvent(&theEvent); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Dlg_DialogSelect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + EventRecord theEvent; + DialogPtr theDialog; + short itemHit; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetEventRecord, &theEvent)) + return NULL; + _rv = DialogSelect(&theEvent, + &theDialog, + &itemHit); + _res = Py_BuildValue("bO&h", + _rv, + WinObj_WhichWindow, theDialog, + itemHit); + return _res; +} + +static PyObject *Dlg_Alert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short alertID; + PyObject* filterProc; + if (!PyArg_ParseTuple(_args, "hO", + &alertID, + &filterProc)) + return NULL; + _rv = Alert(alertID, + Dlg_PassFilterProc(filterProc)); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Dlg_StopAlert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short alertID; + PyObject* filterProc; + if (!PyArg_ParseTuple(_args, "hO", + &alertID, + &filterProc)) + return NULL; + _rv = StopAlert(alertID, + Dlg_PassFilterProc(filterProc)); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Dlg_NoteAlert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short alertID; + PyObject* filterProc; + if (!PyArg_ParseTuple(_args, "hO", + &alertID, + &filterProc)) + return NULL; + _rv = NoteAlert(alertID, + Dlg_PassFilterProc(filterProc)); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Dlg_CautionAlert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short alertID; + PyObject* filterProc; + if (!PyArg_ParseTuple(_args, "hO", + &alertID, + &filterProc)) + return NULL; + _rv = CautionAlert(alertID, + Dlg_PassFilterProc(filterProc)); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Dlg_CouldAlert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short alertID; + if (!PyArg_ParseTuple(_args, "h", + &alertID)) + return NULL; + CouldAlert(alertID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_FreeAlert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short alertID; + if (!PyArg_ParseTuple(_args, "h", + &alertID)) + return NULL; + FreeAlert(alertID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_GetIText(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle item; + Str255 text; + if (!PyArg_ParseTuple(_args, "O&", + ResObj_Convert, &item)) + return NULL; + GetIText(item, + text); + _res = Py_BuildValue("O&", + PyMac_BuildStr255, text); + return _res; +} + +static PyObject *Dlg_SetIText(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle item; + Str255 text; + if (!PyArg_ParseTuple(_args, "O&O&", + ResObj_Convert, &item, + PyMac_GetStr255, text)) + return NULL; + SetIText(item, + text); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_NewCDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + DialogPtr _rv; + Rect boundsRect; + Str255 title; + Boolean visible; + short procID; + WindowPtr behind; + Boolean goAwayFlag; + long refCon; + Handle items; + if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", + PyMac_GetRect, &boundsRect, + PyMac_GetStr255, title, + &visible, + &procID, + WinObj_Convert, &behind, + &goAwayFlag, + &refCon, + ResObj_Convert, &items)) + return NULL; + _rv = NewCDialog((void *)0, + &boundsRect, + title, + visible, + procID, + behind, + goAwayFlag, + refCon, + items); + _res = Py_BuildValue("O&", + DlgObj_New, _rv); + return _res; +} + +static PyObject *Dlg_ResetAlrtStage(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ResetAlrtStage(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_SetDAFont(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short fontNum; + if (!PyArg_ParseTuple(_args, "h", + &fontNum)) + return NULL; + SetDAFont(fontNum); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef Dlg_methods[] = { + {"NewDialog", (PyCFunction)Dlg_NewDialog, 1, + "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle itmLstHndl) -> (DialogPtr _rv)"}, + {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1, + "(short dialogID, WindowPtr behind) -> (DialogPtr _rv)"}, + {"CouldDialog", (PyCFunction)Dlg_CouldDialog, 1, + "(short dialogID) -> None"}, + {"FreeDialog", (PyCFunction)Dlg_FreeDialog, 1, + "(short dialogID) -> None"}, + {"ParamText", (PyCFunction)Dlg_ParamText, 1, + "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"}, + {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1, + "(PyObject* filterProc) -> (short itemHit)"}, + {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1, + "(EventRecord theEvent) -> (Boolean _rv)"}, + {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1, + "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, short itemHit)"}, + {"Alert", (PyCFunction)Dlg_Alert, 1, + "(short alertID, PyObject* filterProc) -> (short _rv)"}, + {"StopAlert", (PyCFunction)Dlg_StopAlert, 1, + "(short alertID, PyObject* filterProc) -> (short _rv)"}, + {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1, + "(short alertID, PyObject* filterProc) -> (short _rv)"}, + {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1, + "(short alertID, PyObject* filterProc) -> (short _rv)"}, + {"CouldAlert", (PyCFunction)Dlg_CouldAlert, 1, + "(short alertID) -> None"}, + {"FreeAlert", (PyCFunction)Dlg_FreeAlert, 1, + "(short alertID) -> None"}, + {"GetIText", (PyCFunction)Dlg_GetIText, 1, + "(Handle item) -> (Str255 text)"}, + {"SetIText", (PyCFunction)Dlg_SetIText, 1, + "(Handle item, Str255 text) -> None"}, + {"NewCDialog", (PyCFunction)Dlg_NewCDialog, 1, + "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle items) -> (DialogPtr _rv)"}, + {"ResetAlrtStage", (PyCFunction)Dlg_ResetAlrtStage, 1, + "() -> None"}, + {"SetDAFont", (PyCFunction)Dlg_SetDAFont, 1, + "(short fontNum) -> None"}, + {NULL, NULL, 0} +}; + + + + +void initDlg() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Dlg", Dlg_methods); + d = PyModule_GetDict(m); + Dlg_Error = PyMac_GetOSErrException(); + if (Dlg_Error == NULL || + PyDict_SetItemString(d, "Error", Dlg_Error) != 0) + Py_FatalError("can't initialize Dlg.Error"); +} + +/* ========================= End module Dlg ========================= */ + diff --git a/Mac/Modules/dlg/dlggen.py b/Mac/Modules/dlg/dlggen.py new file mode 100644 index 0000000..ea64ab7 --- /dev/null +++ b/Mac/Modules/dlg/dlggen.py @@ -0,0 +1,224 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Dialogs.h' + +f = Function(DialogPtr, 'NewDialog', + (NullStorage, 'wStorage', InMode), + (Rect_ptr, 'boundsRect', InMode), + (ConstStr255Param, 'title', InMode), + (Boolean, 'visible', InMode), + (short, 'procID', InMode), + (WindowPtr, 'behind', InMode), + (Boolean, 'goAwayFlag', InMode), + (long, 'refCon', InMode), + (Handle, 'itmLstHndl', InMode), +) +functions.append(f) + +f = Function(DialogPtr, 'GetNewDialog', + (short, 'dialogID', InMode), + (NullStorage, 'dStorage', InMode), + (WindowPtr, 'behind', InMode), +) +functions.append(f) + +f = Function(void, 'CouldDialog', + (short, 'dialogID', InMode), +) +functions.append(f) + +f = Function(void, 'FreeDialog', + (short, 'dialogID', InMode), +) +functions.append(f) + +f = Function(void, 'ParamText', + (ConstStr255Param, 'param0', InMode), + (ConstStr255Param, 'param1', InMode), + (ConstStr255Param, 'param2', InMode), + (ConstStr255Param, 'param3', InMode), +) +functions.append(f) + +f = Function(void, 'ModalDialog', + (ModalFilterProcPtr, 'filterProc', InMode), + (short, 'itemHit', OutMode), +) +functions.append(f) + +f = Function(Boolean, 'IsDialogEvent', + (EventRecord_ptr, 'theEvent', InMode), +) +functions.append(f) + +f = Function(Boolean, 'DialogSelect', + (EventRecord_ptr, 'theEvent', InMode), + (ExistingDialogPtr, 'theDialog', OutMode), + (short, 'itemHit', OutMode), +) +functions.append(f) + +f = Method(void, 'DrawDialog', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Method(void, 'UpdtDialog', + (DialogPtr, 'theDialog', InMode), + (RgnHandle, 'updateRgn', InMode), +) +methods.append(f) + +f = Method(void, 'UpdateDialog', + (DialogPtr, 'theDialog', InMode), + (RgnHandle, 'updateRgn', InMode), +) +methods.append(f) + +f = Function(short, 'Alert', + (short, 'alertID', InMode), + (ModalFilterProcPtr, 'filterProc', InMode), +) +functions.append(f) + +f = Function(short, 'StopAlert', + (short, 'alertID', InMode), + (ModalFilterProcPtr, 'filterProc', InMode), +) +functions.append(f) + +f = Function(short, 'NoteAlert', + (short, 'alertID', InMode), + (ModalFilterProcPtr, 'filterProc', InMode), +) +functions.append(f) + +f = Function(short, 'CautionAlert', + (short, 'alertID', InMode), + (ModalFilterProcPtr, 'filterProc', InMode), +) +functions.append(f) + +f = Function(void, 'CouldAlert', + (short, 'alertID', InMode), +) +functions.append(f) + +f = Function(void, 'FreeAlert', + (short, 'alertID', InMode), +) +functions.append(f) + +f = Method(void, 'GetDItem', + (DialogPtr, 'theDialog', InMode), + (short, 'itemNo', InMode), + (short, 'itemType', OutMode), + (Handle, 'item', OutMode), + (Rect, 'box', OutMode), +) +methods.append(f) + +f = Method(void, 'SetDItem', + (DialogPtr, 'theDialog', InMode), + (short, 'itemNo', InMode), + (short, 'itemType', InMode), + (Handle, 'item', InMode), + (Rect_ptr, 'box', InMode), +) +methods.append(f) + +f = Method(void, 'HideDItem', + (DialogPtr, 'theDialog', InMode), + (short, 'itemNo', InMode), +) +methods.append(f) + +f = Method(void, 'ShowDItem', + (DialogPtr, 'theDialog', InMode), + (short, 'itemNo', InMode), +) +methods.append(f) + +f = Method(void, 'SelIText', + (DialogPtr, 'theDialog', InMode), + (short, 'itemNo', InMode), + (short, 'strtSel', InMode), + (short, 'endSel', InMode), +) +methods.append(f) + +f = Function(void, 'GetIText', + (Handle, 'item', InMode), + (Str255, 'text', OutMode), +) +functions.append(f) + +f = Function(void, 'SetIText', + (Handle, 'item', InMode), + (ConstStr255Param, 'text', InMode), +) +functions.append(f) + +f = Method(short, 'FindDItem', + (DialogPtr, 'theDialog', InMode), + (Point, 'thePt', InMode), +) +methods.append(f) + +f = Function(DialogPtr, 'NewCDialog', + (NullStorage, 'dStorage', InMode), + (Rect_ptr, 'boundsRect', InMode), + (ConstStr255Param, 'title', InMode), + (Boolean, 'visible', InMode), + (short, 'procID', InMode), + (WindowPtr, 'behind', InMode), + (Boolean, 'goAwayFlag', InMode), + (long, 'refCon', InMode), + (Handle, 'items', InMode), +) +functions.append(f) + +f = Function(void, 'ResetAlrtStage', +) +functions.append(f) + +f = Method(void, 'DlgCut', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Method(void, 'DlgPaste', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Method(void, 'DlgCopy', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Method(void, 'DlgDelete', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Function(void, 'SetDAFont', + (short, 'fontNum', InMode), +) +functions.append(f) + +f = Method(void, 'AppendDITL', + (DialogPtr, 'theDialog', InMode), + (Handle, 'theHandle', InMode), + (DITLMethod, 'method', InMode), +) +methods.append(f) + +f = Method(short, 'CountDITL', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Method(void, 'ShortenDITL', + (DialogPtr, 'theDialog', InMode), + (short, 'numberItems', InMode), +) +methods.append(f) diff --git a/Mac/Modules/dlg/dlgscan.py b/Mac/Modules/dlg/dlgscan.py new file mode 100644 index 0000000..2a410f6 --- /dev/null +++ b/Mac/Modules/dlg/dlgscan.py @@ -0,0 +1,67 @@ +# Scan an Apple header file, generating a Python file of generator calls. + +from scantools import Scanner + +LONG = "Dialogs" +SHORT = "dlg" +OBJECT = "DialogPtr" + +def main(): + input = LONG + ".h" + output = SHORT + "gen.py" + defsoutput = LONG + ".py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + 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] + if t == "DialogPtr" and m == "InMode": + classname = "Method" + listname = "methods" + return classname, listname + + def makeblacklistnames(self): + return [ + 'InitDialogs', + 'ErrorSound', + # Dialogs are disposed when the object is deleted + 'CloseDialog', + 'DisposDialog', + 'DisposeDialog', + ] + + def makeblacklisttypes(self): + return [ + ] + + def makerepairinstructions(self): + return [ + ([("Str255", "*", "InMode")], + [("*", "*", "OutMode")]), + + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + + # NewDialog ETC. + ([("void", "*", "OutMode")], + [("NullStorage", "*", "InMode")]), + + ([("DialogPtr", "*", "OutMode")], + [("ExistingDialogPtr", "*", "*")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/dlg/dlgsupport.py b/Mac/Modules/dlg/dlgsupport.py new file mode 100644 index 0000000..85e72bb --- /dev/null +++ b/Mac/Modules/dlg/dlgsupport.py @@ -0,0 +1,121 @@ +# This script generates the Dialogs interface for Python. +# It uses the "bgen" package to generate C code. +# It execs the file dlggen.py which contain the function definitions +# (dlggen.py was generated by dlgscan.py, scanning the header file). + +from macsupport import * + +# Create the type objects + +DialogPtr = OpaqueByValueType("DialogPtr", "DlgObj") + +ModalFilterProcPtr = InputOnlyType("PyObject*", "O") +ModalFilterProcPtr.passInput = lambda name: "Dlg_PassFilterProc(%s)" % name + +RgnHandle = FakeType("_self->ob_itself->visRgn") # XXX + +DITLMethod = Type("DITLMethod", "h") + +includestuff = includestuff + """ +#include + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ + +/* XXX Shouldn't this be a stack? */ +static PyObject *Dlg_FilterProc_callback = NULL; + +static PyObject *DlgObj_New(DialogPtr); /* Forward */ + +static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog, + EventRecord *event, + short *itemHit) +{ + Boolean rv; + PyObject *args, *res; + PyObject *callback = Dlg_FilterProc_callback; + if (callback == NULL) + return 0; /* Default behavior */ + Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */ + args = Py_BuildValue("O&s#", DlgObj_New, dialog, event, sizeof(EventRecord)); + if (args == NULL) + res = NULL; + else { + res = PyEval_CallObject(callback, args); + Py_DECREF(args); + } + if (res == NULL) { + fprintf(stderr, "Exception in Dialog Filter\\n"); + PyErr_Print(); + *itemHit = -1; /* Fake return item */ + return 1; /* We handled it */ + } + else { + Dlg_FilterProc_callback = callback; + if (PyInt_Check(res)) { + *itemHit = PyInt_AsLong(res); + rv = 1; + } + else + rv = PyObject_IsTrue(res); + } + Py_DECREF(res); + return rv; +} + +static ModalFilterProcPtr +Dlg_PassFilterProc(PyObject *callback) +{ + PyObject *tmp = Dlg_FilterProc_callback; + Dlg_FilterProc_callback = NULL; + if (callback == Py_None) { + Py_XDECREF(tmp); + return NULL; + } + Py_INCREF(callback); + Dlg_FilterProc_callback = callback; + Py_XDECREF(tmp); + return &Dlg_UnivFilterProc; +} + +extern PyMethodChain WinObj_chain; +""" + + +# Define a class which specializes our object definition +class MyObjectDefinition(GlobalObjectDefinition): + def __init__(self, name, prefix = None, itselftype = None): + GlobalObjectDefinition.__init__(self, name, prefix, itselftype) + self.basechain = "&WinObj_chain" + def outputInitStructMembers(self): + GlobalObjectDefinition.outputInitStructMembers(self) + Output("SetWRefCon(itself, (long)it);") + def outputCheckNewArg(self): + Output("if (itself == NULL) return Py_None;") + def outputCheckConvertArg(self): + Output("if (v == Py_None) { *p_itself = NULL; return 1; }") + Output("if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);") + Output(" return 1; }") + def outputFreeIt(self, itselfname): + Output("DisposeDialog(%s);", itselfname) + +# Create the generator groups and link them +module = MacModule('Dlg', 'Dlg', includestuff, finalstuff, initstuff) +object = MyObjectDefinition('Dialog', 'DlgObj', 'DialogPtr') +module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +execfile("dlggen.py") + +# add the populated lists to the generator groups +for f in functions: module.add(f) +for f in methods: object.add(f) + +# generate output +SetOutputFileName('Dlgmodule.c') +module.generate() diff --git a/Mac/Modules/evt/Evtmodule.c b/Mac/Modules/evt/Evtmodule.c new file mode 100644 index 0000000..074a33e --- /dev/null +++ b/Mac/Modules/evt/Evtmodule.c @@ -0,0 +1,228 @@ + +/* =========================== Module Evt =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include +#include +#include +#include + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +#include + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ + +static PyObject *Evt_Error; + +static PyObject *Evt_GetNextEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + short eventMask; + EventRecord theEvent; + if (!PyArg_ParseTuple(_args, "h", + &eventMask)) + return NULL; + _rv = GetNextEvent(eventMask, + &theEvent); + _res = Py_BuildValue("bO&", + _rv, + PyMac_BuildEventRecord, &theEvent); + return _res; +} + +static PyObject *Evt_WaitNextEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + short eventMask; + EventRecord theEvent; + unsigned long sleep; + if (!PyArg_ParseTuple(_args, "hl", + &eventMask, + &sleep)) + return NULL; + _rv = WaitNextEvent(eventMask, + &theEvent, + sleep, + (RgnHandle)0); + _res = Py_BuildValue("bO&", + _rv, + PyMac_BuildEventRecord, &theEvent); + return _res; +} + +static PyObject *Evt_EventAvail(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + short eventMask; + EventRecord theEvent; + if (!PyArg_ParseTuple(_args, "h", + &eventMask)) + return NULL; + _rv = EventAvail(eventMask, + &theEvent); + _res = Py_BuildValue("bO&", + _rv, + PyMac_BuildEventRecord, &theEvent); + return _res; +} + +static PyObject *Evt_GetMouse(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point mouseLoc; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + GetMouse(&mouseLoc); + _res = Py_BuildValue("O&", + PyMac_BuildPoint, mouseLoc); + return _res; +} + +static PyObject *Evt_Button(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = Button(); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Evt_StillDown(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = StillDown(); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Evt_WaitMouseUp(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = WaitMouseUp(); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Evt_GetKeys(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + KeyMap theKeys__out__; + int theKeys__len__; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + GetKeys(theKeys__out__); + _res = Py_BuildValue("s#", + (char *)&theKeys__out__, sizeof(KeyMap)); + theKeys__error__: ; + return _res; +} + +static PyObject *Evt_TickCount(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = TickCount(); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyMethodDef Evt_methods[] = { + {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1, + "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"}, + {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1, + "(short eventMask, unsigned long sleep) -> (Boolean _rv, EventRecord theEvent)"}, + {"EventAvail", (PyCFunction)Evt_EventAvail, 1, + "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"}, + {"GetMouse", (PyCFunction)Evt_GetMouse, 1, + "() -> (Point mouseLoc)"}, + {"Button", (PyCFunction)Evt_Button, 1, + "() -> (Boolean _rv)"}, + {"StillDown", (PyCFunction)Evt_StillDown, 1, + "() -> (Boolean _rv)"}, + {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1, + "() -> (Boolean _rv)"}, + {"GetKeys", (PyCFunction)Evt_GetKeys, 1, + "() -> (KeyMap theKeys)"}, + {"TickCount", (PyCFunction)Evt_TickCount, 1, + "() -> (long _rv)"}, + {NULL, NULL, 0} +}; + + + + +void initEvt() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Evt", Evt_methods); + d = PyModule_GetDict(m); + Evt_Error = PyMac_GetOSErrException(); + if (Evt_Error == NULL || + PyDict_SetItemString(d, "Error", Evt_Error) != 0) + Py_FatalError("can't initialize Evt.Error"); +} + +/* ========================= End module Evt ========================= */ + diff --git a/Mac/Modules/evt/evtgen.py b/Mac/Modules/evt/evtgen.py new file mode 100644 index 0000000..ff30b8d --- /dev/null +++ b/Mac/Modules/evt/evtgen.py @@ -0,0 +1,47 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Events.h' + +f = Function(Boolean, 'GetNextEvent', + (short, 'eventMask', InMode), + (EventRecord, 'theEvent', OutMode), +) +functions.append(f) + +f = Function(Boolean, 'WaitNextEvent', + (short, 'eventMask', InMode), + (EventRecord, 'theEvent', OutMode), + (unsigned_long, 'sleep', InMode), + (RgnHandle, 'mouseRgn', InMode), +) +functions.append(f) + +f = Function(Boolean, 'EventAvail', + (short, 'eventMask', InMode), + (EventRecord, 'theEvent', OutMode), +) +functions.append(f) + +f = Function(void, 'GetMouse', + (Point, 'mouseLoc', OutMode), +) +functions.append(f) + +f = Function(Boolean, 'Button', +) +functions.append(f) + +f = Function(Boolean, 'StillDown', +) +functions.append(f) + +f = Function(Boolean, 'WaitMouseUp', +) +functions.append(f) + +f = Function(void, 'GetKeys', + (KeyMap, 'theKeys', OutMode), +) +functions.append(f) + +f = Function(long, 'TickCount', +) +functions.append(f) diff --git a/Mac/Modules/evt/evtscan.py b/Mac/Modules/evt/evtscan.py new file mode 100644 index 0000000..517db71 --- /dev/null +++ b/Mac/Modules/evt/evtscan.py @@ -0,0 +1,59 @@ +# Scan an Apple header file, generating a Python file of generator calls. + +from scantools import Scanner + +LONG = "Events" +SHORT = "evt" +OBJECT = "NOTUSED" + +def main(): + input = LONG + ".h" + output = SHORT + "gen.py" + defsoutput = LONG + ".py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + 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 makeblacklistnames(self): + return [ + ] + + def makeblacklisttypes(self): + return [ + ] + + def makerepairinstructions(self): + return [ + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + + ([("void", "wStorage", "OutMode")], + [("NullStorage", "*", "InMode")]), + + # GetKeys + ([('KeyMap', 'theKeys', 'InMode')], + [('*', '*', 'OutMode')]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/evt/evtsupport.py b/Mac/Modules/evt/evtsupport.py new file mode 100644 index 0000000..4798619 --- /dev/null +++ b/Mac/Modules/evt/evtsupport.py @@ -0,0 +1,74 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'Events.h' # The Apple header file +MODNAME = 'Evt' # The name of the module +OBJECTNAME = 'Event' # The basic name of the objects used here +KIND = 'Record' # Usually 'Ptr' or 'Handle' + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them +OBJECTPREFIX = MODPREFIX + '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 + +from macsupport import * + +# Create the type objects + +WindowPtr = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) +WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX) + +RgnHandle = FakeType("(RgnHandle)0") # XXX + +KeyMap = ArrayOutputBufferType("KeyMap") + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ +""" + +class MyObjectDefinition(GlobalObjectDefinition): + 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... + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) +##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) +##module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +##Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +##methods = [] +execfile(INPUTFILE) + +# add the populated lists to the generator groups +# (in a different wordl the scan program would generate this) +for f in functions: module.add(f) +##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/menu/Menumodule.c b/Mac/Modules/menu/Menumodule.c new file mode 100644 index 0000000..78c4f60 --- /dev/null +++ b/Mac/Modules/menu/Menumodule.c @@ -0,0 +1,908 @@ + +/* ========================== Module Menu =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include +#include +#include +#include + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ + +static PyObject *Menu_Error; + +/* ------------------------ Object type Menu ------------------------ */ + +PyTypeObject Menu_Type; + +#define MenuObj_Check(x) ((x)->ob_type == &Menu_Type) + +typedef struct MenuObject { + PyObject_HEAD + MenuHandle ob_itself; +} MenuObject; + +PyObject *MenuObj_New(itself) + const MenuHandle itself; +{ + MenuObject *it; + it = PyObject_NEW(MenuObject, &Menu_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + return (PyObject *)it; +} +MenuObj_Convert(v, p_itself) + PyObject *v; + MenuHandle *p_itself; +{ + if (!MenuObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "Menu required"); + return 0; + } + *p_itself = ((MenuObject *)v)->ob_itself; + return 1; +} + +static void MenuObj_dealloc(self) + MenuObject *self; +{ + /* Cleanup of self->ob_itself goes here */ + PyMem_DEL(self); +} + +static PyObject *MenuObj_DisposeMenu(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DisposeMenu(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_AppendMenu(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 data; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, data)) + return NULL; + AppendMenu(_self->ob_itself, + data); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_AddResMenu(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ResType theType; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theType)) + return NULL; + AddResMenu(_self->ob_itself, + theType); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_InsertResMenu(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ResType theType; + short afterItem; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &afterItem)) + return NULL; + InsertResMenu(_self->ob_itself, + theType, + afterItem); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_InsertMenu(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short beforeID; + if (!PyArg_ParseTuple(_args, "h", + &beforeID)) + return NULL; + InsertMenu(_self->ob_itself, + beforeID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_InsMenuItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 itemString; + short afterItem; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetStr255, itemString, + &afterItem)) + return NULL; + InsMenuItem(_self->ob_itself, + itemString, + afterItem); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_DelMenuItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + DelMenuItem(_self->ob_itself, + item); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_SetItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + Str255 itemString; + if (!PyArg_ParseTuple(_args, "hO&", + &item, + PyMac_GetStr255, itemString)) + return NULL; + SetItem(_self->ob_itself, + item, + itemString); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_GetItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + Str255 itemString; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + GetItem(_self->ob_itself, + item, + itemString); + _res = Py_BuildValue("O&", + PyMac_BuildStr255, itemString); + return _res; +} + +static PyObject *MenuObj_DisableItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + DisableItem(_self->ob_itself, + item); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_EnableItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + EnableItem(_self->ob_itself, + item); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_CheckItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + Boolean checked; + if (!PyArg_ParseTuple(_args, "hb", + &item, + &checked)) + return NULL; + CheckItem(_self->ob_itself, + item, + checked); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_SetItemMark(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short markChar; + if (!PyArg_ParseTuple(_args, "hh", + &item, + &markChar)) + return NULL; + SetItemMark(_self->ob_itself, + item, + markChar); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_GetItemMark(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short markChar; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + GetItemMark(_self->ob_itself, + item, + &markChar); + _res = Py_BuildValue("h", + markChar); + return _res; +} + +static PyObject *MenuObj_SetItemIcon(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short iconIndex; + if (!PyArg_ParseTuple(_args, "hh", + &item, + &iconIndex)) + return NULL; + SetItemIcon(_self->ob_itself, + item, + iconIndex); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_GetItemIcon(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short iconIndex; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + GetItemIcon(_self->ob_itself, + item, + &iconIndex); + _res = Py_BuildValue("h", + iconIndex); + return _res; +} + +static PyObject *MenuObj_SetItemStyle(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short chStyle; + if (!PyArg_ParseTuple(_args, "hh", + &item, + &chStyle)) + return NULL; + SetItemStyle(_self->ob_itself, + item, + chStyle); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_GetItemStyle(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + Style chStyle; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + GetItemStyle(_self->ob_itself, + item, + &chStyle); + _res = Py_BuildValue("b", + chStyle); + return _res; +} + +static PyObject *MenuObj_CalcMenuSize(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + CalcMenuSize(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_CountMItems(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CountMItems(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *MenuObj_GetItemCmd(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short cmdChar; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + GetItemCmd(_self->ob_itself, + item, + &cmdChar); + _res = Py_BuildValue("h", + cmdChar); + return _res; +} + +static PyObject *MenuObj_SetItemCmd(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short cmdChar; + if (!PyArg_ParseTuple(_args, "hh", + &item, + &cmdChar)) + return NULL; + SetItemCmd(_self->ob_itself, + item, + cmdChar); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_PopUpMenuSelect(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + short top; + short left; + short popUpItem; + if (!PyArg_ParseTuple(_args, "hhh", + &top, + &left, + &popUpItem)) + return NULL; + _rv = PopUpMenuSelect(_self->ob_itself, + top, + left, + popUpItem); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyMethodDef MenuObj_methods[] = { + {"DisposeMenu", (PyCFunction)MenuObj_DisposeMenu, 1, + "() -> None"}, + {"AppendMenu", (PyCFunction)MenuObj_AppendMenu, 1, + "(Str255 data) -> None"}, + {"AddResMenu", (PyCFunction)MenuObj_AddResMenu, 1, + "(ResType theType) -> None"}, + {"InsertResMenu", (PyCFunction)MenuObj_InsertResMenu, 1, + "(ResType theType, short afterItem) -> None"}, + {"InsertMenu", (PyCFunction)MenuObj_InsertMenu, 1, + "(short beforeID) -> None"}, + {"InsMenuItem", (PyCFunction)MenuObj_InsMenuItem, 1, + "(Str255 itemString, short afterItem) -> None"}, + {"DelMenuItem", (PyCFunction)MenuObj_DelMenuItem, 1, + "(short item) -> None"}, + {"SetItem", (PyCFunction)MenuObj_SetItem, 1, + "(short item, Str255 itemString) -> None"}, + {"GetItem", (PyCFunction)MenuObj_GetItem, 1, + "(short item) -> (Str255 itemString)"}, + {"DisableItem", (PyCFunction)MenuObj_DisableItem, 1, + "(short item) -> None"}, + {"EnableItem", (PyCFunction)MenuObj_EnableItem, 1, + "(short item) -> None"}, + {"CheckItem", (PyCFunction)MenuObj_CheckItem, 1, + "(short item, Boolean checked) -> None"}, + {"SetItemMark", (PyCFunction)MenuObj_SetItemMark, 1, + "(short item, short markChar) -> None"}, + {"GetItemMark", (PyCFunction)MenuObj_GetItemMark, 1, + "(short item) -> (short markChar)"}, + {"SetItemIcon", (PyCFunction)MenuObj_SetItemIcon, 1, + "(short item, short iconIndex) -> None"}, + {"GetItemIcon", (PyCFunction)MenuObj_GetItemIcon, 1, + "(short item) -> (short iconIndex)"}, + {"SetItemStyle", (PyCFunction)MenuObj_SetItemStyle, 1, + "(short item, short chStyle) -> None"}, + {"GetItemStyle", (PyCFunction)MenuObj_GetItemStyle, 1, + "(short item) -> (Style chStyle)"}, + {"CalcMenuSize", (PyCFunction)MenuObj_CalcMenuSize, 1, + "() -> None"}, + {"CountMItems", (PyCFunction)MenuObj_CountMItems, 1, + "() -> (short _rv)"}, + {"GetItemCmd", (PyCFunction)MenuObj_GetItemCmd, 1, + "(short item) -> (short cmdChar)"}, + {"SetItemCmd", (PyCFunction)MenuObj_SetItemCmd, 1, + "(short item, short cmdChar) -> None"}, + {"PopUpMenuSelect", (PyCFunction)MenuObj_PopUpMenuSelect, 1, + "(short top, short left, short popUpItem) -> (long _rv)"}, + {NULL, NULL, 0} +}; + +PyMethodChain MenuObj_chain = { MenuObj_methods, NULL }; + +static PyObject *MenuObj_getattr(self, name) + MenuObject *self; + char *name; +{ + return Py_FindMethodInChain(&MenuObj_chain, (PyObject *)self, name); +} + +#define MenuObj_setattr NULL + +PyTypeObject Menu_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Menu", /*tp_name*/ + sizeof(MenuObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) MenuObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) MenuObj_getattr, /*tp_getattr*/ + (setattrfunc) MenuObj_setattr, /*tp_setattr*/ +}; + +/* ---------------------- End object type Menu ---------------------- */ + + +static PyObject *Menu_InitMenus(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + InitMenus(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_NewMenu(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + MenuHandle _rv; + short menuID; + Str255 menuTitle; + if (!PyArg_ParseTuple(_args, "hO&", + &menuID, + PyMac_GetStr255, menuTitle)) + return NULL; + _rv = NewMenu(menuID, + menuTitle); + _res = Py_BuildValue("O&", + MenuObj_New, _rv); + return _res; +} + +static PyObject *Menu_GetMenu(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + MenuHandle _rv; + short resourceID; + if (!PyArg_ParseTuple(_args, "h", + &resourceID)) + return NULL; + _rv = GetMenu(resourceID); + _res = Py_BuildValue("O&", + MenuObj_New, _rv); + return _res; +} + +static PyObject *Menu_DrawMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DrawMenuBar(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_InvalMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + InvalMenuBar(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_DeleteMenu(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short menuID; + if (!PyArg_ParseTuple(_args, "h", + &menuID)) + return NULL; + DeleteMenu(menuID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_ClearMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ClearMenuBar(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_GetNewMBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + short menuBarID; + if (!PyArg_ParseTuple(_args, "h", + &menuBarID)) + return NULL; + _rv = GetNewMBar(menuBarID); + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Menu_GetMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetMenuBar(); + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Menu_SetMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle menuList; + if (!PyArg_ParseTuple(_args, "O&", + ResObj_Convert, &menuList)) + return NULL; + SetMenuBar(menuList); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_MenuKey(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + short ch; + if (!PyArg_ParseTuple(_args, "h", + &ch)) + return NULL; + _rv = MenuKey(ch); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *Menu_HiliteMenu(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short menuID; + if (!PyArg_ParseTuple(_args, "h", + &menuID)) + return NULL; + HiliteMenu(menuID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_GetMHandle(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + MenuHandle _rv; + short menuID; + if (!PyArg_ParseTuple(_args, "h", + &menuID)) + return NULL; + _rv = GetMHandle(menuID); + _res = Py_BuildValue("O&", + MenuObj_New, _rv); + return _res; +} + +static PyObject *Menu_FlashMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short menuID; + if (!PyArg_ParseTuple(_args, "h", + &menuID)) + return NULL; + FlashMenuBar(menuID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_SetMenuFlash(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short count; + if (!PyArg_ParseTuple(_args, "h", + &count)) + return NULL; + SetMenuFlash(count); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_MenuSelect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + Point startPt; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &startPt)) + return NULL; + _rv = MenuSelect(startPt); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *Menu_InitProcMenu(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short resID; + if (!PyArg_ParseTuple(_args, "h", + &resID)) + return NULL; + InitProcMenu(resID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_MenuChoice(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = MenuChoice(); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *Menu_DelMCEntries(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short menuID; + short menuItem; + if (!PyArg_ParseTuple(_args, "hh", + &menuID, + &menuItem)) + return NULL; + DelMCEntries(menuID, + menuItem); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef Menu_methods[] = { + {"InitMenus", (PyCFunction)Menu_InitMenus, 1, + "() -> None"}, + {"NewMenu", (PyCFunction)Menu_NewMenu, 1, + "(short menuID, Str255 menuTitle) -> (MenuHandle _rv)"}, + {"GetMenu", (PyCFunction)Menu_GetMenu, 1, + "(short resourceID) -> (MenuHandle _rv)"}, + {"DrawMenuBar", (PyCFunction)Menu_DrawMenuBar, 1, + "() -> None"}, + {"InvalMenuBar", (PyCFunction)Menu_InvalMenuBar, 1, + "() -> None"}, + {"DeleteMenu", (PyCFunction)Menu_DeleteMenu, 1, + "(short menuID) -> None"}, + {"ClearMenuBar", (PyCFunction)Menu_ClearMenuBar, 1, + "() -> None"}, + {"GetNewMBar", (PyCFunction)Menu_GetNewMBar, 1, + "(short menuBarID) -> (Handle _rv)"}, + {"GetMenuBar", (PyCFunction)Menu_GetMenuBar, 1, + "() -> (Handle _rv)"}, + {"SetMenuBar", (PyCFunction)Menu_SetMenuBar, 1, + "(Handle menuList) -> None"}, + {"MenuKey", (PyCFunction)Menu_MenuKey, 1, + "(short ch) -> (long _rv)"}, + {"HiliteMenu", (PyCFunction)Menu_HiliteMenu, 1, + "(short menuID) -> None"}, + {"GetMHandle", (PyCFunction)Menu_GetMHandle, 1, + "(short menuID) -> (MenuHandle _rv)"}, + {"FlashMenuBar", (PyCFunction)Menu_FlashMenuBar, 1, + "(short menuID) -> None"}, + {"SetMenuFlash", (PyCFunction)Menu_SetMenuFlash, 1, + "(short count) -> None"}, + {"MenuSelect", (PyCFunction)Menu_MenuSelect, 1, + "(Point startPt) -> (long _rv)"}, + {"InitProcMenu", (PyCFunction)Menu_InitProcMenu, 1, + "(short resID) -> None"}, + {"MenuChoice", (PyCFunction)Menu_MenuChoice, 1, + "() -> (long _rv)"}, + {"DelMCEntries", (PyCFunction)Menu_DelMCEntries, 1, + "(short menuID, short menuItem) -> None"}, + {NULL, NULL, 0} +}; + + + + +void initMenu() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Menu", Menu_methods); + d = PyModule_GetDict(m); + Menu_Error = PyMac_GetOSErrException(); + if (Menu_Error == NULL || + PyDict_SetItemString(d, "Error", Menu_Error) != 0) + Py_FatalError("can't initialize Menu.Error"); +} + +/* ======================== End module Menu ========================= */ + diff --git a/Mac/Modules/menu/menugen.py b/Mac/Modules/menu/menugen.py new file mode 100644 index 0000000..30315b8 --- /dev/null +++ b/Mac/Modules/menu/menugen.py @@ -0,0 +1,242 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Menus.h' + +f = Function(void, 'InitMenus', +) +functions.append(f) + +f = Function(MenuHandle, 'NewMenu', + (short, 'menuID', InMode), + (Str255, 'menuTitle', InMode), +) +functions.append(f) + +f = Function(MenuHandle, 'GetMenu', + (short, 'resourceID', InMode), +) +functions.append(f) + +f = Method(void, 'DisposeMenu', + (MenuHandle, 'theMenu', InMode), +) +methods.append(f) + +f = Method(void, 'AppendMenu', + (MenuHandle, 'menu', InMode), + (ConstStr255Param, 'data', InMode), +) +methods.append(f) + +f = Method(void, 'AddResMenu', + (MenuHandle, 'theMenu', InMode), + (ResType, 'theType', InMode), +) +methods.append(f) + +f = Method(void, 'InsertResMenu', + (MenuHandle, 'theMenu', InMode), + (ResType, 'theType', InMode), + (short, 'afterItem', InMode), +) +methods.append(f) + +f = Method(void, 'InsertMenu', + (MenuHandle, 'theMenu', InMode), + (short, 'beforeID', InMode), +) +methods.append(f) + +f = Function(void, 'DrawMenuBar', +) +functions.append(f) + +f = Function(void, 'InvalMenuBar', +) +functions.append(f) + +f = Function(void, 'DeleteMenu', + (short, 'menuID', InMode), +) +functions.append(f) + +f = Function(void, 'ClearMenuBar', +) +functions.append(f) + +f = Function(Handle, 'GetNewMBar', + (short, 'menuBarID', InMode), +) +functions.append(f) + +f = Function(Handle, 'GetMenuBar', +) +functions.append(f) + +f = Function(void, 'SetMenuBar', + (Handle, 'menuList', InMode), +) +functions.append(f) + +f = Method(void, 'InsMenuItem', + (MenuHandle, 'theMenu', InMode), + (ConstStr255Param, 'itemString', InMode), + (short, 'afterItem', InMode), +) +methods.append(f) + +f = Method(void, 'DelMenuItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), +) +methods.append(f) + +f = Function(long, 'MenuKey', + (short, 'ch', InMode), +) +functions.append(f) + +f = Function(void, 'HiliteMenu', + (short, 'menuID', InMode), +) +functions.append(f) + +f = Method(void, 'SetItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (ConstStr255Param, 'itemString', InMode), +) +methods.append(f) + +f = Method(void, 'GetItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (Str255, 'itemString', OutMode), +) +methods.append(f) + +f = Method(void, 'DisableItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), +) +methods.append(f) + +f = Method(void, 'EnableItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), +) +methods.append(f) + +f = Method(void, 'CheckItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (Boolean, 'checked', InMode), +) +methods.append(f) + +f = Method(void, 'SetItemMark', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'markChar', InMode), +) +methods.append(f) + +f = Method(void, 'GetItemMark', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'markChar', OutMode), +) +methods.append(f) + +f = Method(void, 'SetItemIcon', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'iconIndex', InMode), +) +methods.append(f) + +f = Method(void, 'GetItemIcon', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'iconIndex', OutMode), +) +methods.append(f) + +f = Method(void, 'SetItemStyle', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'chStyle', InMode), +) +methods.append(f) + +f = Method(void, 'GetItemStyle', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (Style, 'chStyle', OutMode), +) +methods.append(f) + +f = Method(void, 'CalcMenuSize', + (MenuHandle, 'theMenu', InMode), +) +methods.append(f) + +f = Method(short, 'CountMItems', + (MenuHandle, 'theMenu', InMode), +) +methods.append(f) + +f = Function(MenuHandle, 'GetMHandle', + (short, 'menuID', InMode), +) +functions.append(f) + +f = Function(void, 'FlashMenuBar', + (short, 'menuID', InMode), +) +functions.append(f) + +f = Function(void, 'SetMenuFlash', + (short, 'count', InMode), +) +functions.append(f) + +f = Function(long, 'MenuSelect', + (Point, 'startPt', InMode), +) +functions.append(f) + +f = Function(void, 'InitProcMenu', + (short, 'resID', InMode), +) +functions.append(f) + +f = Method(void, 'GetItemCmd', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'cmdChar', OutMode), +) +methods.append(f) + +f = Method(void, 'SetItemCmd', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'cmdChar', InMode), +) +methods.append(f) + +f = Method(long, 'PopUpMenuSelect', + (MenuHandle, 'menu', InMode), + (short, 'top', InMode), + (short, 'left', InMode), + (short, 'popUpItem', InMode), +) +methods.append(f) + +f = Function(long, 'MenuChoice', +) +functions.append(f) + +f = Function(void, 'DelMCEntries', + (short, 'menuID', InMode), + (short, 'menuItem', InMode), +) +functions.append(f) diff --git a/Mac/Modules/menu/menuscan.py b/Mac/Modules/menu/menuscan.py new file mode 100644 index 0000000..b120052 --- /dev/null +++ b/Mac/Modules/menu/menuscan.py @@ -0,0 +1,53 @@ +# Scan , generating menugen.py. + +from scantools import Scanner + +def main(): + input = "Menus.h" + output = "menugen.py" + defsoutput = "Menus.py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now doing 'import menusupport' ===" + import menusupport + print "=== Done. It's up to you to compile Menumodule.c ===" + +class MyScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "Function" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t == "MenuHandle" and m == "InMode": + classname = "Method" + listname = "methods" + return classname, listname + + def makeblacklistnames(self): + return [ + ] + + def makeblacklisttypes(self): + return [ + 'MCTableHandle', + 'MCEntryPtr', + 'MCTablePtr', + ] + + def makerepairinstructions(self): + return [ + ([("Str255", "itemString", "InMode")], + [("*", "*", "OutMode")]), + + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/menu/menusupport.py b/Mac/Modules/menu/menusupport.py new file mode 100644 index 0000000..c3fb3be --- /dev/null +++ b/Mac/Modules/menu/menusupport.py @@ -0,0 +1,55 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'Menus.h' # The Apple header file +MODNAME = 'Menu' # The name of the module +OBJECTNAME = 'Menu' # The basic name of the objects used here + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +OBJECTTYPE = OBJECTNAME + 'Handle' # The C type used to represent them +OBJECTPREFIX = MODPREFIX + '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 + +from macsupport import * + +# Create the type objects + +MenuHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ +""" + +class MyObjectDefinition(GlobalObjectDefinition): + pass + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) +object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) +module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +execfile(INPUTFILE) + +# add the populated lists to the generator groups +for f in functions: module.add(f) +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/qd/Qdmodule.c b/Mac/Modules/qd/Qdmodule.c new file mode 100644 index 0000000..2f88857 --- /dev/null +++ b/Mac/Modules/qd/Qdmodule.c @@ -0,0 +1,168 @@ + +/* =========================== Module Qd ============================ */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include +#include +#include +#include + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include +#include + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ + +static PyObject *Qd_Error; + +static PyObject *Qd_GlobalToLocal(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point thePoint; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePoint)) + return NULL; + GlobalToLocal(&thePoint); + _res = Py_BuildValue("O&", + PyMac_BuildPoint, thePoint); + return _res; +} + +static PyObject *Qd_LocalToGlobal(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point thePoint; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePoint)) + return NULL; + LocalToGlobal(&thePoint); + _res = Py_BuildValue("O&", + PyMac_BuildPoint, thePoint); + return _res; +} + +static PyObject *Qd_SetPort(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr thePort; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &thePort)) + return NULL; + SetPort(thePort); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Qd_ClipRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Rect r; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetRect, &r)) + return NULL; + ClipRect(&r); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Qd_EraseRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Rect r; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetRect, &r)) + return NULL; + EraseRect(&r); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Qd_OpenDeskAcc(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 name; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, name)) + return NULL; + OpenDeskAcc(name); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef Qd_methods[] = { + {"GlobalToLocal", (PyCFunction)Qd_GlobalToLocal, 1, + "(Point thePoint) -> (Point thePoint)"}, + {"LocalToGlobal", (PyCFunction)Qd_LocalToGlobal, 1, + "(Point thePoint) -> (Point thePoint)"}, + {"SetPort", (PyCFunction)Qd_SetPort, 1, + "(WindowPtr thePort) -> None"}, + {"ClipRect", (PyCFunction)Qd_ClipRect, 1, + "(Rect r) -> None"}, + {"EraseRect", (PyCFunction)Qd_EraseRect, 1, + "(Rect r) -> None"}, + {"OpenDeskAcc", (PyCFunction)Qd_OpenDeskAcc, 1, + "(Str255 name) -> None"}, + {NULL, NULL, 0} +}; + + + + +void initQd() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Qd", Qd_methods); + d = PyModule_GetDict(m); + Qd_Error = PyMac_GetOSErrException(); + if (Qd_Error == NULL || + PyDict_SetItemString(d, "Error", Qd_Error) != 0) + Py_FatalError("can't initialize Qd.Error"); +} + +/* ========================= End module Qd ========================== */ + diff --git a/Mac/Modules/qd/qdedit.py b/Mac/Modules/qd/qdedit.py new file mode 100644 index 0000000..2242c5a --- /dev/null +++ b/Mac/Modules/qd/qdedit.py @@ -0,0 +1,29 @@ +f = Function(void, 'GlobalToLocal', + (Point, 'thePoint', InOutMode), +) +functions.append(f) + +f = Function(void, 'LocalToGlobal', + (Point, 'thePoint', InOutMode), +) +functions.append(f) + +f = Function(void, 'SetPort', + (WindowPtr, 'thePort', InMode), +) +functions.append(f) + +f = Function(void, 'ClipRect', + (Rect, 'r', InMode), +) +functions.append(f) + +f = Function(void, 'EraseRect', + (Rect, 'r', InMode), +) +functions.append(f) + +f = Function(void, 'OpenDeskAcc', + (Str255, 'name', InMode), +) +functions.append(f) diff --git a/Mac/Modules/qd/qdsupport.py b/Mac/Modules/qd/qdsupport.py new file mode 100644 index 0000000..e98b27a --- /dev/null +++ b/Mac/Modules/qd/qdsupport.py @@ -0,0 +1,72 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'QuickDraw.h' # The Apple header file +MODNAME = 'Qd' # The name of the module +OBJECTNAME = 'Graf' # The basic name of the objects used here + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +OBJECTTYPE = OBJECTNAME + 'Ptr' # The C type used to represent them +OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods +INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner +EXTRAFILE = string.lower(MODPREFIX) + 'edit.py' # A similar file but hand-made +OUTPUTFILE = MODNAME + "module.c" # The file generated by this program + +from macsupport import * + +# Create the type objects + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ +#include + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ +""" + +class MyObjectDefinition(GlobalObjectDefinition): + 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; } + """) + def outputFreeIt(self, itselfname): + Output("DisposeWindow(%s);", itselfname) + +# From here on it's basically all boiler plate... + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) +##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) +##module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +#execfile(INPUTFILE) +execfile(EXTRAFILE) + +# add the populated lists to the generator groups +# (in a different wordl the scan program would generate this) +for f in functions: module.add(f) +for f in methods: object.add(f) + +# generate output (open the output file as late as possible) +SetOutputFileName(OUTPUTFILE) +module.generate() +SetOutputFile() # Close it diff --git a/Mac/Modules/res/Resmodule.c b/Mac/Modules/res/Resmodule.c new file mode 100644 index 0000000..484bca6 --- /dev/null +++ b/Mac/Modules/res/Resmodule.c @@ -0,0 +1,1256 @@ + +/* =========================== Module Res =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include +#include +#include +#include + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +#include + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ + +static PyObject *Res_Error; + +/* ---------------------- Object type Resource ---------------------- */ + +PyTypeObject Resource_Type; + +#define ResObj_Check(x) ((x)->ob_type == &Resource_Type) + +typedef struct ResourceObject { + PyObject_HEAD + Handle ob_itself; +} ResourceObject; + +PyObject *ResObj_New(itself) + const Handle itself; +{ + ResourceObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + it = PyObject_NEW(ResourceObject, &Resource_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + return (PyObject *)it; +} +ResObj_Convert(v, p_itself) + PyObject *v; + Handle *p_itself; +{ + if (!ResObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "Resource required"); + return 0; + } + *p_itself = ((ResourceObject *)v)->ob_itself; + return 1; +} + +static void ResObj_dealloc(self) + ResourceObject *self; +{ + /* Cleanup of self->ob_itself goes here */ + PyMem_DEL(self); +} + +static PyObject *ResObj_HomeResFile(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = HomeResFile(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *ResObj_LoadResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + LoadResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_ReleaseResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ReleaseResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_DetachResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DetachResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_GetResAttrs(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetResAttrs(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *ResObj_GetResInfo(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short theID; + ResType theType; + Str255 name; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + GetResInfo(_self->ob_itself, + &theID, + &theType, + name); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("hO&O&", + theID, + PyMac_BuildOSType, theType, + PyMac_BuildStr255, name); + return _res; +} + +static PyObject *ResObj_SetResInfo(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short theID; + Str255 name; + if (!PyArg_ParseTuple(_args, "hO&", + &theID, + PyMac_GetStr255, name)) + return NULL; + SetResInfo(_self->ob_itself, + theID, + name); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_AddResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ResType theType; + short theID; + Str255 name; + if (!PyArg_ParseTuple(_args, "O&hO&", + PyMac_GetOSType, &theType, + &theID, + PyMac_GetStr255, name)) + return NULL; + AddResource(_self->ob_itself, + theType, + theID, + name); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_SizeResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = SizeResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *ResObj_MaxSizeRsrc(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = MaxSizeRsrc(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *ResObj_RsrcMapEntry(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = RsrcMapEntry(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *ResObj_SetResAttrs(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short attrs; + if (!PyArg_ParseTuple(_args, "h", + &attrs)) + return NULL; + SetResAttrs(_self->ob_itself, + attrs); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_ChangedResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ChangedResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_RmveResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + RmveResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_WriteResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + WriteResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_SetResourceSize(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long newSize; + if (!PyArg_ParseTuple(_args, "l", + &newSize)) + return NULL; + SetResourceSize(_self->ob_itself, + newSize); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef ResObj_methods[] = { + {"HomeResFile", (PyCFunction)ResObj_HomeResFile, 1, + "() -> (short _rv)"}, + {"LoadResource", (PyCFunction)ResObj_LoadResource, 1, + "() -> None"}, + {"ReleaseResource", (PyCFunction)ResObj_ReleaseResource, 1, + "() -> None"}, + {"DetachResource", (PyCFunction)ResObj_DetachResource, 1, + "() -> None"}, + {"GetResAttrs", (PyCFunction)ResObj_GetResAttrs, 1, + "() -> (short _rv)"}, + {"GetResInfo", (PyCFunction)ResObj_GetResInfo, 1, + "() -> (short theID, ResType theType, Str255 name)"}, + {"SetResInfo", (PyCFunction)ResObj_SetResInfo, 1, + "(short theID, Str255 name) -> None"}, + {"AddResource", (PyCFunction)ResObj_AddResource, 1, + "(ResType theType, short theID, Str255 name) -> None"}, + {"SizeResource", (PyCFunction)ResObj_SizeResource, 1, + "() -> (long _rv)"}, + {"MaxSizeRsrc", (PyCFunction)ResObj_MaxSizeRsrc, 1, + "() -> (long _rv)"}, + {"RsrcMapEntry", (PyCFunction)ResObj_RsrcMapEntry, 1, + "() -> (long _rv)"}, + {"SetResAttrs", (PyCFunction)ResObj_SetResAttrs, 1, + "(short attrs) -> None"}, + {"ChangedResource", (PyCFunction)ResObj_ChangedResource, 1, + "() -> None"}, + {"RmveResource", (PyCFunction)ResObj_RmveResource, 1, + "() -> None"}, + {"WriteResource", (PyCFunction)ResObj_WriteResource, 1, + "() -> None"}, + {"SetResourceSize", (PyCFunction)ResObj_SetResourceSize, 1, + "(long newSize) -> None"}, + {NULL, NULL, 0} +}; + +PyMethodChain ResObj_chain = { ResObj_methods, NULL }; + +static PyObject *ResObj_getattr(self, name) + ResourceObject *self; + char *name; +{ + + if (strcmp(name, "size") == 0) + return PyInt_FromLong(GetHandleSize(self->ob_itself)); + if (strcmp(name, "data") == 0) { + PyObject *res; + char state; + state = HGetState(self->ob_itself); + HLock(self->ob_itself); + res = PyString_FromStringAndSize( + *self->ob_itself, + GetHandleSize(self->ob_itself)); + HUnlock(self->ob_itself); + HSetState(self->ob_itself, state); + return res; + } + if (strcmp(name, "__members__") == 0) + return Py_BuildValue("[ss]", "data", "size"); + + return Py_FindMethodInChain(&ResObj_chain, (PyObject *)self, name); +} + +#define ResObj_setattr NULL + +PyTypeObject Resource_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Resource", /*tp_name*/ + sizeof(ResourceObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) ResObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) ResObj_getattr, /*tp_getattr*/ + (setattrfunc) ResObj_setattr, /*tp_setattr*/ +}; + +/* -------------------- End object type Resource -------------------- */ + + +static PyObject *Res_InitResources(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = InitResources(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_RsrcZoneInit(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + RsrcZoneInit(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_CloseResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short refNum; + if (!PyArg_ParseTuple(_args, "h", + &refNum)) + return NULL; + CloseResFile(refNum); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_ResError(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = ResError(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_CurResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CurResFile(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_CreateResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 fileName; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, fileName)) + return NULL; + CreateResFile(fileName); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_OpenResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Str255 fileName; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, fileName)) + return NULL; + _rv = OpenResFile(fileName); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_UseResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short refNum; + if (!PyArg_ParseTuple(_args, "h", + &refNum)) + return NULL; + UseResFile(refNum); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_CountTypes(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CountTypes(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_Count1Types(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = Count1Types(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_GetIndType(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ResType theType; + short index; + if (!PyArg_ParseTuple(_args, "h", + &index)) + return NULL; + GetIndType(&theType, + index); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + PyMac_BuildOSType, theType); + return _res; +} + +static PyObject *Res_Get1IndType(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ResType theType; + short index; + if (!PyArg_ParseTuple(_args, "h", + &index)) + return NULL; + Get1IndType(&theType, + index); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + PyMac_BuildOSType, theType); + return _res; +} + +static PyObject *Res_SetResLoad(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean load; + if (!PyArg_ParseTuple(_args, "b", + &load)) + return NULL; + SetResLoad(load); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_CountResources(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + ResType theType; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theType)) + return NULL; + _rv = CountResources(theType); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_Count1Resources(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + ResType theType; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theType)) + return NULL; + _rv = Count1Resources(theType); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_GetIndResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + short index; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &index)) + return NULL; + _rv = GetIndResource(theType, + index); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_Get1IndResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + short index; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &index)) + return NULL; + _rv = Get1IndResource(theType, + index); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_GetResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + short theID; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &theID)) + return NULL; + _rv = GetResource(theType, + theID); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_Get1Resource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + short theID; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &theID)) + return NULL; + _rv = Get1Resource(theType, + theID); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_GetNamedResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + Str255 name; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theType, + PyMac_GetStr255, name)) + return NULL; + _rv = GetNamedResource(theType, + name); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_Get1NamedResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + Str255 name; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theType, + PyMac_GetStr255, name)) + return NULL; + _rv = Get1NamedResource(theType, + name); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_UniqueID(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + ResType theType; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theType)) + return NULL; + _rv = UniqueID(theType); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_Unique1ID(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + ResType theType; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theType)) + return NULL; + _rv = Unique1ID(theType); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_UpdateResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short refNum; + if (!PyArg_ParseTuple(_args, "h", + &refNum)) + return NULL; + UpdateResFile(refNum); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_SetResPurge(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean install; + if (!PyArg_ParseTuple(_args, "b", + &install)) + return NULL; + SetResPurge(install); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_GetResFileAttrs(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short refNum; + if (!PyArg_ParseTuple(_args, "h", + &refNum)) + return NULL; + _rv = GetResFileAttrs(refNum); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_SetResFileAttrs(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short refNum; + short attrs; + if (!PyArg_ParseTuple(_args, "hh", + &refNum, + &attrs)) + return NULL; + SetResFileAttrs(refNum, + attrs); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_OpenRFPerm(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Str255 fileName; + short vRefNum; + char permission; + if (!PyArg_ParseTuple(_args, "O&hc", + PyMac_GetStr255, fileName, + &vRefNum, + &permission)) + return NULL; + _rv = OpenRFPerm(fileName, + vRefNum, + permission); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_RGetResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + short theID; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &theID)) + return NULL; + _rv = RGetResource(theType, + theID); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_HOpenResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short vRefNum; + long dirID; + Str255 fileName; + char permission; + if (!PyArg_ParseTuple(_args, "hlO&c", + &vRefNum, + &dirID, + PyMac_GetStr255, fileName, + &permission)) + return NULL; + _rv = HOpenResFile(vRefNum, + dirID, + fileName, + permission); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_HCreateResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short vRefNum; + long dirID; + Str255 fileName; + if (!PyArg_ParseTuple(_args, "hlO&", + &vRefNum, + &dirID, + PyMac_GetStr255, fileName)) + return NULL; + HCreateResFile(vRefNum, + dirID, + fileName); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_FSpOpenResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + FSSpec spec; + SignedByte permission; + if (!PyArg_ParseTuple(_args, "O&b", + PyMac_GetFSSpec, &spec, + &permission)) + return NULL; + _rv = FSpOpenResFile(&spec, + permission); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_FSpCreateResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + FSSpec spec; + OSType creator; + OSType fileType; + ScriptCode scriptTag; + if (!PyArg_ParseTuple(_args, "O&O&O&h", + PyMac_GetFSSpec, &spec, + PyMac_GetOSType, &creator, + PyMac_GetOSType, &fileType, + &scriptTag)) + return NULL; + FSpCreateResFile(&spec, + creator, + fileType, + scriptTag); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef Res_methods[] = { + {"InitResources", (PyCFunction)Res_InitResources, 1, + "() -> (short _rv)"}, + {"RsrcZoneInit", (PyCFunction)Res_RsrcZoneInit, 1, + "() -> None"}, + {"CloseResFile", (PyCFunction)Res_CloseResFile, 1, + "(short refNum) -> None"}, + {"ResError", (PyCFunction)Res_ResError, 1, + "() -> (short _rv)"}, + {"CurResFile", (PyCFunction)Res_CurResFile, 1, + "() -> (short _rv)"}, + {"CreateResFile", (PyCFunction)Res_CreateResFile, 1, + "(Str255 fileName) -> None"}, + {"OpenResFile", (PyCFunction)Res_OpenResFile, 1, + "(Str255 fileName) -> (short _rv)"}, + {"UseResFile", (PyCFunction)Res_UseResFile, 1, + "(short refNum) -> None"}, + {"CountTypes", (PyCFunction)Res_CountTypes, 1, + "() -> (short _rv)"}, + {"Count1Types", (PyCFunction)Res_Count1Types, 1, + "() -> (short _rv)"}, + {"GetIndType", (PyCFunction)Res_GetIndType, 1, + "(short index) -> (ResType theType)"}, + {"Get1IndType", (PyCFunction)Res_Get1IndType, 1, + "(short index) -> (ResType theType)"}, + {"SetResLoad", (PyCFunction)Res_SetResLoad, 1, + "(Boolean load) -> None"}, + {"CountResources", (PyCFunction)Res_CountResources, 1, + "(ResType theType) -> (short _rv)"}, + {"Count1Resources", (PyCFunction)Res_Count1Resources, 1, + "(ResType theType) -> (short _rv)"}, + {"GetIndResource", (PyCFunction)Res_GetIndResource, 1, + "(ResType theType, short index) -> (Handle _rv)"}, + {"Get1IndResource", (PyCFunction)Res_Get1IndResource, 1, + "(ResType theType, short index) -> (Handle _rv)"}, + {"GetResource", (PyCFunction)Res_GetResource, 1, + "(ResType theType, short theID) -> (Handle _rv)"}, + {"Get1Resource", (PyCFunction)Res_Get1Resource, 1, + "(ResType theType, short theID) -> (Handle _rv)"}, + {"GetNamedResource", (PyCFunction)Res_GetNamedResource, 1, + "(ResType theType, Str255 name) -> (Handle _rv)"}, + {"Get1NamedResource", (PyCFunction)Res_Get1NamedResource, 1, + "(ResType theType, Str255 name) -> (Handle _rv)"}, + {"UniqueID", (PyCFunction)Res_UniqueID, 1, + "(ResType theType) -> (short _rv)"}, + {"Unique1ID", (PyCFunction)Res_Unique1ID, 1, + "(ResType theType) -> (short _rv)"}, + {"UpdateResFile", (PyCFunction)Res_UpdateResFile, 1, + "(short refNum) -> None"}, + {"SetResPurge", (PyCFunction)Res_SetResPurge, 1, + "(Boolean install) -> None"}, + {"GetResFileAttrs", (PyCFunction)Res_GetResFileAttrs, 1, + "(short refNum) -> (short _rv)"}, + {"SetResFileAttrs", (PyCFunction)Res_SetResFileAttrs, 1, + "(short refNum, short attrs) -> None"}, + {"OpenRFPerm", (PyCFunction)Res_OpenRFPerm, 1, + "(Str255 fileName, short vRefNum, char permission) -> (short _rv)"}, + {"RGetResource", (PyCFunction)Res_RGetResource, 1, + "(ResType theType, short theID) -> (Handle _rv)"}, + {"HOpenResFile", (PyCFunction)Res_HOpenResFile, 1, + "(short vRefNum, long dirID, Str255 fileName, char permission) -> (short _rv)"}, + {"HCreateResFile", (PyCFunction)Res_HCreateResFile, 1, + "(short vRefNum, long dirID, Str255 fileName) -> None"}, + {"FSpOpenResFile", (PyCFunction)Res_FSpOpenResFile, 1, + "(FSSpec spec, SignedByte permission) -> (short _rv)"}, + {"FSpCreateResFile", (PyCFunction)Res_FSpCreateResFile, 1, + "(FSSpec spec, OSType creator, OSType fileType, ScriptCode scriptTag) -> None"}, + {NULL, NULL, 0} +}; + + + + + +void initRes() +{ + PyObject *m; + PyObject *d; + + + + + + m = Py_InitModule("Res", Res_methods); + d = PyModule_GetDict(m); + Res_Error = PyMac_GetOSErrException(); + if (Res_Error == NULL || + PyDict_SetItemString(d, "Error", Res_Error) != 0) + Py_FatalError("can't initialize Res.Error"); +} + +/* ========================= End module Res ========================= */ + diff --git a/Mac/Modules/res/resgen.py b/Mac/Modules/res/resgen.py new file mode 100644 index 0000000..3716e9e --- /dev/null +++ b/Mac/Modules/res/resgen.py @@ -0,0 +1,271 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Resources.h' + +f = ResFunction(short, 'InitResources', +) +functions.append(f) + +f = ResFunction(void, 'RsrcZoneInit', +) +functions.append(f) + +f = ResFunction(void, 'CloseResFile', + (short, 'refNum', InMode), +) +functions.append(f) + +f = ResFunction(short, 'ResError', +) +functions.append(f) + +f = ResFunction(short, 'CurResFile', +) +functions.append(f) + +f = ResMethod(short, 'HomeResFile', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResFunction(void, 'CreateResFile', + (ConstStr255Param, 'fileName', InMode), +) +functions.append(f) + +f = ResFunction(short, 'OpenResFile', + (ConstStr255Param, 'fileName', InMode), +) +functions.append(f) + +f = ResFunction(void, 'UseResFile', + (short, 'refNum', InMode), +) +functions.append(f) + +f = ResFunction(short, 'CountTypes', +) +functions.append(f) + +f = ResFunction(short, 'Count1Types', +) +functions.append(f) + +f = ResFunction(void, 'GetIndType', + (ResType, 'theType', OutMode), + (short, 'index', InMode), +) +functions.append(f) + +f = ResFunction(void, 'Get1IndType', + (ResType, 'theType', OutMode), + (short, 'index', InMode), +) +functions.append(f) + +f = ResFunction(void, 'SetResLoad', + (Boolean, 'load', InMode), +) +functions.append(f) + +f = ResFunction(short, 'CountResources', + (ResType, 'theType', InMode), +) +functions.append(f) + +f = ResFunction(short, 'Count1Resources', + (ResType, 'theType', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'GetIndResource', + (ResType, 'theType', InMode), + (short, 'index', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'Get1IndResource', + (ResType, 'theType', InMode), + (short, 'index', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'GetResource', + (ResType, 'theType', InMode), + (short, 'theID', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'Get1Resource', + (ResType, 'theType', InMode), + (short, 'theID', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'GetNamedResource', + (ResType, 'theType', InMode), + (ConstStr255Param, 'name', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'Get1NamedResource', + (ResType, 'theType', InMode), + (ConstStr255Param, 'name', InMode), +) +functions.append(f) + +f = ResMethod(void, 'LoadResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'ReleaseResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'DetachResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResFunction(short, 'UniqueID', + (ResType, 'theType', InMode), +) +functions.append(f) + +f = ResFunction(short, 'Unique1ID', + (ResType, 'theType', InMode), +) +functions.append(f) + +f = ResMethod(short, 'GetResAttrs', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'GetResInfo', + (Handle, 'theResource', InMode), + (short, 'theID', OutMode), + (ResType, 'theType', OutMode), + (Str255, 'name', OutMode), +) +resmethods.append(f) + +f = ResMethod(void, 'SetResInfo', + (Handle, 'theResource', InMode), + (short, 'theID', InMode), + (ConstStr255Param, 'name', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'AddResource', + (Handle, 'theResource', InMode), + (ResType, 'theType', InMode), + (short, 'theID', InMode), + (ConstStr255Param, 'name', InMode), +) +resmethods.append(f) + +f = ResMethod(long, 'SizeResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(long, 'MaxSizeRsrc', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(long, 'RsrcMapEntry', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'SetResAttrs', + (Handle, 'theResource', InMode), + (short, 'attrs', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'ChangedResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'RmveResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResFunction(void, 'UpdateResFile', + (short, 'refNum', InMode), +) +functions.append(f) + +f = ResMethod(void, 'WriteResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResFunction(void, 'SetResPurge', + (Boolean, 'install', InMode), +) +functions.append(f) + +f = ResFunction(short, 'GetResFileAttrs', + (short, 'refNum', InMode), +) +functions.append(f) + +f = ResFunction(void, 'SetResFileAttrs', + (short, 'refNum', InMode), + (short, 'attrs', InMode), +) +functions.append(f) + +f = ResFunction(short, 'OpenRFPerm', + (ConstStr255Param, 'fileName', InMode), + (short, 'vRefNum', InMode), + (char, 'permission', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'RGetResource', + (ResType, 'theType', InMode), + (short, 'theID', InMode), +) +functions.append(f) + +f = ResFunction(short, 'HOpenResFile', + (short, 'vRefNum', InMode), + (long, 'dirID', InMode), + (ConstStr255Param, 'fileName', InMode), + (char, 'permission', InMode), +) +functions.append(f) + +f = ResFunction(void, 'HCreateResFile', + (short, 'vRefNum', InMode), + (long, 'dirID', InMode), + (ConstStr255Param, 'fileName', InMode), +) +functions.append(f) + +f = ResFunction(short, 'FSpOpenResFile', + (FSSpec_ptr, 'spec', InMode), + (SignedByte, 'permission', InMode), +) +functions.append(f) + +f = ResFunction(void, 'FSpCreateResFile', + (FSSpec_ptr, 'spec', InMode), + (OSType, 'creator', InMode), + (OSType, 'fileType', InMode), + (ScriptCode, 'scriptTag', InMode), +) +functions.append(f) + +f = ResMethod(void, 'SetResourceSize', + (Handle, 'theResource', InMode), + (long, 'newSize', InMode), +) +resmethods.append(f) diff --git a/Mac/Modules/res/resscan.py b/Mac/Modules/res/resscan.py new file mode 100644 index 0000000..42bb389 --- /dev/null +++ b/Mac/Modules/res/resscan.py @@ -0,0 +1,60 @@ +# Scan Resources.h header file, generate resgen.py and Resources.py files. +# Then run ressupport to generate Resmodule.c. +# (Should learn how to tell the compiler to compile it as well.) + +import sys +import os +import string +import regex +import regsub +import MacOS + +from scantools import Scanner + +def main(): + input = "Resources.h" + output = "resgen.py" + defsoutput = "Resources.py" + scanner = ResourcesScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now doing 'import ressupport' ===" + import ressupport + print "=== Done 'import ressupport'. It's up to you to compile Resmodule.c ===" + +class ResourcesScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "ResFunction" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t == "Handle" and m == "InMode": + classname = "ResMethod" + listname = "resmethods" + return classname, listname + + def makeblacklistnames(self): + return [ + "ReadPartialResource", + "WritePartialResource", + ] + + def makerepairinstructions(self): + return [ + ([("Str255", "*", "InMode")], + [("*", "*", "OutMode")]), + + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode")], + [("InOutBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("OutBuffer", "*", "InOutMode")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/res/ressupport.py b/Mac/Modules/res/ressupport.py new file mode 100644 index 0000000..5c0d70f --- /dev/null +++ b/Mac/Modules/res/ressupport.py @@ -0,0 +1,77 @@ +# This script will generate the Resources interface for Python. +# It uses the "bgen" package to generate C code. +# It execs the file resgen.py which contain the function definitions +# (resgen.py was generated by resscan.py, scanning the header file). + +from macsupport import * + + +class ResMixIn: + + def checkit(self): + OutLbrace() + Output("OSErr _err = ResError();") + Output("if (_err != noErr) return PyMac_Error(_err);") + OutRbrace() + FunctionGenerator.checkit(self) # XXX + +class ResFunction(ResMixIn, FunctionGenerator): pass +class ResMethod(ResMixIn, MethodGenerator): pass + +# includestuff etc. are imported from macsupport + +includestuff = includestuff + """ +#include + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ +""" + +finalstuff = finalstuff + """ +""" + +initstuff = initstuff + """ +""" + +module = MacModule('Res', 'Res', includestuff, finalstuff, initstuff) + +getattrHookCode = """ +if (strcmp(name, "size") == 0) + return PyInt_FromLong(GetHandleSize(self->ob_itself)); +if (strcmp(name, "data") == 0) { + PyObject *res; + char state; + state = HGetState(self->ob_itself); + HLock(self->ob_itself); + res = PyString_FromStringAndSize( + *self->ob_itself, + GetHandleSize(self->ob_itself)); + HUnlock(self->ob_itself); + HSetState(self->ob_itself, state); + return res; +} +if (strcmp(name, "__members__") == 0) + return Py_BuildValue("[ss]", "data", "size"); +""" + +class ResDefiniton(GlobalObjectDefinition): + + def outputCheckNewArg(self): + Output("if (itself == NULL) return PyMac_Error(resNotFound);") + + def outputGetattrHook(self): + Output(getattrHookCode) + + +resobject = ResDefiniton('Resource', 'ResObj', 'Handle') +module.addobject(resobject) + +functions = [] +resmethods = [] + +execfile('resgen.py') + +for f in functions: module.add(f) +for f in resmethods: resobject.add(f) + +SetOutputFileName('Resmodule.c') +module.generate() diff --git a/Mac/Modules/snd/Sndmodule.c b/Mac/Modules/snd/Sndmodule.c new file mode 100644 index 0000000..0f71b0d --- /dev/null +++ b/Mac/Modules/snd/Sndmodule.c @@ -0,0 +1,786 @@ + +/* =========================== Module Snd =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include +#include +#include +#include + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +#include + +#ifndef __MWERKS__ +#define SndCallBackUPP ProcPtr +#define NewSndCallBackProc(x) (x) +#define SndListHandle Handle +#endif + +#include /* for Set(Current)A5 */ + +/* Create a SndCommand object (an (int, int, int) tuple) */ +static PyObject * +SndCmd_New(SndCommand *pc) +{ + return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2); +} + +/* Convert a SndCommand argument */ +static int +SndCmd_Convert(PyObject *v, SndCommand *pc) +{ + int len; + pc->param1 = 0; + pc->param2 = 0; + if (PyTuple_Check(v)) { + if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) + return 1; + PyErr_Clear(); + return PyArg_ParseTuple(v, "hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); + } + return PyArg_Parse(v, "h", &pc->cmd); +} + +/* Create a NumVersion object (a quintuple of integers) */ +static PyObject * +NumVer_New(NumVersion nv) +{ + return Py_BuildValue("iiiii", + nv.majorRev, + nv.minorRev, + nv.bugFixRev, + nv.stage, + nv.nonRelRev); +} + +static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */ + +static PyObject *Snd_Error; + +/* --------------------- Object type SndChannel --------------------- */ + +staticforward PyTypeObject SndChannel_Type; + +#define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type) + +typedef struct SndChannelObject { + PyObject_HEAD + SndChannelPtr ob_itself; + /* Members used to implement callbacks: */ + PyObject *ob_callback; + long ob_A5; + SndCommand ob_cmd; +} SndChannelObject; + +static PyObject *SndCh_New(itself) + const SndChannelPtr itself; +{ + SndChannelObject *it; + it = PyObject_NEW(SndChannelObject, &SndChannel_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + it->ob_callback = NULL; + it->ob_A5 = SetCurrentA5(); + return (PyObject *)it; +} +static SndCh_Convert(v, p_itself) + PyObject *v; + SndChannelPtr *p_itself; +{ + if (!SndCh_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "SndChannel required"); + return 0; + } + *p_itself = ((SndChannelObject *)v)->ob_itself; + return 1; +} + +static void SndCh_dealloc(self) + SndChannelObject *self; +{ + SndDisposeChannel(self->ob_itself, 1); + Py_XDECREF(self->ob_callback); + PyMem_DEL(self); +} + +static PyObject *SndCh_SndDoCommand(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + SndCommand cmd; + Boolean noWait; + if (!PyArg_ParseTuple(_args, "O&b", + SndCmd_Convert, &cmd, + &noWait)) + return NULL; + _err = SndDoCommand(_self->ob_itself, + &cmd, + noWait); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndDoImmediate(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + SndCommand cmd; + if (!PyArg_ParseTuple(_args, "O&", + SndCmd_Convert, &cmd)) + return NULL; + _err = SndDoImmediate(_self->ob_itself, + &cmd); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndPlay(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + Handle sndHdl; + Boolean async; + if (!PyArg_ParseTuple(_args, "O&b", + ResObj_Convert, &sndHdl, + &async)) + return NULL; + _err = SndPlay(_self->ob_itself, + sndHdl, + async); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndStartFilePlay(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + short fRefNum; + short resNum; + long bufferSize; + Boolean async; + if (!PyArg_ParseTuple(_args, "hhlb", + &fRefNum, + &resNum, + &bufferSize, + &async)) + return NULL; + _err = SndStartFilePlay(_self->ob_itself, + fRefNum, + resNum, + bufferSize, + 0, + 0, + 0, + async); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndPauseFilePlay(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = SndPauseFilePlay(_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndStopFilePlay(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + Boolean async; + if (!PyArg_ParseTuple(_args, "b", + &async)) + return NULL; + _err = SndStopFilePlay(_self->ob_itself, + async); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndChannelStatus(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + short theLength; + SCStatus theStatus__out__; + int theStatus__len__; + if (!PyArg_ParseTuple(_args, "h", + &theLength)) + return NULL; + _err = SndChannelStatus(_self->ob_itself, + theLength, + &theStatus__out__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("s#", + (char *)&theStatus__out__, sizeof(SCStatus)); + theStatus__error__: ; + return _res; +} + +static PyMethodDef SndCh_methods[] = { + {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1, + "(SndCommand cmd, Boolean noWait) -> None"}, + {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1, + "(SndCommand cmd) -> None"}, + {"SndPlay", (PyCFunction)SndCh_SndPlay, 1, + "(Handle sndHdl, Boolean async) -> None"}, + {"SndStartFilePlay", (PyCFunction)SndCh_SndStartFilePlay, 1, + "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"}, + {"SndPauseFilePlay", (PyCFunction)SndCh_SndPauseFilePlay, 1, + "() -> None"}, + {"SndStopFilePlay", (PyCFunction)SndCh_SndStopFilePlay, 1, + "(Boolean async) -> None"}, + {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1, + "(short theLength) -> (SCStatus theStatus)"}, + {NULL, NULL, 0} +}; + +static PyMethodChain SndCh_chain = { SndCh_methods, NULL }; + +static PyObject *SndCh_getattr(self, name) + SndChannelObject *self; + char *name; +{ + return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name); +} + +#define SndCh_setattr NULL + +static PyTypeObject SndChannel_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "SndChannel", /*tp_name*/ + sizeof(SndChannelObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) SndCh_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) SndCh_getattr, /*tp_getattr*/ + (setattrfunc) SndCh_setattr, /*tp_setattr*/ +}; + +/* ------------------- End object type SndChannel ------------------- */ + + +static PyObject *Snd_SndNewChannel(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + SndChannelPtr chan = 0; + short synth; + long init; + PyObject* userRoutine; + if (!PyArg_ParseTuple(_args, "hlO", + &synth, + &init, + &userRoutine)) + return NULL; + if (userRoutine != Py_None && !callable(userRoutine)) + { + PyErr_SetString(PyExc_TypeError, "callback must be callable"); + goto userRoutine__error__; + } + _err = SndNewChannel(&chan, + synth, + init, + (SndCallBackProcPtr)&SndCh_UserRoutine); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + SndCh_New, chan); + if (_res != NULL && userRoutine != Py_None) + { + SndChannelObject *p = (SndChannelObject *)_res; + p->ob_itself->userInfo = (long)p; + Py_INCREF(userRoutine); + p->ob_callback = userRoutine; + } + userRoutine__error__: ; + return _res; +} + +static PyObject *Snd_SndControl(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + short id; + SndCommand cmd; + if (!PyArg_ParseTuple(_args, "h", + &id)) + return NULL; + _err = SndControl(id, + &cmd); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + SndCmd_New, &cmd); + return _res; +} + +static PyObject *Snd_SetSoundVol(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short level; + if (!PyArg_ParseTuple(_args, "h", + &level)) + return NULL; + SetSoundVol(level); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Snd_GetSoundVol(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short level; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + GetSoundVol(&level); + _res = Py_BuildValue("h", + level); + return _res; +} + +static PyObject *Snd_StartSound(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + char *synthRec__in__; + long synthRec__len__; + if (!PyArg_ParseTuple(_args, "s#", + &synthRec__in__, &synthRec__len__)) + return NULL; + StartSound(synthRec__in__, synthRec__len__, + (SndCompletionProcPtr)0); + Py_INCREF(Py_None); + _res = Py_None; + synthRec__error__: ; + return _res; +} + +static PyObject *Snd_StopSound(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + StopSound(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Snd_SoundDone(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = SoundDone(); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Snd_SndSoundManagerVersion(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + NumVersion _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = SndSoundManagerVersion(); + _res = Py_BuildValue("O&", + NumVer_New, _rv); + return _res; +} + +static PyObject *Snd_SndManagerStatus(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + short theLength; + SMStatus theStatus__out__; + int theStatus__len__; + if (!PyArg_ParseTuple(_args, "h", + &theLength)) + return NULL; + _err = SndManagerStatus(theLength, + &theStatus__out__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("s#", + (char *)&theStatus__out__, sizeof(SMStatus)); + theStatus__error__: ; + return _res; +} + +static PyObject *Snd_SndGetSysBeepState(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short sysBeepState; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + SndGetSysBeepState(&sysBeepState); + _res = Py_BuildValue("h", + sysBeepState); + return _res; +} + +static PyObject *Snd_SndSetSysBeepState(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + short sysBeepState; + if (!PyArg_ParseTuple(_args, "h", + &sysBeepState)) + return NULL; + _err = SndSetSysBeepState(sysBeepState); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Snd_MACEVersion(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + NumVersion _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = MACEVersion(); + _res = Py_BuildValue("O&", + NumVer_New, _rv); + return _res; +} + +static PyObject *Snd_Comp3to1(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + char *buffer__in__; + char *buffer__out__; + long buffer__len__; + char *state__in__; + char state__out__[128]; + int state__len__; + unsigned long numChannels; + unsigned long whichChannel; + if (!PyArg_ParseTuple(_args, "s#s#ll", + &buffer__in__, &buffer__len__, + &state__in__, &state__len__, + &numChannels, + &whichChannel)) + return NULL; + if ((buffer__out__ = malloc(buffer__len__)) == NULL) + { + PyErr_NoMemory(); + goto buffer__error__; + } + if (state__len__ != 128) + { + PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); + goto state__error__; + } + Comp3to1(buffer__in__, buffer__out__, buffer__len__, + state__in__, state__out__, + numChannels, + whichChannel); + _res = Py_BuildValue("s#s#", + buffer__out__, buffer__len__, + state__out__, 128); + state__error__: ; + free(buffer__out__); + buffer__error__: ; + return _res; +} + +static PyObject *Snd_Exp1to3(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + char *buffer__in__; + char *buffer__out__; + long buffer__len__; + char *state__in__; + char state__out__[128]; + int state__len__; + unsigned long numChannels; + unsigned long whichChannel; + if (!PyArg_ParseTuple(_args, "s#s#ll", + &buffer__in__, &buffer__len__, + &state__in__, &state__len__, + &numChannels, + &whichChannel)) + return NULL; + if ((buffer__out__ = malloc(buffer__len__)) == NULL) + { + PyErr_NoMemory(); + goto buffer__error__; + } + if (state__len__ != 128) + { + PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); + goto state__error__; + } + Exp1to3(buffer__in__, buffer__out__, buffer__len__, + state__in__, state__out__, + numChannels, + whichChannel); + _res = Py_BuildValue("s#s#", + buffer__out__, buffer__len__, + state__out__, 128); + state__error__: ; + free(buffer__out__); + buffer__error__: ; + return _res; +} + +static PyObject *Snd_Comp6to1(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + char *buffer__in__; + char *buffer__out__; + long buffer__len__; + char *state__in__; + char state__out__[128]; + int state__len__; + unsigned long numChannels; + unsigned long whichChannel; + if (!PyArg_ParseTuple(_args, "s#s#ll", + &buffer__in__, &buffer__len__, + &state__in__, &state__len__, + &numChannels, + &whichChannel)) + return NULL; + if ((buffer__out__ = malloc(buffer__len__)) == NULL) + { + PyErr_NoMemory(); + goto buffer__error__; + } + if (state__len__ != 128) + { + PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); + goto state__error__; + } + Comp6to1(buffer__in__, buffer__out__, buffer__len__, + state__in__, state__out__, + numChannels, + whichChannel); + _res = Py_BuildValue("s#s#", + buffer__out__, buffer__len__, + state__out__, 128); + state__error__: ; + free(buffer__out__); + buffer__error__: ; + return _res; +} + +static PyObject *Snd_Exp1to6(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + char *buffer__in__; + char *buffer__out__; + long buffer__len__; + char *state__in__; + char state__out__[128]; + int state__len__; + unsigned long numChannels; + unsigned long whichChannel; + if (!PyArg_ParseTuple(_args, "s#s#ll", + &buffer__in__, &buffer__len__, + &state__in__, &state__len__, + &numChannels, + &whichChannel)) + return NULL; + if ((buffer__out__ = malloc(buffer__len__)) == NULL) + { + PyErr_NoMemory(); + goto buffer__error__; + } + if (state__len__ != 128) + { + PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); + goto state__error__; + } + Exp1to6(buffer__in__, buffer__out__, buffer__len__, + state__in__, state__out__, + numChannels, + whichChannel); + _res = Py_BuildValue("s#s#", + buffer__out__, buffer__len__, + state__out__, 128); + state__error__: ; + free(buffer__out__); + buffer__error__: ; + return _res; +} + +static PyMethodDef Snd_methods[] = { + {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1, + "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"}, + {"SndControl", (PyCFunction)Snd_SndControl, 1, + "(short id) -> (SndCommand cmd)"}, + {"SetSoundVol", (PyCFunction)Snd_SetSoundVol, 1, + "(short level) -> None"}, + {"GetSoundVol", (PyCFunction)Snd_GetSoundVol, 1, + "() -> (short level)"}, + {"StartSound", (PyCFunction)Snd_StartSound, 1, + "(Buffer synthRec) -> None"}, + {"StopSound", (PyCFunction)Snd_StopSound, 1, + "() -> None"}, + {"SoundDone", (PyCFunction)Snd_SoundDone, 1, + "() -> (Boolean _rv)"}, + {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1, + "() -> (NumVersion _rv)"}, + {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1, + "(short theLength) -> (SMStatus theStatus)"}, + {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1, + "() -> (short sysBeepState)"}, + {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1, + "(short sysBeepState) -> None"}, + {"MACEVersion", (PyCFunction)Snd_MACEVersion, 1, + "() -> (NumVersion _rv)"}, + {"Comp3to1", (PyCFunction)Snd_Comp3to1, 1, + "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, + {"Exp1to3", (PyCFunction)Snd_Exp1to3, 1, + "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, + {"Comp6to1", (PyCFunction)Snd_Comp6to1, 1, + "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, + {"Exp1to6", (PyCFunction)Snd_Exp1to6, 1, + "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, + {NULL, NULL, 0} +}; + + + +/* Routine passed to Py_AddPendingCall -- call the Python callback */ +static int +SndCh_CallCallBack(arg) + void *arg; +{ + SndChannelObject *p = (SndChannelObject *)arg; + PyObject *args; + PyObject *res; + args = Py_BuildValue("(O(hhl))", + p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); + res = PyEval_CallObject(p->ob_callback, args); + Py_DECREF(args); + if (res == NULL) + return -1; + Py_DECREF(res); + return 0; +} + +/* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ +static pascal void +SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd) +{ + SndChannelObject *p = (SndChannelObject *)(chan->userInfo); + if (p->ob_callback != NULL) { + long A5 = SetA5(p->ob_A5); + p->ob_cmd = *cmd; + Py_AddPendingCall(SndCh_CallCallBack, (void *)p); + SetA5(A5); + } +} + + +void initSnd() +{ + PyObject *m; + PyObject *d; + + + + + + m = Py_InitModule("Snd", Snd_methods); + d = PyModule_GetDict(m); + Snd_Error = PyMac_GetOSErrException(); + if (Snd_Error == NULL || + PyDict_SetItemString(d, "Error", Snd_Error) != 0) + Py_FatalError("can't initialize Snd.Error"); +} + +/* ========================= End module Snd ========================= */ + diff --git a/Mac/Modules/snd/sndgen.py b/Mac/Modules/snd/sndgen.py new file mode 100644 index 0000000..2c77a1f --- /dev/null +++ b/Mac/Modules/snd/sndgen.py @@ -0,0 +1,131 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Sound.h' + +f = SndMethod(OSErr, 'SndDoCommand', + (SndChannelPtr, 'chan', InMode), + (SndCommand_ptr, 'cmd', InMode), + (Boolean, 'noWait', InMode), +) +sndmethods.append(f) + +f = SndMethod(OSErr, 'SndDoImmediate', + (SndChannelPtr, 'chan', InMode), + (SndCommand_ptr, 'cmd', InMode), +) +sndmethods.append(f) + +f = SndFunction(OSErr, 'SndNewChannel', + (SndChannelPtr, 'chan', OutMode), + (short, 'synth', InMode), + (long, 'init', InMode), + (SndCallBackProcPtr, 'userRoutine', InMode), +) +functions.append(f) + +f = SndMethod(OSErr, 'SndPlay', + (SndChannelPtr, 'chan', InMode), + (SndListHandle, 'sndHdl', InMode), + (Boolean, 'async', InMode), +) +sndmethods.append(f) + +f = SndFunction(OSErr, 'SndControl', + (short, 'id', InMode), + (SndCommand, 'cmd', OutMode), +) +functions.append(f) + +f = SndFunction(void, 'SetSoundVol', + (short, 'level', InMode), +) +functions.append(f) + +f = SndFunction(void, 'GetSoundVol', + (short, 'level', OutMode), +) +functions.append(f) + +f = SndFunction(NumVersion, 'SndSoundManagerVersion', +) +functions.append(f) + +f = SndMethod(OSErr, 'SndStartFilePlay', + (SndChannelPtr, 'chan', InMode), + (short, 'fRefNum', InMode), + (short, 'resNum', InMode), + (long, 'bufferSize', InMode), + (FakeType('0'), 'theBuffer', InMode), + (AudioSelectionPtr, 'theSelection', InMode), + (ProcPtr, 'theCompletion', InMode), + (Boolean, 'async', InMode), +) +sndmethods.append(f) + +f = SndMethod(OSErr, 'SndPauseFilePlay', + (SndChannelPtr, 'chan', InMode), +) +sndmethods.append(f) + +f = SndMethod(OSErr, 'SndStopFilePlay', + (SndChannelPtr, 'chan', InMode), + (Boolean, 'async', InMode), +) +sndmethods.append(f) + +f = SndMethod(OSErr, 'SndChannelStatus', + (SndChannelPtr, 'chan', InMode), + (short, 'theLength', InMode), + (SCStatus, 'theStatus', OutMode), +) +sndmethods.append(f) + +f = SndFunction(OSErr, 'SndManagerStatus', + (short, 'theLength', InMode), + (SMStatus, 'theStatus', OutMode), +) +functions.append(f) + +f = SndFunction(void, 'SndGetSysBeepState', + (short, 'sysBeepState', OutMode), +) +functions.append(f) + +f = SndFunction(OSErr, 'SndSetSysBeepState', + (short, 'sysBeepState', InMode), +) +functions.append(f) + +f = SndFunction(NumVersion, 'MACEVersion', +) +functions.append(f) + +f = SndFunction(void, 'Comp3to1', + (InOutBuffer, 'buffer', InOutMode), + (InOutBuf128, 'state', InOutMode), + (unsigned_long, 'numChannels', InMode), + (unsigned_long, 'whichChannel', InMode), +) +functions.append(f) + +f = SndFunction(void, 'Exp1to3', + (InOutBuffer, 'buffer', InOutMode), + (InOutBuf128, 'state', InOutMode), + (unsigned_long, 'numChannels', InMode), + (unsigned_long, 'whichChannel', InMode), +) +functions.append(f) + +f = SndFunction(void, 'Comp6to1', + (InOutBuffer, 'buffer', InOutMode), + (InOutBuf128, 'state', InOutMode), + (unsigned_long, 'numChannels', InMode), + (unsigned_long, 'whichChannel', InMode), +) +functions.append(f) + +f = SndFunction(void, 'Exp1to6', + (InOutBuffer, 'buffer', InOutMode), + (InOutBuf128, 'state', InOutMode), + (unsigned_long, 'numChannels', InMode), + (unsigned_long, 'whichChannel', InMode), +) +functions.append(f) diff --git a/Mac/Modules/snd/sndscan.py b/Mac/Modules/snd/sndscan.py new file mode 100644 index 0000000..b63691b --- /dev/null +++ b/Mac/Modules/snd/sndscan.py @@ -0,0 +1,84 @@ +# Scan Sound.h header file, generate sndgen.py and Sound.py files. +# Then import sndsupport (which execs sndgen.py) to generate Sndmodule.c. +# (Should learn how to tell the compiler to compile it as well.) + +from scantools import Scanner + +def main(): + input = "Sound.h" + output = "sndgen.py" + defsoutput = "Sound.py" + scanner = SoundScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now doing 'import sndsupport' ===" + import sndsupport + print "=== Done. It's up to you to compile Sndmodule.c ===" + +class SoundScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "SndFunction" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t == "SndChannelPtr" and m == "InMode": + classname = "SndMethod" + listname = "sndmethods" + return classname, listname + + def makeblacklistnames(self): + return [ + 'SndDisposeChannel', # automatic on deallocation + 'SndAddModifier', # for internal use only + 'SndPlayDoubleBuffer', # very low level routine + # Obsolete: + 'StartSound', + 'StopSound', + 'SoundDone', + + ] + + def makeblacklisttypes(self): + return [ + ] + + def makerepairinstructions(self): + return [ + ([("Str255", "*", "InMode")], + [("*", "*", "OutMode")]), + + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + + ([("SCStatusPtr", "*", "InMode")], + [("SCStatus", "*", "OutMode")]), + + ([("SMStatusPtr", "*", "InMode")], + [("SMStatus", "*", "OutMode")]), + + # For SndPlay's SndListHandle argument + ([("Handle", "sndHdl", "InMode")], + [("SndListHandle", "*", "*")]), + + # For SndStartFilePlay + ([("long", "bufferSize", "InMode"), ("void", "theBuffer", "OutMode")], + [("*", "*", "*"), ("FakeType('0')", "*", "InMode")]), + + # For Comp3to1 etc. + ([("void_ptr", "inBuffer", "InMode"), + ("void", "outBuffer", "OutMode"), + ("unsigned_long", "cnt", "InMode")], + [("InOutBuffer", "buffer", "InOutMode")]), + + # Ditto + ([("void_ptr", "inState", "InMode"), ("void", "outState", "OutMode")], + [("InOutBuf128", "state", "InOutMode")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/snd/sndsupport.py b/Mac/Modules/snd/sndsupport.py new file mode 100644 index 0000000..3516fa6 --- /dev/null +++ b/Mac/Modules/snd/sndsupport.py @@ -0,0 +1,218 @@ +# This script generates the Sound interface for Python. +# It uses the "bgen" package to generate C code. +# It execs the file sndgen.py which contain the function definitions +# (sndgen.py was generated by sndscan.py, scanning the header file). + +from macsupport import * + + +# define our own function and module generators + +class SndMixIn: pass + +class SndFunction(SndMixIn, OSErrFunctionGenerator): pass +class SndMethod(SndMixIn, OSErrMethodGenerator): pass + + +# includestuff etc. are imported from macsupport + +includestuff = includestuff + """ +#include + +#ifndef __MWERKS__ +#define SndCallBackUPP ProcPtr +#define NewSndCallBackProc(x) (x) +#define SndListHandle Handle +#endif +""" + +initstuff = initstuff + """ +""" + + +# define types used for arguments (in addition to standard and macsupport types) + +class SndChannelPtrType(OpaqueByValueType): + def declare(self, name): + # Initializing all SndChannelPtr objects to 0 saves + # special-casing NewSndChannel(), where it is formally an + # input-output parameter but we treat it as output-only + # (since Python users are not supposed to allocate memory) + Output("SndChannelPtr %s = 0;", name) + +SndChannelPtr = SndChannelPtrType('SndChannelPtr', 'SndCh') + +SndCommand = OpaqueType('SndCommand', 'SndCmd') +SndCommand_ptr = OpaqueType('SndCommand', 'SndCmd') +SndListHandle = OpaqueByValueType("SndListHandle", "ResObj") + +class SndCallBackType(InputOnlyType): + def __init__(self): + Type.__init__(self, 'PyObject*', 'O') + def getargsCheck(self, name): + Output("if (%s != Py_None && !callable(%s))", name, name) + OutLbrace() + Output('PyErr_SetString(PyExc_TypeError, "callback must be callable");') + Output("goto %s__error__;", name) + OutRbrace() + def passInput(self, name): + return "(SndCallBackProcPtr)&SndCh_UserRoutine" + def cleanup(self, name): + # XXX This knows it is executing inside the SndNewChannel wrapper + Output("if (_res != NULL && %s != Py_None)", name) + OutLbrace() + Output("SndChannelObject *p = (SndChannelObject *)_res;") + Output("p->ob_itself->userInfo = (long)p;") + Output("Py_INCREF(%s);", name) + Output("p->ob_callback = %s;", name) + OutRbrace() + DedentLevel() + Output(" %s__error__: ;", name) + IndentLevel() + +SndCallBackProcPtr = SndCallBackType() + +SndCompletionProcPtr = FakeType('(SndCompletionProcPtr)0') # XXX + +NumVersion = OpaqueByValueType('NumVersion', 'NumVer') + +InOutBuf128 = FixedInputOutputBufferType(128) + +AudioSelectionPtr = FakeType('0') # XXX + +ProcPtr = FakeType('0') # XXX + +SCStatus = StructOutputBufferType('SCStatus') +SMStatus = StructOutputBufferType('SMStatus') + +includestuff = includestuff + """ +#include /* for Set(Current)A5 */ + +/* Create a SndCommand object (an (int, int, int) tuple) */ +static PyObject * +SndCmd_New(SndCommand *pc) +{ + return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2); +} + +/* Convert a SndCommand argument */ +static int +SndCmd_Convert(PyObject *v, SndCommand *pc) +{ + int len; + pc->param1 = 0; + pc->param2 = 0; + if (PyTuple_Check(v)) { + if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) + return 1; + PyErr_Clear(); + return PyArg_ParseTuple(v, "hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); + } + return PyArg_Parse(v, "h", &pc->cmd); +} + +/* Create a NumVersion object (a quintuple of integers) */ +static PyObject * +NumVer_New(NumVersion nv) +{ + return Py_BuildValue("iiiii", + nv.majorRev, +#ifdef THINK_C + nv.minorRev, + nv.bugFixRev, +#else + (nv.minorAndBugRev>>4) & 0xf, + nv.minorAndBugRev & 0xf, +#endif + nv.stage, + nv.nonRelRev); +} + +static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */ +""" + + +finalstuff = finalstuff + """ +/* Routine passed to Py_AddPendingCall -- call the Python callback */ +static int +SndCh_CallCallBack(arg) + void *arg; +{ + SndChannelObject *p = (SndChannelObject *)arg; + PyObject *args; + PyObject *res; + args = Py_BuildValue("(O(hhl))", + p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); + res = PyEval_CallObject(p->ob_callback, args); + Py_DECREF(args); + if (res == NULL) + return -1; + Py_DECREF(res); + return 0; +} + +/* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ +static pascal void +SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd) +{ + SndChannelObject *p = (SndChannelObject *)(chan->userInfo); + if (p->ob_callback != NULL) { + long A5 = SetA5(p->ob_A5); + p->ob_cmd = *cmd; + Py_AddPendingCall(SndCh_CallCallBack, (void *)p); + SetA5(A5); + } +} +""" + + +# create the module and object definition and link them + +class SndObjectDefinition(ObjectDefinition): + + def outputStructMembers(self): + ObjectDefinition.outputStructMembers(self) + Output("/* Members used to implement callbacks: */") + Output("PyObject *ob_callback;") + Output("long ob_A5;"); + Output("SndCommand ob_cmd;") + + def outputInitStructMembers(self): + ObjectDefinition.outputInitStructMembers(self) + Output("it->ob_callback = NULL;") + Output("it->ob_A5 = SetCurrentA5();"); + + def outputCleanupStructMembers(self): + ObjectDefinition.outputCleanupStructMembers(self) + Output("Py_XDECREF(self->ob_callback);") + + def outputFreeIt(self, itselfname): + Output("SndDisposeChannel(%s, 1);", itselfname) + + +sndobject = SndObjectDefinition('SndChannel', 'SndCh', 'SndChannelPtr') +module = MacModule('Snd', 'Snd', includestuff, finalstuff, initstuff) +module.addobject(sndobject) + + +# create lists of functions and object methods + +functions = [] +sndmethods = [] + + +# populate the lists + +execfile('sndgen.py') + + +# add the functions and methods to the module and object, respectively + +for f in functions: module.add(f) +for f in sndmethods: sndobject.add(f) + + +# generate output + +SetOutputFileName('Sndmodule.c') +module.generate() diff --git a/Mac/Modules/win/Winmodule.c b/Mac/Modules/win/Winmodule.c new file mode 100644 index 0000000..3f60d37 --- /dev/null +++ b/Mac/Modules/win/Winmodule.c @@ -0,0 +1,872 @@ + +/* =========================== Module Win =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include +#include +#include +#include + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ + +#ifdef __MWERKS__ +#define WindowPeek WindowPtr +#endif + +extern PyObject *WinObj_WhichWindow(WindowPtr w); /* Forward */ + +static PyObject *Win_Error; + +/* ----------------------- Object type Window ----------------------- */ + +PyTypeObject Window_Type; + +#define WinObj_Check(x) ((x)->ob_type == &Window_Type) + +typedef struct WindowObject { + PyObject_HEAD + WindowPtr ob_itself; +} WindowObject; + +PyObject *WinObj_New(itself) + const WindowPtr itself; +{ + WindowObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + it = PyObject_NEW(WindowObject, &Window_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + SetWRefCon(itself, (long)it); + return (PyObject *)it; +} +WinObj_Convert(v, p_itself) + PyObject *v; + WindowPtr *p_itself; +{ + if (DlgObj_Check(v)) { + *p_itself = ((WindowObject *)v)->ob_itself; + return 1; + } + + if (v == Py_None) { *p_itself = NULL; return 1; } + if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; } + + if (!WinObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "Window required"); + return 0; + } + *p_itself = ((WindowObject *)v)->ob_itself; + return 1; +} + +static void WinObj_dealloc(self) + WindowObject *self; +{ + DisposeWindow(self->ob_itself); + PyMem_DEL(self); +} + +static PyObject *WinObj_GetWTitle(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 title; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + GetWTitle(_self->ob_itself, + title); + _res = Py_BuildValue("O&", + PyMac_BuildStr255, title); + return _res; +} + +static PyObject *WinObj_SelectWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + SelectWindow(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_HideWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + HideWindow(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_ShowWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ShowWindow(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_ShowHide(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean showFlag; + if (!PyArg_ParseTuple(_args, "b", + &showFlag)) + return NULL; + ShowHide(_self->ob_itself, + showFlag); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_HiliteWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean fHilite; + if (!PyArg_ParseTuple(_args, "b", + &fHilite)) + return NULL; + HiliteWindow(_self->ob_itself, + fHilite); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_BringToFront(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + BringToFront(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_SendBehind(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr behindWindow; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &behindWindow)) + return NULL; + SendBehind(_self->ob_itself, + behindWindow); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_DrawGrowIcon(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DrawGrowIcon(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_MoveWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short hGlobal; + short vGlobal; + Boolean front; + if (!PyArg_ParseTuple(_args, "hhb", + &hGlobal, + &vGlobal, + &front)) + return NULL; + MoveWindow(_self->ob_itself, + hGlobal, + vGlobal, + front); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_SizeWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short w; + short h; + Boolean fUpdate; + if (!PyArg_ParseTuple(_args, "hhb", + &w, + &h, + &fUpdate)) + return NULL; + SizeWindow(_self->ob_itself, + w, + h, + fUpdate); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_ZoomWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short partCode; + Boolean front; + if (!PyArg_ParseTuple(_args, "hb", + &partCode, + &front)) + return NULL; + ZoomWindow(_self->ob_itself, + partCode, + front); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_BeginUpdate(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + BeginUpdate(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_EndUpdate(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + EndUpdate(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_SetWRefCon(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long data; + if (!PyArg_ParseTuple(_args, "l", + &data)) + return NULL; + SetWRefCon(_self->ob_itself, + data); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_GetWRefCon(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetWRefCon(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *WinObj_ClipAbove(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ClipAbove((WindowPeek)(_self->ob_itself)); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_SaveOld(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + SaveOld((WindowPeek)(_self->ob_itself)); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_DrawNew(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean update; + if (!PyArg_ParseTuple(_args, "b", + &update)) + return NULL; + DrawNew((WindowPeek)(_self->ob_itself), + update); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_CalcVis(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + CalcVis((WindowPeek)(_self->ob_itself)); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_GrowWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + Point startPt; + Rect bBox; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetPoint, &startPt, + PyMac_GetRect, &bBox)) + return NULL; + _rv = GrowWindow(_self->ob_itself, + startPt, + &bBox); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *WinObj_TrackBox(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + Point thePt; + short partCode; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetPoint, &thePt, + &partCode)) + return NULL; + _rv = TrackBox(_self->ob_itself, + thePt, + partCode); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *WinObj_GetWVariant(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetWVariant(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *WinObj_SetWTitle(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 title; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, title)) + return NULL; + SetWTitle(_self->ob_itself, + title); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_TrackGoAway(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + Point thePt; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePt)) + return NULL; + _rv = TrackGoAway(_self->ob_itself, + thePt); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *WinObj_DragWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point startPt; + Rect boundsRect; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetPoint, &startPt, + PyMac_GetRect, &boundsRect)) + return NULL; + DragWindow(_self->ob_itself, + startPt, + &boundsRect); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef WinObj_methods[] = { + {"GetWTitle", (PyCFunction)WinObj_GetWTitle, 1, + "() -> (Str255 title)"}, + {"SelectWindow", (PyCFunction)WinObj_SelectWindow, 1, + "() -> None"}, + {"HideWindow", (PyCFunction)WinObj_HideWindow, 1, + "() -> None"}, + {"ShowWindow", (PyCFunction)WinObj_ShowWindow, 1, + "() -> None"}, + {"ShowHide", (PyCFunction)WinObj_ShowHide, 1, + "(Boolean showFlag) -> None"}, + {"HiliteWindow", (PyCFunction)WinObj_HiliteWindow, 1, + "(Boolean fHilite) -> None"}, + {"BringToFront", (PyCFunction)WinObj_BringToFront, 1, + "() -> None"}, + {"SendBehind", (PyCFunction)WinObj_SendBehind, 1, + "(WindowPtr behindWindow) -> None"}, + {"DrawGrowIcon", (PyCFunction)WinObj_DrawGrowIcon, 1, + "() -> None"}, + {"MoveWindow", (PyCFunction)WinObj_MoveWindow, 1, + "(short hGlobal, short vGlobal, Boolean front) -> None"}, + {"SizeWindow", (PyCFunction)WinObj_SizeWindow, 1, + "(short w, short h, Boolean fUpdate) -> None"}, + {"ZoomWindow", (PyCFunction)WinObj_ZoomWindow, 1, + "(short partCode, Boolean front) -> None"}, + {"BeginUpdate", (PyCFunction)WinObj_BeginUpdate, 1, + "() -> None"}, + {"EndUpdate", (PyCFunction)WinObj_EndUpdate, 1, + "() -> None"}, + {"SetWRefCon", (PyCFunction)WinObj_SetWRefCon, 1, + "(long data) -> None"}, + {"GetWRefCon", (PyCFunction)WinObj_GetWRefCon, 1, + "() -> (long _rv)"}, + {"ClipAbove", (PyCFunction)WinObj_ClipAbove, 1, + "() -> None"}, + {"SaveOld", (PyCFunction)WinObj_SaveOld, 1, + "() -> None"}, + {"DrawNew", (PyCFunction)WinObj_DrawNew, 1, + "(Boolean update) -> None"}, + {"CalcVis", (PyCFunction)WinObj_CalcVis, 1, + "() -> None"}, + {"GrowWindow", (PyCFunction)WinObj_GrowWindow, 1, + "(Point startPt, Rect bBox) -> (long _rv)"}, + {"TrackBox", (PyCFunction)WinObj_TrackBox, 1, + "(Point thePt, short partCode) -> (Boolean _rv)"}, + {"GetWVariant", (PyCFunction)WinObj_GetWVariant, 1, + "() -> (short _rv)"}, + {"SetWTitle", (PyCFunction)WinObj_SetWTitle, 1, + "(Str255 title) -> None"}, + {"TrackGoAway", (PyCFunction)WinObj_TrackGoAway, 1, + "(Point thePt) -> (Boolean _rv)"}, + {"DragWindow", (PyCFunction)WinObj_DragWindow, 1, + "(Point startPt, Rect boundsRect) -> None"}, + {NULL, NULL, 0} +}; + +PyMethodChain WinObj_chain = { WinObj_methods, NULL }; + +static PyObject *WinObj_getattr(self, name) + WindowObject *self; + char *name; +{ + return Py_FindMethodInChain(&WinObj_chain, (PyObject *)self, name); +} + +#define WinObj_setattr NULL + +PyTypeObject Window_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Window", /*tp_name*/ + sizeof(WindowObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) WinObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) WinObj_getattr, /*tp_getattr*/ + (setattrfunc) WinObj_setattr, /*tp_setattr*/ +}; + +/* --------------------- End object type Window --------------------- */ + + +static PyObject *Win_InitWindows(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + InitWindows(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Win_NewWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr _rv; + Rect boundsRect; + Str255 title; + Boolean visible; + short theProc; + WindowPtr behind; + Boolean goAwayFlag; + long refCon; + if (!PyArg_ParseTuple(_args, "O&O&bhO&bl", + PyMac_GetRect, &boundsRect, + PyMac_GetStr255, title, + &visible, + &theProc, + WinObj_Convert, &behind, + &goAwayFlag, + &refCon)) + return NULL; + _rv = NewWindow((void *)0, + &boundsRect, + title, + visible, + theProc, + behind, + goAwayFlag, + refCon); + _res = Py_BuildValue("O&", + WinObj_New, _rv); + return _res; +} + +static PyObject *Win_GetNewWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr _rv; + short windowID; + WindowPtr behind; + if (!PyArg_ParseTuple(_args, "hO&", + &windowID, + WinObj_Convert, &behind)) + return NULL; + _rv = GetNewWindow(windowID, + (void *)0, + behind); + _res = Py_BuildValue("O&", + WinObj_New, _rv); + return _res; +} + +static PyObject *Win_FrontWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = FrontWindow(); + _res = Py_BuildValue("O&", + WinObj_New, _rv); + return _res; +} + +static PyObject *Win_InvalRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Rect badRect; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetRect, &badRect)) + return NULL; + InvalRect(&badRect); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Win_ValidRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Rect goodRect; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetRect, &goodRect)) + return NULL; + ValidRect(&goodRect); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Win_CheckUpdate(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + EventRecord theEvent; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CheckUpdate(&theEvent); + _res = Py_BuildValue("bO&", + _rv, + PyMac_BuildEventRecord, &theEvent); + return _res; +} + +static PyObject *Win_FindWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Point thePoint; + WindowPtr theWindow; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePoint)) + return NULL; + _rv = FindWindow(thePoint, + &theWindow); + _res = Py_BuildValue("hO&", + _rv, + WinObj_WhichWindow, theWindow); + return _res; +} + +static PyObject *Win_PinRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + Rect theRect; + Point thePt; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetRect, &theRect, + PyMac_GetPoint, &thePt)) + return NULL; + _rv = PinRect(&theRect, + thePt); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *Win_NewCWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr _rv; + Rect boundsRect; + Str255 title; + Boolean visible; + short procID; + WindowPtr behind; + Boolean goAwayFlag; + long refCon; + if (!PyArg_ParseTuple(_args, "O&O&bhO&bl", + PyMac_GetRect, &boundsRect, + PyMac_GetStr255, title, + &visible, + &procID, + WinObj_Convert, &behind, + &goAwayFlag, + &refCon)) + return NULL; + _rv = NewCWindow((void *)0, + &boundsRect, + title, + visible, + procID, + behind, + goAwayFlag, + refCon); + _res = Py_BuildValue("O&", + WinObj_New, _rv); + return _res; +} + +static PyObject *Win_GetNewCWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr _rv; + short windowID; + WindowPtr behind; + if (!PyArg_ParseTuple(_args, "hO&", + &windowID, + WinObj_Convert, &behind)) + return NULL; + _rv = GetNewCWindow(windowID, + (void *)0, + behind); + _res = Py_BuildValue("O&", + WinObj_New, _rv); + return _res; +} + +static PyMethodDef Win_methods[] = { + {"InitWindows", (PyCFunction)Win_InitWindows, 1, + "() -> None"}, + {"NewWindow", (PyCFunction)Win_NewWindow, 1, + "(Rect boundsRect, Str255 title, Boolean visible, short theProc, WindowPtr behind, Boolean goAwayFlag, long refCon) -> (WindowPtr _rv)"}, + {"GetNewWindow", (PyCFunction)Win_GetNewWindow, 1, + "(short windowID, WindowPtr behind) -> (WindowPtr _rv)"}, + {"FrontWindow", (PyCFunction)Win_FrontWindow, 1, + "() -> (WindowPtr _rv)"}, + {"InvalRect", (PyCFunction)Win_InvalRect, 1, + "(Rect badRect) -> None"}, + {"ValidRect", (PyCFunction)Win_ValidRect, 1, + "(Rect goodRect) -> None"}, + {"CheckUpdate", (PyCFunction)Win_CheckUpdate, 1, + "() -> (Boolean _rv, EventRecord theEvent)"}, + {"FindWindow", (PyCFunction)Win_FindWindow, 1, + "(Point thePoint) -> (short _rv, WindowPtr theWindow)"}, + {"PinRect", (PyCFunction)Win_PinRect, 1, + "(Rect theRect, Point thePt) -> (long _rv)"}, + {"NewCWindow", (PyCFunction)Win_NewCWindow, 1, + "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon) -> (WindowPtr _rv)"}, + {"GetNewCWindow", (PyCFunction)Win_GetNewCWindow, 1, + "(short windowID, WindowPtr behind) -> (WindowPtr _rv)"}, + {NULL, NULL, 0} +}; + + + +/* Return the object corresponding to the window, or NULL */ + +PyObject * +WinObj_WhichWindow(w) + WindowPtr w; +{ + PyObject *it; + + /* XXX What if we find a stdwin window or a window belonging + to some other package? */ + it = (PyObject *) GetWRefCon(w); + if (it == NULL || ((WindowObject *)it)->ob_itself != w) + it = Py_None; + Py_INCREF(it); + return it; +} + + +void initWin() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Win", Win_methods); + d = PyModule_GetDict(m); + Win_Error = PyMac_GetOSErrException(); + if (Win_Error == NULL || + PyDict_SetItemString(d, "Error", Win_Error) != 0) + Py_FatalError("can't initialize Win.Error"); +} + +/* ========================= End module Win ========================= */ + diff --git a/Mac/Modules/win/wingen.py b/Mac/Modules/win/wingen.py new file mode 100644 index 0000000..a8c0cc2 --- /dev/null +++ b/Mac/Modules/win/wingen.py @@ -0,0 +1,226 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Windows.h' + +f = Function(void, 'InitWindows', +) +functions.append(f) + +f = Function(WindowPtr, 'NewWindow', + (NullStorage, 'wStorage', InMode), + (Rect_ptr, 'boundsRect', InMode), + (ConstStr255Param, 'title', InMode), + (Boolean, 'visible', InMode), + (short, 'theProc', InMode), + (WindowPtr, 'behind', InMode), + (Boolean, 'goAwayFlag', InMode), + (long, 'refCon', InMode), +) +functions.append(f) + +f = Function(WindowPtr, 'GetNewWindow', + (short, 'windowID', InMode), + (NullStorage, 'wStorage', InMode), + (WindowPtr, 'behind', InMode), +) +functions.append(f) + +f = Method(void, 'GetWTitle', + (WindowPtr, 'theWindow', InMode), + (Str255, 'title', OutMode), +) +methods.append(f) + +f = Method(void, 'SelectWindow', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'HideWindow', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'ShowWindow', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'ShowHide', + (WindowPtr, 'theWindow', InMode), + (Boolean, 'showFlag', InMode), +) +methods.append(f) + +f = Method(void, 'HiliteWindow', + (WindowPtr, 'theWindow', InMode), + (Boolean, 'fHilite', InMode), +) +methods.append(f) + +f = Method(void, 'BringToFront', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'SendBehind', + (WindowPtr, 'theWindow', InMode), + (WindowPtr, 'behindWindow', InMode), +) +methods.append(f) + +f = Function(WindowPtr, 'FrontWindow', +) +functions.append(f) + +f = Method(void, 'DrawGrowIcon', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'MoveWindow', + (WindowPtr, 'theWindow', InMode), + (short, 'hGlobal', InMode), + (short, 'vGlobal', InMode), + (Boolean, 'front', InMode), +) +methods.append(f) + +f = Method(void, 'SizeWindow', + (WindowPtr, 'theWindow', InMode), + (short, 'w', InMode), + (short, 'h', InMode), + (Boolean, 'fUpdate', InMode), +) +methods.append(f) + +f = Method(void, 'ZoomWindow', + (WindowPtr, 'theWindow', InMode), + (short, 'partCode', InMode), + (Boolean, 'front', InMode), +) +methods.append(f) + +f = Function(void, 'InvalRect', + (Rect_ptr, 'badRect', InMode), +) +functions.append(f) + +f = Function(void, 'ValidRect', + (Rect_ptr, 'goodRect', InMode), +) +functions.append(f) + +f = Method(void, 'BeginUpdate', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'EndUpdate', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'SetWRefCon', + (WindowPtr, 'theWindow', InMode), + (long, 'data', InMode), +) +methods.append(f) + +f = Method(long, 'GetWRefCon', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Function(Boolean, 'CheckUpdate', + (EventRecord, 'theEvent', OutMode), +) +functions.append(f) + +f = Method(void, 'ClipAbove', + (WindowPeek, 'window', InMode), +) +methods.append(f) + +f = Method(void, 'SaveOld', + (WindowPeek, 'window', InMode), +) +methods.append(f) + +f = Method(void, 'DrawNew', + (WindowPeek, 'window', InMode), + (Boolean, 'update', InMode), +) +methods.append(f) + +f = Method(void, 'CalcVis', + (WindowPeek, 'window', InMode), +) +methods.append(f) + +f = Method(long, 'GrowWindow', + (WindowPtr, 'theWindow', InMode), + (Point, 'startPt', InMode), + (Rect_ptr, 'bBox', InMode), +) +methods.append(f) + +f = Function(short, 'FindWindow', + (Point, 'thePoint', InMode), + (ExistingWindowPtr, 'theWindow', OutMode), +) +functions.append(f) + +f = Function(long, 'PinRect', + (Rect_ptr, 'theRect', InMode), + (Point, 'thePt', InMode), +) +functions.append(f) + +f = Method(Boolean, 'TrackBox', + (WindowPtr, 'theWindow', InMode), + (Point, 'thePt', InMode), + (short, 'partCode', InMode), +) +methods.append(f) + +f = Function(WindowPtr, 'NewCWindow', + (NullStorage, 'wStorage', InMode), + (Rect_ptr, 'boundsRect', InMode), + (ConstStr255Param, 'title', InMode), + (Boolean, 'visible', InMode), + (short, 'procID', InMode), + (WindowPtr, 'behind', InMode), + (Boolean, 'goAwayFlag', InMode), + (long, 'refCon', InMode), +) +functions.append(f) + +f = Function(WindowPtr, 'GetNewCWindow', + (short, 'windowID', InMode), + (NullStorage, 'wStorage', InMode), + (WindowPtr, 'behind', InMode), +) +functions.append(f) + +f = Method(short, 'GetWVariant', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'SetWTitle', + (WindowPtr, 'theWindow', InMode), + (ConstStr255Param, 'title', InMode), +) +methods.append(f) + +f = Method(Boolean, 'TrackGoAway', + (WindowPtr, 'theWindow', InMode), + (Point, 'thePt', InMode), +) +methods.append(f) + +f = Method(void, 'DragWindow', + (WindowPtr, 'theWindow', InMode), + (Point, 'startPt', InMode), + (Rect_ptr, 'boundsRect', InMode), +) +methods.append(f) diff --git a/Mac/Modules/win/winscan.py b/Mac/Modules/win/winscan.py new file mode 100644 index 0000000..6ae03f4 --- /dev/null +++ b/Mac/Modules/win/winscan.py @@ -0,0 +1,68 @@ +# Scan an Apple header file, generating a Python file of generator calls. + +from scantools import Scanner + +def main(): + input = "Windows.h" + output = "wingen.py" + defsoutput = "Windows.py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now importing the generated code... ===" + import winsupport + 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] + if t in ("WindowPtr", "WindowPeek") and m == "InMode": + classname = "Method" + listname = "methods" + return classname, listname + + def makeblacklistnames(self): + return [ + 'DisposeWindow', # Implied when the object is deleted + 'CloseWindow', + ] + + def makeblacklisttypes(self): + return [ + 'ProcPtr', + 'GrafPtr', + 'CGrafPtr', + 'RgnHandle', + 'PicHandle', + 'WCTabHandle', + 'AuxWinHandle', + 'PixPatHandle', + ] + + def makerepairinstructions(self): + return [ + + # GetWTitle + ([("Str255", "*", "InMode")], + [("*", "*", "OutMode")]), + + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + + ([("void", "wStorage", "OutMode")], + [("NullStorage", "*", "InMode")]), + + ([("WindowPtr", "*", "OutMode")], + [("ExistingWindowPtr", "*", "*")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/win/winsupport.py b/Mac/Modules/win/winsupport.py new file mode 100644 index 0000000..c1057e2 --- /dev/null +++ b/Mac/Modules/win/winsupport.py @@ -0,0 +1,103 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'Windows.h' # The Apple header file +MODNAME = 'Win' # The name of the module +OBJECTNAME = 'Window' # The basic name of the objects used here + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +OBJECTTYPE = OBJECTNAME + 'Ptr' # The C type used to represent them +OBJECTPREFIX = MODPREFIX + '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 + +from macsupport import * + +# Create the type objects + +WindowPtr = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) +WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX) +WindowPeek.passInput = lambda name: "(WindowPeek)(%s)" % name + +#RgnHandle = FakeType("theWindow->updtRgn") # XXX + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ + +#define resNotFound -192 /* Can't include because of Python's "errors.h" */ + +#ifdef __MWERKS__ +#define WindowPeek WindowPtr +#endif +""" + +finalstuff = finalstuff + """ +/* Return the object corresponding to the window, or NULL */ + +PyObject * +WinObj_WhichWindow(w) + WindowPtr w; +{ + PyObject *it; + + /* XXX What if we find a stdwin window or a window belonging + to some other package? */ + if (w == NULL) + it = NULL; + else + it = (PyObject *) GetWRefCon(w); + if (it == NULL || ((WindowObject *)it)->ob_itself != w) + it = Py_None; + Py_INCREF(it); + return it; +} +""" + +class MyObjectDefinition(GlobalObjectDefinition): + def outputCheckNewArg(self): + Output("if (itself == NULL) return PyMac_Error(resNotFound);") + def outputInitStructMembers(self): + GlobalObjectDefinition.outputInitStructMembers(self) + Output("SetWRefCon(itself, (long)it);") + 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; } + """) + def outputFreeIt(self, itselfname): + Output("DisposeWindow(%s);", itselfname) + +# From here on it's basically all boiler plate... + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) +object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) +module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +execfile(INPUTFILE) + +# add the populated lists to the generator groups +# (in a different wordl the scan program would generate this) +for f in functions: module.add(f) +for f in methods: object.add(f) + +# generate output (open the output file as late as possible) +SetOutputFileName(OUTPUTFILE) +module.generate() -- cgit v0.12