OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tk8.6.12 / library / demos / bind.tcl
1 # bind.tcl --
2 #
3 # This demonstration script creates a text widget with bindings set
4 # up for hypertext-like effects.
5
6 if {![info exists widgetDemo]} {
7     error "This script should be run from the \"widget\" demo."
8 }
9
10 package require Tk
11
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
18
19 ## See Code / Dismiss buttons
20 set btns [addSeeDismiss $w.buttons $w]
21 pack $btns -side bottom -fill x
22
23 text $w.text -yscrollcommand "$w.scroll set" -setgrid true \
24         -width 60 -height 24 -font $font -wrap word
25 ttk::scrollbar $w.scroll -command "$w.text yview"
26 pack $w.scroll -side right -fill y
27 pack $w.text -expand yes -fill both
28
29 # Set up display styles.
30
31 if {[winfo depth $w] > 1} {
32     set bold "-background #43ce80 -relief raised -borderwidth 1"
33     set normal "-background {} -relief flat"
34 } else {
35     set bold "-foreground white -background black"
36     set normal "-foreground {} -background {}"
37 }
38
39 # Add text to widget.
40
41 $w.text insert 0.0 {\
42 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.
43
44 }
45 $w.text insert end \
46 {1. Samples of all the different types of items that can be created in canvas widgets.} d1
47 $w.text insert end \n\n
48 $w.text insert end \
49 {2. A simple two-dimensional plot that allows you to adjust the positions of the data points.} d2
50 $w.text insert end \n\n
51 $w.text insert end \
52 {3. Anchoring and justification modes for text items.} d3
53 $w.text insert end \n\n
54 $w.text insert end \
55 {4. An editor for arrow-head shapes for line items.} d4
56 $w.text insert end \n\n
57 $w.text insert end \
58 {5. A ruler with facilities for editing tab stops.} d5
59 $w.text insert end \n\n
60 $w.text insert end \
61 {6. A grid that demonstrates how canvases can be scrolled.} d6
62
63 # Create bindings for tags.
64
65 foreach tag {d1 d2 d3 d4 d5 d6} {
66     $w.text tag bind $tag <Enter> "$w.text tag configure $tag $bold"
67     $w.text tag bind $tag <Leave> "$w.text tag configure $tag $normal"
68 }
69 # Main widget program sets variable tk_demoDirectory
70 $w.text tag bind d1 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory items.tcl]}
71 $w.text tag bind d2 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory plot.tcl]}
72 $w.text tag bind d3 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory ctext.tcl]}
73 $w.text tag bind d4 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory arrow.tcl]}
74 $w.text tag bind d5 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory ruler.tcl]}
75 $w.text tag bind d6 <Button-1> {source -encoding utf-8 [file join $tk_demoDirectory cscroll.tcl]}
76
77 $w.text mark set insert 0.0
78 $w.text configure -state disabled