Unicode style in win32/PythonWin

Robert kxroberto at googlemail.com
Thu Jan 12 17:01:06 EST 2006


Thomas Heller schrieb:

> "Robert" <kxroberto at googlemail.com> writes:
>
> > Neil Hodgson wrote:
> >> Robert:
> >>
> >> > After "is_platform_unicode = <auto>", scintilla displays some unicode
> >> > as you showed. but the win32-functions (e.g. MessageBox) still do not
> >> > pass through wide unicode.
> >>
> >>     Win32 issues are better discussed on the python-win32 mailing list
> >> which is read by more of the people interested in working on this library.
> >> http://mail.python.org/mailman/listinfo/python-win32
> >>     Patches that improve MessageBox in particular or larger sets of
> >> functions in a general way are likely to be welcomed.
> >
> > ok. I have no patches so far as of now - maybe later. Played with
> > Heller's ctypes for my urgent needs. That works correct with unicode
> > like this:
> >
> >>>> import ctypes
> >>>> ctypes.windll.user32.MessageBoxW(0,u'\u041f\u043e\u0448\u0443\u043a.txt',0,0)
> > 1
>
> FYI, if you assign the argtypes attribute for ctypes functions, the
> ascii/unicode conversion is automatic (if needed).
>
> So after these assignments:
>
>   ctypes.windll.user32.MessageBoxW.argtypes = (c_int, c_wchar_p,
>                                                c_wchar_p, c_int)
>   ctypes.windll.user32.MessageBoxA.argtypes = (c_int, c_char_p,
>                                                c_char_p, c_int)
>
> both MessageBoxA and MessageBoxW can both be called with either ansi and
> unicode strings, and should work correctly.  By default the conversion
> is done with ('msbc', 'ignore'), but this can also be changed,
> ctypes-wide, with a call to ctypes.set_conversion_mode(encoding,errors).

That is a right style of functionality, consistency and duty-free
default execution flow which python and pythonwin are lacking so far.
Those have no prominent mode-setting function, the mode-_tuple_ etc. so
far and/or defaults are set to break simple apps with common tasks.

Only question: is there a reason to have 'ignore' instead of 'replace'
as default? Wouldn't 'replace' deliver better indications (as for
example every Webbrowser does on unknown unicode chars ; (and even
mbcs_encode in 'strict'-mode) ). I can not see any advantage of
'ignore' vs. 'replace' when strict equality anyway has been given up
...

Robert




More information about the Python-list mailing list