3 # Tk version of xcolors
7 # --------------------------------------------------------------------------
8 # Starting with Tcl 8.x, the BLT commands are stored in their own
9 # namespace called "blt". The idea is to prevent name clashes with
10 # Tcl commands and variables from other packages, such as a "table"
11 # command in two different packages.
13 # You can access the BLT commands in a couple of ways. You can prefix
14 # all the BLT commands with the namespace qualifier "blt::"
17 # blt::table . .g -resize both
19 # or you can import all the command into the global namespace.
21 # namespace import blt::*
23 # table . .g -resize both
25 # --------------------------------------------------------------------------
26 if { $tcl_version >= 8.0 } {
27 namespace import blt::*
28 namespace import -force blt::tile::*
30 source scripts/demo.tcl
43 scrollbar .xscroll -command { .canvas xview } -orient horizontal
44 scrollbar .yscroll -command { .canvas yview }
47 -font -*-new*century*schoolbook*-bold-r-*-*-24-*-*-*-*-*-*-* \
48 -text {"Bisque is Beautiful".}
50 button .name -font -*-helvetica-medium-r-*-*-18-*-*-*-*-*-*-* \
51 -command "AddSelection name"
52 button .rgb -font -*-courier-medium-r-*-*-18-*-*-*-*-*-*-* \
53 -command "AddSelection rgb"
57 -yscrollcommand { .yscroll set } \
58 -width [expr 16*$cellWidth] -height 400 \
59 -scrollregion [list 0 0 [expr 16*$cellWidth] 800]
61 frame .border -bd 2 -relief raised
65 -font -*-helvetica-medium-r-*-*-14-*-*-*-*-*-*-*
67 button .quit -text "Quit" -command "exit"
68 button .next -text "Next" -command "DisplayColors next"
69 button .prev -text "Previous" -command "DisplayColors last"
71 selection handle .name GetColor
72 selection handle .rgb GetValue
75 .status config -text \
76 "Press button to write color name into primary selection"
80 .status config -text \
81 "Press button to write RGB value into primary selection"
84 .status config -text ""
88 .status config -text ""
91 bind .canvas <Enter> {
92 .status config -text \
93 "Press button 1 to change background; Button 2 changes foreground"
98 .sample 0,0 -cspan 2 -fill both -reqheight 1i \
99 .name 1,0 -fill both -anchor w \
100 .rgb 1,1 -fill both -anchor w \
101 .canvas 2,0 -cspan 2 -fill both \
102 .yscroll 2,2 -fill y \
103 .border 3,0 -cspan 2 -fill x -reqheight 8 \
104 .status 4,0 -cspan 2 -fill both \
105 .quit 4,1 -anchor e -reqwidth 1i -fill y -padx 10 -pady 4 \
106 .prev 5,0 -anchor e -reqwidth 1i -fill y -padx 10 -pady 4 \
107 .next 5,1 -anchor e -reqwidth 1i -fill y -padx 10 -pady 4
109 proc AddSelection { what } {
111 if {$what == "name" } {
112 set mesg "Color name written into primary selection"
114 set mesg "RGB value written into primary selection"
116 .status config -text $mesg
119 proc GetColor { args } {
120 return [lindex [.name config -text] 4]
123 proc GetValue { args } {
124 return [lindex [.rgb config -text] 4]
127 proc ShowInfo { tagId what info } {
130 if { $lastTagId != {} } {
131 .canvas itemconfig $lastTagId -width 1
133 .canvas itemconfig $tagId -width 3
136 set name [lindex $info 3]
137 .name config -text $name
138 set value [format "#%0.2x%0.2x%0.2x" \
139 [lindex $info 0] [lindex $info 1] [lindex $info 2]]
140 .rgb config -text $value
141 .sample config $what $name
142 .status config -bg $name
146 proc MakeCell { info } {
147 global numCols numRows maxCols cellWidth cellHeight numCells
149 set x [expr $numCols*$cellWidth]
150 set y [expr $numRows*$cellHeight]
151 set color [lindex $info 3]
153 if [catch {winfo rgb . $color}] {
156 # if { [tk colormodel .] != "color" } {
158 # .status config -text "Color table full after $numCells entries."
160 # .status config -text "Color table full after $numCells entries."
161 # return "out of colors"
163 set id [.canvas create rectangle \
164 $x $y [expr $x+$cellWidth] [expr $y+$cellHeight] \
165 -fill $color -outline black]
166 if { $color == "white" } {
171 .canvas bind $id <1> [list ShowInfo $id -bg $info]
172 .canvas bind $id <2> [list ShowInfo $id -fg $info]
175 if { $numCols > $maxCols } {
182 proc DisplayColors { how } {
183 global lastCount numCells cellHeight numRows numCols rgbText
184 global map beginInput
186 # tk colormodel . color
189 if { $how == "last" } {
193 set map [expr $map-1]
196 if ![info exists beginInput($map)] {
197 set beginInput($map) $lastCount
201 set start $beginInput($map)
203 if { $numCells > 0 } {
210 set input [lrange $rgbText $start end]
215 if { [llength $i] == 4 } {
216 if { [MakeCell $i] == "out of colors" } {
222 if { $entryCount == 0 } {
224 .status config -text "No more entries in RGB database"
226 .status config -text "No more entries in RGB database"
228 set lastCount $lineCount
229 proc tkerror {args} {
233 if { $initialized == "no" } {
236 set height [expr $cellHeight*($numRows+1)]
237 .canvas config -scrollregion [list 0 0 [expr 16*$cellWidth] $height]
238 if { $height < 800 } {
239 .canvas config -height $height
242 if [info exists whiteTagId] {
243 ShowInfo $whiteTagId -bg {255 255 255 white}
259 set file [file join $location lib X11 rgb.txt]
260 if { [file exists $file] } {
264 set in [open $file "r"]
265 set rgbText [read $in]
267 set rgbText [split $rgbText \n]