summaryrefslogtreecommitdiff
path: root/lib/status_bar.tcl
blob: a6dea2900657a569fdd1047753806a9a6d194c23 (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
73
74
75
76
# git-gui status bar mega-widget
# Copyright (C) 2007 Shawn Pearce
 
class status_bar {
 
field w         ; # our own window path
field w_l       ; # text widget we draw messages into
field w_c       ; # canvas we draw a progress bar into
field status  {}; # single line of text we show
field prefix  {}; # text we format into status
field units   {}; # unit of progress
 
constructor new {path} {
	set w $path
	set w_l $w.l
	set w_c $w.c
 
	frame $w \
		-borderwidth 1 \
		-relief sunken
	label $w_l \
		-textvariable @status \
		-anchor w \
		-justify left
	pack $w_l -side left
 
	bind $w <Destroy> [cb _delete %W]
	return $this
}
 
method start {msg uds} {
	if {[winfo exists $w_c]} {
		$w_c coords bar 0 0 0 20
	} else {
		canvas $w_c \
			-width 100 \
			-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
		pack $w_c -side right
	}
 
	set status $msg
	set prefix $msg
	set units  $uds
}
 
method update {have total} {
	set pdone 0
	if {$total > 0} {
		set pdone [expr {100 * $have / $total}]
	}
 
	set status [format "%s ... %i of %i %s (%2i%%)" \
		$prefix $have $total $units $pdone]
	$w_c coords bar 0 0 $pdone 20
}
 
method stop {msg} {
	destroy $w_c
	set status $msg
}
 
method show {msg} {
	set status $msg
}
 
method _delete {current} {
	if {$current eq $w} {
		delete_this
	}
}
 
}