blob: c0478ac44b8f5d7e9131d4eebccd9e57851f45a4 [file] [log] [blame]
Fred Drakeb78da331997-12-17 14:12:31 +00001\section{Standard Module \sectcode{EasyDialogs}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-EasyDialogs}
Jack Jansenda53c521995-10-10 14:43:20 +00003\stmodindex{EasyDialogs}
4
5The \code{EasyDialogs} module contains some simple dialogs for
6the Macintosh, modelled after the \code{stdwin} dialogs with similar
Guido van Rossume229d861997-08-18 15:14:26 +00007names. All routines have an optional parameter \var{id} with which you
8can override the DLOG resource used for the dialog, as long as the
9item numbers correspond. See the source for details.
Jack Jansenda53c521995-10-10 14:43:20 +000010
11The \code{EasyDialogs} module defines the following functions:
12
13\renewcommand{\indexsubitem}{(in module EasyDialogs)}
14
15\begin{funcdesc}{Message}{str}
16A modal dialog with the message text \var{str}, which should be at
17most 255 characters long, is displayed. Control is returned when the
18user clicks ``OK''.
19\end{funcdesc}
20
21\begin{funcdesc}{AskString}{prompt\optional{\, default}}
22Ask the user to input a string value, in a modal dialog. \var{Prompt}
23is the promt message, the optional \var{default} arg is the initial
24value for the string. All strings can be at most 255 bytes
25long. \var{AskString} returns the string entered or \code{None} in
26case the user cancelled.
27\end{funcdesc}
28
29\begin{funcdesc}{AskYesNoCancel}{question\optional{\, default}}
30Present a dialog with text \var{question} and three buttons labelled
31``yes'', ``no'' and ``cancel''. Return \code{1} for yes, \code{0} for
32no and \code{-1} for cancel. The default return value chosen by
33hitting return is \code{0}. This can be changed with the optional
34\var{default} argument.
35\end{funcdesc}
36
Jack Jansen350b2b91995-11-14 10:30:27 +000037\begin{funcdesc}{ProgressBar}{\optional{label\, maxval}}
38Display a modeless progress dialog with a thermometer bar. \var{Label}
39is the textstring displayed (default ``Working...''), \var{maxval} is
40the value at which progress is complete (default 100). The returned
41object has one method, \code{set(value)}, which sets the value of the
42progress bar. The bar remains visible until the object returned is
43discarded.
44
45The progress bar has a ``cancel'' button, but it is currently
46non-functional.
47\end{funcdesc}
48
Jack Jansenda53c521995-10-10 14:43:20 +000049Note that \code{EasyDialogs} does not currently use the notification
50manager. This means that displaying dialogs while the program is in
Jack Jansen350b2b91995-11-14 10:30:27 +000051the background will lead to unexpected results and possibly
52crashes. Also, all dialogs are modeless and hence expect to be at the
53top of the stacking order. This is true when the dialogs are created,
54but windows that pop-up later (like a console window) may also result
55in crashes.
Jack Jansenda53c521995-10-10 14:43:20 +000056
57
Fred Drakeb78da331997-12-17 14:12:31 +000058\section{Standard Module \sectcode{FrameWork}}
Jack Jansenda53c521995-10-10 14:43:20 +000059\stmodindex{FrameWork}
Fred Drakeb78da331997-12-17 14:12:31 +000060\label{module-FrameWork}
Jack Jansenda53c521995-10-10 14:43:20 +000061
62The \code{FrameWork} module contains classes that together provide a
63framework for an interactive Macintosh application. The programmer
64builds an application by creating subclasses that override various
65methods of the bases classes, thereby implementing the functionality
66wanted. Overriding functionality can often be done on various
67different levels, i.e. to handle clicks in a single dialog window in a
68non-standard way it is not necessary to override the complete event
69handling.
70
71The \code{FrameWork} is still very much work-in-progress, and the
72documentation describes only the most important functionality, and not
Guido van Rossum66774a91996-07-21 02:20:58 +000073in the most logical manner at that. Examine the source or the examples
74for more details.
Jack Jansenda53c521995-10-10 14:43:20 +000075
Guido van Rossum66774a91996-07-21 02:20:58 +000076The \code{FrameWork} module defines the following functions:
Jack Jansenda53c521995-10-10 14:43:20 +000077
78\renewcommand{\indexsubitem}{(in module FrameWork)}
79
80\begin{funcdesc}{Application}{}
81An object representing the complete application. See below for a
82description of the methods. The default \code{__init__} routine
83creates an empty window dictionary and a menu bar with an apple menu.
84\end{funcdesc}
85
86\begin{funcdesc}{MenuBar}{}
87An object representing the menubar. This object is usually not created
88by the user.
89\end{funcdesc}
90
91\begin{funcdesc}{Menu}{bar\, title\optional{\, after}}
92An object representing a menu. Upon creation you pass the
93\code{MenuBar} the menu appears in, the \var{title} string and a
94position (1-based) \var{after} where the menu should appear (default:
95at the end).
96\end{funcdesc}
97
98\begin{funcdesc}{MenuItem}{menu\, title\optional{\, shortcut\, callback}}
99Create a menu item object. The arguments are the menu to crate the
100item it, the item title string and optionally the keyboard shortcut
101and a callback routine. The callback is called with the arguments
102menu-id, item number within menu (1-based), current front window and
103the event record.
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000104
105In stead of a callable object the callback can also be a string. In
106this case menu selection causes the lookup of a method in the topmost
107window and the application. The method name is the callback string
108with \code{'domenu_'} prepended.
109
110Calling the \code{MenuBar} \code{fixmenudimstate} method sets the
111correct dimming for all menu items based on the current front window.
Jack Jansenda53c521995-10-10 14:43:20 +0000112\end{funcdesc}
113
114\begin{funcdesc}{Separator}{menu}
115Add a separator to the end of a menu.
116\end{funcdesc}
117
118\begin{funcdesc}{SubMenu}{menu\, label}
119Create a submenu named \var{label} under menu \var{menu}. The menu
120object is returned.
121\end{funcdesc}
122
123\begin{funcdesc}{Window}{parent}
124Creates a (modeless) window. \var{Parent} is the application object to
125which the window belongs. The window is not displayed until later.
126\end{funcdesc}
127
128\begin{funcdesc}{DialogWindow}{parent}
129Creates a modeless dialog window.
130\end{funcdesc}
131
Guido van Rossum66774a91996-07-21 02:20:58 +0000132\begin{funcdesc}{windowbounds}{width\, height}
133Return a \code{(left, top, right, bottom)} tuple suitable for creation
134of a window of given width and height. The window will be staggered
135with respect to previous windows, and an attempt is made to keep the
136whole window on-screen. The window will however always be exact the
137size given, so parts may be offscreen.
138\end{funcdesc}
139
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000140\begin{funcdesc}{setwatchcursor}{}
141Set the mouse cursor to a watch.
142\end{funcdesc}
143
144\begin{funcdesc}{setarrowcursor}{}
145Set the mouse cursor to an arrow.
146\end{funcdesc}
Jack Jansenda53c521995-10-10 14:43:20 +0000147
148\subsection{Application objects}
149Application objects have the following methods, among others:
150
151\renewcommand{\indexsubitem}{(Application method)}
152
153\begin{funcdesc}{makeusermenus}{}
154Override this method if you need menus in your application. Append the
155menus to \code{self.menubar}.
156\end{funcdesc}
157
158\begin{funcdesc}{getabouttext}{}
159Override this method to return a text string describing your
160application. Alternatively, override the \code{do_about} method for
161more elaborate about messages.
162\end{funcdesc}
163
164\begin{funcdesc}{mainloop}{\optional{mask\, wait}}
165This routine is the main event loop, call it to set your application
166rolling. \var{Mask} is the mask of events you want to handle,
167\var{wait} is the number of ticks you want to leave to other
168concurrent application (default 0, which is probably not a good
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000169idea). While raising \code{self} to exit the mainloop is still
170supported it is not recommended, call \code{self._quit} instead.
Jack Jansenda53c521995-10-10 14:43:20 +0000171
172The event loop is split into many small parts, each of which can be
173overridden. The default methods take care of dispatching events to
174windows and dialogs, handling drags and resizes, Apple Events, events
175for non-FrameWork windows, etc.
Guido van Rossume229d861997-08-18 15:14:26 +0000176
177In general, all event handlers should return 1 if the event is fully
178handled and 0 otherwise (because the front window was not a FrameWork
179window, for instance). This is needed so that update events and such
180can be passed on to other windows like the Sioux console window.
181Calling \code{MacOS.HandleEvent} is not allowed within \var{our_dispatch}
182or its callees, since this may result in an infinite loop if the
183code is called through the python inner-loop event handler.
184\end{funcdesc}
185
186\begin{funcdesc}{asyncevents}{onoff}
187Call this method with a nonzero parameter to enable
188asynchronous event handling. This will tell the inner interpreter loop
189to call the application event handler \var{async_dispatch} whenever events
190are available. This will cause FrameWork window updates and the user
191interface to remain working during long computations, but will slow the
192interpreter down and may cause surprising results in non-reentrant code
193(such as FrameWork itself). By default \var{async_dispatch} will immedeately
194call \var{our_dispatch} but you may override this to handle only certain
195events asynchronously. Events you do not handle will be passed to Sioux
196and such.
197
198The old on/off value is returned.
Jack Jansenda53c521995-10-10 14:43:20 +0000199\end{funcdesc}
200
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000201\begin{funcdesc}{_quit}{}
202Terminate the event \code{mainloop} at the next convenient moment.
203\end{funcdesc}
204
Jack Jansenda53c521995-10-10 14:43:20 +0000205\begin{funcdesc}{do_char}{c\, event}
206The user typed character \var{c}. The complete details of the event
207can be found in the \var{event} structure. This method can also be
208provided in a \code{Window} object, which overrides the
209application-wide handler if the window is frontmost.
210\end{funcdesc}
211
212\begin{funcdesc}{do_dialogevent}{event}
213Called early in the event loop to handle modeless dialog events. The
214default method simply dispatches the event to the relevant dialog (not
215through the the \code{DialogWindow} object involved). Override if you
216need special handling of dialog events (keyboard shortcuts, etc).
217\end{funcdesc}
218
Guido van Rossum66774a91996-07-21 02:20:58 +0000219\begin{funcdesc}{idle}{event}
220Called by the main event loop when no events are available. The
221null-event is passed (so you can look at mouse position, etc).
Jack Jansen350b2b91995-11-14 10:30:27 +0000222\end{funcdesc}
223
Jack Jansenda53c521995-10-10 14:43:20 +0000224\subsection{Window Objects}
225
226Window objects have the following methods, among others:
227
228\renewcommand{\indexsubitem}{(Window method)}
229
230\begin{funcdesc}{open}{}
231Override this method to open a window. Store the MacOS window-id in
232\code{self.wid} and call \code{self.do_postopen} to register the
233window with the parent application.
234\end{funcdesc}
235
236\begin{funcdesc}{close}{}
237Override this method to do any special processing on window
238close. Call \code{self.do_postclose} to cleanup the parent state.
239\end{funcdesc}
240
241\begin{funcdesc}{do_postresize}{width\, height\, macoswindowid}
242Called after the window is resized. Override if more needs to be done
243than calling \code{InvalRect}.
244\end{funcdesc}
245
246\begin{funcdesc}{do_contentclick}{local\, modifiers\, event}
247The user clicked in the content part of a window. The arguments are
248the coordinates (window-relative), the key modifiers and the raw
249event.
250\end{funcdesc}
251
252\begin{funcdesc}{do_update}{macoswindowid\, event}
253An update event for the window was received. Redraw the window.
254\end{funcdesc}
255
256\begin{funcdesc}{do_activate}{activate\, event}
257The window was activated (\code{activate==1}) or deactivated
258(\code{activate==0}). Handle things like focus highlighting, etc.
259\end{funcdesc}
260
Guido van Rossum66774a91996-07-21 02:20:58 +0000261\subsection{ControlsWindow Object}
262
263ControlsWindow objects have the following methods besides those of
264\code{Window} objects:
265
266\renewcommand{\indexsubitem}{(ControlsWindow method)}
267
268\begin{funcdesc}{do_controlhit}{window\, control\, pcode\, event}
269Part \code{pcode} of control \code{control} was hit by the
270user. Tracking and such has already been taken care of.
271\end{funcdesc}
272
273\subsection{ScrolledWindow Object}
274
275ScrolledWindow objects are ControlsWindow objects with the following
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000276extra methods:
Guido van Rossum66774a91996-07-21 02:20:58 +0000277
278\renewcommand{\indexsubitem}{(ScrolledWindow method)}
279
280\begin{funcdesc}{scrollbars}{\optional{wantx\, wanty}}
281Create (or destroy) horizontal and vertical scrollbars. The arguments
282specify which you want (default: both). The scrollbars always have
283minimum \code{0} and maximum \code{32767}.
284\end{funcdesc}
285
286\begin{funcdesc}{getscrollbarvalues}{}
287You must supply this method. It should return a tuple \code{x, y}
288giving the current position of the scrollbars (between \code{0} and
289\code{32767}). You can return \code{None} for either to indicate the
290whole document is visible in that direction.
291\end{funcdesc}
292
293\begin{funcdesc}{updatescrollbars}{}
294Call this method when the document has changed. It will call
295\code{getscrollbarvalues} and update the scrollbars.
296\end{funcdesc}
297
298\begin{funcdesc}{scrollbar_callback}{which\, what\, value}
299Supplied by you and called after user interaction. \code{Which} will
300be \code{'x'} or \code{'y'}, \code{what} will be \code{'-'},
301\code{'--'}, \code{'set'}, \code{'++'} or \code{'+'}. For
302\code{'set'}, \code{value} will contain the new scrollbar position.
303\end{funcdesc}
304
305\begin{funcdesc}{scalebarvalues}{absmin\, absmax\, curmin\, curmax}
306Auxiliary method to help you calculate values to return from
307\code{getscrollbarvalues}. You pass document minimum and maximum value
308and topmost (leftmost) and bottommost (rightmost) visible values and
309it returns the correct number or \code{None}.
310\end{funcdesc}
311
312\begin{funcdesc}{do_activate}{onoff\, event}
313Takes care of dimming/highlighting scrollbars when a window becomes
314frontmost vv. If you override this method call this one at the end of
315your method.
316\end{funcdesc}
317
318\begin{funcdesc}{do_postresize}{width\, height\, window}
319Moves scrollbars to the correct position. Call this method initially
320if you override it.
321\end{funcdesc}
322
323\begin{funcdesc}{do_controlhit}{window\, control\, pcode\, event}
324Handles scrollbar interaction. If you override it call this method
325first, a nonzero return value indicates the hit was in the scrollbars
326and has been handled.
327\end{funcdesc}
328
Jack Jansenda53c521995-10-10 14:43:20 +0000329\subsection{DialogWindow Objects}
330
331DialogWindow objects have the following methods besides those of
332\code{Window} objects:
333
334\renewcommand{\indexsubitem}{(DialogWindow method)}
335
336\begin{funcdesc}{open}{resid}
337Create the dialog window, from the DLOG resource with id
338\var{resid}. The dialog object is stored in \code{self.wid}.
339\end{funcdesc}
340
341\begin{funcdesc}{do_itemhit}{item\, event}
342Item number \var{item} was hit. You are responsible for redrawing
343toggle buttons, etc.
344\end{funcdesc}
345
Fred Drakeb78da331997-12-17 14:12:31 +0000346\section{Standard Module \sectcode{MiniAEFrame}}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000347\stmodindex{MiniAEFrame}
Fred Drakeb78da331997-12-17 14:12:31 +0000348\label{module-MiniAEFrame}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000349
350The module \var{MiniAEFrame} provides a framework for an application
351that can function as an OSA server, i.e. receive and process
352AppleEvents. It can be used in conjunction with \var{FrameWork} or
353standalone.
354
355This module is temporary, it will eventually be replaced by a module
356that handles argument names better and possibly automates making your
357application scriptable.
358
359The \var{MiniAEFrame} module defines the following classes:
360
361\renewcommand{\indexsubitem}{(in module MiniAEFrame)}
362
363\begin{funcdesc}{AEServer}{}
364A class that handles AppleEvent dispatch. Your application should
365subclass this class together with either
366\code{MiniAEFrame.MiniApplication} or
367\code{FrameWork.Application}. Your \code{__init__} method should call
368the \code{__init__} method for both classes.
369\end{funcdesc}
370
371\begin{funcdesc}{MiniApplication}{}
372A class that is more or less compatible with
373\code{FrameWork.Application} but with less functionality. Its
374eventloop supports the apple menu, command-dot and AppleEvents, other
375events are passed on to the Python interpreter and/or Sioux.
376Useful if your application wants to use \code{AEServer} but does not
377provide its own windows, etc.
378\end{funcdesc}
379
380\subsection{AEServer Objects}
381
382\renewcommand{\indexsubitem}{(AEServer method)}
383
384\begin{funcdesc}{installaehandler}{classe\, type\, callback}
385Installs an AppleEvent handler. \code{Classe} and \code{type} are the
386four-char OSA Class and Type designators, \code{'****'} wildcards are
387allowed. When a matching AppleEvent is received the parameters are
388decoded and your callback is invoked.
389\end{funcdesc}
390
391\begin{funcdesc}{callback}{_object\, **kwargs}
392Your callback is called with the OSA Direct Object as first positional
393parameter. The other parameters are passed as keyword arguments, with
394the 4-char designator as name. Three extra keyword parameters are
395passed: \code{_class} and \code{_type} are the Class and Type
396designators and \code{_attributes} is a dictionary with the AppleEvent
397attributes.
398
399The return value of your method is packed with
400\code{aetools.packevent} and sent as reply.
401\end{funcdesc}
402
403Note that there are some serious problems with the current
404design. AppleEvents which have non-identifier 4-char designators for
405arguments are not implementable, and it is not possible to return an
406error to the originator. This will be addressed in a future release.