App-GUI-Harmonograph
view release on metacpan or search on metacpan
lib/App/GUI/Harmonograph/Frame.pm view on Meta::CPAN
my $self = shift;
my $settings = {};
$settings->{$_} = $self->{'pendulum'}{$_}->get_settings for @{$self->{'pendulum_names'}};
$settings->{$_} = $self->{'tab'}{$_}->get_settings for @{$self->{'tab_names'}};
$settings;
}
sub set_settings {
my ($self, $settings) = @_;
return unless ref $settings eq 'HASH';
$self->{'pendulum'}{$_}->set_settings( $settings->{$_} ) for @{$self->{'pendulum_names'}};
$self->{'tab'}{$_}->set_settings( $settings->{$_} ) for @{$self->{'tab_names'}};
$self->{'tab'}{'color'}->set_active_color_count( $settings->{'visual'}{'colors_used'} );
}
sub draw {
my ($self) = @_;
$self->SetStatusText( "drawing .....", 0 );
my @colors = $self->{'tab'}{'color'}->get_all_colors;
$self->{'progress_bar'}->set_start_color( $colors[0]->values( ) );
$self->{'board'}->draw( $self->get_settings, $self->{'progress_bar'} );
#$self->{'progress_bar'}->paint;
$self->SetStatusText( "done complete drawing", 0 );
}
sub sketch {
my ($self) = @_;
$self->SetStatusText( "sketching a preview .....", 0 );
$self->{'progress_bar'}->reset();
$self->{'board'}->sketch( $self->get_settings, $self->{'progress_bar'} );
$self->SetStatusText( "done sketching a preview", 0 );
if ($self->{'saved'}){
$self->inc_base_counter();
$self->set_settings_save(0);
}
}
sub write_image {
my ($self, $file) = @_;
$self->{'board'}->save_file( $file, $self->get_settings, $self->{'progress_bar'} );
$file = App::GUI::Harmonograph::Settings::shrink_path( $file );
$self->SetStatusText( "saved image under: $file", 0 );
$self->set_settings_save(1);
}
sub set_settings_save {
my ($self, $status) = @_;
$self->{'saved'} = $status;
$self->SetTitle( $self->{'title'} .($self->{'saved'} ? '': ' *'));
}
sub update_base_name {
my ($self) = @_;
my $file = $self->{'txt'}{'file_bname'}->GetValue;
$self->{'config'}->set_value('file_base_name', $file);
$self->{'config'}->set_value('file_base_counter', 1);
$self->inc_base_counter();
}
sub inc_base_counter {
my ($self, $type) = @_;
my $dir = $self->{'config'}->get_value('file_base_dir');
$dir = App::GUI::Harmonograph::Settings::expand_path( $dir );
my $base = File::Spec->catfile( $dir, $self->{'config'}->get_value('file_base_name') );
my $cc = $self->{'config'}->get_value('file_base_counter');
while (1){
last unless -e $base.'_'.$cc.'.svg'
or -e $base.'_'.$cc.'.png'
or -e $base.'_'.$cc.'.jpg'
or -e $base.'_'.$cc.'.gif'
or -e $base.'_'.$cc.'.ini';
$cc++;
}
$self->{'txt'}{'file_bnr'}->SetValue( $cc );
$self->{'config'}->set_value('file_base_counter', $cc);
}
sub change_base_dir {
my $self = shift;
my $dialog = Wx::DirDialog->new ( $self, "Select a directory to store a series of files", $self->{'config'}->get_value('file_base_dir'));
return if $dialog->ShowModal == &Wx::wxID_CANCEL;
my $new_dir = $dialog->GetPath;
$new_dir = App::GUI::Harmonograph::Settings::shrink_path( $new_dir ) . '/';
$self->{'txt'}{'file_bdir'}->SetValue( $new_dir );
$self->{'config'}->set_value('file_base_dir', $new_dir);
$self->update_base_name();
}
sub base_path {
my ($self) = @_;
my $dir = $self->{'config'}->get_value('file_base_dir');
$dir = App::GUI::Harmonograph::Settings::expand_path( $dir );
File::Spec->catfile( $dir, $self->{'config'}->get_value('file_base_name') )
.'_'.$self->{'config'}->get_value('file_base_counter');
}
sub open_settings_dialog {
my ($self) = @_;
my $dialog = Wx::FileDialog->new ( $self, "Select a settings file to load", $self->{'config'}->get_value('open_dir'), '',
( join '|', 'INI files (*.ini)|*.ini', 'All files (*.*)|*.*' ), &Wx::wxFD_OPEN );
return if $dialog->ShowModal == &Wx::wxID_CANCEL;
my $path = $dialog->GetPath;
my $ret = $self->open_setting_file ( $path );
if (not ref $ret) { $self->SetStatusText( $ret, 0) }
else {
my $dir = App::GUI::Harmonograph::Settings::extract_dir( $path );
$self->{'config'}->set_value('open_dir', $dir);
$self->SetStatusText( "loaded settings from ".$dialog->GetPath, 1);
}
}
sub write_settings_dialog {
my ($self) = @_;
my $dialog = Wx::FileDialog->new ( $self, "Select a file name to store data",$self->{'config'}->get_value('write_dir'), '',
( join '|', 'INI files (*.ini)|*.ini', 'All files (*.*)|*.*' ), &Wx::wxFD_SAVE );
return if $dialog->ShowModal == &Wx::wxID_CANCEL;
my $path = $dialog->GetPath;
$path .= '.ini' unless lc substr ($path, -4) eq '.ini';
$path = substr ($path, 0, -4) if lc substr ($path, -4) eq '.ini';
return if -e $path and
Wx::MessageDialog->new( $self, "\n\nReally overwrite the settings file?", 'Confirmation Question',
&Wx::wxYES_NO | &Wx::wxICON_QUESTION )->ShowModal() != &Wx::wxID_YES;
$self->write_settings_file( $path );
my $dir = App::GUI::Harmonograph::Settings::extract_dir( $path );
$self->{'config'}->set_value('write_dir', $dir);
}
sub save_image_dialog {
my ($self) = @_;
my @wildcard = ( 'SVG files (*.svg)|*.svg', 'PNG files (*.png)|*.png', 'JPEG files (*.jpg)|*.jpg');
my $wildcard = '|All files (*.*)|*.*';
my $default_ending = $self->{'config'}->get_value('file_base_ending');
$wildcard = ($default_ending eq 'jpg') ? ( join '|', @wildcard[2,1,0]) . $wildcard :
($default_ending eq 'png') ? ( join '|', @wildcard[1,0,2]) . $wildcard :
( join '|', @wildcard[0,1,2]) . $wildcard ;
my @wildcard_ending = ($default_ending eq 'jpg') ? (qw/jpg png svg/) :
($default_ending eq 'png') ? (qw/png svg jpg/) :
(qw/svg jpg png/) ;
my $dialog = Wx::FileDialog->new ( $self, "select a file name to save image", $self->{'config'}->get_value('save_dir'), '', $wildcard, &Wx::wxFD_SAVE );
return if $dialog->ShowModal == &Wx::wxID_CANCEL;
my $path = $dialog->GetPath;
return if -e $path and
Wx::MessageDialog->new( $self, "\n\nReally overwrite the image file?", 'Confirmation Question',
&Wx::wxYES_NO | &Wx::wxICON_QUESTION )->ShowModal() != &Wx::wxID_YES;
my $file_ending = lc substr ($path, -4);
unless ($dialog->GetFilterIndex == 3 or # filter set to all endings
($file_ending eq '.jpg' or $file_ending eq '.png' or $file_ending eq '.svg')){
$path .= '.' . $wildcard_ending[$dialog->GetFilterIndex];
}
my $ret = $self->write_image( $path );
if ($ret){ $self->SetStatusText( $ret, 0 ) }
( run in 1.126 second using v1.01-cache-2.11-cpan-5b529ec07f3 )