One possible way to implement a simple toolbar. Should be self-explaining.
See also recipe poAppFrame for an example application framework, where this package is used.
Have fun
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # poToolbar.tcl
# Simple package to implement a toolbar.
# Paul Obermeier, 2001.
package provide poToolbar 1.0
namespace eval ::poToolbar {
namespace export AddGroup
namespace export AddButton
namespace export AddCheckButton
variable groupNum
}
proc ::poToolbar::Init {} {
variable groupNum
set groupNum 1
}
proc ::poToolbar::AddGroup { w } {
variable groupNum
if { ![info exists groupNum]} {
Init
}
set newFrame $w.fr$groupNum
frame $newFrame -relief raised -borderwidth 1
pack $newFrame -side left -fill y
incr groupNum
return $newFrame
}
proc ::poToolbar::AddButton { btnName bmpData cmd str args } {
variable groupNum
if { ![info exists groupNum]} {
Init
}
if { [string compare $bmpData ""] == 0 } {
eval button $btnName -relief flat -takefocus 0 \
-command [list $cmd] $args
} else {
set img [image create bitmap -data $bmpData]
eval button $btnName -image $img -relief flat \
-takefocus 0 \
-command [list $cmd] $args
}
::poToolhelp::AddBinding $btnName $str
pack $btnName -side left
}
proc ::poToolbar::AddCheckButton { btnName bmpData cmd str args } {
variable groupNum
if { ![info exists groupNum]} {
Init
}
if { [string compare $bmpData ""] == 0 } {
eval checkbutton $btnName -relief flat -indicatoron 0 \
-takefocus 0 -command [list $cmd] $args
} else {
set img [image create bitmap -data $bmpData]
eval checkbutton $btnName -image $img -relief flat -indicatoron 0 \
-takefocus 0 -command [list $cmd] $args
}
::poToolhelp::AddBinding $btnName $str
pack $btnName -side left
}
catch {puts "Loaded Package poToolbar (File [info script])"}
|
Tags: binding