Monday, December 20, 2010

gnocl::keyFile -getting lists of groups and keys

Today's task is now completed. Its now possible to inquire what groups are present in the .ini file and what they keynames are. The final step is to remove entries and to close any open files. Here's the test-script:

#---------------
# test-keyfile.tcl
#---------------
# William J Giddings, 28/12/2010
#---------------

#!/bin/sh
#\
exec tclsh "$0" "$@"

package require Gnocl

set kf1 [gnocl::keyFile load sample_config.ini]

puts "1 [$kf1 get value -group Person -key name]"
puts "2 [$kf1 get value -key name -group Person ]"
puts "3 [$kf1 get value -group Person -key name]"
puts "4 [$kf1 get value -key name -group Person ]"
puts "5 [$kf1 get integer -key age -group Person ]"
puts "6 [$kf1 get value -key sex -group Person ]"
puts "6 [$kf1 get value -key sex -group Person -locale UK ]"
puts "7 [$kf1 get comment -group Person -key name ]"

$kf1 set comment -group Person -key name -value "HIDI HI, HO DI HO!! HEHE"

# this will add a new group and set a specific key value
$kf1 set value -group NEW -key ENTRY -value HAPPY_CHRISTMAS

puts [$kf1 write sample_config.ini]

# 20/12/2010
# retrieve info on groups and keys
puts GROUPS>>[$kf1 get groups]
puts KEYS>>[$kf1 get keys -group Person]
puts KEYS>>[$kf1 get keys -group "Another Group"]

# extract a value and use it!
set name [$kf1 get value -group Person -key name]

gnocl::window -setSize 0.25 -child [gnocl::label -textVariable name]

No comments: