diff options
author | Guido van Rossum <guido@python.org> | 1995-01-30 11:53:55 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-01-30 11:53:55 (GMT) |
commit | 17448e24081eb713ac00d7bcb681f4f0d8abfcbf (patch) | |
tree | 4f9d6768ef326173e1141b1a92af63247a42b13a /Mac/Lib/toolbox | |
parent | 80ffd6683ca7b06ed743c629459b06b07defbfb3 (diff) | |
download | cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.zip cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.tar.gz cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.tar.bz2 |
Committed a more or less working version.
Diffstat (limited to 'Mac/Lib/toolbox')
-rw-r--r-- | Mac/Lib/toolbox/AppleEvents.py | 103 | ||||
-rw-r--r-- | Mac/Lib/toolbox/Controls.py | 41 | ||||
-rw-r--r-- | Mac/Lib/toolbox/Dialogs.py | 20 | ||||
-rw-r--r-- | Mac/Lib/toolbox/Events.py | 49 | ||||
-rw-r--r-- | Mac/Lib/toolbox/Menus.py | 12 | ||||
-rw-r--r-- | Mac/Lib/toolbox/Resources.py | 12 | ||||
-rw-r--r-- | Mac/Lib/toolbox/Sound.py | 101 | ||||
-rw-r--r-- | Mac/Lib/toolbox/Windows.py | 41 | ||||
-rw-r--r-- | Mac/Lib/toolbox/aetools.py | 296 |
9 files changed, 675 insertions, 0 deletions
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() |