Tuesday, June 12, 2012

gnocl::setStyle -new command

Gtk regards many widget properties as part of a system theme and are called 'style properties' and are not generally accessible via the Gtk+ api. The defaults for the widget can be over-ridden during run time and the loading of a resource file is an example of this. An alternative route, one in which only single changes are intended, can be taken using the new gnocl::setStyle command. This takes three arguments, the specific widget name, the style property name and the value to be assigned.  By default the widget names are NULL strings and, at present, can only be set following widget creation. One useful trick is to name the widget with its own gnocl id. The following script and screenshot show the command at work.

# test-style.tcl
exec tclsh "$0" "$@"

package require Gnocl

set ent(1) [gnocl::entry -name b1 -value "Gnocl"]
set ent(2) [gnocl::entry -name b2 -value "Gnocl"]
set ent(3) [gnocl::entry -name b3 -value "Gnocl"]

# use gnocl id as name
$ent(3) configure -name $ent(3)

puts "1 >>>[$ent(1) cget -name]"
puts "2 >>>[$ent(2) cget -name]"
puts "3 >>>[$ent(3) cget -name]"

gnocl::setStyle b1 {fg[ACTIVE]} "#FF0000"
gnocl::setStyle b1 font_name "Sans Bold 14"
gnocl::setStyle b1 {base[NORMAL]} "#FFFF00"
gnocl::setStyle b1 {text[NORMAL]} "#FF0000"
gnocl::setStyle b1 {bg[SELECTED]} "#FF0000"

gnocl::setStyle b2 font_name "Courier 14"
gnocl::setStyle b2 {text[NORMAL]} "#00FF00"
gnocl::setStyle b2 {base[NORMAL]} "#000000"

gnocl::setStyle $ent(3) {base[NORMAL]} "#0000FF"
gnocl::setStyle $ent(3) {text[NORMAL]} "#FFFFFF"

set box [gnocl::box -orientation vertical]
$box add $ent(1)
$box add $ent(2)
$box add $ent(3)

gnocl::window -child $box

No comments: