Hi Jeff,
I have used the technique that Gisle mentioned in using "use utf8". This
shows that constants can be used in the listbox fine. That makes sense and
works fine.
Added a loop to bring in some data from a piped file. The print statements
(with both constants and read-in values) display nicely as expected.
Constants will display fine both in a print statement as well as in the Tkx
listbox. But when I assign a value read in from stdin to the listbox, I get
garbage again.
So, I have half of the solution - that being for constants. Now, I need to
figure out how to read in a value in such a way as to be able to assign it
with the listbox.
Any further thoughts?
Thanks so much for your kind help.
Greg
PS I have attached my input and output files along with the newly modified
perl script. My command line is "perl lb_b.txt < innput.txt > out.txt". The
input file has no BOM. The perl script does carry the BOM.
PPS The words in this Cyrillic file are actually Mongolian; meaning is "This
book is 1.) interesting 2.) not interesting 3.) new 4.) red." :) The earlier
word, жишээ, was "example".
Please email directly back to [EMAIL PROTECTED]
Thanks,
Greg Eck
-----Original Message-----
From: Gisle Aas [*mailto:[EMAIL PROTECTED] <[EMAIL PROTECTED]>]
Sent: Friday, May 23, 2008 3:36 PM
To: Jeff Hobbs
Cc: [EMAIL PROTECTED]; tcltk@perl.org
Subject: Re: utf-8 support for Tkx ActiveStatePerl (5.8.8) under Windows
Vista
On May 23, 2008, at 06:54, Jeff Hobbs wrote:
> Hi Greg,
>
> Greg Eck wrote:
>> I am looking for a critical answer in a design issue.
>> I want to use the Tkx subset to program a gui, but need to verify
>> that Tkx will indeed display my foreign characters (Mongolian,
>> Tibetan, Chinese).
>
> Tkx (via Tcl/Tk) can properly display all unicode chars in the BMP
> (basic multilingual plane).
>
>> I can see the good utf8 characters being processed in output, but not
>> as displayed in the listbox.
>> Could you verify that this is true or false, bug or deficiency, maybe
>> my lack of knowing the correct syntax?
>> If you could tell me what I need to do in this code snippet to
>> display the $v variable, then I will go ahead and press ahead. If
>> you view the file with Arial Unicode MS or some other pan-Unicode
>> font, you should be able to see the $v variable fine.
>
> I've attached a modified version that adds one more line that does
> display correctly. Note I use direct unicode code points. I'm not
> sure whether it is the utf8() or the special marker starting your file
> that is throwing off the translation. In any case, this shows that it
> is possible and one way to do it.
Don't use Unicode::String as it will give you encoded utf8, which is not
what Tkx wants. Just use plan perl strings and it ought to just work. If
your source code is UTF-8 you should make it start with the BOM marker, or
you can add a 'use utf8' statement early to tell this to perl.
But even after doing this I still see some Chinese(?) letters in the
listbox, not the Cyrillic I expected.
--Gisle
>
> Jeff
> use Unicode::String qw(utf8 latin1 utf16be); use Tkx; use warnings;
>
> my $mw = Tkx::widget->new(".");
> $mw->g_wm_title("GreySon");
> $mw->g_wm_minsize(300,200);
> $u = utf8("hello1");
> $v = utf8("?????");
> $w = utf8("hello3");
> $x = "\x{0436}\x{0438}\x{0448}\x{044d}\x{044d}";
> print "$u $v $x howdy ... \n";
>
> my $message = "The $v hen lives in a chicken coop."; print $message .
> "\n"; my @colors = ($u, $v, $w, $x);
>
> my $label = $mw->new_label(-textvariable => \$message); my $enter =
> $mw->new_label(-text => "Select correct word"); my $lb =
> $mw->new_listbox(-selectmode => "single"); $lb->insert("end",
> @colors); my $show = $mw->new_button(-text => "Show selection",
> -command => \&display); my $exit = $mw->new_button(-text => "Exit",
> -command => sub {exit});
>
> $label->g_pack;
> $enter->g_pack;
> $lb->g_pack;
> $show->g_pack;
> $exit->g_pack;
>
> Tkx::MainLoop();
>
> Tkx::bind($mw, "<<Copy>>", sub { $lb->get($lb->curselection); });
>
> sub display {
> my @selections = $lb->curselection;
> $message = "You selected: ";
> foreach (@selections) {$message .= $lb->get($_);} }
>
ÐÐ½Ñ Ð½Ð¾Ð¼Ñг Ð¼Ð°Ñ Ð¼Ð°Ñ ÑониÑолÑой
ÐÐ½Ñ Ð½Ð¾Ð¼Ñг Ð¼Ð°Ñ Ð¼Ð°Ñ ÑониÑолгүй
ÐÐ½Ñ Ð½Ð¾Ð¼Ñг Ð¼Ð°Ñ ÑÐ¸Ð½Ñ Ð±Ð°Ð¹Ð½Ð°
ÐÐ½Ñ Ð½Ð¾Ð¼Ñг Ð¼Ð°Ñ Ñлаан байна
use Unicode::String qw(utf8 latin1 utf16be);
use utf8;
use Tkx;
use warnings;
my $mw = Tkx::widget->new(".");
$mw->g_wm_title("GreySon");
$mw->g_wm_minsize(300,200);
while (<>) {
chomp ;
@rec = split;
print "$rec[0] $rec[1] $rec[2] $rec[3] $rec[4].\n";
$u = utf8($rec[0]);
$v = "ÑÑÑÑÑÑ";
$w = "red";
$x = "\x{0436}\x{0438}\x{0448}\x{044d}\x{044d}";
print "$u $v $w $x howdy ... \n";
}
my $message = "The $v hen lives in a chicken coop.";
print $message . "\n";
my @colors = ($rec[0], $v, $w, $x);
my $label = $mw->new_label(-textvariable => \$message);
my $enter = $mw->new_label(-text => "Select correct word");
my $lb = $mw->new_listbox(-selectmode => "single");
$lb->insert("end", @colors);
my $show = $mw->new_button(-text => "Show selection", -command => \&display);
my $exit = $mw->new_button(-text => "Exit", -command => sub {exit});
$label->g_pack;
$enter->g_pack;
$lb->g_pack;
$show->g_pack;
$exit->g_pack;
Tkx::MainLoop();
#Tkx::bind($mw, "<<Copy>>", sub { $lb->get($lb->curselection); });
sub display {
my @selections = $lb->curselection;
$message = "You selected: ";
foreach (@selections) {$message .= $lb->get($_);}
}
ÐÐ½Ñ Ð½Ð¾Ð¼Ñг Ð¼Ð°Ñ Ð¼Ð°Ñ ÑониÑолÑой.
ÐÐ½Ñ ÑÑÑÑÑÑ red жиÑÑÑ howdy ...
ÐÐ½Ñ Ð½Ð¾Ð¼Ñг Ð¼Ð°Ñ Ð¼Ð°Ñ ÑониÑолгүй.
ÐÐ½Ñ ÑÑÑÑÑÑ red жиÑÑÑ howdy ...
ÐÐ½Ñ Ð½Ð¾Ð¼Ñг Ð¼Ð°Ñ ÑÐ¸Ð½Ñ Ð±Ð°Ð¹Ð½Ð°.
ÐÐ½Ñ ÑÑÑÑÑÑ red жиÑÑÑ howdy ...
ÐÐ½Ñ Ð½Ð¾Ð¼Ñг Ð¼Ð°Ñ Ñлаан байна.
ÐÐ½Ñ ÑÑÑÑÑÑ red жиÑÑÑ howdy ...
The ÑÑÑÑÑÑ hen lives in a chicken coop.