From b1782e20ab6de03af6488cbcef8c979be024a370 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Tue, 2 Jan 2024 19:18:19 +1100 Subject: [PATCH 01/41] GUI spatial tabs: Add menu to export currently displayed tree --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 43 ++++++++++++++++++++++++ lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm | 1 + 2 files changed, 44 insertions(+) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 7fe14d457..d7ce97c70 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -337,12 +337,55 @@ sub new { $self->{menubar} = $self->get_xmlpage_object('menubar_spatial'); $self->update_export_menu; + $self->update_tree_menu; say "[Spatial tab] - Loaded tab - Spatial Analysis"; return $self; } +sub update_tree_menu { + my $self = shift; + + my $menubar = $self->{menubar}; + my $output_ref = $self->{output_ref}; + + # Clear out old entries from menu so we can rebuild it. + # This will be useful when we add checks for which export methods are valid. + my $tree_menu = $self->{tree_menu}; + + if (!$tree_menu) { + $tree_menu = Gtk2::MenuItem->new_with_label('Tree'); + $menubar->append($tree_menu); + $self->{tree_menu} = $tree_menu; + } + + if (!$output_ref || ($output_ref->get_param('COMPLETED') // 1) != 1) { + # completed == 2 for clusters analyses with matrices only + $tree_menu->set_sensitive(0); + } + else { + my $submenu = Gtk2::Menu->new; + + my $menu_item = Gtk2::MenuItem->new('Export'); + $menu_item->set_has_tooltip(1); + $menu_item->set_tooltip_text ('Export the currently displayed tree'); + $submenu->append($menu_item); + $menu_item->signal_connect_swapped( + activate => sub { + my $tree_ref = $self->get_current_tree; + return Biodiverse::GUI::Export::Run($tree_ref); + }, + ); + + $tree_menu->set_submenu($submenu); + $tree_menu->set_sensitive(1); + } + + $menubar->show_all(); +} + + # doesn't work yet sub screenshot { diff --git a/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm b/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm index 9b3707399..382e4593f 100644 --- a/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm +++ b/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm @@ -218,6 +218,7 @@ sub new { $self->{menubar} = $self->get_xmlpage_object('menubar_spatial'); $self->update_export_menu; + $self->update_tree_menu; # debug stuff $self->{selected_list} = 'SUBELEMENTS'; From d60f19d80810fa9d04ca9322ef73c5bcec8bdf80 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Tue, 2 Jan 2024 19:53:12 +1100 Subject: [PATCH 02/41] GUI: store colours on tree when highlighting nbr sets Also ensure we update the tree side menu when an analysis has been run. --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index d7ce97c70..a52b89aa4 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -349,6 +349,7 @@ sub update_tree_menu { my $menubar = $self->{menubar}; my $output_ref = $self->{output_ref}; + return if !$output_ref; # Clear out old entries from menu so we can rebuild it. # This will be useful when we add checks for which export methods are valid. @@ -360,7 +361,7 @@ sub update_tree_menu { $self->{tree_menu} = $tree_menu; } - if (!$output_ref || ($output_ref->get_param('COMPLETED') // 1) != 1) { + if (($output_ref->get_param('COMPLETED') // 1) != 1) { # completed == 2 for clusters analyses with matrices only $tree_menu->set_sensitive(0); } @@ -1539,6 +1540,7 @@ sub on_run { $self->{initialising_grid} = 0; $self->update_export_menu; + $self->update_tree_menu; $self->{project}->set_dirty; @@ -1700,6 +1702,10 @@ sub highlight_paths_on_dendrogram { : $colour; $dendrogram->highlight_node ($node_ref, $colour_ref); + $dendrogram->set_node_colour( + colour_ref => $colour_ref, + node_name => $node_name, + ); $done{$node_name}[$idx]++; @@ -1785,6 +1791,10 @@ sub colour_branches_on_dendrogram { : COLOUR_BLACK; $dendrogram->highlight_node ($node_ref, $colour_ref); + $dendrogram->set_node_colour( + colour_ref => $colour_ref, + node_name => $node_name, + ); $done{$node_name}++; From df1114d010107c98758f5eb31d48d79bb315bf00 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Tue, 2 Jan 2024 19:53:25 +1100 Subject: [PATCH 03/41] Dendrogram.pm: simplify some code --- lib/Biodiverse/GUI/Dendrogram.pm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Biodiverse/GUI/Dendrogram.pm b/lib/Biodiverse/GUI/Dendrogram.pm index 0cd9c3087..3973d316e 100644 --- a/lib/Biodiverse/GUI/Dendrogram.pm +++ b/lib/Biodiverse/GUI/Dendrogram.pm @@ -1145,14 +1145,17 @@ sub clear_node_colours { $self->{node_colours_cache} = {}; my $tree = $self->get_tree_object(); - if($tree) { - foreach my $node ($tree->get_node_refs()) { - $self->set_node_colour( - node_name => $node->get_name(), - colour_ref => DEFAULT_LINE_COLOUR, - ); - } + + return if !$tree; + + foreach my $node ($tree->get_node_refs()) { + $self->set_node_colour( + node_name => $node->get_name(), + colour_ref => DEFAULT_LINE_COLOUR, + ); } + + return; } sub set_node_colour { From 68a3a64918da3c09ba65657deeaaf91d9e89745a Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Tue, 2 Jan 2024 21:05:23 +1100 Subject: [PATCH 04/41] Legend.pm: add a set_visible method --- lib/Biodiverse/GUI/Legend.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Biodiverse/GUI/Legend.pm b/lib/Biodiverse/GUI/Legend.pm index d0081a1c6..730d97ccc 100644 --- a/lib/Biodiverse/GUI/Legend.pm +++ b/lib/Biodiverse/GUI/Legend.pm @@ -150,6 +150,21 @@ sub show { return; } +sub set_visible { + my ($self, $check) = @_; + + return if !$self->{legend_group}; + + if ($check) { + $self->{legend_group}->show; + } + else { + $self->{legend_group}->hide; + } + + return; +} + # Makes a rectangle and fills it # with colours for the chosen legend # mode. From 5985a2d176390eeb2f330e44ea42d352fc276e3c Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Tue, 2 Jan 2024 21:08:01 +1100 Subject: [PATCH 05/41] GUI Spatial tab: start moving menu items into tree menu --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 43 ++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index a52b89aa4..4febb0adb 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -290,7 +290,6 @@ sub new { menuitem_spatial_tree_colour_mode_sat => {toggled => \&on_tree_colour_mode_changed}, menuitem_spatial_tree_colour_mode_grey => {toggled => \&on_tree_colour_mode_changed}, - menuitem_spatial_tree_show_legend => {toggled => \&on_show_tree_legend_changed}, ); # bodge - should set the radio group @@ -368,6 +367,40 @@ sub update_tree_menu { else { my $submenu = Gtk2::Menu->new; + my @menu_items = ( + { + type => 'Gtk2::CheckMenuItem', + label => 'Show legend', + tooltip => 'Show or hide the legend on the tree plot (if one is relevant)', + event => 'toggled', + callback => \&on_show_tree_legend_changed, + active => 1, + self_key => 'checkbox_show_legend', + } + ); + + foreach my $item (@menu_items) { + my $type = $item->{type} // 'Gtk2::MenuItem'; + my $menu_item = $type->new($item->{label}); + if (my $key = $item->{self_key}) { + $self->{$key} = $menu_item, + } + if (my $tooltip = $item->{tooltip}) { + $menu_item->set_has_tooltip(1); + $menu_item->set_tooltip_text($tooltip); + } + if (exists $item->{active}) { + $menu_item->set_active($item->{active}); + } + if (my $callback = $item->{callback}) { + $menu_item->signal_connect_swapped( + $item->{event} => $callback, + $item->{callback_args} // $self + ); + } + $submenu->append($menu_item); + } + my $menu_item = Gtk2::MenuItem->new('Export'); $menu_item->set_has_tooltip(1); $menu_item->set_tooltip_text ('Export the currently displayed tree'); @@ -565,8 +598,6 @@ sub init_branch_colouring_menu { my $label = Gtk2::Label->new('Branch colouring: '); - my $checkbox_show_legend - = $self->get_xmlpage_object('menuitem_spatial_tree_show_legend'); $menubar = Gtk2::MenuBar->new; my $menu = Gtk2::Menu->new; my $menuitem = Gtk2::MenuItem->new_with_label('Branch colouring: '); @@ -575,7 +606,9 @@ sub init_branch_colouring_menu { my $menu_action = sub { my $args = shift; my ($self, $listname, $output_ref) = @$args; - if ($checkbox_show_legend->get_active) { + my $chk_show_legend = $self->{checkbox_show_legend}; + my $show_legend = $chk_show_legend ? $chk_show_legend->get_active : 1; + if ($show_legend) { $self->{dendrogram}->update_legend; # need dendrogram to pass on coords $self->{dendrogram}->get_legend->show; } @@ -1757,7 +1790,7 @@ sub colour_branches_on_dendrogram { my @minmax_args = ($min, $max); my $colour_method = $legend->get_colour_method; - my $checkbox_show_legend = $self->get_xmlpage_object('menuitem_spatial_tree_show_legend'); + my $checkbox_show_legend = $self->{checkbox_show_legend}; if ($checkbox_show_legend->get_active) { $dendrogram->update_legend; # need dendrogram to pass on coords $legend->show; From 334340062794cb6c50df590d8a980e416b31ae8c Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Tue, 2 Jan 2024 21:49:34 +1100 Subject: [PATCH 06/41] GUI spatial tab: reset branch colours when hover ends Otherwise we were ending up with a mix of colours from different colouring systems. This was missed when storing colours in commit d60f19d80810fa9d04ca9322ef73c5bcec8bdf80 --- lib/Biodiverse/GUI/Dendrogram.pm | 12 +++++++++--- lib/Biodiverse/GUI/Tabs/Spatial.pm | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/Biodiverse/GUI/Dendrogram.pm b/lib/Biodiverse/GUI/Dendrogram.pm index 3973d316e..0a4706374 100644 --- a/lib/Biodiverse/GUI/Dendrogram.pm +++ b/lib/Biodiverse/GUI/Dendrogram.pm @@ -263,6 +263,11 @@ sub destroy { return; } +# makes it available outside the class +sub get_default_line_colour { + DEFAULT_LINE_COLOUR(); +} + ########################################################## # The Slider ########################################################## @@ -1852,7 +1857,7 @@ sub replay_multiselect_store { # Remove any existing highlights sub clear_highlights { - my $self = shift; + my ($self, $new_colour) = @_; # set all nodes to recorded/default colour return if !$self->{highlighted_lines}; @@ -1862,8 +1867,9 @@ sub clear_highlights { my $line = $self->{node_lines}{$node_name}; next if !$line; my $colour_ref - = $self->get_node_colour_aa ( $node_name ) - || DEFAULT_LINE_COLOUR; + = $new_colour + || $self->get_node_colour_aa ( $node_name ) + || DEFAULT_LINE_COLOUR; $line->set(fill_color_gdk => $colour_ref); } $self->{highlighted_lines} = undef; diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 4febb0adb..1a6a14d02 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -1834,7 +1834,7 @@ sub colour_branches_on_dendrogram { $node_ref = $node_ref->get_parent; } } - + } sub on_end_grid_hover { @@ -1842,7 +1842,7 @@ sub on_end_grid_hover { my $dendrogram = $self->{dendrogram} // return; - $dendrogram->clear_highlights; + $dendrogram->clear_highlights ($dendrogram->get_default_line_colour); } sub get_trees_are_available_to_plot { From 679256f031a3e24c9cf1cdd10ae40821b44e9fd2 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 10:19:11 +1100 Subject: [PATCH 07/41] GUI spatial tab: side menu toggles branch colour log scale --- bin/ui/hboxSpatialPage.ui | 2 ++ lib/Biodiverse/GUI/Tabs/Spatial.pm | 31 ++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/bin/ui/hboxSpatialPage.ui b/bin/ui/hboxSpatialPage.ui index 0fecb64cc..a7054a797 100644 --- a/bin/ui/hboxSpatialPage.ui +++ b/bin/ui/hboxSpatialPage.ui @@ -483,6 +483,7 @@ Colours are scaled using percentiles defined in the colour stretch menu. True + True diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 1a6a14d02..729dc562e 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -350,8 +350,6 @@ sub update_tree_menu { my $output_ref = $self->{output_ref}; return if !$output_ref; - # Clear out old entries from menu so we can rebuild it. - # This will be useful when we add checks for which export methods are valid. my $tree_menu = $self->{tree_menu}; if (!$tree_menu) { @@ -375,8 +373,21 @@ sub update_tree_menu { event => 'toggled', callback => \&on_show_tree_legend_changed, active => 1, - self_key => 'checkbox_show_legend', - } + self_key => 'checkbox_show_tree_legend', + }, + { + type => 'Gtk2::CheckMenuItem', + label => 'Log scale', + tooltip => "Log scale the colours.\n" + . "Uses the min and max determined by the Colour stretch choice.", + event => 'toggled', + callback => sub { + my ($self, $menuitem) = @_; + $self->{use_tree_log_scale} = $menuitem->get_active; + }, + active => 1, + self_key => 'checkbox_log_tree_legend', + }, ); foreach my $item (@menu_items) { @@ -393,9 +404,10 @@ sub update_tree_menu { $menu_item->set_active($item->{active}); } if (my $callback = $item->{callback}) { + my $args = $item->{callback_args}; $menu_item->signal_connect_swapped( $item->{event} => $callback, - $item->{callback_args} // $self + $args // $self ); } $submenu->append($menu_item); @@ -606,7 +618,7 @@ sub init_branch_colouring_menu { my $menu_action = sub { my $args = shift; my ($self, $listname, $output_ref) = @$args; - my $chk_show_legend = $self->{checkbox_show_legend}; + my $chk_show_legend = $self->{checkbox_show_tree_legend}; my $show_legend = $chk_show_legend ? $chk_show_legend->get_active : 1; if ($show_legend) { $self->{dendrogram}->update_legend; # need dendrogram to pass on coords @@ -1770,8 +1782,7 @@ sub colour_branches_on_dendrogram { index => '', ); - my $log_check_box = $self->get_xmlpage_object('menuitem_spatial_tree_log_scale'); - $legend->set_log_mode($log_check_box->get_active); + $legend->set_log_mode($self->{use_tree_log_scale}); my $flip_check_box = $self->get_xmlpage_object('menuitem_spatial_tree_colour_stretch_flip_mode'); $legend->set_invert_colours ($flip_check_box->get_active); @@ -1790,8 +1801,8 @@ sub colour_branches_on_dendrogram { my @minmax_args = ($min, $max); my $colour_method = $legend->get_colour_method; - my $checkbox_show_legend = $self->{checkbox_show_legend}; - if ($checkbox_show_legend->get_active) { + my $checkbox_show_tree_legend = $self->{checkbox_show_tree_legend}; + if ($checkbox_show_tree_legend->get_active) { $dendrogram->update_legend; # need dendrogram to pass on coords $legend->show; } From 21c578bd669f62d2990a2932cce1b88974d1d05e Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 10:27:39 +1100 Subject: [PATCH 08/41] GUI spatial tab: side menu toggles branch colour flipping --- bin/ui/hboxSpatialPage.ui | 3 ++- lib/Biodiverse/GUI/Tabs/Spatial.pm | 29 +++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/bin/ui/hboxSpatialPage.ui b/bin/ui/hboxSpatialPage.ui index a7054a797..79f7790ba 100644 --- a/bin/ui/hboxSpatialPage.ui +++ b/bin/ui/hboxSpatialPage.ui @@ -506,7 +506,7 @@ Uses the min and max determined by the Colour stretch choice. True ---> + True @@ -517,6 +517,7 @@ Uses the min and max determined by the Colour stretch choice. False +--> True diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 729dc562e..54f2fafca 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -386,8 +386,31 @@ sub update_tree_menu { $self->{use_tree_log_scale} = $menuitem->get_active; }, active => 1, - self_key => 'checkbox_log_tree_legend', + # self_key => 'checkbox_log_tree_legend', }, + # + # + # True + # False + # Invert colour stretch + # Invert (flip) the colour range. Has no effect on categorical colouring. + # True + # False + # + # + { + type => 'Gtk2::CheckMenuItem', + label => 'Invert colour stretch', + tooltip => "Invert (flip) the colour range. Has no effect on categorical colouring.", + event => 'toggled', + callback => sub { + my ($self, $menuitem) = @_; + $self->{tree_invert_colours} = $menuitem->get_active; + }, + active => 0, + # self_key => 'invert_tree_colours', + }, + ); foreach my $item (@menu_items) { @@ -1783,9 +1806,7 @@ sub colour_branches_on_dendrogram { ); $legend->set_log_mode($self->{use_tree_log_scale}); - - my $flip_check_box = $self->get_xmlpage_object('menuitem_spatial_tree_colour_stretch_flip_mode'); - $legend->set_invert_colours ($flip_check_box->get_active); + $legend->set_invert_colours ($self->{tree_invert_colours}); my $listref = $output_ref->get_list_ref ( list => $list_name, From 6af78c4d818c0eddf8447e948bdf76f4c16a07df Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 10:37:56 +1100 Subject: [PATCH 09/41] GUI spatial tab: side menu handles tree line widths --- bin/ui/hboxSpatialPage.ui | 2 ++ lib/Biodiverse/GUI/Tabs/Spatial.pm | 25 ++++++++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/bin/ui/hboxSpatialPage.ui b/bin/ui/hboxSpatialPage.ui index 79f7790ba..46093ddea 100644 --- a/bin/ui/hboxSpatialPage.ui +++ b/bin/ui/hboxSpatialPage.ui @@ -559,6 +559,7 @@ Uses the min and max determined by the Colour stretch choice. + diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 54f2fafca..cb826bd39 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -282,7 +282,7 @@ sub new { menuitem_spatial_undef_cell_colour => {activate => \&on_set_undef_cell_colour}, menuitem_spatial_cell_show_outline => {toggled => \&on_set_cell_show_outline}, menuitem_spatial_show_legend => {toggled => \&on_show_hide_legend}, - menuitem_spatial_set_tree_line_widths => {activate => \&on_set_tree_line_widths}, + # menuitem_spatial_set_tree_line_widths => {activate => \&on_set_tree_line_widths}, button_spatial_options => {clicked => \&run_options_dialogue}, @@ -386,18 +386,7 @@ sub update_tree_menu { $self->{use_tree_log_scale} = $menuitem->get_active; }, active => 1, - # self_key => 'checkbox_log_tree_legend', }, - # - # - # True - # False - # Invert colour stretch - # Invert (flip) the colour range. Has no effect on categorical colouring. - # True - # False - # - # { type => 'Gtk2::CheckMenuItem', label => 'Invert colour stretch', @@ -408,9 +397,15 @@ sub update_tree_menu { $self->{tree_invert_colours} = $menuitem->get_active; }, active => 0, - # self_key => 'invert_tree_colours', }, - + { + type => 'Gtk2::MenuItem', + label => 'Set tree branch line widths', + tooltip => "Set the width of the tree branches.\n" + . "Does not affect the vertical connectors.", + event => 'activate', + callback => \&on_set_tree_line_widths, + }, ); foreach my $item (@menu_items) { @@ -423,7 +418,7 @@ sub update_tree_menu { $menu_item->set_has_tooltip(1); $menu_item->set_tooltip_text($tooltip); } - if (exists $item->{active}) { + if ($type =~ 'Check|Radio' && exists $item->{active}) { $menu_item->set_active($item->{active}); } if (my $callback = $item->{callback}) { From e8a9e6bb87638c907d0227e1bdbde59bafccc372 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 10:42:41 +1100 Subject: [PATCH 10/41] GUI spatial tab: add separator to side menu before tree export --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index cb826bd39..6cf06497c 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -406,11 +406,18 @@ sub update_tree_menu { event => 'activate', callback => \&on_set_tree_line_widths, }, + { + type => 'Gtk2::SeparatorMenuItem' + }, ); foreach my $item (@menu_items) { my $type = $item->{type} // 'Gtk2::MenuItem'; - my $menu_item = $type->new($item->{label}); + my $menu_item = $type->new($item->{label} // ()); + $submenu->append($menu_item); + + next if $type =~ /Separator/; + if (my $key = $item->{self_key}) { $self->{$key} = $menu_item, } @@ -428,7 +435,6 @@ sub update_tree_menu { $args // $self ); } - $submenu->append($menu_item); } my $menu_item = Gtk2::MenuItem->new('Export'); From e4a1fc8bb485d4653922f667026b210e2cb70ed3 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 10:49:25 +1100 Subject: [PATCH 11/41] GUI spatial tab: move tree side-menu export to builder hash --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 6cf06497c..3f76d34aa 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -409,6 +409,16 @@ sub update_tree_menu { { type => 'Gtk2::SeparatorMenuItem' }, + { + type => 'Gtk2::MenuItem', + label => 'Export', + tooltip => 'Export the currently displayed tree', + event => 'activate', + callback => sub { + my $tree_ref = $self->get_current_tree; + return Biodiverse::GUI::Export::Run($tree_ref); + }, + }, ); foreach my $item (@menu_items) { @@ -436,18 +446,7 @@ sub update_tree_menu { ); } } - - my $menu_item = Gtk2::MenuItem->new('Export'); - $menu_item->set_has_tooltip(1); - $menu_item->set_tooltip_text ('Export the currently displayed tree'); - $submenu->append($menu_item); - $menu_item->signal_connect_swapped( - activate => sub { - my $tree_ref = $self->get_current_tree; - return Biodiverse::GUI::Export::Run($tree_ref); - }, - ); - + $tree_menu->set_submenu($submenu); $tree_menu->set_sensitive(1); } From 0d802f8b91f399ab0fcba3788fdaa1d2446a0f6a Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 11:16:04 +1100 Subject: [PATCH 12/41] GUI spatial tab: refactor side menu builder into method --- lib/Biodiverse/GUI/Dendrogram.pm | 2 + lib/Biodiverse/GUI/Tabs/Spatial.pm | 60 +++++++++++++++++------------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/lib/Biodiverse/GUI/Dendrogram.pm b/lib/Biodiverse/GUI/Dendrogram.pm index 0a4706374..2470df796 100644 --- a/lib/Biodiverse/GUI/Dendrogram.pm +++ b/lib/Biodiverse/GUI/Dendrogram.pm @@ -855,6 +855,8 @@ sub set_branch_line_width { my ($self, $val) = @_; my $current = $self->get_branch_line_width; + $val ||= 0; + $self->{branch_line_width} = $val; if ($current != $val && $self->{tree_node}) { diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 3f76d34aa..e45a582a6 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -421,32 +421,11 @@ sub update_tree_menu { }, ); - foreach my $item (@menu_items) { - my $type = $item->{type} // 'Gtk2::MenuItem'; - my $menu_item = $type->new($item->{label} // ()); - $submenu->append($menu_item); - - next if $type =~ /Separator/; + $self->_add_items_to_menu ( + menu => $submenu, + items => \@menu_items, + ); - if (my $key = $item->{self_key}) { - $self->{$key} = $menu_item, - } - if (my $tooltip = $item->{tooltip}) { - $menu_item->set_has_tooltip(1); - $menu_item->set_tooltip_text($tooltip); - } - if ($type =~ 'Check|Radio' && exists $item->{active}) { - $menu_item->set_active($item->{active}); - } - if (my $callback = $item->{callback}) { - my $args = $item->{callback_args}; - $menu_item->signal_connect_swapped( - $item->{event} => $callback, - $args // $self - ); - } - } - $tree_menu->set_submenu($submenu); $tree_menu->set_sensitive(1); } @@ -454,7 +433,38 @@ sub update_tree_menu { $menubar->show_all(); } +sub _add_items_to_menu { + my ($self, %args) = @_; + my @menu_items = @{$args{items}}; + my $submenu = $args{menu}; + foreach my $item (@menu_items) { + my $type = $item->{type} // 'Gtk2::MenuItem'; + my $menu_item = $type->new($item->{label} // ()); + $submenu->append($menu_item); + + next if $type =~ /Separator/; + + if (my $key = $item->{self_key}) { + $self->{$key} = $menu_item, + } + if (my $tooltip = $item->{tooltip}) { + $menu_item->set_has_tooltip(1); + $menu_item->set_tooltip_text($tooltip); + } + if ($type =~ 'Check|Radio' && exists $item->{active}) { + $menu_item->set_active($item->{active}); + } + if (my $callback = $item->{callback}) { + my $args = $item->{callback_args}; + $menu_item->signal_connect_swapped( + $item->{event} => $callback, + $args // $self + ); + } + } + +} # doesn't work yet sub screenshot { From c6bf98c131a12c54e5399ad3918dd94d7e4b4089 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 12:00:57 +1100 Subject: [PATCH 13/41] GUI spatial tab: add colour mode to side menu And remove it from the display menu. --- bin/ui/hboxSpatialPage.ui | 4 +- lib/Biodiverse/GUI/Tabs/Spatial.pm | 64 +++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/bin/ui/hboxSpatialPage.ui b/bin/ui/hboxSpatialPage.ui index 46093ddea..57930d19c 100644 --- a/bin/ui/hboxSpatialPage.ui +++ b/bin/ui/hboxSpatialPage.ui @@ -469,6 +469,7 @@ Colours are scaled using percentiles defined in the colour stretch menu. True + True @@ -559,7 +558,6 @@ Uses the min and max determined by the Colour stretch choice. - From 7f3c96341727a955fd96c5ce08682d0adf713da3 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 12:06:22 +1100 Subject: [PATCH 15/41] GUI spatial tab: refactor side menu items into a method --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 168 +++++++++++++++-------------- 1 file changed, 87 insertions(+), 81 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 58ccdf4e0..0a59adc6c 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -359,89 +359,9 @@ sub update_tree_menu { else { my $submenu = Gtk2::Menu->new; - my @menu_items = ( - { - type => 'Gtk2::CheckMenuItem', - label => 'Show legend', - tooltip => 'Show or hide the legend on the tree plot (if one is relevant)', - event => 'toggled', - callback => \&on_show_tree_legend_changed, - active => 1, - self_key => 'checkbox_show_tree_legend', - }, - { - type => 'Gtk2::CheckMenuItem', - label => 'Log scale', - tooltip => "Log scale the colours.\n" - . "Uses the min and max determined by the Colour stretch choice.", - event => 'toggled', - callback => sub { - my ($self, $menuitem) = @_; - $self->{use_tree_log_scale} = $menuitem->get_active; - }, - active => 1, - }, - { - type => 'Gtk2::CheckMenuItem', - label => 'Invert colour stretch', - tooltip => "Invert (flip) the colour range. Has no effect on categorical colouring.", - event => 'toggled', - callback => sub { - my ($self, $menuitem) = @_; - $self->{tree_invert_colours} = $menuitem->get_active; - }, - active => 0, - }, - { - type => 'submenu_radio_group', - label => 'Colour mode', - items => [ # could be refactored - { - type => 'Gtk2::RadioMenuItem', - label => 'Hue', - event => 'activate', - callback => \&on_tree_colour_mode_changed, - }, - { - type => 'Gtk2::RadioMenuItem', - label => 'Sat...', - event => 'activate', - callback => \&on_tree_colour_mode_changed, - }, - { - type => 'Gtk2::RadioMenuItem', - label => 'Grey', - event => 'activate', - callback => \&on_tree_colour_mode_changed, - } - ], - }, - { - type => 'Gtk2::MenuItem', - label => 'Set tree branch line widths', - tooltip => "Set the width of the tree branches.\n" - . "Does not affect the vertical connectors.", - event => 'activate', - callback => \&on_set_tree_line_widths, - }, - { - type => 'Gtk2::SeparatorMenuItem' - }, - { - type => 'Gtk2::MenuItem', - label => 'Export', - tooltip => 'Export the currently displayed tree', - event => 'activate', - callback => sub { - my $tree_ref = $self->get_current_tree; - return Biodiverse::GUI::Export::Run($tree_ref); - }, - }, - ); - $self->_add_items_to_menu ( menu => $submenu, - items => \@menu_items, + items => scalar $self->get_tree_menu_items, ); $tree_menu->set_submenu($submenu); @@ -451,6 +371,92 @@ sub update_tree_menu { $menubar->show_all(); } +sub get_tree_menu_items { + my $self = shift; + + my @menu_items = ( + { + type => 'Gtk2::CheckMenuItem', + label => 'Show legend', + tooltip => 'Show or hide the legend on the tree plot (if one is relevant)', + event => 'toggled', + callback => \&on_show_tree_legend_changed, + active => 1, + self_key => 'checkbox_show_tree_legend', + }, + { + type => 'Gtk2::CheckMenuItem', + label => 'Log scale', + tooltip => "Log scale the colours.\n" + . "Uses the min and max determined by the Colour stretch choice.", + event => 'toggled', + callback => sub { + my ($self, $menuitem) = @_; + $self->{use_tree_log_scale} = $menuitem->get_active; + }, + active => 1, + }, + { + type => 'Gtk2::CheckMenuItem', + label => 'Invert colour stretch', + tooltip => "Invert (flip) the colour range. Has no effect on categorical colouring.", + event => 'toggled', + callback => sub { + my ($self, $menuitem) = @_; + $self->{tree_invert_colours} = $menuitem->get_active; + }, + active => 0, + }, + { + type => 'submenu_radio_group', + label => 'Colour mode', + items => [ # could be refactored + { + type => 'Gtk2::RadioMenuItem', + label => 'Hue', + event => 'activate', + callback => \&on_tree_colour_mode_changed, + }, + { + type => 'Gtk2::RadioMenuItem', + label => 'Sat...', + event => 'activate', + callback => \&on_tree_colour_mode_changed, + }, + { + type => 'Gtk2::RadioMenuItem', + label => 'Grey', + event => 'activate', + callback => \&on_tree_colour_mode_changed, + } + ], + }, + { + type => 'Gtk2::MenuItem', + label => 'Set tree branch line widths', + tooltip => "Set the width of the tree branches.\n" + . "Does not affect the vertical connectors.", + event => 'activate', + callback => \&on_set_tree_line_widths, + }, + { + type => 'Gtk2::SeparatorMenuItem' + }, + { + type => 'Gtk2::MenuItem', + label => 'Export', + tooltip => 'Export the currently displayed tree', + event => 'activate', + callback => sub { + my $tree_ref = $self->get_current_tree; + return Biodiverse::GUI::Export::Run($tree_ref); + }, + }, + ); + + return wantarray ? @menu_items : \@menu_items; +} + sub _add_items_to_menu { my ($self, %args) = @_; my @menu_items = @{$args{items}}; From 4460ccdbe97c635303a777ec42e523291f80a2b5 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 12:16:37 +1100 Subject: [PATCH 16/41] GUI SpatialMatrix tab: subset side menu items --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 8 +++++--- lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm | 9 ++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 0a59adc6c..efd67d700 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -338,12 +338,14 @@ sub new { } sub update_tree_menu { - my $self = shift; + my ($self, $menu_items) = @_; my $menubar = $self->{menubar}; my $output_ref = $self->{output_ref}; return if !$output_ref; + $menu_items ||= $self->get_tree_menu_items; + my $tree_menu = $self->{tree_menu}; if (!$tree_menu) { @@ -361,7 +363,7 @@ sub update_tree_menu { $self->_add_items_to_menu ( menu => $submenu, - items => scalar $self->get_tree_menu_items, + items => $menu_items, ); $tree_menu->set_submenu($submenu); @@ -440,7 +442,7 @@ sub get_tree_menu_items { callback => \&on_set_tree_line_widths, }, { - type => 'Gtk2::SeparatorMenuItem' + type => 'Gtk2::SeparatorMenuItem', }, { type => 'Gtk2::MenuItem', diff --git a/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm b/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm index 382e4593f..3dee342ba 100644 --- a/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm +++ b/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm @@ -153,7 +153,6 @@ sub new { menuitem_spatial_undef_cell_colour => {activate => \&on_set_undef_cell_colour}, menuitem_spatial_cell_show_outline => {toggled => \&on_set_cell_show_outline}, menuitem_spatial_show_legend => {toggled => \&on_show_hide_legend}, - menuitem_spatial_set_tree_line_widths => {activate => \&on_set_tree_line_widths}, ); for my $n (0..6) { @@ -232,6 +231,14 @@ sub on_show_hide_parameters { } +sub get_tree_menu_items { + my $self = shift; + my @items = $self->SUPER::get_tree_menu_items; + my $re_wanted = qr/Set tree branch line widths|Export/; + @items = grep {$_->{type} =~ /Separator/ or $_->{label} =~ /$re_wanted/} @items; + return wantarray ? @items : \@items; +} + sub init_grid { my $self = shift; From 7719be561d45f79c92abfaf0597aa72a757f1f3d Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 12:23:22 +1100 Subject: [PATCH 17/41] GUI spatial tab: Make side menu clearer --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index efd67d700..b9aaa3572 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -377,6 +377,12 @@ sub get_tree_menu_items { my $self = shift; my @menu_items = ( + { + type => 'Gtk2::MenuItem', + label => 'Branch colouring', + tooltip => "These options control the branch colouring (when relevant)\n" + . 'The menu to control what is displayed is below the tree.', + }, { type => 'Gtk2::CheckMenuItem', label => 'Show legend', @@ -433,6 +439,9 @@ sub get_tree_menu_items { } ], }, + { + type => 'Gtk2::SeparatorMenuItem', + }, { type => 'Gtk2::MenuItem', label => 'Set tree branch line widths', From 3342a503d4595878d92f26056adeaf9b9df6085b Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 19:58:06 +1100 Subject: [PATCH 18/41] GUI: Move _add_items_to_menu into Tabs.pm --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 57 ------------------------------ lib/Biodiverse/GUI/Tabs/Tab.pm | 57 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index b9aaa3572..d51b2f617 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -468,63 +468,6 @@ sub get_tree_menu_items { return wantarray ? @menu_items : \@menu_items; } -sub _add_items_to_menu { - my ($self, %args) = @_; - my @menu_items = @{$args{items}}; - my $menu = $args{menu}; - my $radio_group = $args{radio_group}; - - ITEM: - foreach my $item (@menu_items) { - my $type = $item->{type} // 'Gtk2::MenuItem'; - - if ($type eq 'submenu_radio_group') { - # a bit messy - my $menu_item = Gtk2::MenuItem->new($item->{label} // ()); - $menu->append($menu_item); - my $radio_submenu = Gtk2::Menu->new; - $self->_add_items_to_menu( - items => $item->{items}, - menu => $radio_submenu, # temp - radio_group => [], - ); - $menu_item->set_submenu($radio_submenu); - next ITEM; - } - - my $menu_item; - if ($type =~ /Radio/) { - $menu_item = $type->new($radio_group, $item->{label} // ()); - push @$radio_group, $menu_item; - } - else { - $menu_item = $type->new($item->{label} // ()); - } - $menu->append($menu_item); - - next ITEM if $type =~ /Separator/; - - if (my $key = $item->{self_key}) { - $self->{$key} = $menu_item, - } - if (my $tooltip = $item->{tooltip}) { - $menu_item->set_has_tooltip(1); - $menu_item->set_tooltip_text($tooltip); - } - if (($type =~ 'Check') && exists $item->{active}) { - $menu_item->set_active($item->{active}); - } - if (my $callback = $item->{callback}) { - my $args = $item->{callback_args}; - $menu_item->signal_connect_swapped( - $item->{event} => $callback, - $args // $self - ); - } - } - -} - # doesn't work yet sub screenshot { my $self = shift; diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index 0c3dc45ab..798dc8dde 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -1158,4 +1158,61 @@ sub update_display_list_combos { return; } +sub _add_items_to_menu { + my ($self, %args) = @_; + my @menu_items = @{$args{items}}; + my $menu = $args{menu}; + my $radio_group = $args{radio_group}; + + ITEM: + foreach my $item (@menu_items) { + my $type = $item->{type} // 'Gtk2::MenuItem'; + + if ($type eq 'submenu_radio_group') { + # a bit messy + my $menu_item = Gtk2::MenuItem->new($item->{label} // ()); + $menu->append($menu_item); + my $radio_submenu = Gtk2::Menu->new; + $self->_add_items_to_menu( + items => $item->{items}, + menu => $radio_submenu, # temp + radio_group => [], + ); + $menu_item->set_submenu($radio_submenu); + next ITEM; + } + + my $menu_item; + if ($type =~ /Radio/) { + $menu_item = $type->new($radio_group, $item->{label} // ()); + push @$radio_group, $menu_item; + } + else { + $menu_item = $type->new($item->{label} // ()); + } + $menu->append($menu_item); + + next ITEM if $type =~ /Separator/; + + if (my $key = $item->{self_key}) { + $self->{$key} = $menu_item, + } + if (my $tooltip = $item->{tooltip}) { + $menu_item->set_has_tooltip(1); + $menu_item->set_tooltip_text($tooltip); + } + if (($type =~ 'Check') && exists $item->{active}) { + $menu_item->set_active($item->{active}); + } + if (my $callback = $item->{callback}) { + my $args = $item->{callback_args}; + $menu_item->signal_connect_swapped( + $item->{event} => $callback, + $args // $self + ); + } + } + +} + 1; From cb1d4920c854c6c88a7b2bd735f53fd2ae4604ef Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 3 Jan 2024 20:23:27 +1100 Subject: [PATCH 19/41] GUI labels tab: fix some legend related issues These were missed in recent commits that focused on the spatial tab. --- lib/Biodiverse/GUI/Dendrogram.pm | 17 ++++++++++------- lib/Biodiverse/GUI/Tabs/Labels.pm | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Biodiverse/GUI/Dendrogram.pm b/lib/Biodiverse/GUI/Dendrogram.pm index 2470df796..05f2fe0e7 100644 --- a/lib/Biodiverse/GUI/Dendrogram.pm +++ b/lib/Biodiverse/GUI/Dendrogram.pm @@ -1248,13 +1248,16 @@ sub recolour_cluster_lines { my $analysis_max = $self->{analysis_max}; my $colour_mode = $self->get_cluster_colour_mode(); - my $legend = $map->get_legend; - $legend->set_colour_mode_from_list_and_index ( - list => $list_name, - index => $list_index, - ); - my @minmax_args = ($analysis_min, $analysis_max); - my $colour_method = $legend->get_colour_method; + my ($legend, @minmax_args, $colour_method); + if ($colour_mode ne 'palette' and not $self->in_multiselect_mode) { + $legend = $map->get_legend; + $legend->set_colour_mode_from_list_and_index( + list => $list_name, + index => $list_index, + ); + @minmax_args = ($analysis_min, $analysis_max); + $colour_method = $legend->get_colour_method; + } foreach my $node_ref (@$cluster_nodes) { diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index 4dd02f25f..7bb0ce47b 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -994,6 +994,7 @@ sub on_selected_labels_changed { else { $grid->set_legend_log_mode_off; } + my $legend = $grid->get_legend; my $colour_func = sub { my $elt = shift; @@ -1003,7 +1004,7 @@ sub on_selected_labels_changed { #if ($use_log) { # $val = log ($val + 1); #} - return $grid->get_colour($val, 0, $display_max_value); + return $legend->get_colour($val, 0, $display_max_value); }; $grid->colour($colour_func); From f06ca9ca07a75a354b2fdd0384f999c05fc50396 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Thu, 4 Jan 2024 20:25:36 +1100 Subject: [PATCH 20/41] GUI Labels tab: use array args methods in two places Micro-optimisation but might be useful. --- lib/Biodiverse/GUI/Tabs/Labels.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index 7bb0ce47b..7dcf6ef2a 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -1224,9 +1224,9 @@ sub on_grid_hover { # highlight in the tree foreach my $label (keys %$labels) { # Might not match some or all nodes - next if !$tree->exists_node (name => $label); + next if !$tree->exists_node_name_aa ($label); eval { - my $node_ref = $tree->get_node_ref (node => $label); + my $node_ref = $tree->get_node_ref_aa ($label); $self->{dendrogram}->highlight_path($node_ref); } } From 4e4a4603bb37b42e9a8b243dfee262b8566c4a72 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Thu, 4 Jan 2024 20:47:44 +1100 Subject: [PATCH 21/41] GUI Labels tab: micro-optimise some code Useful for large data sets. --- lib/Biodiverse/GUI/Tabs/Labels.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index 7dcf6ef2a..daa2d52ae 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -5,6 +5,8 @@ use warnings; use English ( -no_match_vars ); +use experimental qw(refaliasing); + #use Data::Dumper; use Sort::Key::Natural qw /natsort mkkey_natural/; @@ -960,12 +962,12 @@ sub on_selected_labels_changed { #FIXME: This copies the hash (???recheck???) - not very fast... #my %hash = $self->{base_ref}->get_groups_with_label_as_hash(label => $label); # SWL - just use a ref. Unless Eugene was thinking of what the sub does... - my $hash = $bd->get_groups_with_label_as_hash (label => $label); + \my %hash = $bd->get_groups_with_label_as_hash_aa ($label); # groups contains count of how many different labels occur in it - foreach my $group (keys %$hash) { - $group_richness{$group}++; - } + # postfix-if for speed + $group_richness{$_}++ + foreach keys %hash; } my $grid = $self->{grid}; From 18cab44f35ee4ad43dff6d738bb900adcf66f1cc Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Thu, 4 Jan 2024 20:59:09 +1100 Subject: [PATCH 22/41] GUI: move method from Spatial.pm to Tab.pm This makes it available to other tab objects. --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 36 ------------------------------ lib/Biodiverse/GUI/Tabs/Tab.pm | 36 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index d51b2f617..5b5f5b2a1 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -337,42 +337,6 @@ sub new { return $self; } -sub update_tree_menu { - my ($self, $menu_items) = @_; - - my $menubar = $self->{menubar}; - my $output_ref = $self->{output_ref}; - return if !$output_ref; - - $menu_items ||= $self->get_tree_menu_items; - - my $tree_menu = $self->{tree_menu}; - - if (!$tree_menu) { - $tree_menu = Gtk2::MenuItem->new_with_label('Tree'); - $menubar->append($tree_menu); - $self->{tree_menu} = $tree_menu; - } - - if (($output_ref->get_param('COMPLETED') // 1) != 1) { - # completed == 2 for clusters analyses with matrices only - $tree_menu->set_sensitive(0); - } - else { - my $submenu = Gtk2::Menu->new; - - $self->_add_items_to_menu ( - menu => $submenu, - items => $menu_items, - ); - - $tree_menu->set_submenu($submenu); - $tree_menu->set_sensitive(1); - } - - $menubar->show_all(); -} - sub get_tree_menu_items { my $self = shift; diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index 798dc8dde..5e6d18023 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -1158,6 +1158,42 @@ sub update_display_list_combos { return; } +sub update_tree_menu { + my ($self, $menu_items) = @_; + + my $menubar = $self->{menubar}; + my $output_ref = $self->{output_ref}; + return if !$output_ref; + + $menu_items ||= $self->get_tree_menu_items; + + my $tree_menu = $self->{tree_menu}; + + if (!$tree_menu) { + $tree_menu = Gtk2::MenuItem->new_with_label('Tree'); + $menubar->append($tree_menu); + $self->{tree_menu} = $tree_menu; + } + + if (($output_ref->get_param('COMPLETED') // 1) != 1) { + # completed == 2 for clusters analyses with matrices only + $tree_menu->set_sensitive(0); + } + else { + my $submenu = Gtk2::Menu->new; + + $self->_add_items_to_menu ( + menu => $submenu, + items => $menu_items, + ); + + $tree_menu->set_submenu($submenu); + $tree_menu->set_sensitive(1); + } + + $menubar->show_all(); +} + sub _add_items_to_menu { my ($self, %args) = @_; my @menu_items = @{$args{items}}; From a88fc21b5c13e374761bc2d59bf5856941f3525f Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Thu, 4 Jan 2024 21:30:35 +1100 Subject: [PATCH 23/41] GUI Labels tab: Add a side menu for the tree --- lib/Biodiverse/GUI/Tabs/Labels.pm | 71 +++++++++++++++++++++++++++++++ lib/Biodiverse/GUI/Tabs/Tab.pm | 6 +-- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index daa2d52ae..fe4e8f45e 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -209,6 +209,7 @@ sub new { $self->{menubar} = $self->get_xmlpage_object('menubarLabelsOptions'); $self->update_selection_menu; $self->update_export_menu; + $self->update_tree_menu (output_ref => $self->get_base_ref->get_groups_ref); say "[GUI] - Loaded tab - Labels"; @@ -326,6 +327,76 @@ sub init_dendrogram { return 1; } +sub get_tree_menu_items { + my $self = shift; + + my @menu_items = ( + { + type => 'Gtk2::MenuItem', + label => 'Tree controls', + tooltip => "Options to work with the displayed tree " + . "(this is the same as the one selected at " + . "the project level)", + }, + { + type => 'submenu_radio_group', + label => 'Plot branches by', + items => [ + { + type => 'Gtk2::RadioMenuItem', + label => 'Length', + event => 'activate', + callback => sub { + my $self = shift; + state $mode_string = 'length'; + say "[Labels tab] Changing mode to $mode_string"; + $self->{plot_mode} = $mode_string; + $self->{dendrogram}->set_plot_mode($mode_string); + }, + }, + { + type => 'Gtk2::RadioMenuItem', + label => 'Depth', + event => 'activate', + callback => sub { + my $self = shift; + state $mode_string = 'depth'; + say "[Labels tab] Changing mode to $mode_string"; + $self->{plot_mode} = $mode_string; + $self->{dendrogram}->set_plot_mode($mode_string); + }, + }, + ], + }, + { + type => 'Gtk2::SeparatorMenuItem', + }, + { + type => 'Gtk2::MenuItem', + label => 'Set tree branch line widths', + tooltip => "Set the width of the tree branches.\n" + . "Does not affect the vertical connectors.", + event => 'activate', + callback => \&on_set_tree_line_widths, + }, + { + type => 'Gtk2::SeparatorMenuItem', + }, + { + type => 'Gtk2::MenuItem', + label => 'Export tree', + tooltip => 'Export the currently displayed tree', + event => 'activate', + callback => sub { + my $tree_ref = $self->{project}->get_selected_phylogeny; + return Biodiverse::GUI::Export::Run($tree_ref); + }, + }, + ); + + return wantarray ? @menu_items : \@menu_items; +} + ################################################## # Labels list ################################################## diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index 5e6d18023..c83a663dc 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -1159,13 +1159,13 @@ sub update_display_list_combos { } sub update_tree_menu { - my ($self, $menu_items) = @_; + my ($self, %args) = @_; my $menubar = $self->{menubar}; - my $output_ref = $self->{output_ref}; + my $output_ref = $args{output_ref} || $self->{output_ref}; return if !$output_ref; - $menu_items ||= $self->get_tree_menu_items; + my $menu_items = $args{menu_items} || $self->get_tree_menu_items; my $tree_menu = $self->{tree_menu}; From eae7423ff26a0c05fd80abdfb25194dc5dbb1cfc Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Thu, 4 Jan 2024 22:08:53 +1100 Subject: [PATCH 24/41] GUI Labels tab: Update the side menu to handle more cases And in the process, we now keep track of the plot mode across trees. So if a user wants depth based plotting then this is consistent as the tree is changed. --- bin/ui/hboxLabelsPage.ui | 71 ------------------------------- lib/Biodiverse/GUI/Tabs/Labels.pm | 67 ++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 91 deletions(-) diff --git a/bin/ui/hboxLabelsPage.ui b/bin/ui/hboxLabelsPage.ui index 1b9624746..5a9a0462c 100644 --- a/bin/ui/hboxLabelsPage.ui +++ b/bin/ui/hboxLabelsPage.ui @@ -241,77 +241,6 @@ True - - - True - False - - - - - True - False - Tree - True - - - - - True - False - Plot branches using their lengths. - Length - True - True - True - - - - - True - False - Plot branches as a function of depth from the root node. - Depth - True - True - phylogeny_plot_length - - - - - True - False - When hovering on a branch, -highlight the groups on the grid -in which it is found. - - Highlight groups on map? - True - True - - - - - True - False - When hovering over a cell on the map, -highlight the paths from the tip to the root of the tree -for labels found in that group. - Highlight node paths for groups? - True - True - - - - - True - False - Set the width of the tree branches. -Does not affect the vertical connectors. - Set tree branch line widths - True - - diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index fe4e8f45e..a76c16b29 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -188,14 +188,11 @@ sub new { $self->get_xmlpage_object("btnSelectToolVL")->set_active(1); - # CONVERT THIS TO A HASH BASED LOOP, as per Clustering.pm - # plot length triggers depth and vice versa - $xml->get_object('phylogeny_plot_length')->signal_connect_swapped(toggled => \&on_phylogeny_plot_mode_changed, $self); - $xml->get_object('highlight_groups_on_map_labels_tab')->signal_connect_swapped(activate => \&on_highlight_groups_on_map_changed, $self); - $xml->get_object('use_highlight_path_changed1')->signal_connect_swapped(activate => \&on_use_highlight_path_changed, $self); - $xml->get_object('menuitem_labels_show_legend')->signal_connect_swapped(toggled => \&on_show_hide_legend, $self); - $xml->get_object('menuitem_labels_set_tree_line_widths')->signal_connect_swapped(activate => \&on_set_tree_line_widths, $self); - + $xml->get_object('menuitem_labels_show_legend')->signal_connect_swapped( + toggled => \&on_show_hide_legend, + $self + ); + foreach my $type_option (qw /auto linear log/) { my $radio_item = 'radiomenuitem_grid_colouring_' . $type_option; $xml->get_object($radio_item)->signal_connect_swapped( @@ -330,10 +327,22 @@ sub init_dendrogram { sub get_tree_menu_items { my $self = shift; + my $dendro_plot_mode_callback = sub { + my ($self, $mode_string) = @_; + $mode_string ||= 'length'; + say "[Labels tab] Changing mode to $mode_string"; + $self->{plot_mode} = $mode_string; + return if !$self->{project}->get_selected_phylogeny; + my $dendrogram = $self->{dendrogram}; + if ($dendrogram) { + $self->{dendrogram}->set_plot_mode($mode_string) + }; + }; + my @menu_items = ( { type => 'Gtk2::MenuItem', - label => 'Tree controls', + label => 'Tree options:', tooltip => "Options to work with the displayed tree " . "(this is the same as the one selected at " . "the project level)", @@ -347,11 +356,7 @@ sub get_tree_menu_items { label => 'Length', event => 'activate', callback => sub { - my $self = shift; - state $mode_string = 'length'; - say "[Labels tab] Changing mode to $mode_string"; - $self->{plot_mode} = $mode_string; - $self->{dendrogram}->set_plot_mode($mode_string); + $dendro_plot_mode_callback->($self, 'length'); }, }, { @@ -359,15 +364,31 @@ sub get_tree_menu_items { label => 'Depth', event => 'activate', callback => sub { - my $self = shift; - state $mode_string = 'depth'; - say "[Labels tab] Changing mode to $mode_string"; - $self->{plot_mode} = $mode_string; - $self->{dendrogram}->set_plot_mode($mode_string); + $dendro_plot_mode_callback->($self, 'depth'); }, }, ], }, + { + type => 'Gtk2::CheckMenuItem', + label => 'Highlight groups on map?', + tooltip => 'When hovering the mouse over a tree branch, ' + . 'highlight the groups on the map in which it is found.', + event => 'toggled', + callback => \&on_highlight_groups_on_map_changed, + active => 1, + self_key => 'checkbox_show_tree_legend', + }, + { + type => 'Gtk2::CheckMenuItem', + label => 'Highlight paths on tree?', + tooltip => "When hovering over a group on the map, highlight the paths " + . "connecting the tips of the tree (that match labels in the group) " + . "to the root.", + event => 'toggled', + callback => \&on_use_highlight_path_changed, + active => 1, + }, { type => 'Gtk2::SeparatorMenuItem', }, @@ -389,6 +410,7 @@ sub get_tree_menu_items { event => 'activate', callback => sub { my $tree_ref = $self->{project}->get_selected_phylogeny; + return if !$tree_ref; return Biodiverse::GUI::Export::Run($tree_ref); }, }, @@ -816,6 +838,10 @@ sub set_phylogeny_options_sensitive { my $self = shift; my $enabled = shift; + # These are handled differently now. + # Leaving code as a reminder, but returning early. + return; + my $page = $self->{xmlPage}; for my $widget ( @@ -837,7 +863,8 @@ sub on_selected_phylogeny_changed { $self->{dendrogram}->clear; if ($phylogeny) { - $self->{dendrogram}->set_cluster($phylogeny, 'length'); # now storing tree objects directly + # now storing tree objects directly + $self->{dendrogram}->set_cluster($phylogeny, $self->{plot_mode} //= 'length'); $self->set_phylogeny_options_sensitive(1); } else { From ee40b32ff37a7693a0122f95c520669317e269c3 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Thu, 4 Jan 2024 22:46:16 +1100 Subject: [PATCH 25/41] GUI Cluster tab: Add a side menu for the cluster tree Has a lot of overlap with the Labels tab, but there are sufficient differences to suggest refactoring would make maintenance harder. --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 148 ++++++++++++++++++++++++++ lib/Biodiverse/GUI/Tabs/Tab.pm | 4 + 2 files changed, 152 insertions(+) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index b4a8d7b19..93195bc7a 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -332,6 +332,7 @@ sub new { $self->{menubar} = $self->get_xmlpage_object('menubar_clustering'); $self->update_export_menu; + $self->update_tree_menu; $self->init_colour_clusters; say "[Clustering tab] - Loaded tab - Clustering Analysis"; @@ -339,6 +340,153 @@ sub new { return $self; } +sub get_cluster_ref { + my $self = shift; + $self->{output_ref}; +} + +# has a lot in common with Labels::get_tree_menu_items +sub get_tree_menu_items { + my $self = shift; + + my $dendro_plot_mode_callback = sub { + my ($self, $mode_string) = @_; + $mode_string ||= 'length'; + say "[Clustering tab] Changing mode to $mode_string"; + $self->{plot_mode} = $mode_string; + my $dendrogram = $self->{dendrogram}; + if ($dendrogram) { + $self->{dendrogram}->set_plot_mode($mode_string) + }; + }; + + my $dendro_select_mode_callback = sub { + my ($self, $mode_string) = @_; + $mode_string ||= 'length'; + say "[Clustering tab] Changing selection mode to $mode_string"; + $self->{group_mode} = $mode_string; + my $dendrogram = $self->{dendrogram}; + if ($dendrogram) { + $self->{dendrogram}->set_group_mode($mode_string) + }; + }; + + my $tooltip_select_by = < 'Gtk2::MenuItem', + label => 'Tree options:', + tooltip => "Options to work with the cluster tree", + }, + { + type => 'submenu_radio_group', + label => 'Plot branches by', + items => [ + { + type => 'Gtk2::RadioMenuItem', + label => 'Length', + event => 'activate', + callback => sub { + $dendro_plot_mode_callback->($self, 'length'); + }, + }, + { + type => 'Gtk2::RadioMenuItem', + label => 'Depth', + event => 'activate', + callback => sub { + $dendro_plot_mode_callback->($self, 'depth'); + }, + }, + ], + }, + { + type => 'submenu_radio_group', + label => 'Select branches by', + tooltip => $tooltip_select_by, + items => [ + { + type => 'Gtk2::RadioMenuItem', + label => 'Length', + event => 'activate', + callback => sub { + $dendro_select_mode_callback->($self, 'length'); + }, + }, + { + type => 'Gtk2::RadioMenuItem', + label => 'Depth', + event => 'activate', + callback => sub { + $dendro_select_mode_callback->($self, 'depth'); + }, + }, + ], + }, + { + type => 'Gtk2::CheckMenuItem', + label => 'Highlight groups on map?', + tooltip => 'When hovering the mouse over a tree branch, ' + . 'highlight the groups on the map in which it is found.', + event => 'toggled', + callback => \&on_highlight_groups_on_map_changed, + active => 1, + self_key => 'checkbox_show_tree_legend', + }, + { + type => 'Gtk2::CheckMenuItem', + label => 'Highlight paths on tree?', + tooltip => "When hovering over a group on the map, highlight the paths " + . "connecting the tips of the tree (that match labels in the group) " + . "to the root.", + event => 'toggled', + callback => \&on_use_highlight_path_changed, + active => 1, + }, + { + type => 'Gtk2::SeparatorMenuItem', + }, + { + type => 'Gtk2::MenuItem', + label => 'Set tree branch line widths', + tooltip => "Set the width of the tree branches.\n" + . "Does not affect the vertical connectors.", + event => 'activate', + callback => \&on_set_tree_line_widths, + }, + { + type => 'Gtk2::SeparatorMenuItem', + }, + { + type => 'Gtk2::MenuItem', + label => 'Export tree', + tooltip => 'Export the currently displayed tree', + event => 'activate', + callback => sub { + my $tree_ref = $self->get_cluster_ref; + return Biodiverse::GUI::Export::Run($tree_ref); + }, + }, + ); + + return wantarray ? @menu_items : \@menu_items; +} + sub init_colour_clusters { my $self = shift; my $cluster_ref = $self->{output_ref}; diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index c83a663dc..7893cde82 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -1207,6 +1207,10 @@ sub _add_items_to_menu { if ($type eq 'submenu_radio_group') { # a bit messy my $menu_item = Gtk2::MenuItem->new($item->{label} // ()); + if (my $tooltip = $item->{tooltip}) { + $menu_item->set_has_tooltip(1); + $menu_item->set_tooltip_text($tooltip); + } $menu->append($menu_item); my $radio_submenu = Gtk2::Menu->new; $self->_add_items_to_menu( From e5be4309bfe47c404ed6f3d893b89f2cf166ee59 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Thu, 4 Jan 2024 23:09:27 +1100 Subject: [PATCH 26/41] GUI Cluster tab: More side menu options for the cluster tree And clean up the old stuff. --- bin/ui/hboxClusteringPage.ui | 120 -------------------------- lib/Biodiverse/GUI/Dendrogram.pm | 8 ++ lib/Biodiverse/GUI/Tabs/Clustering.pm | 31 +++---- 3 files changed, 24 insertions(+), 135 deletions(-) diff --git a/bin/ui/hboxClusteringPage.ui b/bin/ui/hboxClusteringPage.ui index 338811f99..5f5ef9f08 100644 --- a/bin/ui/hboxClusteringPage.ui +++ b/bin/ui/hboxClusteringPage.ui @@ -408,126 +408,6 @@ Colours are currently taken from the outer ring. True - - - True - False - - - - - True - False - Plot by - True - - - False - - - True - False - Length - True - True - - - - - - True - False - Depth - True - plot_length - - - - - - - - - - True - False - Should the grouping be done by length or depth? - -This allows decoupling of node selection from the tree display so trees with many reversals can be more easily plotted by depth, but selections still use the branch lengths. - -This setting has no effect on the slider bar. It always groups using the plot method, selecting whichever branches it crosses. - Group by - True - - - False - - - True - False - Length - True - True - - - - - - True - False - Depth - True - group_length - - - - - - - - - - True - False - Highlight groups under this node when hovering over the node - Highlight groups on map? - True - True - - - - - - True - False - Highlight paths on the tree associated with groups on the map when you hover the mouse over them - Highlight node paths for groups? - True - True - - - - - - True - False - When deselected, the slider bar will not change the display colours. - Use the slider bar to select nodes for colouring? - True - True - - - - - True - False - Set the width of the tree branches. -Does not affect the vertical connectors. - - Set tree branch line widths - True - - diff --git a/lib/Biodiverse/GUI/Dendrogram.pm b/lib/Biodiverse/GUI/Dendrogram.pm index 05f2fe0e7..099f479d4 100644 --- a/lib/Biodiverse/GUI/Dendrogram.pm +++ b/lib/Biodiverse/GUI/Dendrogram.pm @@ -683,6 +683,14 @@ sub toggle_use_slider_to_select_nodes { return; } +sub set_use_slider_to_select_nodes { + my ($self, $bool) = @_; + + $self->{use_slider_to_select_nodes} = !!$bool; + + return; +} + # Colours a certain number of nodes below sub do_colour_nodes_below { my $self = shift; diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index 93195bc7a..bb30fd1fb 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -217,8 +217,8 @@ sub new { $self->{definition_query1}->get_object ); - $xml_page->get_object('plot_length') ->set_active(1); - $xml_page->get_object('group_length')->set_active(1); + # $xml_page->get_object('plot_length') ->set_active(1); + # $xml_page->get_object('group_length')->set_active(1); $self->{plot_mode} = 'length'; $self->{group_mode} = 'length'; @@ -278,16 +278,6 @@ sub new { btnZoomOutToolCL => {clicked => \&on_zoom_out_tool}, btnZoomFitToolCL => {clicked => \&on_zoom_fit_tool}, - plot_length => {toggled => \&on_plot_mode_changed}, - group_length => {toggled => \&on_group_mode_changed}, - - highlight_groups_on_map => - {toggled => \&on_highlight_groups_on_map_changed}, - use_highlight_path_changed => - {toggled => \&on_use_highlight_path_changed}, - menu_use_slider_to_select_nodes => - {toggled => \&on_menu_use_slider_to_select_nodes}, - menuitem_cluster_colour_mode_hue => {toggled => \&on_colour_mode_changed}, menuitem_cluster_colour_mode_sat => {activate => \&on_colour_mode_changed}, menuitem_cluster_colour_mode_grey => {toggled => \&on_colour_mode_changed}, @@ -303,7 +293,6 @@ sub new { menu_cluster_cell_show_outline => {toggled => \&on_set_cell_show_outline}, menuitem_cluster_show_legend => {toggled => \&on_show_hide_legend}, #menuitem_cluster_data_tearoff => {activate => \&on_toolbar_data_menu_tearoff}, - menuitem_cluster_set_tree_line_widths => {activate => \&on_set_tree_line_widths}, menuitem_cluster_excluded_cell_colour => {activate => \&on_set_excluded_cell_colour}, menuitem_cluster_undef_cell_colour => {activate => \&on_set_undef_cell_colour}, ); @@ -440,7 +429,7 @@ EOT }, { type => 'Gtk2::CheckMenuItem', - label => 'Highlight groups on map?', + label => 'Highlight groups on map', tooltip => 'When hovering the mouse over a tree branch, ' . 'highlight the groups on the map in which it is found.', event => 'toggled', @@ -450,7 +439,7 @@ EOT }, { type => 'Gtk2::CheckMenuItem', - label => 'Highlight paths on tree?', + label => 'Highlight paths on tree', tooltip => "When hovering over a group on the map, highlight the paths " . "connecting the tips of the tree (that match labels in the group) " . "to the root.", @@ -458,6 +447,18 @@ EOT callback => \&on_use_highlight_path_changed, active => 1, }, + { + type => 'Gtk2::CheckMenuItem', + label => 'Use the slider bar to select branches for colouring', + tooltip => "When deselected, the slider bar will not change the display colours.", + event => 'toggled', + callback => sub { + my ($self, $menuitem) = @_; + my $bool = $menuitem->get_active; + $self->{dendrogram}->set_use_slider_to_select_nodes ($bool); + }, + active => 1, + }, { type => 'Gtk2::SeparatorMenuItem', }, From 3f46a55cf79deab3f5d27b32b75052be2d9b0686 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 08:08:52 +1100 Subject: [PATCH 27/41] GUI tree plotting: no need to set plot/group mode if unchanged Avoids some double firing of events. --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 2 ++ lib/Biodiverse/GUI/Tabs/Labels.pm | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index bb30fd1fb..d36a5df85 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -341,6 +341,7 @@ sub get_tree_menu_items { my $dendro_plot_mode_callback = sub { my ($self, $mode_string) = @_; $mode_string ||= 'length'; + return if $self->{plot_mode} eq $mode_string; say "[Clustering tab] Changing mode to $mode_string"; $self->{plot_mode} = $mode_string; my $dendrogram = $self->{dendrogram}; @@ -352,6 +353,7 @@ sub get_tree_menu_items { my $dendro_select_mode_callback = sub { my ($self, $mode_string) = @_; $mode_string ||= 'length'; + return if $self->{group_mode} eq $mode_string; say "[Clustering tab] Changing selection mode to $mode_string"; $self->{group_mode} = $mode_string; my $dendrogram = $self->{dendrogram}; diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index a76c16b29..e53278584 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -330,6 +330,7 @@ sub get_tree_menu_items { my $dendro_plot_mode_callback = sub { my ($self, $mode_string) = @_; $mode_string ||= 'length'; + return if $self->{plot_mode} eq $mode_string; say "[Labels tab] Changing mode to $mode_string"; $self->{plot_mode} = $mode_string; return if !$self->{project}->get_selected_phylogeny; From 4dedbff17554e6cee8132aa6cbfbe8643f160ab7 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 08:49:41 +1100 Subject: [PATCH 28/41] GUI spatial tabs: Support tree plot by depth Also avoid some uninitialised warnings. --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 2 +- lib/Biodiverse/GUI/Tabs/Labels.pm | 2 +- lib/Biodiverse/GUI/Tabs/Spatial.pm | 35 ++++++++++++++++++++++++ lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm | 2 +- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index d36a5df85..095724c87 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -341,7 +341,7 @@ sub get_tree_menu_items { my $dendro_plot_mode_callback = sub { my ($self, $mode_string) = @_; $mode_string ||= 'length'; - return if $self->{plot_mode} eq $mode_string; + return if ($self->{plot_mode} // '') eq $mode_string; say "[Clustering tab] Changing mode to $mode_string"; $self->{plot_mode} = $mode_string; my $dendrogram = $self->{dendrogram}; diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index e53278584..e78afadb3 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -330,7 +330,7 @@ sub get_tree_menu_items { my $dendro_plot_mode_callback = sub { my ($self, $mode_string) = @_; $mode_string ||= 'length'; - return if $self->{plot_mode} eq $mode_string; + return if ($self->{plot_mode} // '') eq $mode_string; say "[Labels tab] Changing mode to $mode_string"; $self->{plot_mode} = $mode_string; return if !$self->{project}->get_selected_phylogeny; diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 5b5f5b2a1..9113b81ba 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -340,6 +340,19 @@ sub new { sub get_tree_menu_items { my $self = shift; + my $dendro_plot_mode_callback = sub { + my ($self, $mode_string) = @_; + $mode_string ||= 'length'; + return if ($self->{plot_mode} // '') eq $mode_string; + say "[Spatial tab] Changing tree plot mode to $mode_string"; + $self->{plot_mode} = $mode_string; + return if !$self->get_current_tree; + my $dendrogram = $self->{dendrogram}; + if ($dendrogram) { + $self->{dendrogram}->set_plot_mode($mode_string) + }; + }; + my @menu_items = ( { type => 'Gtk2::MenuItem', @@ -406,6 +419,28 @@ sub get_tree_menu_items { { type => 'Gtk2::SeparatorMenuItem', }, + { + type => 'submenu_radio_group', + label => 'Plot branches by', + items => [ + { + type => 'Gtk2::RadioMenuItem', + label => 'Length', + event => 'activate', + callback => sub { + $dendro_plot_mode_callback->($self, 'length'); + }, + }, + { + type => 'Gtk2::RadioMenuItem', + label => 'Depth', + event => 'activate', + callback => sub { + $dendro_plot_mode_callback->($self, 'depth'); + }, + }, + ], + }, { type => 'Gtk2::MenuItem', label => 'Set tree branch line widths', diff --git a/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm b/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm index 3dee342ba..eb3934944 100644 --- a/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm +++ b/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm @@ -234,7 +234,7 @@ sub on_show_hide_parameters { sub get_tree_menu_items { my $self = shift; my @items = $self->SUPER::get_tree_menu_items; - my $re_wanted = qr/Set tree branch line widths|Export/; + my $re_wanted = qr/Set tree branch line widths|Plot branches by|Export/; @items = grep {$_->{type} =~ /Separator/ or $_->{label} =~ /$re_wanted/} @items; return wantarray ? @items : \@items; } From 3c9ab5443e7ae02beeddd998a31a9dbe8af3d13b Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 15:18:12 +1100 Subject: [PATCH 29/41] GUI: refactor tree plot mode code This unifies the interfaces across the different tab types and enables a future refactor to combine the common tree menu items. --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 26 ++++++++------------------ lib/Biodiverse/GUI/Tabs/Labels.pm | 26 +++++++------------------- lib/Biodiverse/GUI/Tabs/Spatial.pm | 21 ++------------------- lib/Biodiverse/GUI/Tabs/Tab.pm | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 56 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index 095724c87..0d589aab3 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -334,22 +334,16 @@ sub get_cluster_ref { $self->{output_ref}; } +sub get_current_tree { + my $self = shift; + $self->get_cluster_ref; +} + + # has a lot in common with Labels::get_tree_menu_items sub get_tree_menu_items { my $self = shift; - my $dendro_plot_mode_callback = sub { - my ($self, $mode_string) = @_; - $mode_string ||= 'length'; - return if ($self->{plot_mode} // '') eq $mode_string; - say "[Clustering tab] Changing mode to $mode_string"; - $self->{plot_mode} = $mode_string; - my $dendrogram = $self->{dendrogram}; - if ($dendrogram) { - $self->{dendrogram}->set_plot_mode($mode_string) - }; - }; - my $dendro_select_mode_callback = sub { my ($self, $mode_string) = @_; $mode_string ||= 'length'; @@ -392,17 +386,13 @@ EOT type => 'Gtk2::RadioMenuItem', label => 'Length', event => 'activate', - callback => sub { - $dendro_plot_mode_callback->($self, 'length'); - }, + callback => sub {$self->set_dendrogram_plot_mode ('length')}, }, { type => 'Gtk2::RadioMenuItem', label => 'Depth', event => 'activate', - callback => sub { - $dendro_plot_mode_callback->($self, 'depth'); - }, + callback => sub {$self->set_dendrogram_plot_mode ('depth')}, }, ], }, diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index e78afadb3..d19f9c0a1 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -324,21 +324,13 @@ sub init_dendrogram { return 1; } -sub get_tree_menu_items { +sub get_current_tree { my $self = shift; + return $self->{project}->get_selected_phylogeny; +} - my $dendro_plot_mode_callback = sub { - my ($self, $mode_string) = @_; - $mode_string ||= 'length'; - return if ($self->{plot_mode} // '') eq $mode_string; - say "[Labels tab] Changing mode to $mode_string"; - $self->{plot_mode} = $mode_string; - return if !$self->{project}->get_selected_phylogeny; - my $dendrogram = $self->{dendrogram}; - if ($dendrogram) { - $self->{dendrogram}->set_plot_mode($mode_string) - }; - }; +sub get_tree_menu_items { + my $self = shift; my @menu_items = ( { @@ -356,17 +348,13 @@ sub get_tree_menu_items { type => 'Gtk2::RadioMenuItem', label => 'Length', event => 'activate', - callback => sub { - $dendro_plot_mode_callback->($self, 'length'); - }, + callback => sub {$self->set_dendrogram_plot_mode ('length')}, }, { type => 'Gtk2::RadioMenuItem', label => 'Depth', event => 'activate', - callback => sub { - $dendro_plot_mode_callback->($self, 'depth'); - }, + callback => sub {$self->set_dendrogram_plot_mode ('depth')}, }, ], }, diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 9113b81ba..54206ffb7 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -340,19 +340,6 @@ sub new { sub get_tree_menu_items { my $self = shift; - my $dendro_plot_mode_callback = sub { - my ($self, $mode_string) = @_; - $mode_string ||= 'length'; - return if ($self->{plot_mode} // '') eq $mode_string; - say "[Spatial tab] Changing tree plot mode to $mode_string"; - $self->{plot_mode} = $mode_string; - return if !$self->get_current_tree; - my $dendrogram = $self->{dendrogram}; - if ($dendrogram) { - $self->{dendrogram}->set_plot_mode($mode_string) - }; - }; - my @menu_items = ( { type => 'Gtk2::MenuItem', @@ -427,17 +414,13 @@ sub get_tree_menu_items { type => 'Gtk2::RadioMenuItem', label => 'Length', event => 'activate', - callback => sub { - $dendro_plot_mode_callback->($self, 'length'); - }, + callback => sub {$self->set_dendrogram_plot_mode ('length')}, }, { type => 'Gtk2::RadioMenuItem', label => 'Depth', event => 'activate', - callback => sub { - $dendro_plot_mode_callback->($self, 'depth'); - }, + callback => sub {$self->set_dendrogram_plot_mode ('depth')}, }, ], }, diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index 7893cde82..cd563fc93 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -980,6 +980,21 @@ sub get_colour_from_chooser { return $colour; } +sub set_dendrogram_plot_mode { + my ($self, $mode_string) = @_; + $mode_string ||= 'length'; + return if ($self->{plot_mode} // '') eq $mode_string; + my $tab_type = (blessed $self) =~ s/.+:://r; + say "[$tab_type tab] Changing tree plot mode to $mode_string"; + $self->{plot_mode} = $mode_string; + return if !$self->get_current_tree; + my $dendrogram = $self->{dendrogram}; + if ($dendrogram) { + $self->{dendrogram}->set_plot_mode($mode_string) + }; +}; + + sub on_set_tree_line_widths { my $self = shift; From 6e04217f206417b4d7eb652ba1036787c63ab787 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 15:25:50 +1100 Subject: [PATCH 30/41] GUI: refactor tree plot selection mode code Same process as the previous commit, although it is only used in the Clustering tab and its subclasses. --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 20 ++------------------ lib/Biodiverse/GUI/Tabs/Tab.pm | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index 0d589aab3..3b782cbd4 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -344,18 +344,6 @@ sub get_current_tree { sub get_tree_menu_items { my $self = shift; - my $dendro_select_mode_callback = sub { - my ($self, $mode_string) = @_; - $mode_string ||= 'length'; - return if $self->{group_mode} eq $mode_string; - say "[Clustering tab] Changing selection mode to $mode_string"; - $self->{group_mode} = $mode_string; - my $dendrogram = $self->{dendrogram}; - if ($dendrogram) { - $self->{dendrogram}->set_group_mode($mode_string) - }; - }; - my $tooltip_select_by = < 'Gtk2::RadioMenuItem', label => 'Length', event => 'activate', - callback => sub { - $dendro_select_mode_callback->($self, 'length'); - }, + callback => sub {$self->set_dendrogram_group_by_mode ('length');}, }, { type => 'Gtk2::RadioMenuItem', label => 'Depth', event => 'activate', - callback => sub { - $dendro_select_mode_callback->($self, 'depth'); - }, + callback => sub {$self->set_dendrogram_group_by_mode('depth');}, }, ], }, diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index cd563fc93..9170ebe66 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -988,9 +988,22 @@ sub set_dendrogram_plot_mode { say "[$tab_type tab] Changing tree plot mode to $mode_string"; $self->{plot_mode} = $mode_string; return if !$self->get_current_tree; - my $dendrogram = $self->{dendrogram}; - if ($dendrogram) { - $self->{dendrogram}->set_plot_mode($mode_string) + if (my $dendrogram = $self->{dendrogram}) { + $dendrogram->set_plot_mode($mode_string) + }; +}; + +# only used by Clustering at the moment +sub set_dendrogram_group_by_mode { + my ($self, $mode_string) = @_; + $mode_string ||= 'length'; + return if $self->{group_mode} eq $mode_string; + my $tab_type = (blessed $self) =~ s/.+:://r; + say "[$tab_type tab] Changing selection grouping mode to $mode_string"; + $self->{group_mode} = $mode_string; + return if !$self->get_current_tree; + if (my $dendrogram = $self->{dendrogram}) { + $dendrogram->set_group_mode($mode_string) }; }; From 1d4dd2aa34390298a1c5614cba5775ab93fb99a5 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 15:51:34 +1100 Subject: [PATCH 31/41] GUI: refactor tree plotting menu items These were repeated across several packages. --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 55 +------------------ lib/Biodiverse/GUI/Tabs/Labels.pm | 19 +------ lib/Biodiverse/GUI/Tabs/Spatial.pm | 19 +------ lib/Biodiverse/GUI/Tabs/Tab.pm | 79 +++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 89 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index 3b782cbd4..fd579ccc2 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -344,65 +344,14 @@ sub get_current_tree { sub get_tree_menu_items { my $self = shift; - my $tooltip_select_by = < 'Gtk2::MenuItem', label => 'Tree options:', tooltip => "Options to work with the cluster tree", }, - { - type => 'submenu_radio_group', - label => 'Plot branches by', - items => [ - { - type => 'Gtk2::RadioMenuItem', - label => 'Length', - event => 'activate', - callback => sub {$self->set_dendrogram_plot_mode ('length')}, - }, - { - type => 'Gtk2::RadioMenuItem', - label => 'Depth', - event => 'activate', - callback => sub {$self->set_dendrogram_plot_mode ('depth')}, - }, - ], - }, - { - type => 'submenu_radio_group', - label => 'Select branches by', - tooltip => $tooltip_select_by, - items => [ - { - type => 'Gtk2::RadioMenuItem', - label => 'Length', - event => 'activate', - callback => sub {$self->set_dendrogram_group_by_mode ('length');}, - }, - { - type => 'Gtk2::RadioMenuItem', - label => 'Depth', - event => 'activate', - callback => sub {$self->set_dendrogram_group_by_mode('depth');}, - }, - ], - }, + $self->get_tree_menu_item ('plot_branches_by'), + $self->get_tree_menu_item ('group_branches_by'), { type => 'Gtk2::CheckMenuItem', label => 'Highlight groups on map', diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index d19f9c0a1..0bf082509 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -340,24 +340,7 @@ sub get_tree_menu_items { . "(this is the same as the one selected at " . "the project level)", }, - { - type => 'submenu_radio_group', - label => 'Plot branches by', - items => [ - { - type => 'Gtk2::RadioMenuItem', - label => 'Length', - event => 'activate', - callback => sub {$self->set_dendrogram_plot_mode ('length')}, - }, - { - type => 'Gtk2::RadioMenuItem', - label => 'Depth', - event => 'activate', - callback => sub {$self->set_dendrogram_plot_mode ('depth')}, - }, - ], - }, + $self->get_tree_menu_item ('plot_branches_by'), { type => 'Gtk2::CheckMenuItem', label => 'Highlight groups on map?', diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 54206ffb7..fe5b5f97f 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -406,24 +406,7 @@ sub get_tree_menu_items { { type => 'Gtk2::SeparatorMenuItem', }, - { - type => 'submenu_radio_group', - label => 'Plot branches by', - items => [ - { - type => 'Gtk2::RadioMenuItem', - label => 'Length', - event => 'activate', - callback => sub {$self->set_dendrogram_plot_mode ('length')}, - }, - { - type => 'Gtk2::RadioMenuItem', - label => 'Depth', - event => 'activate', - callback => sub {$self->set_dendrogram_plot_mode ('depth')}, - }, - ], - }, + $self->get_tree_menu_item ('plot_branches_by'), { type => 'Gtk2::MenuItem', label => 'Set tree branch line widths', diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index 9170ebe66..062e95389 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -1283,4 +1283,83 @@ sub _add_items_to_menu { } +sub get_tree_menu_item { + my ($self, $wanted) = @_; + + state $tooltip_select_by = < { + type => 'submenu_radio_group', + label => 'Plot branches by', + items => [ + { + type => 'Gtk2::RadioMenuItem', + label => 'Length', + event => 'activate', + callback => sub { + my $self = shift; + $self->set_dendrogram_plot_mode('length'), + }, + }, + { + type => 'Gtk2::RadioMenuItem', + label => 'Depth', + event => 'activate', + callback => sub { + my $self = shift; + $self->set_dendrogram_plot_mode ('depth'); + }, + }, + ], + }, + group_branches_by => { + type => 'submenu_radio_group', + label => 'Select branches by', + tooltip => $tooltip_select_by, + items => [ + { + type => 'Gtk2::RadioMenuItem', + label => 'Length', + event => 'activate', + callback => sub { + my $self = shift; + $self->set_dendrogram_group_by_mode ('length'); + }, + }, + { + type => 'Gtk2::RadioMenuItem', + label => 'Depth', + event => 'activate', + callback => sub { + my $self = shift; + $self->set_dendrogram_group_by_mode('depth'); + }, + }, + ], + }, + + }; + + my $item = $items->{$wanted}; + croak "Cannot find tree menu item item $wanted" + if !$item; + + return $item; +} + 1; From ec6e0bc9e38f33de3b25b8e94cf21965428fb74b Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 15:56:04 +1100 Subject: [PATCH 32/41] GUI: refactor tree plotting branch width menu item --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 9 +------- lib/Biodiverse/GUI/Tabs/Labels.pm | 9 +------- lib/Biodiverse/GUI/Tabs/Spatial.pm | 11 ++-------- lib/Biodiverse/GUI/Tabs/Tab.pm | 31 ++++++++++++++++----------- 4 files changed, 23 insertions(+), 37 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index fd579ccc2..5ba79948b 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -387,14 +387,7 @@ sub get_tree_menu_items { { type => 'Gtk2::SeparatorMenuItem', }, - { - type => 'Gtk2::MenuItem', - label => 'Set tree branch line widths', - tooltip => "Set the width of the tree branches.\n" - . "Does not affect the vertical connectors.", - event => 'activate', - callback => \&on_set_tree_line_widths, - }, + $self->get_tree_menu_item('set_tree_branch_line_widths'), { type => 'Gtk2::SeparatorMenuItem', }, diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index 0bf082509..7aa3c15f8 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -364,14 +364,7 @@ sub get_tree_menu_items { { type => 'Gtk2::SeparatorMenuItem', }, - { - type => 'Gtk2::MenuItem', - label => 'Set tree branch line widths', - tooltip => "Set the width of the tree branches.\n" - . "Does not affect the vertical connectors.", - event => 'activate', - callback => \&on_set_tree_line_widths, - }, + $self->get_tree_menu_item('set_tree_branch_line_widths'), { type => 'Gtk2::SeparatorMenuItem', }, diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index fe5b5f97f..9ce7cf9e0 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -406,15 +406,8 @@ sub get_tree_menu_items { { type => 'Gtk2::SeparatorMenuItem', }, - $self->get_tree_menu_item ('plot_branches_by'), - { - type => 'Gtk2::MenuItem', - label => 'Set tree branch line widths', - tooltip => "Set the width of the tree branches.\n" - . "Does not affect the vertical connectors.", - event => 'activate', - callback => \&on_set_tree_line_widths, - }, + $self->get_tree_menu_item('plot_branches_by'), + $self->get_tree_menu_item('set_tree_branch_line_widths'), { type => 'Gtk2::SeparatorMenuItem', }, diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index 062e95389..80a32bd38 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -1303,15 +1303,15 @@ EOT ; state $items = { - plot_branches_by => { + plot_branches_by => { type => 'submenu_radio_group', label => 'Plot branches by', items => [ { - type => 'Gtk2::RadioMenuItem', - label => 'Length', - event => 'activate', - callback => sub { + type => 'Gtk2::RadioMenuItem', + label => 'Length', + event => 'activate', + callback => sub { my $self = shift; $self->set_dendrogram_plot_mode('length'), }, @@ -1322,23 +1322,23 @@ EOT event => 'activate', callback => sub { my $self = shift; - $self->set_dendrogram_plot_mode ('depth'); + $self->set_dendrogram_plot_mode('depth'); }, }, ], }, - group_branches_by => { - type => 'submenu_radio_group', - label => 'Select branches by', + group_branches_by => { + type => 'submenu_radio_group', + label => 'Select branches by', tooltip => $tooltip_select_by, - items => [ + items => [ { type => 'Gtk2::RadioMenuItem', label => 'Length', event => 'activate', callback => sub { my $self = shift; - $self->set_dendrogram_group_by_mode ('length'); + $self->set_dendrogram_group_by_mode('length'); }, }, { @@ -1352,7 +1352,14 @@ EOT }, ], }, - + set_tree_branch_line_widths => { + type => 'Gtk2::MenuItem', + label => 'Set tree branch line widths', + tooltip => "Set the width of the tree branches.\n" + . "Does not affect the vertical connectors.", + event => 'activate', + callback => \&on_set_tree_line_widths, + }, }; my $item = $items->{$wanted}; From 8832bb9f2c01c34e7a9c1c81cb6d48a3302ec1fd Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 15:58:39 +1100 Subject: [PATCH 33/41] GUI: refactor tree plotting separator menu item --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 4 +--- lib/Biodiverse/GUI/Tabs/Labels.pm | 4 +--- lib/Biodiverse/GUI/Tabs/Spatial.pm | 8 ++------ lib/Biodiverse/GUI/Tabs/Tab.pm | 7 +++++-- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index 5ba79948b..5fee15619 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -388,9 +388,7 @@ sub get_tree_menu_items { type => 'Gtk2::SeparatorMenuItem', }, $self->get_tree_menu_item('set_tree_branch_line_widths'), - { - type => 'Gtk2::SeparatorMenuItem', - }, + $self->get_tree_menu_item('separator'), { type => 'Gtk2::MenuItem', label => 'Export tree', diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index 7aa3c15f8..30786d3a3 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -365,9 +365,7 @@ sub get_tree_menu_items { type => 'Gtk2::SeparatorMenuItem', }, $self->get_tree_menu_item('set_tree_branch_line_widths'), - { - type => 'Gtk2::SeparatorMenuItem', - }, + $self->get_tree_menu_item('separator'), { type => 'Gtk2::MenuItem', label => 'Export tree', diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 9ce7cf9e0..036342cc4 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -403,14 +403,10 @@ sub get_tree_menu_items { } ], }, - { - type => 'Gtk2::SeparatorMenuItem', - }, + $self->get_tree_menu_item('separator'), $self->get_tree_menu_item('plot_branches_by'), $self->get_tree_menu_item('set_tree_branch_line_widths'), - { - type => 'Gtk2::SeparatorMenuItem', - }, + $self->get_tree_menu_item('separator'), { type => 'Gtk2::MenuItem', label => 'Export', diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index 80a32bd38..446a8ef68 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -1303,7 +1303,7 @@ EOT ; state $items = { - plot_branches_by => { + plot_branches_by => { type => 'submenu_radio_group', label => 'Plot branches by', items => [ @@ -1327,7 +1327,7 @@ EOT }, ], }, - group_branches_by => { + group_branches_by => { type => 'submenu_radio_group', label => 'Select branches by', tooltip => $tooltip_select_by, @@ -1360,6 +1360,9 @@ EOT event => 'activate', callback => \&on_set_tree_line_widths, }, + separator => { + type => 'Gtk2::SeparatorMenuItem', + }, }; my $item = $items->{$wanted}; From 53f57c3c78cfd84f01c992f6df5636b96c5c9df9 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 16:22:22 +1100 Subject: [PATCH 34/41] GUI: refactor tree plotting highlight menu items --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 30 +++++---------------------- lib/Biodiverse/GUI/Tabs/Labels.pm | 28 ++++--------------------- lib/Biodiverse/GUI/Tabs/Tab.pm | 29 +++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 50 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index 5fee15619..db25679be 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -350,28 +350,10 @@ sub get_tree_menu_items { label => 'Tree options:', tooltip => "Options to work with the cluster tree", }, - $self->get_tree_menu_item ('plot_branches_by'), - $self->get_tree_menu_item ('group_branches_by'), - { - type => 'Gtk2::CheckMenuItem', - label => 'Highlight groups on map', - tooltip => 'When hovering the mouse over a tree branch, ' - . 'highlight the groups on the map in which it is found.', - event => 'toggled', - callback => \&on_highlight_groups_on_map_changed, - active => 1, - self_key => 'checkbox_show_tree_legend', - }, - { - type => 'Gtk2::CheckMenuItem', - label => 'Highlight paths on tree', - tooltip => "When hovering over a group on the map, highlight the paths " - . "connecting the tips of the tree (that match labels in the group) " - . "to the root.", - event => 'toggled', - callback => \&on_use_highlight_path_changed, - active => 1, - }, + $self->get_tree_menu_item('plot_branches_by'), + $self->get_tree_menu_item('group_branches_by'), + $self->get_tree_menu_item('highlight_groups_on_map'), + $self->get_tree_menu_item('highlight_paths_on_tree'), { type => 'Gtk2::CheckMenuItem', label => 'Use the slider bar to select branches for colouring', @@ -384,9 +366,7 @@ sub get_tree_menu_items { }, active => 1, }, - { - type => 'Gtk2::SeparatorMenuItem', - }, + $self->get_tree_menu_item('separator'), $self->get_tree_menu_item('set_tree_branch_line_widths'), $self->get_tree_menu_item('separator'), { diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index 30786d3a3..52cc8a87f 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -340,30 +340,10 @@ sub get_tree_menu_items { . "(this is the same as the one selected at " . "the project level)", }, - $self->get_tree_menu_item ('plot_branches_by'), - { - type => 'Gtk2::CheckMenuItem', - label => 'Highlight groups on map?', - tooltip => 'When hovering the mouse over a tree branch, ' - . 'highlight the groups on the map in which it is found.', - event => 'toggled', - callback => \&on_highlight_groups_on_map_changed, - active => 1, - self_key => 'checkbox_show_tree_legend', - }, - { - type => 'Gtk2::CheckMenuItem', - label => 'Highlight paths on tree?', - tooltip => "When hovering over a group on the map, highlight the paths " - . "connecting the tips of the tree (that match labels in the group) " - . "to the root.", - event => 'toggled', - callback => \&on_use_highlight_path_changed, - active => 1, - }, - { - type => 'Gtk2::SeparatorMenuItem', - }, + $self->get_tree_menu_item('plot_branches_by'), + $self->get_tree_menu_item('highlight_groups_on_map'), + $self->get_tree_menu_item('highlight_paths_on_tree'), + $self->get_tree_menu_item('separator'), $self->get_tree_menu_item('set_tree_branch_line_widths'), $self->get_tree_menu_item('separator'), { diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index 446a8ef68..dce93587f 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -1360,7 +1360,33 @@ EOT event => 'activate', callback => \&on_set_tree_line_widths, }, - separator => { + highlight_groups_on_map => { + type => 'Gtk2::CheckMenuItem', + label => 'Highlight groups on map', + tooltip => 'When hovering the mouse over a tree branch, ' + . 'highlight the groups on the map in which it is found.', + event => 'toggled', + callback => sub { + my $self = shift; + $self->on_highlight_groups_on_map_changed; + }, + active => 1, + self_key => 'checkbox_show_tree_legend', + }, + highlight_paths_on_tree => { + type => 'Gtk2::CheckMenuItem', + label => 'Highlight paths on tree', + tooltip => "When hovering over a group on the map, highlight the paths " + . "connecting the tips of the tree (that match labels in the group) " + . "to the root.", + event => 'toggled', + callback => sub { + my $self = shift; + $self->on_use_highlight_path_changed; + }, + active => 1, + }, + separator => { type => 'Gtk2::SeparatorMenuItem', }, }; @@ -1372,4 +1398,5 @@ EOT return $item; } + 1; From ae49223b78088049c3f1b59b7ef470aaa5184543 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 16:38:49 +1100 Subject: [PATCH 35/41] GUI: refactor tree plotting menu item setups --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 14 +++++++------- lib/Biodiverse/GUI/Tabs/Labels.pm | 10 ++++------ lib/Biodiverse/GUI/Tabs/Spatial.pm | 7 +++---- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index db25679be..100d322d9 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -350,10 +350,10 @@ sub get_tree_menu_items { label => 'Tree options:', tooltip => "Options to work with the cluster tree", }, - $self->get_tree_menu_item('plot_branches_by'), - $self->get_tree_menu_item('group_branches_by'), - $self->get_tree_menu_item('highlight_groups_on_map'), - $self->get_tree_menu_item('highlight_paths_on_tree'), + ( map {$self->get_tree_menu_item($_)} + qw /plot_branches_by group_branches_by + highlight_groups_on_map highlight_paths_on_tree/ + ), { type => 'Gtk2::CheckMenuItem', label => 'Use the slider bar to select branches for colouring', @@ -366,9 +366,9 @@ sub get_tree_menu_items { }, active => 1, }, - $self->get_tree_menu_item('separator'), - $self->get_tree_menu_item('set_tree_branch_line_widths'), - $self->get_tree_menu_item('separator'), + ( map {$self->get_tree_menu_item($_)} + qw/separator set_tree_branch_line_widths separator/ + ), { type => 'Gtk2::MenuItem', label => 'Export tree', diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index 52cc8a87f..6d198960e 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -340,12 +340,10 @@ sub get_tree_menu_items { . "(this is the same as the one selected at " . "the project level)", }, - $self->get_tree_menu_item('plot_branches_by'), - $self->get_tree_menu_item('highlight_groups_on_map'), - $self->get_tree_menu_item('highlight_paths_on_tree'), - $self->get_tree_menu_item('separator'), - $self->get_tree_menu_item('set_tree_branch_line_widths'), - $self->get_tree_menu_item('separator'), + ( map {$self->get_tree_menu_item($_)} + qw /plot_branches_by highlight_groups_on_map highlight_paths_on_tree + separator set_tree_branch_line_widths separator/ + ), { type => 'Gtk2::MenuItem', label => 'Export tree', diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 036342cc4..0c7367836 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -403,10 +403,9 @@ sub get_tree_menu_items { } ], }, - $self->get_tree_menu_item('separator'), - $self->get_tree_menu_item('plot_branches_by'), - $self->get_tree_menu_item('set_tree_branch_line_widths'), - $self->get_tree_menu_item('separator'), + ( map {$self->get_tree_menu_item($_)} + qw /separator plot_branches_by set_tree_branch_line_widths separator/ + ), { type => 'Gtk2::MenuItem', label => 'Export', From 6958a4b6f55addbbe784338a48c6f80ea0655cbd Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 16:54:50 +1100 Subject: [PATCH 36/41] GUI: refactor tree plot export menu items --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 13 ++----------- lib/Biodiverse/GUI/Tabs/Labels.pm | 17 ++++------------- lib/Biodiverse/GUI/Tabs/Spatial.pm | 13 ++----------- lib/Biodiverse/GUI/Tabs/Tab.pm | 12 ++++++++++++ 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index 100d322d9..8d03666a1 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -367,18 +367,9 @@ sub get_tree_menu_items { active => 1, }, ( map {$self->get_tree_menu_item($_)} - qw/separator set_tree_branch_line_widths separator/ + qw/separator set_tree_branch_line_widths + separator export_tree/ ), - { - type => 'Gtk2::MenuItem', - label => 'Export tree', - tooltip => 'Export the currently displayed tree', - event => 'activate', - callback => sub { - my $tree_ref = $self->get_cluster_ref; - return Biodiverse::GUI::Export::Run($tree_ref); - }, - }, ); return wantarray ? @menu_items : \@menu_items; diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index 6d198960e..88a359c1a 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -341,20 +341,11 @@ sub get_tree_menu_items { . "the project level)", }, ( map {$self->get_tree_menu_item($_)} - qw /plot_branches_by highlight_groups_on_map highlight_paths_on_tree - separator set_tree_branch_line_widths separator/ + qw /plot_branches_by + highlight_groups_on_map highlight_paths_on_tree + separator set_tree_branch_line_widths + separator export_tree / ), - { - type => 'Gtk2::MenuItem', - label => 'Export tree', - tooltip => 'Export the currently displayed tree', - event => 'activate', - callback => sub { - my $tree_ref = $self->{project}->get_selected_phylogeny; - return if !$tree_ref; - return Biodiverse::GUI::Export::Run($tree_ref); - }, - }, ); return wantarray ? @menu_items : \@menu_items; diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 0c7367836..335d8f986 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -404,18 +404,9 @@ sub get_tree_menu_items { ], }, ( map {$self->get_tree_menu_item($_)} - qw /separator plot_branches_by set_tree_branch_line_widths separator/ + qw /separator plot_branches_by set_tree_branch_line_widths + separator export_tree / ), - { - type => 'Gtk2::MenuItem', - label => 'Export', - tooltip => 'Export the currently displayed tree', - event => 'activate', - callback => sub { - my $tree_ref = $self->get_current_tree; - return Biodiverse::GUI::Export::Run($tree_ref); - }, - }, ); return wantarray ? @menu_items : \@menu_items; diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index dce93587f..4f4e5e1a7 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -1386,6 +1386,18 @@ EOT }, active => 1, }, + export_tree => { + type => 'Gtk2::MenuItem', + label => 'Export tree', + tooltip => 'Export the currently displayed tree', + event => 'activate', + callback => sub { + my $self = shift; + my $tree_ref = $self->get_current_tree; + return if !$tree_ref; + return Biodiverse::GUI::Export::Run($tree_ref); + }, + }, separator => { type => 'Gtk2::SeparatorMenuItem', }, From c7aa12bd90d04a14c6235e20e2e8664fee34cc65 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 17:00:08 +1100 Subject: [PATCH 37/41] GUI Clustering: update tree side menu after run --- lib/Biodiverse/GUI/Tabs/Clustering.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index 8d03666a1..bda1e5c93 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -1371,6 +1371,7 @@ sub on_run_analysis { } $self->init_colour_clusters; + $self->update_tree_menu; # If just ran a new analysis, pull up the pane if ($isnew or not $new_analysis) { From 563b92cf1268f6a4afe61f5d3978cd92cd094a23 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 17:04:48 +1100 Subject: [PATCH 38/41] GUI Export interface: reinstate keyboard snooper before returning Otherwise we lose all keyboard shortcuts. --- lib/Biodiverse/GUI/Export.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Biodiverse/GUI/Export.pm b/lib/Biodiverse/GUI/Export.pm index 1ff01f827..7f3d7e65e 100644 --- a/lib/Biodiverse/GUI/Export.pm +++ b/lib/Biodiverse/GUI/Export.pm @@ -36,6 +36,7 @@ sub Run { my $gui = Biodiverse::GUI::GUIManager->instance; # stop keyboard events being applied to any open tabs + my $snooper_status = $gui->keyboard_snooper_active; $gui->activate_keyboard_snooper (0); # Get the Parameters metadata @@ -77,6 +78,7 @@ sub Run { if ($format_response ne 'ok') { $format_dlg->destroy; + $gui->activate_keyboard_snooper ($snooper_status); return; } @@ -98,7 +100,10 @@ sub Run { selected_format => $selected_format, ); - return if !$results->{success}; + if (!$results->{success}) { + $gui->activate_keyboard_snooper($snooper_status); + return; + } my $chooser = $results->{chooser}; my $parameters_table = $results->{param_table}; @@ -139,7 +144,7 @@ sub Run { } $dlg->destroy; - $gui->activate_keyboard_snooper (1); + $gui->activate_keyboard_snooper ($snooper_status); return; } From 05226efcceba4e812905141fee8cdeb7ba6f9bcf Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 5 Jan 2024 17:59:01 +1100 Subject: [PATCH 39/41] GUI: abstract more xmlPage calls Might have some gremlins lurking but they will manifest through usage. --- lib/Biodiverse/GUI/Dendrogram.pm | 1 + lib/Biodiverse/GUI/Tabs/Clustering.pm | 45 +++++++++++------------- lib/Biodiverse/GUI/Tabs/Labels.pm | 33 +++++++---------- lib/Biodiverse/GUI/Tabs/Outputs.pm | 17 ++++----- lib/Biodiverse/GUI/Tabs/Randomise.pm | 27 ++++++-------- lib/Biodiverse/GUI/Tabs/RegionGrower.pm | 3 +- lib/Biodiverse/GUI/Tabs/Spatial.pm | 13 +++---- lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm | 2 +- lib/Biodiverse/GUI/Tabs/Tab.pm | 4 --- 9 files changed, 57 insertions(+), 88 deletions(-) diff --git a/lib/Biodiverse/GUI/Dendrogram.pm b/lib/Biodiverse/GUI/Dendrogram.pm index 099f479d4..930fb9854 100644 --- a/lib/Biodiverse/GUI/Dendrogram.pm +++ b/lib/Biodiverse/GUI/Dendrogram.pm @@ -118,6 +118,7 @@ sub new { foreach my $widget_name (qw /selector_toggle selector_colorbutton autoincrement_toggle/) { eval { + # use get_xmlpage_object from parent $self->{$widget_name} = $self->get_parent_tab->{xmlPage}->get_object($widget_name); }; diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index bda1e5c93..8534931a4 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -63,7 +63,7 @@ sub new { $self->{xmlPage} = $xml_page; $self->{xmlLabel} = $xml_label; - my $page = $xml_page->get_object('hboxClusteringPage'); + my $page = $self->get_xmlpage_object('hboxClusteringPage'); my $label = $xml_label->get_object('hboxClusteringLabel'); my $label_text = $self->{xmlLabel}->get_object('lblClusteringName')->get_text; @@ -127,8 +127,8 @@ sub new { $self->queue_set_pane(1, 'vpaneClustering'); $self->{existing} = 0; - $xml_page->get_object('toolbarClustering')->hide; - $xml_page->get_object('toolbar_clustering_bottom')->hide; + $self->get_xmlpage_object('toolbarClustering')->hide; + $self->get_xmlpage_object('toolbar_clustering_bottom')->hide; } else { # We're being called to show an EXISTING output @@ -169,7 +169,7 @@ sub new { $defq_object = $def_query_init1; } if (my $prng_seed = $cluster_ref->get_prng_seed_argument()) { - my $spin_widget = $xml_page->get_object('spinbutton_cluster_prng_seed'); + my $spin_widget = $self->get_xmlpage_object('spinbutton_cluster_prng_seed'); $spin_widget->set_value ($prng_seed); } } @@ -192,7 +192,7 @@ sub new { initial_text => $sp_initial1, condition_object => $spatial_conditions[0], ); - $xml_page->get_object('frameClusterSpatialParams1')->add( + $self->get_xmlpage_object('frameClusterSpatialParams1')->add( $self->{spatialParams1}->get_object, ); @@ -202,7 +202,7 @@ sub new { start_hidden => $start_hidden, condition_object => $spatial_conditions[1], ); - $xml_page->get_object('frameClusterSpatialParams2')->add( + $self->get_xmlpage_object('frameClusterSpatialParams2')->add( $self->{spatialParams2}->get_object ); @@ -213,12 +213,12 @@ sub new { is_def_query => 'is_def_query', condition_object => $defq_object, ); - $xml_page->get_object('frameClusterDefinitionQuery1')->add( + $self->get_xmlpage_object('frameClusterDefinitionQuery1')->add( $self->{definition_query1}->get_object ); - # $xml_page->get_object('plot_length') ->set_active(1); - # $xml_page->get_object('group_length')->set_active(1); + # $self->get_xmlpage_object('plot_length') ->set_active(1); + # $self->get_xmlpage_object('group_length')->set_active(1); $self->{plot_mode} = 'length'; $self->{group_mode} = 'length'; @@ -253,7 +253,7 @@ sub new { ); Biodiverse::GUI::Tabs::CalculationsTree::init_calculations_tree( - $xml_page->get_object('treeSpatialCalculations'), + $self->get_xmlpage_object('treeSpatialCalculations'), $self->{calculations_model} ); @@ -306,7 +306,7 @@ sub new { foreach my $widget_name (sort keys %widgets_and_signals) { my $args = $widgets_and_signals{$widget_name}; #say $widget_name; - my $widget = $xml_page->get_object($widget_name); + my $widget = $self->get_xmlpage_object($widget_name); if (!defined $widget) { warn "$widget_name not found"; next; @@ -407,9 +407,8 @@ sub setup_tie_breaker_widgets { my $self = shift; my $existing = shift; - my $xml_page = $self->{xmlPage}; my $hbox_name = 'hbox_cluster_tie_breakers'; - my $breaker_hbox = $xml_page->get_object($hbox_name); + my $breaker_hbox = $self->get_xmlpage_object($hbox_name); my ($tie_breakers, $bd); if ($existing) { @@ -486,13 +485,12 @@ sub setup_tie_breaker_widgets { # thus avoiding the need to build the list. sub set_colour_stretch_widgets_and_signals { my $self = shift; - my $xml_page = $self->{xmlPage}; # lazy - should build from menu widget my $i = 0; foreach my $stretch (qw /min-max 5-95 2.5-97.5 min-95 min-97.5 5-max 2.5-max/) { my $widget_name = "radio_dendro_colour_stretch$i"; - my $widget = $xml_page->get_object($widget_name); + my $widget = $self->get_xmlpage_object($widget_name); my $sub = sub { my $self = shift; @@ -569,11 +567,9 @@ sub on_show_hide_parameters { sub init_map { my $self = shift; - my $xml_page = $self->{xmlPage}; - - my $frame = $xml_page->get_object('mapFrame'); - my $hscroll = $xml_page->get_object('mapHScroll'); - my $vscroll = $xml_page->get_object('mapVScroll'); + my $frame = $self->get_xmlpage_object('mapFrame'); + my $hscroll = $self->get_xmlpage_object('mapHScroll'); + my $vscroll = $self->get_xmlpage_object('mapVScroll'); my $click_closure = sub { $self->on_grid_popup(@_); }; my $hover_closure = sub { $self->on_grid_hover(@_); }; @@ -600,12 +596,12 @@ sub init_map { $grid->set_base_struct($self->{basedata_ref}->get_groups_ref); - my $menu_log_checkbox = $xml_page->get_object('menu_dendro_colour_stretch_log_mode'); + my $menu_log_checkbox = $self->get_xmlpage_object('menu_dendro_colour_stretch_log_mode'); $menu_log_checkbox->signal_connect_swapped( toggled => \&on_grid_colour_scaling_changed, $self, ); - my $checkbox = $xml_page->get_object('menu_dendro_colour_stretch_flip_mode'); + my $checkbox = $self->get_xmlpage_object('menu_dendro_colour_stretch_flip_mode'); $checkbox->signal_connect_swapped( toggled => \&on_grid_colour_flip_changed, $self, @@ -1757,8 +1753,7 @@ sub show_cluster_descendents { sub on_name_changed { my $self = shift; - my $xml_page = $self->{xmlPage}; - my $name = $xml_page->get_object('txtClusterName')->get_text(); + my $name = $self->get_xmlpage_object('txtClusterName')->get_text(); my $label_widget = $self->{xmlLabel}->get_object('lblClusteringName'); $label_widget->set_text($name); @@ -1768,7 +1763,7 @@ sub on_name_changed { my $param_widget - = $xml_page->get_object('lbl_parameter_clustering_name'); + = $self->get_xmlpage_object('lbl_parameter_clustering_name'); $param_widget->set_markup("Name"); my $bd = $self->{basedata_ref}; diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index 88a359c1a..f517e22bf 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -164,7 +164,6 @@ sub new { $self->{active_pane} = ''; # Connect signals - my $xml = $self->{xmlPage}; $self->{xmlLabel}->get_object('btnLabelsClose')->signal_connect_swapped(clicked => \&on_close, $self); @@ -184,18 +183,18 @@ sub new { $sig_clicked->('btnZoomOutToolVL', \&on_zoom_out_tool); $sig_clicked->('btnZoomFitToolVL', \&on_zoom_fit_tool); - $xml->get_object('menuitem_labels_overlays')->signal_connect_swapped(activate => \&on_overlays, $self); + $self->get_xmlpage_object('menuitem_labels_overlays')->signal_connect_swapped(activate => \&on_overlays, $self); $self->get_xmlpage_object("btnSelectToolVL")->set_active(1); - $xml->get_object('menuitem_labels_show_legend')->signal_connect_swapped( + $self->get_xmlpage_object('menuitem_labels_show_legend')->signal_connect_swapped( toggled => \&on_show_hide_legend, $self ); foreach my $type_option (qw /auto linear log/) { my $radio_item = 'radiomenuitem_grid_colouring_' . $type_option; - $xml->get_object($radio_item)->signal_connect_swapped( + $self->get_xmlpage_object($radio_item)->signal_connect_swapped( toggled => \&on_grid_colour_scaling_changed, $self, ); @@ -824,12 +823,10 @@ sub on_selected_matrix_changed { $self->{matrix_ref} = $matrix_ref; - my $xml_page = $self->{xmlPage}; - # hide the second list if no matrix selected - my $list_window = $xml_page->get_object('scrolledwindow_labels2'); + my $list_window = $self->get_xmlpage_object('scrolledwindow_labels2'); - my $list = $xml_page->get_object('listLabels1'); + my $list = $self->get_xmlpage_object('listLabels1'); my $col = $list->get_column ($labels_model_list2_sel_col); my $labels_are_in_mx = $self->some_labels_are_in_matrix; @@ -860,8 +857,6 @@ sub on_grid_colour_scaling_changed { # avoid triggering twice - we only care about which one is active return if !$radio_widget->get_active; - - my $xml_page = $self->{xmlPage}; my %names_and_strings; foreach my $opt (qw /auto linear log/) { @@ -871,7 +866,7 @@ sub on_grid_colour_scaling_changed { my $mode_string; foreach my $name (keys %names_and_strings) { my $string = $names_and_strings{$name}; - my $widget = $xml_page->get_object($name); + my $widget = $self->get_xmlpage_object($name); if ($widget->get_active) { $mode_string = $string; last; @@ -1125,9 +1120,8 @@ sub on_sorted { my $redraw = $args{redraw}; - my $xml_page = $self->{xmlPage}; - my $hmodel = $xml_page->get_object('listLabels1')->get_model(); - my $vmodel = $xml_page->get_object('listLabels2')->get_model(); + my $hmodel = $self->get_xmlpage_object('listLabels1')->get_model(); + my $vmodel = $self->get_xmlpage_object('listLabels2')->get_model(); my $model = $self->{labels_model}; my $matrix_ref = $self->{matrix_ref}; @@ -1287,10 +1281,9 @@ sub on_grid_select { } # Select all terminal labels - my $xml_page = $self->{xmlPage}; - my $model = $self->{labels_model}; - my $hmodel = $xml_page->get_object('listLabels1')->get_model(); - my $hselection = $xml_page ->get_object('listLabels1')->get_selection(); + my $model = $self->{labels_model}; + my $hmodel = $self->get_xmlpage_object('listLabels1')->get_model(); + my $hselection = $self->get_xml_page_object('listLabels1')->get_selection(); my $sel_mode = $self->get_selection_mode; @@ -1334,8 +1327,6 @@ sub on_grid_select { sub on_phylogeny_plot_mode_changed { my ($self, $combo) = @_; - my $xml_page = $self->{xmlPage}; - my %names_and_strings = ( phylogeny_plot_depth => 'depth', phylogeny_plot_length => 'length', @@ -1344,7 +1335,7 @@ sub on_phylogeny_plot_mode_changed { my $mode_string; while (my ($name, $string) = each %names_and_strings) { - my $widget = $xml_page->get_object($name); + my $widget = $self->get_xmlpage_object($name); if ($widget->get_active) { $mode_string = $string; last; diff --git a/lib/Biodiverse/GUI/Tabs/Outputs.pm b/lib/Biodiverse/GUI/Tabs/Outputs.pm index 00f2f56cb..8bcca457d 100644 --- a/lib/Biodiverse/GUI/Tabs/Outputs.pm +++ b/lib/Biodiverse/GUI/Tabs/Outputs.pm @@ -30,7 +30,7 @@ sub new { $self->{xmlLabel} = Gtk2::Builder->new(); $self->{xmlLabel}->add_from_file($self->{gui}->get_gtk_ui_file('hboxOutputsLabel.ui')); - my $page = $self->{xmlPage} ->get_object('hboxOutputsPage'); + my $page = $self->get_xmlpage_object('hboxOutputsPage'); my $label = $self->{xmlLabel}->get_object('hboxOutputsLabel'); my $menu_label = Gtk2::Label->new ('Outputs tab'); @@ -78,13 +78,11 @@ sub new { $model->signal_connect('row-inserted' => \&on_row_inserted, $self); # Connect signals - #$self->{xmlLabel}->get_object("btnOutputsClose")->signal_connect_swapped(clicked => \&Tabs::Tab::on_close, $self); - my $xml_page = $self->{xmlPage}; - $xml_page->get_object('btnOutputsShow' )->signal_connect_swapped(clicked => \&on_show, $self); - $xml_page->get_object('btnOutputsExport')->signal_connect_swapped(clicked => \&on_export, $self); - $xml_page->get_object('btnOutputsDelete')->signal_connect_swapped(clicked => \&on_delete, $self); - $xml_page->get_object('btnOutputsRename')->signal_connect_swapped(clicked => \&on_rename, $self); - $xml_page->get_object('btnOutputsDescribe')->signal_connect_swapped(clicked => \&on_describe, $self); + $self->get_xmlpage_object('btnOutputsShow' )->signal_connect_swapped(clicked => \&on_show, $self); + $self->get_xmlpage_object('btnOutputsExport')->signal_connect_swapped(clicked => \&on_export, $self); + $self->get_xmlpage_object('btnOutputsDelete')->signal_connect_swapped(clicked => \&on_delete, $self); + $self->get_xmlpage_object('btnOutputsRename')->signal_connect_swapped(clicked => \&on_rename, $self); + $self->get_xmlpage_object('btnOutputsDescribe')->signal_connect_swapped(clicked => \&on_describe, $self); @@ -206,12 +204,11 @@ sub on_row_changed { my $sensitive = $type eq 'output' || $type eq 'basedata'; - my $xml_page = $self->{xmlPage}; my @widget_name_array = qw /btnOutputsExport btnOutputsDelete btnOutputsRename/; foreach my $widget_name (@widget_name_array) { - $xml_page->get_object($widget_name)->set_sensitive($sensitive); + $self->get_xmlpage_object($widget_name)->set_sensitive($sensitive); } # If clicked on basedata, select it diff --git a/lib/Biodiverse/GUI/Tabs/Randomise.pm b/lib/Biodiverse/GUI/Tabs/Randomise.pm index dd7cd0c63..b2c97711d 100644 --- a/lib/Biodiverse/GUI/Tabs/Randomise.pm +++ b/lib/Biodiverse/GUI/Tabs/Randomise.pm @@ -55,10 +55,9 @@ sub new { $self->{xmlLabel} = Gtk2::Builder->new(); $self->{xmlLabel}->add_from_file($self->{gui}->get_gtk_ui_file('hboxRandomiseLabel.ui')); - my $xml_page = $self->{xmlPage}; my $xml_label = $self->{xmlLabel}; - my $page = $xml_page ->get_object('vboxRandomisePage'); + my $page = $self->get_xmlpage_object('vboxRandomisePage'); my $label = $xml_label->get_object('hboxRandomiseLabel'); my $label_text = $xml_label->get_object('lblRandomiseName')->get_text; my $label_widget = Gtk2::Label->new ($label_text); @@ -105,7 +104,7 @@ sub new { $self->add_iteration_count_to_table ($output_ref); my $name; - my $seed_widget = $xml_page->get_object('randomise_seed_value'); + my $seed_widget = $self->get_xmlpage_object('randomise_seed_value'); if ($output_ref) { #$self->{project}->register_in_outputs_model ($output_ref, $self); $self->register_in_outputs_model ($output_ref, $self); @@ -119,7 +118,7 @@ sub new { } $xml_label->get_object('lblRandomiseName')->set_text($name); - $xml_page ->get_object('randomise_results_list_name')->set_text ($name); + $self->get_xmlpage_object('randomise_results_list_name')->set_text ($name); $self->{tab_menu_label}->set_text($name ); # Connect signals @@ -127,11 +126,11 @@ sub new { clicked => \&on_close, $self, ); - $xml_page->get_object('btnRandomise')->signal_connect_swapped( + $self->get_xmlpage_object('btnRandomise')->signal_connect_swapped( clicked => \&on_run, $self, ); - $xml_page->get_object('randomise_results_list_name')->signal_connect_swapped( + $self->get_xmlpage_object('randomise_results_list_name')->signal_connect_swapped( changed => \&on_name_changed, $self, ); @@ -145,9 +144,7 @@ sub new { sub get_table_widget { my $self = shift; - my $xml_page = $self->{xmlPage}; - - my $table = $xml_page->get_object('table_randomise_setup'); + my $table = $self->get_xmlpage_object('table_randomise_setup'); return $table; } @@ -167,9 +164,7 @@ sub add_iteration_count_to_table { my $self = shift; my $output_ref = shift; - my $xml_page = $self->{xmlPage}; - - my $table = $xml_page->get_object('table_randomise_setup'); + my $table = $self->get_xmlpage_object('table_randomise_setup'); my $count = defined $output_ref ? $output_ref->get_param ('TOTAL_ITERATIONS') @@ -218,9 +213,8 @@ sub set_button_sensitivity { comboFunction /; - my $xml_page = $self->{xmlPage}; foreach my $widget (@widgets) { - $xml_page->get_object($widget)->set_sensitive ($sens); + $self->get_xmlpage_object($widget)->set_sensitive ($sens); } my $table = $self->get_xmlpage_object('tableParams'); @@ -619,9 +613,8 @@ sub on_run { $args{iterations} = $self->get_xmlpage_object('spinIterations')->get_value_as_int; - my $xml_page = $self->{xmlPage}; - my $name = $xml_page->get_object('randomise_results_list_name')->get_text; - my $seed = $xml_page->get_object('randomise_seed_value')->get_text; + my $name = $self->get_xmlpage_object('randomise_results_list_name')->get_text; + my $seed = $self->get_xmlpage_object('randomise_seed_value')->get_text; $seed =~ s/\s//g; # strip any whitespace if (not defined $seed or length ($seed) == 0) { warn "[GUI Randomise] PRNG seed is not defined, using system default\n"; diff --git a/lib/Biodiverse/GUI/Tabs/RegionGrower.pm b/lib/Biodiverse/GUI/Tabs/RegionGrower.pm index 8326e8289..c1aaf68d3 100644 --- a/lib/Biodiverse/GUI/Tabs/RegionGrower.pm +++ b/lib/Biodiverse/GUI/Tabs/RegionGrower.pm @@ -20,8 +20,7 @@ sub new { bless $self, $class; # now add some additional stuff - my $xml_page = $self->{xmlPage}; - my $hbox = $xml_page->get_object('hbox_cluster_metric'); + my $hbox = $self->get_xmlpage_object('hbox_cluster_metric'); my $label_widget = Gtk2::Label->new('Objective function: '); my $combo_minmax = Gtk2::ComboBox->new_text(); diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 335d8f986..3879751dc 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -141,7 +141,7 @@ sub new { $self->{output_ref} = $output_ref; # Initialise widgets - $self->{title_widget} = $self->{xmlPage} ->get_object('txtSpatialName'); + $self->{title_widget} = $self->get_xmlpage_object('txtSpatialName'); $self->{label_widget} = $self->{xmlLabel}->get_object('lblSpatialName'); $self->{title_widget}->set_text($self->{output_name} ); @@ -477,8 +477,7 @@ sub setup_dendrogram { sub update_dendrogram_combo { my $self = shift; - my $xmlpage = $self->{xmlPage}; - my $combobox = $xmlpage->get_object('comboTreeSelect'); + my $combobox = $self->get_xmlpage_object('comboTreeSelect'); # Clear the curent entries. # We need to load a new ListStore to avoid crashes due @@ -572,8 +571,7 @@ sub init_branch_colouring_menu { return if !defined $self->{output_ref}; return if blessed ($self) =~ /Matrix/; - my $xml_page = $self->{xmlPage}; - my $bottom_hbox = $xml_page->get_object('hbox_spatial_tab_bottom'); + my $bottom_hbox = $self->get_xmlpage_object('hbox_spatial_tab_bottom'); my $menubar = $self->{branch_colouring_menu}; my $have_menu = !!$menubar; @@ -1884,8 +1882,7 @@ sub get_current_tree { sub on_name_changed { my $self = shift; - my $xml_page = $self->{xmlPage}; - my $name = $xml_page->get_object('txtSpatialName')->get_text(); + my $name = $self->get_xmlpage_object('txtSpatialName')->get_text(); my $label_widget = $self->{xmlLabel}->get_object('lblSpatialName'); $label_widget->set_text($name); @@ -1894,7 +1891,7 @@ sub on_name_changed { $tab_menu_label->set_text($name); my $param_widget - = $xml_page->get_object('lbl_parameter_spatial_name'); + = $self->get_xmlpage_object('lbl_parameter_spatial_name'); $param_widget->set_markup("Name"); my $bd = $self->{basedata_ref}; diff --git a/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm b/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm index eb3934944..4a1210f14 100644 --- a/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm +++ b/lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm @@ -106,7 +106,7 @@ sub new { # Initialise widgets - $self->{title_widget} = $self->{xmlPage} ->get_object('txtSpatialName'); + $self->{title_widget} = $self->get_xmlpage_object('txtSpatialName'); $self->{label_widget} = $self->{xmlLabel}->get_object('lblSpatialName'); $self->{title_widget}->set_text($self->{output_name} ); diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index 4f4e5e1a7..5eb9f93fd 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -445,8 +445,6 @@ sub on_grid_colour_flip_changed { return if !$grid; - my $xml_page = $self->{xmlPage}; - my $active = !!$checkbox->get_active; my $prev_mode = !!$grid->get_legend->get_invert_colours; @@ -465,8 +463,6 @@ sub on_grid_colour_flip_changed { sub on_grid_colour_scaling_changed { my ($self, $checkbox) = @_; - my $xml_page = $self->{xmlPage}; - my $active = $checkbox->get_active; if ($active) { From 3a4bf3cd07f1ede0c848f8e2ce0c6306f3cfeba4 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Sat, 6 Jan 2024 11:45:52 +1100 Subject: [PATCH 40/41] GUI tabs: rename Display side menu to Map This makes more sense now we have separated the tree options into a separate menu. Add some separators as well. --- bin/ui/hboxClusteringPage.ui | 2 +- bin/ui/hboxLabelsPage.ui | 13 +++++++++++-- bin/ui/hboxSpatialPage.ui | 2 +- lib/Biodiverse/GUI/Tabs/Tab.pm | 4 +++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/bin/ui/hboxClusteringPage.ui b/bin/ui/hboxClusteringPage.ui index 5f5ef9f08..318f1b892 100644 --- a/bin/ui/hboxClusteringPage.ui +++ b/bin/ui/hboxClusteringPage.ui @@ -182,7 +182,7 @@ True False - Display + Map True diff --git a/bin/ui/hboxLabelsPage.ui b/bin/ui/hboxLabelsPage.ui index 5a9a0462c..16ecf998f 100644 --- a/bin/ui/hboxLabelsPage.ui +++ b/bin/ui/hboxLabelsPage.ui @@ -150,6 +150,15 @@ False + + + True + False + + + False + + True @@ -163,7 +172,7 @@ True False - Display + Map True @@ -173,7 +182,7 @@ True False - Grid + Display options: True diff --git a/bin/ui/hboxSpatialPage.ui b/bin/ui/hboxSpatialPage.ui index c6df15f42..180864bdc 100644 --- a/bin/ui/hboxSpatialPage.ui +++ b/bin/ui/hboxSpatialPage.ui @@ -176,7 +176,7 @@ True False - Display + Map True diff --git a/lib/Biodiverse/GUI/Tabs/Tab.pm b/lib/Biodiverse/GUI/Tabs/Tab.pm index 5eb9f93fd..4c3ff19ff 100644 --- a/lib/Biodiverse/GUI/Tabs/Tab.pm +++ b/lib/Biodiverse/GUI/Tabs/Tab.pm @@ -1194,7 +1194,9 @@ sub update_tree_menu { my $tree_menu = $self->{tree_menu}; if (!$tree_menu) { - $tree_menu = Gtk2::MenuItem->new_with_label('Tree'); + my $sep = Gtk2::SeparatorMenuItem->new; + $menubar->append($sep); + $tree_menu = Gtk2::MenuItem->new_with_label('Tree'); $menubar->append($tree_menu); $self->{tree_menu} = $tree_menu; } From ca832712af47d3b686128ad1f3cb7c0d563dc06a Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Sat, 6 Jan 2024 15:49:20 +1100 Subject: [PATCH 41/41] Fix an incorrectly spelt method name --- lib/Biodiverse/GUI/Tabs/Labels.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Biodiverse/GUI/Tabs/Labels.pm b/lib/Biodiverse/GUI/Tabs/Labels.pm index f517e22bf..0500ad196 100644 --- a/lib/Biodiverse/GUI/Tabs/Labels.pm +++ b/lib/Biodiverse/GUI/Tabs/Labels.pm @@ -1283,7 +1283,7 @@ sub on_grid_select { # Select all terminal labels my $model = $self->{labels_model}; my $hmodel = $self->get_xmlpage_object('listLabels1')->get_model(); - my $hselection = $self->get_xml_page_object('listLabels1')->get_selection(); + my $hselection = $self->get_xmlpage_object('listLabels1')->get_selection(); my $sel_mode = $self->get_selection_mode;