Commit cdaf4100 authored by Stefan Tauner's avatar Stefan Tauner
Browse files

FIJISettingsViewer: split updating widgets' values from validation

This makes sure that validation uses the correct values.
Otherwise the validation of checkbuttons may overwrite the values
of depending entries.
parent 4cbbcc63
......@@ -201,13 +201,13 @@ sub update {
}
my $const_cnt = @design_widgets;
my $net_choices = defined($self->{'nets'}) ? $self->{'nets'} : [];
my $dut_port_choices = defined($self->{'netlist'}) ? $self->{'netlist'}->get_toplevel_port_names("i") : [];
# Update widgets' values depending on their type
for (my $i = 0 ; $i < $const_cnt ; $i += 3) {
# The order of the widgets depends on their *construction* time(!)
my ($namew, $unitw, $valw) = @design_widgets[$i .. $i + 3];
my ($namew, $unitw, $val_w) = @design_widgets[$i .. $i + 3];
my $name = $namew->{'fiji_id'};
# get DESIGNMAP key from stored INI Field name
......@@ -228,66 +228,67 @@ sub update {
}
$logger->trace("Connect widget ($name) with new settings instance hash ($k)");
my $orig_ref = \$self->{'settings'}->{'design'}->{$k};
my $type = DESIGNMAP->{$k}->{'type'};
my $orig = $$orig_ref;
my $val = defined($type) && ($type eq 'hexadecimal' || $type eq 'lfsrpoly') ? sprintf("0x%x", $orig) : $orig;
my $autocomplete_choices;
my $val_ref = \$self->{'settings'}->{'design'}->{$k};
my $type = DESIGNMAP->{$k}->{'type'};
$val_ref = \(sprintf("0x%x", $$val_ref)) if ($type eq 'hexadecimal' || $type eq 'lfsrpoly');
if (defined $type) {
if (ref($val_w) eq 'Tk::CompleteEntry') {
# Update CompleteEntry Fields with the new choices if defined
if ($type eq 'dut_port') {
$autocomplete_choices = $dut_port_choices;
} elsif ($type eq 'lfsrpoly') {
$orig_ref = \$val;
$val_w->configure('-choices' => $dut_port_choices,);
}
$val_w->configure('-textvariable' => $val_ref);
} elsif (ref($val_w) eq 'Tk::Checkbutton') {
# Set fields depending on checkbuttons, check if checkbutton forbids another
$val_w->configure('-variable' => $val_ref);
} elsif (ref($val_w) eq 'Tk::Optionmenu') {
$val_w->configure('-textvariable' => $val_ref);
} elsif (ref($val_w) eq 'Tk::Frame') {
# Tk::Frames need a little extra work, because the design widget is a child widget
if ($type eq 'dir' || $type eq 'file') {
# If the frame is a 'dir' type Frame, it contains an "open" button as child 0
# and a readonly entry field for the path as child 1
(($val_w->children)[1])->configure('-text' => $$val_ref);
} elsif ($type eq 'net') {
my $entry = ($val_w->children)[1];
$entry->configure('-textvariable' => $val_ref);
}
} else {
$val_w->configure('-textvariable' => $val_ref);
}
}
# Validate the new settings
for (my $i = 0 ; $i < $const_cnt ; $i += 3) {
# The order of the widgets depends on their *construction* time(!)
my ($namew, $unitw, $val_w) = @design_widgets[$i .. $i + 3];
my $name = $namew->{'fiji_id'};
my $k = FIJI::ini2constkey($name);
my $type = DESIGNMAP->{$k}->{'type'};
# Update widgets depending on their type
# FIXME: use isa() instead?
if (ref($valw) eq 'Tk::CompleteEntry') {
if (ref($val_w) eq 'Tk::Checkbutton') {
# Update CompleteEntry Fields with the new choices if defined
$valw->configure(
'-choices' => $autocomplete_choices,
)
if defined($autocomplete_choices);
$valw->configure('-textvariable' => $orig_ref);
my $valid = $valw->validate();
} elsif (ref($valw) eq 'Tk::Checkbutton') {
# Set fields depending on checkbuttons, check if checkbutton forbids another
$valw->configure('-variable' => $orig_ref);
# Check if checkbutton forbids another
if (defined($self->{'depends'}->{$k}) && defined($self->{'forbidden_by'}->{$k})) {
$valw->configure('-command' => [\&_set_fields_by_button, $self, $valw, $self->{'depends'}->{$k}, $self->{'forbidden_by'}->{$k}]);
$val_w->configure('-command' => [\&_set_fields_by_button, $self, $val_w, $self->{'depends'}->{$k}, $self->{'forbidden_by'}->{$k}]);
} elsif (defined($self->{'depends'}->{$k})) {
$valw->configure('-command' => [\&_set_fields_by_button, $self, $valw, $self->{'depends'}->{$k}, []]);
$val_w->configure('-command' => [\&_set_fields_by_button, $self, $val_w, $self->{'depends'}->{$k}, []]);
} elsif (defined($self->{'forbidden_by'}->{$k})) {
$valw->configure('-command' => [\&_set_fields_by_button, $self, $valw, [], $self->{'forbidden_by'}->{$k}]);
$val_w->configure('-command' => [\&_set_fields_by_button, $self, $val_w, [], $self->{'forbidden_by'}->{$k}]);
}
_set_fields_by_button($self, $valw, $self->{'depends'}->{$k}, $self->{'forbidden_by'}->{$k});
} elsif (ref($valw) eq 'Tk::Optionmenu') {
$valw->configure('-textvariable' => $orig_ref);
} elsif (ref($valw) eq 'Tk::Frame' && defined($type)) {
# Tk::Frames need a little extra work, because the design widget is
# a child widget.
if ($type eq 'dir' || $type eq 'file') {
# If the frame is a 'dir' type Frame, it contains an "open" button as child 0
# and a readonly entry field for the path as child 1
(($valw->children)[1])->configure('-text' => (defined $val) ? $val : "");
} elsif ($type eq 'net') {
my $entry = ($valw->children)[1];
$entry->configure('-textvariable' => $orig_ref);
_set_fields_by_button($self, $val_w, $self->{'depends'}->{$k}, $self->{'forbidden_by'}->{$k});
} elsif (ref($val_w) eq 'Tk::Frame') {
if ($type eq 'net') {
my $entry = ($val_w->children)[1];
$entry->validate();
}
} else {
if (defined($val)) {
$valw->configure('-text' => $val);
} else {
$valw->delete('0', 'end');
}
my $valid = $valw->validate();
my $valid = $val_w->validate() if (ref($val_w) ne 'Tk::Optionmenu');
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment