#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

if { $argc != 1 } {
   puts "usage: $argv0 socket-XID"
}

load ../src/gnocl.so

set mainBox [gnocl::box -orientation vertical]
set om [gnocl::optionMenu -command {puts "value %v"}]
$om add hallo1
$om add hallo2
$om add hallo3
$mainBox add $om

set om [gnocl::optionMenu -command {printValue %w %v ::varOp2} -variable varOp2]
$om add hallo1 -value hallo1
$om add hallo2 -value hallo2
$om add hallo3 -value hallo3
$mainBox add $om

set hbox1 [gnocl::box -orientation horizontal -label "set via var"]
set hbox2 [gnocl::box -orientation horizontal -label "set via setValue"]
foreach el {1 2 3} {
   set var "hallo$el"
   $hbox1 add [gnocl::button -text "op = $var" -command "set ::varOp2 $var"]
   $hbox2 add [gnocl::button -text "op = $var" -command "$om setValue $var"]
}
$mainBox add $hbox1
$mainBox add $hbox2


proc printValue { win val var } {
   puts -nonewline "\""
   puts -nonewline $val
   puts -nonewline "\" = \""
   puts -nonewline [$win getValue]
   puts -nonewline "\" = \""
   puts -nonewline [set $var]
   puts "\""
}

if { $argc == 1 } {
   set win [gnocl::plug [lindex $argv 0] -child $mainBox]
} else {
   set win [gnocl::window -child $mainBox]
}

gnocl::mainLoop

