Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 909 list more trees in the spatial tab tree combobox #910

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 74 additions & 25 deletions lib/Biodiverse/GUI/Tabs/Spatial.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Biodiverse::GUI::Tabs::Spatial;
use 5.014;
use 5.026;
use strict;
use warnings;

Expand Down Expand Up @@ -479,34 +479,73 @@ sub update_dendrogram_combo {

my $combobox = $self->get_xmlpage_object('comboTreeSelect');

# Clear the curent entries.
# Clear the current entries.
# We need to load a new ListStore to avoid crashes due
# to them being destroyed somewhere in the refresh process
my $model = Gtk2::ListStore->new('Glib::String');
my $model = Gtk2::ListStore->new('Glib::String', 'Glib::Scalar');
$combobox->set_model ($model);

my $combo_items = 0;
foreach my $option ('project', 'none', 'hide panel') {
$combobox->append_text($option);
$combo_items ++;
}
# Need to work out how to italicise some of the entries.
# This code currently duplicates the text.
# my $renderer = Gtk2::CellRendererText->new();
# $combobox->pack_start($renderer, 0);
# $combobox->add_attribute($renderer, markup => 0);
# $renderer->set_visible(0);

no autovivification;
my @combo_items;

my $output_ref = $self->{output_ref};
if ($output_ref && $output_ref->can('get_embedded_tree') && $output_ref->get_embedded_tree) {
$combobox->prepend_text('analysis');
$combo_items++;
my $iter = $model->append();
$model->set( $iter, 0 => 'analysis', 1 => 'analysis' );
push @combo_items, 'analysis';
}

foreach my $option ('project', 'none', 'hide panel') {
my $iter = $model->append();
$model->set( $iter, 0 => $option, 1 => $option );
push @combo_items, $option;
}

my $list = $self->{gui}->get_project->get_phylogeny_list;
foreach my $tree (@$list) {
my $name = $tree->get_name;
my $iter = $model->append();
$model->set( $iter, 0 => $name, 1 => $tree );
}

if ($self->get_trees_are_available_to_plot) {
$combobox->set_active(0);
}
else {
# Last one is 'hide panel'
# It would be nice to extract from the model itself, if someone could work that out...
$combobox->set_active ($combo_items-1);
# It would be nice to extract from the model itself,
# if someone could work that out...
$combobox->set_active (
List::MoreUtils::firstidx {$_ eq 'hide panel'} @combo_items
);
}

state $tooltip = <<~'EOT';
Choose the tree to plot in the right hand pane.

"analysis", if visible, is the tree used in the calculations.

"project" is the currently selected tree at the project level.

"none" displays no tree but leaves the tree panel visible.

"hide panel" stops displaying the tree panel.

The remainder of the options are the trees available at
the project level. Note that this set is not updated as
trees are added to and removed from the project.
Changes can be triggered by closing and reopening the tab.
EOT
;

$combobox->set_tooltip_text ($tooltip);

return;
}

# For the phylogeny tree:
Expand Down Expand Up @@ -1850,31 +1889,41 @@ sub get_current_tree {

return if !$self->{output_ref};

my $combo = $self->get_xmlpage_object('comboTreeSelect');
my $model = $combo->get_model;
my $iter = $combo->get_active_iter;

# check combo box to choose if project phylogeny or tree used in spatial analysis
my $tree_method = $self->get_xmlpage_object('comboTreeSelect')->get_active_text();
$tree_method //= 'none';
my $choice = $model->get($iter, 1);
$choice //= 'none';

my $tree_frame = $self->get_xmlpage_object ('frame_spatial_tree_plot');

if ($tree_method eq 'hide panel') {
if ($choice eq 'hide panel') {
$tree_frame->hide;
return;
}
else {
$tree_frame->show;
}

return if $tree_method eq 'none';
$tree_frame->show;

return if $choice eq 'none';

# phylogenies
if ($tree_method eq 'analysis') {
my $tree;
if ($choice eq 'analysis') {
# get tree from spatial analysis, if possible
return if !$self->{output_ref}->can('get_embedded_tree');
return $self->{output_ref}->get_embedded_tree;
$tree = $self->{output_ref}->get_embedded_tree;
}
elsif ($choice eq 'project') {
# get tree from project
$tree = $self->{project}->get_selected_phylogeny;
}
else {
$tree = $choice;
}

# get tree from project
return $self->{project}->get_selected_phylogeny;
return $tree;
}

# Keep name in sync with the tab label
Expand Down