[Pyobjc-dev] Need a little direction with delegates and main event loop
Brought to you by:
ronaldoussoren
From: Zachery B. <zb...@ur...> - 2003-07-21 20:26:18
|
Hey, all. I'm about 80% of the way done with my first PyObjC app. I've based it=20 on Bill's Cocoa-Python Application template. I've done enough tweaking=20= to both the MyAppDelegate and MainMenu.nib, that I think I'm off-track=20= a bit. Here is some background info on the app and some particular=20 issues I'm facing: It's a "nativication" of Casey Duncan's zopeedit.py, a client-side=20 helper app for his External Editor product for Zope [1]. The=20 server-side method marshalls any editor-worthy Zope object (could be=20 text, like Python Scripts, Zope Page Templates, DTML Methods, &c or it=20= could be images, like gif, jpeg, png, &c) and prepends it with several=20= lines of RFC822 headers of useful metadata. The client side script=20 strips those off for use internally, writes the remaining file out to a=20= temp file, and launches an editor based on a lookup of the=20 content-type/meta-type in an editor mapping. This file zopeedit.py=20 works fine as a standalone on Linux/Windows, but it seems that Mac=20 browsers won't accept an arbitrary file (albeit executable) as a valid=20= helper. This can be somewhat worked around by wrapping the python=20 script in an AppleScript wrapper and using _that_ as the helper app,=20 but it doesn't work for all kinds of editors (notably Carbon apps -=20 with Cocoa apps, I can typically point to the underlying binary in an=20 app bundle - can't seem to do that with Carbon apps, even if they're=20 bundled). So I set about writing my own app in PyObjC, so I could reuse=20= as much code as possible, and extend it where I can to make a more=20 pleasant UI. After cautiously (and incessantly) pestering Bill, I was=20 able to create an Application Delegate whose openFile_: method I=20 overrode to strip the file, look up the appropriate editor (using=20 NSUserDefaults now instead of ConfigParser), and open the stripped file=20= with it. Works great. Some issues: =95=A0Now, unfortunately, I need to fulfill the main loop of the = zopeedit=20 script, and I'm at a bit of a loss on how to do that in the template=20 I'm using. Its __main__.py just jumps right into=20 AppHelper.runEventLoop(). Coupled with the desire to have a bit more=20 control over the event loop, I need to set up some initial app=20 attributes (my current workaround is ugly and doesn't seem to work=20 terribly well anyway). =95=A0I'm trying to make a nice UI table of currently open edits = showing=20 filename and application editing them. I understand the need to=20 delegate the class that will fulfill the various tableView_... methods,=20= but I'm not sure a) where to make the connections in the nib file, and=20= b) where to define their implementation in the project. Here's a rough breakdown of what I'm looking at: =95=A0My app has a data structure of some sort holding current edits=20= (filename, the app that will edit them, and associated metadata used=20 for pushing the changes back to the server) I'd like this to be=20 established in the creation of the app - does this belong in=20 __main__.py? Originally, I tried establishing this in=20 applicationDidFinishLaunching_(), but application_openFile_() is called=20= before that, so I tried moving it to applicationWillFinishLaunching_(),=20= and still it seems not to have been made correctly. =95=A0This data structure needs to fulfill the NSTableDataSource = methods=20 to be set as the data source of the table view. Does this data=20 structure need to be accounted for in the nib? Or just in Python code -=20= meaning, does it need to extend NibClassBuilder.AutoBaseClass? =95=A0The original script just runs with a while: 1 loop watching = over=20 the tempfile it creates and pushes the file back to the server when the=20= mod time changes. I'd prefer to use notifications (seems more elegant),=20= but if I can extend the main event loop with this behavior, that would=20= be an acceptable initial concession. That's basically it. It's an exceedingly simple python script, but=20 turning it into a full Mac OS X app has proved challenging (mostly=20 because I don't have my Cocoa experience - I'm sure all these feature=20 requirements are very simple to the initiated) :) Thanks, Zac [1] External Editor product:=20 <http://www.zope.org/Members/Caseman/ExternalEditor> - You don't need=20 Zope expertise to understand the client-side aspect.= |