<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html > <head><title>Controlling the interface</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)"> <meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)"> <!-- 3,html --> <meta name="src" content="nipguide.tex"> <meta name="date" content="2010-06-30 13:34:00"> <link rel="stylesheet" type="text/css" href="nipguide.css"> </head><body > <!--l. 1292--><div class="crosslinks"><p class="noindent">[<a href="nipguidese34.html" >next</a>] [<a href="nipguidese32.html" >prev</a>] [<a href="nipguidese32.html#tailnipguidese32.html" >prev-tail</a>] [<a href="#tailnipguidese33.html">tail</a>] [<a href="nipguidech6.html#nipguidese33.html" >up</a>] </p></div> <h3 class="sectionHead"><span class="titlemark">6.12 </span> <a id="x44-790006.12"></a>Controlling the interface</h3> <!--l. 1293--><p class="noindent" ><a name="nip_label_sec:bowser"></a> <!--l. 1295--><p class="indent" > <span class="pcrr7t-">nip2 </span>looks at the scraps of program you type in and execute and tries to show them on the screen in a graphical way. The sorts of display you get depend on where in <span class="pcrr7t-">nip2</span> you define the expression, and what sort of value it has. <!--l. 1300--><p class="noindent" > <h4 class="subsectionHead"><span class="titlemark">6.12.1 </span> <a id="x44-800006.12.1"></a>Tools and toolkits</h4> <!--l. 1301--><p class="noindent" ><a name="nip_label_sec:tools"></a> <!--l. 1303--><p class="indent" > Definitions in toolkits are turned into menus off the <span class="pcrr7t-">Toolkits </span>menu in the main window, and added to the toolkit browser. Toolkits are loaded from files at startup or can be made in the program window. Toolkit or a definition names which start with an underscore character are hidden and not displayed. The toolkits are always displayed in alphabetical order, but you can order the items within a toolkit in any way you like. <!--l. 1311--><p class="indent" > There are two ways to write toolkit definitions. Function definitions and zero-argument classes simply appear as menu items, built from static analysis of their source code. However, if a definition evaluates to an instance of the class <span class="pcrr7t-">Menu</span>, a menu item is built from dynamic analysis of the value of the definition. <!--l. 1317--><p class="noindent" > <h5 class="subsubsectionHead"><a id="x44-810006.12.1"></a>Static menu items</h5> <!--l. 1319--><p class="noindent" >Zero-argument classes within toolkits are displayed as pull-right menus. You can nest classes to any depth. <!--l. 1322--><p class="indent" > <span class="pcrr7t-">nip2 </span>uses the first line of the comment before a definition as help text for that function, so it’s a good idea to put a simple one-line description of the function at the start of a comment. <!--l. 1326--><p class="indent" > For example, if the following text is placed in a file called <span class="pcrr7t-">Fred.def </span>on <span class="pcrr7t-">nip2</span>’s start path, you’ll get a menu in the tookits called <span class="pcrr7t-">Fred </span>with a pull-right and a tooltip. See Figure <a href="#x44-810011">6.1<!--tex4ht:ref: fg:toolkit --></a>. <div class="verbatim" id="verbatim-84"> Banana a = a ⋆ 3;  <br />  <br />Subfred = class {  <br />  // add two things  <br />  Jim a b = a + b;  <br />  Apple e = e ⋆ 12;  <br />  Harry z = 12 + z;  <br />} </div> <!--l. 1339--><p class="nopar" > <!--l. 1341--><p class="indent" > <hr class="figure"><div class="figure" > <a id="x44-810011"></a> <div class="center" > <!--l. 1342--><p class="noindent" > <!--l. 1342--><p class="noindent" ><img src="figs/toolkit.jpg" alt="PIC" ></div> <br /> <div class="caption" ><span class="id">Figure 6.1: </span><span class="content">How <span class="pcrr7t-">Fred.def </span>will look</span></div><!--tex4ht:label?: x44-810011 --> <!--l. 1344--><p class="noindent" ><a name="nip_label_fg:toolkit"></a> <!--l. 1345--><p class="indent" > </div><hr class="endfigure"> <h5 class="subsubsectionHead"><a id="x44-820006.12.1"></a>Dynamic menu items</h5> <!--l. 1349--><p class="noindent" >Dynamic menus give you much more control over the way menus are drawn and make it easy to reuse menus. A dynamic menu item is a class instance that is a sub-class of <span class="pcrr7t-">Menuitem</span>. It needs to have three members: <span class="pcrr7t-">label</span>, the text that should appear in the menu (with an underscore character to indicate the mnenonic); <span class="pcrr7t-">tooltip</span>, a short hint that appears as a tooltip or in the toolkit browser; <span class="pcrr7t-">icon</span>, an optional image file to be displayed in the menu next to the text; and <span class="pcrr7t-">action</span>, the function that is called when the menu item is activated. <span class="pcrr7t-">label </span>and <span class="pcrr7t-">tooltip </span>are constructor arguments for <span class="pcrr7t-">Menu</span>. <!--l. 1359--><p class="indent" > So for example: <div class="verbatim" id="verbatim-85"> Wombat_find_item = class Menuitem  <br />  "_Find Wombat"  <br />  "analyse image and locate wombat" {  <br />  icon = "nip-slider-16.png";  <br />  action x = im_wombat_locate x;  <br />} </div> <!--l. 1368--><p class="nopar" > <!--l. 1370--><p class="noindent" >will appear as shown in Figure <a href="#x44-820012">6.2<!--tex4ht:ref: fg:toolkit2 --></a>. <!--l. 1373--><p class="indent" > <hr class="figure"><div class="figure" > <a id="x44-820012"></a> <div class="center" > <!--l. 1374--><p class="noindent" > <!--l. 1374--><p class="noindent" ><img src="figs/toolkit2.jpg" alt="PIC" ></div> <br /> <div class="caption" ><span class="id">Figure 6.2: </span><span class="content">How <span class="pcrr7t-">Wombat</span><span class="pcrr7t-">_find</span><span class="pcrr7t-">_item </span>will look</span></div><!--tex4ht:label?: x44-820012 --> <!--l. 1376--><p class="noindent" ><a name="nip_label_fg:toolkit2"></a> <!--l. 1377--><p class="indent" > </div><hr class="endfigure"> <!--l. 1379--><p class="indent" > A dynamic pullright menu is a subclass of <span class="pcrr7t-">Menupullright</span>. It’s just like <span class="pcrr7t-">Menuitem</span>, but without the need for an <span class="pcrr7t-">action </span>member. Any members which are subclasses of <span class="pcrr7t-">Menu </span>are displayed as items in the submenu. So again: <div class="verbatim" id="verbatim-86"> Wombat_item = class Menupullright  <br />  "_Wombat"  <br />  "wombat-related operations" {  <br />  icon = "nip-slider-16.png";  <br />  item1 = Wombat_find_item;  <br />  sep = Menuseparator;  <br />  boink = Wombat_find_item;  <br />} </div> <!--l. 1393--><p class="nopar" > <!--l. 1395--><p class="noindent" >will appear as shown in Figure <a href="#x44-820023">6.3<!--tex4ht:ref: fg:toolkit3 --></a>. <!--l. 1398--><p class="indent" > <hr class="figure"><div class="figure" > <a id="x44-820023"></a> <div class="center" > <!--l. 1399--><p class="noindent" > <!--l. 1399--><p class="noindent" ><img src="figs/toolkit3.jpg" alt="PIC" ></div> <br /> <div class="caption" ><span class="id">Figure 6.3: </span><span class="content">How <span class="pcrr7t-">Wombat</span><span class="pcrr7t-">_item </span>will look</span></div><!--tex4ht:label?: x44-820023 --> <!--l. 1401--><p class="noindent" ><a name="nip_label_fg:toolkit3"></a> <!--l. 1402--><p class="indent" > </div><hr class="endfigure"> <h4 class="subsectionHead"><span class="titlemark">6.12.2 </span> <a id="x44-830006.12.2"></a>Workspaces</h4> <!--l. 1405--><p class="noindent" ><a name="nip_label_sec:workspaces"></a> <!--l. 1407--><p class="indent" > Definitions in workspaces are displayed with <span class="pcrr7t-">nip2</span>’s class browser. Each row is displayed in four main parts: a button for the row name, a line of text, a set of sub-rows for the members of the row’s class, and a graphic display representing the row’s value. See Figure <a href="#x44-830014">6.4<!--tex4ht:ref: fg:row2 --></a>. <!--l. 1412--><p class="indent" > <hr class="figure"><div class="figure" > <a id="x44-830014"></a> <div class="center" > <!--l. 1413--><p class="noindent" > <!--l. 1413--><p class="noindent" ><img src="figs/ir8a.jpg" alt="PIC" ></div> <br /> <div class="caption" ><span class="id">Figure 6.4: </span><span class="content">Components of a workspace row</span></div><!--tex4ht:label?: x44-830014 --> <!--l. 1415--><p class="noindent" ><a name="nip_label_fg:row2"></a> <!--l. 1416--><p class="indent" > </div><hr class="endfigure"> <!--l. 1418--><p class="indent" > The text part of the right-hand-side of each row is always displayed, but the sub-rows are only displayed if the row represents a class, and the graphic is only displayed if the class is an instance of one of the classes in Table <a href="#x44-830025">6.5<!--tex4ht:ref: tb:classes --></a>. You can subclass these if you want to use the graphic display in your own widgets. <!--l. 1424--><p class="indent" > There are three separate ways to set the value for a row. You can edit the line of program text, you can edit one of the members, or you can manipulate the graphic representation (dragging a slider, or moving a region). These can be contradictory, so <span class="pcrr7t-">nip2 </span>resolves conflicts by always applying changes in the order text, then graphic, then member. <!--l. 1430--><p class="indent" > When it applies a graphic change, <span class="pcrr7t-">nip2 </span>rebuilds the class using a class member called <span class="ptmri7t-">class-name</span><span class="pcrr7t-">_edit</span>, or if that is not defined, the class’s constructor member. For example, the <span class="pcrr7t-">Colour </span>class can be defined as: <div class="verbatim" id="verbatim-87"> Colour colour_space value = class {}  <br />A1 = Colour "sRGB" [255,0,0]; </div> <!--l. 1438--><p class="nopar" > <!--l. 1440--><p class="noindent" >There are two ways to change <span class="pcrr7t-">A1</span>. You can open <span class="pcrr7t-">A1</span> and change <span class="pcrr7t-">colour</span><span class="pcrr7t-">_space </span>to <span class="pcrr7t-">"Lab"</span>, or you can double-click on the swatch and drag the disc. When you click <span class="pcrr7t-">OK </span>on the colour edit dialog, <span class="pcrr7t-">nip2 </span>searches for a member called <span class="pcrr7t-">Colour</span><span class="pcrr7t-">_edit</span>, fails to find it, and so picks the <span class="pcrr7t-">Colour </span>member instead (the default constructor generated by <span class="pcrr7t-">nip2</span>). It then replaces the value of A1 with <!--l. 1448--><p class="indent" > [needs finishing] <!--l. 1451--><p class="indent" > <a id="x44-830025"></a><hr class="float"><div class="float" > <div class="center" > <!--l. 1451--><p class="noindent" > <div class="tabular"> <table id="TBL-7" class="tabular" cellspacing="0" cellpadding="0" rules="groups" ><colgroup id="TBL-7-1g"><col id="TBL-7-1"></colgroup><colgroup id="TBL-7-2g"><col id="TBL-7-2"></colgroup><tr class="hline"><td><hr></td><td><hr></td></tr><tr style="vertical-align:baseline;" id="TBL-7-1-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-1-1" class="td11">Class </td><td style="white-space:nowrap; text-align:left;" id="TBL-7-1-2" class="td11">Description </td> </tr><tr class="hline"><td><hr></td><td><hr></td></tr><tr style="vertical-align:baseline;" id="TBL-7-2-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-2-1" class="td11"><span class="pcrr7t-">Clock </span><span class="pcrro7t-">interval value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-2-2" class="td11">A clock widget, handy for animations </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-3-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-3-1" class="td11"><span class="pcrr7t-">Expression </span><span class="pcrro7t-">caption expr </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-3-2" class="td11">Displays an editable expression </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-4-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-4-1" class="td11"><span class="pcrr7t-">Group </span><span class="pcrro7t-">value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-4-2" class="td11">A group of objects for iteration </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-5-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-5-1" class="td11"><span class="pcrr7t-">List </span><span class="pcrro7t-">value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-5-2" class="td11">A list of related objects </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-6-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-6-1" class="td11"><span class="pcrr7t-">Pathname </span><span class="pcrro7t-">caption value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-6-2" class="td11">Displays a file browser </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-7-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-7-1" class="td11"><span class="pcrr7t-">Fontname </span><span class="pcrro7t-">caption value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-7-2" class="td11">Displays a font browser </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-8-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-8-1" class="td11"><span class="pcrr7t-">Toggle </span><span class="pcrro7t-">caption value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-8-2" class="td11">A toggle switch </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-9-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-9-1" class="td11"><span class="pcrr7t-">Scale </span><span class="pcrro7t-">caption from to value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-9-2" class="td11">A slider </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-10-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-10-1" class="td11"><span class="pcrr7t-">Option </span><span class="pcrro7t-">caption labels value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-10-2" class="td11">Select one item from a list </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-11-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-11-1" class="td11"><span class="pcrr7t-">Colour </span><span class="pcrro7t-">colour</span><span class="pcrro7t-">_space value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-11-2" class="td11">A patch of colour </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-12-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-12-1" class="td11"><span class="pcrr7t-">Matrix</span><span class="pcrr7t-">_vips </span><span class="pcrro7t-">value scale offset filename display</span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-12-2" class="td11">A matrix </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-13-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-13-1" class="td11"><span class="pcrr7t-">Arrow </span><span class="pcrro7t-">image left top width height </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-13-2" class="td11">Two points joined by a line on an image</td> </tr><tr style="vertical-align:baseline;" id="TBL-7-14-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-14-1" class="td11"><span class="pcrr7t-">Region </span><span class="pcrro7t-">image left top width height </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-14-2" class="td11">A sub-area of an image </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-15-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-15-1" class="td11"><span class="pcrr7t-">Plot </span><span class="pcrro7t-">options value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-15-2" class="td11">Displays a plot widget </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-16-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-16-1" class="td11"><span class="pcrr7t-">Image </span><span class="pcrro7t-">value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-16-2" class="td11">An image </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-17-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-17-1" class="td11"><span class="pcrr7t-">Number </span><span class="pcrro7t-">caption value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-17-2" class="td11">Displays an editable number </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-18-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-18-1" class="td11"><span class="pcrr7t-">Real </span><span class="pcrro7t-">value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-18-2" class="td11">Displays a real number </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-19-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-19-1" class="td11"><span class="pcrr7t-">Vector </span><span class="pcrro7t-">value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-19-2" class="td11">Displays a list of reals </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-20-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-20-1" class="td11"><span class="pcrr7t-">String </span><span class="pcrro7t-">caption value </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-20-2" class="td11">Displays an editable string </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-21-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-21-1" class="td11"><span class="pcrr7t-">Mark </span><span class="pcrro7t-">image left top </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-21-2" class="td11">A point on an image </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-22-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-22-1" class="td11"><span class="pcrr7t-">HGuide </span><span class="pcrro7t-">image top </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-22-2" class="td11">A horizontal line on an image </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-23-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-23-1" class="td11"><span class="pcrr7t-">VGuide </span><span class="pcrro7t-">image left </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-23-2" class="td11">A vertical line on an image </td> </tr><tr style="vertical-align:baseline;" id="TBL-7-24-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-24-1" class="td11"><span class="pcrr7t-">Area </span><span class="pcrro7t-">image left top width height </span></td><td style="white-space:nowrap; text-align:left;" id="TBL-7-24-2" class="td11">A sub-area of an image, fixed in size </td> </tr><tr class="hline"><td><hr></td><td><hr></td></tr><tr style="vertical-align:baseline;" id="TBL-7-25-"><td style="white-space:nowrap; text-align:left;" id="TBL-7-25-1" class="td11"> </td></tr></table></div></div> <br /><div class="caption" ><span class="id">Table 6.5: </span><span class="content"><span class="pcrr7t-">nip2 </span>built in graphic classes</span></div><!--tex4ht:label?: x44-830025 --> <!--l. 1507--><p class="noindent" ><a name="nip_label_tb:classes"></a> </div><hr class="endfloat" /> <h4 class="subsectionHead"><span class="titlemark">6.12.3 </span> <a id="x44-840006.12.3"></a>The <span class="pcrr7t-">Image </span>class</h4> <!--l. 1511--><p class="noindent" ><a name="nip_label_sec:Image"></a> . <!--l. 1513--><p class="indent" > say supports mioxed ops with real, vector and complex constants <!--l. 1515--><p class="noindent" > <h4 class="subsectionHead"><span class="titlemark">6.12.4 </span> <a id="x44-850006.12.4"></a>The <span class="pcrr7t-">Colour </span>class</h4> <!--l. 1516--><p class="noindent" ><a name="nip_label_sec:colour"></a> <!--l. 1518--><p class="indent" > This class displays a swatch of colour. If you double-click on the <div class="verbatim" id="verbatim-88"> Pathname caption value = class {} </div> <!--l. 1522--><p class="nopar" > <!--l. 1524--><div class="crosslinks"><p class="noindent">[<a href="nipguidese34.html" >next</a>] [<a href="nipguidese32.html" >prev</a>] [<a href="nipguidese32.html#tailnipguidese32.html" >prev-tail</a>] [<a href="nipguidese33.html" >front</a>] [<a href="nipguidech6.html#nipguidese33.html" >up</a>] </p></div> <!--l. 1524--><p class="indent" > <a id="tailnipguidese33.html"></a> </body></html>