blob: a3018ec107c4ed6d043d96a0a02e8ee97127a43a [file] [log] [blame]
Fred Drakec817e271998-08-10 18:40:22 +00001\section{\module{EasyDialogs} ---
Fred Drakef6863c11999-03-02 16:37:17 +00002 Basic Macintosh dialogs}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00003
Fred Drakef6863c11999-03-02 16:37:17 +00004\declaremodule{standard}{EasyDialogs}
5 \platform{Mac}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00006\modulesynopsis{Basic Macintosh dialogs.}
7
Fred Drake8a5a2702002-04-15 19:53:35 +00008The \module{EasyDialogs} module contains some simple dialogs for the
9Macintosh. All routines take an optional resource ID parameter \var{id}
10with which one can override the \constant{DLOG} resource used for the
11dialog, provided that the dialog items correspond (both type and item
12number) to those in the default \constant{DLOG} resource. See source
13code for details.
Fred Drake4973b352000-08-30 14:33:02 +000014
Fred Drake41788db1998-04-04 06:23:02 +000015The \module{EasyDialogs} module defines the following functions:
Jack Jansenda53c521995-10-10 14:43:20 +000016
Jack Jansenda53c521995-10-10 14:43:20 +000017
Fred Drake8a5a2702002-04-15 19:53:35 +000018\begin{funcdesc}{Message}{str\optional{, id\optional{, ok=None}}}
19Displays a modal dialog with the message text \var{str}, which should be
20at most 255 characters long. The button text defaults to ``OK'', but is
21set to the string argument \var{ok} if the latter is supplied. Control
22is returned when the user clicks the ``OK'' button.
Jack Jansenda53c521995-10-10 14:43:20 +000023\end{funcdesc}
24
Fred Drake8a5a2702002-04-15 19:53:35 +000025
26\begin{funcdesc}{AskString}{prompt\optional{, default\optional{,
27 id\optional{, ok\optional{, cancel}}}}}
28Asks the user to input a string value via a modal dialog. \var{prompt}
29is the prompt message, and the optional \var{default} supplies the
30initial value for the string (otherwise \code{""} is used). The text of
31the ``OK'' and ``Cancel'' buttons can be changed with the \var{ok} and
32\var{cancel} arguments. All strings can be at most 255 bytes long.
33\function{AskString()} returns the string entered or \code{None} in case
34the user cancelled.
Fred Drakeeab58af2000-10-14 04:56:52 +000035\end{funcdesc}
36
Fred Drake8a5a2702002-04-15 19:53:35 +000037
38\begin{funcdesc}{AskPassword}{prompt\optional{, default\optional{,
39 id\optional{, ok\optional{, cancel}}}}}
40Asks the user to input a string value via a modal dialog. Like
41\function{AskString()}, but with the text shown as bullets. The
42arguments have the same meaning as for \function{AskString()}.
Jack Jansenda53c521995-10-10 14:43:20 +000043\end{funcdesc}
44
Fred Drake8a5a2702002-04-15 19:53:35 +000045
46\begin{funcdesc}{AskYesNoCancel}{question\optional{, default\optional{,
47 yes\optional{, no\optional{, cancel\optional{, id}}}}}}
48Presents a dialog with prompt \var{question} and three buttons labelled
49``Yes'', ``No'', and ``Cancel''. Returns \code{1} for ``Yes'', \code{0}
50for ``No'' and \code{-1} for ``Cancel''. The value of \var{default} (or
51\code{0} if \var{default} is not supplied) is returned when the
52\kbd{RETURN} key is pressed. The text of the buttons can be changed with
53the \var{yes}, \var{no}, and \var{cancel} arguments; to prevent a button
54from appearing, supply \code{""} for the corresponding argument.
Jack Jansenda53c521995-10-10 14:43:20 +000055\end{funcdesc}
56
Jack Jansen350b2b91995-11-14 10:30:27 +000057
Fred Drake8a5a2702002-04-15 19:53:35 +000058\begin{funcdesc}{ProgressBar}{\optional{title\optional{, maxval\optional{,
59 label\optional{, id}}}}}
60Displays a modeless progress-bar dialog. This is the constructor for the
61\class{ProgressBar} class described below. \var{title} is the text
62string displayed (default ``Working...''), \var{maxval} is the value at
63which progress is complete (default \code{0}, indicating that an
64indeterminate amount of work remains to be done), and \var{label} is
65the text that is displayed above the progress bar itself.
Jack Jansen350b2b91995-11-14 10:30:27 +000066\end{funcdesc}
Fred Drake8a5a2702002-04-15 19:53:35 +000067
68
69\begin{funcdesc}{GetArgv}{\optional{optionlist\optional{
70 commandlist\optional{, addoldfile\optional{, addnewfile\optional{,
71 addfolder\optional{, id}}}}}}}
72Displays a dialog which aids the user in constructing a command-line
73argument list. Returns the list in \code{sys.argv} format, suitable for
74passing as an argument to \function{getopt.getopt()}. \var{addoldfile},
75\var{addnewfile}, and \var{addfolder} are boolean arguments. When
76nonzero, they enable the user to insert into the command line paths to
77an existing file, a (possibly) not-yet-existent file, and a folder,
78respectively. (Note: Option arguments must appear in the command line
79before file and folder arguments in order to be recognized by
80\function{getopt.getopt()}.) Arguments containing spaces can be
81specified by enclosing them within single or double quotes. A
82\exception{SystemExit} exception is raised if the user presses the
83``Cancel'' button.
84
85\var{optionlist} is a list that determines a popup menu from which the
86allowed options are selected. Its items can take one of two forms:
87\var{optstr} or \code{(\var{optstr}, \var{descr})}. When present,
88\var{descr} is a short descriptive string that is displayed in the
89dialog while this option is selected in the popup menu. The
90correspondence between \var{optstr}s and command-line arguments is:
91
92\begin{tableii}{l|l}{textrm}{\var{optstr} format}{Command-line format}
93\lineii{\code{x}}
94 {\programopt{-x} (short option)}
95\lineii{\code{x:} or \code{x=}}
96 {\programopt{-x} (short option with value)}
97\lineii{\code{xyz}}
98 {\longprogramopt{xyz} (long option)}
99\lineii{\code{xyz:} or \code{xyz=}}
100 {\longprogramopt{xyz} (long option with value)}
101\end{tableii}
102
103\var{commandlist} is a list of items of the form \var{cmdstr} or
104\code{(\var{cmdstr}, \var{descr})}, where \var{descr} is as above. The
105\var{cmdstr}s will appear in a popup menu. When chosen, the text of
106\var{cmdstr} will be appended to the command line as is, except that a
107trailing \character{:} or \character{=} (if present) will be trimmed
108off.
109
110\versionadded{2.0}
111\end{funcdesc}
112
113
114
115\subsection{ProgressBar Objects \label{progressbar-objects}}
116
117\class{ProgressBar} objects provide support for modeless progress-bar
118dialogs. Both determinate (thermometer style) and indeterminate
119(barber-pole style) progress bars are supported. The bar will be
120determinate if its maximum value is greater than zero; otherwise it
121will be indeterminate.
122\versionchanged[Support for indeterminate-style progress bars was
123 added]{2.2}
124
125The dialog is displayed immediately after creation. If the dialog's
126``Cancel'' button is pressed, or if \kbd{Cmd-.} or \kbd{ESC} is typed,
127the dialog window is hidden and \exception{KeyboardInterrupt} is
128raised (but note that this response does not occur until the progress
129bar is next updated, typically via a call to \method{inc()} or
130\method{set()}). Otherwise, the bar remains visible until the
131\class{ProgressBar} object is discarded.
132
133\class{ProgressBar} objects possess the following attributes and
134methods:
135
136\begin{memberdesc}[ProgressBar]{curval}
137The current value (of type integer or long integer) of the progress
138bar. The normal access methods coerce \member{curval} between
139\code{0} and \member{maxval}. This attribute should not be altered
140directly.
141\end{memberdesc}
142
143\begin{memberdesc}[ProgressBar]{maxval}
144The maximum value (of type integer or long integer) of the progress
145bar; the progress bar (thermometer style) is full when \member{curval}
146equals \member{maxval}. If \member{maxval} is \code{0}, the bar will
147be indeterminate (barber-pole). This attribute should not be altered
148directly.
149\end{memberdesc}
150
151\begin{methoddesc}[ProgressBar]{title}{\optional{newstr}}
152Sets the text in the title bar of the progress dialog to
153\var{newstr}.
154\end{methoddesc}
155
156\begin{methoddesc}[ProgressBar]{label}{\optional{newstr}}
157Sets the text in the progress box of the progress dialog to
158\var{newstr}.
159\end{methoddesc}
160
161\begin{methoddesc}[ProgressBar]{set}{value\optional{, max}}
162Sets the progress bar's \member{curval} to \var{value}, and also
163\member{maxval} to \var{max} if the latter is provided. \var{value}
164is first coerced between 0 and \member{maxval}. The thermometer bar
165is updated to reflect the changes, including a change from
166indeterminate to determinate or vice versa.
167\end{methoddesc}
168
169\begin{methoddesc}[ProgressBar]{inc}{\optional{n}}
170Increments the progress bar's \member{curval} by \var{n}, or by \code{1}
171if \var{n} is not provided. (Note that \var{n} may be negative, in
172which case the effect is a decrement.) The progress bar is updated to
173reflect the change. If the bar is indeterminate, this causes one
174``spin'' of the barber pole. The resulting \member{curval} is coerced
175between 0 and \member{maxval} if incrementing causes it to fall
176outside this range.
177\end{methoddesc}