[Pythonmac-SIG] Integrating aemreceive into a class--help

Kevin Walzer kw at codebykevin.com
Tue Jan 12 01:00:29 CET 2010


I'm having a harder time than expected integrating aemreceive into my 
application class.

While aemreceive's example code is admirably clear and the docs are 
thorough, they are geared for procedural code, and I keep tripping over 
scoping issues in trying to integrate the library into a more OO setting.

Here's where things stand:

First, I simply import aemreceive into my app class. Next, I wrap its 
"installeventhandler" function into a class method, cf:

   def installeventhandler (self,
                              eventcallback,
                              eventcode,
                              *parameterdefinitions):
         aemreceive.installeventhandler(eventcallback, eventcode, 
*parameterdefinitions, codecs=aem.Codecs())

Next, in my app class's __init__ method, I install the event handler 
like so:

self.installeventhandler(self.getDomain,
                                  'CoKvdman',
                                  ('----', 'self', 
aemreceive.kae.typeUnicodeText),
                                  ('----', 'domain', 
aemreceive.kae.typeUnicodeText)
                                  )

This actually builds and runs the application without any complaints 
about "self" being undefined. However, I still can't actually get data 
from my Apple Event. As it's currently set up, I get this error from 
AppleScript:

  "Required parameter '----' is missing."

I'm not clear on what this means. According to the aemreceive docs, I 
need to provide a tuple for each parameter included. This means two, 
i.e. "self" and "domain," as outlined above. I don't know what the 
missing parameter is.

This doesn't *look* right to me: "self" prepends the "getDomain" method 
and actually shouldn't be included in the parameter setup as well, by my 
logic. However, the application crashes if I change "self.getDomain" to 
"getDomain" because, of course, "getDomain" is not defined.

Any guidance in getting the parameters for the event handlers correctly 
fleshed out would be much appreciated. In particular, I'm not sure where 
"self" should go, nor am I even certain if 
aemreceive.kae.typeUnicodeText is the correct data type for that.

I hope I don't sound too frustrated. Apple Events are very complicated, 
and has's work on making them accessible via this higher-level interface 
is admirable. Tk-Aqua's built-in "do-script" functionality is easier to 
use, and is very flexible in the sense that it allows you to execute 
*any* Tcl code, but aemreceive allows you to provide a real AppleScript 
interface to Python commands (you don't have to call raw Python code 
from AppleScript). There's a richer Tcl interface to Apple Events called 
TclAE, but it's more low-level and complex, and and it's only minimally 
maintained, so the extensive work needed to make it  64-bit capable has 
not yet been done.

So, thanks again to has for his good work on this! And looking forward 
to additional advice on the package.

Best,
Kevin

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com


More information about the Pythonmac-SIG mailing list