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