1# systray.tcl -- 2# 3# This demonstration script showcases the tk systray and tk sysnotify commands. 4# 5 6if {![info exists widgetDemo]} { 7 error "This script should be run from the \"widget\" demo." 8} 9 10set w .systray 11destroy $w 12toplevel $w 13wm title $w "System Tray Demonstration" 14positionWindow $w 15 16catch {tk systray destroy} 17set trayIconExists false 18 19set iconmenu .menubar 20destroy $iconmenu 21menu $iconmenu 22$iconmenu add command -label "Status" -command { puts "status icon clicked" } 23$iconmenu add command -label "Exit" -command exit 24 25pack [label $w.l -text "This demonstration showcases 26 the tk systray and tk sysnotify commands. 27 Running this demo creates the systray icon. 28 Clicking the buttons below modifies and destroys the icon 29 and displays the notification."] 30 31image create photo book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw== 32 33labelframe $w.f -text "Tray Icon" 34button $w.f.b0 -text "Create" -command create 35button $w.f.b1 -text "Modify" -command modify 36button $w.f.b2 -text "Destroy" -command remove 37pack $w.f.b0 $w.f.b1 $w.f.b2 -padx 5 -pady 3 -side left -expand true -fill x 38 39button $w.b3 -text "Display Notification" -command notify 40pack $w.f $w.b3 -expand true -fill x -padx 5 -pady 5 41 42proc create {} { 43 global trayIconExists 44 if {$trayIconExists} { 45 tk_messageBox -message "Systray icon already exists" 46 return 47 } 48 tk systray create -image book -text "Systray sample" \ 49 -button1 {puts "foo"} \ 50 -button3 {tk_popup $iconmenu [winfo pointerx .] [winfo pointery .]} 51 set trayIconExists true 52} 53 54proc modify {} { 55 global trayIconExists 56 if {!$trayIconExists} { 57 tk_messageBox -message "Please create systray icon first" 58 return 59 } 60 image create photo page -data R0lGODlhCwAPAKIAAP//////AMDAwICAgAAA/wAAAAAAAAAAACwAAAAACwAPAAADMzi6CzAugiAgDGE68aB0RXgRJBFVX0SNpQlUWfahQOvSsgrX7eZJMlQMWBEYj8iQchlKAAA7 61 tk systray configure -image page 62 tk systray configure -text "Modified text" 63 tk systray configure -button1 {puts "this is a different output"} 64 tk systray configure -button3 {puts "hello yall"} 65} 66 67proc notify {} { 68 global trayIconExists 69 if {!$trayIconExists} { 70 tk_messageBox -message "Please create systray icon first" 71 return 72 } 73 tk sysnotify "Alert" "This is an alert" 74} 75 76proc remove {} { 77 global trayIconExists 78 if {!$trayIconExists} { 79 tk_messageBox -message "Systray icon was already destroyed" 80 return 81 } 82 tk systray destroy 83 set trayIconExists false 84} 85 86create 87 88## See Code / Dismiss buttons 89pack [addSeeDismiss $w.buttons $w] -side bottom -fill x 90