Posted to tcl by Emiliano at Wed Jan 23 14:34:21 GMT 2008view raw

  1. package require Tk
  2. package require tile
  3. ttk::setTheme clam
  4.  
  5. proc add.instance { {title {}} } {
  6. global NB state
  7.  
  8. set inst inst[format %04d $state(ID)]
  9.  
  10. set pw [ttk::panedwindow $NB.$inst -orient vertical]
  11.  
  12. # add the upper text
  13. set fup [ttk::frame $pw.up -padding 2]
  14. set txt [add.text $fup]
  15.  
  16. #the lower text
  17. set fdown [ttk::frame $pw.down -padding 2]
  18. set peer [add.text $fdown $txt]
  19. # we want the lower pane to be hidden
  20. grid propagate $fdown 0
  21.  
  22. #in the case of resize, the upper pane should take all the space
  23. $pw add $fup -weight 1
  24. $pw add $fdown -weight 0
  25.  
  26. if {$title eq ""} {
  27. set title "Untitled-$state(ID)"
  28. }
  29.  
  30. $NB insert end $pw -text $title
  31.  
  32. set state($inst.txt) $txt
  33. set state($inst.peer) $peer
  34. set state($inst.filename) {}
  35. set state($inst.modified) 0
  36. set state($inst.title) $title
  37.  
  38. incr state(ID)
  39. }
  40.  
  41. proc add.text { parent {peerof {}} } {
  42. set vs [ttk::scrollbar $parent.vs -orient vertical]
  43. set hs [ttk::scrollbar $parent.hs -orient horizontal]
  44.  
  45. if {$peerof eq ""} {
  46. set t [text $parent.txt \
  47. -yscrollcommand [list $vs set] \
  48. -xscrollcommand [list $hs set]]
  49. } else {
  50. set t [$peerof peer create $parent.txt \
  51. -yscrollcommand [list $vs set] \
  52. -xscrollcommand [list $hs set]]
  53. }
  54.  
  55. $vs configure -command [list $t yview]
  56. $hs configure -command [list $t xview]
  57.  
  58. grid $t $vs -sticky news
  59. grid $hs -sticky news
  60. grid columnconfigure $parent 0 -weight 1
  61. grid rowconfigure $parent 0 -weight 1
  62.  
  63. return $t
  64. }
  65.  
  66. proc build.gui {} {
  67. global NB
  68.  
  69. set NB [ttk::notebook .nb]
  70.  
  71. pack $NB -expand 1 -fill both
  72.  
  73. option add *Text.background white
  74. option add *Text.highlightThickness 0
  75. option add *Text.borderWidth 1
  76. option add *Text.selectBorderWidth 0
  77. }
  78.  
  79. proc init {} {
  80. global state
  81. set state(ID) 0
  82. }
  83.  
  84. init
  85. build.gui
  86. add.instance
  87.  
  88. bind all <Control-t> add.instance
  89.  
  90. #after pressing ctrl-t, no new tab is shown inmediately
  91. #it *shows* after a while or after resizing the main window
  92.  

Comments

Posted by jenglish at Tue Feb 05 03:39:40 GMT 2008 [text] [code]

Filed as SF bug #1878298; fixed in CVS 2008-01-29