summaryrefslogtreecommitdiffstats
path: root/Mac
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1996-09-20 15:28:28 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1996-09-20 15:28:28 (GMT)
commitc46f56e35fc733c4a571e5cdb9890771a6440fa4 (patch)
treea6ecfb385d3f061538ffe3088820235264771029 /Mac
parent0585d41198047d8961b5d774efe3c7d9eea62e86 (diff)
downloadcpython-c46f56e35fc733c4a571e5cdb9890771a6440fa4.zip
cpython-c46f56e35fc733c4a571e5cdb9890771a6440fa4.tar.gz
cpython-c46f56e35fc733c4a571e5cdb9890771a6440fa4.tar.bz2
- Added optional "start" argument to TalkTo initialializer, which
starts the app (if needed). - Added aetools.Error, which is returned in case of server-generated errors (better than MacOS.Error, which was raised previously)
Diffstat (limited to 'Mac')
-rw-r--r--Mac/Lib/toolbox/aetools.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/Mac/Lib/toolbox/aetools.py b/Mac/Lib/toolbox/aetools.py
index 72e5475..41b7f24 100644
--- a/Mac/Lib/toolbox/aetools.py
+++ b/Mac/Lib/toolbox/aetools.py
@@ -29,6 +29,8 @@ import MacOS
from aetypes import *
from aepack import pack, unpack, coerce, AEDescType
+Error = 'aetools.Error'
+
# Special code to unpack an AppleEvent (which is *not* a disguised record!)
# Note by Jack: No??!? If I read the docs correctly it *is*....
@@ -105,35 +107,49 @@ def enumsubst(arguments, key, edict):
def decodeerror(arguments):
"""Create the 'best' argument for a raise MacOS.Error"""
errn = arguments['errn']
- errarg = (errn, MacOS.GetErrorString(errn))
+ errarg = (errn, )
if arguments.has_key('errs'):
errarg = errarg + (arguments['errs'],)
if arguments.has_key('erob'):
errarg = errarg + (arguments['erob'],)
+ if len(errarg) == 1:
+ errarg = errarg + ('Server returned error code %d'%errn, )
return errarg
class TalkTo:
"""An AE connection to an application"""
- def __init__(self, signature):
+ def __init__(self, signature, start=0):
"""Create a communication channel with a particular application.
Addressing the application is done by specifying either a
4-byte signature, an AEDesc or an object that will __aepack__
to an AEDesc.
"""
+ self.target_signature = None
if type(signature) == AEDescType:
self.target = signature
elif type(signature) == InstanceType and hasattr(signature, '__aepack__'):
self.target = signature.__aepack__()
elif type(signature) == StringType and len(signature) == 4:
self.target = AE.AECreateDesc(AppleEvents.typeApplSignature, signature)
+ self.target_signature = signature
else:
raise TypeError, "signature should be 4-char string or AEDesc"
self.send_flags = AppleEvents.kAEWaitReply
self.send_priority = AppleEvents.kAENormalPriority
self.send_timeout = AppleEvents.kAEDefaultTimeout
-
+ if start:
+ self.start()
+
+ def start(self):
+ """Start the application, if it is not running yet"""
+ import findertools
+ import macfs
+
+ fss = macfs.FindApplication(self.target_signature)
+ findertools.launch(fss)
+
def newevent(self, code, subcode, parameters = {}, attributes = {}):
"""Create a complete structure for an apple event"""
@@ -177,7 +193,7 @@ class TalkTo:
_reply, _arguments, _attributes = self.send(_code, _subcode,
_arguments, _attributes)
if _arguments.has_key('errn'):
- raise MacOS.Error, decodeerror(_arguments)
+ raise Error, decodeerror(_arguments)
if _arguments.has_key('----'):
return _arguments['----']