Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bd5c3d824c3db63ffd9226c15941e6ad > files > 2377

mozart-1.4.0-1mdv2010.0.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>8.1 Dialogs</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="node41.html">- Up -</A></TD><TD><A href="node43.html#section.tools.error">Next &gt;&gt;</A></TD></TR></TABLE><DIV id="section.tools.dialogs"><H2><A name="section.tools.dialogs">8.1 Dialogs</A></H2><P><A name="label333"></A> A dialog displays some graphical information and several buttons. A simple abstraction to build dialogs is provided by the class <CODE>TkTools<SPAN class="keyword">.</SPAN>dialog</CODE>. </P><P> <A href="node42.html#figure.tools.dialog">Figure&nbsp;8.1</A> shows an example dialog for deleting a file. The class <CODE>TkTools<SPAN class="keyword">.</SPAN>dialog</CODE> is a subclass of <CODE>Tk<SPAN class="keyword">.</SPAN>frame</CODE>. Creating and initializing an instance of this class creates a toplevel widget together with buttons displayed at the bottom of the toplevel widget. The instance itself serves as container for user-defined widgets that are displayed at the top of the dialog (as the label and the entry widget in our example). </P><P> </P><DIV id="figure.tools.dialog"><HR><P><A name="figure.tools.dialog"></A></P><P> </P><DIV align="center"><IMG alt="" src="dialog.gif"></DIV><P> </P><DL class="anonymous"><DD class="code"><CODE>D={New&nbsp;TkTools<SPAN class="keyword">.</SPAN>dialog<BR>&nbsp;&nbsp;&nbsp;tkInit(title:&nbsp;&nbsp;&nbsp;<SPAN class="string">'Remove&nbsp;File'</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buttons:&nbsp;[<SPAN class="string">'Okay'</SPAN>&nbsp;<SPAN class="keyword">#</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">$</SPAN>}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">try</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{OS<SPAN class="keyword">.</SPAN>unlink&nbsp;{E&nbsp;tkReturn(get&nbsp;$)}}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{D&nbsp;tkClose}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">catch</SPAN>&nbsp;_&nbsp;<SPAN class="keyword">then</SPAN>&nbsp;<SPAN class="keyword">skip</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="string">'Cancel'</SPAN>&nbsp;<SPAN class="keyword">#</SPAN>&nbsp;tkClose]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:&nbsp;1)}<BR>L={New&nbsp;Tk<SPAN class="keyword">.</SPAN>label&nbsp;tkInit(parent:D&nbsp;text:<SPAN class="string">'File&nbsp;name:'</SPAN>)}<BR>E={New&nbsp;Tk<SPAN class="keyword">.</SPAN>entry&nbsp;tkInit(parent:D&nbsp;bg:wheat&nbsp;width:20)}<BR>{Tk<SPAN class="keyword">.</SPAN>batch&nbsp;[pack(L&nbsp;E&nbsp;side:left&nbsp;pady:2<SPAN class="keyword">#</SPAN>m)&nbsp;focus(E)]}</CODE></DD></DL><P> </P><P class="caption"><STRONG>Figure&nbsp;8.1:</STRONG> A dialog to remove files.</P><HR></DIV><P> </P><P> The initialization message for a dialog must contain the <CODE>title</CODE> option, which gives the title of the dialog. The buttons to be displayed are specified by a list of pairs, where the first pair in the list describes the leftmost button. The pair consists of the label of the button and the action for the button. The action can be also the atom <CODE>tkClose</CODE>, which means that the action of the button sends a <CODE>tkClose</CODE> message to the dialog. In a similar manner, the action can be a unary tuple with label <CODE>tkClose</CODE>, which means that first the action specified by the tuple's argument is executed and then the dialog is closed. The <CODE>default</CODE> option specifies which button should be the default one. The default button is marked by a sunken frame drawn around the button. </P><P> In the above example, pressing the <CODE><SPAN class="string">'Okay'</SPAN></CODE> button executes an <CODE>rm</CODE> command to remove the file with the name as given by the entry widget&nbsp;<CODE>E</CODE>. Only if execution of this command returns&nbsp;<CODE>0</CODE>, the dialog is closed. </P><P> The class <CODE>TkTools<SPAN class="keyword">.</SPAN>dialog</CODE> is a subclass of <CODE>Tk<SPAN class="keyword">.</SPAN>frame</CODE>. In particular it allows to wait until the dialog object gets closed. For example, the execution of </P><BLOCKQUOTE class="code"><CODE>{Wait&nbsp;D<SPAN class="keyword">.</SPAN>tkClosed}</CODE></BLOCKQUOTE><P> blocks until the dialog in the above example is closed. </P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node41.html">- Up -</A></TD><TD><A href="node43.html#section.tools.error">Next &gt;&gt;</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 (20090610)</SPAN></ADDRESS></BODY></HTML>