OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / SGI / util / SGI / lib / blt2.4 / demos / htext.txt
1 #!/home/people/tkys/Eos/util/SGI/bin/bltwish
2
3         This is a (for lack of a better name) hypertext widget.
4
5 This widget combines text and other Tk widgets in the same window.
6 It is sort of a cross between a read-only text widget and the pack command.
7 Any widget can be attached to the hypertext window by the %% 
8 set this $htext(widget)
9 label $this.lab -text "append " -relief sunken \
10         -font *-Courier-Bold-R-Normal-*-12-120-*
11 $this append $this.lab 
12 %% command.
13 For example,
14 %% message $this.msg -relief sunken -bd 2 -aspect 10000 -font \
15  *-Courier-Medium-R-Normal-*-12-* -text {set w $htext(widget)
16 label $w.face -bitmap @bitmaps/face \ 
17   -relief sunken -borderwidth 2
18 $w append $w.face -padx 2 -pady 0.25i}
19 $this append $this.msg \
20         -fill both %% added this %%
21 global tk_library
22 label $this.face \
23         -bitmap @bitmaps/face  \
24         -relief sunken -borderwidth 2
25 $this append $this.face -padx 2 -pady 0.25i 
26 %%.
27 There can be many types of widgets in the same document.  For example,
28 this is a simple %% 
29 button $this.but -bg pink -text { button } \
30   -command { puts stderr { a stupid message } } 
31 $this append $this.but 
32 %%. If you click on the button, it prints a stupid message.
33 Any Tk widget can be used, including %%
34 set whichTile 0
35 proc ChangeTile { w } {
36    global whichTile
37
38    if { $whichTile } {
39         $w configure -tile bgTexture2
40    } else {
41         $w configure -tile bgTexture1
42    }
43 }
44 checkbutton $this.ckbut -bg lightblue -text { check buttons } \
45    -variable whichTile -command "ChangeTile $this" 
46 $this append $this.ckbut -justify top
47 %%, %%
48 radiobutton $this.rdbut -bg mediumseagreen -text { radio buttons } \
49         -command { puts stderr { radio button pressed } } 
50 $this append $this.rdbut -justify bottom
51 %%, 
52 and scales %%
53 # -sliderforeground
54 scale $this.sc -showvalue true \
55         -length 100 \
56         -foreground powderblue \
57         -sliderlength 10 \
58         -orient horizontal  
59 $this append $this.sc
60 %%.
61
62         Widget trees can be also be included. The following example is
63 *borrowed* from the widget demo. It is a couple of frames surrounding a
64 listbox, a message, and a button widget.
65 %%
66     set w $this.frame 
67     frame $w 
68     message $w.msg -font *times-medium-r-normal--*-12-120-* -aspect 300 \
69             -text "A listbox containing the 50 states is displayed below, along with a scrollbar.  You can scan the list either using the scrollbar or by dragging in the listbox window with button 3 pressed.  Click the \"OK\" button when you've seen enough." -bg lightsteelblue -relief sunken
70     frame $w.frame -borderwidth 10 
71     pack append $w.frame \
72         [scrollbar $w.frame.scroll -relief sunken \
73             -command "$w.frame.list yview"] {right expand filly frame w} \
74         [listbox $w.frame.list -yscroll "$w.frame.scroll set" -relief sunken] \
75             {left expand filly frame e}
76     $w.frame.list insert 0 Alabama Alaska Arizona Arkansas California \
77         Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois \
78         Indiana Iowa Kansas Kentucky Louisiana Maine Maryland \
79         Massachusetts Michigan Minnesota Mississippi Missouri \
80         Montana Nebraska Nevada "New Hampshire" "New Jersey" "New Mexico" \
81         "New York" "North Carolina" "North Dakota" \
82         Ohio Oklahoma Oregon Pennsylvania "Rhode Island" \
83         "South Carolina" "South Dakota" \
84         Tennessee Texas Utah Vermont Virginia Washington \
85         "West Virginia" Wisconsin Wyoming
86     button $w.ok -text OK -command "puts stderr $w; destroy $w"
87
88     pack append $w $w.msg {top fill} $w.frame {top expand fill} \
89         $w.ok {bottom fill}
90     $w config -bg lightsteelblue -relief sunken
91
92 $this append $w -pady 0.25i
93 %%
94
95 You can add you own home-grown widgets.  Here's the graph widget.
96 Beside it is the "color" demo.  Moving the scales, adjusts the background
97 color of the graph.
98 %%
99 #
100 # Simple script to change colors of a window.
101 #
102 global xlabel ylabel red green blue graph
103 set red 255
104 set green 215
105 set blue 0
106
107 option add *Scale.sliderForeground "#cdb79e"
108 option add *Scale.activeForeground "#ffe4c4"
109 set w $this.colorFrame
110 frame $w
111 scale $w.red -command "color red" -label "Red Intensity" \
112         -from 0 -to 255 -orient horizontal -bg "#ffaeb9" -length 250
113 scale $w.green -command "color green" -label "Green Intensity" \
114         -from 0 -to 255 -orient horizontal -bg "#43cd80"
115 scale $w.blue -command "color blue" -label "Blue Intensity"  \
116         -from 0 -to 255 -orient horizontal -bg "#7ec0ee"
117
118 $w.blue set $blue
119 $w.green set $green
120 $w.red set $red
121
122 pack append $w $w.red {top expand fill}
123 pack append $w $w.green {top expand fill}
124 pack append $w $w.blue {top expand fill}
125
126 proc color {which intensity} {
127     global red green blue graph xlabel ylabel
128     set $which $intensity
129     set rgb [format #%02x%02x%02x $red $green $blue]
130     $graph config -bg $rgb
131     $xlabel config -bg $rgb
132     $ylabel config -bg $rgb
133 }
134
135 $this append $w 
136
137 %% 
138 %%
139 proc makeplot { widget } {
140
141     graph $widget
142     set X { 
143         2.00000e-01 4.00000e-01 6.00000e-01 8.00000e-01 1.00000e+00 
144         1.20000e+00 1.40000e+00 1.60000e+00 1.80000e+00 2.00000e+00 
145         2.20000e+00 2.40000e+00 2.60000e+00 2.80000e+00 3.00000e+00 
146         3.20000e+00 3.40000e+00 3.60000e+00 3.80000e+00 4.00000e+00 
147         4.20000e+00 4.40000e+00 4.60000e+00 4.80000e+00 5.00000e+00 
148     } 
149
150     $widget element create Y1 -xdata $X -ydata { 
151         1.14471e+01 2.09373e+01 2.84608e+01 3.40080e+01 3.75691e+01 
152         3.91345e+01 3.92706e+01 3.93474e+01 3.94242e+01 3.95010e+01 
153         3.95778e+01 3.96545e+01 3.97313e+01 3.98081e+01 3.98849e+01 
154         3.99617e+01 4.00384e+01 4.01152e+01 4.01920e+01 4.02688e+01 
155         4.03455e+01 4.04223e+01 4.04990e+01 4.05758e+01 4.06526e+01 
156     } -symbol circle -label VGS=2.0 -color blue4 -fill blue
157
158     $widget element create Y2 -xdata $X -ydata { 
159         2.61825e+01 5.04696e+01 7.28517e+01 9.33192e+01 1.11863e+02 
160         1.28473e+02 1.43140e+02 1.55854e+02 1.66606e+02 1.75386e+02 
161         1.82185e+02 1.86994e+02 1.89802e+02 1.90683e+02 1.91047e+02 
162         1.91411e+02 1.91775e+02 1.92139e+02 1.92503e+02 1.92867e+02 
163         1.93231e+02 1.93595e+02 1.93958e+02 1.94322e+02 1.94686e+02 
164     } -symbol diamond -label VGS=3.5 -color green4 -fill green
165
166     $widget element create Y3 -xdata $X -ydata { 
167         4.07008e+01 7.95658e+01 1.16585e+02 1.51750e+02 1.85051e+02 
168         2.16479e+02 2.46024e+02 2.73676e+02 2.99427e+02 3.23267e+02 
169         3.45187e+02 3.65177e+02 3.83228e+02 3.99331e+02 4.13476e+02 
170         4.25655e+02 4.35856e+02 4.44073e+02 4.50294e+02 4.54512e+02 
171         4.56716e+02 4.57596e+02 4.58448e+02 4.59299e+02 4.60151e+02 
172    } -symbol triangle -label VGS=5.0 -color red4 -fill red
173
174 }
175
176 option add *graph.title  "Plot Title" 
177 option add *graph.xTitle "X Axis Label"
178 option add *graph.yTitle "Y Axis Label" 
179 #option add *graph.legendMapped false 
180 option add *graph.elemPixels 8
181 option add *graph.relief ridge
182 option add *graph.borderWidth 2
183
184 set graph $this.graph
185 set xlabel $this.xlab
186 set ylabel $this.ylab
187 makeplot $graph
188 $this append $graph -padx 0.25i -pady 0.25i 
189
190 %%
191 If you click on any button in the graph, you will get the coordinate 
192 values at the pointer location.  
193
194 The current coordinate values are %%
195 label $xlabel -text { ??? ??? } -relief sunken
196 label $ylabel -text { ??? ??? } -relief sunken
197 bind $graph <ButtonPress> {labelxy [ %W invtransform %x %y ]}
198
199 proc labelxy { values } {
200     global xlabel ylabel
201     scan $values "%e %e" x y
202     $xlabel config -text $x
203     $ylabel config -text $y
204 }
205 $this append $this.xlab -width 100 -fill x
206 %% and %%
207 $this append $this.ylab -width 100 -fill x
208 %%.
209
210
211 There are four global variables automatically created when a hypertext
212 file is read. They are:
213
214 %% 
215 button $this.l1 -text " \$htext(widget) " \
216         -command "puts $this" -bg orange
217 $this append $this.l1 -width 200 -pady 4
218 %%the pathname of the hypertext widget. 
219 %% 
220 button $this.l2 -text " \$htext(file) " \
221         -command "puts $htext(file)" -bg orange
222 $this append $this.l2 -width 200 -pady 4
223 %%the file being read.
224 %% 
225 button $this.l3 -text " \$htext(line) "  \
226         -command "puts $htext(line)" -bg orange
227 $this append $this.l3 -width 200 -pady 4
228 %%the current line number.
229 %% 
230 button $this.l4 -text " \$htext(index) " \
231         -command "puts $htext(index)" -bg orange
232 $this append $this.l4 -width 200 -pady 4
233 %%the current index in the text.
234
235 Click on any button and the current value is printed on standard output.
236
237 The hypertext widget works with plain text too. If you don't want
238 to read it, click on the %% 
239 button $this.goto -text button -fg purple -bg white \
240         -command "global endOfText; $this gotoline \$endOfText"
241 $this append $this.goto
242 %% to jump to the end of the plain text.
243
244          ------------------------------------------------------
245
246 This is version 2.0 of the BLT library.  BLT is an extension the Tk
247 toolkit, adding new widgets, geometry managers, and miscellaneous
248 commands.  It does not require any patching of the Tcl or Tk source
249 files.
250
251 This release works with both Tk versions 3.6 and 4.0.  It may work
252 with 4.1, but I haven't it tried it yet.  
253
254 There are many changes in this release.  Not least of which is that
255 each command no longer has a "blt_" prefix.  This wart has been
256 removed since [Incr Tcl] 2.0 now includes namespaces.  There's no good
257 reason to "uglify" code when the right solution is now available.
258
259 BLT will automatically use namespaces if you compile with with the
260 itcl-2.x versions of Tcl and Tk headers and libraries.  BLT will
261 reside in its own namespace called "blt". All the normal BLT commands
262 and variables will reside there.
263
264 There are too many bug fixes and changes to list here (I'm putting
265 together a separate list), so check the manual pages.
266
267 The BLT library adds the following commands to Tk:
268
269 table      A table-based geometry manager for Tk.  You specify the 
270            widget layout as row and column positions in the table.  
271            Has many options for constraining window resizing.
272          
273 graph      A XY graph widget.  Plots two-variable data.  Supports
274            two sets of X and Y axes, inverted axes, custom axis
275            layout.  
276          
277 barchart   A barchart widget.  Plots two-variable data using bars.  
278            Supports two sets of X and Y axes, inverted axes, custom axis 
279            layout.  
280          
281 vector     Creates a vector of floating point values.  The vector's 
282            components can be manipulated in three ways: through a Tcl 
283            array variable, a Tcl command, or the C API. 
284
285 spline     Computes a spline fitting a set of data points (x and y vectors) 
286            and produces a vector of the interpolated images (y-coordinates) 
287            at a given set of x-coordinates.
288
289 busy       For handling user-interaction when the application is "busy".
290            Manages an invisible "busy" window which prevents further 
291            user device (keyboard, mouse, button, etc.) interactions.
292            Also provides a different cursor which supersedes application
293            cursors.
294          
295 bgexec     Like Tcl's "exec ... &", but collects the output, error, and 
296            status of the detached UNIX subprocesses.  Sets a Tcl variable 
297            upon completion.  Can be used with "tkwait variable" to handle 
298            expose events, etc. while waiting for subprocesses to finish.  
299          
300 drag&drop  Command which adds drag-n-drop capabilities to Tk.  It 
301            provides "send"-style communication between drag-drop 
302            sources and targets.  The result is a much more powerful
303            drag-and-drop mechanism than is available with OpenLook
304            or Motif.  
305          
306 htext      A simple hypertext widget. Allows text and Tk widgets to
307            be combined in a scrollable text window.  Any Tk widget 
308            can be embedded and used to form hyper-links.  Other 
309            options allow for selections and text searches.
310          
311 bitmap     Command for creating and manipulating bitmaps from Tcl. Lets 
312            you read and write bitmaps from Tcl. Can also define X bitmaps  
313            and create bitmaps from text strings.  Other options let
314            you rotate and scale bitmaps.
315          
316 winop      Low-level Xlib calls let you raise, lower, map, or, unmap 
317            any window.  
318          
319 watch      Lets you specify Tcl procedures to be run before and/or
320            after every Tcl command.  May be used for logging,
321            tracing, profiling, or debugging or Tcl code.
322          
323 bltdebug   Prints out each Tcl command before it's executed.  
324
325 ---------
326
327 How to get and test BLT:
328
329 The following describes how to get and install the BLT library.
330
331 0. FTP the distribution from harbor.ecn.purdue.edu
332
333         ftp ftp.aud.alcatel.com
334         cd pub/tcl/extensions
335         binary 
336         get BLT2.0.tar.gz
337         quit
338
339 1. Uncompress and untar the distribution file.  
340
341         zcat BLT2.0.tar.gz | tar -xvf - 
342
343
344    This will create a directory "blt2.0" with the following 
345    subdirectories:
346         
347                         blt2.0
348              ______________|_____________
349              |          |       |        |
350            demos   library     man      src
351                                          |
352                                        shared
353
354 2. Run ./configure
355
356    Go into the "blt2.0" directory 
357
358         cd blt2.0
359
360    and run the auto-configuration script "./configure"
361
362         ./configure 
363
364    * If you want to use gcc, it's "./configure -with-cc=gcc"
365
366         ./configure -with-cc=gcc
367
368    * By default, the demo program, libBLT.a, the library files, and
369      manual pages will be installed in "/usr/local/blt".  You can 
370      change this by giving the -prefix option to ./configure.
371
372         ./configure -prefix=/depot/stuff/blt
373     
374   The "configure" script will print out where is finds the X, Tcl, and Tk 
375   header files and libraries.   If you see "__Edit_config.BLT__" has
376   a value, you should edit the generated file "config.BLT".  Edit the
377   paths to the correct values and re-run "configure".
378
379   The configure script creates an include file "src/bltConfig.h".
380   It will also generate new Makefiles from their respective templates 
381   (Makefile.in).
382
383         Makefile.in             ==> Makefile
384         src/Makefile.in         ==> src/Makefile
385         src/shared/Makefile.in  ==> src/shared/Makefile
386         man/Makefile.in         ==> man/Makefile
387         library/Makefile.in     ==> library/Makefile
388
389   If "configure" can't find something (e.g. it can't find the X libraries),
390   edit the file "config.BLT" and re-run "configure".
391
392   Otherwise, you'll have to edit the Makefiles files by hand.
393
394
395 3. Compile the demonstration program "bltwish".
396
397         make 
398
399 4. Test by running the demos. 
400
401    Go into the demos directory 
402     
403         cd demos
404
405    and run the test scripts.
406         
407         ./graph
408
409    If your system doesn't support "#!" in shell scripts, then it's
410
411         ../blt_wish -f ./graph
412
413
414 5. Installing BLT
415
416    The following directories will be created when BLT is installed.  
417    By default, the top directory is /usr/local/blt.  
418
419        _____________|_______________
420        |     |        |     |      |  
421       bin  include   lib  blt2.0  man
422      
423    You can change the top directory by supplying the -prefix option to
424    ./configure.
425
426    * If you don't install BLT, you will need to set the BLT_LIBRARY
427      environment variable or the Tcl variable "blt_library" in your
428      scripts.  Otherwise, you may not be able generate PostScript 
429      output for graphs and barcharts, or use the drag&drop facility 
430      properly.
431
432 6. Adding BLT to your program.
433
434    Add the following lines to your program's Tcl_AppInit routine 
435
436         if (Blt_Init(interp) != TCL_OK) {
437             return TCL_ERROR;
438         }
439
440    Link with libBLT.a
441
442    and that's all there's to it.
443
444 7. Send bugs reports, suggestions, etc. to
445
446         gah@mhcnet.att.com or ghowlett@fast.net
447
448    Make sure you include BLT and the version number in the subject line.
449
450
451 %%
452 global endOfText
453 set endOfText [expr $htext(line)-1 ]
454
455 global updateInterval count barchart
456 global Red Green Blue
457 set updateInterval 2000
458 set count 0
459 set Red bb
460 set Green 00
461 set Blue 33
462
463 option add *barchart.title "Bar Chart" 
464 option add *barchart.xTitle "X"
465 option add *barchart.yTitle "Y"
466 option add *barchart.y2Title "Y"
467 option add *barchart.ySubTicks 0
468 option add *barchart.xTicks 0
469 option add *barchart.legendMapped false
470 option add *barchart.AxisFont *-Courier-Bold-R-Normal-*-8-80-* 
471 option add *barchart.y2Mapped true
472
473 set barchart $this.barchart
474 barchart $barchart -bd 2 -relief raised  -tile bgTexture2
475 $barchart y2axis use y
476 $this append $barchart -fill both -padx 10 -pady 10
477
478 proc AnimateBarchart {  } {
479     global updateInterval
480     global barchart count Red Blue Green
481     
482     if { [info commands $barchart] != $barchart } {
483         return
484     }   
485     incr count
486     if { $count > 16 } {
487         $barchart element delete [lindex [$barchart element show] 0]
488     }
489     set color [format "%x" [expr $count%16]]
490     set Green ${color}${color}
491     $barchart element create $count -data { $count sin($count*0.1)} \
492         -fg #${Red}${Green}${Blue} -bg brown 
493     after $updateInterval AnimateBarchart
494 }
495 AnimateBarchart
496
497 %%
498
499         Press %%
500 button $this.quit -command { exit } -text {Quit} -bg pink
501 $this append $this.quit
502 %% to remove the window.
503