[Pythonmac-SIG] FBAs with bundlebuilder?

has hengist.podd at virgin.net
Sun Sep 19 02:16:19 CEST 2004


Ronald Oussoren wrote:

>Why would pythoneers need another API then AS-ers? If I understand 
>you correctly the only part that's only for AS-ers is a default main 
>function, others could supply their own eventloop.

As an oblique answer, here's an example of where I'm up to:

------- main.py script -------

from asapp import *

#######
# Callback functions

def inttotext(direct):
	try:
		return u''.join([unichr(i) for i in direct])
	except ValueError, e:
		raise EventError(-1700, 'Some number was outside 
range 0-65535.')

def texttoint(direct):
	return [ord(c) for c in direct]


#######
# Install callbacks as Apple event handlers

app = Application()

tc = app.suite('????', 'Text Commands Suite', 'Commands for working 
with text.')

tc.command(inttotext,
	'Pyth', 'Ucha', 'unicode characters', "Convert a list of 
integers to Unicode text.",
	('The unicode text.', typeUnicode),
	(kDirectArg, 'direct', 'List of integers in range 0-65535.', 
typeInteger, kList))

tc.command(texttoint,
	'Pyth', 'Uint', 'unicode numbers', "Convert Unicode text to a 
list of integers.",
	('List of integers.', typeInteger, kList),
	(kDirectArg, 'direct', 'The unicode text.', typeUnicode))

app.run()


------- end -------


------- build.py script -------

from asapp.build import build
build('TextCommands.app')

------- end -------

(Note: I'd really like the build script to go away in default cases, 
and just have a drag-n-drop applet that takes the mainprogram script 
and creates the application directly from that. Only time a build 
script should be needed is if you want to include 3rd-party modules 
in the application. Still working on this.)


I've made it as procedural as possible, avoiding any need to write 
classes as most ASers don't know squat about OOP. This means I can't 
use 'aehandler' decorators and auto-discovery here, since decorators 
don't work on modules, but never mind... and I guess it's one fewer 
'advanced' language concept for ASers to grok. It's something I still 
intend to explore in the broader aeom framework, which will be 
targeted squarely at Python-based application developers and support 
stuff like resolving object specifiers against an application's 
object model. Though it's early days and I'm still working on ideas 
for this as it's a pretty major project. [1][2]


BTW, anyone know if there's a bug/request filed on BB-built 
applications to do something about them falling over and dying upon 
launch if there's a bug in the top-level code of the mainprogram 
script or that of any of its dependencies. This is something 
AppleScript applets handle quite nicely: if a bug occurs on launch 
(or any other time for that matter), an error dialog appears 
describing the problem, along with a button you can click to open the 
script in Script Editor ready for fixing. ASers definitely won't 
tolerate the current behaviour, so something will definitely need 
done about it asap.

Cheers,

has

--

[1] Any ideas if/how an Apple Event Object Model support framework 
could be made to play nice with PyObjC apps? Presumably AE handling 
in PyObjC-based apps falls to Cocoa Scripting by default? Whereas 
aeom would build on aem.receive and aem.types.objectspecifier, which 
are powered by the Carbon Apple Event Manager.

[2] Anyone know of any nice, clean, easy-to-grok document-based 
applications written in Python using MVC that I can study?
-- 
http://freespace.virgin.net/hamish.sanderson/


More information about the Pythonmac-SIG mailing list