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