Re: [Pyobjc-dev] Need a little direction with delegates and main event loop
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-07-22 05:38:02
|
On Monday, 21 July, 2003, at 22:25, Zachery Bir wrote: > 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=20= > a 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=20 > reuse as much code as possible, and extend it where I can to make a=20 > more pleasant UI. After cautiously (and incessantly) pestering Bill, I=20= > was 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=20 > file with it. Works great. > > Some issues: > > =95=A0Now, unfortunately, I need to fulfill the main loop of the=20 > zopeedit script, and I'm at a bit of a loss on how to do that in the=20= > template 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). There is not much you can do about the runloop, maybe NSRunLoop has=20 methods that allow you to do the outer loop yourself (e.g. while 1:=20 someRunLoop.step()) but that is almost certainly not the right=20 solution. If you only want to setup some global state you can do that before the=20= call to runEventLoop. For timed events look at NSTimer, .... > > =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_...=20 > methods, but I'm not sure a) where to make the connections in the nib=20= > file, and b) where to define their implementation in the project. There is only one connection in the NIB file for this: from the=20 TableView to its data source. The relevant outlet of NSTableView is=20 named dataSource. The TableView example shows you how to implement=20 them. > > 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=20 > called before that, so I tried moving it to=20 > applicationWillFinishLaunching_(), and still it seems not to have been=20= > made correctly. IIRC applicatonWillFinishLaunching_ is called just before=20 applicationDidFinishLaunching, that won't help. I'd create the initial=20= state before calling runEventLoop, and probably in the same file as the=20= rest of the implementation of the model. > > =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? See the TableView example. The datastructure itself need not be present=20= in the NIB. I'd keep the model seperate from the controller. The=20 TableView example doesn't do this, I'll fix that. What I find usefull is using a seperate class for storing the state,=20 and using the controller object (which is mentioned in the NIB) to=20 shuffle data to/from that state. > > =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=20 > the mod time changes. I'd prefer to use notifications (seems more=20 > elegant), but if I can extend the main event loop with this behavior,=20= > that would be an acceptable initial concession. You can use timers to check if the modification time changes. I don't=20 know if there is a higher level API for this (like notification). > > 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) :) Cocoa starts out pretty simple, but most people seem to suffer from a=20 setback soon until they grasp the ideas behind Cocoa. Ronald > > 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. > > > ------------------------------------------------------- > This SF.net email is sponsored by: VM Ware > With VMware you can run multiple operating systems on a single = machine. > WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at = the > same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > |