App-GUI-Harmonograph
view release on metacpan or search on metacpan
lib/App/GUI/Harmonograph/Frame.pm view on Meta::CPAN
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++;
}
lib/App/GUI/Harmonograph/Frame.pm view on Meta::CPAN
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;
lib/App/GUI/Harmonograph/Settings.pm view on Meta::CPAN
use FindBin;
use File::Spec;
# parameter of a drawing
package App::GUI::Harmonograph::Settings;
sub load {
my ($file) = @_;
return unless defined $file;
$file = expand_path( $file );
my $data = {};
open my $FH, '<', $file or return "could not read $file: $!";
my $cat = '';
while (<$FH>) {
chomp;
next unless $_ or substr( $_, 0, 1) eq '#';
if (/\s*\[(\w+)\]/) { $cat = $1 }
elsif (/\s*(\w+)\s*=\s*(.+)\s*$/){ $data->{$cat}{$1} = $2 }
}
close $FH;
lib/App/GUI/Harmonograph/Settings.pm view on Meta::CPAN
sub shrink_path {
my ($path) = @_;
my $i = index($path, $FindBin::Bin );
$path = '.' . substr( $path, length $FindBin::Bin) if $i > -1;
$i = index($path, $ENV{HOME} );
$path = '~' . substr( $path, length $ENV{HOME}) if $i > -1;
$path;
}
sub expand_path {
my ($path) = @_;
$path = File::Spec->catdir( $FindBin::Bin, substr( $path, 1) ) if substr($path, 0,1) eq '.';
$path = File::Spec->catdir( $ENV{HOME}, substr( $path, 1) ) if substr($path, 0,1) eq '~';
$path;
}
sub are_equal {
my ($h1, $h2) = @_;
return 0 unless ref $h1 eq 'HASH' and ref $h2 eq 'HASH';
( run in 1.519 second using v1.01-cache-2.11-cpan-5b529ec07f3 )