1
# ----------------------------------------------------------------------------
3
# This file is part of Unifix BWidget Toolkit
4
# ----------------------------------------------------------------------------
6
# - ProgressBar::create
7
# - ProgressBar::configure
9
# - ProgressBar::_destroy
10
# - ProgressBar::_modify
11
# ----------------------------------------------------------------------------
13
namespace eval ProgressBar {
14
Widget::define ProgressBar progressbar
16
Widget::declare ProgressBar {
18
{normal incremental infinite nonincremental_infinite}}
19
{-maximum Int 100 0 "%d >= 0"}
20
{-background TkResource "" 0 frame}
21
{-foreground TkResource "blue" 0 label}
22
{-borderwidth TkResource 2 0 frame}
23
{-troughcolor TkResource "" 0 scrollbar}
24
{-relief TkResource sunken 0 label}
25
{-orient Enum horizontal 1 {horizontal vertical}}
26
{-variable String "" 0}
28
{-width TkResource 100 0 frame}
29
{-height TkResource 4m 0 frame}
30
{-bg Synonym -background}
31
{-fg Synonym -foreground}
32
{-bd Synonym -borderwidth}
35
Widget::addmap ProgressBar "" :cmd {-background {} -width {} -height {}}
36
Widget::addmap ProgressBar "" .bar {
37
-troughcolor -background -borderwidth {} -relief {}
44
# ----------------------------------------------------------------------------
45
# Command ProgressBar::create
46
# ----------------------------------------------------------------------------
47
proc ProgressBar::create { path args } {
50
array set maps [list ProgressBar {} :cmd {} .bar {}]
51
array set maps [Widget::parseArgs ProgressBar $args]
52
eval frame $path $maps(:cmd) -class ProgressBar -bd 0 \
53
-highlightthickness 0 -relief flat
54
Widget::initFromODB ProgressBar $path $maps(ProgressBar)
56
set c [eval [list canvas $path.bar] $maps(.bar) -highlightthickness 0]
57
set fg [Widget::cget $path -foreground]
58
if { [string equal [Widget::cget $path -orient] "horizontal"] } {
59
$path.bar create rectangle -1 0 0 0 -fill $fg -outline $fg -tags rect
61
$path.bar create rectangle 0 1 0 0 -fill $fg -outline $fg -tags rect
64
set _widget($path,val) 0
65
set _widget($path,dir) 1
66
set _widget($path,var) [Widget::cget $path -variable]
67
if {$_widget($path,var) != ""} {
68
GlobalVar::tracevar variable $_widget($path,var) w \
69
[list ProgressBar::_modify $path]
70
set _widget($path,afterid) \
71
[after idle [list ProgressBar::_modify $path]]
74
bind $path.bar <Destroy> [list ProgressBar::_destroy $path]
75
bind $path.bar <Configure> [list ProgressBar::_modify $path]
77
return [Widget::create ProgressBar $path]
81
# ----------------------------------------------------------------------------
82
# Command ProgressBar::configure
83
# ----------------------------------------------------------------------------
84
proc ProgressBar::configure { path args } {
87
set res [Widget::configure $path $args]
89
if { [Widget::hasChangedX $path -variable] } {
90
set newv [Widget::cget $path -variable]
91
if { $_widget($path,var) != "" } {
92
GlobalVar::tracevar vdelete $_widget($path,var) w \
93
[list ProgressBar::_modify $path]
96
set _widget($path,var) $newv
97
GlobalVar::tracevar variable $newv w \
98
[list ProgressBar::_modify $path]
99
if {![info exists _widget($path,afterid)]} {
100
set _widget($path,afterid) \
101
[after idle [list ProgressBar::_modify $path]]
104
set _widget($path,var) ""
108
foreach {cbd cor cma} [Widget::hasChangedX $path -borderwidth \
109
-orient -maximum] break
111
if { $cbd || $cor || $cma } {
112
if {![info exists _widget($path,afterid)]} {
113
set _widget($path,afterid) \
114
[after idle [list ProgressBar::_modify $path]]
117
if { [Widget::hasChangedX $path -foreground] } {
118
set fg [Widget::cget $path -foreground]
119
$path.bar itemconfigure rect -fill $fg -outline $fg
125
# ----------------------------------------------------------------------------
126
# Command ProgressBar::cget
127
# ----------------------------------------------------------------------------
128
proc ProgressBar::cget { path option } {
129
return [Widget::cget $path $option]
133
# ----------------------------------------------------------------------------
134
# Command ProgressBar::_modify
135
# ----------------------------------------------------------------------------
136
proc ProgressBar::_modify { path args } {
139
catch {unset _widget($path,afterid)}
140
if { ![GlobalVar::exists $_widget($path,var)] ||
141
[set val [GlobalVar::getvar $_widget($path,var)]] < 0 } {
142
catch {place forget $path.bar}
144
place $path.bar -relx 0 -rely 0 -relwidth 1 -relheight 1
145
set type [Widget::getoption $path -type]
146
if { $val != 0 && $type != "normal" && \
147
$type != "nonincremental_infinite"} {
148
set val [expr {$val+$_widget($path,val)}]
150
set _widget($path,val) $val
151
set max [Widget::getoption $path -maximum]
152
set bd [expr {2*[$path.bar cget -bd]}]
153
set w [winfo width $path.bar]
154
set h [winfo height $path.bar]
155
if {$type == "infinite" || $type == "nonincremental_infinite"} {
156
# JDC: New infinite behaviour
157
set tval [expr {$val % $max}]
158
if { $tval < ($max / 2.0) } {
159
set x0 [expr {double($tval) / double($max) * 1.5}]
161
set x0 [expr {(1.0-(double($tval) / double($max))) * 1.5}]
163
set x1 [expr {$x0 + 0.25}]
164
if {[Widget::getoption $path -orient] == "horizontal"} {
165
$path.bar coords rect [expr {$x0*$w}] 0 [expr {$x1*$w}] $h
167
$path.bar coords rect 0 [expr {$h-$x0*$h}] $w \
171
if { $val > $max } {set val $max}
172
if {[Widget::getoption $path -orient] == "horizontal"} {
173
$path.bar coords rect -1 0 [expr {$val*$w/$max}] $h
175
$path.bar coords rect 0 [expr {$h+1}] $w \
176
[expr {$h*(1.0 - double($val)/$max)}]
180
if {![Widget::cget $path -idle]} {
186
# ----------------------------------------------------------------------------
187
# Command ProgressBar::_destroy
188
# ----------------------------------------------------------------------------
189
proc ProgressBar::_destroy { path } {
192
if {[info exists _widget($path,afterid)]} {
193
after cancel $_widget($path,afterid)
194
unset _widget($path,afterid)
196
if {[info exists _widget($path,var)]} {
197
if {$_widget($path,var) != ""} {
198
GlobalVar::tracevar vdelete $_widget($path,var) w \
199
[list ProgressBar::_modify $path]
201
unset _widget($path,var)
203
unset _widget($path,dir)
204
Widget::destroy $path