masked UnicodeWarning

I am sometimes getting the following in 2.8.9.1 on Windows.

C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\lib\masked\combobox.py:706: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if self.GetCurrentSelection() == -1 and self.GetValue().lower().strip() in self._ctrl_constraints._compareChoices:

Is this me doing something wrong or should this be changed in masked.combobox?

Werner

Werner F. Bruhin wrote:

I am sometimes getting the following in 2.8.9.1 on Windows.

C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\lib\masked\combobox.py:706: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if self.GetCurrentSelection() == -1 and self.GetValue().lower().strip() in self._ctrl_constraints._compareChoices:

Is this me doing something wrong or should this be changed in masked.combobox?

What is self.GetValue() and self._ctrl_constraints._compareChoices at the time the warning is issued?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Werner F. Bruhin wrote:

I am sometimes getting the following in 2.8.9.1 on Windows.

C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\lib\masked\combobox.py:706: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if self.GetCurrentSelection() == -1 and self.GetValue().lower().strip() in self._ctrl_constraints._compareChoices:

Is this me doing something wrong or should this be changed in masked.combobox?

What is self.GetValue() and self._ctrl_constraints._compareChoices at the time the warning is issued?

I added to comobox:
        print 'getvalue: %s' % str(self.GetValue().lower())
        print 'compareChoices: %s' % str(self._ctrl_constraints._compareChoices)

and get this:

getvalue: find a match, for a dish - french site
compareChoices: ['vinoxml wine profiles from gws', 'wine availability search on gws', 'find a match, for a dish - french site', 'find a match, for a dish, english site', 'find a match, for a wine - french site', 'find a match, for a wine - english site']
getvalue: rosé compareChoices: ['red', 'white', 'ros\xe3\xa9', 'white moelleux', 'white mousseux', 'ros\xe3\xa9 mousseux', 'red mousseux']

The choices get loaded like this into the comobox:
    def loadTypeVinsPlats(self):
        sourceList = [['1', [_("Red"),]],
                      ['2', [_("White"),]],
                      ['3', [_("Rose"),]],
                      ['4', [_("White Moelleux"),]],
                      ['5', [_("White Mousseux"),]],
                      ['6', [_("Rose Mousseux"),]],
                      ['7', [_("Red Mousseux"),]],
                     ]
               self.typeVinsPlats.Clear()
        for item in sourceList:
            self.typeVinsPlats.Append(item[1][0], item)

And the source code and the charset in Poedit are set to utf-8 and "Rose" is translated to "Rosé" in gettext/Poedit.

It looks like something is going wrong when appending items?

Werner

Werner F. Bruhin wrote:

Robin Dunn wrote:

Werner F. Bruhin wrote:

I am sometimes getting the following in 2.8.9.1 on Windows.

C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\lib\masked\combobox.py:706: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if self.GetCurrentSelection() == -1 and self.GetValue().lower().strip() in self._ctrl_constraints._compareChoices:

Is this me doing something wrong or should this be changed in masked.combobox?

What is self.GetValue() and self._ctrl_constraints._compareChoices at the time the warning is issued?

I added to comobox:
       print 'getvalue: %s' % str(self.GetValue().lower())
       print 'compareChoices: %s' % str(self._ctrl_constraints._compareChoices)

and get this:

getvalue: find a match, for a dish - french site
compareChoices: ['vinoxml wine profiles from gws', 'wine availability search on gws', 'find a match, for a dish - french site', 'find a match, for a dish, english site', 'find a match, for a wine - french site', 'find a match, for a wine - english site']
getvalue: rosé compareChoices: ['red', 'white', 'ros\xe3\xa9', 'white moelleux', 'white mousseux', 'ros\xe3\xa9 mousseux', 'red mousseux']

The choices get loaded like this into the comobox:
   def loadTypeVinsPlats(self):
       sourceList = [['1', [_("Red"),]],
                     ['2', [_("White"),]],
                     ['3', [_("Rose"),]],
                     ['4', [_("White Moelleux"),]],
                     ['5', [_("White Mousseux"),]],
                     ['6', [_("Rose Mousseux"),]],
                     ['7', [_("Red Mousseux"),]],
                    ]
             self.typeVinsPlats.Clear()
       for item in sourceList:
           self.typeVinsPlats.Append(item[1][0], item)

And the source code and the charset in Poedit are set to utf-8 and "Rose" is translated to "Rosé" in gettext/Poedit.

It looks like something is going wrong when appending items?

Probably something related to the encoding being used. If you keep your values in Unicode then there won't need to be conversions that can break...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin,

Robin Dunn wrote:
....

The choices get loaded like this into the comobox:
   def loadTypeVinsPlats(self):
       sourceList = [['1', [_("Red"),]],
                     ['2', [_("White"),]],
                     ['3', [_("Rose"),]],
                     ['4', [_("White Moelleux"),]],
                     ['5', [_("White Mousseux"),]],
                     ['6', [_("Rose Mousseux"),]],
                     ['7', [_("Red Mousseux"),]],
                    ]
             self.typeVinsPlats.Clear()
       for item in sourceList:
           self.typeVinsPlats.Append(item[1][0], item)

And the source code and the charset in Poedit are set to utf-8 and "Rose" is translated to "Rosé" in gettext/Poedit.

It looks like something is going wrong when appending items?

Probably something related to the encoding being used. If you keep your values in Unicode then there won't need to be conversions that can break...

How stupid of me not seeing that I used strings instead of Unicode.

You are right changing the "Rosé" to u"Rosé" etc got rid of the exception.

Thanks a lot
Werner

Robin,

Werner F. Bruhin wrote:

Robin,

Robin Dunn wrote:
....

The choices get loaded like this into the comobox:
   def loadTypeVinsPlats(self):
       sourceList = [['1', [_("Red"),]],
                     ['2', [_("White"),]],
                     ['3', [_("Rose"),]],
                     ['4', [_("White Moelleux"),]],
                     ['5', [_("White Mousseux"),]],
                     ['6', [_("Rose Mousseux"),]],
                     ['7', [_("Red Mousseux"),]],
                    ]
             self.typeVinsPlats.Clear()
       for item in sourceList:
           self.typeVinsPlats.Append(item[1][0], item)

And the source code and the charset in Poedit are set to utf-8 and "Rose" is translated to "Rosé" in gettext/Poedit.

It looks like something is going wrong when appending items?

Probably something related to the encoding being used. If you keep your values in Unicode then there won't need to be conversions that can break...

How stupid of me not seeing that I used strings instead of Unicode.

You are right changing the "Rosé" to u"Rosé" etc got rid of the exception.

I still seem to have a problem here. I think it has to do with gettext.

        sourceList = [[u'1', [_(u"Red"),]],
                      [u'2', [_(u"White"),]],
                      [u'3', [_(u"Rose"),]],
                      [u'4', [_(u"White Moelleux"),]],
                      [u'5', [_(u"White Mousseux"),]],
                      [u'6', [_(u"Rose Mousseux"),]],
                      [u'7', [_(u"Red Mousseux"),]],
                     ]
       looking at "sourceList" here with the debugger I have strings.

I changed my app call to gettext as follows:
import gettext
gettext.install('twcb', os.path.join(os.getcwd(), 'locale'), unicode=1)

But even setting "unicode=1" I still get strings, which then generate the error originally mentioned in this thread. Note that my .mo files are utf-8 encoded and my app also uses a default encoding of utf-8.

Anyone knows how I can get gettext to return unicode objects?

        self.typeVinsPlats.Clear()
        for item in sourceList:
            self.typeVinsPlats.Append(item[1][0], item)

A work around is to change the above to:
        self.typeVinsPlats.Clear()
        for item in sourceList:
            self.typeVinsPlats.Append(unicode(item[1][0]), item)

But I really think this is a work around.

Werner

You are right changing the "Rosé" to u"Rosé" etc got rid of the
exception.

I still seem to have a problem here. I think it has to do with gettext.

       sourceList = [[u'1', [_(u"Red"),]],
                     [u'2', [_(u"White"),]],
                     [u'3', [_(u"Rose"),]],
                     [u'4', [_(u"White Moelleux"),]],
                     [u'5', [_(u"White Mousseux"),]],
                     [u'6', [_(u"Rose Mousseux"),]],
                     [u'7', [_(u"Red Mousseux"),]],
                    ]
      looking at "sourceList" here with the debugger I have strings.

Maybe the debugger is turning them into strings for display?
What does a simple

  print type(sourceList['3'][0])

say ?

I changed my app call to gettext as follows:
import gettext
gettext.install('twcb', os.path.join(os.getcwd(), 'locale'), unicode=1)

But even setting "unicode=1" I still get strings,

Hm, strange, this works for me with GNUmed under Python 2.5.

However, we usually do _('some string') instead of _(u'some string').

Also, I am not sure changing "Rosé" to u"Rosé" will causally
solve your initial problem. The presentation of the string
you *see* in the source file interacts with the encoding of
the source *file* (as set in the first line) not with what
you tell Python the string of characters is supposed to be a
type of (which you do by declaring it u'' == to be of type
unicode). Only if the viewable character presentation so
*happens* to map 1:1 onto Unicode code points does that
work. OR if you truly use unicode source
files/terminal/keyboard (that does NOT mean utf8 ones !).

Or maybe I got this last part wrong - happy to be corrected.

Can you try the simplest possible example:

merkur:~/bin# python
Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import gettext
gettext.install('gnumed', unicode=1)
_('abc')

u'abc'

Does that return u'' for you or not ?

Karsten

···

On Tue, Feb 03, 2009 at 06:38:17PM +0100, Werner F. Bruhin wrote:
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

Karsten,

Thanks for looking at this. Reviewing your comments and trying to document what happens for me put me to the problem.

My initial "install" call did set unicode:
gettext.install('twcb', os.path.join(os.getcwd(), 'locale'), unicode=1)

but when I change language I did not, so changing these calls to e.g.

langFr.install(unicode=1)

I.e. I get Unicode back from gettext calls and the masked problem has gone away (at least for now :wink: ).

Thanks again
Werner

Thanks for looking at this. Reviewing your comments and trying to
document what happens for me put me to the problem.

...

I.e. I get Unicode back from gettext calls and the masked problem has
gone away (at least for now :wink: ).

Most welcome. Proper l10n/i18n is a hard, interesting, and
worthwhile issue.

Karsten

···

On Wed, Feb 04, 2009 at 02:18:55PM +0100, Werner F. Bruhin wrote:
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346