Last active
August 24, 2017 06:44
-
-
Save stanislavvv/e2afaaf7bc5359f7de1d50c05eb10a08 to your computer and use it in GitHub Desktop.
exec command and set ballon for systray icon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/wish | |
array set fonts { | |
main {-*-fixed-bold-r-*-*-13-*-*-*-*-*-iso10646-1} | |
} | |
# default command: | |
set command exec | |
lappend command curl | |
lappend command -s | |
lappend command http://wttr.in/?0&q&T | |
# re-set command by cli arguments | |
if { $::argc > 0 } { | |
set command exec | |
foreach arg $::argv { | |
lappend command $arg | |
} | |
} | |
# interval between executions of command | |
set interval 300000 | |
# icon in base64, taken from old mpd control script | |
set STOP { | |
R0lGODlhBwAHAOcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0N | |
DQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8f | |
HyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDEx | |
MTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkND | |
Q0REREVFRUZGRkdHR0hISElJSUpKSktLS0xMTE1NTU5OTk9PT1BQUFFRUVJSUlNTU1RUVFVV | |
VVZWVldXV1hYWFlZWVpaWltbW1xcXF1dXV5eXl9fX2BgYGFhYWJiYmNjY2RkZGVlZWZmZmdn | |
Z2hoaGlpaWpqamtra2xsbG1tbW5ubm9vb3BwcHFxcXJycnNzc3R0dHV1dXZ2dnd3d3h4eHl5 | |
eXp6ent7e3x8fH19fX5+fn9/f4CAgIGBgYKCgoODg4SEhIWFhYaGhoeHh4iIiImJiYqKiouL | |
i4yMjI2NjY6Ojo+Pj5CQkJGRkZKSkpOTk5SUlJWVlZaWlpeXl5iYmJmZmZqampubm5ycnJ2d | |
nZ6enp+fn6CgoKGhoaKioqOjo6SkpKWlpaampqenp6ioqKmpqaqqqqurq6ysrK2tra6urq+v | |
r7CwsLGxsbKysrOzs7S0tLW1tba2tre3t7i4uLm5ubq6uru7u7y8vL29vb6+vr+/v8DAwMHB | |
wcLCwsPDw8TExMXFxcbGxsfHx8jIyMnJycrKysvLy8zMzM3Nzc7Ozs/Pz9DQ0NHR0dLS0tPT | |
09TU1NXV1dbW1tfX19jY2NnZ2dra2tvb29zc3N3d3d7e3t/f3+Dg4OHh4eLi4uPj4+Tk5OXl | |
5ebm5ufn5+jo6Onp6erq6uvr6+zs7O3t7e7u7u/v7/Dw8PHx8fLy8vPz8/T09PX19fb29vf3 | |
9/j4+Pn5+fr6+vv7+/z8/P39/f7+/v///yH5BAEKAP8ALAAAAAAHAAcAAAgYAP8JHCgQgEGD | |
BQ8CSHiQIcJ/ChcSHBgQADs= | |
} | |
image create photo stop_img -data $STOP | |
package require tktray | |
# procedures taken from http://wiki.tcl.tk/16317 and sligthly modified | |
proc setBalloonHelp {w msg args} { | |
array set opt [concat { | |
-tag "" | |
} $args] | |
if {$msg ne ""} then { | |
set toolTipScript\ | |
[list showBalloonHelp %W [string map {% %%} $msg]] | |
set enterScript [list after 300 $toolTipScript] | |
set leaveScript [list after cancel $toolTipScript] | |
append leaveScript \n [list after 200 [list destroy .balloonHelp]] | |
} else { | |
set enterScript {} | |
set leaveScript {} | |
} | |
if {$opt(-tag) ne ""} then { | |
switch -- [winfo class $w] { | |
Text { | |
$w tag bind $opt(-tag) <Enter> $enterScript | |
$w tag bind $opt(-tag) <Leave> $leaveScript | |
} | |
Canvas { | |
$w bind $opt(-tag) <Enter> $enterScript | |
$w bind $opt(-tag) <Leave> $leaveScript | |
} | |
default { | |
bind $w <Enter> $enterScript | |
bind $w <Leave> $leaveScript | |
} | |
} | |
} else { | |
bind $w <Enter> $enterScript | |
bind $w <Leave> $leaveScript | |
} | |
} | |
proc showBalloonHelp {w msg} { | |
global ::fonts | |
set t .balloonHelp | |
catch {destroy $t} | |
toplevel $t -bg black | |
wm overrideredirect $t yes | |
if {$::tcl_platform(platform) == "macintosh"} { | |
unsupported1 style $t floating sideTitlebar | |
} | |
pack [label $t.l -text $msg -justify left -bg yellow -font $fonts(main)]\ | |
-padx 1\ | |
-pady 1 | |
set width [expr {[winfo reqwidth $t.l] + 2}] | |
set height [expr {[winfo reqheight $t.l] + 2}] | |
set xMax [expr {[winfo screenwidth $w] - $width}] | |
set yMax [expr {[winfo screenheight $w] - $height}] | |
set x [winfo pointerx $w] | |
set y [expr {[winfo pointery $w] + 20}] | |
if {$x > $xMax} then { | |
set x $xMax | |
} | |
if {$y > $yMax} then { | |
set y $yMax | |
} | |
wm geometry $t +$x+$y | |
set destroyScript [list destroy .balloonHelp] | |
bind $t <Enter> [list after cancel $destroyScript] | |
bind $t <Leave> $destroyScript | |
} | |
proc update_balloon {} { | |
global ::command | |
global ::interval | |
set result "" | |
try { | |
set result [eval $command] | |
} | |
setBalloonHelp .trayicon $result | |
after $interval update_balloon | |
} | |
tktray::icon .trayicon -class TestTray -image stop_img | |
update_balloon | |
wm withdraw . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment