blob: 6954143cbd198105a86194ae24274c188edd627d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# systray.tcl --
#
# This demonstration script showcases the tk systray and tk sysnotify commands.
#
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
## See Code / Dismiss buttons
pack [addSeeDismiss $w.buttons $w] -side bottom -fill x
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
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==
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 3p -pady 3p -side left -expand true -fill x
button $w.b3 -text "Display Notification" -command notify
pack $w.f $w.b3 -fill x -padx 3p -pady 3p
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
|