cinap_lenrekadd hg and python4bb9e2215 years agoHistory
314 lines · 12.1 KB · TeX
RawDownload
\section{\module{FrameWork} ---         Interactive application framework} \declaremodule{standard}{FrameWork}  \platform{Mac}\modulesynopsis{Interactive application framework.}  The \module{FrameWork} module contains classes that together provide aframework for an interactive Macintosh application. The programmerbuilds an application by creating subclasses that override variousmethods of the bases classes, thereby implementing the functionalitywanted. Overriding functionality can often be done on variousdifferent levels, i.e. to handle clicks in a single dialog window in anon-standard way it is not necessary to override the complete eventhandling. Work on the \module{FrameWork} has pretty much stopped, now that\module{PyObjC} is available for full Cocoa access from Python, and thedocumentation describes only the most important functionality, and notin the most logical manner at that. Examine the source or the examplesfor more details.  The following are some comments posted on theMacPython newsgroup about the strengths and limitations of\module{FrameWork}: \begin{quotation}The strong point of \module{FrameWork} is that it allows you to breakinto the control-flow at many different places. \refmodule{W}, forinstance, uses a different way to enable/disable menus and that plugsright in leaving the rest intact.  The weak points of\module{FrameWork} are that it has no abstract command interface (butthat shouldn't be difficult), that its dialog support is minimal andthat its control/toolbar support is non-existent.\end{quotation}  The \module{FrameWork} module defines the following functions:  \begin{funcdesc}{Application}{}An object representing the complete application. See below for adescription of the methods. The default \method{__init__()} routinecreates an empty window dictionary and a menu bar with an apple menu.\end{funcdesc} \begin{funcdesc}{MenuBar}{}An object representing the menubar. This object is usually not createdby the user.\end{funcdesc} \begin{funcdesc}{Menu}{bar, title\optional{, after}}An object representing a menu. Upon creation you pass the\code{MenuBar} the menu appears in, the \var{title} string and aposition (1-based) \var{after} where the menu should appear (default:at the end).\end{funcdesc} \begin{funcdesc}{MenuItem}{menu, title\optional{, shortcut, callback}}Create a menu item object. The arguments are the menu to create, theitem title string and optionally the keyboard shortcutand a callback routine. The callback is called with the argumentsmenu-id, item number within menu (1-based), current front window andthe event record. Instead of a callable object the callback can also be a string. Inthis case menu selection causes the lookup of a method in the topmostwindow and the application. The method name is the callback stringwith \code{'domenu_'} prepended. Calling the \code{MenuBar} \method{fixmenudimstate()} method sets thecorrect dimming for all menu items based on the current front window.\end{funcdesc} \begin{funcdesc}{Separator}{menu}Add a separator to the end of a menu.\end{funcdesc} \begin{funcdesc}{SubMenu}{menu, label}Create a submenu named \var{label} under menu \var{menu}. The menuobject is returned.\end{funcdesc} \begin{funcdesc}{Window}{parent}Creates a (modeless) window. \var{Parent} is the application object towhich the window belongs. The window is not displayed until later.\end{funcdesc} \begin{funcdesc}{DialogWindow}{parent}Creates a modeless dialog window.\end{funcdesc} \begin{funcdesc}{windowbounds}{width, height}Return a \code{(\var{left}, \var{top}, \var{right}, \var{bottom})}tuple suitable for creation of a window of given width and height. Thewindow will be staggered with respect to previous windows, and anattempt is made to keep the whole window on-screen. However, the window willhowever always be the exact size given, so parts may be offscreen.\end{funcdesc} \begin{funcdesc}{setwatchcursor}{}Set the mouse cursor to a watch.\end{funcdesc} \begin{funcdesc}{setarrowcursor}{}Set the mouse cursor to an arrow.\end{funcdesc}  \subsection{Application Objects \label{application-objects}} Application objects have the following methods, among others:  \begin{methoddesc}[Application]{makeusermenus}{}Override this method if you need menus in your application. Append themenus to the attribute \member{menubar}.\end{methoddesc} \begin{methoddesc}[Application]{getabouttext}{}Override this method to return a text string describing yourapplication.  Alternatively, override the \method{do_about()} methodfor more elaborate ``about'' messages.\end{methoddesc} \begin{methoddesc}[Application]{mainloop}{\optional{mask\optional{, wait}}}This routine is the main event loop, call it to set your applicationrolling. \var{Mask} is the mask of events you want to handle,\var{wait} is the number of ticks you want to leave to otherconcurrent application (default 0, which is probably not a goodidea). While raising \var{self} to exit the mainloop is stillsupported it is not recommended: call \code{self._quit()} instead. The event loop is split into many small parts, each of which can beoverridden. The default methods take care of dispatching events towindows and dialogs, handling drags and resizes, Apple Events, eventsfor non-FrameWork windows, etc. In general, all event handlers should return \code{1} if the event is fullyhandled and \code{0} otherwise (because the front window was not a FrameWorkwindow, for instance). This is needed so that update events and suchcan be passed on to other windows like the Sioux console window.Calling \function{MacOS.HandleEvent()} is not allowed within\var{our_dispatch} or its callees, since this may result in aninfinite loop if the code is called through the Python inner-loopevent handler.\end{methoddesc} \begin{methoddesc}[Application]{asyncevents}{onoff}Call this method with a nonzero parameter to enableasynchronous event handling. This will tell the inner interpreter loopto call the application event handler \var{async_dispatch} whenever eventsare available. This will cause FrameWork window updates and the userinterface to remain working during long computations, but will slow theinterpreter down and may cause surprising results in non-reentrant code(such as FrameWork itself). By default \var{async_dispatch} will immediatelycall \var{our_dispatch} but you may override this to handle only certainevents asynchronously. Events you do not handle will be passed to Siouxand such. The old on/off value is returned.\end{methoddesc} \begin{methoddesc}[Application]{_quit}{}Terminate the running \method{mainloop()} call at the next convenientmoment.\end{methoddesc} \begin{methoddesc}[Application]{do_char}{c, event}The user typed character \var{c}. The complete details of the eventcan be found in the \var{event} structure. This method can also beprovided in a \code{Window} object, which overrides theapplication-wide handler if the window is frontmost.\end{methoddesc} \begin{methoddesc}[Application]{do_dialogevent}{event}Called early in the event loop to handle modeless dialog events. Thedefault method simply dispatches the event to the relevant dialog (notthrough the \code{DialogWindow} object involved). Override if youneed special handling of dialog events (keyboard shortcuts, etc).\end{methoddesc} \begin{methoddesc}[Application]{idle}{event}Called by the main event loop when no events are available. Thenull-event is passed (so you can look at mouse position, etc).\end{methoddesc}  \subsection{Window Objects \label{window-objects}} Window objects have the following methods, among others: \setindexsubitem{(Window method)} \begin{methoddesc}[Window]{open}{}Override this method to open a window. Store the MacOS window-id in\member{self.wid} and call the \method{do_postopen()} method toregister the window with the parent application.\end{methoddesc} \begin{methoddesc}[Window]{close}{}Override this method to do any special processing on windowclose. Call the \method{do_postclose()} method to cleanup the parentstate.\end{methoddesc} \begin{methoddesc}[Window]{do_postresize}{width, height, macoswindowid}Called after the window is resized. Override if more needs to be donethan calling \code{InvalRect}.\end{methoddesc} \begin{methoddesc}[Window]{do_contentclick}{local, modifiers, event}The user clicked in the content part of a window. The arguments arethe coordinates (window-relative), the key modifiers and the rawevent.\end{methoddesc} \begin{methoddesc}[Window]{do_update}{macoswindowid, event}An update event for the window was received. Redraw the window.\end{methoddesc} \begin{methoddesc}{do_activate}{activate, event}The window was activated (\code{\var{activate} == 1}) or deactivated(\code{\var{activate} == 0}). Handle things like focus highlighting,etc.\end{methoddesc}  \subsection{ControlsWindow Object \label{controlswindow-object}} ControlsWindow objects have the following methods besides those of\code{Window} objects:  \begin{methoddesc}[ControlsWindow]{do_controlhit}{window, control,                                                  pcode, event}Part \var{pcode} of control \var{control} was hit by theuser. Tracking and such has already been taken care of.\end{methoddesc}  \subsection{ScrolledWindow Object \label{scrolledwindow-object}} ScrolledWindow objects are ControlsWindow objects with the followingextra methods:  \begin{methoddesc}[ScrolledWindow]{scrollbars}{\optional{wantx\optional{,                                               wanty}}}Create (or destroy) horizontal and vertical scrollbars. The argumentsspecify which you want (default: both). The scrollbars always haveminimum \code{0} and maximum \code{32767}.\end{methoddesc} \begin{methoddesc}[ScrolledWindow]{getscrollbarvalues}{}You must supply this method. It should return a tuple \code{(\var{x},\var{y})} giving the current position of the scrollbars (between\code{0} and \code{32767}). You can return \code{None} for either toindicate the whole document is visible in that direction.\end{methoddesc} \begin{methoddesc}[ScrolledWindow]{updatescrollbars}{}Call this method when the document has changed. It will call\method{getscrollbarvalues()} and update the scrollbars.\end{methoddesc} \begin{methoddesc}[ScrolledWindow]{scrollbar_callback}{which, what, value}Supplied by you and called after user interaction. \var{which} willbe \code{'x'} or \code{'y'}, \var{what} will be \code{'-'},\code{'--'}, \code{'set'}, \code{'++'} or \code{'+'}. For\code{'set'}, \var{value} will contain the new scrollbar position.\end{methoddesc} \begin{methoddesc}[ScrolledWindow]{scalebarvalues}{absmin, absmax,                                                   curmin, curmax}Auxiliary method to help you calculate values to return from\method{getscrollbarvalues()}. You pass document minimum and maximum valueand topmost (leftmost) and bottommost (rightmost) visible values andit returns the correct number or \code{None}.\end{methoddesc} \begin{methoddesc}[ScrolledWindow]{do_activate}{onoff, event}Takes care of dimming/highlighting scrollbars when a window becomesfrontmost. If you override this method, call this one at the end ofyour method.\end{methoddesc} \begin{methoddesc}[ScrolledWindow]{do_postresize}{width, height, window}Moves scrollbars to the correct position. Call this method initiallyif you override it.\end{methoddesc} \begin{methoddesc}[ScrolledWindow]{do_controlhit}{window, control,                                                  pcode, event}Handles scrollbar interaction. If you override it call this methodfirst, a nonzero return value indicates the hit was in the scrollbarsand has been handled.\end{methoddesc}  \subsection{DialogWindow Objects \label{dialogwindow-objects}} DialogWindow objects have the following methods besides those of\code{Window} objects:  \begin{methoddesc}[DialogWindow]{open}{resid}Create the dialog window, from the DLOG resource with id\var{resid}. The dialog object is stored in \member{self.wid}.\end{methoddesc} \begin{methoddesc}[DialogWindow]{do_itemhit}{item, event}Item number \var{item} was hit. You are responsible for redrawingtoggle buttons, etc.\end{methoddesc}