App-GUI-Cellgraph

 view release on metacpan or  search on metacpan

lib/App/GUI/Cellgraph/Frame/Tab/Start.pm  view on Meta::CPAN


# tab to input states and action values of firs row of automata

package App::GUI::Cellgraph::Frame::Tab::Start;
use v5.12;
use warnings;
use Wx;
use base qw/Wx::Panel/;
use App::GUI::Cellgraph::Widget::ColorToggle;
use Graphics::Toolkit::Color qw/color/;

sub new {
    my ( $class, $parent ) = @_;
    my $self = $class->SUPER::new( $parent, -1);

    $self->{'state_count'} = 2;
    $self->{'cells_in_row'} = my $cell_count = 20;
    $self->{'cells_iterator'} = [0 .. $cell_count - 1];
    $self->{'call_back'} = sub {};
    my $rule_cell_size = 20;

    $self->{'state_colors'}   = [map { [$_->values('rgb')]} color('white')->gradient( to => 'black', steps => $self->{'state_count'})];
    $self->{'state_switches'} = [map { App::GUI::Cellgraph::Widget::ColorToggle->new
                                       ( $self, $rule_cell_size, $rule_cell_size, $self->{'state_colors'}, 0) } @{$self->{'cells_iterator'}}];
    $self->{'state_switches'}[$_]->SetToolTip('click with left or right to change state of this cell in starting row') for @{$self->{'cells_iterator'}};
    # $self->{'state_switches'}[0]->Enable(0);
    $self->{'action_colors'}   = [map {[$_->values('rgb')]} color('white')->gradient(to => 'orange', steps => 6)];
    $self->{'action_switches'} = [map { App::GUI::Cellgraph::Widget::ColorToggle->new( $self, $rule_cell_size, $rule_cell_size, $self->{'action_colors'}, 0) } @{$self->{'cells_iterator'}}];
    $self->{'action_switches'}[$_]->SetToolTip('click with left or right to change action value of this cell in starting row') for @{$self->{'cells_iterator'}};

    $self->{'widget'}{'state_summary'}  = Wx::TextCtrl->new( $self, -1, 0, [-1,-1], [ 180, -1] );
    $self->{'widget'}{'state_summary'}->SetToolTip('condensed content of start row states');
    $self->{'widget'}{'action_summary'}  = Wx::TextCtrl->new( $self, -1, 0, [-1,-1], [ 180, -1] );
    $self->{'widget'}{'state_summary'}->SetToolTip('condensed content of start row activity values');
    $self->{'widget'}{'repeat_states'} = Wx::CheckBox->new( $self, -1, '  Repeat');
    $self->{'widget'}{'repeat_action'} = Wx::CheckBox->new( $self, -1, '  Repeat');
    $self->{'widget'}{'repeat_states'}->SetToolTip('repeat this pattern to fill first row');
    $self->{'widget'}{'repeat_action'}->SetToolTip('repeat this pattern to fill first row');
    $self->{'widget'}{'button'}{'prev_state'}  = Wx::Button->new( $self, -1, '<',  [-1,-1], [30,25] );
    $self->{'widget'}{'button'}{'next_state'}  = Wx::Button->new( $self, -1, '>',  [-1,-1], [30,25] );
    $self->{'widget'}{'button'}{'prev_action'} = Wx::Button->new( $self, -1, '<',  [-1,-1], [30,25] );
    $self->{'widget'}{'button'}{'next_action'} = Wx::Button->new( $self, -1, '>',  [-1,-1], [30,25] );
    $self->{'widget'}{'button'}{'init_state'}  = Wx::Button->new( $self, -1, '1',  [-1,-1], [30,25] );
    $self->{'widget'}{'button'}{'rnd_state'}   = Wx::Button->new( $self, -1, '?',  [-1,-1], [30,25] );
    $self->{'widget'}{'button'}{'init_action'} = Wx::Button->new( $self, -1, '1',  [-1,-1], [30,25] );
    $self->{'widget'}{'button'}{'rnd_action'}  = Wx::Button->new( $self, -1, '?',  [-1,-1], [30,25] );
    $self->{'widget'}{'button'}{'prev_state'}->SetToolTip('decrement number that summarizes all cell states of starting row');
    $self->{'widget'}{'button'}{'next_state'}->SetToolTip('increment number that summarizes all cell states of starting row');
    $self->{'widget'}{'button'}{'prev_action'}->SetToolTip('decrement number that summarizes the  activity values of all starting cells');
    $self->{'widget'}{'button'}{'next_action'}->SetToolTip('increment number that summarizes all cell activity values');
    $self->{'widget'}{'button'}{'init_state'}->SetToolTip('reset cell states in starting row to initial values');
    $self->{'widget'}{'button'}{'rnd_state'}->SetToolTip('generate random cell state values in starting row');
    $self->{'widget'}{'button'}{'init_action'}->SetToolTip('reset cell activity values to initial values');
    $self->{'widget'}{'button'}{'rnd_action'}->SetToolTip('generate random cell activity values in starting row');
    $self->{'label'}{'state_rules'}    = Wx::StaticText->new( $self, -1, 'Cell States' );
    $self->{'label'}{'action_rules'}   = Wx::StaticText->new( $self, -1, 'Activity Values' );
    $self->{'label'}{'state_summary'}  = Wx::StaticText->new( $self, -1, 'Summary:' );
    $self->{'label'}{'action_summary'} = Wx::StaticText->new( $self, -1, 'Summary:' );
    $self->{'label'}{'state_summary'}->SetToolTip('ID of current starting row configuration');
    $self->{'label'}{'action_summary'}->SetToolTip('ID of the configuration of activity values');

    Wx::Event::EVT_BUTTON( $self, $self->{'widget'}{'button'}{'prev_state'},  sub { $self->prev_state;  $self->{'call_back'}->() });
    Wx::Event::EVT_BUTTON( $self, $self->{'widget'}{'button'}{'next_state'},  sub { $self->next_state;  $self->{'call_back'}->() });
    Wx::Event::EVT_BUTTON( $self, $self->{'widget'}{'button'}{'init_state'},  sub { $self->init_state;  $self->{'call_back'}->() });
    Wx::Event::EVT_BUTTON( $self, $self->{'widget'}{'button'}{'rnd_state'},   sub { $self->random_state;$self->{'call_back'}->() });
    Wx::Event::EVT_BUTTON( $self, $self->{'widget'}{'button'}{'prev_action'}, sub { $self->prev_action;  $self->{'call_back'}->() });
    Wx::Event::EVT_BUTTON( $self, $self->{'widget'}{'button'}{'next_action'}, sub { $self->next_action;  $self->{'call_back'}->() });
    Wx::Event::EVT_BUTTON( $self, $self->{'widget'}{'button'}{'init_action'}, sub { $self->init_action;  $self->{'call_back'}->() });
    Wx::Event::EVT_BUTTON( $self, $self->{'widget'}{'button'}{'rnd_action'},  sub { $self->random_action;$self->{'call_back'}->() });
    Wx::Event::EVT_CHECKBOX($self,$self->{'widget'}{$_}, sub { $self->{'call_back'}->() }) for qw/repeat_states repeat_action/;
    $_->SetCallBack( sub { $self->set_state_list( $self->get_state_list ); $self->{'call_back'}->() }) for @{$self->{'state_switches'}};
    $_->SetCallBack( sub { $self->set_action_list( $self->get_action_list ); $self->{'call_back'}->() }) for @{$self->{'action_switches'}};




( run in 1.131 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )