This file is indexed.

/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">&lt;&lt; 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&nbsp;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">&lt;</SPAN><A name="label262">Definition of MakePopup</A><SPAN class="chunkborder">&gt;=</SPAN></SPAN></DT><DD class="code"><CODE><SPAN class="keyword">fun</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">MakePopup</SPAN>&nbsp;Parent&nbsp;Text}<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">fun</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">$</SPAN>}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[X&nbsp;Y&nbsp;H]={Map&nbsp;[rootx&nbsp;rooty&nbsp;height]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">fun</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">$</SPAN>&nbsp;WI}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{Tk<SPAN class="keyword">.</SPAN>returnInt&nbsp;winfo(WI&nbsp;Parent)}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;W={New&nbsp;Tk<SPAN class="keyword">.</SPAN>toplevel&nbsp;tkInit(withdraw:<SPAN class="keyword">true</SPAN>&nbsp;bg:black)}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;M={New&nbsp;Tk<SPAN class="keyword">.</SPAN>message<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tkInit(parent:W&nbsp;text:Text&nbsp;bg:khaki&nbsp;aspect:400)}<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">in</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{Tk<SPAN class="keyword">.</SPAN>batch&nbsp;[wm(overrideredirect&nbsp;W&nbsp;<SPAN class="keyword">true</SPAN>)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wm(geometry&nbsp;W&nbsp;<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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pack(M&nbsp;padx:2&nbsp;pady:2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wm(deiconify&nbsp;W)]}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;W<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR><SPAN class="keyword">end</SPAN></CODE></DD></DL><P class="caption"><STRONG>Figure&nbsp;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&nbsp;<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&nbsp;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">&lt;</SPAN><A name="label264">Definition of HelpListener</A><SPAN class="chunkborder">&gt;=</SPAN></SPAN></DT><DD class="code"><CODE><SPAN class="keyword">class</SPAN>&nbsp;<SPAN class="type">HelpListener</SPAN>&nbsp;<SPAN class="keyword">from</SPAN><SPAN class="type">&nbsp;Tk.listener</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">attr</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cancel:&nbsp;<SPAN class="keyword">unit</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;popup:&nbsp;&nbsp;<SPAN class="keyword">unit</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">meth</SPAN>&nbsp;<SPAN class="functionname">init</SPAN>(parent:P&nbsp;text:T)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;popup&nbsp;<SPAN class="keyword">:=</SPAN>&nbsp;{MakePopup&nbsp;P&nbsp;T}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tk<SPAN class="keyword">.</SPAN>listener<SPAN class="keyword">,</SPAN>tkInit<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">meth</SPAN>&nbsp;<SPAN class="functionname">enter</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">in</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cancel&nbsp;<SPAN class="keyword">:=</SPAN>&nbsp;C<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">thread</SPAN>&nbsp;A={Alarm&nbsp;1000}&nbsp;<SPAN class="keyword">in</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{WaitOr&nbsp;C&nbsp;A}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">if</SPAN>&nbsp;{IsDet&nbsp;A}&nbsp;<SPAN class="keyword">then</SPAN>&nbsp;W={<SPAN class="keyword">@</SPAN>popup}&nbsp;<SPAN class="keyword">in</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{Wait&nbsp;C}&nbsp;{W&nbsp;tkClose}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">meth</SPAN>&nbsp;<SPAN class="functionname">leave</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">@</SPAN>cancel=<SPAN class="keyword">unit</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR><SPAN class="keyword">end</SPAN></CODE></DD></DL><P class="caption"><STRONG>Figure&nbsp;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&nbsp;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>&nbsp;<BR>&nbsp;&nbsp;&nbsp;</CODE><SPAN class="chunktitle"><SPAN class="chunkborder">&lt;</SPAN><A href="node31.html#label262">Definition of MakePopup</A><SPAN class="chunkborder">&gt;</SPAN></SPAN><CODE>&nbsp;<BR>&nbsp;&nbsp;&nbsp;</CODE><SPAN class="chunktitle"><SPAN class="chunkborder">&lt;</SPAN><A href="node31.html#label264">Definition of HelpListener</A><SPAN class="chunkborder">&gt;</SPAN></SPAN><CODE>&nbsp;<BR><SPAN class="keyword">in</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">AttachHelp</SPAN>&nbsp;Widget&nbsp;Text}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;L={New&nbsp;HelpListener&nbsp;init(parent:Widget&nbsp;text:Text)}<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">in</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{Widget&nbsp;tkBind(event:<SPAN class="string">'&lt;Enter&gt;'</SPAN>&nbsp;&nbsp;action:L<SPAN class="keyword">#</SPAN>enter&nbsp;append:<SPAN class="keyword">true</SPAN>)}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{Widget&nbsp;tkBind(event:<SPAN class="string">'&lt;Leave&gt;'</SPAN>&nbsp;&nbsp;action:L<SPAN class="keyword">#</SPAN>leave&nbsp;append:<SPAN class="keyword">true</SPAN>)}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{Widget&nbsp;tkBind(event:<SPAN class="string">'&lt;Button&gt;'</SPAN>&nbsp;action:L<SPAN class="keyword">#</SPAN>leave&nbsp;append:<SPAN class="keyword">true</SPAN>)}<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR><SPAN class="keyword">end</SPAN></CODE></DD></DL><P class="caption"><STRONG>Figure&nbsp;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&nbsp;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&nbsp;[<SPAN class="string">'Okay'</SPAN>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">#</SPAN>&nbsp;<SPAN class="string">'Do&nbsp;nothing&nbsp;meaningful.'</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="string">'Cancel'</SPAN>&nbsp;<SPAN class="keyword">#</SPAN>&nbsp;<SPAN class="string">'Do&nbsp;nothing&nbsp;at&nbsp;all.'</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="string">'Quit'</SPAN>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">#</SPAN>&nbsp;<SPAN class="string">'Close&nbsp;the&nbsp;window.'</SPAN>]<BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">fun</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">$</SPAN>&nbsp;Text&nbsp;<SPAN class="keyword">#</SPAN>&nbsp;Help}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B={New&nbsp;Tk<SPAN class="keyword">.</SPAN>button&nbsp;tkInit(parent:W&nbsp;text:Text)}<BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">in</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{AttachHelp&nbsp;B&nbsp;Help}&nbsp;B<BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>}<BR>{Tk<SPAN class="keyword">.</SPAN>send&nbsp;pack(b(Bs)&nbsp;side:left&nbsp;padx:2<SPAN class="keyword">#</SPAN>m&nbsp;pady:2<SPAN class="keyword">#</SPAN>m)}</CODE></DD></DL><P> </P><P class="caption"><STRONG>Figure&nbsp;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">&lt;&lt; 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&nbsp;Schulte</A><BR><SPAN class="version">Version 1.4.0 (20110908185330)</SPAN></ADDRESS></BODY></HTML>