| 1 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | # FILE : progressbar.tcl |
|---|
| 3 | # PURPOSE : facilitates the use of a progress bar in tcl |
|---|
| 4 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 5 | |
|---|
| 6 | namespace eval ::progressbar { |
|---|
| 7 | variable data |
|---|
| 8 | } |
|---|
| 9 | |
|---|
| 10 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 11 | proc ::progressbar::Show { {title ""} {w 20} {h 2} {tolvar {}}} { |
|---|
| 12 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 13 | variable data |
|---|
| 14 | |
|---|
| 15 | set cmd {} |
|---|
| 16 | set stop {} |
|---|
| 17 | |
|---|
| 18 | if { [llength $tolvar] } { |
|---|
| 19 | set cmd "::progressbar::AbortAndDestroy $tolvar" |
|---|
| 20 | set stop [mc "Abort"] |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | ProgressDlg .__ProgressBarDialog -title $title \ |
|---|
| 24 | -variable ::progressbar::data(var) \ |
|---|
| 25 | -textvariable ::progressbar::data(txt) \ |
|---|
| 26 | -width $w -height $h -stop $stop -command $cmd |
|---|
| 27 | wm protocol .__ProgressBarDialog WM_DELETE_WINDOW [list ::progressbar::Destroy] |
|---|
| 28 | set data(var) 0 |
|---|
| 29 | update |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 34 | proc ::progressbar::Destroy { } { |
|---|
| 35 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 36 | variable data |
|---|
| 37 | |
|---|
| 38 | destroy .__ProgressBarDialog |
|---|
| 39 | set data(var) "" |
|---|
| 40 | set data(txt) "" |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 45 | proc ::progressbar::Set { p } { |
|---|
| 46 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 47 | variable data |
|---|
| 48 | |
|---|
| 49 | set data(var) $p |
|---|
| 50 | update |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 55 | proc ::progressbar::SetText { t } { |
|---|
| 56 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 57 | variable data |
|---|
| 58 | |
|---|
| 59 | set data(txt) $t |
|---|
| 60 | update |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 65 | proc ::progressbar::AbortAndDestroy { tolvar } { |
|---|
| 66 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 67 | ::tol::console eval "Real $tolvar := (1.0)" |
|---|
| 68 | ::tol::console stack release $tolvar |
|---|
| 69 | ::progressbar::Destroy |
|---|
| 70 | } |
|---|