panel_resize.tcl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #***************************************************************
  2. #*
  3. #* MODULE: panel_resize.tcl 1.0
  4. #*
  5. #* AUTHOR(S): ACS - Massimo Cuomo - m.cuomo at acsys.it
  6. #*
  7. #* PURPOSE: Resize panel: useful when saving images for movie
  8. #* at fixed resolution
  9. #*
  10. #*
  11. #* COPYRIGHT: (C) 2005 by the ACS / GRASS Development Team
  12. #*
  13. #* This program is free software under the
  14. #* GNU General Public License (>=v2).
  15. #* Read the file COPYING that comes with GRASS
  16. #* for details.
  17. #*
  18. #**************************************************************
  19. proc mkresizePanel {BASE} {
  20. # global Nv_
  21. catch {destroy $BASE}
  22. # Initialize panel info
  23. if [catch {set Nv_($BASE)}] {
  24. set panel [St_create {window name size priority} \
  25. $BASE "Resize Draw Area" 1 5]
  26. } else {
  27. set panel $Nv_($BASE)
  28. }
  29. frame $BASE -relief groove -borderwidth 2
  30. Nv_mkPanelname $BASE "Resize Panel"
  31. frame $BASE.top
  32. frame $BASE.bottom -bd 2 -relief groove
  33. frame $BASE.top2
  34. label $BASE.top.label -text "Resize: "
  35. pack $BASE.top.label -side left -fill y -pady 4
  36. label $BASE.top.lwidth -text width
  37. label $BASE.top.lheight -text height
  38. entry $BASE.top.width -width 6 -borderwidth 2 -relief sunken
  39. entry $BASE.top.height -width 6 -borderwidth 2 -relief sunken
  40. resize_panel_refresh $BASE.top
  41. resize_borders
  42. pack $BASE.top.lwidth $BASE.top.width $BASE.top.lheight $BASE.top.height -side left
  43. button $BASE.bottom.resize -text Resize -command "resize_togl $BASE.top"
  44. pack $BASE.bottom.resize -side left
  45. button $BASE.bottom.refresh -text Refresh -command "resize_panel_refresh $BASE.top"
  46. pack $BASE.bottom.refresh -side left
  47. button $BASE.bottom.close -text Close -command "Nv_closePanel $BASE"
  48. pack $BASE.bottom.close -side right
  49. pack $BASE.top $BASE.top2 $BASE.bottom \
  50. -expand 1 -fill both -side top
  51. return $panel
  52. }
  53. proc resize_togl {W} {
  54. global Nv_ Wborder Hborder
  55. set width [expr [$W.width get] + $Wborder]
  56. set height [expr [$W.height get] + $Hborder]
  57. # $Nv_(TOP).canvas configure -width $width
  58. # $Nv_(TOP).canvas configure -height $height
  59. wm geometry . "$width\x$height\+10+10"
  60. }
  61. proc resize_togl {W} {
  62. global Nv_ Wborder Hborder
  63. set width [expr [$W.width get] + $Wborder]
  64. set height [expr [$W.height get] + $Hborder]
  65. wm geometry . "$width\x$height\+10+10"
  66. # as border depends from absolute geometry
  67. # after first approx set, recalculate them and then
  68. # fine tune resizing again
  69. update
  70. resize_borders
  71. set width [expr [$W.width get] + $Wborder]
  72. set height [expr [$W.height get] + $Hborder]
  73. wm geometry . "$width\x$height\+10+10"
  74. update
  75. resize_panel_refresh $W
  76. }
  77. proc resize_panel_refresh {W} {
  78. global Nv_
  79. set wlst [$Nv_(TOP).canvas configure -width]
  80. set hlst [$Nv_(TOP).canvas configure -height]
  81. $W.width delete 0 end
  82. $W.height delete 0 end
  83. $W.width insert 0 [lindex $wlst 4]
  84. $W.height insert 0 [lindex $hlst 4]
  85. }
  86. proc resize_borders {} {
  87. global Nv_ Wborder Hborder
  88. set wlst [$Nv_(TOP).canvas configure -width]
  89. set hlst [$Nv_(TOP).canvas configure -height]
  90. set Wborder [expr [winfo width .] - [lindex $wlst 4]]
  91. set Hborder [expr [winfo height .] - [lindex $hlst 4]]
  92. # puts "-------------------------------- W $Wborder H $Hborder"
  93. }