blob: 012b8c52d3d671472e3fc7805d7f79c473bff95e [file] [log] [blame]
Fred Drakeb4efb6c1998-02-18 17:19:11 +00001\section{Standard Module \sectcode{FrameWork}}
2\stmodindex{FrameWork}
3\label{module-FrameWork}
4
5The \code{FrameWork} module contains classes that together provide a
6framework 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
14The \code{FrameWork} is still very much work-in-progress, and the
15documentation 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
19The \code{FrameWork} module defines the following functions:
20
21\setindexsubitem{(in module FrameWork)}
22
23\begin{funcdesc}{Application}{}
24An object representing the complete application. See below for a
25description of the methods. The default \code{__init__} routine
26creates an empty window dictionary and a menu bar with an apple menu.
27\end{funcdesc}
28
29\begin{funcdesc}{MenuBar}{}
30An object representing the menubar. This object is usually not created
31by the user.
32\end{funcdesc}
33
34\begin{funcdesc}{Menu}{bar\, title\optional{\, after}}
35An object representing a menu. Upon creation you pass the
36\code{MenuBar} the menu appears in, the \var{title} string and a
37position (1-based) \var{after} where the menu should appear (default:
38at the end).
39\end{funcdesc}
40
41\begin{funcdesc}{MenuItem}{menu\, title\optional{\, shortcut\, callback}}
42Create a menu item object. The arguments are the menu to crate the
43item it, the item title string and optionally the keyboard shortcut
44and a callback routine. The callback is called with the arguments
45menu-id, item number within menu (1-based), current front window and
46the event record.
47
48In stead of a callable object the callback can also be a string. In
49this case menu selection causes the lookup of a method in the topmost
50window and the application. The method name is the callback string
51with \code{'domenu_'} prepended.
52
53Calling the \code{MenuBar} \code{fixmenudimstate} method sets the
54correct dimming for all menu items based on the current front window.
55\end{funcdesc}
56
57\begin{funcdesc}{Separator}{menu}
58Add a separator to the end of a menu.
59\end{funcdesc}
60
61\begin{funcdesc}{SubMenu}{menu\, label}
62Create a submenu named \var{label} under menu \var{menu}. The menu
63object is returned.
64\end{funcdesc}
65
66\begin{funcdesc}{Window}{parent}
67Creates a (modeless) window. \var{Parent} is the application object to
68which the window belongs. The window is not displayed until later.
69\end{funcdesc}
70
71\begin{funcdesc}{DialogWindow}{parent}
72Creates a modeless dialog window.
73\end{funcdesc}
74
75\begin{funcdesc}{windowbounds}{width\, height}
76Return a \code{(left, top, right, bottom)} tuple suitable for creation
77of a window of given width and height. The window will be staggered
78with respect to previous windows, and an attempt is made to keep the
79whole window on-screen. The window will however always be exact the
80size given, so parts may be offscreen.
81\end{funcdesc}
82
83\begin{funcdesc}{setwatchcursor}{}
84Set the mouse cursor to a watch.
85\end{funcdesc}
86
87\begin{funcdesc}{setarrowcursor}{}
88Set the mouse cursor to an arrow.
89\end{funcdesc}
90
91\subsection{Application objects}
92Application objects have the following methods, among others:
93
94\setindexsubitem{(Application method)}
95
96\begin{funcdesc}{makeusermenus}{}
97Override this method if you need menus in your application. Append the
98menus to \code{self.menubar}.
99\end{funcdesc}
100
101\begin{funcdesc}{getabouttext}{}
102Override this method to return a text string describing your
103application. Alternatively, override the \code{do_about} method for
104more elaborate about messages.
105\end{funcdesc}
106
107\begin{funcdesc}{mainloop}{\optional{mask\, wait}}
108This routine is the main event loop, call it to set your application
109rolling. \var{Mask} is the mask of events you want to handle,
110\var{wait} is the number of ticks you want to leave to other
111concurrent application (default 0, which is probably not a good
112idea). While raising \code{self} to exit the mainloop is still
113supported it is not recommended, call \code{self._quit} instead.
114
115The event loop is split into many small parts, each of which can be
116overridden. The default methods take care of dispatching events to
117windows and dialogs, handling drags and resizes, Apple Events, events
118for non-FrameWork windows, etc.
119
120In general, all event handlers should return 1 if the event is fully
121handled and 0 otherwise (because the front window was not a FrameWork
122window, for instance). This is needed so that update events and such
123can be passed on to other windows like the Sioux console window.
124Calling \code{MacOS.HandleEvent} is not allowed within \var{our_dispatch}
125or its callees, since this may result in an infinite loop if the
126code is called through the python inner-loop event handler.
127\end{funcdesc}
128
129\begin{funcdesc}{asyncevents}{onoff}
130Call this method with a nonzero parameter to enable
131asynchronous event handling. This will tell the inner interpreter loop
132to call the application event handler \var{async_dispatch} whenever events
133are available. This will cause FrameWork window updates and the user
134interface to remain working during long computations, but will slow the
135interpreter down and may cause surprising results in non-reentrant code
136(such as FrameWork itself). By default \var{async_dispatch} will immedeately
137call \var{our_dispatch} but you may override this to handle only certain
138events asynchronously. Events you do not handle will be passed to Sioux
139and such.
140
141The old on/off value is returned.
142\end{funcdesc}
143
144\begin{funcdesc}{_quit}{}
145Terminate the event \code{mainloop} at the next convenient moment.
146\end{funcdesc}
147
148\begin{funcdesc}{do_char}{c\, event}
149The user typed character \var{c}. The complete details of the event
150can be found in the \var{event} structure. This method can also be
151provided in a \code{Window} object, which overrides the
152application-wide handler if the window is frontmost.
153\end{funcdesc}
154
155\begin{funcdesc}{do_dialogevent}{event}
156Called early in the event loop to handle modeless dialog events. The
157default method simply dispatches the event to the relevant dialog (not
158through the the \code{DialogWindow} object involved). Override if you
159need special handling of dialog events (keyboard shortcuts, etc).
160\end{funcdesc}
161
162\begin{funcdesc}{idle}{event}
163Called by the main event loop when no events are available. The
164null-event is passed (so you can look at mouse position, etc).
165\end{funcdesc}
166
167\subsection{Window Objects}
168
169Window objects have the following methods, among others:
170
171\setindexsubitem{(Window method)}
172
173\begin{funcdesc}{open}{}
174Override this method to open a window. Store the MacOS window-id in
175\code{self.wid} and call \code{self.do_postopen} to register the
176window with the parent application.
177\end{funcdesc}
178
179\begin{funcdesc}{close}{}
180Override this method to do any special processing on window
181close. Call \code{self.do_postclose} to cleanup the parent state.
182\end{funcdesc}
183
184\begin{funcdesc}{do_postresize}{width\, height\, macoswindowid}
185Called after the window is resized. Override if more needs to be done
186than calling \code{InvalRect}.
187\end{funcdesc}
188
189\begin{funcdesc}{do_contentclick}{local\, modifiers\, event}
190The user clicked in the content part of a window. The arguments are
191the coordinates (window-relative), the key modifiers and the raw
192event.
193\end{funcdesc}
194
195\begin{funcdesc}{do_update}{macoswindowid\, event}
196An update event for the window was received. Redraw the window.
197\end{funcdesc}
198
199\begin{funcdesc}{do_activate}{activate\, event}
200The window was activated (\code{activate==1}) or deactivated
201(\code{activate==0}). Handle things like focus highlighting, etc.
202\end{funcdesc}
203
204\subsection{ControlsWindow Object}
205
206ControlsWindow objects have the following methods besides those of
207\code{Window} objects:
208
209\setindexsubitem{(ControlsWindow method)}
210
211\begin{funcdesc}{do_controlhit}{window\, control\, pcode\, event}
212Part \code{pcode} of control \code{control} was hit by the
213user. Tracking and such has already been taken care of.
214\end{funcdesc}
215
216\subsection{ScrolledWindow Object}
217
218ScrolledWindow objects are ControlsWindow objects with the following
219extra methods:
220
221\setindexsubitem{(ScrolledWindow method)}
222
223\begin{funcdesc}{scrollbars}{\optional{wantx\, wanty}}
224Create (or destroy) horizontal and vertical scrollbars. The arguments
225specify which you want (default: both). The scrollbars always have
226minimum \code{0} and maximum \code{32767}.
227\end{funcdesc}
228
229\begin{funcdesc}{getscrollbarvalues}{}
230You must supply this method. It should return a tuple \code{x, y}
231giving the current position of the scrollbars (between \code{0} and
232\code{32767}). You can return \code{None} for either to indicate the
233whole document is visible in that direction.
234\end{funcdesc}
235
236\begin{funcdesc}{updatescrollbars}{}
237Call this method when the document has changed. It will call
238\code{getscrollbarvalues} and update the scrollbars.
239\end{funcdesc}
240
241\begin{funcdesc}{scrollbar_callback}{which\, what\, value}
242Supplied by you and called after user interaction. \code{Which} will
243be \code{'x'} or \code{'y'}, \code{what} will be \code{'-'},
244\code{'--'}, \code{'set'}, \code{'++'} or \code{'+'}. For
245\code{'set'}, \code{value} will contain the new scrollbar position.
246\end{funcdesc}
247
248\begin{funcdesc}{scalebarvalues}{absmin\, absmax\, curmin\, curmax}
249Auxiliary method to help you calculate values to return from
250\code{getscrollbarvalues}. You pass document minimum and maximum value
251and topmost (leftmost) and bottommost (rightmost) visible values and
252it returns the correct number or \code{None}.
253\end{funcdesc}
254
255\begin{funcdesc}{do_activate}{onoff\, event}
256Takes care of dimming/highlighting scrollbars when a window becomes
257frontmost vv. If you override this method call this one at the end of
258your method.
259\end{funcdesc}
260
261\begin{funcdesc}{do_postresize}{width\, height\, window}
262Moves scrollbars to the correct position. Call this method initially
263if you override it.
264\end{funcdesc}
265
266\begin{funcdesc}{do_controlhit}{window\, control\, pcode\, event}
267Handles scrollbar interaction. If you override it call this method
268first, a nonzero return value indicates the hit was in the scrollbars
269and has been handled.
270\end{funcdesc}
271
272\subsection{DialogWindow Objects}
273
274DialogWindow objects have the following methods besides those of
275\code{Window} objects:
276
277\setindexsubitem{(DialogWindow method)}
278
279\begin{funcdesc}{open}{resid}
280Create the dialog window, from the DLOG resource with id
281\var{resid}. The dialog object is stored in \code{self.wid}.
282\end{funcdesc}
283
284\begin{funcdesc}{do_itemhit}{item\, event}
285Item number \var{item} was hit. You are responsible for redrawing
286toggle buttons, etc.
287\end{funcdesc}