blob: 7c10e25330b86ce83b2bd634925bcc632648b23a [file] [log] [blame]
Fred Drakec817e271998-08-10 18:40:22 +00001\section{\module{FrameWork} ---
2 Interactive application framework.}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00003\declaremodule{standard}{FrameWork}
4
5\modulesynopsis{Interactive application framework.}
6
Fred Drakeb4efb6c1998-02-18 17:19:11 +00007
Fred Drake41788db1998-04-04 06:23:02 +00008The \module{FrameWork} module contains classes that together provide a
Fred Drakeb4efb6c1998-02-18 17:19:11 +00009framework for an interactive Macintosh application. The programmer
10builds an application by creating subclasses that override various
11methods of the bases classes, thereby implementing the functionality
12wanted. Overriding functionality can often be done on various
13different levels, i.e. to handle clicks in a single dialog window in a
14non-standard way it is not necessary to override the complete event
15handling.
16
Fred Drake41788db1998-04-04 06:23:02 +000017The \module{FrameWork} is still very much work-in-progress, and the
Fred Drakeb4efb6c1998-02-18 17:19:11 +000018documentation describes only the most important functionality, and not
19in the most logical manner at that. Examine the source or the examples
20for more details.
21
Fred Drake41788db1998-04-04 06:23:02 +000022The \module{FrameWork} module defines the following functions:
Fred Drakeb4efb6c1998-02-18 17:19:11 +000023
Fred Drakeb4efb6c1998-02-18 17:19:11 +000024
25\begin{funcdesc}{Application}{}
26An object representing the complete application. See below for a
Fred Drake41788db1998-04-04 06:23:02 +000027description of the methods. The default \method{__init__()} routine
Fred Drakeb4efb6c1998-02-18 17:19:11 +000028creates an empty window dictionary and a menu bar with an apple menu.
29\end{funcdesc}
30
31\begin{funcdesc}{MenuBar}{}
32An object representing the menubar. This object is usually not created
33by the user.
34\end{funcdesc}
35
Fred Drakecce10901998-03-17 06:33:25 +000036\begin{funcdesc}{Menu}{bar, title\optional{, after}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +000037An object representing a menu. Upon creation you pass the
38\code{MenuBar} the menu appears in, the \var{title} string and a
39position (1-based) \var{after} where the menu should appear (default:
40at the end).
41\end{funcdesc}
42
Fred Drakecce10901998-03-17 06:33:25 +000043\begin{funcdesc}{MenuItem}{menu, title\optional{, shortcut, callback}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +000044Create a menu item object. The arguments are the menu to crate the
45item it, the item title string and optionally the keyboard shortcut
46and a callback routine. The callback is called with the arguments
47menu-id, item number within menu (1-based), current front window and
48the event record.
49
50In stead of a callable object the callback can also be a string. In
51this case menu selection causes the lookup of a method in the topmost
52window and the application. The method name is the callback string
53with \code{'domenu_'} prepended.
54
55Calling the \code{MenuBar} \code{fixmenudimstate} method sets the
56correct dimming for all menu items based on the current front window.
57\end{funcdesc}
58
59\begin{funcdesc}{Separator}{menu}
60Add a separator to the end of a menu.
61\end{funcdesc}
62
Fred Drakecce10901998-03-17 06:33:25 +000063\begin{funcdesc}{SubMenu}{menu, label}
Fred Drakeb4efb6c1998-02-18 17:19:11 +000064Create a submenu named \var{label} under menu \var{menu}. The menu
65object is returned.
66\end{funcdesc}
67
68\begin{funcdesc}{Window}{parent}
69Creates a (modeless) window. \var{Parent} is the application object to
70which the window belongs. The window is not displayed until later.
71\end{funcdesc}
72
73\begin{funcdesc}{DialogWindow}{parent}
74Creates a modeless dialog window.
75\end{funcdesc}
76
Fred Drakecce10901998-03-17 06:33:25 +000077\begin{funcdesc}{windowbounds}{width, height}
Fred Drakeb4efb6c1998-02-18 17:19:11 +000078Return a \code{(left, top, right, bottom)} tuple suitable for creation
79of a window of given width and height. The window will be staggered
80with respect to previous windows, and an attempt is made to keep the
81whole window on-screen. The window will however always be exact the
82size given, so parts may be offscreen.
83\end{funcdesc}
84
85\begin{funcdesc}{setwatchcursor}{}
86Set the mouse cursor to a watch.
87\end{funcdesc}
88
89\begin{funcdesc}{setarrowcursor}{}
90Set the mouse cursor to an arrow.
91\end{funcdesc}
92
Fred Drake41788db1998-04-04 06:23:02 +000093\subsection{Application Objects}
94\label{application-objects}
95
Fred Drakeb4efb6c1998-02-18 17:19:11 +000096Application objects have the following methods, among others:
97
98\setindexsubitem{(Application method)}
99
100\begin{funcdesc}{makeusermenus}{}
101Override this method if you need menus in your application. Append the
Fred Drake41788db1998-04-04 06:23:02 +0000102menus to the attribute \member{menubar}.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000103\end{funcdesc}
104
105\begin{funcdesc}{getabouttext}{}
106Override this method to return a text string describing your
Fred Drake41788db1998-04-04 06:23:02 +0000107application. Alternatively, override the \method{do_about()} method
108for more elaborate ``about'' messages.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000109\end{funcdesc}
110
Fred Drake41788db1998-04-04 06:23:02 +0000111\begin{funcdesc}{mainloop}{\optional{mask\optional{, wait}}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000112This routine is the main event loop, call it to set your application
113rolling. \var{Mask} is the mask of events you want to handle,
114\var{wait} is the number of ticks you want to leave to other
115concurrent application (default 0, which is probably not a good
116idea). While raising \code{self} to exit the mainloop is still
117supported it is not recommended, call \code{self._quit} instead.
118
119The event loop is split into many small parts, each of which can be
120overridden. The default methods take care of dispatching events to
121windows and dialogs, handling drags and resizes, Apple Events, events
122for non-FrameWork windows, etc.
123
Fred Drake41788db1998-04-04 06:23:02 +0000124In general, all event handlers should return \code{1} if the event is fully
125handled and \code{0} otherwise (because the front window was not a FrameWork
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000126window, for instance). This is needed so that update events and such
127can be passed on to other windows like the Sioux console window.
Fred Drake41788db1998-04-04 06:23:02 +0000128Calling \function{MacOS.HandleEvent()} is not allowed within
129\var{our_dispatch} or its callees, since this may result in an
130infinite loop if the code is called through the Python inner-loop
131event handler.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000132\end{funcdesc}
133
134\begin{funcdesc}{asyncevents}{onoff}
135Call this method with a nonzero parameter to enable
136asynchronous event handling. This will tell the inner interpreter loop
137to call the application event handler \var{async_dispatch} whenever events
138are available. This will cause FrameWork window updates and the user
139interface to remain working during long computations, but will slow the
140interpreter down and may cause surprising results in non-reentrant code
141(such as FrameWork itself). By default \var{async_dispatch} will immedeately
142call \var{our_dispatch} but you may override this to handle only certain
143events asynchronously. Events you do not handle will be passed to Sioux
144and such.
145
146The old on/off value is returned.
147\end{funcdesc}
148
149\begin{funcdesc}{_quit}{}
Fred Drake41788db1998-04-04 06:23:02 +0000150Terminate the running \method{mainloop()} call at the next convenient
151moment.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000152\end{funcdesc}
153
Fred Drakecce10901998-03-17 06:33:25 +0000154\begin{funcdesc}{do_char}{c, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000155The user typed character \var{c}. The complete details of the event
156can be found in the \var{event} structure. This method can also be
157provided in a \code{Window} object, which overrides the
158application-wide handler if the window is frontmost.
159\end{funcdesc}
160
161\begin{funcdesc}{do_dialogevent}{event}
162Called early in the event loop to handle modeless dialog events. The
163default method simply dispatches the event to the relevant dialog (not
164through the the \code{DialogWindow} object involved). Override if you
165need special handling of dialog events (keyboard shortcuts, etc).
166\end{funcdesc}
167
168\begin{funcdesc}{idle}{event}
169Called by the main event loop when no events are available. The
170null-event is passed (so you can look at mouse position, etc).
171\end{funcdesc}
172
173\subsection{Window Objects}
Fred Drake41788db1998-04-04 06:23:02 +0000174\label{window-objects}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000175
176Window objects have the following methods, among others:
177
178\setindexsubitem{(Window method)}
179
180\begin{funcdesc}{open}{}
181Override this method to open a window. Store the MacOS window-id in
182\code{self.wid} and call \code{self.do_postopen} to register the
183window with the parent application.
184\end{funcdesc}
185
186\begin{funcdesc}{close}{}
187Override this method to do any special processing on window
188close. Call \code{self.do_postclose} to cleanup the parent state.
189\end{funcdesc}
190
Fred Drakecce10901998-03-17 06:33:25 +0000191\begin{funcdesc}{do_postresize}{width, height, macoswindowid}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000192Called after the window is resized. Override if more needs to be done
193than calling \code{InvalRect}.
194\end{funcdesc}
195
Fred Drakecce10901998-03-17 06:33:25 +0000196\begin{funcdesc}{do_contentclick}{local, modifiers, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000197The user clicked in the content part of a window. The arguments are
198the coordinates (window-relative), the key modifiers and the raw
199event.
200\end{funcdesc}
201
Fred Drakecce10901998-03-17 06:33:25 +0000202\begin{funcdesc}{do_update}{macoswindowid, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000203An update event for the window was received. Redraw the window.
204\end{funcdesc}
205
Fred Drakecce10901998-03-17 06:33:25 +0000206\begin{funcdesc}{do_activate}{activate, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000207The window was activated (\code{activate==1}) or deactivated
208(\code{activate==0}). Handle things like focus highlighting, etc.
209\end{funcdesc}
210
211\subsection{ControlsWindow Object}
Fred Drake41788db1998-04-04 06:23:02 +0000212\label{controlswindow-object}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000213
214ControlsWindow objects have the following methods besides those of
215\code{Window} objects:
216
217\setindexsubitem{(ControlsWindow method)}
218
Fred Drakecce10901998-03-17 06:33:25 +0000219\begin{funcdesc}{do_controlhit}{window, control, pcode, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000220Part \code{pcode} of control \code{control} was hit by the
221user. Tracking and such has already been taken care of.
222\end{funcdesc}
223
224\subsection{ScrolledWindow Object}
Fred Drake41788db1998-04-04 06:23:02 +0000225\label{scrolledwindow-object}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000226
227ScrolledWindow objects are ControlsWindow objects with the following
228extra methods:
229
230\setindexsubitem{(ScrolledWindow method)}
231
Fred Drake41788db1998-04-04 06:23:02 +0000232\begin{funcdesc}{scrollbars}{\optional{wantx\optional{, wanty}}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000233Create (or destroy) horizontal and vertical scrollbars. The arguments
234specify which you want (default: both). The scrollbars always have
235minimum \code{0} and maximum \code{32767}.
236\end{funcdesc}
237
238\begin{funcdesc}{getscrollbarvalues}{}
Fred Drake41788db1998-04-04 06:23:02 +0000239You must supply this method. It should return a tuple \code{(\var{x},
240\var{y})} giving the current position of the scrollbars (between
241\code{0} and \code{32767}). You can return \code{None} for either to
242indicate the whole document is visible in that direction.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000243\end{funcdesc}
244
245\begin{funcdesc}{updatescrollbars}{}
246Call this method when the document has changed. It will call
Fred Drake41788db1998-04-04 06:23:02 +0000247\method{getscrollbarvalues()} and update the scrollbars.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000248\end{funcdesc}
249
Fred Drakecce10901998-03-17 06:33:25 +0000250\begin{funcdesc}{scrollbar_callback}{which, what, value}
Fred Drake41788db1998-04-04 06:23:02 +0000251Supplied by you and called after user interaction. \var{which} will
252be \code{'x'} or \code{'y'}, \var{what} will be \code{'-'},
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000253\code{'--'}, \code{'set'}, \code{'++'} or \code{'+'}. For
Fred Drake41788db1998-04-04 06:23:02 +0000254\code{'set'}, \var{value} will contain the new scrollbar position.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000255\end{funcdesc}
256
Fred Drakecce10901998-03-17 06:33:25 +0000257\begin{funcdesc}{scalebarvalues}{absmin, absmax, curmin, curmax}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000258Auxiliary method to help you calculate values to return from
Fred Drake41788db1998-04-04 06:23:02 +0000259\method{getscrollbarvalues()}. You pass document minimum and maximum value
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000260and topmost (leftmost) and bottommost (rightmost) visible values and
261it returns the correct number or \code{None}.
262\end{funcdesc}
263
Fred Drakecce10901998-03-17 06:33:25 +0000264\begin{funcdesc}{do_activate}{onoff, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000265Takes care of dimming/highlighting scrollbars when a window becomes
266frontmost vv. If you override this method call this one at the end of
267your method.
268\end{funcdesc}
269
Fred Drakecce10901998-03-17 06:33:25 +0000270\begin{funcdesc}{do_postresize}{width, height, window}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000271Moves scrollbars to the correct position. Call this method initially
272if you override it.
273\end{funcdesc}
274
Fred Drakecce10901998-03-17 06:33:25 +0000275\begin{funcdesc}{do_controlhit}{window, control, pcode, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000276Handles scrollbar interaction. If you override it call this method
277first, a nonzero return value indicates the hit was in the scrollbars
278and has been handled.
279\end{funcdesc}
280
281\subsection{DialogWindow Objects}
Fred Drake41788db1998-04-04 06:23:02 +0000282\label{dialogwindow-objects}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000283
284DialogWindow objects have the following methods besides those of
285\code{Window} objects:
286
287\setindexsubitem{(DialogWindow method)}
288
289\begin{funcdesc}{open}{resid}
290Create the dialog window, from the DLOG resource with id
291\var{resid}. The dialog object is stored in \code{self.wid}.
292\end{funcdesc}
293
Fred Drakecce10901998-03-17 06:33:25 +0000294\begin{funcdesc}{do_itemhit}{item, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000295Item number \var{item} was hit. You are responsible for redrawing
296toggle buttons, etc.
297\end{funcdesc}