Takamoto has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
May I assue that Tk chooseDirectory is faulty with Unicode paths on Windows?
My assumption is based on the following observation: on the same Windows 10 (Perl 5.26.1) machine the following scripts returns different paths. With getOpenFile and getSaveFile, the paths - even with unicode characters (chinese and so on) - are okay. I can use them to do things (open file, save it, etc.). The path returned by chooseDirectory is unusable (????). I read quite a lot about chooseDirectory and Unicode on this form, POD and so on. However, never found a working solution to get a usable path from chooseDirectory. Notice that my script has to work on potentially any Windows machine, irrespective of its way to encode paths. What do you think?
use Tk; use strict; use warnings; my $mw = MainWindow->new; my $menubar = $mw->Menu(-type => 'menubar'); $mw->configure(-menu => $menubar); my $mfile = $menubar->cascade(-label => '~File', -tearoff => 0); $mfile->command(-label => '~Open', -accelerator => 'Control+o', -command => \&open_file); $mfile->command(-label => '~Save', -accelerator => 'Control+s', -command => \&save_file); $mfile->command(-label => '~Select Dir', -accelerator => 'Control+d', -command => \&select_dir); my $exit = $mw->Button(-text => 'Exit', -command => [$mw => 'destroy']); $mw->bind('<Control-o>', [\&open_file]); $mw->bind('<Control-s>', [\&save_file]); $mw->bind('<Control-d>', [\&select_dir]); $exit->pack; my $types = [ ['Perl files', '.pl'], ['All Files', '*'],]; MainLoop; sub open_file { my $open = $mw->getOpenFile(-filetypes => $types, -defaultextension => '.pl'); print qq{You chose to open "$open"\n} if $open; } sub save_file { my $save = $mw->getSaveFile(-filetypes => $types, -initialfile => 'test', -defaultextension => '.pl'); print qq{You chose to save as "$save"\n} if $save; } sub select_dir { my $DirSelected = $mw->chooseDirectory(-initialdir => "~", -title +=> 'Choose directory to save your backup'); print qq{You chose to save as "$DirSelected"\n} if $DirSelected; }
Update
I just moved to a Chinese machine with a Chinese username. Well, here even getOpenFile/getSaveFile fail. Windows fires an error message saying that the path does not exist (with ??? in place of the user's name).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk unicode paths chooseDirectory vs getOpenFile and getSaveFile
by Lotus1 (Vicar) on Mar 04, 2019 at 14:26 UTC | |
by Takamoto (Monk) on Mar 04, 2019 at 16:27 UTC | |
|
Re: Tk unicode paths chooseDirectory vs getOpenFile and getSaveFile
by vr (Curate) on Mar 04, 2019 at 17:37 UTC | |
by vr (Curate) on Mar 05, 2019 at 14:48 UTC | |
by Takamoto (Monk) on Mar 12, 2019 at 15:18 UTC | |
|
Re: Tk unicode paths chooseDirectory vs getOpenFile and getSaveFile
by Takamoto (Monk) on Mar 04, 2019 at 18:59 UTC |