blob: 5bd2e2a8d59d62e8c1640540ca35605c73e014d1 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Standard Module \module{FrameWork}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +00002\stmodindex{FrameWork}
3\label{module-FrameWork}
4
Fred Drake41788db1998-04-04 06:23:02 +00005The \module{FrameWork} module contains classes that together provide a
Fred Drakeb4efb6c1998-02-18 17:19:11 +00006framework for an interactive Macintosh application. The programmer
7builds an application by creating subclasses that override various
8methods of the bases classes, thereby implementing the functionality
9wanted. Overriding functionality can often be done on various
10different levels, i.e. to handle clicks in a single dialog window in a
11non-standard way it is not necessary to override the complete event
12handling.
13
Fred Drake41788db1998-04-04 06:23:02 +000014The \module{FrameWork} is still very much work-in-progress, and the
Fred Drakeb4efb6c1998-02-18 17:19:11 +000015documentation describes only the most important functionality, and not
16in the most logical manner at that. Examine the source or the examples
17for more details.
18
Fred Drake41788db1998-04-04 06:23:02 +000019The \module{FrameWork} module defines the following functions:
Fred Drakeb4efb6c1998-02-18 17:19:11 +000020
Fred Drakeb4efb6c1998-02-18 17:19:11 +000021
22\begin{funcdesc}{Application}{}
23An object representing the complete application. See below for a
Fred Drake41788db1998-04-04 06:23:02 +000024description of the methods. The default \method{__init__()} routine
Fred Drakeb4efb6c1998-02-18 17:19:11 +000025creates an empty window dictionary and a menu bar with an apple menu.
26\end{funcdesc}
27
28\begin{funcdesc}{MenuBar}{}
29An object representing the menubar. This object is usually not created
30by the user.
31\end{funcdesc}
32
Fred Drakecce10901998-03-17 06:33:25 +000033\begin{funcdesc}{Menu}{bar, title\optional{, after}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +000034An object representing a menu. Upon creation you pass the
35\code{MenuBar} the menu appears in, the \var{title} string and a
36position (1-based) \var{after} where the menu should appear (default:
37at the end).
38\end{funcdesc}
39
Fred Drakecce10901998-03-17 06:33:25 +000040\begin{funcdesc}{MenuItem}{menu, title\optional{, shortcut, callback}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +000041Create a menu item object. The arguments are the menu to crate the
42item it, the item title string and optionally the keyboard shortcut
43and a callback routine. The callback is called with the arguments
44menu-id, item number within menu (1-based), current front window and
45the event record.
46
47In stead of a callable object the callback can also be a string. In
48this case menu selection causes the lookup of a method in the topmost
49window and the application. The method name is the callback string
50with \code{'domenu_'} prepended.
51
52Calling the \code{MenuBar} \code{fixmenudimstate} method sets the
53correct dimming for all menu items based on the current front window.
54\end{funcdesc}
55
56\begin{funcdesc}{Separator}{menu}
57Add a separator to the end of a menu.
58\end{funcdesc}
59
Fred Drakecce10901998-03-17 06:33:25 +000060\begin{funcdesc}{SubMenu}{menu, label}
Fred Drakeb4efb6c1998-02-18 17:19:11 +000061Create a submenu named \var{label} under menu \var{menu}. The menu
62object is returned.
63\end{funcdesc}
64
65\begin{funcdesc}{Window}{parent}
66Creates a (modeless) window. \var{Parent} is the application object to
67which the window belongs. The window is not displayed until later.
68\end{funcdesc}
69
70\begin{funcdesc}{DialogWindow}{parent}
71Creates a modeless dialog window.
72\end{funcdesc}
73
Fred Drakecce10901998-03-17 06:33:25 +000074\begin{funcdesc}{windowbounds}{width, height}
Fred Drakeb4efb6c1998-02-18 17:19:11 +000075Return a \code{(left, top, right, bottom)} tuple suitable for creation
76of a window of given width and height. The window will be staggered
77with respect to previous windows, and an attempt is made to keep the
78whole window on-screen. The window will however always be exact the
79size given, so parts may be offscreen.
80\end{funcdesc}
81
82\begin{funcdesc}{setwatchcursor}{}
83Set the mouse cursor to a watch.
84\end{funcdesc}
85
86\begin{funcdesc}{setarrowcursor}{}
87Set the mouse cursor to an arrow.
88\end{funcdesc}
89
Fred Drake41788db1998-04-04 06:23:02 +000090\subsection{Application Objects}
91\label{application-objects}
92
Fred Drakeb4efb6c1998-02-18 17:19:11 +000093Application objects have the following methods, among others:
94
95\setindexsubitem{(Application method)}
96
97\begin{funcdesc}{makeusermenus}{}
98Override this method if you need menus in your application. Append the
Fred Drake41788db1998-04-04 06:23:02 +000099menus to the attribute \member{menubar}.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000100\end{funcdesc}
101
102\begin{funcdesc}{getabouttext}{}
103Override this method to return a text string describing your
Fred Drake41788db1998-04-04 06:23:02 +0000104application. Alternatively, override the \method{do_about()} method
105for more elaborate ``about'' messages.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000106\end{funcdesc}
107
Fred Drake41788db1998-04-04 06:23:02 +0000108\begin{funcdesc}{mainloop}{\optional{mask\optional{, wait}}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000109This routine is the main event loop, call it to set your application
110rolling. \var{Mask} is the mask of events you want to handle,
111\var{wait} is the number of ticks you want to leave to other
112concurrent application (default 0, which is probably not a good
113idea). While raising \code{self} to exit the mainloop is still
114supported it is not recommended, call \code{self._quit} instead.
115
116The event loop is split into many small parts, each of which can be
117overridden. The default methods take care of dispatching events to
118windows and dialogs, handling drags and resizes, Apple Events, events
119for non-FrameWork windows, etc.
120
Fred Drake41788db1998-04-04 06:23:02 +0000121In general, all event handlers should return \code{1} if the event is fully
122handled and \code{0} otherwise (because the front window was not a FrameWork
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000123window, for instance). This is needed so that update events and such
124can be passed on to other windows like the Sioux console window.
Fred Drake41788db1998-04-04 06:23:02 +0000125Calling \function{MacOS.HandleEvent()} is not allowed within
126\var{our_dispatch} or its callees, since this may result in an
127infinite loop if the code is called through the Python inner-loop
128event handler.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000129\end{funcdesc}
130
131\begin{funcdesc}{asyncevents}{onoff}
132Call this method with a nonzero parameter to enable
133asynchronous event handling. This will tell the inner interpreter loop
134to call the application event handler \var{async_dispatch} whenever events
135are available. This will cause FrameWork window updates and the user
136interface to remain working during long computations, but will slow the
137interpreter down and may cause surprising results in non-reentrant code
138(such as FrameWork itself). By default \var{async_dispatch} will immedeately
139call \var{our_dispatch} but you may override this to handle only certain
140events asynchronously. Events you do not handle will be passed to Sioux
141and such.
142
143The old on/off value is returned.
144\end{funcdesc}
145
146\begin{funcdesc}{_quit}{}
Fred Drake41788db1998-04-04 06:23:02 +0000147Terminate the running \method{mainloop()} call at the next convenient
148moment.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000149\end{funcdesc}
150
Fred Drakecce10901998-03-17 06:33:25 +0000151\begin{funcdesc}{do_char}{c, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000152The user typed character \var{c}. The complete details of the event
153can be found in the \var{event} structure. This method can also be
154provided in a \code{Window} object, which overrides the
155application-wide handler if the window is frontmost.
156\end{funcdesc}
157
158\begin{funcdesc}{do_dialogevent}{event}
159Called early in the event loop to handle modeless dialog events. The
160default method simply dispatches the event to the relevant dialog (not
161through the the \code{DialogWindow} object involved). Override if you
162need special handling of dialog events (keyboard shortcuts, etc).
163\end{funcdesc}
164
165\begin{funcdesc}{idle}{event}
166Called by the main event loop when no events are available. The
167null-event is passed (so you can look at mouse position, etc).
168\end{funcdesc}
169
170\subsection{Window Objects}
Fred Drake41788db1998-04-04 06:23:02 +0000171\label{window-objects}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000172
173Window objects have the following methods, among others:
174
175\setindexsubitem{(Window method)}
176
177\begin{funcdesc}{open}{}
178Override this method to open a window. Store the MacOS window-id in
179\code{self.wid} and call \code{self.do_postopen} to register the
180window with the parent application.
181\end{funcdesc}
182
183\begin{funcdesc}{close}{}
184Override this method to do any special processing on window
185close. Call \code{self.do_postclose} to cleanup the parent state.
186\end{funcdesc}
187
Fred Drakecce10901998-03-17 06:33:25 +0000188\begin{funcdesc}{do_postresize}{width, height, macoswindowid}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000189Called after the window is resized. Override if more needs to be done
190than calling \code{InvalRect}.
191\end{funcdesc}
192
Fred Drakecce10901998-03-17 06:33:25 +0000193\begin{funcdesc}{do_contentclick}{local, modifiers, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000194The user clicked in the content part of a window. The arguments are
195the coordinates (window-relative), the key modifiers and the raw
196event.
197\end{funcdesc}
198
Fred Drakecce10901998-03-17 06:33:25 +0000199\begin{funcdesc}{do_update}{macoswindowid, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000200An update event for the window was received. Redraw the window.
201\end{funcdesc}
202
Fred Drakecce10901998-03-17 06:33:25 +0000203\begin{funcdesc}{do_activate}{activate, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000204The window was activated (\code{activate==1}) or deactivated
205(\code{activate==0}). Handle things like focus highlighting, etc.
206\end{funcdesc}
207
208\subsection{ControlsWindow Object}
Fred Drake41788db1998-04-04 06:23:02 +0000209\label{controlswindow-object}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000210
211ControlsWindow objects have the following methods besides those of
212\code{Window} objects:
213
214\setindexsubitem{(ControlsWindow method)}
215
Fred Drakecce10901998-03-17 06:33:25 +0000216\begin{funcdesc}{do_controlhit}{window, control, pcode, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000217Part \code{pcode} of control \code{control} was hit by the
218user. Tracking and such has already been taken care of.
219\end{funcdesc}
220
221\subsection{ScrolledWindow Object}
Fred Drake41788db1998-04-04 06:23:02 +0000222\label{scrolledwindow-object}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000223
224ScrolledWindow objects are ControlsWindow objects with the following
225extra methods:
226
227\setindexsubitem{(ScrolledWindow method)}
228
Fred Drake41788db1998-04-04 06:23:02 +0000229\begin{funcdesc}{scrollbars}{\optional{wantx\optional{, wanty}}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000230Create (or destroy) horizontal and vertical scrollbars. The arguments
231specify which you want (default: both). The scrollbars always have
232minimum \code{0} and maximum \code{32767}.
233\end{funcdesc}
234
235\begin{funcdesc}{getscrollbarvalues}{}
Fred Drake41788db1998-04-04 06:23:02 +0000236You must supply this method. It should return a tuple \code{(\var{x},
237\var{y})} giving the current position of the scrollbars (between
238\code{0} and \code{32767}). You can return \code{None} for either to
239indicate the whole document is visible in that direction.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000240\end{funcdesc}
241
242\begin{funcdesc}{updatescrollbars}{}
243Call this method when the document has changed. It will call
Fred Drake41788db1998-04-04 06:23:02 +0000244\method{getscrollbarvalues()} and update the scrollbars.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000245\end{funcdesc}
246
Fred Drakecce10901998-03-17 06:33:25 +0000247\begin{funcdesc}{scrollbar_callback}{which, what, value}
Fred Drake41788db1998-04-04 06:23:02 +0000248Supplied by you and called after user interaction. \var{which} will
249be \code{'x'} or \code{'y'}, \var{what} will be \code{'-'},
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000250\code{'--'}, \code{'set'}, \code{'++'} or \code{'+'}. For
Fred Drake41788db1998-04-04 06:23:02 +0000251\code{'set'}, \var{value} will contain the new scrollbar position.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000252\end{funcdesc}
253
Fred Drakecce10901998-03-17 06:33:25 +0000254\begin{funcdesc}{scalebarvalues}{absmin, absmax, curmin, curmax}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000255Auxiliary method to help you calculate values to return from
Fred Drake41788db1998-04-04 06:23:02 +0000256\method{getscrollbarvalues()}. You pass document minimum and maximum value
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000257and topmost (leftmost) and bottommost (rightmost) visible values and
258it returns the correct number or \code{None}.
259\end{funcdesc}
260
Fred Drakecce10901998-03-17 06:33:25 +0000261\begin{funcdesc}{do_activate}{onoff, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000262Takes care of dimming/highlighting scrollbars when a window becomes
263frontmost vv. If you override this method call this one at the end of
264your method.
265\end{funcdesc}
266
Fred Drakecce10901998-03-17 06:33:25 +0000267\begin{funcdesc}{do_postresize}{width, height, window}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000268Moves scrollbars to the correct position. Call this method initially
269if you override it.
270\end{funcdesc}
271
Fred Drakecce10901998-03-17 06:33:25 +0000272\begin{funcdesc}{do_controlhit}{window, control, pcode, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000273Handles scrollbar interaction. If you override it call this method
274first, a nonzero return value indicates the hit was in the scrollbars
275and has been handled.
276\end{funcdesc}
277
278\subsection{DialogWindow Objects}
Fred Drake41788db1998-04-04 06:23:02 +0000279\label{dialogwindow-objects}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000280
281DialogWindow objects have the following methods besides those of
282\code{Window} objects:
283
284\setindexsubitem{(DialogWindow method)}
285
286\begin{funcdesc}{open}{resid}
287Create the dialog window, from the DLOG resource with id
288\var{resid}. The dialog object is stored in \code{self.wid}.
289\end{funcdesc}
290
Fred Drakecce10901998-03-17 06:33:25 +0000291\begin{funcdesc}{do_itemhit}{item, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000292Item number \var{item} was hit. You are responsible for redrawing
293toggle buttons, etc.
294\end{funcdesc}