summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--library/demos/systray.tcl67
1 files changed, 50 insertions, 17 deletions
diff --git a/library/demos/systray.tcl b/library/demos/systray.tcl
index 5a26c85..a5dc79e 100644
--- a/library/demos/systray.tcl
+++ b/library/demos/systray.tcl
@@ -7,50 +7,83 @@ if {![info exists widgetDemo]} {
error "This script should be run from the \"widget\" demo."
}
-
set w .systray
destroy $w
toplevel $w
wm title $w "System Tray Demonstration"
positionWindow $w
+catch {tk systray destroy}
+set trayIconExists false
+
set iconmenu .menubar
destroy $iconmenu
menu $iconmenu
$iconmenu add command -label "Status" -command { puts "status icon clicked" }
$iconmenu add command -label "Exit" -command exit
-pack [label $w.l -text "This demonstration showcases \nthe tk systray and tk sysnotify commands\nRunning this demo creates the systray icon.\nClicking the buttons below modifies and destroys the icon\nand displays the notification."]
+pack [label $w.l -text "This demonstration showcases
+ the tk systray and tk sysnotify commands.
+ Running this demo creates the systray icon.
+ Clicking the buttons below modifies and destroys the icon
+ and displays the notification."]
image create photo book -data R0lGODlhDwAPAKIAAP//////AP8AAMDAwICAgAAAAAAAAAAAACwAAAAADwAPAAADSQhA2u5ksPeKABKSCaya29d4WKgERFF0l1IMQCAKatvBJ0OTdzzXI1xMB3TBZAvATtB6NSLKleXi3OBoLqrVgc0yv+DVSEUuFxIAOw==
-pack [button $w.b1 -text "Modify Tray Icon" -command modify]
-pack [button $w.b3 -text "Destroy Tray Icon" -command {tk systray destroy}]
-pack [button $w.b2 -text "Display Notification" -command notify]
-
-
-tk systray create -image book -text "Systray sample" -button1 {puts "foo"} -button3 {tk_popup $iconmenu [winfo pointerx .] [winfo pointery .]}
-
-
-proc modify { } {
+labelframe $w.f -text "Tray Icon"
+button $w.f.b0 -text "Create" -command create
+button $w.f.b1 -text "Modify" -command modify
+button $w.f.b2 -text "Destroy" -command remove
+pack $w.f.b0 $w.f.b1 $w.f.b2 -padx 5 -pady 3 -side left -expand true -fill x
+
+button $w.b3 -text "Display Notification" -command notify
+pack $w.f $w.b3 -expand true -fill x -padx 5 -pady 5
+
+proc create {} {
+ global trayIconExists
+ if {$trayIconExists} {
+ tk_messageBox -message "Systray icon already exists"
+ return
+ }
+ tk systray create -image book -text "Systray sample" \
+ -button1 {puts "foo"} \
+ -button3 {tk_popup $iconmenu [winfo pointerx .] [winfo pointery .]}
+ set trayIconExists true
+}
+proc modify {} {
+ global trayIconExists
+ if {!$trayIconExists} {
+ tk_messageBox -message "Please create systray icon first"
+ return
+ }
image create photo page -data R0lGODlhCwAPAKIAAP//////AMDAwICAgAAA/wAAAAAAAAAAACwAAAAACwAPAAADMzi6CzAugiAgDGE68aB0RXgRJBFVX0SNpQlUWfahQOvSsgrX7eZJMlQMWBEYj8iQchlKAAA7
-
tk systray configure -image page
tk systray configure -text "Modified text"
tk systray configure -button1 {puts "this is a different output"}
tk systray configure -button3 {puts "hello yall"}
-
}
-
proc notify {} {
+ global trayIconExists
+ if {!$trayIconExists} {
+ tk_messageBox -message "Please create systray icon first"
+ return
+ }
tk sysnotify "Alert" "This is an alert"
}
+proc remove {} {
+ global trayIconExists
+ if {!$trayIconExists} {
+ tk_messageBox -message "Systray icon was already destroyed"
+ return
+ }
+ tk systray destroy
+ set trayIconExists false
+}
+
+create
## See Code / Dismiss buttons
pack [addSeeDismiss $w.buttons $w] -side bottom -fill x
-
-
-