Fred Drake | 3a0351c | 1998-04-04 07:23:21 +0000 | [diff] [blame] | 1 | \section{Standard Module \module{FrameWork}} |
Fred Drake | fe7f3bc | 1998-07-23 17:55:31 +0000 | [diff] [blame] | 2 | \declaremodule{standard}{FrameWork} |
| 3 | |
| 4 | \modulesynopsis{Interactive application framework.} |
| 5 | |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 6 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 7 | The \module{FrameWork} module contains classes that together provide a |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 8 | framework for an interactive Macintosh application. The programmer |
| 9 | builds an application by creating subclasses that override various |
| 10 | methods of the bases classes, thereby implementing the functionality |
| 11 | wanted. Overriding functionality can often be done on various |
| 12 | different levels, i.e. to handle clicks in a single dialog window in a |
| 13 | non-standard way it is not necessary to override the complete event |
| 14 | handling. |
| 15 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 16 | The \module{FrameWork} is still very much work-in-progress, and the |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 17 | documentation describes only the most important functionality, and not |
| 18 | in the most logical manner at that. Examine the source or the examples |
| 19 | for more details. |
| 20 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 21 | The \module{FrameWork} module defines the following functions: |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 22 | |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 23 | |
| 24 | \begin{funcdesc}{Application}{} |
| 25 | An object representing the complete application. See below for a |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 26 | description of the methods. The default \method{__init__()} routine |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 27 | creates an empty window dictionary and a menu bar with an apple menu. |
| 28 | \end{funcdesc} |
| 29 | |
| 30 | \begin{funcdesc}{MenuBar}{} |
| 31 | An object representing the menubar. This object is usually not created |
| 32 | by the user. |
| 33 | \end{funcdesc} |
| 34 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 35 | \begin{funcdesc}{Menu}{bar, title\optional{, after}} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 36 | An object representing a menu. Upon creation you pass the |
| 37 | \code{MenuBar} the menu appears in, the \var{title} string and a |
| 38 | position (1-based) \var{after} where the menu should appear (default: |
| 39 | at the end). |
| 40 | \end{funcdesc} |
| 41 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 42 | \begin{funcdesc}{MenuItem}{menu, title\optional{, shortcut, callback}} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 43 | Create a menu item object. The arguments are the menu to crate the |
| 44 | item it, the item title string and optionally the keyboard shortcut |
| 45 | and a callback routine. The callback is called with the arguments |
| 46 | menu-id, item number within menu (1-based), current front window and |
| 47 | the event record. |
| 48 | |
| 49 | In stead of a callable object the callback can also be a string. In |
| 50 | this case menu selection causes the lookup of a method in the topmost |
| 51 | window and the application. The method name is the callback string |
| 52 | with \code{'domenu_'} prepended. |
| 53 | |
| 54 | Calling the \code{MenuBar} \code{fixmenudimstate} method sets the |
| 55 | correct dimming for all menu items based on the current front window. |
| 56 | \end{funcdesc} |
| 57 | |
| 58 | \begin{funcdesc}{Separator}{menu} |
| 59 | Add a separator to the end of a menu. |
| 60 | \end{funcdesc} |
| 61 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 62 | \begin{funcdesc}{SubMenu}{menu, label} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 63 | Create a submenu named \var{label} under menu \var{menu}. The menu |
| 64 | object is returned. |
| 65 | \end{funcdesc} |
| 66 | |
| 67 | \begin{funcdesc}{Window}{parent} |
| 68 | Creates a (modeless) window. \var{Parent} is the application object to |
| 69 | which the window belongs. The window is not displayed until later. |
| 70 | \end{funcdesc} |
| 71 | |
| 72 | \begin{funcdesc}{DialogWindow}{parent} |
| 73 | Creates a modeless dialog window. |
| 74 | \end{funcdesc} |
| 75 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 76 | \begin{funcdesc}{windowbounds}{width, height} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 77 | Return a \code{(left, top, right, bottom)} tuple suitable for creation |
| 78 | of a window of given width and height. The window will be staggered |
| 79 | with respect to previous windows, and an attempt is made to keep the |
| 80 | whole window on-screen. The window will however always be exact the |
| 81 | size given, so parts may be offscreen. |
| 82 | \end{funcdesc} |
| 83 | |
| 84 | \begin{funcdesc}{setwatchcursor}{} |
| 85 | Set the mouse cursor to a watch. |
| 86 | \end{funcdesc} |
| 87 | |
| 88 | \begin{funcdesc}{setarrowcursor}{} |
| 89 | Set the mouse cursor to an arrow. |
| 90 | \end{funcdesc} |
| 91 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 92 | \subsection{Application Objects} |
| 93 | \label{application-objects} |
| 94 | |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 95 | Application objects have the following methods, among others: |
| 96 | |
| 97 | \setindexsubitem{(Application method)} |
| 98 | |
| 99 | \begin{funcdesc}{makeusermenus}{} |
| 100 | Override this method if you need menus in your application. Append the |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 101 | menus to the attribute \member{menubar}. |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 102 | \end{funcdesc} |
| 103 | |
| 104 | \begin{funcdesc}{getabouttext}{} |
| 105 | Override this method to return a text string describing your |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 106 | application. Alternatively, override the \method{do_about()} method |
| 107 | for more elaborate ``about'' messages. |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 108 | \end{funcdesc} |
| 109 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 110 | \begin{funcdesc}{mainloop}{\optional{mask\optional{, wait}}} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 111 | This routine is the main event loop, call it to set your application |
| 112 | rolling. \var{Mask} is the mask of events you want to handle, |
| 113 | \var{wait} is the number of ticks you want to leave to other |
| 114 | concurrent application (default 0, which is probably not a good |
| 115 | idea). While raising \code{self} to exit the mainloop is still |
| 116 | supported it is not recommended, call \code{self._quit} instead. |
| 117 | |
| 118 | The event loop is split into many small parts, each of which can be |
| 119 | overridden. The default methods take care of dispatching events to |
| 120 | windows and dialogs, handling drags and resizes, Apple Events, events |
| 121 | for non-FrameWork windows, etc. |
| 122 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 123 | In general, all event handlers should return \code{1} if the event is fully |
| 124 | handled and \code{0} otherwise (because the front window was not a FrameWork |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 125 | window, for instance). This is needed so that update events and such |
| 126 | can be passed on to other windows like the Sioux console window. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 127 | Calling \function{MacOS.HandleEvent()} is not allowed within |
| 128 | \var{our_dispatch} or its callees, since this may result in an |
| 129 | infinite loop if the code is called through the Python inner-loop |
| 130 | event handler. |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 131 | \end{funcdesc} |
| 132 | |
| 133 | \begin{funcdesc}{asyncevents}{onoff} |
| 134 | Call this method with a nonzero parameter to enable |
| 135 | asynchronous event handling. This will tell the inner interpreter loop |
| 136 | to call the application event handler \var{async_dispatch} whenever events |
| 137 | are available. This will cause FrameWork window updates and the user |
| 138 | interface to remain working during long computations, but will slow the |
| 139 | interpreter down and may cause surprising results in non-reentrant code |
| 140 | (such as FrameWork itself). By default \var{async_dispatch} will immedeately |
| 141 | call \var{our_dispatch} but you may override this to handle only certain |
| 142 | events asynchronously. Events you do not handle will be passed to Sioux |
| 143 | and such. |
| 144 | |
| 145 | The old on/off value is returned. |
| 146 | \end{funcdesc} |
| 147 | |
| 148 | \begin{funcdesc}{_quit}{} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 149 | Terminate the running \method{mainloop()} call at the next convenient |
| 150 | moment. |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 151 | \end{funcdesc} |
| 152 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 153 | \begin{funcdesc}{do_char}{c, event} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 154 | The user typed character \var{c}. The complete details of the event |
| 155 | can be found in the \var{event} structure. This method can also be |
| 156 | provided in a \code{Window} object, which overrides the |
| 157 | application-wide handler if the window is frontmost. |
| 158 | \end{funcdesc} |
| 159 | |
| 160 | \begin{funcdesc}{do_dialogevent}{event} |
| 161 | Called early in the event loop to handle modeless dialog events. The |
| 162 | default method simply dispatches the event to the relevant dialog (not |
| 163 | through the the \code{DialogWindow} object involved). Override if you |
| 164 | need special handling of dialog events (keyboard shortcuts, etc). |
| 165 | \end{funcdesc} |
| 166 | |
| 167 | \begin{funcdesc}{idle}{event} |
| 168 | Called by the main event loop when no events are available. The |
| 169 | null-event is passed (so you can look at mouse position, etc). |
| 170 | \end{funcdesc} |
| 171 | |
| 172 | \subsection{Window Objects} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 173 | \label{window-objects} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 174 | |
| 175 | Window objects have the following methods, among others: |
| 176 | |
| 177 | \setindexsubitem{(Window method)} |
| 178 | |
| 179 | \begin{funcdesc}{open}{} |
| 180 | Override this method to open a window. Store the MacOS window-id in |
| 181 | \code{self.wid} and call \code{self.do_postopen} to register the |
| 182 | window with the parent application. |
| 183 | \end{funcdesc} |
| 184 | |
| 185 | \begin{funcdesc}{close}{} |
| 186 | Override this method to do any special processing on window |
| 187 | close. Call \code{self.do_postclose} to cleanup the parent state. |
| 188 | \end{funcdesc} |
| 189 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 190 | \begin{funcdesc}{do_postresize}{width, height, macoswindowid} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 191 | Called after the window is resized. Override if more needs to be done |
| 192 | than calling \code{InvalRect}. |
| 193 | \end{funcdesc} |
| 194 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 195 | \begin{funcdesc}{do_contentclick}{local, modifiers, event} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 196 | The user clicked in the content part of a window. The arguments are |
| 197 | the coordinates (window-relative), the key modifiers and the raw |
| 198 | event. |
| 199 | \end{funcdesc} |
| 200 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 201 | \begin{funcdesc}{do_update}{macoswindowid, event} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 202 | An update event for the window was received. Redraw the window. |
| 203 | \end{funcdesc} |
| 204 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 205 | \begin{funcdesc}{do_activate}{activate, event} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 206 | The window was activated (\code{activate==1}) or deactivated |
| 207 | (\code{activate==0}). Handle things like focus highlighting, etc. |
| 208 | \end{funcdesc} |
| 209 | |
| 210 | \subsection{ControlsWindow Object} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 211 | \label{controlswindow-object} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 212 | |
| 213 | ControlsWindow objects have the following methods besides those of |
| 214 | \code{Window} objects: |
| 215 | |
| 216 | \setindexsubitem{(ControlsWindow method)} |
| 217 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 218 | \begin{funcdesc}{do_controlhit}{window, control, pcode, event} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 219 | Part \code{pcode} of control \code{control} was hit by the |
| 220 | user. Tracking and such has already been taken care of. |
| 221 | \end{funcdesc} |
| 222 | |
| 223 | \subsection{ScrolledWindow Object} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 224 | \label{scrolledwindow-object} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 225 | |
| 226 | ScrolledWindow objects are ControlsWindow objects with the following |
| 227 | extra methods: |
| 228 | |
| 229 | \setindexsubitem{(ScrolledWindow method)} |
| 230 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 231 | \begin{funcdesc}{scrollbars}{\optional{wantx\optional{, wanty}}} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 232 | Create (or destroy) horizontal and vertical scrollbars. The arguments |
| 233 | specify which you want (default: both). The scrollbars always have |
| 234 | minimum \code{0} and maximum \code{32767}. |
| 235 | \end{funcdesc} |
| 236 | |
| 237 | \begin{funcdesc}{getscrollbarvalues}{} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 238 | You must supply this method. It should return a tuple \code{(\var{x}, |
| 239 | \var{y})} giving the current position of the scrollbars (between |
| 240 | \code{0} and \code{32767}). You can return \code{None} for either to |
| 241 | indicate the whole document is visible in that direction. |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 242 | \end{funcdesc} |
| 243 | |
| 244 | \begin{funcdesc}{updatescrollbars}{} |
| 245 | Call this method when the document has changed. It will call |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 246 | \method{getscrollbarvalues()} and update the scrollbars. |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 247 | \end{funcdesc} |
| 248 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 249 | \begin{funcdesc}{scrollbar_callback}{which, what, value} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 250 | Supplied by you and called after user interaction. \var{which} will |
| 251 | be \code{'x'} or \code{'y'}, \var{what} will be \code{'-'}, |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 252 | \code{'--'}, \code{'set'}, \code{'++'} or \code{'+'}. For |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 253 | \code{'set'}, \var{value} will contain the new scrollbar position. |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 254 | \end{funcdesc} |
| 255 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 256 | \begin{funcdesc}{scalebarvalues}{absmin, absmax, curmin, curmax} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 257 | Auxiliary method to help you calculate values to return from |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 258 | \method{getscrollbarvalues()}. You pass document minimum and maximum value |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 259 | and topmost (leftmost) and bottommost (rightmost) visible values and |
| 260 | it returns the correct number or \code{None}. |
| 261 | \end{funcdesc} |
| 262 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 263 | \begin{funcdesc}{do_activate}{onoff, event} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 264 | Takes care of dimming/highlighting scrollbars when a window becomes |
| 265 | frontmost vv. If you override this method call this one at the end of |
| 266 | your method. |
| 267 | \end{funcdesc} |
| 268 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 269 | \begin{funcdesc}{do_postresize}{width, height, window} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 270 | Moves scrollbars to the correct position. Call this method initially |
| 271 | if you override it. |
| 272 | \end{funcdesc} |
| 273 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 274 | \begin{funcdesc}{do_controlhit}{window, control, pcode, event} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 275 | Handles scrollbar interaction. If you override it call this method |
| 276 | first, a nonzero return value indicates the hit was in the scrollbars |
| 277 | and has been handled. |
| 278 | \end{funcdesc} |
| 279 | |
| 280 | \subsection{DialogWindow Objects} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 281 | \label{dialogwindow-objects} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 282 | |
| 283 | DialogWindow objects have the following methods besides those of |
| 284 | \code{Window} objects: |
| 285 | |
| 286 | \setindexsubitem{(DialogWindow method)} |
| 287 | |
| 288 | \begin{funcdesc}{open}{resid} |
| 289 | Create the dialog window, from the DLOG resource with id |
| 290 | \var{resid}. The dialog object is stored in \code{self.wid}. |
| 291 | \end{funcdesc} |
| 292 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 293 | \begin{funcdesc}{do_itemhit}{item, event} |
Fred Drake | b4efb6c | 1998-02-18 17:19:11 +0000 | [diff] [blame] | 294 | Item number \var{item} was hit. You are responsible for redrawing |
| 295 | toggle buttons, etc. |
| 296 | \end{funcdesc} |