/usr/share/mozart/doc/wp/node31.html is in mozart-doc 1.4.0-8ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>5.12 Example: Help Popups</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node30.html#section.widgets-2.file"><< Prev</A></TD><TD><A href="node19.html">- Up -</A></TD></TR></TABLE><DIV id="section.widgets-2.help"><H2><A name="section.widgets-2.help">5.12 Example: Help Popups</A></H2><P> In the following we want to look at a small example which provides for a generic interactive help popup window. The idea is that if the mouse pointer stays over a widget for some time without pressing a mouse button, a small help text is displayed. The help text should disappear if the mouse pointer leaves the screen area covered by the widget. </P><P> We will build a procedure <CODE>AttachHelp</CODE> such that help texts are enabled by application of the procedure to a widget and a help text. We proceed in three steps, the first is to create a function to create a toplevel widget that displays the help text, the second is a listener class (that is, a subclass of <CODE>Tk<SPAN class="keyword">.</SPAN>listener</CODE>), and the last step is the definition of <CODE>AttachHelp</CODE> itself. </P><H3><A name="label261">5.12.1 Displaying Help</A></H3><P> The procedure <CODE>MakePopup</CODE> shown in <A href="node31.html#figure.widgets-2.help-create">Figure 5.12</A> takes a widget and the help text as its argument and returns a function to create a toplevel widget containing the text at a position relative to the widget on the screen. </P><P> </P><DIV id="figure.widgets-2.help-create"><HR><P><A name="figure.widgets-2.help-create"></A></P><DL><DT><SPAN class="chunktitle"><SPAN class="chunkborder"><</SPAN><A name="label262">Definition of MakePopup</A><SPAN class="chunkborder">>=</SPAN></SPAN></DT><DD class="code"><CODE><SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">MakePopup</SPAN> Parent Text}<BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN>}<BR> [X Y H]={Map [rootx rooty height]<BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> WI}<BR> {Tk<SPAN class="keyword">.</SPAN>returnInt winfo(WI Parent)}<BR> <SPAN class="keyword">end</SPAN>}<BR> W={New Tk<SPAN class="keyword">.</SPAN>toplevel tkInit(withdraw:<SPAN class="keyword">true</SPAN> bg:black)}<BR> M={New Tk<SPAN class="keyword">.</SPAN>message<BR> tkInit(parent:W text:Text bg:khaki aspect:400)}<BR> <SPAN class="keyword">in</SPAN> <BR> {Tk<SPAN class="keyword">.</SPAN>batch [wm(overrideredirect W <SPAN class="keyword">true</SPAN>)<BR> wm(geometry W <SPAN class="string">'+'</SPAN><SPAN class="keyword">#</SPAN>X<SPAN class="keyword">+</SPAN>10<SPAN class="keyword">#</SPAN><SPAN class="string">'+'</SPAN><SPAN class="keyword">#</SPAN>Y<SPAN class="keyword">+</SPAN>H)<BR> pack(M padx:2 pady:2)<BR> wm(deiconify W)]}<BR> W<BR> <SPAN class="keyword">end</SPAN> <BR><SPAN class="keyword">end</SPAN></CODE></DD></DL><P class="caption"><STRONG>Figure 5.12:</STRONG> Creating a help window.</P><HR></DIV><P> </P><P> The returned function creates a toplevel widget in withdrawn state and configures the toplevel widget such that it: </P><OL type="1"><LI><P>is not equipped with a frame from the window manager. This is done by using the window manager command <CODE>overrideredirect</CODE>: the window manager is advised to not ``redirect'' the toplevel widget into a frame. </P></LI><LI><P>appears at a position relative to <CODE>X</CODE> and <CODE>Y</CODE> coordinates of the widget parent, which done by the <CODE>geometry</CODE> window manager command. </P></LI><LI><P>appears on the screen by deiconifying it. </P></LI></OL><P> </P><H3><A name="label263">5.12.2 The Listener Class</A></H3><P> The listener class <CODE>HelpListener</CODE> is shown in <A href="node31.html#figure.widgets-2.help-mixin">Figure 5.13</A>. The method <CODE>init</CODE> initializes an instance of this class by creating a procedure for creation of the popup widget. </P><P> </P><DIV id="figure.widgets-2.help-mixin"><HR><P><A name="figure.widgets-2.help-mixin"></A></P><DL><DT><SPAN class="chunktitle"><SPAN class="chunkborder"><</SPAN><A name="label264">Definition of HelpListener</A><SPAN class="chunkborder">>=</SPAN></SPAN></DT><DD class="code"><CODE><SPAN class="keyword">class</SPAN> <SPAN class="type">HelpListener</SPAN> <SPAN class="keyword">from</SPAN><SPAN class="type"> Tk.listener</SPAN> <BR> <SPAN class="keyword">attr</SPAN> <BR> cancel: <SPAN class="keyword">unit</SPAN> <BR> popup: <SPAN class="keyword">unit</SPAN> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">init</SPAN>(parent:P text:T)<BR> popup <SPAN class="keyword">:=</SPAN> {MakePopup P T}<BR> Tk<SPAN class="keyword">.</SPAN>listener<SPAN class="keyword">,</SPAN>tkInit<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">enter</SPAN> <BR> C<BR> <SPAN class="keyword">in</SPAN> <BR> cancel <SPAN class="keyword">:=</SPAN> C<BR> <SPAN class="keyword">thread</SPAN> A={Alarm 1000} <SPAN class="keyword">in</SPAN> <BR> {WaitOr C A}<BR> <SPAN class="keyword">if</SPAN> {IsDet A} <SPAN class="keyword">then</SPAN> W={<SPAN class="keyword">@</SPAN>popup} <SPAN class="keyword">in</SPAN> <BR> {Wait C} {W tkClose}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">leave</SPAN> <BR> <SPAN class="keyword">@</SPAN>cancel=<SPAN class="keyword">unit</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR><SPAN class="keyword">end</SPAN></CODE></DD></DL><P class="caption"><STRONG>Figure 5.13:</STRONG> The listener class <CODE>HelpListener</CODE>.</P><HR></DIV><P> </P><P> When the mouse pointer enters the parent widget, the method <CODE>enter</CODE> gets executed. This method stores a new variable <CODE>C</CODE> in the attribute <CODE>cancel</CODE> which serves as flag whether the help popup must be closed. The newly created thread waits until either one second has elapsed (<CODE>A</CODE> gets bound after 1000 milliseconds) or the widget has been left (<CODE>C</CODE> gets bound). Then possibly the widget for the help text is created, which gets closed when the parent widget is left. Note that if both <CODE>A</CODE> and <CODE>C</CODE> happen to be bound at the same time, the popup will be created and then closed immediately. </P><P> The <CODE>leave</CODE> method signals that the help popup must be closed by binding the variable stored in <CODE>cancel</CODE>. </P><H3><A name="label265">5.12.3 <CODE>AttachHelp</CODE></A></H3><P> The definition of <CODE>AttachHelp</CODE> is shown in <A href="node31.html#figure.widgets-2.attach">Figure 5.14</A>. It creates a listener and creates event bindings that are served by that listener. </P><P> </P><DIV id="figure.widgets-2.attach"><HR><P><A name="figure.widgets-2.attach"></A></P><DL class="anonymous"><DD class="code"><CODE><SPAN class="keyword">local</SPAN> <BR> </CODE><SPAN class="chunktitle"><SPAN class="chunkborder"><</SPAN><A href="node31.html#label262">Definition of MakePopup</A><SPAN class="chunkborder">></SPAN></SPAN><CODE> <BR> </CODE><SPAN class="chunktitle"><SPAN class="chunkborder"><</SPAN><A href="node31.html#label264">Definition of HelpListener</A><SPAN class="chunkborder">></SPAN></SPAN><CODE> <BR><SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">AttachHelp</SPAN> Widget Text}<BR> L={New HelpListener init(parent:Widget text:Text)}<BR> <SPAN class="keyword">in</SPAN> <BR> {Widget tkBind(event:<SPAN class="string">'<Enter>'</SPAN> action:L<SPAN class="keyword">#</SPAN>enter append:<SPAN class="keyword">true</SPAN>)}<BR> {Widget tkBind(event:<SPAN class="string">'<Leave>'</SPAN> action:L<SPAN class="keyword">#</SPAN>leave append:<SPAN class="keyword">true</SPAN>)}<BR> {Widget tkBind(event:<SPAN class="string">'<Button>'</SPAN> action:L<SPAN class="keyword">#</SPAN>leave append:<SPAN class="keyword">true</SPAN>)}<BR> <SPAN class="keyword">end</SPAN> <BR><SPAN class="keyword">end</SPAN></CODE></DD></DL><P class="caption"><STRONG>Figure 5.14.</STRONG></P><HR></DIV><P> </P><H3><A name="label266">5.12.4 Using Help Popups</A></H3><P> A small example that shows how to use help popups is shown in <A href="node31.html#figure.widgets-2.help-use">Figure 5.15</A>. </P><P> </P><DIV id="figure.widgets-2.help-use"><HR><P><A name="figure.widgets-2.help-use"></A></P><P> </P><DIV align="center"><IMG alt="" src="help.gif"></DIV><P> </P><DL class="anonymous"><DD class="code"><CODE>Bs={Map [<SPAN class="string">'Okay'</SPAN> <SPAN class="keyword">#</SPAN> <SPAN class="string">'Do nothing meaningful.'</SPAN> <BR> <SPAN class="string">'Cancel'</SPAN> <SPAN class="keyword">#</SPAN> <SPAN class="string">'Do nothing at all.'</SPAN> <BR> <SPAN class="string">'Quit'</SPAN> <SPAN class="keyword">#</SPAN> <SPAN class="string">'Close the window.'</SPAN>]<BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> Text <SPAN class="keyword">#</SPAN> Help}<BR> B={New Tk<SPAN class="keyword">.</SPAN>button tkInit(parent:W text:Text)}<BR> <SPAN class="keyword">in</SPAN> <BR> {AttachHelp B Help} B<BR> <SPAN class="keyword">end</SPAN>}<BR>{Tk<SPAN class="keyword">.</SPAN>send pack(b(Bs) side:left padx:2<SPAN class="keyword">#</SPAN>m pady:2<SPAN class="keyword">#</SPAN>m)}</CODE></DD></DL><P> </P><P class="caption"><STRONG>Figure 5.15:</STRONG> Demo of the <CODE>HelpPopup</CODE> class.</P><HR></DIV><P> </P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node30.html#section.widgets-2.file"><< Prev</A></TD><TD><A href="node19.html">- Up -</A></TD></TR></TABLE><HR><ADDRESS><A href="http://www.ps.uni-sb.de/~schulte/">Christian Schulte</A><BR><SPAN class="version">Version 1.4.0 (20110908185330)</SPAN></ADDRESS></BODY></HTML>
|