wxComboBox and Unicode

We database (Access) that contains some text in Hebrew
When I'am trying to load wxComboBox with data I've got
in ADO Recordset it fails
Here the code I'm using:

self.__rs.Open ("select CategoryID, CategoryName from Category;",
self.__conn, 1)
       lstCategoryNames=[]
       while not self.__rs.EOF:

lstCategoryNames.append((self.__rs.Fields("CategoryName").Value))
           self.__rs.MoveNext()

       wxStaticText(self, -1, "???", pos=(675,80))

       self.cbCategory = wxComboBox(self, wxNewId(), lstCategoryNames[0],
                wxPoint(450,80), wxSize(220, -1),
                  lstCategoryNames, style=wxCB_READONLY | wxCB_DROPDOWN)

Here the FULL error screen

Traceback (most recent call last):
File "C:\Documents and Settings\Owner\My
Documents\Reuven\Lessons\ExamTest.py"
, line 213, in ?
   pnlEditSong(frame, wxNewId())
File "C:\Documents and Settings\Owner\My
Documents\Reuven\Lessons\ExamTest.py"
, line 67, in __init__
   lstCategoryNames, style=wxCB_READONLY | wxCB_DROPDOWN)
File "C:\Python22\Lib\site-packages\wxPython\controls.py", line 330, in
__init

···

__
   self.this = apply(controlsc.new_wxComboBox,_args,_kwargs)
TypeError: Unable to convert string
12:58:51: Debug: e:\projects\wx\src\msw\app.cpp(439):
'UnregisterClass(canvas)'
failed with error 0x00000584 (class still has open windows.).

Reuven Abliyev wrote:

We database (Access) that contains some text in Hebrew
When I'am trying to load wxComboBox with data I've got
in ADO Recordset it fails
Here the code I'm using:

self.__rs.Open ("select CategoryID, CategoryName from Category;",
self.__conn, 1)
       lstCategoryNames=
       while not self.__rs.EOF:

lstCategoryNames.append((self.__rs.Fields("CategoryName").Value))
           self.__rs.MoveNext()

       wxStaticText(self, -1, "???", pos=(675,80))

       self.cbCategory = wxComboBox(self, wxNewId(), lstCategoryNames[0],
                wxPoint(450,80), wxSize(220, -1),
                  lstCategoryNames, style=wxCB_READONLY | wxCB_DROPDOWN)

If you are using the Unicode version of wxPython then try converting the strings in lstCategoryNames to Unicode objects beofre passing them to the wxComboBox. One of the items in your list is not able to be converted by the code that is trying to automatically do it in wxPython, if you do it yourself you'll be able to see why and perhaps work around it.

···

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

If you are using the Unicode version of wxPython then try converting the
strings in lstCategoryNames to Unicode objects beofre passing them to
the wxComboBox. One of the items in your list is not able to be
converted by the code that is trying to automatically do it in wxPython,
if you do it yourself you'll be able to see why and >perhaps work around

it.

One of the items in your list is not able to be
converted by the code that is trying to automatically do >it in wxPython,

These those ones that contains Hebrew text, I've tried to use unicode
function but it writes same message

print self.__rs.Fields("CategoryName").Value
UnicodeError: ASCII encoding error: ordinal not in range(128)

What can I do in this case?

Reuven Abliyev wrote:

If you are using the Unicode version of wxPython then try converting the
strings in lstCategoryNames to Unicode objects beofre passing them to
the wxComboBox. One of the items in your list is not able to be
converted by the code that is trying to automatically do it in wxPython,
if you do it yourself you'll be able to see why and >perhaps work around

it.

One of the items in your list is not able to be
converted by the code that is trying to automatically do >it in wxPython,

These those ones that contains Hebrew text, I've tried to use unicode
function but it writes same message

print self.__rs.Fields("CategoryName").Value
UnicodeError: ASCII encoding error: ordinal not in range(128)

What can I do in this case?

Take a look at the Python docs for the unicode objects and encodings for more details, but I think you need to specify a different encoding to use to convert the value. THe error above indicates that it is attempting to use the ASCII encoding and has found a character that doesn't fall in the right range.

···

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