Saturday, November 03, 2012

Customized Tooltip Windows

Gtk allows the user to create custom tooltips which might include mixed items such as icons, images and text. The recent addition of the gnocl::tooltip command to allows such things to be done. The following test script shows how its done.

# test-tooltip.tcl
#! /bin/sh/
#\
exec tclsh "$0" "$@"
package require Gnocl


set lab(1) [ gnocl::label -text "LABEL 1" -tooltip "I'm label #1" ]
set lab(2) [ gnocl::label -text "LABEL 2" -tooltip "I'm label #2" ]
set box [gnocl::box]
$box add $lab(1) -expand 1 -fill {1 1}
$box add $lab(2) -expand 1 -fill {1 1}

set main [gnocl::window -title main -tooltip "HELLO WORLD!" -child $box -setSize 0.25]

#---------------
# create custom tooltip
#---------------
#
proc myToolTip {} {
   
    # create custom tooltip window
    set lab [gnocl::label -text HIDIHI -xPad 10]
    set im [gnocl::image -image %#About ]
    set box [gnocl::box -borderWidth 1 -shadow in]
   
    $box add $im
    $box add $lab

    # keep copy of component widget ids using -data option
    return [gnocl::window -visible 0 -type popup -child $box -backgroundColor #FBF998 -data "lab $lab im $im box $box" ]
}

set tip [myToolTip]
 
gnocl::tooltip $lab(2) -window $tip

eval [lindex [$tip cget -data] 1] configure -text HoDiHo!!!

No comments: