App-GUI-Harmonograph

 view release on metacpan or  search on metacpan

lib/App/GUI/Harmonograph/Frame.pm  view on Meta::CPAN


package App::GUI::Harmonograph::Frame;
use v5.12;
use warnings;
use utf8;
use base qw/Wx::Frame/;
use Wx::AUI;
use App::GUI::Wx::Widget::Custom::ProgressBar;
use App::GUI::Harmonograph::Dialog::About;
use App::GUI::Harmonograph::Frame::Panel::Board;
use App::GUI::Harmonograph::Frame::Panel::Pendulum;
use App::GUI::Harmonograph::Frame::Tab::Function;
use App::GUI::Harmonograph::Frame::Tab::Visual;
use App::GUI::Harmonograph::Frame::Tab::Color;
use App::GUI::Harmonograph::Settings; # file IO for parameters of image
use App::GUI::Harmonograph::Config;   # file IO for program config: dirs, color set store

sub new {
    my ( $class, $parent, $title ) = @_;
    my $self = $class->SUPER::new( $parent, -1, $title );
    $self->SetIcon( Wx::GetWxPerlIcon() ); # !!! better icon
    $self->{'title'} = $title;
    $self->{'config'} = App::GUI::Harmonograph::Config->new();
    Wx::ToolTip::Enable( $self->{'config'}->get_value('tips') );
    Wx::InitAllImageHandlers();
    $self->CreateStatusBar( 2 );
    $self->SetStatusWidths( 620, -1);
    $self->SetStatusText( "no file loaded", 1 );

    # create GUI parts
    $self->{'tabs'}             = Wx::AuiNotebook->new($self, -1, [-1,-1], [-1,-1], &Wx::wxAUI_NB_TOP );
    $self->{'tab'}{'linear'}    = Wx::Panel->new($self->{'tabs'});
    $self->{'tab'}{'epicycle'}  = Wx::Panel->new($self->{'tabs'});
    $self->{'tab'}{'circular'}  = Wx::Panel->new($self->{'tabs'});
    $self->{'tab'}{'function'}  = App::GUI::Harmonograph::Frame::Tab::Function->new( $self->{'tabs'} );
    $self->{'tab'}{'color'}     = App::GUI::Harmonograph::Frame::Tab::Color->new( $self->{'tabs'}, $self->{'config'}, 10 );
    $self->{'tab'}{'visual'}    = App::GUI::Harmonograph::Frame::Tab::Visual->new( $self->{'tabs'}, $self->{'tab'}{'color'} );
    $self->{'tabs'}->AddPage( $self->{'tab'}{'linear'},   'Linearl Pendulum');
    $self->{'tabs'}->AddPage( $self->{'tab'}{'epicycle'}, 'Epi Pendulum');
    $self->{'tabs'}->AddPage( $self->{'tab'}{'circular'}, 'Rotary Pendulum');
    $self->{'tabs'}->AddPage( $self->{'tab'}{'function'}, 'Functions');
    $self->{'tabs'}->AddPage( $self->{'tab'}{'visual'},   'Visuals');
    $self->{'tabs'}->AddPage( $self->{'tab'}{'color'},    'Colors');

    $self->{'pendulum'}{'x'} = App::GUI::Harmonograph::Frame::Panel::Pendulum->new( $self->{'tab'}{'linear'},   'X ', 'pendulum in x direction (left to right)', 1, 100);
    $self->{'pendulum'}{'y'} = App::GUI::Harmonograph::Frame::Panel::Pendulum->new( $self->{'tab'}{'linear'},   'Y ', 'pendulum in y direction (up - down)',     1, 100);
    $self->{'pendulum'}{'e'} = App::GUI::Harmonograph::Frame::Panel::Pendulum->new( $self->{'tab'}{'epicycle'}, 'E ', 'epicycle in x direction (left to right)', 0, 100);
    $self->{'pendulum'}{'f'} = App::GUI::Harmonograph::Frame::Panel::Pendulum->new( $self->{'tab'}{'epicycle'}, 'F ', 'epicycle in y direction (up - down)',     0, 100);
    $self->{'pendulum'}{'w'} = App::GUI::Harmonograph::Frame::Panel::Pendulum->new( $self->{'tab'}{'circular'}, 'W' , 'circular wobbling pendulum',               0, 100);
    $self->{'pendulum'}{'r'} = App::GUI::Harmonograph::Frame::Panel::Pendulum->new( $self->{'tab'}{'circular'}, 'R ', 'rotation pendulum',                       0, 100);

    $self->{'tab_names'} = [qw/function visual color/];
    $self->{'pendulum_names'} = [qw/x y e f w r/];
    $self->{'pendulum'}{$_}->SetCallBack( sub { $self->sketch( ) } ) for @{$self->{'pendulum_names'}};
    $self->{'tab'}{$_}->SetCallBack( sub { $self->sketch( ) } ) for @{$self->{'tab_names'}};

    $self->{'progress_bar'}     = App::GUI::Wx::Widget::Custom::ProgressBar->new( $self, 455,  10, [20, 20, 110] );
    $self->{'board'}            = App::GUI::Harmonograph::Frame::Panel::Board->new( $self, 600, 600 );
    $self->{'dialog'}{'about'}  = App::GUI::Harmonograph::Dialog::About->new();

    my $btnw = 44; my $btnh     = 30;# button width and height
    $self->{'btn'}{'dir'}       = Wx::Button->new( $self, -1, 'Di&r',  [-1,-1],[$btnw, $btnh] );
    $self->{'btn'}{'write_next'}= Wx::Button->new( $self, -1, '&INI',  [-1,-1],[$btnw, $btnh] );
    $self->{'btn'}{'draw'}      = Wx::Button->new( $self, -1, '&Draw', [-1,-1],[$btnw, $btnh] );
    $self->{'btn'}{'save_next'} = Wx::Button->new( $self, -1, '&Save', [-1,-1],[$btnw, $btnh] );
    $self->{'txt'}{'file_bdir'} = Wx::TextCtrl->new( $self,-1, $self->{'config'}->get_value('file_base_dir'), [-1,-1],  [185, -1] );
    $self->{'txt'}{'file_bname'}= Wx::TextCtrl->new( $self,-1, $self->{'config'}->get_value('file_base_name'), [-1,-1],   [100, -1] );
    $self->{'txt'}{'file_bnr'}  = Wx::TextCtrl->new( $self,-1, $self->{'config'}->get_value('file_base_counter'), [-1,-1], [ 36, -1], &Wx::wxTE_READONLY );

    $self->{'btn'}{'dir'}->SetToolTip('select directory to save file series in');
    $self->{'btn'}{'write_next'}->SetToolTip('save current image settings into text file with name seen in text field with added number and file ending .ini');
    $self->{'btn'}{'draw'}->SetToolTip('redraw the harmonographic image');
    $self->{'btn'}{'save_next'}->SetToolTip('save current image into SVG file with name seen in text field with added number and file ending .svg');
    $self->{'txt'}{'file_bname'}->SetToolTip("file base name (without ending) for a series of files you save (settings and images)");
    $self->{'txt'}{'file_bnr'}->SetToolTip("index of file base name,\nwhen pushing Next button, image or settings are saved under Dir + File + Index + Ending");

    # Events
    Wx::Event::EVT_TEXT_ENTER( $self, $self->{'txt'}{'file_bname'}, sub { $self->update_base_name });
    Wx::Event::EVT_KILL_FOCUS(        $self->{'txt'}{'file_bname'}, sub { $self->update_base_name });



( run in 0.581 second using v1.01-cache-2.11-cpan-98e64b0badf )