Michael Barton wrote:
> So, I think that the GUI should probably set GRASS_FT_ENCODING to the
> locale's encoding (e.g. from "locale charmap").
You mean instead of having the user set it?
Yes.
AFAICT:
Tcl and Python both use Unicode internally, and automatically convert
to the locale's encoding when calling system functions. So if the user
types a value for e.g. "d.text text=..." into the GUI, the sequence of
bytes which end up in the corresponding argv will be in the locale's
encoding.
At least, that's the default. With Tcl, you can change the default
encoding with "encoding system <name>", where <name> is one of the
values returned by "encoding names". Also, when reading/writing
streams (files or pipes), you can change the encoding for that
particular stream with "fconfigure $fh -encoding ...".
But, in general, the GUI should probably stick with the locale's
encoding, as that's what external commands will normally be expecting.
How do I access locale charmap from TclTk or wxPython?
Tcl:
set encoding [exec locale charmap]
Python:
encoding = Popen(["locale", "charmap"], stdout=PIPE).communicate()[0].strip()
AFAICT, the resulting value will be valid for iconv(), and thus for
$GRASS_FT_ENCODING.
Needless to say, this won't work on Windows. You can get the Windows
codepage by parsing the output from "mode con cp /status", although
there might be better solutions. iconv appears to accept cp??? for
most of the common ones (e.g. cp437 = US, cp850 = western Europe,
etc).
--
Glynn Clements <glynn@gclements.plus.com>