views:

436

answers:

1

I'd like to create a ListBox in wxPython with the same semantics as a multiple select box in HTML. Specifically I'd like the following semantics

  • When the user clicks on an entry in the list, all other entries become de-selected and the clicked entry becomes selected. If the entry was already selected then it stays selected.
  • When the user holds down the Ctrl key while clicking on an entry, all other entries stay unchanged, but it toggles whether the clicked entry is selected.
  • When the user holds down shift and clicks on an entry, that entry and every entry between it and the last clicked entry become selected.

In Java I get this by using the JList class in Swing and setting the selection mode to MULTIPLE_INTERVAL_SELECTED. I assume that there's a way to do this with the wxPython toolkit, but I can't figure out how to get a ListBox or ListCtrl or any other class to do this short of doing an enormous amount of event-driven programming myself.

+3  A: 

I think what you're looking for is the wxLB_EXTENDED list box style. Specify style = wx.LB_EXTENDED when you create the ListBox.

You can then use the GetSelections method to obtain a list of the selected items.

ChrisN