[Pyobjc-dev] NSApplicationMain idiom: wish to standardize
Brought to you by:
ronaldoussoren
From: Just v. R. <ju...@le...> - 2003-03-20 14:23:43
|
I've been using the following idiom to enter the Cocoa main event loop for some time now: def unexpectedErrorAlert(): exceptionInfo = traceback.format_exception_only(*sys.exc_info()[:2])[0].strip() return NSRunAlertPanel("An unexpected error has occurred", "(%s)" % exceptionInfo, "Continue", "Quit", None) mainFunc = NSApplicationMain args = (sys.argv,) while 1: try: mainFunc(*args) except: traceback.print_exc() if not unexpectedErrorAlert(): break mainFunc = NSApp().run args = () else: break It's more complicated than what I originally thought was needed back when we discussed NSApplicationMain raising exceptions, as simply calling NSApplicationMain() again causes the main nib to be reloaded. The thing is, it's quite a few lines now, and I keep copying it to new apps. I would like to put it in a module, but if it's deemed general enough, I could also integrate it into PyObjC somewhere. What do people think, is it desirable to have in PyObjC? I would propose a new submodule op AppKit, eg. named mainHelper.py. The above could then become from AppKit import mainHelper mainHelper.runEventLoop() Better names are gladly accepted... Just |