]> granicus.if.org Git - python/commitdiff
- Added optional "start" argument to TalkTo initialializer, which
authorJack Jansen <jack.jansen@cwi.nl>
Fri, 20 Sep 1996 15:28:28 +0000 (15:28 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Fri, 20 Sep 1996 15:28:28 +0000 (15:28 +0000)
  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)

Mac/Lib/toolbox/aetools.py

index 72e547568aaf069f32633ce639009b4790698226..41b7f2497084680d500b7429f158fa967c083608 100644 (file)
@@ -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['----']