App-InvestSim

 view release on metacpan or  search on metacpan

lib/App/InvestSim/GUI.pm  view on Meta::CPAN


my $currently_selected;
sub set_core_table_selected_state {
  my ($widget) = @_;
  $currently_selected->m_state('!selected') if $currently_selected;
  $currently_selected = $widget;
  $widget->m_state('selected');
}

# Some global variables for some widgets that are accessed by other methods.
my $modes_combobox;
my @core_display_values;
my $display_table;
my $rent_cap_entry;

# Some variables that are linked to widgets, that are set from elsewhere.
my ($total_rent_text, $rent_cap_text, $pinel_worth_text, $notary_fees_text, $total_invested_text);

# How to format the various modes of the drop-down menu.
my @modes_format;

lib/App/InvestSim/GUI.pm  view on Meta::CPAN

  $modes_format[MEAN_BALANCE_OVERALL] = \&format_euro;
  $modes[NET_GAIN] = "Gain Net de l'opération";
  $modes_format[NET_GAIN] = \&format_euro;
  $modes[INVESTMENT_RETURN] = "Rendement de l'opération";
  $modes_format[INVESTMENT_RETURN] = \&format_percent;
  {
    my $frame = $root->new_ttk__frame(-padding => 5);
    $frame->g_grid(-column => 1, -row => 1, -sticky => "nwes");
    $frame->g_grid_columnconfigure(0, -weight => 1); # So that it extends to the whole width.

    $modes_combobox = $frame->new_ttk__combobox(-state => 'readonly', -values => \@modes, -justify => 'center');
    $modes_combobox->g_grid(-column => 0, -row => 0, -sticky => "we");
    $modes_combobox->m_current(MONTHLY_PAYMENT);
    $modes_combobox->g_bind('<<ComboboxSelected>>', \&update_displayed_mode);
  }

  # Build the core table with the computation output.
  {
    my $frame = $root->new_ttk__frame(-padding => 3);
    $frame->g_grid(-column => 1, -row => 2, -sticky => "nwes");
     # So that it extends to the same width as column 0 of the top bar. All other
     # columns have a fixed width that is the same as the matching column in the
     # top bar.
    $frame->g_grid_columnconfigure(0, -weight => 1);

lib/App/InvestSim/GUI.pm  view on Meta::CPAN

      calculate_all();
    });

  # We're done, we can show the UI.
  $root->g_wm_deiconify();
}

# Update the values displayed in the core value table.
my @computed_values; # The output of compute_all()
sub update_displayed_mode {
  my $current_mode = $modes_combobox->m_current();
  $modes_combobox->m_selection('clear');
  my $format = $modes_format[$current_mode];
  for my $i (0..NUM_LOAN_DURATION-1) {
    for my $j (0..NUM_LOAN_AMOUNT-1) {
      $core_display_values[$i][$j] = $format->($computed_values[$i][$j][$current_mode]);
    }
  }
}

sub clear_displayed_table {
  $display_table->m_delete($display_table->m_children(''));

lib/App/InvestSim/GUI.pm  view on Meta::CPAN

    $pinel_worth_text = format_euro(App::InvestSim::Finance::pinel_investment_value());
  } else {
    $rent_cap_text = 'N/A';
    $pinel_worth_text = 'N/A';
  }

  $total_rent_text = format_euro(App::InvestSim::Finance::total_rent());
  $notary_fees_text = format_euro(App::InvestSim::Finance::notary_fees());
  $total_invested_text = format_euro(App::InvestSim::Finance::total_invested());

  my $current_mode = $modes_combobox->m_current();
  $modes_combobox->m_selection('clear');
  for my $i (0..NUM_LOAN_DURATION-1) {
    for my $j (0..NUM_LOAN_AMOUNT-1) {
      $computed_values[$i][$j] = [ App::InvestSim::Finance::calculate($values{loan_amounts}[$j], $values{loan_durations}[$i], $values{loan_rates}[$i]) ];
    }
  }
  update_displayed_table();
  update_displayed_mode();
}

1;



( run in 0.679 second using v1.01-cache-2.11-cpan-39bf76dae61 )