PyObjCTools.AppHelper – Work with AppKit

This module exports functions that are useful when working with the AppKit framework (or more generally, run loops).

PyObjCTools.AppHelper.callAfter(func, *args, **kwargs) None

Call function on the main thread. Returns immediately.

Parameters:
  • func – The callable to invoke on the main thread.

  • *args – Positional arguments for func.

  • **kwds – Keyword arguments for func.

PyObjCTools.AppHelper.callLater(delay, func, *args, **kwargs) None

Call a function on the main thread after a delay. Returns immediately.

Parameters:
  • delay – The delay in sectonds before invoking func

  • func – The callable to invoke on the main thread.

  • *args – Positional arguments for func.

  • **kwds – Keyword arguments for func.

PyObjCTools.AppHelper.endSheetMethod(method) objc.selector

Convert a method to a form that is suitable to use as the delegate callback for sheet methods.

Parameters:

method – Callable with 3 arguments (the source object, return code and context)

Returns:

Callable wrapped in a selector with the correct signature

PyObjCTools.AppHelper.stopEventLoop() None

Stops the event loop (if started by runConsoleEventLoop()) or sends the NSApplication a terminate: message.

PyObjCTools.AppHelper.runConsoleEventLoop(argv=None, installInterrupt=False, mode=NSDefaultRunLoopMode, maxTimeout=3.0) None

Run a NSRunLoop in a stoppable way (with stopEventLoop).

Parameters:
  • argv – Program argument vector, defaults to sys.argv.

  • installInterrupt – If true install a signal handler that will handle “CTRL+C”.

  • mode – The runloop mode

  • maxTimeout – The maximum delay between calling stopEventLoop() and actually stopping the run loop.

PyObjCTools.AppHelper.runEventLoop(argv=None, unexpectedErrorAlert=None, installInterrupt=None, pdb=None, main=NSApplicationMain) None

Run the event loop using NSApplicationMain and ask the user if we should continue if an exception is caught.

Note

This function doesn’t return unless it throws an exception.

Parameters:
  • argv – Program argument vector, defaults to sys.argv.

  • unexpectedErrorAlert – Callable without arguments that will be invoked when uncaught exception is detected. Defaults to dropping into pdb when pdb is true and to showing an alert panel otherwise.

  • installInterrupt – If true install a signal handler that will handle “CTRL+C”.

  • pdb – If true assume we’re running with a debugger, default is False unless “USE_PDB” is set in the environment

  • main – Main function to use, defaults to NSApplicationMain