Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 1 | \section{Standard module \sectcode{EasyDialogs}} |
| 2 | \stmodindex{EasyDialogs} |
| 3 | |
| 4 | The \code{EasyDialogs} module contains some simple dialogs for |
| 5 | the Macintosh, modelled after the \code{stdwin} dialogs with similar |
| 6 | names. |
| 7 | |
| 8 | The \code{EasyDialogs} module defines the following functions: |
| 9 | |
| 10 | \renewcommand{\indexsubitem}{(in module EasyDialogs)} |
| 11 | |
| 12 | \begin{funcdesc}{Message}{str} |
| 13 | A modal dialog with the message text \var{str}, which should be at |
| 14 | most 255 characters long, is displayed. Control is returned when the |
| 15 | user clicks ``OK''. |
| 16 | \end{funcdesc} |
| 17 | |
| 18 | \begin{funcdesc}{AskString}{prompt\optional{\, default}} |
| 19 | Ask the user to input a string value, in a modal dialog. \var{Prompt} |
| 20 | is the promt message, the optional \var{default} arg is the initial |
| 21 | value for the string. All strings can be at most 255 bytes |
| 22 | long. \var{AskString} returns the string entered or \code{None} in |
| 23 | case the user cancelled. |
| 24 | \end{funcdesc} |
| 25 | |
| 26 | \begin{funcdesc}{AskYesNoCancel}{question\optional{\, default}} |
| 27 | Present a dialog with text \var{question} and three buttons labelled |
| 28 | ``yes'', ``no'' and ``cancel''. Return \code{1} for yes, \code{0} for |
| 29 | no and \code{-1} for cancel. The default return value chosen by |
| 30 | hitting return is \code{0}. This can be changed with the optional |
| 31 | \var{default} argument. |
| 32 | \end{funcdesc} |
| 33 | |
Jack Jansen | 350b2b9 | 1995-11-14 10:30:27 +0000 | [diff] [blame] | 34 | \begin{funcdesc}{ProgressBar}{\optional{label\, maxval}} |
| 35 | Display a modeless progress dialog with a thermometer bar. \var{Label} |
| 36 | is the textstring displayed (default ``Working...''), \var{maxval} is |
| 37 | the value at which progress is complete (default 100). The returned |
| 38 | object has one method, \code{set(value)}, which sets the value of the |
| 39 | progress bar. The bar remains visible until the object returned is |
| 40 | discarded. |
| 41 | |
| 42 | The progress bar has a ``cancel'' button, but it is currently |
| 43 | non-functional. |
| 44 | \end{funcdesc} |
| 45 | |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 46 | Note that \code{EasyDialogs} does not currently use the notification |
| 47 | manager. This means that displaying dialogs while the program is in |
Jack Jansen | 350b2b9 | 1995-11-14 10:30:27 +0000 | [diff] [blame] | 48 | the background will lead to unexpected results and possibly |
| 49 | crashes. Also, all dialogs are modeless and hence expect to be at the |
| 50 | top of the stacking order. This is true when the dialogs are created, |
| 51 | but windows that pop-up later (like a console window) may also result |
| 52 | in crashes. |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 53 | |
| 54 | |
| 55 | \section{Standard module \sectcode{FrameWork}} |
| 56 | \stmodindex{FrameWork} |
| 57 | |
| 58 | The \code{FrameWork} module contains classes that together provide a |
| 59 | framework for an interactive Macintosh application. The programmer |
| 60 | builds an application by creating subclasses that override various |
| 61 | methods of the bases classes, thereby implementing the functionality |
| 62 | wanted. Overriding functionality can often be done on various |
| 63 | different levels, i.e. to handle clicks in a single dialog window in a |
| 64 | non-standard way it is not necessary to override the complete event |
| 65 | handling. |
| 66 | |
| 67 | The \code{FrameWork} is still very much work-in-progress, and the |
| 68 | documentation describes only the most important functionality, and not |
Guido van Rossum | 66774a9 | 1996-07-21 02:20:58 +0000 | [diff] [blame^] | 69 | in the most logical manner at that. Examine the source or the examples |
| 70 | for more details. |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 71 | |
Guido van Rossum | 66774a9 | 1996-07-21 02:20:58 +0000 | [diff] [blame^] | 72 | The \code{FrameWork} module defines the following functions: |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 73 | |
| 74 | \renewcommand{\indexsubitem}{(in module FrameWork)} |
| 75 | |
| 76 | \begin{funcdesc}{Application}{} |
| 77 | An object representing the complete application. See below for a |
| 78 | description of the methods. The default \code{__init__} routine |
| 79 | creates an empty window dictionary and a menu bar with an apple menu. |
| 80 | \end{funcdesc} |
| 81 | |
| 82 | \begin{funcdesc}{MenuBar}{} |
| 83 | An object representing the menubar. This object is usually not created |
| 84 | by the user. |
| 85 | \end{funcdesc} |
| 86 | |
| 87 | \begin{funcdesc}{Menu}{bar\, title\optional{\, after}} |
| 88 | An object representing a menu. Upon creation you pass the |
| 89 | \code{MenuBar} the menu appears in, the \var{title} string and a |
| 90 | position (1-based) \var{after} where the menu should appear (default: |
| 91 | at the end). |
| 92 | \end{funcdesc} |
| 93 | |
| 94 | \begin{funcdesc}{MenuItem}{menu\, title\optional{\, shortcut\, callback}} |
| 95 | Create a menu item object. The arguments are the menu to crate the |
| 96 | item it, the item title string and optionally the keyboard shortcut |
| 97 | and a callback routine. The callback is called with the arguments |
| 98 | menu-id, item number within menu (1-based), current front window and |
| 99 | the event record. |
| 100 | \end{funcdesc} |
| 101 | |
| 102 | \begin{funcdesc}{Separator}{menu} |
| 103 | Add a separator to the end of a menu. |
| 104 | \end{funcdesc} |
| 105 | |
| 106 | \begin{funcdesc}{SubMenu}{menu\, label} |
| 107 | Create a submenu named \var{label} under menu \var{menu}. The menu |
| 108 | object is returned. |
| 109 | \end{funcdesc} |
| 110 | |
| 111 | \begin{funcdesc}{Window}{parent} |
| 112 | Creates a (modeless) window. \var{Parent} is the application object to |
| 113 | which the window belongs. The window is not displayed until later. |
| 114 | \end{funcdesc} |
| 115 | |
| 116 | \begin{funcdesc}{DialogWindow}{parent} |
| 117 | Creates a modeless dialog window. |
| 118 | \end{funcdesc} |
| 119 | |
Guido van Rossum | 66774a9 | 1996-07-21 02:20:58 +0000 | [diff] [blame^] | 120 | \begin{funcdesc}{windowbounds}{width\, height} |
| 121 | Return a \code{(left, top, right, bottom)} tuple suitable for creation |
| 122 | of a window of given width and height. The window will be staggered |
| 123 | with respect to previous windows, and an attempt is made to keep the |
| 124 | whole window on-screen. The window will however always be exact the |
| 125 | size given, so parts may be offscreen. |
| 126 | \end{funcdesc} |
| 127 | |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 128 | |
| 129 | \subsection{Application objects} |
| 130 | Application objects have the following methods, among others: |
| 131 | |
| 132 | \renewcommand{\indexsubitem}{(Application method)} |
| 133 | |
| 134 | \begin{funcdesc}{makeusermenus}{} |
| 135 | Override this method if you need menus in your application. Append the |
| 136 | menus to \code{self.menubar}. |
| 137 | \end{funcdesc} |
| 138 | |
| 139 | \begin{funcdesc}{getabouttext}{} |
| 140 | Override this method to return a text string describing your |
| 141 | application. Alternatively, override the \code{do_about} method for |
| 142 | more elaborate about messages. |
| 143 | \end{funcdesc} |
| 144 | |
| 145 | \begin{funcdesc}{mainloop}{\optional{mask\, wait}} |
| 146 | This routine is the main event loop, call it to set your application |
| 147 | rolling. \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 |
| 149 | concurrent application (default 0, which is probably not a good |
| 150 | idea). This method does not return until \code{self} is raised. |
| 151 | |
| 152 | The event loop is split into many small parts, each of which can be |
| 153 | overridden. The default methods take care of dispatching events to |
| 154 | windows and dialogs, handling drags and resizes, Apple Events, events |
| 155 | for non-FrameWork windows, etc. |
| 156 | \end{funcdesc} |
| 157 | |
| 158 | \begin{funcdesc}{do_char}{c\, event} |
| 159 | The user typed character \var{c}. The complete details of the event |
| 160 | can be found in the \var{event} structure. This method can also be |
| 161 | provided in a \code{Window} object, which overrides the |
| 162 | application-wide handler if the window is frontmost. |
| 163 | \end{funcdesc} |
| 164 | |
| 165 | \begin{funcdesc}{do_dialogevent}{event} |
| 166 | Called early in the event loop to handle modeless dialog events. The |
| 167 | default method simply dispatches the event to the relevant dialog (not |
| 168 | through the the \code{DialogWindow} object involved). Override if you |
| 169 | need special handling of dialog events (keyboard shortcuts, etc). |
| 170 | \end{funcdesc} |
| 171 | |
Guido van Rossum | 66774a9 | 1996-07-21 02:20:58 +0000 | [diff] [blame^] | 172 | \begin{funcdesc}{idle}{event} |
| 173 | Called by the main event loop when no events are available. The |
| 174 | null-event is passed (so you can look at mouse position, etc). |
Jack Jansen | 350b2b9 | 1995-11-14 10:30:27 +0000 | [diff] [blame] | 175 | \end{funcdesc} |
| 176 | |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 177 | \subsection{Window Objects} |
| 178 | |
| 179 | Window objects have the following methods, among others: |
| 180 | |
| 181 | \renewcommand{\indexsubitem}{(Window method)} |
| 182 | |
| 183 | \begin{funcdesc}{open}{} |
| 184 | Override 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 |
| 186 | window with the parent application. |
| 187 | \end{funcdesc} |
| 188 | |
| 189 | \begin{funcdesc}{close}{} |
| 190 | Override this method to do any special processing on window |
| 191 | close. Call \code{self.do_postclose} to cleanup the parent state. |
| 192 | \end{funcdesc} |
| 193 | |
| 194 | \begin{funcdesc}{do_postresize}{width\, height\, macoswindowid} |
| 195 | Called after the window is resized. Override if more needs to be done |
| 196 | than calling \code{InvalRect}. |
| 197 | \end{funcdesc} |
| 198 | |
| 199 | \begin{funcdesc}{do_contentclick}{local\, modifiers\, event} |
| 200 | The user clicked in the content part of a window. The arguments are |
| 201 | the coordinates (window-relative), the key modifiers and the raw |
| 202 | event. |
| 203 | \end{funcdesc} |
| 204 | |
| 205 | \begin{funcdesc}{do_update}{macoswindowid\, event} |
| 206 | An update event for the window was received. Redraw the window. |
| 207 | \end{funcdesc} |
| 208 | |
| 209 | \begin{funcdesc}{do_activate}{activate\, event} |
| 210 | The window was activated (\code{activate==1}) or deactivated |
| 211 | (\code{activate==0}). Handle things like focus highlighting, etc. |
| 212 | \end{funcdesc} |
| 213 | |
Guido van Rossum | 66774a9 | 1996-07-21 02:20:58 +0000 | [diff] [blame^] | 214 | \subsection{ControlsWindow Object} |
| 215 | |
| 216 | ControlsWindow 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} |
| 222 | Part \code{pcode} of control \code{control} was hit by the |
| 223 | user. Tracking and such has already been taken care of. |
| 224 | \end{funcdesc} |
| 225 | |
| 226 | \subsection{ScrolledWindow Object} |
| 227 | |
| 228 | ScrolledWindow objects are ControlsWindow objects with the following |
| 229 | extra mathods: |
| 230 | |
| 231 | \renewcommand{\indexsubitem}{(ScrolledWindow method)} |
| 232 | |
| 233 | \begin{funcdesc}{scrollbars}{\optional{wantx\, wanty}} |
| 234 | Create (or destroy) horizontal and vertical scrollbars. The arguments |
| 235 | specify which you want (default: both). The scrollbars always have |
| 236 | minimum \code{0} and maximum \code{32767}. |
| 237 | \end{funcdesc} |
| 238 | |
| 239 | \begin{funcdesc}{getscrollbarvalues}{} |
| 240 | You must supply this method. It should return a tuple \code{x, y} |
| 241 | giving the current position of the scrollbars (between \code{0} and |
| 242 | \code{32767}). You can return \code{None} for either to indicate the |
| 243 | whole document is visible in that direction. |
| 244 | \end{funcdesc} |
| 245 | |
| 246 | \begin{funcdesc}{updatescrollbars}{} |
| 247 | Call 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} |
| 252 | Supplied by you and called after user interaction. \code{Which} will |
| 253 | be \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} |
| 259 | Auxiliary method to help you calculate values to return from |
| 260 | \code{getscrollbarvalues}. You pass document minimum and maximum value |
| 261 | and topmost (leftmost) and bottommost (rightmost) visible values and |
| 262 | it returns the correct number or \code{None}. |
| 263 | \end{funcdesc} |
| 264 | |
| 265 | \begin{funcdesc}{do_activate}{onoff\, event} |
| 266 | Takes care of dimming/highlighting scrollbars when a window becomes |
| 267 | frontmost vv. If you override this method call this one at the end of |
| 268 | your method. |
| 269 | \end{funcdesc} |
| 270 | |
| 271 | \begin{funcdesc}{do_postresize}{width\, height\, window} |
| 272 | Moves scrollbars to the correct position. Call this method initially |
| 273 | if you override it. |
| 274 | \end{funcdesc} |
| 275 | |
| 276 | \begin{funcdesc}{do_controlhit}{window\, control\, pcode\, event} |
| 277 | Handles scrollbar interaction. If you override it call this method |
| 278 | first, a nonzero return value indicates the hit was in the scrollbars |
| 279 | and has been handled. |
| 280 | \end{funcdesc} |
| 281 | |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 282 | \subsection{DialogWindow Objects} |
| 283 | |
| 284 | DialogWindow objects have the following methods besides those of |
| 285 | \code{Window} objects: |
| 286 | |
| 287 | \renewcommand{\indexsubitem}{(DialogWindow method)} |
| 288 | |
| 289 | \begin{funcdesc}{open}{resid} |
| 290 | Create 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} |
| 295 | Item number \var{item} was hit. You are responsible for redrawing |
| 296 | toggle buttons, etc. |
| 297 | \end{funcdesc} |
| 298 | |