Improved metadirective handling
[tcl-tlc.git] / scripts / tooltips.itk
blob9e27385e6a588a4d2b6437ce3538223b8a109ffe
1 # vim: foldmarker=<<<,>>> foldmethod=marker ft=tcl ts=4 shiftwidth=4
3 class tlc::Tooltips {
4         constructor {args} {}
5         destructor {}
7         public {
8                 variable tooltipdelay   1000
9                 variable tooltiptimeout 5500
11                 method set_tips {args}
12         }
14         protected {
15                 variable tiptargets
17                 method path {key}
18         }
20         private {
21                 variable hoverbox
22         }
26 configbody tlc::Tooltips::tooltipdelay { #<<<1
27         $hoverbox configure -delay $tooltipdelay
31 configbody tlc::Tooltips::tooltiptimeout { #<<<1
32         $hoverbox configure -showtime $tooltiptimeout
36 body tlc::Tooltips::constructor {args} { #<<<1
37         array set tiptargets {}
39         set hoverbox    [tlc::Hoverbox .tooltips#auto]
43 body tlc::Tooltips::destructor {} { #<<<1
44         if {[info exists hoverbox] && [winfo exists $hoverbox]} {
45                 destroy $hoverbox
46                 unset hoverbox
47         }
51 body tlc::Tooltips::set_tips {args} { #<<<1
52         if {[llength $args] == 1} {
53                 # Support the variant syntax of one item packed with all the tips
54                 # (for convenience)
55                 set args        [lindex $args 0]
56         }
57         foreach {label tip} $args {
58                 set widget      [path $label]
59                 if {$tip != ""} {
60                         $hoverbox attach $widget $tip
61                 } else {
62                         $hoverbox detach $widget
63                 }
64         }
68 body tlc::Tooltips::path {key} { #<<<1
69         if {![info exists tiptargets($key)]} {
70                 error "Invalid key: ($key)"
71         }
73         return $tiptargets($key)