1# -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- 2# 3# $Id: Meter.tcl,v 1.4 2001/12/09 05:31:07 idiscovery Exp $ 4# 5# Tix Demostration Program 6# 7# This sample program is structured in such a way so that it can be 8# executed from the Tix demo program "widget": it must have a 9# procedure called "RunSample". It should also have the "if" statment 10# at the end of this file so that it can be run as a standalone 11# program using tixwish. 12 13# This program demonstrates the use of the tixMeter widget -- it is 14# used to display the progress of a background job 15# 16 17proc RunSample {w} { 18 set top [frame $w.f -bd 1 -relief raised] 19 set box [tixButtonBox $w.b -bd 1 -relief raised] 20 21 pack $box -side bottom -fill both 22 pack $top -side top -fill both -expand yes 23 24 # Create the Meter and the Label 25 # 26 label $top.lab -text "Work in progress ...." 27 tixMeter $top.met -value 0 -text 0% 28 29 pack $top.lab -side top -padx 50 -pady 10 -anchor c 30 pack $top.met -side top -padx 50 -pady 10 -anchor c 31 32 33 # Create the buttons 34 # 35 $box add cancel -text Cancel -command "destroy $w" \ 36 -width 6 -under 0 37 $box add restart -text Restart -width 6 -under 0 38 39 $box subwidget restart config -command \ 40 "Meter:Start $top.met [$box subwidget cancel] [$box subwidget restart]" 41 42 $box subwidget restart invoke 43} 44 45proc Meter:Start {meter cancel restart} { 46 $restart config -state disabled 47 $cancel config -text Cancel 48 after 40 Meter:BackgroundJob $meter 0 $cancel $restart 49} 50 51proc Meter:BackgroundJob {meter progress cancel restart} { 52 if ![winfo exists $meter] { 53 # the window has already been destroyed 54 # 55 return 56 } 57 58 set progress [expr $progress + 0.02] 59 set text [expr int($progress*100.0)]% 60 61 $meter config -value $progress -text $text 62 63 if {$progress < 1.0} { 64 after 40 Meter:BackgroundJob $meter $progress $cancel $restart 65 } else { 66 $cancel config -text OK -under 0 67 $restart config -state normal 68 } 69} 70 71if {![info exists tix_demo_running]} { 72 wm withdraw . 73 set w .demo 74 toplevel $w; wm transient $w "" 75 RunSample $w 76 bind $w <Destroy> {if {"%W" == ".demo"} exit} 77} 78