|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| class status_bar {
|
|
|
| field allow_multiple
|
|
|
| field w
|
| field w_l
|
| field w_c
|
| field c_pack
|
|
|
| field baseline_text
|
| field status_bar_text
|
|
|
| field operations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| field completed_operation_count
|
|
|
| constructor new {path} {
|
| set w $path
|
| set w_l $w.l
|
| set w_c $w.c
|
|
|
|
|
| set allow_multiple 1
|
|
|
| set baseline_text ""
|
| set operations [list]
|
| set completed_operation_count 0
|
|
|
| ttk::frame $w
|
| ttk::label $w_l \
|
| -textvariable @status_bar_text \
|
| -anchor w \
|
| -justify left
|
| pack $w_l -side left
|
| set c_pack [cb _oneline_pack]
|
|
|
| bind $w <Destroy> [cb _delete %W]
|
| return $this
|
| }
|
|
|
| method _oneline_pack {} {
|
| $w_c conf -width 100
|
| pack $w_c -side right
|
| }
|
|
|
| constructor two_line {path} {
|
| set w $path
|
| set w_l $w.l
|
| set w_c $w.c
|
|
|
|
|
| set allow_multiple 0
|
|
|
| set baseline_text ""
|
| set operations [list]
|
| set completed_operation_count 0
|
|
|
| ttk::frame $w
|
| ttk::label $w_l \
|
| -textvariable @status_bar_text \
|
| -anchor w \
|
| -justify left
|
| pack $w_l -anchor w -fill x
|
| set c_pack [list pack $w_c -fill x]
|
|
|
| bind $w <Destroy> [cb _delete %W]
|
| return $this
|
| }
|
|
|
| method ensure_canvas {} {
|
| if {[winfo exists $w_c]} {
|
| $w_c coords bar 0 0 0 20
|
| } else {
|
| canvas $w_c \
|
| -height [expr {int([winfo reqheight $w_l] * 0.6)}] \
|
| -borderwidth 1 \
|
| -relief groove \
|
| -highlightt 0
|
| $w_c create rectangle 0 0 0 20 -tags bar -fill navy
|
| eval $c_pack
|
| }
|
| }
|
|
|
| method show {msg} {
|
| $this ensure_canvas
|
| set baseline_text $msg
|
| $this refresh
|
| }
|
|
|
| method start {msg {uds {}}} {
|
| set baseline_text ""
|
|
|
| if {!$allow_multiple && [llength $operations]} {
|
| return [lindex $operations 0]
|
| }
|
|
|
| $this ensure_canvas
|
|
|
| set operation [status_bar_operation::new $this $msg $uds]
|
|
|
| lappend operations $operation
|
|
|
| $this refresh
|
|
|
| return $operation
|
| }
|
|
|
| method refresh {} {
|
| set new_text ""
|
|
|
| set total [expr $completed_operation_count * 100]
|
| set have $total
|
|
|
| foreach operation $operations {
|
| if {$new_text != ""} {
|
| append new_text " / "
|
| }
|
|
|
| append new_text [$operation get_status]
|
|
|
| set total [expr $total + 100]
|
| set have [expr $have + [$operation get_progress]]
|
| }
|
|
|
| if {$new_text == ""} {
|
| set new_text $baseline_text
|
| }
|
|
|
| set status_bar_text $new_text
|
|
|
| if {[winfo exists $w_c]} {
|
| set pixel_width 0
|
| if {$have > 0} {
|
| set pixel_width [expr {[winfo width $w_c] * $have / $total}]
|
| }
|
|
|
| $w_c coords bar 0 0 $pixel_width 20
|
| }
|
| }
|
|
|
| method stop {operation stop_msg} {
|
| set idx [lsearch $operations $operation]
|
|
|
| if {$idx >= 0} {
|
| set operations [lreplace $operations $idx $idx]
|
| set completed_operation_count [expr \
|
| $completed_operation_count + 1]
|
|
|
| if {[llength $operations] == 0} {
|
| set completed_operation_count 0
|
|
|
| destroy $w_c
|
| if {$stop_msg ne {}} {
|
| set baseline_text $stop_msg
|
| }
|
| }
|
|
|
| $this refresh
|
| }
|
| }
|
|
|
| method stop_all {{stop_msg {}}} {
|
|
|
| set operations_copy $operations
|
| set operations [list]
|
|
|
| foreach operation $operations_copy {
|
| $operation stop
|
| }
|
|
|
| if {$stop_msg ne {}} {
|
| set baseline_text $stop_msg
|
| }
|
|
|
| $this refresh
|
| }
|
|
|
| method _delete {current} {
|
| if {$current eq $w} {
|
| delete_this
|
| }
|
| }
|
|
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| class status_bar_operation {
|
|
|
| field status_bar
|
|
|
| field is_active;
|
|
|
| field status {}
|
| field progress {}
|
| field prefix {}
|
| field units {}
|
| field meter {}
|
|
|
| constructor new {owner msg uds} {
|
| set status_bar $owner
|
|
|
| set status $msg
|
| set progress 0
|
| set prefix $msg
|
| set units $uds
|
| set meter {}
|
|
|
| set is_active 1
|
|
|
| return $this
|
| }
|
|
|
| method get_is_active {} { return $is_active }
|
| method get_status {} { return $status }
|
| method get_progress {} { return $progress }
|
|
|
| method update {have total} {
|
| if {!$is_active} { return }
|
|
|
| set progress 0
|
|
|
| if {$total > 0} {
|
| set progress [expr {100 * $have / $total}]
|
| }
|
|
|
| set prec [string length [format %i $total]]
|
|
|
| set status [mc "%s ... %*i of %*i %s (%3i%%)" \
|
| $prefix \
|
| $prec $have \
|
| $prec $total \
|
| $units $progress]
|
|
|
| $status_bar refresh
|
| }
|
|
|
| method update_meter {buf} {
|
| if {!$is_active} { return }
|
|
|
| append meter $buf
|
| set r [string last "\r" $meter]
|
| if {$r == -1} {
|
| return
|
| }
|
|
|
| set prior [string range $meter 0 $r]
|
| set meter [string range $meter [expr {$r + 1}] end]
|
| set p "\\((\\d+)/(\\d+)\\)"
|
| if {[regexp ":\\s*\\d+% $p\(?:, done.\\s*\n|\\s*\r)\$" $prior _j a b]} {
|
| update $this $a $b
|
| } elseif {[regexp "$p\\s+done\r\$" $prior _j a b]} {
|
| update $this $a $b
|
| }
|
| }
|
|
|
| method stop {{stop_msg {}}} {
|
| if {$is_active} {
|
| set is_active 0
|
| $status_bar stop $this $stop_msg
|
| }
|
| }
|
|
|
| method restart {msg} {
|
| if {!$is_active} { return }
|
|
|
| set status $msg
|
| set prefix $msg
|
| set meter {}
|
| $status_bar refresh
|
| }
|
|
|
| method _delete {} {
|
| stop
|
| delete_this
|
| }
|
|
|
| }
|
|
|