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