blob: 31f8a473a97cafe42908d9ee091974dcd100d5a2 [file] [log] [blame]
Fred Drakec817e271998-08-10 18:40:22 +00001\section{\module{FrameWork} ---
Fred Drakef6863c11999-03-02 16:37:17 +00002 Interactive application framework}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00003
Fred Drakef6863c11999-03-02 16:37:17 +00004\declaremodule{standard}{FrameWork}
5 \platform{Mac}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00006\modulesynopsis{Interactive application framework.}
7
Fred Drakeb4efb6c1998-02-18 17:19:11 +00008
Fred Drake41788db1998-04-04 06:23:02 +00009The \module{FrameWork} module contains classes that together provide a
Fred Drakeb4efb6c1998-02-18 17:19:11 +000010framework for an interactive Macintosh application. The programmer
11builds an application by creating subclasses that override various
12methods of the bases classes, thereby implementing the functionality
13wanted. Overriding functionality can often be done on various
14different levels, i.e. to handle clicks in a single dialog window in a
15non-standard way it is not necessary to override the complete event
16handling.
17
Fred Drake41788db1998-04-04 06:23:02 +000018The \module{FrameWork} is still very much work-in-progress, and the
Fred Drakeb4efb6c1998-02-18 17:19:11 +000019documentation describes only the most important functionality, and not
20in the most logical manner at that. Examine the source or the examples
21for more details.
22
Fred Drake41788db1998-04-04 06:23:02 +000023The \module{FrameWork} module defines the following functions:
Fred Drakeb4efb6c1998-02-18 17:19:11 +000024
Fred Drakeb4efb6c1998-02-18 17:19:11 +000025
26\begin{funcdesc}{Application}{}
27An object representing the complete application. See below for a
Fred Drake41788db1998-04-04 06:23:02 +000028description of the methods. The default \method{__init__()} routine
Fred Drakeb4efb6c1998-02-18 17:19:11 +000029creates an empty window dictionary and a menu bar with an apple menu.
30\end{funcdesc}
31
32\begin{funcdesc}{MenuBar}{}
33An object representing the menubar. This object is usually not created
34by the user.
35\end{funcdesc}
36
Fred Drakecce10901998-03-17 06:33:25 +000037\begin{funcdesc}{Menu}{bar, title\optional{, after}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +000038An object representing a menu. Upon creation you pass the
39\code{MenuBar} the menu appears in, the \var{title} string and a
40position (1-based) \var{after} where the menu should appear (default:
41at the end).
42\end{funcdesc}
43
Fred Drakecce10901998-03-17 06:33:25 +000044\begin{funcdesc}{MenuItem}{menu, title\optional{, shortcut, callback}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +000045Create a menu item object. The arguments are the menu to crate the
46item it, the item title string and optionally the keyboard shortcut
47and a callback routine. The callback is called with the arguments
48menu-id, item number within menu (1-based), current front window and
49the event record.
50
51In stead of a callable object the callback can also be a string. In
52this case menu selection causes the lookup of a method in the topmost
53window and the application. The method name is the callback string
54with \code{'domenu_'} prepended.
55
Fred Drakef6863c11999-03-02 16:37:17 +000056Calling the \code{MenuBar} \method{fixmenudimstate()} method sets the
Fred Drakeb4efb6c1998-02-18 17:19:11 +000057correct dimming for all menu items based on the current front window.
58\end{funcdesc}
59
60\begin{funcdesc}{Separator}{menu}
61Add a separator to the end of a menu.
62\end{funcdesc}
63
Fred Drakecce10901998-03-17 06:33:25 +000064\begin{funcdesc}{SubMenu}{menu, label}
Fred Drakeb4efb6c1998-02-18 17:19:11 +000065Create a submenu named \var{label} under menu \var{menu}. The menu
66object is returned.
67\end{funcdesc}
68
69\begin{funcdesc}{Window}{parent}
70Creates a (modeless) window. \var{Parent} is the application object to
71which the window belongs. The window is not displayed until later.
72\end{funcdesc}
73
74\begin{funcdesc}{DialogWindow}{parent}
75Creates a modeless dialog window.
76\end{funcdesc}
77
Fred Drakecce10901998-03-17 06:33:25 +000078\begin{funcdesc}{windowbounds}{width, height}
Fred Drakef6863c11999-03-02 16:37:17 +000079Return a \code{(\var{left}, \var{top}, \var{right}, \var{bottom})}
80tuple suitable for creation of a window of given width and height. The
81window will be staggered with respect to previous windows, and an
82attempt is made to keep the whole window on-screen. The window will
83however always be exact the size given, so parts may be offscreen.
Fred Drakeb4efb6c1998-02-18 17:19:11 +000084\end{funcdesc}
85
86\begin{funcdesc}{setwatchcursor}{}
87Set the mouse cursor to a watch.
88\end{funcdesc}
89
90\begin{funcdesc}{setarrowcursor}{}
91Set the mouse cursor to an arrow.
92\end{funcdesc}
93
Fred Drakef6863c11999-03-02 16:37:17 +000094
95\subsection{Application Objects \label{application-objects}}
Fred Drake41788db1998-04-04 06:23:02 +000096
Fred Drakeb4efb6c1998-02-18 17:19:11 +000097Application objects have the following methods, among others:
98
Fred Drakeb4efb6c1998-02-18 17:19:11 +000099
Fred Drakef6863c11999-03-02 16:37:17 +0000100\begin{methoddesc}[Application]{makeusermenus}{}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000101Override 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 Drakef6863c11999-03-02 16:37:17 +0000103\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000104
Fred Drakef6863c11999-03-02 16:37:17 +0000105\begin{methoddesc}[Application]{getabouttext}{}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000106Override 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 Drakef6863c11999-03-02 16:37:17 +0000109\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000110
Fred Drakef6863c11999-03-02 16:37:17 +0000111\begin{methoddesc}[Application]{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
Fred Drakef6863c11999-03-02 16:37:17 +0000116idea). While raising \var{self} to exit the mainloop is still
117supported it is not recommended: call \code{self._quit()} instead.
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000118
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 Drakef6863c11999-03-02 16:37:17 +0000132\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000133
Fred Drakef6863c11999-03-02 16:37:17 +0000134\begin{methoddesc}[Application]{asyncevents}{onoff}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000135Call 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.
Fred Drakef6863c11999-03-02 16:37:17 +0000147\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000148
Fred Drakef6863c11999-03-02 16:37:17 +0000149\begin{methoddesc}[Application]{_quit}{}
Fred Drake41788db1998-04-04 06:23:02 +0000150Terminate the running \method{mainloop()} call at the next convenient
151moment.
Fred Drakef6863c11999-03-02 16:37:17 +0000152\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000153
Fred Drakef6863c11999-03-02 16:37:17 +0000154\begin{methoddesc}[Application]{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.
Fred Drakef6863c11999-03-02 16:37:17 +0000159\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000160
Fred Drakef6863c11999-03-02 16:37:17 +0000161\begin{methoddesc}[Application]{do_dialogevent}{event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000162Called 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).
Fred Drakef6863c11999-03-02 16:37:17 +0000166\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000167
Fred Drakef6863c11999-03-02 16:37:17 +0000168\begin{methoddesc}[Application]{idle}{event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000169Called by the main event loop when no events are available. The
170null-event is passed (so you can look at mouse position, etc).
Fred Drakef6863c11999-03-02 16:37:17 +0000171\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000172
Fred Drakef6863c11999-03-02 16:37:17 +0000173
174\subsection{Window Objects \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
Fred Drakef6863c11999-03-02 16:37:17 +0000180\begin{methoddesc}[Window]{open}{}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000181Override this method to open a window. Store the MacOS window-id in
Fred Drakef6863c11999-03-02 16:37:17 +0000182\member{self.wid} and call the \method{do_postopen()} method to
183register the window with the parent application.
184\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000185
Fred Drakef6863c11999-03-02 16:37:17 +0000186\begin{methoddesc}[Window]{close}{}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000187Override this method to do any special processing on window
Fred Drakef6863c11999-03-02 16:37:17 +0000188close. Call the \method{do_postclose()} method to cleanup the parent
189state.
190\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000191
Fred Drakef6863c11999-03-02 16:37:17 +0000192\begin{methoddesc}[Window]{do_postresize}{width, height, macoswindowid}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000193Called after the window is resized. Override if more needs to be done
194than calling \code{InvalRect}.
Fred Drakef6863c11999-03-02 16:37:17 +0000195\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000196
Fred Drakef6863c11999-03-02 16:37:17 +0000197\begin{methoddesc}[Window]{do_contentclick}{local, modifiers, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000198The user clicked in the content part of a window. The arguments are
199the coordinates (window-relative), the key modifiers and the raw
200event.
Fred Drakef6863c11999-03-02 16:37:17 +0000201\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000202
Fred Drakef6863c11999-03-02 16:37:17 +0000203\begin{methoddesc}[Window]{do_update}{macoswindowid, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000204An update event for the window was received. Redraw the window.
Fred Drakef6863c11999-03-02 16:37:17 +0000205\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000206
Fred Drakef6863c11999-03-02 16:37:17 +0000207\begin{methoddesc}{do_activate}{activate, event}
208The window was activated (\code{\var{activate} == 1}) or deactivated
209(\code{\var{activate} == 0}). Handle things like focus highlighting,
210etc.
211\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000212
Fred Drakef6863c11999-03-02 16:37:17 +0000213
214\subsection{ControlsWindow Object \label{controlswindow-object}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000215
216ControlsWindow objects have the following methods besides those of
217\code{Window} objects:
218
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000219
Fred Drakef6863c11999-03-02 16:37:17 +0000220\begin{methoddesc}[ControlsWindow]{do_controlhit}{window, control,
221 pcode, event}
222Part \var{pcode} of control \var{control} was hit by the
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000223user. Tracking and such has already been taken care of.
Fred Drakef6863c11999-03-02 16:37:17 +0000224\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000225
Fred Drakef6863c11999-03-02 16:37:17 +0000226
227\subsection{ScrolledWindow Object \label{scrolledwindow-object}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000228
229ScrolledWindow objects are ControlsWindow objects with the following
230extra methods:
231
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000232
Fred Drakef6863c11999-03-02 16:37:17 +0000233\begin{methoddesc}[ScrolledWindow]{scrollbars}{\optional{wantx\optional{,
234 wanty}}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000235Create (or destroy) horizontal and vertical scrollbars. The arguments
236specify which you want (default: both). The scrollbars always have
237minimum \code{0} and maximum \code{32767}.
Fred Drakef6863c11999-03-02 16:37:17 +0000238\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000239
Fred Drakef6863c11999-03-02 16:37:17 +0000240\begin{methoddesc}[ScrolledWindow]{getscrollbarvalues}{}
Fred Drake41788db1998-04-04 06:23:02 +0000241You must supply this method. It should return a tuple \code{(\var{x},
242\var{y})} giving the current position of the scrollbars (between
243\code{0} and \code{32767}). You can return \code{None} for either to
244indicate the whole document is visible in that direction.
Fred Drakef6863c11999-03-02 16:37:17 +0000245\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000246
Fred Drakef6863c11999-03-02 16:37:17 +0000247\begin{methoddesc}[ScrolledWindow]{updatescrollbars}{}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000248Call this method when the document has changed. It will call
Fred Drake41788db1998-04-04 06:23:02 +0000249\method{getscrollbarvalues()} and update the scrollbars.
Fred Drakef6863c11999-03-02 16:37:17 +0000250\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000251
Fred Drakef6863c11999-03-02 16:37:17 +0000252\begin{methoddesc}[ScrolledWindow]{scrollbar_callback}{which, what, value}
Fred Drake41788db1998-04-04 06:23:02 +0000253Supplied by you and called after user interaction. \var{which} will
254be \code{'x'} or \code{'y'}, \var{what} will be \code{'-'},
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000255\code{'--'}, \code{'set'}, \code{'++'} or \code{'+'}. For
Fred Drake41788db1998-04-04 06:23:02 +0000256\code{'set'}, \var{value} will contain the new scrollbar position.
Fred Drakef6863c11999-03-02 16:37:17 +0000257\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000258
Fred Drakef6863c11999-03-02 16:37:17 +0000259\begin{methoddesc}[ScrolledWindow]{scalebarvalues}{absmin, absmax,
260 curmin, curmax}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000261Auxiliary method to help you calculate values to return from
Fred Drake41788db1998-04-04 06:23:02 +0000262\method{getscrollbarvalues()}. You pass document minimum and maximum value
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000263and topmost (leftmost) and bottommost (rightmost) visible values and
264it returns the correct number or \code{None}.
Fred Drakef6863c11999-03-02 16:37:17 +0000265\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000266
Fred Drakef6863c11999-03-02 16:37:17 +0000267\begin{methoddesc}[ScrolledWindow]{do_activate}{onoff, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000268Takes care of dimming/highlighting scrollbars when a window becomes
269frontmost vv. If you override this method call this one at the end of
270your method.
Fred Drakef6863c11999-03-02 16:37:17 +0000271\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000272
Fred Drakef6863c11999-03-02 16:37:17 +0000273\begin{methoddesc}[ScrolledWindow]{do_postresize}{width, height, window}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000274Moves scrollbars to the correct position. Call this method initially
275if you override it.
Fred Drakef6863c11999-03-02 16:37:17 +0000276\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000277
Fred Drakef6863c11999-03-02 16:37:17 +0000278\begin{methoddesc}[ScrolledWindow]{do_controlhit}{window, control,
279 pcode, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000280Handles scrollbar interaction. If you override it call this method
281first, a nonzero return value indicates the hit was in the scrollbars
282and has been handled.
Fred Drakef6863c11999-03-02 16:37:17 +0000283\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000284
Fred Drakef6863c11999-03-02 16:37:17 +0000285
286\subsection{DialogWindow Objects \label{dialogwindow-objects}}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000287
288DialogWindow objects have the following methods besides those of
289\code{Window} objects:
290
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000291
Fred Drakef6863c11999-03-02 16:37:17 +0000292\begin{methoddesc}[DialogWindow]{open}{resid}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000293Create the dialog window, from the DLOG resource with id
Fred Drakef6863c11999-03-02 16:37:17 +0000294\var{resid}. The dialog object is stored in \member{self.wid}.
295\end{methoddesc}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000296
Fred Drakef6863c11999-03-02 16:37:17 +0000297\begin{methoddesc}[DialogWindow]{do_itemhit}{item, event}
Fred Drakeb4efb6c1998-02-18 17:19:11 +0000298Item number \var{item} was hit. You are responsible for redrawing
299toggle buttons, etc.
Fred Drakef6863c11999-03-02 16:37:17 +0000300\end{methoddesc}