blob: dbda57fba13ec4135e32119e6e3ce8b82beeffbe [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
2:mod:`EasyDialogs` --- Basic Macintosh dialogs
3==============================================
4
5.. module:: EasyDialogs
6 :platform: Mac
7 :synopsis: Basic Macintosh dialogs.
Benjamin Peterson23681932008-05-12 21:42:13 +00008 :deprecated:
Georg Brandl8ec7f652007-08-15 14:28:01 +00009
10
11The :mod:`EasyDialogs` module contains some simple dialogs for the Macintosh.
12All routines take an optional resource ID parameter *id* with which one can
13override the :const:`DLOG` resource used for the dialog, provided that the
14dialog items correspond (both type and item number) to those in the default
15:const:`DLOG` resource. See source code for details.
16
Benjamin Peterson23681932008-05-12 21:42:13 +000017.. warning::
18
19 This module is removed in 3.0.
20
21
Georg Brandl8ec7f652007-08-15 14:28:01 +000022The :mod:`EasyDialogs` module defines the following functions:
23
24
25.. function:: Message(str[, id[, ok]])
26
27 Displays a modal dialog with the message text *str*, which should be at most 255
28 characters long. The button text defaults to "OK", but is set to the string
29 argument *ok* if the latter is supplied. Control is returned when the user
30 clicks the "OK" button.
31
32
33.. function:: AskString(prompt[, default[, id[, ok[, cancel]]]])
34
35 Asks the user to input a string value via a modal dialog. *prompt* is the prompt
36 message, and the optional *default* supplies the initial value for the string
37 (otherwise ``""`` is used). The text of the "OK" and "Cancel" buttons can be
38 changed with the *ok* and *cancel* arguments. All strings can be at most 255
39 bytes long. :func:`AskString` returns the string entered or :const:`None` in
40 case the user cancelled.
41
42
43.. function:: AskPassword(prompt[, default[, id[, ok[, cancel]]]])
44
45 Asks the user to input a string value via a modal dialog. Like
46 :func:`AskString`, but with the text shown as bullets. The arguments have the
47 same meaning as for :func:`AskString`.
48
49
50.. function:: AskYesNoCancel(question[, default[, yes[, no[, cancel[, id]]]]])
51
52 Presents a dialog with prompt *question* and three buttons labelled "Yes", "No",
53 and "Cancel". Returns ``1`` for "Yes", ``0`` for "No" and ``-1`` for "Cancel".
54 The value of *default* (or ``0`` if *default* is not supplied) is returned when
55 the :kbd:`RETURN` key is pressed. The text of the buttons can be changed with
56 the *yes*, *no*, and *cancel* arguments; to prevent a button from appearing,
57 supply ``""`` for the corresponding argument.
58
59
60.. function:: ProgressBar([title[, maxval[, label[, id]]]])
61
62 Displays a modeless progress-bar dialog. This is the constructor for the
63 :class:`ProgressBar` class described below. *title* is the text string displayed
64 (default "Working..."), *maxval* is the value at which progress is complete
65 (default ``0``, indicating that an indeterminate amount of work remains to be
66 done), and *label* is the text that is displayed above the progress bar itself.
67
68
69.. function:: GetArgv([optionlist[ commandlist[, addoldfile[, addnewfile[, addfolder[, id]]]]]])
70
71 Displays a dialog which aids the user in constructing a command-line argument
72 list. Returns the list in ``sys.argv`` format, suitable for passing as an
73 argument to :func:`getopt.getopt`. *addoldfile*, *addnewfile*, and *addfolder*
74 are boolean arguments. When nonzero, they enable the user to insert into the
75 command line paths to an existing file, a (possibly) not-yet-existent file, and
76 a folder, respectively. (Note: Option arguments must appear in the command line
77 before file and folder arguments in order to be recognized by
78 :func:`getopt.getopt`.) Arguments containing spaces can be specified by
79 enclosing them within single or double quotes. A :exc:`SystemExit` exception is
80 raised if the user presses the "Cancel" button.
81
82 *optionlist* is a list that determines a popup menu from which the allowed
83 options are selected. Its items can take one of two forms: *optstr* or
84 ``(optstr, descr)``. When present, *descr* is a short descriptive string that
85 is displayed in the dialog while this option is selected in the popup menu. The
86 correspondence between *optstr*\s and command-line arguments is:
87
88 +----------------------+------------------------------------------+
89 | *optstr* format | Command-line format |
90 +======================+==========================================+
91 | ``x`` | :option:`-x` (short option) |
92 +----------------------+------------------------------------------+
93 | ``x:`` or ``x=`` | :option:`-x` (short option with value) |
94 +----------------------+------------------------------------------+
95 | ``xyz`` | :option:`--xyz` (long option) |
96 +----------------------+------------------------------------------+
97 | ``xyz:`` or ``xyz=`` | :option:`--xyz` (long option with value) |
98 +----------------------+------------------------------------------+
99
100 *commandlist* is a list of items of the form *cmdstr* or ``(cmdstr, descr)``,
101 where *descr* is as above. The *cmdstr*s will appear in a popup menu. When
102 chosen, the text of *cmdstr* will be appended to the command line as is, except
103 that a trailing ``':'`` or ``'='`` (if present) will be trimmed off.
104
105 .. versionadded:: 2.0
106
107
108.. function:: AskFileForOpen( [message] [, typeList] [, defaultLocation] [, defaultOptionFlags] [, location] [, clientName] [, windowTitle] [, actionButtonLabel] [, cancelButtonLabel] [, preferenceKey] [, popupExtension] [, eventProc] [, previewProc] [, filterProc] [, wanted] )
109
110 Post a dialog asking the user for a file to open, and return the file selected
111 or :const:`None` if the user cancelled. *message* is a text message to display,
112 *typeList* is a list of 4-char filetypes allowable, *defaultLocation* is the
113 pathname, :class:`FSSpec` or :class:`FSRef` of the folder to show initially,
114 *location* is the ``(x, y)`` position on the screen where the dialog is shown,
115 *actionButtonLabel* is a string to show instead of "Open" in the OK button,
116 *cancelButtonLabel* is a string to show instead of "Cancel" in the cancel
117 button, *wanted* is the type of value wanted as a return: :class:`str`,
118 :class:`unicode`, :class:`FSSpec`, :class:`FSRef` and subtypes thereof are
119 acceptable.
120
121 .. index:: single: Navigation Services
122
123 For a description of the other arguments please see the Apple Navigation
124 Services documentation and the :mod:`EasyDialogs` source code.
125
126
127.. function:: AskFileForSave( [message] [, savedFileName] [, defaultLocation] [, defaultOptionFlags] [, location] [, clientName] [, windowTitle] [, actionButtonLabel] [, cancelButtonLabel] [, preferenceKey] [, popupExtension] [, fileType] [, fileCreator] [, eventProc] [, wanted] )
128
129 Post a dialog asking the user for a file to save to, and return the file
130 selected or :const:`None` if the user cancelled. *savedFileName* is the default
131 for the file name to save to (the return value). See :func:`AskFileForOpen` for
132 a description of the other arguments.
133
134
135.. function:: AskFolder( [message] [, defaultLocation] [, defaultOptionFlags] [, location] [, clientName] [, windowTitle] [, actionButtonLabel] [, cancelButtonLabel] [, preferenceKey] [, popupExtension] [, eventProc] [, filterProc] [, wanted] )
136
137 Post a dialog asking the user to select a folder, and return the folder selected
138 or :const:`None` if the user cancelled. See :func:`AskFileForOpen` for a
139 description of the arguments.
140
141
142.. seealso::
143
144 `Navigation Services Reference <http://developer.apple.com/documentation/Carbon/Reference/Navigation_Services_Ref/>`_
145 Programmer's reference documentation for the Navigation Services, a part of the
146 Carbon framework.
147
148
149.. _progressbar-objects:
150
151ProgressBar Objects
152-------------------
153
154:class:`ProgressBar` objects provide support for modeless progress-bar dialogs.
155Both determinate (thermometer style) and indeterminate (barber-pole style)
156progress bars are supported. The bar will be determinate if its maximum value
157is greater than zero; otherwise it will be indeterminate.
158
159.. versionchanged:: 2.2
160 Support for indeterminate-style progress bars was added.
161
162The dialog is displayed immediately after creation. If the dialog's "Cancel"
163button is pressed, or if :kbd:`Cmd-.` or :kbd:`ESC` is typed, the dialog window
164is hidden and :exc:`KeyboardInterrupt` is raised (but note that this response
165does not occur until the progress bar is next updated, typically via a call to
166:meth:`inc` or :meth:`set`). Otherwise, the bar remains visible until the
167:class:`ProgressBar` object is discarded.
168
169:class:`ProgressBar` objects possess the following attributes and methods:
170
171
172.. attribute:: ProgressBar.curval
173
174 The current value (of type integer or long integer) of the progress bar. The
175 normal access methods coerce :attr:`curval` between ``0`` and :attr:`maxval`.
176 This attribute should not be altered directly.
177
178
179.. attribute:: ProgressBar.maxval
180
181 The maximum value (of type integer or long integer) of the progress bar; the
182 progress bar (thermometer style) is full when :attr:`curval` equals
183 :attr:`maxval`. If :attr:`maxval` is ``0``, the bar will be indeterminate
184 (barber-pole). This attribute should not be altered directly.
185
186
187.. method:: ProgressBar.title([newstr])
188
189 Sets the text in the title bar of the progress dialog to *newstr*.
190
191
192.. method:: ProgressBar.label([newstr])
193
194 Sets the text in the progress box of the progress dialog to *newstr*.
195
196
197.. method:: ProgressBar.set(value[, max])
198
199 Sets the progress bar's :attr:`curval` to *value*, and also :attr:`maxval` to
200 *max* if the latter is provided. *value* is first coerced between 0 and
201 :attr:`maxval`. The thermometer bar is updated to reflect the changes,
202 including a change from indeterminate to determinate or vice versa.
203
204
205.. method:: ProgressBar.inc([n])
206
207 Increments the progress bar's :attr:`curval` by *n*, or by ``1`` if *n* is not
208 provided. (Note that *n* may be negative, in which case the effect is a
209 decrement.) The progress bar is updated to reflect the change. If the bar is
210 indeterminate, this causes one "spin" of the barber pole. The resulting
211 :attr:`curval` is coerced between 0 and :attr:`maxval` if incrementing causes it
212 to fall outside this range.
213