Skip to content

Instantly share code, notes, and snippets.

@jmcveigh
Last active June 15, 2016 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmcveigh/cee40862fd4f4b545576cc59184f44b5 to your computer and use it in GitHub Desktop.
Save jmcveigh/cee40862fd4f4b545576cc59184f44b5 to your computer and use it in GitHub Desktop.
ATTN: Philip Brady RE: Tk Options
#!/bin/perl -w
package Application {
use Moose;
use Tk;
require Tk::BrowseEntry;
use feature 'say';
use feature 'state';
use feature 'switch';
use namespace::autoclean;
has '_mw' => (
is => 'rw',
isa => 'Tk::MainWindow',
);
has '_packdirs' => (
is => 'rw',
isa => 'ArrayRef',
required => 1,
default => sub { [] },
);
has '_top' => (
is => 'rw',
isa => 'Tk::Widget',
);
has '_fh' => (
is => 'ro',
isa => 'ArrayRef[Tk::Frame]',
default => sub { [] },
);
has '_f' => (
is => 'ro',
isa => 'ArrayRef[Tk::Frame]',
default => sub { [] },
);
use YAML::Tiny;
sub _build_mw {
my ($self) = @_;
my $numWidgets = 4;
my $yaml = YAML::Tiny->read('tk-options-labels.yml');
$self->_mw(MainWindow->new(-title => "Tk Options"));
# create top, bottom, left and right frames
my %def_fh1 = (
'side' => 'top', 'fill' => 'y','cells' => 3,
);
my %def_fh2 = (
'side' => 'bottom', 'fill' => 'y','cells' => 3,
);
my %def_fh3 = (
'side' => 'left', 'fill' => 'x','cells' => 1,
);
my %def_fh4 = (
'side' => 'right', 'fill' => 'x','cells' => 1,
);
my @def_fh = (\%def_fh1,\%def_fh2,\%def_fh3,\%def_fh4);
my ($idx_fh, $idx_f, $idx_be) = (0,0,0);
# create widgits within top and bottom frames
for (0 .. 3) {
push @{$self->_fh}, $self->_mw->Frame(
-borderwidth => 2,
-relief => 'groove',
)->pack(
-side => $def_fh[$idx_fh]{'side'},
-fill => $def_fh[$idx_fh]{'fill'},
);
say $def_fh[$idx_fh]{'side'};
for (0 .. $def_fh[$idx_fh]{'cells'}) {
push @{$self->_f}, $self->_fh->[$idx_fh]->Frame(
-borderwidth => 2,
-relief => 'groove'
)->pack(
-side => 'left',
-anchor => 'n',
);
$self->_f->[$idx_f]->Label(-text => $yaml->[0]->[$idx_f]->{'header'})->pack(-ipady => 5, -side => 'top');
for (0 .. $#{$yaml->[0]->[$idx_f]->{'options'}}) {
$self->_packdirs->[$idx_be] = 'Skip';
$self->_f->[$idx_f]->BrowseEntry(-label => $yaml->[0]->[$idx_f]->{'options'}->[$_],
-choices => ["On", "Off", "Skip"],
-variable => \$self->_packdirs->[$idx_be], -browsecmd => \&repack)
->pack(-ipady => 5, -side => 'top');
$idx_be++;
}
$self->_f->[$idx_f]->Button(-text => $yaml->[0]->[$idx_f]->{'cta'})->pack(-ipady => 5, -side => 'top');
$idx_f++;
}
$idx_fh++;
}
$self->_top($self->_mw->Toplevel(-title => "File Options"));
my $c;
my $idx = 0;
foreach (0 .. 8)
{
my $b = $self->_top->Button(-text => "Open Folder ${idx}", -font => "Courier 20 bold")->pack(-side => 'bottom', -fill => 'both', -expand => 1);
$idx++;
}
MainLoop;
}
sub main {
my ($self) = @_;
$self->_build_mw;
}
__PACKAGE__->meta->make_immutable;
}
my $app = Application->new->main unless caller;
1;
- header: Command 1
cta: Process 1
options:
- Option 1
- header: Command 2
cta: Process 2
options:
- Option 1
- Option 2
- header: Command 3
cta: Process 3
options:
- Option 1
- Option 2
- Option 3
- header: Command 4
cta: Process 4
options:
- Option 1
- Option 2
- Option 3
- Option 4
- header: Command 5
cta: Process 5
options:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- header: Command 6
cta: Process 6
options:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- header: Command 7
cta: Process 7
options:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- header: Command 8
cta: Process 8
options:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- header: Command 9
cta: Process 9
options:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- header: Command 10
cta: Process 10
options:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- header: Command 11
cta: Process 11
options:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- header: Command 12
cta: Process 12
options:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment