Sometimes you just want to drop a small toolbar or widget holder on screen without all the decorations and controls. This code minimal minimal object is about as simple as it gets.
proc gnocl::sticky { {orientation "horizontal"} } {
if { [lsearch "vertical horizontal" $orientation] == -1 } {
return -code error \
"Error! \"$orientation\" should be one of vertical or horizontal (default."
}
set box [gnocl::box -orientation $orientation \-borderWidth 0 -padding 0]
set wid [gnocl::window -decorated 0 -child $box -height 25 -width 25]
if { $orientation == "vertical"} { set tmp height} else {set tmp width}
set eBox [gnocl::eventBox -borderWidth 0 -${tmp}Request 5 -background black]
$eBox configure \
-onButtonPress { %w configure -data "%x %y" -background red} \
-onButtonRelease { %w configure -data "%x %y" -background black } \
-onMotion { %t_ configure -x [expr %X - [lindex %d 0]] -y [expr %Y - [lindex %d 1]] }
$box add $eBox -fill 1 -expand 0
rename $wid ${wid}_
# overload the basic window object
proc $wid { cmd args } {
set wid [lindex [::info level 0] 0]
switch $cmd {
remove -
add { [${wid}_ cget -child] $cmd {*}$args }
default { ${wid}_ $cmd {*}$args }
}
}
return $wid
}
Comments