aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2011-01-24 22:36:36 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2011-01-24 22:36:36 +0000
commit64f0164c4a7a9b430c5c89161753161f28334b1f (patch)
treeabe049630daf7b557a848e011a4bd0fc601e4b92
parent6b9a70bcb973d931933439776f5ba87f63298b7a (diff)
added balloon help tooltips
svn path=/trunk/scripts/guiplugins/buttonbar-plugin/; revision=14815
-rw-r--r--balloonhelp.tcl97
-rw-r--r--buttonbar-plugin.tcl38
2 files changed, 118 insertions, 17 deletions
diff --git a/balloonhelp.tcl b/balloonhelp.tcl
new file mode 100644
index 0000000..71f6130
--- /dev/null
+++ b/balloonhelp.tcl
@@ -0,0 +1,97 @@
+package provide balloonhelp 0.1
+
+package require Tk
+
+namespace eval balloonhelp {
+ set mytoplevel ".balloonhelp"
+}
+
+proc ::balloonhelp::setBalloonHelp {w msg args} {
+ variable mytoplevel
+ array set opt [concat {
+ -tag ""
+ } $args]
+ if {$msg ne ""} then {
+ set toolTipScript\
+ [list balloonhelp::showBalloonHelp %W [string map {% %%} $msg]]
+ set enterScript [list after 1000 $toolTipScript]
+ set leaveScript [list after cancel $toolTipScript]
+ append leaveScript \n [list after 200 [list destroy $mytoplevel]]
+ } 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 ::balloonhelp::showBalloonHelp {w msg} {
+ variable mytoplevel
+ catch {destroy $mytoplevel}
+ toplevel $mytoplevel -bg grey
+ wm overrideredirect $mytoplevel yes
+ switch -- $::windowingsystem {
+ "aqua" {
+ wm attributes $mytoplevel -topmost 1 -transparent 1 -alpha 0.8
+ ::tk::unsupported::MacWindowStyle style $mytoplevel floating {noTitleBar noShadow}
+ }
+ "x11" {
+ wm attributes $mytoplevel -alpha 0.8
+ }
+ "win32" {
+ wm attributes $mytoplevel -topmost 1 -alpha 0.8
+ }
+ }
+ pack [label $mytoplevel.l -text [subst $msg] -bg yellow -font {Helvetica 9}]\
+ -padx 1\
+ -pady 1
+ set width [expr {[winfo reqwidth $mytoplevel.l] + 2}]
+ set height [expr {[winfo reqheight $mytoplevel.l] + 2}]
+ set xMax [expr {[winfo screenwidth $w] - $width}]
+ set yMax [expr {[winfo screenheight $w] - $height}]
+ set x [expr [winfo pointerx $w] + 5]
+ set y [expr {[winfo pointery $w] + 10}]
+ if {$x > $xMax} then {
+ set x $xMax
+ }
+ if {$y > $yMax} then {
+ set y $yMax
+ }
+ wm geometry $mytoplevel +$x+$y
+ set destroyScript [list destroy .balloonhelp]
+ bind $mytoplevel <Enter> [list after cancel $destroyScript]
+ bind $mytoplevel <Leave> $destroyScript
+}
+
+# demo
+if false {
+ pack [button .b -text tryme -command {puts "you did it!"}]
+ balloonhelp::setBalloonHelp .b "Text that describes\nwhat the button does"
+ #
+ pack [text .t -width 30 -height 5] -expand yes -fill both
+ .t insert end abcDEFghi
+ .t tag configure yellow -background yellow
+ .t tag add yellow 1.1 1.6
+ balloonhelp::setBalloonHelp .t "Colorised Text" -tag yellow
+ #
+ pack [canvas .c] -expand yes -fill both
+ set id [.c create rectangle 10 10 100 100 -fill white]
+ balloonhelp::setBalloonHelp .c {Geometry: [.c coords $::id]} -tag $id
+}
diff --git a/buttonbar-plugin.tcl b/buttonbar-plugin.tcl
index 8eafe29..c14e6e3 100644
--- a/buttonbar-plugin.tcl
+++ b/buttonbar-plugin.tcl
@@ -6,42 +6,46 @@
# menubar will be removed.
package require base64
+#package require buttonhelp
+eval [read [open [file join $::current_plugin_loadpath balloonhelp.tcl]]]
-proc make_pd_button {mytoplevel name} {
+proc make_pd_button {mytoplevel name description} {
button $mytoplevel.buttonbar.$name -image buttonimage$name \
-relief flat -borderwidth 0 -highlightthickness 0 \
-highlightcolor grey -highlightbackground grey -padx 0 -pady 0 \
-command "menu_send_float \$::focused_window $name 0"
pack $mytoplevel.buttonbar.$name -side left -padx 0 -pady 0
+ balloonhelp::setBalloonHelp $mytoplevel.buttonbar.$name $description
}
-proc make_iemgui_button {mytoplevel name} {
+proc make_iemgui_button {mytoplevel name description} {
button $mytoplevel.buttonbar.$name -image buttonimage$name \
-relief sunken -borderwidth 0 -highlightthickness 0 \
-highlightcolor grey -highlightbackground grey -padx 0 -pady 0 \
-command "menu_send \$::focused_window $name"
pack $mytoplevel.buttonbar.$name -side left -padx 0 -pady 0
+ balloonhelp::setBalloonHelp $mytoplevel.buttonbar.$name $description
}
proc showhide_buttonbar {mytoplevel} {
if { ! [winfo exists $mytoplevel.buttonbar]} {
frame $mytoplevel.buttonbar -cursor arrow -background grey \
-pady 0
- make_pd_button $mytoplevel obj
- make_pd_button $mytoplevel msg
- make_pd_button $mytoplevel floatatom
- make_pd_button $mytoplevel symbolatom
- make_pd_button $mytoplevel text
- make_iemgui_button $mytoplevel bng
- make_iemgui_button $mytoplevel toggle
- make_iemgui_button $mytoplevel numbox
- make_iemgui_button $mytoplevel hslider
- make_iemgui_button $mytoplevel vslider
- make_iemgui_button $mytoplevel hradio
- make_iemgui_button $mytoplevel vradio
- make_iemgui_button $mytoplevel vumeter
- make_iemgui_button $mytoplevel mycnv
- make_iemgui_button $mytoplevel menuarray
+ make_pd_button $mytoplevel obj {Object (obj)}
+ make_pd_button $mytoplevel msg {Message (msg)}
+ make_pd_button $mytoplevel floatatom {Number (floatatom)}
+ make_pd_button $mytoplevel symbolatom {Symbol (symbolatom)}
+ make_pd_button $mytoplevel text {Comment}
+ make_iemgui_button $mytoplevel bng {Bang Button \[bng]}
+ make_iemgui_button $mytoplevel toggle {Toggle \[tgl]}
+ make_iemgui_button $mytoplevel numbox {Number2 \[my_numbox]}
+ make_iemgui_button $mytoplevel hslider {Horizontal Slider \[hslider]}
+ make_iemgui_button $mytoplevel vslider {Verical Slider \[vslider]}
+ make_iemgui_button $mytoplevel hradio {Horizontal Radio Button \[hradio]}
+ make_iemgui_button $mytoplevel vradio {Vertical Radio Button \[vradio]}
+ make_iemgui_button $mytoplevel vumeter {VU Meter \[vumeter]}
+ make_iemgui_button $mytoplevel mycnv {Canvas \[mycnv]}
+ make_iemgui_button $mytoplevel menuarray {Array (menuarray)}
}
if {$::editmode($mytoplevel)} {
set tkcanvas [tkcanvas_name $mytoplevel]