📄 c-extend5.html
字号:
<dl class="margin"><dd><p class="Body"><a name="84903"> </a>The following sample Tcl application extends the Tornado browser by adding a new page to display network interface information. Add extension files following these guidelines:</p></dl><dl class="margin"><p><ol class="List"><li value="1."><a name="84904"> </a>Place all files you want auto-sourced by the browser into the subdirectory <i class="textVariable">installDir</i><b class="file">\resource\tcl\app-config\browser </b>and name them <i class="textVariable">filename</i><b class="file">.win32.tcl</b>. You must source the file that contains the host-independent data extraction and formatting routines:</li></ol></p><dl class="margin"><dl class="margin"><dd><pre class="Code3"><b><a name="84905">source [wtxPath host resource tcl]net-core.tcl</a></b></pre></dl></dl><p><ol class="List"><li value="2."><a name="84906"> </a>Append a page title string to the browser global <b class="symbol_lc">pageList</b> variable: </li></ol></p><dl class="margin"><dl class="margin"><dd><pre class="Code3"><b><a name="84907">lappend pageList "Network Information"</a></b></pre></dl></dl><dl class="margin"><dd><div class="Indent"><a name="84908"> </a>This makes the Windows browser aware of the new browser screen.</div><br></dl><p><ol class="List"><li value="3."><a name="84909"> </a>Create a hook routine to be called by the browser when your page description string is selected from the browser page list:<b class="command"> invokeNetworkInformation</b>. </li></ol></p><dl class="margin"><dl class="margin"><dd><pre class="Code3"><b><a name="84910">proc invokeNetworkInformation {} { global currentBrowserProc global autoResize allControlsDestroy Browser setupNetworkInfoPage set currentBrowserProc refreshNetworkInfoPage if {$autoResize} { windowSizeCallbackSet Browser "adjustNetworkInfoPage" } }</a></b></pre></dl></dl><dl class="margin"><dd><div class="Indent"><a name="84911"> </a>The name has the form: </div><br><dl class="margin"><dd><pre class="Code3"><b><a name="84912">invoke<i class="textVariable">DescriptionStringW/oSpaces</i> </a></b></pre></dl><dd><div class="Indent"><a name="84913"> </a>where the description string is the page title sting appended to <b class="symbol_lc">pageList</b>. This procedure destroys all the previous browser controls and calls procedures to initialize the page, refresh the data, and adjust the tree control when the user resizes the browser window. </div><br></dl><p><ol class="List"><li value="4."><a name="84914"> </a>Perform initial setup for the browser page. This step creates a tree control, initializes its structure, gets the required network information, and inserts it into the tree control.</li></ol></p><dl class="margin"><dl class="margin"><dd><pre class="Code3"><b><a name="84915">proc setupNetworkInfoPage {} { global autoResize</a></b><dd> <b><a name="84917"> beginWaitCursor</a></b><dd> <b><a name="84919"> if {$autoResize} { set clientSz [windowClientSizeGet Browser] set maxXExtent [expr [lindex $clientSz 0] - 14] set maxYExtent [expr [lindex $clientSz 1] - 14] } { set maxXExtent 300 set maxYExtent 400 }</a></b><dd> <b><a name="84921"> controlCreate Browser [list hierarchy -name networkInfo \ -x 7 -y 7 -w $maxXExtent -h $maxYExtent] controlStructureSet Browser.networkInfo \ "+ {name flags addr destaddr metric mtu \ {packets {received sent}}\ {errors {input output collision}}}"</a></b><dd> <b><a name="84923"> refreshNetworkInfoPage endWaitCursor }</a></b></pre></dl></dl><p><ol class="List"><li value="5."><a name="84924"> </a>The following callback adjusts the tree control so that it fits properly when the user resizes the browser window.</li></ol></p><dl class="margin"><dl class="margin"><dd><pre class="Code3"><b><a name="84925">proc adjustNetworkInfoPage {} { global autoResize if [controlExists Browser.networkInfo] { set clientSz [windowClientSizeGet Browser] if {$autoResize} { set maxXExtent [expr [lindex $clientSz 0] - 14] set maxYExtent [expr [lindex $clientSz 1] - 14] } { set maxXExtent 300 set maxYExtent 160 } controlPositionSet Browser.networkInfo 7 25 controlSizeSet Browser.networkInfo $maxXExtent \ [expr $maxYExtent - 18] } }</a></b></pre></dl></dl><p><ol class="List"><li value="6."><a name="84926"> </a>The following callback refreshes the data displayed by the tree control. <b class="symbol_lc">getAllIf</b> is the wrapper for the shared code in <b class="file">net-core.tcl</b>. It loops through and collects the data for all network interfaces. (For the complete procedure, see <a href="c-extend5.html#84938">Example 5-4</a>.)</li></ol></p><dl class="margin"><dl class="margin"><dd><pre class="Code3"><b><a name="84930">proc refreshNetworkInfoPage {} { controlValuesSet Browser.networkInfo [getAllIf] }</a></b></pre></dl></dl></dl><dl class="margin"><dd><p class="Body"><a name="84934"> </a><a href="c-extend5.html#84938">Example 5-4</a> gives the complete code to install the sample Tcl application (developed in <a href="c-extend5.html#84776"><i class="title">Generating the Data</i></a>) in the browser on a Windows host.</p></dl></dl><h4 class="EntityTitle"><a name="84938"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 5-4: <b class="file">01NetBrws.win32.tcl</b> </font></a></h4><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84940"> </a>This file should be stored in the<b class="file"> </b><i class="textVariable">installDir</i><b class="file">\host\resource\tcl\app-config\browser </b>directory.</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85542">########################################################################## # 01NetBrws.win32.tcl - sample UITcl code illustrating user extension of the # Tornado Browser. # # Copyright 1994-1997 Wind River Systems, Inc. # # This sample Tcl application extends the Tornado browser by adding a new # page to display network interface information. # ######################################################################### # Do not source this file if the platform is not win32 if {![string match *win32* [wtxHostType]]} return # source the host-independent data extraction and formatting routines source [wtxPath host resource tcl]net-core.tcl # hook our page into the browser lappend pageList "Network Information" # hook for Target Server Information panel called by Browser proc invokeNetworkInformation {} { global currentBrowserProc global autoResize allControlsDestroy Browser setupNetworkInfoPage # hook-in refresh button set currentBrowserProc refreshNetworkInfoPage # ensure window size reflects Browser's if {$autoResize} { windowSizeCallbackSet Browser "adjustNetworkInfoPage" } }</a></b><dd> <b><a name="85543"> # initial setup of the browser page proc setupNetworkInfoPage {} { global autoResize beginWaitCursor if {$autoResize} { set clientSz [windowClientSizeGet Browser] set maxXExtent [expr [lindex $clientSz 0] - 14] set maxYExtent [expr [lindex $clientSz 1] - 14] } { set maxXExtent 300 set maxYExtent 400 } controlCreate Browser [list hierarchy -name networkInfo \ -x 7 -y 7 -w $maxXExtent -h $maxYExtent] controlStructureSet Browser.networkInfo \ "+ {name flags addr destaddr metric mtu \ {packets {received sent}}\ {errors {input output collision}}}" refreshNetworkInfoPage endWaitCursor }</a></b><dd> <b><a name="85544"> # adjust page layout when user resizes proc adjustNetworkInfoPage {} { global autoResize if [controlExists Browser.networkInfo] { set clientSz [windowClientSizeGet Browser] if {$autoResize} { set maxXExtent [expr [lindex $clientSz 0] - 14] set maxYExtent [expr [lindex $clientSz 1] - 14] } { set maxXExtent 300 set maxYExtent 160 } controlPositionSet Browser.networkInfo 7 25 controlSizeSet Browser.networkInfo $maxXExtent \ [expr $maxYExtent - 18] } }</a></b><dd> <b><a name="85545"> # refresh the data displayed by the page proc refreshNetworkInfoPage {} { controlValuesSet Browser.networkInfo [getAllIf] }</a></b><dd> <b><a name="85546"> # loop through and collect the data for all interfaces proc getAllIf {} { set allIf "" foreach netIf [netIfList] { set thisIf "" set ifInfo [netIfInfo $netIf] lappend thisIf [format "%s%d" [lindex $ifInfo 0] \ [lindex $ifInfo 1]] lappend thisIf [format "(%#x) %s" \ [lindex $ifInfo 2] [ifFlagsFormat \ [lindex $ifInfo 2]]] set ifAddrList [netIfAddrList $netIf] lappend thisIf [ifAddrFormat [lrange $ifAddrList 0 3]] lappend thisIf [ifAddrFormat [lrange $ifAddrList 4 7]] # metric lappend thisIf [lindex $ifInfo 4] # mtu lappend thisIf [expr [lindex $ifInfo 3]] # add packet arrays lappend thisIf [list [expr [lindex $ifInfo 5]] \ [expr [lindex $ifInfo 7]]] # add error/collision counts lappend thisIf [list [expr [lindex $ifInfo 6]] \ [expr [lindex $ifInfo 8]] \ [expr [lindex $ifInfo 9]]] lappend allIf $thisIf } return $allIf }</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="79990"> </a></p></dl></dl><a name="foot"><hr></a><p class="FootnoteNumberMarker">1: <span class="Footnote"><a name="84831"> </a>To have an icon appear in the toolbar button instead of the name, place an X bitmap file with the same name as the button in the directory <i class="textVariable">installDir</i><b class="file">/resource/bitmaps/Browser/controls</b>. You can do this with any Tornado tool that has a toolbar.</span><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="c-extend.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-extend.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-extend4.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-adding.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p></body></html><!---by WRS Documentation (), Wind River Systems, Inc. conversion tool: Quadralay WebWorks Publisher 4.0.11 template: CSS Template, Jan 1998 - Jefro --->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -