Sophie

Sophie

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

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

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>8.3 Menubars</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="node43.html#section.tools.error">&lt;&lt; Prev</A></TD><TD><A href="node41.html">- Up -</A></TD><TD><A href="node45.html#section.tools.images">Next &gt;&gt;</A></TD></TR></TABLE><DIV id="section.tools.menubars"><H2><A name="section.tools.menubars">8.3 Menubars</A></H2><DIV class="apropos"><P class="margin">keyboard accelerators</P><P> A menubar is a frame widget containing several menubutton widgets. To each of the menubutton widgets a menu is attached. The menu contains menuitems being either radiobutton entries, checkbutton entries, command entries (similar to button widgets), separator entries or cascade entries to which sub menus are attached. The menu entries can be equipped with <A name="label337"></A><EM>keyboard accelerators</EM> describing key event bindings that can be used to invoke the action of the menu entry. A keyboard accelerator must be added to the menu entry and the right event binding needs to be created. </P></DIV><P> Creating a menubar by hand has to follow this structure and is inconvenient due to the large numbers of different kinds of widgets and menu entries that are to be created. To ease the creation of a menubar, the <CODE>TkTools</CODE> module provides the procedure <CODE>TkTools<SPAN class="keyword">.</SPAN>menubar</CODE> that creates to a given specification a menubar and creates keyboard accelerators with the right event bindings. The specification of a menubar consists of messages used to initialize the necessary widgets and entries, where the label determines the kind of entry to be created. </P><P> <A href="node44.html#figure.tools.menubar">Figure&nbsp;8.3</A> shows an example for menubar creation. The procedure <CODE>TkTools<SPAN class="keyword">.</SPAN>menubar</CODE> takes two widgets and two menubar specifications as input and returns a frame containing the widgets for the menubar. The widget given as first argument serves as parent for the menubar's frame, whereas the widget given as second argument receives the key bindings for the accelerators. The specification given as third (fourth) argument describe the left (right) part of the menubar. </P><P> </P><DIV id="figure.tools.menubar"><HR><P><A name="figure.tools.menubar"></A></P><P> </P><DIV align="center"><IMG alt="" src="menubar.gif"></DIV><P> <A name="label339"></A> </P><DL class="anonymous"><DD class="code"><CODE>V={New&nbsp;Tk<SPAN class="keyword">.</SPAN>variable&nbsp;tkInit(0)}<BR>B={TkTools<SPAN class="keyword">.</SPAN>menubar&nbsp;W&nbsp;W<BR>&nbsp;&nbsp;&nbsp;[menubutton(text:<SPAN class="string">'Test'</SPAN>&nbsp;underline:0<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;menu:&nbsp;[command(label:&nbsp;&nbsp;&nbsp;<SPAN class="string">'About&nbsp;test'</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;&nbsp;&nbsp;&nbsp;&nbsp;action:&nbsp;&nbsp;Browse<SPAN class="keyword">#</SPAN>about<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;&nbsp;&nbsp;&nbsp;&nbsp;key:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alt(a)<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;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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;feature:&nbsp;test)<BR>&nbsp;&nbsp;&nbsp;&nbsp;menubutton(text:<SPAN class="string">'Options'</SPAN>&nbsp;underline:0<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;menu:&nbsp;[checkbutton(label:&nbsp;<SPAN class="string">'Incremental'</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var:&nbsp;{New&nbsp;Tk<SPAN class="keyword">.</SPAN>variable&nbsp;tkInit(<SPAN class="keyword">false</SPAN>)})<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;separator<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cascade(label:&nbsp;<SPAN class="string">'Size'</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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p;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;radiobutton(label:<SPAN class="string">'Large'</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var:V&nbsp;value:&nbsp;2)])])]<BR>&nbsp;&nbsp;&nbsp;nil}<BR>F={New&nbsp;Tk<SPAN class="keyword">.</SPAN>frame&nbsp;tkInit(parent:W&nbsp;width:10<SPAN class="keyword">#</SPAN>c&nbsp;height:5<SPAN class="keyword">#</SPAN>c&nbsp;bg:ivory)}<BR>{Tk<SPAN class="keyword">.</SPAN>send&nbsp;pack(B&nbsp;F&nbsp;fill:x)}</CODE></DD></DL><P> </P><P class="caption"><STRONG>Figure&nbsp;8.3:</STRONG> A menubar.</P><HR></DIV><P> </P><P> A menubar specification consists of a list of <CODE>menubutton</CODE> messages. The valid options are those for the <CODE>tkInit</CODE> method of a menubutton widget object, where the parent field is not necessary, and the additional options <CODE>menu</CODE> and <CODE>feature</CODE>. The value for the <CODE>menu</CODE> option must be a list of specifications for the menu entries. The menu entries are specified similar to the menubuttons, the allow for the additional options <CODE>feature</CODE>, <CODE>key</CODE>, and <CODE>event</CODE>. </P><P> The value for the <CODE>key</CODE> describes the keyboard accelerator and event binding to be created. They can be used as follows: </P><TABLE align="center" bgcolor="#f0f0e0"><TR valign="top"><TH><P><CODE>key</CODE> option value</P></TH><TH><P>accelerator</P></TH><TH><P>event binding</P></TH></TR><TR valign="top"><TD><P><CODE>a</CODE></P></TD><TD><P><SPAN class="key">a</SPAN></P></TD><TD><P><CODE>a</CODE></P></TD></TR><TR valign="top"><TD><P><CODE>ctrl(a)</CODE></P></TD><TD><P><SPAN class="key">C-a</SPAN></P></TD><TD><P><CODE>&lt;Control-a&gt;</CODE></P></TD></TR><TR valign="top"><TD><P><CODE>alt(a)</CODE></P></TD><TD><P><SPAN class="key">A-a</SPAN></P></TD><TD><P><CODE>&lt;Alt-a&gt;</CODE></P></TD></TR><TR valign="top"><TD><P><CODE>alt(ctrl(a))</CODE></P></TD><TD><P><SPAN class="key">A-C-a</SPAN></P></TD><TD><P><CODE>&lt;Alt-Control-a&gt;</CODE></P></TD></TR><TR valign="top"><TD><P><CODE>ctrl(alt(a))</CODE></P></TD><TD><P><SPAN class="key">C-A-a</SPAN></P></TD><TD><P><CODE>&lt;Control-Alt-a&gt;</CODE></P></TD></TR></TABLE><P> </P><P> In case one wants to use different event bindings than those generated from the <CODE>key</CODE> option value, one can specify the event pattern as value for the option <CODE>event</CODE>. </P><P> The <CODE>feature</CODE> options for menubuttons and menu entries attach features to the created objects such that the object get accessible by these features. For instance, to disable the <SPAN class="menu">``About test''</SPAN> entry is possible with </P><DL class="anonymous"><DD class="code"><CODE>{B<SPAN class="keyword">.</SPAN>test<SPAN class="keyword">.</SPAN>about&nbsp;tk(entryconfigure&nbsp;state:disabled)}</CODE></DD></DL><P> </P><P> The menus attached to menubuttons or to cascade entries can be accessed under the feature <CODE>menu</CODE>. For instance the first tear off entry from the <SPAN class="menu">``Test''</SPAN> menu can be removed with </P><DL class="anonymous"><DD class="code"><CODE>{B<SPAN class="keyword">.</SPAN>test<SPAN class="keyword">.</SPAN>menu&nbsp;tk(configure&nbsp;tearoff:<SPAN class="keyword">false</SPAN>)}</CODE></DD></DL><P> </P><P> It is possible to extend a menubar created with <CODE>TkTools<SPAN class="keyword">.</SPAN>menubar</CODE> with further entries. The following statement adds a menu entry just before the <CODE>Quit</CODE> entry: <A name="label341"></A> </P><DL class="anonymous"><DD class="code"><CODE>A={New&nbsp;Tk<SPAN class="keyword">.</SPAN>menuentry<SPAN class="keyword">.</SPAN>command&nbsp;tkInit(parent:B<SPAN class="keyword">.</SPAN>test<SPAN class="keyword">.</SPAN>menu<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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;before:B<SPAN class="keyword">.</SPAN>test<SPAN class="keyword">.</SPAN>quit<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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label:&nbsp;<SPAN class="string">'Exit'</SPAN>)}</CODE></DD></DL><P> which can be deleted and removed from the menu again by: </P><DL class="anonymous"><DD class="code"><CODE>{A&nbsp;tkClose}</CODE></DD></DL><P> </P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node43.html#section.tools.error">&lt;&lt; Prev</A></TD><TD><A href="node41.html">- Up -</A></TD><TD><A href="node45.html#section.tools.images">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>