Posted to tcl by patthoyts at Thu May 04 23:32:30 GMT 2006view raw

  1. # Basic winico application minimization demo
  2.  
  3. package require Tk
  4. package require Winico
  5.  
  6. namespace eval Demo {
  7. variable IconFile {}
  8. }
  9.  
  10. proc ::Demo::WinicoInit {toplevel} {
  11. if {[tk windowingsystem] eq "win32" && ![catch {package require Winico}]} {
  12. variable TaskbarIcon
  13. variable IconFile
  14. variable WinicoWmState [wm state $toplevel]
  15.  
  16. if {[file exists $IconFile]} {
  17. set TaskbarIcon [winico createfrom $IconFile]
  18. } else {
  19. set TaskbarIcon [winico load exclamation]
  20. }
  21. winico taskbar add $TaskbarIcon \
  22. -pos 0 \
  23. -text [wm title $toplevel] \
  24. -callback [list [namespace origin WinicoCallback] $toplevel %m %i]
  25. bind $toplevel <Destroy> [namespace origin WinicoCleanup]
  26. }
  27. }
  28.  
  29. proc ::Demo::WinicoCleanup {} {
  30. variable TaskbarIcon
  31. winico taskbar delete $TaskbarIcon
  32. }
  33.  
  34. proc ::Demo::WinicoCallback {toplevel msg icn} {
  35. variable WinicoWmState
  36. switch -exact -- $msg {
  37. WM_LBUTTONDOWN {
  38. if { [wm state $toplevel] eq "withdrawn" } {
  39. wm state $toplevel $WinicoWmState
  40. wm deiconify $toplevel
  41. } else {
  42. set WinicoWmState [wm state $toplevel]
  43. wm withdraw $toplevel
  44. }
  45. }
  46. }
  47. }
  48.  
  49. proc ::Demo::Main {} {
  50. #wm withdraw .
  51. wm title . "Winico Minimization Demo"
  52. pack [button .b -text Exit -command {set ::forever 1}]
  53. WinicoInit .
  54. bind . <Control-F2> {console show}
  55. set ::forever 0
  56. tkwait variable ::forever
  57. }
  58.  
  59. if {!$tcl_interactive} {
  60. set r [catch [linsert $argv 0 ::Demo::Main] err]
  61. if {$r} { tk_messageBox -icon error -message $err }
  62. exit
  63. }
  64.  
  65.