gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1KB

  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. # This program demonstrates the use of the tixMeter widget -- it is
  13. # used to display the progress of a background job
  14. #
  15. proc RunSample {w} {
  16. set top [frame $w.f -bd 1 -relief raised]
  17. set box [tixButtonBox $w.b -bd 1 -relief raised]
  18. pack $box -side bottom -fill both
  19. pack $top -side top -fill both -expand yes
  20. # Create the Meter and the Label
  21. #
  22. label $top.lab -text "Work in progress ...."
  23. tixMeter $top.met -value 0 -text 0%
  24. pack $top.lab -side top -padx 50 -pady 10 -anchor c
  25. pack $top.met -side top -padx 50 -pady 10 -anchor c
  26. # Create the buttons
  27. #
  28. $box add cancel -text Cancel -command "destroy $w" \
  29. -width 6 -under 0
  30. $box add restart -text Restart -width 6 -under 0
  31. $box subwidget restart config -command \
  32. "Meter:Start $top.met [$box subwidget cancel] [$box subwidget restart]"
  33. $box subwidget restart invoke
  34. }
  35. proc Meter:Start {meter cancel restart} {
  36. $restart config -state disabled
  37. $cancel config -text Cancel
  38. after 40 Meter:BackgroundJob $meter 0 $cancel $restart
  39. }
  40. proc Meter:BackgroundJob {meter progress cancel restart} {
  41. if ![winfo exists $meter] {
  42. # the window has already been destroyed
  43. #
  44. return
  45. }
  46. set progress [expr $progress + 0.02]
  47. set text [expr int($progress*100.0)]%
  48. $meter config -value $progress -text $text
  49. if {$progress < 1.0} {
  50. after 40 Meter:BackgroundJob $meter $progress $cancel $restart
  51. } else {
  52. $cancel config -text OK -under 0
  53. $restart config -state normal
  54. }
  55. }
  56. if {![info exists tix_demo_running]} {
  57. wm withdraw .
  58. set w .demo
  59. toplevel $w; wm transient $w ""
  60. RunSample $w
  61. bind $w <Destroy> {if {"%W" == ".demo"} exit}
  62. }
上海开阖软件有限公司 沪ICP备12045867号-1