CLI-Gwrap

 view release on metacpan or  search on metacpan

lib/CLI/Gwrapper/wxGrid.pm  view on Meta::CPAN


    return $grid;
}

sub _populate_args_grid {
    my ($self, $parent, $name) = @_;

    return if (not my $opts = @{$self->$name});

    my $opts_rows = ($opts + $self->columns - 1) / $self->columns;
    my $grid = Wx::GridSizer->new($opts_rows, $self->columns, 0, 0);

    for my $opt (@{$self->{$name}}) {
        $self->_build_opt_widget($opt, $parent, $grid);
    }

    return $grid;
}

my @buttons = (
    { name => 'Execute',  cb => \&onClick_Execute,                      },
    { name => 'Help',     cb => \&onClick_Help,                         },
    { name => 'Close',    cb => \&onClick_Close,    flags => wxID_EXIT, },
);

# add Execute, Help, and Done buttons
sub _populate_control_h_boxsizer {
    my ($self, $parent) = @_;

    my $num_buttons = scalar @buttons;
    $num_buttons -- if (not $self->help);
    my $grid = Wx::GridSizer->new(1, , 0, 0);

    for my $b (@buttons) {
        next if ($b->{name} eq 'Help' and
                 not $self->help);
        my $button = Wx::Button->new(
            $parent,        # parent
            -1,             # ID
            $b->{name},     # button label
        );
        # attach callback to button press
        EVT_BUTTON(
            $parent,        # parent
            $button,        # the button
            sub {           # callback funtion
                $b->{cb}->($self, @_);
            },
        );
        $grid->Add(
            $button,
            1,              # proportion
            wxALIGN_CENTER | wxALIGN_CENTER_HORIZONTAL | wxALL,       # flags
            0,              # border
        );
    }

    return $grid;
}

# Button callbacks
sub onClick_Execute {
    my ($self, $button, $event) = @_;

    my @cmd_line = (
        $self->command->[0],    # the CLI command
    );
    if ($self->main_opt) {
        my $opt_string = $self->main_opt->retriever->();
        push @cmd_line, $opt_string if (defined $opt_string and $opt_string ne '');
    }
    for my $opt (@{$self->opts}, @{$self->advanced}) {
        my $opt_string = $opt->retriever->();
        push @cmd_line, $opt_string if (defined $opt_string and $opt_string ne '');
    }
  # printf "Execute: %s\n", join(' ', @cmd_line);
    $self->_execute_and_show(\@cmd_line, $self->persist);

    if (not $self->persist) {
        $self->frame->Close(1);
    }
}

sub onClick_Help {
    my ($self, $button, $event) = @_;

    my @cmd_line = (
        $self->command->[0],    # the CLI command
        $self->help,            # the option that invokes help
    );
  # printf "Help: %s\n", join(' ', @cmd_line);
    $self->_execute_and_show(\@cmd_line, 'persist');
}

sub onClick_Close {
    my ($self, $button, $event) = @_;

  # print "Close\n";
    $self->frame->Close(1);
}

sub _build_page {
    my ($self, $type) = @_;

    my $name = "${type}_page";
    return $self->$name if ($self->$name);

    my $panel = Wx::Panel->new($self->notebook);
    $self->$name($panel);
    $self->notebook->AddPage($panel, $type);

    return $panel;
}

sub _build_text_ctrl {
    my ($self, $type) = @_;

    my $name = "${type}_text_ctrl";
    return $self->$name if ($self->$name);

    my $panel = $self->_build_page($type);



( run in 0.715 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )