For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > March 2007 > Trouble with unicode path on Windows









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 Trouble with unicode path on Windows
Franck ANIERE

2007-02-24, 7:01 pm

Hello,

I have a weird problem with perl/tk on Windows.
I use Activeperl 5.5.8 build 820 and Tk 804.027.
Each time I try to use some data in an unicode path
(for example with french accentued caracters), the Tk
code fails to load it, while the other perl code has no
problem.

This can be seen with the code supplied at the end of
this message : if I run this script (name try.pl) with
perl try.pl 1, the script works (I read a picture via
open and give the data to Tk::Photo via -data). With
perl try.pl 0, the script does not work (I then use
Tk::Photo with -file). The error message is
"Cannot open c:\essayé\try.jpg" in mode "r" at c:\perl\lib\tk\Image.pm
line 21.

This problem is not only for loading pictures, if even fails with
file requesters.


I have tried :

- To rebuild perl from source supplied by ActiveState, and changing
USING_WIDE from 0 to 1 in win32.h => it is worse as the open
workaround does not work

- To rebuild perl/tk from source => no change from the PPM


I think this is an encoding problem located in Perl/tk (as other perl
functions seem to work well), but I can't see where. I've been searching
for ws, and I really need some help :( (I can't use the workaround in
a very big piece of software, as it would break my code)

Thanks a lot in advance for your help,

Best regards,

F.A.

Here comes the example code :

use strict;
use Tk;
use Tk::JPEG;
use MIME::Base64;
use Cwd;

sub Hello ($$$)
{
my $tmp;
my $tmp2;
my $mode = shift;
my $root = shift;
my $win = shift;
my $pic;

if ($mode)
{
$tmp = $/;
undef $/;
open TOTO,$root."/try.jpg" or die "arg";
binmode TOTO;
$tmp2 = <TOTO>;
close TOTO;
$/ = $tmp2;
$pic = $win->Photo (-data=>encode_base64($tmp2));
}
else
{
$pic = $win->Photo (-file=>$root."/try.jpg");
}
$win->Label (-image=>$pic)->pack ();
}

my $theroot = cwd;
my $window = MainWindow->new ();

Hello ($ARGV[0],$theroot,$window);

MainLoop ();
Jean-Louis MOREL

2007-02-25, 4:03 am

Dans l'article <45e0bdcb$0$21148$7a628cd7@news.club-internet.fr>,
aniere@yahoo.com a dit...
>
>I have a weird problem with perl/tk on Windows.
>I use Activeperl 5.5.8 build 820 and Tk 804.027.
>Each time I try to use some data in an unicode path
>(for example with french accentued caracters), the Tk
>code fails to load it, while the other perl code has no
>problem.
>


A workaround:

$pic = $win->Photo(-file=>Win32::GetShortPathName($root."/try.jpg"));

(No Unicode problem with the good old DOS ;-)

--
J-L.M.
http://www.bribes.org/perl

Franck ANIERE

2007-02-25, 10:02 pm

Jean-Louis MOREL a écrit :

>
> A workaround:
>
> $pic = $win->Photo(-file=>Win32::GetShortPathName($root."/try.jpg"));
>
> (No Unicode problem with the good old DOS ;-)
>


This workaround works fine, thank you very much for your help !

best regards,

F.A.
Slaven Rezic

2007-03-04, 7:03 pm

Franck ANIERE <aniere@yahoo.com> writes:

> Hello,
>
> I have a weird problem with perl/tk on Windows.
> I use Activeperl 5.5.8 build 820 and Tk 804.027.
> Each time I try to use some data in an unicode path
> (for example with french accentued caracters), the Tk
> code fails to load it, while the other perl code has no
> problem.
>
> This can be seen with the code supplied at the end of
> this message : if I run this script (name try.pl) with
> perl try.pl 1, the script works (I read a picture via
> open and give the data to Tk::Photo via -data). With
> perl try.pl 0, the script does not work (I then use
> Tk::Photo with -file). The error message is
> "Cannot open c:\essayé\try.jpg" in mode "r" at c:\perl\lib\tk\Image.pm
> line 21.
>
> This problem is not only for loading pictures, if even fails with
> file requesters.
>
>
> I have tried :
>
> - To rebuild perl from source supplied by ActiveState, and
> changing USING_WIDE from 0 to 1 in win32.h => it is worse as the open
> workaround does not work
>
> - To rebuild perl/tk from source => no change from the PPM
>
>
> I think this is an encoding problem located in Perl/tk (as other perl
> functions seem to work well), but I can't see where. I've been
> searching for ws, and I really need some help :( (I can't use the
> workaround in
> a very big piece of software, as it would break my code)
>


I fixed some of the unicode filename related problems in Tk
804.027_500 (latest development release, the search.cpan.org). Maybe
you can try this one. But I guess there are some more bugs left...

Regards,
Slaven

--
Slaven Rezic - slaven <at> rezic <dot> de
Tired of using file selectors? Real programmers use the TAB key for
completion and not for jumping around. Try
http://search.cpan.org/search?mode=...y=Tk::PathEntry
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com