Posted to tcl by kbk at Tue Aug 13 21:56:44 GMT 2019view raw

  1. package require Tk 8.6
  2.  
  3. set quote {I don't really care how time is reckoned so long as there is some agreement about it, but I object to being told that I am saving daylight when my reason tells me that I am doing nothing of the kind. I even object to the implication that I am wasting something valuable if I stay in bed after the sun has risen. As an admirer of moonlight I resent the bossy insistence of those who want to reduce my time for enjoying it. At the back of the Daylight Saving scheme I detect the bony, blue-fingered hand of Puritanism, eager to push people into bed earlier, and get them up earlier, to make them healthy, wealthy and wise in spite of themselves.}
  4.  
  5.  
  6.  
  7. proc makequote {t quote} {
  8. variable quoteseq
  9. variable quotes
  10. set f .t.f[incr quoteseq($t)]
  11. set bg [.t cget -background]
  12. frame $f -background $bg -borderwidth 0 -relief flat
  13. grid [frame $f.bar -width 2 -background black] \
  14. -row 0 -column 0 -sticky ns -padx {5 10}
  15. set t2 $f.t
  16. text $t2 -background $bg -font quotefont \
  17. -relief flat -borderwidth 0 -highlightthickness 0 -wrap word
  18. bind $t2 <<WidgetViewSync>> "adjustquote %W %d"
  19. grid $t2 -row 0 -column 1 -sticky nsew
  20. grid rowconfigure $f 0 -weight 1
  21. grid columnconfigure $f 1 -weight 1
  22. grid propagate $f 0
  23. $t2 insert 1.0 $quote\n
  24. lappend quotes($t) $t2
  25. set inspt [.t index insert]
  26. .t insert $inspt \n blockquote
  27. .t window create $inspt -window $f
  28. }
  29.  
  30. proc configuretext {t w} {
  31. variable quotes
  32. if {$t ne $w} return
  33. foreach q $quotes($t) {
  34. [winfo parent $q] configure -width [expr {[winfo width $t] - 25}]
  35. }
  36.  
  37. }
  38.  
  39. proc adjustquote {q insync} {
  40. if {!$insync} return
  41. set ph [$q count -ypixels 1.0 end-1l]
  42. [winfo parent $q] configure -height [expr {$ph + 5}]
  43. }
  44.  
  45. font create quotefont -family Helvetica -size 10 -slant italic
  46.  
  47. grid [text .t -width 80 -height 25 -background white -font {Helvetica 12}\
  48. -yscrollcommand [list .y set]] \
  49. -row 0 -column 0 -sticky nsew
  50. set quotes(.t) {}
  51. bind .t <Configure> "configuretext .t %W"
  52. grid [scrollbar .y -orient vertical -command [list .t yview]] \
  53. -row 0 -column 1 -sticky nsew
  54. grid rowconfigure . 0 -weight 1
  55. grid columnconfigure . 0 -weight 1
  56.  
  57. .t insert insert "Here is an interesting quote:\n"
  58. makequote .t $quote
  59. .t insert end " -- Robertson Davies\n"
  60.  
  61. grid [ttk::sizegrip .grip] -row 1 -column 0 -columnspan 2 -sticky se