wx.ComboBox doesn't update GetSelection() after its items are removed

224 views
Skip to first unread message

Adam Bielański

unread,
Aug 23, 2012, 7:33:08 AM8/23/12
to wxpytho...@googlegroups.com
Hi all,

First of all - OS and versions: Windows 7, Python 2.6, wxPython 2.9.3.1

Now here's issue description, scenario and sample app:

Description: GetSelection() returns invalid value after combobox dropdown has
been dismissed by clicking outside combobox area.

Scenario:
Let's create a wx.ComboBox and fill it with items. When user opens it and clicks
on a dropdown or combo itself to select/dismiss dropdown, everything's fine.
Issue occurs when user has some item selected in combo, then opens a dropdown
and left-clicks somewhere outside combo and dropdown area. That click dismiss
dropdown and combobox keeps previous selection. So far so good, it seems.

Now when you click a button labelled 'Remove first' (by calling
self._combo.Delete(0)), result of self._combo.GetSelection() doesn't change! (If
you click that button several times, self._combo.GetSelection() will be greater
than self._combo.GetCount(), but that's not part of this scenario) It would be
easy to workaround in client code, but watch out for another button - 'Select
second'. Clicking it calls 'self._combo.SetSelection(1)'. Now you'd expect
self._combo.GetSelection() to return 1, but it still returns the old value!
However, combo box UI have been updated and it displays correct (second on the
list) value...


Sample application is in the attachment. For the sake of clarity I added print
statements, so clicking a button yields current selection to stdout.

Please advise on how to workaround this issue in current wxPython release.

Best regards,

Adam Bielański.

sampleComboIssue.py

Robin Dunn

unread,
Aug 23, 2012, 2:15:45 PM8/23/12
to wxpytho...@googlegroups.com
Upgrade to 2.9.4.0. Unless I'm misunderstanding your description of the
problem all seems to be working as expected there.


--
Robin Dunn
Software Craftsman
http://wxPython.org

Adam Bielański

unread,
Aug 24, 2012, 3:08:47 AM8/24/12
to wxpytho...@googlegroups.com


W dniu 2012-08-23 20:15, Robin Dunn pisze:
Hi,

Thanks for answering. I have just installed 2.9.4.0 and the issue still exists.
I'm using Windows 7 x32 - maybe it makes a difference if it's x32 not x64
(didn't have chance to verify it yet).

Anyway - I have added a button, not bound to anything to my sample app, but now
I can write detailed step-by-step scenario:

1. Run 'sampleComboIssue.py' app and make your console visible
[Output I see: 'wxPython version: 2.9.4.0 msw (classic)']
2. Click combo box and select item labelled 'two'
[No output at this step]
3. Click combo box again and having it expanded, click a button labelled 'Just a
button' (note that there's no event handler for this button EVT_BUTTON event)
[Combo box collapses, no output printed on console, combo value is still 'two']
4. Click 'Remove first' button
[Output I see:
"""
onRemove PRE
onRemove removing first item
onRemove items left 8. Selection: 7
"""
]
5. Click 'Select second' button
[Output I see:
"""
onSelect PRE GetSelection(): 7 (zero)
onSelect setting selection to 1
onSelect POST GetSelection(): 7 (zero)
"""]
6. Displayed combo box value is 'four', not 'zero', since combo displays item at
position 1, which is correct result of calling SetSelection(). But result of
GetSelection() is still 7.
Now you can click 'Select second' again, but it will just repeat the same output
as in step 6.

You can also click 'Remove first' button and this will make result of
GetSelection() be greater than result of GetCount(). To check it, click 'Select
second' after clicking 'Remove first'. Output I see in such case is:
"""
onRemove PRE
onRemove removing first item
onRemove items left 7. Selection: 7
onSelect PRE GetSelection(): 7 (Position 7 not found)
onSelect setting selection to 1
onSelect POST GetSelection(): 7 (Position 7 not found)
"""
Displayed combo value is 'one', but using GetSelection()/SetSelection()/Select()
API I can't get it nor change it.

Any help will be appreciated.

Adam Bielański.
sampleComboIssue.py

Robin Dunn

unread,
Aug 24, 2012, 9:44:57 PM8/24/12
to wxpytho...@googlegroups.com
On 8/24/12 12:08 AM, Adam Bielański wrote:
>

> Displayed combo value is 'one', but using
> GetSelection()/SetSelection()/Select() API I can't get it nor change it.
>
> Any help will be appreciated.

It looks like this is already fixed for 2.9.5. I was able to duplicate
the issue following your directions with 2.9.4, but not in my current
2.9.5 workspace, the GetSelection value at the end is correctly 1.

Unfortunately the only work arounds that comes to mind is to Clear() the
items from the combo and then Append the new list and select the one
that should be selected. Another would be to keep track of the current
selection yourself, updating the value in the appropriate event handlers
and also when you explicitly set the selection yourself.
Reply all
Reply to author
Forward
0 new messages