The next example introduces entry widgets:
$Spc::res_h{ blsc} = "volts";
$Spc::res_h{ volts_title} = { text => "Voltages"};
foreach my $i( qw( 1 2 3 4))
{
$Spc::res_h{ "volts_io" . $i} =
{
label => { name => "U$i",
width => 12, # optional
get => sub { get_volts( "U$i");},
unit => "V"},
entry => { set => sub { set_volts( "U$i", $_[0]);}}};
}
#
# the callback functions
#
sub get_volts
{
my ( $u) = @_;
my $ret = Util::P6( Spectra::random());
print " reading $u: $ret \n";
$ret;
}
sub set_volts
{
my ( $u, $value) = @_;
print " setting $u to $value\n";
}
The widget is displayed in figure 14.3.
$Spc::res_h{ "volts_io" . $i} = { ...};
The letters 'io' select the IO widget. An IO widget is a composite widget, which is optionally made of labels, checkbuttons, selectbuttons and entry widgets. |
label => { name => "U$i", get => sub { get_volts( "U$i");}}
Creates a label widget, which has a name and an associated callback function that returns a value which is displayed by the widget. Notice that in this example 4 rows are created. Each has a different callback function. The functions differ by the values of $i.
|
entry => { set => sub { set_volts( "U$i", $_[0]);}}
Creates an entry widget. The contents is passed to the 'set' function, once the 'Exec' button is pressed.
|