Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 1 | \section{Standard module \sectcode{EasyDialogs}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 2 | \label{module-EasyDialogs} |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 3 | \stmodindex{EasyDialogs} |
| 4 | |
| 5 | The \code{EasyDialogs} module contains some simple dialogs for |
| 6 | the Macintosh, modelled after the \code{stdwin} dialogs with similar |
Guido van Rossum | e229d86 | 1997-08-18 15:14:26 +0000 | [diff] [blame] | 7 | names. All routines have an optional parameter \var{id} with which you |
| 8 | can override the DLOG resource used for the dialog, as long as the |
| 9 | item numbers correspond. See the source for details. |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 10 | |
| 11 | The \code{EasyDialogs} module defines the following functions: |
| 12 | |
| 13 | \renewcommand{\indexsubitem}{(in module EasyDialogs)} |
| 14 | |
| 15 | \begin{funcdesc}{Message}{str} |
| 16 | A modal dialog with the message text \var{str}, which should be at |
| 17 | most 255 characters long, is displayed. Control is returned when the |
| 18 | user clicks ``OK''. |
| 19 | \end{funcdesc} |
| 20 | |
| 21 | \begin{funcdesc}{AskString}{prompt\optional{\, default}} |
| 22 | Ask the user to input a string value, in a modal dialog. \var{Prompt} |
| 23 | is the promt message, the optional \var{default} arg is the initial |
| 24 | value for the string. All strings can be at most 255 bytes |
| 25 | long. \var{AskString} returns the string entered or \code{None} in |
| 26 | case the user cancelled. |
| 27 | \end{funcdesc} |
| 28 | |
| 29 | \begin{funcdesc}{AskYesNoCancel}{question\optional{\, default}} |
| 30 | Present a dialog with text \var{question} and three buttons labelled |
| 31 | ``yes'', ``no'' and ``cancel''. Return \code{1} for yes, \code{0} for |
| 32 | no and \code{-1} for cancel. The default return value chosen by |
| 33 | hitting return is \code{0}. This can be changed with the optional |
| 34 | \var{default} argument. |
| 35 | \end{funcdesc} |
| 36 | |
Jack Jansen | 350b2b9 | 1995-11-14 10:30:27 +0000 | [diff] [blame] | 37 | \begin{funcdesc}{ProgressBar}{\optional{label\, maxval}} |
| 38 | Display a modeless progress dialog with a thermometer bar. \var{Label} |
| 39 | is the textstring displayed (default ``Working...''), \var{maxval} is |
| 40 | the value at which progress is complete (default 100). The returned |
| 41 | object has one method, \code{set(value)}, which sets the value of the |
| 42 | progress bar. The bar remains visible until the object returned is |
| 43 | discarded. |
| 44 | |
| 45 | The progress bar has a ``cancel'' button, but it is currently |
| 46 | non-functional. |
| 47 | \end{funcdesc} |
| 48 | |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 49 | Note that \code{EasyDialogs} does not currently use the notification |
| 50 | manager. This means that displaying dialogs while the program is in |
Jack Jansen | 350b2b9 | 1995-11-14 10:30:27 +0000 | [diff] [blame] | 51 | the background will lead to unexpected results and possibly |
| 52 | crashes. Also, all dialogs are modeless and hence expect to be at the |
| 53 | top of the stacking order. This is true when the dialogs are created, |
| 54 | but windows that pop-up later (like a console window) may also result |
| 55 | in crashes. |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | \section{Standard module \sectcode{FrameWork}} |
| 59 | \stmodindex{FrameWork} |
| 60 | |
| 61 | The \code{FrameWork} module contains classes that together provide a |
| 62 | framework for an interactive Macintosh application. The programmer |
| 63 | builds an application by creating subclasses that override various |
| 64 | methods of the bases classes, thereby implementing the functionality |
| 65 | wanted. Overriding functionality can often be done on various |
| 66 | different levels, i.e. to handle clicks in a single dialog window in a |
| 67 | non-standard way it is not necessary to override the complete event |
| 68 | handling. |
| 69 | |
| 70 | The \code{FrameWork} is still very much work-in-progress, and the |
| 71 | documentation describes only the most important functionality, and not |
Guido van Rossum | 66774a9 | 1996-07-21 02:20:58 +0000 | [diff] [blame] | 72 | in the most logical manner at that. Examine the source or the examples |
| 73 | for more details. |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 74 | |
Guido van Rossum | 66774a9 | 1996-07-21 02:20:58 +0000 | [diff] [blame] | 75 | The \code{FrameWork} module defines the following functions: |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 76 | |
| 77 | \renewcommand{\indexsubitem}{(in module FrameWork)} |
| 78 | |
| 79 | \begin{funcdesc}{Application}{} |
| 80 | An object representing the complete application. See below for a |
| 81 | description of the methods. The default \code{__init__} routine |
| 82 | creates an empty window dictionary and a menu bar with an apple menu. |
| 83 | \end{funcdesc} |
| 84 | |
| 85 | \begin{funcdesc}{MenuBar}{} |
| 86 | An object representing the menubar. This object is usually not created |
| 87 | by the user. |
| 88 | \end{funcdesc} |
| 89 | |
| 90 | \begin{funcdesc}{Menu}{bar\, title\optional{\, after}} |
| 91 | An object representing a menu. Upon creation you pass the |
| 92 | \code{MenuBar} the menu appears in, the \var{title} string and a |
| 93 | position (1-based) \var{after} where the menu should appear (default: |
| 94 | at the end). |
| 95 | \end{funcdesc} |
| 96 | |
| 97 | \begin{funcdesc}{MenuItem}{menu\, title\optional{\, shortcut\, callback}} |
| 98 | Create a menu item object. The arguments are the menu to crate the |
| 99 | item it, the item title string and optionally the keyboard shortcut |
| 100 | and a callback routine. The callback is called with the arguments |
| 101 | menu-id, item number within menu (1-based), current front window and |
| 102 | the event record. |
Guido van Rossum | 7e42cab | 1996-10-15 14:37:31 +0000 | [diff] [blame] | 103 | |
| 104 | In stead of a callable object the callback can also be a string. In |
| 105 | this case menu selection causes the lookup of a method in the topmost |
| 106 | window and the application. The method name is the callback string |
| 107 | with \code{'domenu_'} prepended. |
| 108 | |
| 109 | Calling the \code{MenuBar} \code{fixmenudimstate} method sets the |
| 110 | correct dimming for all menu items based on the current front window. |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 111 | \end{funcdesc} |
| 112 | |
| 113 | \begin{funcdesc}{Separator}{menu} |
| 114 | Add a separator to the end of a menu. |
| 115 | \end{funcdesc} |
| 116 | |
| 117 | \begin{funcdesc}{SubMenu}{menu\, label} |
| 118 | Create a submenu named \var{label} under menu \var{menu}. The menu |
| 119 | object is returned. |
| 120 | \end{funcdesc} |
| 121 | |
| 122 | \begin{funcdesc}{Window}{parent} |
| 123 | Creates a (modeless) window. \var{Parent} is the application object to |
| 124 | which the window belongs. The window is not displayed until later. |
| 125 | \end{funcdesc} |
| 126 | |
| 127 | \begin{funcdesc}{DialogWindow}{parent} |
| 128 | Creates a modeless dialog window. |
| 129 | \end{funcdesc} |
| 130 | |
Guido van Rossum | 66774a9 | 1996-07-21 02:20:58 +0000 | [diff] [blame] | 131 | \begin{funcdesc}{windowbounds}{width\, height} |
| 132 | Return a \code{(left, top, right, bottom)} tuple suitable for creation |
| 133 | of a window of given width and height. The window will be staggered |
| 134 | with respect to previous windows, and an attempt is made to keep the |
| 135 | whole window on-screen. The window will however always be exact the |
| 136 | size given, so parts may be offscreen. |
| 137 | \end{funcdesc} |
| 138 | |
Guido van Rossum | 7e42cab | 1996-10-15 14:37:31 +0000 | [diff] [blame] | 139 | \begin{funcdesc}{setwatchcursor}{} |
| 140 | Set the mouse cursor to a watch. |
| 141 | \end{funcdesc} |
| 142 | |
| 143 | \begin{funcdesc}{setarrowcursor}{} |
| 144 | Set the mouse cursor to an arrow. |
| 145 | \end{funcdesc} |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 146 | |
| 147 | \subsection{Application objects} |
| 148 | Application objects have the following methods, among others: |
| 149 | |
| 150 | \renewcommand{\indexsubitem}{(Application method)} |
| 151 | |
| 152 | \begin{funcdesc}{makeusermenus}{} |
| 153 | Override this method if you need menus in your application. Append the |
| 154 | menus to \code{self.menubar}. |
| 155 | \end{funcdesc} |
| 156 | |
| 157 | \begin{funcdesc}{getabouttext}{} |
| 158 | Override this method to return a text string describing your |
| 159 | application. Alternatively, override the \code{do_about} method for |
| 160 | more elaborate about messages. |
| 161 | \end{funcdesc} |
| 162 | |
| 163 | \begin{funcdesc}{mainloop}{\optional{mask\, wait}} |
| 164 | This routine is the main event loop, call it to set your application |
| 165 | rolling. \var{Mask} is the mask of events you want to handle, |
| 166 | \var{wait} is the number of ticks you want to leave to other |
| 167 | concurrent application (default 0, which is probably not a good |
Guido van Rossum | 7e42cab | 1996-10-15 14:37:31 +0000 | [diff] [blame] | 168 | idea). While raising \code{self} to exit the mainloop is still |
| 169 | supported it is not recommended, call \code{self._quit} instead. |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 170 | |
| 171 | The event loop is split into many small parts, each of which can be |
| 172 | overridden. The default methods take care of dispatching events to |
| 173 | windows and dialogs, handling drags and resizes, Apple Events, events |
| 174 | for non-FrameWork windows, etc. |
Guido van Rossum | e229d86 | 1997-08-18 15:14:26 +0000 | [diff] [blame] | 175 | |
| 176 | In general, all event handlers should return 1 if the event is fully |
| 177 | handled and 0 otherwise (because the front window was not a FrameWork |
| 178 | window, for instance). This is needed so that update events and such |
| 179 | can be passed on to other windows like the Sioux console window. |
| 180 | Calling \code{MacOS.HandleEvent} is not allowed within \var{our_dispatch} |
| 181 | or its callees, since this may result in an infinite loop if the |
| 182 | code is called through the python inner-loop event handler. |
| 183 | \end{funcdesc} |
| 184 | |
| 185 | \begin{funcdesc}{asyncevents}{onoff} |
| 186 | Call this method with a nonzero parameter to enable |
| 187 | asynchronous event handling. This will tell the inner interpreter loop |
| 188 | to call the application event handler \var{async_dispatch} whenever events |
| 189 | are available. This will cause FrameWork window updates and the user |
| 190 | interface to remain working during long computations, but will slow the |
| 191 | interpreter down and may cause surprising results in non-reentrant code |
| 192 | (such as FrameWork itself). By default \var{async_dispatch} will immedeately |
| 193 | call \var{our_dispatch} but you may override this to handle only certain |
| 194 | events asynchronously. Events you do not handle will be passed to Sioux |
| 195 | and such. |
| 196 | |
| 197 | The old on/off value is returned. |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 198 | \end{funcdesc} |
| 199 | |
Guido van Rossum | 7e42cab | 1996-10-15 14:37:31 +0000 | [diff] [blame] | 200 | \begin{funcdesc}{_quit}{} |
| 201 | Terminate the event \code{mainloop} at the next convenient moment. |
| 202 | \end{funcdesc} |
| 203 | |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 204 | \begin{funcdesc}{do_char}{c\, event} |
| 205 | The user typed character \var{c}. The complete details of the event |
| 206 | can be found in the \var{event} structure. This method can also be |
| 207 | provided in a \code{Window} object, which overrides the |
| 208 | application-wide handler if the window is frontmost. |
| 209 | \end{funcdesc} |
| 210 | |
| 211 | \begin{funcdesc}{do_dialogevent}{event} |
| 212 | Called early in the event loop to handle modeless dialog events. The |
| 213 | default method simply dispatches the event to the relevant dialog (not |
| 214 | through the the \code{DialogWindow} object involved). Override if you |
| 215 | need special handling of dialog events (keyboard shortcuts, etc). |
| 216 | \end{funcdesc} |
| 217 | |
Guido van Rossum | 66774a9 | 1996-07-21 02:20:58 +0000 | [diff] [blame] | 218 | \begin{funcdesc}{idle}{event} |
| 219 | Called by the main event loop when no events are available. The |
| 220 | null-event is passed (so you can look at mouse position, etc). |
Jack Jansen | 350b2b9 | 1995-11-14 10:30:27 +0000 | [diff] [blame] | 221 | \end{funcdesc} |
| 222 | |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 223 | \subsection{Window Objects} |
| 224 | |
| 225 | Window objects have the following methods, among others: |
| 226 | |
| 227 | \renewcommand{\indexsubitem}{(Window method)} |
| 228 | |
| 229 | \begin{funcdesc}{open}{} |
| 230 | Override this method to open a window. Store the MacOS window-id in |
| 231 | \code{self.wid} and call \code{self.do_postopen} to register the |
| 232 | window with the parent application. |
| 233 | \end{funcdesc} |
| 234 | |
| 235 | \begin{funcdesc}{close}{} |
| 236 | Override this method to do any special processing on window |
| 237 | close. Call \code{self.do_postclose} to cleanup the parent state. |
| 238 | \end{funcdesc} |
| 239 | |
| 240 | \begin{funcdesc}{do_postresize}{width\, height\, macoswindowid} |
| 241 | Called after the window is resized. Override if more needs to be done |
| 242 | than calling \code{InvalRect}. |
| 243 | \end{funcdesc} |
| 244 | |
| 245 | \begin{funcdesc}{do_contentclick}{local\, modifiers\, event} |
| 246 | The user clicked in the content part of a window. The arguments are |
| 247 | the coordinates (window-relative), the key modifiers and the raw |
| 248 | event. |
| 249 | \end{funcdesc} |
| 250 | |
| 251 | \begin{funcdesc}{do_update}{macoswindowid\, event} |
| 252 | An update event for the window was received. Redraw the window. |
| 253 | \end{funcdesc} |
| 254 | |
| 255 | \begin{funcdesc}{do_activate}{activate\, event} |
| 256 | The window was activated (\code{activate==1}) or deactivated |
| 257 | (\code{activate==0}). Handle things like focus highlighting, etc. |
| 258 | \end{funcdesc} |
| 259 | |
Guido van Rossum | 66774a9 | 1996-07-21 02:20:58 +0000 | [diff] [blame] | 260 | \subsection{ControlsWindow Object} |
| 261 | |
| 262 | ControlsWindow objects have the following methods besides those of |
| 263 | \code{Window} objects: |
| 264 | |
| 265 | \renewcommand{\indexsubitem}{(ControlsWindow method)} |
| 266 | |
| 267 | \begin{funcdesc}{do_controlhit}{window\, control\, pcode\, event} |
| 268 | Part \code{pcode} of control \code{control} was hit by the |
| 269 | user. Tracking and such has already been taken care of. |
| 270 | \end{funcdesc} |
| 271 | |
| 272 | \subsection{ScrolledWindow Object} |
| 273 | |
| 274 | ScrolledWindow objects are ControlsWindow objects with the following |
Guido van Rossum | 7e42cab | 1996-10-15 14:37:31 +0000 | [diff] [blame] | 275 | extra methods: |
Guido van Rossum | 66774a9 | 1996-07-21 02:20:58 +0000 | [diff] [blame] | 276 | |
| 277 | \renewcommand{\indexsubitem}{(ScrolledWindow method)} |
| 278 | |
| 279 | \begin{funcdesc}{scrollbars}{\optional{wantx\, wanty}} |
| 280 | Create (or destroy) horizontal and vertical scrollbars. The arguments |
| 281 | specify which you want (default: both). The scrollbars always have |
| 282 | minimum \code{0} and maximum \code{32767}. |
| 283 | \end{funcdesc} |
| 284 | |
| 285 | \begin{funcdesc}{getscrollbarvalues}{} |
| 286 | You must supply this method. It should return a tuple \code{x, y} |
| 287 | giving the current position of the scrollbars (between \code{0} and |
| 288 | \code{32767}). You can return \code{None} for either to indicate the |
| 289 | whole document is visible in that direction. |
| 290 | \end{funcdesc} |
| 291 | |
| 292 | \begin{funcdesc}{updatescrollbars}{} |
| 293 | Call this method when the document has changed. It will call |
| 294 | \code{getscrollbarvalues} and update the scrollbars. |
| 295 | \end{funcdesc} |
| 296 | |
| 297 | \begin{funcdesc}{scrollbar_callback}{which\, what\, value} |
| 298 | Supplied by you and called after user interaction. \code{Which} will |
| 299 | be \code{'x'} or \code{'y'}, \code{what} will be \code{'-'}, |
| 300 | \code{'--'}, \code{'set'}, \code{'++'} or \code{'+'}. For |
| 301 | \code{'set'}, \code{value} will contain the new scrollbar position. |
| 302 | \end{funcdesc} |
| 303 | |
| 304 | \begin{funcdesc}{scalebarvalues}{absmin\, absmax\, curmin\, curmax} |
| 305 | Auxiliary method to help you calculate values to return from |
| 306 | \code{getscrollbarvalues}. You pass document minimum and maximum value |
| 307 | and topmost (leftmost) and bottommost (rightmost) visible values and |
| 308 | it returns the correct number or \code{None}. |
| 309 | \end{funcdesc} |
| 310 | |
| 311 | \begin{funcdesc}{do_activate}{onoff\, event} |
| 312 | Takes care of dimming/highlighting scrollbars when a window becomes |
| 313 | frontmost vv. If you override this method call this one at the end of |
| 314 | your method. |
| 315 | \end{funcdesc} |
| 316 | |
| 317 | \begin{funcdesc}{do_postresize}{width\, height\, window} |
| 318 | Moves scrollbars to the correct position. Call this method initially |
| 319 | if you override it. |
| 320 | \end{funcdesc} |
| 321 | |
| 322 | \begin{funcdesc}{do_controlhit}{window\, control\, pcode\, event} |
| 323 | Handles scrollbar interaction. If you override it call this method |
| 324 | first, a nonzero return value indicates the hit was in the scrollbars |
| 325 | and has been handled. |
| 326 | \end{funcdesc} |
| 327 | |
Jack Jansen | da53c52 | 1995-10-10 14:43:20 +0000 | [diff] [blame] | 328 | \subsection{DialogWindow Objects} |
| 329 | |
| 330 | DialogWindow objects have the following methods besides those of |
| 331 | \code{Window} objects: |
| 332 | |
| 333 | \renewcommand{\indexsubitem}{(DialogWindow method)} |
| 334 | |
| 335 | \begin{funcdesc}{open}{resid} |
| 336 | Create the dialog window, from the DLOG resource with id |
| 337 | \var{resid}. The dialog object is stored in \code{self.wid}. |
| 338 | \end{funcdesc} |
| 339 | |
| 340 | \begin{funcdesc}{do_itemhit}{item\, event} |
| 341 | Item number \var{item} was hit. You are responsible for redrawing |
| 342 | toggle buttons, etc. |
| 343 | \end{funcdesc} |
| 344 | |
Guido van Rossum | 7e42cab | 1996-10-15 14:37:31 +0000 | [diff] [blame] | 345 | \section{Standard module \sectcode{MiniAEFrame}} |
| 346 | \stmodindex{MiniAEFrame} |
| 347 | |
| 348 | The module \var{MiniAEFrame} provides a framework for an application |
| 349 | that can function as an OSA server, i.e. receive and process |
| 350 | AppleEvents. It can be used in conjunction with \var{FrameWork} or |
| 351 | standalone. |
| 352 | |
| 353 | This module is temporary, it will eventually be replaced by a module |
| 354 | that handles argument names better and possibly automates making your |
| 355 | application scriptable. |
| 356 | |
| 357 | The \var{MiniAEFrame} module defines the following classes: |
| 358 | |
| 359 | \renewcommand{\indexsubitem}{(in module MiniAEFrame)} |
| 360 | |
| 361 | \begin{funcdesc}{AEServer}{} |
| 362 | A class that handles AppleEvent dispatch. Your application should |
| 363 | subclass this class together with either |
| 364 | \code{MiniAEFrame.MiniApplication} or |
| 365 | \code{FrameWork.Application}. Your \code{__init__} method should call |
| 366 | the \code{__init__} method for both classes. |
| 367 | \end{funcdesc} |
| 368 | |
| 369 | \begin{funcdesc}{MiniApplication}{} |
| 370 | A class that is more or less compatible with |
| 371 | \code{FrameWork.Application} but with less functionality. Its |
| 372 | eventloop supports the apple menu, command-dot and AppleEvents, other |
| 373 | events are passed on to the Python interpreter and/or Sioux. |
| 374 | Useful if your application wants to use \code{AEServer} but does not |
| 375 | provide its own windows, etc. |
| 376 | \end{funcdesc} |
| 377 | |
| 378 | \subsection{AEServer Objects} |
| 379 | |
| 380 | \renewcommand{\indexsubitem}{(AEServer method)} |
| 381 | |
| 382 | \begin{funcdesc}{installaehandler}{classe\, type\, callback} |
| 383 | Installs an AppleEvent handler. \code{Classe} and \code{type} are the |
| 384 | four-char OSA Class and Type designators, \code{'****'} wildcards are |
| 385 | allowed. When a matching AppleEvent is received the parameters are |
| 386 | decoded and your callback is invoked. |
| 387 | \end{funcdesc} |
| 388 | |
| 389 | \begin{funcdesc}{callback}{_object\, **kwargs} |
| 390 | Your callback is called with the OSA Direct Object as first positional |
| 391 | parameter. The other parameters are passed as keyword arguments, with |
| 392 | the 4-char designator as name. Three extra keyword parameters are |
| 393 | passed: \code{_class} and \code{_type} are the Class and Type |
| 394 | designators and \code{_attributes} is a dictionary with the AppleEvent |
| 395 | attributes. |
| 396 | |
| 397 | The return value of your method is packed with |
| 398 | \code{aetools.packevent} and sent as reply. |
| 399 | \end{funcdesc} |
| 400 | |
| 401 | Note that there are some serious problems with the current |
| 402 | design. AppleEvents which have non-identifier 4-char designators for |
| 403 | arguments are not implementable, and it is not possible to return an |
| 404 | error to the originator. This will be addressed in a future release. |