2.13.1 Application Objects

Application objects have the following methods, among others:

makeusermenus()
Override this method if you need menus in your application. Append the menus to the attribute menubar.

getabouttext()
Override this method to return a text string describing your application. Alternatively, override the do_about() method for more elaborate ``about'' messages.

mainloop([mask[, wait]])
This routine is the main event loop, call it to set your application rolling. Mask is the mask of events you want to handle, wait is the number of ticks you want to leave to other concurrent application (default 0, which is probably not a good idea). While raising self to exit the mainloop is still supported it is not recommended: call self._quit() instead.

The event loop is split into many small parts, each of which can be overridden. The default methods take care of dispatching events to windows and dialogs, handling drags and resizes, Apple Events, events for non-FrameWork windows, etc.

In general, all event handlers should return 1 if the event is fully handled and 0 otherwise (because the front window was not a FrameWork window, for instance). This is needed so that update events and such can be passed on to other windows like the Sioux console window. Calling MacOS.HandleEvent() is not allowed within our_dispatch or its callees, since this may result in an infinite loop if the code is called through the Python inner-loop event handler.

asyncevents(onoff)
Call this method with a nonzero parameter to enable asynchronous event handling. This will tell the inner interpreter loop to call the application event handler async_dispatch whenever events are available. This will cause FrameWork window updates and the user interface to remain working during long computations, but will slow the interpreter down and may cause surprising results in non-reentrant code (such as FrameWork itself). By default async_dispatch will immedeately call our_dispatch but you may override this to handle only certain events asynchronously. Events you do not handle will be passed to Sioux and such.

The old on/off value is returned.

_quit()
Terminate the running mainloop() call at the next convenient moment.

do_char(c, event)
The user typed character c. The complete details of the event can be found in the event structure. This method can also be provided in a Window object, which overrides the application-wide handler if the window is frontmost.

do_dialogevent(event)
Called early in the event loop to handle modeless dialog events. The default method simply dispatches the event to the relevant dialog (not through the the DialogWindow object involved). Override if you need special handling of dialog events (keyboard shortcuts, etc).

idle(event)
Called by the main event loop when no events are available. The null-event is passed (so you can look at mouse position, etc).

See About this document... for information on suggesting changes.