#!/usr/bin/perl -w -- 
#
# generated by wxGlade 0.9.5 on Sun Feb  2 13:54:50 2020
#
# To get wxPerl visit http://www.wxperl.it
#

# Note that this code file is not valid as it contains Python specific parts! It's just for testing.

use Wx qw[:allclasses];
use strict;

# begin wxGlade: dependencies
# end wxGlade

# begin wxGlade: extracode
import matplotlib
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
# end wxGlade

package MyFrame;

use Wx qw[:everything];
use base qw(Wx::Frame);
use strict;

sub new {
    my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
    $parent = undef              unless defined $parent;
    $id     = -1                 unless defined $id;
    $title  = ""                 unless defined $title;
    $pos    = wxDefaultPosition  unless defined $pos;
    $size   = wxDefaultSize      unless defined $size;
    $name   = ""                 unless defined $name;

    # begin wxGlade: MyFrame::new
    $style = wxDEFAULT_FRAME_STYLE
        unless defined $style;

    $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name );
    $self->SetSize(Wx::Size->new(400, 300));
    $self->{panel_1} = Wx::Panel->new($self, wxID_ANY);
    figure = self.matplotlib_figure = Figure()
    # 1x1 grid, first subplot
    self.matplotlib_axes = figure.add_subplot(111)
    $self->{matplotlib_canvas} = FigureCanvas->new($self->{panel_1}, wxID_ANY, figure);
    $self->{text_function} = Wx::TextCtrl->new($self->{panel_1}, wxID_ANY, "sin(x)");
    $self->{text_xmin} = Wx::TextCtrl->new($self->{panel_1}, wxID_ANY, "0");
    $self->{text_max} = Wx::TextCtrl->new($self->{panel_1}, wxID_ANY, "10");
    $self->{text_xstep} = Wx::TextCtrl->new($self->{panel_1}, wxID_ANY, "0.1");
    $self->{button_plot} = Wx::Button->new($self->{panel_1}, wxID_ANY, "Plot");
    $self->{button_clear} = Wx::Button->new($self->{panel_1}, wxID_ANY, "Clear");

    $self->__set_properties();
    $self->__do_layout();

    Wx::Event::EVT_BUTTON($self, $self->{button_plot}->GetId, $self->can('on_button_plot'));

    # end wxGlade
    # some extra code at end of MyFrame new
    return $self;

}


sub __set_properties {
    my $self = shift;
    # begin wxGlade: MyFrame::__set_properties
    $self->SetTitle("matplotlib canvas example");
    $self->{text_xmin}->SetMinSize(Wx::Size->new(40, -1));
    $self->{text_max}->SetMinSize(Wx::Size->new(40, -1));
    $self->{text_xstep}->SetMinSize(Wx::Size->new(40, -1));
    $self->{button_plot}->SetDefault();
    # end wxGlade
}

sub __do_layout {
    my $self = shift;
    # begin wxGlade: MyFrame::__do_layout
    $self->{sizer_1} = Wx::BoxSizer->new(wxVERTICAL);
    $self->{sizer_2} = Wx::BoxSizer->new(wxVERTICAL);
    $self->{sizer_3} = Wx::BoxSizer->new(wxHORIZONTAL);
    $self->{sizer_4} = Wx::BoxSizer->new(wxHORIZONTAL);
    $self->{sizer_2}->Add($self->{matplotlib_canvas}, 1, wxALL|wxEXPAND, 3);
    my $label_4 = Wx::StaticText->new($self->{panel_1}, wxID_ANY, "f(x) = ");
    $self->{sizer_4}->Add($label_4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
    $self->{sizer_4}->Add($self->{text_function}, 1, 0, 0);
    $self->{sizer_2}->Add($self->{sizer_4}, 0, wxALL|wxEXPAND, 5);
    my $label_1 = Wx::StaticText->new($self->{panel_1}, wxID_ANY, "xmin");
    $self->{sizer_3}->Add($label_1, 0, wxALIGN_CENTER_VERTICAL, 0);
    $self->{sizer_3}->Add($self->{text_xmin}, 0, 0, 0);
    my $label_2 = Wx::StaticText->new($self->{panel_1}, wxID_ANY, "xmax");
    $self->{sizer_3}->Add($label_2, 0, wxALIGN_CENTER_VERTICAL, 0);
    $self->{sizer_3}->Add($self->{text_max}, 0, 0, 0);
    my $label_3 = Wx::StaticText->new($self->{panel_1}, wxID_ANY, "step");
    $self->{sizer_3}->Add($label_3, 0, wxALIGN_CENTER_VERTICAL, 0);
    $self->{sizer_3}->Add($self->{text_xstep}, 0, 0, 0);
    $self->{sizer_3}->Add(20, 20, 1, 0, 0);
    $self->{sizer_3}->Add($self->{button_plot}, 0, 0, 0);
    $self->{sizer_3}->Add($self->{button_clear}, 0, wxLEFT, 8);
    $self->{sizer_2}->Add($self->{sizer_3}, 0, wxALL|wxEXPAND, 5);
    $self->{panel_1}->SetSizer($self->{sizer_2});
    $self->{sizer_1}->Add($self->{panel_1}, 1, wxEXPAND, 0);
    $self->SetSizer($self->{sizer_1});
    $self->Layout();
    # end wxGlade
}

sub on_button_plot {
    my ($self, $event) = @_;
    # wxGlade: MyFrame::on_button_plot <event_handler>
    warn "Event handler (on_button_plot) not implemented";
    $event->Skip;
    # end wxGlade
}


# end of class MyFrame

1;

package MyApp;

use base qw(Wx::App);
use strict;

sub OnInit {
    my( $self ) = shift;

    Wx::InitAllImageHandlers();

    my $frame = MyFrame->new();

    $self->SetTopWindow($frame);
    $frame->Show(1);

    return 1;
}
# end of class MyApp

# some extra code after MyApp

package main;

unless(caller){
    my $app = MyApp->new();
    $app->MainLoop();
}
