/Doc/library/easydialogs.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 215 lines · 145 code · 70 blank · 0 comment · 0 complexity · 1c4447552ea903ba84fc3d3ee8dd902e MD5 · raw file

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