cinap_lenrekadd hg and python4bb9e2215 years agoHistory
832 lines · 27.4 KB · TeX
RawDownload
\chapter{Standard Windowing Interface} The modules in this chapter are available only on those systems wherethe STDWIN library is available.  STDWIN runs on \UNIX{} under X11 andon the Macintosh.  See CWI report CS-R8817. \warning{Using STDWIN is not recommended for newapplications.  It has never been ported to Microsoft Windows orWindows NT, and for X11 or the Macintosh it lacks importantfunctionality --- in particular, it has no tools for the constructionof dialogs.  For most platforms, alternative, native solutions exist(though none are currently documented in this manual): Tkinter for\UNIX{} under X11, native Xt with Motif or Athena widgets for \UNIX{}under X11, Win32 for Windows and Windows NT, and a collection ofnative toolkit interfaces for the Macintosh.}  \section{\module{stdwin} ---         Platform-independent Graphical User Interface System} \declaremodule{builtin}{stdwin}\modulesynopsis{Older graphical user interface system for X11 and Macintosh.}  This module defines several new object types and functions thatprovide access to the functionality of STDWIN. On \UNIX{} running X11, it can only be used if the \envvar{DISPLAY}environment variable is set or an explicit\programopt{-display} \var{displayname} argument is passed to thePython interpreter. Functions have names that usually resemble their C STDWIN counterpartswith the initial `w' dropped.  Points are represented by pairs ofintegers; rectangles by pairs of points.  For a complete descriptionof STDWIN please refer to the documentation of STDWIN for Cprogrammers (aforementioned CWI report). \subsection{Functions Defined in Module \module{stdwin}}\nodename{STDWIN Functions} The following functions are defined in the \module{stdwin} module: \begin{funcdesc}{open}{title}Open a new window whose initial title is given by the string argument.Return a window object; window object methods are describedbelow.\footnote{	The Python version of STDWIN does not support draw procedures;	all drawing requests are reported as draw events.}\end{funcdesc} \begin{funcdesc}{getevent}{}Wait for and return the next event.An event is returned as a triple: the first element is the eventtype, a small integer; the second element is the window object to whichthe event applies, or\code{None}if it applies to no window in particular;the third element is type-dependent.Names for event types and command codes are defined in the standardmodule \refmodule{stdwinevents}.\end{funcdesc} \begin{funcdesc}{pollevent}{}Return the next event, if one is immediately available.If no event is available, return \code{()}.\end{funcdesc} \begin{funcdesc}{getactive}{}Return the window that is currently active, or \code{None} if nowindow is currently active.  (This can be emulated by monitoringWE_ACTIVATE and WE_DEACTIVATE events.)\end{funcdesc} \begin{funcdesc}{listfontnames}{pattern}Return the list of font names in the system that match the pattern (astring).  The pattern should normally be \code{'*'}; returns allavailable fonts.  If the underlying window system is X11, otherpatterns follow the standard X11 font selection syntax (as used e.g.in resource definitions), i.e. the wildcard character \code{'*'}matches any sequence of characters (including none) and \code{'?'}matches any single character.On the Macintosh this function currently returns an empty list.\end{funcdesc} \begin{funcdesc}{setdefscrollbars}{hflag, vflag}Set the flags controlling whether subsequently opened windows willhave horizontal and/or vertical scroll bars.\end{funcdesc} \begin{funcdesc}{setdefwinpos}{h, v}Set the default window position for windows opened subsequently.\end{funcdesc} \begin{funcdesc}{setdefwinsize}{width, height}Set the default window size for windows opened subsequently.\end{funcdesc} \begin{funcdesc}{getdefscrollbars}{}Return the flags controlling whether subsequently opened windows willhave horizontal and/or vertical scroll bars.\end{funcdesc} \begin{funcdesc}{getdefwinpos}{}Return the default window position for windows opened subsequently.\end{funcdesc} \begin{funcdesc}{getdefwinsize}{}Return the default window size for windows opened subsequently.\end{funcdesc} \begin{funcdesc}{getscrsize}{}Return the screen size in pixels.\end{funcdesc} \begin{funcdesc}{getscrmm}{}Return the screen size in millimetres.\end{funcdesc} \begin{funcdesc}{fetchcolor}{colorname}Return the pixel value corresponding to the given color name.Return the default foreground color for unknown color names.Hint: the following code tests whether you are on a machine thatsupports more than two colors:\begin{verbatim}if stdwin.fetchcolor('black') <> \          stdwin.fetchcolor('red') <> \          stdwin.fetchcolor('white'):    print 'color machine'else:    print 'monochrome machine'\end{verbatim}\end{funcdesc} \begin{funcdesc}{setfgcolor}{pixel}Set the default foreground color.This will become the default foreground color of windows openedsubsequently, including dialogs.\end{funcdesc} \begin{funcdesc}{setbgcolor}{pixel}Set the default background color.This will become the default background color of windows openedsubsequently, including dialogs.\end{funcdesc} \begin{funcdesc}{getfgcolor}{}Return the pixel value of the current default foreground color.\end{funcdesc} \begin{funcdesc}{getbgcolor}{}Return the pixel value of the current default background color.\end{funcdesc} \begin{funcdesc}{setfont}{fontname}Set the current default font.This will become the default font for windows opened subsequently,and is also used by the text measuring functions \function{textwidth()},\function{textbreak()}, \function{lineheight()} and\function{baseline()} below.  This accepts two more optionalparameters, size and style:  Size is the font size (in `points').Style is a single character specifying the style, as follows:\code{'b'} = bold,\code{'i'} = italic,\code{'o'} = bold + italic,\code{'u'} = underline;default style is roman.Size and style are ignored under X11 but used on the Macintosh.(Sorry for all this complexity --- a more uniform interface is being designed.)\end{funcdesc} \begin{funcdesc}{menucreate}{title}Create a menu object referring to a global menu (a menu that appears inall windows).Methods of menu objects are described below.Note: normally, menus are created locally; see the window method\method{menucreate()} below.\warning{The menu only appears in a window as long as the objectreturned by this call exists.}\end{funcdesc} \begin{funcdesc}{newbitmap}{width, height}Create a new bitmap object of the given dimensions.Methods of bitmap objects are described below.Not available on the Macintosh.\end{funcdesc} \begin{funcdesc}{fleep}{}Cause a beep or bell (or perhaps a `visual bell' or flash, hence thename).\end{funcdesc} \begin{funcdesc}{message}{string}Display a dialog box containing the string.The user must click OK before the function returns.\end{funcdesc} \begin{funcdesc}{askync}{prompt, default}Display a dialog that prompts the user to answer a question with yes orno.  Return 0 for no, 1 for yes.  If the user hits the Return key, thedefault (which must be 0 or 1) is returned.  If the user cancels thedialog, \exception{KeyboardInterrupt} is raised.\end{funcdesc} \begin{funcdesc}{askstr}{prompt, default}Display a dialog that prompts the user for a string.If the user hits the Return key, the default string is returned.If the user cancels the dialog, \exception{KeyboardInterrupt} israised.\end{funcdesc} \begin{funcdesc}{askfile}{prompt, default, new}Ask the user to specify a filename.  If \var{new} is zero it must bean existing file; otherwise, it must be a new file.  If the usercancels the dialog, \exception{KeyboardInterrupt} is raised.\end{funcdesc} \begin{funcdesc}{setcutbuffer}{i, string}Store the string in the system's cut buffer number \var{i}, where itcan be found (for pasting) by other applications.  On X11, there are 8cut buffers (numbered 0..7).  Cut buffer number 0 is the `clipboard'on the Macintosh.\end{funcdesc} \begin{funcdesc}{getcutbuffer}{i}Return the contents of the system's cut buffer number \var{i}.\end{funcdesc} \begin{funcdesc}{rotatecutbuffers}{n}On X11, rotate the 8 cut buffers by \var{n}.  Ignored on theMacintosh.\end{funcdesc} \begin{funcdesc}{getselection}{i}Return X11 selection number \var{i.}  Selections are not cut buffers.Selection numbers are defined in module \refmodule{stdwinevents}.Selection \constant{WS_PRIMARY} is the \dfn{primary} selection (usedby \program{xterm}, for instance); selection \constant{WS_SECONDARY}is the \dfn{secondary} selection; selection \constant{WS_CLIPBOARD} isthe \dfn{clipboard} selection (used by \program{xclipboard}).  On theMacintosh, this always returns an empty string.\end{funcdesc} \begin{funcdesc}{resetselection}{i}Reset selection number \var{i}, if this process owns it.  (See windowmethod \method{setselection()}).\end{funcdesc} \begin{funcdesc}{baseline}{}Return the baseline of the current font (defined by STDWIN as thevertical distance between the baseline and the top of thecharacters).\end{funcdesc} \begin{funcdesc}{lineheight}{}Return the total line height of the current font.\end{funcdesc} \begin{funcdesc}{textbreak}{str, width}Return the number of characters of the string that fit into a space of\var{width}bits wide when drawn in the current font.\end{funcdesc} \begin{funcdesc}{textwidth}{str}Return the width in bits of the string when drawn in the current font.\end{funcdesc} \begin{funcdesc}{connectionnumber}{}\funcline{fileno}{}(X11 under \UNIX{} only) Return the ``connection number'' used by theunderlying X11 implementation.  (This is normally the file number ofthe socket.)  Both functions return the same value;\method{connectionnumber()} is named after the corresponding function inX11 and STDWIN, while \method{fileno()} makes it possible to use the\module{stdwin} module as a ``file'' object parameter to\function{select.select()}.  Note that if \constant{select()} implies thatinput is possible on \module{stdwin}, this does not guarantee that anevent is ready --- it may be some internal communication going onbetween the X server and the client library.  Thus, you should call\function{stdwin.pollevent()} until it returns \code{None} to check forevents if you don't want your program to block.  Because of internalbuffering in X11, it is also possible that \function{stdwin.pollevent()}returns an event while \function{select()} does not find \module{stdwin} tobe ready, so you should read any pending events with\function{stdwin.pollevent()} until it returns \code{None} before enteringa blocking \function{select()} call.\withsubitem{(in module select)}{\ttindex{select()}}\end{funcdesc} \subsection{Window Objects}\nodename{STDWIN Window Objects} Window objects are created by \function{stdwin.open()}.  They are closedby their \method{close()} method or when they are garbage-collected.Window objects have the following methods: \begin{methoddesc}[window]{begindrawing}{}Return a drawing object, whose methods (described below) allow drawingin the window.\end{methoddesc} \begin{methoddesc}[window]{change}{rect}Invalidate the given rectangle; this may cause a draw event.\end{methoddesc} \begin{methoddesc}[window]{gettitle}{}Returns the window's title string.\end{methoddesc} \begin{methoddesc}[window]{getdocsize}{}\begin{sloppypar}Return a pair of integers giving the size of the document as set by\method{setdocsize()}.\end{sloppypar}\end{methoddesc} \begin{methoddesc}[window]{getorigin}{}Return a pair of integers giving the origin of the window with respectto the document.\end{methoddesc} \begin{methoddesc}[window]{gettitle}{}Return the window's title string.\end{methoddesc} \begin{methoddesc}[window]{getwinsize}{}Return a pair of integers giving the size of the window.\end{methoddesc} \begin{methoddesc}[window]{getwinpos}{}Return a pair of integers giving the position of the window's upperleft corner (relative to the upper left corner of the screen).\end{methoddesc} \begin{methoddesc}[window]{menucreate}{title}Create a menu object referring to a local menu (a menu that appearsonly in this window).Methods of menu objects are described below.\warning{The menu only appears as long as the objectreturned by this call exists.}\end{methoddesc} \begin{methoddesc}[window]{scroll}{rect, point}Scroll the given rectangle by the vector given by the point.\end{methoddesc} \begin{methoddesc}[window]{setdocsize}{point}Set the size of the drawing document.\end{methoddesc} \begin{methoddesc}[window]{setorigin}{point}Move the origin of the window (its upper left corner)to the given point in the document.\end{methoddesc} \begin{methoddesc}[window]{setselection}{i, str}Attempt to set X11 selection number \var{i} to the string \var{str}.(See \module{stdwin} function \function{getselection()} for themeaning of \var{i}.)  Return true if it succeeds.If  succeeds, the window ``owns'' the selection until(a) another application takes ownership of the selection; or(b) the window is deleted; or(c) the application clears ownership by calling\function{stdwin.resetselection(\var{i})}.  When another applicationtakes ownership of the selection, a \constant{WE_LOST_SEL} event isreceived for no particular window and with the selection number asdetail.  Ignored on the Macintosh.\end{methoddesc} \begin{methoddesc}[window]{settimer}{dsecs}Schedule a timer event for the window in \code{\var{dsecs}/10}seconds.\end{methoddesc} \begin{methoddesc}[window]{settitle}{title}Set the window's title string.\end{methoddesc} \begin{methoddesc}[window]{setwincursor}{name}\begin{sloppypar}Set the window cursor to a cursor of the given name.  It raises\exception{RuntimeError} if no cursor of the given name exists.Suitable names include\code{'ibeam'},\code{'arrow'},\code{'cross'},\code{'watch'}and\code{'plus'}.On X11, there are many more (see \code{<X11/cursorfont.h>}).\end{sloppypar}\end{methoddesc} \begin{methoddesc}[window]{setwinpos}{h, v}Set the position of the window's upper left corner (relative tothe upper left corner of the screen).\end{methoddesc} \begin{methoddesc}[window]{setwinsize}{width, height}Set the window's size.\end{methoddesc} \begin{methoddesc}[window]{show}{rect}Try to ensure that the given rectangle of the document is visible inthe window.\end{methoddesc} \begin{methoddesc}[window]{textcreate}{rect}Create a text-edit object in the document at the given rectangle.Methods of text-edit objects are described below.\end{methoddesc} \begin{methoddesc}[window]{setactive}{}Attempt to make this window the active window.  If successful, thiswill generate a WE_ACTIVATE event (and a WE_DEACTIVATE event in caseanother window in this application became inactive).\end{methoddesc} \begin{methoddesc}[window]{close}{}Discard the window object.  It should not be used again.\end{methoddesc} \subsection{Drawing Objects} Drawing objects are created exclusively by the window method\method{begindrawing()}.  Only one drawing object can exist at anygiven time; the drawing object must be deleted to finish drawing.  Nodrawing object may exist when \function{stdwin.getevent()} is called.Drawing objects have the following methods: \begin{methoddesc}[drawing]{box}{rect}Draw a box just inside a rectangle.\end{methoddesc} \begin{methoddesc}[drawing]{circle}{center, radius}Draw a circle with given center point and radius.\end{methoddesc} \begin{methoddesc}[drawing]{elarc}{center, (rh, rv), (a1, a2)}Draw an elliptical arc with given center point.\code{(\var{rh}, \var{rv})}gives the half sizes of the horizontal and vertical radii.\code{(\var{a1}, \var{a2})}gives the angles (in degrees) of the begin and end points.0 degrees is at 3 o'clock, 90 degrees is at 12 o'clock.\end{methoddesc} \begin{methoddesc}[drawing]{erase}{rect}Erase a rectangle.\end{methoddesc} \begin{methoddesc}[drawing]{fillcircle}{center, radius}Draw a filled circle with given center point and radius.\end{methoddesc} \begin{methoddesc}[drawing]{fillelarc}{center, (rh, rv), (a1, a2)}Draw a filled elliptical arc; arguments as for \method{elarc()}.\end{methoddesc} \begin{methoddesc}[drawing]{fillpoly}{points}Draw a filled polygon given by a list (or tuple) of points.\end{methoddesc} \begin{methoddesc}[drawing]{invert}{rect}Invert a rectangle.\end{methoddesc} \begin{methoddesc}[drawing]{line}{p1, p2}Draw a line from point\var{p1}to\var{p2}.\end{methoddesc} \begin{methoddesc}[drawing]{paint}{rect}Fill a rectangle.\end{methoddesc} \begin{methoddesc}[drawing]{poly}{points}Draw the lines connecting the given list (or tuple) of points.\end{methoddesc} \begin{methoddesc}[drawing]{shade}{rect, percent}Fill a rectangle with a shading pattern that is about\var{percent}percent filled.\end{methoddesc} \begin{methoddesc}[drawing]{text}{p, str}Draw a string starting at point p (the point specifies thetop left coordinate of the string).\end{methoddesc} \begin{methoddesc}[drawing]{xorcircle}{center, radius}\funcline{xorelarc}{center, (rh, rv), (a1, a2)}\funcline{xorline}{p1, p2}\funcline{xorpoly}{points}Draw a circle, an elliptical arc, a line or a polygon, respectively,in XOR mode.

Lines 1–500 of 832.