Posted to tcl by emiliano at Fri Sep 04 18:20:47 GMT 2009view raw

  1. #!/usr/bin/env tclsh
  2.  
  3. package require Tk
  4. package require tile
  5. ttk::style theme use alt
  6.  
  7. # ----------------------------------------------------------------
  8. proc p.makewindow {} {
  9. eval destroy [winfo children .]
  10. catch { destroy .topw error_topw }
  11. set ::topw [ toplevel .topw -background #c0c0c0 ]
  12. wm withdraw .
  13. wm geometry $::topw 400x200+20+20
  14. wm resizable $::topw 1 1
  15. set _captionText prototype
  16. wm title $::topw Prototype
  17. }
  18.  
  19. # ----------------------------------------------------------------
  20. proc p.makemenus {} {
  21.  
  22. # PREPARE MENU...
  23. $::topw configure -menu $::topw.menubar
  24. menu $::topw.menubar -font {Arial 13} -bd 1 -tearoff 0
  25.  
  26. # BUILD TOP ROW...
  27. $::topw.menubar add cascade \
  28. -menu $::topw.menubar.file \
  29. -label File -font {Arial 13} \
  30. -underline 0
  31. menu $::topw.menubar.file \
  32. -title File -font {Arial 13} \
  33. -tearoff 0
  34.  
  35. $::topw.menubar.file add command \
  36. -label Exit -command exit
  37. }
  38.  
  39. # ----------------------------------------------------------------
  40. proc p.maketext {} {
  41.  
  42. ttk::frame $::topw.parenttextframe -padding 0
  43. set ::parenttext $::topw.parenttextframe.parenttext
  44. text $::parenttext
  45. $::parenttext configure -setgrid true
  46. $::parenttext configure -wrap word
  47. $::parenttext configure -yscrollcommand "$::topw.parenttextframe.vscroll set"
  48. $::parenttext configure -background #ffffff -foreground #000000
  49. $::parenttext configure -font {Arial 15}
  50. $::parenttext configure -exportselection 1
  51. $::parenttext configure -state normal
  52. $::parenttext configure -undo 1
  53.  
  54. ttk::scrollbar $::topw.parenttextframe.vscroll -orient vertical -command [list $::parenttext yview]
  55.  
  56. ttk::frame $::topw.status -padding 0
  57. ttk::label $::topw.status.bar1
  58. $::topw.status.bar1 configure -font {Arial 13}
  59. $::topw.status.bar1 configure -background #c0c0c0
  60. $::topw.status.bar1 configure -foreground #000000
  61. $::topw.status.bar1 configure -relief ridge
  62. $::topw.status.bar1 configure -anchor w
  63. $::topw.status.bar1 configure -text "Status bar"
  64.  
  65. pack $::topw.parenttextframe -fill both -expand 1
  66. pack $::parenttext -side left -fill both -expand 1
  67. pack $::topw.parenttextframe.vscroll -side right -fill y
  68.  
  69. pack $::topw.status -fill both -expand 0
  70. pack $::topw.status.bar1 -side left -fill both -expand 1
  71.  
  72.  
  73. set ::popup $::parenttext.popuptext
  74. text $::popup
  75. $::popup configure -setgrid true
  76. $::popup configure -wrap word
  77. $::popup configure -background #FF8080 -foreground #000000
  78. $::popup configure -font {Arial 15}
  79. $::popup configure -height 2
  80.  
  81. }
  82.  
  83. # ----------------------------------------------------------------
  84. p.makewindow
  85. p.makemenus
  86. p.maketext
  87.  
  88. # ----------------------------------------------------------------
  89. bind $parenttext <Key-F1> { appear }
  90. bind $parenttext <Key-F2> { disappear }
  91.  
  92. # ----------------------------------------------------------------
  93. proc appear {} {
  94. $::popup delete 1.0 end
  95. $::parenttext window create insert -window $::popup
  96. $::popup insert end "Why doesn't this popup appear at the current line instead of at the top?"
  97. }
  98.  
  99. proc disappear {} {
  100. $::popup delete 1.0 end
  101. $::parenttext window configure $::popup -window {}
  102. }
  103.  
  104. # ----------------------------------------------------------------
  105. $::parenttext insert end "Move the caret around the text and press F1 and F2.\n\n"
  106. for {set i 1} {$i <= 20} {incr i} {
  107. $::parenttext insert end "This is a sample paragraph, just meant to fill up the text widget with some text.\n\n"
  108. }
  109. focus $::parenttext
  110. $::parenttext mark set insert 1.end
  111.  
  112.  
  113.