<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <link rel="STYLESHEET" href="mac.css" type='text/css' /> <link rel="SHORTCUT ICON" href="../icons/pyfav.gif" /> <link rel='start' href='../index.html' title='Python Documentation Index' /> <link rel="first" href="mac.html" title='Macintosh Library Modules' /> <link rel='contents' href='contents.html' title="Contents" /> <link rel='index' href='genindex.html' title='Index' /> <link rel='last' href='about.html' title='About this document...' /> <link rel='help' href='about.html' title='About this document...' /> <LINK rel="next" href="window-objects.html"> <LINK rel="prev" href="module-FrameWork.html"> <LINK rel="parent" href="module-FrameWork.html"> <LINK rel="next" href="window-objects.html"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name='aesop' content='information' /> <META name="description" content="Application Objects "> <META name="keywords" content="mac"> <META name="resource-type" content="document"> <META name="distribution" content="global"> <title>2.9.1 Application Objects </title> </head> <body> <DIV CLASS="navigation"> <div id='top-navigation-panel'> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td class='online-navigation'><a rel="prev" title="2.9 FrameWork " href="module-FrameWork.html"><img src='../icons/previous.png' border='0' height='32' alt='Previous Page' width='32' /></A></td> <td class='online-navigation'><a rel="parent" title="2.9 FrameWork " href="module-FrameWork.html"><img src='../icons/up.png' border='0' height='32' alt='Up One Level' width='32' /></A></td> <td class='online-navigation'><a rel="next" title="2.9.2 Window Objects" href="window-objects.html"><img src='../icons/next.png' border='0' height='32' alt='Next Page' width='32' /></A></td> <td align="center" width="100%">Macintosh Library Modules</td> <td class='online-navigation'><a rel="contents" title="Table of Contents" href="contents.html"><img src='../icons/contents.png' border='0' height='32' alt='Contents' width='32' /></A></td> <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' border='0' height='32' alt='Module Index' width='32' /></a></td> <td class='online-navigation'><a rel="index" title="Index" href="genindex.html"><img src='../icons/index.png' border='0' height='32' alt='Index' width='32' /></A></td> </tr></table> <div class='online-navigation'> <b class="navlabel">Previous:</b> <a class="sectref" rel="prev" href="module-FrameWork.html">2.9 FrameWork </A> <b class="navlabel">Up:</b> <a class="sectref" rel="parent" href="module-FrameWork.html">2.9 FrameWork </A> <b class="navlabel">Next:</b> <a class="sectref" rel="next" href="window-objects.html">2.9.2 Window Objects</A> </div> <hr /></div> </DIV> <!--End of Navigation Panel--> <H2><A NAME="SECTION004910000000000000000"><!--x--></A><A NAME="application-objects"><!--z--></A> <BR> 2.9.1 Application Objects </H2> <P> Application objects have the following methods, among others: <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-116' class="method">makeusermenus</tt></b>(</nobr></td> <td>)</td></tr></table></dt> <dd> Override this method if you need menus in your application. Append the menus to the attribute <tt class="member">menubar</tt>. </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-117' class="method">getabouttext</tt></b>(</nobr></td> <td>)</td></tr></table></dt> <dd> Override this method to return a text string describing your application. Alternatively, override the <tt class="method">do_about()</tt> method for more elaborate ``about'' messages. </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-118' class="method">mainloop</tt></b>(</nobr></td> <td><big>[</big><var>mask</var><big>[</big><var>, wait</var><big>]</big><big>]</big>)</td></tr></table></dt> <dd> This routine is the main event loop, call it to set your application rolling. <var>Mask</var> is the mask of events you want to handle, <var>wait</var> is the number of ticks you want to leave to other concurrent application (default 0, which is probably not a good idea). While raising <var>self</var> to exit the mainloop is still supported it is not recommended: call <code>self._quit()</code> instead. <P> 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. <P> In general, all event handlers should return <code>1</code> if the event is fully handled and <code>0</code> 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 <tt class="function">MacOS.HandleEvent()</tt> is not allowed within <var>our_dispatch</var> or its callees, since this may result in an infinite loop if the code is called through the Python inner-loop event handler. </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-119' class="method">asyncevents</tt></b>(</nobr></td> <td><var>onoff</var>)</td></tr></table></dt> <dd> 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 <var>async_dispatch</var> 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 <var>async_dispatch</var> will immedeately call <var>our_dispatch</var> but you may override this to handle only certain events asynchronously. Events you do not handle will be passed to Sioux and such. <P> The old on/off value is returned. </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-120' class="method">_quit</tt></b>(</nobr></td> <td>)</td></tr></table></dt> <dd> Terminate the running <tt class="method">mainloop()</tt> call at the next convenient moment. </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-121' class="method">do_char</tt></b>(</nobr></td> <td><var>c, event</var>)</td></tr></table></dt> <dd> The user typed character <var>c</var>. The complete details of the event can be found in the <var>event</var> structure. This method can also be provided in a <code>Window</code> object, which overrides the application-wide handler if the window is frontmost. </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-122' class="method">do_dialogevent</tt></b>(</nobr></td> <td><var>event</var>)</td></tr></table></dt> <dd> 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 <code>DialogWindow</code> object involved). Override if you need special handling of dialog events (keyboard shortcuts, etc). </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-123' class="method">idle</tt></b>(</nobr></td> <td><var>event</var>)</td></tr></table></dt> <dd> Called by the main event loop when no events are available. The null-event is passed (so you can look at mouse position, etc). </dl> <P> <DIV CLASS="navigation"> <div class='online-navigation'><hr /> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td class='online-navigation'><a rel="prev" title="2.9 FrameWork " rel="prev" title="2.9 FrameWork " href="module-FrameWork.html"><img src='../icons/previous.png' border='0' height='32' alt='Previous Page' width='32' /></A></td> <td class='online-navigation'><a rel="parent" title="2.9 FrameWork " rel="parent" title="2.9 FrameWork " href="module-FrameWork.html"><img src='../icons/up.png' border='0' height='32' alt='Up One Level' width='32' /></A></td> <td class='online-navigation'><a rel="next" title="2.9.2 Window Objects" rel="next" title="2.9.2 Window Objects" href="window-objects.html"><img src='../icons/next.png' border='0' height='32' alt='Next Page' width='32' /></A></td> <td align="center" width="100%">Macintosh Library Modules</td> <td class='online-navigation'><a rel="contents" title="Table of Contents" rel="contents" title="Table of Contents" href="contents.html"><img src='../icons/contents.png' border='0' height='32' alt='Contents' width='32' /></A></td> <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' border='0' height='32' alt='Module Index' width='32' /></a></td> <td class='online-navigation'><a rel="index" title="Index" rel="index" title="Index" href="genindex.html"><img src='../icons/index.png' border='0' height='32' alt='Index' width='32' /></A></td> </tr></table> <div class='online-navigation'> <b class="navlabel">Previous:</b> <a class="sectref" rel="prev" href="module-FrameWork.html">2.9 FrameWork </A> <b class="navlabel">Up:</b> <a class="sectref" rel="parent" href="module-FrameWork.html">2.9 FrameWork </A> <b class="navlabel">Next:</b> <a class="sectref" rel="next" href="window-objects.html">2.9.2 Window Objects</A> </div> </div> <hr /> <span class="release-info">Release 2.3.4, documentation updated on May 20, 2004.</span> </DIV> <!--End of Navigation Panel--> <ADDRESS> See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. </ADDRESS> </BODY> </HTML>