From c599e009061af49582e619ccdeca2a749ee3ab15 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 25 Jan 2011 00:31:36 +0000 Subject: converted to use tcllib's tooltip package svn path=/trunk/scripts/guiplugins/buttonbar-plugin/; revision=14816 --- balloonhelp.tcl | 97 ----------- buttonbar-plugin.tcl | 9 +- pkgIndex.tcl | 10 ++ tooltip-1.4.2.tcl | 447 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 462 insertions(+), 101 deletions(-) delete mode 100644 balloonhelp.tcl create mode 100644 pkgIndex.tcl create mode 100644 tooltip-1.4.2.tcl diff --git a/balloonhelp.tcl b/balloonhelp.tcl deleted file mode 100644 index 71f6130..0000000 --- a/balloonhelp.tcl +++ /dev/null @@ -1,97 +0,0 @@ -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) $enterScript - $w tag bind $opt(-tag) $leaveScript - } - Canvas { - $w bind $opt(-tag) $enterScript - $w bind $opt(-tag) $leaveScript - } - default { - bind $w $enterScript - bind $w $leaveScript - } - } - } else { - bind $w $enterScript - bind $w $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 [list after cancel $destroyScript] - bind $mytoplevel $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 c14e6e3..f2975c3 100644 --- a/buttonbar-plugin.tcl +++ b/buttonbar-plugin.tcl @@ -5,9 +5,10 @@ # not in Edit Mode. Also, if a patch is switched to Run Mode, the # menubar will be removed. +lappend ::auto_path $::current_plugin_loadpath + package require base64 -#package require buttonhelp -eval [read [open [file join $::current_plugin_loadpath balloonhelp.tcl]]] +package require tooltip 1.4.2 proc make_pd_button {mytoplevel name description} { button $mytoplevel.buttonbar.$name -image buttonimage$name \ @@ -15,7 +16,7 @@ proc make_pd_button {mytoplevel name description} { -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 + ::tooltip::tooltip $mytoplevel.buttonbar.$name $description } proc make_iemgui_button {mytoplevel name description} { @@ -24,7 +25,7 @@ proc make_iemgui_button {mytoplevel name description} { -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 + ::tooltip::tooltip $mytoplevel.buttonbar.$name $description } proc showhide_buttonbar {mytoplevel} { diff --git a/pkgIndex.tcl b/pkgIndex.tcl new file mode 100644 index 0000000..ff70e2d --- /dev/null +++ b/pkgIndex.tcl @@ -0,0 +1,10 @@ +# Tcl package index file, version 1.1 +# This file is generated by the "pkg_mkIndex" command +# and sourced either when an application starts up or +# by a "package unknown" script. It invokes the +# "package ifneeded" command to set up package-related +# information so that packages will be loaded automatically +# in response to "package require" commands. When this +# script is sourced, the variable $dir must contain the +# full path name of this file's directory. +package ifneeded tooltip 1.4.2 [list source [file join $dir tooltip-1.4.2.tcl]] diff --git a/tooltip-1.4.2.tcl b/tooltip-1.4.2.tcl new file mode 100644 index 0000000..151583a --- /dev/null +++ b/tooltip-1.4.2.tcl @@ -0,0 +1,447 @@ +# ACTIVESTATE TEAPOT-PKG BEGIN TM -*- tcl -*- +# -- Tcl Module + +# @@ Meta Begin +# Package tooltip 1.4.2 +# Meta as::origin http://sourceforge.net/projects/tcllib +# Meta category Tooltip management +# Meta description Tooltip management +# Meta platform tcl +# Meta require {Tk 8.4} +# Meta require msgcat +# Meta subject hover help balloon tooltip +# Meta summary tooltip +# @@ Meta End + + + +# ACTIVESTATE TEAPOT-PKG BEGIN REQUIREMENTS + +package require Tk 8.4 +package require msgcat + +# ACTIVESTATE TEAPOT-PKG END REQUIREMENTS + +# ACTIVESTATE TEAPOT-PKG BEGIN DECLARE + +package provide tooltip 1.4.2 + +# ACTIVESTATE TEAPOT-PKG END DECLARE +# ACTIVESTATE TEAPOT-PKG END TM +# tooltip.tcl -- +# +# Balloon help +# +# Copyright (c) 1996-2007 Jeffrey Hobbs +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. +# +# RCS: @(#) $Id: tooltip.tcl,v 1.14 2008/08/08 22:50:13 patthoyts Exp $ +# +# Initiated: 28 October 1996 + + +package require Tk 8.4 +package provide tooltip 1.4.2 +package require msgcat + +#------------------------------------------------------------------------ +# PROCEDURE +# tooltip::tooltip +# +# DESCRIPTION +# Implements a tooltip (balloon help) system +# +# ARGUMENTS +# tooltip