Add tcl/tk, so gitk and git-gui will work
[msysgit/historical-msysgit.git] / lib / tk8.4 / demos / bind.tcl
blob6b2961268cd4a75259805623658925ea29e32408
1 # bind.tcl --
3 # This demonstration script creates a text widget with bindings set
4 # up for hypertext-like effects.
6 # RCS: @(#) $Id: bind.tcl,v 1.2 1998/09/14 18:23:26 stanton Exp $
8 if {![info exists widgetDemo]} {
9 error "This script should be run from the \"widget\" demo."
12 set w .bind
13 catch {destroy $w}
14 toplevel $w
15 wm title $w "Text Demonstration - Tag Bindings"
16 wm iconname $w "bind"
17 positionWindow $w
19 frame $w.buttons
20 pack $w.buttons -side bottom -fill x -pady 2m
21 button $w.buttons.dismiss -text Dismiss -command "destroy $w"
22 button $w.buttons.code -text "See Code" -command "showCode $w"
23 pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
25 text $w.text -yscrollcommand "$w.scroll set" -setgrid true \
26 -width 60 -height 24 -font $font -wrap word
27 scrollbar $w.scroll -command "$w.text yview"
28 pack $w.scroll -side right -fill y
29 pack $w.text -expand yes -fill both
31 # Set up display styles.
33 if {[winfo depth $w] > 1} {
34 set bold "-background #43ce80 -relief raised -borderwidth 1"
35 set normal "-background {} -relief flat"
36 } else {
37 set bold "-foreground white -background black"
38 set normal "-foreground {} -background {}"
41 # Add text to widget.
43 $w.text insert 0.0 {\
44 The same tag mechanism that controls display styles in text widgets can also be used to associate Tcl commands with regions of text, so that mouse or keyboard actions on the text cause particular Tcl commands to be invoked. For example, in the text below the descriptions of the canvas demonstrations have been tagged. When you move the mouse over a demo description the description lights up, and when you press button 1 over a description then that particular demonstration is invoked.
47 $w.text insert end \
48 {1. Samples of all the different types of items that can be created in canvas widgets.} d1
49 $w.text insert end \n\n
50 $w.text insert end \
51 {2. A simple two-dimensional plot that allows you to adjust the positions of the data points.} d2
52 $w.text insert end \n\n
53 $w.text insert end \
54 {3. Anchoring and justification modes for text items.} d3
55 $w.text insert end \n\n
56 $w.text insert end \
57 {4. An editor for arrow-head shapes for line items.} d4
58 $w.text insert end \n\n
59 $w.text insert end \
60 {5. A ruler with facilities for editing tab stops.} d5
61 $w.text insert end \n\n
62 $w.text insert end \
63 {6. A grid that demonstrates how canvases can be scrolled.} d6
65 # Create bindings for tags.
67 foreach tag {d1 d2 d3 d4 d5 d6} {
68 $w.text tag bind $tag <Any-Enter> "$w.text tag configure $tag $bold"
69 $w.text tag bind $tag <Any-Leave> "$w.text tag configure $tag $normal"
71 $w.text tag bind d1 <1> {source [file join $tk_library demos items.tcl]}
72 $w.text tag bind d2 <1> {source [file join $tk_library demos plot.tcl]}
73 $w.text tag bind d3 <1> {source [file join $tk_library demos ctext.tcl]}
74 $w.text tag bind d4 <1> {source [file join $tk_library demos arrow.tcl]}
75 $w.text tag bind d5 <1> {source [file join $tk_library demos ruler.tcl]}
76 $w.text tag bind d6 <1> {source [file join $tk_library demos cscroll.tcl]}
78 $w.text mark set insert 0.0
79 $w.text configure -state disabled