Skip to content

Commit

Permalink
GUI: abstract more xmlPage calls
Browse files Browse the repository at this point in the history
Might have some gremlins lurking
but they will manifest through usage.
  • Loading branch information
shawnlaffan committed Jan 5, 2024
1 parent 563b92c commit 05226ef
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 88 deletions.
1 change: 1 addition & 0 deletions lib/Biodiverse/GUI/Dendrogram.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
45 changes: 20 additions & 25 deletions lib/Biodiverse/GUI/Tabs/Clustering.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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,
);

Expand All @@ -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
);

Expand All @@ -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';

Expand Down Expand Up @@ -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}
);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(@_); };
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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("<b>Name</b>");

my $bd = $self->{basedata_ref};
Expand Down
33 changes: 12 additions & 21 deletions lib/Biodiverse/GUI/Tabs/Labels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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/) {
Expand All @@ -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;
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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',
Expand All @@ -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;
Expand Down
17 changes: 7 additions & 10 deletions lib/Biodiverse/GUI/Tabs/Outputs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);



Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 05226ef

Please sign in to comment.