blob: 1c2df7ce7376c641ab30961f1f63adc5b7b5864a [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.
100\end{funcdesc}
101
102\begin{funcdesc}{Separator}{menu}
103Add a separator to the end of a menu.
104\end{funcdesc}
105
106\begin{funcdesc}{SubMenu}{menu\, label}
107Create a submenu named \var{label} under menu \var{menu}. The menu
108object is returned.
109\end{funcdesc}
110
111\begin{funcdesc}{Window}{parent}
112Creates a (modeless) window. \var{Parent} is the application object to
113which the window belongs. The window is not displayed until later.
114\end{funcdesc}
115
116\begin{funcdesc}{DialogWindow}{parent}
117Creates a modeless dialog window.
118\end{funcdesc}
119
Guido van Rossum66774a91996-07-21 02:20:58 +0000120\begin{funcdesc}{windowbounds}{width\, height}
121Return a \code{(left, top, right, bottom)} tuple suitable for creation
122of a window of given width and height. The window will be staggered
123with respect to previous windows, and an attempt is made to keep the
124whole window on-screen. The window will however always be exact the
125size given, so parts may be offscreen.
126\end{funcdesc}
127
Jack Jansenda53c521995-10-10 14:43:20 +0000128
129\subsection{Application objects}
130Application objects have the following methods, among others:
131
132\renewcommand{\indexsubitem}{(Application method)}
133
134\begin{funcdesc}{makeusermenus}{}
135Override this method if you need menus in your application. Append the
136menus to \code{self.menubar}.
137\end{funcdesc}
138
139\begin{funcdesc}{getabouttext}{}
140Override this method to return a text string describing your
141application. Alternatively, override the \code{do_about} method for
142more elaborate about messages.
143\end{funcdesc}
144
145\begin{funcdesc}{mainloop}{\optional{mask\, wait}}
146This routine is the main event loop, call it to set your application
147rolling. \var{Mask} is the mask of events you want to handle,
148\var{wait} is the number of ticks you want to leave to other
149concurrent application (default 0, which is probably not a good
150idea). This method does not return until \code{self} is raised.
151
152The event loop is split into many small parts, each of which can be
153overridden. The default methods take care of dispatching events to
154windows and dialogs, handling drags and resizes, Apple Events, events
155for non-FrameWork windows, etc.
156\end{funcdesc}
157
158\begin{funcdesc}{do_char}{c\, event}
159The user typed character \var{c}. The complete details of the event
160can be found in the \var{event} structure. This method can also be
161provided in a \code{Window} object, which overrides the
162application-wide handler if the window is frontmost.
163\end{funcdesc}
164
165\begin{funcdesc}{do_dialogevent}{event}
166Called early in the event loop to handle modeless dialog events. The
167default method simply dispatches the event to the relevant dialog (not
168through the the \code{DialogWindow} object involved). Override if you
169need special handling of dialog events (keyboard shortcuts, etc).
170\end{funcdesc}
171
Guido van Rossum66774a91996-07-21 02:20:58 +0000172\begin{funcdesc}{idle}{event}
173Called by the main event loop when no events are available. The
174null-event is passed (so you can look at mouse position, etc).
Jack Jansen350b2b91995-11-14 10:30:27 +0000175\end{funcdesc}
176
Jack Jansenda53c521995-10-10 14:43:20 +0000177\subsection{Window Objects}
178
179Window objects have the following methods, among others:
180
181\renewcommand{\indexsubitem}{(Window method)}
182
183\begin{funcdesc}{open}{}
184Override this method to open a window. Store the MacOS window-id in
185\code{self.wid} and call \code{self.do_postopen} to register the
186window with the parent application.
187\end{funcdesc}
188
189\begin{funcdesc}{close}{}
190Override this method to do any special processing on window
191close. Call \code{self.do_postclose} to cleanup the parent state.
192\end{funcdesc}
193
194\begin{funcdesc}{do_postresize}{width\, height\, macoswindowid}
195Called after the window is resized. Override if more needs to be done
196than calling \code{InvalRect}.
197\end{funcdesc}
198
199\begin{funcdesc}{do_contentclick}{local\, modifiers\, event}
200The user clicked in the content part of a window. The arguments are
201the coordinates (window-relative), the key modifiers and the raw
202event.
203\end{funcdesc}
204
205\begin{funcdesc}{do_update}{macoswindowid\, event}
206An update event for the window was received. Redraw the window.
207\end{funcdesc}
208
209\begin{funcdesc}{do_activate}{activate\, event}
210The window was activated (\code{activate==1}) or deactivated
211(\code{activate==0}). Handle things like focus highlighting, etc.
212\end{funcdesc}
213
Guido van Rossum66774a91996-07-21 02:20:58 +0000214\subsection{ControlsWindow Object}
215
216ControlsWindow objects have the following methods besides those of
217\code{Window} objects:
218
219\renewcommand{\indexsubitem}{(ControlsWindow method)}
220
221\begin{funcdesc}{do_controlhit}{window\, control\, pcode\, event}
222Part \code{pcode} of control \code{control} was hit by the
223user. Tracking and such has already been taken care of.
224\end{funcdesc}
225
226\subsection{ScrolledWindow Object}
227
228ScrolledWindow objects are ControlsWindow objects with the following
229extra mathods:
230
231\renewcommand{\indexsubitem}{(ScrolledWindow method)}
232
233\begin{funcdesc}{scrollbars}{\optional{wantx\, wanty}}
234Create (or destroy) horizontal and vertical scrollbars. The arguments
235specify which you want (default: both). The scrollbars always have
236minimum \code{0} and maximum \code{32767}.
237\end{funcdesc}
238
239\begin{funcdesc}{getscrollbarvalues}{}
240You must supply this method. It should return a tuple \code{x, y}
241giving the current position of the scrollbars (between \code{0} and
242\code{32767}). You can return \code{None} for either to indicate the
243whole document is visible in that direction.
244\end{funcdesc}
245
246\begin{funcdesc}{updatescrollbars}{}
247Call this method when the document has changed. It will call
248\code{getscrollbarvalues} and update the scrollbars.
249\end{funcdesc}
250
251\begin{funcdesc}{scrollbar_callback}{which\, what\, value}
252Supplied by you and called after user interaction. \code{Which} will
253be \code{'x'} or \code{'y'}, \code{what} will be \code{'-'},
254\code{'--'}, \code{'set'}, \code{'++'} or \code{'+'}. For
255\code{'set'}, \code{value} will contain the new scrollbar position.
256\end{funcdesc}
257
258\begin{funcdesc}{scalebarvalues}{absmin\, absmax\, curmin\, curmax}
259Auxiliary method to help you calculate values to return from
260\code{getscrollbarvalues}. You pass document minimum and maximum value
261and topmost (leftmost) and bottommost (rightmost) visible values and
262it returns the correct number or \code{None}.
263\end{funcdesc}
264
265\begin{funcdesc}{do_activate}{onoff\, event}
266Takes care of dimming/highlighting scrollbars when a window becomes
267frontmost vv. If you override this method call this one at the end of
268your method.
269\end{funcdesc}
270
271\begin{funcdesc}{do_postresize}{width\, height\, window}
272Moves scrollbars to the correct position. Call this method initially
273if you override it.
274\end{funcdesc}
275
276\begin{funcdesc}{do_controlhit}{window\, control\, pcode\, event}
277Handles scrollbar interaction. If you override it call this method
278first, a nonzero return value indicates the hit was in the scrollbars
279and has been handled.
280\end{funcdesc}
281
Jack Jansenda53c521995-10-10 14:43:20 +0000282\subsection{DialogWindow Objects}
283
284DialogWindow objects have the following methods besides those of
285\code{Window} objects:
286
287\renewcommand{\indexsubitem}{(DialogWindow method)}
288
289\begin{funcdesc}{open}{resid}
290Create the dialog window, from the DLOG resource with id
291\var{resid}. The dialog object is stored in \code{self.wid}.
292\end{funcdesc}
293
294\begin{funcdesc}{do_itemhit}{item\, event}
295Item number \var{item} was hit. You are responsible for redrawing
296toggle buttons, etc.
297\end{funcdesc}
298