Skip to content

Commit

Permalink
ParametersTable objects now store a hash of the label and control wid…
Browse files Browse the repository at this point in the history
…gets, indexed by parameter name.

This allows interfaces to show/hide the pairs, which is what is done for the randomisations.

Updates #76
  • Loading branch information
shawnlaffan committed Jun 11, 2016
1 parent 7bba247 commit ea9a860
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/Biodiverse/GUI/ParametersTable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ sub fill {
}

next PARAM if !$widget; # might not be putting into table (eg: using the filechooser)

my $param_name = $param->{name};

# Make the label
my $label_text = $param->{label_text} || $param->{name};
my $label_text = $param->{label_text} // $param_name;
chomp $label_text;
my $label = Gtk2::Label->new ($label_text);
$label->set_line_wrap(30);
Expand All @@ -120,7 +122,7 @@ sub fill {
$widget = Gtk2::HBox->new;
}

$label_widget_pairs{$label_text} = [$label, $widget];
$label_widget_pairs{$param_name} = [$label, $widget];

my $rows = $table->get('n-rows');

Expand Down Expand Up @@ -156,7 +158,6 @@ sub fill {
$table->set('n-rows' => $rows);
$table->attach($label, 0, 1, $rows, $rows + 1, 'fill', [], 0, 0);
$table->attach($widget, 1, 2, $rows, $rows + 1, $fill_flags, [], 0, 0);
$label_widget_pairs{$label_text} = [$label, $widget];
}

# Add a tooltip
Expand Down
17 changes: 14 additions & 3 deletions lib/Biodiverse/GUI/Tabs/Randomise.pm
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ sub on_function_changed {
my $widget_hash = ($self->{widget_hash} //= {});
my $params_hash = ($self->{params_hash} //= {});
my $metadata_cache = $self->get_metadata_cache;
my $params_table = $self->get_parameters_table;
my $label_widget_pairs_hash = $params_table->get_label_widget_pairs_hash;

# Get the Parameters metadata
my $func = $self->get_selected_function;
Expand All @@ -365,18 +367,27 @@ sub on_function_changed {
my %func_p_hash = map {$_->get_name => $_} @$params;

P_NAME:
foreach my $p_name (keys %$widget_hash) {
foreach my $p_name (keys %$label_widget_pairs_hash) {
no autovivification;

my $parameter = $params_hash->{$p_name};
my $show_hide = 'show';
my $lw = $label_widget_pairs_hash->{$p_name};
my ($label, $widget) = @$lw;

if (exists $func_p_hash{$p_name}) {
# desensitise by default, but mutable params can always be changed
my $sens = $parameter->get_mutable // $sensitise;
$parameter->set_sensitive ($sens); # needed now?
$widget_hash->{$p_name}->set_sensitive($sens);
$widget->set_sensitive($sens);
}
else {
$widget_hash->{$p_name}->set_sensitive(0);
$widget->set_sensitive(0);
$show_hide = 'hide';
}
foreach my $w ($label, $widget) {
next if !$w;
$w->$show_hide;
}
}

Expand Down

0 comments on commit ea9a860

Please sign in to comment.