blob: 591cb82ef79bcbde64467f1240067440d7537c9f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# Copyright (C) 1999-2018
# Smithsonian Astrophysical Observatory, Cambridge, MA, USA
# For conditions of distribution and use, see copyright notice in "copyright"
package provide DS9 1.0
proc slider {w from to label varname cmd {num {5}} {width {7}}} {
ttk::frame $w
ttk::scale $w.slider \
-length 300 \
-orient horizontal \
-variable $varname \
-takefocus 0 \
-command [list SliderCmd $w $varname $cmd]
ttk::label $w.label -text $label
ttk::entry $w.entry -textvariable $varname -width $width
grid $w.label -sticky w -columnspan $num
grid $w.slider -row 1 -columnspan $num -padx 2 -pady 2 -sticky news
grid $w.entry -row 1 -column $num -padx 2 -pady 2
for {set ii 0} {$ii<$num} {incr ii} {
ttk::label $w.t$ii -width $width -anchor center
grid $w.t$ii -row 2 -column $ii
grid columnconfigure $w $ii -weight 1
}
grid rowconfigure $w 1 -weight 1
grid columnconfigure $w 0 -weight 1
grid rowconfigure $w 2 -weight 1
bind $w.entry <Return> $cmd
SliderMinMax $w $from $to $num
return $w
}
proc SliderMinMax {w from to num} {
$w.slider configure -from $from -to $to
if {$from == $to} {
for {set ii 0} {$ii<$num} {incr ii} {
$w.t$ii configure -text {}
}
} else {
for {set ii 0} {$ii<$num} {incr ii} {
set vv [expr ($to*1.-$from)/($num-1)*$ii + $from]
if {[string is integer $from] && [string is integer $to]} {
set vv [expr int($vv)]
} else {
set vv [format {%.5g} $vv]
}
$w.t$ii configure -text $vv
}
}
}
proc SliderCmd {w varname cmd vv} {
upvar $varname var
set from [$w.slider cget -from]
set to [$w.slider cget -to]
if {[string is integer $from] && [string is integer $to]} {
set var [expr int($vv)]
}
if {$cmd != {}} {
eval $cmd
}
}
|