Skip to content

Commit

Permalink
demo: show contents of options file
Browse files Browse the repository at this point in the history
... and unlink the temporary options file after usage.
  • Loading branch information
eserte committed Nov 30, 2014
1 parent b628ee1 commit 1fca758
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion demos/tk-getopt.pl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ sub tk_getopt {

);

my(undef,$optfilename) = tempfile(SUFFIX => ".tk-getopt");
my(undef,$optfilename) = tempfile(SUFFIX => ".tk-getopt", UNLINK => 1);
my $opt = new Tk::Getopt(-opttable => \@opttable,
-options => $options,
-filename => $optfilename);
Expand All @@ -173,6 +173,21 @@ sub tk_getopt {
);
if (defined $answer) {
$top->messageBox(-message => "The button pressed was <$answer>.");
if ($answer eq 'ok') {
my $config_data = do {
open my $fh, $optfilename
or die "Error while opening $optfilename: $!";
local $/;
<$fh>;
};
my $t = $top->Toplevel(-title => 'Contents of config file');
my $txt = $t->Scrolled('ROText', -wrap => 'none', -scrollbars => 'oe')->pack(qw(-fill both -expand 1));
$txt->insert('end', $config_data);
my $wait = 1;
$t->Button(-text => 'Ok', -command => sub { $wait = 0 })->pack;
$t->waitVariable(\$wait);
$t->destroy;
}
} else {
$top->messageBox(-message => "Undefined answer, probably closed via the window manager close button.");
}
Expand Down

0 comments on commit 1fca758

Please sign in to comment.