J
Josef Moellers
In an application which downloads an image from a webcam, I'd like to
save an image if it's interesting.
For that, I have a "Save image" button, which calls this sub:
sub save {
my $top = shift;
my @tv = localtime;
my $base = 'webcam-'
. sprintf('%04d.%02d.%02d', $tv[5]+1900, $tv[4]+1, $tv[3])
. '-'
. sprintf('%02d:%02d:%02d', $tv[2], $tv[1], $tv[0])
. '.pnm';
my $dst = $top->getSaveFile(-initialdir => $HOME,
-defaultextension => '.pnm',
-initialfile => $base,
-title => 'Save Snapshot',
-filetypes => [ ['Images', '.pnm' ],
['All files', '*' ] ]);
if (defined $dst) {
print STDERR "dst=$dst\n";
} else {
print STDERR "dst=<undef>\n";
}
if (defined $dst && $dst ne "") {
copy($tmpnam, $dst) or die "Copy failed: $!";
}
}
Unfortunately, I cannot just hit the "Save" button in the getSaveFile
window to use the given "webcam-..." name, I have to somehow make it
"dirty". How can I convince the getSaveFile widget to use this
initialfile without further action (i.e. just hit the "Save" button)?
Josef
save an image if it's interesting.
For that, I have a "Save image" button, which calls this sub:
sub save {
my $top = shift;
my @tv = localtime;
my $base = 'webcam-'
. sprintf('%04d.%02d.%02d', $tv[5]+1900, $tv[4]+1, $tv[3])
. '-'
. sprintf('%02d:%02d:%02d', $tv[2], $tv[1], $tv[0])
. '.pnm';
my $dst = $top->getSaveFile(-initialdir => $HOME,
-defaultextension => '.pnm',
-initialfile => $base,
-title => 'Save Snapshot',
-filetypes => [ ['Images', '.pnm' ],
['All files', '*' ] ]);
if (defined $dst) {
print STDERR "dst=$dst\n";
} else {
print STDERR "dst=<undef>\n";
}
if (defined $dst && $dst ne "") {
copy($tmpnam, $dst) or die "Copy failed: $!";
}
}
Unfortunately, I cannot just hit the "Save" button in the getSaveFile
window to use the given "webcam-..." name, I have to somehow make it
"dirty". How can I convince the getSaveFile widget to use this
initialfile without further action (i.e. just hit the "Save" button)?
Josef