| 1 | \section{\module{FrameWork} ---
|
|---|
| 2 | Interactive application framework}
|
|---|
| 3 |
|
|---|
| 4 | \declaremodule{standard}{FrameWork}
|
|---|
| 5 | \platform{Mac}
|
|---|
| 6 | \modulesynopsis{Interactive application framework.}
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | The \module{FrameWork} module contains classes that together provide a
|
|---|
| 10 | framework for an interactive Macintosh application. The programmer
|
|---|
| 11 | builds an application by creating subclasses that override various
|
|---|
| 12 | methods of the bases classes, thereby implementing the functionality
|
|---|
| 13 | wanted. Overriding functionality can often be done on various
|
|---|
| 14 | different levels, i.e. to handle clicks in a single dialog window in a
|
|---|
| 15 | non-standard way it is not necessary to override the complete event
|
|---|
| 16 | handling.
|
|---|
| 17 |
|
|---|
| 18 | Work on the \module{FrameWork} has pretty much stopped, now that
|
|---|
| 19 | \module{PyObjC} is available for full Cocoa access from Python, and the
|
|---|
| 20 | documentation describes only the most important functionality, and not
|
|---|
| 21 | in the most logical manner at that. Examine the source or the examples
|
|---|
| 22 | for more details. The following are some comments posted on the
|
|---|
| 23 | MacPython newsgroup about the strengths and limitations of
|
|---|
| 24 | \module{FrameWork}:
|
|---|
| 25 |
|
|---|
| 26 | \begin{quotation}
|
|---|
| 27 | The strong point of \module{FrameWork} is that it allows you to break
|
|---|
| 28 | into the control-flow at many different places. \refmodule{W}, for
|
|---|
| 29 | instance, uses a different way to enable/disable menus and that plugs
|
|---|
| 30 | right in leaving the rest intact. The weak points of
|
|---|
| 31 | \module{FrameWork} are that it has no abstract command interface (but
|
|---|
| 32 | that shouldn't be difficult), that its dialog support is minimal and
|
|---|
| 33 | that its control/toolbar support is non-existent.
|
|---|
| 34 | \end{quotation}
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | The \module{FrameWork} module defines the following functions:
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | \begin{funcdesc}{Application}{}
|
|---|
| 41 | An object representing the complete application. See below for a
|
|---|
| 42 | description of the methods. The default \method{__init__()} routine
|
|---|
| 43 | creates an empty window dictionary and a menu bar with an apple menu.
|
|---|
| 44 | \end{funcdesc}
|
|---|
| 45 |
|
|---|
| 46 | \begin{funcdesc}{MenuBar}{}
|
|---|
| 47 | An object representing the menubar. This object is usually not created
|
|---|
| 48 | by the user.
|
|---|
| 49 | \end{funcdesc}
|
|---|
| 50 |
|
|---|
| 51 | \begin{funcdesc}{Menu}{bar, title\optional{, after}}
|
|---|
| 52 | An object representing a menu. Upon creation you pass the
|
|---|
| 53 | \code{MenuBar} the menu appears in, the \var{title} string and a
|
|---|
| 54 | position (1-based) \var{after} where the menu should appear (default:
|
|---|
| 55 | at the end).
|
|---|
| 56 | \end{funcdesc}
|
|---|
| 57 |
|
|---|
| 58 | \begin{funcdesc}{MenuItem}{menu, title\optional{, shortcut, callback}}
|
|---|
| 59 | Create a menu item object. The arguments are the menu to create, the
|
|---|
| 60 | item title string and optionally the keyboard shortcut
|
|---|
| 61 | and a callback routine. The callback is called with the arguments
|
|---|
| 62 | menu-id, item number within menu (1-based), current front window and
|
|---|
| 63 | the event record.
|
|---|
| 64 |
|
|---|
| 65 | Instead of a callable object the callback can also be a string. In
|
|---|
| 66 | this case menu selection causes the lookup of a method in the topmost
|
|---|
| 67 | window and the application. The method name is the callback string
|
|---|
| 68 | with \code{'domenu_'} prepended.
|
|---|
| 69 |
|
|---|
| 70 | Calling the \code{MenuBar} \method{fixmenudimstate()} method sets the
|
|---|
| 71 | correct dimming for all menu items based on the current front window.
|
|---|
| 72 | \end{funcdesc}
|
|---|
| 73 |
|
|---|
| 74 | \begin{funcdesc}{Separator}{menu}
|
|---|
| 75 | Add a separator to the end of a menu.
|
|---|
| 76 | \end{funcdesc}
|
|---|
| 77 |
|
|---|
| 78 | \begin{funcdesc}{SubMenu}{menu, label}
|
|---|
| 79 | Create a submenu named \var{label} under menu \var{menu}. The menu
|
|---|
| 80 | object is returned.
|
|---|
| 81 | \end{funcdesc}
|
|---|
| 82 |
|
|---|
| 83 | \begin{funcdesc}{Window}{parent}
|
|---|
| 84 | Creates a (modeless) window. \var{Parent} is the application object to
|
|---|
| 85 | which the window belongs. The window is not displayed until later.
|
|---|
| 86 | \end{funcdesc}
|
|---|
| 87 |
|
|---|
| 88 | \begin{funcdesc}{DialogWindow}{parent}
|
|---|
| 89 | Creates a modeless dialog window.
|
|---|
| 90 | \end{funcdesc}
|
|---|
| 91 |
|
|---|
| 92 | \begin{funcdesc}{windowbounds}{width, height}
|
|---|
| 93 | Return a \code{(\var{left}, \var{top}, \var{right}, \var{bottom})}
|
|---|
| 94 | tuple suitable for creation of a window of given width and height. The
|
|---|
| 95 | window will be staggered with respect to previous windows, and an
|
|---|
| 96 | attempt is made to keep the whole window on-screen. However, the window will
|
|---|
| 97 | however always be the exact size given, so parts may be offscreen.
|
|---|
| 98 | \end{funcdesc}
|
|---|
| 99 |
|
|---|
| 100 | \begin{funcdesc}{setwatchcursor}{}
|
|---|
| 101 | Set the mouse cursor to a watch.
|
|---|
| 102 | \end{funcdesc}
|
|---|
| 103 |
|
|---|
| 104 | \begin{funcdesc}{setarrowcursor}{}
|
|---|
| 105 | Set the mouse cursor to an arrow.
|
|---|
| 106 | \end{funcdesc}
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | \subsection{Application Objects \label{application-objects}}
|
|---|
| 110 |
|
|---|
| 111 | Application objects have the following methods, among others:
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 | \begin{methoddesc}[Application]{makeusermenus}{}
|
|---|
| 115 | Override this method if you need menus in your application. Append the
|
|---|
| 116 | menus to the attribute \member{menubar}.
|
|---|
| 117 | \end{methoddesc}
|
|---|
| 118 |
|
|---|
| 119 | \begin{methoddesc}[Application]{getabouttext}{}
|
|---|
| 120 | Override this method to return a text string describing your
|
|---|
| 121 | application. Alternatively, override the \method{do_about()} method
|
|---|
| 122 | for more elaborate ``about'' messages.
|
|---|
| 123 | \end{methoddesc}
|
|---|
| 124 |
|
|---|
| 125 | \begin{methoddesc}[Application]{mainloop}{\optional{mask\optional{, wait}}}
|
|---|
| 126 | This routine is the main event loop, call it to set your application
|
|---|
| 127 | rolling. \var{Mask} is the mask of events you want to handle,
|
|---|
| 128 | \var{wait} is the number of ticks you want to leave to other
|
|---|
| 129 | concurrent application (default 0, which is probably not a good
|
|---|
| 130 | idea). While raising \var{self} to exit the mainloop is still
|
|---|
| 131 | supported it is not recommended: call \code{self._quit()} instead.
|
|---|
| 132 |
|
|---|
| 133 | The event loop is split into many small parts, each of which can be
|
|---|
| 134 | overridden. The default methods take care of dispatching events to
|
|---|
| 135 | windows and dialogs, handling drags and resizes, Apple Events, events
|
|---|
| 136 | for non-FrameWork windows, etc.
|
|---|
| 137 |
|
|---|
| 138 | In general, all event handlers should return \code{1} if the event is fully
|
|---|
| 139 | handled and \code{0} otherwise (because the front window was not a FrameWork
|
|---|
| 140 | window, for instance). This is needed so that update events and such
|
|---|
| 141 | can be passed on to other windows like the Sioux console window.
|
|---|
| 142 | Calling \function{MacOS.HandleEvent()} is not allowed within
|
|---|
| 143 | \var{our_dispatch} or its callees, since this may result in an
|
|---|
| 144 | infinite loop if the code is called through the Python inner-loop
|
|---|
| 145 | event handler.
|
|---|
| 146 | \end{methoddesc}
|
|---|
| 147 |
|
|---|
| 148 | \begin{methoddesc}[Application]{asyncevents}{onoff}
|
|---|
| 149 | Call this method with a nonzero parameter to enable
|
|---|
|
|---|