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.

136 lines
3.4KB

  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: SGrid0.tcl,v 1.3 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. # A very simple demonstration of the tixGrid widget
  13. #
  14. proc RunSample {w} {
  15. wm title $w "The First Grid Example"
  16. wm geometry $w 480x300
  17. set top [frame $w.f -bd 1 -relief raised]
  18. set box [tixButtonBox $w.b -bd 1 -relief raised]
  19. pack $box -side bottom -fill both
  20. pack $top -side top -fill both -expand yes
  21. label $top.lab -text "This widget is still under alpha
  22. Please ignore the debug messages
  23. Not all features have been implemented" -justify left
  24. pack $top.lab -side top -anchor c -padx 3 -pady 3
  25. MakeGrid $top
  26. # Create the buttons
  27. #
  28. $box add ok -text Ok -command "destroy $w" -width 6
  29. $box add cancel -text Cancel -command "destroy $w" -width 6
  30. }
  31. # This command is called whenever the background of the grid needs to
  32. # be reformatted. The x1, y1, x2, y2 specifies the four corners of the area
  33. # that needs to be reformatted.
  34. #
  35. # area:
  36. # x-margin: the horizontal margin
  37. # y-margin: the vertical margin
  38. # s-margin: the overlap area of the x- and y-margins
  39. # main: The rest
  40. #
  41. proc SimpleFormat {w area x1 y1 x2 y2} {
  42. global margin
  43. set bg(s-margin) gray65
  44. set bg(x-margin) gray65
  45. set bg(y-margin) gray65
  46. set bg(main) gray20
  47. case $area {
  48. main {
  49. # The "grid" format is consecutive boxes without 3d borders
  50. #
  51. $w format grid $x1 $y1 $x2 $y2 \
  52. -relief raised -bd 1 -bordercolor $bg($area) -filled 0 -bg red\
  53. -xon 1 -yon 1 -xoff 0 -yoff 0 -anchor se
  54. }
  55. {x-margin y-margin s-margin} {
  56. # border specifies consecutive 3d borders
  57. #
  58. $w format border $x1 $y1 $x2 $y2 \
  59. -fill 1 -relief raised -bd 1 -bg $bg($area) \
  60. -selectbackground gray80
  61. }
  62. }
  63. }
  64. # Print a number in $ format
  65. #
  66. #
  67. proc Dollar {s} {
  68. set n [string len $s]
  69. set start [expr $n % 3]
  70. if {$start == 0} {
  71. set start 3
  72. }
  73. set str ""
  74. for {set i 0} {$i < $n} {incr i} {
  75. if {$start == 0} {
  76. append str ","
  77. set start 3
  78. }
  79. incr start -1
  80. append str [string index $s $i]
  81. }
  82. return $str
  83. }
  84. proc MakeGrid {w} {
  85. # Create the grid
  86. #
  87. tixScrolledGrid $w.g -bd 0
  88. pack $w.g -expand yes -fill both -padx 3 -pady 3
  89. set grid [$w.g subwidget grid]
  90. $grid config -formatcmd "SimpleFormat $grid"
  91. # Set the size of the columns
  92. #
  93. $grid size col 0 -size 10char
  94. $grid size col 1 -size auto
  95. $grid size col 2 -size auto
  96. $grid size col 3 -size auto
  97. $grid size col 4 -size auto
  98. # set the default size of the column and rows. these sizes will be used
  99. # if the size of a row or column has not be set via the "size col ?"
  100. # command
  101. $grid size col default -size 5char
  102. $grid size row default -size 1.1char -pad0 3
  103. for {set x 0} {$x < 10} {incr x} {
  104. for {set y 0} {$y < 10} {incr y} {
  105. $grid set $x $y -itemtype text -text ($x,$y)
  106. }
  107. }
  108. }
  109. if {![info exists tix_demo_running]} {
  110. wm withdraw .
  111. set w .demo
  112. toplevel $w; wm transient $w ""
  113. RunSample $w
  114. bind $w <Destroy> exit
  115. }
上海开阖软件有限公司 沪ICP备12045867号-1