/usr/share/tcltk/tklib0.6/widget/statusbar.tcl is in tklib 0.6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | # -*- tcl -*-
#
# statusbar.tcl -
# Create a status bar Tk widget
#
# RCS: @(#) $Id: statusbar.tcl,v 1.8 2010/06/01 18:06:52 hobbs Exp $
#
# Creation and Options - widget::scrolledwindow $path ...
#
# -separator -default 1 ; show horizontal separator on top of statusbar
# -resize -default 1 ; show resize control on bottom right
# -resizeseparator -default 1 ; show separator for resize control
# ## Padding can be a list of {padx pady}
# -ipad -default 1 ; provides padding around each status bar item
# -pad -default 0 ; provides general padding around the status bar
#
# All other options to frame
#
# Methods
# $path getframe => $frame
# $path add $widget ?args? => $widget
# All other methods to frame
#
# Bindings
# NONE
#
# Provides a status bar to be placed at the bottom of a toplevel.
# Currently does not support being placed in a toplevel that has
# gridding applied (via widget -setgrid or wm grid).
#
# Ensure that the widget is placed at the very bottom of the toplevel,
# otherwise the resize behavior may behave oddly.
#
package require widget
if {0} {
proc sample {} {
# sample usage
eval destroy [winfo children .]
pack [text .t -width 0 -height 0] -fill both -expand 1
set sbar .s
widget::statusbar $sbar
pack $sbar -side bottom -fill x
set f [$sbar getframe]
# Specify -width 1 for the label widget so it truncates nicely
# instead of requesting large sizes for long messages
set w [label $f.status -width 1 -anchor w -textvariable ::STATUS]
set ::STATUS "This is a status message"
# give the entry weight, as we want it to be the one that expands
$sbar add $w -weight 1
# BWidget's progressbar
set w [ProgressBar $f.bpbar -orient horizontal \
-variable ::PROGRESS -bd 1 -relief sunken]
set ::PROGRESS 50
$sbar add $w
}
}
snit::widget widget::statusbar {
hulltype ttk::frame
component resizer
component separator
component sepresize
component frame
# -background, -borderwidth and -relief apply to outer frame, but relief
# should be left flat for proper look
delegate option * to hull
delegate method * to hull
option -separator -default 1 -configuremethod C-separator \
-type [list snit::boolean]
option -resize -default 1 -configuremethod C-resize \
-type [list snit::boolean]
option -resizeseparator -default 1 -configuremethod C-resize \
-type [list snit::boolean]
# -pad provides general padding around the status bar
# -ipad provides padding around each status bar item
# Padding can be a list of {padx pady}
option -ipad -default 2 -configuremethod C-ipad \
-type [list snit::listtype -type {snit::integer} -minlen 1 -maxlen 4]
delegate option -pad to frame as -padding
variable ITEMS -array {}
variable uid 0
constructor args {
$hull configure -height 18
install frame using ttk::frame $win.frame
install resizer using ttk::sizegrip $win.resizer
install separator using ttk::separator $win.separator \
-orient horizontal
install sepresize using ttk::separator $win.sepresize \
-orient vertical
grid $separator -row 0 -column 0 -columnspan 3 -sticky ew
grid $frame -row 1 -column 0 -sticky news
grid $sepresize -row 1 -column 1 -sticky ns;# -padx $ipadx -pady $ipady
grid $resizer -row 1 -column 2 -sticky se
grid columnconfigure $win 0 -weight 1
$self configurelist $args
}
method C-ipad {option value} {
set options($option) $value
# returns pad values - each will be a list of 2 ints
foreach {px py} [$self _padval $value] { break }
foreach w [grid slaves $frame] {
if {[string match _sep* $w]} {
grid configure $w -padx $px -pady 0
} else {
grid configure $w -padx $px -pady $py
}
}
}
method C-separator {option value} {
set options($option) $value
if {$value} {
grid $separator
} else {
grid remove $separator
}
}
method C-resize {option value} {
set options($option) $value
if {$options(-resize)} {
if {$options(-resizeseparator)} {
grid $sepresize
}
grid $resizer
} else {
grid remove $sepresize $resizer
}
}
# Use this or 'add' - but not both
method getframe {} { return $frame }
method add {what args} {
if {[winfo exists $what]} {
set w $what
set symbol $w
set ours 0
} else {
set w $frame._$what[incr uid]
set symbol [lindex $args 0]
set args [lrange $args 1 end]
if {![llength $args] || $symbol eq "%AUTO%"} {
# Autogenerate symbol name
set symbol _$what$uid
}
if {[info exists ITEMS($symbol)]} {
return -code error "item '$symbol' already exists"
}
if {$what eq "label" || $what eq "button"
|| $what eq "checkbutton" || $what eq "radiobutton"} {
set w [ttk::$what $w -style Toolbutton -takefocus 0]
} elseif {$what eq "separator"} {
set w [ttk::separator $w -orient vertical]
} elseif {$what eq "space"} {
set w [ttk::frame $w]
} else {
return -code error "unknown item type '$what'"
}
set ours 1
}
set opts(-weight) [string equal $what "space"]
set opts(-separator) 0
set opts(-sticky) news
set opts(-pad) $options(-ipad)
if {$what eq "separator"} {
# separators should not have pady by default
lappend opts(-pad) 0
}
set cmdargs [list]
set len [llength $args]
for {set i 0} {$i < $len} {incr i} {
set key [lindex $args $i]
set val [lindex $args [incr i]]
if {$key eq "--"} {
eval [list lappend cmdargs] [lrange $args $i end]
break
}
if {[info exists opts($key)]} {
set opts($key) $val
} else {
# no error - pass to command
lappend cmdargs $key $val
}
}
if {[catch {eval [linsert $cmdargs 0 $w configure]} err]} {
# we only want to destroy widgets we created
if {$ours} { destroy $w }
return -code error $err
}
set ITEMS($symbol) $w
widget::isa listofint 4 -pad $opts(-pad)
# returns pad values - each will be a list of 2 ints
foreach {px py} [$self _padval $opts(-pad)] { break }
# get cols,rows extent
foreach {cols rows} [grid size $frame] break
# Add separator if requested, and we aren't the first element
if {$opts(-separator) && $cols != 0} {
set sep [ttk::separator $frame._sep[winfo name $w] \
-orient vertical]
# No pady for separators, and adjust padx for separator space
set sx $px
if {[lindex $sx 0] < 2} { lset sx 0 2 }
lset px 1 0
grid $sep -row 0 -column $cols -sticky ns -padx $sx -pady 0
incr cols
}
grid $w -in $frame -row 0 -column $cols -sticky $opts(-sticky) \
-padx $px -pady $py
grid columnconfigure $frame $cols -weight $opts(-weight)
return $symbol
}
method remove {args} {
set destroy [string equal [lindex $args 0] "-destroy"]
if {$destroy} {
set args [lrange $args 1 end]
}
foreach sym $args {
# Should we ignore unknown (possibly already removed) items?
#if {![info exists ITEMS($sym)]} { continue }
set w $ITEMS($sym)
# separator name is based off item name
set sep $frame._sep[winfo name $w]
# destroy separator for remove or destroy case
destroy $sep
if {$destroy} {
destroy $w
} else {
grid forget $w
}
unset ITEMS($sym)
}
}
method delete {args} {
eval [linsert $args 0 $self remove -destroy]
}
method items {{ptn *}} {
# return from ordered list
if {$ptn ne "*"} {
return [array names ITEMS $ptn]
}
return [array names ITEMS]
}
method _padval {val} {
set len [llength $val]
if {$len == 0} {
return [list 0 0 0 0]
} elseif {$len == 1} {
return [list [list $val $val] [list $val $val]]
} elseif {$len == 2} {
set x [lindex $val 0] ; set y [lindex $val 1]
return [list [list $x $x] [list $y $y]]
} elseif {$len == 3} {
return [list [list [lindex $val 0] [lindex $val 2]] \
[list [lindex $val 1] [lindex $val 1]]]
} else {
return $val
}
}
}
package provide widget::statusbar 1.2.1
|