ttkpane.tcl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # ttkpane.tcl --
  2. #
  3. # This demonstration script creates a Ttk pane with some content.
  4. if {![info exists widgetDemo]} {
  5. error "This script should be run from the \"widget\" demo."
  6. }
  7. package require Tk
  8. set w .ttkpane
  9. catch {destroy $w}
  10. toplevel $w
  11. wm title $w "Themed Nested Panes"
  12. wm iconname $w "ttkpane"
  13. positionWindow $w
  14. ttk::label $w.msg -font $font -wraplength 4i -justify left -text "This demonstration shows off a nested set of themed paned windows. Their sizes can be changed by grabbing the area between each contained pane and dragging the divider."
  15. pack $w.msg [ttk::separator $w.msgSep] -side top -fill x
  16. ## See Code / Dismiss
  17. pack [addSeeDismiss $w.seeDismiss $w] -side bottom -fill x
  18. ttk::frame $w.f
  19. pack $w.f -fill both -expand 1
  20. set w $w.f
  21. ttk::panedwindow $w.outer -orient horizontal
  22. $w.outer add [ttk::panedwindow $w.outer.inLeft -orient vertical]
  23. $w.outer add [ttk::panedwindow $w.outer.inRight -orient vertical]
  24. $w.outer.inLeft add [ttk::labelframe $w.outer.inLeft.top -text Button]
  25. $w.outer.inLeft add [ttk::labelframe $w.outer.inLeft.bot -text Clocks]
  26. $w.outer.inRight add [ttk::labelframe $w.outer.inRight.top -text Progress]
  27. $w.outer.inRight add [ttk::labelframe $w.outer.inRight.bot -text Text]
  28. if {[tk windowingsystem] eq "aqua"} {
  29. foreach i [list inLeft.top inLeft.bot inRight.top inRight.bot] {
  30. $w.outer.$i configure -padding 3
  31. }
  32. }
  33. # Fill the button pane
  34. ttk::button $w.outer.inLeft.top.b -text "Press Me" -command {
  35. tk_messageBox -type ok -icon info -message "Ouch!" -detail "That hurt..." \
  36. -parent .ttkpane -title "Button Pressed"
  37. }
  38. pack $w.outer.inLeft.top.b -padx 2 -pady 5
  39. # Fill the clocks pane
  40. set i 0
  41. proc every {delay script} {
  42. uplevel #0 $script
  43. after $delay [list every $delay $script]
  44. }
  45. set testzones {
  46. :Europe/Berlin
  47. :America/Argentina/Buenos_Aires
  48. :Africa/Johannesburg
  49. :Europe/London
  50. :America/Los_Angeles
  51. :Europe/Moscow
  52. :America/New_York
  53. :Asia/Singapore
  54. :Australia/Sydney
  55. :Asia/Tokyo
  56. }
  57. # Force a pre-load of all the timezones needed; otherwise can end up
  58. # poor-looking synch problems!
  59. set zones {}
  60. foreach zone $testzones {
  61. if {![catch {clock format 0 -timezone $zone}]} {
  62. lappend zones $zone
  63. }
  64. }
  65. if {[llength $zones] < 2} { lappend zones -0200 :GMT :UTC +0200 }
  66. foreach zone $zones {
  67. set city [string map {_ " "} [regexp -inline {[^/]+$} $zone]]
  68. if {$i} {
  69. pack [ttk::separator $w.outer.inLeft.bot.s$i] -fill x
  70. }
  71. ttk::label $w.outer.inLeft.bot.l$i -text $city -anchor w
  72. ttk::label $w.outer.inLeft.bot.t$i -textvariable time($zone) -anchor w
  73. pack $w.outer.inLeft.bot.l$i $w.outer.inLeft.bot.t$i -fill x
  74. every 1000 "set time($zone) \[clock format \[clock seconds\] -timezone $zone -format %T\]"
  75. incr i
  76. }
  77. # Fill the progress pane
  78. ttk::progressbar $w.outer.inRight.top.progress -mode indeterminate
  79. pack $w.outer.inRight.top.progress -fill both -expand 1
  80. $w.outer.inRight.top.progress start
  81. # Fill the text pane
  82. if {[tk windowingsystem] ne "aqua"} {
  83. # The trick with the ttk::frame makes the text widget look like it fits with
  84. # the current Ttk theme despite not being a themed widget itself. It is done
  85. # by styling the frame like an entry, turning off the border in the text
  86. # widget, and putting the text widget in the frame with enough space to allow
  87. # the surrounding border to show through (2 pixels seems to be enough).
  88. ttk::frame $w.outer.inRight.bot.f -style TEntry
  89. text $w.txt -wrap word -yscroll "$w.sb set" -width 30 -borderwidth 0
  90. pack $w.txt -fill both -expand 1 -in $w.outer.inRight.bot.f -pady 2 -padx 2
  91. ttk::scrollbar $w.sb -orient vertical -command "$w.txt yview"
  92. pack $w.sb -side right -fill y -in $w.outer.inRight.bot
  93. pack $w.outer.inRight.bot.f -fill both -expand 1
  94. pack $w.outer -fill both -expand 1
  95. } else {
  96. text $w.txt -wrap word -yscroll "$w.sb set" -width 30 -borderwidth 0
  97. ttk::scrollbar $w.sb -orient vertical -command "$w.txt yview"
  98. pack $w.sb -side right -fill y -in $w.outer.inRight.bot
  99. pack $w.txt -fill both -expand 1 -in $w.outer.inRight.bot
  100. pack $w.outer -fill both -expand 1 -padx 10 -pady {6 10}
  101. }