Home > Archive > PerlTk > April 2004 > getOpenFile() won't open a file without an extension.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
getOpenFile() won't open a file without an extension.
|
|
| Brian McGonigle 2004-04-14, 12:31 am |
| getOpenFile() won't open a file without a file extension. I have
['All Files', '*'] listed as a file type. Am I doing something wrong
or is this normal behavior? If this is normal, is there an alternative
that doesn't do this?
Thanks,
Brian
| |
| Marc Dashevsky 2004-04-14, 12:31 am |
| Brian McGonigle says in article <b35725c1.0404131905.2eb8202e@posting.google.com>:
> getOpenFile() won't open a file without a file extension. I have
> ['All Files', '*'] listed as a file type. Am I doing something wrong
> or is this normal behavior?
I'm not sure what you mean -- getOpenFile() doesn't actually open a file.
What is the failure mode? How do you know it's not working?
Care to show us a small script that demonstrates the problem?
--
Marc Dashevsky -- Put "usenet" in Subject if you want me to read e-mail.
http://MarcDashevsky.com
| |
| Brian McGonigle 2004-04-14, 5:37 am |
| Marc Dashevsky wrote:
> Brian McGonigle says in article <b35725c1.0404131905.2eb8202e@posting.google.com>:
>
>
>
> I'm not sure what you mean -- getOpenFile() doesn't actually open a file.
> What is the failure mode? How do you know it's not working?
> Care to show us a small script that demonstrates the problem?
>
Sorry I wasn't more clear. It's not returning a filename that doesn't
have an extension. It won't close when I hit "Ok". Actually, I think
it's having trouble with names not containing a ".". If I choose "All
files (*)" from the file types drop-down and double-click a file, it
hides all files except directories and the file I chose, and then
refuses to accept that file. I think it might be using it as an
abbreviation rather than a filename. If I have two files with the same
name, minus the extension (".pl" for example) on one of them, and
double-click the one without the extension, I can see both files but the
rest disappear. Here's how I use it in a sub:
sub FileDialog {
my $operation = shift;
my $types;
my $file;
my @types =
(["Text files", [qw/.txt .doc/]],
["Perl Source Files", [qw/.pl .pm/]],
["POD", ".pod"],
["HTML Source Files", [qw/ .html .htm/]],
["Bash Shell scripts", [qw/ .sh/]],
["All Source Files", [qw/.pl .pm .html .htm .sh/]],
["All files", '*']
);
if ($operation eq 'Open') {
$file = $mw->getOpenFile(-filetypes => \@types,
-initialdir => dirname($active{'file'}),
-defaultextension => '*');
}
else {
$file = $mw->getSaveFile(-filetypes => \@types,
-initialdir => dirname($active{'file'}),
-initialfile => basename($active{'file'}),
-defaultextension => '*');
}
return $file;
}
"$active{'file'}" is the variable I use to identify the file loaded in
the active text widget. I use a NoteBook with a text widget on every
page. I uses the "-raisecommand" of each notebook page to set
references to the active page and text widgets. My toolbar buttons only
worry about
$active{whatever} and let the raisecommand to the magic.
| |
| Marc Dashevsky 2004-04-14, 8:32 am |
| Brian McGonigle says in article <nH6fc.29773$F9.22394@nwrddc01.gnilink.net>:
> Marc Dashevsky wrote:
>
> Sorry I wasn't more clear. It's not returning a filename that doesn't
> have an extension. It won't close when I hit "Ok". Actually, I think
> it's having trouble with names not containing a ".". If I choose "All
> files (*)" from the file types drop-down and double-click a file, it
> hides all files except directories and the file I chose, and then
> refuses to accept that file. I think it might be using it as an
> abbreviation rather than a filename. If I have two files with the same
> name, minus the extension (".pl" for example) on one of them, and
> double-click the one without the extension, I can see both files but the
> rest disappear.
It must be a version or an OS issue. The following works fine in my
Win2k, perl 5.8.2, Tk 800.024 environment.
use strict;
use Tk;
use File::Basename;
my %active;
$active{'file'} = 'D:/xxx';
my $mw = tkinit;
print FileDialog('Open'), "\n";
sub FileDialog {
my $operation = shift;
my $types;
my $file;
my @types =
(["Text files", [qw/.txt .doc/]],
["Perl Source Files", [qw/.pl .pm/]],
["POD", ".pod"],
["HTML Source Files", [qw/ .html .htm/]],
["Bash Shell scripts", [qw/ .sh/]],
["All Source Files", [qw/.pl .pm .html .htm .sh/]],
["All files", '*']
);
if ($operation eq 'Open') {
$file = $mw->getOpenFile(-filetypes => \@types,
-initialdir => dirname($active{'file'}),
-defaultextension => '*');
}
else {
$file = $mw->getSaveFile(-filetypes => \@types,
-initialdir => dirname($active{'file'}),
-initialfile => basename($active{'file'}),
-defaultextension => '*');
}
return $file;
}
--
Marc Dashevsky -- Put "usenet" in Subject if you want me to read e-mail.
http://MarcDashevsky.com
| |
| Slaven Rezic 2004-04-14, 8:32 pm |
| Brian McGonigle <brian.mcgonigle@verizon.net> writes:
> Marc Dashevsky wrote:
>
> Sorry I wasn't more clear. It's not returning a filename that doesn't
> have an extension. It won't close when I hit "Ok". Actually, I think
> it's having trouble with names not containing a ".". If I choose "All
> files (*)" from the file types drop-down and double-click a file, it
> hides all files except directories and the file I chose, and then
> refuses to accept that file. I think it might be using it as an
> abbreviation rather than a filename. If I have two files with the same
> name, minus the extension (".pl" for example) on one of them, and
> double-click the one without the extension, I can see both files but
> the rest disappear. Here's how I use it in a sub:
>
> sub FileDialog {
> my $operation = shift;
> my $types;
> my $file;
>
> my @types =
> (["Text files", [qw/.txt .doc/]],
> ["Perl Source Files", [qw/.pl .pm/]],
> ["POD", ".pod"],
> ["HTML Source Files", [qw/ .html .htm/]],
> ["Bash Shell scripts", [qw/ .sh/]],
> ["All Source Files", [qw/.pl .pm .html .htm .sh/]],
> ["All files", '*']
> );
> if ($operation eq 'Open') {
> $file = $mw->getOpenFile(-filetypes => \@types,
> -initialdir => dirname($active{'file'}),
> -defaultextension => '*');
^^^^^^^^^^^^^^^^^^^^^^^^
> }
> else {
> $file = $mw->getSaveFile(-filetypes => \@types,
> -initialdir => dirname($active{'file'}),
> -initialfile => basename($active{'file'}),
> -defaultextension => '*');
^^^^^^^^^^^^^^^^^^^^^^^^^
Using -defaultextension here is wrong. This is meant to automatically
append an extension to an extensionless filename. For "Open" mode,
this is almost always meaningless. In "Save" mode, it should be a
"real" extension like ".txt" or similar.
> }
> return $file;
> }
>
> "$active{'file'}" is the variable I use to identify the file loaded in
> the active text widget. I use a NoteBook with a text widget on every
> page. I uses the "-raisecommand" of each notebook page to set
> references to the active page and text widgets. My toolbar buttons
> only worry about
> $active{whatever} and let the raisecommand to the magic.
>
Regards,
Slaven
--
Slaven Rezic - slaven@rezic.de
Visualize Makefiles with GraphViz:
http://user.cs.tu-berlin.de/~eserte...phViz-Makefile/
| |
| Slaven Rezic 2004-04-14, 8:32 pm |
| Brian McGonigle <brian.mcgonigle@verizon.net> writes:
> Marc Dashevsky wrote:
>
> Sorry I wasn't more clear. It's not returning a filename that doesn't
> have an extension. It won't close when I hit "Ok". Actually, I think
> it's having trouble with names not containing a ".". If I choose "All
> files (*)" from the file types drop-down and double-click a file, it
> hides all files except directories and the file I chose, and then
> refuses to accept that file. I think it might be using it as an
> abbreviation rather than a filename. If I have two files with the same
> name, minus the extension (".pl" for example) on one of them, and
> double-click the one without the extension, I can see both files but
> the rest disappear. Here's how I use it in a sub:
>
[...]
Confirmed for Tk804.02*. I will do some research...
Regards,
Slaven
--
Slaven Rezic - slaven@rezic.de
Visualize Makefiles with GraphViz:
http://user.cs.tu-berlin.de/~eserte...phViz-Makefile/
| |
| Brian McGonigle 2004-04-15, 7:36 am |
| Slaven Rezic wrote:
> Brian McGonigle <brian.mcgonigle@verizon.net> writes:
>
>
>
> [...]
>
> Confirmed for Tk804.02*. I will do some research...
>
> Regards,
> Slaven
>
It's working now. Thanks much!
|
|
|
|
|