up/down arrow keys on ComboBox work correctly under Linux, but not under Windows.

I have a wx.ComboBox that is created like this

      self.input_text = wx.ComboBox(self, choices=self.history,
                                    style=wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER|wx.WANTS_CHARS)
      self.input_text.SetFocus()
      self.input_text.Bind(wx.EVT_CHAR, self.on_text_char)

I insert a list of text strings into it like this

         self.history.append(command)
         self.input_text.SetItems(self.history)

When I press the up arrow on Linux, the last text string from
that list is put into the ComboBox, when I press the down arrow,
the first text string from that list is put into the ComboBox.
I believe this is correct. At least it is the behaviour I expect.

On Windows, both up arrow and down arrow put the first text string
(self.history[]) into the ComboBox.

Is this a bug or a feature?

Is there any way to configure the ComboBox, so it behaves
correctly under Windows?

I was using 2.8.7.1 with Python 2.5.2.
I updated to 2.8.10.1 to see if that fixes the problem.
Unfortunately, the problem still exists in 2.8.10.1.

TIA for any help!

Carsten.

Hi Carsten,

···

On Aug 13, 12:02 pm, Carsten Koch <CarstenKochI...@web.de> wrote:

I have a wx.ComboBox that is created like this

  self\.input\_text = wx\.ComboBox\(self, choices=self\.history,
                                style=wx\.CB\_DROPDOWN|wx\.TE\_PROCESS\_ENTER|wx\.WANTS\_CHARS\)
  self\.input\_text\.SetFocus\(\)
  self\.input\_text\.Bind\(wx\.EVT\_CHAR, self\.on\_text\_char\)

I insert a list of text strings into it like this

     self\.history\.append\(command\)
     self\.input\_text\.SetItems\(self\.history\)

When I press the up arrow on Linux, the last text string from
that list is put into the ComboBox, when I press the down arrow,
the first text string from that list is put into the ComboBox.
I believe this is correct. At least it is the behaviour I expect.

On Windows, both up arrow and down arrow put the first text string
(self.history) into the ComboBox.

Is this a bug or a feature?

Is there any way to configure the ComboBox, so it behaves
correctly under Windows?

I was using 2.8.7.1 with Python 2.5.2.
I updated to 2.8.10.1 to see if that fixes the problem.
Unfortunately, the problem still exists in 2.8.10.1.

TIA for any help!

Carsten.

I'm not aware of a way to make ComboBox do that itself. But you should
be able to catch the key event from the arrow keys and just handle it
in the key press handler.

- Mike

Carsten Koch wrote:

I have a wx.ComboBox that is created like this

      self.input_text = wx.ComboBox(self, choices=self.history,
                                    style=wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER|wx.WANTS_CHARS)
      self.input_text.SetFocus()
      self.input_text.Bind(wx.EVT_CHAR, self.on_text_char)

I insert a list of text strings into it like this

         self.history.append(command)
         self.input_text.SetItems(self.history)

When I press the up arrow on Linux, the last text string from
that list is put into the ComboBox, when I press the down arrow,
the first text string from that list is put into the ComboBox.
I believe this is correct. At least it is the behaviour I expect.

On Windows, both up arrow and down arrow put the first text string
(self.history) into the ComboBox.

Is this a bug or a feature?

Neither. It's just the way that the native widgets work, and each is correct for the platform as far as the platform designers are concerned.

···

--
Robin Dunn
Software Craftsman

Hi Mike,

...

> self.input_text = wx.ComboBox(self, choices=self.history,
> style=wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER|wx.WANTS_CHARS)
> self.input_text.SetFocus()
> self.input_text.Bind(wx.EVT_CHAR, self.on_text_char)

...

> When I press the up arrow on Linux, the last text string from
> that list is put into the ComboBox, when I press the down arrow,
> the first text string from that list is put into the ComboBox.
> I believe this is correct. At least it is the behaviour I expect.
>
> On Windows, both up arrow and down arrow put the first text string
> (self.history) into the ComboBox.

...

I'm not aware of a way to make ComboBox do that itself. But you should
be able to catch the key event from the arrow keys and just handle it
in the key press handler.

This sounded like a good idea, so I implemented it.
As you see in the original code above, I already have
the wx.WANTS_CHARS flag set and a wx.EVT_CHAR handler
implemented, so all I needed to do was extend that handler:

   def on_text_char(self, event):
      """
         A character key has been pressed.
      """
      if event.KeyCode == wx.WXK_TAB:
         self.request_file_name_completion()
      elif event.KeyCode == wx.WXK_RETURN:
         self.process_input_text()
      elif event.KeyCode == wx.WXK_ESCAPE:
         self.shell.stdin.write(chr(event.KeyCode) + '\n')
      elif event.KeyCode == wx.WXK_UP:
         self.move_history_index(-1)
      elif event.KeyCode == wx.WXK_DOWN:
         self.move_history_index(+1)
      else:
         event.Skip() # let wx process all other key codes.

Under Linux, this works fine, too (like my original code).
Under Windows, on_text_char does not get called at all
when I press an arrow key. :frowning:

I googled and found out that this has just been reported
last month by somebody else. See this thread:
http://groups.google.com/group/wxPython-users/browse_thread/thread/07601b47a69c6ec0

@raf, have you ever found a solution for your
windows oddity 1: arrow key in combobox doesn't generate EVT_CHAR
?

Cheers,
Carsten.

···

On Thu, 2009-08-13 at 11:58 -0700, Mike Driscoll wrote:

Hi Mike,

...

> self.input_text = wx.ComboBox(self, choices=self.history,
> style=wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER|wx.WANTS_CHARS)
> self.input_text.SetFocus()
> self.input_text.Bind(wx.EVT_CHAR, self.on_text_char)

...

> When I press the up arrow on Linux, the last text string from
> that list is put into the ComboBox, when I press the down arrow,
> the first text string from that list is put into the ComboBox.
> I believe this is correct. At least it is the behaviour I expect.
>
> On Windows, both up arrow and down arrow put the first text string
> (self.history) into the ComboBox.

...

I'm not aware of a way to make ComboBox do that itself. But you should
be able to catch the key event from the arrow keys and just handle it
in the key press handler.

This sounded like a good idea, so I implemented it.
As you see in the original code above, I already have
the wx.WANTS_CHARS flag set and a wx.EVT_CHAR handler
implemented, so all I needed to do was extend that handler:

   def on_text_char(self, event):
      """
         A character key has been pressed.
      """
      if event.KeyCode == wx.WXK_TAB:
         self.request_file_name_completion()
      elif event.KeyCode == wx.WXK_RETURN:
         self.process_input_text()
      elif event.KeyCode == wx.WXK_ESCAPE:
         self.shell.stdin.write(chr(event.KeyCode) + '\n')
      elif event.KeyCode == wx.WXK_UP:
         self.move_history_index(-1)
      elif event.KeyCode == wx.WXK_DOWN:
         self.move_history_index(+1)
      else:
         event.Skip() # let wx process all other key codes.

Under Linux, this works fine, too (like my original code).
Under Windows, on_text_char does not get called at all
when I press an arrow key. :frowning:

I googled and found out that this has just been reported
last month by somebody else. See this thread:
http://groups.google.com/group/wxPython-users/browse_thread/thread/07601b47a69c6ec0

@raf, have you ever found a solution for your
windows oddity 1: arrow key in combobox doesn't generate EVT_CHAR
?

Cheers,
Carsten.

···

On Thu, 2009-08-13 at 11:58 -0700, Mike Driscoll wrote: