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