Re: [Pyobjc-dev] Attempt at writing Cocoa services with pyobjc
Brought to you by:
ronaldoussoren
From: Dinu G. <gh...@da...> - 2003-01-06 19:07:34
|
bb...@ma...: > A Cocoa application generally has the concept of a 'Main NIB file'. > That is, a NIB file that is automatically loaded at application launch > that contains things like the main menu and the primary controller > object. In the case of Cocoa/Python, the default 'controller' object > is an instance of MyAppDelegate. The instance appears in > MainMenu.nib. Ok, I removed just the window from the NIB, but now see spurious complaints like "Could not connect the action buttonPressed: to target of class NSApplication" though I can't find any action method named buttonPressed. > Ahhh... I see... you want to create a services engine that runs > completely in the background. I'll leave the above in anyway (it is > still useful). Yes, ideally without any icons popping up anywhere. > Yes -- this is a bug in the bridge, sort of. There is a category on > NSAutoreleasePool that allows you to push and pop pools, as needed. > > [...] So, just call... > > NSAutoreleasePool.pyobjcPushPool() > > ... instead of NSAutoreleasePool.alloc().init(). Done, but with little if any effect, see below. > PyObjC maps Objective-C exceptions to Python and vice-versa. That is, > you can do: > > try: > NSRunLoop.currentRunLoop().configureAsServer() > NSRunLoop.currentRunLoop().run() > except: > ... handle exception as you would any other Python exception ... Tried to replace this with code more like Ronald's, also with little effect. Here are all three versions I tried: if 0: # inspired by Ronald's code in service.py serviceProvider = PyServices.PyServices.alloc().init() NSRegisterServicesProvider(serviceProvider, "PyServices") NSRunLoop.currentRunLoop().configureAsServer() NSRunLoop.currentRunLoop().run() sys.exit() if 0: # pass control to the AppKit (from template __main__.py) import sys sys.exit(AppKit.NSApplicationMain(sys.argv)) if 1: # stuff ported from URLServices' main.m ## pool = NSAutoreleasePool.alloc().init() pool = NSAutoreleasePool.pyobjcPushPool() serviceProvider = PyServices.PyServices.alloc().init() NSRegisterServicesProvider(serviceProvider, "PyServices") # NS_DURING try: NSRunLoop.currentRunLoop().configureAsServer() NSRunLoop.currentRunLoop().run() # NS_HANDLER except: pass # NSLog("%@", localException) # NS_ENDHANDLER serviceProvider.release() pool.release() > Agreed. I haven't seen URLServices -- is there any reason not to have > some kind of a UI? I.e. does it need preferences, documentation or > any kind of a UI? If so, I would punt on creating an 'invisible' > service -- they are handy for a lot of things, but it also means that > the user cannot easily kill/quit the service. If the service is every > invoked from a disk image or other removable media, the media cannot > be ejected until the service is killed. For now no GUI will be just what I want, later we'll see. Also, I don't care about killing/quitting the service. I do about re- starting newly "improved" services (during development) for which you can either relogin or use a tool named "reloadservices" that I got from somewhere... Here is what I have so far or mentioned before: http://python.net/~gherman/tmp/PythonServices.tgz http://python.net/~gherman/tmp/URLServices.tgz http://python.net/~gherman/tmp/reloadservices Bill, if you can give the first a quick look, great, otherwise I'll delve a bit deeper in frustration... Dinu -- Dinu C. Gherman ...................................................................... "Any sufficiently advanced technology is indistinguishable from magic." (Arthur C. Clarke) |