<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>15.1 Application Objects </TITLE>
<META NAME="description" CONTENT="15.1 Application Objects ">
<META NAME="keywords" CONTENT="mac">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="mac.css">
<LINK REL="next" HREF="window-objects.html">
<LINK REL="previous" HREF="module-FrameWork.html">
<LINK REL="up" HREF="module-FrameWork.html">
<LINK REL="next" HREF="window-objects.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="window-objects.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-FrameWork.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-FrameWork.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Macintosh Library Modules</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="window-objects.html">15.2 Window Objects</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-FrameWork.html">15. FrameWork  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-FrameWork.html">15. FrameWork  </A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION0021510000000000000000"></A>
<BR>
15.1 Application Objects 
</H2>

<P>
Application objects have the following methods, among others:

<P>
<dl><dt><b><a name="l2h-233"><tt class=method>makeusermenus</tt></a></b> ()
<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><b><a name="l2h-234"><tt class=method>getabouttext</tt></a></b> ()
<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><b><a name="l2h-235"><tt class=method>mainloop</tt></a></b> (<big>[</big><var>mask</var><big>[</big><var>, wait</var><big>]</big><big>]</big>)
<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 <tt>self._quit()</tt> 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 <tt>1</tt> if the event is fully
handled and <tt>0</tt> 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><b><a name="l2h-236"><tt class=method>asyncevents</tt></a></b> (<var>onoff</var>)
<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><b><a name="l2h-237"><tt class=method>_quit</tt></a></b> ()
<dd>
Terminate the running <tt class=method>mainloop()</tt> call at the next convenient
moment.
</dl>

<P>
<dl><dt><b><a name="l2h-238"><tt class=method>do_char</tt></a></b> (<var>c, event</var>)
<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 <tt>Window</tt> object, which overrides the
application-wide handler if the window is frontmost.
</dl>

<P>
<dl><dt><b><a name="l2h-239"><tt class=method>do_dialogevent</tt></a></b> (<var>event</var>)
<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 the <tt>DialogWindow</tt> object involved). Override if you
need special handling of dialog events (keyboard shortcuts, etc).
</dl>

<P>
<dl><dt><b><a name="l2h-240"><tt class=method>idle</tt></a></b> (<var>event</var>)
<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>
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="window-objects.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-FrameWork.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-FrameWork.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Macintosh Library Modules</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="window-objects.html">15.2 Window Objects</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-FrameWork.html">15. FrameWork  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-FrameWork.html">15. FrameWork  </A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
