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